Changeset 1385 in vbox for trunk/src/VBox/Main
- Timestamp:
- Mar 9, 2007 7:20:25 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 19381
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/VMMDevInterface.cpp
r1080 r1385 459 459 } 460 460 461 /// @todo hgcmShutdown461 hgcmReset (); 462 462 #endif 463 463 if (pData->pVMMDev) … … 485 485 486 486 pData->pVMMDev->hgcmDisconnect(cmd, pData->pVMMDev->getShFlClientId()); 487 487 } 488 489 hgcmReset (); 490 491 if (pData->pVMMDev->mSharedFolderClientId) 492 { 488 493 /* Reload Shared Folder HGCM service */ 489 494 HGCMSERVICELOCATION loc; -
trunk/src/VBox/Main/hgcm/HGCM.cpp
r1080 r1385 134 134 VBOXHGCMSVCFNTABLE m_fntable; 135 135 136 int m_cClients; 137 int m_cClientsAllocated; 138 139 uint32_t *m_paClientIds; 136 140 137 141 int loadServiceDLL (void); … … 150 154 public: 151 155 156 static void Reset (void); 157 152 158 static int FindService (HGCMService **ppsvc, HGCMServiceLocation *loc); 153 159 static HGCMService *FindServiceByName (const char *pszServiceName); … … 156 162 157 163 uint32_t SizeOfClient (void) { return m_fntable.cbClient; }; 164 165 void DisconnectAll (void); 158 166 159 167 int Connect (uint32_t u32ClientID); … … 279 287 #define HGCMMSGID_LOADSTATE (14) 280 288 #define HGCMMSGID_SAVESTATE (15) 289 #define HGCMMSGID_RESET (16) 281 290 282 291 class HGCMMsgConnect: public HGCMMsgHeader … … 348 357 349 358 VBOXHGCMSVCPARM *paParms; 359 }; 360 361 class HGCMMsgReset: public HGCMMsgHeader 362 { 350 363 }; 351 364 … … 381 394 m_pszSvcLibrary (NULL), 382 395 m_hLdrMod (NIL_RTLDRMOD), 383 m_pfnLoad (NULL) 396 m_pfnLoad (NULL), 397 m_cClients (0), 398 m_cClientsAllocated (0), 399 m_paClientIds (NULL) 384 400 { 385 401 memset (&m_fntable, 0, sizeof (m_fntable)); … … 403 419 case HGCMMSGID_LOADSTATE: 404 420 case HGCMMSGID_SAVESTATE: return new HGCMMsgLoadSaveState (); 421 case HGCMMSGID_RESET: return new HGCMMsgReset (); 405 422 default: 406 423 Log(("hgcmMessageAlloc::Unsupported message number %08X\n", u32MsgId)); 424 AssertReleaseMsgFailed(("Msg id = %08X\n", u32MsgId)); 407 425 } 408 426 … … 410 428 } 411 429 430 static g_fResetting = false; 412 431 413 432 static DECLCALLBACK(void) hgcmMsgCompletionCallback (int32_t result, HGCMMsgCore *pMsgCore) … … 418 437 LogFlow(("MAIN::hgcmMsgCompletionCallback: message %p\n", pMsgCore)); 419 438 420 if (pMsgHdr->pHGCMPort )439 if (pMsgHdr->pHGCMPort && !g_fResetting) 421 440 { 422 441 pMsgHdr->pHGCMPort->pfnCompleted (pMsgHdr->pHGCMPort, result, pMsgHdr->pCmd); … … 599 618 RTStrPrintf (achThreadName, sizeof (achThreadName), "HGCM%08X", this); 600 619 601 /* @todo do a proper fix 0x12345678 -> sizeof */ 602 rc = hgcmThreadCreate (&m_thread, achThreadName, hgcmServiceThread, this, 0x12345678 /* sizeof (HGCMMsgCall) */); 620 rc = hgcmThreadCreate (&m_thread, achThreadName, hgcmServiceThread, this); 603 621 604 622 if (VBOX_SUCCESS(rc)) … … 627 645 HGCMMSGHANDLE hMsg; 628 646 629 rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_LOAD, sizeof (HGCMMsgSvcLoad),hgcmMessageAlloc);647 rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_LOAD, hgcmMessageAlloc); 630 648 631 649 if (VBOX_SUCCESS(rc)) … … 656 674 LogFlow(("HGCMService::InstanceDestroy\n")); 657 675 658 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_UNLOAD, sizeof (HGCMMsgSvcUnload),hgcmMessageAlloc);676 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_UNLOAD, hgcmMessageAlloc); 659 677 660 678 if (VBOX_SUCCESS(rc)) … … 803 821 } 804 822 823 /* static */ void HGCMService::Reset (void) 824 { 825 /* This is called when the VM is being reset, 826 * that is no more requests from guest is expected. 827 * Scan al services and disconnect all clients. 828 */ 829 830 g_fResetting = true; 831 832 HGCMService *psvc = sm_pSvcListHead; 833 834 while (psvc) 835 { 836 psvc->DisconnectAll (); 837 838 psvc = psvc->m_pSvcNext; 839 } 840 841 g_fResetting = false; 842 } 843 805 844 void HGCMService::ReleaseService (void) 806 845 { … … 926 965 LogFlow(("MAIN::HGCMService::Connect: client id = %d\n", u32ClientID)); 927 966 928 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_CONNECT, sizeof (HGCMMsgSvcConnect),hgcmMessageAlloc);967 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_CONNECT, hgcmMessageAlloc); 929 968 930 969 if (VBOX_SUCCESS(rc)) … … 939 978 940 979 rc = hgcmMsgSend (hMsg); 980 981 if (VBOX_SUCCESS (rc)) 982 { 983 /* Add the client Id to the array. */ 984 if (m_cClients == m_cClientsAllocated) 985 { 986 m_paClientIds = (uint32_t *)RTMemRealloc (m_paClientIds, (m_cClientsAllocated + 64) * sizeof (m_paClientIds[0])); 987 Assert(m_paClientIds); 988 } 989 990 m_paClientIds[m_cClients] = u32ClientID; 991 m_cClients++; 992 } 941 993 } 942 994 else … … 956 1008 HGCMMSGHANDLE hMsg; 957 1009 958 rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_DISCONNECT, sizeof (HGCMMsgSvcDisconnect),hgcmMessageAlloc);1010 rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_DISCONNECT, hgcmMessageAlloc); 959 1011 960 1012 if (VBOX_SUCCESS(rc)) … … 969 1021 970 1022 rc = hgcmMsgSend (hMsg); 1023 1024 /* Remove the client id from the array. */ 1025 int i; 1026 for (i = 0; i < m_cClients; i++) 1027 { 1028 if (m_paClientIds[i] == u32ClientID) 1029 { 1030 m_cClients--; 1031 1032 if (m_cClients > i) 1033 { 1034 memmove (&m_paClientIds[i], &m_paClientIds[i + 1], m_cClients - i); 1035 } 1036 1037 break; 1038 } 1039 } 971 1040 } 972 1041 else … … 978 1047 } 979 1048 1049 void HGCMService::DisconnectAll (void) 1050 { 1051 while (m_cClients && m_paClientIds) 1052 { 1053 Log(("MAIN::HGCMService::DisconnectAll: id %d\n", m_paClientIds[0])); 1054 Disconnect (m_paClientIds[0]); 1055 } 1056 } 1057 980 1058 /* Forward the call request to the dedicated service thread. 981 1059 */ … … 986 1064 LogFlow(("MAIN::HGCMService::Call\n")); 987 1065 988 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_GUESTCALL, sizeof (HGCMMsgCall),hgcmMessageAlloc);1066 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_GUESTCALL, hgcmMessageAlloc); 989 1067 990 1068 if (VBOX_SUCCESS(rc)) … … 1030 1108 LogFlow(("MAIN::HGCMService::HostCall %s\n", m_pszSvcName)); 1031 1109 1032 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_HOSTCALL, sizeof (HGCMMsgHostCall),hgcmMessageAlloc);1110 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_HOSTCALL, hgcmMessageAlloc); 1033 1111 1034 1112 if (VBOX_SUCCESS(rc)) … … 1063 1141 LogFlow(("MAIN::HGCMService::SaveState %s\n", m_pszSvcName)); 1064 1142 1065 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SAVESTATE, sizeof (HGCMMsgLoadSaveState),hgcmMessageAlloc);1143 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SAVESTATE, hgcmMessageAlloc); 1066 1144 1067 1145 if (VBOX_SUCCESS(rc)) … … 1092 1170 LogFlow(("MAIN::HGCMService::LoadState %s\n", m_pszSvcName)); 1093 1171 1094 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_LOADSTATE, sizeof (HGCMMsgLoadSaveState),hgcmMessageAlloc);1172 int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_LOADSTATE, hgcmMessageAlloc); 1095 1173 1096 1174 if (VBOX_SUCCESS(rc)) … … 1242 1320 } break; 1243 1321 1244 1245 1322 case HGCMMSGID_HOSTCALL: 1246 1323 { … … 1258 1335 } break; 1259 1336 1337 case HGCMMSGID_RESET: 1338 { 1339 LogFlow(("HGCMMSGID_RESET\n")); 1340 1341 HGCMMsgReset *pMsg = (HGCMMsgReset *)pMsgCore; 1342 1343 HGCMService::Reset (); 1344 } break; 1345 1260 1346 default: 1261 1347 { … … 1291 1377 HGCMMSGHANDLE hMsg = 0; 1292 1378 1293 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_CONNECT, sizeof (HGCMMsgConnect),hgcmMessageAlloc);1379 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_CONNECT, hgcmMessageAlloc); 1294 1380 1295 1381 if (VBOX_SUCCESS(rc)) … … 1346 1432 HGCMMSGHANDLE hMsg = 0; 1347 1433 1348 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_DISCONNECT, sizeof (HGCMMsgDisconnect),hgcmMessageAlloc);1434 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_DISCONNECT, hgcmMessageAlloc); 1349 1435 1350 1436 if (VBOX_SUCCESS(rc)) … … 1439 1525 HGCMMSGHANDLE hMsg = 0; 1440 1526 1441 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_LOAD, sizeof (HGCMMsgLoad),hgcmMessageAlloc);1527 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_LOAD, hgcmMessageAlloc); 1442 1528 1443 1529 if (VBOX_SUCCESS(rc)) … … 1520 1606 HGCMMSGHANDLE hMsg = 0; 1521 1607 1522 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_HOSTCALL, sizeof (HGCMMsgHostCall),hgcmMessageAlloc);1608 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_HOSTCALL, hgcmMessageAlloc); 1523 1609 1524 1610 if (VBOX_SUCCESS(rc)) … … 1566 1652 /* Start main HGCM thread that will process Connect/Disconnect requests. */ 1567 1653 1568 /* @todo do a proper fix 0x12345678 -> sizeof */ 1569 rc = hgcmThreadCreate (&g_hgcmThread, "MainHGCMthread", hgcmThread, NULL, 0x12345678 /*sizeof (HGCMMsgConnect)*/); 1654 rc = hgcmThreadCreate (&g_hgcmThread, "MainHGCMthread", hgcmThread, NULL); 1570 1655 1571 1656 if (VBOX_FAILURE (rc)) … … 1579 1664 return rc; 1580 1665 } 1666 1667 int hgcmReset (void) 1668 { 1669 int rc = VINF_SUCCESS; 1670 Log(("MAIN::hgcmReset\n")); 1671 1672 /* Disconnect all clients. */ 1673 HGCMMSGHANDLE hMsg = 0; 1674 1675 rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_RESET, hgcmMessageAlloc); 1676 1677 if (VBOX_SUCCESS(rc)) 1678 { 1679 HGCMMsgReset *pMsg = (HGCMMsgReset *)hgcmObjReference (hMsg, HGCMOBJ_MSG); 1680 1681 AssertRelease(pMsg); 1682 1683 pMsg->pHGCMPort = NULL; /* Not used by the call. */ 1684 1685 rc = hgcmMsgSend (hMsg); 1686 1687 hgcmObjDereference (pMsg); 1688 1689 LogFlow(("MAIN::hgcmReset: hgcmMsgSend returned %Vrc\n", rc)); 1690 } 1691 else 1692 { 1693 Log(("MAIN::hgcmReset:Message allocation failed: %Vrc\n", rc)); 1694 } 1695 1696 LogFlow(("MAIN::hgcmReset: rc = %Vrc\n", rc)); 1697 return rc; 1698 } -
trunk/src/VBox/Main/hgcm/HGCMThread.cpp
r1344 r1385 134 134 HGCMThread (); 135 135 136 int Initialize (HGCMTHREADHANDLE handle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser , uint32_t cbMsg);137 138 int MsgAlloc (HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, uint32_t cbMsg,PFNHGCMNEWMSGALLOC pfnNewMessage);136 int Initialize (HGCMTHREADHANDLE handle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser); 137 138 int MsgAlloc (HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage); 139 139 int MsgGet (HGCMMsgCore **ppMsg); 140 140 int MsgPost (HGCMMsgCore *pMsg, PHGCMMSGCALLBACK pfnCallback, bool bWait); … … 151 151 #define HGCM_MSG_F_IN_PROCESS (0x00000004) 152 152 153 void HGCMMsgCore::InitializeCore (uint32_t cbMsg, uint32_tu32MsgId, HGCMThread *pThread)153 void HGCMMsgCore::InitializeCore (uint32_t u32MsgId, HGCMThread *pThread) 154 154 { 155 155 m_u32Version = HGCMMSG_VERSION; … … 248 248 } 249 249 250 int HGCMThread::Initialize (HGCMTHREADHANDLE handle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser , uint32_t cbMsg)250 int HGCMThread::Initialize (HGCMTHREADHANDLE handle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser) 251 251 { 252 252 int rc = VINF_SUCCESS; … … 328 328 329 329 330 int HGCMThread::MsgAlloc (HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, uint32_t cbMsg,PFNHGCMNEWMSGALLOC pfnNewMessage)330 int HGCMThread::MsgAlloc (HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage) 331 331 { 332 332 int rc = VINF_SUCCESS; … … 353 353 354 354 /* Initialize just allocated message core */ 355 pmsg->InitializeCore ( cbMsg,u32MsgId, this);355 pmsg->InitializeCore (u32MsgId, this); 356 356 357 357 /* and the message specific data. */ … … 591 591 */ 592 592 593 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser , uint32_t cbMsg)593 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser) 594 594 { 595 595 int rc = VINF_SUCCESS; … … 608 608 609 609 /* Initialize the object. */ 610 rc = pThread->Initialize (handle, pszThreadName, pfnThread, pvUser , cbMsg);610 rc = pThread->Initialize (handle, pszThreadName, pfnThread, pvUser); 611 611 } 612 612 else … … 636 636 } 637 637 638 int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, uint32_t cbMsg,PFNHGCMNEWMSGALLOC pfnNewMessage)639 { 640 LogFlow(("hgcmMsgAlloc: thread handle = %d, pHandle = %p, cbMsg = %d, sizeof (HGCMMsgCore) = %d\n", hThread, pHandle, cbMsg, sizeof (HGCMMsgCore)));641 642 if (!pHandle || cbMsg < sizeof (HGCMMsgCore))638 int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage) 639 { 640 LogFlow(("hgcmMsgAlloc: thread handle = %d, pHandle = %p, sizeof (HGCMMsgCore) = %d\n", hThread, pHandle, sizeof (HGCMMsgCore))); 641 642 if (!pHandle) 643 643 { 644 644 return VERR_INVALID_PARAMETER; … … 655 655 else 656 656 { 657 rc = pThread->MsgAlloc (pHandle, u32MsgId, cbMsg,pfnNewMessage);657 rc = pThread->MsgAlloc (pHandle, u32MsgId, pfnNewMessage); 658 658 659 659 hgcmObjDereference (pThread); -
trunk/src/VBox/Main/include/hgcm/HGCM.h
r1080 r1385 36 36 int hgcmInit (void); 37 37 38 int hgcmReset (void); 39 38 40 int hgcmLoadInternal (const char *pszServiceName, const char *pszServiceLibrary); 39 41 -
trunk/src/VBox/Main/include/hgcm/HGCMThread.h
r1344 r1385 84 84 int32_t m_rcSend; 85 85 86 void InitializeCore (uint32_t cbMsg, uint32_tu32MsgId, HGCMThread *pThread);86 void InitializeCore (uint32_t u32MsgId, HGCMThread *pThread); 87 87 88 88 protected: … … 132 132 * @param pfnThread The worker thread function. 133 133 * @param pvUser A pointer passed to worker thread. 134 * @param cbMsg Size of a typical message.135 134 * 136 135 * @return VBox error code 137 136 */ 138 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser , uint32_t cbMsg);137 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser); 139 138 140 139 /** Allocate a message to be posted to HGCM worker thread. … … 143 142 * @param pHandle Where to store the returned message handle. 144 143 * @param u32MsgId Message identifier. 145 * @param cbMsg Size of message.146 144 * @param pfnNewMessage New message allocation callback. 147 145 * 148 146 * @return VBox error code 149 147 */ 150 int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, uint32_t cbMsg,PFNHGCMNEWMSGALLOC pfnNewMessage);148 int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage); 151 149 152 150 /** Post a message to HGCM worker thread.
Note:
See TracChangeset
for help on using the changeset viewer.