VirtualBox

Changeset 63639 in vbox


Ignore:
Timestamp:
Aug 25, 2016 2:31:10 PM (8 years ago)
Author:
vboxsync
Message:

VBoxC: Looks like VirtualBoxClient::Data::m_pEventSource is holding in extra reference on the ATL module, causing VBoxC to be unloaded too late because DllCanUnloadNow() returns S_FALSE due to GetLockCount() being 1 instead of 0. Created a hack for discounting the module lock held by the EventSource in the VirtualBoxClient singelton.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/VirtualBoxClientImpl.h

    r62258 r63639  
    6666    struct Data
    6767    {
    68         Data()
     68        Data() : m_ThreadWatcher(NIL_RTTHREAD), m_SemEvWatcher(NIL_RTSEMEVENT)
    6969        {}
     70
     71        ~Data()
     72        {
     73            /* HACK ALERT! This is for DllCanUnloadNow(). */
     74            if (m_pEventSource.isNotNull())
     75            {
     76                s_cUnnecessaryAtlModuleLocks--;
     77                AssertMsg(s_cUnnecessaryAtlModuleLocks == 0, ("%d\n", s_cUnnecessaryAtlModuleLocks));
     78            }
     79        }
    7080
    7181        ComPtr<IVirtualBox> m_pVirtualBox;
     
    7787
    7888    Data mData;
     89
     90public:
     91    /** Hack for discounting the AtlModule lock held by Data::m_pEventSource during
     92     * DllCanUnloadNow().  This is incremented to 1 when init() initialized
     93     * m_pEventSource and is decremented by the Data destructor (above). */
     94    static LONG s_cUnnecessaryAtlModuleLocks;
    7995};
    8096
    81 #endif // ____H_VIRTUALBOXCLIENTIMPL
     97#endif
    8298/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/src-client/VirtualBoxClientImpl.cpp

    r61117 r63639  
    3737uint32_t VirtualBoxClient::g_cInstances = 0;
    3838
     39LONG VirtualBoxClient::s_cUnnecessaryAtlModuleLocks = 0;
    3940
    4041// constructor / destructor
     
    104105        AssertComRCThrow(rc, setError(rc,
    105106                                      tr("Could not initialize EventSource for VirtualBoxClient")));
     107
     108        /* HACK ALERT! This is for DllCanUnloadNow(). */
     109        s_cUnnecessaryAtlModuleLocks++;
     110        AssertMsg(s_cUnnecessaryAtlModuleLocks == 1, ("%d\n", s_cUnnecessaryAtlModuleLocks));
    106111
    107112        /* Setting up the VBoxSVC watcher thread. If anything goes wrong here it
  • trunk/src/VBox/Main/src-client/win/dllmain.cpp

    r60865 r63639  
    7575{
    7676    AssertReturn(g_pAtlComModule, S_OK);
    77     return g_pAtlComModule->GetLockCount() == 0 ? S_OK : S_FALSE;
     77    LONG const cLocks = g_pAtlComModule->GetLockCount();
     78    Assert(cLocks >= VirtualBoxClient::s_cUnnecessaryAtlModuleLocks);
     79    return cLocks <= VirtualBoxClient::s_cUnnecessaryAtlModuleLocks ? S_OK : S_FALSE;
    7880}
    7981
     
    8385STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
    8486{
     87    HRESULT hrc;
    8588    AssertReturn(g_pAtlComModule, E_UNEXPECTED);
    8689    return g_pAtlComModule->GetClassObject(rclsid, riid, ppv);
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