VirtualBox

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

Last change on this file since 68458 was 68458, checked in by vboxsync, 7 years ago

Introducing macros for initializing the VBoxGuestHGCMCallInfo structure.

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