1 | /* $Id: VBoxGuestR3LibGuestCtrl.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, guest control.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #include <iprt/string.h>
|
---|
32 | #include <iprt/mem.h>
|
---|
33 | #include <iprt/assert.h>
|
---|
34 | #include <iprt/cpp/autores.h>
|
---|
35 | #include <iprt/stdarg.h>
|
---|
36 | #include <VBox/log.h>
|
---|
37 | #include <VBox/HostServices/GuestControlSvc.h>
|
---|
38 |
|
---|
39 | #include "VBGLR3Internal.h"
|
---|
40 |
|
---|
41 |
|
---|
42 | /*******************************************************************************
|
---|
43 | * Structures and Typedefs *
|
---|
44 | *******************************************************************************/
|
---|
45 |
|
---|
46 | using namespace guestControl;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Connects to the guest control service.
|
---|
50 | *
|
---|
51 | * @returns VBox status code
|
---|
52 | * @param pu32ClientId Where to put the client id on success. The client id
|
---|
53 | * must be passed to all the other calls to the service.
|
---|
54 | */
|
---|
55 | VBGLR3DECL(int) VbglR3GuestCtrlConnect(uint32_t *pu32ClientId)
|
---|
56 | {
|
---|
57 | VBoxGuestHGCMConnectInfo Info;
|
---|
58 | Info.result = VERR_WRONG_ORDER;
|
---|
59 | Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
|
---|
60 | RT_ZERO(Info.Loc.u);
|
---|
61 | strcpy(Info.Loc.u.host.achName, "VBoxGuestControlSvc");
|
---|
62 | Info.u32ClientID = UINT32_MAX; /* try make valgrind shut up. */
|
---|
63 |
|
---|
64 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
|
---|
65 | if (RT_SUCCESS(rc))
|
---|
66 | {
|
---|
67 | rc = Info.result;
|
---|
68 | if (RT_SUCCESS(rc))
|
---|
69 | *pu32ClientId = Info.u32ClientID;
|
---|
70 | }
|
---|
71 | return rc;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Disconnect from the guest control service.
|
---|
77 | *
|
---|
78 | * @returns VBox status code.
|
---|
79 | * @param u32ClientId The client id returned by VbglR3GuestCtrlConnect().
|
---|
80 | */
|
---|
81 | VBGLR3DECL(int) VbglR3GuestCtrlDisconnect(uint32_t u32ClientId)
|
---|
82 | {
|
---|
83 | VBoxGuestHGCMDisconnectInfo Info;
|
---|
84 | Info.result = VERR_WRONG_ORDER;
|
---|
85 | Info.u32ClientID = u32ClientId;
|
---|
86 |
|
---|
87 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
|
---|
88 | if (RT_SUCCESS(rc))
|
---|
89 | rc = Info.result;
|
---|
90 | return rc;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Waits until a new host message arrives.
|
---|
96 | * This will block until a message becomes available.
|
---|
97 | *
|
---|
98 | * @returns VBox status code.
|
---|
99 | * @param u32ClientId The client id returned by VbglR3GuestCtrlConnect().
|
---|
100 | * @param puMsg Where to store the message id.
|
---|
101 | * @param puNumParms Where to store the number of parameters which will be received
|
---|
102 | * in a second call to the host.
|
---|
103 | */
|
---|
104 | VBGLR3DECL(int) VbglR3GuestCtrlWaitForHostMsg(uint32_t u32ClientId, uint32_t *puMsg, uint32_t *puNumParms)
|
---|
105 | {
|
---|
106 | AssertPtrReturn(puMsg, VERR_INVALID_POINTER);
|
---|
107 | AssertPtrReturn(puNumParms, VERR_INVALID_POINTER);
|
---|
108 |
|
---|
109 | VBoxGuestCtrlHGCMMsgType Msg;
|
---|
110 |
|
---|
111 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
112 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
113 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG; /* Tell the host we want our next command. */
|
---|
114 | Msg.hdr.cParms = 2; /* Just peek for the next message! */
|
---|
115 |
|
---|
116 | VbglHGCMParmUInt32Set(&Msg.msg, 0);
|
---|
117 | VbglHGCMParmUInt32Set(&Msg.num_parms, 0);
|
---|
118 |
|
---|
119 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
120 | if (RT_SUCCESS(rc))
|
---|
121 | {
|
---|
122 | rc = VbglHGCMParmUInt32Get(&Msg.msg, puMsg);
|
---|
123 | if (RT_SUCCESS(rc))
|
---|
124 | rc = VbglHGCMParmUInt32Get(&Msg.num_parms, puNumParms);
|
---|
125 | if (RT_SUCCESS(rc))
|
---|
126 | rc = Msg.hdr.result;
|
---|
127 | /* Ok, so now we know what message type and how much parameters there are. */
|
---|
128 | }
|
---|
129 | return rc;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Asks the host to cancel (release) all pending waits which were deferred.
|
---|
135 | *
|
---|
136 | * @returns VBox status code.
|
---|
137 | * @param u32ClientId The client id returned by VbglR3GuestCtrlConnect().
|
---|
138 | */
|
---|
139 | VBGLR3DECL(int) VbglR3GuestCtrlCancelPendingWaits(uint32_t u32ClientId)
|
---|
140 | {
|
---|
141 | VBoxGuestCtrlHGCMMsgCancelPendingWaits Msg;
|
---|
142 |
|
---|
143 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
144 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
145 | Msg.hdr.u32Function = GUEST_CANCEL_PENDING_WAITS;
|
---|
146 | Msg.hdr.cParms = 0;
|
---|
147 |
|
---|
148 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
149 | if (RT_SUCCESS(rc))
|
---|
150 | {
|
---|
151 | int rc2 = Msg.hdr.result;
|
---|
152 | if (RT_FAILURE(rc2))
|
---|
153 | rc = rc2;
|
---|
154 | }
|
---|
155 | return rc;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Allocates and gets host data, based on the message id.
|
---|
161 | *
|
---|
162 | * This will block until data becomes available.
|
---|
163 | *
|
---|
164 | * @returns VBox status code.
|
---|
165 | * @param u32ClientId The client id returned by VbglR3GuestCtrlConnect().
|
---|
166 | * @param uNumParms
|
---|
167 | ** @todo Docs!
|
---|
168 | */
|
---|
169 | VBGLR3DECL(int) VbglR3GuestCtrlExecGetHostCmdExec(uint32_t u32ClientId, uint32_t cParms,
|
---|
170 | uint32_t *puContext,
|
---|
171 | char *pszCmd, uint32_t cbCmd,
|
---|
172 | uint32_t *puFlags,
|
---|
173 | char *pszArgs, uint32_t cbArgs, uint32_t *pcArgs,
|
---|
174 | char *pszEnv, uint32_t *pcbEnv, uint32_t *pcEnvVars,
|
---|
175 | char *pszUser, uint32_t cbUser,
|
---|
176 | char *pszPassword, uint32_t cbPassword,
|
---|
177 | uint32_t *pcMsTimeLimit)
|
---|
178 | {
|
---|
179 | AssertReturn(cParms == 11, VERR_INVALID_PARAMETER);
|
---|
180 |
|
---|
181 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
182 | AssertPtrReturn(pszCmd, VERR_INVALID_POINTER);
|
---|
183 | AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
|
---|
184 | AssertPtrReturn(pszArgs, VERR_INVALID_POINTER);
|
---|
185 | AssertPtrReturn(pcArgs, VERR_INVALID_POINTER);
|
---|
186 | AssertPtrReturn(pszEnv, VERR_INVALID_POINTER);
|
---|
187 | AssertPtrReturn(pcbEnv, VERR_INVALID_POINTER);
|
---|
188 | AssertPtrReturn(pcEnvVars, VERR_INVALID_POINTER);
|
---|
189 | AssertPtrReturn(pszUser, VERR_INVALID_POINTER);
|
---|
190 | AssertPtrReturn(pszPassword, VERR_INVALID_POINTER);
|
---|
191 | AssertPtrReturn(pcMsTimeLimit, VERR_INVALID_POINTER);
|
---|
192 |
|
---|
193 | VBoxGuestCtrlHGCMMsgExecCmd Msg;
|
---|
194 |
|
---|
195 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
196 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
197 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
198 | Msg.hdr.cParms = 11;
|
---|
199 |
|
---|
200 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
201 | VbglHGCMParmPtrSet(&Msg.cmd, pszCmd, cbCmd);
|
---|
202 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
203 | VbglHGCMParmUInt32Set(&Msg.num_args, 0);
|
---|
204 | VbglHGCMParmPtrSet(&Msg.args, pszArgs, cbArgs);
|
---|
205 | VbglHGCMParmUInt32Set(&Msg.num_env, 0);
|
---|
206 | VbglHGCMParmUInt32Set(&Msg.cb_env, 0);
|
---|
207 | VbglHGCMParmPtrSet(&Msg.env, pszEnv, *pcbEnv);
|
---|
208 | VbglHGCMParmPtrSet(&Msg.username, pszUser, cbUser);
|
---|
209 | VbglHGCMParmPtrSet(&Msg.password, pszPassword, cbPassword);
|
---|
210 | VbglHGCMParmUInt32Set(&Msg.timeout, 0);
|
---|
211 |
|
---|
212 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
213 | if (RT_SUCCESS(rc))
|
---|
214 | {
|
---|
215 | int rc2 = Msg.hdr.result;
|
---|
216 | if (RT_FAILURE(rc2))
|
---|
217 | {
|
---|
218 | rc = rc2;
|
---|
219 | }
|
---|
220 | else
|
---|
221 | {
|
---|
222 | Msg.context.GetUInt32(puContext);
|
---|
223 | Msg.flags.GetUInt32(puFlags);
|
---|
224 | Msg.num_args.GetUInt32(pcArgs);
|
---|
225 | Msg.num_env.GetUInt32(pcEnvVars);
|
---|
226 | Msg.cb_env.GetUInt32(pcbEnv);
|
---|
227 | Msg.timeout.GetUInt32(pcMsTimeLimit);
|
---|
228 | }
|
---|
229 | }
|
---|
230 | return rc;
|
---|
231 | }
|
---|
232 |
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Allocates and gets host data, based on the message id.
|
---|
236 | *
|
---|
237 | * This will block until data becomes available.
|
---|
238 | *
|
---|
239 | * @returns VBox status code.
|
---|
240 | * @param u32ClientId The client id returned by VbglR3GuestCtrlConnect().
|
---|
241 | * @param cParms
|
---|
242 | ** @todo Docs!
|
---|
243 | */
|
---|
244 | VBGLR3DECL(int) VbglR3GuestCtrlExecGetHostCmdOutput(uint32_t u32ClientId, uint32_t cParms,
|
---|
245 | uint32_t *puContext, uint32_t *puPID,
|
---|
246 | uint32_t *puHandle, uint32_t *puFlags)
|
---|
247 | {
|
---|
248 | AssertReturn(cParms == 4, VERR_INVALID_PARAMETER);
|
---|
249 |
|
---|
250 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
251 | AssertPtrReturn(puPID, VERR_INVALID_POINTER);
|
---|
252 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
253 | AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
|
---|
254 |
|
---|
255 | VBoxGuestCtrlHGCMMsgExecOut Msg;
|
---|
256 |
|
---|
257 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
258 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
259 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
260 | Msg.hdr.cParms = 4;
|
---|
261 |
|
---|
262 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
263 | VbglHGCMParmUInt32Set(&Msg.pid, 0);
|
---|
264 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
265 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
266 |
|
---|
267 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
268 | if (RT_SUCCESS(rc))
|
---|
269 | {
|
---|
270 | int rc2 = Msg.hdr.result;
|
---|
271 | if (RT_FAILURE(rc2))
|
---|
272 | {
|
---|
273 | rc = rc2;
|
---|
274 | }
|
---|
275 | else
|
---|
276 | {
|
---|
277 | Msg.context.GetUInt32(puContext);
|
---|
278 | Msg.pid.GetUInt32(puPID);
|
---|
279 | Msg.handle.GetUInt32(puHandle);
|
---|
280 | Msg.flags.GetUInt32(puFlags);
|
---|
281 | }
|
---|
282 | }
|
---|
283 | return rc;
|
---|
284 | }
|
---|
285 |
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Retrieves the input data from host which then gets sent to the
|
---|
289 | * started process.
|
---|
290 | *
|
---|
291 | * This will block until data becomes available.
|
---|
292 | *
|
---|
293 | * @returns VBox status code.
|
---|
294 | * @param u32ClientId The client id returned by VbglR3GuestCtrlConnect().
|
---|
295 | * @param cParms
|
---|
296 | ** @todo Docs!
|
---|
297 | */
|
---|
298 | VBGLR3DECL(int) VbglR3GuestCtrlExecGetHostCmdInput(uint32_t u32ClientId, uint32_t cParms,
|
---|
299 | uint32_t *puContext, uint32_t *puPID,
|
---|
300 | uint32_t *puFlags,
|
---|
301 | void *pvData, uint32_t cbData,
|
---|
302 | uint32_t *pcbSize)
|
---|
303 | {
|
---|
304 | AssertReturn(cParms == 5, VERR_INVALID_PARAMETER);
|
---|
305 |
|
---|
306 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
307 | AssertPtrReturn(puPID, VERR_INVALID_POINTER);
|
---|
308 | AssertPtrReturn(puFlags, VERR_INVALID_POINTER);
|
---|
309 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
310 | AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
|
---|
311 |
|
---|
312 | VBoxGuestCtrlHGCMMsgExecIn Msg;
|
---|
313 |
|
---|
314 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
315 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
316 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
317 | Msg.hdr.cParms = 5;
|
---|
318 |
|
---|
319 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
320 | VbglHGCMParmUInt32Set(&Msg.pid, 0);
|
---|
321 | VbglHGCMParmUInt32Set(&Msg.flags, 0);
|
---|
322 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
323 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
324 |
|
---|
325 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
326 | if (RT_SUCCESS(rc))
|
---|
327 | {
|
---|
328 | int rc2 = Msg.hdr.result;
|
---|
329 | if (RT_FAILURE(rc2))
|
---|
330 | {
|
---|
331 | rc = rc2;
|
---|
332 | }
|
---|
333 | else
|
---|
334 | {
|
---|
335 | Msg.context.GetUInt32(puContext);
|
---|
336 | Msg.pid.GetUInt32(puPID);
|
---|
337 | Msg.flags.GetUInt32(puFlags);
|
---|
338 | Msg.size.GetUInt32(pcbSize);
|
---|
339 | }
|
---|
340 | }
|
---|
341 | return rc;
|
---|
342 | }
|
---|
343 |
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * Reports the process status (along with some other stuff) to the host.
|
---|
347 | *
|
---|
348 | * @returns VBox status code.
|
---|
349 | ** @todo Docs!
|
---|
350 | */
|
---|
351 | VBGLR3DECL(int) VbglR3GuestCtrlExecReportStatus(uint32_t u32ClientId,
|
---|
352 | uint32_t u32Context,
|
---|
353 | uint32_t u32PID,
|
---|
354 | uint32_t u32Status,
|
---|
355 | uint32_t u32Flags,
|
---|
356 | void *pvData,
|
---|
357 | uint32_t cbData)
|
---|
358 | {
|
---|
359 | VBoxGuestCtrlHGCMMsgExecStatus Msg;
|
---|
360 |
|
---|
361 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
362 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
363 | Msg.hdr.u32Function = GUEST_EXEC_SEND_STATUS;
|
---|
364 | Msg.hdr.cParms = 5;
|
---|
365 |
|
---|
366 | VbglHGCMParmUInt32Set(&Msg.context, u32Context);
|
---|
367 | VbglHGCMParmUInt32Set(&Msg.pid, u32PID);
|
---|
368 | VbglHGCMParmUInt32Set(&Msg.status, u32Status);
|
---|
369 | VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
|
---|
370 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
371 |
|
---|
372 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
373 | if (RT_SUCCESS(rc))
|
---|
374 | {
|
---|
375 | int rc2 = Msg.hdr.result;
|
---|
376 | if (RT_FAILURE(rc2))
|
---|
377 | rc = rc2;
|
---|
378 | }
|
---|
379 | return rc;
|
---|
380 | }
|
---|
381 |
|
---|
382 |
|
---|
383 | /**
|
---|
384 | * Sends output (from stdout/stderr) from a running process.
|
---|
385 | *
|
---|
386 | * @returns VBox status code.
|
---|
387 | ** @todo Docs!
|
---|
388 | */
|
---|
389 | VBGLR3DECL(int) VbglR3GuestCtrlExecSendOut(uint32_t u32ClientId,
|
---|
390 | uint32_t u32Context,
|
---|
391 | uint32_t u32PID,
|
---|
392 | uint32_t u32Handle,
|
---|
393 | uint32_t u32Flags,
|
---|
394 | void *pvData,
|
---|
395 | uint32_t cbData)
|
---|
396 | {
|
---|
397 | VBoxGuestCtrlHGCMMsgExecOut Msg;
|
---|
398 |
|
---|
399 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
400 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
401 | Msg.hdr.u32Function = GUEST_EXEC_SEND_OUTPUT;
|
---|
402 | Msg.hdr.cParms = 5;
|
---|
403 |
|
---|
404 | VbglHGCMParmUInt32Set(&Msg.context, u32Context);
|
---|
405 | VbglHGCMParmUInt32Set(&Msg.pid, u32PID);
|
---|
406 | VbglHGCMParmUInt32Set(&Msg.handle, u32Handle);
|
---|
407 | VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
|
---|
408 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
409 |
|
---|
410 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
411 | if (RT_SUCCESS(rc))
|
---|
412 | {
|
---|
413 | int rc2 = Msg.hdr.result;
|
---|
414 | if (RT_FAILURE(rc2))
|
---|
415 | rc = rc2;
|
---|
416 | }
|
---|
417 | return rc;
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * Reports back the input status to the host.
|
---|
423 | *
|
---|
424 | * @returns VBox status code.
|
---|
425 | ** @todo Docs!
|
---|
426 | */
|
---|
427 | VBGLR3DECL(int) VbglR3GuestCtrlExecReportStatusIn(uint32_t u32ClientId,
|
---|
428 | uint32_t u32Context,
|
---|
429 | uint32_t u32PID,
|
---|
430 | uint32_t u32Status,
|
---|
431 | uint32_t u32Flags,
|
---|
432 | uint32_t cbWritten)
|
---|
433 | {
|
---|
434 | VBoxGuestCtrlHGCMMsgExecStatusIn Msg;
|
---|
435 |
|
---|
436 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
437 | Msg.hdr.u32ClientID = u32ClientId;
|
---|
438 | Msg.hdr.u32Function = GUEST_EXEC_SEND_INPUT_STATUS;
|
---|
439 | Msg.hdr.cParms = 5;
|
---|
440 |
|
---|
441 | VbglHGCMParmUInt32Set(&Msg.context, u32Context);
|
---|
442 | VbglHGCMParmUInt32Set(&Msg.pid, u32PID);
|
---|
443 | VbglHGCMParmUInt32Set(&Msg.status, u32Status);
|
---|
444 | VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
|
---|
445 | VbglHGCMParmUInt32Set(&Msg.written, cbWritten);
|
---|
446 |
|
---|
447 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
448 | if (RT_SUCCESS(rc))
|
---|
449 | {
|
---|
450 | int rc2 = Msg.hdr.result;
|
---|
451 | if (RT_FAILURE(rc2))
|
---|
452 | rc = rc2;
|
---|
453 | }
|
---|
454 | return rc;
|
---|
455 | }
|
---|
456 |
|
---|
457 |
|
---|
458 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetHostCmdOpen(uint32_t uClientId, uint32_t cParms,
|
---|
459 | uint32_t *puContext,
|
---|
460 | char *pszFileName, uint32_t cbFileName,
|
---|
461 | char *pszOpenMode, uint32_t cbOpenMode,
|
---|
462 | char *pszDisposition, uint32_t cbDisposition,
|
---|
463 | uint32_t *puCreationMode,
|
---|
464 | uint64_t *puOffset)
|
---|
465 | {
|
---|
466 | AssertReturn(cParms == 6, VERR_INVALID_PARAMETER);
|
---|
467 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
468 | AssertPtrReturn(pszFileName, VERR_INVALID_POINTER);
|
---|
469 | AssertReturn(cbFileName, VERR_INVALID_PARAMETER);
|
---|
470 | AssertPtrReturn(pszOpenMode, VERR_INVALID_POINTER);
|
---|
471 | AssertReturn(cbOpenMode, VERR_INVALID_PARAMETER);
|
---|
472 | AssertPtrReturn(pszDisposition, VERR_INVALID_POINTER);
|
---|
473 | AssertReturn(cbDisposition, VERR_INVALID_PARAMETER);
|
---|
474 | AssertPtrReturn(puCreationMode, VERR_INVALID_POINTER);
|
---|
475 | AssertPtrReturn(puOffset, VERR_INVALID_POINTER);
|
---|
476 |
|
---|
477 | VBoxGuestCtrlHGCMMsgFileOpen Msg;
|
---|
478 |
|
---|
479 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
480 | Msg.hdr.u32ClientID = uClientId;
|
---|
481 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
482 | Msg.hdr.cParms = 6;
|
---|
483 |
|
---|
484 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
485 | VbglHGCMParmPtrSet(&Msg.filename, pszFileName, cbFileName);
|
---|
486 | VbglHGCMParmPtrSet(&Msg.openmode, pszOpenMode, cbOpenMode);
|
---|
487 | VbglHGCMParmPtrSet(&Msg.disposition, pszDisposition, cbDisposition);
|
---|
488 | VbglHGCMParmUInt32Set(&Msg.creationmode, 0);
|
---|
489 | VbglHGCMParmUInt64Set(&Msg.offset, 0);
|
---|
490 |
|
---|
491 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
492 | if (RT_SUCCESS(rc))
|
---|
493 | {
|
---|
494 | int rc2 = Msg.hdr.result;
|
---|
495 | if (RT_FAILURE(rc2))
|
---|
496 | {
|
---|
497 | rc = rc2;
|
---|
498 | }
|
---|
499 | else
|
---|
500 | {
|
---|
501 | Msg.context.GetUInt32(puContext);
|
---|
502 | Msg.creationmode.GetUInt32(puCreationMode);
|
---|
503 | Msg.offset.GetUInt64(puOffset);
|
---|
504 | }
|
---|
505 | }
|
---|
506 | return rc;
|
---|
507 | }
|
---|
508 |
|
---|
509 |
|
---|
510 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetHostCmdClose(uint32_t uClientId, uint32_t cParms,
|
---|
511 | uint32_t *puContext,
|
---|
512 | uint32_t *puHandle)
|
---|
513 | {
|
---|
514 | AssertReturn(cParms == 2, VERR_INVALID_PARAMETER);
|
---|
515 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
516 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
517 |
|
---|
518 | VBoxGuestCtrlHGCMMsgFileClose Msg;
|
---|
519 |
|
---|
520 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
521 | Msg.hdr.u32ClientID = uClientId;
|
---|
522 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
523 | Msg.hdr.cParms = 2;
|
---|
524 |
|
---|
525 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
526 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
527 |
|
---|
528 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
529 | if (RT_SUCCESS(rc))
|
---|
530 | {
|
---|
531 | int rc2 = Msg.hdr.result;
|
---|
532 | if (RT_FAILURE(rc2))
|
---|
533 | {
|
---|
534 | rc = rc2;
|
---|
535 | }
|
---|
536 | else
|
---|
537 | {
|
---|
538 | Msg.context.GetUInt32(puContext);
|
---|
539 | Msg.handle.GetUInt32(puHandle);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | return rc;
|
---|
543 | }
|
---|
544 |
|
---|
545 |
|
---|
546 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetHostCmdRead(uint32_t uClientId, uint32_t cParms,
|
---|
547 | uint32_t *puContext,
|
---|
548 | uint32_t *puHandle, uint32_t *puToRead)
|
---|
549 | {
|
---|
550 | AssertReturn(cParms == 4, VERR_INVALID_PARAMETER);
|
---|
551 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
552 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
553 | AssertPtrReturn(puToRead, VERR_INVALID_POINTER);
|
---|
554 |
|
---|
555 | VBoxGuestCtrlHGCMMsgFileRead Msg;
|
---|
556 |
|
---|
557 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
558 | Msg.hdr.u32ClientID = uClientId;
|
---|
559 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
560 | Msg.hdr.cParms = 4;
|
---|
561 |
|
---|
562 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
563 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
564 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
565 |
|
---|
566 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
567 | if (RT_SUCCESS(rc))
|
---|
568 | {
|
---|
569 | int rc2 = Msg.hdr.result;
|
---|
570 | if (RT_FAILURE(rc2))
|
---|
571 | {
|
---|
572 | rc = rc2;
|
---|
573 | }
|
---|
574 | else
|
---|
575 | {
|
---|
576 | Msg.context.GetUInt32(puContext);
|
---|
577 | Msg.handle.GetUInt32(puHandle);
|
---|
578 | Msg.size.GetUInt32(puToRead);
|
---|
579 | }
|
---|
580 | }
|
---|
581 | return rc;
|
---|
582 | }
|
---|
583 |
|
---|
584 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetHostCmdWrite(uint32_t uClientId, uint32_t cParms,
|
---|
585 | uint32_t *puContext,
|
---|
586 | uint32_t *puHandle,
|
---|
587 | void *pvData, uint32_t cbData,
|
---|
588 | uint32_t *pcbSize)
|
---|
589 | {
|
---|
590 | AssertReturn(cParms == 4, VERR_INVALID_PARAMETER);
|
---|
591 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
592 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
593 | AssertPtrReturn(pvData, VERR_INVALID_POINTER);
|
---|
594 | AssertReturn(cbData, VERR_INVALID_PARAMETER);
|
---|
595 | AssertPtrReturn(pcbSize, VERR_INVALID_POINTER);
|
---|
596 |
|
---|
597 | VBoxGuestCtrlHGCMMsgFileWrite Msg;
|
---|
598 |
|
---|
599 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
600 | Msg.hdr.u32ClientID = uClientId;
|
---|
601 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
602 | Msg.hdr.cParms = 4;
|
---|
603 |
|
---|
604 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
605 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
606 | VbglHGCMParmPtrSet(&Msg.data, pvData, cbData);
|
---|
607 | VbglHGCMParmUInt32Set(&Msg.size, 0);
|
---|
608 |
|
---|
609 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
610 | if (RT_SUCCESS(rc))
|
---|
611 | {
|
---|
612 | int rc2 = Msg.hdr.result;
|
---|
613 | if (RT_FAILURE(rc2))
|
---|
614 | {
|
---|
615 | rc = rc2;
|
---|
616 | }
|
---|
617 | else
|
---|
618 | {
|
---|
619 | Msg.context.GetUInt32(puContext);
|
---|
620 | Msg.handle.GetUInt32(puHandle);
|
---|
621 | Msg.size.GetUInt32(pcbSize);
|
---|
622 | }
|
---|
623 | }
|
---|
624 | return rc;
|
---|
625 | }
|
---|
626 |
|
---|
627 |
|
---|
628 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetHostCmdSeek(uint32_t uClientId, uint32_t cParms,
|
---|
629 | uint32_t *puContext,
|
---|
630 | uint32_t *puHandle,
|
---|
631 | uint32_t *puSeekMethod, uint64_t *puOffset)
|
---|
632 | {
|
---|
633 | AssertReturn(cParms == 4, VERR_INVALID_PARAMETER);
|
---|
634 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
635 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
636 | AssertPtrReturn(puSeekMethod, VERR_INVALID_POINTER);
|
---|
637 | AssertPtrReturn(puOffset, VERR_INVALID_POINTER);
|
---|
638 |
|
---|
639 | VBoxGuestCtrlHGCMMsgFileSeek Msg;
|
---|
640 |
|
---|
641 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
642 | Msg.hdr.u32ClientID = uClientId;
|
---|
643 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
644 | Msg.hdr.cParms = 4;
|
---|
645 |
|
---|
646 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
647 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
648 | VbglHGCMParmUInt32Set(&Msg.method, 0);
|
---|
649 | VbglHGCMParmUInt64Set(&Msg.offset, 0);
|
---|
650 |
|
---|
651 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
652 | if (RT_SUCCESS(rc))
|
---|
653 | {
|
---|
654 | int rc2 = Msg.hdr.result;
|
---|
655 | if (RT_FAILURE(rc2))
|
---|
656 | {
|
---|
657 | rc = rc2;
|
---|
658 | }
|
---|
659 | else
|
---|
660 | {
|
---|
661 | Msg.context.GetUInt32(puContext);
|
---|
662 | Msg.handle.GetUInt32(puHandle);
|
---|
663 | Msg.method.GetUInt32(puSeekMethod);
|
---|
664 | Msg.offset.GetUInt64(puOffset);
|
---|
665 | }
|
---|
666 | }
|
---|
667 | return rc;
|
---|
668 | }
|
---|
669 |
|
---|
670 |
|
---|
671 | VBGLR3DECL(int) VbglR3GuestCtrlFileGetHostCmdTell(uint32_t uClientId, uint32_t cParms,
|
---|
672 | uint32_t *puContext,
|
---|
673 | uint32_t *puHandle)
|
---|
674 | {
|
---|
675 | AssertReturn(cParms == 2, VERR_INVALID_PARAMETER);
|
---|
676 | AssertPtrReturn(puContext, VERR_INVALID_POINTER);
|
---|
677 | AssertPtrReturn(puHandle, VERR_INVALID_POINTER);
|
---|
678 |
|
---|
679 | VBoxGuestCtrlHGCMMsgFileTell Msg;
|
---|
680 |
|
---|
681 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
682 | Msg.hdr.u32ClientID = uClientId;
|
---|
683 | Msg.hdr.u32Function = GUEST_GET_HOST_MSG;
|
---|
684 | Msg.hdr.cParms = 2;
|
---|
685 |
|
---|
686 | VbglHGCMParmUInt32Set(&Msg.context, 0);
|
---|
687 | VbglHGCMParmUInt32Set(&Msg.handle, 0);
|
---|
688 |
|
---|
689 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
690 | if (RT_SUCCESS(rc))
|
---|
691 | {
|
---|
692 | int rc2 = Msg.hdr.result;
|
---|
693 | if (RT_FAILURE(rc2))
|
---|
694 | {
|
---|
695 | rc = rc2;
|
---|
696 | }
|
---|
697 | else
|
---|
698 | {
|
---|
699 | Msg.context.GetUInt32(puContext);
|
---|
700 | Msg.handle.GetUInt32(puHandle);
|
---|
701 | }
|
---|
702 | }
|
---|
703 | return rc;
|
---|
704 | }
|
---|
705 |
|
---|
706 |
|
---|
707 | VBGLR3DECL(int) VbglR3GuestCtrlFileNotify(uint32_t uClientId,
|
---|
708 | uint32_t uContext, uint32_t uHandle,
|
---|
709 | uint32_t uType,
|
---|
710 | void *pvPayload, uint32_t cbPayload)
|
---|
711 | {
|
---|
712 | AssertPtrReturn(uContext, VERR_INVALID_POINTER);
|
---|
713 | AssertPtrReturn(uHandle, VERR_INVALID_POINTER);
|
---|
714 | AssertPtrReturn(pvPayload, VERR_INVALID_POINTER);
|
---|
715 | AssertReturn(cbPayload, VERR_INVALID_PARAMETER);
|
---|
716 |
|
---|
717 | VBoxGuestCtrlHGCMMsgFileNotify Msg;
|
---|
718 |
|
---|
719 | Msg.hdr.result = VERR_WRONG_ORDER;
|
---|
720 | Msg.hdr.u32ClientID = uClientId;
|
---|
721 | Msg.hdr.u32Function = GUEST_FILE_NOTIFY;
|
---|
722 | Msg.hdr.cParms = 4;
|
---|
723 |
|
---|
724 | VbglHGCMParmUInt32Set(&Msg.context, uContext);
|
---|
725 | VbglHGCMParmUInt32Set(&Msg.handle, uHandle);
|
---|
726 | VbglHGCMParmUInt32Set(&Msg.type, uType);
|
---|
727 | VbglHGCMParmPtrSet(&Msg.payload, pvPayload, cbPayload);
|
---|
728 |
|
---|
729 | int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
|
---|
730 | if (RT_SUCCESS(rc))
|
---|
731 | {
|
---|
732 | int rc2 = Msg.hdr.result;
|
---|
733 | if (RT_FAILURE(rc2))
|
---|
734 | rc = rc2;
|
---|
735 | }
|
---|
736 | return rc;
|
---|
737 | }
|
---|
738 |
|
---|