[55401] | 1 | /* $Id: HGCM.cpp 99739 2023-05-11 01:01:08Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * HGCM (Host-Guest Communication Manager)
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 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 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
[67914] | 28 | #define LOG_GROUP LOG_GROUP_HGCM
|
---|
| 29 | #include "LoggingNew.h"
|
---|
[1] | 30 |
|
---|
[35374] | 31 | #include "HGCM.h"
|
---|
| 32 | #include "HGCMThread.h"
|
---|
[1] | 33 |
|
---|
| 34 | #include <VBox/err.h>
|
---|
| 35 | #include <VBox/hgcmsvc.h>
|
---|
[35346] | 36 | #include <VBox/vmm/ssm.h>
|
---|
[75495] | 37 | #include <VBox/vmm/stam.h>
|
---|
[93444] | 38 | #include <VBox/vmm/vmmr3vtable.h>
|
---|
[35346] | 39 | #include <VBox/sup.h>
|
---|
[90238] | 40 | #include <VBox/AssertGuest.h>
|
---|
[1] | 41 |
|
---|
| 42 | #include <iprt/alloc.h>
|
---|
| 43 | #include <iprt/avl.h>
|
---|
| 44 | #include <iprt/critsect.h>
|
---|
| 45 | #include <iprt/asm.h>
|
---|
| 46 | #include <iprt/ldr.h>
|
---|
[6952] | 47 | #include <iprt/param.h>
|
---|
| 48 | #include <iprt/path.h>
|
---|
[1] | 49 | #include <iprt/string.h>
|
---|
| 50 | #include <iprt/semaphore.h>
|
---|
| 51 | #include <iprt/thread.h>
|
---|
| 52 |
|
---|
[21227] | 53 | #include <VBox/VMMDev.h>
|
---|
[75497] | 54 | #include <new>
|
---|
[1] | 55 |
|
---|
| 56 | /**
|
---|
| 57 | * A service gets one thread, which synchronously delivers messages to
|
---|
| 58 | * the service. This is good for serialization.
|
---|
| 59 | *
|
---|
| 60 | * Some services may want to process messages asynchronously, and will want
|
---|
| 61 | * a next message to be delivered, while a previous message is still being
|
---|
| 62 | * processed.
|
---|
| 63 | *
|
---|
| 64 | * The dedicated service thread delivers a next message when service
|
---|
| 65 | * returns after fetching a previous one. The service will call a message
|
---|
| 66 | * completion callback when message is actually processed. So returning
|
---|
| 67 | * from the service call means only that the service is processing message.
|
---|
| 68 | *
|
---|
| 69 | * 'Message processed' condition is indicated by service, which call the
|
---|
| 70 | * callback, even if the callback is called synchronously in the dedicated
|
---|
| 71 | * thread.
|
---|
| 72 | *
|
---|
| 73 | * This message completion callback is only valid for Call requests.
|
---|
[1711] | 74 | * Connect and Disconnect are processed synchronously by the service.
|
---|
[1] | 75 | */
|
---|
| 76 |
|
---|
| 77 |
|
---|
[1681] | 78 | /* The maximum allowed size of a service name in bytes. */
|
---|
| 79 | #define VBOX_HGCM_SVC_NAME_MAX_BYTES 1024
|
---|
[1] | 80 |
|
---|
[2386] | 81 | struct _HGCMSVCEXTHANDLEDATA
|
---|
| 82 | {
|
---|
| 83 | char *pszServiceName;
|
---|
| 84 | /* The service name follows. */
|
---|
| 85 | };
|
---|
| 86 |
|
---|
[90228] | 87 | class HGCMClient;
|
---|
| 88 |
|
---|
[1] | 89 | /** Internal helper service object. HGCM code would use it to
|
---|
| 90 | * hold information about services and communicate with services.
|
---|
| 91 | * The HGCMService is an (in future) abstract class that implements
|
---|
| 92 | * common functionality. There will be derived classes for specific
|
---|
[1711] | 93 | * service types.
|
---|
[1] | 94 | */
|
---|
| 95 |
|
---|
| 96 | class HGCMService
|
---|
| 97 | {
|
---|
| 98 | private:
|
---|
| 99 | VBOXHGCMSVCHELPERS m_svcHelpers;
|
---|
| 100 |
|
---|
| 101 | static HGCMService *sm_pSvcListHead;
|
---|
| 102 | static HGCMService *sm_pSvcListTail;
|
---|
| 103 |
|
---|
[1711] | 104 | static int sm_cServices;
|
---|
[1] | 105 |
|
---|
[75539] | 106 | HGCMThread *m_pThread;
|
---|
| 107 | friend DECLCALLBACK(void) hgcmServiceThread(HGCMThread *pThread, void *pvUser);
|
---|
[1] | 108 |
|
---|
| 109 | uint32_t volatile m_u32RefCnt;
|
---|
| 110 |
|
---|
| 111 | HGCMService *m_pSvcNext;
|
---|
| 112 | HGCMService *m_pSvcPrev;
|
---|
| 113 |
|
---|
| 114 | char *m_pszSvcName;
|
---|
| 115 | char *m_pszSvcLibrary;
|
---|
[6985] | 116 |
|
---|
[1] | 117 | RTLDRMOD m_hLdrMod;
|
---|
| 118 | PFNVBOXHGCMSVCLOAD m_pfnLoad;
|
---|
| 119 |
|
---|
| 120 | VBOXHGCMSVCFNTABLE m_fntable;
|
---|
| 121 |
|
---|
[91097] | 122 | /** Set if servicing SVC_MSG_CONNECT or SVC_MSG_DISCONNECT.
|
---|
| 123 | * Used for context checking pfnDisconnectClient calls, as it can only
|
---|
| 124 | * safely be made when the main HGCM thread is waiting on the service to
|
---|
| 125 | * process those messages. */
|
---|
| 126 | bool m_fInConnectOrDisconnect;
|
---|
| 127 |
|
---|
[90238] | 128 | uint32_t m_acClients[HGCM_CLIENT_CATEGORY_MAX]; /**< Clients per category. */
|
---|
[70599] | 129 | uint32_t m_cClients;
|
---|
| 130 | uint32_t m_cClientsAllocated;
|
---|
[1] | 131 |
|
---|
[1385] | 132 | uint32_t *m_paClientIds;
|
---|
[6985] | 133 |
|
---|
[2386] | 134 | HGCMSVCEXTHANDLE m_hExtension;
|
---|
[1385] | 135 |
|
---|
[75495] | 136 | PUVM m_pUVM;
|
---|
[93444] | 137 | PCVMMR3VTABLE m_pVMM;
|
---|
[75853] | 138 | PPDMIHGCMPORT m_pHgcmPort;
|
---|
[75495] | 139 |
|
---|
| 140 | /** @name Statistics
|
---|
| 141 | * @{ */
|
---|
| 142 | STAMPROFILE m_StatHandleMsg;
|
---|
[90238] | 143 | STAMCOUNTER m_StatTooManyClients;
|
---|
| 144 | STAMCOUNTER m_StatTooManyCalls;
|
---|
[75495] | 145 | /** @} */
|
---|
| 146 |
|
---|
[51092] | 147 | int loadServiceDLL(void);
|
---|
| 148 | void unloadServiceDLL(void);
|
---|
[1] | 149 |
|
---|
[1711] | 150 | /*
|
---|
| 151 | * Main HGCM thread methods.
|
---|
| 152 | */
|
---|
[93444] | 153 | int instanceCreate(const char *pszServiceLibrary, const char *pszServiceName,
|
---|
| 154 | PUVM pUVM, PCVMMR3VTABLE pVMM, PPDMIHGCMPORT pHgcmPort);
|
---|
| 155 | void registerStatistics(const char *pszServiceName, PUVM pUVM, PCVMMR3VTABLE pVMM);
|
---|
[51092] | 156 | void instanceDestroy(void);
|
---|
[1] | 157 |
|
---|
[93444] | 158 | int saveClientState(uint32_t u32ClientId, PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM);
|
---|
| 159 | int loadClientState(uint32_t u32ClientId, PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t uVersion);
|
---|
[1711] | 160 |
|
---|
[51092] | 161 | HGCMService();
|
---|
| 162 | ~HGCMService() {};
|
---|
[1] | 163 |
|
---|
[98278] | 164 | static DECLCALLBACK(int) svcHlpCallComplete(VBOXHGCMCALLHANDLE callHandle, int32_t vrc);
|
---|
[91100] | 165 | static DECLCALLBACK(int) svcHlpDisconnectClient(void *pvInstance, uint32_t idClient);
|
---|
[75406] | 166 | static DECLCALLBACK(bool) svcHlpIsCallRestored(VBOXHGCMCALLHANDLE callHandle);
|
---|
[75990] | 167 | static DECLCALLBACK(bool) svcHlpIsCallCancelled(VBOXHGCMCALLHANDLE callHandle);
|
---|
[75495] | 168 | static DECLCALLBACK(int) svcHlpStamRegisterV(void *pvInstance, void *pvSample, STAMTYPE enmType,
|
---|
| 169 | STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc,
|
---|
| 170 | const char *pszName, va_list va);
|
---|
| 171 | static DECLCALLBACK(int) svcHlpStamDeregisterV(void *pvInstance, const char *pszPatFmt, va_list va);
|
---|
| 172 | static DECLCALLBACK(int) svcHlpInfoRegister(void *pvInstance, const char *pszName, const char *pszDesc,
|
---|
| 173 | PFNDBGFHANDLEREXT pfnHandler, void *pvUser);
|
---|
| 174 | static DECLCALLBACK(int) svcHlpInfoDeregister(void *pvInstance, const char *pszName);
|
---|
[75769] | 175 | static DECLCALLBACK(uint32_t) svcHlpGetRequestor(VBOXHGCMCALLHANDLE hCall);
|
---|
[75853] | 176 | static DECLCALLBACK(uint64_t) svcHlpGetVMMDevSessionId(void *pvInstance);
|
---|
[12423] | 177 |
|
---|
[1] | 178 | public:
|
---|
| 179 |
|
---|
[1711] | 180 | /*
|
---|
| 181 | * Main HGCM thread methods.
|
---|
| 182 | */
|
---|
[93444] | 183 | static int LoadService(const char *pszServiceLibrary, const char *pszServiceName,
|
---|
| 184 | PUVM pUVM, PCVMMR3VTABLE pVMM, PPDMIHGCMPORT pHgcmPort);
|
---|
[75574] | 185 | void UnloadService(bool fUvmIsInvalid);
|
---|
[1711] | 186 |
|
---|
[75574] | 187 | static void UnloadAll(bool fUvmIsInvalid);
|
---|
[1711] | 188 |
|
---|
[51092] | 189 | static int ResolveService(HGCMService **ppsvc, const char *pszServiceName);
|
---|
| 190 | void ReferenceService(void);
|
---|
| 191 | void ReleaseService(void);
|
---|
[1711] | 192 |
|
---|
[51092] | 193 | static void Reset(void);
|
---|
[1681] | 194 |
|
---|
[93444] | 195 | static int SaveState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM);
|
---|
| 196 | static int LoadState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t uVersion);
|
---|
[1] | 197 |
|
---|
[75773] | 198 | int CreateAndConnectClient(uint32_t *pu32ClientIdOut, uint32_t u32ClientIdIn, uint32_t fRequestor, bool fRestoring);
|
---|
[90228] | 199 | int DisconnectClient(uint32_t u32ClientId, bool fFromService, HGCMClient *pClient);
|
---|
[1711] | 200 |
|
---|
[51092] | 201 | int HostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM *paParms);
|
---|
[75969] | 202 | static void BroadcastNotify(HGCMNOTIFYEVENT enmEvent);
|
---|
| 203 | void Notify(HGCMNOTIFYEVENT enmEvent);
|
---|
[1711] | 204 |
|
---|
[51092] | 205 | uint32_t SizeOfClient(void) { return m_fntable.cbClient; };
|
---|
[1] | 206 |
|
---|
[51092] | 207 | int RegisterExtension(HGCMSVCEXTHANDLE handle, PFNHGCMSVCEXT pfnExtension, void *pvExtension);
|
---|
| 208 | void UnregisterExtension(HGCMSVCEXTHANDLE handle);
|
---|
[2386] | 209 |
|
---|
[1711] | 210 | /*
|
---|
| 211 | * The service thread methods.
|
---|
| 212 | */
|
---|
[1385] | 213 |
|
---|
[90238] | 214 | int GuestCall(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t u32ClientId, HGCMClient *pClient,
|
---|
[75500] | 215 | uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM aParms[], uint64_t tsArrival);
|
---|
[75990] | 216 | void GuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t idClient);
|
---|
[1] | 217 | };
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | class HGCMClient: public HGCMObject
|
---|
| 221 | {
|
---|
| 222 | public:
|
---|
[90238] | 223 | HGCMClient(uint32_t a_fRequestor, uint32_t a_idxCategory)
|
---|
[75853] | 224 | : HGCMObject(HGCMOBJ_CLIENT)
|
---|
| 225 | , pService(NULL)
|
---|
| 226 | , pvData(NULL)
|
---|
| 227 | , fRequestor(a_fRequestor)
|
---|
[90238] | 228 | , idxCategory(a_idxCategory)
|
---|
| 229 | , cPendingCalls(0)
|
---|
[91748] | 230 | , m_fGuestAccessible(false)
|
---|
[90238] | 231 | {
|
---|
| 232 | Assert(idxCategory < HGCM_CLIENT_CATEGORY_MAX);
|
---|
| 233 | }
|
---|
[51092] | 234 | ~HGCMClient();
|
---|
[1] | 235 |
|
---|
[51092] | 236 | int Init(HGCMService *pSvc);
|
---|
[1] | 237 |
|
---|
[91748] | 238 | /** Lookups a client object by its handle. */
|
---|
| 239 | static HGCMClient *ReferenceByHandle(uint32_t idClient)
|
---|
| 240 | {
|
---|
| 241 | return (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | /** Lookups a client object by its handle and makes sure that it's accessible to the guest. */
|
---|
| 245 | static HGCMClient *ReferenceByHandleForGuest(uint32_t idClient)
|
---|
| 246 | {
|
---|
| 247 | HGCMClient *pClient = (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
|
---|
| 248 | if (pClient)
|
---|
| 249 | {
|
---|
| 250 | if (RT_LIKELY(pClient->m_fGuestAccessible))
|
---|
| 251 | return pClient;
|
---|
| 252 | pClient->Dereference();
|
---|
| 253 | }
|
---|
| 254 | return NULL;
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | /** Make the client object accessible to the guest. */
|
---|
| 258 | void makeAccessibleToGuest()
|
---|
| 259 | {
|
---|
| 260 | ASMAtomicWriteBool(&m_fGuestAccessible, true);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[1] | 263 | /** Service that the client is connected to. */
|
---|
| 264 | HGCMService *pService;
|
---|
| 265 |
|
---|
| 266 | /** Client specific data. */
|
---|
| 267 | void *pvData;
|
---|
[75853] | 268 |
|
---|
| 269 | /** The requestor flags this client was created with.
|
---|
| 270 | * @sa VMMDevRequestHeader::fRequestor */
|
---|
| 271 | uint32_t fRequestor;
|
---|
| 272 |
|
---|
[90238] | 273 | /** The client category (HGCM_CLIENT_CATEGORY_XXX). */
|
---|
| 274 | uint32_t idxCategory;
|
---|
| 275 |
|
---|
| 276 | /** Number of pending calls. */
|
---|
| 277 | uint32_t volatile cPendingCalls;
|
---|
| 278 |
|
---|
[91748] | 279 | protected:
|
---|
| 280 | /** Set if the client is accessible to the guest, clear if not. */
|
---|
| 281 | bool volatile m_fGuestAccessible;
|
---|
| 282 |
|
---|
[75853] | 283 | private: /* none of this: */
|
---|
| 284 | HGCMClient();
|
---|
| 285 | HGCMClient(HGCMClient const &);
|
---|
| 286 | HGCMClient &operator=(HGCMClient const &);
|
---|
[1] | 287 | };
|
---|
| 288 |
|
---|
[51092] | 289 | HGCMClient::~HGCMClient()
|
---|
[1] | 290 | {
|
---|
[51092] | 291 | if (pService->SizeOfClient() > 0)
|
---|
[75853] | 292 | {
|
---|
[51092] | 293 | RTMemFree(pvData);
|
---|
[75853] | 294 | pvData = NULL;
|
---|
| 295 | }
|
---|
[1] | 296 | }
|
---|
| 297 |
|
---|
[75853] | 298 |
|
---|
[51092] | 299 | int HGCMClient::Init(HGCMService *pSvc)
|
---|
[1] | 300 | {
|
---|
| 301 | pService = pSvc;
|
---|
| 302 |
|
---|
[51092] | 303 | if (pService->SizeOfClient() > 0)
|
---|
[1] | 304 | {
|
---|
[51092] | 305 | pvData = RTMemAllocZ(pService->SizeOfClient());
|
---|
[1] | 306 |
|
---|
| 307 | if (!pvData)
|
---|
| 308 | {
|
---|
| 309 | return VERR_NO_MEMORY;
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | return VINF_SUCCESS;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 |
|
---|
[51092] | 317 | #define HGCM_CLIENT_DATA(pService, pClient)(pClient->pvData)
|
---|
[1] | 318 |
|
---|
| 319 |
|
---|
[1711] | 320 |
|
---|
| 321 | HGCMService *HGCMService::sm_pSvcListHead = NULL;
|
---|
| 322 | HGCMService *HGCMService::sm_pSvcListTail = NULL;
|
---|
| 323 | int HGCMService::sm_cServices = 0;
|
---|
| 324 |
|
---|
[51092] | 325 | HGCMService::HGCMService()
|
---|
[1711] | 326 | :
|
---|
[75539] | 327 | m_pThread (NULL),
|
---|
[1711] | 328 | m_u32RefCnt (0),
|
---|
| 329 | m_pSvcNext (NULL),
|
---|
| 330 | m_pSvcPrev (NULL),
|
---|
| 331 | m_pszSvcName (NULL),
|
---|
| 332 | m_pszSvcLibrary (NULL),
|
---|
| 333 | m_hLdrMod (NIL_RTLDRMOD),
|
---|
| 334 | m_pfnLoad (NULL),
|
---|
[91097] | 335 | m_fInConnectOrDisconnect(false),
|
---|
[1711] | 336 | m_cClients (0),
|
---|
| 337 | m_cClientsAllocated (0),
|
---|
[2386] | 338 | m_paClientIds (NULL),
|
---|
[75495] | 339 | m_hExtension (NULL),
|
---|
[75853] | 340 | m_pUVM (NULL),
|
---|
[93444] | 341 | m_pVMM (NULL),
|
---|
[75853] | 342 | m_pHgcmPort (NULL)
|
---|
[1711] | 343 | {
|
---|
[90238] | 344 | RT_ZERO(m_acClients);
|
---|
[47117] | 345 | RT_ZERO(m_fntable);
|
---|
[1711] | 346 | }
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | static bool g_fResetting = false;
|
---|
| 350 | static bool g_fSaveState = false;
|
---|
| 351 |
|
---|
| 352 |
|
---|
| 353 | /** Helper function to load a local service DLL.
|
---|
| 354 | *
|
---|
| 355 | * @return VBox code
|
---|
| 356 | */
|
---|
[48229] | 357 | int HGCMService::loadServiceDLL(void)
|
---|
[1711] | 358 | {
|
---|
[2386] | 359 | LogFlowFunc(("m_pszSvcLibrary = %s\n", m_pszSvcLibrary));
|
---|
[1711] | 360 |
|
---|
| 361 | if (m_pszSvcLibrary == NULL)
|
---|
| 362 | {
|
---|
| 363 | return VERR_INVALID_PARAMETER;
|
---|
| 364 | }
|
---|
| 365 |
|
---|
[35188] | 366 | RTERRINFOSTATIC ErrInfo;
|
---|
[48229] | 367 | RTErrInfoInitStatic(&ErrInfo);
|
---|
[1711] | 368 |
|
---|
[94937] | 369 | int vrc;
|
---|
[35188] | 370 |
|
---|
[48229] | 371 | if (RTPathHasPath(m_pszSvcLibrary))
|
---|
[94937] | 372 | vrc = SUPR3HardenedLdrLoadPlugIn(m_pszSvcLibrary, &m_hLdrMod, &ErrInfo.Core);
|
---|
[48229] | 373 | else
|
---|
[94937] | 374 | vrc = SUPR3HardenedLdrLoadAppPriv(m_pszSvcLibrary, &m_hLdrMod, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
|
---|
[48229] | 375 |
|
---|
[94937] | 376 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 377 | {
|
---|
[2386] | 378 | LogFlowFunc(("successfully loaded the library.\n"));
|
---|
[1711] | 379 |
|
---|
| 380 | m_pfnLoad = NULL;
|
---|
| 381 |
|
---|
[94937] | 382 | vrc = RTLdrGetSymbol(m_hLdrMod, VBOX_HGCM_SVCLOAD_NAME, (void**)&m_pfnLoad);
|
---|
[1711] | 383 |
|
---|
[94937] | 384 | if (RT_FAILURE(vrc) || !m_pfnLoad)
|
---|
[1711] | 385 | {
|
---|
[94937] | 386 | Log(("HGCMService::loadServiceDLL: Error resolving the service entry point %s, vrc = %Rrc, m_pfnLoad = %p\n",
|
---|
| 387 | VBOX_HGCM_SVCLOAD_NAME, vrc, m_pfnLoad));
|
---|
[1711] | 388 |
|
---|
[94937] | 389 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 390 | {
|
---|
| 391 | /* m_pfnLoad was NULL */
|
---|
[94937] | 392 | vrc = VERR_SYMBOL_NOT_FOUND;
|
---|
[1711] | 393 | }
|
---|
| 394 | }
|
---|
| 395 |
|
---|
[94937] | 396 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 397 | {
|
---|
[47117] | 398 | RT_ZERO(m_fntable);
|
---|
[1711] | 399 |
|
---|
[48229] | 400 | m_fntable.cbSize = sizeof(m_fntable);
|
---|
[1711] | 401 | m_fntable.u32Version = VBOX_HGCM_SVC_VERSION;
|
---|
| 402 | m_fntable.pHelpers = &m_svcHelpers;
|
---|
| 403 |
|
---|
[90267] | 404 | /* Total max calls: (2048 + 1024 + 1024) * 8192 = 33 554 432 */
|
---|
| 405 | m_fntable.idxLegacyClientCategory = HGCM_CLIENT_CATEGORY_KERNEL;
|
---|
| 406 | m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_KERNEL] = _2K;
|
---|
| 407 | m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_ROOT] = _1K;
|
---|
| 408 | m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_USER] = _1K;
|
---|
| 409 | m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_KERNEL] = _8K;
|
---|
| 410 | m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_ROOT] = _4K;
|
---|
| 411 | m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_USER] = _2K;
|
---|
| 412 | /** @todo provide way to configure different values via extra data. */
|
---|
| 413 |
|
---|
[94937] | 414 | vrc = m_pfnLoad(&m_fntable);
|
---|
[1711] | 415 |
|
---|
[94937] | 416 | LogFlowFunc(("m_pfnLoad vrc = %Rrc\n", vrc));
|
---|
[1711] | 417 |
|
---|
[94937] | 418 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 419 | {
|
---|
[90238] | 420 | if ( m_fntable.pfnUnload != NULL
|
---|
| 421 | && m_fntable.pfnConnect != NULL
|
---|
| 422 | && m_fntable.pfnDisconnect != NULL
|
---|
| 423 | && m_fntable.pfnCall != NULL
|
---|
[1711] | 424 | )
|
---|
| 425 | {
|
---|
[90238] | 426 | Assert(m_fntable.idxLegacyClientCategory < RT_ELEMENTS(m_fntable.acMaxClients));
|
---|
| 427 | LogRel2(("HGCMService::loadServiceDLL: acMaxClients={%u,%u,%u} acMaxCallsPerClient={%u,%u,%u} => %RU64 calls; idxLegacyClientCategory=%d; %s\n",
|
---|
| 428 | m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_KERNEL],
|
---|
| 429 | m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_ROOT],
|
---|
| 430 | m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_USER],
|
---|
| 431 | m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_KERNEL],
|
---|
| 432 | m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_ROOT],
|
---|
| 433 | m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_USER],
|
---|
| 434 | (uint64_t)m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_KERNEL]
|
---|
| 435 | * m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_KERNEL]
|
---|
| 436 | + (uint64_t)m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_ROOT]
|
---|
| 437 | * m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_ROOT]
|
---|
| 438 | + (uint64_t)m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_USER]
|
---|
| 439 | * m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_USER],
|
---|
| 440 | m_fntable.idxLegacyClientCategory, m_pszSvcName));
|
---|
| 441 | }
|
---|
| 442 | else
|
---|
| 443 | {
|
---|
[1711] | 444 | Log(("HGCMService::loadServiceDLL: at least one of function pointers is NULL\n"));
|
---|
| 445 |
|
---|
[94937] | 446 | vrc = VERR_INVALID_PARAMETER;
|
---|
[1711] | 447 |
|
---|
| 448 | if (m_fntable.pfnUnload)
|
---|
| 449 | {
|
---|
[48229] | 450 | m_fntable.pfnUnload(m_fntable.pvService);
|
---|
[1711] | 451 | }
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | }
|
---|
| 456 | else
|
---|
| 457 | {
|
---|
[94937] | 458 | LogRel(("HGCM: Failed to load the service library: [%s], vrc = %Rrc - %s. The service will be not available.\n",
|
---|
| 459 | m_pszSvcLibrary, vrc, ErrInfo.Core.pszMsg));
|
---|
[1711] | 460 | m_hLdrMod = NIL_RTLDRMOD;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
[94937] | 463 | if (RT_FAILURE(vrc))
|
---|
[1711] | 464 | {
|
---|
[48229] | 465 | unloadServiceDLL();
|
---|
[1711] | 466 | }
|
---|
| 467 |
|
---|
[94937] | 468 | return vrc;
|
---|
[1711] | 469 | }
|
---|
| 470 |
|
---|
[99739] | 471 | /**
|
---|
| 472 | * Helper function to free a local service DLL.
|
---|
[1711] | 473 | */
|
---|
[48229] | 474 | void HGCMService::unloadServiceDLL(void)
|
---|
[1711] | 475 | {
|
---|
| 476 | if (m_hLdrMod)
|
---|
| 477 | {
|
---|
[48229] | 478 | RTLdrClose(m_hLdrMod);
|
---|
[1711] | 479 | }
|
---|
| 480 |
|
---|
[47117] | 481 | RT_ZERO(m_fntable);
|
---|
[1711] | 482 | m_pfnLoad = NULL;
|
---|
| 483 | m_hLdrMod = NIL_RTLDRMOD;
|
---|
| 484 | }
|
---|
| 485 |
|
---|
[1] | 486 | /*
|
---|
[1711] | 487 | * Messages processed by service threads. These threads only call the service entry points.
|
---|
[1] | 488 | */
|
---|
| 489 |
|
---|
[75990] | 490 | #define SVC_MSG_LOAD (0) /**< Load the service library and call VBOX_HGCM_SVCLOAD_NAME entry point. */
|
---|
| 491 | #define SVC_MSG_UNLOAD (1) /**< call pfnUnload and unload the service library. */
|
---|
| 492 | #define SVC_MSG_CONNECT (2) /**< pfnConnect */
|
---|
| 493 | #define SVC_MSG_DISCONNECT (3) /**< pfnDisconnect */
|
---|
| 494 | #define SVC_MSG_GUESTCALL (4) /**< pfnGuestCall */
|
---|
| 495 | #define SVC_MSG_HOSTCALL (5) /**< pfnHostCall */
|
---|
| 496 | #define SVC_MSG_LOADSTATE (6) /**< pfnLoadState. */
|
---|
| 497 | #define SVC_MSG_SAVESTATE (7) /**< pfnSaveState. */
|
---|
| 498 | #define SVC_MSG_QUIT (8) /**< Terminate the thread. */
|
---|
| 499 | #define SVC_MSG_REGEXT (9) /**< pfnRegisterExtension */
|
---|
| 500 | #define SVC_MSG_UNREGEXT (10) /**< pfnRegisterExtension */
|
---|
| 501 | #define SVC_MSG_NOTIFY (11) /**< pfnNotify */
|
---|
| 502 | #define SVC_MSG_GUESTCANCELLED (12) /**< pfnCancelled */
|
---|
[1] | 503 |
|
---|
| 504 | class HGCMMsgSvcLoad: public HGCMMsgCore
|
---|
| 505 | {
|
---|
[75495] | 506 | public:
|
---|
| 507 | HGCMMsgSvcLoad() : HGCMMsgCore(), pUVM() {}
|
---|
| 508 |
|
---|
| 509 | /** The user mode VM handle (for statistics and such). */
|
---|
| 510 | PUVM pUVM;
|
---|
[1] | 511 | };
|
---|
| 512 |
|
---|
| 513 | class HGCMMsgSvcUnload: public HGCMMsgCore
|
---|
| 514 | {
|
---|
| 515 | };
|
---|
| 516 |
|
---|
| 517 | class HGCMMsgSvcConnect: public HGCMMsgCore
|
---|
| 518 | {
|
---|
| 519 | public:
|
---|
[75773] | 520 | /** client identifier */
|
---|
[1711] | 521 | uint32_t u32ClientId;
|
---|
[75773] | 522 | /** Requestor flags. */
|
---|
| 523 | uint32_t fRequestor;
|
---|
| 524 | /** Set if restoring. */
|
---|
| 525 | bool fRestoring;
|
---|
[1] | 526 | };
|
---|
| 527 |
|
---|
| 528 | class HGCMMsgSvcDisconnect: public HGCMMsgCore
|
---|
| 529 | {
|
---|
| 530 | public:
|
---|
[90228] | 531 | /** client identifier */
|
---|
[1711] | 532 | uint32_t u32ClientId;
|
---|
[90228] | 533 | /** The client instance. */
|
---|
| 534 | HGCMClient *pClient;
|
---|
[1] | 535 | };
|
---|
| 536 |
|
---|
| 537 | class HGCMMsgHeader: public HGCMMsgCore
|
---|
| 538 | {
|
---|
| 539 | public:
|
---|
[51092] | 540 | HGCMMsgHeader() : pCmd(NULL), pHGCMPort(NULL) {};
|
---|
[6985] | 541 |
|
---|
[1] | 542 | /* Command pointer/identifier. */
|
---|
| 543 | PVBOXHGCMCMD pCmd;
|
---|
| 544 |
|
---|
| 545 | /* Port to be informed on message completion. */
|
---|
| 546 | PPDMIHGCMPORT pHGCMPort;
|
---|
| 547 | };
|
---|
| 548 |
|
---|
| 549 | class HGCMMsgCall: public HGCMMsgHeader
|
---|
| 550 | {
|
---|
| 551 | public:
|
---|
[90238] | 552 | HGCMMsgCall() : pcCounter(NULL)
|
---|
| 553 | { }
|
---|
[75541] | 554 |
|
---|
| 555 | HGCMMsgCall(HGCMThread *pThread)
|
---|
[90238] | 556 | : pcCounter(NULL)
|
---|
[75541] | 557 | {
|
---|
| 558 | InitializeCore(SVC_MSG_GUESTCALL, pThread);
|
---|
| 559 | Initialize();
|
---|
| 560 | }
|
---|
[90238] | 561 | ~HGCMMsgCall()
|
---|
| 562 | {
|
---|
| 563 | Log(("~HGCMMsgCall %p\n", this));
|
---|
| 564 | Assert(!pcCounter);
|
---|
| 565 | }
|
---|
[75541] | 566 |
|
---|
[90238] | 567 | /** Points to HGCMClient::cPendingCalls if it needs to be decremented. */
|
---|
| 568 | uint32_t volatile *pcCounter;
|
---|
| 569 |
|
---|
[1] | 570 | /* client identifier */
|
---|
[1711] | 571 | uint32_t u32ClientId;
|
---|
[1] | 572 |
|
---|
| 573 | /* function number */
|
---|
| 574 | uint32_t u32Function;
|
---|
| 575 |
|
---|
| 576 | /* number of parameters */
|
---|
| 577 | uint32_t cParms;
|
---|
| 578 |
|
---|
| 579 | VBOXHGCMSVCPARM *paParms;
|
---|
[75500] | 580 |
|
---|
| 581 | /** The STAM_GET_TS() value when the request arrived. */
|
---|
| 582 | uint64_t tsArrival;
|
---|
[1] | 583 | };
|
---|
| 584 |
|
---|
[75990] | 585 | class HGCMMsgCancelled: public HGCMMsgHeader
|
---|
| 586 | {
|
---|
| 587 | public:
|
---|
| 588 | HGCMMsgCancelled() {}
|
---|
| 589 |
|
---|
| 590 | HGCMMsgCancelled(HGCMThread *pThread)
|
---|
| 591 | {
|
---|
| 592 | InitializeCore(SVC_MSG_GUESTCANCELLED, pThread);
|
---|
| 593 | Initialize();
|
---|
| 594 | }
|
---|
| 595 | ~HGCMMsgCancelled() { Log(("~HGCMMsgCancelled %p\n", this)); }
|
---|
| 596 |
|
---|
| 597 | /** The client identifier. */
|
---|
| 598 | uint32_t idClient;
|
---|
| 599 | };
|
---|
| 600 |
|
---|
[1711] | 601 | class HGCMMsgLoadSaveStateClient: public HGCMMsgCore
|
---|
[1] | 602 | {
|
---|
| 603 | public:
|
---|
[93444] | 604 | PSSMHANDLE pSSM;
|
---|
| 605 | PCVMMR3VTABLE pVMM;
|
---|
| 606 | uint32_t uVersion;
|
---|
| 607 | uint32_t u32ClientId;
|
---|
[906] | 608 | };
|
---|
| 609 |
|
---|
[1711] | 610 | class HGCMMsgHostCallSvc: public HGCMMsgCore
|
---|
[1] | 611 | {
|
---|
| 612 | public:
|
---|
| 613 | /* function number */
|
---|
| 614 | uint32_t u32Function;
|
---|
| 615 |
|
---|
| 616 | /* number of parameters */
|
---|
| 617 | uint32_t cParms;
|
---|
| 618 |
|
---|
| 619 | VBOXHGCMSVCPARM *paParms;
|
---|
| 620 | };
|
---|
| 621 |
|
---|
[2386] | 622 | class HGCMMsgSvcRegisterExtension: public HGCMMsgCore
|
---|
| 623 | {
|
---|
| 624 | public:
|
---|
| 625 | /* Handle of the extension to be registered. */
|
---|
| 626 | HGCMSVCEXTHANDLE handle;
|
---|
| 627 | /* The extension entry point. */
|
---|
| 628 | PFNHGCMSVCEXT pfnExtension;
|
---|
| 629 | /* The extension pointer. */
|
---|
| 630 | void *pvExtension;
|
---|
| 631 | };
|
---|
| 632 |
|
---|
| 633 | class HGCMMsgSvcUnregisterExtension: public HGCMMsgCore
|
---|
| 634 | {
|
---|
| 635 | public:
|
---|
| 636 | /* Handle of the registered extension. */
|
---|
| 637 | HGCMSVCEXTHANDLE handle;
|
---|
| 638 | };
|
---|
| 639 |
|
---|
[75969] | 640 | class HGCMMsgNotify: public HGCMMsgCore
|
---|
| 641 | {
|
---|
| 642 | public:
|
---|
| 643 | /** The event. */
|
---|
| 644 | HGCMNOTIFYEVENT enmEvent;
|
---|
| 645 | };
|
---|
| 646 |
|
---|
[51092] | 647 | static HGCMMsgCore *hgcmMessageAllocSvc(uint32_t u32MsgId)
|
---|
[1385] | 648 | {
|
---|
[1] | 649 | switch (u32MsgId)
|
---|
| 650 | {
|
---|
[51092] | 651 | case SVC_MSG_LOAD: return new HGCMMsgSvcLoad();
|
---|
| 652 | case SVC_MSG_UNLOAD: return new HGCMMsgSvcUnload();
|
---|
| 653 | case SVC_MSG_CONNECT: return new HGCMMsgSvcConnect();
|
---|
| 654 | case SVC_MSG_DISCONNECT: return new HGCMMsgSvcDisconnect();
|
---|
| 655 | case SVC_MSG_HOSTCALL: return new HGCMMsgHostCallSvc();
|
---|
| 656 | case SVC_MSG_GUESTCALL: return new HGCMMsgCall();
|
---|
[6985] | 657 | case SVC_MSG_LOADSTATE:
|
---|
[51092] | 658 | case SVC_MSG_SAVESTATE: return new HGCMMsgLoadSaveStateClient();
|
---|
| 659 | case SVC_MSG_REGEXT: return new HGCMMsgSvcRegisterExtension();
|
---|
| 660 | case SVC_MSG_UNREGEXT: return new HGCMMsgSvcUnregisterExtension();
|
---|
[75969] | 661 | case SVC_MSG_NOTIFY: return new HGCMMsgNotify();
|
---|
[75990] | 662 | case SVC_MSG_GUESTCANCELLED: return new HGCMMsgCancelled();
|
---|
[1] | 663 | default:
|
---|
[1385] | 664 | AssertReleaseMsgFailed(("Msg id = %08X\n", u32MsgId));
|
---|
[1] | 665 | }
|
---|
| 666 |
|
---|
| 667 | return NULL;
|
---|
| 668 | }
|
---|
| 669 |
|
---|
[1711] | 670 | /*
|
---|
| 671 | * The service thread. Loads the service library and calls the service entry points.
|
---|
| 672 | */
|
---|
[75539] | 673 | DECLCALLBACK(void) hgcmServiceThread(HGCMThread *pThread, void *pvUser)
|
---|
[1] | 674 | {
|
---|
| 675 | HGCMService *pSvc = (HGCMService *)pvUser;
|
---|
| 676 | AssertRelease(pSvc != NULL);
|
---|
| 677 |
|
---|
[1711] | 678 | bool fQuit = false;
|
---|
[1] | 679 |
|
---|
[1711] | 680 | while (!fQuit)
|
---|
[1] | 681 | {
|
---|
[1711] | 682 | HGCMMsgCore *pMsgCore;
|
---|
[94937] | 683 | int vrc = hgcmMsgGet(pThread, &pMsgCore);
|
---|
[1] | 684 |
|
---|
[94937] | 685 | if (RT_FAILURE(vrc))
|
---|
[1] | 686 | {
|
---|
[1711] | 687 | /* The error means some serious unrecoverable problem in the hgcmMsg/hgcmThread layer. */
|
---|
[94937] | 688 | AssertMsgFailed(("%Rrc\n", vrc));
|
---|
[1711] | 689 | break;
|
---|
[1] | 690 | }
|
---|
| 691 |
|
---|
[75495] | 692 | STAM_REL_PROFILE_START(&pSvc->m_StatHandleMsg, a);
|
---|
| 693 |
|
---|
[1577] | 694 | /* Cache required information to avoid unnecessary pMsgCore access. */
|
---|
[51092] | 695 | uint32_t u32MsgId = pMsgCore->MsgId();
|
---|
[1577] | 696 |
|
---|
| 697 | switch (u32MsgId)
|
---|
[1] | 698 | {
|
---|
[1711] | 699 | case SVC_MSG_LOAD:
|
---|
[1] | 700 | {
|
---|
[1711] | 701 | LogFlowFunc(("SVC_MSG_LOAD\n"));
|
---|
[94937] | 702 | vrc = pSvc->loadServiceDLL();
|
---|
[1] | 703 | } break;
|
---|
| 704 |
|
---|
[1711] | 705 | case SVC_MSG_UNLOAD:
|
---|
[1] | 706 | {
|
---|
[1711] | 707 | LogFlowFunc(("SVC_MSG_UNLOAD\n"));
|
---|
[3209] | 708 | if (pSvc->m_fntable.pfnUnload)
|
---|
| 709 | {
|
---|
[51092] | 710 | pSvc->m_fntable.pfnUnload(pSvc->m_fntable.pvService);
|
---|
[3209] | 711 | }
|
---|
| 712 |
|
---|
[51092] | 713 | pSvc->unloadServiceDLL();
|
---|
[1711] | 714 | fQuit = true;
|
---|
[1] | 715 | } break;
|
---|
| 716 |
|
---|
[1711] | 717 | case SVC_MSG_CONNECT:
|
---|
[1] | 718 | {
|
---|
| 719 | HGCMMsgSvcConnect *pMsg = (HGCMMsgSvcConnect *)pMsgCore;
|
---|
| 720 |
|
---|
[1711] | 721 | LogFlowFunc(("SVC_MSG_CONNECT u32ClientId = %d\n", pMsg->u32ClientId));
|
---|
[1] | 722 |
|
---|
[91748] | 723 | HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
|
---|
[1] | 724 |
|
---|
| 725 | if (pClient)
|
---|
| 726 | {
|
---|
[91097] | 727 | pSvc->m_fInConnectOrDisconnect = true;
|
---|
[94937] | 728 | vrc = pSvc->m_fntable.pfnConnect(pSvc->m_fntable.pvService, pMsg->u32ClientId,
|
---|
| 729 | HGCM_CLIENT_DATA(pSvc, pClient),
|
---|
| 730 | pMsg->fRequestor, pMsg->fRestoring);
|
---|
[91097] | 731 | pSvc->m_fInConnectOrDisconnect = false;
|
---|
[1] | 732 |
|
---|
[51092] | 733 | hgcmObjDereference(pClient);
|
---|
[1] | 734 | }
|
---|
[1711] | 735 | else
|
---|
| 736 | {
|
---|
[94937] | 737 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1711] | 738 | }
|
---|
[1] | 739 | } break;
|
---|
| 740 |
|
---|
[1711] | 741 | case SVC_MSG_DISCONNECT:
|
---|
[1] | 742 | {
|
---|
| 743 | HGCMMsgSvcDisconnect *pMsg = (HGCMMsgSvcDisconnect *)pMsgCore;
|
---|
| 744 |
|
---|
[90228] | 745 | LogFlowFunc(("SVC_MSG_DISCONNECT u32ClientId = %d, pClient = %p\n", pMsg->u32ClientId, pMsg->pClient));
|
---|
[1] | 746 |
|
---|
[90228] | 747 | if (pMsg->pClient)
|
---|
[1] | 748 | {
|
---|
[91097] | 749 | pSvc->m_fInConnectOrDisconnect = true;
|
---|
[94937] | 750 | vrc = pSvc->m_fntable.pfnDisconnect(pSvc->m_fntable.pvService, pMsg->u32ClientId,
|
---|
| 751 | HGCM_CLIENT_DATA(pSvc, pMsg->pClient));
|
---|
[91097] | 752 | pSvc->m_fInConnectOrDisconnect = false;
|
---|
[1] | 753 | }
|
---|
[1711] | 754 | else
|
---|
| 755 | {
|
---|
[94937] | 756 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1711] | 757 | }
|
---|
[1] | 758 | } break;
|
---|
| 759 |
|
---|
[1711] | 760 | case SVC_MSG_GUESTCALL:
|
---|
[1] | 761 | {
|
---|
| 762 | HGCMMsgCall *pMsg = (HGCMMsgCall *)pMsgCore;
|
---|
| 763 |
|
---|
[1711] | 764 | LogFlowFunc(("SVC_MSG_GUESTCALL u32ClientId = %d, u32Function = %d, cParms = %d, paParms = %p\n",
|
---|
| 765 | pMsg->u32ClientId, pMsg->u32Function, pMsg->cParms, pMsg->paParms));
|
---|
[1] | 766 |
|
---|
[91748] | 767 | HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(pMsg->u32ClientId);
|
---|
[1] | 768 |
|
---|
| 769 | if (pClient)
|
---|
| 770 | {
|
---|
[51092] | 771 | pSvc->m_fntable.pfnCall(pSvc->m_fntable.pvService, (VBOXHGCMCALLHANDLE)pMsg, pMsg->u32ClientId,
|
---|
| 772 | HGCM_CLIENT_DATA(pSvc, pClient), pMsg->u32Function,
|
---|
[75500] | 773 | pMsg->cParms, pMsg->paParms, pMsg->tsArrival);
|
---|
[1] | 774 |
|
---|
[51092] | 775 | hgcmObjDereference(pClient);
|
---|
[1] | 776 | }
|
---|
| 777 | else
|
---|
| 778 | {
|
---|
[94937] | 779 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1] | 780 | }
|
---|
| 781 | } break;
|
---|
| 782 |
|
---|
[75990] | 783 | case SVC_MSG_GUESTCANCELLED:
|
---|
| 784 | {
|
---|
| 785 | HGCMMsgCancelled *pMsg = (HGCMMsgCancelled *)pMsgCore;
|
---|
| 786 |
|
---|
| 787 | LogFlowFunc(("SVC_MSG_GUESTCANCELLED idClient = %d\n", pMsg->idClient));
|
---|
| 788 |
|
---|
[91748] | 789 | HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(pMsg->idClient);
|
---|
[75990] | 790 |
|
---|
| 791 | if (pClient)
|
---|
| 792 | {
|
---|
| 793 | pSvc->m_fntable.pfnCancelled(pSvc->m_fntable.pvService, pMsg->idClient, HGCM_CLIENT_DATA(pSvc, pClient));
|
---|
| 794 |
|
---|
| 795 | hgcmObjDereference(pClient);
|
---|
| 796 | }
|
---|
| 797 | else
|
---|
| 798 | {
|
---|
[94937] | 799 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[75990] | 800 | }
|
---|
| 801 | } break;
|
---|
| 802 |
|
---|
[1711] | 803 | case SVC_MSG_HOSTCALL:
|
---|
[1] | 804 | {
|
---|
[1711] | 805 | HGCMMsgHostCallSvc *pMsg = (HGCMMsgHostCallSvc *)pMsgCore;
|
---|
[1] | 806 |
|
---|
[51092] | 807 | LogFlowFunc(("SVC_MSG_HOSTCALL u32Function = %d, cParms = %d, paParms = %p\n",
|
---|
| 808 | pMsg->u32Function, pMsg->cParms, pMsg->paParms));
|
---|
[1] | 809 |
|
---|
[94937] | 810 | vrc = pSvc->m_fntable.pfnHostCall(pSvc->m_fntable.pvService, pMsg->u32Function, pMsg->cParms, pMsg->paParms);
|
---|
[1] | 811 | } break;
|
---|
| 812 |
|
---|
[1711] | 813 | case SVC_MSG_LOADSTATE:
|
---|
[1080] | 814 | {
|
---|
[1711] | 815 | HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)pMsgCore;
|
---|
[1080] | 816 |
|
---|
[1711] | 817 | LogFlowFunc(("SVC_MSG_LOADSTATE\n"));
|
---|
[1080] | 818 |
|
---|
[91748] | 819 | HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
|
---|
[1681] | 820 |
|
---|
| 821 | if (pClient)
|
---|
[1080] | 822 | {
|
---|
[75853] | 823 | /* fRequestor: Restored by the message sender already. */
|
---|
| 824 | bool fHaveClientState = pSvc->m_fntable.pfnLoadState != NULL;
|
---|
| 825 | if (pMsg->uVersion > HGCM_SAVED_STATE_VERSION_V2)
|
---|
[94937] | 826 | vrc = pMsg->pVMM->pfnSSMR3GetBool(pMsg->pSSM, &fHaveClientState);
|
---|
[75853] | 827 | else
|
---|
[94937] | 828 | vrc = VINF_SUCCESS;
|
---|
| 829 | if (RT_SUCCESS(vrc) )
|
---|
[1681] | 830 | {
|
---|
[75853] | 831 | if (pSvc->m_fntable.pfnLoadState)
|
---|
[94937] | 832 | vrc = pSvc->m_fntable.pfnLoadState(pSvc->m_fntable.pvService, pMsg->u32ClientId,
|
---|
| 833 | HGCM_CLIENT_DATA(pSvc, pClient), pMsg->pSSM, pMsg->pVMM,
|
---|
| 834 | fHaveClientState ? pMsg->uVersion : 0);
|
---|
[75853] | 835 | else
|
---|
[94937] | 836 | AssertLogRelStmt(!fHaveClientState, vrc = VERR_INTERNAL_ERROR_5);
|
---|
[1681] | 837 | }
|
---|
[51092] | 838 | hgcmObjDereference(pClient);
|
---|
[1080] | 839 | }
|
---|
[1711] | 840 | else
|
---|
| 841 | {
|
---|
[94937] | 842 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1711] | 843 | }
|
---|
| 844 | } break;
|
---|
[1080] | 845 |
|
---|
[1711] | 846 | case SVC_MSG_SAVESTATE:
|
---|
[1080] | 847 | {
|
---|
[1711] | 848 | HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)pMsgCore;
|
---|
[1080] | 849 |
|
---|
[1711] | 850 | LogFlowFunc(("SVC_MSG_SAVESTATE\n"));
|
---|
[1080] | 851 |
|
---|
[91748] | 852 | HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
|
---|
[1711] | 853 |
|
---|
[94937] | 854 | vrc = VINF_SUCCESS;
|
---|
[1681] | 855 |
|
---|
| 856 | if (pClient)
|
---|
[1080] | 857 | {
|
---|
[93444] | 858 | pMsg->pVMM->pfnSSMR3PutU32(pMsg->pSSM, pClient->fRequestor); /* Quicker to save this here than in the message sender. */
|
---|
[94937] | 859 | vrc = pMsg->pVMM->pfnSSMR3PutBool(pMsg->pSSM, pSvc->m_fntable.pfnSaveState != NULL);
|
---|
| 860 | if (RT_SUCCESS(vrc) && pSvc->m_fntable.pfnSaveState)
|
---|
[1681] | 861 | {
|
---|
| 862 | g_fSaveState = true;
|
---|
[94937] | 863 | vrc = pSvc->m_fntable.pfnSaveState(pSvc->m_fntable.pvService, pMsg->u32ClientId,
|
---|
| 864 | HGCM_CLIENT_DATA(pSvc, pClient), pMsg->pSSM, pMsg->pVMM);
|
---|
[1681] | 865 | g_fSaveState = false;
|
---|
| 866 | }
|
---|
| 867 |
|
---|
[51092] | 868 | hgcmObjDereference(pClient);
|
---|
[1080] | 869 | }
|
---|
[1711] | 870 | else
|
---|
| 871 | {
|
---|
[94937] | 872 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1711] | 873 | }
|
---|
| 874 | } break;
|
---|
[6985] | 875 |
|
---|
[2386] | 876 | case SVC_MSG_REGEXT:
|
---|
| 877 | {
|
---|
| 878 | HGCMMsgSvcRegisterExtension *pMsg = (HGCMMsgSvcRegisterExtension *)pMsgCore;
|
---|
[1080] | 879 |
|
---|
[2386] | 880 | LogFlowFunc(("SVC_MSG_REGEXT handle = %p, pfn = %p\n", pMsg->handle, pMsg->pfnExtension));
|
---|
[6985] | 881 |
|
---|
[2386] | 882 | if (pSvc->m_hExtension)
|
---|
| 883 | {
|
---|
[94937] | 884 | vrc = VERR_NOT_SUPPORTED;
|
---|
[2386] | 885 | }
|
---|
| 886 | else
|
---|
| 887 | {
|
---|
| 888 | if (pSvc->m_fntable.pfnRegisterExtension)
|
---|
| 889 | {
|
---|
[94937] | 890 | vrc = pSvc->m_fntable.pfnRegisterExtension(pSvc->m_fntable.pvService, pMsg->pfnExtension,
|
---|
| 891 | pMsg->pvExtension);
|
---|
[2386] | 892 | }
|
---|
| 893 | else
|
---|
| 894 | {
|
---|
[94937] | 895 | vrc = VERR_NOT_SUPPORTED;
|
---|
[2386] | 896 | }
|
---|
[6985] | 897 |
|
---|
[94937] | 898 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 899 | {
|
---|
| 900 | pSvc->m_hExtension = pMsg->handle;
|
---|
| 901 | }
|
---|
| 902 | }
|
---|
| 903 | } break;
|
---|
| 904 |
|
---|
| 905 | case SVC_MSG_UNREGEXT:
|
---|
| 906 | {
|
---|
| 907 | HGCMMsgSvcUnregisterExtension *pMsg = (HGCMMsgSvcUnregisterExtension *)pMsgCore;
|
---|
| 908 |
|
---|
| 909 | LogFlowFunc(("SVC_MSG_UNREGEXT handle = %p\n", pMsg->handle));
|
---|
[6985] | 910 |
|
---|
[2386] | 911 | if (pSvc->m_hExtension != pMsg->handle)
|
---|
| 912 | {
|
---|
[94937] | 913 | vrc = VERR_NOT_SUPPORTED;
|
---|
[2386] | 914 | }
|
---|
| 915 | else
|
---|
| 916 | {
|
---|
| 917 | if (pSvc->m_fntable.pfnRegisterExtension)
|
---|
| 918 | {
|
---|
[94937] | 919 | vrc = pSvc->m_fntable.pfnRegisterExtension(pSvc->m_fntable.pvService, NULL, NULL);
|
---|
[2386] | 920 | }
|
---|
| 921 | else
|
---|
| 922 | {
|
---|
[94937] | 923 | vrc = VERR_NOT_SUPPORTED;
|
---|
[2386] | 924 | }
|
---|
[6985] | 925 |
|
---|
[2386] | 926 | pSvc->m_hExtension = NULL;
|
---|
| 927 | }
|
---|
| 928 | } break;
|
---|
| 929 |
|
---|
[75969] | 930 | case SVC_MSG_NOTIFY:
|
---|
| 931 | {
|
---|
| 932 | HGCMMsgNotify *pMsg = (HGCMMsgNotify *)pMsgCore;
|
---|
| 933 |
|
---|
| 934 | LogFlowFunc(("SVC_MSG_NOTIFY enmEvent = %d\n", pMsg->enmEvent));
|
---|
| 935 |
|
---|
| 936 | pSvc->m_fntable.pfnNotify(pSvc->m_fntable.pvService, pMsg->enmEvent);
|
---|
| 937 | } break;
|
---|
| 938 |
|
---|
[1] | 939 | default:
|
---|
| 940 | {
|
---|
[1711] | 941 | AssertMsgFailed(("hgcmServiceThread::Unsupported message number %08X\n", u32MsgId));
|
---|
[94937] | 942 | vrc = VERR_NOT_SUPPORTED;
|
---|
[1] | 943 | } break;
|
---|
| 944 | }
|
---|
| 945 |
|
---|
[1711] | 946 | if (u32MsgId != SVC_MSG_GUESTCALL)
|
---|
[1] | 947 | {
|
---|
[1711] | 948 | /* For SVC_MSG_GUESTCALL the service calls the completion helper.
|
---|
| 949 | * Other messages have to be completed here.
|
---|
[1] | 950 | */
|
---|
[94937] | 951 | hgcmMsgComplete (pMsgCore, vrc);
|
---|
[1] | 952 | }
|
---|
[75495] | 953 | STAM_REL_PROFILE_STOP(&pSvc->m_StatHandleMsg, a);
|
---|
[1] | 954 | }
|
---|
[1711] | 955 | }
|
---|
[1] | 956 |
|
---|
[75406] | 957 | /**
|
---|
| 958 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnCallComplete}
|
---|
| 959 | */
|
---|
[98278] | 960 | /* static */ DECLCALLBACK(int) HGCMService::svcHlpCallComplete(VBOXHGCMCALLHANDLE callHandle, int32_t vrc)
|
---|
[1711] | 961 | {
|
---|
| 962 | HGCMMsgCore *pMsgCore = (HGCMMsgCore *)callHandle;
|
---|
| 963 |
|
---|
[75747] | 964 | /* Only call the completion for these messages. The helper
|
---|
| 965 | * is called by the service, and the service does not get
|
---|
| 966 | * any other messages.
|
---|
| 967 | */
|
---|
| 968 | AssertMsgReturn(pMsgCore->MsgId() == SVC_MSG_GUESTCALL, ("%d\n", pMsgCore->MsgId()), VERR_WRONG_TYPE);
|
---|
[98278] | 969 | return hgcmMsgComplete(pMsgCore, vrc);
|
---|
[1] | 970 | }
|
---|
| 971 |
|
---|
[75406] | 972 | /**
|
---|
| 973 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnDisconnectClient}
|
---|
| 974 | */
|
---|
[91100] | 975 | /* static */ DECLCALLBACK(int) HGCMService::svcHlpDisconnectClient(void *pvInstance, uint32_t idClient)
|
---|
[6981] | 976 | {
|
---|
| 977 | HGCMService *pService = static_cast <HGCMService *> (pvInstance);
|
---|
[91097] | 978 | AssertReturn(pService, VERR_INVALID_HANDLE);
|
---|
[12423] | 979 |
|
---|
[91097] | 980 | /* Only safe to call when the main HGCM thread is waiting on the service
|
---|
| 981 | to handle a SVC_MSG_CONNECT or SVC_MSG_DISCONNECT message. Otherwise
|
---|
| 982 | we'd risk racing it and corrupt data structures. */
|
---|
| 983 | AssertReturn(pService->m_fInConnectOrDisconnect, VERR_INVALID_CONTEXT);
|
---|
[90228] | 984 |
|
---|
[91100] | 985 | /* Resolve the client ID and verify that it belongs to this service before
|
---|
| 986 | trying to disconnect it. */
|
---|
[94937] | 987 | int vrc = VERR_NOT_FOUND;
|
---|
[91748] | 988 | HGCMClient * const pClient = HGCMClient::ReferenceByHandle(idClient);
|
---|
[91100] | 989 | if (pClient)
|
---|
| 990 | {
|
---|
| 991 | if (pClient->pService == pService)
|
---|
[94937] | 992 | vrc = pService->DisconnectClient(idClient, true, pClient);
|
---|
[91100] | 993 | hgcmObjDereference(pClient);
|
---|
| 994 | }
|
---|
[94937] | 995 | return vrc;
|
---|
[6981] | 996 | }
|
---|
| 997 |
|
---|
[75406] | 998 | /**
|
---|
| 999 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnIsCallRestored}
|
---|
| 1000 | */
|
---|
| 1001 | /* static */ DECLCALLBACK(bool) HGCMService::svcHlpIsCallRestored(VBOXHGCMCALLHANDLE callHandle)
|
---|
| 1002 | {
|
---|
[75990] | 1003 | HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)callHandle;
|
---|
[75406] | 1004 | AssertPtrReturn(pMsgHdr, false);
|
---|
| 1005 |
|
---|
| 1006 | PVBOXHGCMCMD pCmd = pMsgHdr->pCmd;
|
---|
| 1007 | AssertPtrReturn(pCmd, false);
|
---|
| 1008 |
|
---|
| 1009 | PPDMIHGCMPORT pHgcmPort = pMsgHdr->pHGCMPort;
|
---|
| 1010 | AssertPtrReturn(pHgcmPort, false);
|
---|
| 1011 |
|
---|
| 1012 | return pHgcmPort->pfnIsCmdRestored(pHgcmPort, pCmd);
|
---|
| 1013 | }
|
---|
| 1014 |
|
---|
[75495] | 1015 | /**
|
---|
[75990] | 1016 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnIsCallCancelled}
|
---|
| 1017 | */
|
---|
| 1018 | /* static */ DECLCALLBACK(bool) HGCMService::svcHlpIsCallCancelled(VBOXHGCMCALLHANDLE callHandle)
|
---|
| 1019 | {
|
---|
| 1020 | HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)callHandle;
|
---|
| 1021 | AssertPtrReturn(pMsgHdr, false);
|
---|
| 1022 |
|
---|
| 1023 | PVBOXHGCMCMD pCmd = pMsgHdr->pCmd;
|
---|
| 1024 | AssertPtrReturn(pCmd, false);
|
---|
| 1025 |
|
---|
| 1026 | PPDMIHGCMPORT pHgcmPort = pMsgHdr->pHGCMPort;
|
---|
| 1027 | AssertPtrReturn(pHgcmPort, false);
|
---|
| 1028 |
|
---|
| 1029 | return pHgcmPort->pfnIsCmdCancelled(pHgcmPort, pCmd);
|
---|
| 1030 | }
|
---|
| 1031 |
|
---|
| 1032 | /**
|
---|
[75495] | 1033 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnStamRegisterV}
|
---|
| 1034 | */
|
---|
| 1035 | /* static */ DECLCALLBACK(int)
|
---|
| 1036 | HGCMService::svcHlpStamRegisterV(void *pvInstance, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
| 1037 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list va)
|
---|
| 1038 | {
|
---|
| 1039 | HGCMService *pService = static_cast <HGCMService *>(pvInstance);
|
---|
| 1040 | AssertPtrReturn(pService, VERR_INVALID_PARAMETER);
|
---|
| 1041 |
|
---|
[93444] | 1042 | if (pService->m_pUVM)
|
---|
| 1043 | return pService->m_pVMM->pfnSTAMR3RegisterVU(pService->m_pUVM, pvSample, enmType, enmVisibility,
|
---|
| 1044 | enmUnit, pszDesc, pszName, va);
|
---|
| 1045 | return VINF_SUCCESS;
|
---|
[75495] | 1046 | }
|
---|
| 1047 |
|
---|
| 1048 | /**
|
---|
| 1049 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnStamDeregisterV}
|
---|
| 1050 | */
|
---|
| 1051 | /* static */ DECLCALLBACK(int) HGCMService::svcHlpStamDeregisterV(void *pvInstance, const char *pszPatFmt, va_list va)
|
---|
| 1052 | {
|
---|
| 1053 | HGCMService *pService = static_cast <HGCMService *>(pvInstance);
|
---|
| 1054 | AssertPtrReturn(pService, VERR_INVALID_PARAMETER);
|
---|
| 1055 |
|
---|
[75574] | 1056 | if (pService->m_pUVM)
|
---|
[93444] | 1057 | return pService->m_pVMM->pfnSTAMR3DeregisterV(pService->m_pUVM, pszPatFmt, va);
|
---|
[75574] | 1058 | return VINF_SUCCESS;
|
---|
[75495] | 1059 | }
|
---|
| 1060 |
|
---|
| 1061 | /**
|
---|
| 1062 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnInfoRegister}
|
---|
| 1063 | */
|
---|
| 1064 | /* static */ DECLCALLBACK(int) HGCMService::svcHlpInfoRegister(void *pvInstance, const char *pszName, const char *pszDesc,
|
---|
| 1065 | PFNDBGFHANDLEREXT pfnHandler, void *pvUser)
|
---|
| 1066 | {
|
---|
| 1067 | HGCMService *pService = static_cast <HGCMService *>(pvInstance);
|
---|
| 1068 | AssertPtrReturn(pService, VERR_INVALID_PARAMETER);
|
---|
| 1069 |
|
---|
[93444] | 1070 | if (pService->m_pUVM)
|
---|
| 1071 | return pService->m_pVMM->pfnDBGFR3InfoRegisterExternal(pService->m_pUVM, pszName, pszDesc, pfnHandler, pvUser);
|
---|
| 1072 | return VINF_SUCCESS;
|
---|
[75495] | 1073 | }
|
---|
| 1074 |
|
---|
| 1075 | /**
|
---|
| 1076 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnInfoDeregister}
|
---|
| 1077 | */
|
---|
| 1078 | /* static */ DECLCALLBACK(int) HGCMService::svcHlpInfoDeregister(void *pvInstance, const char *pszName)
|
---|
| 1079 | {
|
---|
| 1080 | HGCMService *pService = static_cast <HGCMService *>(pvInstance);
|
---|
| 1081 | AssertPtrReturn(pService, VERR_INVALID_PARAMETER);
|
---|
[75574] | 1082 | if (pService->m_pUVM)
|
---|
[93444] | 1083 | return pService->m_pVMM->pfnDBGFR3InfoDeregisterExternal(pService->m_pUVM, pszName);
|
---|
[75574] | 1084 | return VINF_SUCCESS;
|
---|
[75495] | 1085 | }
|
---|
| 1086 |
|
---|
[75769] | 1087 | /**
|
---|
| 1088 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnGetRequestor}
|
---|
| 1089 | */
|
---|
| 1090 | /* static */ DECLCALLBACK(uint32_t) HGCMService::svcHlpGetRequestor(VBOXHGCMCALLHANDLE hCall)
|
---|
| 1091 | {
|
---|
| 1092 | HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)(hCall);
|
---|
[75771] | 1093 | AssertPtrReturn(pMsgHdr, VMMDEV_REQUESTOR_LOWEST);
|
---|
[75769] | 1094 |
|
---|
| 1095 | PVBOXHGCMCMD pCmd = pMsgHdr->pCmd;
|
---|
[75771] | 1096 | AssertPtrReturn(pCmd, VMMDEV_REQUESTOR_LOWEST);
|
---|
[75769] | 1097 |
|
---|
| 1098 | PPDMIHGCMPORT pHgcmPort = pMsgHdr->pHGCMPort;
|
---|
[75771] | 1099 | AssertPtrReturn(pHgcmPort, VMMDEV_REQUESTOR_LOWEST);
|
---|
[75769] | 1100 |
|
---|
| 1101 | return pHgcmPort->pfnGetRequestor(pHgcmPort, pCmd);
|
---|
| 1102 | }
|
---|
| 1103 |
|
---|
[75853] | 1104 | /**
|
---|
| 1105 | * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnGetVMMDevSessionId}
|
---|
| 1106 | */
|
---|
| 1107 | /* static */ DECLCALLBACK(uint64_t) HGCMService::svcHlpGetVMMDevSessionId(void *pvInstance)
|
---|
| 1108 | {
|
---|
| 1109 | HGCMService *pService = static_cast <HGCMService *>(pvInstance);
|
---|
| 1110 | AssertPtrReturn(pService, UINT64_MAX);
|
---|
[75769] | 1111 |
|
---|
[75853] | 1112 | PPDMIHGCMPORT pHgcmPort = pService->m_pHgcmPort;
|
---|
| 1113 | AssertPtrReturn(pHgcmPort, UINT64_MAX);
|
---|
| 1114 |
|
---|
| 1115 | return pHgcmPort->pfnGetVMMDevSessionId(pHgcmPort);
|
---|
| 1116 | }
|
---|
| 1117 |
|
---|
| 1118 |
|
---|
[75740] | 1119 | static DECLCALLBACK(int) hgcmMsgCompletionCallback(int32_t result, HGCMMsgCore *pMsgCore)
|
---|
[1] | 1120 | {
|
---|
[1711] | 1121 | /* Call the VMMDev port interface to issue IRQ notification. */
|
---|
| 1122 | HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)pMsgCore;
|
---|
[1] | 1123 |
|
---|
[1711] | 1124 | LogFlow(("MAIN::hgcmMsgCompletionCallback: message %p\n", pMsgCore));
|
---|
[1] | 1125 |
|
---|
[75740] | 1126 | if (pMsgHdr->pHGCMPort)
|
---|
[1711] | 1127 | {
|
---|
[75740] | 1128 | if (!g_fResetting)
|
---|
| 1129 | return pMsgHdr->pHGCMPort->pfnCompleted(pMsgHdr->pHGCMPort,
|
---|
| 1130 | g_fSaveState ? VINF_HGCM_SAVE_STATE : result, pMsgHdr->pCmd);
|
---|
| 1131 | return VERR_ALREADY_RESET; /* best I could find. */
|
---|
[1711] | 1132 | }
|
---|
[75740] | 1133 | return VERR_NOT_AVAILABLE;
|
---|
[1711] | 1134 | }
|
---|
[1] | 1135 |
|
---|
[1711] | 1136 | /*
|
---|
| 1137 | * The main HGCM methods of the service.
|
---|
| 1138 | */
|
---|
[1] | 1139 |
|
---|
[93444] | 1140 | int HGCMService::instanceCreate(const char *pszServiceLibrary, const char *pszServiceName,
|
---|
| 1141 | PUVM pUVM, PCVMMR3VTABLE pVMM, PPDMIHGCMPORT pHgcmPort)
|
---|
[1711] | 1142 | {
|
---|
| 1143 | LogFlowFunc(("name %s, lib %s\n", pszServiceName, pszServiceLibrary));
|
---|
[93444] | 1144 |
|
---|
[1711] | 1145 | /* The maximum length of the thread name, allowed by the RT is 15. */
|
---|
[39336] | 1146 | char szThreadName[16];
|
---|
[51092] | 1147 | if (!strncmp(pszServiceName, RT_STR_TUPLE("VBoxShared")))
|
---|
| 1148 | RTStrPrintf(szThreadName, sizeof(szThreadName), "Sh%s", pszServiceName + 10);
|
---|
| 1149 | else if (!strncmp(pszServiceName, RT_STR_TUPLE("VBox")))
|
---|
| 1150 | RTStrCopy(szThreadName, sizeof(szThreadName), pszServiceName + 4);
|
---|
[39336] | 1151 | else
|
---|
[51092] | 1152 | RTStrCopy(szThreadName, sizeof(szThreadName), pszServiceName);
|
---|
[1711] | 1153 |
|
---|
[94937] | 1154 | int vrc = hgcmThreadCreate(&m_pThread, szThreadName, hgcmServiceThread, this, pszServiceName, pUVM, pVMM);
|
---|
| 1155 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1156 | {
|
---|
[51092] | 1157 | m_pszSvcName = RTStrDup(pszServiceName);
|
---|
| 1158 | m_pszSvcLibrary = RTStrDup(pszServiceLibrary);
|
---|
[1] | 1159 |
|
---|
| 1160 | if (!m_pszSvcName || !m_pszSvcLibrary)
|
---|
| 1161 | {
|
---|
[51092] | 1162 | RTStrFree(m_pszSvcLibrary);
|
---|
[1] | 1163 | m_pszSvcLibrary = NULL;
|
---|
[6985] | 1164 |
|
---|
[51092] | 1165 | RTStrFree(m_pszSvcName);
|
---|
[1] | 1166 | m_pszSvcName = NULL;
|
---|
[6985] | 1167 |
|
---|
[94937] | 1168 | vrc = VERR_NO_MEMORY;
|
---|
[1] | 1169 | }
|
---|
| 1170 | else
|
---|
| 1171 | {
|
---|
[75853] | 1172 | m_pUVM = pUVM;
|
---|
[93444] | 1173 | m_pVMM = pVMM;
|
---|
[75853] | 1174 | m_pHgcmPort = pHgcmPort;
|
---|
| 1175 |
|
---|
[93444] | 1176 | registerStatistics(pszServiceName, pUVM, pVMM);
|
---|
[75495] | 1177 |
|
---|
[1711] | 1178 | /* Initialize service helpers table. */
|
---|
[75853] | 1179 | m_svcHelpers.pfnCallComplete = svcHlpCallComplete;
|
---|
| 1180 | m_svcHelpers.pvInstance = this;
|
---|
| 1181 | m_svcHelpers.pfnDisconnectClient = svcHlpDisconnectClient;
|
---|
| 1182 | m_svcHelpers.pfnIsCallRestored = svcHlpIsCallRestored;
|
---|
[75990] | 1183 | m_svcHelpers.pfnIsCallCancelled = svcHlpIsCallCancelled;
|
---|
[75853] | 1184 | m_svcHelpers.pfnStamRegisterV = svcHlpStamRegisterV;
|
---|
| 1185 | m_svcHelpers.pfnStamDeregisterV = svcHlpStamDeregisterV;
|
---|
| 1186 | m_svcHelpers.pfnInfoRegister = svcHlpInfoRegister;
|
---|
| 1187 | m_svcHelpers.pfnInfoDeregister = svcHlpInfoDeregister;
|
---|
| 1188 | m_svcHelpers.pfnGetRequestor = svcHlpGetRequestor;
|
---|
| 1189 | m_svcHelpers.pfnGetVMMDevSessionId = svcHlpGetVMMDevSessionId;
|
---|
[6985] | 1190 |
|
---|
[1] | 1191 | /* Execute the load request on the service thread. */
|
---|
[75541] | 1192 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 1193 | vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_LOAD, hgcmMessageAllocSvc);
|
---|
[1] | 1194 |
|
---|
[94937] | 1195 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1196 | {
|
---|
[75541] | 1197 | HGCMMsgSvcLoad *pMsg = (HGCMMsgSvcLoad *)pCoreMsg;
|
---|
| 1198 |
|
---|
[75495] | 1199 | pMsg->pUVM = pUVM;
|
---|
| 1200 |
|
---|
[94937] | 1201 | vrc = hgcmMsgSend(pMsg);
|
---|
[1] | 1202 | }
|
---|
| 1203 | }
|
---|
| 1204 | }
|
---|
| 1205 |
|
---|
[94937] | 1206 | if (RT_FAILURE(vrc))
|
---|
[1] | 1207 | {
|
---|
[51092] | 1208 | instanceDestroy();
|
---|
[1] | 1209 | }
|
---|
| 1210 |
|
---|
[94937] | 1211 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1212 | return vrc;
|
---|
[1] | 1213 | }
|
---|
| 1214 |
|
---|
[93444] | 1215 | /** Called by HGCMService::instanceCreate to register statistics. */
|
---|
| 1216 | void HGCMService::registerStatistics(const char *pszServiceName, PUVM pUVM, PCVMMR3VTABLE pVMM)
|
---|
| 1217 | {
|
---|
| 1218 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_StatHandleMsg, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_OCCURENCE,
|
---|
| 1219 | "Message handling", "/HGCM/%s/Msg", pszServiceName);
|
---|
| 1220 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_StatTooManyCalls, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
|
---|
| 1221 | "Too many calls (per client)", "/HGCM/%s/TooManyCalls", pszServiceName);
|
---|
| 1222 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_StatTooManyClients, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
|
---|
| 1223 | "Too many clients", "/HGCM/%s/TooManyClients", pszServiceName);
|
---|
| 1224 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_cClients, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
|
---|
| 1225 | "Number of clients", "/HGCM/%s/Clients", pszServiceName);
|
---|
| 1226 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_acClients[HGCM_CLIENT_CATEGORY_KERNEL], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1227 | STAMUNIT_OCCURENCES, "Number of kernel clients", "/HGCM/%s/Clients/Kernel", pszServiceName);
|
---|
| 1228 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_acClients[HGCM_CLIENT_CATEGORY_ROOT], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1229 | STAMUNIT_OCCURENCES, "Number of root/admin clients", "/HGCM/%s/Clients/Root", pszServiceName);
|
---|
| 1230 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_acClients[HGCM_CLIENT_CATEGORY_USER], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1231 | STAMUNIT_OCCURENCES, "Number of regular user clients", "/HGCM/%s/Clients/User", pszServiceName);
|
---|
| 1232 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_KERNEL], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1233 | STAMUNIT_OCCURENCES, "Max number of kernel clients", "/HGCM/%s/Clients/KernelMax", pszServiceName);
|
---|
| 1234 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_ROOT], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1235 | STAMUNIT_OCCURENCES, "Max number of root clients", "/HGCM/%s/Clients/RootMax", pszServiceName);
|
---|
| 1236 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.acMaxClients[HGCM_CLIENT_CATEGORY_USER], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1237 | STAMUNIT_OCCURENCES, "Max number of user clients", "/HGCM/%s/Clients/UserMax", pszServiceName);
|
---|
| 1238 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.idxLegacyClientCategory, STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1239 | STAMUNIT_OCCURENCES, "Legacy client mapping", "/HGCM/%s/Clients/LegacyClientMapping", pszServiceName);
|
---|
| 1240 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_KERNEL], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1241 | STAMUNIT_OCCURENCES, "Max number of call per kernel client", "/HGCM/%s/MaxCallsKernelClient", pszServiceName);
|
---|
| 1242 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_ROOT], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1243 | STAMUNIT_OCCURENCES, "Max number of call per root client", "/HGCM/%s/MaxCallsRootClient", pszServiceName);
|
---|
| 1244 | pVMM->pfnSTAMR3RegisterFU(pUVM, &m_fntable.acMaxCallsPerClient[HGCM_CLIENT_CATEGORY_USER], STAMTYPE_U32, STAMVISIBILITY_ALWAYS,
|
---|
| 1245 | STAMUNIT_OCCURENCES, "Max number of call per user client", "/HGCM/%s/MaxCallsUserClient", pszServiceName);
|
---|
| 1246 | }
|
---|
| 1247 |
|
---|
[51092] | 1248 | void HGCMService::instanceDestroy(void)
|
---|
[1] | 1249 | {
|
---|
[1711] | 1250 | LogFlowFunc(("%s\n", m_pszSvcName));
|
---|
| 1251 |
|
---|
[75541] | 1252 | HGCMMsgCore *pMsg;
|
---|
[94937] | 1253 | int vrc = hgcmMsgAlloc(m_pThread, &pMsg, SVC_MSG_UNLOAD, hgcmMessageAllocSvc);
|
---|
[1] | 1254 |
|
---|
[94937] | 1255 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1256 | {
|
---|
[94937] | 1257 | vrc = hgcmMsgSend(pMsg);
|
---|
[1788] | 1258 |
|
---|
[94937] | 1259 | if (RT_SUCCESS(vrc))
|
---|
[75539] | 1260 | hgcmThreadWait(m_pThread);
|
---|
[1] | 1261 | }
|
---|
| 1262 |
|
---|
[75574] | 1263 | if (m_pszSvcName && m_pUVM)
|
---|
[93444] | 1264 | m_pVMM->pfnSTAMR3DeregisterF(m_pUVM, "/HGCM/%s/*", m_pszSvcName);
|
---|
[75495] | 1265 | m_pUVM = NULL;
|
---|
[75853] | 1266 | m_pHgcmPort = NULL;
|
---|
[75495] | 1267 |
|
---|
[51092] | 1268 | RTStrFree(m_pszSvcLibrary);
|
---|
[1] | 1269 | m_pszSvcLibrary = NULL;
|
---|
[1711] | 1270 |
|
---|
[51092] | 1271 | RTStrFree(m_pszSvcName);
|
---|
[1] | 1272 | m_pszSvcName = NULL;
|
---|
[78910] | 1273 |
|
---|
| 1274 | if (m_paClientIds)
|
---|
| 1275 | {
|
---|
| 1276 | RTMemFree(m_paClientIds);
|
---|
| 1277 | m_paClientIds = NULL;
|
---|
| 1278 | }
|
---|
[1] | 1279 | }
|
---|
| 1280 |
|
---|
[93444] | 1281 | int HGCMService::saveClientState(uint32_t u32ClientId, PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM)
|
---|
[1] | 1282 | {
|
---|
[1711] | 1283 | LogFlowFunc(("%s\n", m_pszSvcName));
|
---|
| 1284 |
|
---|
[75541] | 1285 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 1286 | int vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_SAVESTATE, hgcmMessageAllocSvc);
|
---|
[1711] | 1287 |
|
---|
[94937] | 1288 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1289 | {
|
---|
[75541] | 1290 | HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)pCoreMsg;
|
---|
[1] | 1291 |
|
---|
[1711] | 1292 | pMsg->u32ClientId = u32ClientId;
|
---|
| 1293 | pMsg->pSSM = pSSM;
|
---|
[93444] | 1294 | pMsg->pVMM = pVMM;
|
---|
[1711] | 1295 |
|
---|
[94937] | 1296 | vrc = hgcmMsgSend(pMsg);
|
---|
[1] | 1297 | }
|
---|
| 1298 |
|
---|
[94937] | 1299 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1300 | return vrc;
|
---|
[1] | 1301 | }
|
---|
| 1302 |
|
---|
[93444] | 1303 | int HGCMService::loadClientState(uint32_t u32ClientId, PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t uVersion)
|
---|
[1] | 1304 | {
|
---|
[1711] | 1305 | LogFlowFunc(("%s\n", m_pszSvcName));
|
---|
[1] | 1306 |
|
---|
[75541] | 1307 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 1308 | int vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_LOADSTATE, hgcmMessageAllocSvc);
|
---|
[1] | 1309 |
|
---|
[94937] | 1310 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1311 | {
|
---|
[75541] | 1312 | HGCMMsgLoadSaveStateClient *pMsg = (HGCMMsgLoadSaveStateClient *)pCoreMsg;
|
---|
[1] | 1313 |
|
---|
[75853] | 1314 | pMsg->pSSM = pSSM;
|
---|
[93444] | 1315 | pMsg->pVMM = pVMM;
|
---|
[75853] | 1316 | pMsg->uVersion = uVersion;
|
---|
[1711] | 1317 | pMsg->u32ClientId = u32ClientId;
|
---|
[1] | 1318 |
|
---|
[94937] | 1319 | vrc = hgcmMsgSend(pMsg);
|
---|
[1] | 1320 | }
|
---|
| 1321 |
|
---|
[94937] | 1322 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1323 | return vrc;
|
---|
[1] | 1324 | }
|
---|
| 1325 |
|
---|
| 1326 |
|
---|
[1711] | 1327 | /** The method creates a service and references it.
|
---|
| 1328 | *
|
---|
[75853] | 1329 | * @param pszServiceLibrary The library to be loaded.
|
---|
| 1330 | * @param pszServiceName The name of the service.
|
---|
| 1331 | * @param pUVM The user mode VM handle (for statistics and such).
|
---|
[93444] | 1332 | * @param pVMM The VMM vtable (for statistics and such).
|
---|
[75853] | 1333 | * @param pHgcmPort The VMMDev HGCM port interface.
|
---|
| 1334 | *
|
---|
[98278] | 1335 | * @return VBox status code.
|
---|
[75853] | 1336 | * @thread main HGCM
|
---|
[1711] | 1337 | */
|
---|
[75853] | 1338 | /* static */ int HGCMService::LoadService(const char *pszServiceLibrary, const char *pszServiceName,
|
---|
[93444] | 1339 | PUVM pUVM, PCVMMR3VTABLE pVMM, PPDMIHGCMPORT pHgcmPort)
|
---|
[1] | 1340 | {
|
---|
[75495] | 1341 | LogFlowFunc(("lib %s, name = %s, pUVM = %p\n", pszServiceLibrary, pszServiceName, pUVM));
|
---|
[1] | 1342 |
|
---|
[1711] | 1343 | /* Look at already loaded services to avoid double loading. */
|
---|
[1] | 1344 |
|
---|
[1711] | 1345 | HGCMService *pSvc;
|
---|
[94937] | 1346 | int vrc = HGCMService::ResolveService(&pSvc, pszServiceName);
|
---|
[6985] | 1347 |
|
---|
[94937] | 1348 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1349 | {
|
---|
[1711] | 1350 | /* The service is already loaded. */
|
---|
[51092] | 1351 | pSvc->ReleaseService();
|
---|
[94937] | 1352 | vrc = VERR_HGCM_SERVICE_EXISTS;
|
---|
[1] | 1353 | }
|
---|
| 1354 | else
|
---|
| 1355 | {
|
---|
[1711] | 1356 | /* Create the new service. */
|
---|
[75495] | 1357 | pSvc = new (std::nothrow) HGCMService();
|
---|
[1] | 1358 |
|
---|
[1711] | 1359 | if (!pSvc)
|
---|
[1] | 1360 | {
|
---|
[94937] | 1361 | vrc = VERR_NO_MEMORY;
|
---|
[1] | 1362 | }
|
---|
[1711] | 1363 | else
|
---|
[1] | 1364 | {
|
---|
[1711] | 1365 | /* Load the library and call the initialization entry point. */
|
---|
[94937] | 1366 | vrc = pSvc->instanceCreate(pszServiceLibrary, pszServiceName, pUVM, pVMM, pHgcmPort);
|
---|
| 1367 | if (RT_SUCCESS(vrc))
|
---|
[1] | 1368 | {
|
---|
| 1369 | /* Insert the just created service to list for future references. */
|
---|
[1711] | 1370 | pSvc->m_pSvcNext = sm_pSvcListHead;
|
---|
| 1371 | pSvc->m_pSvcPrev = NULL;
|
---|
[6985] | 1372 |
|
---|
[1] | 1373 | if (sm_pSvcListHead)
|
---|
[1711] | 1374 | sm_pSvcListHead->m_pSvcPrev = pSvc;
|
---|
[1] | 1375 | else
|
---|
[1711] | 1376 | sm_pSvcListTail = pSvc;
|
---|
[1] | 1377 |
|
---|
[1711] | 1378 | sm_pSvcListHead = pSvc;
|
---|
| 1379 |
|
---|
[1681] | 1380 | sm_cServices++;
|
---|
[1711] | 1381 |
|
---|
| 1382 | /* Reference the service (for first time) until it is unloaded on HGCM termination. */
|
---|
[51092] | 1383 | AssertRelease(pSvc->m_u32RefCnt == 0);
|
---|
| 1384 | pSvc->ReferenceService();
|
---|
[1711] | 1385 |
|
---|
| 1386 | LogFlowFunc(("service %p\n", pSvc));
|
---|
[1] | 1387 | }
|
---|
| 1388 | }
|
---|
| 1389 | }
|
---|
| 1390 |
|
---|
[94937] | 1391 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1392 | return vrc;
|
---|
[1] | 1393 | }
|
---|
| 1394 |
|
---|
[1711] | 1395 | /** The method unloads a service.
|
---|
| 1396 | *
|
---|
| 1397 | * @thread main HGCM
|
---|
| 1398 | */
|
---|
[75574] | 1399 | void HGCMService::UnloadService(bool fUvmIsInvalid)
|
---|
[1711] | 1400 | {
|
---|
| 1401 | LogFlowFunc(("name = %s\n", m_pszSvcName));
|
---|
| 1402 |
|
---|
[75574] | 1403 | if (fUvmIsInvalid)
|
---|
[75853] | 1404 | {
|
---|
[75574] | 1405 | m_pUVM = NULL;
|
---|
[75853] | 1406 | m_pHgcmPort = NULL;
|
---|
| 1407 | }
|
---|
[75574] | 1408 |
|
---|
[1711] | 1409 | /* Remove the service from the list. */
|
---|
| 1410 | if (m_pSvcNext)
|
---|
| 1411 | {
|
---|
| 1412 | m_pSvcNext->m_pSvcPrev = m_pSvcPrev;
|
---|
| 1413 | }
|
---|
| 1414 | else
|
---|
| 1415 | {
|
---|
| 1416 | sm_pSvcListTail = m_pSvcPrev;
|
---|
| 1417 | }
|
---|
| 1418 |
|
---|
| 1419 | if (m_pSvcPrev)
|
---|
| 1420 | {
|
---|
| 1421 | m_pSvcPrev->m_pSvcNext = m_pSvcNext;
|
---|
| 1422 | }
|
---|
| 1423 | else
|
---|
| 1424 | {
|
---|
| 1425 | sm_pSvcListHead = m_pSvcNext;
|
---|
| 1426 | }
|
---|
| 1427 |
|
---|
| 1428 | sm_cServices--;
|
---|
| 1429 |
|
---|
| 1430 | /* The service must be unloaded only if all clients were disconnected. */
|
---|
| 1431 | LogFlowFunc(("m_u32RefCnt = %d\n", m_u32RefCnt));
|
---|
[51092] | 1432 | AssertRelease(m_u32RefCnt == 1);
|
---|
[1711] | 1433 |
|
---|
| 1434 | /* Now the service can be released. */
|
---|
[51092] | 1435 | ReleaseService();
|
---|
[1711] | 1436 | }
|
---|
| 1437 |
|
---|
| 1438 | /** The method unloads all services.
|
---|
| 1439 | *
|
---|
| 1440 | * @thread main HGCM
|
---|
| 1441 | */
|
---|
[75574] | 1442 | /* static */ void HGCMService::UnloadAll(bool fUvmIsInvalid)
|
---|
[1711] | 1443 | {
|
---|
| 1444 | while (sm_pSvcListHead)
|
---|
| 1445 | {
|
---|
[75574] | 1446 | sm_pSvcListHead->UnloadService(fUvmIsInvalid);
|
---|
[1711] | 1447 | }
|
---|
| 1448 | }
|
---|
| 1449 |
|
---|
| 1450 | /** The method obtains a referenced pointer to the service with
|
---|
| 1451 | * specified name. The caller must call ReleaseService when
|
---|
| 1452 | * the pointer is no longer needed.
|
---|
| 1453 | *
|
---|
| 1454 | * @param ppSvc Where to store the pointer to the service.
|
---|
| 1455 | * @param pszServiceName The name of the service.
|
---|
[98278] | 1456 | * @return VBox status code.
|
---|
[1711] | 1457 | * @thread main HGCM
|
---|
| 1458 | */
|
---|
[51092] | 1459 | /* static */ int HGCMService::ResolveService(HGCMService **ppSvc, const char *pszServiceName)
|
---|
[1711] | 1460 | {
|
---|
| 1461 | LogFlowFunc(("ppSvc = %p name = %s\n",
|
---|
| 1462 | ppSvc, pszServiceName));
|
---|
| 1463 |
|
---|
| 1464 | if (!ppSvc || !pszServiceName)
|
---|
| 1465 | {
|
---|
| 1466 | return VERR_INVALID_PARAMETER;
|
---|
| 1467 | }
|
---|
| 1468 |
|
---|
| 1469 | HGCMService *pSvc = sm_pSvcListHead;
|
---|
| 1470 |
|
---|
| 1471 | while (pSvc)
|
---|
| 1472 | {
|
---|
[51092] | 1473 | if (strcmp(pSvc->m_pszSvcName, pszServiceName) == 0)
|
---|
[1711] | 1474 | {
|
---|
| 1475 | break;
|
---|
| 1476 | }
|
---|
| 1477 |
|
---|
| 1478 | pSvc = pSvc->m_pSvcNext;
|
---|
| 1479 | }
|
---|
| 1480 |
|
---|
| 1481 | LogFlowFunc(("lookup in the list is %p\n", pSvc));
|
---|
| 1482 |
|
---|
| 1483 | if (pSvc == NULL)
|
---|
| 1484 | {
|
---|
[10807] | 1485 | *ppSvc = NULL;
|
---|
[1711] | 1486 | return VERR_HGCM_SERVICE_NOT_FOUND;
|
---|
| 1487 | }
|
---|
| 1488 |
|
---|
[51092] | 1489 | pSvc->ReferenceService();
|
---|
[1711] | 1490 |
|
---|
| 1491 | *ppSvc = pSvc;
|
---|
| 1492 |
|
---|
| 1493 | return VINF_SUCCESS;
|
---|
| 1494 | }
|
---|
| 1495 |
|
---|
| 1496 | /** The method increases reference counter.
|
---|
| 1497 | *
|
---|
| 1498 | * @thread main HGCM
|
---|
| 1499 | */
|
---|
[51092] | 1500 | void HGCMService::ReferenceService(void)
|
---|
[1711] | 1501 | {
|
---|
[51092] | 1502 | ASMAtomicIncU32(&m_u32RefCnt);
|
---|
[22814] | 1503 | LogFlowFunc(("[%s] m_u32RefCnt = %d\n", m_pszSvcName, m_u32RefCnt));
|
---|
[6985] | 1504 | }
|
---|
[1711] | 1505 |
|
---|
| 1506 | /** The method dereferences a service and deletes it when no more refs.
|
---|
| 1507 | *
|
---|
| 1508 | * @thread main HGCM
|
---|
| 1509 | */
|
---|
[51092] | 1510 | void HGCMService::ReleaseService(void)
|
---|
[1711] | 1511 | {
|
---|
| 1512 | LogFlowFunc(("m_u32RefCnt = %d\n", m_u32RefCnt));
|
---|
[51092] | 1513 | uint32_t u32RefCnt = ASMAtomicDecU32(&m_u32RefCnt);
|
---|
[1711] | 1514 | AssertRelease(u32RefCnt != ~0U);
|
---|
| 1515 |
|
---|
| 1516 | LogFlowFunc(("u32RefCnt = %d, name %s\n", u32RefCnt, m_pszSvcName));
|
---|
| 1517 |
|
---|
| 1518 | if (u32RefCnt == 0)
|
---|
| 1519 | {
|
---|
[51092] | 1520 | instanceDestroy();
|
---|
[1711] | 1521 | delete this;
|
---|
| 1522 | }
|
---|
| 1523 | }
|
---|
| 1524 |
|
---|
| 1525 | /** The method is called when the VM is being reset or terminated
|
---|
| 1526 | * and disconnects all clients from all services.
|
---|
| 1527 | *
|
---|
| 1528 | * @thread main HGCM
|
---|
| 1529 | */
|
---|
[51092] | 1530 | /* static */ void HGCMService::Reset(void)
|
---|
[1385] | 1531 | {
|
---|
| 1532 | g_fResetting = true;
|
---|
| 1533 |
|
---|
[1711] | 1534 | HGCMService *pSvc = sm_pSvcListHead;
|
---|
[1385] | 1535 |
|
---|
[1711] | 1536 | while (pSvc)
|
---|
[1385] | 1537 | {
|
---|
[1711] | 1538 | while (pSvc->m_cClients && pSvc->m_paClientIds)
|
---|
| 1539 | {
|
---|
[90228] | 1540 | uint32_t const idClient = pSvc->m_paClientIds[0];
|
---|
[91748] | 1541 | HGCMClient * const pClient = HGCMClient::ReferenceByHandle(idClient);
|
---|
[90228] | 1542 | Assert(pClient);
|
---|
| 1543 | LogFlowFunc(("handle %d/%p\n", pSvc->m_paClientIds[0], pClient));
|
---|
| 1544 |
|
---|
| 1545 | pSvc->DisconnectClient(pSvc->m_paClientIds[0], false, pClient);
|
---|
| 1546 |
|
---|
| 1547 | hgcmObjDereference(pClient);
|
---|
[1711] | 1548 | }
|
---|
[1385] | 1549 |
|
---|
[1711] | 1550 | pSvc = pSvc->m_pSvcNext;
|
---|
[1385] | 1551 | }
|
---|
[1711] | 1552 |
|
---|
[1385] | 1553 | g_fResetting = false;
|
---|
| 1554 | }
|
---|
| 1555 |
|
---|
[1711] | 1556 | /** The method saves the HGCM state.
|
---|
| 1557 | *
|
---|
| 1558 | * @param pSSM The saved state context.
|
---|
[93444] | 1559 | * @param pVMM The VMM vtable.
|
---|
| 1560 | * @return VBox status code.
|
---|
[1711] | 1561 | * @thread main HGCM
|
---|
| 1562 | */
|
---|
[93444] | 1563 | /* static */ int HGCMService::SaveState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM)
|
---|
[1681] | 1564 | {
|
---|
| 1565 | /* Save the current handle count and restore afterwards to avoid client id conflicts. */
|
---|
[94937] | 1566 | int vrc = pVMM->pfnSSMR3PutU32(pSSM, hgcmObjQueryHandleCount());
|
---|
| 1567 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1568 |
|
---|
| 1569 | LogFlowFunc(("%d services to be saved:\n", sm_cServices));
|
---|
[6985] | 1570 |
|
---|
[1681] | 1571 | /* Save number of services. */
|
---|
[94937] | 1572 | vrc = pVMM->pfnSSMR3PutU32(pSSM, sm_cServices);
|
---|
| 1573 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1574 |
|
---|
| 1575 | /* Save every service. */
|
---|
| 1576 | HGCMService *pSvc = sm_pSvcListHead;
|
---|
| 1577 |
|
---|
| 1578 | while (pSvc)
|
---|
| 1579 | {
|
---|
| 1580 | LogFlowFunc(("Saving service [%s]\n", pSvc->m_pszSvcName));
|
---|
| 1581 |
|
---|
| 1582 | /* Save the length of the service name. */
|
---|
[94937] | 1583 | vrc = pVMM->pfnSSMR3PutU32(pSSM, (uint32_t) strlen(pSvc->m_pszSvcName) + 1);
|
---|
| 1584 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1585 |
|
---|
| 1586 | /* Save the name of the service. */
|
---|
[94937] | 1587 | vrc = pVMM->pfnSSMR3PutStrZ(pSSM, pSvc->m_pszSvcName);
|
---|
| 1588 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1589 |
|
---|
| 1590 | /* Save the number of clients. */
|
---|
[94937] | 1591 | vrc = pVMM->pfnSSMR3PutU32(pSSM, pSvc->m_cClients);
|
---|
| 1592 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1593 |
|
---|
| 1594 | /* Call the service for every client. Normally a service must not have
|
---|
| 1595 | * a global state to be saved: only per client info is relevant.
|
---|
| 1596 | * The global state of a service is configured during VM startup.
|
---|
| 1597 | */
|
---|
[70599] | 1598 | uint32_t i;
|
---|
[1681] | 1599 |
|
---|
| 1600 | for (i = 0; i < pSvc->m_cClients; i++)
|
---|
| 1601 | {
|
---|
[1711] | 1602 | uint32_t u32ClientId = pSvc->m_paClientIds[i];
|
---|
[1681] | 1603 |
|
---|
[1711] | 1604 | Log(("client id 0x%08X\n", u32ClientId));
|
---|
[1681] | 1605 |
|
---|
[75853] | 1606 | /* Save the client id. (fRequestor is saved via SVC_MSG_SAVESTATE for convenience.) */
|
---|
[94937] | 1607 | vrc = pVMM->pfnSSMR3PutU32(pSSM, u32ClientId);
|
---|
| 1608 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1609 |
|
---|
| 1610 | /* Call the service, so the operation is executed by the service thread. */
|
---|
[94937] | 1611 | vrc = pSvc->saveClientState(u32ClientId, pSSM, pVMM);
|
---|
| 1612 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1613 | }
|
---|
| 1614 |
|
---|
| 1615 | pSvc = pSvc->m_pSvcNext;
|
---|
| 1616 | }
|
---|
| 1617 |
|
---|
| 1618 | return VINF_SUCCESS;
|
---|
| 1619 | }
|
---|
| 1620 |
|
---|
[1711] | 1621 | /** The method loads saved HGCM state.
|
---|
| 1622 | *
|
---|
[75853] | 1623 | * @param pSSM The saved state handle.
|
---|
[93444] | 1624 | * @param pVMM The VMM vtable.
|
---|
[75853] | 1625 | * @param uVersion The state version being loaded.
|
---|
[93444] | 1626 | * @return VBox status code.
|
---|
[1711] | 1627 | * @thread main HGCM
|
---|
| 1628 | */
|
---|
[93444] | 1629 | /* static */ int HGCMService::LoadState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t uVersion)
|
---|
[1681] | 1630 | {
|
---|
| 1631 | /* Restore handle count to avoid client id conflicts. */
|
---|
| 1632 | uint32_t u32;
|
---|
| 1633 |
|
---|
[94937] | 1634 | int vrc = pVMM->pfnSSMR3GetU32(pSSM, &u32);
|
---|
| 1635 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1636 |
|
---|
| 1637 | hgcmObjSetHandleCount(u32);
|
---|
| 1638 |
|
---|
| 1639 | /* Get the number of services. */
|
---|
| 1640 | uint32_t cServices;
|
---|
| 1641 |
|
---|
[94937] | 1642 | vrc = pVMM->pfnSSMR3GetU32(pSSM, &cServices);
|
---|
| 1643 | AssertRCReturn(vrc, vrc);
|
---|
[6985] | 1644 |
|
---|
[1681] | 1645 | LogFlowFunc(("%d services to be restored:\n", cServices));
|
---|
| 1646 |
|
---|
| 1647 | while (cServices--)
|
---|
| 1648 | {
|
---|
| 1649 | /* Get the length of the service name. */
|
---|
[94937] | 1650 | vrc = pVMM->pfnSSMR3GetU32(pSSM, &u32);
|
---|
| 1651 | AssertRCReturn(vrc, vrc);
|
---|
[1681] | 1652 | AssertReturn(u32 <= VBOX_HGCM_SVC_NAME_MAX_BYTES, VERR_SSM_UNEXPECTED_DATA);
|
---|
[6985] | 1653 |
|
---|
[1681] | 1654 | /* Get the service name. */
|
---|
[75385] | 1655 | char szServiceName[VBOX_HGCM_SVC_NAME_MAX_BYTES];
|
---|
[94937] | 1656 | vrc = pVMM->pfnSSMR3GetStrZ(pSSM, szServiceName, u32);
|
---|
| 1657 | AssertRCReturn(vrc, vrc);
|
---|
[6985] | 1658 |
|
---|
[75385] | 1659 | LogRel(("HGCM: Restoring [%s]\n", szServiceName));
|
---|
[6985] | 1660 |
|
---|
[1681] | 1661 | /* Resolve the service instance. */
|
---|
[6985] | 1662 | HGCMService *pSvc;
|
---|
[94937] | 1663 | vrc = ResolveService(&pSvc, szServiceName);
|
---|
| 1664 | AssertLogRelMsgReturn(pSvc, ("vrc=%Rrc, %s\n", vrc, szServiceName), VERR_SSM_UNEXPECTED_DATA);
|
---|
[6985] | 1665 |
|
---|
[1681] | 1666 | /* Get the number of clients. */
|
---|
| 1667 | uint32_t cClients;
|
---|
[94937] | 1668 | vrc = pVMM->pfnSSMR3GetU32(pSSM, &cClients);
|
---|
| 1669 | if (RT_FAILURE(vrc))
|
---|
[1711] | 1670 | {
|
---|
[51092] | 1671 | pSvc->ReleaseService();
|
---|
[1711] | 1672 | AssertFailed();
|
---|
[94937] | 1673 | return vrc;
|
---|
[1711] | 1674 | }
|
---|
| 1675 |
|
---|
[1681] | 1676 | while (cClients--)
|
---|
| 1677 | {
|
---|
[75853] | 1678 | /* Get the client ID and fRequest (convieniently save via SVC_MSG_SAVESTATE
|
---|
| 1679 | but restored here in time for calling CreateAndConnectClient). */
|
---|
[1711] | 1680 | uint32_t u32ClientId;
|
---|
[94937] | 1681 | vrc = pVMM->pfnSSMR3GetU32(pSSM, &u32ClientId);
|
---|
[75853] | 1682 | uint32_t fRequestor = VMMDEV_REQUESTOR_LEGACY;
|
---|
[94937] | 1683 | if (RT_SUCCESS(vrc) && uVersion > HGCM_SAVED_STATE_VERSION_V2)
|
---|
| 1684 | vrc = pVMM->pfnSSMR3GetU32(pSSM, &fRequestor);
|
---|
| 1685 | AssertLogRelMsgRCReturnStmt(vrc, ("vrc=%Rrc, %s\n", vrc, szServiceName), pSvc->ReleaseService(), vrc);
|
---|
[1681] | 1686 |
|
---|
| 1687 | /* Connect the client. */
|
---|
[94937] | 1688 | vrc = pSvc->CreateAndConnectClient(NULL, u32ClientId, fRequestor, true /*fRestoring*/);
|
---|
| 1689 | AssertLogRelMsgRCReturnStmt(vrc, ("vrc=%Rrc, %s\n", vrc, szServiceName), pSvc->ReleaseService(), vrc);
|
---|
[1] | 1690 |
|
---|
[1711] | 1691 | /* Call the service, so the operation is executed by the service thread. */
|
---|
[94937] | 1692 | vrc = pSvc->loadClientState(u32ClientId, pSSM, pVMM, uVersion);
|
---|
| 1693 | AssertLogRelMsgRCReturnStmt(vrc, ("vrc=%Rrc, %s\n", vrc, szServiceName), pSvc->ReleaseService(), vrc);
|
---|
[1] | 1694 | }
|
---|
| 1695 |
|
---|
[51092] | 1696 | pSvc->ReleaseService();
|
---|
[1] | 1697 | }
|
---|
| 1698 |
|
---|
[1711] | 1699 | return VINF_SUCCESS;
|
---|
[1] | 1700 | }
|
---|
| 1701 |
|
---|
[1681] | 1702 | /* Create a new client instance and connect it to the service.
|
---|
| 1703 | *
|
---|
| 1704 | * @param pu32ClientIdOut If not NULL, then the method must generate a new handle for the client.
|
---|
| 1705 | * If NULL, use the given 'u32ClientIdIn' handle.
|
---|
| 1706 | * @param u32ClientIdIn The handle for the client, when 'pu32ClientIdOut' is NULL.
|
---|
[75773] | 1707 | * @param fRequestor The requestor flags, VMMDEV_REQUESTOR_LEGACY if not available.
|
---|
| 1708 | * @param fRestoring Set if we're restoring a saved state.
|
---|
| 1709 | * @return VBox status code.
|
---|
[1681] | 1710 | */
|
---|
[75773] | 1711 | int HGCMService::CreateAndConnectClient(uint32_t *pu32ClientIdOut, uint32_t u32ClientIdIn, uint32_t fRequestor, bool fRestoring)
|
---|
[1681] | 1712 | {
|
---|
[75773] | 1713 | LogFlowFunc(("pu32ClientIdOut = %p, u32ClientIdIn = %d, fRequestor = %#x, fRestoring = %d\n",
|
---|
| 1714 | pu32ClientIdOut, u32ClientIdIn, fRequestor, fRestoring));
|
---|
[1711] | 1715 |
|
---|
[90238] | 1716 | /*
|
---|
| 1717 | * Categorize the client (compress VMMDEV_REQUESTOR_USR_MASK)
|
---|
| 1718 | * and check the respective client limit.
|
---|
| 1719 | */
|
---|
| 1720 | uint32_t idxClientCategory;
|
---|
| 1721 | if (fRequestor == VMMDEV_REQUESTOR_LEGACY)
|
---|
| 1722 | {
|
---|
| 1723 | idxClientCategory = m_fntable.idxLegacyClientCategory;
|
---|
| 1724 | AssertStmt(idxClientCategory < RT_ELEMENTS(m_acClients), idxClientCategory = HGCM_CLIENT_CATEGORY_KERNEL);
|
---|
| 1725 | }
|
---|
| 1726 | else
|
---|
| 1727 | switch (fRequestor & VMMDEV_REQUESTOR_USR_MASK)
|
---|
| 1728 | {
|
---|
| 1729 | case VMMDEV_REQUESTOR_USR_DRV:
|
---|
| 1730 | case VMMDEV_REQUESTOR_USR_DRV_OTHER:
|
---|
| 1731 | idxClientCategory = HGCM_CLIENT_CATEGORY_KERNEL;
|
---|
| 1732 | break;
|
---|
| 1733 | case VMMDEV_REQUESTOR_USR_ROOT:
|
---|
| 1734 | case VMMDEV_REQUESTOR_USR_SYSTEM:
|
---|
| 1735 | idxClientCategory = HGCM_CLIENT_CATEGORY_ROOT;
|
---|
| 1736 | break;
|
---|
| 1737 | default:
|
---|
| 1738 | idxClientCategory = HGCM_CLIENT_CATEGORY_USER;
|
---|
| 1739 | break;
|
---|
| 1740 | }
|
---|
| 1741 |
|
---|
| 1742 | if ( m_acClients[idxClientCategory] < m_fntable.acMaxClients[idxClientCategory]
|
---|
| 1743 | || fRestoring)
|
---|
| 1744 | { }
|
---|
| 1745 | else
|
---|
| 1746 | {
|
---|
| 1747 | LogRel2(("Too many concurrenct clients for HGCM service '%s': %u, max %u; category %u\n",
|
---|
| 1748 | m_pszSvcName, m_cClients, m_fntable.acMaxClients[idxClientCategory], idxClientCategory));
|
---|
| 1749 | STAM_REL_COUNTER_INC(&m_StatTooManyClients);
|
---|
| 1750 | return VERR_HGCM_TOO_MANY_CLIENTS;
|
---|
| 1751 | }
|
---|
| 1752 |
|
---|
[1711] | 1753 | /* Allocate a client information structure. */
|
---|
[90238] | 1754 | HGCMClient *pClient = new (std::nothrow) HGCMClient(fRequestor, idxClientCategory);
|
---|
[1] | 1755 |
|
---|
[1681] | 1756 | if (!pClient)
|
---|
| 1757 | {
|
---|
[55988] | 1758 | Log1WarningFunc(("Could not allocate HGCMClient!!!\n"));
|
---|
[1681] | 1759 | return VERR_NO_MEMORY;
|
---|
| 1760 | }
|
---|
| 1761 |
|
---|
| 1762 | uint32_t handle;
|
---|
[6985] | 1763 |
|
---|
[1681] | 1764 | if (pu32ClientIdOut != NULL)
|
---|
| 1765 | {
|
---|
[51092] | 1766 | handle = hgcmObjGenerateHandle(pClient);
|
---|
[1681] | 1767 | }
|
---|
| 1768 | else
|
---|
| 1769 | {
|
---|
[51092] | 1770 | handle = hgcmObjAssignHandle(pClient, u32ClientIdIn);
|
---|
[1681] | 1771 | }
|
---|
| 1772 |
|
---|
[1711] | 1773 | LogFlowFunc(("client id = %d\n", handle));
|
---|
| 1774 |
|
---|
[1681] | 1775 | AssertRelease(handle);
|
---|
| 1776 |
|
---|
[1711] | 1777 | /* Initialize the HGCM part of the client. */
|
---|
[94937] | 1778 | int vrc = pClient->Init(this);
|
---|
[1681] | 1779 |
|
---|
[94937] | 1780 | if (RT_SUCCESS(vrc))
|
---|
[1681] | 1781 | {
|
---|
[1711] | 1782 | /* Call the service. */
|
---|
[75541] | 1783 | HGCMMsgCore *pCoreMsg;
|
---|
[1711] | 1784 |
|
---|
[94937] | 1785 | vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_CONNECT, hgcmMessageAllocSvc);
|
---|
[1711] | 1786 |
|
---|
[94937] | 1787 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 1788 | {
|
---|
[75541] | 1789 | HGCMMsgSvcConnect *pMsg = (HGCMMsgSvcConnect *)pCoreMsg;
|
---|
[1711] | 1790 |
|
---|
| 1791 | pMsg->u32ClientId = handle;
|
---|
[75774] | 1792 | pMsg->fRequestor = fRequestor;
|
---|
| 1793 | pMsg->fRestoring = fRestoring;
|
---|
[1711] | 1794 |
|
---|
[94937] | 1795 | vrc = hgcmMsgSend(pMsg);
|
---|
[1711] | 1796 |
|
---|
[94937] | 1797 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 1798 | {
|
---|
| 1799 | /* Add the client Id to the array. */
|
---|
| 1800 | if (m_cClients == m_cClientsAllocated)
|
---|
| 1801 | {
|
---|
[70599] | 1802 | const uint32_t cDelta = 64;
|
---|
| 1803 |
|
---|
| 1804 | /* Guards against integer overflow on 32bit arch and also limits size of m_paClientIds array to 4GB*/
|
---|
| 1805 | if (m_cClientsAllocated < UINT32_MAX / sizeof(m_paClientIds[0]) - cDelta)
|
---|
| 1806 | {
|
---|
| 1807 | uint32_t *paClientIdsNew;
|
---|
| 1808 |
|
---|
[75541] | 1809 | paClientIdsNew = (uint32_t *)RTMemRealloc(m_paClientIds,
|
---|
| 1810 | (m_cClientsAllocated + cDelta) * sizeof(m_paClientIds[0]));
|
---|
[70599] | 1811 | Assert(paClientIdsNew);
|
---|
| 1812 |
|
---|
| 1813 | if (paClientIdsNew)
|
---|
| 1814 | {
|
---|
| 1815 | m_paClientIds = paClientIdsNew;
|
---|
| 1816 | m_cClientsAllocated += cDelta;
|
---|
| 1817 | }
|
---|
| 1818 | else
|
---|
| 1819 | {
|
---|
[94937] | 1820 | vrc = VERR_NO_MEMORY;
|
---|
[70599] | 1821 | }
|
---|
| 1822 | }
|
---|
| 1823 | else
|
---|
| 1824 | {
|
---|
[94937] | 1825 | vrc = VERR_NO_MEMORY;
|
---|
[70599] | 1826 | }
|
---|
[1711] | 1827 | }
|
---|
[6985] | 1828 |
|
---|
[94937] | 1829 | if (RT_SUCCESS(vrc))
|
---|
[90238] | 1830 | {
|
---|
| 1831 | m_paClientIds[m_cClients] = handle;
|
---|
| 1832 | m_cClients++;
|
---|
| 1833 | m_acClients[idxClientCategory]++;
|
---|
[90240] | 1834 | LogFunc(("idClient=%u m_cClients=%u m_acClients[%u]=%u %s\n",
|
---|
[90239] | 1835 | handle, m_cClients, idxClientCategory, m_acClients[idxClientCategory], m_pszSvcName));
|
---|
[90238] | 1836 | }
|
---|
[1711] | 1837 | }
|
---|
| 1838 | }
|
---|
[1681] | 1839 | }
|
---|
| 1840 |
|
---|
[94937] | 1841 | if (RT_SUCCESS(vrc))
|
---|
[1681] | 1842 | {
|
---|
| 1843 | if (pu32ClientIdOut != NULL)
|
---|
| 1844 | {
|
---|
| 1845 | *pu32ClientIdOut = handle;
|
---|
| 1846 | }
|
---|
[1711] | 1847 |
|
---|
[51092] | 1848 | ReferenceService();
|
---|
[91748] | 1849 |
|
---|
| 1850 | /* The guest may now use this client object. */
|
---|
| 1851 | pClient->makeAccessibleToGuest();
|
---|
[1681] | 1852 | }
|
---|
[90238] | 1853 | else
|
---|
| 1854 | {
|
---|
| 1855 | hgcmObjDeleteHandle(handle);
|
---|
| 1856 | }
|
---|
[6985] | 1857 |
|
---|
[94937] | 1858 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1859 | return vrc;
|
---|
[1681] | 1860 | }
|
---|
| 1861 |
|
---|
[90228] | 1862 | /**
|
---|
| 1863 | * Disconnect the client from the service and delete the client handle.
|
---|
[1711] | 1864 | *
|
---|
[90228] | 1865 | * @param u32ClientId The handle of the client.
|
---|
| 1866 | * @param fFromService Set if called by the service via
|
---|
[91100] | 1867 | * svcHlpDisconnectClient().
|
---|
| 1868 | * @param pClient The client disconnecting.
|
---|
[90228] | 1869 | * @return VBox status code.
|
---|
[1711] | 1870 | */
|
---|
[90228] | 1871 | int HGCMService::DisconnectClient(uint32_t u32ClientId, bool fFromService, HGCMClient *pClient)
|
---|
[1] | 1872 | {
|
---|
[91100] | 1873 | AssertPtr(pClient);
|
---|
[90228] | 1874 | LogFlowFunc(("client id = %d, fFromService = %d, pClient = %p\n", u32ClientId, fFromService, pClient));
|
---|
[1] | 1875 |
|
---|
[90228] | 1876 | /*
|
---|
| 1877 | * Destroy the client handle prior to the disconnecting to avoid creating
|
---|
| 1878 | * a race with other messages from the same client. See @bugref{10038}
|
---|
[90229] | 1879 | * for further details.
|
---|
[90228] | 1880 | */
|
---|
[90238] | 1881 | Assert(pClient->idxCategory < HGCM_CLIENT_CATEGORY_MAX);
|
---|
| 1882 | Assert(m_acClients[pClient->idxCategory] > 0);
|
---|
| 1883 |
|
---|
[90228] | 1884 | bool fReleaseService = false;
|
---|
[94937] | 1885 | int vrc = VERR_NOT_FOUND;
|
---|
[90228] | 1886 | for (uint32_t i = 0; i < m_cClients; i++)
|
---|
| 1887 | {
|
---|
| 1888 | if (m_paClientIds[i] == u32ClientId)
|
---|
| 1889 | {
|
---|
[90238] | 1890 | if (m_acClients[pClient->idxCategory] > 0)
|
---|
| 1891 | m_acClients[pClient->idxCategory]--;
|
---|
| 1892 |
|
---|
[90228] | 1893 | m_cClients--;
|
---|
| 1894 |
|
---|
| 1895 | if (m_cClients > i)
|
---|
| 1896 | memmove(&m_paClientIds[i], &m_paClientIds[i + 1], sizeof(m_paClientIds[0]) * (m_cClients - i));
|
---|
| 1897 |
|
---|
| 1898 | /* Delete the client handle. */
|
---|
| 1899 | hgcmObjDeleteHandle(u32ClientId);
|
---|
| 1900 | fReleaseService = true;
|
---|
| 1901 |
|
---|
[94937] | 1902 | vrc = VINF_SUCCESS;
|
---|
[90228] | 1903 | break;
|
---|
| 1904 | }
|
---|
| 1905 | }
|
---|
| 1906 |
|
---|
| 1907 | /* Some paranoia wrt to not trusting the client ID array. */
|
---|
[94937] | 1908 | Assert(vrc == VINF_SUCCESS || fFromService);
|
---|
| 1909 | if (vrc == VERR_NOT_FOUND && !fFromService)
|
---|
[90228] | 1910 | {
|
---|
[90238] | 1911 | if (m_acClients[pClient->idxCategory] > 0)
|
---|
| 1912 | m_acClients[pClient->idxCategory]--;
|
---|
| 1913 |
|
---|
[90228] | 1914 | hgcmObjDeleteHandle(u32ClientId);
|
---|
| 1915 | fReleaseService = true;
|
---|
| 1916 | }
|
---|
| 1917 |
|
---|
[98278] | 1918 | LogFunc(("idClient=%u m_cClients=%u m_acClients[%u]=%u %s (cPendingCalls=%u) vrc=%Rrc\n", u32ClientId, m_cClients,
|
---|
[94937] | 1919 | pClient->idxCategory, m_acClients[pClient->idxCategory], m_pszSvcName, pClient->cPendingCalls, vrc));
|
---|
[90238] | 1920 |
|
---|
[90228] | 1921 | /*
|
---|
| 1922 | * Call the service.
|
---|
| 1923 | */
|
---|
[6981] | 1924 | if (!fFromService)
|
---|
[1] | 1925 | {
|
---|
[6981] | 1926 | /* Call the service. */
|
---|
[75541] | 1927 | HGCMMsgCore *pCoreMsg;
|
---|
[1] | 1928 |
|
---|
[94937] | 1929 | vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_DISCONNECT, hgcmMessageAllocSvc);
|
---|
[1] | 1930 |
|
---|
[94937] | 1931 | if (RT_SUCCESS(vrc))
|
---|
[6981] | 1932 | {
|
---|
[75541] | 1933 | HGCMMsgSvcDisconnect *pMsg = (HGCMMsgSvcDisconnect *)pCoreMsg;
|
---|
[1] | 1934 |
|
---|
[6981] | 1935 | pMsg->u32ClientId = u32ClientId;
|
---|
[90228] | 1936 | pMsg->pClient = pClient;
|
---|
[6967] | 1937 |
|
---|
[94937] | 1938 | vrc = hgcmMsgSend(pMsg);
|
---|
[6981] | 1939 | }
|
---|
[22732] | 1940 | else
|
---|
| 1941 | {
|
---|
[22814] | 1942 | LogRel(("(%d, %d) [%s] hgcmMsgAlloc(%p, SVC_MSG_DISCONNECT) failed %Rrc\n",
|
---|
[94937] | 1943 | u32ClientId, fFromService, RT_VALID_PTR(m_pszSvcName)? m_pszSvcName: "", m_pThread, vrc));
|
---|
[22732] | 1944 | }
|
---|
[6981] | 1945 | }
|
---|
| 1946 |
|
---|
[22732] | 1947 |
|
---|
[90228] | 1948 | /*
|
---|
| 1949 | * Release the pClient->pService reference.
|
---|
| 1950 | */
|
---|
| 1951 | if (fReleaseService)
|
---|
| 1952 | ReleaseService();
|
---|
[1711] | 1953 |
|
---|
[94937] | 1954 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1955 | return vrc;
|
---|
[1] | 1956 | }
|
---|
| 1957 |
|
---|
[51092] | 1958 | int HGCMService::RegisterExtension(HGCMSVCEXTHANDLE handle,
|
---|
| 1959 | PFNHGCMSVCEXT pfnExtension,
|
---|
| 1960 | void *pvExtension)
|
---|
[2386] | 1961 | {
|
---|
| 1962 | LogFlowFunc(("%s\n", handle->pszServiceName));
|
---|
| 1963 |
|
---|
| 1964 | /* Forward the message to the service thread. */
|
---|
[75541] | 1965 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 1966 | int vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_REGEXT, hgcmMessageAllocSvc);
|
---|
[2386] | 1967 |
|
---|
[94937] | 1968 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 1969 | {
|
---|
[75541] | 1970 | HGCMMsgSvcRegisterExtension *pMsg = (HGCMMsgSvcRegisterExtension *)pCoreMsg;
|
---|
[2386] | 1971 |
|
---|
| 1972 | pMsg->handle = handle;
|
---|
| 1973 | pMsg->pfnExtension = pfnExtension;
|
---|
| 1974 | pMsg->pvExtension = pvExtension;
|
---|
| 1975 |
|
---|
[94937] | 1976 | vrc = hgcmMsgSend(pMsg);
|
---|
[2386] | 1977 | }
|
---|
| 1978 |
|
---|
[94937] | 1979 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 1980 | return vrc;
|
---|
[2386] | 1981 | }
|
---|
| 1982 |
|
---|
[51092] | 1983 | void HGCMService::UnregisterExtension(HGCMSVCEXTHANDLE handle)
|
---|
[2386] | 1984 | {
|
---|
| 1985 | /* Forward the message to the service thread. */
|
---|
[75541] | 1986 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 1987 | int vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_UNREGEXT, hgcmMessageAllocSvc);
|
---|
[2386] | 1988 |
|
---|
[94937] | 1989 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 1990 | {
|
---|
[75541] | 1991 | HGCMMsgSvcUnregisterExtension *pMsg = (HGCMMsgSvcUnregisterExtension *)pCoreMsg;
|
---|
[2386] | 1992 |
|
---|
| 1993 | pMsg->handle = handle;
|
---|
| 1994 |
|
---|
[94937] | 1995 | vrc = hgcmMsgSend(pMsg);
|
---|
[2386] | 1996 | }
|
---|
| 1997 |
|
---|
[94937] | 1998 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
[2386] | 1999 | }
|
---|
| 2000 |
|
---|
[90238] | 2001 | /** @callback_method_impl{FNHGCMMSGCALLBACK} */
|
---|
| 2002 | static DECLCALLBACK(int) hgcmMsgCallCompletionCallback(int32_t result, HGCMMsgCore *pMsgCore)
|
---|
| 2003 | {
|
---|
| 2004 | /*
|
---|
| 2005 | * Do common message completion then decrement the call counter
|
---|
| 2006 | * for the client if necessary.
|
---|
| 2007 | */
|
---|
[94937] | 2008 | int vrc = hgcmMsgCompletionCallback(result, pMsgCore);
|
---|
[90238] | 2009 |
|
---|
| 2010 | HGCMMsgCall *pMsg = (HGCMMsgCall *)pMsgCore;
|
---|
| 2011 | if (pMsg->pcCounter)
|
---|
| 2012 | {
|
---|
| 2013 | uint32_t cCalls = ASMAtomicDecU32(pMsg->pcCounter);
|
---|
| 2014 | AssertStmt(cCalls < UINT32_MAX / 2, ASMAtomicWriteU32(pMsg->pcCounter, 0));
|
---|
| 2015 | pMsg->pcCounter = NULL;
|
---|
| 2016 | Log3Func(("pMsg=%p cPendingCalls=%u / %u (fun %u, %u parms)\n",
|
---|
| 2017 | pMsg, cCalls, pMsg->u32ClientId, pMsg->u32Function, pMsg->cParms));
|
---|
| 2018 | }
|
---|
| 2019 |
|
---|
[94937] | 2020 | return vrc;
|
---|
[90238] | 2021 | }
|
---|
| 2022 |
|
---|
[75541] | 2023 | /** Perform a guest call to the service.
|
---|
[1711] | 2024 | *
|
---|
| 2025 | * @param pHGCMPort The port to be used for completion confirmation.
|
---|
| 2026 | * @param pCmd The VBox HGCM context.
|
---|
| 2027 | * @param u32ClientId The client handle to be disconnected and deleted.
|
---|
[90238] | 2028 | * @param pClient The client data.
|
---|
[1711] | 2029 | * @param u32Function The function number.
|
---|
| 2030 | * @param cParms Number of parameters.
|
---|
| 2031 | * @param paParms Pointer to array of parameters.
|
---|
[75500] | 2032 | * @param tsArrival The STAM_GET_TS() value when the request arrived.
|
---|
[98278] | 2033 | * @return VBox status code.
|
---|
[75541] | 2034 | * @retval VINF_HGCM_ASYNC_EXECUTE on success.
|
---|
[1] | 2035 | */
|
---|
[90238] | 2036 | int HGCMService::GuestCall(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t u32ClientId, HGCMClient *pClient,
|
---|
| 2037 | uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival)
|
---|
[1] | 2038 | {
|
---|
[75990] | 2039 | LogFlow(("MAIN::HGCMService::GuestCall\n"));
|
---|
[1] | 2040 |
|
---|
[94937] | 2041 | int vrc;
|
---|
[90238] | 2042 | HGCMMsgCall *pMsg = new(std::nothrow) HGCMMsgCall(m_pThread);
|
---|
[75541] | 2043 | if (pMsg)
|
---|
[1] | 2044 | {
|
---|
[75990] | 2045 | pMsg->Reference(); /** @todo starts out with zero references. */
|
---|
[1] | 2046 |
|
---|
[90238] | 2047 | uint32_t cCalls = ASMAtomicIncU32(&pClient->cPendingCalls);
|
---|
| 2048 | Assert(pClient->idxCategory < RT_ELEMENTS(m_fntable.acMaxCallsPerClient));
|
---|
| 2049 | if (cCalls < m_fntable.acMaxCallsPerClient[pClient->idxCategory])
|
---|
| 2050 | {
|
---|
| 2051 | pMsg->pcCounter = &pClient->cPendingCalls;
|
---|
| 2052 | Log3(("MAIN::HGCMService::GuestCall: pMsg=%p cPendingCalls=%u / %u / %s (fun %u, %u parms)\n",
|
---|
| 2053 | pMsg, cCalls, u32ClientId, m_pszSvcName, u32Function, cParms));
|
---|
[1] | 2054 |
|
---|
[90238] | 2055 | pMsg->pCmd = pCmd;
|
---|
| 2056 | pMsg->pHGCMPort = pHGCMPort;
|
---|
| 2057 | pMsg->u32ClientId = u32ClientId;
|
---|
| 2058 | pMsg->u32Function = u32Function;
|
---|
| 2059 | pMsg->cParms = cParms;
|
---|
| 2060 | pMsg->paParms = paParms;
|
---|
| 2061 | pMsg->tsArrival = tsArrival;
|
---|
| 2062 |
|
---|
[94937] | 2063 | vrc = hgcmMsgPost(pMsg, hgcmMsgCallCompletionCallback);
|
---|
[90238] | 2064 |
|
---|
[94937] | 2065 | if (RT_SUCCESS(vrc))
|
---|
[90238] | 2066 | { /* Reference donated on success. */ }
|
---|
| 2067 | else
|
---|
| 2068 | {
|
---|
| 2069 | ASMAtomicDecU32(&pClient->cPendingCalls);
|
---|
| 2070 | pMsg->pcCounter = NULL;
|
---|
[94937] | 2071 | Log(("MAIN::HGCMService::GuestCall: hgcmMsgPost failed: %Rrc\n", vrc));
|
---|
[90238] | 2072 | pMsg->Dereference();
|
---|
| 2073 | }
|
---|
| 2074 | }
|
---|
| 2075 | else
|
---|
| 2076 | {
|
---|
| 2077 | ASMAtomicDecU32(&pClient->cPendingCalls);
|
---|
| 2078 | LogRel2(("HGCM: Too many calls to '%s' from client %u: %u, max %u; category %u\n", m_pszSvcName, u32ClientId,
|
---|
| 2079 | cCalls, m_fntable.acMaxCallsPerClient[pClient->idxCategory], pClient->idxCategory));
|
---|
| 2080 | pMsg->Dereference();
|
---|
| 2081 | STAM_REL_COUNTER_INC(&m_StatTooManyCalls);
|
---|
[94937] | 2082 | vrc = VERR_HGCM_TOO_MANY_CLIENT_CALLS;
|
---|
[90238] | 2083 | }
|
---|
[1] | 2084 | }
|
---|
| 2085 | else
|
---|
| 2086 | {
|
---|
[75990] | 2087 | Log(("MAIN::HGCMService::GuestCall: Message allocation failed\n"));
|
---|
[94937] | 2088 | vrc = VERR_NO_MEMORY;
|
---|
[1] | 2089 | }
|
---|
| 2090 |
|
---|
[94937] | 2091 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2092 | return vrc;
|
---|
[1] | 2093 | }
|
---|
| 2094 |
|
---|
[75990] | 2095 | /** Guest cancelled a request (call, connection attempt, disconnect attempt).
|
---|
| 2096 | *
|
---|
[90238] | 2097 | * @param pHGCMPort The port to be used for completion confirmation
|
---|
[75990] | 2098 | * @param pCmd The VBox HGCM context.
|
---|
[76013] | 2099 | * @param idClient The client handle to be disconnected and deleted.
|
---|
[75990] | 2100 | */
|
---|
| 2101 | void HGCMService::GuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t idClient)
|
---|
| 2102 | {
|
---|
| 2103 | LogFlow(("MAIN::HGCMService::GuestCancelled\n"));
|
---|
| 2104 |
|
---|
| 2105 | if (m_fntable.pfnCancelled)
|
---|
| 2106 | {
|
---|
| 2107 | HGCMMsgCancelled *pMsg = new (std::nothrow) HGCMMsgCancelled(m_pThread);
|
---|
| 2108 | if (pMsg)
|
---|
| 2109 | {
|
---|
| 2110 | pMsg->Reference(); /** @todo starts out with zero references. */
|
---|
| 2111 |
|
---|
| 2112 | pMsg->pCmd = pCmd;
|
---|
| 2113 | pMsg->pHGCMPort = pHGCMPort;
|
---|
| 2114 | pMsg->idClient = idClient;
|
---|
| 2115 |
|
---|
| 2116 | hgcmMsgPost(pMsg, NULL);
|
---|
| 2117 | }
|
---|
| 2118 | else
|
---|
| 2119 | Log(("MAIN::HGCMService::GuestCancelled: Message allocation failed\n"));
|
---|
| 2120 | }
|
---|
| 2121 | }
|
---|
| 2122 |
|
---|
[75541] | 2123 | /** Perform a host call the service.
|
---|
[1711] | 2124 | *
|
---|
| 2125 | * @param u32Function The function number.
|
---|
| 2126 | * @param cParms Number of parameters.
|
---|
| 2127 | * @param paParms Pointer to array of parameters.
|
---|
[98278] | 2128 | * @return VBox status code.
|
---|
[1] | 2129 | */
|
---|
[51092] | 2130 | int HGCMService::HostCall(uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM *paParms)
|
---|
[1] | 2131 | {
|
---|
[1711] | 2132 | LogFlowFunc(("%s u32Function = %d, cParms = %d, paParms = %p\n",
|
---|
| 2133 | m_pszSvcName, u32Function, cParms, paParms));
|
---|
| 2134 |
|
---|
[75541] | 2135 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2136 | int vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_HOSTCALL, hgcmMessageAllocSvc);
|
---|
[1] | 2137 |
|
---|
[94937] | 2138 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2139 | {
|
---|
[75541] | 2140 | HGCMMsgHostCallSvc *pMsg = (HGCMMsgHostCallSvc *)pCoreMsg;
|
---|
[1] | 2141 |
|
---|
| 2142 | pMsg->u32Function = u32Function;
|
---|
| 2143 | pMsg->cParms = cParms;
|
---|
| 2144 | pMsg->paParms = paParms;
|
---|
| 2145 |
|
---|
[94937] | 2146 | vrc = hgcmMsgSend(pMsg);
|
---|
[1] | 2147 | }
|
---|
| 2148 |
|
---|
[94937] | 2149 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2150 | return vrc;
|
---|
[1] | 2151 | }
|
---|
| 2152 |
|
---|
[75969] | 2153 | /** Posts a broadcast notification event to all interested services.
|
---|
| 2154 | *
|
---|
| 2155 | * @param enmEvent The notification event.
|
---|
| 2156 | */
|
---|
| 2157 | /*static*/ void HGCMService::BroadcastNotify(HGCMNOTIFYEVENT enmEvent)
|
---|
| 2158 | {
|
---|
| 2159 | for (HGCMService *pService = sm_pSvcListHead; pService != NULL; pService = pService->m_pSvcNext)
|
---|
| 2160 | {
|
---|
| 2161 | pService->Notify(enmEvent);
|
---|
| 2162 | }
|
---|
| 2163 | }
|
---|
| 2164 |
|
---|
| 2165 | /** Posts a broadcast notification event to the service.
|
---|
| 2166 | *
|
---|
| 2167 | * @param enmEvent The notification event.
|
---|
| 2168 | */
|
---|
| 2169 | void HGCMService::Notify(HGCMNOTIFYEVENT enmEvent)
|
---|
| 2170 | {
|
---|
| 2171 | LogFlowFunc(("%s enmEvent=%d pfnNotify=%p\n", m_pszSvcName, enmEvent, m_fntable.pfnNotify));
|
---|
| 2172 | if (m_fntable.pfnNotify)
|
---|
| 2173 | {
|
---|
| 2174 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2175 | int vrc = hgcmMsgAlloc(m_pThread, &pCoreMsg, SVC_MSG_NOTIFY, hgcmMessageAllocSvc);
|
---|
| 2176 | if (RT_SUCCESS(vrc))
|
---|
[75969] | 2177 | {
|
---|
| 2178 | HGCMMsgNotify *pMsg = (HGCMMsgNotify *)pCoreMsg;
|
---|
| 2179 | pMsg->enmEvent = enmEvent;
|
---|
| 2180 |
|
---|
[94937] | 2181 | vrc = hgcmMsgPost(pMsg, NULL);
|
---|
| 2182 | AssertRC(vrc);
|
---|
[75969] | 2183 | }
|
---|
| 2184 | }
|
---|
| 2185 | }
|
---|
| 2186 |
|
---|
[6985] | 2187 | /*
|
---|
[1711] | 2188 | * Main HGCM thread that manages services.
|
---|
| 2189 | */
|
---|
[6985] | 2190 |
|
---|
[1711] | 2191 | /* Messages processed by the main HGCM thread. */
|
---|
[75969] | 2192 | #define HGCM_MSG_CONNECT (10) /**< Connect a client to a service. */
|
---|
| 2193 | #define HGCM_MSG_DISCONNECT (11) /**< Disconnect the specified client id. */
|
---|
| 2194 | #define HGCM_MSG_LOAD (12) /**< Load the service. */
|
---|
| 2195 | #define HGCM_MSG_HOSTCALL (13) /**< Call the service. */
|
---|
| 2196 | #define HGCM_MSG_LOADSTATE (14) /**< Load saved state for the specified service. */
|
---|
| 2197 | #define HGCM_MSG_SAVESTATE (15) /**< Save state for the specified service. */
|
---|
| 2198 | #define HGCM_MSG_RESET (16) /**< Disconnect all clients from the specified service. */
|
---|
| 2199 | #define HGCM_MSG_QUIT (17) /**< Unload all services and terminate the thread. */
|
---|
| 2200 | #define HGCM_MSG_REGEXT (18) /**< Register a service extension. */
|
---|
| 2201 | #define HGCM_MSG_UNREGEXT (19) /**< Unregister a service extension. */
|
---|
| 2202 | #define HGCM_MSG_BRD_NOTIFY (20) /**< Broadcast notification event (VM state change). */
|
---|
[1080] | 2203 |
|
---|
[1711] | 2204 | class HGCMMsgMainConnect: public HGCMMsgHeader
|
---|
| 2205 | {
|
---|
| 2206 | public:
|
---|
| 2207 | /* Service name. */
|
---|
| 2208 | const char *pszServiceName;
|
---|
| 2209 | /* Where to store the client handle. */
|
---|
| 2210 | uint32_t *pu32ClientId;
|
---|
| 2211 | };
|
---|
[1080] | 2212 |
|
---|
[1711] | 2213 | class HGCMMsgMainDisconnect: public HGCMMsgHeader
|
---|
| 2214 | {
|
---|
| 2215 | public:
|
---|
| 2216 | /* Handle of the client to be disconnected. */
|
---|
| 2217 | uint32_t u32ClientId;
|
---|
| 2218 | };
|
---|
[1080] | 2219 |
|
---|
[1711] | 2220 | class HGCMMsgMainLoad: public HGCMMsgCore
|
---|
| 2221 | {
|
---|
| 2222 | public:
|
---|
| 2223 | /* Name of the library to be loaded. */
|
---|
| 2224 | const char *pszServiceLibrary;
|
---|
| 2225 | /* Name to be assigned to the service. */
|
---|
| 2226 | const char *pszServiceName;
|
---|
[75495] | 2227 | /** The user mode VM handle (for statistics and such). */
|
---|
| 2228 | PUVM pUVM;
|
---|
[93444] | 2229 | /** The VMM vtable (for statistics and such). */
|
---|
| 2230 | PCVMMR3VTABLE pVMM;
|
---|
[75853] | 2231 | /** The HGCM port on the VMMDev device (for session ID and such). */
|
---|
| 2232 | PPDMIHGCMPORT pHgcmPort;
|
---|
[1711] | 2233 | };
|
---|
[1080] | 2234 |
|
---|
[1711] | 2235 | class HGCMMsgMainHostCall: public HGCMMsgCore
|
---|
| 2236 | {
|
---|
| 2237 | public:
|
---|
| 2238 | /* Which service to call. */
|
---|
| 2239 | const char *pszServiceName;
|
---|
| 2240 | /* Function number. */
|
---|
| 2241 | uint32_t u32Function;
|
---|
| 2242 | /* Number of the function parameters. */
|
---|
| 2243 | uint32_t cParms;
|
---|
| 2244 | /* Pointer to array of the function parameters. */
|
---|
| 2245 | VBOXHGCMSVCPARM *paParms;
|
---|
| 2246 | };
|
---|
[1080] | 2247 |
|
---|
[1711] | 2248 | class HGCMMsgMainLoadSaveState: public HGCMMsgCore
|
---|
| 2249 | {
|
---|
| 2250 | public:
|
---|
[75853] | 2251 | /** Saved state handle. */
|
---|
[1711] | 2252 | PSSMHANDLE pSSM;
|
---|
[93444] | 2253 | /** The VMM vtable. */
|
---|
| 2254 | PCVMMR3VTABLE pVMM;
|
---|
[75853] | 2255 | /** The HGCM saved state version being loaded (ignore for save). */
|
---|
| 2256 | uint32_t uVersion;
|
---|
[1711] | 2257 | };
|
---|
[1080] | 2258 |
|
---|
[1711] | 2259 | class HGCMMsgMainReset: public HGCMMsgCore
|
---|
| 2260 | {
|
---|
[75991] | 2261 | public:
|
---|
| 2262 | /** Set if this is actually a shutdown and not a VM reset. */
|
---|
| 2263 | bool fForShutdown;
|
---|
[1711] | 2264 | };
|
---|
[1080] | 2265 |
|
---|
[1711] | 2266 | class HGCMMsgMainQuit: public HGCMMsgCore
|
---|
| 2267 | {
|
---|
[75574] | 2268 | public:
|
---|
| 2269 | /** Whether UVM has gone invalid already or not. */
|
---|
| 2270 | bool fUvmIsInvalid;
|
---|
[1711] | 2271 | };
|
---|
[1080] | 2272 |
|
---|
[2386] | 2273 | class HGCMMsgMainRegisterExtension: public HGCMMsgCore
|
---|
| 2274 | {
|
---|
| 2275 | public:
|
---|
[75574] | 2276 | /** Returned handle to be used in HGCMMsgMainUnregisterExtension. */
|
---|
[2386] | 2277 | HGCMSVCEXTHANDLE *pHandle;
|
---|
[75574] | 2278 | /** Name of the service. */
|
---|
[2386] | 2279 | const char *pszServiceName;
|
---|
[75574] | 2280 | /** The extension entry point. */
|
---|
[2386] | 2281 | PFNHGCMSVCEXT pfnExtension;
|
---|
[75574] | 2282 | /** The extension pointer. */
|
---|
[2386] | 2283 | void *pvExtension;
|
---|
| 2284 | };
|
---|
| 2285 |
|
---|
| 2286 | class HGCMMsgMainUnregisterExtension: public HGCMMsgCore
|
---|
| 2287 | {
|
---|
| 2288 | public:
|
---|
| 2289 | /* Handle of the registered extension. */
|
---|
| 2290 | HGCMSVCEXTHANDLE handle;
|
---|
| 2291 | };
|
---|
| 2292 |
|
---|
[75969] | 2293 | class HGCMMsgMainBroadcastNotify: public HGCMMsgCore
|
---|
| 2294 | {
|
---|
| 2295 | public:
|
---|
| 2296 | /** The notification event. */
|
---|
| 2297 | HGCMNOTIFYEVENT enmEvent;
|
---|
| 2298 | };
|
---|
| 2299 |
|
---|
[33146] | 2300 |
|
---|
[1711] | 2301 | static HGCMMsgCore *hgcmMainMessageAlloc (uint32_t u32MsgId)
|
---|
[1080] | 2302 | {
|
---|
[1711] | 2303 | switch (u32MsgId)
|
---|
[1080] | 2304 | {
|
---|
[51092] | 2305 | case HGCM_MSG_CONNECT: return new HGCMMsgMainConnect();
|
---|
| 2306 | case HGCM_MSG_DISCONNECT: return new HGCMMsgMainDisconnect();
|
---|
| 2307 | case HGCM_MSG_LOAD: return new HGCMMsgMainLoad();
|
---|
| 2308 | case HGCM_MSG_HOSTCALL: return new HGCMMsgMainHostCall();
|
---|
[6985] | 2309 | case HGCM_MSG_LOADSTATE:
|
---|
[51092] | 2310 | case HGCM_MSG_SAVESTATE: return new HGCMMsgMainLoadSaveState();
|
---|
| 2311 | case HGCM_MSG_RESET: return new HGCMMsgMainReset();
|
---|
| 2312 | case HGCM_MSG_QUIT: return new HGCMMsgMainQuit();
|
---|
| 2313 | case HGCM_MSG_REGEXT: return new HGCMMsgMainRegisterExtension();
|
---|
| 2314 | case HGCM_MSG_UNREGEXT: return new HGCMMsgMainUnregisterExtension();
|
---|
[75969] | 2315 | case HGCM_MSG_BRD_NOTIFY: return new HGCMMsgMainBroadcastNotify();
|
---|
[33146] | 2316 |
|
---|
[1711] | 2317 | default:
|
---|
| 2318 | AssertReleaseMsgFailed(("Msg id = %08X\n", u32MsgId));
|
---|
[1080] | 2319 | }
|
---|
| 2320 |
|
---|
[1711] | 2321 | return NULL;
|
---|
[1080] | 2322 | }
|
---|
| 2323 |
|
---|
[1711] | 2324 |
|
---|
| 2325 | /* The main HGCM thread handler. */
|
---|
[75539] | 2326 | static DECLCALLBACK(void) hgcmThread(HGCMThread *pThread, void *pvUser)
|
---|
[1] | 2327 | {
|
---|
[75539] | 2328 | LogFlowFunc(("pThread = %p, pvUser = %p\n", pThread, pvUser));
|
---|
[1711] | 2329 |
|
---|
[1] | 2330 | NOREF(pvUser);
|
---|
| 2331 |
|
---|
[1711] | 2332 | bool fQuit = false;
|
---|
[1] | 2333 |
|
---|
[1711] | 2334 | while (!fQuit)
|
---|
[1] | 2335 | {
|
---|
[1711] | 2336 | HGCMMsgCore *pMsgCore;
|
---|
[94937] | 2337 | int vrc = hgcmMsgGet(pThread, &pMsgCore);
|
---|
[1] | 2338 |
|
---|
[94937] | 2339 | if (RT_FAILURE(vrc))
|
---|
[1] | 2340 | {
|
---|
[1711] | 2341 | /* The error means some serious unrecoverable problem in the hgcmMsg/hgcmThread layer. */
|
---|
[94937] | 2342 | AssertMsgFailed(("%Rrc\n", vrc));
|
---|
[1711] | 2343 | break;
|
---|
[1] | 2344 | }
|
---|
| 2345 |
|
---|
[51092] | 2346 | uint32_t u32MsgId = pMsgCore->MsgId();
|
---|
[1577] | 2347 |
|
---|
| 2348 | switch (u32MsgId)
|
---|
[1] | 2349 | {
|
---|
[1711] | 2350 | case HGCM_MSG_CONNECT:
|
---|
[1] | 2351 | {
|
---|
[1711] | 2352 | HGCMMsgMainConnect *pMsg = (HGCMMsgMainConnect *)pMsgCore;
|
---|
[1] | 2353 |
|
---|
[1711] | 2354 | LogFlowFunc(("HGCM_MSG_CONNECT pszServiceName %s, pu32ClientId %p\n",
|
---|
| 2355 | pMsg->pszServiceName, pMsg->pu32ClientId));
|
---|
[1] | 2356 |
|
---|
[1711] | 2357 | /* Resolve the service name to the pointer to service instance.
|
---|
[1] | 2358 | */
|
---|
[1711] | 2359 | HGCMService *pService;
|
---|
[94937] | 2360 | vrc = HGCMService::ResolveService(&pService, pMsg->pszServiceName);
|
---|
[1] | 2361 |
|
---|
[94937] | 2362 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2363 | {
|
---|
[1711] | 2364 | /* Call the service instance method. */
|
---|
[94937] | 2365 | vrc = pService->CreateAndConnectClient(pMsg->pu32ClientId,
|
---|
| 2366 | 0,
|
---|
| 2367 | pMsg->pHGCMPort->pfnGetRequestor(pMsg->pHGCMPort, pMsg->pCmd),
|
---|
| 2368 | pMsg->pHGCMPort->pfnIsCmdRestored(pMsg->pHGCMPort, pMsg->pCmd));
|
---|
[1] | 2369 |
|
---|
[1711] | 2370 | /* Release the service after resolve. */
|
---|
[51092] | 2371 | pService->ReleaseService();
|
---|
[1] | 2372 | }
|
---|
| 2373 | } break;
|
---|
| 2374 |
|
---|
[1711] | 2375 | case HGCM_MSG_DISCONNECT:
|
---|
[1] | 2376 | {
|
---|
[1711] | 2377 | HGCMMsgMainDisconnect *pMsg = (HGCMMsgMainDisconnect *)pMsgCore;
|
---|
[1] | 2378 |
|
---|
[1711] | 2379 | LogFlowFunc(("HGCM_MSG_DISCONNECT u32ClientId = %d\n",
|
---|
| 2380 | pMsg->u32ClientId));
|
---|
[1] | 2381 |
|
---|
[91748] | 2382 | HGCMClient *pClient = HGCMClient::ReferenceByHandle(pMsg->u32ClientId);
|
---|
[1] | 2383 |
|
---|
| 2384 | if (!pClient)
|
---|
| 2385 | {
|
---|
[94937] | 2386 | vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1711] | 2387 | break;
|
---|
[1] | 2388 | }
|
---|
| 2389 |
|
---|
[1711] | 2390 | /* The service the client belongs to. */
|
---|
| 2391 | HGCMService *pService = pClient->pService;
|
---|
[1] | 2392 |
|
---|
[1711] | 2393 | /* Call the service instance to disconnect the client. */
|
---|
[94937] | 2394 | vrc = pService->DisconnectClient(pMsg->u32ClientId, false, pClient);
|
---|
[1] | 2395 |
|
---|
[51092] | 2396 | hgcmObjDereference(pClient);
|
---|
[1] | 2397 | } break;
|
---|
| 2398 |
|
---|
[1711] | 2399 | case HGCM_MSG_LOAD:
|
---|
[1] | 2400 | {
|
---|
[1711] | 2401 | HGCMMsgMainLoad *pMsg = (HGCMMsgMainLoad *)pMsgCore;
|
---|
[1] | 2402 |
|
---|
[75495] | 2403 | LogFlowFunc(("HGCM_MSG_LOAD pszServiceName = %s, pMsg->pszServiceLibrary = %s, pMsg->pUVM = %p\n",
|
---|
| 2404 | pMsg->pszServiceName, pMsg->pszServiceLibrary, pMsg->pUVM));
|
---|
[1] | 2405 |
|
---|
[94937] | 2406 | vrc = HGCMService::LoadService(pMsg->pszServiceLibrary, pMsg->pszServiceName,
|
---|
| 2407 | pMsg->pUVM, pMsg->pVMM, pMsg->pHgcmPort);
|
---|
[1] | 2408 | } break;
|
---|
| 2409 |
|
---|
[1711] | 2410 | case HGCM_MSG_HOSTCALL:
|
---|
[1] | 2411 | {
|
---|
[1711] | 2412 | HGCMMsgMainHostCall *pMsg = (HGCMMsgMainHostCall *)pMsgCore;
|
---|
[1] | 2413 |
|
---|
[1711] | 2414 | LogFlowFunc(("HGCM_MSG_HOSTCALL pszServiceName %s, u32Function %d, cParms %d, paParms %p\n",
|
---|
| 2415 | pMsg->pszServiceName, pMsg->u32Function, pMsg->cParms, pMsg->paParms));
|
---|
[1] | 2416 |
|
---|
[1711] | 2417 | /* Resolve the service name to the pointer to service instance. */
|
---|
| 2418 | HGCMService *pService;
|
---|
[94937] | 2419 | vrc = HGCMService::ResolveService(&pService, pMsg->pszServiceName);
|
---|
[1] | 2420 |
|
---|
[94937] | 2421 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2422 | {
|
---|
[94937] | 2423 | vrc = pService->HostCall(pMsg->u32Function, pMsg->cParms, pMsg->paParms);
|
---|
[1711] | 2424 |
|
---|
[51092] | 2425 | pService->ReleaseService();
|
---|
[1] | 2426 | }
|
---|
| 2427 | } break;
|
---|
[909] | 2428 |
|
---|
[75969] | 2429 | case HGCM_MSG_BRD_NOTIFY:
|
---|
| 2430 | {
|
---|
| 2431 | HGCMMsgMainBroadcastNotify *pMsg = (HGCMMsgMainBroadcastNotify *)pMsgCore;
|
---|
| 2432 |
|
---|
| 2433 | LogFlowFunc(("HGCM_MSG_BRD_NOTIFY enmEvent=%d\n", pMsg->enmEvent));
|
---|
| 2434 |
|
---|
| 2435 | HGCMService::BroadcastNotify(pMsg->enmEvent);
|
---|
| 2436 | } break;
|
---|
| 2437 |
|
---|
[1711] | 2438 | case HGCM_MSG_RESET:
|
---|
[1385] | 2439 | {
|
---|
[1711] | 2440 | LogFlowFunc(("HGCM_MSG_RESET\n"));
|
---|
[1385] | 2441 |
|
---|
[51092] | 2442 | HGCMService::Reset();
|
---|
[75969] | 2443 |
|
---|
[75991] | 2444 | HGCMMsgMainReset *pMsg = (HGCMMsgMainReset *)pMsgCore;
|
---|
| 2445 | if (!pMsg->fForShutdown)
|
---|
| 2446 | HGCMService::BroadcastNotify(HGCMNOTIFYEVENT_RESET);
|
---|
[1385] | 2447 | } break;
|
---|
| 2448 |
|
---|
[1711] | 2449 | case HGCM_MSG_LOADSTATE:
|
---|
[1681] | 2450 | {
|
---|
[1711] | 2451 | HGCMMsgMainLoadSaveState *pMsg = (HGCMMsgMainLoadSaveState *)pMsgCore;
|
---|
[1681] | 2452 |
|
---|
[1711] | 2453 | LogFlowFunc(("HGCM_MSG_LOADSTATE\n"));
|
---|
[1681] | 2454 |
|
---|
[94937] | 2455 | vrc = HGCMService::LoadState(pMsg->pSSM, pMsg->pVMM, pMsg->uVersion);
|
---|
[1681] | 2456 | } break;
|
---|
| 2457 |
|
---|
[1711] | 2458 | case HGCM_MSG_SAVESTATE:
|
---|
[1681] | 2459 | {
|
---|
[1711] | 2460 | HGCMMsgMainLoadSaveState *pMsg = (HGCMMsgMainLoadSaveState *)pMsgCore;
|
---|
[1681] | 2461 |
|
---|
[1711] | 2462 | LogFlowFunc(("HGCM_MSG_SAVESTATE\n"));
|
---|
[1681] | 2463 |
|
---|
[94937] | 2464 | vrc = HGCMService::SaveState(pMsg->pSSM, pMsg->pVMM);
|
---|
[1681] | 2465 | } break;
|
---|
[1711] | 2466 |
|
---|
| 2467 | case HGCM_MSG_QUIT:
|
---|
| 2468 | {
|
---|
[75574] | 2469 | HGCMMsgMainQuit *pMsg = (HGCMMsgMainQuit *)pMsgCore;
|
---|
[1711] | 2470 | LogFlowFunc(("HGCM_MSG_QUIT\n"));
|
---|
| 2471 |
|
---|
[75574] | 2472 | HGCMService::UnloadAll(pMsg->fUvmIsInvalid);
|
---|
[1711] | 2473 |
|
---|
| 2474 | fQuit = true;
|
---|
| 2475 | } break;
|
---|
| 2476 |
|
---|
[2386] | 2477 | case HGCM_MSG_REGEXT:
|
---|
| 2478 | {
|
---|
| 2479 | HGCMMsgMainRegisterExtension *pMsg = (HGCMMsgMainRegisterExtension *)pMsgCore;
|
---|
[6985] | 2480 |
|
---|
[2386] | 2481 | LogFlowFunc(("HGCM_MSG_REGEXT\n"));
|
---|
[6985] | 2482 |
|
---|
[2386] | 2483 | /* Allocate the handle data. */
|
---|
[51092] | 2484 | HGCMSVCEXTHANDLE handle = (HGCMSVCEXTHANDLE)RTMemAllocZ(sizeof(struct _HGCMSVCEXTHANDLEDATA)
|
---|
| 2485 | + strlen(pMsg->pszServiceName)
|
---|
| 2486 | + sizeof(char));
|
---|
[6985] | 2487 |
|
---|
[2386] | 2488 | if (handle == NULL)
|
---|
| 2489 | {
|
---|
[94937] | 2490 | vrc = VERR_NO_MEMORY;
|
---|
[2386] | 2491 | }
|
---|
| 2492 | else
|
---|
| 2493 | {
|
---|
[51092] | 2494 | handle->pszServiceName = (char *)((uint8_t *)handle + sizeof(struct _HGCMSVCEXTHANDLEDATA));
|
---|
| 2495 | strcpy(handle->pszServiceName, pMsg->pszServiceName);
|
---|
[6985] | 2496 |
|
---|
[2386] | 2497 | HGCMService *pService;
|
---|
[94937] | 2498 | vrc = HGCMService::ResolveService(&pService, handle->pszServiceName);
|
---|
[2386] | 2499 |
|
---|
[94937] | 2500 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 2501 | {
|
---|
[51092] | 2502 | pService->RegisterExtension(handle, pMsg->pfnExtension, pMsg->pvExtension);
|
---|
[2386] | 2503 |
|
---|
[51092] | 2504 | pService->ReleaseService();
|
---|
[2386] | 2505 | }
|
---|
[6985] | 2506 |
|
---|
[94937] | 2507 | if (RT_FAILURE(vrc))
|
---|
[2386] | 2508 | {
|
---|
[51092] | 2509 | RTMemFree(handle);
|
---|
[2386] | 2510 | }
|
---|
| 2511 | else
|
---|
| 2512 | {
|
---|
| 2513 | *pMsg->pHandle = handle;
|
---|
| 2514 | }
|
---|
| 2515 | }
|
---|
| 2516 | } break;
|
---|
| 2517 |
|
---|
| 2518 | case HGCM_MSG_UNREGEXT:
|
---|
| 2519 | {
|
---|
| 2520 | HGCMMsgMainUnregisterExtension *pMsg = (HGCMMsgMainUnregisterExtension *)pMsgCore;
|
---|
| 2521 |
|
---|
| 2522 | LogFlowFunc(("HGCM_MSG_UNREGEXT\n"));
|
---|
| 2523 |
|
---|
| 2524 | HGCMService *pService;
|
---|
[94937] | 2525 | vrc = HGCMService::ResolveService(&pService, pMsg->handle->pszServiceName);
|
---|
[2386] | 2526 |
|
---|
[94937] | 2527 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 2528 | {
|
---|
[51092] | 2529 | pService->UnregisterExtension(pMsg->handle);
|
---|
[2386] | 2530 |
|
---|
[51092] | 2531 | pService->ReleaseService();
|
---|
[2386] | 2532 | }
|
---|
[6985] | 2533 |
|
---|
[51092] | 2534 | RTMemFree(pMsg->handle);
|
---|
[2386] | 2535 | } break;
|
---|
| 2536 |
|
---|
[1] | 2537 | default:
|
---|
| 2538 | {
|
---|
[1711] | 2539 | AssertMsgFailed(("hgcmThread: Unsupported message number %08X!!!\n", u32MsgId));
|
---|
[94937] | 2540 | vrc = VERR_NOT_SUPPORTED;
|
---|
[1] | 2541 | } break;
|
---|
| 2542 | }
|
---|
| 2543 |
|
---|
[1711] | 2544 | /* Complete the message processing. */
|
---|
[94937] | 2545 | hgcmMsgComplete(pMsgCore, vrc);
|
---|
[1711] | 2546 |
|
---|
[94937] | 2547 | LogFlowFunc(("message processed %Rrc\n", vrc));
|
---|
[1] | 2548 | }
|
---|
| 2549 | }
|
---|
| 2550 |
|
---|
[1711] | 2551 |
|
---|
| 2552 | /*
|
---|
| 2553 | * The HGCM API.
|
---|
| 2554 | */
|
---|
| 2555 |
|
---|
[75539] | 2556 | /** The main hgcm thread. */
|
---|
| 2557 | static HGCMThread *g_pHgcmThread = 0;
|
---|
[1] | 2558 |
|
---|
| 2559 | /*
|
---|
[1711] | 2560 | * Public HGCM functions.
|
---|
| 2561 | *
|
---|
| 2562 | * hgcmGuest* - called as a result of the guest HGCM requests.
|
---|
| 2563 | * hgcmHost* - called by the host.
|
---|
[1] | 2564 | */
|
---|
[1711] | 2565 |
|
---|
| 2566 | /* Load a HGCM service from the specified library.
|
---|
| 2567 | * Assign the specified name to the service.
|
---|
| 2568 | *
|
---|
[6792] | 2569 | * @param pszServiceLibrary The library to be loaded.
|
---|
[1711] | 2570 | * @param pszServiceName The name to be assigned to the service.
|
---|
[75495] | 2571 | * @param pUVM The user mode VM handle (for statistics and such).
|
---|
[93444] | 2572 | * @param pVMM The VMM vtable (for statistics and such).
|
---|
[75853] | 2573 | * @param pHgcmPort The HGCM port on the VMMDev device (for session ID and such).
|
---|
[98278] | 2574 | * @return VBox status code.
|
---|
[1711] | 2575 | */
|
---|
[51092] | 2576 | int HGCMHostLoad(const char *pszServiceLibrary,
|
---|
[75495] | 2577 | const char *pszServiceName,
|
---|
[75853] | 2578 | PUVM pUVM,
|
---|
[93444] | 2579 | PCVMMR3VTABLE pVMM,
|
---|
[75853] | 2580 | PPDMIHGCMPORT pHgcmPort)
|
---|
[1] | 2581 | {
|
---|
[6792] | 2582 | LogFlowFunc(("lib = %s, name = %s\n", pszServiceLibrary, pszServiceName));
|
---|
[1] | 2583 |
|
---|
[6792] | 2584 | if (!pszServiceLibrary || !pszServiceName)
|
---|
[1] | 2585 | return VERR_INVALID_PARAMETER;
|
---|
| 2586 |
|
---|
[1711] | 2587 | /* Forward the request to the main hgcm thread. */
|
---|
[75541] | 2588 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2589 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_LOAD, hgcmMainMessageAlloc);
|
---|
| 2590 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2591 | {
|
---|
[1711] | 2592 | /* Initialize the message. Since the message is synchronous, use the supplied pointers. */
|
---|
[75541] | 2593 | HGCMMsgMainLoad *pMsg = (HGCMMsgMainLoad *)pCoreMsg;
|
---|
[1] | 2594 |
|
---|
[6792] | 2595 | pMsg->pszServiceLibrary = pszServiceLibrary;
|
---|
[1711] | 2596 | pMsg->pszServiceName = pszServiceName;
|
---|
[75495] | 2597 | pMsg->pUVM = pUVM;
|
---|
[93444] | 2598 | pMsg->pVMM = pVMM;
|
---|
[75853] | 2599 | pMsg->pHgcmPort = pHgcmPort;
|
---|
[1] | 2600 |
|
---|
[94937] | 2601 | vrc = hgcmMsgSend(pMsg);
|
---|
[1] | 2602 | }
|
---|
| 2603 |
|
---|
[94937] | 2604 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2605 | return vrc;
|
---|
[1] | 2606 | }
|
---|
| 2607 |
|
---|
[2386] | 2608 | /* Register a HGCM service extension.
|
---|
| 2609 | *
|
---|
| 2610 | * @param pHandle Returned handle for the registered extension.
|
---|
| 2611 | * @param pszServiceName The name of the service.
|
---|
[28200] | 2612 | * @param pfnExtension The extension entry point (callback).
|
---|
| 2613 | * @param pvExtension The extension pointer.
|
---|
[98278] | 2614 | * @return VBox status code.
|
---|
[2386] | 2615 | */
|
---|
[51092] | 2616 | int HGCMHostRegisterServiceExtension(HGCMSVCEXTHANDLE *pHandle,
|
---|
| 2617 | const char *pszServiceName,
|
---|
| 2618 | PFNHGCMSVCEXT pfnExtension,
|
---|
| 2619 | void *pvExtension)
|
---|
[2386] | 2620 | {
|
---|
| 2621 | LogFlowFunc(("pHandle = %p, name = %s, pfn = %p, rv = %p\n", pHandle, pszServiceName, pfnExtension, pvExtension));
|
---|
[1711] | 2622 |
|
---|
[2386] | 2623 | if (!pHandle || !pszServiceName || !pfnExtension)
|
---|
| 2624 | {
|
---|
| 2625 | return VERR_INVALID_PARAMETER;
|
---|
| 2626 | }
|
---|
| 2627 |
|
---|
| 2628 | /* Forward the request to the main hgcm thread. */
|
---|
[75541] | 2629 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2630 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_REGEXT, hgcmMainMessageAlloc);
|
---|
[2386] | 2631 |
|
---|
[94937] | 2632 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 2633 | {
|
---|
| 2634 | /* Initialize the message. Since the message is synchronous, use the supplied pointers. */
|
---|
[75541] | 2635 | HGCMMsgMainRegisterExtension *pMsg = (HGCMMsgMainRegisterExtension *)pCoreMsg;
|
---|
[2386] | 2636 |
|
---|
| 2637 | pMsg->pHandle = pHandle;
|
---|
| 2638 | pMsg->pszServiceName = pszServiceName;
|
---|
| 2639 | pMsg->pfnExtension = pfnExtension;
|
---|
| 2640 | pMsg->pvExtension = pvExtension;
|
---|
| 2641 |
|
---|
[94937] | 2642 | vrc = hgcmMsgSend(pMsg);
|
---|
[2386] | 2643 | }
|
---|
| 2644 |
|
---|
[94937] | 2645 | LogFlowFunc(("*pHandle = %p, vrc = %Rrc\n", *pHandle, vrc));
|
---|
| 2646 | return vrc;
|
---|
[2386] | 2647 | }
|
---|
| 2648 |
|
---|
[51092] | 2649 | void HGCMHostUnregisterServiceExtension(HGCMSVCEXTHANDLE handle)
|
---|
[2386] | 2650 | {
|
---|
| 2651 | LogFlowFunc(("handle = %p\n", handle));
|
---|
| 2652 |
|
---|
| 2653 | /* Forward the request to the main hgcm thread. */
|
---|
[75541] | 2654 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2655 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_UNREGEXT, hgcmMainMessageAlloc);
|
---|
[2386] | 2656 |
|
---|
[94937] | 2657 | if (RT_SUCCESS(vrc))
|
---|
[2386] | 2658 | {
|
---|
| 2659 | /* Initialize the message. */
|
---|
[75541] | 2660 | HGCMMsgMainUnregisterExtension *pMsg = (HGCMMsgMainUnregisterExtension *)pCoreMsg;
|
---|
[2386] | 2661 |
|
---|
| 2662 | pMsg->handle = handle;
|
---|
| 2663 |
|
---|
[94937] | 2664 | vrc = hgcmMsgSend(pMsg);
|
---|
[2386] | 2665 | }
|
---|
| 2666 |
|
---|
[94937] | 2667 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
[2386] | 2668 | return;
|
---|
| 2669 | }
|
---|
| 2670 |
|
---|
[1711] | 2671 | /* Find a service and inform it about a client connection, create a client handle.
|
---|
| 2672 | *
|
---|
| 2673 | * @param pHGCMPort The port to be used for completion confirmation.
|
---|
| 2674 | * @param pCmd The VBox HGCM context.
|
---|
| 2675 | * @param pszServiceName The name of the service to be connected to.
|
---|
| 2676 | * @param pu32ClientId Where the store the created client handle.
|
---|
[98278] | 2677 | * @return VBox status code.
|
---|
[1] | 2678 | */
|
---|
[51092] | 2679 | int HGCMGuestConnect(PPDMIHGCMPORT pHGCMPort,
|
---|
| 2680 | PVBOXHGCMCMD pCmd,
|
---|
| 2681 | const char *pszServiceName,
|
---|
| 2682 | uint32_t *pu32ClientId)
|
---|
[1] | 2683 | {
|
---|
[1711] | 2684 | LogFlowFunc(("pHGCMPort = %p, pCmd = %p, name = %s, pu32ClientId = %p\n",
|
---|
| 2685 | pHGCMPort, pCmd, pszServiceName, pu32ClientId));
|
---|
[1] | 2686 |
|
---|
[1711] | 2687 | if (pHGCMPort == NULL || pCmd == NULL || pszServiceName == NULL || pu32ClientId == NULL)
|
---|
[1] | 2688 | {
|
---|
| 2689 | return VERR_INVALID_PARAMETER;
|
---|
| 2690 | }
|
---|
| 2691 |
|
---|
[1711] | 2692 | /* Forward the request to the main hgcm thread. */
|
---|
[75541] | 2693 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2694 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_CONNECT, hgcmMainMessageAlloc);
|
---|
[1] | 2695 |
|
---|
[94937] | 2696 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2697 | {
|
---|
[1711] | 2698 | /* Initialize the message. Since 'pszServiceName' and 'pu32ClientId'
|
---|
| 2699 | * will not be deallocated by the caller until the message is completed,
|
---|
| 2700 | * use the supplied pointers.
|
---|
| 2701 | */
|
---|
[75541] | 2702 | HGCMMsgMainConnect *pMsg = (HGCMMsgMainConnect *)pCoreMsg;
|
---|
[1] | 2703 |
|
---|
[1711] | 2704 | pMsg->pHGCMPort = pHGCMPort;
|
---|
| 2705 | pMsg->pCmd = pCmd;
|
---|
| 2706 | pMsg->pszServiceName = pszServiceName;
|
---|
| 2707 | pMsg->pu32ClientId = pu32ClientId;
|
---|
[1] | 2708 |
|
---|
[94937] | 2709 | vrc = hgcmMsgPost(pMsg, hgcmMsgCompletionCallback);
|
---|
[1] | 2710 | }
|
---|
| 2711 |
|
---|
[98278] | 2712 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
[94937] | 2713 | return vrc;
|
---|
[1] | 2714 | }
|
---|
| 2715 |
|
---|
[1711] | 2716 | /* Tell a service that the client is disconnecting, destroy the client handle.
|
---|
| 2717 | *
|
---|
| 2718 | * @param pHGCMPort The port to be used for completion confirmation.
|
---|
| 2719 | * @param pCmd The VBox HGCM context.
|
---|
| 2720 | * @param u32ClientId The client handle to be disconnected and deleted.
|
---|
[98278] | 2721 | * @return VBox status code.
|
---|
[1711] | 2722 | */
|
---|
[51092] | 2723 | int HGCMGuestDisconnect(PPDMIHGCMPORT pHGCMPort,
|
---|
| 2724 | PVBOXHGCMCMD pCmd,
|
---|
| 2725 | uint32_t u32ClientId)
|
---|
[1681] | 2726 | {
|
---|
[1711] | 2727 | LogFlowFunc(("pHGCMPort = %p, pCmd = %p, u32ClientId = %d\n",
|
---|
| 2728 | pHGCMPort, pCmd, u32ClientId));
|
---|
[1681] | 2729 |
|
---|
[1711] | 2730 | if (!pHGCMPort || !pCmd || !u32ClientId)
|
---|
| 2731 | {
|
---|
| 2732 | return VERR_INVALID_PARAMETER;
|
---|
| 2733 | }
|
---|
| 2734 |
|
---|
| 2735 | /* Forward the request to the main hgcm thread. */
|
---|
[75541] | 2736 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2737 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_DISCONNECT, hgcmMainMessageAlloc);
|
---|
[1681] | 2738 |
|
---|
[94937] | 2739 | if (RT_SUCCESS(vrc))
|
---|
[1681] | 2740 | {
|
---|
[1711] | 2741 | /* Initialize the message. */
|
---|
[75541] | 2742 | HGCMMsgMainDisconnect *pMsg = (HGCMMsgMainDisconnect *)pCoreMsg;
|
---|
[1681] | 2743 |
|
---|
[1711] | 2744 | pMsg->pCmd = pCmd;
|
---|
| 2745 | pMsg->pHGCMPort = pHGCMPort;
|
---|
| 2746 | pMsg->u32ClientId = u32ClientId;
|
---|
[1681] | 2747 |
|
---|
[94937] | 2748 | vrc = hgcmMsgPost(pMsg, hgcmMsgCompletionCallback);
|
---|
[1681] | 2749 | }
|
---|
| 2750 |
|
---|
[94937] | 2751 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2752 | return vrc;
|
---|
[1681] | 2753 | }
|
---|
| 2754 |
|
---|
[75853] | 2755 | /** Helper to send either HGCM_MSG_SAVESTATE or HGCM_MSG_LOADSTATE messages to the main HGCM thread.
|
---|
[1711] | 2756 | *
|
---|
| 2757 | * @param pSSM The SSM handle.
|
---|
[93444] | 2758 | * @param pVMM The VMM vtable.
|
---|
[75853] | 2759 | * @param idMsg The message to be sent: HGCM_MSG_SAVESTATE or HGCM_MSG_LOADSTATE.
|
---|
| 2760 | * @param uVersion The state version being loaded.
|
---|
[98278] | 2761 | * @return VBox status code.
|
---|
[1711] | 2762 | */
|
---|
[93444] | 2763 | static int hgcmHostLoadSaveState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t idMsg, uint32_t uVersion)
|
---|
[1681] | 2764 | {
|
---|
[93444] | 2765 | LogFlowFunc(("pSSM = %p, pVMM = %p, idMsg = %d, uVersion = %#x\n", pSSM, pVMM, idMsg, uVersion));
|
---|
[1681] | 2766 |
|
---|
[75541] | 2767 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2768 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, idMsg, hgcmMainMessageAlloc);
|
---|
| 2769 | if (RT_SUCCESS(vrc))
|
---|
[906] | 2770 | {
|
---|
[75541] | 2771 | HGCMMsgMainLoadSaveState *pMsg = (HGCMMsgMainLoadSaveState *)pCoreMsg;
|
---|
[1711] | 2772 | AssertRelease(pMsg);
|
---|
[906] | 2773 |
|
---|
[1711] | 2774 | pMsg->pSSM = pSSM;
|
---|
[93444] | 2775 | pMsg->pVMM = pVMM;
|
---|
[75853] | 2776 | pMsg->uVersion = uVersion;
|
---|
[906] | 2777 |
|
---|
[94937] | 2778 | vrc = hgcmMsgSend(pMsg);
|
---|
[1711] | 2779 | }
|
---|
[906] | 2780 |
|
---|
[94937] | 2781 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2782 | return vrc;
|
---|
[906] | 2783 | }
|
---|
| 2784 |
|
---|
[75853] | 2785 | /** Save the state of services.
|
---|
[1711] | 2786 | *
|
---|
[93444] | 2787 | * @param pSSM The SSM handle.
|
---|
| 2788 | * @param pVMM The VMM vtable.
|
---|
| 2789 | * @return VBox status code.
|
---|
[1711] | 2790 | */
|
---|
[93444] | 2791 | int HGCMHostSaveState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM)
|
---|
[906] | 2792 | {
|
---|
[93444] | 2793 | return hgcmHostLoadSaveState(pSSM, pVMM, HGCM_MSG_SAVESTATE, HGCM_SAVED_STATE_VERSION);
|
---|
[1711] | 2794 | }
|
---|
[906] | 2795 |
|
---|
[75853] | 2796 | /** Load the state of services.
|
---|
[1711] | 2797 | *
|
---|
[93444] | 2798 | * @param pSSM The SSM handle.
|
---|
| 2799 | * @param pVMM The VMM vtable.
|
---|
| 2800 | * @param uVersion The state version being loaded.
|
---|
| 2801 | * @return VBox status code.
|
---|
[1711] | 2802 | */
|
---|
[93444] | 2803 | int HGCMHostLoadState(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t uVersion)
|
---|
[1711] | 2804 | {
|
---|
[93444] | 2805 | return hgcmHostLoadSaveState(pSSM, pVMM, HGCM_MSG_LOADSTATE, uVersion);
|
---|
[906] | 2806 | }
|
---|
| 2807 |
|
---|
[75990] | 2808 | /** The guest calls the service.
|
---|
[1711] | 2809 | *
|
---|
| 2810 | * @param pHGCMPort The port to be used for completion confirmation.
|
---|
| 2811 | * @param pCmd The VBox HGCM context.
|
---|
[75990] | 2812 | * @param u32ClientId The client handle.
|
---|
[1711] | 2813 | * @param u32Function The function number.
|
---|
| 2814 | * @param cParms Number of parameters.
|
---|
| 2815 | * @param paParms Pointer to array of parameters.
|
---|
[75500] | 2816 | * @param tsArrival The STAM_GET_TS() value when the request arrived.
|
---|
[98278] | 2817 | * @return VBox status code.
|
---|
[1711] | 2818 | */
|
---|
[51092] | 2819 | int HGCMGuestCall(PPDMIHGCMPORT pHGCMPort,
|
---|
| 2820 | PVBOXHGCMCMD pCmd,
|
---|
| 2821 | uint32_t u32ClientId,
|
---|
| 2822 | uint32_t u32Function,
|
---|
| 2823 | uint32_t cParms,
|
---|
[75500] | 2824 | VBOXHGCMSVCPARM *paParms,
|
---|
| 2825 | uint64_t tsArrival)
|
---|
[1] | 2826 | {
|
---|
[1711] | 2827 | LogFlowFunc(("pHGCMPort = %p, pCmd = %p, u32ClientId = %d, u32Function = %d, cParms = %d, paParms = %p\n",
|
---|
| 2828 | pHGCMPort, pCmd, u32ClientId, u32Function, cParms, paParms));
|
---|
[1] | 2829 |
|
---|
[1711] | 2830 | if (!pHGCMPort || !pCmd || u32ClientId == 0)
|
---|
[1] | 2831 | {
|
---|
| 2832 | return VERR_INVALID_PARAMETER;
|
---|
| 2833 | }
|
---|
| 2834 |
|
---|
[94937] | 2835 | int vrc = VERR_HGCM_INVALID_CLIENT_ID;
|
---|
[1] | 2836 |
|
---|
[1711] | 2837 | /* Resolve the client handle to the client instance pointer. */
|
---|
[91748] | 2838 | HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(u32ClientId);
|
---|
[1] | 2839 |
|
---|
[1711] | 2840 | if (pClient)
|
---|
[1] | 2841 | {
|
---|
[1711] | 2842 | AssertRelease(pClient->pService);
|
---|
[1] | 2843 |
|
---|
[1711] | 2844 | /* Forward the message to the service thread. */
|
---|
[94937] | 2845 | vrc = pClient->pService->GuestCall(pHGCMPort, pCmd, u32ClientId, pClient, u32Function, cParms, paParms, tsArrival);
|
---|
[1] | 2846 |
|
---|
[51092] | 2847 | hgcmObjDereference(pClient);
|
---|
[1] | 2848 | }
|
---|
| 2849 |
|
---|
[94937] | 2850 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2851 | return vrc;
|
---|
[1] | 2852 | }
|
---|
| 2853 |
|
---|
[75990] | 2854 | /** The guest cancelled a request (call, connect, disconnect)
|
---|
| 2855 | *
|
---|
| 2856 | * @param pHGCMPort The port to be used for completion confirmation.
|
---|
| 2857 | * @param pCmd The VBox HGCM context.
|
---|
| 2858 | * @param idClient The client handle.
|
---|
| 2859 | */
|
---|
| 2860 | void HGCMGuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t idClient)
|
---|
| 2861 | {
|
---|
| 2862 | LogFlowFunc(("pHGCMPort = %p, pCmd = %p, idClient = %d\n", pHGCMPort, pCmd, idClient));
|
---|
| 2863 | AssertReturnVoid(pHGCMPort);
|
---|
| 2864 | AssertReturnVoid(pCmd);
|
---|
| 2865 | AssertReturnVoid(idClient != 0);
|
---|
| 2866 |
|
---|
| 2867 | /* Resolve the client handle to the client instance pointer. */
|
---|
[91748] | 2868 | HGCMClient *pClient = HGCMClient::ReferenceByHandleForGuest(idClient);
|
---|
[75990] | 2869 |
|
---|
| 2870 | if (pClient)
|
---|
| 2871 | {
|
---|
| 2872 | AssertRelease(pClient->pService);
|
---|
| 2873 |
|
---|
| 2874 | /* Forward the message to the service thread. */
|
---|
| 2875 | pClient->pService->GuestCancelled(pHGCMPort, pCmd, idClient);
|
---|
| 2876 |
|
---|
| 2877 | hgcmObjDereference(pClient);
|
---|
| 2878 | }
|
---|
| 2879 |
|
---|
| 2880 | LogFlowFunc(("returns\n"));
|
---|
| 2881 | }
|
---|
| 2882 |
|
---|
[75969] | 2883 | /** The host calls the service.
|
---|
[1711] | 2884 | *
|
---|
| 2885 | * @param pszServiceName The service name to be called.
|
---|
| 2886 | * @param u32Function The function number.
|
---|
| 2887 | * @param cParms Number of parameters.
|
---|
| 2888 | * @param paParms Pointer to array of parameters.
|
---|
[98278] | 2889 | * @return VBox status code.
|
---|
[1] | 2890 | */
|
---|
[51092] | 2891 | int HGCMHostCall(const char *pszServiceName,
|
---|
| 2892 | uint32_t u32Function,
|
---|
| 2893 | uint32_t cParms,
|
---|
| 2894 | VBOXHGCMSVCPARM *paParms)
|
---|
[1] | 2895 | {
|
---|
[1711] | 2896 | LogFlowFunc(("name = %s, u32Function = %d, cParms = %d, paParms = %p\n",
|
---|
| 2897 | pszServiceName, u32Function, cParms, paParms));
|
---|
[1] | 2898 |
|
---|
[1711] | 2899 | if (!pszServiceName)
|
---|
[1] | 2900 | {
|
---|
| 2901 | return VERR_INVALID_PARAMETER;
|
---|
| 2902 | }
|
---|
| 2903 |
|
---|
[1711] | 2904 | /* Host calls go to main HGCM thread that resolves the service name to the
|
---|
| 2905 | * service instance pointer and then, using the service pointer, forwards
|
---|
| 2906 | * the message to the service thread.
|
---|
| 2907 | * So it is slow but host calls are intended mostly for configuration and
|
---|
| 2908 | * other non-time-critical functions.
|
---|
| 2909 | */
|
---|
[75541] | 2910 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2911 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_HOSTCALL, hgcmMainMessageAlloc);
|
---|
[1711] | 2912 |
|
---|
[94937] | 2913 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2914 | {
|
---|
[75541] | 2915 | HGCMMsgMainHostCall *pMsg = (HGCMMsgMainHostCall *)pCoreMsg;
|
---|
[6985] | 2916 |
|
---|
[1711] | 2917 | pMsg->pszServiceName = (char *)pszServiceName;
|
---|
| 2918 | pMsg->u32Function = u32Function;
|
---|
| 2919 | pMsg->cParms = cParms;
|
---|
| 2920 | pMsg->paParms = paParms;
|
---|
[1] | 2921 |
|
---|
[94937] | 2922 | vrc = hgcmMsgSend(pMsg);
|
---|
[1711] | 2923 | }
|
---|
[1] | 2924 |
|
---|
[94937] | 2925 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2926 | return vrc;
|
---|
[1] | 2927 | }
|
---|
| 2928 |
|
---|
[75969] | 2929 | /** Posts a notification event to all services.
|
---|
| 2930 | *
|
---|
| 2931 | * @param enmEvent The notification event.
|
---|
[98278] | 2932 | * @return VBox status code.
|
---|
[75969] | 2933 | */
|
---|
| 2934 | int HGCMBroadcastEvent(HGCMNOTIFYEVENT enmEvent)
|
---|
| 2935 | {
|
---|
| 2936 | LogFlowFunc(("enmEvent=%d\n", enmEvent));
|
---|
| 2937 |
|
---|
| 2938 | HGCMMsgCore *pCoreMsg;
|
---|
[94937] | 2939 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pCoreMsg, HGCM_MSG_BRD_NOTIFY, hgcmMainMessageAlloc);
|
---|
[75969] | 2940 |
|
---|
[94937] | 2941 | if (RT_SUCCESS(vrc))
|
---|
[75969] | 2942 | {
|
---|
| 2943 | HGCMMsgMainBroadcastNotify *pMsg = (HGCMMsgMainBroadcastNotify *)pCoreMsg;
|
---|
| 2944 |
|
---|
| 2945 | pMsg->enmEvent = enmEvent;
|
---|
| 2946 |
|
---|
[94937] | 2947 | vrc = hgcmMsgPost(pMsg, NULL);
|
---|
[75969] | 2948 | }
|
---|
| 2949 |
|
---|
[94937] | 2950 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2951 | return vrc;
|
---|
[75969] | 2952 | }
|
---|
| 2953 |
|
---|
| 2954 |
|
---|
[75991] | 2955 | int HGCMHostReset(bool fForShutdown)
|
---|
[1] | 2956 | {
|
---|
[1711] | 2957 | LogFlowFunc(("\n"));
|
---|
[6985] | 2958 |
|
---|
[1711] | 2959 | /* Disconnect all clients.
|
---|
| 2960 | */
|
---|
[1] | 2961 |
|
---|
[75991] | 2962 | HGCMMsgCore *pMsgCore;
|
---|
[94937] | 2963 | int vrc = hgcmMsgAlloc(g_pHgcmThread, &pMsgCore, HGCM_MSG_RESET, hgcmMainMessageAlloc);
|
---|
[1] | 2964 |
|
---|
[94937] | 2965 | if (RT_SUCCESS(vrc))
|
---|
[75991] | 2966 | {
|
---|
| 2967 | HGCMMsgMainReset *pMsg = (HGCMMsgMainReset *)pMsgCore;
|
---|
| 2968 |
|
---|
| 2969 | pMsg->fForShutdown = fForShutdown;
|
---|
| 2970 |
|
---|
[94937] | 2971 | vrc = hgcmMsgSend(pMsg);
|
---|
[75991] | 2972 | }
|
---|
[1] | 2973 |
|
---|
[94937] | 2974 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2975 | return vrc;
|
---|
[1] | 2976 | }
|
---|
| 2977 |
|
---|
[51092] | 2978 | int HGCMHostInit(void)
|
---|
[1] | 2979 | {
|
---|
[1711] | 2980 | LogFlowFunc(("\n"));
|
---|
[1] | 2981 |
|
---|
[94937] | 2982 | int vrc = hgcmThreadInit();
|
---|
[1] | 2983 |
|
---|
[94937] | 2984 | if (RT_SUCCESS(vrc))
|
---|
[1] | 2985 | {
|
---|
[1711] | 2986 | /*
|
---|
| 2987 | * Start main HGCM thread.
|
---|
| 2988 | */
|
---|
[1] | 2989 |
|
---|
[94937] | 2990 | vrc = hgcmThreadCreate(&g_pHgcmThread, "MainHGCMthread", hgcmThread, NULL /*pvUser*/,
|
---|
| 2991 | NULL /*pszStatsSubDir*/, NULL /*pUVM*/, NULL /*pVMM*/);
|
---|
[1] | 2992 |
|
---|
[94937] | 2993 | if (RT_FAILURE(vrc))
|
---|
| 2994 | LogRel(("Failed to start HGCM thread. HGCM services will be unavailable!!! vrc = %Rrc\n", vrc));
|
---|
[1] | 2995 | }
|
---|
| 2996 |
|
---|
[94937] | 2997 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 2998 | return vrc;
|
---|
[1] | 2999 | }
|
---|
[1385] | 3000 |
|
---|
[75574] | 3001 | int HGCMHostShutdown(bool fUvmIsInvalid /*= false*/)
|
---|
[1385] | 3002 | {
|
---|
[1711] | 3003 | LogFlowFunc(("\n"));
|
---|
[1385] | 3004 |
|
---|
[1711] | 3005 | /*
|
---|
| 3006 | * Do HGCMReset and then unload all services.
|
---|
| 3007 | */
|
---|
[1385] | 3008 |
|
---|
[94937] | 3009 | int vrc = HGCMHostReset(true /*fForShutdown*/);
|
---|
[1711] | 3010 |
|
---|
[94937] | 3011 | if (RT_SUCCESS(vrc))
|
---|
[1385] | 3012 | {
|
---|
[1711] | 3013 | /* Send the quit message to the main hgcmThread. */
|
---|
[75574] | 3014 | HGCMMsgCore *pMsgCore;
|
---|
[94937] | 3015 | vrc = hgcmMsgAlloc(g_pHgcmThread, &pMsgCore, HGCM_MSG_QUIT, hgcmMainMessageAlloc);
|
---|
[1385] | 3016 |
|
---|
[94937] | 3017 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 3018 | {
|
---|
[75574] | 3019 | HGCMMsgMainQuit *pMsg = (HGCMMsgMainQuit *)pMsgCore;
|
---|
| 3020 | pMsg->fUvmIsInvalid = fUvmIsInvalid;
|
---|
| 3021 |
|
---|
[94937] | 3022 | vrc = hgcmMsgSend(pMsg);
|
---|
[1385] | 3023 |
|
---|
[94937] | 3024 | if (RT_SUCCESS(vrc))
|
---|
[1711] | 3025 | {
|
---|
[1788] | 3026 | /* Wait for the thread termination. */
|
---|
[75539] | 3027 | hgcmThreadWait(g_pHgcmThread);
|
---|
[75541] | 3028 | g_pHgcmThread = NULL;
|
---|
[1788] | 3029 |
|
---|
[51092] | 3030 | hgcmThreadUninit();
|
---|
[1711] | 3031 | }
|
---|
| 3032 | }
|
---|
| 3033 | }
|
---|
[1385] | 3034 |
|
---|
[94937] | 3035 | LogFlowFunc(("vrc = %Rrc\n", vrc));
|
---|
| 3036 | return vrc;
|
---|
[1385] | 3037 | }
|
---|
[75541] | 3038 |
|
---|