VirtualBox

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

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

VBoxGuestLib: Use common VbglR3HGCMConnect to connect.

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

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