1 | /* $Id: VBoxGuestR3LibGuestCtrl.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, guest control.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2022 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.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 |
|
---|
61 | using namespace guestControl;
|
---|
62 |
|
---|
63 |
|
---|
64 | /*********************************************************************************************************************************
|
---|
65 | * Global Variables *
|
---|
66 | *********************************************************************************************************************************/
|
---|
67 | /** Set if GUEST_MSG_PEEK_WAIT and friends are supported. */
|
---|
68 | static 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 | */
|
---|
78 | VBGLR3DECL(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 | */
|
---|
90 | VBGLR3DECL(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 | */
|
---|
106 | static 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 | */
|
---|
179 | DECL_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 | */
|
---|
274 | DECLINLINE(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 | */
|
---|
286 | DECLINLINE(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 | */
|
---|
300 | VBGLR3DECL(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 | */
|
---|
312 | VBGLR3DECL(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 | */
|
---|
333 | VBGLR3DECL(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 | */
|
---|
372 | VBGLR3DECL(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 | */
|
---|
421 | VBGLR3DECL(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 | */
|
---|
509 | VBGLR3DECL(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 | */
|
---|
531 | VBGLR3DECL(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 | */
|
---|
549 | VBGLR3DECL(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 | */
|
---|
574 | VBGLR3DECL(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 | */
|
---|
602 | VBGLR3DECL(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 | */
|
---|
619 | VBGLR3DECL(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 | */
|
---|
632 | VBGLR3DECL(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 | */
|
---|
657 | VBGLR3DECL(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 | */
|
---|
682 | VBGLR3DECL(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 | */
|
---|
707 | VBGLR3DECL(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 | */
|
---|
724 | VBGLR3DECL(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 | */
|
---|
746 | VBGLR3DECL(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 | */
|
---|
768 | VBGLR3DECL(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 | */
|
---|
805 | VBGLR3DECL(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 | */
|
---|
817 | VBGLR3DECL(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 | */
|
---|
835 | VBGLR3DECL(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 | */
|
---|
852 | VBGLR3DECL(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 | */
|
---|
897 | VBGLR3DECL(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 | */
|
---|
953 | VBGLR3DECL(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 | /**
|
---|
983 | * Retrieves a HOST_PATH_RENAME message.
|
---|
984 | */
|
---|
985 | VBGLR3DECL(int) VbglR3GuestCtrlPathGetRename(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
986 | char *pszSource, uint32_t cbSource,
|
---|
987 | char *pszDest, uint32_t cbDest,
|
---|
988 | uint32_t *pfFlags)
|
---|
989 | {
|
---|
990 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
991 | AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
|
---|
992 |
|
---|
993 | AssertPtrReturn(pszSource, VERR_INVALID_POINTER);
|
---|
994 | AssertReturn(cbSource, VERR_INVALID_PARAMETER);
|
---|
995 | AssertPtrReturn(pszDest, VERR_INVALID_POINTER);
|
---|
996 | AssertReturn(cbDest, VERR_INVALID_PARAMETER);
|
---|
997 | AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
|
---|
998 |
|
---|
999 | int rc;
|
---|
1000 | do
|
---|
1001 | {
|
---|
1002 | HGCMMsgPathRename Msg;
|
---|
1003 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1004 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_PATH_RENAME);
|
---|
1005 | VbglHGCMParmPtrSet(&Msg.source, pszSource, cbSource);
|
---|
1006 | VbglHGCMParmPtrSet(&Msg.dest, pszDest, cbDest);
|
---|
1007 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
1008 |
|
---|
1009 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1010 | if (RT_SUCCESS(rc))
|
---|
1011 | {
|
---|
1012 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1013 | Msg.flags.GetUInt32(pfFlags);
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1017 | return rc;
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 |
|
---|
1021 | /**
|
---|
1022 | * Retrieves a HOST_PATH_USER_DOCUMENTS message.
|
---|
1023 | */
|
---|
1024 | VBGLR3DECL(int) VbglR3GuestCtrlPathGetUserDocuments(PVBGLR3GUESTCTRLCMDCTX pCtx)
|
---|
1025 | {
|
---|
1026 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1027 | AssertReturn(pCtx->uNumParms == 1, VERR_INVALID_PARAMETER);
|
---|
1028 |
|
---|
1029 | int rc;
|
---|
1030 | do
|
---|
1031 | {
|
---|
1032 | HGCMMsgPathUserDocuments Msg;
|
---|
1033 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1034 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_PATH_USER_DOCUMENTS);
|
---|
1035 |
|
---|
1036 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1037 | if (RT_SUCCESS(rc))
|
---|
1038 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1039 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1040 | return rc;
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 |
|
---|
1044 | /**
|
---|
1045 | * Retrieves a HOST_PATH_USER_HOME message.
|
---|
1046 | */
|
---|
1047 | VBGLR3DECL(int) VbglR3GuestCtrlPathGetUserHome(PVBGLR3GUESTCTRLCMDCTX pCtx)
|
---|
1048 | {
|
---|
1049 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1050 | AssertReturn(pCtx->uNumParms == 1, VERR_INVALID_PARAMETER);
|
---|
1051 |
|
---|
1052 | int rc;
|
---|
1053 | do
|
---|
1054 | {
|
---|
1055 | HGCMMsgPathUserHome Msg;
|
---|
1056 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1057 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_PATH_USER_HOME);
|
---|
1058 |
|
---|
1059 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1060 | if (RT_SUCCESS(rc))
|
---|
1061 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1062 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1063 | return rc;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | /**
|
---|
1067 | * Retrieves a HOST_MSG_SHUTDOWN message.
|
---|
1068 | *
|
---|
1069 | * @returns VBox status code.
|
---|
1070 | * @param pCtx Guest control command context to use.
|
---|
1071 | * @param pfAction Where to store the action flags on success.
|
---|
1072 | */
|
---|
1073 | VBGLR3DECL(int) VbglR3GuestCtrlGetShutdown(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *pfAction)
|
---|
1074 | {
|
---|
1075 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1076 | AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
|
---|
1077 | AssertPtrReturn(pfAction, VERR_INVALID_POINTER);
|
---|
1078 |
|
---|
1079 | int rc;
|
---|
1080 | do
|
---|
1081 | {
|
---|
1082 | HGCMMsgShutdown Msg;
|
---|
1083 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1084 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_SHUTDOWN);
|
---|
1085 | VbglHGCMParmUInt32Set(&Msg.action, 0);
|
---|
1086 |
|
---|
1087 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1088 | if (RT_SUCCESS(rc))
|
---|
1089 | {
|
---|
1090 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1091 | Msg.action.GetUInt32(pfAction);
|
---|
1092 | }
|
---|
1093 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1094 | return rc;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | /**
|
---|
1098 | * Initializes a process startup info, extended version.
|
---|
1099 | *
|
---|
1100 | * @returns VBox status code.
|
---|
1101 | * @param pStartupInfo Process startup info to initializes.
|
---|
1102 | * @param cbCmd Size (in bytes) to use for the command buffer.
|
---|
1103 | * @param cbUser Size (in bytes) to use for the user name buffer.
|
---|
1104 | * @param cbPassword Size (in bytes) to use for the password buffer.
|
---|
1105 | * @param cbDomain Size (in bytes) to use for the domain buffer.
|
---|
1106 | * @param cbArgs Size (in bytes) to use for the arguments buffer.
|
---|
1107 | * @param cbEnv Size (in bytes) to use for the environment buffer.
|
---|
1108 | */
|
---|
1109 | VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInitEx(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo,
|
---|
1110 | size_t cbCmd,
|
---|
1111 | size_t cbUser, size_t cbPassword, size_t cbDomain,
|
---|
1112 | size_t cbArgs, size_t cbEnv)
|
---|
1113 | {
|
---|
1114 | AssertPtrReturn(pStartupInfo, VERR_INVALID_POINTER);
|
---|
1115 | AssertReturn(cbCmd, VERR_INVALID_PARAMETER);
|
---|
1116 | AssertReturn(cbUser, VERR_INVALID_PARAMETER);
|
---|
1117 | AssertReturn(cbPassword, VERR_INVALID_PARAMETER);
|
---|
1118 | AssertReturn(cbDomain, VERR_INVALID_PARAMETER);
|
---|
1119 | AssertReturn(cbArgs, VERR_INVALID_PARAMETER);
|
---|
1120 | AssertReturn(cbEnv, VERR_INVALID_PARAMETER);
|
---|
1121 |
|
---|
1122 | RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
|
---|
1123 |
|
---|
1124 | #define ALLOC_STR(a_Str, a_cb) \
|
---|
1125 | if ((a_cb) > 0) \
|
---|
1126 | { \
|
---|
1127 | pStartupInfo->psz##a_Str = RTStrAlloc(a_cb); \
|
---|
1128 | AssertPtrBreak(pStartupInfo->psz##a_Str); \
|
---|
1129 | pStartupInfo->cb##a_Str = (uint32_t)a_cb; \
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | do
|
---|
1133 | {
|
---|
1134 | ALLOC_STR(Cmd, cbCmd);
|
---|
1135 | ALLOC_STR(Args, cbArgs);
|
---|
1136 | ALLOC_STR(Env, cbEnv);
|
---|
1137 | ALLOC_STR(User, cbUser);
|
---|
1138 | ALLOC_STR(Password, cbPassword);
|
---|
1139 | ALLOC_STR(Domain, cbDomain);
|
---|
1140 |
|
---|
1141 | return VINF_SUCCESS;
|
---|
1142 |
|
---|
1143 | } while (0);
|
---|
1144 |
|
---|
1145 | #undef ALLOC_STR
|
---|
1146 |
|
---|
1147 | VbglR3GuestCtrlProcStartupInfoDestroy(pStartupInfo);
|
---|
1148 | return VERR_NO_MEMORY;
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | /**
|
---|
1152 | * Initializes a process startup info with default values.
|
---|
1153 | *
|
---|
1154 | * @param pStartupInfo Process startup info to initializes.
|
---|
1155 | */
|
---|
1156 | VBGLR3DECL(int) VbglR3GuestCtrlProcStartupInfoInit(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
|
---|
1157 | {
|
---|
1158 | return VbglR3GuestCtrlProcStartupInfoInitEx(pStartupInfo,
|
---|
1159 | GUEST_PROC_DEF_CMD_LEN,
|
---|
1160 | GUEST_PROC_DEF_USER_LEN /* Deprecated, now handled via session creation. */,
|
---|
1161 | GUEST_PROC_DEF_PASSWORD_LEN /* Ditto. */,
|
---|
1162 | GUEST_PROC_DEF_DOMAIN_LEN /* Ditto. */,
|
---|
1163 | GUEST_PROC_DEF_ARGS_LEN, GUEST_PROC_DEF_ENV_LEN);
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 | /**
|
---|
1167 | * Destroys a process startup info.
|
---|
1168 | *
|
---|
1169 | * @param pStartupInfo Process startup info to destroy.
|
---|
1170 | */
|
---|
1171 | VBGLR3DECL(void) VbglR3GuestCtrlProcStartupInfoDestroy(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
|
---|
1172 | {
|
---|
1173 | if (!pStartupInfo)
|
---|
1174 | return;
|
---|
1175 |
|
---|
1176 | RTStrFree(pStartupInfo->pszCmd);
|
---|
1177 | RTStrFree(pStartupInfo->pszArgs);
|
---|
1178 | RTStrFree(pStartupInfo->pszEnv);
|
---|
1179 | RTStrFree(pStartupInfo->pszUser);
|
---|
1180 | RTStrFree(pStartupInfo->pszPassword);
|
---|
1181 | RTStrFree(pStartupInfo->pszDomain);
|
---|
1182 |
|
---|
1183 | RT_BZERO(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | /**
|
---|
1187 | * Free's a process startup info.
|
---|
1188 | *
|
---|
1189 | * @param pStartupInfo Process startup info to free.
|
---|
1190 | * The pointer will not be valid anymore after return.
|
---|
1191 | */
|
---|
1192 | VBGLR3DECL(void) VbglR3GuestCtrlProcStartupInfoFree(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
|
---|
1193 | {
|
---|
1194 | if (!pStartupInfo)
|
---|
1195 | return;
|
---|
1196 |
|
---|
1197 | VbglR3GuestCtrlProcStartupInfoDestroy(pStartupInfo);
|
---|
1198 |
|
---|
1199 | RTMemFree(pStartupInfo);
|
---|
1200 | pStartupInfo = NULL;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | /**
|
---|
1204 | * Duplicates a process startup info.
|
---|
1205 | *
|
---|
1206 | * @returns Duplicated process startup info on success, or NULL on error.
|
---|
1207 | * @param pStartupInfo Process startup info to duplicate.
|
---|
1208 | */
|
---|
1209 | VBGLR3DECL(PVBGLR3GUESTCTRLPROCSTARTUPINFO) VbglR3GuestCtrlProcStartupInfoDup(PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo)
|
---|
1210 | {
|
---|
1211 | AssertPtrReturn(pStartupInfo, NULL);
|
---|
1212 |
|
---|
1213 | PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfoDup = (PVBGLR3GUESTCTRLPROCSTARTUPINFO)
|
---|
1214 | RTMemDup(pStartupInfo, sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
|
---|
1215 | if (pStartupInfoDup)
|
---|
1216 | {
|
---|
1217 | do
|
---|
1218 | {
|
---|
1219 | pStartupInfoDup->pszCmd = NULL;
|
---|
1220 | pStartupInfoDup->pszArgs = NULL;
|
---|
1221 | pStartupInfoDup->pszEnv = NULL;
|
---|
1222 | pStartupInfoDup->pszUser = NULL;
|
---|
1223 | pStartupInfoDup->pszPassword = NULL;
|
---|
1224 | pStartupInfoDup->pszDomain = NULL;
|
---|
1225 |
|
---|
1226 | #define DUP_STR(a_Str) \
|
---|
1227 | if (pStartupInfo->cb##a_Str) \
|
---|
1228 | { \
|
---|
1229 | pStartupInfoDup->psz##a_Str = (char *)RTStrDup(pStartupInfo->psz##a_Str); \
|
---|
1230 | AssertPtrBreak(pStartupInfoDup->psz##a_Str); \
|
---|
1231 | pStartupInfoDup->cb##a_Str = (uint32_t)strlen(pStartupInfoDup->psz##a_Str) + 1 /* Include terminator */; \
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | #define DUP_MEM(a_Str) \
|
---|
1235 | if (pStartupInfo->cb##a_Str) \
|
---|
1236 | { \
|
---|
1237 | pStartupInfoDup->psz##a_Str = (char *)RTMemDup(pStartupInfo->psz##a_Str, pStartupInfo->cb##a_Str); \
|
---|
1238 | AssertPtrBreak(pStartupInfoDup->psz##a_Str); \
|
---|
1239 | pStartupInfoDup->cb##a_Str = (uint32_t)pStartupInfo->cb##a_Str; \
|
---|
1240 | }
|
---|
1241 |
|
---|
1242 | DUP_STR(Cmd);
|
---|
1243 | DUP_MEM(Args);
|
---|
1244 | DUP_MEM(Env);
|
---|
1245 | DUP_STR(User);
|
---|
1246 | DUP_STR(Password);
|
---|
1247 | DUP_STR(Domain);
|
---|
1248 |
|
---|
1249 | #undef DUP_STR
|
---|
1250 | #undef DUP_MEM
|
---|
1251 |
|
---|
1252 | return pStartupInfoDup;
|
---|
1253 |
|
---|
1254 | } while (0); /* To use break macros above. */
|
---|
1255 |
|
---|
1256 | VbglR3GuestCtrlProcStartupInfoFree(pStartupInfoDup);
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 | return NULL;
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | /**
|
---|
1263 | * Retrieves a HOST_EXEC_CMD message.
|
---|
1264 | *
|
---|
1265 | * @returns VBox status code.
|
---|
1266 | * @param pCtx Guest control command context to use.
|
---|
1267 | * @param ppStartupInfo Where to store the allocated session startup info.
|
---|
1268 | * Needs to be free'd by VbglR3GuestCtrlProcStartupInfoFree().
|
---|
1269 | */
|
---|
1270 | VBGLR3DECL(int) VbglR3GuestCtrlProcGetStart(PVBGLR3GUESTCTRLCMDCTX pCtx, PVBGLR3GUESTCTRLPROCSTARTUPINFO *ppStartupInfo)
|
---|
1271 | {
|
---|
1272 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1273 | AssertPtrReturn(ppStartupInfo, VERR_INVALID_POINTER);
|
---|
1274 |
|
---|
1275 | PVBGLR3GUESTCTRLPROCSTARTUPINFO pStartupInfo
|
---|
1276 | = (PVBGLR3GUESTCTRLPROCSTARTUPINFO)RTMemAlloc(sizeof(VBGLR3GUESTCTRLPROCSTARTUPINFO));
|
---|
1277 | if (!pStartupInfo)
|
---|
1278 | return VERR_NO_MEMORY;
|
---|
1279 |
|
---|
1280 | int rc = VbglR3GuestCtrlProcStartupInfoInit(pStartupInfo);
|
---|
1281 | if (RT_FAILURE(rc))
|
---|
1282 | {
|
---|
1283 | VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo);
|
---|
1284 | return rc;
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | unsigned cRetries = 0;
|
---|
1288 | const unsigned cMaxRetries = 32; /* Should be enough for now. */
|
---|
1289 | const unsigned cGrowthFactor = 2; /* By how much the buffers will grow if they're too small yet. */
|
---|
1290 |
|
---|
1291 | do
|
---|
1292 | {
|
---|
1293 | LogRel(("VbglR3GuestCtrlProcGetStart: Retrieving\n"));
|
---|
1294 |
|
---|
1295 | HGCMMsgProcExec Msg;
|
---|
1296 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1297 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_CMD);
|
---|
1298 | VbglHGCMParmPtrSet(&Msg.cmd, pStartupInfo->pszCmd, pStartupInfo->cbCmd);
|
---|
1299 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
1300 | VbglHGCMParmUInt32Set(&Msg.num_args, 0);
|
---|
1301 | VbglHGCMParmPtrSet(&Msg.args, pStartupInfo->pszArgs, pStartupInfo->cbArgs);
|
---|
1302 | VbglHGCMParmUInt32Set(&Msg.num_env, 0);
|
---|
1303 | VbglHGCMParmUInt32Set(&Msg.cb_env, 0);
|
---|
1304 | VbglHGCMParmPtrSet(&Msg.env, pStartupInfo->pszEnv, pStartupInfo->cbEnv);
|
---|
1305 | if (pCtx->uProtocol < 2)
|
---|
1306 | {
|
---|
1307 | VbglHGCMParmPtrSet(&Msg.u.v1.username, pStartupInfo->pszUser, pStartupInfo->cbUser);
|
---|
1308 | VbglHGCMParmPtrSet(&Msg.u.v1.password, pStartupInfo->pszPassword, pStartupInfo->cbPassword);
|
---|
1309 | VbglHGCMParmUInt32Set(&Msg.u.v1.timeout, 0);
|
---|
1310 | }
|
---|
1311 | else
|
---|
1312 | {
|
---|
1313 | VbglHGCMParmUInt32Set(&Msg.u.v2.timeout, 0);
|
---|
1314 | VbglHGCMParmUInt32Set(&Msg.u.v2.priority, 0);
|
---|
1315 | VbglHGCMParmUInt32Set(&Msg.u.v2.num_affinity, 0);
|
---|
1316 | VbglHGCMParmPtrSet(&Msg.u.v2.affinity, pStartupInfo->uAffinity, sizeof(pStartupInfo->uAffinity));
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1320 | if (RT_FAILURE(rc))
|
---|
1321 | {
|
---|
1322 | LogRel(("VbglR3GuestCtrlProcGetStart: 1 - %Rrc (retry %u, cbCmd=%RU32, cbArgs=%RU32, cbEnv=%RU32)\n",
|
---|
1323 | rc, cRetries, pStartupInfo->cbCmd, pStartupInfo->cbArgs, pStartupInfo->cbEnv));
|
---|
1324 |
|
---|
1325 | if ( rc == VERR_BUFFER_OVERFLOW
|
---|
1326 | && cRetries++ < cMaxRetries)
|
---|
1327 | {
|
---|
1328 | #define GROW_STR(a_Str, a_cbMax) \
|
---|
1329 | pStartupInfo->psz##a_Str = (char *)RTMemRealloc(pStartupInfo->psz##a_Str, \
|
---|
1330 | RT_MIN(pStartupInfo->cb##a_Str * cGrowthFactor, a_cbMax)); \
|
---|
1331 | AssertPtrBreakStmt(pStartupInfo->psz##a_Str, VERR_NO_MEMORY); \
|
---|
1332 | pStartupInfo->cb##a_Str = RT_MIN(pStartupInfo->cb##a_Str * cGrowthFactor, a_cbMax);
|
---|
1333 |
|
---|
1334 | /* We can't tell which parameter doesn't fit, so we have to resize all. */
|
---|
1335 | GROW_STR(Cmd , GUEST_PROC_MAX_CMD_LEN);
|
---|
1336 | GROW_STR(Args, GUEST_PROC_MAX_ARGS_LEN);
|
---|
1337 | GROW_STR(Env, GUEST_PROC_MAX_ENV_LEN);
|
---|
1338 |
|
---|
1339 | #undef GROW_STR
|
---|
1340 | LogRel(("VbglR3GuestCtrlProcGetStart: 2 - %Rrc (retry %u, cbCmd=%RU32, cbArgs=%RU32, cbEnv=%RU32)\n",
|
---|
1341 | rc, cRetries, pStartupInfo->cbCmd, pStartupInfo->cbArgs, pStartupInfo->cbEnv));
|
---|
1342 | LogRel(("g_fVbglR3GuestCtrlHavePeekGetCancel=%RTbool\n", RT_BOOL(g_fVbglR3GuestCtrlHavePeekGetCancel)));
|
---|
1343 | }
|
---|
1344 | else
|
---|
1345 | break;
|
---|
1346 | }
|
---|
1347 | else
|
---|
1348 | {
|
---|
1349 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1350 | Msg.flags.GetUInt32(&pStartupInfo->fFlags);
|
---|
1351 | Msg.num_args.GetUInt32(&pStartupInfo->cArgs);
|
---|
1352 | Msg.num_env.GetUInt32(&pStartupInfo->cEnvVars);
|
---|
1353 | Msg.cb_env.GetUInt32(&pStartupInfo->cbEnv);
|
---|
1354 | if (pCtx->uProtocol < 2)
|
---|
1355 | Msg.u.v1.timeout.GetUInt32(&pStartupInfo->uTimeLimitMS);
|
---|
1356 | else
|
---|
1357 | {
|
---|
1358 | Msg.u.v2.timeout.GetUInt32(&pStartupInfo->uTimeLimitMS);
|
---|
1359 | Msg.u.v2.priority.GetUInt32(&pStartupInfo->uPriority);
|
---|
1360 | Msg.u.v2.num_affinity.GetUInt32(&pStartupInfo->cAffinity);
|
---|
1361 | }
|
---|
1362 | }
|
---|
1363 | } while (( rc == VERR_INTERRUPTED
|
---|
1364 | || rc == VERR_BUFFER_OVERFLOW) && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1365 |
|
---|
1366 | if (RT_SUCCESS(rc))
|
---|
1367 | {
|
---|
1368 | *ppStartupInfo = pStartupInfo;
|
---|
1369 | }
|
---|
1370 | else
|
---|
1371 | VbglR3GuestCtrlProcStartupInfoFree(pStartupInfo);
|
---|
1372 |
|
---|
1373 | LogRel(("VbglR3GuestCtrlProcGetStart: Returning %Rrc (retry %u, cbCmd=%RU32, cbArgs=%RU32, cbEnv=%RU32)\n",
|
---|
1374 | rc, cRetries, pStartupInfo->cbCmd, pStartupInfo->cbArgs, pStartupInfo->cbEnv));
|
---|
1375 |
|
---|
1376 | LogFlowFuncLeaveRC(rc);
|
---|
1377 | return rc;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | /**
|
---|
1381 | * Allocates and gets host data, based on the message ID.
|
---|
1382 | *
|
---|
1383 | * This will block until data becomes available.
|
---|
1384 | *
|
---|
1385 | * @returns VBox status code.
|
---|
1386 | * @param pCtx Guest control command context to use.
|
---|
1387 | * @param puPID Where to return the guest PID to retrieve output from on success.
|
---|
1388 | * @param puHandle Where to return the guest process handle to retrieve output from on success.
|
---|
1389 | * @param pfFlags Where to return the output flags on success.
|
---|
1390 | */
|
---|
1391 | VBGLR3DECL(int) VbglR3GuestCtrlProcGetOutput(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1392 | uint32_t *puPID, uint32_t *puHandle, uint32_t *pfFlags)
|
---|
1393 | {
|
---|
1394 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1395 | AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
|
---|
1396 |
|
---|
1397 | AssertPtrReturn(puPID, VERR_INVALID_POINTER);
|
---|
1398 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1399 | AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
|
---|
1400 |
|
---|
1401 | int rc;
|
---|
1402 | do
|
---|
1403 | {
|
---|
1404 | HGCMMsgProcOutput Msg;
|
---|
1405 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1406 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_GET_OUTPUT);
|
---|
1407 | VbglHGCMParmUInt32Set(&Msg.pid, 0);
|
---|
1408 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1409 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
1410 |
|
---|
1411 | rc = VbglR3HGCMCall(&Msg.hdr, RT_UOFFSETOF(HGCMMsgProcOutput, data));
|
---|
1412 | if (RT_SUCCESS(rc))
|
---|
1413 | {
|
---|
1414 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1415 | Msg.pid.GetUInt32(puPID);
|
---|
1416 | Msg.handle.GetUInt32(puHandle);
|
---|
1417 | Msg.flags.GetUInt32(pfFlags);
|
---|
1418 | }
|
---|
1419 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1420 | return rc;
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 |
|
---|
1424 | /**
|
---|
1425 | * Retrieves the input data from host which then gets sent to the started
|
---|
1426 | * process (HOST_EXEC_SET_INPUT).
|
---|
1427 | *
|
---|
1428 | * This will block until data becomes available.
|
---|
1429 | */
|
---|
1430 | VBGLR3DECL(int) VbglR3GuestCtrlProcGetInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1431 | uint32_t *puPID, uint32_t *pfFlags,
|
---|
1432 | void *pvData, uint32_t cbData,
|
---|
1433 | uint32_t *pcbSize)
|
---|
1434 | {
|
---|
1435 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1436 | AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
|
---|
1437 |
|
---|
1438 | AssertPtrReturn(puPID, VERR_INVALID_POINTER);
|
---|
1439 | AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
|
---|
1440 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
1441 | AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
|
---|
1442 |
|
---|
1443 | int rc;
|
---|
1444 | do
|
---|
1445 | {
|
---|
1446 | HGCMMsgProcInput Msg;
|
---|
1447 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1448 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_SET_INPUT);
|
---|
1449 | VbglHGCMParmUInt32Set(&Msg.pid, 0);
|
---|
1450 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
1451 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
1452 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
1453 |
|
---|
1454 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1455 | if (RT_SUCCESS(rc))
|
---|
1456 | {
|
---|
1457 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1458 | Msg.pid.GetUInt32(puPID);
|
---|
1459 | Msg.flags.GetUInt32(pfFlags);
|
---|
1460 | Msg.size.GetUInt32(pcbSize);
|
---|
1461 | }
|
---|
1462 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1463 |
|
---|
1464 | if ( rc != VERR_TOO_MUCH_DATA
|
---|
1465 | || g_fVbglR3GuestCtrlHavePeekGetCancel)
|
---|
1466 | return rc;
|
---|
1467 | return VERR_BUFFER_OVERFLOW;
|
---|
1468 | }
|
---|
1469 |
|
---|
1470 |
|
---|
1471 | /**
|
---|
1472 | * Retrieves a HOST_DIR_REMOVE message.
|
---|
1473 | */
|
---|
1474 | VBGLR3DECL(int) VbglR3GuestCtrlDirGetRemove(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1475 | char *pszPath, uint32_t cbPath,
|
---|
1476 | uint32_t *pfFlags)
|
---|
1477 | {
|
---|
1478 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1479 | AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
|
---|
1480 |
|
---|
1481 | AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
|
---|
1482 | AssertReturn(cbPath, VERR_INVALID_PARAMETER);
|
---|
1483 | AssertPtrReturn(pfFlags, VERR_INVALID_POINTER);
|
---|
1484 |
|
---|
1485 | int rc;
|
---|
1486 | do
|
---|
1487 | {
|
---|
1488 | HGCMMsgDirRemove Msg;
|
---|
1489 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1490 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_DIR_REMOVE);
|
---|
1491 | VbglHGCMParmPtrSet(&Msg.path, pszPath, cbPath);
|
---|
1492 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
1493 |
|
---|
1494 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1495 | if (RT_SUCCESS(rc))
|
---|
1496 | {
|
---|
1497 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1498 | Msg.flags.GetUInt32(pfFlags);
|
---|
1499 | }
|
---|
1500 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1501 | return rc;
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 |
|
---|
1505 | /**
|
---|
1506 | * Retrieves a HOST_FILE_OPEN message.
|
---|
1507 | */
|
---|
1508 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1509 | char *pszFileName, uint32_t cbFileName,
|
---|
1510 | char *pszAccess, uint32_t cbAccess,
|
---|
1511 | char *pszDisposition, uint32_t cbDisposition,
|
---|
1512 | char *pszSharing, uint32_t cbSharing,
|
---|
1513 | uint32_t *puCreationMode,
|
---|
1514 | uint64_t *poffAt)
|
---|
1515 | {
|
---|
1516 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1517 | AssertReturn(pCtx->uNumParms == 7, VERR_INVALID_PARAMETER);
|
---|
1518 |
|
---|
1519 | AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
|
---|
1520 | AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
|
---|
1521 | AssertPtrReturn(pszAccess, VERR_INVALID_POINTER);
|
---|
1522 | AssertReturn(cbAccess, VERR_INVALID_PARAMETER);
|
---|
1523 | AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER);
|
---|
1524 | AssertReturn(cbDisposition, VERR_INVALID_PARAMETER);
|
---|
1525 | AssertPtrReturn(pszSharing, VERR_INVALID_POINTER);
|
---|
1526 | AssertReturn(cbSharing, VERR_INVALID_PARAMETER);
|
---|
1527 | AssertPtrReturn(puCreationMode, VERR_INVALID_POINTER);
|
---|
1528 | AssertPtrReturn(poffAt, VERR_INVALID_POINTER);
|
---|
1529 |
|
---|
1530 | int rc;
|
---|
1531 | do
|
---|
1532 | {
|
---|
1533 | HGCMMsgFileOpen Msg;
|
---|
1534 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1535 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_OPEN);
|
---|
1536 | VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
|
---|
1537 | VbglHGCMParmPtrSet(&Msg.openmode, pszAccess, cbAccess);
|
---|
1538 | VbglHGCMParmPtrSet(&Msg.disposition, pszDisposition, cbDisposition);
|
---|
1539 | VbglHGCMParmPtrSet(&Msg.sharing, pszSharing, cbSharing);
|
---|
1540 | VbglHGCMParmUInt32Set(&Msg.creationmode, 0);
|
---|
1541 | VbglHGCMParmUInt64Set(&Msg.offset, 0);
|
---|
1542 |
|
---|
1543 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1544 | if (RT_SUCCESS(rc))
|
---|
1545 | {
|
---|
1546 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1547 | Msg.creationmode.GetUInt32(puCreationMode);
|
---|
1548 | Msg.offset.GetUInt64(poffAt);
|
---|
1549 | }
|
---|
1550 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1551 | return rc;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 |
|
---|
1555 | /**
|
---|
1556 | * Retrieves a HOST_FILE_CLOSE message.
|
---|
1557 | */
|
---|
1558 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetClose(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
|
---|
1559 | {
|
---|
1560 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1561 |
|
---|
1562 | AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
|
---|
1563 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1564 |
|
---|
1565 | int rc;
|
---|
1566 | do
|
---|
1567 | {
|
---|
1568 | HGCMMsgFileClose Msg;
|
---|
1569 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1570 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_CLOSE);
|
---|
1571 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1572 |
|
---|
1573 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1574 | if (RT_SUCCESS(rc))
|
---|
1575 | {
|
---|
1576 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1577 | Msg.handle.GetUInt32(puHandle);
|
---|
1578 | }
|
---|
1579 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1580 | return rc;
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 |
|
---|
1584 | /**
|
---|
1585 | * Retrieves a HOST_FILE_READ message.
|
---|
1586 | */
|
---|
1587 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetRead(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle, uint32_t *puToRead)
|
---|
1588 | {
|
---|
1589 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1590 |
|
---|
1591 | AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
|
---|
1592 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1593 | AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
|
---|
1594 |
|
---|
1595 | int rc;
|
---|
1596 | do
|
---|
1597 | {
|
---|
1598 | HGCMMsgFileRead Msg;
|
---|
1599 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1600 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_READ);
|
---|
1601 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1602 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
1603 |
|
---|
1604 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1605 | if (RT_SUCCESS(rc))
|
---|
1606 | {
|
---|
1607 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1608 | Msg.handle.GetUInt32(puHandle);
|
---|
1609 | Msg.size.GetUInt32(puToRead);
|
---|
1610 | }
|
---|
1611 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1612 | return rc;
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 |
|
---|
1616 | /**
|
---|
1617 | * Retrieves a HOST_FILE_READ_AT message.
|
---|
1618 | */
|
---|
1619 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetReadAt(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1620 | uint32_t *puHandle, uint32_t *puToRead, uint64_t *poffAt)
|
---|
1621 | {
|
---|
1622 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1623 |
|
---|
1624 | AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
|
---|
1625 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1626 | AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
|
---|
1627 |
|
---|
1628 | int rc;
|
---|
1629 | do
|
---|
1630 | {
|
---|
1631 | HGCMMsgFileReadAt Msg;
|
---|
1632 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1633 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_READ_AT);
|
---|
1634 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1635 | VbglHGCMParmUInt64Set(&Msg.offset, 0);
|
---|
1636 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
1637 |
|
---|
1638 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1639 | if (RT_SUCCESS(rc))
|
---|
1640 | {
|
---|
1641 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1642 | Msg.handle.GetUInt32(puHandle);
|
---|
1643 | Msg.offset.GetUInt64(poffAt);
|
---|
1644 | Msg.size.GetUInt32(puToRead);
|
---|
1645 | }
|
---|
1646 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1647 | return rc;
|
---|
1648 | }
|
---|
1649 |
|
---|
1650 |
|
---|
1651 | /**
|
---|
1652 | * Retrieves a HOST_FILE_WRITE message.
|
---|
1653 | */
|
---|
1654 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle,
|
---|
1655 | void *pvData, uint32_t cbData, uint32_t *pcbSize)
|
---|
1656 | {
|
---|
1657 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1658 |
|
---|
1659 | AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
|
---|
1660 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1661 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
1662 | AssertReturn(cbData, VERR_INVALID_PARAMETER);
|
---|
1663 | AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
|
---|
1664 |
|
---|
1665 | int rc;
|
---|
1666 | do
|
---|
1667 | {
|
---|
1668 | HGCMMsgFileWrite Msg;
|
---|
1669 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1670 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_WRITE);
|
---|
1671 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1672 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
1673 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
1674 |
|
---|
1675 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1676 | if (RT_SUCCESS(rc))
|
---|
1677 | {
|
---|
1678 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1679 | Msg.handle.GetUInt32(puHandle);
|
---|
1680 | Msg.size.GetUInt32(pcbSize);
|
---|
1681 | }
|
---|
1682 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1683 |
|
---|
1684 | if ( rc != VERR_TOO_MUCH_DATA
|
---|
1685 | || g_fVbglR3GuestCtrlHavePeekGetCancel)
|
---|
1686 | return rc;
|
---|
1687 | return VERR_BUFFER_OVERFLOW;
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 |
|
---|
1691 | /**
|
---|
1692 | * Retrieves a HOST_FILE_WRITE_AT message.
|
---|
1693 | */
|
---|
1694 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetWriteAt(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle,
|
---|
1695 | void *pvData, uint32_t cbData, uint32_t *pcbSize, uint64_t *poffAt)
|
---|
1696 | {
|
---|
1697 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1698 |
|
---|
1699 | AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
|
---|
1700 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1701 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
1702 | AssertReturn(cbData, VERR_INVALID_PARAMETER);
|
---|
1703 | AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
|
---|
1704 |
|
---|
1705 | int rc;
|
---|
1706 | do
|
---|
1707 | {
|
---|
1708 | HGCMMsgFileWriteAt Msg;
|
---|
1709 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1710 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_WRITE_AT);
|
---|
1711 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1712 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
1713 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
1714 | VbglHGCMParmUInt64Set(&Msg.offset, 0);
|
---|
1715 |
|
---|
1716 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1717 | if (RT_SUCCESS(rc))
|
---|
1718 | {
|
---|
1719 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1720 | Msg.handle.GetUInt32(puHandle);
|
---|
1721 | Msg.size.GetUInt32(pcbSize);
|
---|
1722 | Msg.offset.GetUInt64(poffAt);
|
---|
1723 | }
|
---|
1724 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1725 |
|
---|
1726 | if ( rc != VERR_TOO_MUCH_DATA
|
---|
1727 | || g_fVbglR3GuestCtrlHavePeekGetCancel)
|
---|
1728 | return rc;
|
---|
1729 | return VERR_BUFFER_OVERFLOW;
|
---|
1730 | }
|
---|
1731 |
|
---|
1732 |
|
---|
1733 | /**
|
---|
1734 | * Retrieves a HOST_FILE_SEEK message.
|
---|
1735 | */
|
---|
1736 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetSeek(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1737 | uint32_t *puHandle, uint32_t *puSeekMethod, uint64_t *poffAt)
|
---|
1738 | {
|
---|
1739 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1740 |
|
---|
1741 | AssertReturn(pCtx->uNumParms == 4, VERR_INVALID_PARAMETER);
|
---|
1742 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1743 | AssertPtrReturn(puSeekMethod, VERR_INVALID_POINTER);
|
---|
1744 | AssertPtrReturn(poffAt, VERR_INVALID_POINTER);
|
---|
1745 |
|
---|
1746 | int rc;
|
---|
1747 | do
|
---|
1748 | {
|
---|
1749 | HGCMMsgFileSeek Msg;
|
---|
1750 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1751 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_SEEK);
|
---|
1752 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1753 | VbglHGCMParmUInt32Set(&Msg.method, 0);
|
---|
1754 | VbglHGCMParmUInt64Set(&Msg.offset, 0);
|
---|
1755 |
|
---|
1756 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1757 | if (RT_SUCCESS(rc))
|
---|
1758 | {
|
---|
1759 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1760 | Msg.handle.GetUInt32(puHandle);
|
---|
1761 | Msg.method.GetUInt32(puSeekMethod);
|
---|
1762 | Msg.offset.GetUInt64(poffAt);
|
---|
1763 | }
|
---|
1764 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1765 | return rc;
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 |
|
---|
1769 | /**
|
---|
1770 | * Retrieves a HOST_FILE_TELL message.
|
---|
1771 | */
|
---|
1772 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetTell(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle)
|
---|
1773 | {
|
---|
1774 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1775 |
|
---|
1776 | AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
|
---|
1777 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1778 |
|
---|
1779 | int rc;
|
---|
1780 | do
|
---|
1781 | {
|
---|
1782 | HGCMMsgFileTell Msg;
|
---|
1783 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1784 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_FILE_TELL);
|
---|
1785 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
1786 |
|
---|
1787 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1788 | if (RT_SUCCESS(rc))
|
---|
1789 | {
|
---|
1790 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1791 | Msg.handle.GetUInt32(puHandle);
|
---|
1792 | }
|
---|
1793 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1794 | return rc;
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 |
|
---|
1798 | /**
|
---|
1799 | * Retrieves a HOST_FILE_SET_SIZE message.
|
---|
1800 | */
|
---|
1801 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetSetSize(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puHandle, uint64_t *pcbNew)
|
---|
1802 | {
|
---|
1803 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1804 |
|
---|
1805 | AssertReturn(pCtx->uNumParms == 3, VERR_INVALID_PARAMETER);
|
---|
1806 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
1807 | AssertPtrReturn(pcbNew, VERR_INVALID_POINTER);
|
---|
1808 |
|
---|
1809 | int rc;
|
---|
1810 | do
|
---|
1811 | {
|
---|
1812 | HGCMMsgFileSetSize Msg;
|
---|
1813 | VBGL_HGCM_HDR_INIT(&Msg.Hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1814 | VbglHGCMParmUInt32Set(&Msg.id32Context, HOST_MSG_FILE_SET_SIZE);
|
---|
1815 | VbglHGCMParmUInt32Set(&Msg.id32Handle, 0);
|
---|
1816 | VbglHGCMParmUInt64Set(&Msg.cb64NewSize, 0);
|
---|
1817 |
|
---|
1818 | rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
|
---|
1819 | if (RT_SUCCESS(rc))
|
---|
1820 | {
|
---|
1821 | Msg.id32Context.GetUInt32(&pCtx->uContextID);
|
---|
1822 | Msg.id32Handle.GetUInt32(puHandle);
|
---|
1823 | Msg.cb64NewSize.GetUInt64(pcbNew);
|
---|
1824 | }
|
---|
1825 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1826 | return rc;
|
---|
1827 | }
|
---|
1828 |
|
---|
1829 |
|
---|
1830 | /**
|
---|
1831 | * Retrieves a HOST_EXEC_TERMINATE message.
|
---|
1832 | */
|
---|
1833 | VBGLR3DECL(int) VbglR3GuestCtrlProcGetTerminate(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t *puPID)
|
---|
1834 | {
|
---|
1835 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1836 |
|
---|
1837 | AssertReturn(pCtx->uNumParms == 2, VERR_INVALID_PARAMETER);
|
---|
1838 | AssertPtrReturn(puPID, VERR_INVALID_POINTER);
|
---|
1839 |
|
---|
1840 | int rc;
|
---|
1841 | do
|
---|
1842 | {
|
---|
1843 | HGCMMsgProcTerminate Msg;
|
---|
1844 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1845 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_TERMINATE);
|
---|
1846 | VbglHGCMParmUInt32Set(&Msg.pid, 0);
|
---|
1847 |
|
---|
1848 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1849 | if (RT_SUCCESS(rc))
|
---|
1850 | {
|
---|
1851 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1852 | Msg.pid.GetUInt32(puPID);
|
---|
1853 | }
|
---|
1854 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1855 | return rc;
|
---|
1856 | }
|
---|
1857 |
|
---|
1858 |
|
---|
1859 | /**
|
---|
1860 | * Retrieves a HOST_EXEC_WAIT_FOR message.
|
---|
1861 | */
|
---|
1862 | VBGLR3DECL(int) VbglR3GuestCtrlProcGetWaitFor(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1863 | uint32_t *puPID, uint32_t *puWaitFlags, uint32_t *puTimeoutMS)
|
---|
1864 | {
|
---|
1865 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1866 |
|
---|
1867 | AssertReturn(pCtx->uNumParms == 5, VERR_INVALID_PARAMETER);
|
---|
1868 | AssertPtrReturn(puPID, VERR_INVALID_POINTER);
|
---|
1869 |
|
---|
1870 | int rc;
|
---|
1871 | do
|
---|
1872 | {
|
---|
1873 | HGCMMsgProcWaitFor Msg;
|
---|
1874 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, vbglR3GuestCtrlGetMsgFunctionNo(pCtx->uClientID), pCtx->uNumParms);
|
---|
1875 | VbglHGCMParmUInt32Set(&Msg.context, HOST_MSG_EXEC_WAIT_FOR);
|
---|
1876 | VbglHGCMParmUInt32Set(&Msg.pid, 0);
|
---|
1877 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
1878 | VbglHGCMParmUInt32Set(&Msg.timeout, 0);
|
---|
1879 |
|
---|
1880 | rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
1881 | if (RT_SUCCESS(rc))
|
---|
1882 | {
|
---|
1883 | Msg.context.GetUInt32(&pCtx->uContextID);
|
---|
1884 | Msg.pid.GetUInt32(puPID);
|
---|
1885 | Msg.flags.GetUInt32(puWaitFlags);
|
---|
1886 | Msg.timeout.GetUInt32(puTimeoutMS);
|
---|
1887 | }
|
---|
1888 | } while (rc == VERR_INTERRUPTED && g_fVbglR3GuestCtrlHavePeekGetCancel);
|
---|
1889 | return rc;
|
---|
1890 | }
|
---|
1891 |
|
---|
1892 |
|
---|
1893 | /**
|
---|
1894 | * Replies to a HOST_MSG_FILE_OPEN message.
|
---|
1895 | *
|
---|
1896 | * @returns VBox status code.
|
---|
1897 | * @param pCtx Guest control command context to use.
|
---|
1898 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
1899 | * @param uFileHandle File handle of opened file on success.
|
---|
1900 | */
|
---|
1901 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbOpen(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1902 | uint32_t uRc, uint32_t uFileHandle)
|
---|
1903 | {
|
---|
1904 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1905 |
|
---|
1906 | HGCMReplyFileNotify Msg;
|
---|
1907 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
|
---|
1908 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
1909 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_OPEN);
|
---|
1910 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
1911 | VbglHGCMParmUInt32Set(&Msg.u.open.handle, uFileHandle);
|
---|
1912 |
|
---|
1913 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.open));
|
---|
1914 | }
|
---|
1915 |
|
---|
1916 |
|
---|
1917 | /**
|
---|
1918 | * Replies to a HOST_MSG_FILE_CLOSE message.
|
---|
1919 | *
|
---|
1920 | * @returns VBox status code.
|
---|
1921 | * @param pCtx Guest control command context to use.
|
---|
1922 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
1923 | */
|
---|
1924 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbClose(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1925 | uint32_t uRc)
|
---|
1926 | {
|
---|
1927 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1928 |
|
---|
1929 | HGCMReplyFileNotify Msg;
|
---|
1930 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 3);
|
---|
1931 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
1932 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_CLOSE);
|
---|
1933 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
1934 |
|
---|
1935 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSETOF(HGCMReplyFileNotify, u));
|
---|
1936 | }
|
---|
1937 |
|
---|
1938 |
|
---|
1939 | /**
|
---|
1940 | * Sends an unexpected file handling error to the host.
|
---|
1941 | *
|
---|
1942 | * @returns VBox status code.
|
---|
1943 | * @param pCtx Guest control command context to use.
|
---|
1944 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
1945 | */
|
---|
1946 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbError(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc)
|
---|
1947 | {
|
---|
1948 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1949 |
|
---|
1950 | HGCMReplyFileNotify Msg;
|
---|
1951 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 3);
|
---|
1952 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
1953 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_ERROR);
|
---|
1954 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
1955 |
|
---|
1956 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSETOF(HGCMReplyFileNotify, u));
|
---|
1957 | }
|
---|
1958 |
|
---|
1959 |
|
---|
1960 | /**
|
---|
1961 | * Replies to a HOST_MSG_FILE_READ message.
|
---|
1962 | *
|
---|
1963 | * @returns VBox status code.
|
---|
1964 | * @param pCtx Guest control command context to use.
|
---|
1965 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
1966 | * @param pvData Pointer to read file data from guest on success.
|
---|
1967 | * @param cbData Size (in bytes) of read file data from guest on success.
|
---|
1968 | */
|
---|
1969 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbRead(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
1970 | uint32_t uRc,
|
---|
1971 | void *pvData, uint32_t cbData)
|
---|
1972 | {
|
---|
1973 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
1974 |
|
---|
1975 | HGCMReplyFileNotify Msg;
|
---|
1976 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
|
---|
1977 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
1978 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_READ);
|
---|
1979 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
1980 | VbglHGCMParmPtrSet(&Msg.u.read.data, pvData, cbData);
|
---|
1981 |
|
---|
1982 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.read));
|
---|
1983 | }
|
---|
1984 |
|
---|
1985 |
|
---|
1986 | /**
|
---|
1987 | * Replies to a HOST_MSG_FILE_READ_AT message.
|
---|
1988 | *
|
---|
1989 | * @returns VBox status code.
|
---|
1990 | * @param pCtx Guest control command context to use.
|
---|
1991 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
1992 | * @param pvData Pointer to read file data from guest on success.
|
---|
1993 | * @param cbData Size (in bytes) of read file data from guest on success.
|
---|
1994 | * @param offNew New offset (in bytes) the guest file pointer points at on success.
|
---|
1995 | */
|
---|
1996 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbReadOffset(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc,
|
---|
1997 | void *pvData, uint32_t cbData, int64_t offNew)
|
---|
1998 | {
|
---|
1999 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2000 |
|
---|
2001 | HGCMReplyFileNotify Msg;
|
---|
2002 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 5);
|
---|
2003 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2004 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_READ_OFFSET);
|
---|
2005 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
2006 | VbglHGCMParmPtrSet(&Msg.u.ReadOffset.pvData, pvData, cbData);
|
---|
2007 | VbglHGCMParmUInt64Set(&Msg.u.ReadOffset.off64New, (uint64_t)offNew);
|
---|
2008 |
|
---|
2009 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.ReadOffset));
|
---|
2010 | }
|
---|
2011 |
|
---|
2012 |
|
---|
2013 | /**
|
---|
2014 | * Replies to a HOST_MSG_FILE_WRITE message.
|
---|
2015 | *
|
---|
2016 | * @returns VBox status code.
|
---|
2017 | * @param pCtx Guest control command context to use.
|
---|
2018 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
2019 | * @param cbWritten Size (in bytes) of file data successfully written to guest file. Can be partial.
|
---|
2020 | */
|
---|
2021 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbWrite(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t cbWritten)
|
---|
2022 | {
|
---|
2023 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2024 |
|
---|
2025 | HGCMReplyFileNotify Msg;
|
---|
2026 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
|
---|
2027 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2028 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_WRITE);
|
---|
2029 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
2030 | VbglHGCMParmUInt32Set(&Msg.u.write.written, cbWritten);
|
---|
2031 |
|
---|
2032 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.write));
|
---|
2033 | }
|
---|
2034 |
|
---|
2035 |
|
---|
2036 | /**
|
---|
2037 | * Replies to a HOST_MSG_FILE_WRITE_AT message.
|
---|
2038 | *
|
---|
2039 | * @returns VBox status code.
|
---|
2040 | * @param pCtx Guest control command context to use.
|
---|
2041 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
2042 | * @param cbWritten Size (in bytes) of file data successfully written to guest file. Can be partial.
|
---|
2043 | * @param offNew New offset (in bytes) the guest file pointer points at on success.
|
---|
2044 | */
|
---|
2045 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbWriteOffset(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint32_t cbWritten, int64_t offNew)
|
---|
2046 | {
|
---|
2047 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2048 |
|
---|
2049 | HGCMReplyFileNotify Msg;
|
---|
2050 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 5);
|
---|
2051 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2052 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_WRITE_OFFSET);
|
---|
2053 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
2054 | VbglHGCMParmUInt32Set(&Msg.u.WriteOffset.cb32Written, cbWritten);
|
---|
2055 | VbglHGCMParmUInt64Set(&Msg.u.WriteOffset.off64New, (uint64_t)offNew);
|
---|
2056 |
|
---|
2057 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.WriteOffset));
|
---|
2058 | }
|
---|
2059 |
|
---|
2060 |
|
---|
2061 | /**
|
---|
2062 | * Replies to a HOST_MSG_FILE_SEEK message.
|
---|
2063 | *
|
---|
2064 | * @returns VBox status code.
|
---|
2065 | * @param pCtx Guest control command context to use.
|
---|
2066 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
2067 | * @param offCurrent New offset (in bytes) the guest file pointer points at on success.
|
---|
2068 | */
|
---|
2069 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbSeek(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t offCurrent)
|
---|
2070 | {
|
---|
2071 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2072 |
|
---|
2073 | HGCMReplyFileNotify Msg;
|
---|
2074 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
|
---|
2075 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2076 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SEEK);
|
---|
2077 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
2078 | VbglHGCMParmUInt64Set(&Msg.u.seek.offset, offCurrent);
|
---|
2079 |
|
---|
2080 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.seek));
|
---|
2081 | }
|
---|
2082 |
|
---|
2083 |
|
---|
2084 | /**
|
---|
2085 | * Replies to a HOST_MSG_FILE_TELL message.
|
---|
2086 | *
|
---|
2087 | * @returns VBox status code.
|
---|
2088 | * @param pCtx Guest control command context to use.
|
---|
2089 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
2090 | * @param offCurrent Current offset (in bytes) the guest file pointer points at on success.
|
---|
2091 | */
|
---|
2092 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbTell(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t offCurrent)
|
---|
2093 | {
|
---|
2094 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2095 |
|
---|
2096 | HGCMReplyFileNotify Msg;
|
---|
2097 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
|
---|
2098 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2099 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_TELL);
|
---|
2100 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
2101 | VbglHGCMParmUInt64Set(&Msg.u.tell.offset, offCurrent);
|
---|
2102 |
|
---|
2103 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.tell));
|
---|
2104 | }
|
---|
2105 |
|
---|
2106 |
|
---|
2107 | /**
|
---|
2108 | * Replies to a HOST_MSG_FILE_SET_SIZE message.
|
---|
2109 | *
|
---|
2110 | * @returns VBox status code.
|
---|
2111 | * @param pCtx Guest control command context to use.
|
---|
2112 | * @param uRc Guest rc of operation (note: IPRT-style signed int).
|
---|
2113 | * @param cbNew New file size (in bytes) of the guest file on success.
|
---|
2114 | */
|
---|
2115 | VBGLR3DECL(int) VbglR3GuestCtrlFileCbSetSize(PVBGLR3GUESTCTRLCMDCTX pCtx, uint32_t uRc, uint64_t cbNew)
|
---|
2116 | {
|
---|
2117 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2118 |
|
---|
2119 | HGCMReplyFileNotify Msg;
|
---|
2120 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_FILE_NOTIFY, 4);
|
---|
2121 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2122 | VbglHGCMParmUInt32Set(&Msg.type, GUEST_FILE_NOTIFYTYPE_SET_SIZE);
|
---|
2123 | VbglHGCMParmUInt32Set(&Msg.rc, uRc);
|
---|
2124 | VbglHGCMParmUInt64Set(&Msg.u.SetSize.cb64Size, cbNew);
|
---|
2125 |
|
---|
2126 | return VbglR3HGCMCall(&Msg.hdr, RT_UOFFSET_AFTER(HGCMReplyFileNotify, u.SetSize));
|
---|
2127 | }
|
---|
2128 |
|
---|
2129 |
|
---|
2130 | /**
|
---|
2131 | * Callback for reporting a guest process status (along with some other stuff) to the host.
|
---|
2132 | *
|
---|
2133 | * @returns VBox status code.
|
---|
2134 | * @param pCtx Guest control command context to use.
|
---|
2135 | * @param uPID Guest process PID to report status for.
|
---|
2136 | * @param uStatus Status to report. Of type PROC_STS_XXX.
|
---|
2137 | * @param fFlags Additional status flags, depending on the reported status. See RTPROCSTATUS.
|
---|
2138 | * @param pvData Pointer to additional status data. Optional.
|
---|
2139 | * @param cbData Size (in bytes) of additional status data.
|
---|
2140 | */
|
---|
2141 | VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatus(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
2142 | uint32_t uPID, uint32_t uStatus, uint32_t fFlags,
|
---|
2143 | void *pvData, uint32_t cbData)
|
---|
2144 | {
|
---|
2145 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2146 |
|
---|
2147 | HGCMMsgProcStatus Msg;
|
---|
2148 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_EXEC_STATUS, 5);
|
---|
2149 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2150 | VbglHGCMParmUInt32Set(&Msg.pid, uPID);
|
---|
2151 | VbglHGCMParmUInt32Set(&Msg.status, uStatus);
|
---|
2152 | VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
|
---|
2153 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
2154 |
|
---|
2155 | return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
2156 | }
|
---|
2157 |
|
---|
2158 |
|
---|
2159 | /**
|
---|
2160 | * Sends output (from stdout/stderr) from a running process.
|
---|
2161 | *
|
---|
2162 | * @returns VBox status code.
|
---|
2163 | * @param pCtx Guest control command context to use.
|
---|
2164 | * @param uPID Guest process PID to report status for.
|
---|
2165 | * @param uHandle Guest process handle the output belong to.
|
---|
2166 | * @param fFlags Additional output flags.
|
---|
2167 | * @param pvData Pointer to actual output data.
|
---|
2168 | * @param cbData Size (in bytes) of output data.
|
---|
2169 | */
|
---|
2170 | VBGLR3DECL(int) VbglR3GuestCtrlProcCbOutput(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
2171 | uint32_t uPID,uint32_t uHandle, uint32_t fFlags,
|
---|
2172 | void *pvData, uint32_t cbData)
|
---|
2173 | {
|
---|
2174 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2175 |
|
---|
2176 | HGCMMsgProcOutput Msg;
|
---|
2177 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_EXEC_OUTPUT, 5);
|
---|
2178 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2179 | VbglHGCMParmUInt32Set(&Msg.pid, uPID);
|
---|
2180 | VbglHGCMParmUInt32Set(&Msg.handle, uHandle);
|
---|
2181 | VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
|
---|
2182 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
2183 |
|
---|
2184 | return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
2185 | }
|
---|
2186 |
|
---|
2187 |
|
---|
2188 | /**
|
---|
2189 | * Callback for reporting back the input status of a guest process to the host.
|
---|
2190 | *
|
---|
2191 | * @returns VBox status code.
|
---|
2192 | * @param pCtx Guest control command context to use.
|
---|
2193 | * @param uPID Guest process PID to report status for.
|
---|
2194 | * @param uStatus Status to report. Of type INPUT_STS_XXX.
|
---|
2195 | * @param fFlags Additional input flags.
|
---|
2196 | * @param cbWritten Size (in bytes) of input data handled.
|
---|
2197 | */
|
---|
2198 | VBGLR3DECL(int) VbglR3GuestCtrlProcCbStatusInput(PVBGLR3GUESTCTRLCMDCTX pCtx,
|
---|
2199 | uint32_t uPID, uint32_t uStatus,
|
---|
2200 | uint32_t fFlags, uint32_t cbWritten)
|
---|
2201 | {
|
---|
2202 | AssertPtrReturn(pCtx, VERR_INVALID_POINTER);
|
---|
2203 |
|
---|
2204 | HGCMMsgProcStatusInput Msg;
|
---|
2205 | VBGL_HGCM_HDR_INIT(&Msg.hdr, pCtx->uClientID, GUEST_MSG_EXEC_INPUT_STATUS, 5);
|
---|
2206 | VbglHGCMParmUInt32Set(&Msg.context, pCtx->uContextID);
|
---|
2207 | VbglHGCMParmUInt32Set(&Msg.pid, uPID);
|
---|
2208 | VbglHGCMParmUInt32Set(&Msg.status, uStatus);
|
---|
2209 | VbglHGCMParmUInt32Set(&Msg.flags, fFlags);
|
---|
2210 | VbglHGCMParmUInt32Set(&Msg.written, cbWritten);
|
---|
2211 |
|
---|
2212 | return VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
|
---|
2213 | }
|
---|
2214 |
|
---|