VirtualBox

Changeset 1385 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Mar 9, 2007 7:20:25 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
19381
Message:

Implemented hgcmReset. Removed more obsolete code.

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/VMMDevInterface.cpp

    r1080 r1385  
    459459    }
    460460
    461     /// @todo hgcmShutdown
     461    hgcmReset ();
    462462#endif
    463463    if (pData->pVMMDev)
     
    485485
    486486        pData->pVMMDev->hgcmDisconnect(cmd, pData->pVMMDev->getShFlClientId());
    487 
     487    }
     488   
     489    hgcmReset ();
     490
     491    if (pData->pVMMDev->mSharedFolderClientId)
     492    {
    488493        /* Reload Shared Folder HGCM service */
    489494        HGCMSERVICELOCATION loc;
  • trunk/src/VBox/Main/hgcm/HGCM.cpp

    r1080 r1385  
    134134        VBOXHGCMSVCFNTABLE m_fntable;
    135135
     136        int m_cClients;
     137        int m_cClientsAllocated;
     138
     139        uint32_t *m_paClientIds;
    136140
    137141        int loadServiceDLL (void);
     
    150154    public:
    151155
     156        static void Reset (void);
     157   
    152158        static int FindService (HGCMService **ppsvc, HGCMServiceLocation *loc);
    153159        static HGCMService *FindServiceByName (const char *pszServiceName);
     
    156162
    157163        uint32_t SizeOfClient (void) { return m_fntable.cbClient; };
     164
     165        void DisconnectAll (void);
    158166
    159167        int Connect (uint32_t u32ClientID);
     
    279287#define HGCMMSGID_LOADSTATE  (14)
    280288#define HGCMMSGID_SAVESTATE  (15)
     289#define HGCMMSGID_RESET      (16)
    281290
    282291class HGCMMsgConnect: public HGCMMsgHeader
     
    348357
    349358        VBOXHGCMSVCPARM *paParms;
     359};
     360
     361class HGCMMsgReset: public HGCMMsgHeader
     362{
    350363};
    351364
     
    381394    m_pszSvcLibrary (NULL),
    382395    m_hLdrMod    (NIL_RTLDRMOD),
    383     m_pfnLoad    (NULL)
     396    m_pfnLoad    (NULL),
     397    m_cClients   (0),
     398    m_cClientsAllocated (0),
     399    m_paClientIds (NULL)
    384400{
    385401    memset (&m_fntable, 0, sizeof (m_fntable));
     
    403419        case HGCMMSGID_LOADSTATE:     
    404420        case HGCMMSGID_SAVESTATE:       return new HGCMMsgLoadSaveState ();
     421        case HGCMMSGID_RESET:           return new HGCMMsgReset ();
    405422        default:
    406423            Log(("hgcmMessageAlloc::Unsupported message number %08X\n", u32MsgId));
     424            AssertReleaseMsgFailed(("Msg id = %08X\n", u32MsgId));
    407425    }
    408426
     
    410428}
    411429
     430static g_fResetting = false;
    412431
    413432static DECLCALLBACK(void) hgcmMsgCompletionCallback (int32_t result, HGCMMsgCore *pMsgCore)
     
    418437    LogFlow(("MAIN::hgcmMsgCompletionCallback: message %p\n", pMsgCore));
    419438
    420     if (pMsgHdr->pHGCMPort)
     439    if (pMsgHdr->pHGCMPort && !g_fResetting)
    421440    {
    422441        pMsgHdr->pHGCMPort->pfnCompleted (pMsgHdr->pHGCMPort, result, pMsgHdr->pCmd);
     
    599618    RTStrPrintf (achThreadName, sizeof (achThreadName), "HGCM%08X", this);
    600619
    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);
    603621
    604622    if (VBOX_SUCCESS(rc))
     
    627645            HGCMMSGHANDLE hMsg;
    628646
    629             rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_LOAD, sizeof (HGCMMsgSvcLoad), hgcmMessageAlloc);
     647            rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_LOAD, hgcmMessageAlloc);
    630648
    631649            if (VBOX_SUCCESS(rc))
     
    656674    LogFlow(("HGCMService::InstanceDestroy\n"));
    657675
    658     int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_UNLOAD, sizeof (HGCMMsgSvcUnload), hgcmMessageAlloc);
     676    int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_UNLOAD, hgcmMessageAlloc);
    659677
    660678    if (VBOX_SUCCESS(rc))
     
    803821}
    804822
     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
    805844void HGCMService::ReleaseService (void)
    806845{
     
    926965    LogFlow(("MAIN::HGCMService::Connect: client id = %d\n", u32ClientID));
    927966
    928     int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_CONNECT, sizeof (HGCMMsgSvcConnect), hgcmMessageAlloc);
     967    int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_CONNECT, hgcmMessageAlloc);
    929968
    930969    if (VBOX_SUCCESS(rc))
     
    939978
    940979        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        }
    941993    }
    942994    else
     
    9561008    HGCMMSGHANDLE hMsg;
    9571009
    958     rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_DISCONNECT, sizeof (HGCMMsgSvcDisconnect), hgcmMessageAlloc);
     1010    rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SVC_DISCONNECT, hgcmMessageAlloc);
    9591011
    9601012    if (VBOX_SUCCESS(rc))
     
    9691021
    9701022        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        }
    9711040    }
    9721041    else
     
    9781047}
    9791048
     1049void 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
    9801058/* Forward the call request to the dedicated service thread.
    9811059 */
     
    9861064    LogFlow(("MAIN::HGCMService::Call\n"));
    9871065
    988     int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_GUESTCALL, sizeof (HGCMMsgCall), hgcmMessageAlloc);
     1066    int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_GUESTCALL, hgcmMessageAlloc);
    9891067
    9901068    if (VBOX_SUCCESS(rc))
     
    10301108    LogFlow(("MAIN::HGCMService::HostCall %s\n", m_pszSvcName));
    10311109
    1032     int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_HOSTCALL, sizeof (HGCMMsgHostCall), hgcmMessageAlloc);
     1110    int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_HOSTCALL, hgcmMessageAlloc);
    10331111
    10341112    if (VBOX_SUCCESS(rc))
     
    10631141    LogFlow(("MAIN::HGCMService::SaveState %s\n", m_pszSvcName));
    10641142
    1065     int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SAVESTATE, sizeof (HGCMMsgLoadSaveState), hgcmMessageAlloc);
     1143    int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_SAVESTATE, hgcmMessageAlloc);
    10661144
    10671145    if (VBOX_SUCCESS(rc))
     
    10921170    LogFlow(("MAIN::HGCMService::LoadState %s\n", m_pszSvcName));
    10931171
    1094     int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_LOADSTATE, sizeof (HGCMMsgLoadSaveState), hgcmMessageAlloc);
     1172    int rc = hgcmMsgAlloc (m_thread, &hMsg, HGCMMSGID_LOADSTATE, hgcmMessageAlloc);
    10951173
    10961174    if (VBOX_SUCCESS(rc))
     
    12421320            } break;
    12431321
    1244 
    12451322            case HGCMMSGID_HOSTCALL:
    12461323            {
     
    12581335            } break;
    12591336
     1337            case HGCMMSGID_RESET:
     1338            {
     1339                LogFlow(("HGCMMSGID_RESET\n"));
     1340
     1341                HGCMMsgReset *pMsg = (HGCMMsgReset *)pMsgCore;
     1342
     1343                HGCMService::Reset ();
     1344            } break;
     1345
    12601346            default:
    12611347            {
     
    12911377    HGCMMSGHANDLE hMsg = 0;
    12921378
    1293     rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_CONNECT, sizeof (HGCMMsgConnect), hgcmMessageAlloc);
     1379    rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_CONNECT, hgcmMessageAlloc);
    12941380
    12951381    if (VBOX_SUCCESS(rc))
     
    13461432    HGCMMSGHANDLE hMsg = 0;
    13471433
    1348     rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_DISCONNECT, sizeof (HGCMMsgDisconnect), hgcmMessageAlloc);
     1434    rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_DISCONNECT, hgcmMessageAlloc);
    13491435
    13501436    if (VBOX_SUCCESS(rc))
     
    14391525    HGCMMSGHANDLE hMsg = 0;
    14401526
    1441     rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_LOAD, sizeof (HGCMMsgLoad), hgcmMessageAlloc);
     1527    rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_LOAD, hgcmMessageAlloc);
    14421528
    14431529    if (VBOX_SUCCESS(rc))
     
    15201606    HGCMMSGHANDLE hMsg = 0;
    15211607
    1522     rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_HOSTCALL, sizeof (HGCMMsgHostCall), hgcmMessageAlloc);
     1608    rc = hgcmMsgAlloc (g_hgcmThread, &hMsg, HGCMMSGID_HOSTCALL, hgcmMessageAlloc);
    15231609
    15241610    if (VBOX_SUCCESS(rc))
     
    15661652        /* Start main HGCM thread that will process Connect/Disconnect requests. */
    15671653
    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);
    15701655
    15711656        if (VBOX_FAILURE (rc))
     
    15791664    return rc;
    15801665}
     1666
     1667int 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  
    134134        HGCMThread ();
    135135
    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);
    139139        int MsgGet (HGCMMsgCore **ppMsg);
    140140        int MsgPost (HGCMMsgCore *pMsg, PHGCMMSGCALLBACK pfnCallback, bool bWait);
     
    151151#define HGCM_MSG_F_IN_PROCESS (0x00000004)
    152152
    153 void HGCMMsgCore::InitializeCore (uint32_t cbMsg, uint32_t u32MsgId, HGCMThread *pThread)
     153void HGCMMsgCore::InitializeCore (uint32_t u32MsgId, HGCMThread *pThread)
    154154{
    155155    m_u32Version  = HGCMMSG_VERSION;
     
    248248}
    249249
    250 int HGCMThread::Initialize (HGCMTHREADHANDLE handle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser, uint32_t cbMsg)
     250int HGCMThread::Initialize (HGCMTHREADHANDLE handle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser)
    251251{
    252252    int rc = VINF_SUCCESS;
     
    328328
    329329
    330 int HGCMThread::MsgAlloc (HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, uint32_t cbMsg, PFNHGCMNEWMSGALLOC pfnNewMessage)
     330int HGCMThread::MsgAlloc (HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage)
    331331{
    332332    int rc = VINF_SUCCESS;
     
    353353
    354354        /* Initialize just allocated message core */
    355         pmsg->InitializeCore (cbMsg, u32MsgId, this);
     355        pmsg->InitializeCore (u32MsgId, this);
    356356
    357357        /* and the message specific data. */
     
    591591 */
    592592
    593 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser, uint32_t cbMsg)
     593int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser)
    594594{
    595595    int rc = VINF_SUCCESS;
     
    608608
    609609        /* Initialize the object. */
    610         rc = pThread->Initialize (handle, pszThreadName, pfnThread, pvUser, cbMsg);
     610        rc = pThread->Initialize (handle, pszThreadName, pfnThread, pvUser);
    611611    }
    612612    else
     
    636636}
    637637
    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))
     638int 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)
    643643    {
    644644        return VERR_INVALID_PARAMETER;
     
    655655    else
    656656    {
    657         rc = pThread->MsgAlloc (pHandle, u32MsgId, cbMsg, pfnNewMessage);
     657        rc = pThread->MsgAlloc (pHandle, u32MsgId, pfnNewMessage);
    658658
    659659        hgcmObjDereference (pThread);
  • trunk/src/VBox/Main/include/hgcm/HGCM.h

    r1080 r1385  
    3636int hgcmInit (void);
    3737
     38int hgcmReset (void);
     39
    3840int hgcmLoadInternal (const char *pszServiceName, const char *pszServiceLibrary);
    3941
  • trunk/src/VBox/Main/include/hgcm/HGCMThread.h

    r1344 r1385  
    8484        int32_t m_rcSend;
    8585
    86         void InitializeCore (uint32_t cbMsg, uint32_t u32MsgId, HGCMThread *pThread);
     86        void InitializeCore (uint32_t u32MsgId, HGCMThread *pThread);
    8787
    8888    protected:
     
    132132 * @param pfnThread     The worker thread function.
    133133 * @param pvUser        A pointer passed to worker thread.
    134  * @param cbMsg         Size of a typical message.
    135134 *
    136135 * @return VBox error code
    137136 */
    138 int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser, uint32_t cbMsg);
     137int hgcmThreadCreate (HGCMTHREADHANDLE *pHandle, const char *pszThreadName, PFNHGCMTHREAD pfnThread, void *pvUser);
    139138
    140139/** Allocate a message to be posted to HGCM worker thread.
     
    143142 * @param pHandle       Where to store the returned message handle.
    144143 * @param u32MsgId      Message identifier.
    145  * @param cbMsg         Size of message.
    146144 * @param pfnNewMessage New message allocation callback.
    147145 *
    148146 * @return VBox error code
    149147 */
    150 int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, uint32_t cbMsg, PFNHGCMNEWMSGALLOC pfnNewMessage);
     148int hgcmMsgAlloc (HGCMTHREADHANDLE hThread, HGCMMSGHANDLE *pHandle, uint32_t u32MsgId, PFNHGCMNEWMSGALLOC pfnNewMessage);
    151149
    152150/** Post a message to HGCM worker thread.
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette