VirtualBox

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

Last change on this file since 62847 was 62847, checked in by vboxsync, 8 years ago

VbglR3GuestCtrlFileGetWriteAt: Fixed bug where the offset output parameter wasn't set, causing the caller (vgsvcGstCtrlSessionHandleFileWriteAt) to pass random stack garbage to RTFileWriteAt. (My guess is that we don't really use thie method, as we should've noticed this already.) New MSC warnings founds this problem.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.4 KB
Line 
1/* $Id: VBoxGuestR3LibGuestCtrl.cpp 62847 2016-08-01 21:27:18Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, guest control.
4 */
5
6/*
7 * Copyright (C) 2010-2016 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
41using namespace guestControl;
42
43
44/**
45 * Connects to the guest control service.
46 *
47 * @returns VBox status code
48 * @param puClientId Where to put The client ID on success. The client ID
49 * must be passed to all the other calls to the service.
50 */
51VBGLR3DECL(int) VbglR3GuestCtrlConnect(uint32_t *puClientId)
52{
53 VBoxGuestHGCMConnectInfo Info;
54 Info.result = VERR_WRONG_ORDER;
55 Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
56 RT_ZERO(Info.Loc.u);
57 strcpy(Info.Loc.u.host.achName, "VBoxGuestControlSvc");
58 Info.u32ClientID = UINT32_MAX; /* try make valgrind shut up. */
59
60 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
61 if (RT_SUCCESS(rc))
62 {
63 rc = Info.result;
64 if (RT_SUCCESS(rc))
65 *puClientId = Info.u32ClientID;
66 }
67 return rc;
68}
69
70
71/**
72 * Disconnect from the guest control service.
73 *
74 * @returns VBox status code.
75 * @param uClientId The client ID returned by VbglR3GuestCtrlConnect().
76 */
77VBGLR3DECL(int) VbglR3GuestCtrlDisconnect(uint32_t uClientId)
78{
79 VBoxGuestHGCMDisconnectInfo Info;
80 Info.result = VERR_WRONG_ORDER;
81 Info.u32ClientID = uClientId;
82
83 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
84 if (RT_SUCCESS(rc))
85 rc = Info.result;
86 return rc;
87}
88
89
90/**
91 * Waits until a new host message arrives.
92 * This will block until a message becomes available.
93 *
94 * @returns VBox status code.
95 * @param uClientId The client ID returned by VbglR3GuestCtrlConnect().
96 * @param puMsg Where to store the message id.
97 * @param puNumParms Where to store the number of parameters which will be received
98 * in a second call to the host.
99 */
100VBGLR3DECL(int) VbglR3GuestCtrlMsgWaitFor(uint32_t uClientId, uint32_t *puMsg, uint32_t *puNumParms)
101{
102 AssertPtrReturn(puMsg, VERR_INVALID_POINTER);
103 AssertPtrReturn(puNumParms, VERR_INVALID_POINTER);
104
105 HGCMMsgCmdWaitFor Msg;
106
107 Msg.hdr.result = VERR_WRONG_ORDER;
108 Msg.hdr.u32ClientID = uClientId;
109 Msg.hdr.u32Function = GUEST_MSG_WAIT; /* Tell the host we want our next command. */
110 Msg.hdr.cParms = 2; /* Just peek for the next message! */
111
112 VbglHGCMParmUInt32Set(&Msg.msg, 0);
113 VbglHGCMParmUInt32Set(&Msg.num_parms, 0);
114
115 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
116 if (RT_SUCCESS(rc))
117 {
118 rc = VbglHGCMParmUInt32Get(&Msg.msg, puMsg);
119 if (RT_SUCCESS(rc))
120 {
121 rc = VbglHGCMParmUInt32Get(&Msg.num_parms, puNumParms);
122 if (RT_SUCCESS(rc))
123 rc = Msg.hdr.result;
124 /* Ok, so now we know what message type and how much parameters there are. */
125 }
126 }
127 return rc;
128}
129
130
131/**
132 * Asks the host guest control service to set a command filter to this
133 * client so that it only will receive certain commands in the future.
134 * The filter(s) are a bitmask for the context IDs, served from the host.
135 *
136 * @return IPRT status code.
137 * @param uClientId The client ID returned by VbglR3GuestCtrlConnect().
138 * @param uValue The value to filter messages for.
139 * @param uMaskAdd Filter mask to add.
140 * @param uMaskRemove Filter mask to remove.
141 */
142VBGLR3DECL(int) VbglR3GuestCtrlMsgFilterSet(uint32_t uClientId, uint32_t uValue,
143 uint32_t uMaskAdd, uint32_t uMaskRemove)
144{
145 HGCMMsgCmdFilterSet Msg;
146
147 Msg.hdr.result = VERR_WRONG_ORDER;
148 Msg.hdr.u32ClientID = uClientId;
149 Msg.hdr.u32Function = GUEST_MSG_FILTER_SET; /* Tell the host we want to set a filter. */
150 Msg.hdr.cParms = 4;
151
152 VbglHGCMParmUInt32Set(&Msg.value, uValue);
153 VbglHGCMParmUInt32Set(&Msg.mask_add, uMaskAdd);
154 VbglHGCMParmUInt32Set(&Msg.mask_remove, uMaskRemove);
155 VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
156
157 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
158 if (RT_SUCCESS(rc))
159 rc = Msg.hdr.result;
160 return rc;
161}
162
163
164/**
165 * Disables a previously set message filter.
166 *
167 * @return IPRT status code.
168 * @param uClientId The client ID returned by VbglR3GuestCtrlConnect().
169 */
170VBGLR3DECL(int) VbglR3GuestCtrlMsgFilterUnset(uint32_t uClientId)
171{
172 HGCMMsgCmdFilterUnset Msg;
173
174 Msg.hdr.result = VERR_WRONG_ORDER;
175 Msg.hdr.u32ClientID = uClientId;
176 Msg.hdr.u32Function = GUEST_MSG_FILTER_UNSET; /* Tell the host we want to unset the filter. */
177 Msg.hdr.cParms = 1;
178
179 VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
180
181 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
182 if (RT_SUCCESS(rc))
183 rc = Msg.hdr.result;
184 return rc;
185}
186
187
188VBGLR3DECL(int) VbglR3GuestCtrlMsgReply(PVBGLR3GUESTCTRLCMDCTX pCtx,
189 int rc)
190{
191 return VbglR3GuestCtrlMsgReplyEx(pCtx, rc, 0 /* uType */,
192 NULL /* pvPayload */, 0 /* cbPayload */);
193}
194
195
196VBGLR3DECL(int) VbglR3GuestCtrlMsgReplyEx(PVBGLR3GUESTCTRLCMDCTX pCtx,
197 int rc, uint32_t uType,
198 void *pvPayload, uint32_t cbPayload)
199{
200 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
201 /* Everything else is optional. */
202
203 HGCMMsgCmdReply Msg;
204
205 Msg.hdr.result = VERR_WRONG_ORDER;
206 Msg.hdr.u32ClientID = pCtx->uClientID;
207 Msg.hdr.u32Function = GUEST_MSG_REPLY;
208 Msg.hdr.cParms = 4;
209
210 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
211 VbglHGCMParmUInt32Set(&Msg.rc, (uint32_t)rc); /* int vs. uint32_t */
212 VbglHGCMParmUInt32Set(&Msg.type, uType);
213 VbglHGCMParmPtrSet(&Msg.payload, pvPayload, cbPayload);
214
215 int rc2 = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
216 if (RT_SUCCESS(rc))
217 {
218 int rc3 = Msg.hdr.result;
219 if (RT_FAILURE(rc3))
220 rc2 = rc3;
221 }
222 return rc2;
223}
224
225
226/**
227 * Tells the host service to skip the current message returned by
228 * VbglR3GuestCtrlMsgWaitFor().
229 *
230 * @return IPRT status code.
231 * @param uClientId The client ID returned by VbglR3GuestCtrlConnect().
232 */
233VBGLR3DECL(int) VbglR3GuestCtrlMsgSkip(uint32_t uClientId)
234{
235 HGCMMsgCmdSkip Msg;
236
237 Msg.hdr.result = VERR_WRONG_ORDER;
238 Msg.hdr.u32ClientID = uClientId;
239 Msg.hdr.u32Function = GUEST_MSG_SKIP; /* Tell the host we want to skip
240 the current assigned command. */
241 Msg.hdr.cParms = 1;
242
243 VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
244
245 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
246 if (RT_SUCCESS(rc))
247 rc = Msg.hdr.result;
248
249 return rc;
250}
251
252
253/**
254 * Asks the host to cancel (release) all pending waits which were deferred.
255 *
256 * @returns VBox status code.
257 * @param uClientId The client ID returned by VbglR3GuestCtrlConnect().
258 */
259VBGLR3DECL(int) VbglR3GuestCtrlCancelPendingWaits(uint32_t uClientId)
260{
261 HGCMMsgCancelPendingWaits Msg;
262
263 Msg.hdr.result = VERR_WRONG_ORDER;
264 Msg.hdr.u32ClientID = uClientId;
265 Msg.hdr.u32Function = GUEST_CANCEL_PENDING_WAITS;
266 Msg.hdr.cParms = 0;
267
268 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
269 if (RT_SUCCESS(rc))
270 {
271 int rc2 = Msg.hdr.result;
272 if (RT_FAILURE(rc2))
273 rc = rc2;
274 }
275 return rc;
276}
277
278
279/**
280 * Asks a specific guest session to close.
281 *
282 * @return IPRT status code.
283 * @param pCtx Host context.
284 * @param fFlags Some kind of flag. Figure it out yourself.
285 ** @todo Docs!
286 */
287VBGLR3DECL(int) VbglR3GuestCtrlSessionClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t fFlags)
288{
289 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
290 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
291
292 HGCMMsgSessionClose Msg;
293
294 Msg.hdr.result = VERR_WRONG_ORDER;
295 Msg.hdr.u32ClientID = pCtx->uClientID;
296 Msg.hdr.u32Function = GUEST_SESSION_CLOSE;
297 Msg.hdr.cParms = pCtx->uNumParms;
298
299 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
300 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
301
302 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
303 if (RT_SUCCESS(rc))
304 {
305 int rc2 = Msg.hdr.result;
306 if (RT_FAILURE(rc2))
307 rc = rc2;
308 }
309
310 return rc;
311}
312
313
314VBGLR3DECL(int) VbglR3GuestCtrlSessionNotify(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uType, uint32_t uResult)
315{
316 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
317
318 HGCMMsgSessionNotify Msg;
319
320 Msg.hdr.result = VERR_WRONG_ORDER;
321 Msg.hdr.u32ClientID = pCtx->uClientID;
322 Msg.hdr.u32Function = GUEST_SESSION_NOTIFY;
323 Msg.hdr.cParms = 3;
324
325 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
326 VbglHGCMParmUInt32Set(&Msg.type, uType);
327 VbglHGCMParmUInt32Set(&Msg.result, uResult);
328
329 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
330 if (RT_SUCCESS(rc))
331 {
332 int rc2 = Msg.hdr.result;
333 if (RT_FAILURE(rc2))
334 rc = rc2;
335 }
336 return rc;
337}
338
339
340/**
341 * Retrieves the request to create a new guest session.
342 *
343 * @return IPRT status code.
344 ** @todo Docs!
345 */
346VBGLR3DECL(int) VbglR3GuestCtrlSessionGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
347 uint32_t *puProtocol,
348 char *pszUser, uint32_t cbUser,
349 char *pszPassword, uint32_t cbPassword,
350 char *pszDomain, uint32_t cbDomain,
351 uint32_t *pfFlags, uint32_t *pidSession)
352{
353 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
354 AssertReturn(pCtx->uNumParms == 6, VERR_INVALID_PARAMETER);
355
356 AssertPtrReturn(puProtocol, VERR_INVALID_POINTER);
357 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
358 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
359 AssertPtrReturn(pszDomain, VERR_INVALID_POINTER);
360 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
361
362 HGCMMsgSessionOpen Msg;
363
364 Msg.hdr.result = VERR_WRONG_ORDER;
365 Msg.hdr.u32ClientID = pCtx->uClientID;
366 Msg.hdr.u32Function = GUEST_MSG_WAIT;
367 Msg.hdr.cParms = pCtx->uNumParms;
368
369 VbglHGCMParmUInt32Set(&Msg.context, 0);
370 VbglHGCMParmUInt32Set(&Msg.protocol, 0);
371 VbglHGCMParmPtrSet(&Msg.username, pszUser, cbUser);
372 VbglHGCMParmPtrSet(&Msg.password, pszPassword, cbPassword);
373 VbglHGCMParmPtrSet(&Msg.domain, pszDomain, cbDomain);
374 VbglHGCMParmUInt32Set(&Msg.flags, 0);
375
376 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
377 if (RT_SUCCESS(rc))
378 {
379 int rc2 = Msg.hdr.result;
380 if (RT_FAILURE(rc2))
381 {
382 rc = rc2;
383 }
384 else
385 {
386 Msg.context.GetUInt32(&pCtx->uContextID);
387 Msg.protocol.GetUInt32(puProtocol);
388 Msg.flags.GetUInt32(pfFlags);
389
390 if (pidSession)
391 *pidSession = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtx->uContextID);
392 }
393 }
394
395 return rc;
396}
397
398
399/**
400 * Retrieves the request to terminate an existing guest session.
401 *
402 * @return IPRT status code.
403 ** @todo Docs!
404 */
405VBGLR3DECL(int) VbglR3GuestCtrlSessionGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *pfFlags, uint32_t *pidSession)
406{
407 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
408 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
409
410 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
411
412 HGCMMsgSessionClose Msg;
413
414 Msg.hdr.result = VERR_WRONG_ORDER;
415 Msg.hdr.u32ClientID = pCtx->uClientID;
416 Msg.hdr.u32Function = GUEST_MSG_WAIT;
417 Msg.hdr.cParms = pCtx->uNumParms;
418
419 VbglHGCMParmUInt32Set(&Msg.context, 0);
420 VbglHGCMParmUInt32Set(&Msg.flags, 0);
421
422 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
423 if (RT_SUCCESS(rc))
424 {
425 int rc2 = Msg.hdr.result;
426 if (RT_FAILURE(rc2))
427 {
428 rc = rc2;
429 }
430 else
431 {
432 Msg.context.GetUInt32(&pCtx->uContextID);
433 Msg.flags.GetUInt32(pfFlags);
434
435 if (pidSession)
436 *pidSession = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtx->uContextID);
437 }
438 }
439
440 return rc;
441}
442
443
444VBGLR3DECL(int) VbglR3GuestCtrlPathGetRename(PVBGLR3GUESTCTRLCMDCTX pCtx,
445 char *pszSource, uint32_t cbSource,
446 char *pszDest, uint32_t cbDest,
447 uint32_t *pfFlags)
448{
449 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
450 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
451
452 AssertPtrReturn(pszSource, VERR_INVALID_POINTER);
453 AssertReturn(cbSource, VERR_INVALID_PARAMETER);
454 AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
455 AssertReturn(cbDest, VERR_INVALID_PARAMETER);
456 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
457
458 HGCMMsgPathRename Msg;
459
460 Msg.hdr.result = VERR_WRONG_ORDER;
461 Msg.hdr.u32ClientID = pCtx->uClientID;
462 Msg.hdr.u32Function = GUEST_MSG_WAIT;
463 Msg.hdr.cParms = pCtx->uNumParms;
464
465 VbglHGCMParmUInt32Set(&Msg.context, 0);
466 VbglHGCMParmPtrSet(&Msg.source, pszSource, cbSource);
467 VbglHGCMParmPtrSet(&Msg.dest, pszDest, cbDest);
468 VbglHGCMParmUInt32Set(&Msg.flags, 0);
469
470 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
471 if (RT_SUCCESS(rc))
472 {
473 int rc2 = Msg.hdr.result;
474 if (RT_FAILURE(rc2))
475 {
476 rc = rc2;
477 }
478 else
479 {
480 Msg.context.GetUInt32(&pCtx->uContextID);
481 Msg.flags.GetUInt32(pfFlags);
482 }
483 }
484 return rc;
485}
486
487
488/**
489 * Allocates and gets host data, based on the message id.
490 *
491 * This will block until data becomes available.
492 *
493 * @returns VBox status code.
494 ** @todo Docs!
495 ** @todo Move the parameters in an own struct!
496 */
497VBGLR3DECL(int) VbglR3GuestCtrlProcGetStart(PVBGLR3GUESTCTRLCMDCTX pCtx,
498 char *pszCmd, uint32_t cbCmd,
499 uint32_t *pfFlags,
500 char *pszArgs, uint32_t cbArgs, uint32_t *pcArgs,
501 char *pszEnv, uint32_t *pcbEnv, uint32_t *pcEnvVars,
502 char *pszUser, uint32_t cbUser,
503 char *pszPassword, uint32_t cbPassword,
504 uint32_t *puTimeoutMS,
505 uint32_t *puPriority,
506 uint64_t *puAffinity, uint32_t cbAffinity, uint32_t *pcAffinity)
507{
508 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
509
510 AssertPtrReturn(pszCmd, VERR_INVALID_POINTER);
511 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
512 AssertPtrReturn(pszArgs, VERR_INVALID_POINTER);
513 AssertPtrReturn(pcArgs, VERR_INVALID_POINTER);
514 AssertPtrReturn(pszEnv, VERR_INVALID_POINTER);
515 AssertPtrReturn(pcbEnv, VERR_INVALID_POINTER);
516 AssertPtrReturn(pcEnvVars, VERR_INVALID_POINTER);
517 AssertPtrReturn(puTimeoutMS, VERR_INVALID_POINTER);
518
519 HGCMMsgProcExec Msg;
520
521 Msg.hdr.result = VERR_WRONG_ORDER;
522 Msg.hdr.u32ClientID = pCtx->uClientID;
523 Msg.hdr.u32Function = GUEST_MSG_WAIT;
524 Msg.hdr.cParms = pCtx->uNumParms;
525
526 VbglHGCMParmUInt32Set(&Msg.context, 0);
527 VbglHGCMParmPtrSet(&Msg.cmd, pszCmd, cbCmd);
528 VbglHGCMParmUInt32Set(&Msg.flags, 0);
529 VbglHGCMParmUInt32Set(&Msg.num_args, 0);
530 VbglHGCMParmPtrSet(&Msg.args, pszArgs, cbArgs);
531 VbglHGCMParmUInt32Set(&Msg.num_env, 0);
532 VbglHGCMParmUInt32Set(&Msg.cb_env, 0);
533 VbglHGCMParmPtrSet(&Msg.env, pszEnv, *pcbEnv);
534 if (pCtx->uProtocol < 2)
535 {
536 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
537 AssertReturn(cbUser, VERR_INVALID_PARAMETER);
538 AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
539 AssertReturn(pszPassword, VERR_INVALID_PARAMETER);
540
541 VbglHGCMParmPtrSet(&Msg.u.v1.username, pszUser, cbUser);
542 VbglHGCMParmPtrSet(&Msg.u.v1.password, pszPassword, cbPassword);
543 VbglHGCMParmUInt32Set(&Msg.u.v1.timeout, 0);
544 }
545 else
546 {
547 AssertPtrReturn(puAffinity, VERR_INVALID_POINTER);
548 AssertReturn(cbAffinity, VERR_INVALID_PARAMETER);
549
550 VbglHGCMParmUInt32Set(&Msg.u.v2.timeout, 0);
551 VbglHGCMParmUInt32Set(&Msg.u.v2.priority, 0);
552 VbglHGCMParmUInt32Set(&Msg.u.v2.num_affinity, 0);
553 VbglHGCMParmPtrSet(&Msg.u.v2.affinity, puAffinity, cbAffinity);
554 }
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(&pCtx->uContextID);
567 Msg.flags.GetUInt32(pfFlags);
568 Msg.num_args.GetUInt32(pcArgs);
569 Msg.num_env.GetUInt32(pcEnvVars);
570 Msg.cb_env.GetUInt32(pcbEnv);
571 if (pCtx->uProtocol < 2)
572 {
573 Msg.u.v1.timeout.GetUInt32(puTimeoutMS);
574 }
575 else
576 {
577 Msg.u.v2.timeout.GetUInt32(puTimeoutMS);
578 Msg.u.v2.priority.GetUInt32(puPriority);
579 Msg.u.v2.num_affinity.GetUInt32(pcAffinity);
580 }
581 }
582 }
583 return rc;
584}
585
586
587/**
588 * Allocates and gets host data, based on the message id.
589 *
590 * This will block until data becomes available.
591 *
592 * @returns VBox status code.
593 ** @todo Docs!
594 */
595VBGLR3DECL(int) VbglR3GuestCtrlProcGetOutput(PVBGLR3GUESTCTRLCMDCTX pCtx,
596 uint32_t *puPID, uint32_t *puHandle, uint32_t *pfFlags)
597{
598 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
599 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
600
601 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
602 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
603 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
604
605 HGCMMsgProcOutput Msg;
606
607 Msg.hdr.result = VERR_WRONG_ORDER;
608 Msg.hdr.u32ClientID = pCtx->uClientID;
609 Msg.hdr.u32Function = GUEST_MSG_WAIT;
610 Msg.hdr.cParms = pCtx->uNumParms;
611
612 VbglHGCMParmUInt32Set(&Msg.context, 0);
613 VbglHGCMParmUInt32Set(&Msg.pid, 0);
614 VbglHGCMParmUInt32Set(&Msg.handle, 0);
615 VbglHGCMParmUInt32Set(&Msg.flags, 0);
616
617 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
618 if (RT_SUCCESS(rc))
619 {
620 int rc2 = Msg.hdr.result;
621 if (RT_FAILURE(rc2))
622 {
623 rc = rc2;
624 }
625 else
626 {
627 Msg.context.GetUInt32(&pCtx->uContextID);
628 Msg.pid.GetUInt32(puPID);
629 Msg.handle.GetUInt32(puHandle);
630 Msg.flags.GetUInt32(pfFlags);
631 }
632 }
633 return rc;
634}
635
636
637/**
638 * Retrieves the input data from host which then gets sent to the
639 * started process.
640 *
641 * This will block until data becomes available.
642 *
643 * @returns VBox status code.
644 ** @todo Docs!
645 */
646VBGLR3DECL(int) VbglR3GuestCtrlProcGetInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
647 uint32_t *puPID, uint32_t *pfFlags,
648 void *pvData, uint32_t cbData,
649 uint32_t *pcbSize)
650{
651 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
652 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
653
654 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
655 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
656 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
657 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
658
659 HGCMMsgProcInput Msg;
660
661 Msg.hdr.result = VERR_WRONG_ORDER;
662 Msg.hdr.u32ClientID = pCtx->uClientID;
663 Msg.hdr.u32Function = GUEST_MSG_WAIT;
664 Msg.hdr.cParms = pCtx->uNumParms;
665
666 VbglHGCMParmUInt32Set(&Msg.context, 0);
667 VbglHGCMParmUInt32Set(&Msg.pid, 0);
668 VbglHGCMParmUInt32Set(&Msg.flags, 0);
669 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
670 VbglHGCMParmUInt32Set(&Msg.size, 0);
671
672 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
673 if (RT_SUCCESS(rc))
674 {
675 int rc2 = Msg.hdr.result;
676 if (RT_FAILURE(rc2))
677 {
678 rc = rc2;
679 }
680 else
681 {
682 Msg.context.GetUInt32(&pCtx->uContextID);
683 Msg.pid.GetUInt32(puPID);
684 Msg.flags.GetUInt32(pfFlags);
685 Msg.size.GetUInt32(pcbSize);
686 }
687 }
688 return rc;
689}
690
691
692VBGLR3DECL(int) VbglR3GuestCtrlDirGetRemove(PVBGLR3GUESTCTRLCMDCTX pCtx,
693 char *pszPath, uint32_t cbPath,
694 uint32_t *pfFlags)
695{
696 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
697 AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
698
699 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
700 AssertReturn(cbPath, VERR_INVALID_PARAMETER);
701 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
702
703 HGCMMsgDirRemove Msg;
704
705 Msg.hdr.result = VERR_WRONG_ORDER;
706 Msg.hdr.u32ClientID = pCtx->uClientID;
707 Msg.hdr.u32Function = GUEST_MSG_WAIT;
708 Msg.hdr.cParms = pCtx->uNumParms;
709
710 VbglHGCMParmUInt32Set(&Msg.context, 0);
711 VbglHGCMParmPtrSet(&Msg.path, pszPath, cbPath);
712 VbglHGCMParmUInt32Set(&Msg.flags, 0);
713
714 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
715 if (RT_SUCCESS(rc))
716 {
717 int rc2 = Msg.hdr.result;
718 if (RT_FAILURE(rc2))
719 {
720 rc = rc2;
721 }
722 else
723 {
724 Msg.context.GetUInt32(&pCtx->uContextID);
725 Msg.flags.GetUInt32(pfFlags);
726 }
727 }
728 return rc;
729}
730
731
732VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
733 char *pszFileName, uint32_t cbFileName,
734 char *pszAccess, uint32_t cbAccess,
735 char *pszDisposition, uint32_t cbDisposition,
736 char *pszSharing, uint32_t cbSharing,
737 uint32_t *puCreationMode,
738 uint64_t *poffAt)
739{
740 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
741 AssertReturn(pCtx->uNumParms == 7, VERR_INVALID_PARAMETER);
742
743 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
744 AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
745 AssertPtrReturn(pszAccess, VERR_INVALID_POINTER);
746 AssertReturn(cbAccess, VERR_INVALID_PARAMETER);
747 AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER);
748 AssertReturn(cbDisposition, VERR_INVALID_PARAMETER);
749 AssertPtrReturn(pszSharing, VERR_INVALID_POINTER);
750 AssertReturn(cbSharing, VERR_INVALID_PARAMETER);
751 AssertPtrReturn(puCreationMode, VERR_INVALID_POINTER);
752 AssertPtrReturn(poffAt, VERR_INVALID_POINTER);
753
754 HGCMMsgFileOpen Msg;
755
756 Msg.hdr.result = VERR_WRONG_ORDER;
757 Msg.hdr.u32ClientID = pCtx->uClientID;
758 Msg.hdr.u32Function = GUEST_MSG_WAIT;
759 Msg.hdr.cParms = pCtx->uNumParms;
760
761 VbglHGCMParmUInt32Set(&Msg.context, 0);
762 VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
763 VbglHGCMParmPtrSet(&Msg.openmode, pszAccess, cbAccess);
764 VbglHGCMParmPtrSet(&Msg.disposition, pszDisposition, cbDisposition);
765 VbglHGCMParmPtrSet(&Msg.sharing, pszSharing, cbSharing);
766 VbglHGCMParmUInt32Set(&Msg.creationmode, 0);
767 VbglHGCMParmUInt64Set(&Msg.offset, 0);
768
769 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
770 if (RT_SUCCESS(rc))
771 {
772 int rc2 = Msg.hdr.result;
773 if (RT_FAILURE(rc2))
774 {
775 rc = rc2;
776 }
777 else
778 {
779 Msg.context.GetUInt32(&pCtx->uContextID);
780 Msg.creationmode.GetUInt32(puCreationMode);
781 Msg.offset.GetUInt64(poffAt);
782 }
783 }
784 return rc;
785}
786
787
788VBGLR3DECL(int) VbglR3GuestCtrlFileGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
789{
790 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
791
792 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
793 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
794
795 HGCMMsgFileClose Msg;
796
797 Msg.hdr.result = VERR_WRONG_ORDER;
798 Msg.hdr.u32ClientID = pCtx->uClientID;
799 Msg.hdr.u32Function = GUEST_MSG_WAIT;
800 Msg.hdr.cParms = pCtx->uNumParms;
801
802 VbglHGCMParmUInt32Set(&Msg.context, 0);
803 VbglHGCMParmUInt32Set(&Msg.handle, 0);
804
805 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
806 if (RT_SUCCESS(rc))
807 {
808 int rc2 = Msg.hdr.result;
809 if (RT_FAILURE(rc2))
810 {
811 rc = rc2;
812 }
813 else
814 {
815 Msg.context.GetUInt32(&pCtx->uContextID);
816 Msg.handle.GetUInt32(puHandle);
817 }
818 }
819 return rc;
820}
821
822
823VBGLR3DECL(int) VbglR3GuestCtrlFileGetRead(PVBGLR3GUESTCTRLCMDCTX pCtx,
824 uint32_t *puHandle, uint32_t *puToRead)
825{
826 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
827
828 AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
829 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
830 AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
831
832 HGCMMsgFileRead Msg;
833
834 Msg.hdr.result = VERR_WRONG_ORDER;
835 Msg.hdr.u32ClientID = pCtx->uClientID;
836 Msg.hdr.u32Function = GUEST_MSG_WAIT;
837 Msg.hdr.cParms = pCtx->uNumParms;
838
839 VbglHGCMParmUInt32Set(&Msg.context, 0);
840 VbglHGCMParmUInt32Set(&Msg.handle, 0);
841 VbglHGCMParmUInt32Set(&Msg.size, 0);
842
843 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
844 if (RT_SUCCESS(rc))
845 {
846 int rc2 = Msg.hdr.result;
847 if (RT_FAILURE(rc2))
848 {
849 rc = rc2;
850 }
851 else
852 {
853 Msg.context.GetUInt32(&pCtx->uContextID);
854 Msg.handle.GetUInt32(puHandle);
855 Msg.size.GetUInt32(puToRead);
856 }
857 }
858 return rc;
859}
860
861
862VBGLR3DECL(int) VbglR3GuestCtrlFileGetReadAt(PVBGLR3GUESTCTRLCMDCTX pCtx,
863 uint32_t *puHandle, uint32_t *puToRead, uint64_t *poffAt)
864{
865 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
866
867 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
868 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
869 AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
870
871 HGCMMsgFileReadAt Msg;
872
873 Msg.hdr.result = VERR_WRONG_ORDER;
874 Msg.hdr.u32ClientID = pCtx->uClientID;
875 Msg.hdr.u32Function = GUEST_MSG_WAIT;
876 Msg.hdr.cParms = pCtx->uNumParms;
877
878 VbglHGCMParmUInt32Set(&Msg.context, 0);
879 VbglHGCMParmUInt32Set(&Msg.handle, 0);
880 VbglHGCMParmUInt32Set(&Msg.offset, 0);
881 VbglHGCMParmUInt32Set(&Msg.size, 0);
882
883 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
884 if (RT_SUCCESS(rc))
885 {
886 int rc2 = Msg.hdr.result;
887 if (RT_FAILURE(rc2))
888 {
889 rc = rc2;
890 }
891 else
892 {
893 Msg.context.GetUInt32(&pCtx->uContextID);
894 Msg.handle.GetUInt32(puHandle);
895 Msg.offset.GetUInt64(poffAt);
896 Msg.size.GetUInt32(puToRead);
897 }
898 }
899 return rc;
900}
901
902
903VBGLR3DECL(int) VbglR3GuestCtrlFileGetWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle,
904 void *pvData, uint32_t cbData, uint32_t *pcbSize)
905{
906 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
907
908 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
909 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
910 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
911 AssertReturn(cbData, VERR_INVALID_PARAMETER);
912 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
913
914 HGCMMsgFileWrite Msg;
915
916 Msg.hdr.result = VERR_WRONG_ORDER;
917 Msg.hdr.u32ClientID = pCtx->uClientID;
918 Msg.hdr.u32Function = GUEST_MSG_WAIT;
919 Msg.hdr.cParms = pCtx->uNumParms;
920
921 VbglHGCMParmUInt32Set(&Msg.context, 0);
922 VbglHGCMParmUInt32Set(&Msg.handle, 0);
923 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
924 VbglHGCMParmUInt32Set(&Msg.size, 0);
925
926 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
927 if (RT_SUCCESS(rc))
928 {
929 int rc2 = Msg.hdr.result;
930 if (RT_FAILURE(rc2))
931 {
932 rc = rc2;
933 }
934 else
935 {
936 Msg.context.GetUInt32(&pCtx->uContextID);
937 Msg.handle.GetUInt32(puHandle);
938 Msg.size.GetUInt32(pcbSize);
939 }
940 }
941 return rc;
942}
943
944
945VBGLR3DECL(int) VbglR3GuestCtrlFileGetWriteAt(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle,
946 void *pvData, uint32_t cbData, uint32_t *pcbSize, uint64_t *poffAt)
947{
948 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
949
950 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
951 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
952 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
953 AssertReturn(cbData, VERR_INVALID_PARAMETER);
954 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
955
956 HGCMMsgFileWriteAt Msg;
957
958 Msg.hdr.result = VERR_WRONG_ORDER;
959 Msg.hdr.u32ClientID = pCtx->uClientID;
960 Msg.hdr.u32Function = GUEST_MSG_WAIT;
961 Msg.hdr.cParms = pCtx->uNumParms;
962
963 VbglHGCMParmUInt32Set(&Msg.context, 0);
964 VbglHGCMParmUInt32Set(&Msg.handle, 0);
965 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
966 VbglHGCMParmUInt32Set(&Msg.size, 0);
967 VbglHGCMParmUInt32Set(&Msg.offset, 0);
968
969 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
970 if (RT_SUCCESS(rc))
971 {
972 int rc2 = Msg.hdr.result;
973 if (RT_FAILURE(rc2))
974 {
975 rc = rc2;
976 }
977 else
978 {
979 Msg.context.GetUInt32(&pCtx->uContextID);
980 Msg.handle.GetUInt32(puHandle);
981 Msg.size.GetUInt32(pcbSize);
982 Msg.offset.GetUInt64(poffAt);
983 }
984 }
985 return rc;
986}
987
988
989VBGLR3DECL(int) VbglR3GuestCtrlFileGetSeek(PVBGLR3GUESTCTRLCMDCTX pCtx,
990 uint32_t *puHandle, uint32_t *puSeekMethod, uint64_t *poffAt)
991{
992 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
993
994 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
995 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
996 AssertPtrReturn(puSeekMethod, VERR_INVALID_POINTER);
997 AssertPtrReturn(poffAt, VERR_INVALID_POINTER);
998
999 HGCMMsgFileSeek Msg;
1000
1001 Msg.hdr.result = VERR_WRONG_ORDER;
1002 Msg.hdr.u32ClientID = pCtx->uClientID;
1003 Msg.hdr.u32Function = GUEST_MSG_WAIT;
1004 Msg.hdr.cParms = pCtx->uNumParms;
1005
1006 VbglHGCMParmUInt32Set(&Msg.context, 0);
1007 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1008 VbglHGCMParmUInt32Set(&Msg.method, 0);
1009 VbglHGCMParmUInt64Set(&Msg.offset, 0);
1010
1011 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1012 if (RT_SUCCESS(rc))
1013 {
1014 int rc2 = Msg.hdr.result;
1015 if (RT_FAILURE(rc2))
1016 {
1017 rc = rc2;
1018 }
1019 else
1020 {
1021 Msg.context.GetUInt32(&pCtx->uContextID);
1022 Msg.handle.GetUInt32(puHandle);
1023 Msg.method.GetUInt32(puSeekMethod);
1024 Msg.offset.GetUInt64(poffAt);
1025 }
1026 }
1027 return rc;
1028}
1029
1030
1031VBGLR3DECL(int) VbglR3GuestCtrlFileGetTell(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
1032{
1033 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1034
1035 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1036 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1037
1038 HGCMMsgFileTell Msg;
1039
1040 Msg.hdr.result = VERR_WRONG_ORDER;
1041 Msg.hdr.u32ClientID = pCtx->uClientID;
1042 Msg.hdr.u32Function = GUEST_MSG_WAIT;
1043 Msg.hdr.cParms = pCtx->uNumParms;
1044
1045 VbglHGCMParmUInt32Set(&Msg.context, 0);
1046 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1047
1048 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1049 if (RT_SUCCESS(rc))
1050 {
1051 int rc2 = Msg.hdr.result;
1052 if (RT_FAILURE(rc2))
1053 {
1054 rc = rc2;
1055 }
1056 else
1057 {
1058 Msg.context.GetUInt32(&pCtx->uContextID);
1059 Msg.handle.GetUInt32(puHandle);
1060 }
1061 }
1062 return rc;
1063}
1064
1065
1066VBGLR3DECL(int) VbglR3GuestCtrlProcGetTerminate(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puPID)
1067{
1068 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1069
1070 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1071 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
1072
1073 HGCMMsgProcTerminate Msg;
1074
1075 Msg.hdr.result = VERR_WRONG_ORDER;
1076 Msg.hdr.u32ClientID = pCtx->uClientID;
1077 Msg.hdr.u32Function = GUEST_MSG_WAIT;
1078 Msg.hdr.cParms = pCtx->uNumParms;
1079
1080 VbglHGCMParmUInt32Set(&Msg.context, 0);
1081 VbglHGCMParmUInt32Set(&Msg.pid, 0);
1082
1083 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1084 if (RT_SUCCESS(rc))
1085 {
1086 int rc2 = Msg.hdr.result;
1087 if (RT_FAILURE(rc2))
1088 {
1089 rc = rc2;
1090 }
1091 else
1092 {
1093 Msg.context.GetUInt32(&pCtx->uContextID);
1094 Msg.pid.GetUInt32(puPID);
1095 }
1096 }
1097 return rc;
1098}
1099
1100
1101VBGLR3DECL(int) VbglR3GuestCtrlProcGetWaitFor(PVBGLR3GUESTCTRLCMDCTX pCtx,
1102 uint32_t *puPID, uint32_t *puWaitFlags, uint32_t *puTimeoutMS)
1103{
1104 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1105
1106 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
1107 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
1108
1109 HGCMMsgProcWaitFor Msg;
1110
1111 Msg.hdr.result = VERR_WRONG_ORDER;
1112 Msg.hdr.u32ClientID = pCtx->uClientID;
1113 Msg.hdr.u32Function = GUEST_MSG_WAIT;
1114 Msg.hdr.cParms = pCtx->uNumParms;
1115
1116 VbglHGCMParmUInt32Set(&Msg.context, 0);
1117 VbglHGCMParmUInt32Set(&Msg.pid, 0);
1118 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1119 VbglHGCMParmUInt32Set(&Msg.timeout, 0);
1120
1121 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1122 if (RT_SUCCESS(rc))
1123 {
1124 int rc2 = Msg.hdr.result;
1125 if (RT_FAILURE(rc2))
1126 {
1127 rc = rc2;
1128 }
1129 else
1130 {
1131 Msg.context.GetUInt32(&pCtx->uContextID);
1132 Msg.pid.GetUInt32(puPID);
1133 Msg.flags.GetUInt32(puWaitFlags);
1134 Msg.timeout.GetUInt32(puTimeoutMS);
1135 }
1136 }
1137 return rc;
1138}
1139
1140
1141VBGLR3DECL(int) VbglR3GuestCtrlFileCbOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
1142 uint32_t uRc, uint32_t uFileHandle)
1143{
1144 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1145
1146 HGCMReplyFileNotify Msg;
1147
1148 Msg.hdr.result = VERR_WRONG_ORDER;
1149 Msg.hdr.u32ClientID = pCtx->uClientID;
1150 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1151 Msg.hdr.cParms = 4;
1152
1153 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1154 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_OPEN);
1155 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1156
1157 VbglHGCMParmUInt32Set(&Msg.u.open.handle, uFileHandle);
1158
1159 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1160 if (RT_SUCCESS(rc))
1161 {
1162 int rc2 = Msg.hdr.result;
1163 if (RT_FAILURE(rc2))
1164 rc = rc2;
1165 }
1166 return rc;
1167}
1168
1169
1170VBGLR3DECL(int) VbglR3GuestCtrlFileCbClose(PVBGLR3GUESTCTRLCMDCTX pCtx,
1171 uint32_t uRc)
1172{
1173 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1174
1175 HGCMReplyFileNotify Msg;
1176
1177 Msg.hdr.result = VERR_WRONG_ORDER;
1178 Msg.hdr.u32ClientID = pCtx->uClientID;
1179 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1180 Msg.hdr.cParms = 3;
1181
1182 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1183 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_CLOSE);
1184 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1185
1186 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1187 if (RT_SUCCESS(rc))
1188 {
1189 int rc2 = Msg.hdr.result;
1190 if (RT_FAILURE(rc2))
1191 rc = rc2;
1192 }
1193 return rc;
1194}
1195
1196
1197VBGLR3DECL(int) VbglR3GuestCtrlFileCbError(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc)
1198{
1199 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1200
1201 HGCMReplyFileNotify Msg;
1202
1203 Msg.hdr.result = VERR_WRONG_ORDER;
1204 Msg.hdr.u32ClientID = pCtx->uClientID;
1205 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1206 Msg.hdr.cParms = 3;
1207
1208 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1209 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_ERROR);
1210 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1211
1212 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1213 if (RT_SUCCESS(rc))
1214 {
1215 int rc2 = Msg.hdr.result;
1216 if (RT_FAILURE(rc2))
1217 rc = rc2;
1218 }
1219 return rc;
1220}
1221
1222
1223VBGLR3DECL(int) VbglR3GuestCtrlFileCbRead(PVBGLR3GUESTCTRLCMDCTX pCtx,
1224 uint32_t uRc,
1225 void *pvData, uint32_t cbData)
1226{
1227 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1228
1229 HGCMReplyFileNotify Msg;
1230
1231 Msg.hdr.result = VERR_WRONG_ORDER;
1232 Msg.hdr.u32ClientID = pCtx->uClientID;
1233 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1234 Msg.hdr.cParms = 4;
1235
1236 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1237 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_READ);
1238 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1239
1240 VbglHGCMParmPtrSet(&Msg.u.read.data, pvData, cbData);
1241
1242 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1243 if (RT_SUCCESS(rc))
1244 {
1245 int rc2 = Msg.hdr.result;
1246 if (RT_FAILURE(rc2))
1247 rc = rc2;
1248 }
1249 return rc;
1250}
1251
1252
1253VBGLR3DECL(int) VbglR3GuestCtrlFileCbWrite(PVBGLR3GUESTCTRLCMDCTX pCtx,
1254 uint32_t uRc, uint32_t uWritten)
1255{
1256 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1257
1258 HGCMReplyFileNotify Msg;
1259
1260 Msg.hdr.result = VERR_WRONG_ORDER;
1261 Msg.hdr.u32ClientID = pCtx->uClientID;
1262 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1263 Msg.hdr.cParms = 4;
1264
1265 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1266 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_WRITE);
1267 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1268
1269 VbglHGCMParmUInt32Set(&Msg.u.write.written, uWritten);
1270
1271 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1272 if (RT_SUCCESS(rc))
1273 {
1274 int rc2 = Msg.hdr.result;
1275 if (RT_FAILURE(rc2))
1276 rc = rc2;
1277 }
1278 return rc;
1279}
1280
1281
1282VBGLR3DECL(int) VbglR3GuestCtrlFileCbSeek(PVBGLR3GUESTCTRLCMDCTX pCtx,
1283 uint32_t uRc, uint64_t uOffActual)
1284{
1285 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1286
1287 HGCMReplyFileNotify Msg;
1288
1289 Msg.hdr.result = VERR_WRONG_ORDER;
1290 Msg.hdr.u32ClientID = pCtx->uClientID;
1291 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1292 Msg.hdr.cParms = 4;
1293
1294 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1295 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SEEK);
1296 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1297
1298 VbglHGCMParmUInt64Set(&Msg.u.seek.offset, uOffActual);
1299
1300 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1301 if (RT_SUCCESS(rc))
1302 {
1303 int rc2 = Msg.hdr.result;
1304 if (RT_FAILURE(rc2))
1305 rc = rc2;
1306 }
1307 return rc;
1308}
1309
1310
1311VBGLR3DECL(int) VbglR3GuestCtrlFileCbTell(PVBGLR3GUESTCTRLCMDCTX pCtx,
1312 uint32_t uRc, uint64_t uOffActual)
1313{
1314 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1315
1316 HGCMReplyFileNotify Msg;
1317
1318 Msg.hdr.result = VERR_WRONG_ORDER;
1319 Msg.hdr.u32ClientID = pCtx->uClientID;
1320 Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
1321 Msg.hdr.cParms = 4;
1322
1323 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1324 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_TELL);
1325 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
1326
1327 VbglHGCMParmUInt64Set(&Msg.u.tell.offset, uOffActual);
1328
1329 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1330 if (RT_SUCCESS(rc))
1331 {
1332 int rc2 = Msg.hdr.result;
1333 if (RT_FAILURE(rc2))
1334 rc = rc2;
1335 }
1336 return rc;
1337}
1338
1339
1340/**
1341 * Callback for reporting a guest process status (along with some other stuff) to the host.
1342 *
1343 * @returns VBox status code.
1344 ** @todo Docs!
1345 */
1346VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatus(PVBGLR3GUESTCTRLCMDCTX pCtx,
1347 uint32_t uPID, uint32_t uStatus, uint32_t fFlags,
1348 void *pvData, uint32_t cbData)
1349{
1350 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1351
1352 HGCMMsgProcStatus Msg;
1353
1354 Msg.hdr.result = VERR_WRONG_ORDER;
1355 Msg.hdr.u32ClientID = pCtx->uClientID;
1356 Msg.hdr.u32Function = GUEST_EXEC_STATUS;
1357 Msg.hdr.cParms = 5;
1358
1359 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1360 VbglHGCMParmUInt32Set(&Msg.pid, uPID);
1361 VbglHGCMParmUInt32Set(&Msg.status, uStatus);
1362 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
1363 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
1364
1365 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1366 if (RT_SUCCESS(rc))
1367 {
1368 int rc2 = Msg.hdr.result;
1369 if (RT_FAILURE(rc2))
1370 rc = rc2;
1371 }
1372 return rc;
1373}
1374
1375
1376/**
1377 * Sends output (from stdout/stderr) from a running process.
1378 *
1379 * @returns VBox status code.
1380 ** @todo Docs!
1381 */
1382VBGLR3DECL(int) VbglR3GuestCtrlProcCbOutput(PVBGLR3GUESTCTRLCMDCTX pCtx,
1383 uint32_t uPID,uint32_t uHandle, uint32_t fFlags,
1384 void *pvData, uint32_t cbData)
1385{
1386 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1387
1388 HGCMMsgProcOutput Msg;
1389
1390 Msg.hdr.result = VERR_WRONG_ORDER;
1391 Msg.hdr.u32ClientID = pCtx->uClientID;
1392 Msg.hdr.u32Function = GUEST_EXEC_OUTPUT;
1393 Msg.hdr.cParms = 5;
1394
1395 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1396 VbglHGCMParmUInt32Set(&Msg.pid, uPID);
1397 VbglHGCMParmUInt32Set(&Msg.handle, uHandle);
1398 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
1399 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
1400
1401 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1402 if (RT_SUCCESS(rc))
1403 {
1404 int rc2 = Msg.hdr.result;
1405 if (RT_FAILURE(rc2))
1406 rc = rc2;
1407 }
1408 return rc;
1409}
1410
1411
1412/**
1413 * Callback for reporting back the input status of a guest process to the host.
1414 *
1415 * @returns VBox status code.
1416 ** @todo Docs!
1417 */
1418VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatusInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
1419 uint32_t uPID, uint32_t uStatus,
1420 uint32_t fFlags, uint32_t cbWritten)
1421{
1422 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1423
1424 HGCMMsgProcStatusInput Msg;
1425
1426 Msg.hdr.result = VERR_WRONG_ORDER;
1427 Msg.hdr.u32ClientID = pCtx->uClientID;
1428 Msg.hdr.u32Function = GUEST_EXEC_INPUT_STATUS;
1429 Msg.hdr.cParms = 5;
1430
1431 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
1432 VbglHGCMParmUInt32Set(&Msg.pid, uPID);
1433 VbglHGCMParmUInt32Set(&Msg.status, uStatus);
1434 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
1435 VbglHGCMParmUInt32Set(&Msg.written, cbWritten);
1436
1437 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
1438 if (RT_SUCCESS(rc))
1439 {
1440 int rc2 = Msg.hdr.result;
1441 if (RT_FAILURE(rc2))
1442 rc = rc2;
1443 }
1444 return rc;
1445}
1446
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