VirtualBox

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

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

Copyright year updates by scm.

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