VirtualBox

source: vbox/trunk/include/VBox/HostServices/GuestControlSvc.h@ 39798

Last change on this file since 39798 was 39654, checked in by vboxsync, 13 years ago

GuestControlSvc.h: Fixed wait-for-start flag.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1/** @file
2 * Guest control service - Common header for host service and guest clients.
3 */
4
5/*
6 * Copyright (C) 2011 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_HostService_GuestControlService_h
27#define ___VBox_HostService_GuestControlService_h
28
29#include <VBox/types.h>
30#include <VBox/VMMDev.h>
31#include <VBox/VBoxGuest2.h>
32#include <VBox/hgcmsvc.h>
33#include <VBox/log.h>
34#include <iprt/assert.h>
35#include <iprt/string.h>
36
37/* Everything defined in this file lives in this namespace. */
38namespace guestControl {
39
40/******************************************************************************
41* Typedefs, constants and inlines *
42******************************************************************************/
43
44/**
45 * Process status when executed in the guest.
46 * Note: Has to match Main's ExecuteProcessStatus_*!
47 */
48enum eProcessStatus
49{
50 /** Process is in an undefined state. */
51 PROC_STS_UNDEFINED = 0,
52 /** Process has been started. */
53 PROC_STS_STARTED = 1,
54 /** Process terminated normally. */
55 PROC_STS_TEN = 2,
56 /** Process terminated via signal. */
57 PROC_STS_TES = 3,
58 /** Process terminated abnormally. */
59 PROC_STS_TEA = 4,
60 /** Process timed out and was killed. */
61 PROC_STS_TOK = 5,
62 /** Process timed out and was not killed successfully. */
63 PROC_STS_TOA = 6,
64 /** Service/OS is stopping, process was killed. */
65 PROC_STS_DWN = 7,
66 /** Something went wrong (error code in flags). */
67 PROC_STS_ERROR = 8
68};
69
70/**
71 * Input flags, set by the host. This is needed for
72 * handling flags on the guest side.
73 * Note: Has to match Main's ProcessInputFlag_* flags!
74 */
75#define INPUT_FLAG_NONE 0
76#define INPUT_FLAG_EOF RT_BIT(0)
77
78/**
79 * Execution flags.
80 * Note: Has to match Main's ExecuteProcessFlag_* flags!
81 */
82#define EXECUTEPROCESSFLAG_NONE 0x0
83#define EXECUTEPROCESSFLAG_WAIT_START RT_BIT(0)
84#define EXECUTEPROCESSFLAG_IGNORE_ORPHANED RT_BIT(1)
85#define EXECUTEPROCESSFLAG_HIDDEN RT_BIT(2)
86#define EXECUTEPROCESSFLAG_NO_PROFILE RT_BIT(3)
87#define EXECUTEPROCESSFLAG_WAIT_STDOUT RT_BIT(4)
88#define EXECUTEPROCESSFLAG_WAIT_STDERR RT_BIT(5)
89
90/**
91 * Pipe handle IDs used internally for referencing to
92 * a certain pipe buffer.
93 */
94#define OUTPUT_HANDLE_ID_STDOUT_DEPRECATED 0 /* Needed for VBox hosts < 4.1.0. */
95#define OUTPUT_HANDLE_ID_STDOUT 1
96#define OUTPUT_HANDLE_ID_STDERR 2
97
98/** @name Internal tools built into VBoxService which are used in order to
99 * accomplish tasks host<->guest.
100 * @{
101 */
102#define VBOXSERVICE_TOOL_CAT "vbox_cat"
103#define VBOXSERVICE_TOOL_LS "vbox_ls"
104#define VBOXSERVICE_TOOL_MKDIR "vbox_mkdir"
105#define VBOXSERVICE_TOOL_STAT "vbox_stat"
106/** @} */
107
108/**
109 * Input status, reported by the client.
110 */
111enum eInputStatus
112{
113 /** Input is in an undefined state. */
114 INPUT_STS_UNDEFINED = 0,
115 /** Input was written (partially, see cbProcessed). */
116 INPUT_STS_WRITTEN = 1,
117 /** Input failed with an error (see flags for rc). */
118 INPUT_STS_ERROR = 20,
119 /** Process has abandoned / terminated input handling. */
120 INPUT_STS_TERMINATED = 21,
121 /** Too much input data. */
122 INPUT_STS_OVERFLOW = 30
123};
124
125/**
126 * The guest control callback data header. Must come first
127 * on each callback structure defined below this struct.
128 */
129typedef struct VBoxGuestCtrlCallbackHeader
130{
131 /** Magic number to identify the structure. */
132 uint32_t u32Magic;
133 /** Context ID to identify callback data. */
134 uint32_t u32ContextID;
135} CALLBACKHEADER;
136typedef CALLBACKHEADER *PCALLBACKHEADER;
137
138typedef struct VBoxGuestCtrlCallbackDataClientDisconnected
139{
140 /** Callback data header. */
141 CALLBACKHEADER hdr;
142} CALLBACKDATACLIENTDISCONNECTED;
143typedef CALLBACKDATACLIENTDISCONNECTED *PCALLBACKDATACLIENTDISCONNECTED;
144
145/**
146 * Data structure to pass to the service extension callback. We use this to
147 * notify the host of changes to properties.
148 */
149typedef struct VBoxGuestCtrlCallbackDataExecStatus
150{
151 /** Callback data header. */
152 CALLBACKHEADER hdr;
153 /** The process ID (PID). */
154 uint32_t u32PID;
155 /** The process status. */
156 uint32_t u32Status;
157 /** Optional flags, varies, based on u32Status. */
158 uint32_t u32Flags;
159 /** Optional data buffer (not used atm). */
160 void *pvData;
161 /** Size of optional data buffer (not used atm). */
162 uint32_t cbData;
163} CALLBACKDATAEXECSTATUS;
164typedef CALLBACKDATAEXECSTATUS *PCALLBACKDATAEXECSTATUS;
165
166typedef struct VBoxGuestCtrlCallbackDataExecOut
167{
168 /** Callback data header. */
169 CALLBACKHEADER hdr;
170 /** The process ID (PID). */
171 uint32_t u32PID;
172 /** The handle ID (stdout/stderr). */
173 uint32_t u32HandleId;
174 /** Optional flags (not used atm). */
175 uint32_t u32Flags;
176 /** Optional data buffer. */
177 void *pvData;
178 /** Size (in bytes) of optional data buffer. */
179 uint32_t cbData;
180} CALLBACKDATAEXECOUT;
181typedef CALLBACKDATAEXECOUT *PCALLBACKDATAEXECOUT;
182
183typedef struct VBoxGuestCtrlCallbackDataExecInStatus
184{
185 /** Callback data header. */
186 CALLBACKHEADER hdr;
187 /** The process ID (PID). */
188 uint32_t u32PID;
189 /** Current input status. */
190 uint32_t u32Status;
191 /** Optional flags. */
192 uint32_t u32Flags;
193 /** Size (in bytes) of processed input data. */
194 uint32_t cbProcessed;
195} CALLBACKDATAEXECINSTATUS;
196typedef CALLBACKDATAEXECINSTATUS *PCALLBACKDATAEXECINSTATUS;
197
198enum eVBoxGuestCtrlCallbackDataMagic
199{
200 CALLBACKDATAMAGIC_CLIENT_DISCONNECTED = 0x08041984,
201
202 CALLBACKDATAMAGIC_EXEC_STATUS = 0x26011982,
203 CALLBACKDATAMAGIC_EXEC_OUT = 0x11061949,
204 CALLBACKDATAMAGIC_EXEC_IN_STATUS = 0x19091951
205};
206
207enum eVBoxGuestCtrlCallbackType
208{
209 VBOXGUESTCTRLCALLBACKTYPE_UNKNOWN = 0,
210
211 VBOXGUESTCTRLCALLBACKTYPE_EXEC_START = 1,
212 VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT = 2,
213 VBOXGUESTCTRLCALLBACKTYPE_EXEC_INPUT_STATUS = 3
214};
215
216/**
217 * The service functions which are callable by host.
218 */
219enum eHostFn
220{
221 /**
222 * The host asks the client to cancel all pending waits and exit.
223 */
224 HOST_CANCEL_PENDING_WAITS = 0,
225
226 /*
227 * Execution handling.
228 */
229
230 /**
231 * The host wants to execute something in the guest. This can be a command line
232 * or starting a program.
233 */
234 HOST_EXEC_CMD = 100,
235 /**
236 * Sends input data for stdin to a running process executed by HOST_EXEC_CMD.
237 */
238 HOST_EXEC_SET_INPUT = 101,
239 /**
240 * Gets the current status of a running process, e.g.
241 * new data on stdout/stderr, process terminated etc.
242 */
243 HOST_EXEC_GET_OUTPUT = 102
244};
245
246/**
247 * The service functions which are called by guest. The numbers may not change,
248 * so we hardcode them.
249 */
250enum eGuestFn
251{
252 /**
253 * Guest waits for a new message the host wants to process on the guest side.
254 * This is a blocking call and can be deferred.
255 */
256 GUEST_GET_HOST_MSG = 1,
257 /**
258 * Guest asks the host to cancel all pending waits the guest itself waits on.
259 * This becomes necessary when the guest wants to quit but still waits for
260 * commands from the host.
261 */
262 GUEST_CANCEL_PENDING_WAITS = 2,
263 /**
264 * Guest disconnected (terminated normally or due to a crash HGCM
265 * detected when calling service::clientDisconnect().
266 */
267 GUEST_DISCONNECTED = 3,
268
269 /*
270 * Process execution.
271 */
272
273 /**
274 * Guests sends output from an executed process.
275 */
276 GUEST_EXEC_SEND_OUTPUT = 100,
277 /**
278 * Guest sends a status update of an executed process to the host.
279 */
280 GUEST_EXEC_SEND_STATUS = 101,
281 /**
282 * Guests sends an input status notification to the host.
283 */
284 GUEST_EXEC_SEND_INPUT_STATUS = 102
285};
286
287/*
288 * HGCM parameter structures.
289 */
290#pragma pack (1)
291
292typedef struct VBoxGuestCtrlHGCMMsgType
293{
294 VBoxGuestHGCMCallInfo hdr;
295
296 /**
297 * The returned command the host wants to
298 * run on the guest.
299 */
300 HGCMFunctionParameter msg; /* OUT uint32_t */
301 /** Number of parameters the message needs. */
302 HGCMFunctionParameter num_parms; /* OUT uint32_t */
303
304} VBoxGuestCtrlHGCMMsgType;
305
306/**
307 * Asks the guest control host service to cancel all pending (outstanding)
308 * waits which were not processed yet. This is handy for a graceful shutdown.
309 */
310typedef struct VBoxGuestCtrlHGCMMsgCancelPendingWaits
311{
312 VBoxGuestHGCMCallInfo hdr;
313} VBoxGuestCtrlHGCMMsgCancelPendingWaits;
314
315/**
316 * Executes a command inside the guest.
317 */
318typedef struct VBoxGuestCtrlHGCMMsgExecCmd
319{
320 VBoxGuestHGCMCallInfo hdr;
321 /** Context ID. */
322 HGCMFunctionParameter context;
323 /** The command to execute on the guest. */
324 HGCMFunctionParameter cmd;
325 /** Execution flags (see IGuest::ExecuteProcessFlag_*). */
326 HGCMFunctionParameter flags;
327 /** Number of arguments. */
328 HGCMFunctionParameter num_args;
329 /** The actual arguments. */
330 HGCMFunctionParameter args;
331 /** Number of environment value pairs. */
332 HGCMFunctionParameter num_env;
333 /** Size (in bytes) of environment block, including terminating zeros. */
334 HGCMFunctionParameter cb_env;
335 /** The actual environment block. */
336 HGCMFunctionParameter env;
337 /** The user name to run the executed command under. */
338 HGCMFunctionParameter username;
339 /** The user's password. */
340 HGCMFunctionParameter password;
341 /** Timeout (in msec) which either specifies the
342 * overall lifetime of the process or how long it
343 * can take to bring the process up and running -
344 * (depends on the IGuest::ExecuteProcessFlag_*). */
345 HGCMFunctionParameter timeout;
346
347} VBoxGuestCtrlHGCMMsgExecCmd;
348
349/**
350 * Injects input to a previously executed process via stdin.
351 */
352typedef struct VBoxGuestCtrlHGCMMsgExecIn
353{
354 VBoxGuestHGCMCallInfo hdr;
355 /** Context ID. */
356 HGCMFunctionParameter context;
357 /** The process ID (PID) to send the input to. */
358 HGCMFunctionParameter pid;
359 /** Input flags (see IGuest::ProcessInputFlag_*). */
360 HGCMFunctionParameter flags;
361 /** Data buffer. */
362 HGCMFunctionParameter data;
363 /** Actual size of data (in bytes). */
364 HGCMFunctionParameter size;
365
366} VBoxGuestCtrlHGCMMsgExecIn;
367
368/**
369 * Retrieves ouptut from a previously executed process
370 * from stdout/stderr.
371 */
372typedef struct VBoxGuestCtrlHGCMMsgExecOut
373{
374 VBoxGuestHGCMCallInfo hdr;
375 /** Context ID. */
376 HGCMFunctionParameter context;
377 /** The process ID (PID). */
378 HGCMFunctionParameter pid;
379 /** The pipe handle ID (stdout/stderr). */
380 HGCMFunctionParameter handle;
381 /** Optional flags. */
382 HGCMFunctionParameter flags;
383 /** Data buffer. */
384 HGCMFunctionParameter data;
385
386} VBoxGuestCtrlHGCMMsgExecOut;
387
388/**
389 * Reports the current status of a (just) started
390 * or terminated process.
391 */
392typedef struct VBoxGuestCtrlHGCMMsgExecStatus
393{
394 VBoxGuestHGCMCallInfo hdr;
395 /** Context ID. */
396 HGCMFunctionParameter context;
397 /** The process ID (PID). */
398 HGCMFunctionParameter pid;
399 /** The process status. */
400 HGCMFunctionParameter status;
401 /** Optional flags (based on status). */
402 HGCMFunctionParameter flags;
403 /** Optional data buffer (not used atm). */
404 HGCMFunctionParameter data;
405
406} VBoxGuestCtrlHGCMMsgExecStatus;
407
408/**
409 * Reports back the status of data written to a process.
410 */
411typedef struct VBoxGuestCtrlHGCMMsgExecStatusIn
412{
413 VBoxGuestHGCMCallInfo hdr;
414 /** Context ID. */
415 HGCMFunctionParameter context;
416 /** The process ID (PID). */
417 HGCMFunctionParameter pid;
418 /** Status of the operation. */
419 HGCMFunctionParameter status;
420 /** Optional flags. */
421 HGCMFunctionParameter flags;
422 /** Data written. */
423 HGCMFunctionParameter written;
424
425} VBoxGuestCtrlHGCMMsgExecStatusIn;
426
427#pragma pack ()
428
429/**
430 * Structure for buffering execution requests in the host service.
431 */
432typedef struct VBoxGuestCtrlParamBuffer
433{
434 uint32_t uMsg;
435 uint32_t uParmCount;
436 PVBOXHGCMSVCPARM pParms;
437} VBOXGUESTCTRPARAMBUFFER;
438typedef VBOXGUESTCTRPARAMBUFFER *PVBOXGUESTCTRPARAMBUFFER;
439
440} /* namespace guestControl */
441
442#endif /* !___VBox_HostService_GuestControlService_h */
443
Note: See TracBrowser for help on using the repository browser.

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