VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestCtrl.cpp@ 44863

Last change on this file since 44863 was 44863, checked in by vboxsync, 12 years ago

GuestCtrl: Infrastructure changes for handling and executing dedicated guest sessions and protocol versioning (untested, work in progress).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.9 KB
Line 
1/* $Id: VBoxGuestR3LibGuestCtrl.cpp 44863 2013-02-28 12:18:17Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, guest control.
4 */
5
6/*
7 * Copyright (C) 2010-2013 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/string.h>
32#include <iprt/mem.h>
33#include <iprt/assert.h>
34#include <iprt/cpp/autores.h>
35#include <iprt/stdarg.h>
36#include <VBox/log.h>
37#include <VBox/HostServices/GuestControlSvc.h>
38
39#include "VBGLR3Internal.h"
40
41
42/*******************************************************************************
43* Structures and Typedefs *
44*******************************************************************************/
45
46using namespace guestControl;
47
48/**
49 * Connects to the guest control service.
50 *
51 * @returns VBox status code
52 * @param puClientId Where to put the client id on success. The client id
53 * must be passed to all the other calls to the service.
54 */
55VBGLR3DECL(int) VbglR3GuestCtrlConnect(uint32_t *puClientId)
56{
57 VBoxGuestHGCMConnectInfo Info;
58 Info.result = VERR_WRONG_ORDER;
59 Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
60 RT_ZERO(Info.Loc.u);
61 strcpy(Info.Loc.u.host.achName, "VBoxGuestControlSvc");
62 Info.u32ClientID = UINT32_MAX; /* try make valgrind shut up. */
63
64 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
65 if (RT_SUCCESS(rc))
66 {
67 rc = Info.result;
68 if (RT_SUCCESS(rc))
69 *puClientId = Info.u32ClientID;
70 }
71 return rc;
72}
73
74
75/**
76 * Disconnect from the guest control service.
77 *
78 * @returns VBox status code.
79 * @param uClientId The client id returned by VbglR3GuestCtrlConnect().
80 */
81VBGLR3DECL(int) VbglR3GuestCtrlDisconnect(uint32_t uClientId)
82{
83 VBoxGuestHGCMDisconnectInfo Info;
84 Info.result = VERR_WRONG_ORDER;
85 Info.u32ClientID = uClientId;
86
87 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
88 if (RT_SUCCESS(rc))
89 rc = Info.result;
90 return rc;
91}
92
93
94/**
95 * Waits until a new host message arrives.
96 * This will block until a message becomes available.
97 *
98 * @returns VBox status code.
99 * @param uClientId The client id returned by VbglR3GuestCtrlConnect().
100 * @param puMsg Where to store the message id.
101 * @param puNumParms Where to store the number of parameters which will be received
102 * in a second call to the host.
103 */
104VBGLR3DECL(int) VbglR3GuestCtrlMsgWaitFor(uint32_t uClientId, uint32_t *puMsg, uint32_t *puNumParms)
105{
106 AssertPtrReturn(puMsg, VERR_INVALID_POINTER);
107 AssertPtrReturn(puNumParms, VERR_INVALID_POINTER);
108
109 HGCMMsgCmdWaitFor Msg;
110
111 Msg.hdr.result = VERR_WRONG_ORDER;
112 Msg.hdr.u32ClientID = uClientId;
113 Msg.hdr.u32Function = GUEST_MSG_WAIT; /* Tell the host we want our next command. */
114 Msg.hdr.cParms = 2; /* Just peek for the next message! */
115
116 VbglHGCMParmUInt32Set(&Msg.msg, 0);
117 VbglHGCMParmUInt32Set(&Msg.num_parms, 0);
118
119 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
120 if (RT_SUCCESS(rc))
121 {
122 rc = VbglHGCMParmUInt32Get(&Msg.msg, puMsg);
123 if (RT_SUCCESS(rc))
124 rc = VbglHGCMParmUInt32Get(&Msg.num_parms, puNumParms);
125 if (RT_SUCCESS(rc))
126 rc = Msg.hdr.result;
127 /* Ok, so now we know what message type and how much parameters there are. */
128 }
129 return rc;
130}
131
132
133/**
134 * Asks the host guest control service to set a command filter to this
135 * client so that it only will receive certain commands in the future.
136 *
137 * @return IPRT status code.
138 * @param uClientId The client id returned by VbglR3GuestCtrlConnect().
139 * @param uFilterAdd Filter mask to add.
140 * @param uFilterRemove Filter mask to remove.
141 */
142VBGLR3DECL(int) VbglR3GuestCtrlMsgSetFilter(uint32_t uClientId,
143 uint32_t uFilterAdd, uint32_t uFilterRemove)
144{
145 HGCMMsgCmdSetFilter Msg;
146
147 Msg.hdr.result = VERR_WRONG_ORDER;
148 Msg.hdr.u32ClientID = uClientId;
149 Msg.hdr.u32Function = GUEST_MSG_FILTER; /* Tell the host we want to set a filter. */
150 Msg.hdr.cParms = 2;
151
152 VbglHGCMParmUInt32Set(&Msg.add, uFilterAdd);
153 VbglHGCMParmUInt32Set(&Msg.remove, uFilterRemove);
154
155 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
156 if (RT_SUCCESS(rc))
157 rc = Msg.hdr.result;
158 return rc;
159}
160
161
162/**
163 * Asks the host to cancel (release) all pending waits which were deferred.
164 *
165 * @returns VBox status code.
166 * @param uClientId The client id returned by VbglR3GuestCtrlConnect().
167 */
168VBGLR3DECL(int) VbglR3GuestCtrlCancelPendingWaits(uint32_t uClientId)
169{
170 HGCMMsgCancelPendingWaits Msg;
171
172 Msg.hdr.result = VERR_WRONG_ORDER;
173 Msg.hdr.u32ClientID = uClientId;
174 Msg.hdr.u32Function = GUEST_CANCEL_PENDING_WAITS;
175 Msg.hdr.cParms = 0;
176
177 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
178 if (RT_SUCCESS(rc))
179 {
180 int rc2 = Msg.hdr.result;
181 if (RT_FAILURE(rc2))
182 rc = rc2;
183 }
184 return rc;
185}
186
187
188VBGLR3DECL(int) VbglR3GuestCtrlSessionNotify(uint32_t uClientId, uint32_t uContext,
189 uint32_t uType, uint32_t uResult)
190{
191 HGCMMsgSessionNotify Msg;
192
193 Msg.hdr.result = VERR_WRONG_ORDER;
194 Msg.hdr.u32ClientID = uClientId;
195 Msg.hdr.u32Function = GUEST_SESSION_NOTIFY;
196 Msg.hdr.cParms = 3;
197
198 VbglHGCMParmUInt32Set(&Msg.context, uContext);
199 VbglHGCMParmUInt32Set(&Msg.type, uType);
200 VbglHGCMParmUInt32Set(&Msg.result, uResult);
201
202 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
203 if (RT_SUCCESS(rc))
204 {
205 int rc2 = Msg.hdr.result;
206 if (RT_FAILURE(rc2))
207 rc = rc2;
208 }
209 return rc;
210}
211
212
213/**
214 * Retrieves the request to create a new guest session.
215 *
216 * @return IPRT status code.
217 * @param pHostCtx Host context.
218 ** @todo Docs!
219 */
220VBGLR3DECL(int) VbglR3GuestCtrlSessionGetOpen(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
221 uint32_t *puProtocol,
222 char *pszUser, uint32_t cbUser,
223 char *pszPassword, uint32_t cbPassword,
224 char *pszDomain, uint32_t cbDomain,
225 uint32_t *puFlags, uint32_t *puSessionID)
226{
227 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
228 AssertReturn(pHostCtx->uNumParms == 6, VERR_INVALID_PARAMETER);
229
230 AssertPtrReturn(puProtocol, VERR_INVALID_POINTER);
231 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
232 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
233 AssertPtrReturn(pszDomain, VERR_INVALID_POINTER);
234 AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
235
236 HGCMMsgSessionOpen Msg;
237
238 Msg.hdr.result = VERR_WRONG_ORDER;
239 Msg.hdr.u32ClientID = pHostCtx->uClientID;
240 Msg.hdr.u32Function = GUEST_MSG_WAIT;
241 Msg.hdr.cParms = pHostCtx->uNumParms;
242
243 VbglHGCMParmUInt32Set(&Msg.context, 0);
244 VbglHGCMParmUInt32Set(&Msg.protocol, 0);
245 VbglHGCMParmPtrSet(&Msg.username, pszUser, cbUser);
246 VbglHGCMParmPtrSet(&Msg.password, pszPassword, cbPassword);
247 VbglHGCMParmPtrSet(&Msg.domain, pszDomain, cbDomain);
248 VbglHGCMParmUInt32Set(&Msg.flags, 0);
249
250 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
251 if (RT_SUCCESS(rc))
252 {
253 int rc2 = Msg.hdr.result;
254 if (RT_FAILURE(rc2))
255 {
256 rc = rc2;
257 }
258 else
259 {
260 Msg.context.GetUInt32(&pHostCtx->uContextID);
261 Msg.protocol.GetUInt32(puProtocol);
262 Msg.flags.GetUInt32(puFlags);
263
264 if (puSessionID)
265 *puSessionID = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pHostCtx->uContextID);
266 }
267 }
268
269 return rc;
270}
271
272
273/**
274 * Retrieves the request to terminate an existing guest session.
275 *
276 * @return IPRT status code.
277 * @param pHostCtx Host context.
278 ** @todo Docs!
279 */
280VBGLR3DECL(int) VbglR3GuestCtrlSessionGetClose(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puFlags, uint32_t *puSessionID)
281{
282 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
283 AssertReturn(pHostCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
284
285 AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
286
287 HGCMMsgSessionClose Msg;
288
289 Msg.hdr.result = VERR_WRONG_ORDER;
290 Msg.hdr.u32ClientID = pHostCtx->uClientID;
291 Msg.hdr.u32Function = GUEST_MSG_WAIT;
292 Msg.hdr.cParms = pHostCtx->uNumParms;
293
294 VbglHGCMParmUInt32Set(&Msg.context, 0);
295 VbglHGCMParmUInt32Set(&Msg.flags, 0);
296
297 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
298 if (RT_SUCCESS(rc))
299 {
300 int rc2 = Msg.hdr.result;
301 if (RT_FAILURE(rc2))
302 {
303 rc = rc2;
304 }
305 else
306 {
307 Msg.context.GetUInt32(&pHostCtx->uContextID);
308 Msg.flags.GetUInt32(puFlags);
309
310 if (puSessionID)
311 *puSessionID = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pHostCtx->uContextID);
312 }
313 }
314
315 return rc;
316}
317
318
319/**
320 * Allocates and gets host data, based on the message id.
321 *
322 * This will block until data becomes available.
323 *
324 * @returns VBox status code.
325 ** @todo Docs!
326 ** @todo Move the parameters in an own struct!
327 */
328VBGLR3DECL(int) VbglR3GuestCtrlProcGetStart(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
329 char *pszCmd, uint32_t cbCmd,
330 uint32_t *puFlags,
331 char *pszArgs, uint32_t cbArgs, uint32_t *pcArgs,
332 char *pszEnv, uint32_t *pcbEnv, uint32_t *pcEnvVars,
333 char *pszUser, uint32_t cbUser,
334 char *pszPassword, uint32_t cbPassword,
335 uint32_t *puTimeoutMS,
336 uint32_t *puPriority,
337 uint64_t *puAffinity, uint32_t cbAffinity, uint32_t *pcAffinity)
338{
339 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
340
341 AssertPtrReturn(pszCmd, VERR_INVALID_POINTER);
342 AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
343 AssertPtrReturn(pszArgs, VERR_INVALID_POINTER);
344 AssertPtrReturn(pcArgs, VERR_INVALID_POINTER);
345 AssertPtrReturn(pszEnv, VERR_INVALID_POINTER);
346 AssertPtrReturn(pcbEnv, VERR_INVALID_POINTER);
347 AssertPtrReturn(pcEnvVars, VERR_INVALID_POINTER);
348 AssertPtrReturn(puTimeoutMS, VERR_INVALID_POINTER);
349
350 HGCMMsgProcExec Msg;
351
352 Msg.hdr.result = VERR_WRONG_ORDER;
353 Msg.hdr.u32ClientID = pHostCtx->uClientID;
354 Msg.hdr.u32Function = GUEST_MSG_WAIT;
355 Msg.hdr.cParms = pHostCtx->uNumParms;
356
357 VbglHGCMParmUInt32Set(&Msg.context, 0);
358 VbglHGCMParmPtrSet(&Msg.cmd, pszCmd, cbCmd);
359 VbglHGCMParmUInt32Set(&Msg.flags, 0);
360 VbglHGCMParmUInt32Set(&Msg.num_args, 0);
361 VbglHGCMParmPtrSet(&Msg.args, pszArgs, cbArgs);
362 VbglHGCMParmUInt32Set(&Msg.num_env, 0);
363 VbglHGCMParmUInt32Set(&Msg.cb_env, 0);
364 VbglHGCMParmPtrSet(&Msg.env, pszEnv, *pcbEnv);
365 if (pHostCtx->uProtocol < 2)
366 {
367 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
368 AssertReturn(cbUser, VERR_INVALID_PARAMETER);
369 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
370 AssertReturn(pszPassword, VERR_INVALID_PARAMETER);
371
372 VbglHGCMParmPtrSet(&Msg.u.v1.username, pszUser, cbUser);
373 VbglHGCMParmPtrSet(&Msg.u.v1.password, pszPassword, cbPassword);
374 VbglHGCMParmUInt32Set(&Msg.u.v1.timeout, 0);
375 }
376 else
377 {
378 AssertPtrReturn(puAffinity, VERR_INVALID_POINTER);
379 AssertReturn(cbAffinity, VERR_INVALID_PARAMETER);
380
381 VbglHGCMParmUInt32Set(&Msg.u.v2.timeout, 0);
382 VbglHGCMParmUInt32Set(&Msg.u.v2.priority, 0);
383 VbglHGCMParmUInt32Set(&Msg.u.v2.num_affinity, 0);
384 VbglHGCMParmPtrSet(&Msg.u.v2.affinity, puAffinity, cbAffinity);
385 }
386
387 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
388 if (RT_SUCCESS(rc))
389 {
390 int rc2 = Msg.hdr.result;
391 if (RT_FAILURE(rc2))
392 {
393 rc = rc2;
394 }
395 else
396 {
397 Msg.context.GetUInt32(&pHostCtx->uContextID);
398 Msg.flags.GetUInt32(puFlags);
399 Msg.num_args.GetUInt32(pcArgs);
400 Msg.num_env.GetUInt32(pcEnvVars);
401 Msg.cb_env.GetUInt32(pcbEnv);
402 if (pHostCtx->uProtocol < 2)
403 {
404 Msg.u.v1.timeout.GetUInt32(puTimeoutMS);
405 }
406 else
407 {
408 Msg.u.v2.timeout.GetUInt32(puTimeoutMS);
409 Msg.u.v2.priority.GetUInt32(puPriority);
410 Msg.u.v2.num_affinity.GetUInt32(pcAffinity);
411 }
412 }
413 }
414 return rc;
415}
416
417
418/**
419 * Allocates and gets host data, based on the message id.
420 *
421 * This will block until data becomes available.
422 *
423 * @returns VBox status code.
424 ** @todo Docs!
425 */
426VBGLR3DECL(int) VbglR3GuestCtrlProcGetOutput(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
427 uint32_t *puPID, uint32_t *puHandle, uint32_t *puFlags)
428{
429 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
430 AssertReturn(pHostCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
431
432 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
433 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
434 AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
435
436 HGCMMsgProcOutput Msg;
437
438 Msg.hdr.result = VERR_WRONG_ORDER;
439 Msg.hdr.u32ClientID = pHostCtx->uClientID;
440 Msg.hdr.u32Function = GUEST_MSG_WAIT;
441 Msg.hdr.cParms = pHostCtx->uNumParms;
442
443 VbglHGCMParmUInt32Set(&Msg.context, 0);
444 VbglHGCMParmUInt32Set(&Msg.pid, 0);
445 VbglHGCMParmUInt32Set(&Msg.handle, 0);
446 VbglHGCMParmUInt32Set(&Msg.flags, 0);
447
448 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
449 if (RT_SUCCESS(rc))
450 {
451 int rc2 = Msg.hdr.result;
452 if (RT_FAILURE(rc2))
453 {
454 rc = rc2;
455 }
456 else
457 {
458 Msg.context.GetUInt32(&pHostCtx->uContextID);
459 Msg.pid.GetUInt32(puPID);
460 Msg.handle.GetUInt32(puHandle);
461 Msg.flags.GetUInt32(puFlags);
462 }
463 }
464 return rc;
465}
466
467
468/**
469 * Retrieves the input data from host which then gets sent to the
470 * started process.
471 *
472 * This will block until data becomes available.
473 *
474 * @returns VBox status code.
475 ** @todo Docs!
476 */
477VBGLR3DECL(int) VbglR3GuestCtrlProcGetInput(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
478 uint32_t *puPID, uint32_t *puFlags,
479 void *pvData, uint32_t cbData,
480 uint32_t *pcbSize)
481{
482 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
483 AssertReturn(pHostCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
484
485 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
486 AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
487 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
488 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
489
490 HGCMMsgProcInput Msg;
491
492 Msg.hdr.result = VERR_WRONG_ORDER;
493 Msg.hdr.u32ClientID = pHostCtx->uClientID;
494 Msg.hdr.u32Function = GUEST_MSG_WAIT;
495 Msg.hdr.cParms = pHostCtx->uNumParms;
496
497 VbglHGCMParmUInt32Set(&Msg.context, 0);
498 VbglHGCMParmUInt32Set(&Msg.pid, 0);
499 VbglHGCMParmUInt32Set(&Msg.flags, 0);
500 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
501 VbglHGCMParmUInt32Set(&Msg.size, 0);
502
503 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
504 if (RT_SUCCESS(rc))
505 {
506 int rc2 = Msg.hdr.result;
507 if (RT_FAILURE(rc2))
508 {
509 rc = rc2;
510 }
511 else
512 {
513 Msg.context.GetUInt32(&pHostCtx->uContextID);
514 Msg.pid.GetUInt32(puPID);
515 Msg.flags.GetUInt32(puFlags);
516 Msg.size.GetUInt32(pcbSize);
517 }
518 }
519 return rc;
520}
521
522
523VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
524 char *pszFileName, uint32_t cbFileName,
525 char *pszOpenMode, uint32_t cbOpenMode,
526 char *pszDisposition, uint32_t cbDisposition,
527 uint32_t *puCreationMode,
528 uint64_t *puOffset)
529{
530 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
531 AssertReturn(pHostCtx->uNumParms == 6, VERR_INVALID_PARAMETER);
532
533 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
534 AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
535 AssertPtrReturn(pszOpenMode, VERR_INVALID_POINTER);
536 AssertReturn(cbOpenMode, VERR_INVALID_PARAMETER);
537 AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER);
538 AssertReturn(cbDisposition, VERR_INVALID_PARAMETER);
539 AssertPtrReturn(puCreationMode, VERR_INVALID_POINTER);
540 AssertPtrReturn(puOffset, VERR_INVALID_POINTER);
541
542 HGCMMsgFileOpen Msg;
543
544 Msg.hdr.result = VERR_WRONG_ORDER;
545 Msg.hdr.u32ClientID = pHostCtx->uClientID;
546 Msg.hdr.u32Function = GUEST_MSG_WAIT;
547 Msg.hdr.cParms = pHostCtx->uNumParms;
548
549 VbglHGCMParmUInt32Set(&Msg.context, 0);
550 VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
551 VbglHGCMParmPtrSet(&Msg.openmode, pszOpenMode, cbOpenMode);
552 VbglHGCMParmPtrSet(&Msg.disposition, pszDisposition, cbDisposition);
553 VbglHGCMParmUInt32Set(&Msg.creationmode, 0);
554 VbglHGCMParmUInt64Set(&Msg.offset, 0);
555
556 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
557 if (RT_SUCCESS(rc))
558 {
559 int rc2 = Msg.hdr.result;
560 if (RT_FAILURE(rc2))
561 {
562 rc = rc2;
563 }
564 else
565 {
566 Msg.context.GetUInt32(&pHostCtx->uContextID);
567 Msg.creationmode.GetUInt32(puCreationMode);
568 Msg.offset.GetUInt64(puOffset);
569 }
570 }
571 return rc;
572}
573
574
575VBGLR3DECL(int) VbglR3GuestCtrlFileGetClose(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puHandle)
576{
577 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
578
579 AssertReturn(pHostCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
580 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
581
582 HGCMMsgFileClose Msg;
583
584 Msg.hdr.result = VERR_WRONG_ORDER;
585 Msg.hdr.u32ClientID = pHostCtx->uClientID;
586 Msg.hdr.u32Function = GUEST_MSG_WAIT;
587 Msg.hdr.cParms = pHostCtx->uNumParms;
588
589 VbglHGCMParmUInt32Set(&Msg.context, 0);
590 VbglHGCMParmUInt32Set(&Msg.handle, 0);
591
592 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
593 if (RT_SUCCESS(rc))
594 {
595 int rc2 = Msg.hdr.result;
596 if (RT_FAILURE(rc2))
597 {
598 rc = rc2;
599 }
600 else
601 {
602 Msg.context.GetUInt32(&pHostCtx->uContextID);
603 Msg.handle.GetUInt32(puHandle);
604 }
605 }
606 return rc;
607}
608
609
610VBGLR3DECL(int) VbglR3GuestCtrlFileGetRead(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
611 uint32_t *puHandle, uint32_t *puToRead)
612{
613 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
614
615 AssertReturn(pHostCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
616 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
617 AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
618
619 HGCMMsgFileRead Msg;
620
621 Msg.hdr.result = VERR_WRONG_ORDER;
622 Msg.hdr.u32ClientID = pHostCtx->uClientID;
623 Msg.hdr.u32Function = GUEST_MSG_WAIT;
624 Msg.hdr.cParms = pHostCtx->uNumParms;
625
626 VbglHGCMParmUInt32Set(&Msg.context, 0);
627 VbglHGCMParmUInt32Set(&Msg.handle, 0);
628 VbglHGCMParmUInt32Set(&Msg.size, 0);
629
630 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
631 if (RT_SUCCESS(rc))
632 {
633 int rc2 = Msg.hdr.result;
634 if (RT_FAILURE(rc2))
635 {
636 rc = rc2;
637 }
638 else
639 {
640 Msg.context.GetUInt32(&pHostCtx->uContextID);
641 Msg.handle.GetUInt32(puHandle);
642 Msg.size.GetUInt32(puToRead);
643 }
644 }
645 return rc;
646}
647
648
649VBGLR3DECL(int) VbglR3GuestCtrlFileGetReadAt(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
650 uint32_t *puHandle, uint32_t *puToRead, uint64_t *puOffset)
651{
652 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
653
654 AssertReturn(pHostCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
655 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
656 AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
657
658 HGCMMsgFileRead Msg;
659
660 Msg.hdr.result = VERR_WRONG_ORDER;
661 Msg.hdr.u32ClientID = pHostCtx->uClientID;
662 Msg.hdr.u32Function = GUEST_MSG_WAIT;
663 Msg.hdr.cParms = pHostCtx->uNumParms;
664
665 VbglHGCMParmUInt32Set(&Msg.context, 0);
666 VbglHGCMParmUInt32Set(&Msg.handle, 0);
667 VbglHGCMParmUInt32Set(&Msg.size, 0);
668
669 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
670 if (RT_SUCCESS(rc))
671 {
672 int rc2 = Msg.hdr.result;
673 if (RT_FAILURE(rc2))
674 {
675 rc = rc2;
676 }
677 else
678 {
679 Msg.context.GetUInt32(&pHostCtx->uContextID);
680 Msg.handle.GetUInt32(puHandle);
681 Msg.size.GetUInt32(puToRead);
682 }
683 }
684 return rc;
685}
686
687
688VBGLR3DECL(int) VbglR3GuestCtrlFileGetWrite(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puHandle,
689 void *pvData, uint32_t cbData, uint32_t *pcbSize)
690{
691 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
692
693 AssertReturn(pHostCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
694 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
695 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
696 AssertReturn(cbData, VERR_INVALID_PARAMETER);
697 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
698
699 HGCMMsgFileWrite Msg;
700
701 Msg.hdr.result = VERR_WRONG_ORDER;
702 Msg.hdr.u32ClientID = pHostCtx->uClientID;
703 Msg.hdr.u32Function = GUEST_MSG_WAIT;
704 Msg.hdr.cParms = pHostCtx->uNumParms;
705
706 VbglHGCMParmUInt32Set(&Msg.context, 0);
707 VbglHGCMParmUInt32Set(&Msg.handle, 0);
708 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
709 VbglHGCMParmUInt32Set(&Msg.size, 0);
710
711 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
712 if (RT_SUCCESS(rc))
713 {
714 int rc2 = Msg.hdr.result;
715 if (RT_FAILURE(rc2))
716 {
717 rc = rc2;
718 }
719 else
720 {
721 Msg.context.GetUInt32(&pHostCtx->uContextID);
722 Msg.handle.GetUInt32(puHandle);
723 Msg.size.GetUInt32(pcbSize);
724 }
725 }
726 return rc;
727}
728
729
730VBGLR3DECL(int) VbglR3GuestCtrlFileGetWriteAt(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puHandle,
731 void *pvData, uint32_t cbData, uint32_t *pcbSize, uint64_t *puOffset)
732{
733 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
734
735 AssertReturn(pHostCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
736 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
737 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
738 AssertReturn(cbData, VERR_INVALID_PARAMETER);
739 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
740
741 HGCMMsgFileWriteAt Msg;
742
743 Msg.hdr.result = VERR_WRONG_ORDER;
744 Msg.hdr.u32ClientID = pHostCtx->uClientID;
745 Msg.hdr.u32Function = GUEST_MSG_WAIT;
746 Msg.hdr.cParms = pHostCtx->uNumParms;
747
748 VbglHGCMParmUInt32Set(&Msg.context, 0);
749 VbglHGCMParmUInt32Set(&Msg.handle, 0);
750 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
751 VbglHGCMParmUInt32Set(&Msg.size, 0);
752 VbglHGCMParmUInt32Set(&Msg.offset, 0);
753
754 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
755 if (RT_SUCCESS(rc))
756 {
757 int rc2 = Msg.hdr.result;
758 if (RT_FAILURE(rc2))
759 {
760 rc = rc2;
761 }
762 else
763 {
764 Msg.context.GetUInt32(&pHostCtx->uContextID);
765 Msg.handle.GetUInt32(puHandle);
766 Msg.size.GetUInt32(pcbSize);
767 }
768 }
769 return rc;
770}
771
772
773VBGLR3DECL(int) VbglR3GuestCtrlFileGetSeek(PVBGLR3GUESTCTRLHOSTCTX pHostCtx,
774 uint32_t *puHandle, uint32_t *puSeekMethod, uint64_t *puOffset)
775{
776 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
777
778 AssertReturn(pHostCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
779 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
780 AssertPtrReturn(puSeekMethod, VERR_INVALID_POINTER);
781 AssertPtrReturn(puOffset, VERR_INVALID_POINTER);
782
783 HGCMMsgFileSeek Msg;
784
785 Msg.hdr.result = VERR_WRONG_ORDER;
786 Msg.hdr.u32ClientID = pHostCtx->uClientID;
787 Msg.hdr.u32Function = GUEST_MSG_WAIT;
788 Msg.hdr.cParms = pHostCtx->uNumParms;
789
790 VbglHGCMParmUInt32Set(&Msg.context, 0);
791 VbglHGCMParmUInt32Set(&Msg.handle, 0);
792 VbglHGCMParmUInt32Set(&Msg.method, 0);
793 VbglHGCMParmUInt64Set(&Msg.offset, 0);
794
795 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
796 if (RT_SUCCESS(rc))
797 {
798 int rc2 = Msg.hdr.result;
799 if (RT_FAILURE(rc2))
800 {
801 rc = rc2;
802 }
803 else
804 {
805 Msg.context.GetUInt32(&pHostCtx->uContextID);
806 Msg.handle.GetUInt32(puHandle);
807 Msg.method.GetUInt32(puSeekMethod);
808 Msg.offset.GetUInt64(puOffset);
809 }
810 }
811 return rc;
812}
813
814
815VBGLR3DECL(int) VbglR3GuestCtrlFileGetTell(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puHandle)
816{
817 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
818
819 AssertReturn(pHostCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
820 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
821
822 HGCMMsgFileTell Msg;
823
824 Msg.hdr.result = VERR_WRONG_ORDER;
825 Msg.hdr.u32ClientID = pHostCtx->uClientID;
826 Msg.hdr.u32Function = GUEST_MSG_WAIT;
827 Msg.hdr.cParms = pHostCtx->uNumParms;
828
829 VbglHGCMParmUInt32Set(&Msg.context, 0);
830 VbglHGCMParmUInt32Set(&Msg.handle, 0);
831
832 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
833 if (RT_SUCCESS(rc))
834 {
835 int rc2 = Msg.hdr.result;
836 if (RT_FAILURE(rc2))
837 {
838 rc = rc2;
839 }
840 else
841 {
842 Msg.context.GetUInt32(&pHostCtx->uContextID);
843 Msg.handle.GetUInt32(puHandle);
844 }
845 }
846 return rc;
847}
848
849
850VBGLR3DECL(int) VbglR3GuestCtrlProcGetTerminate(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puPID)
851{
852 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
853
854 AssertReturn(pHostCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
855 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
856
857 HGCMMsgProcTerminate Msg;
858
859 Msg.hdr.result = VERR_WRONG_ORDER;
860 Msg.hdr.u32ClientID = pHostCtx->uClientID;
861 Msg.hdr.u32Function = GUEST_MSG_WAIT;
862 Msg.hdr.cParms = pHostCtx->uNumParms;
863
864 VbglHGCMParmUInt32Set(&Msg.context, 0);
865 VbglHGCMParmUInt32Set(&Msg.pid, 0);
866
867 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
868 if (RT_SUCCESS(rc))
869 {
870 int rc2 = Msg.hdr.result;
871 if (RT_FAILURE(rc2))
872 {
873 rc = rc2;
874 }
875 else
876 {
877 Msg.context.GetUInt32(&pHostCtx->uContextID);
878 Msg.pid.GetUInt32(puPID);
879 }
880 }
881 return rc;
882}
883
884
885VBGLR3DECL(int) VbglR3GuestCtrlProcGetWaitFor(PVBGLR3GUESTCTRLHOSTCTX pHostCtx, uint32_t *puPID, uint32_t *puWaitFlags, uint32_t *puTimeoutMS)
886{
887 AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
888
889 AssertReturn(pHostCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
890 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
891
892 HGCMMsgProcWaitFor Msg;
893
894 Msg.hdr.result = VERR_WRONG_ORDER;
895 Msg.hdr.u32ClientID = pHostCtx->uClientID;
896 Msg.hdr.u32Function = GUEST_MSG_WAIT;
897 Msg.hdr.cParms = pHostCtx->uNumParms;
898
899 VbglHGCMParmUInt32Set(&Msg.context, 0);
900 VbglHGCMParmUInt32Set(&Msg.pid, 0);
901 VbglHGCMParmUInt32Set(&Msg.flags, 0);
902 VbglHGCMParmUInt32Set(&Msg.timeout, 0);
903
904 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
905 if (RT_SUCCESS(rc))
906 {
907 int rc2 = Msg.hdr.result;
908 if (RT_FAILURE(rc2))
909 {
910 rc = rc2;
911 }
912 else
913 {
914 Msg.context.GetUInt32(&pHostCtx->uContextID);
915 Msg.pid.GetUInt32(puPID);
916 Msg.flags.GetUInt32(puWaitFlags);
917 Msg.timeout.GetUInt32(puTimeoutMS);
918 }
919 }
920 return rc;
921}
922
923
924VBGLR3DECL(int) VbglR3GuestCtrlFileNotify(uint32_t uClientId, uint32_t uContext,
925 uint32_t uType,
926 void *pvPayload, uint32_t cbPayload)
927{
928 AssertPtrReturn(uContext, VERR_INVALID_POINTER);
929 AssertPtrReturn(pvPayload, VERR_INVALID_POINTER);
930 AssertReturn(cbPayload, VERR_INVALID_PARAMETER);
931
932 HGCMMsgFileNotify Msg;
933
934 Msg.hdr.result = VERR_WRONG_ORDER;
935 Msg.hdr.u32ClientID = uClientId;
936 //Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
937 Msg.hdr.cParms = 3;
938
939 VbglHGCMParmUInt32Set(&Msg.context, uContext);
940 VbglHGCMParmUInt32Set(&Msg.type, uType);
941 VbglHGCMParmPtrSet(&Msg.payload, pvPayload, cbPayload);
942
943 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
944 if (RT_SUCCESS(rc))
945 {
946 int rc2 = Msg.hdr.result;
947 if (RT_FAILURE(rc2))
948 rc = rc2;
949 }
950 return rc;
951}
952
953
954/**
955 * Callback for reporting a guest process status (along with some other stuff) to the host.
956 *
957 * @returns VBox status code.
958 ** @todo Docs!
959 */
960VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatus(uint32_t u32ClientID,
961 uint32_t u32Context,
962 uint32_t u32PID,
963 uint32_t u32Status,
964 uint32_t u32Flags,
965 void *pvData,
966 uint32_t cbData)
967{
968 HGCMMsgProcStatus Msg;
969
970 Msg.hdr.result = VERR_WRONG_ORDER;
971 Msg.hdr.u32ClientID = u32ClientID;
972 Msg.hdr.u32Function = GUEST_EXEC_STATUS;
973 Msg.hdr.cParms = 5;
974
975 VbglHGCMParmUInt32Set(&Msg.context, u32Context);
976 VbglHGCMParmUInt32Set(&Msg.pid, u32PID);
977 VbglHGCMParmUInt32Set(&Msg.status, u32Status);
978 VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
979 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
980
981 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
982 if (RT_SUCCESS(rc))
983 {
984 int rc2 = Msg.hdr.result;
985 if (RT_FAILURE(rc2))
986 rc = rc2;
987 }
988 return rc;
989}
990
991
992/**
993 * Sends output (from stdout/stderr) from a running process.
994 *
995 * @returns VBox status code.
996 ** @todo Docs!
997 */
998VBGLR3DECL(int) VbglR3GuestCtrlProcCbOutput(uint32_t u32ClientID,
999 uint32_t u32Context,
1000 uint32_t u32PID,
1001 uint32_t u32Handle,
1002 uint32_t u32Flags,
1003 void *pvData,
1004 uint32_t cbData)
1005{
1006 HGCMMsgProcOutput Msg;
1007
1008 Msg.hdr.result = VERR_WRONG_ORDER;
1009 Msg.hdr.u32ClientID = u32ClientID;
1010 Msg.hdr.u32Function = GUEST_EXEC_OUTPUT;
1011 Msg.hdr.cParms = 5;
1012
1013 VbglHGCMParmUInt32Set(&Msg.context, u32Context);
1014 VbglHGCMParmUInt32Set(&Msg.pid, u32PID);
1015 VbglHGCMParmUInt32Set(&Msg.handle, u32Handle);
1016 VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
1017 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
1018
1019 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1020 if (RT_SUCCESS(rc))
1021 {
1022 int rc2 = Msg.hdr.result;
1023 if (RT_FAILURE(rc2))
1024 rc = rc2;
1025 }
1026 return rc;
1027}
1028
1029
1030/**
1031 * Callback for reporting back the input status of a guest process to the host.
1032 *
1033 * @returns VBox status code.
1034 ** @todo Docs!
1035 */
1036VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatusInput(uint32_t u32ClientID,
1037 uint32_t u32Context,
1038 uint32_t u32PID,
1039 uint32_t u32Status,
1040 uint32_t u32Flags,
1041 uint32_t cbWritten)
1042{
1043 HGCMMsgProcStatusInput Msg;
1044
1045 Msg.hdr.result = VERR_WRONG_ORDER;
1046 Msg.hdr.u32ClientID = u32ClientID;
1047 Msg.hdr.u32Function = GUEST_EXEC_INPUT_STATUS;
1048 Msg.hdr.cParms = 5;
1049
1050 VbglHGCMParmUInt32Set(&Msg.context, u32Context);
1051 VbglHGCMParmUInt32Set(&Msg.pid, u32PID);
1052 VbglHGCMParmUInt32Set(&Msg.status, u32Status);
1053 VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
1054 VbglHGCMParmUInt32Set(&Msg.written, cbWritten);
1055
1056 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1057 if (RT_SUCCESS(rc))
1058 {
1059 int rc2 = Msg.hdr.result;
1060 if (RT_FAILURE(rc2))
1061 rc = rc2;
1062 }
1063 return rc;
1064}
1065
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