VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp@ 98824

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

Guest Control: Made the directory entry reading really dynamic by letting the guest tell us the size it reports to the guest (limited by GSTCTL_DIRENTRY_MAX_SIZE). Re-introduced the #pragma pack(1) because we need the structures on mixed bitness (32 / 64 or vice versa) with the same size. bugref:9783

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 101.3 KB
 
1/* $Id: VBoxGuestR3LibGuestCtrl.cpp 98824 2023-03-02 17:06:36Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, guest control.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.alldomusa.eu.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/string.h>
42#include <iprt/mem.h>
43#include <iprt/assert.h>
44#include <iprt/cpp/autores.h>
45#include <iprt/stdarg.h>
46#include <VBox/err.h>
47#include <VBox/log.h>
48#include <VBox/GuestHost/GuestControl.h>
49#include <VBox/HostServices/GuestControlSvc.h>
50
51#ifndef RT_OS_WINDOWS
52# include <signal.h>
53# ifdef RT_OS_DARWIN
54# include <pthread.h>
55# define sigprocmask pthread_sigmask /* On xnu sigprocmask works on the process, not the calling thread as elsewhere. */
56# endif
57#endif
58
59#include "VBoxGuestR3LibInternal.h"
60
61using namespace guestControl;
62
63
64/*********************************************************************************************************************************
65* Global Variables *
66*********************************************************************************************************************************/
67/** Set if GUEST_MSG_PEEK_WAIT and friends are supported. */
68static int g_fVbglR3GuestCtrlHavePeekGetCancel = -1;
69
70
71/**
72 * Connects to the guest control service.
73 *
74 * @returns VBox status code
75 * @param pidClient Where to put The client ID on success. The client ID
76 * must be passed to all the other calls to the service.
77 */
78VBGLR3DECL(int) VbglR3GuestCtrlConnect(uint32_t *pidClient)
79{
80 return VbglR3HGCMConnect("VBoxGuestControlSvc", pidClient);
81}
82
83
84/**
85 * Disconnect from the guest control service.
86 *
87 * @returns VBox status code.
88 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
89 */
90VBGLR3DECL(int) VbglR3GuestCtrlDisconnect(uint32_t idClient)
91{
92 return VbglR3HGCMDisconnect(idClient);
93}
94
95
96/**
97 * Waits until a new host message arrives.
98 * This will block until a message becomes available.
99 *
100 * @returns VBox status code.
101 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
102 * @param pidMsg Where to store the message id.
103 * @param pcParameters Where to store the number of parameters which will
104 * be received in a second call to the host.
105 */
106static int vbglR3GuestCtrlMsgWaitFor(uint32_t idClient, uint32_t *pidMsg, uint32_t *pcParameters)
107{
108 AssertPtrReturn(pidMsg, VERR_INVALID_POINTER);
109 AssertPtrReturn(pcParameters, VERR_INVALID_POINTER);
110
111 HGCMMsgWaitFor Msg;
112 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient,
113 GUEST_MSG_WAIT, /* Tell the host we want our next message. */
114 2); /* Just peek for the next message! */
115 VbglHGCMParmUInt32Set(&Msg.msg, 0);
116 VbglHGCMParmUInt32Set(&Msg.num_parms, 0);
117
118 /*
119 * We should always get a VERR_TOO_MUCH_DATA response here, see
120 * guestControl::HostMessage::Peek() and its caller ClientState::SendReply().
121 * We accept success too here, in case someone decide to make the protocol
122 * slightly more sane.
123 *
124 * Note! A really sane protocol design would have a separate call for getting
125 * info about a pending message (returning VINF_SUCCESS), and a separate
126 * one for retriving the actual message parameters. Not this weird
127 * stuff, to put it rather bluntly.
128 *
129 * Note! As a result of this weird design, we are not able to correctly
130 * retrieve message if we're interrupted by a signal, like SIGCHLD.
131 * Because IPRT wants to use waitpid(), we're forced to have a handler
132 * installed for SIGCHLD, so when working with child processes there
133 * will be signals in the air and we will get VERR_INTERRUPTED returns.
134 * The way HGCM handles interrupted calls is to silently (?) drop them
135 * as they complete (see VMMDev), so the server knows little about it
136 * and just goes on to the next message inline.
137 *
138 * So, as a "temporary" mesasure, we block SIGCHLD here while waiting,
139 * because it will otherwise be impossible do simple stuff like 'mkdir'
140 * on a mac os x guest, and probably most other unix guests.
141 */
142#ifdef RT_OS_WINDOWS
143 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
144#else
145 sigset_t SigSet;
146 sigemptyset(&SigSet);
147 sigaddset(&SigSet, SIGCHLD);
148 sigprocmask(SIG_BLOCK, &SigSet, NULL);
149 int rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
150 sigprocmask(SIG_UNBLOCK, &SigSet, NULL);
151#endif
152 if ( rc == VERR_TOO_MUCH_DATA
153 || RT_SUCCESS(rc))
154 {
155 int rc2 = VbglHGCMParmUInt32Get(&Msg.msg, pidMsg);
156 if (RT_SUCCESS(rc2))
157 {
158 rc2 = VbglHGCMParmUInt32Get(&Msg.num_parms, pcParameters);
159 if (RT_SUCCESS(rc2))
160 {
161 /* Ok, so now we know what message type and how much parameters there are. */
162 return rc;
163 }
164 }
165 rc = rc2;
166 }
167 *pidMsg = UINT32_MAX - 1;
168 *pcParameters = UINT32_MAX - 2;
169 return rc;
170}
171
172
173/**
174 * Determins the value of g_fVbglR3GuestCtrlHavePeekGetCancel.
175 *
176 * @returns true if supported, false if not.
177 * @param idClient The client ID to use for the testing.
178 */
179DECL_NO_INLINE(static, bool) vbglR3GuestCtrlDetectPeekGetCancelSupport(uint32_t idClient)
180{
181 /*
182 * Seems we get VINF_SUCCESS back from the host if we try unsupported
183 * guest control messages, so we need to supply some random message
184 * parameters and check that they change.
185 */
186 uint32_t const idDummyMsg = UINT32_C(0x8350bdca);
187 uint32_t const cDummyParmeters = UINT32_C(0x7439604f);
188 uint32_t const cbDummyMask = UINT32_C(0xc0ffe000);
189 Assert(cDummyParmeters > VMMDEV_MAX_HGCM_PARMS);
190
191 int rc;
192 struct
193 {
194 VBGLIOCHGCMCALL Hdr;
195 HGCMFunctionParameter idMsg;
196 HGCMFunctionParameter cParams;
197 HGCMFunctionParameter acbParams[14];
198 } PeekCall;
199 Assert(RT_ELEMENTS(PeekCall.acbParams) + 2 < VMMDEV_MAX_HGCM_PARMS);
200
201 do
202 {
203 memset(&PeekCall, 0xf6, sizeof(PeekCall));
204 VBGL_HGCM_HDR_INIT(&PeekCall.Hdr, idClient, GUEST_MSG_PEEK_NOWAIT, 16);
205 VbglHGCMParmUInt32Set(&PeekCall.idMsg, idDummyMsg);
206 VbglHGCMParmUInt32Set(&PeekCall.cParams, cDummyParmeters);
207 for (uint32_t i = 0; i < RT_ELEMENTS(PeekCall.acbParams); i++)
208 VbglHGCMParmUInt32Set(&PeekCall.acbParams[i], i | cbDummyMask);
209
210 rc = VbglR3HGCMCall(&PeekCall.Hdr, sizeof(PeekCall));
211 } while (rc == VERR_INTERRUPTED);
212
213 LogRel2(("vbglR3GuestCtrlDetectPeekGetCancelSupport: rc=%Rrc %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x %#x\n",
214 rc, PeekCall.idMsg.u.value32, PeekCall.cParams.u.value32,
215 PeekCall.acbParams[ 0].u.value32, PeekCall.acbParams[ 1].u.value32,
216 PeekCall.acbParams[ 2].u.value32, PeekCall.acbParams[ 3].u.value32,
217 PeekCall.acbParams[ 4].u.value32, PeekCall.acbParams[ 5].u.value32,
218 PeekCall.acbParams[ 6].u.value32, PeekCall.acbParams[ 7].u.value32,
219 PeekCall.acbParams[ 8].u.value32, PeekCall.acbParams[ 9].u.value32,
220 PeekCall.acbParams[10].u.value32, PeekCall.acbParams[11].u.value32,
221 PeekCall.acbParams[12].u.value32, PeekCall.acbParams[13].u.value32));
222
223 /*
224 * VERR_TRY_AGAIN is likely and easy.
225 */
226 if ( rc == VERR_TRY_AGAIN
227 && PeekCall.idMsg.u.value32 == 0
228 && PeekCall.cParams.u.value32 == 0
229 && PeekCall.acbParams[0].u.value32 == 0
230 && PeekCall.acbParams[1].u.value32 == 0
231 && PeekCall.acbParams[2].u.value32 == 0
232 && PeekCall.acbParams[3].u.value32 == 0)
233 {
234 g_fVbglR3GuestCtrlHavePeekGetCancel = 1;
235 LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Supported (#1)\n"));
236 return true;
237 }
238
239 /*
240 * VINF_SUCCESS is annoying but with 16 parameters we've got plenty to check.
241 */
242 if ( rc == VINF_SUCCESS
243 && PeekCall.idMsg.u.value32 != idDummyMsg
244 && PeekCall.idMsg.u.value32 != 0
245 && PeekCall.cParams.u.value32 <= VMMDEV_MAX_HGCM_PARMS)
246 {
247 for (uint32_t i = 0; i < RT_ELEMENTS(PeekCall.acbParams); i++)
248 if (PeekCall.acbParams[i].u.value32 != (i | cbDummyMask))
249 {
250 g_fVbglR3GuestCtrlHavePeekGetCancel = 0;
251 LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Not supported (#1)\n"));
252 return false;
253 }
254 g_fVbglR3GuestCtrlHavePeekGetCancel = 1;
255 LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Supported (#2)\n"));
256 return true;
257 }
258
259 /*
260 * Okay, pretty sure it's not supported then.
261 */
262 LogRel(("vbglR3GuestCtrlDetectPeekGetCancelSupport: Not supported (#3)\n"));
263 g_fVbglR3GuestCtrlHavePeekGetCancel = 0;
264 return false;
265}
266
267
268/**
269 * Reads g_fVbglR3GuestCtrlHavePeekGetCancel and resolved -1.
270 *
271 * @returns true if supported, false if not.
272 * @param idClient The client ID to use for the testing.
273 */
274DECLINLINE(bool) vbglR3GuestCtrlSupportsPeekGetCancel(uint32_t idClient)
275{
276 int fState = g_fVbglR3GuestCtrlHavePeekGetCancel;
277 if (RT_LIKELY(fState != -1))
278 return fState != 0;
279 return vbglR3GuestCtrlDetectPeekGetCancelSupport(idClient);
280}
281
282
283/**
284 * Figures which getter function to use to retrieve the message.
285 */
286DECLINLINE(uint32_t) vbglR3GuestCtrlGetMsgFunctionNo(uint32_t idClient)
287{
288 return vbglR3GuestCtrlSupportsPeekGetCancel(idClient) ? GUEST_MSG_GET : GUEST_MSG_WAIT;
289}
290
291
292/**
293 * Checks if the host supports the optimizes message and session functions.
294 *
295 * @returns true / false.
296 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
297 * We may need to use this for checking.
298 * @since 6.0
299 */
300VBGLR3DECL(bool) VbglR3GuestCtrlSupportsOptimizations(uint32_t idClient)
301{
302 return vbglR3GuestCtrlSupportsPeekGetCancel(idClient);
303}
304
305
306/**
307 * Make us the guest control master client.
308 *
309 * @returns VBox status code.
310 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
311 */
312VBGLR3DECL(int) VbglR3GuestCtrlMakeMeMaster(uint32_t idClient)
313{
314 int rc;
315 do
316 {
317 VBGLIOCHGCMCALL Hdr;
318 VBGL_HGCM_HDR_INIT(&Hdr, idClient, GUEST_MSG_MAKE_ME_MASTER, 0);
319 rc = VbglR3HGCMCall(&Hdr, sizeof(Hdr));
320 } while (rc == VERR_INTERRUPTED);
321 return rc;
322}
323
324
325/**
326 * Reports features to the host and retrieve host feature set.
327 *
328 * @returns VBox status code.
329 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
330 * @param fGuestFeatures Features to report, VBOX_GUESTCTRL_GF_XXX.
331 * @param pfHostFeatures Where to store the features VBOX_GUESTCTRL_HF_XXX.
332 */
333VBGLR3DECL(int) VbglR3GuestCtrlReportFeatures(uint32_t idClient, uint64_t fGuestFeatures, uint64_t *pfHostFeatures)
334{
335 int rc;
336 do
337 {
338 struct
339 {
340 VBGLIOCHGCMCALL Hdr;
341 HGCMFunctionParameter f64Features0;
342 HGCMFunctionParameter f64Features1;
343 } Msg;
344 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_REPORT_FEATURES, 2);
345 VbglHGCMParmUInt64Set(&Msg.f64Features0, fGuestFeatures);
346 VbglHGCMParmUInt64Set(&Msg.f64Features1, VBOX_GUESTCTRL_GF_1_MUST_BE_ONE);
347
348 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
349 if (RT_SUCCESS(rc))
350 {
351 Assert(Msg.f64Features0.type == VMMDevHGCMParmType_64bit);
352 Assert(Msg.f64Features1.type == VMMDevHGCMParmType_64bit);
353 if (Msg.f64Features1.u.value64 & VBOX_GUESTCTRL_GF_1_MUST_BE_ONE)
354 rc = VERR_NOT_SUPPORTED;
355 else if (pfHostFeatures)
356 *pfHostFeatures = Msg.f64Features0.u.value64;
357 break;
358 }
359 } while (rc == VERR_INTERRUPTED);
360 return rc;
361
362}
363
364
365/**
366 * Query the host features.
367 *
368 * @returns VBox status code.
369 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
370 * @param pfHostFeatures Where to store the host feature, VBOX_GUESTCTRL_HF_XXX.
371 */
372VBGLR3DECL(int) VbglR3GuestCtrlQueryFeatures(uint32_t idClient, uint64_t *pfHostFeatures)
373{
374 int rc;
375 do
376 {
377 struct
378 {
379 VBGLIOCHGCMCALL Hdr;
380 HGCMFunctionParameter f64Features0;
381 HGCMFunctionParameter f64Features1;
382 } Msg;
383 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_QUERY_FEATURES, 2);
384 VbglHGCMParmUInt64Set(&Msg.f64Features0, 0);
385 VbglHGCMParmUInt64Set(&Msg.f64Features1, RT_BIT_64(63));
386
387 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
388 if (RT_SUCCESS(rc))
389 {
390 Assert(Msg.f64Features0.type == VMMDevHGCMParmType_64bit);
391 Assert(Msg.f64Features1.type == VMMDevHGCMParmType_64bit);
392 if (Msg.f64Features1.u.value64 & RT_BIT_64(63))
393 rc = VERR_NOT_SUPPORTED;
394 else if (pfHostFeatures)
395 *pfHostFeatures = Msg.f64Features0.u.value64;
396 break;
397 }
398 } while (rc == VERR_INTERRUPTED);
399 return rc;
400
401}
402
403
404/**
405 * Peeks at the next host message, waiting for one to turn up.
406 *
407 * @returns VBox status code.
408 * @retval VERR_INTERRUPTED if interrupted. Does the necessary cleanup, so
409 * caller just have to repeat this call.
410 * @retval VERR_VM_RESTORED if the VM has been restored (idRestoreCheck).
411 *
412 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
413 * @param pidMsg Where to store the message id.
414 * @param pcParameters Where to store the number of parameters which will
415 * be received in a second call to the host.
416 * @param pidRestoreCheck Pointer to the VbglR3GetSessionId() variable to use
417 * for the VM restore check. Optional.
418 *
419 * @note Restore check is only performed optimally with a 6.0 host.
420 */
421VBGLR3DECL(int) VbglR3GuestCtrlMsgPeekWait(uint32_t idClient, uint32_t *pidMsg, uint32_t *pcParameters, uint64_t *pidRestoreCheck)
422{
423 AssertPtrReturn(pidMsg, VERR_INVALID_POINTER);
424 AssertPtrReturn(pcParameters, VERR_INVALID_POINTER);
425
426 int rc;
427 if (vbglR3GuestCtrlSupportsPeekGetCancel(idClient))
428 {
429 struct
430 {
431 VBGLIOCHGCMCALL Hdr;
432 HGCMFunctionParameter idMsg; /* Doubles as restore check on input. */
433 HGCMFunctionParameter cParameters;
434 } Msg;
435 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_PEEK_WAIT, 2);
436 VbglHGCMParmUInt64Set(&Msg.idMsg, pidRestoreCheck ? *pidRestoreCheck : 0);
437 VbglHGCMParmUInt32Set(&Msg.cParameters, 0);
438 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
439 LogRel2(("VbglR3GuestCtrlMsgPeekWait -> %Rrc\n", rc));
440 if (RT_SUCCESS(rc))
441 {
442 AssertMsgReturn( Msg.idMsg.type == VMMDevHGCMParmType_64bit
443 && Msg.cParameters.type == VMMDevHGCMParmType_32bit,
444 ("msg.type=%d num_parms.type=%d\n", Msg.idMsg.type, Msg.cParameters.type),
445 VERR_INTERNAL_ERROR_3);
446
447 *pidMsg = (uint32_t)Msg.idMsg.u.value64;
448 *pcParameters = Msg.cParameters.u.value32;
449 return rc;
450 }
451
452 /*
453 * If interrupted we must cancel the call so it doesn't prevent us from making another one.
454 */
455 if (rc == VERR_INTERRUPTED)
456 {
457 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_CANCEL, 0);
458 int rc2 = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg.Hdr));
459 AssertRC(rc2);
460 }
461
462 /*
463 * If restored, update pidRestoreCheck.
464 */
465 if (rc == VERR_VM_RESTORED && pidRestoreCheck)
466 *pidRestoreCheck = Msg.idMsg.u.value64;
467
468 *pidMsg = UINT32_MAX - 1;
469 *pcParameters = UINT32_MAX - 2;
470 return rc;
471 }
472
473 /*
474 * Fallback if host < v6.0.
475 *
476 * Note! The restore check isn't perfect. Would require checking afterwards
477 * and stash the result if we were restored during the call. Too much
478 * hazzle for a downgrade scenario.
479 */
480 if (pidRestoreCheck)
481 {
482 uint64_t idRestoreCur = *pidRestoreCheck;
483 rc = VbglR3GetSessionId(&idRestoreCur);
484 if (RT_SUCCESS(rc) && idRestoreCur != *pidRestoreCheck)
485 {
486 *pidRestoreCheck = idRestoreCur;
487 return VERR_VM_RESTORED;
488 }
489 }
490
491 rc = vbglR3GuestCtrlMsgWaitFor(idClient, pidMsg, pcParameters);
492 if (rc == VERR_TOO_MUCH_DATA)
493 rc = VINF_SUCCESS;
494 return rc;
495}
496
497
498/**
499 * Asks the host guest control service to set a message filter to this
500 * client so that it only will receive certain messages in the future.
501 * The filter(s) are a bitmask for the context IDs, served from the host.
502 *
503 * @return IPRT status code.
504 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
505 * @param uValue The value to filter messages for.
506 * @param uMaskAdd Filter mask to add.
507 * @param uMaskRemove Filter mask to remove.
508 */
509VBGLR3DECL(int) VbglR3GuestCtrlMsgFilterSet(uint32_t idClient, uint32_t uValue, uint32_t uMaskAdd, uint32_t uMaskRemove)
510{
511 HGCMMsgFilterSet Msg;
512
513 /* Tell the host we want to set a filter. */
514 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, GUEST_MSG_FILTER_SET, 4);
515 VbglHGCMParmUInt32Set(&Msg.value, uValue);
516 VbglHGCMParmUInt32Set(&Msg.mask_add, uMaskAdd);
517 VbglHGCMParmUInt32Set(&Msg.mask_remove, uMaskRemove);
518 VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
519
520 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
521}
522
523
524/**
525 * Replies to a message from the host.
526 *
527 * @returns VBox status code.
528 * @param pCtx Guest control command context to use.
529 * @param rc Guest rc to reply.
530 */
531VBGLR3DECL(int) VbglR3GuestCtrlMsgReply(PVBGLR3GUESTCTRLCMDCTX pCtx,
532 int rc)
533{
534 return VbglR3GuestCtrlMsgReplyEx(pCtx, rc, 0 /* uType */,
535 NULL /* pvPayload */, 0 /* cbPayload */);
536}
537
538
539/**
540 * Replies to a message from the host, extended version.
541 *
542 * @returns VBox status code.
543 * @param pCtx Guest control command context to use.
544 * @param rc Guest rc to reply.
545 * @param uType Reply type; not used yet and must be 0.
546 * @param pvPayload Pointer to data payload to reply. Optional.
547 * @param cbPayload Size of data payload (in bytes) to reply.
548 */
549VBGLR3DECL(int) VbglR3GuestCtrlMsgReplyEx(PVBGLR3GUESTCTRLCMDCTX pCtx,
550 int rc, uint32_t uType,
551 void *pvPayload, uint32_t cbPayload)
552{
553 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
554 /* Everything else is optional. */
555
556 HGCMMsgReply Msg;
557 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_REPLY, 4);
558 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
559 VbglHGCMParmUInt32Set(&Msg.type, uType);
560 VbglHGCMParmUInt32Set(&Msg.rc, (uint32_t)rc); /* int vs. uint32_t */
561 VbglHGCMParmPtrSet(&Msg.payload, pvPayload, cbPayload);
562
563 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
564}
565
566/**
567 * Tell the host to skip the current message replying VERR_NOT_SUPPORTED
568 *
569 * @return IPRT status code.
570 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
571 * @param rcSkip The status code to pass back to Main when skipping.
572 * @param idMsg The message ID to skip, pass UINT32_MAX to pass any.
573 */
574VBGLR3DECL(int) VbglR3GuestCtrlMsgSkip(uint32_t idClient, int rcSkip, uint32_t idMsg)
575{
576 if (vbglR3GuestCtrlSupportsPeekGetCancel(idClient))
577 {
578 struct
579 {
580 VBGLIOCHGCMCALL Hdr;
581 HGCMFunctionParameter rcSkip;
582 HGCMFunctionParameter idMsg;
583 } Msg;
584 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_SKIP, 2);
585 VbglHGCMParmUInt32Set(&Msg.rcSkip, (uint32_t)rcSkip);
586 VbglHGCMParmUInt32Set(&Msg.idMsg, idMsg);
587 return VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
588 }
589
590 /* This is generally better than nothing... */
591 return VbglR3GuestCtrlMsgSkipOld(idClient);
592}
593
594
595/**
596 * Tells the host service to skip the current message returned by
597 * VbglR3GuestCtrlMsgWaitFor().
598 *
599 * @return IPRT status code.
600 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
601 */
602VBGLR3DECL(int) VbglR3GuestCtrlMsgSkipOld(uint32_t idClient)
603{
604 HGCMMsgSkip Msg;
605
606 /* Tell the host we want to skip the current assigned message. */
607 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, GUEST_MSG_SKIP_OLD, 1);
608 VbglHGCMParmUInt32Set(&Msg.flags, 0 /* Flags, unused */);
609 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
610}
611
612
613/**
614 * Asks the host to cancel (release) all pending waits which were deferred.
615 *
616 * @returns VBox status code.
617 * @param idClient The client ID returned by VbglR3GuestCtrlConnect().
618 */
619VBGLR3DECL(int) VbglR3GuestCtrlCancelPendingWaits(uint32_t idClient)
620{
621 HGCMMsgCancelPendingWaits Msg;
622 VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, GUEST_MSG_CANCEL, 0);
623 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
624}
625
626
627/**
628 * Prepares a session.
629 * @since 6.0
630 * @sa GUEST_SESSION_PREPARE
631 */
632VBGLR3DECL(int) VbglR3GuestCtrlSessionPrepare(uint32_t idClient, uint32_t idSession, void const *pvKey, uint32_t cbKey)
633{
634 int rc;
635 do
636 {
637 struct
638 {
639 VBGLIOCHGCMCALL Hdr;
640 HGCMFunctionParameter idSession;
641 HGCMFunctionParameter pKey;
642 } Msg;
643 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_SESSION_PREPARE, 2);
644 VbglHGCMParmUInt32Set(&Msg.idSession, idSession);
645 VbglHGCMParmPtrSet(&Msg.pKey, (void *)pvKey, cbKey);
646 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
647 } while (rc == VERR_INTERRUPTED);
648 return rc;
649}
650
651
652/**
653 * Accepts a session.
654 * @since 6.0
655 * @sa GUEST_SESSION_ACCEPT
656 */
657VBGLR3DECL(int) VbglR3GuestCtrlSessionAccept(uint32_t idClient, uint32_t idSession, void const *pvKey, uint32_t cbKey)
658{
659 int rc;
660 do
661 {
662 struct
663 {
664 VBGLIOCHGCMCALL Hdr;
665 HGCMFunctionParameter idSession;
666 HGCMFunctionParameter pKey;
667 } Msg;
668 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_SESSION_ACCEPT, 2);
669 VbglHGCMParmUInt32Set(&Msg.idSession, idSession);
670 VbglHGCMParmPtrSet(&Msg.pKey, (void *)pvKey, cbKey);
671 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
672 } while (rc == VERR_INTERRUPTED);
673 return rc;
674}
675
676
677/**
678 * Cancels a prepared session.
679 * @since 6.0
680 * @sa GUEST_SESSION_CANCEL_PREPARED
681 */
682VBGLR3DECL(int) VbglR3GuestCtrlSessionCancelPrepared(uint32_t idClient, uint32_t idSession)
683{
684 int rc;
685 do
686 {
687 struct
688 {
689 VBGLIOCHGCMCALL Hdr;
690 HGCMFunctionParameter idSession;
691 } Msg;
692 VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_SESSION_CANCEL_PREPARED, 1);
693 VbglHGCMParmUInt32Set(&Msg.idSession, idSession);
694 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
695 } while (rc == VERR_INTERRUPTED);
696 return rc;
697}
698
699
700/**
701 * Invalidates the internal state because the (VM) session has been changed (i.e. restored).
702 *
703 * @returns VBox status code.
704 * @param idClient Client ID to use for invalidating state.
705 * @param idNewControlSession New control session ID. Currently unused.
706 */
707VBGLR3DECL(int) VbglR3GuestCtrlSessionHasChanged(uint32_t idClient, uint64_t idNewControlSession)
708{
709 RT_NOREF(idNewControlSession);
710
711 vbglR3GuestCtrlDetectPeekGetCancelSupport(idClient);
712
713 return VINF_SUCCESS;
714}
715
716
717/**
718 * Asks a specific guest session to close.
719 *
720 * @return IPRT status code.
721 * @param pCtx Guest control command context to use.
722 * @param fFlags Some kind of flag. Figure it out yourself.
723 */
724VBGLR3DECL(int) VbglR3GuestCtrlSessionClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t fFlags)
725{
726 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
727 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
728
729 HGCMMsgSessionClose Msg;
730 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_SESSION_CLOSE, pCtx->uNumParms);
731 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
732 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
733
734 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
735}
736
737
738/**
739 * Notifies a guest session.
740 *
741 * @returns VBox status code.
742 * @param pCtx Guest control command context to use.
743 * @param uType Notification type of type GUEST_SESSION_NOTIFYTYPE_XXX.
744 * @param iResult Result code (rc) to notify.
745 */
746VBGLR3DECL(int) VbglR3GuestCtrlSessionNotify(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uType, int32_t iResult)
747{
748 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
749
750 HGCMMsgSessionNotify Msg;
751 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_SESSION_NOTIFY, 3);
752 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
753 VbglHGCMParmUInt32Set(&Msg.type, uType);
754 VbglHGCMParmUInt32Set(&Msg.result, (uint32_t)iResult);
755
756 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
757}
758
759/**
760 * Initializes a session startup info, extended version.
761 *
762 * @returns VBox status code.
763 * @param pStartupInfo Session startup info to initializes.
764 * @param cbUser Size (in bytes) to use for the user name buffer.
765 * @param cbPassword Size (in bytes) to use for the password buffer.
766 * @param cbDomain Size (in bytes) to use for the domain name buffer.
767 */
768VBGLR3DECL(int) VbglR3GuestCtrlSessionStartupInfoInitEx(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo,
769 size_t cbUser, size_t cbPassword, size_t cbDomain)
770{
771 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);
772
773 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO));
774
775#define ALLOC_STR(a_Str, a_cb) \
776 if ((a_cb) > 0) \
777 { \
778 pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \
779 AssertPtrBreak(pStartupInfo->psz##a_Str); \
780 pStartupInfo->cb##a_Str = (uint32_t)a_cb; \
781 }
782
783 do
784 {
785 ALLOC_STR(User, cbUser);
786 ALLOC_STR(Password, cbPassword);
787 ALLOC_STR(Domain, cbDomain);
788
789 return VINF_SUCCESS;
790
791 } while (0);
792
793#undef ALLOC_STR
794
795 VbglR3GuestCtrlSessionStartupInfoDestroy(pStartupInfo);
796 return VERR_NO_MEMORY;
797}
798
799/**
800 * Initializes a session startup info.
801 *
802 * @returns VBox status code.
803 * @param pStartupInfo Session startup info to initializes.
804 */
805VBGLR3DECL(int) VbglR3GuestCtrlSessionStartupInfoInit(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo)
806{
807 return VbglR3GuestCtrlSessionStartupInfoInitEx(pStartupInfo,
808 GUEST_PROC_DEF_USER_LEN, GUEST_PROC_DEF_PASSWORD_LEN,
809 GUEST_PROC_DEF_DOMAIN_LEN);
810}
811
812/**
813 * Destroys a session startup info.
814 *
815 * @param pStartupInfo Session startup info to destroy.
816 */
817VBGLR3DECL(void) VbglR3GuestCtrlSessionStartupInfoDestroy(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo)
818{
819 if (!pStartupInfo)
820 return;
821
822 RTStrFree(pStartupInfo->pszUser);
823 RTStrFree(pStartupInfo->pszPassword);
824 RTStrFree(pStartupInfo->pszDomain);
825
826 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO));
827}
828
829/**
830 * Free's a session startup info.
831 *
832 * @param pStartupInfo Session startup info to free.
833 * The pointer will not be valid anymore after return.
834 */
835VBGLR3DECL(void) VbglR3GuestCtrlSessionStartupInfoFree(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo)
836{
837 if (!pStartupInfo)
838 return;
839
840 VbglR3GuestCtrlSessionStartupInfoDestroy(pStartupInfo);
841
842 RTMemFree(pStartupInfo);
843 pStartupInfo = NULL;
844}
845
846/**
847 * Duplicates a session startup info.
848 *
849 * @returns Duplicated session startup info on success, or NULL on error.
850 * @param pStartupInfo Session startup info to duplicate.
851 */
852VBGLR3DECL(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO) VbglR3GuestCtrlSessionStartupInfoDup(PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo)
853{
854 AssertPtrReturn(pStartupInfo, NULL);
855
856 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfoDup = (PVBGLR3GUESTCTRLSESSIONSTARTUPINFO)
857 RTMemDup(pStartupInfo, sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO));
858 if (pStartupInfoDup)
859 {
860 do
861 {
862 pStartupInfoDup->pszUser = NULL;
863 pStartupInfoDup->pszPassword = NULL;
864 pStartupInfoDup->pszDomain = NULL;
865
866#define DUP_STR(a_Str) \
867 if (pStartupInfo->cb##a_Str) \
868 { \
869 pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \
870 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \
871 pStartupInfoDup->cb##a_Str = (uint32_t)strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \
872 }
873 DUP_STR(User);
874 DUP_STR(Password);
875 DUP_STR(Domain);
876
877#undef DUP_STR
878
879 return pStartupInfoDup;
880
881 } while (0); /* To use break macros above. */
882
883 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfoDup);
884 }
885
886 return NULL;
887}
888
889/**
890 * Retrieves a HOST_SESSION_CREATE message.
891 *
892 * @returns VBox status code.
893 * @param pCtx Guest control command context to use.
894 * @param ppStartupInfo Where to store the allocated session startup info.
895 * Needs to be free'd by VbglR3GuestCtrlSessionStartupInfoFree().
896 */
897VBGLR3DECL(int) VbglR3GuestCtrlSessionGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, PVBGLR3GUESTCTRLSESSIONSTARTUPINFO *ppStartupInfo)
898{
899 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
900 AssertReturn(pCtx->uNumParms == 6, VERR_INVALID_PARAMETER);
901 AssertPtrReturn(ppStartupInfo, VERR_INVALID_POINTER);
902
903 PVBGLR3GUESTCTRLSESSIONSTARTUPINFO pStartupInfo
904 = (PVBGLR3GUESTCTRLSESSIONSTARTUPINFO)RTMemAlloc(sizeof(VBGLR3GUESTCTRLSESSIONSTARTUPINFO));
905 if (!pStartupInfo)
906 return VERR_NO_MEMORY;
907
908 int rc = VbglR3GuestCtrlSessionStartupInfoInit(pStartupInfo);
909 if (RT_FAILURE(rc))
910 {
911 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo);
912 return rc;
913 }
914
915 do
916 {
917 HGCMMsgSessionOpen Msg;
918 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
919 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_SESSION_CREATE);
920 VbglHGCMParmUInt32Set(&Msg.protocol, 0);
921 VbglHGCMParmPtrSet(&Msg.username, pStartupInfo->pszUser, pStartupInfo->cbUser);
922 VbglHGCMParmPtrSet(&Msg.password, pStartupInfo->pszPassword, pStartupInfo->cbPassword);
923 VbglHGCMParmPtrSet(&Msg.domain, pStartupInfo->pszDomain, pStartupInfo->cbDomain);
924 VbglHGCMParmUInt32Set(&Msg.flags, 0);
925
926 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
927 if (RT_SUCCESS(rc))
928 {
929 Msg.context.GetUInt32(&pCtx->uContextID);
930 Msg.protocol.GetUInt32(&pStartupInfo->uProtocol);
931 Msg.flags.GetUInt32(&pStartupInfo->fFlags);
932
933 pStartupInfo->uSessionID = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtx->uContextID);
934 }
935
936 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
937
938 if (RT_SUCCESS(rc))
939 {
940 *ppStartupInfo = pStartupInfo;
941 }
942 else
943 VbglR3GuestCtrlSessionStartupInfoFree(pStartupInfo);
944
945 LogFlowFuncLeaveRC(rc);
946 return rc;
947}
948
949
950/**
951 * Retrieves a HOST_SESSION_CLOSE message.
952 */
953VBGLR3DECL(int) VbglR3GuestCtrlSessionGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *pfFlags, uint32_t *pidSession)
954{
955 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
956 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
957
958 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
959
960 int rc;
961 do
962 {
963 HGCMMsgSessionClose Msg;
964 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
965 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_SESSION_CLOSE);
966 VbglHGCMParmUInt32Set(&Msg.flags, 0);
967
968 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
969 if (RT_SUCCESS(rc))
970 {
971 Msg.context.GetUInt32(&pCtx->uContextID);
972 Msg.flags.GetUInt32(pfFlags);
973
974 if (pidSession)
975 *pidSession = VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pCtx->uContextID);
976 }
977 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
978 return rc;
979}
980
981
982#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
983/**
984 * Retrieves a HOST_MSG_DIR_OPEN message.
985 *
986 * @returns VBox status code.
987 * @param pCtx Guest control command context to use.
988 * @param pszPath Where to return the directory path to open.
989 * @param cbPath Size (in bytes) of \a pszPath.
990 * @param pfFlags Where to return the directory listing flags.
991 * @param enmFilter Where to return the directory filter type.
992 * @param penmAttrAdd Where to return the additional attributes enumeration to use for reading directory entries later.
993 * @param pfReadFlags Where to return the flags for reading directory entries later.
994 */
995VBGLR3DECL(int) VbglR3GuestCtrlDirGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, char *pszPath, uint32_t cbPath, uint32_t *pfFlags,
996 GSTCTLDIRFILTER *penmFilter, GSTCTLFSOBJATTRADD *penmReadAttrAdd, uint32_t *pfReadFlags)
997{
998 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
999 AssertReturn(pCtx->uNumParms == 6, VERR_INVALID_PARAMETER);
1000
1001 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
1002 AssertReturn(cbPath, VERR_INVALID_PARAMETER);
1003 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1004 AssertPtrReturn(penmFilter, VERR_INVALID_POINTER);
1005 AssertPtrReturn(penmReadAttrAdd, VERR_INVALID_POINTER);
1006 AssertPtrReturn(pfReadFlags, VERR_INVALID_POINTER);
1007
1008 int rc;
1009 do
1010 {
1011 HGCMMsgDirOpen Msg;
1012 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1013 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_OPEN);
1014 VbglHGCMParmPtrSet(&Msg.path, pszPath, cbPath);
1015 VbglHGCMParmUInt32Set(&Msg.filter, 0);
1016 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1017 VbglHGCMParmUInt32Set(&Msg.read_attr_add, 0);
1018 VbglHGCMParmUInt32Set(&Msg.read_flags, 0);
1019
1020 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1021 if (RT_SUCCESS(rc))
1022 {
1023 Msg.context.GetUInt32(&pCtx->uContextID);
1024 Msg.filter.GetUInt32((uint32_t *)penmFilter);
1025 Msg.flags.GetUInt32(pfFlags);
1026 Msg.read_attr_add.GetUInt32((uint32_t *)penmReadAttrAdd);
1027 Msg.read_flags.GetUInt32(pfReadFlags);
1028 }
1029 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1030 return rc;
1031}
1032
1033
1034/**
1035 * Retrieves a HOST_MSG_DIR_CLOSE message.
1036 *
1037 * @returns VBox status code.
1038 * @param pCtx Guest control command context to use.
1039 * @param puHandle Where to return the handle of the guest directory to close.
1040 */
1041VBGLR3DECL(int) VbglR3GuestCtrlDirGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
1042{
1043 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1044 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1045
1046 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1047
1048 int rc;
1049 do
1050 {
1051 HGCMMsgDirClose Msg;
1052 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1053 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_CLOSE);
1054 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1055
1056 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1057 if (RT_SUCCESS(rc))
1058 {
1059 Msg.context.GetUInt32(&pCtx->uContextID);
1060 Msg.handle.GetUInt32(puHandle);
1061 }
1062 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1063 return rc;
1064}
1065
1066
1067/**
1068 * Retrieves a HOST_MSG_DIR_READ message.
1069 *
1070 * @returns VBox status code.
1071 * @param pCtx Guest control command context to use.
1072 * @param puHandle Where to return the directory handle to rewind.
1073 */
1074VBGLR3DECL(int) VbglR3GuestCtrlDirGetRead(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
1075{
1076 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1077 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1078
1079 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1080
1081 int rc;
1082 do
1083 {
1084 HGCMMsgDirRead Msg;
1085 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1086 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_READ);
1087 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1088
1089 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1090 if (RT_SUCCESS(rc))
1091 {
1092 Msg.context.GetUInt32(&pCtx->uContextID);
1093 Msg.handle.GetUInt32(puHandle);
1094 }
1095 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1096 return rc;
1097}
1098
1099
1100/**
1101 * Retrieves a HOST_MSG_DIR_REWIND message.
1102 *
1103 * @returns VBox status code.
1104 * @param pCtx Guest control command context to use.
1105 * @param puHandle Where to return the directory handle to rewind.
1106 */
1107VBGLR3DECL(int) VbglR3GuestCtrlDirGetRewind(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
1108{
1109 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1110 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1111
1112 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1113
1114 int rc;
1115 do
1116 {
1117 HGCMMsgDirRewind Msg;
1118 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1119 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_REWIND);
1120 VbglHGCMParmUInt64Set(&Msg.handle, 0);
1121
1122 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1123 if (RT_SUCCESS(rc))
1124 {
1125 Msg.context.GetUInt32(&pCtx->uContextID);
1126 Msg.handle.GetUInt32(puHandle);
1127 }
1128 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1129 return rc;
1130}
1131#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
1132
1133
1134/**
1135 * Retrieves a HOST_PATH_RENAME message.
1136 */
1137VBGLR3DECL(int) VbglR3GuestCtrlPathGetRename(PVBGLR3GUESTCTRLCMDCTX pCtx,
1138 char *pszSource, uint32_t cbSource,
1139 char *pszDest, uint32_t cbDest,
1140 uint32_t *pfFlags)
1141{
1142 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1143 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
1144
1145 AssertPtrReturn(pszSource, VERR_INVALID_POINTER);
1146 AssertReturn(cbSource, VERR_INVALID_PARAMETER);
1147 AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
1148 AssertReturn(cbDest, VERR_INVALID_PARAMETER);
1149 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1150
1151 int rc;
1152 do
1153 {
1154 HGCMMsgPathRename Msg;
1155 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1156 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_PATH_RENAME);
1157 VbglHGCMParmPtrSet(&Msg.source, pszSource, cbSource);
1158 VbglHGCMParmPtrSet(&Msg.dest, pszDest, cbDest);
1159 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1160
1161 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1162 if (RT_SUCCESS(rc))
1163 {
1164 Msg.context.GetUInt32(&pCtx->uContextID);
1165 Msg.flags.GetUInt32(pfFlags);
1166 }
1167
1168 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1169 return rc;
1170}
1171
1172
1173/**
1174 * Retrieves a HOST_PATH_USER_DOCUMENTS message.
1175 */
1176VBGLR3DECL(int) VbglR3GuestCtrlPathGetUserDocuments(PVBGLR3GUESTCTRLCMDCTX pCtx)
1177{
1178 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1179 AssertReturn(pCtx->uNumParms == 1, VERR_INVALID_PARAMETER);
1180
1181 int rc;
1182 do
1183 {
1184 HGCMMsgPathUserDocuments Msg;
1185 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1186 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_PATH_USER_DOCUMENTS);
1187
1188 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1189 if (RT_SUCCESS(rc))
1190 Msg.context.GetUInt32(&pCtx->uContextID);
1191 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1192 return rc;
1193}
1194
1195
1196/**
1197 * Retrieves a HOST_PATH_USER_HOME message.
1198 */
1199VBGLR3DECL(int) VbglR3GuestCtrlPathGetUserHome(PVBGLR3GUESTCTRLCMDCTX pCtx)
1200{
1201 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1202 AssertReturn(pCtx->uNumParms == 1, VERR_INVALID_PARAMETER);
1203
1204 int rc;
1205 do
1206 {
1207 HGCMMsgPathUserHome Msg;
1208 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1209 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_PATH_USER_HOME);
1210
1211 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1212 if (RT_SUCCESS(rc))
1213 Msg.context.GetUInt32(&pCtx->uContextID);
1214 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1215 return rc;
1216}
1217
1218
1219#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
1220/**
1221 * Retrieves a HOST_MSG_FS_QUERY_INFO message.
1222 *
1223 * @returns VBox status code.
1224 * @param pCtx Guest control command context to use.
1225 * @param pszPath Where to return the path of the file system object to query.
1226 * @param cbPath Size (in bytes) of \a pszPath.
1227 * @param penmAddAttrib Where to return the additional attributes enumeration.
1228 * @param pfFlags Where to return the flags for .
1229 */
1230VBGLR3DECL(int) VbglR3GuestCtrlFsGetQueryInfo(PVBGLR3GUESTCTRLCMDCTX pCtx,
1231 char *pszPath, uint32_t cbPath, GSTCTLFSOBJATTRADD *penmAddAttrib, uint32_t *pfFlags)
1232{
1233 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1234 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
1235
1236 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
1237 AssertReturn(cbPath, VERR_INVALID_PARAMETER);
1238 AssertPtrReturn(penmAddAttrib, VERR_INVALID_POINTER);
1239 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1240
1241 int rc;
1242 do
1243 {
1244 HGCMMsgFsQueryInfo Msg;
1245 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1246 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FS_QUERY_INFO);
1247 VbglHGCMParmPtrSet(&Msg.path, pszPath, cbPath);
1248 VbglHGCMParmUInt32Set(&Msg.add_attributes, 0);
1249 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1250
1251 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1252 if (RT_SUCCESS(rc))
1253 {
1254 Msg.context.GetUInt32(&pCtx->uContextID);
1255 Msg.add_attributes.GetUInt32((uint32_t *)penmAddAttrib);
1256 Msg.flags.GetUInt32(pfFlags);
1257 }
1258
1259 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1260 return rc;
1261}
1262
1263
1264/**
1265 * Retrieves a HOST_MSG_FS_CREATE_TEMP message.
1266 *
1267 * @returns VBox status code.
1268 * @param pCtx Guest control command context to use.
1269 * @param pszTemplate Where to return the template name.
1270 * @param cbTemplate Size (in bytes) of \a pszTemplate.
1271 * @param pszPath Where to return the temporary directory path.
1272 * @param cbTemplate Size (in bytes) of \a pszPath.
1273 * @param pfFlags Where to return the creation flags.
1274 * @param pfMode Where to return the creation mode.
1275 */
1276VBGLR3DECL(int) VbglR3GuestCtrlFsGetCreateTemp(PVBGLR3GUESTCTRLCMDCTX pCtx,
1277 char *pszTemplate, uint32_t cbTemplate, char *pszPath, uint32_t cbPath,
1278 uint32_t *pfFlags, uint32_t *pfMode)
1279{
1280 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1281 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
1282
1283 AssertPtrReturn(pszTemplate, VERR_INVALID_POINTER);
1284 AssertReturn(cbTemplate, VERR_INVALID_PARAMETER);
1285 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
1286 AssertReturn(cbPath, VERR_INVALID_PARAMETER);
1287 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1288 AssertPtrReturn(pfMode, VERR_INVALID_POINTER);
1289
1290 int rc;
1291 do
1292 {
1293 HGCMMsgFsCreateTemp Msg;
1294 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1295 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FS_CREATE_TEMP);
1296 VbglHGCMParmPtrSet(&Msg.template_name, pszTemplate, cbTemplate);
1297 VbglHGCMParmPtrSet(&Msg.tmpdir, pszPath, cbPath);
1298 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1299 VbglHGCMParmUInt32Set(&Msg.mode, 0);
1300
1301 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1302 if (RT_SUCCESS(rc))
1303 {
1304 Msg.context.GetUInt32(&pCtx->uContextID);
1305 Msg.flags.GetUInt32(pfFlags);
1306 Msg.mode.GetUInt32(pfMode);
1307 }
1308
1309 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1310 return rc;
1311}
1312#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
1313
1314
1315/**
1316 * Retrieves a HOST_MSG_SHUTDOWN message.
1317 *
1318 * @returns VBox status code.
1319 * @param pCtx Guest control command context to use.
1320 * @param pfAction Where to store the action flags on success.
1321 */
1322VBGLR3DECL(int) VbglR3GuestCtrlGetShutdown(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *pfAction)
1323{
1324 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1325 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1326 AssertPtrReturn(pfAction, VERR_INVALID_POINTER);
1327
1328 int rc;
1329 do
1330 {
1331 HGCMMsgShutdown Msg;
1332 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1333 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_SHUTDOWN);
1334 VbglHGCMParmUInt32Set(&Msg.action, 0);
1335
1336 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1337 if (RT_SUCCESS(rc))
1338 {
1339 Msg.context.GetUInt32(&pCtx->uContextID);
1340 Msg.action.GetUInt32(pfAction);
1341 }
1342 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1343 return rc;
1344}
1345
1346/**
1347 * Initializes a process startup info, extended version.
1348 *
1349 * @returns VBox status code.
1350 * @param pStartupInfo Process startup info to initializes.
1351 * @param cbCmd Size (in bytes) to use for the command buffer.
1352 * @param cbUser Size (in bytes) to use for the user name buffer.
1353 * @param cbPassword Size (in bytes) to use for the password buffer.
1354 * @param cbDomain Size (in bytes) to use for the domain buffer.
1355 * @param cbArgs Size (in bytes) to use for the arguments buffer.
1356 * @param cbEnv Size (in bytes) to use for the environment buffer.
1357 */
1358VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInitEx(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo,
1359 size_t cbCmd,
1360 size_t cbUser, size_t cbPassword, size_t cbDomain,
1361 size_t cbArgs, size_t cbEnv)
1362{
1363 AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);
1364 AssertReturn(cbCmd, VERR_INVALID_PARAMETER);
1365 AssertReturn(cbUser, VERR_INVALID_PARAMETER);
1366 AssertReturn(cbPassword, VERR_INVALID_PARAMETER);
1367 AssertReturn(cbDomain, VERR_INVALID_PARAMETER);
1368 AssertReturn(cbArgs, VERR_INVALID_PARAMETER);
1369 AssertReturn(cbEnv, VERR_INVALID_PARAMETER);
1370
1371 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
1372
1373#define ALLOC_STR(a_Str, a_cb) \
1374 if ((a_cb) > 0) \
1375 { \
1376 pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \
1377 AssertPtrBreak(pStartupInfo->psz##a_Str); \
1378 pStartupInfo->cb##a_Str = (uint32_t)a_cb; \
1379 }
1380
1381 do
1382 {
1383 ALLOC_STR(Cmd, cbCmd);
1384 ALLOC_STR(Args, cbArgs);
1385 ALLOC_STR(Env, cbEnv);
1386 ALLOC_STR(User, cbUser);
1387 ALLOC_STR(Password, cbPassword);
1388 ALLOC_STR(Domain, cbDomain);
1389
1390 return VINF_SUCCESS;
1391
1392 } while (0);
1393
1394#undef ALLOC_STR
1395
1396 VbglR3GuestCtrlProcStartupInfoDestroy(pStartupInfo);
1397 return VERR_NO_MEMORY;
1398}
1399
1400/**
1401 * Initializes a process startup info with default values.
1402 *
1403 * @param pStartupInfo Process startup info to initializes.
1404 */
1405VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInit(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
1406{
1407 return VbglR3GuestCtrlProcStartupInfoInitEx(pStartupInfo,
1408 GUEST_PROC_DEF_CMD_LEN,
1409 GUEST_PROC_DEF_USER_LEN /* Deprecated, now handled via session creation. */,
1410 GUEST_PROC_DEF_PASSWORD_LEN /* Ditto. */,
1411 GUEST_PROC_DEF_DOMAIN_LEN /* Ditto. */,
1412 GUEST_PROC_DEF_ARGS_LEN, GUEST_PROC_DEF_ENV_LEN);
1413}
1414
1415/**
1416 * Destroys a process startup info.
1417 *
1418 * @param pStartupInfo Process startup info to destroy.
1419 */
1420VBGLR3DECL(void) VbglR3GuestCtrlProcStartupInfoDestroy(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
1421{
1422 if (!pStartupInfo)
1423 return;
1424
1425 RTStrFree(pStartupInfo->pszCmd);
1426 RTStrFree(pStartupInfo->pszArgs);
1427 RTStrFree(pStartupInfo->pszEnv);
1428 RTStrFree(pStartupInfo->pszUser);
1429 RTStrFree(pStartupInfo->pszPassword);
1430 RTStrFree(pStartupInfo->pszDomain);
1431
1432 RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
1433}
1434
1435/**
1436 * Free's a process startup info.
1437 *
1438 * @param pStartupInfo Process startup info to free.
1439 * The pointer will not be valid anymore after return.
1440 */
1441VBGLR3DECL(void) VbglR3GuestCtrlProcStartupInfoFree(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
1442{
1443 if (!pStartupInfo)
1444 return;
1445
1446 VbglR3GuestCtrlProcStartupInfoDestroy(pStartupInfo);
1447
1448 RTMemFree(pStartupInfo);
1449 pStartupInfo = NULL;
1450}
1451
1452/**
1453 * Duplicates a process startup info.
1454 *
1455 * @returns Duplicated process startup info on success, or NULL on error.
1456 * @param pStartupInfo Process startup info to duplicate.
1457 */
1458VBGLR3DECL(PVBGLR3GUESTCTRLPROCSTARTUPINFO) VbglR3GuestCtrlProcStartupInfoDup(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
1459{
1460 AssertPtrReturn(pStartupInfo, NULL);
1461
1462 PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfoDup = (PVBGLR3GUESTCTRLPROCSTARTUPINFO)
1463 RTMemDup(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
1464 if (pStartupInfoDup)
1465 {
1466 do
1467 {
1468 pStartupInfoDup->pszCmd = NULL;
1469 pStartupInfoDup->pszArgs = NULL;
1470 pStartupInfoDup->pszEnv = NULL;
1471 pStartupInfoDup->pszUser = NULL;
1472 pStartupInfoDup->pszPassword = NULL;
1473 pStartupInfoDup->pszDomain = NULL;
1474
1475#define DUP_STR(a_Str) \
1476 if (pStartupInfo->cb##a_Str) \
1477 { \
1478 pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \
1479 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \
1480 pStartupInfoDup->cb##a_Str = (uint32_t)strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \
1481 }
1482
1483#define DUP_MEM(a_Str) \
1484 if (pStartupInfo->cb##a_Str) \
1485 { \
1486 pStartupInfoDup->psz##a_Str = (char *)RTMemDup(pStartupInfo->psz##a_Str, pStartupInfo->cb##a_Str); \
1487 AssertPtrBreak(pStartupInfoDup->psz##a_Str); \
1488 pStartupInfoDup->cb##a_Str = (uint32_t)pStartupInfo->cb##a_Str; \
1489 }
1490
1491 DUP_STR(Cmd);
1492 DUP_MEM(Args);
1493 DUP_MEM(Env);
1494 DUP_STR(User);
1495 DUP_STR(Password);
1496 DUP_STR(Domain);
1497
1498#undef DUP_STR
1499#undef DUP_MEM
1500
1501 return pStartupInfoDup;
1502
1503 } while (0); /* To use break macros above. */
1504
1505 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfoDup);
1506 }
1507
1508 return NULL;
1509}
1510
1511/**
1512 * Retrieves a HOST_EXEC_CMD message.
1513 *
1514 * @returns VBox status code.
1515 * @param pCtx Guest control command context to use.
1516 * @param ppStartupInfo Where to store the allocated session startup info.
1517 * Needs to be free'd by VbglR3GuestCtrlProcStartupInfoFree().
1518 */
1519VBGLR3DECL(int) VbglR3GuestCtrlProcGetStart(PVBGLR3GUESTCTRLCMDCTX pCtx, PVBGLR3GUESTCTRLPROCSTARTUPINFO *ppStartupInfo)
1520{
1521 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1522 AssertPtrReturn(ppStartupInfo, VERR_INVALID_POINTER);
1523
1524 PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo
1525 = (PVBGLR3GUESTCTRLPROCSTARTUPINFO)RTMemAlloc(sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
1526 if (!pStartupInfo)
1527 return VERR_NO_MEMORY;
1528
1529 int rc = VbglR3GuestCtrlProcStartupInfoInit(pStartupInfo);
1530 if (RT_FAILURE(rc))
1531 {
1532 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo);
1533 return rc;
1534 }
1535
1536 unsigned cRetries = 0;
1537 const unsigned cMaxRetries = 32; /* Should be enough for now. */
1538 const unsigned cGrowthFactor = 2; /* By how much the buffers will grow if they're too small yet. */
1539
1540 do
1541 {
1542 LogRel(("VbglR3GuestCtrlProcGetStart: Retrieving\n"));
1543
1544 HGCMMsgProcExec Msg;
1545 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1546 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_CMD);
1547 VbglHGCMParmPtrSet(&Msg.cmd, pStartupInfo->pszCmd, pStartupInfo->cbCmd);
1548 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1549 VbglHGCMParmUInt32Set(&Msg.num_args, 0);
1550 VbglHGCMParmPtrSet(&Msg.args, pStartupInfo->pszArgs, pStartupInfo->cbArgs);
1551 VbglHGCMParmUInt32Set(&Msg.num_env, 0);
1552 VbglHGCMParmUInt32Set(&Msg.cb_env, 0);
1553 VbglHGCMParmPtrSet(&Msg.env, pStartupInfo->pszEnv, pStartupInfo->cbEnv);
1554 if (pCtx->uProtocol < 2)
1555 {
1556 VbglHGCMParmPtrSet(&Msg.u.v1.username, pStartupInfo->pszUser, pStartupInfo->cbUser);
1557 VbglHGCMParmPtrSet(&Msg.u.v1.password, pStartupInfo->pszPassword, pStartupInfo->cbPassword);
1558 VbglHGCMParmUInt32Set(&Msg.u.v1.timeout, 0);
1559 }
1560 else
1561 {
1562 VbglHGCMParmUInt32Set(&Msg.u.v2.timeout, 0);
1563 VbglHGCMParmUInt32Set(&Msg.u.v2.priority, 0);
1564 VbglHGCMParmUInt32Set(&Msg.u.v2.num_affinity, 0);
1565 VbglHGCMParmPtrSet(&Msg.u.v2.affinity, pStartupInfo->uAffinity, sizeof(pStartupInfo->uAffinity));
1566 }
1567
1568 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1569 if (RT_FAILURE(rc))
1570 {
1571 LogRel(("VbglR3GuestCtrlProcGetStart: 1 - %Rrc (retry %u, cbCmd=%RU32, cbArgs=%RU32, cbEnv=%RU32)\n",
1572 rc, cRetries, pStartupInfo->cbCmd, pStartupInfo->cbArgs, pStartupInfo->cbEnv));
1573
1574 if ( rc == VERR_BUFFER_OVERFLOW
1575 && cRetries++ < cMaxRetries)
1576 {
1577#define GROW_STR(a_Str, a_cbMax) \
1578 pStartupInfo->psz##a_Str = (char *)RTMemRealloc(pStartupInfo->psz##a_Str, \
1579 RT_MIN(pStartupInfo->cb##a_Str * cGrowthFactor, a_cbMax)); \
1580 AssertPtrBreakStmt(pStartupInfo->psz##a_Str, VERR_NO_MEMORY); \
1581 pStartupInfo->cb##a_Str = RT_MIN(pStartupInfo->cb##a_Str * cGrowthFactor, a_cbMax);
1582
1583 /* We can't tell which parameter doesn't fit, so we have to resize all. */
1584 GROW_STR(Cmd , GUEST_PROC_MAX_CMD_LEN);
1585 GROW_STR(Args, GUEST_PROC_MAX_ARGS_LEN);
1586 GROW_STR(Env, GUEST_PROC_MAX_ENV_LEN);
1587
1588#undef GROW_STR
1589 LogRel(("VbglR3GuestCtrlProcGetStart: 2 - %Rrc (retry %u, cbCmd=%RU32, cbArgs=%RU32, cbEnv=%RU32)\n",
1590 rc, cRetries, pStartupInfo->cbCmd, pStartupInfo->cbArgs, pStartupInfo->cbEnv));
1591 LogRel(("g_fVbglR3GuestCtrlHavePeekGetCancel=%RTbool\n", RT_BOOL(g_fVbglR3GuestCtrlHavePeekGetCancel)));
1592 }
1593 else
1594 break;
1595 }
1596 else
1597 {
1598 Msg.context.GetUInt32(&pCtx->uContextID);
1599 Msg.flags.GetUInt32(&pStartupInfo->fFlags);
1600 Msg.num_args.GetUInt32(&pStartupInfo->cArgs);
1601 Msg.num_env.GetUInt32(&pStartupInfo->cEnvVars);
1602 Msg.cb_env.GetUInt32(&pStartupInfo->cbEnv);
1603 if (pCtx->uProtocol < 2)
1604 Msg.u.v1.timeout.GetUInt32(&pStartupInfo->uTimeLimitMS);
1605 else
1606 {
1607 Msg.u.v2.timeout.GetUInt32(&pStartupInfo->uTimeLimitMS);
1608 Msg.u.v2.priority.GetUInt32(&pStartupInfo->uPriority);
1609 Msg.u.v2.num_affinity.GetUInt32(&pStartupInfo->cAffinity);
1610 }
1611 }
1612 } while (( rc == VERR_INTERRUPTED
1613 || rc == VERR_BUFFER_OVERFLOW) && g_fVbglR3GuestCtrlHavePeekGetCancel);
1614
1615 if (RT_SUCCESS(rc))
1616 {
1617 *ppStartupInfo = pStartupInfo;
1618 }
1619 else
1620 VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo);
1621
1622 LogRel(("VbglR3GuestCtrlProcGetStart: Returning %Rrc (retry %u, cbCmd=%RU32, cbArgs=%RU32, cbEnv=%RU32)\n",
1623 rc, cRetries, pStartupInfo->cbCmd, pStartupInfo->cbArgs, pStartupInfo->cbEnv));
1624
1625 LogFlowFuncLeaveRC(rc);
1626 return rc;
1627}
1628
1629/**
1630 * Allocates and gets host data, based on the message ID.
1631 *
1632 * This will block until data becomes available.
1633 *
1634 * @returns VBox status code.
1635 * @param pCtx Guest control command context to use.
1636 * @param puPID Where to return the guest PID to retrieve output from on success.
1637 * @param puHandle Where to return the guest process handle to retrieve output from on success.
1638 * @param pfFlags Where to return the output flags on success.
1639 */
1640VBGLR3DECL(int) VbglR3GuestCtrlProcGetOutput(PVBGLR3GUESTCTRLCMDCTX pCtx,
1641 uint32_t *puPID, uint32_t *puHandle, uint32_t *pfFlags)
1642{
1643 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1644 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
1645
1646 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
1647 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1648 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1649
1650 int rc;
1651 do
1652 {
1653 HGCMMsgProcOutput Msg;
1654 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1655 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_GET_OUTPUT);
1656 VbglHGCMParmUInt32Set(&Msg.pid, 0);
1657 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1658 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1659
1660 rc = VbglR3HGCMCall(&Msg.hdr, RT_UOFFSETOF(HGCMMsgProcOutput, data));
1661 if (RT_SUCCESS(rc))
1662 {
1663 Msg.context.GetUInt32(&pCtx->uContextID);
1664 Msg.pid.GetUInt32(puPID);
1665 Msg.handle.GetUInt32(puHandle);
1666 Msg.flags.GetUInt32(pfFlags);
1667 }
1668 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1669 return rc;
1670}
1671
1672
1673/**
1674 * Retrieves the input data from host which then gets sent to the started
1675 * process (HOST_EXEC_SET_INPUT).
1676 *
1677 * This will block until data becomes available.
1678 */
1679VBGLR3DECL(int) VbglR3GuestCtrlProcGetInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
1680 uint32_t *puPID, uint32_t *pfFlags,
1681 void *pvData, uint32_t cbData,
1682 uint32_t *pcbSize)
1683{
1684 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1685 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
1686
1687 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
1688 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1689 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
1690 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
1691
1692 int rc;
1693 do
1694 {
1695 HGCMMsgProcInput Msg;
1696 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1697 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_SET_INPUT);
1698 VbglHGCMParmUInt32Set(&Msg.pid, 0);
1699 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1700 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
1701 VbglHGCMParmUInt32Set(&Msg.size, 0);
1702
1703 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1704 if (RT_SUCCESS(rc))
1705 {
1706 Msg.context.GetUInt32(&pCtx->uContextID);
1707 Msg.pid.GetUInt32(puPID);
1708 Msg.flags.GetUInt32(pfFlags);
1709 Msg.size.GetUInt32(pcbSize);
1710 }
1711 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1712
1713 if ( rc != VERR_TOO_MUCH_DATA
1714 || g_fVbglR3GuestCtrlHavePeekGetCancel)
1715 return rc;
1716 return VERR_BUFFER_OVERFLOW;
1717}
1718
1719
1720#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
1721/**
1722 * Retrieves a HOST_MSG_DIR_CREATE message.
1723 *
1724 * @returns VBox status code.
1725 * @param pCtx Guest control command context to use.
1726 * @param pszPath Where to return the path.
1727 * @param cbPath Size (in bytes) of \a pszPath.
1728 * @param pfMode Where to return the creation mode.
1729 * @param pfFlags Where to return the creation flags (GSTCTL_CREATEDIRECTORY_F_XXX).
1730 */
1731VBGLR3DECL(int) VbglR3GuestCtrlDirGetCreate(PVBGLR3GUESTCTRLCMDCTX pCtx, char *pszPath, uint32_t cbPath, uint32_t *pfMode, uint32_t *pfFlags)
1732{
1733 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1734 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
1735
1736 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
1737 AssertReturn(cbPath, VERR_INVALID_PARAMETER);
1738 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1739 AssertPtrReturn(pfMode, VERR_INVALID_POINTER);
1740
1741 int rc;
1742 do
1743 {
1744 HGCMMsgDirCreate Msg;
1745 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1746 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_CREATE);
1747 VbglHGCMParmPtrSet(&Msg.path, pszPath, cbPath);
1748 VbglHGCMParmUInt32Set(&Msg.mode, 0);
1749 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1750
1751 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1752 if (RT_SUCCESS(rc))
1753 {
1754 Msg.context.GetUInt32(&pCtx->uContextID);
1755 Msg.flags.GetUInt32(pfFlags);
1756 Msg.mode.GetUInt32(pfMode);
1757 }
1758
1759 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1760 return rc;
1761}
1762#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
1763
1764
1765/**
1766 * Retrieves a HOST_DIR_REMOVE message.
1767 */
1768VBGLR3DECL(int) VbglR3GuestCtrlDirGetRemove(PVBGLR3GUESTCTRLCMDCTX pCtx,
1769 char *pszPath, uint32_t cbPath,
1770 uint32_t *pfFlags)
1771{
1772 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1773 AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
1774
1775 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
1776 AssertReturn(cbPath, VERR_INVALID_PARAMETER);
1777 AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
1778
1779 int rc;
1780 do
1781 {
1782 HGCMMsgDirRemove Msg;
1783 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1784 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_REMOVE);
1785 VbglHGCMParmPtrSet(&Msg.path, pszPath, cbPath);
1786 VbglHGCMParmUInt32Set(&Msg.flags, 0);
1787
1788 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1789 if (RT_SUCCESS(rc))
1790 {
1791 Msg.context.GetUInt32(&pCtx->uContextID);
1792 Msg.flags.GetUInt32(pfFlags);
1793 }
1794 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1795 return rc;
1796}
1797
1798
1799/**
1800 * Retrieves a HOST_FILE_OPEN message.
1801 */
1802VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
1803 char *pszFileName, uint32_t cbFileName,
1804 char *pszAccess, uint32_t cbAccess,
1805 char *pszDisposition, uint32_t cbDisposition,
1806 char *pszSharing, uint32_t cbSharing,
1807 uint32_t *puCreationMode,
1808 uint64_t *poffAt)
1809{
1810 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1811 AssertReturn(pCtx->uNumParms == 7, VERR_INVALID_PARAMETER);
1812
1813 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
1814 AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
1815 AssertPtrReturn(pszAccess, VERR_INVALID_POINTER);
1816 AssertReturn(cbAccess, VERR_INVALID_PARAMETER);
1817 AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER);
1818 AssertReturn(cbDisposition, VERR_INVALID_PARAMETER);
1819 AssertPtrReturn(pszSharing, VERR_INVALID_POINTER);
1820 AssertReturn(cbSharing, VERR_INVALID_PARAMETER);
1821 AssertPtrReturn(puCreationMode, VERR_INVALID_POINTER);
1822 AssertPtrReturn(poffAt, VERR_INVALID_POINTER);
1823
1824 int rc;
1825 do
1826 {
1827 HGCMMsgFileOpen Msg;
1828 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1829 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_OPEN);
1830 VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
1831 VbglHGCMParmPtrSet(&Msg.openmode, pszAccess, cbAccess);
1832 VbglHGCMParmPtrSet(&Msg.disposition, pszDisposition, cbDisposition);
1833 VbglHGCMParmPtrSet(&Msg.sharing, pszSharing, cbSharing);
1834 VbglHGCMParmUInt32Set(&Msg.creationmode, 0);
1835 VbglHGCMParmUInt64Set(&Msg.offset, 0);
1836
1837 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1838 if (RT_SUCCESS(rc))
1839 {
1840 Msg.context.GetUInt32(&pCtx->uContextID);
1841 Msg.creationmode.GetUInt32(puCreationMode);
1842 Msg.offset.GetUInt64(poffAt);
1843 }
1844 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1845 return rc;
1846}
1847
1848
1849/**
1850 * Retrieves a HOST_FILE_CLOSE message.
1851 */
1852VBGLR3DECL(int) VbglR3GuestCtrlFileGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
1853{
1854 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1855
1856 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
1857 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1858
1859 int rc;
1860 do
1861 {
1862 HGCMMsgFileClose Msg;
1863 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1864 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_CLOSE);
1865 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1866
1867 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1868 if (RT_SUCCESS(rc))
1869 {
1870 Msg.context.GetUInt32(&pCtx->uContextID);
1871 Msg.handle.GetUInt32(puHandle);
1872 }
1873 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1874 return rc;
1875}
1876
1877
1878/**
1879 * Retrieves a HOST_FILE_READ message.
1880 */
1881VBGLR3DECL(int) VbglR3GuestCtrlFileGetRead(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle, uint32_t *puToRead)
1882{
1883 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1884
1885 AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
1886 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1887 AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
1888
1889 int rc;
1890 do
1891 {
1892 HGCMMsgFileRead Msg;
1893 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1894 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_READ);
1895 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1896 VbglHGCMParmUInt32Set(&Msg.size, 0);
1897
1898 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1899 if (RT_SUCCESS(rc))
1900 {
1901 Msg.context.GetUInt32(&pCtx->uContextID);
1902 Msg.handle.GetUInt32(puHandle);
1903 Msg.size.GetUInt32(puToRead);
1904 }
1905 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1906 return rc;
1907}
1908
1909
1910/**
1911 * Retrieves a HOST_FILE_READ_AT message.
1912 */
1913VBGLR3DECL(int) VbglR3GuestCtrlFileGetReadAt(PVBGLR3GUESTCTRLCMDCTX pCtx,
1914 uint32_t *puHandle, uint32_t *puToRead, uint64_t *poffAt)
1915{
1916 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1917
1918 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
1919 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1920 AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
1921
1922 int rc;
1923 do
1924 {
1925 HGCMMsgFileReadAt Msg;
1926 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1927 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_READ_AT);
1928 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1929 VbglHGCMParmUInt64Set(&Msg.offset, 0);
1930 VbglHGCMParmUInt32Set(&Msg.size, 0);
1931
1932 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1933 if (RT_SUCCESS(rc))
1934 {
1935 Msg.context.GetUInt32(&pCtx->uContextID);
1936 Msg.handle.GetUInt32(puHandle);
1937 Msg.offset.GetUInt64(poffAt);
1938 Msg.size.GetUInt32(puToRead);
1939 }
1940 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1941 return rc;
1942}
1943
1944
1945/**
1946 * Retrieves a HOST_FILE_WRITE message.
1947 */
1948VBGLR3DECL(int) VbglR3GuestCtrlFileGetWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle,
1949 void *pvData, uint32_t cbData, uint32_t *pcbSize)
1950{
1951 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1952
1953 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
1954 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1955 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
1956 AssertReturn(cbData, VERR_INVALID_PARAMETER);
1957 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
1958
1959 int rc;
1960 do
1961 {
1962 HGCMMsgFileWrite Msg;
1963 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
1964 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_WRITE);
1965 VbglHGCMParmUInt32Set(&Msg.handle, 0);
1966 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
1967 VbglHGCMParmUInt32Set(&Msg.size, 0);
1968
1969 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
1970 if (RT_SUCCESS(rc))
1971 {
1972 Msg.context.GetUInt32(&pCtx->uContextID);
1973 Msg.handle.GetUInt32(puHandle);
1974 Msg.size.GetUInt32(pcbSize);
1975 }
1976 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
1977
1978 if ( rc != VERR_TOO_MUCH_DATA
1979 || g_fVbglR3GuestCtrlHavePeekGetCancel)
1980 return rc;
1981 return VERR_BUFFER_OVERFLOW;
1982}
1983
1984
1985/**
1986 * Retrieves a HOST_FILE_WRITE_AT message.
1987 */
1988VBGLR3DECL(int) VbglR3GuestCtrlFileGetWriteAt(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle,
1989 void *pvData, uint32_t cbData, uint32_t *pcbSize, uint64_t *poffAt)
1990{
1991 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
1992
1993 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
1994 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
1995 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
1996 AssertReturn(cbData, VERR_INVALID_PARAMETER);
1997 AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
1998
1999 int rc;
2000 do
2001 {
2002 HGCMMsgFileWriteAt Msg;
2003 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2004 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_WRITE_AT);
2005 VbglHGCMParmUInt32Set(&Msg.handle, 0);
2006 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
2007 VbglHGCMParmUInt32Set(&Msg.size, 0);
2008 VbglHGCMParmUInt64Set(&Msg.offset, 0);
2009
2010 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2011 if (RT_SUCCESS(rc))
2012 {
2013 Msg.context.GetUInt32(&pCtx->uContextID);
2014 Msg.handle.GetUInt32(puHandle);
2015 Msg.size.GetUInt32(pcbSize);
2016 Msg.offset.GetUInt64(poffAt);
2017 }
2018 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2019
2020 if ( rc != VERR_TOO_MUCH_DATA
2021 || g_fVbglR3GuestCtrlHavePeekGetCancel)
2022 return rc;
2023 return VERR_BUFFER_OVERFLOW;
2024}
2025
2026
2027/**
2028 * Retrieves a HOST_FILE_SEEK message.
2029 */
2030VBGLR3DECL(int) VbglR3GuestCtrlFileGetSeek(PVBGLR3GUESTCTRLCMDCTX pCtx,
2031 uint32_t *puHandle, uint32_t *puSeekMethod, uint64_t *poffAt)
2032{
2033 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2034
2035 AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
2036 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
2037 AssertPtrReturn(puSeekMethod, VERR_INVALID_POINTER);
2038 AssertPtrReturn(poffAt, VERR_INVALID_POINTER);
2039
2040 int rc;
2041 do
2042 {
2043 HGCMMsgFileSeek Msg;
2044 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2045 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_SEEK);
2046 VbglHGCMParmUInt32Set(&Msg.handle, 0);
2047 VbglHGCMParmUInt32Set(&Msg.method, 0);
2048 VbglHGCMParmUInt64Set(&Msg.offset, 0);
2049
2050 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2051 if (RT_SUCCESS(rc))
2052 {
2053 Msg.context.GetUInt32(&pCtx->uContextID);
2054 Msg.handle.GetUInt32(puHandle);
2055 Msg.method.GetUInt32(puSeekMethod);
2056 Msg.offset.GetUInt64(poffAt);
2057 }
2058 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2059 return rc;
2060}
2061
2062
2063/**
2064 * Retrieves a HOST_FILE_TELL message.
2065 */
2066VBGLR3DECL(int) VbglR3GuestCtrlFileGetTell(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
2067{
2068 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2069
2070 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
2071 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
2072
2073 int rc;
2074 do
2075 {
2076 HGCMMsgFileTell Msg;
2077 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2078 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_TELL);
2079 VbglHGCMParmUInt32Set(&Msg.handle, 0);
2080
2081 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2082 if (RT_SUCCESS(rc))
2083 {
2084 Msg.context.GetUInt32(&pCtx->uContextID);
2085 Msg.handle.GetUInt32(puHandle);
2086 }
2087 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2088 return rc;
2089}
2090
2091
2092/**
2093 * Retrieves a HOST_FILE_SET_SIZE message.
2094 */
2095VBGLR3DECL(int) VbglR3GuestCtrlFileGetSetSize(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle, uint64_t *pcbNew)
2096{
2097 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2098
2099 AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
2100 AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
2101 AssertPtrReturn(pcbNew, VERR_INVALID_POINTER);
2102
2103 int rc;
2104 do
2105 {
2106 HGCMMsgFileSetSize Msg;
2107 VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2108 VbglHGCMParmUInt32Set(&Msg.id32Context, HOST_MSG_FILE_SET_SIZE);
2109 VbglHGCMParmUInt32Set(&Msg.id32Handle, 0);
2110 VbglHGCMParmUInt64Set(&Msg.cb64NewSize, 0);
2111
2112 rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
2113 if (RT_SUCCESS(rc))
2114 {
2115 Msg.id32Context.GetUInt32(&pCtx->uContextID);
2116 Msg.id32Handle.GetUInt32(puHandle);
2117 Msg.cb64NewSize.GetUInt64(pcbNew);
2118 }
2119 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2120 return rc;
2121}
2122
2123
2124#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
2125VBGLR3DECL(int) VbglR3GuestCtrlFileGetRemove(PVBGLR3GUESTCTRLCMDCTX pCtx, char *pszFileName, uint32_t cbFileName)
2126{
2127 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2128
2129 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
2130 AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
2131 AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
2132
2133 int rc;
2134 do
2135 {
2136 HGCMMsgFileRemove Msg;
2137 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2138 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_REMOVE);
2139 VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
2140
2141 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2142 if (RT_SUCCESS(rc))
2143 {
2144 Msg.context.GetUInt32(&pCtx->uContextID);
2145 }
2146 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2147 return rc;
2148}
2149#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
2150
2151
2152/**
2153 * Retrieves a HOST_EXEC_TERMINATE message.
2154 */
2155VBGLR3DECL(int) VbglR3GuestCtrlProcGetTerminate(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puPID)
2156{
2157 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2158
2159 AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
2160 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
2161
2162 int rc;
2163 do
2164 {
2165 HGCMMsgProcTerminate Msg;
2166 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2167 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_TERMINATE);
2168 VbglHGCMParmUInt32Set(&Msg.pid, 0);
2169
2170 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2171 if (RT_SUCCESS(rc))
2172 {
2173 Msg.context.GetUInt32(&pCtx->uContextID);
2174 Msg.pid.GetUInt32(puPID);
2175 }
2176 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2177 return rc;
2178}
2179
2180
2181/**
2182 * Retrieves a HOST_EXEC_WAIT_FOR message.
2183 */
2184VBGLR3DECL(int) VbglR3GuestCtrlProcGetWaitFor(PVBGLR3GUESTCTRLCMDCTX pCtx,
2185 uint32_t *puPID, uint32_t *puWaitFlags, uint32_t *puTimeoutMS)
2186{
2187 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2188
2189 AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
2190 AssertPtrReturn(puPID, VERR_INVALID_POINTER);
2191
2192 int rc;
2193 do
2194 {
2195 HGCMMsgProcWaitFor Msg;
2196 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
2197 VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_WAIT_FOR);
2198 VbglHGCMParmUInt32Set(&Msg.pid, 0);
2199 VbglHGCMParmUInt32Set(&Msg.flags, 0);
2200 VbglHGCMParmUInt32Set(&Msg.timeout, 0);
2201
2202 rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2203 if (RT_SUCCESS(rc))
2204 {
2205 Msg.context.GetUInt32(&pCtx->uContextID);
2206 Msg.pid.GetUInt32(puPID);
2207 Msg.flags.GetUInt32(puWaitFlags);
2208 Msg.timeout.GetUInt32(puTimeoutMS);
2209 }
2210 } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
2211 return rc;
2212}
2213
2214
2215/*********************************************************************************************************************************
2216 * Directory callbacks *
2217 ********************************************************************************************************************************/
2218
2219#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
2220/**
2221 * Replies to a HOST_MSG_DIR_OPEN message.
2222 *
2223 * @returns VBox status code.
2224 * @param pCtx Guest control command context to use.
2225 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2226 * @param uDirHandle Directory handle of opened directory.
2227 */
2228VBGLR3DECL(int) VbglR3GuestCtrlDirCbOpen(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t uDirHandle)
2229{
2230 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2231
2232 HGCMReplyDirNotify Msg;
2233 VBGL_HGCM_HDR_INIT(&Msg.reply_hdr.hdr, pCtx->uClientID, GUEST_MSG_DIR_NOTIFY, GSTCTL_HGCM_REPLY_HDR_PARMS + 1);
2234 VbglHGCMParmUInt32Set(&Msg.reply_hdr.context, pCtx->uContextID);
2235 VbglHGCMParmUInt32Set(&Msg.reply_hdr.type, GUEST_DIR_NOTIFYTYPE_OPEN);
2236 VbglHGCMParmUInt32Set(&Msg.reply_hdr.rc, uRc);
2237
2238 VbglHGCMParmUInt32Set(&Msg.u.open.handle, uDirHandle);
2239
2240 return VbglR3HGCMCall(&Msg.reply_hdr.hdr, RT_UOFFSET_AFTER(HGCMReplyDirNotify, u.open));
2241}
2242
2243
2244/**
2245 * Replies to a HOST_MSG_DIR_CLOSE message.
2246 *
2247 * @returns VBox status code.
2248 * @param pCtx Guest control command context to use.
2249 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2250 */
2251VBGLR3DECL(int) VbglR3GuestCtrlDirCbClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc)
2252{
2253 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2254
2255 HGCMReplyDirNotify Msg;
2256 VBGL_HGCM_HDR_INIT(&Msg.reply_hdr.hdr, pCtx->uClientID, GUEST_MSG_DIR_NOTIFY, GSTCTL_HGCM_REPLY_HDR_PARMS);
2257 VbglHGCMParmUInt32Set(&Msg.reply_hdr.context, pCtx->uContextID);
2258 VbglHGCMParmUInt32Set(&Msg.reply_hdr.type, GUEST_DIR_NOTIFYTYPE_CLOSE);
2259 VbglHGCMParmUInt32Set(&Msg.reply_hdr.rc, uRc);
2260
2261 return VbglR3HGCMCall(&Msg.reply_hdr.hdr, RT_UOFFSET_AFTER(HGCMReplyDirNotify, reply_hdr));
2262}
2263
2264
2265/**
2266 * Replies to a HOST_MSG_DIR_READ message, extended version.
2267 *
2268 * @returns VBox status code.
2269 * @param pCtx Guest control command context to use.
2270 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2271 * @param pEntry Directory entry to send.
2272 * @param cbSize Size (in bytes) of the OFFSET(GSTCTLDIRENTRYEX, szName[pEntry->cbName + 1]).
2273 * See RTDirReadEx() for more information.
2274 * @param pszUser Associated user ID (owner, uid) as a string.
2275 * @param pszGroups Associated user groups as a string.
2276 * Multiple groups are delimited by "\r\n", whereas the first group always is the primary group.
2277 */
2278VBGLR3DECL(int) VbglR3GuestCtrlDirCbReadEx(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, PGSTCTLDIRENTRYEX pEntry, uint32_t cbSize,
2279 const char *pszUser, const char *pszGroups)
2280{
2281 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2282 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
2283 AssertPtrReturn(pszGroups, VERR_INVALID_POINTER);
2284
2285 HGCMReplyDirNotify Msg;
2286 VBGL_HGCM_HDR_INIT(&Msg.reply_hdr.hdr, pCtx->uClientID, GUEST_MSG_DIR_NOTIFY, GSTCTL_HGCM_REPLY_HDR_PARMS + 3);
2287 VbglHGCMParmUInt32Set(&Msg.reply_hdr.context, pCtx->uContextID);
2288 VbglHGCMParmUInt32Set(&Msg.reply_hdr.type, GUEST_DIR_NOTIFYTYPE_READ);
2289 VbglHGCMParmUInt32Set(&Msg.reply_hdr.rc, uRc);
2290
2291 VbglHGCMParmPtrSet (&Msg.u.read.entry, pEntry, cbSize);
2292 VbglHGCMParmPtrSetString(&Msg.u.read.user, pszUser);
2293 VbglHGCMParmPtrSetString(&Msg.u.read.groups, pszGroups);
2294
2295 return VbglR3HGCMCall(&Msg.reply_hdr.hdr, RT_UOFFSET_AFTER(HGCMReplyDirNotify, u.read));
2296}
2297
2298
2299/**
2300 * Replies to a HOST_MSG_DIR_READ message.
2301 *
2302 * @returns VBox status code.
2303 * @param pCtx Guest control command context to use.
2304 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2305 * @param pEntry Directory entry to send.
2306 * @param cbSize Size (in bytes) of the OFFSET(GSTCTLDIRENTRYEX, szName[pEntry->cbName + 1]).
2307 * See RTDirReadEx() for more information.
2308 */
2309VBGLR3DECL(int) VbglR3GuestCtrlDirCbRead(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, PGSTCTLDIRENTRYEX pEntry, uint32_t cbSize)
2310{
2311 char szIgnored[1] = { 0 };
2312 return VbglR3GuestCtrlDirCbReadEx(pCtx, uRc, pEntry, cbSize, szIgnored /* pszUser */, szIgnored /* pszGroups */);
2313}
2314
2315
2316/**
2317 * Replies to a HOST_MSG_DIR_REWIND message.
2318 *
2319 * @returns VBox status code.
2320 * @param pCtx Guest control command context to use.
2321 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2322 */
2323VBGLR3DECL(int) VbglR3GuestCtrlDirCbRewind(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc)
2324{
2325 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2326
2327 HGCMReplyDirNotify Msg;
2328 VBGL_HGCM_HDR_INIT(&Msg.reply_hdr.hdr, pCtx->uClientID, GUEST_MSG_DIR_NOTIFY, GSTCTL_HGCM_REPLY_HDR_PARMS);
2329 VbglHGCMParmUInt32Set(&Msg.reply_hdr.context, pCtx->uContextID);
2330 VbglHGCMParmUInt32Set(&Msg.reply_hdr.type, GUEST_DIR_NOTIFYTYPE_REWIND);
2331 VbglHGCMParmUInt32Set(&Msg.reply_hdr.rc, uRc);
2332
2333 return VbglR3HGCMCall(&Msg.reply_hdr.hdr, RT_UOFFSET_AFTER(HGCMReplyDirNotify, u));
2334}
2335#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
2336
2337
2338/*********************************************************************************************************************************
2339 * File callbacks *
2340 ********************************************************************************************************************************/
2341
2342/**
2343 * Replies to a HOST_MSG_FILE_OPEN message.
2344 *
2345 * @returns VBox status code.
2346 * @param pCtx Guest control command context to use.
2347 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2348 * @param uFileHandle File handle of opened file on success.
2349 */
2350VBGLR3DECL(int) VbglR3GuestCtrlFileCbOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
2351 uint32_t uRc, uint32_t uFileHandle)
2352{
2353 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2354
2355 HGCMReplyFileNotify Msg;
2356 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
2357 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2358 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_OPEN);
2359 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2360 VbglHGCMParmUInt32Set(&Msg.u.open.handle, uFileHandle);
2361
2362 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.open));
2363}
2364
2365
2366/**
2367 * Replies to a HOST_MSG_FILE_CLOSE message.
2368 *
2369 * @returns VBox status code.
2370 * @param pCtx Guest control command context to use.
2371 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2372 */
2373VBGLR3DECL(int) VbglR3GuestCtrlFileCbClose(PVBGLR3GUESTCTRLCMDCTX pCtx,
2374 uint32_t uRc)
2375{
2376 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2377
2378 HGCMReplyFileNotify Msg;
2379 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 3);
2380 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2381 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_CLOSE);
2382 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2383
2384 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSETOF(HGCMReplyFileNotify, u));
2385}
2386
2387
2388/**
2389 * Sends an unexpected file handling error to the host.
2390 *
2391 * @returns VBox status code.
2392 * @param pCtx Guest control command context to use.
2393 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2394 */
2395VBGLR3DECL(int) VbglR3GuestCtrlFileCbError(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc)
2396{
2397 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2398
2399 HGCMReplyFileNotify Msg;
2400 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 3);
2401 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2402 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_ERROR);
2403 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2404
2405 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSETOF(HGCMReplyFileNotify, u));
2406}
2407
2408
2409/**
2410 * Replies to a HOST_MSG_FILE_READ message.
2411 *
2412 * @returns VBox status code.
2413 * @param pCtx Guest control command context to use.
2414 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2415 * @param pvData Pointer to read file data from guest on success.
2416 * @param cbData Size (in bytes) of read file data from guest on success.
2417 */
2418VBGLR3DECL(int) VbglR3GuestCtrlFileCbRead(PVBGLR3GUESTCTRLCMDCTX pCtx,
2419 uint32_t uRc,
2420 void *pvData, uint32_t cbData)
2421{
2422 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2423
2424 HGCMReplyFileNotify Msg;
2425 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
2426 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2427 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_READ);
2428 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2429 VbglHGCMParmPtrSet(&Msg.u.read.data, pvData, cbData);
2430
2431 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.read));
2432}
2433
2434
2435/**
2436 * Replies to a HOST_MSG_FILE_READ_AT message.
2437 *
2438 * @returns VBox status code.
2439 * @param pCtx Guest control command context to use.
2440 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2441 * @param pvData Pointer to read file data from guest on success.
2442 * @param cbData Size (in bytes) of read file data from guest on success.
2443 * @param offNew New offset (in bytes) the guest file pointer points at on success.
2444 */
2445VBGLR3DECL(int) VbglR3GuestCtrlFileCbReadOffset(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc,
2446 void *pvData, uint32_t cbData, int64_t offNew)
2447{
2448 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2449
2450 HGCMReplyFileNotify Msg;
2451 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 5);
2452 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2453 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_READ_OFFSET);
2454 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2455 VbglHGCMParmPtrSet(&Msg.u.ReadOffset.pvData, pvData, cbData);
2456 VbglHGCMParmUInt64Set(&Msg.u.ReadOffset.off64New, (uint64_t)offNew);
2457
2458 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.ReadOffset));
2459}
2460
2461
2462/**
2463 * Replies to a HOST_MSG_FILE_WRITE message.
2464 *
2465 * @returns VBox status code.
2466 * @param pCtx Guest control command context to use.
2467 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2468 * @param cbWritten Size (in bytes) of file data successfully written to guest file. Can be partial.
2469 */
2470VBGLR3DECL(int) VbglR3GuestCtrlFileCbWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t cbWritten)
2471{
2472 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2473
2474 HGCMReplyFileNotify Msg;
2475 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
2476 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2477 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_WRITE);
2478 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2479 VbglHGCMParmUInt32Set(&Msg.u.write.written, cbWritten);
2480
2481 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.write));
2482}
2483
2484
2485/**
2486 * Replies to a HOST_MSG_FILE_WRITE_AT message.
2487 *
2488 * @returns VBox status code.
2489 * @param pCtx Guest control command context to use.
2490 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2491 * @param cbWritten Size (in bytes) of file data successfully written to guest file. Can be partial.
2492 * @param offNew New offset (in bytes) the guest file pointer points at on success.
2493 */
2494VBGLR3DECL(int) VbglR3GuestCtrlFileCbWriteOffset(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t cbWritten, int64_t offNew)
2495{
2496 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2497
2498 HGCMReplyFileNotify Msg;
2499 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 5);
2500 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2501 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_WRITE_OFFSET);
2502 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2503 VbglHGCMParmUInt32Set(&Msg.u.WriteOffset.cb32Written, cbWritten);
2504 VbglHGCMParmUInt64Set(&Msg.u.WriteOffset.off64New, (uint64_t)offNew);
2505
2506 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.WriteOffset));
2507}
2508
2509
2510/**
2511 * Replies to a HOST_MSG_FILE_SEEK message.
2512 *
2513 * @returns VBox status code.
2514 * @param pCtx Guest control command context to use.
2515 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2516 * @param offCurrent New offset (in bytes) the guest file pointer points at on success.
2517 */
2518VBGLR3DECL(int) VbglR3GuestCtrlFileCbSeek(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t offCurrent)
2519{
2520 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2521
2522 HGCMReplyFileNotify Msg;
2523 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
2524 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2525 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SEEK);
2526 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2527 VbglHGCMParmUInt64Set(&Msg.u.seek.offset, offCurrent);
2528
2529 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.seek));
2530}
2531
2532
2533/**
2534 * Replies to a HOST_MSG_FILE_TELL message.
2535 *
2536 * @returns VBox status code.
2537 * @param pCtx Guest control command context to use.
2538 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2539 * @param offCurrent Current offset (in bytes) the guest file pointer points at on success.
2540 */
2541VBGLR3DECL(int) VbglR3GuestCtrlFileCbTell(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t offCurrent)
2542{
2543 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2544
2545 HGCMReplyFileNotify Msg;
2546 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
2547 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2548 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_TELL);
2549 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2550 VbglHGCMParmUInt64Set(&Msg.u.tell.offset, offCurrent);
2551
2552 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.tell));
2553}
2554
2555
2556/**
2557 * Replies to a HOST_MSG_FILE_SET_SIZE message.
2558 *
2559 * @returns VBox status code.
2560 * @param pCtx Guest control command context to use.
2561 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2562 * @param cbNew New file size (in bytes) of the guest file on success.
2563 */
2564VBGLR3DECL(int) VbglR3GuestCtrlFileCbSetSize(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t cbNew)
2565{
2566 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2567
2568 HGCMReplyFileNotify Msg;
2569 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
2570 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2571 VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SET_SIZE);
2572 VbglHGCMParmUInt32Set(&Msg.rc, uRc);
2573 VbglHGCMParmUInt64Set(&Msg.u.SetSize.cb64Size, cbNew);
2574
2575 return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.SetSize));
2576}
2577
2578
2579/*********************************************************************************************************************************
2580 * File system callbacks *
2581 ********************************************************************************************************************************/
2582
2583#ifdef VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS
2584/**
2585 * Replies to a HOST_MSG_FS_QUERY_INFO message, extended version.
2586 *
2587 * @returns VBox status code.
2588 * @param pCtx Guest control command context to use.
2589 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2590 * @param pFsObjInfo Guest file system object information to send.
2591 * @param pszUser Associated user ID (owner, uid) as a string.
2592 * @param pszGroups Associated user groups as a string.
2593 * Multiple groups are delimited by "\r\n", whereas the first group always is the primary group.
2594 */
2595VBGLR3DECL(int) VbglR3GuestCtrlFsCbQueryInfoEx(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, PGSTCTLFSOBJINFO pFsObjInfo,
2596 const char *pszUser, const char *pszGroups)
2597{
2598 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2599 AssertPtrReturn(pFsObjInfo, VERR_INVALID_POINTER);
2600 AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
2601 AssertPtrReturn(pszGroups, VERR_INVALID_POINTER);
2602
2603 HGCMReplyFsNotify Msg;
2604 VBGL_HGCM_HDR_INIT(&Msg.reply_hdr.hdr, pCtx->uClientID, GUEST_MSG_FS_NOTIFY, GSTCTL_HGCM_REPLY_HDR_PARMS + 3);
2605 VbglHGCMParmUInt32Set(&Msg.reply_hdr.context, pCtx->uContextID);
2606 VbglHGCMParmUInt32Set(&Msg.reply_hdr.type, GUEST_FS_NOTIFYTYPE_QUERY_INFO);
2607 VbglHGCMParmUInt32Set(&Msg.reply_hdr.rc, uRc);
2608
2609 VbglHGCMParmPtrSet (&Msg.u.queryinfo.obj_info, pFsObjInfo, sizeof(GSTCTLFSOBJINFO));
2610 VbglHGCMParmPtrSetString(&Msg.u.queryinfo.user, pszUser);
2611 VbglHGCMParmPtrSetString(&Msg.u.queryinfo.groups, pszGroups);
2612
2613 return VbglR3HGCMCall(&Msg.reply_hdr.hdr, RT_UOFFSET_AFTER(HGCMReplyFsNotify, u.queryinfo));
2614}
2615
2616
2617/**
2618 * Replies to a HOST_MSG_FS_QUERY_INFO message.
2619 *
2620 * @returns VBox status code.
2621 * @param pCtx Guest control command context to use.
2622 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2623 * @param pFsObjInfo Guest file system object information to send.
2624 */
2625VBGLR3DECL(int) VbglR3GuestCtrlFsCbQueryInfo(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, PGSTCTLFSOBJINFO pFsObjInfo)
2626{
2627 char szIgnored[1] = { 0 };
2628 return VbglR3GuestCtrlFsCbQueryInfoEx(pCtx, uRc, pFsObjInfo, szIgnored /* pszUser */, szIgnored /* pszGroups */);
2629}
2630
2631
2632/**
2633 * Replies to a HOST_MSG_FS_CREATE_TEMP message.
2634 *
2635 * @returns VBox status code.
2636 * @param pCtx Guest control command context to use.
2637 * @param uRc Guest rc of operation (note: IPRT-style signed int).
2638 * @param pszPath Path of created temporary file / directory, if \a uRc marks a success.
2639 * Specify an empty path on failure -- NULL is not allowed!
2640 */
2641VBGLR3DECL(int) VbglR3GuestCtrlFsCbCreateTemp(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, const char *pszPath)
2642{
2643 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2644 AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
2645
2646 HGCMReplyFsNotify Msg;
2647 VBGL_HGCM_HDR_INIT(&Msg.reply_hdr.hdr, pCtx->uClientID, GUEST_MSG_FS_NOTIFY, GSTCTL_HGCM_REPLY_HDR_PARMS + 1);
2648 VbglHGCMParmUInt32Set(&Msg.reply_hdr.context, pCtx->uContextID);
2649 VbglHGCMParmUInt32Set(&Msg.reply_hdr.type, GUEST_FS_NOTIFYTYPE_CREATE_TEMP);
2650 VbglHGCMParmUInt32Set(&Msg.reply_hdr.rc, uRc);
2651
2652 VbglHGCMParmPtrSetString(&Msg.u.createtemp.path, pszPath);
2653
2654 return VbglR3HGCMCall(&Msg.reply_hdr.hdr, RT_UOFFSET_AFTER(HGCMReplyFsNotify, u.createtemp));
2655}
2656#endif /* VBOX_WITH_GSTCTL_TOOLBOX_AS_CMDS */
2657
2658
2659/*********************************************************************************************************************************
2660 * Process callbacks *
2661 ********************************************************************************************************************************/
2662
2663/**
2664 * Callback for reporting a guest process status (along with some other stuff) to the host.
2665 *
2666 * @returns VBox status code.
2667 * @param pCtx Guest control command context to use.
2668 * @param uPID Guest process PID to report status for.
2669 * @param uStatus Status to report. Of type PROC_STS_XXX.
2670 * @param fFlags Additional status flags, depending on the reported status. See RTPROCSTATUS.
2671 * @param pvData Pointer to additional status data. Optional.
2672 * @param cbData Size (in bytes) of additional status data.
2673 */
2674VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatus(PVBGLR3GUESTCTRLCMDCTX pCtx,
2675 uint32_t uPID, uint32_t uStatus, uint32_t fFlags,
2676 void *pvData, uint32_t cbData)
2677{
2678 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2679
2680 HGCMMsgProcStatus Msg;
2681 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_EXEC_STATUS, 5);
2682 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2683 VbglHGCMParmUInt32Set(&Msg.pid, uPID);
2684 VbglHGCMParmUInt32Set(&Msg.status, uStatus);
2685 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
2686 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
2687
2688 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2689}
2690
2691
2692/**
2693 * Sends output (from stdout/stderr) from a running process.
2694 *
2695 * @returns VBox status code.
2696 * @param pCtx Guest control command context to use.
2697 * @param uPID Guest process PID to report status for.
2698 * @param uHandle Guest process handle the output belong to.
2699 * @param fFlags Additional output flags.
2700 * @param pvData Pointer to actual output data.
2701 * @param cbData Size (in bytes) of output data.
2702 */
2703VBGLR3DECL(int) VbglR3GuestCtrlProcCbOutput(PVBGLR3GUESTCTRLCMDCTX pCtx,
2704 uint32_t uPID,uint32_t uHandle, uint32_t fFlags,
2705 void *pvData, uint32_t cbData)
2706{
2707 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2708
2709 HGCMMsgProcOutput Msg;
2710 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_EXEC_OUTPUT, 5);
2711 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2712 VbglHGCMParmUInt32Set(&Msg.pid, uPID);
2713 VbglHGCMParmUInt32Set(&Msg.handle, uHandle);
2714 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
2715 VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
2716
2717 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2718}
2719
2720
2721/**
2722 * Callback for reporting back the input status of a guest process to the host.
2723 *
2724 * @returns VBox status code.
2725 * @param pCtx Guest control command context to use.
2726 * @param uPID Guest process PID to report status for.
2727 * @param uStatus Status to report. Of type INPUT_STS_XXX.
2728 * @param fFlags Additional input flags.
2729 * @param cbWritten Size (in bytes) of input data handled.
2730 */
2731VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatusInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
2732 uint32_t uPID, uint32_t uStatus,
2733 uint32_t fFlags, uint32_t cbWritten)
2734{
2735 AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
2736
2737 HGCMMsgProcStatusInput Msg;
2738 VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_EXEC_INPUT_STATUS, 5);
2739 VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
2740 VbglHGCMParmUInt32Set(&Msg.pid, uPID);
2741 VbglHGCMParmUInt32Set(&Msg.status, uStatus);
2742 VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
2743 VbglHGCMParmUInt32Set(&Msg.written, cbWritten);
2744
2745 return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
2746}
2747
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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