VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.h@ 85800

Last change on this file since 85800 was 84215, checked in by vboxsync, 5 years ago

Guest Control/VbglR3 + VBoxService: Moved code to retrieve and allocate session and process startup information into VbglR3; required as preparation dealing with longer command line arguments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/* $Id: VBoxServiceControl.h 84215 2020-05-08 14:08:23Z vboxsync $ */
2/** @file
3 * VBoxServiceControl.h - Internal guest control definitions.
4 */
5
6/*
7 * Copyright (C) 2013-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef GA_INCLUDED_SRC_common_VBoxService_VBoxServiceControl_h
19#define GA_INCLUDED_SRC_common_VBoxService_VBoxServiceControl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <iprt/critsect.h>
25#include <iprt/list.h>
26#include <iprt/req.h>
27
28#include <VBox/VBoxGuestLib.h>
29#include <VBox/GuestHost/GuestControl.h>
30#include <VBox/HostServices/GuestControlSvc.h>
31
32
33/**
34 * Pipe IDs for handling the guest process poll set.
35 */
36typedef enum VBOXSERVICECTRLPIPEID
37{
38 VBOXSERVICECTRLPIPEID_UNKNOWN = 0,
39 VBOXSERVICECTRLPIPEID_STDIN = 10,
40 VBOXSERVICECTRLPIPEID_STDIN_WRITABLE = 11,
41 /** Pipe for reading from guest process' stdout. */
42 VBOXSERVICECTRLPIPEID_STDOUT = 40,
43 /** Pipe for reading from guest process' stderr. */
44 VBOXSERVICECTRLPIPEID_STDERR = 50,
45 /** Notification pipe for waking up the guest process
46 * control thread. */
47 VBOXSERVICECTRLPIPEID_IPC_NOTIFY = 100
48} VBOXSERVICECTRLPIPEID;
49
50/**
51 * Structure for one (opened) guest file.
52 */
53typedef struct VBOXSERVICECTRLFILE
54{
55 /** Pointer to list archor of following
56 * list node.
57 * @todo Would be nice to have a RTListGetAnchor(). */
58 PRTLISTANCHOR pAnchor;
59 /** Node to global guest control file list. */
60 /** @todo Use a map later? */
61 RTLISTNODE Node;
62 /** The file name. */
63 char *pszName;
64 /** The file handle on the guest. */
65 RTFILE hFile;
66 /** File handle to identify this file. */
67 uint32_t uHandle;
68 /** Context ID. */
69 uint32_t uContextID;
70 /** RTFILE_O_XXX flags. */
71 uint64_t fOpen;
72} VBOXSERVICECTRLFILE;
73/** Pointer to thread data. */
74typedef VBOXSERVICECTRLFILE *PVBOXSERVICECTRLFILE;
75
76/**
77 * Structure for a guest session thread to
78 * observe/control the forked session instance from
79 * the VBoxService main executable.
80 */
81typedef struct VBOXSERVICECTRLSESSIONTHREAD
82{
83 /** Node to global guest control session list. */
84 /** @todo Use a map later? */
85 RTLISTNODE Node;
86 /** The sessions's startup info. */
87 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO
88 pStartupInfo;
89 /** Critical section for thread-safe use. */
90 RTCRITSECT CritSect;
91 /** The worker thread. */
92 RTTHREAD Thread;
93 /** Process handle for forked child. */
94 RTPROCESS hProcess;
95 /** Shutdown indicator; will be set when the thread
96 * needs (or is asked) to shutdown. */
97 bool volatile fShutdown;
98 /** Indicator set by the service thread exiting. */
99 bool volatile fStopped;
100 /** Whether the thread was started or not. */
101 bool fStarted;
102#if 0 /* Pipe IPC not used yet. */
103 /** Pollset containing all the pipes. */
104 RTPOLLSET hPollSet;
105 RTPIPE hStdInW;
106 RTPIPE hStdOutR;
107 RTPIPE hStdErrR;
108 struct StdPipe
109 {
110 RTHANDLE hChild;
111 PRTHANDLE phChild;
112 } StdIn,
113 StdOut,
114 StdErr;
115 /** The notification pipe associated with this guest session.
116 * This is NIL_RTPIPE for output pipes. */
117 RTPIPE hNotificationPipeW;
118 /** The other end of hNotificationPipeW. */
119 RTPIPE hNotificationPipeR;
120#endif
121 /** Pipe for handing the secret key to the session process. */
122 RTPIPE hKeyPipe;
123 /** Secret key. */
124 uint8_t abKey[_4K];
125} VBOXSERVICECTRLSESSIONTHREAD;
126/** Pointer to thread data. */
127typedef VBOXSERVICECTRLSESSIONTHREAD *PVBOXSERVICECTRLSESSIONTHREAD;
128
129/** Defines the prefix being used for telling our service executable that we're going
130 * to spawn a new (Guest Control) user session. */
131#define VBOXSERVICECTRLSESSION_GETOPT_PREFIX "guestsession"
132
133/** Flag indicating that this session has been spawned from
134 * the main executable. */
135#define VBOXSERVICECTRLSESSION_FLAG_SPAWN RT_BIT(0)
136/** Flag indicating that this session is anonymous, that is,
137 * it will run start guest processes with the same credentials
138 * as the main executable. */
139#define VBOXSERVICECTRLSESSION_FLAG_ANONYMOUS RT_BIT(1)
140/** Flag indicating that started guest processes will dump their
141 * stdout output to a separate file on disk. For debugging. */
142#define VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT RT_BIT(2)
143/** Flag indicating that started guest processes will dump their
144 * stderr output to a separate file on disk. For debugging. */
145#define VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR RT_BIT(3)
146
147/**
148 * Structure for maintaining a guest session. This also
149 * contains all started threads (e.g. for guest processes).
150 *
151 * This structure can act in two different ways:
152 * - For legacy guest control handling (protocol version < 2)
153 * this acts as a per-guest process structure containing all
154 * the information needed to get a guest process up and running.
155 * - For newer guest control protocols (>= 2) this structure is
156 * part of the forked session child, maintaining all guest
157 * control objects under it.
158 */
159typedef struct VBOXSERVICECTRLSESSION
160{
161 /* The session's startup information. */
162 VBGLR3GUESTCTRLSESSIONSTARTUPINFO
163 StartupInfo;
164 /** List of active guest process threads
165 * (VBOXSERVICECTRLPROCESS). */
166 RTLISTANCHOR lstProcesses;
167 /** Number of guest processes in the process list. */
168 uint32_t cProcesses;
169 /** List of guest control files (VBOXSERVICECTRLFILE). */
170 RTLISTANCHOR lstFiles;
171 /** Number of guest files in the file list. */
172 uint32_t cFiles;
173 /** The session's critical section. */
174 RTCRITSECT CritSect;
175 /** Internal session flags, not related
176 * to StartupInfo stuff.
177 * @sa VBOXSERVICECTRLSESSION_FLAG_* flags. */
178 uint32_t fFlags;
179 /** How many processes do we allow keeping around at a time? */
180 uint32_t uProcsMaxKept;
181} VBOXSERVICECTRLSESSION;
182/** Pointer to guest session. */
183typedef VBOXSERVICECTRLSESSION *PVBOXSERVICECTRLSESSION;
184
185/**
186 * Structure for holding data for one (started) guest process.
187 */
188typedef struct VBOXSERVICECTRLPROCESS
189{
190 /** Node. */
191 RTLISTNODE Node;
192 /** Process handle. */
193 RTPROCESS hProcess;
194 /** Number of references using this struct. */
195 uint32_t cRefs;
196 /** The worker thread. */
197 RTTHREAD Thread;
198 /** The session this guest process
199 * is bound to. */
200 PVBOXSERVICECTRLSESSION pSession;
201 /** Shutdown indicator; will be set when the thread
202 * needs (or is asked) to shutdown. */
203 bool volatile fShutdown;
204 /** Whether the guest process thread was stopped or not. */
205 bool volatile fStopped;
206 /** Whether the guest process thread was started or not. */
207 bool fStarted;
208 /** Context ID. */
209 uint32_t uContextID;
210 /** Critical section for thread-safe use. */
211 RTCRITSECT CritSect;
212 /** Process startup information. */
213 PVBGLR3GUESTCTRLPROCSTARTUPINFO
214 pStartupInfo;
215 /** The process' PID assigned by the guest OS. */
216 uint32_t uPID;
217 /** The process' request queue to handle requests
218 * from the outside, e.g. the session. */
219 RTREQQUEUE hReqQueue;
220 /** Our pollset, used for accessing the process'
221 * std* pipes + the notification pipe. */
222 RTPOLLSET hPollSet;
223 /** StdIn pipe for addressing writes to the
224 * guest process' stdin.*/
225 RTPIPE hPipeStdInW;
226 /** StdOut pipe for addressing reads from
227 * guest process' stdout.*/
228 RTPIPE hPipeStdOutR;
229 /** StdOut pipe for addressing reads from
230 * guest process' stderr.*/
231 RTPIPE hPipeStdErrR;
232
233 /** The write end of the notification pipe that is used to poke the thread
234 * monitoring the process.
235 * This is NIL_RTPIPE for output pipes. */
236 RTPIPE hNotificationPipeW;
237 /** The other end of hNotificationPipeW, read by vgsvcGstCtrlProcessProcLoop(). */
238 RTPIPE hNotificationPipeR;
239} VBOXSERVICECTRLPROCESS;
240/** Pointer to thread data. */
241typedef VBOXSERVICECTRLPROCESS *PVBOXSERVICECTRLPROCESS;
242
243RT_C_DECLS_BEGIN
244
245extern RTLISTANCHOR g_lstControlSessionThreads;
246extern VBOXSERVICECTRLSESSION g_Session;
247extern uint32_t g_idControlSvcClient;
248extern uint64_t g_fControlHostFeatures0;
249extern bool g_fControlSupportsOptimizations;
250
251
252/** @name Guest session thread handling.
253 * @{ */
254extern int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pSessionStartupInfo, PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread);
255extern int VGSvcGstCtrlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pSession, uint32_t uFlags);
256extern int VGSvcGstCtrlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t uFlags);
257extern int VGSvcGstCtrlSessionThreadTerminate(PVBOXSERVICECTRLSESSIONTHREAD pSession);
258extern RTEXITCODE VGSvcGstCtrlSessionSpawnInit(int argc, char **argv);
259/** @} */
260/** @name Per-session functions.
261 * @{ */
262extern PVBOXSERVICECTRLPROCESS VGSvcGstCtrlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID);
263extern int VGSvcGstCtrlSessionClose(PVBOXSERVICECTRLSESSION pSession);
264extern int VGSvcGstCtrlSessionDestroy(PVBOXSERVICECTRLSESSION pSession);
265extern int VGSvcGstCtrlSessionInit(PVBOXSERVICECTRLSESSION pSession, uint32_t uFlags);
266extern int VGSvcGstCtrlSessionHandler(PVBOXSERVICECTRLSESSION pSession, uint32_t uMsg, PVBGLR3GUESTCTRLCMDCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf, volatile bool *pfShutdown);
267extern int VGSvcGstCtrlSessionProcessAdd(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess);
268extern int VGSvcGstCtrlSessionProcessRemove(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess);
269extern int VGSvcGstCtrlSessionProcessStartAllowed(const PVBOXSERVICECTRLSESSION pSession, bool *pfAllowed);
270extern int VGSvcGstCtrlSessionReapProcesses(PVBOXSERVICECTRLSESSION pSession);
271/** @} */
272/** @name Per-guest process functions.
273 * @{ */
274extern int VGSvcGstCtrlProcessFree(PVBOXSERVICECTRLPROCESS pProcess);
275extern int VGSvcGstCtrlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fPendingClose, void *pvBuf, uint32_t cbBuf);
276extern int VGSvcGstCtrlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags);
277extern int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess);
278extern void VGSvcGstCtrlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess);
279extern int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, const PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContext);
280extern int VGSvcGstCtrlProcessStop(PVBOXSERVICECTRLPROCESS pProcess);
281extern int VGSvcGstCtrlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *pRc);
282/** @} */
283
284RT_C_DECLS_END
285
286#endif /* !GA_INCLUDED_SRC_common_VBoxService_VBoxServiceControl_h */
287
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette