VirtualBox

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

Last change on this file since 75946 was 75858, checked in by vboxsync, 6 years ago

VBoxService: Mark printf-style formatters as such, fixing fallout. Eliminated another redundant connection to the guest control service. bugref:9313

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 KB
Line 
1/* $Id: VBoxServiceControl.h 75858 2018-12-01 22:13:05Z vboxsync $ */
2/** @file
3 * VBoxServiceControl.h - Internal guest control definitions.
4 */
5
6/*
7 * Copyright (C) 2013-2017 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 ___VBoxServiceControl_h
19#define ___VBoxServiceControl_h
20
21#include <iprt/critsect.h>
22#include <iprt/list.h>
23#include <iprt/req.h>
24
25#include <VBox/VBoxGuestLib.h>
26#include <VBox/GuestHost/GuestControl.h>
27#include <VBox/HostServices/GuestControlSvc.h>
28
29
30/**
31 * Pipe IDs for handling the guest process poll set.
32 */
33typedef enum VBOXSERVICECTRLPIPEID
34{
35 VBOXSERVICECTRLPIPEID_UNKNOWN = 0,
36 VBOXSERVICECTRLPIPEID_STDIN = 10,
37 VBOXSERVICECTRLPIPEID_STDIN_WRITABLE = 11,
38 /** Pipe for reading from guest process' stdout. */
39 VBOXSERVICECTRLPIPEID_STDOUT = 40,
40 /** Pipe for reading from guest process' stderr. */
41 VBOXSERVICECTRLPIPEID_STDERR = 50,
42 /** Notification pipe for waking up the guest process
43 * control thread. */
44 VBOXSERVICECTRLPIPEID_IPC_NOTIFY = 100
45} VBOXSERVICECTRLPIPEID;
46
47/**
48 * Structure for one (opened) guest file.
49 */
50typedef struct VBOXSERVICECTRLFILE
51{
52 /** Pointer to list archor of following
53 * list node.
54 * @todo Would be nice to have a RTListGetAnchor(). */
55 PRTLISTANCHOR pAnchor;
56 /** Node to global guest control file list. */
57 /** @todo Use a map later? */
58 RTLISTNODE Node;
59 /** The file name. */
60 char szName[RTPATH_MAX];
61 /** The file handle on the guest. */
62 RTFILE hFile;
63 /** File handle to identify this file. */
64 uint32_t uHandle;
65 /** Context ID. */
66 uint32_t uContextID;
67} VBOXSERVICECTRLFILE;
68/** Pointer to thread data. */
69typedef VBOXSERVICECTRLFILE *PVBOXSERVICECTRLFILE;
70
71typedef struct VBOXSERVICECTRLSESSIONSTARTUPINFO
72{
73 /** The session's protocol version to use. */
74 uint32_t uProtocol;
75 /** The session's ID. */
76 uint32_t uSessionID;
77 /** User name (account) to start the guest session under. */
78 char szUser[GUESTPROCESS_MAX_USER_LEN];
79 /** Password of specified user name (account). */
80 char szPassword[GUESTPROCESS_MAX_PASSWORD_LEN];
81 /** Domain of the user account. */
82 char szDomain[GUESTPROCESS_MAX_DOMAIN_LEN];
83 /** Session creation flags.
84 * @sa VBOXSERVICECTRLSESSIONSTARTUPFLAG_* flags. */
85 uint32_t fFlags;
86} VBOXSERVICECTRLSESSIONSTARTUPINFO;
87/** Pointer to thread data. */
88typedef VBOXSERVICECTRLSESSIONSTARTUPINFO *PVBOXSERVICECTRLSESSIONSTARTUPINFO;
89
90/**
91 * Structure for a guest session thread to
92 * observe/control the forked session instance from
93 * the VBoxService main executable.
94 */
95typedef struct VBOXSERVICECTRLSESSIONTHREAD
96{
97 /** Node to global guest control session list. */
98 /** @todo Use a map later? */
99 RTLISTNODE Node;
100 /** The sessions's startup info. */
101 VBOXSERVICECTRLSESSIONSTARTUPINFO StartupInfo;
102 /** Critical section for thread-safe use. */
103 RTCRITSECT CritSect;
104 /** The worker thread. */
105 RTTHREAD Thread;
106 /** Process handle for forked child. */
107 RTPROCESS hProcess;
108 /** Shutdown indicator; will be set when the thread
109 * needs (or is asked) to shutdown. */
110 bool volatile fShutdown;
111 /** Indicator set by the service thread exiting. */
112 bool volatile fStopped;
113 /** Whether the thread was started or not. */
114 bool fStarted;
115#if 0 /* Pipe IPC not used yet. */
116 /** Pollset containing all the pipes. */
117 RTPOLLSET hPollSet;
118 RTPIPE hStdInW;
119 RTPIPE hStdOutR;
120 RTPIPE hStdErrR;
121 struct StdPipe
122 {
123 RTHANDLE hChild;
124 PRTHANDLE phChild;
125 } StdIn,
126 StdOut,
127 StdErr;
128 /** The notification pipe associated with this guest session.
129 * This is NIL_RTPIPE for output pipes. */
130 RTPIPE hNotificationPipeW;
131 /** The other end of hNotificationPipeW. */
132 RTPIPE hNotificationPipeR;
133#endif
134 /** Pipe for handing the secret key to the session process. */
135 RTPIPE hKeyPipe;
136 /** Secret key. */
137 uint8_t abKey[_4K];
138} VBOXSERVICECTRLSESSIONTHREAD;
139/** Pointer to thread data. */
140typedef VBOXSERVICECTRLSESSIONTHREAD *PVBOXSERVICECTRLSESSIONTHREAD;
141
142/** Flag indicating that this session has been spawned from
143 * the main executable. */
144#define VBOXSERVICECTRLSESSION_FLAG_SPAWN RT_BIT(0)
145/** Flag indicating that this session is anonymous, that is,
146 * it will run start guest processes with the same credentials
147 * as the main executable. */
148#define VBOXSERVICECTRLSESSION_FLAG_ANONYMOUS RT_BIT(1)
149/** Flag indicating that started guest processes will dump their
150 * stdout output to a separate file on disk. For debugging. */
151#define VBOXSERVICECTRLSESSION_FLAG_DUMPSTDOUT RT_BIT(2)
152/** Flag indicating that started guest processes will dump their
153 * stderr output to a separate file on disk. For debugging. */
154#define VBOXSERVICECTRLSESSION_FLAG_DUMPSTDERR RT_BIT(3)
155
156/**
157 * Structure for maintaining a guest session. This also
158 * contains all started threads (e.g. for guest processes).
159 *
160 * This structure can act in two different ways:
161 * - For legacy guest control handling (protocol version < 2)
162 * this acts as a per-guest process structure containing all
163 * the information needed to get a guest process up and running.
164 * - For newer guest control protocols (>= 2) this structure is
165 * part of the forked session child, maintaining all guest
166 * control objects under it.
167 */
168typedef struct VBOXSERVICECTRLSESSION
169{
170 /* The session's startup information. */
171 VBOXSERVICECTRLSESSIONSTARTUPINFO
172 StartupInfo;
173 /** List of active guest process threads
174 * (VBOXSERVICECTRLPROCESS). */
175 RTLISTANCHOR lstProcesses;
176 /** List of guest control files (VBOXSERVICECTRLFILE). */
177 RTLISTANCHOR lstFiles;
178 /** The session's critical section. */
179 RTCRITSECT CritSect;
180 /** Internal session flags, not related
181 * to StartupInfo stuff.
182 * @sa VBOXSERVICECTRLSESSION_FLAG_* flags. */
183 uint32_t fFlags;
184 /** How many processes do we allow keeping around at a time? */
185 uint32_t uProcsMaxKept;
186} VBOXSERVICECTRLSESSION;
187/** Pointer to guest session. */
188typedef VBOXSERVICECTRLSESSION *PVBOXSERVICECTRLSESSION;
189
190/**
191 * Structure holding information for starting a guest
192 * process.
193 */
194typedef struct VBOXSERVICECTRLPROCSTARTUPINFO
195{
196 /** Full qualified path of process to start (without arguments). */
197 char szCmd[GUESTPROCESS_MAX_CMD_LEN];
198 /** Process execution flags. @sa */
199 uint32_t uFlags;
200 /** Command line arguments. */
201 char szArgs[GUESTPROCESS_MAX_ARGS_LEN];
202 /** Number of arguments specified in pszArgs. */
203 uint32_t uNumArgs;
204 /** String of environment variables ("FOO=BAR") to pass to the process
205 * to start. */
206 char szEnv[GUESTPROCESS_MAX_ENV_LEN];
207 /** Size (in bytes) of environment variables block. */
208 uint32_t cbEnv;
209 /** Number of environment variables specified in pszEnv. */
210 uint32_t uNumEnvVars;
211 /** User name (account) to start the process under. */
212 char szUser[GUESTPROCESS_MAX_USER_LEN];
213 /** Password of specified user name (account). */
214 char szPassword[GUESTPROCESS_MAX_PASSWORD_LEN];
215 /** Domain to be used for authenticating the specified user name (account). */
216 char szDomain[GUESTPROCESS_MAX_DOMAIN_LEN];
217 /** Time limit (in ms) of the process' life time. */
218 uint32_t uTimeLimitMS;
219 /** Process priority. */
220 uint32_t uPriority;
221 /** Process affinity. At the moment we support
222 * up to 4 * 64 = 256 CPUs. */
223 uint64_t uAffinity[4];
224 /** Number of used process affinity blocks. */
225 uint32_t uNumAffinity;
226} VBOXSERVICECTRLPROCSTARTUPINFO;
227/** Pointer to a guest process block. */
228typedef VBOXSERVICECTRLPROCSTARTUPINFO *PVBOXSERVICECTRLPROCSTARTUPINFO;
229
230/**
231 * Structure for holding data for one (started) guest process.
232 */
233typedef struct VBOXSERVICECTRLPROCESS
234{
235 /** Node. */
236 RTLISTNODE Node;
237 /** Process handle. */
238 RTPROCESS hProcess;
239 /** Number of references using this struct. */
240 uint32_t cRefs;
241 /** The worker thread. */
242 RTTHREAD Thread;
243 /** The session this guest process
244 * is bound to. */
245 PVBOXSERVICECTRLSESSION pSession;
246 /** Shutdown indicator; will be set when the thread
247 * needs (or is asked) to shutdown. */
248 bool volatile fShutdown;
249 /** Whether the guest process thread was stopped or not. */
250 bool volatile fStopped;
251 /** Whether the guest process thread was started or not. */
252 bool fStarted;
253 /** Context ID. */
254 uint32_t uContextID;
255 /** Critical section for thread-safe use. */
256 RTCRITSECT CritSect;
257 /** Process startup information. */
258 VBOXSERVICECTRLPROCSTARTUPINFO
259 StartupInfo;
260 /** The process' PID assigned by the guest OS. */
261 uint32_t uPID;
262 /** The process' request queue to handle requests
263 * from the outside, e.g. the session. */
264 RTREQQUEUE hReqQueue;
265 /** Our pollset, used for accessing the process'
266 * std* pipes + the notification pipe. */
267 RTPOLLSET hPollSet;
268 /** StdIn pipe for addressing writes to the
269 * guest process' stdin.*/
270 RTPIPE hPipeStdInW;
271 /** StdOut pipe for addressing reads from
272 * guest process' stdout.*/
273 RTPIPE hPipeStdOutR;
274 /** StdOut pipe for addressing reads from
275 * guest process' stdout.*/
276 RTPIPE hPipeStdErrR;
277
278 /** The write end of the notification pipe that is used to poke the thread
279 * monitoring the process.
280 * This is NIL_RTPIPE for output pipes. */
281 RTPIPE hNotificationPipeW;
282 /** The other end of hNotificationPipeW, read by vgsvcGstCtrlProcessProcLoop(). */
283 RTPIPE hNotificationPipeR;
284} VBOXSERVICECTRLPROCESS;
285/** Pointer to thread data. */
286typedef VBOXSERVICECTRLPROCESS *PVBOXSERVICECTRLPROCESS;
287
288RT_C_DECLS_BEGIN
289
290extern RTLISTANCHOR g_lstControlSessionThreads;
291extern VBOXSERVICECTRLSESSION g_Session;
292extern uint32_t g_idControlSvcClient;
293extern bool g_fControlSupportsOptimizations;
294
295
296/** @name Guest session thread handling.
297 * @{ */
298extern int VGSvcGstCtrlSessionThreadCreate(PRTLISTANCHOR pList, const PVBOXSERVICECTRLSESSIONSTARTUPINFO pSessionStartupInfo, PVBOXSERVICECTRLSESSIONTHREAD *ppSessionThread);
299extern int VGSvcGstCtrlSessionThreadDestroy(PVBOXSERVICECTRLSESSIONTHREAD pSession, uint32_t uFlags);
300extern int VGSvcGstCtrlSessionThreadDestroyAll(PRTLISTANCHOR pList, uint32_t uFlags);
301extern int VGSvcGstCtrlSessionThreadTerminate(PVBOXSERVICECTRLSESSIONTHREAD pSession);
302extern RTEXITCODE VGSvcGstCtrlSessionSpawnInit(int argc, char **argv);
303/** @} */
304/** @name Per-session functions.
305 * @{ */
306extern PVBOXSERVICECTRLPROCESS VGSvcGstCtrlSessionRetainProcess(PVBOXSERVICECTRLSESSION pSession, uint32_t uPID);
307extern int VGSvcGstCtrlSessionClose(PVBOXSERVICECTRLSESSION pSession);
308extern int VGSvcGstCtrlSessionDestroy(PVBOXSERVICECTRLSESSION pSession);
309extern int VGSvcGstCtrlSessionInit(PVBOXSERVICECTRLSESSION pSession, uint32_t uFlags);
310extern int VGSvcGstCtrlSessionHandler(PVBOXSERVICECTRLSESSION pSession, uint32_t uMsg, PVBGLR3GUESTCTRLCMDCTX pHostCtx, void *pvScratchBuf, size_t cbScratchBuf, volatile bool *pfShutdown);
311extern int VGSvcGstCtrlSessionProcessAdd(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess);
312extern int VGSvcGstCtrlSessionProcessRemove(PVBOXSERVICECTRLSESSION pSession, PVBOXSERVICECTRLPROCESS pProcess);
313extern int VGSvcGstCtrlSessionProcessStartAllowed(const PVBOXSERVICECTRLSESSION pSession, bool *pbAllowed);
314extern int VGSvcGstCtrlSessionReapProcesses(PVBOXSERVICECTRLSESSION pSession);
315/** @} */
316/** @name Per-guest process functions.
317 * @{ */
318extern int VGSvcGstCtrlProcessFree(PVBOXSERVICECTRLPROCESS pProcess);
319extern int VGSvcGstCtrlProcessHandleInput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, bool fPendingClose, void *pvBuf, uint32_t cbBuf);
320extern int VGSvcGstCtrlProcessHandleOutput(PVBOXSERVICECTRLPROCESS pProcess, PVBGLR3GUESTCTRLCMDCTX pHostCtx, uint32_t uHandle, uint32_t cbToRead, uint32_t uFlags);
321extern int VGSvcGstCtrlProcessHandleTerm(PVBOXSERVICECTRLPROCESS pProcess);
322extern void VGSvcGstCtrlProcessRelease(PVBOXSERVICECTRLPROCESS pProcess);
323extern int VGSvcGstCtrlProcessStart(const PVBOXSERVICECTRLSESSION pSession, const PVBOXSERVICECTRLPROCSTARTUPINFO pStartupInfo, uint32_t uContext);
324extern int VGSvcGstCtrlProcessStop(PVBOXSERVICECTRLPROCESS pProcess);
325extern int VGSvcGstCtrlProcessWait(const PVBOXSERVICECTRLPROCESS pProcess, RTMSINTERVAL msTimeout, int *pRc);
326/** @} */
327
328RT_C_DECLS_END
329
330#endif
331
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