VirtualBox

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

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

GuestCtrl: Added support for explicitly waiting on stdout/stderr, bugfixes, logging adjustments.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 12.7 KB
 
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.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 * 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(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/** @name Internal tools built into VBoxService which are used in order to
98 * accomplish tasks host<->guest.
99 * @{
100 */
101#define VBOXSERVICE_TOOL_CAT "vbox_cat"
102#define VBOXSERVICE_TOOL_LS "vbox_ls"
103#define VBOXSERVICE_TOOL_MKDIR "vbox_mkdir"
104#define VBOXSERVICE_TOOL_STAT "vbox_stat"
105/** @} */
106
107/**
108 * Input status, reported by the client.
109 */
110enum eInputStatus
111{
112 /** Input is in an undefined state. */
113 INPUT_STS_UNDEFINED = 0,
114 /** Input was written (partially, see cbProcessed). */
115 INPUT_STS_WRITTEN = 1,
116 /** Input failed with an error (see flags for rc). */
117 INPUT_STS_ERROR = 20,
118 /** Process has abandoned / terminated input handling. */
119 INPUT_STS_TERMINATED = 21,
120 /** Too much input data. */
121 INPUT_STS_OVERFLOW = 30
122};
123
124/**
125 * The guest control callback data header. Must come first
126 * on each callback structure defined below this struct.
127 */
128typedef struct VBoxGuestCtrlCallbackHeader
129{
130 /** Magic number to identify the structure. */
131 uint32_t u32Magic;
132 /** Context ID to identify callback data. */
133 uint32_t u32ContextID;
134} CALLBACKHEADER;
135typedef CALLBACKHEADER *PCALLBACKHEADER;
136
137typedef struct VBoxGuestCtrlCallbackDataClientDisconnected
138{
139 /** Callback data header. */
140 CALLBACKHEADER hdr;
141} CALLBACKDATACLIENTDISCONNECTED;
142typedef CALLBACKDATACLIENTDISCONNECTED *PCALLBACKDATACLIENTDISCONNECTED;
143
144/**
145 * Data structure to pass to the service extension callback. We use this to
146 * notify the host of changes to properties.
147 */
148typedef struct VBoxGuestCtrlCallbackDataExecStatus
149{
150 /** Callback data header. */
151 CALLBACKHEADER hdr;
152 /** The process ID (PID). */
153 uint32_t u32PID;
154 /** The process status. */
155 uint32_t u32Status;
156 /** Optional flags, varies, based on u32Status. */
157 uint32_t u32Flags;
158 /** Optional data buffer (not used atm). */
159 void *pvData;
160 /** Size of optional data buffer (not used atm). */
161 uint32_t cbData;
162} CALLBACKDATAEXECSTATUS;
163typedef CALLBACKDATAEXECSTATUS *PCALLBACKDATAEXECSTATUS;
164
165typedef struct VBoxGuestCtrlCallbackDataExecOut
166{
167 /** Callback data header. */
168 CALLBACKHEADER hdr;
169 /** The process ID (PID). */
170 uint32_t u32PID;
171 /** The handle ID (stdout/stderr). */
172 uint32_t u32HandleId;
173 /** Optional flags (not used atm). */
174 uint32_t u32Flags;
175 /** Optional data buffer. */
176 void *pvData;
177 /** Size (in bytes) of optional data buffer. */
178 uint32_t cbData;
179} CALLBACKDATAEXECOUT;
180typedef CALLBACKDATAEXECOUT *PCALLBACKDATAEXECOUT;
181
182typedef struct VBoxGuestCtrlCallbackDataExecInStatus
183{
184 /** Callback data header. */
185 CALLBACKHEADER hdr;
186 /** The process ID (PID). */
187 uint32_t u32PID;
188 /** Current input status. */
189 uint32_t u32Status;
190 /** Optional flags. */
191 uint32_t u32Flags;
192 /** Size (in bytes) of processed input data. */
193 uint32_t cbProcessed;
194} CALLBACKDATAEXECINSTATUS;
195typedef CALLBACKDATAEXECINSTATUS *PCALLBACKDATAEXECINSTATUS;
196
197enum eVBoxGuestCtrlCallbackDataMagic
198{
199 CALLBACKDATAMAGIC_CLIENT_DISCONNECTED = 0x08041984,
200
201 CALLBACKDATAMAGIC_EXEC_STATUS = 0x26011982,
202 CALLBACKDATAMAGIC_EXEC_OUT = 0x11061949,
203 CALLBACKDATAMAGIC_EXEC_IN_STATUS = 0x19091951
204};
205
206enum eVBoxGuestCtrlCallbackType
207{
208 VBOXGUESTCTRLCALLBACKTYPE_UNKNOWN = 0,
209
210 VBOXGUESTCTRLCALLBACKTYPE_EXEC_START = 1,
211 VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT = 2,
212 VBOXGUESTCTRLCALLBACKTYPE_EXEC_INPUT_STATUS = 3
213};
214
215/**
216 * The service functions which are callable by host.
217 */
218enum eHostFn
219{
220 /**
221 * The host asks the client to cancel all pending waits and exit.
222 */
223 HOST_CANCEL_PENDING_WAITS = 0,
224
225 /*
226 * Execution handling.
227 */
228
229 /**
230 * The host wants to execute something in the guest. This can be a command line
231 * or starting a program.
232 */
233 HOST_EXEC_CMD = 100,
234 /**
235 * Sends input data for stdin to a running process executed by HOST_EXEC_CMD.
236 */
237 HOST_EXEC_SET_INPUT = 101,
238 /**
239 * Gets the current status of a running process, e.g.
240 * new data on stdout/stderr, process terminated etc.
241 */
242 HOST_EXEC_GET_OUTPUT = 102
243};
244
245/**
246 * The service functions which are called by guest. The numbers may not change,
247 * so we hardcode them.
248 */
249enum eGuestFn
250{
251 /**
252 * Guest waits for a new message the host wants to process on the guest side.
253 * This is a blocking call and can be deferred.
254 */
255 GUEST_GET_HOST_MSG = 1,
256 /**
257 * Guest asks the host to cancel all pending waits the guest itself waits on.
258 * This becomes necessary when the guest wants to quit but still waits for
259 * commands from the host.
260 */
261 GUEST_CANCEL_PENDING_WAITS = 2,
262 /**
263 * Guest disconnected (terminated normally or due to a crash HGCM
264 * detected when calling service::clientDisconnect().
265 */
266 GUEST_DISCONNECTED = 3,
267
268 /*
269 * Process execution.
270 */
271
272 /**
273 * Guests sends output from an executed process.
274 */
275 GUEST_EXEC_SEND_OUTPUT = 100,
276 /**
277 * Guest sends a status update of an executed process to the host.
278 */
279 GUEST_EXEC_SEND_STATUS = 101,
280 /**
281 * Guests sends an input status notification to the host.
282 */
283 GUEST_EXEC_SEND_INPUT_STATUS = 102
284};
285
286/*
287 * HGCM parameter structures.
288 */
289#pragma pack (1)
290
291typedef struct VBoxGuestCtrlHGCMMsgType
292{
293 VBoxGuestHGCMCallInfo hdr;
294
295 /**
296 * The returned command the host wants to
297 * run on the guest.
298 */
299 HGCMFunctionParameter msg; /* OUT uint32_t */
300 /** Number of parameters the message needs. */
301 HGCMFunctionParameter num_parms; /* OUT uint32_t */
302
303} VBoxGuestCtrlHGCMMsgType;
304
305/**
306 * Asks the guest control host service to cancel all pending (outstanding)
307 * waits which were not processed yet. This is handy for a graceful shutdown.
308 */
309typedef struct VBoxGuestCtrlHGCMMsgCancelPendingWaits
310{
311 VBoxGuestHGCMCallInfo hdr;
312} VBoxGuestCtrlHGCMMsgCancelPendingWaits;
313
314/**
315 * Executes a command inside the guest.
316 */
317typedef struct VBoxGuestCtrlHGCMMsgExecCmd
318{
319 VBoxGuestHGCMCallInfo hdr;
320 /** Context ID. */
321 HGCMFunctionParameter context;
322 /** The command to execute on the guest. */
323 HGCMFunctionParameter cmd;
324 /** Execution flags (see IGuest::ExecuteProcessFlag_*). */
325 HGCMFunctionParameter flags;
326 /** Number of arguments. */
327 HGCMFunctionParameter num_args;
328 /** The actual arguments. */
329 HGCMFunctionParameter args;
330 /** Number of environment value pairs. */
331 HGCMFunctionParameter num_env;
332 /** Size (in bytes) of environment block, including terminating zeros. */
333 HGCMFunctionParameter cb_env;
334 /** The actual environment block. */
335 HGCMFunctionParameter env;
336 /** The user name to run the executed command under. */
337 HGCMFunctionParameter username;
338 /** The user's password. */
339 HGCMFunctionParameter password;
340 /** Timeout (in msec) which either specifies the
341 * overall lifetime of the process or how long it
342 * can take to bring the process up and running -
343 * (depends on the IGuest::ExecuteProcessFlag_*). */
344 HGCMFunctionParameter timeout;
345
346} VBoxGuestCtrlHGCMMsgExecCmd;
347
348/**
349 * Injects input to a previously executed process via stdin.
350 */
351typedef struct VBoxGuestCtrlHGCMMsgExecIn
352{
353 VBoxGuestHGCMCallInfo hdr;
354 /** Context ID. */
355 HGCMFunctionParameter context;
356 /** The process ID (PID) to send the input to. */
357 HGCMFunctionParameter pid;
358 /** Input flags (see IGuest::ProcessInputFlag_*). */
359 HGCMFunctionParameter flags;
360 /** Data buffer. */
361 HGCMFunctionParameter data;
362 /** Actual size of data (in bytes). */
363 HGCMFunctionParameter size;
364
365} VBoxGuestCtrlHGCMMsgExecIn;
366
367/**
368 * Retrieves ouptut from a previously executed process
369 * from stdout/stderr.
370 */
371typedef struct VBoxGuestCtrlHGCMMsgExecOut
372{
373 VBoxGuestHGCMCallInfo hdr;
374 /** Context ID. */
375 HGCMFunctionParameter context;
376 /** The process ID (PID). */
377 HGCMFunctionParameter pid;
378 /** The pipe handle ID (stdout/stderr). */
379 HGCMFunctionParameter handle;
380 /** Optional flags. */
381 HGCMFunctionParameter flags;
382 /** Data buffer. */
383 HGCMFunctionParameter data;
384
385} VBoxGuestCtrlHGCMMsgExecOut;
386
387/**
388 * Reports the current status of a (just) started
389 * or terminated process.
390 */
391typedef struct VBoxGuestCtrlHGCMMsgExecStatus
392{
393 VBoxGuestHGCMCallInfo hdr;
394 /** Context ID. */
395 HGCMFunctionParameter context;
396 /** The process ID (PID). */
397 HGCMFunctionParameter pid;
398 /** The process status. */
399 HGCMFunctionParameter status;
400 /** Optional flags (based on status). */
401 HGCMFunctionParameter flags;
402 /** Optional data buffer (not used atm). */
403 HGCMFunctionParameter data;
404
405} VBoxGuestCtrlHGCMMsgExecStatus;
406
407/**
408 * Reports back the status of data written to a process.
409 */
410typedef struct VBoxGuestCtrlHGCMMsgExecStatusIn
411{
412 VBoxGuestHGCMCallInfo hdr;
413 /** Context ID. */
414 HGCMFunctionParameter context;
415 /** The process ID (PID). */
416 HGCMFunctionParameter pid;
417 /** Status of the operation. */
418 HGCMFunctionParameter status;
419 /** Optional flags. */
420 HGCMFunctionParameter flags;
421 /** Data written. */
422 HGCMFunctionParameter written;
423
424} VBoxGuestCtrlHGCMMsgExecStatusIn;
425
426#pragma pack ()
427
428/**
429 * Structure for buffering execution requests in the host service.
430 */
431typedef struct VBoxGuestCtrlParamBuffer
432{
433 uint32_t uMsg;
434 uint32_t uParmCount;
435 PVBOXHGCMSVCPARM pParms;
436} VBOXGUESTCTRPARAMBUFFER;
437typedef VBOXGUESTCTRPARAMBUFFER *PVBOXGUESTCTRPARAMBUFFER;
438
439} /* namespace guestControl */
440
441#endif /* !___VBox_HostService_GuestControlService_h */
442
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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