VirtualBox

Changeset 75574 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Nov 19, 2018 2:31:44 PM (6 years ago)
Author:
vboxsync
Message:

Main/HGCM: Shutdown HGCM on VM construction failure, indicating that pUVM is invalid preventing info and stats deregistration calls.

Location:
trunk/src/VBox/Main/src-client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r75495 r75574  
    1039610396             * If VMR3Create() failed it has released the VM memory.
    1039710397             */
     10398            if (pConsole->m_pVMMDev)
     10399            {
     10400                alock.release(); /* just to be on the safe side... */
     10401                pConsole->m_pVMMDev->hgcmShutdown(true /*fUvmIsInvalid*/);
     10402                alock.acquire();
     10403            }
    1039810404            VMR3ReleaseUVM(pConsole->mpUVM);
    1039910405            pConsole->mpUVM = NULL;
  • trunk/src/VBox/Main/src-client/HGCM.cpp

    r75541 r75574  
    156156         */
    157157        static int LoadService(const char *pszServiceLibrary, const char *pszServiceName, PUVM pUVM);
    158         void UnloadService(void);
    159 
    160         static void UnloadAll(void);
     158        void UnloadService(bool fUvmIsInvalid);
     159
     160        static void UnloadAll(bool fUvmIsInvalid);
    161161
    162162        static int ResolveService(HGCMService **ppsvc, const char *pszServiceName);
     
    865865     AssertPtrReturn(pService, VERR_INVALID_PARAMETER);
    866866
    867      return STAMR3DeregisterV(pService->m_pUVM, pszPatFmt, va);
     867     if (pService->m_pUVM)
     868         return STAMR3DeregisterV(pService->m_pUVM, pszPatFmt, va);
     869     return VINF_SUCCESS;
    868870}
    869871
     
    887889     HGCMService *pService = static_cast <HGCMService *>(pvInstance);
    888890     AssertPtrReturn(pService, VERR_INVALID_PARAMETER);
    889 
    890      return DBGFR3InfoDeregisterExternal(pService->m_pUVM, pszName);
     891     if (pService->m_pUVM)
     892         return DBGFR3InfoDeregisterExternal(pService->m_pUVM, pszName);
     893     return VINF_SUCCESS;
    891894}
    892895
     
    994997    }
    995998
    996     if (m_pszSvcName)
     999    if (m_pszSvcName && m_pUVM)
    9971000        STAMR3DeregisterF(m_pUVM, "/HGCM/%s/*", m_pszSvcName);
    9981001    m_pUVM = NULL;
     
    11211124 * @thread main HGCM
    11221125 */
    1123 void HGCMService::UnloadService(void)
     1126void HGCMService::UnloadService(bool fUvmIsInvalid)
    11241127{
    11251128    LogFlowFunc(("name = %s\n", m_pszSvcName));
     1129
     1130    if (fUvmIsInvalid)
     1131        m_pUVM = NULL;
    11261132
    11271133    /* Remove the service from the list. */
     
    11581164 * @thread main HGCM
    11591165 */
    1160 /* static */ void HGCMService::UnloadAll(void)
     1166/* static */ void HGCMService::UnloadAll(bool fUvmIsInvalid)
    11611167{
    11621168    while (sm_pSvcListHead)
    11631169    {
    1164         sm_pSvcListHead->UnloadService();
     1170        sm_pSvcListHead->UnloadService(fUvmIsInvalid);
    11651171    }
    11661172}
     
    18441850class HGCMMsgMainQuit: public HGCMMsgCore
    18451851{
     1852    public:
     1853        /** Whether UVM has gone invalid already or not. */
     1854        bool fUvmIsInvalid;
    18461855};
    18471856
     
    18491858{
    18501859    public:
    1851         /* Returned handle to be used in HGCMMsgMainUnregisterExtension. */
     1860        /** Returned handle to be used in HGCMMsgMainUnregisterExtension. */
    18521861        HGCMSVCEXTHANDLE *pHandle;
    1853         /* Name of the service. */
     1862        /** Name of the service. */
    18541863        const char *pszServiceName;
    1855         /* The extension entry point. */
     1864        /** The extension entry point. */
    18561865        PFNHGCMSVCEXT pfnExtension;
    1857         /* The extension pointer. */
     1866        /** The extension pointer. */
    18581867        void *pvExtension;
    18591868};
     
    20792088            case HGCM_MSG_QUIT:
    20802089            {
     2090                HGCMMsgMainQuit *pMsg = (HGCMMsgMainQuit *)pMsgCore;
    20812091                LogFlowFunc(("HGCM_MSG_QUIT\n"));
    20822092
    2083                 HGCMService::UnloadAll();
     2093                HGCMService::UnloadAll(pMsg->fUvmIsInvalid);
    20842094
    20852095                fQuit = true;
     
    26362646}
    26372647
    2638 int HGCMHostShutdown(void)
     2648int HGCMHostShutdown(bool fUvmIsInvalid /*= false*/)
    26392649{
    26402650    LogFlowFunc(("\n"));
     
    26492659    {
    26502660        /* Send the quit message to the main hgcmThread. */
    2651         HGCMMsgCore *pMsg;
    2652         rc = hgcmMsgAlloc(g_pHgcmThread, &pMsg, HGCM_MSG_QUIT, hgcmMainMessageAlloc);
     2661        HGCMMsgCore *pMsgCore;
     2662        rc = hgcmMsgAlloc(g_pHgcmThread, &pMsgCore, HGCM_MSG_QUIT, hgcmMainMessageAlloc);
    26532663
    26542664        if (RT_SUCCESS(rc))
    26552665        {
     2666            HGCMMsgMainQuit *pMsg = (HGCMMsgMainQuit *)pMsgCore;
     2667            pMsg->fUvmIsInvalid = fUvmIsInvalid;
     2668
    26562669            rc = hgcmMsgSend(pMsg);
    26572670
  • trunk/src/VBox/Main/src-client/VMMDevInterface.cpp

    r75500 r75574  
    5959{
    6060    /** Pointer to the VMMDev object. */
    61     VMMDev                      *pVMMDev;
     61    VMMDev                     *pVMMDev;
    6262    /** Pointer to the driver instance structure. */
    6363    PPDMDRVINS                  pDrvIns;
     
    9595{
    9696#ifdef VBOX_WITH_HGCM
    97     if (hgcmIsActive())
    98     {
    99         ASMAtomicWriteBool(&m_fHGCMActive, false);
    100         HGCMHostShutdown();
    101     }
    102 #endif /* VBOX_WITH_HGCM */
     97    if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
     98        HGCMHostShutdown(true /*fUvmIsInvalid*/);
     99#endif
    103100    RTSemEventDestroy(mCredentialsEvent);
    104101    if (mpDrv)
     
    707704}
    708705
    709 void VMMDev::hgcmShutdown(void)
    710 {
    711     ASMAtomicWriteBool(&m_fHGCMActive, false);
    712     HGCMHostShutdown();
     706/**
     707 * Used by Console::i_powerDown to shut down the services before the VM is destroyed.
     708 */
     709void VMMDev::hgcmShutdown(bool fUvmIsInvalid /*= false*/)
     710{
     711    if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
     712        HGCMHostShutdown(fUvmIsInvalid);
    713713}
    714714
     
    777777    LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
    778778
    779 #ifdef VBOX_WITH_HGCM
    780     /* HGCM is shut down on the VMMDev destructor. */
    781 #endif /* VBOX_WITH_HGCM */
    782779    if (pThis->pVMMDev)
     780    {
     781#ifdef VBOX_WITH_HGCM
     782        /* When VM construction goes wrong, we prefer shutting down HGCM here
     783           while pUVM is still valid, rather than in ~VMMDev. */
     784        if (ASMAtomicCmpXchgBool(&pThis->pVMMDev->m_fHGCMActive, false, true))
     785            HGCMHostShutdown();
     786#endif
    783787        pThis->pVMMDev->mpDrv = NULL;
     788    }
    784789}
    785790
Note: See TracChangeset for help on using the changeset viewer.

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