VirtualBox

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

最後變更 在這個檔案從42462是 42462,由 vboxsync 提交於 13 年 前

Build fix.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 14.0 KB
 
1/** @file
2 * Guest control service - Common header for host service and guest clients.
3 */
4
5/*
6 * Copyright (C) 2011-2012 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.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 */
47enum eProcessStatus
48{
49 /** Process is in an undefined state. */
50 PROC_STS_UNDEFINED = 0,
51 /** Process has been started. */
52 PROC_STS_STARTED = 1,
53 /** Process terminated normally. */
54 PROC_STS_TEN = 2,
55 /** Process terminated via signal. */
56 PROC_STS_TES = 3,
57 /** Process terminated abnormally. */
58 PROC_STS_TEA = 4,
59 /** Process timed out and was killed. */
60 PROC_STS_TOK = 5,
61 /** Process timed out and was not killed successfully. */
62 PROC_STS_TOA = 6,
63 /** Service/OS is stopping, process was killed. */
64 PROC_STS_DWN = 7,
65 /** Something went wrong (error code in flags). */
66 PROC_STS_ERROR = 8
67};
68
69/**
70 * Input flags, set by the host. This is needed for
71 * handling flags on the guest side.
72 * Note: Has to match Main's ProcessInputFlag_* flags!
73 */
74#define INPUT_FLAG_NONE 0x0
75#define INPUT_FLAG_EOF RT_BIT(0)
76
77/**
78 * Execution flags.
79 * Note: Has to match Main's CreateProcessFlag_* flags!
80 */
81#define EXECUTEPROCESSFLAG_NONE 0x0
82#define EXECUTEPROCESSFLAG_WAIT_START RT_BIT(0)
83#define EXECUTEPROCESSFLAG_IGNORE_ORPHANED RT_BIT(1)
84#define EXECUTEPROCESSFLAG_HIDDEN RT_BIT(2)
85#define EXECUTEPROCESSFLAG_NO_PROFILE RT_BIT(3)
86#define EXECUTEPROCESSFLAG_WAIT_STDOUT RT_BIT(4)
87#define EXECUTEPROCESSFLAG_WAIT_STDERR RT_BIT(5)
88
89/**
90 * Pipe handle IDs used internally for referencing to
91 * a certain pipe buffer.
92 */
93#define OUTPUT_HANDLE_ID_STDOUT_DEPRECATED 0 /* Needed for VBox hosts < 4.1.0. */
94#define OUTPUT_HANDLE_ID_STDOUT 1
95#define OUTPUT_HANDLE_ID_STDERR 2
96
97/**
98 * Defines for guest process array lengths.
99 */
100#define GUESTPROCESS_MAX_CMD_LEN _1K
101#define GUESTPROCESS_MAX_ARGS_LEN _1K
102#define GUESTPROCESS_MAX_ENV_LEN _64K
103#define GUESTPROCESS_MAX_USER_LEN 128
104#define GUESTPROCESS_MAX_PASSWORD_LEN 128
105
106/** @name Internal tools built into VBoxService which are used in order to
107 * accomplish tasks host<->guest.
108 * @{
109 */
110#define VBOXSERVICE_TOOL_CAT "vbox_cat"
111#define VBOXSERVICE_TOOL_LS "vbox_ls"
112#define VBOXSERVICE_TOOL_MKDIR "vbox_mkdir"
113#define VBOXSERVICE_TOOL_STAT "vbox_stat"
114/** @} */
115
116/**
117 * Input status, reported by the client.
118 */
119enum eInputStatus
120{
121 /** Input is in an undefined state. */
122 INPUT_STS_UNDEFINED = 0,
123 /** Input was written (partially, see cbProcessed). */
124 INPUT_STS_WRITTEN = 1,
125 /** Input failed with an error (see flags for rc). */
126 INPUT_STS_ERROR = 20,
127 /** Process has abandoned / terminated input handling. */
128 INPUT_STS_TERMINATED = 21,
129 /** Too much input data. */
130 INPUT_STS_OVERFLOW = 30
131};
132
133/**
134 * The guest control callback data header. Must come first
135 * on each callback structure defined below this struct.
136 */
137typedef struct VBoxGuestCtrlCallbackHeader
138{
139 /** Magic number to identify the structure. */
140 uint32_t u32Magic;
141 /** Context ID to identify callback data. */
142 uint32_t u32ContextID;
143} CALLBACKHEADER;
144typedef CALLBACKHEADER *PCALLBACKHEADER;
145
146typedef struct VBoxGuestCtrlCallbackDataClientDisconnected
147{
148 /** Callback data header. */
149 CALLBACKHEADER hdr;
150} CALLBACKDATACLIENTDISCONNECTED;
151typedef CALLBACKDATACLIENTDISCONNECTED *PCALLBACKDATACLIENTDISCONNECTED;
152
153/**
154 * Data structure to pass to the service extension callback. We use this to
155 * notify the host of changes to properties.
156 */
157typedef struct VBoxGuestCtrlCallbackDataExecStatus
158{
159 /** Callback data header. */
160 CALLBACKHEADER hdr;
161 /** The process ID (PID). */
162 uint32_t u32PID;
163 /** The process status. */
164 uint32_t u32Status;
165 /** Optional flags, varies, based on u32Status. */
166 uint32_t u32Flags;
167 /** Optional data buffer (not used atm). */
168 void *pvData;
169 /** Size of optional data buffer (not used atm). */
170 uint32_t cbData;
171} CALLBACKDATAEXECSTATUS;
172typedef CALLBACKDATAEXECSTATUS *PCALLBACKDATAEXECSTATUS;
173
174typedef struct VBoxGuestCtrlCallbackDataExecOut
175{
176 /** Callback data header. */
177 CALLBACKHEADER hdr;
178 /** The process ID (PID). */
179 uint32_t u32PID;
180 /** The handle ID (stdout/stderr). */
181 uint32_t u32HandleId;
182 /** Optional flags (not used atm). */
183 uint32_t u32Flags;
184 /** Optional data buffer. */
185 void *pvData;
186 /** Size (in bytes) of optional data buffer. */
187 uint32_t cbData;
188} CALLBACKDATAEXECOUT;
189typedef CALLBACKDATAEXECOUT *PCALLBACKDATAEXECOUT;
190
191typedef struct VBoxGuestCtrlCallbackDataExecInStatus
192{
193 /** Callback data header. */
194 CALLBACKHEADER hdr;
195 /** The process ID (PID). */
196 uint32_t u32PID;
197 /** Current input status. */
198 uint32_t u32Status;
199 /** Optional flags. */
200 uint32_t u32Flags;
201 /** Size (in bytes) of processed input data. */
202 uint32_t cbProcessed;
203} CALLBACKDATAEXECINSTATUS;
204typedef CALLBACKDATAEXECINSTATUS *PCALLBACKDATAEXECINSTATUS;
205
206enum eVBoxGuestCtrlCallbackDataMagic
207{
208 CALLBACKDATAMAGIC_CLIENT_DISCONNECTED = 0x08041984,
209
210 CALLBACKDATAMAGIC_EXEC_STATUS = 0x26011982,
211 CALLBACKDATAMAGIC_EXEC_OUT = 0x11061949,
212 CALLBACKDATAMAGIC_EXEC_IN_STATUS = 0x19091951
213};
214
215enum eVBoxGuestCtrlCallbackType
216{
217 VBOXGUESTCTRLCALLBACKTYPE_UNKNOWN = 0,
218
219 VBOXGUESTCTRLCALLBACKTYPE_EXEC_START = 1,
220 VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT = 2,
221 VBOXGUESTCTRLCALLBACKTYPE_EXEC_INPUT_STATUS = 3
222};
223
224/**
225 * The service functions which are callable by host.
226 */
227enum eHostFn
228{
229 /**
230 * The host asks the client to cancel all pending waits and exit.
231 */
232 HOST_CANCEL_PENDING_WAITS = 0,
233
234 /*
235 * Execution handling.
236 */
237
238 /**
239 * The host wants to execute something in the guest. This can be a command line
240 * or starting a program.
241 */
242 HOST_EXEC_CMD = 100,
243 /**
244 * Sends input data for stdin to a running process executed by HOST_EXEC_CMD.
245 */
246 HOST_EXEC_SET_INPUT = 101,
247 /**
248 * Gets the current status of a running process, e.g.
249 * new data on stdout/stderr, process terminated etc.
250 */
251 HOST_EXEC_GET_OUTPUT = 102,
252
253 /*
254 * Guest control 2.0 commands start in the 2xx number space.
255 */
256
257 /**
258 * Waits for a certain event to happen. This can be an input, output
259 * or status event.
260 */
261 HOST_EXEC_WAIT_FOR = 210
262};
263
264/**
265 * The service functions which are called by guest. The numbers may not change,
266 * so we hardcode them.
267 */
268enum eGuestFn
269{
270 /**
271 * Guest waits for a new message the host wants to process on the guest side.
272 * This is a blocking call and can be deferred.
273 */
274 GUEST_GET_HOST_MSG = 1,
275 /**
276 * Guest asks the host to cancel all pending waits the guest itself waits on.
277 * This becomes necessary when the guest wants to quit but still waits for
278 * commands from the host.
279 */
280 GUEST_CANCEL_PENDING_WAITS = 2,
281 /**
282 * Guest disconnected (terminated normally or due to a crash HGCM
283 * detected when calling service::clientDisconnect().
284 */
285 GUEST_DISCONNECTED = 3,
286
287 /*
288 * Process execution.
289 * The 1xx commands are legacy guest control commands and
290 * will be replaced by newer commands in the future.
291 */
292
293 /**
294 * Guests sends output from an executed process.
295 */
296 GUEST_EXEC_SEND_OUTPUT = 100,
297 /**
298 * Guest sends a status update of an executed process to the host.
299 */
300 GUEST_EXEC_SEND_STATUS = 101,
301 /**
302 * Guests sends an input status notification to the host.
303 */
304 GUEST_EXEC_SEND_INPUT_STATUS = 102,
305
306 /*
307 * Guest control 2.0 commands start in the 2xx number space.
308 */
309
310 /**
311 * Guest notifies the host about some I/O event. This can be
312 * a stdout, stderr or a stdin event. The actual event only tells
313 * how many data is available / can be sent without actually
314 * transmitting the data.
315 */
316 GUEST_EXEC_IO_NOTIFY = 210
317};
318
319/*
320 * HGCM parameter structures.
321 */
322#pragma pack (1)
323
324typedef struct VBoxGuestCtrlHGCMMsgType
325{
326 VBoxGuestHGCMCallInfo hdr;
327
328 /**
329 * The returned command the host wants to
330 * run on the guest.
331 */
332 HGCMFunctionParameter msg; /* OUT uint32_t */
333 /** Number of parameters the message needs. */
334 HGCMFunctionParameter num_parms; /* OUT uint32_t */
335
336} VBoxGuestCtrlHGCMMsgType;
337
338/**
339 * Asks the guest control host service to cancel all pending (outstanding)
340 * waits which were not processed yet. This is handy for a graceful shutdown.
341 */
342typedef struct VBoxGuestCtrlHGCMMsgCancelPendingWaits
343{
344 VBoxGuestHGCMCallInfo hdr;
345} VBoxGuestCtrlHGCMMsgCancelPendingWaits;
346
347/**
348 * Executes a command inside the guest.
349 */
350typedef struct VBoxGuestCtrlHGCMMsgExecCmd
351{
352 VBoxGuestHGCMCallInfo hdr;
353 /** Context ID. */
354 HGCMFunctionParameter context;
355 /** The command to execute on the guest. */
356 HGCMFunctionParameter cmd;
357 /** Execution flags (see IGuest::ProcessCreateFlag_*). */
358 HGCMFunctionParameter flags;
359 /** Number of arguments. */
360 HGCMFunctionParameter num_args;
361 /** The actual arguments. */
362 HGCMFunctionParameter args;
363 /** Number of environment value pairs. */
364 HGCMFunctionParameter num_env;
365 /** Size (in bytes) of environment block, including terminating zeros. */
366 HGCMFunctionParameter cb_env;
367 /** The actual environment block. */
368 HGCMFunctionParameter env;
369 /** The user name to run the executed command under. */
370 HGCMFunctionParameter username;
371 /** The user's password. */
372 HGCMFunctionParameter password;
373 /** Timeout (in msec) which either specifies the
374 * overall lifetime of the process or how long it
375 * can take to bring the process up and running -
376 * (depends on the IGuest::ProcessCreateFlag_*). */
377 HGCMFunctionParameter timeout;
378
379} VBoxGuestCtrlHGCMMsgExecCmd;
380
381/**
382 * Injects input to a previously executed process via stdin.
383 */
384typedef struct VBoxGuestCtrlHGCMMsgExecIn
385{
386 VBoxGuestHGCMCallInfo hdr;
387 /** Context ID. */
388 HGCMFunctionParameter context;
389 /** The process ID (PID) to send the input to. */
390 HGCMFunctionParameter pid;
391 /** Input flags (see IGuest::ProcessInputFlag_*). */
392 HGCMFunctionParameter flags;
393 /** Data buffer. */
394 HGCMFunctionParameter data;
395 /** Actual size of data (in bytes). */
396 HGCMFunctionParameter size;
397
398} VBoxGuestCtrlHGCMMsgExecIn;
399
400/**
401 * Retrieves ouptut from a previously executed process
402 * from stdout/stderr.
403 */
404typedef struct VBoxGuestCtrlHGCMMsgExecOut
405{
406 VBoxGuestHGCMCallInfo hdr;
407 /** Context ID. */
408 HGCMFunctionParameter context;
409 /** The process ID (PID). */
410 HGCMFunctionParameter pid;
411 /** The pipe handle ID (stdout/stderr). */
412 HGCMFunctionParameter handle;
413 /** Optional flags. */
414 HGCMFunctionParameter flags;
415 /** Data buffer. */
416 HGCMFunctionParameter data;
417
418} VBoxGuestCtrlHGCMMsgExecOut;
419
420/**
421 * Reports the current status of a (just) started
422 * or terminated process.
423 */
424typedef struct VBoxGuestCtrlHGCMMsgExecStatus
425{
426 VBoxGuestHGCMCallInfo hdr;
427 /** Context ID. */
428 HGCMFunctionParameter context;
429 /** The process ID (PID). */
430 HGCMFunctionParameter pid;
431 /** The process status. */
432 HGCMFunctionParameter status;
433 /** Optional flags (based on status). */
434 HGCMFunctionParameter flags;
435 /** Optional data buffer (not used atm). */
436 HGCMFunctionParameter data;
437
438} VBoxGuestCtrlHGCMMsgExecStatus;
439
440/**
441 * Reports back the status of data written to a process.
442 */
443typedef struct VBoxGuestCtrlHGCMMsgExecStatusIn
444{
445 VBoxGuestHGCMCallInfo hdr;
446 /** Context ID. */
447 HGCMFunctionParameter context;
448 /** The process ID (PID). */
449 HGCMFunctionParameter pid;
450 /** Status of the operation. */
451 HGCMFunctionParameter status;
452 /** Optional flags. */
453 HGCMFunctionParameter flags;
454 /** Data written. */
455 HGCMFunctionParameter written;
456
457} VBoxGuestCtrlHGCMMsgExecStatusIn;
458
459/**
460 * Reports back the currente I/O status of a guest process.
461 */
462typedef struct VBoxGuestCtrlHGCMMsgExecIONotify
463{
464 VBoxGuestHGCMCallInfo hdr;
465 /** Context ID. */
466 HGCMFunctionParameter context;
467 /** Data written. */
468 HGCMFunctionParameter written;
469
470} VBoxGuestCtrlHGCMMsgExecIONotify;
471
472#pragma pack ()
473
474/**
475 * Structure for buffering execution requests in the host service.
476 */
477typedef struct VBoxGuestCtrlParamBuffer
478{
479 uint32_t uMsg;
480 uint32_t uParmCount;
481 PVBOXHGCMSVCPARM pParms;
482} VBOXGUESTCTRPARAMBUFFER;
483typedef VBOXGUESTCTRPARAMBUFFER *PVBOXGUESTCTRPARAMBUFFER;
484
485} /* namespace guestControl */
486
487#endif /* !___VBox_HostService_GuestControlService_h */
488
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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