1 | /** @file
|
---|
2 | * Host-Guest Communication Manager (HGCM) - Service library definitions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef VBOX_INCLUDED_hgcmsvc_h
|
---|
27 | #define VBOX_INCLUDED_hgcmsvc_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/assert.h>
|
---|
33 | #include <iprt/stdarg.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 | #include <VBox/cdefs.h>
|
---|
36 | #include <VBox/types.h>
|
---|
37 | #include <iprt/err.h>
|
---|
38 | #ifdef IN_RING3
|
---|
39 | # include <iprt/mem.h>
|
---|
40 | # include <VBox/err.h>
|
---|
41 | # include <VBox/vmm/stam.h>
|
---|
42 | # include <VBox/vmm/dbgf.h>
|
---|
43 | # include <VBox/vmm/ssm.h>
|
---|
44 | #endif
|
---|
45 | #ifdef VBOX_TEST_HGCM_PARMS
|
---|
46 | # include <iprt/test.h>
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | /** @todo proper comments. */
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Service interface version.
|
---|
53 | *
|
---|
54 | * Includes layout of both VBOXHGCMSVCFNTABLE and VBOXHGCMSVCHELPERS.
|
---|
55 | *
|
---|
56 | * A service can work with these structures if major version
|
---|
57 | * is equal and minor version of service is <= version of the
|
---|
58 | * structures.
|
---|
59 | *
|
---|
60 | * For example when a new helper is added at the end of helpers
|
---|
61 | * structure, then the minor version will be increased. All older
|
---|
62 | * services still can work because they have their old helpers
|
---|
63 | * unchanged.
|
---|
64 | *
|
---|
65 | * Revision history.
|
---|
66 | * 1.1->2.1 Because the pfnConnect now also has the pvClient parameter.
|
---|
67 | * 2.1->2.2 Because pfnSaveState and pfnLoadState were added
|
---|
68 | * 2.2->3.1 Because pfnHostCall is now synchronous, returns rc, and parameters were changed
|
---|
69 | * 3.1->3.2 Because pfnRegisterExtension was added
|
---|
70 | * 3.2->3.3 Because pfnDisconnectClient helper was added
|
---|
71 | * 3.3->4.1 Because the pvService entry and parameter was added
|
---|
72 | * 4.1->4.2 Because the VBOX_HGCM_SVC_PARM_CALLBACK parameter type was added
|
---|
73 | * 4.2->5.1 Removed the VBOX_HGCM_SVC_PARM_CALLBACK parameter type, as
|
---|
74 | * this problem is already solved by service extension callbacks
|
---|
75 | * 5.1->6.1 Because pfnCall got a new parameter. Also new helpers. (VBox 6.0)
|
---|
76 | * 6.1->6.2 Because pfnCallComplete starts returning a status code (VBox 6.0).
|
---|
77 | * 6.2->6.3 Because pfnGetRequestor was added (VBox 6.0).
|
---|
78 | * 6.3->6.4 Bacause pfnConnect got an additional parameter (VBox 6.0).
|
---|
79 | * 6.4->6.5 Bacause pfnGetVMMDevSessionId was added pfnLoadState got the version
|
---|
80 | * parameter (VBox 6.0).
|
---|
81 | * 6.5->7.1 Because pfnNotify was added (VBox 6.0).
|
---|
82 | * 7.1->8.1 Because pfnCancelled & pfnIsCallCancelled were added (VBox 6.0).
|
---|
83 | */
|
---|
84 | #define VBOX_HGCM_SVC_VERSION_MAJOR (0x0008)
|
---|
85 | #define VBOX_HGCM_SVC_VERSION_MINOR (0x0001)
|
---|
86 | #define VBOX_HGCM_SVC_VERSION ((VBOX_HGCM_SVC_VERSION_MAJOR << 16) + VBOX_HGCM_SVC_VERSION_MINOR)
|
---|
87 |
|
---|
88 |
|
---|
89 | /** Typed pointer to distinguish a call to service. */
|
---|
90 | struct VBOXHGCMCALLHANDLE_TYPEDEF;
|
---|
91 | typedef struct VBOXHGCMCALLHANDLE_TYPEDEF *VBOXHGCMCALLHANDLE;
|
---|
92 |
|
---|
93 | /** Service helpers pointers table. */
|
---|
94 | typedef struct VBOXHGCMSVCHELPERS
|
---|
95 | {
|
---|
96 | /** The service has processed the Call request. */
|
---|
97 | DECLR3CALLBACKMEMBER(int, pfnCallComplete, (VBOXHGCMCALLHANDLE callHandle, int32_t rc));
|
---|
98 |
|
---|
99 | void *pvInstance;
|
---|
100 |
|
---|
101 | /** The service disconnects the client. */
|
---|
102 | DECLR3CALLBACKMEMBER(void, pfnDisconnectClient, (void *pvInstance, uint32_t u32ClientID));
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Check if the @a callHandle is for a call restored and re-submitted from saved state.
|
---|
106 | *
|
---|
107 | * @returns true if restored, false if not.
|
---|
108 | * @param callHandle The call we're checking up on.
|
---|
109 | */
|
---|
110 | DECLR3CALLBACKMEMBER(bool, pfnIsCallRestored, (VBOXHGCMCALLHANDLE callHandle));
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Check if the @a callHandle is for a cancelled call.
|
---|
114 | *
|
---|
115 | * @returns true if cancelled, false if not.
|
---|
116 | * @param callHandle The call we're checking up on.
|
---|
117 | */
|
---|
118 | DECLR3CALLBACKMEMBER(bool, pfnIsCallCancelled, (VBOXHGCMCALLHANDLE callHandle));
|
---|
119 |
|
---|
120 | /** Access to STAMR3RegisterV. */
|
---|
121 | DECLR3CALLBACKMEMBER(int, pfnStamRegisterV,(void *pvInstance, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
122 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list va)
|
---|
123 | RT_IPRT_FORMAT_ATTR(7, 0));
|
---|
124 | /** Access to STAMR3DeregisterV. */
|
---|
125 | DECLR3CALLBACKMEMBER(int, pfnStamDeregisterV,(void *pvInstance, const char *pszPatFmt, va_list va) RT_IPRT_FORMAT_ATTR(2, 0));
|
---|
126 |
|
---|
127 | /** Access to DBGFR3InfoRegisterExternal. */
|
---|
128 | DECLR3CALLBACKMEMBER(int, pfnInfoRegister,(void *pvInstance, const char *pszName, const char *pszDesc,
|
---|
129 | PFNDBGFHANDLEREXT pfnHandler, void *pvUser));
|
---|
130 | /** Access to DBGFR3InfoDeregisterExternal. */
|
---|
131 | DECLR3CALLBACKMEMBER(int, pfnInfoDeregister,(void *pvInstance, const char *pszName));
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Retrieves the VMMDevRequestHeader::fRequestor value.
|
---|
135 | *
|
---|
136 | * @returns The field value, VMMDEV_REQUESTOR_LEGACY if not supported by the
|
---|
137 | * guest, VMMDEV_REQUESTOR_LOWEST if invalid call.
|
---|
138 | * @param hCall The call we're checking up on.
|
---|
139 | */
|
---|
140 | DECLR3CALLBACKMEMBER(uint32_t, pfnGetRequestor, (VBOXHGCMCALLHANDLE hCall));
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Retrieves VMMDevState::idSession.
|
---|
144 | *
|
---|
145 | * @returns current VMMDev session ID value.
|
---|
146 | */
|
---|
147 | DECLR3CALLBACKMEMBER(uint64_t, pfnGetVMMDevSessionId, (void *pvInstance));
|
---|
148 |
|
---|
149 | } VBOXHGCMSVCHELPERS;
|
---|
150 |
|
---|
151 | typedef VBOXHGCMSVCHELPERS *PVBOXHGCMSVCHELPERS;
|
---|
152 |
|
---|
153 | #if defined(IN_RING3) || defined(IN_SLICKEDIT)
|
---|
154 |
|
---|
155 | /** Wrapper around STAMR3RegisterF. */
|
---|
156 | DECLINLINE(int) RT_IPRT_FORMAT_ATTR(7, 8)
|
---|
157 | HGCMSvcHlpStamRegister(PVBOXHGCMSVCHELPERS pHlp, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
158 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
|
---|
159 | {
|
---|
160 | int rc;
|
---|
161 | va_list va;
|
---|
162 | va_start(va, pszName);
|
---|
163 | rc = pHlp->pfnStamRegisterV(pHlp->pvInstance, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
|
---|
164 | va_end(va);
|
---|
165 | return rc;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /** Wrapper around STAMR3RegisterV. */
|
---|
169 | DECLINLINE(int) RT_IPRT_FORMAT_ATTR(7, 0)
|
---|
170 | HGCMSvcHlpStamRegisterV(PVBOXHGCMSVCHELPERS pHlp, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
171 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list va)
|
---|
172 | {
|
---|
173 | return pHlp->pfnStamRegisterV(pHlp->pvInstance, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, va);
|
---|
174 | }
|
---|
175 |
|
---|
176 | /** Wrapper around STAMR3DeregisterF. */
|
---|
177 | DECLINLINE(int) RT_IPRT_FORMAT_ATTR(2, 3) HGCMSvcHlpStamDeregister(PVBOXHGCMSVCHELPERS pHlp, const char *pszPatFmt, ...)
|
---|
178 | {
|
---|
179 | int rc;
|
---|
180 | va_list va;
|
---|
181 | va_start(va, pszPatFmt);
|
---|
182 | rc = pHlp->pfnStamDeregisterV(pHlp->pvInstance, pszPatFmt, va);
|
---|
183 | va_end(va);
|
---|
184 | return rc;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /** Wrapper around STAMR3DeregisterV. */
|
---|
188 | DECLINLINE(int) RT_IPRT_FORMAT_ATTR(2, 0) HGCMSvcHlpStamDeregisterV(PVBOXHGCMSVCHELPERS pHlp, const char *pszPatFmt, va_list va)
|
---|
189 | {
|
---|
190 | return pHlp->pfnStamDeregisterV(pHlp->pvInstance, pszPatFmt, va);
|
---|
191 | }
|
---|
192 |
|
---|
193 | /** Wrapper around DBGFR3InfoRegisterExternal. */
|
---|
194 | DECLINLINE(int) HGCMSvcHlpInfoRegister(PVBOXHGCMSVCHELPERS pHlp, const char *pszName, const char *pszDesc,
|
---|
195 | PFNDBGFHANDLEREXT pfnHandler, void *pvUser)
|
---|
196 | {
|
---|
197 | return pHlp->pfnInfoRegister(pHlp->pvInstance, pszName, pszDesc, pfnHandler, pvUser);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /** Wrapper around DBGFR3InfoDeregisterExternal. */
|
---|
201 | DECLINLINE(int) HGCMSvcHlpInfoDeregister(PVBOXHGCMSVCHELPERS pHlp, const char *pszName)
|
---|
202 | {
|
---|
203 | return pHlp->pfnInfoDeregister(pHlp->pvInstance, pszName);
|
---|
204 | }
|
---|
205 |
|
---|
206 | #endif /* IN_RING3 */
|
---|
207 |
|
---|
208 |
|
---|
209 | #define VBOX_HGCM_SVC_PARM_INVALID (0U)
|
---|
210 | #define VBOX_HGCM_SVC_PARM_32BIT (1U)
|
---|
211 | #define VBOX_HGCM_SVC_PARM_64BIT (2U)
|
---|
212 | #define VBOX_HGCM_SVC_PARM_PTR (3U)
|
---|
213 | #define VBOX_HGCM_SVC_PARM_PAGES (4U)
|
---|
214 |
|
---|
215 | /** VBOX_HGCM_SVC_PARM_PAGES specific data. */
|
---|
216 | typedef struct VBOXHGCMSVCPARMPAGES
|
---|
217 | {
|
---|
218 | uint32_t cb;
|
---|
219 | uint16_t cPages;
|
---|
220 | uint16_t u16Padding;
|
---|
221 | void **papvPages;
|
---|
222 | } VBOXHGCMSVCPARMPAGES;
|
---|
223 | typedef VBOXHGCMSVCPARMPAGES *PVBOXHGCMSVCPARMPAGES;
|
---|
224 |
|
---|
225 | typedef struct VBOXHGCMSVCPARM
|
---|
226 | {
|
---|
227 | /** VBOX_HGCM_SVC_PARM_* values. */
|
---|
228 | uint32_t type;
|
---|
229 |
|
---|
230 | union
|
---|
231 | {
|
---|
232 | uint32_t uint32;
|
---|
233 | uint64_t uint64;
|
---|
234 | struct
|
---|
235 | {
|
---|
236 | uint32_t size;
|
---|
237 | void *addr;
|
---|
238 | } pointer;
|
---|
239 | /** VBOX_HGCM_SVC_PARM_PAGES */
|
---|
240 | VBOXHGCMSVCPARMPAGES Pages;
|
---|
241 | } u;
|
---|
242 | } VBOXHGCMSVCPARM;
|
---|
243 |
|
---|
244 | /** Extract an uint32_t value from an HGCM parameter structure. */
|
---|
245 | DECLINLINE(int) HGCMSvcGetU32(VBOXHGCMSVCPARM *pParm, uint32_t *pu32)
|
---|
246 | {
|
---|
247 | int rc = VINF_SUCCESS;
|
---|
248 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
249 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
250 | AssertPtrReturn(pu32, VERR_INVALID_POINTER);
|
---|
251 | if (pParm->type != VBOX_HGCM_SVC_PARM_32BIT)
|
---|
252 | rc = VERR_INVALID_PARAMETER;
|
---|
253 | if (RT_SUCCESS(rc))
|
---|
254 | *pu32 = pParm->u.uint32;
|
---|
255 | return rc;
|
---|
256 | }
|
---|
257 |
|
---|
258 | /** Extract an uint64_t value from an HGCM parameter structure. */
|
---|
259 | DECLINLINE(int) HGCMSvcGetU64(VBOXHGCMSVCPARM *pParm, uint64_t *pu64)
|
---|
260 | {
|
---|
261 | int rc = VINF_SUCCESS;
|
---|
262 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
263 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
264 | AssertPtrReturn(pu64, VERR_INVALID_POINTER);
|
---|
265 | if (pParm->type != VBOX_HGCM_SVC_PARM_64BIT)
|
---|
266 | rc = VERR_INVALID_PARAMETER;
|
---|
267 | if (RT_SUCCESS(rc))
|
---|
268 | *pu64 = pParm->u.uint64;
|
---|
269 | return rc;
|
---|
270 | }
|
---|
271 |
|
---|
272 | /** Extract an pointer value from an HGCM parameter structure. */
|
---|
273 | DECLINLINE(int) HGCMSvcGetPv(VBOXHGCMSVCPARM *pParm, void **ppv, uint32_t *pcb)
|
---|
274 | {
|
---|
275 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
276 | AssertPtrReturn(ppv, VERR_INVALID_POINTER);
|
---|
277 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
278 | if (pParm->type == VBOX_HGCM_SVC_PARM_PTR)
|
---|
279 | {
|
---|
280 | *ppv = pParm->u.pointer.addr;
|
---|
281 | *pcb = pParm->u.pointer.size;
|
---|
282 | return VINF_SUCCESS;
|
---|
283 | }
|
---|
284 |
|
---|
285 | return VERR_INVALID_PARAMETER;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /** Extract a constant pointer value from an HGCM parameter structure. */
|
---|
289 | DECLINLINE(int) HGCMSvcGetPcv(VBOXHGCMSVCPARM *pParm, const void **ppv, uint32_t *pcb)
|
---|
290 | {
|
---|
291 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
292 | AssertPtrReturn(ppv, VERR_INVALID_POINTER);
|
---|
293 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
294 | if (pParm->type == VBOX_HGCM_SVC_PARM_PTR)
|
---|
295 | {
|
---|
296 | *ppv = (const void *)pParm->u.pointer.addr;
|
---|
297 | *pcb = pParm->u.pointer.size;
|
---|
298 | return VINF_SUCCESS;
|
---|
299 | }
|
---|
300 |
|
---|
301 | return VERR_INVALID_PARAMETER;
|
---|
302 | }
|
---|
303 |
|
---|
304 | /** Extract a valid pointer to a non-empty buffer from an HGCM parameter
|
---|
305 | * structure. */
|
---|
306 | DECLINLINE(int) HGCMSvcGetBuf(VBOXHGCMSVCPARM *pParm, void **ppv, uint32_t *pcb)
|
---|
307 | {
|
---|
308 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
309 | AssertPtrReturn(ppv, VERR_INVALID_POINTER);
|
---|
310 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
311 | if ( pParm->type == VBOX_HGCM_SVC_PARM_PTR
|
---|
312 | && VALID_PTR(pParm->u.pointer.addr)
|
---|
313 | && pParm->u.pointer.size > 0)
|
---|
314 | {
|
---|
315 | *ppv = pParm->u.pointer.addr;
|
---|
316 | *pcb = pParm->u.pointer.size;
|
---|
317 | return VINF_SUCCESS;
|
---|
318 | }
|
---|
319 |
|
---|
320 | return VERR_INVALID_PARAMETER;
|
---|
321 | }
|
---|
322 |
|
---|
323 | /** Extract a valid pointer to a non-empty constant buffer from an HGCM
|
---|
324 | * parameter structure. */
|
---|
325 | DECLINLINE(int) HGCMSvcGetCBuf(VBOXHGCMSVCPARM *pParm, const void **ppv, uint32_t *pcb)
|
---|
326 | {
|
---|
327 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
328 | AssertPtrReturn(ppv, VERR_INVALID_POINTER);
|
---|
329 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
330 | if ( pParm->type == VBOX_HGCM_SVC_PARM_PTR
|
---|
331 | && VALID_PTR(pParm->u.pointer.addr)
|
---|
332 | && pParm->u.pointer.size > 0)
|
---|
333 | {
|
---|
334 | *ppv = (const void *)pParm->u.pointer.addr;
|
---|
335 | *pcb = pParm->u.pointer.size;
|
---|
336 | return VINF_SUCCESS;
|
---|
337 | }
|
---|
338 |
|
---|
339 | return VERR_INVALID_PARAMETER;
|
---|
340 | }
|
---|
341 |
|
---|
342 | /** Extract a string value from an HGCM parameter structure. */
|
---|
343 | DECLINLINE(int) HGCMSvcGetStr(VBOXHGCMSVCPARM *pParm, char **ppch, uint32_t *pcb)
|
---|
344 | {
|
---|
345 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
346 | AssertPtrReturn(ppch, VERR_INVALID_POINTER);
|
---|
347 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
348 | if ( pParm->type == VBOX_HGCM_SVC_PARM_PTR
|
---|
349 | && VALID_PTR(pParm->u.pointer.addr)
|
---|
350 | && pParm->u.pointer.size > 0)
|
---|
351 | {
|
---|
352 | int rc = RTStrValidateEncodingEx((char *)pParm->u.pointer.addr,
|
---|
353 | pParm->u.pointer.size,
|
---|
354 | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
|
---|
355 | if (RT_FAILURE(rc))
|
---|
356 | return rc;
|
---|
357 | *ppch = (char *)pParm->u.pointer.addr;
|
---|
358 | *pcb = pParm->u.pointer.size;
|
---|
359 | return VINF_SUCCESS;
|
---|
360 | }
|
---|
361 |
|
---|
362 | return VERR_INVALID_PARAMETER;
|
---|
363 | }
|
---|
364 |
|
---|
365 | /** Extract a constant string value from an HGCM parameter structure. */
|
---|
366 | DECLINLINE(int) HGCMSvcGetCStr(VBOXHGCMSVCPARM *pParm, const char **ppch, uint32_t *pcb)
|
---|
367 | {
|
---|
368 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
369 | AssertPtrReturn(ppch, VERR_INVALID_POINTER);
|
---|
370 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
371 | if ( pParm->type == VBOX_HGCM_SVC_PARM_PTR
|
---|
372 | && VALID_PTR(pParm->u.pointer.addr)
|
---|
373 | && pParm->u.pointer.size > 0)
|
---|
374 | {
|
---|
375 | int rc = RTStrValidateEncodingEx((char *)pParm->u.pointer.addr,
|
---|
376 | pParm->u.pointer.size,
|
---|
377 | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
|
---|
378 | if (RT_FAILURE(rc))
|
---|
379 | return rc;
|
---|
380 | *ppch = (char *)pParm->u.pointer.addr;
|
---|
381 | *pcb = pParm->u.pointer.size;
|
---|
382 | return VINF_SUCCESS;
|
---|
383 | }
|
---|
384 |
|
---|
385 | return VERR_INVALID_PARAMETER;
|
---|
386 | }
|
---|
387 |
|
---|
388 | /** Extract a constant string value from an HGCM parameter structure. */
|
---|
389 | DECLINLINE(int) HGCMSvcGetPsz(VBOXHGCMSVCPARM *pParm, const char **ppch, uint32_t *pcb)
|
---|
390 | {
|
---|
391 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
392 | AssertPtrReturn(ppch, VERR_INVALID_POINTER);
|
---|
393 | AssertPtrReturn(pcb, VERR_INVALID_POINTER);
|
---|
394 | if ( pParm->type == VBOX_HGCM_SVC_PARM_PTR
|
---|
395 | && VALID_PTR(pParm->u.pointer.addr)
|
---|
396 | && pParm->u.pointer.size > 0)
|
---|
397 | {
|
---|
398 | int rc = RTStrValidateEncodingEx((const char *)pParm->u.pointer.addr,
|
---|
399 | pParm->u.pointer.size,
|
---|
400 | RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
|
---|
401 | if (RT_FAILURE(rc))
|
---|
402 | return rc;
|
---|
403 | *ppch = (const char *)pParm->u.pointer.addr;
|
---|
404 | *pcb = pParm->u.pointer.size;
|
---|
405 | return VINF_SUCCESS;
|
---|
406 | }
|
---|
407 |
|
---|
408 | return VERR_INVALID_PARAMETER;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /** Set a uint32_t value to an HGCM parameter structure */
|
---|
412 | DECLINLINE(void) HGCMSvcSetU32(VBOXHGCMSVCPARM *pParm, uint32_t u32)
|
---|
413 | {
|
---|
414 | AssertPtr(pParm);
|
---|
415 | pParm->type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
416 | pParm->u.uint32 = u32;
|
---|
417 | }
|
---|
418 |
|
---|
419 | /** Set a uint64_t value to an HGCM parameter structure */
|
---|
420 | DECLINLINE(void) HGCMSvcSetU64(VBOXHGCMSVCPARM *pParm, uint64_t u64)
|
---|
421 | {
|
---|
422 | AssertPtr(pParm);
|
---|
423 | pParm->type = VBOX_HGCM_SVC_PARM_64BIT;
|
---|
424 | pParm->u.uint64 = u64;
|
---|
425 | }
|
---|
426 |
|
---|
427 | /** Set a pointer value to an HGCM parameter structure */
|
---|
428 | DECLINLINE(void) HGCMSvcSetPv(VBOXHGCMSVCPARM *pParm, void *pv, uint32_t cb)
|
---|
429 | {
|
---|
430 | AssertPtr(pParm);
|
---|
431 | pParm->type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
432 | pParm->u.pointer.addr = pv;
|
---|
433 | pParm->u.pointer.size = cb;
|
---|
434 | }
|
---|
435 |
|
---|
436 | /** Set a pointer value to an HGCM parameter structure */
|
---|
437 | DECLINLINE(void) HGCMSvcSetStr(VBOXHGCMSVCPARM *pParm, const char *psz)
|
---|
438 | {
|
---|
439 | AssertPtr(pParm);
|
---|
440 | pParm->type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
441 | pParm->u.pointer.addr = (void *)psz;
|
---|
442 | pParm->u.pointer.size = (uint32_t)strlen(psz) + 1;
|
---|
443 | }
|
---|
444 |
|
---|
445 | #ifdef __cplusplus
|
---|
446 | # ifdef IPRT_INCLUDED_cpp_ministring_h
|
---|
447 | /** Set a const string value to an HGCM parameter structure */
|
---|
448 | DECLINLINE(void) HGCMSvcSetRTCStr(VBOXHGCMSVCPARM *pParm, const RTCString &rString)
|
---|
449 | {
|
---|
450 | AssertPtr(pParm);
|
---|
451 | pParm->type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
452 | pParm->u.pointer.addr = (void *)rString.c_str();
|
---|
453 | pParm->u.pointer.size = (uint32_t)rString.length() + 1;
|
---|
454 | }
|
---|
455 | # endif
|
---|
456 | #endif
|
---|
457 |
|
---|
458 | #ifdef IN_RING3
|
---|
459 | /**
|
---|
460 | * Puts (serializes) a VBOXHGCMSVCPARM struct into SSM.
|
---|
461 | *
|
---|
462 | * @returns VBox status code.
|
---|
463 | * @param pParm VBOXHGCMSVCPARM to serialize.
|
---|
464 | * @param pSSM SSM handle to serialize to.
|
---|
465 | */
|
---|
466 | DECLINLINE(int) HGCMSvcSSMR3Put(VBOXHGCMSVCPARM *pParm, PSSMHANDLE pSSM)
|
---|
467 | {
|
---|
468 | int rc;
|
---|
469 |
|
---|
470 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
471 | AssertPtrReturn(pSSM, VERR_INVALID_POINTER);
|
---|
472 |
|
---|
473 | rc = SSMR3PutU32(pSSM, sizeof(VBOXHGCMSVCPARM));
|
---|
474 | AssertRCReturn(rc, rc);
|
---|
475 | rc = SSMR3PutU32(pSSM, pParm->type);
|
---|
476 | AssertRCReturn(rc, rc);
|
---|
477 |
|
---|
478 | switch (pParm->type)
|
---|
479 | {
|
---|
480 | case VBOX_HGCM_SVC_PARM_32BIT:
|
---|
481 | rc = SSMR3PutU32(pSSM, pParm->u.uint32);
|
---|
482 | break;
|
---|
483 | case VBOX_HGCM_SVC_PARM_64BIT:
|
---|
484 | rc = SSMR3PutU64(pSSM, pParm->u.uint64);
|
---|
485 | break;
|
---|
486 | case VBOX_HGCM_SVC_PARM_PTR:
|
---|
487 | rc = SSMR3PutU32(pSSM, pParm->u.pointer.size);
|
---|
488 | if (RT_SUCCESS(rc))
|
---|
489 | rc = SSMR3PutMem(pSSM, pParm->u.pointer.addr, pParm->u.pointer.size);
|
---|
490 | break;
|
---|
491 | default:
|
---|
492 | AssertMsgFailed(("Paramter type %RU32 not implemented yet\n", pParm->type));
|
---|
493 | rc = VERR_NOT_IMPLEMENTED;
|
---|
494 | break;
|
---|
495 | }
|
---|
496 |
|
---|
497 | return rc;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /**
|
---|
501 | * Gets (loads) a VBOXHGCMSVCPARM struct from SSM.
|
---|
502 | *
|
---|
503 | * @returns VBox status code.
|
---|
504 | * @param pParm VBOXHGCMSVCPARM to load into. Must be initialied (zero-ed) properly.
|
---|
505 | * @param pSSM SSM handle to load from.
|
---|
506 | */
|
---|
507 | DECLINLINE(int) HGCMSvcSSMR3Get(VBOXHGCMSVCPARM *pParm, PSSMHANDLE pSSM)
|
---|
508 | {
|
---|
509 | uint32_t cbParm;
|
---|
510 | int rc;
|
---|
511 |
|
---|
512 | AssertPtrReturn(pParm, VERR_INVALID_POINTER);
|
---|
513 | AssertPtrReturn(pSSM, VERR_INVALID_POINTER);
|
---|
514 |
|
---|
515 | rc = SSMR3GetU32(pSSM, &cbParm);
|
---|
516 | AssertRCReturn(rc, rc);
|
---|
517 | AssertReturn(cbParm == sizeof(VBOXHGCMSVCPARM), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
|
---|
518 |
|
---|
519 | rc = SSMR3GetU32(pSSM, &pParm->type);
|
---|
520 | AssertRCReturn(rc, rc);
|
---|
521 |
|
---|
522 | switch (pParm->type)
|
---|
523 | {
|
---|
524 | case VBOX_HGCM_SVC_PARM_32BIT:
|
---|
525 | {
|
---|
526 | rc = SSMR3GetU32(pSSM, &pParm->u.uint32);
|
---|
527 | AssertRCReturn(rc, rc);
|
---|
528 | break;
|
---|
529 | }
|
---|
530 |
|
---|
531 | case VBOX_HGCM_SVC_PARM_64BIT:
|
---|
532 | {
|
---|
533 | rc = SSMR3GetU64(pSSM, &pParm->u.uint64);
|
---|
534 | AssertRCReturn(rc, rc);
|
---|
535 | break;
|
---|
536 | }
|
---|
537 |
|
---|
538 | case VBOX_HGCM_SVC_PARM_PTR:
|
---|
539 | {
|
---|
540 | AssertMsgReturn(pParm->u.pointer.size == 0,
|
---|
541 | ("Pointer size parameter already in use (or not initialized)\n"), VERR_INVALID_PARAMETER);
|
---|
542 |
|
---|
543 | rc = SSMR3GetU32(pSSM, &pParm->u.pointer.size);
|
---|
544 | AssertRCReturn(rc, rc);
|
---|
545 |
|
---|
546 | AssertMsgReturn(pParm->u.pointer.addr == NULL,
|
---|
547 | ("Pointer parameter already in use (or not initialized)\n"), VERR_INVALID_PARAMETER);
|
---|
548 |
|
---|
549 | pParm->u.pointer.addr = RTMemAlloc(pParm->u.pointer.size);
|
---|
550 | AssertPtrReturn(pParm->u.pointer.addr, VERR_NO_MEMORY);
|
---|
551 | rc = SSMR3GetMem(pSSM, pParm->u.pointer.addr, pParm->u.pointer.size);
|
---|
552 |
|
---|
553 | AssertRCReturn(rc, rc);
|
---|
554 | break;
|
---|
555 | }
|
---|
556 |
|
---|
557 | default:
|
---|
558 | AssertMsgFailed(("Paramter type %RU32 not implemented yet\n", pParm->type));
|
---|
559 | rc = VERR_NOT_IMPLEMENTED;
|
---|
560 | break;
|
---|
561 | }
|
---|
562 |
|
---|
563 | return VINF_SUCCESS;
|
---|
564 | }
|
---|
565 | #endif /* IN_RING3 */
|
---|
566 |
|
---|
567 | typedef VBOXHGCMSVCPARM *PVBOXHGCMSVCPARM;
|
---|
568 |
|
---|
569 |
|
---|
570 | /** Service specific extension callback.
|
---|
571 | * This callback is called by the service to perform service specific operation.
|
---|
572 | *
|
---|
573 | * @param pvExtension The extension pointer.
|
---|
574 | * @param u32Function What the callback is supposed to do.
|
---|
575 | * @param pvParm The function parameters.
|
---|
576 | * @param cbParm The size of the function parameters.
|
---|
577 | */
|
---|
578 | typedef DECLCALLBACK(int) FNHGCMSVCEXT(void *pvExtension, uint32_t u32Function, void *pvParm, uint32_t cbParms);
|
---|
579 | typedef FNHGCMSVCEXT *PFNHGCMSVCEXT;
|
---|
580 |
|
---|
581 | /**
|
---|
582 | * Notification event.
|
---|
583 | */
|
---|
584 | typedef enum HGCMNOTIFYEVENT
|
---|
585 | {
|
---|
586 | HGCMNOTIFYEVENT_INVALID = 0,
|
---|
587 | HGCMNOTIFYEVENT_POWER_ON,
|
---|
588 | HGCMNOTIFYEVENT_RESUME,
|
---|
589 | HGCMNOTIFYEVENT_SUSPEND,
|
---|
590 | HGCMNOTIFYEVENT_RESET,
|
---|
591 | HGCMNOTIFYEVENT_POWER_OFF,
|
---|
592 | HGCMNOTIFYEVENT_END,
|
---|
593 | HGCMNOTIFYEVENT_32BIT_HACK = 0x7fffffff
|
---|
594 | } HGCMNOTIFYEVENT;
|
---|
595 |
|
---|
596 |
|
---|
597 | /** The Service DLL entry points.
|
---|
598 | *
|
---|
599 | * HGCM will call the DLL "VBoxHGCMSvcLoad"
|
---|
600 | * function and the DLL must fill in the VBOXHGCMSVCFNTABLE
|
---|
601 | * with function pointers.
|
---|
602 | *
|
---|
603 | * @note The structure is used in separately compiled binaries so an explicit
|
---|
604 | * packing is required.
|
---|
605 | */
|
---|
606 | typedef struct VBOXHGCMSVCFNTABLE
|
---|
607 | {
|
---|
608 | /** @name Filled by HGCM
|
---|
609 | * @{ */
|
---|
610 |
|
---|
611 | /** Size of the structure. */
|
---|
612 | uint32_t cbSize;
|
---|
613 |
|
---|
614 | /** Version of the structure, including the helpers. */
|
---|
615 | uint32_t u32Version;
|
---|
616 |
|
---|
617 | PVBOXHGCMSVCHELPERS pHelpers;
|
---|
618 | /** @} */
|
---|
619 |
|
---|
620 | /** @name Filled in by the service.
|
---|
621 | * @{ */
|
---|
622 |
|
---|
623 | /** Size of client information the service want to have. */
|
---|
624 | uint32_t cbClient;
|
---|
625 | #if ARCH_BITS == 64
|
---|
626 | /** Ensure that the following pointers are properly aligned on 64-bit system. */
|
---|
627 | uint32_t u32Alignment0;
|
---|
628 | #endif
|
---|
629 |
|
---|
630 | /** Uninitialize service */
|
---|
631 | DECLR3CALLBACKMEMBER(int, pfnUnload, (void *pvService));
|
---|
632 |
|
---|
633 | /** Inform the service about a client connection. */
|
---|
634 | DECLR3CALLBACKMEMBER(int, pfnConnect, (void *pvService, uint32_t u32ClientID, void *pvClient, uint32_t fRequestor, bool fRestoring));
|
---|
635 |
|
---|
636 | /** Inform the service that the client wants to disconnect. */
|
---|
637 | DECLR3CALLBACKMEMBER(int, pfnDisconnect, (void *pvService, uint32_t u32ClientID, void *pvClient));
|
---|
638 |
|
---|
639 | /** Service entry point.
|
---|
640 | * Return code is passed to pfnCallComplete callback.
|
---|
641 | */
|
---|
642 | DECLR3CALLBACKMEMBER(void, pfnCall, (void *pvService, VBOXHGCMCALLHANDLE callHandle, uint32_t u32ClientID, void *pvClient,
|
---|
643 | uint32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival));
|
---|
644 | /** Informs the service that a call was cancelled by the guest (optional).
|
---|
645 | *
|
---|
646 | * This is called for guest calls, connect requests and disconnect requests.
|
---|
647 | * There is unfortunately no way of obtaining the call handle for a guest call
|
---|
648 | * or otherwise identify the request, so that's left to the service to figure
|
---|
649 | * out using VBOXHGCMSVCHELPERS::pfnIsCallCancelled. Because this is an
|
---|
650 | * asynchronous call, the service may have completed the request already.
|
---|
651 | */
|
---|
652 | DECLR3CALLBACKMEMBER(void, pfnCancelled, (void *pvService, uint32_t idClient, void *pvClient));
|
---|
653 |
|
---|
654 | /** Host Service entry point meant for privileged features invisible to the guest.
|
---|
655 | * Return code is passed to pfnCallComplete callback.
|
---|
656 | */
|
---|
657 | DECLR3CALLBACKMEMBER(int, pfnHostCall, (void *pvService, uint32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]));
|
---|
658 |
|
---|
659 | /** Inform the service about a VM save operation. */
|
---|
660 | DECLR3CALLBACKMEMBER(int, pfnSaveState, (void *pvService, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM));
|
---|
661 |
|
---|
662 | /** Inform the service about a VM load operation. */
|
---|
663 | DECLR3CALLBACKMEMBER(int, pfnLoadState, (void *pvService, uint32_t u32ClientID, void *pvClient, PSSMHANDLE pSSM,
|
---|
664 | uint32_t uVersion));
|
---|
665 |
|
---|
666 | /** Register a service extension callback. */
|
---|
667 | DECLR3CALLBACKMEMBER(int, pfnRegisterExtension, (void *pvService, PFNHGCMSVCEXT pfnExtension, void *pvExtension));
|
---|
668 |
|
---|
669 | /** Notification (VM state). */
|
---|
670 | DECLR3CALLBACKMEMBER(void, pfnNotify, (void *pvService, HGCMNOTIFYEVENT enmEvent));
|
---|
671 |
|
---|
672 | /** User/instance data pointer for the service. */
|
---|
673 | void *pvService;
|
---|
674 |
|
---|
675 | /** @} */
|
---|
676 | } VBOXHGCMSVCFNTABLE;
|
---|
677 |
|
---|
678 |
|
---|
679 | /** @name HGCM saved state
|
---|
680 | * @note Need to be here so we can add saved to service which doesn't have it.
|
---|
681 | * @{ */
|
---|
682 | /** HGCM saved state version. */
|
---|
683 | #define HGCM_SAVED_STATE_VERSION 3
|
---|
684 | /** HGCM saved state version w/o client state indicators. */
|
---|
685 | #define HGCM_SAVED_STATE_VERSION_V2 2
|
---|
686 | /** @} */
|
---|
687 |
|
---|
688 |
|
---|
689 | /** Service initialization entry point. */
|
---|
690 | typedef DECLCALLBACK(int) VBOXHGCMSVCLOAD(VBOXHGCMSVCFNTABLE *ptable);
|
---|
691 | typedef VBOXHGCMSVCLOAD *PFNVBOXHGCMSVCLOAD;
|
---|
692 | #define VBOX_HGCM_SVCLOAD_NAME "VBoxHGCMSvcLoad"
|
---|
693 |
|
---|
694 | #endif /* !VBOX_INCLUDED_hgcmsvc_h */
|
---|
695 |
|
---|