VirtualBox

Changeset 2936 in kBuild for trunk/src/kWorker


Ignore:
Timestamp:
Sep 18, 2016 8:47:59 PM (8 years ago)
Author:
bird
Message:

kWorker: Intercept TlsAlloc and TlsFree too, same reason as for the FlsAlloc/Free.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kWorker/kWorker.c

    r2935 r2936  
    70367036 * Thread/Fiber local storage leak prevention.
    70377037 *
    7038  * Note! The FlsAlloc/Free causes problems for statically linked VS2010
    7039  *       code like VBoxBs3ObjConverter.exe.  One thing is that we're
    7040  *       leaking these indexes, but more importantely we crash during
     7038 * Note! The FlsAlloc/Free & TlsAlloc/Free causes problems for statically
     7039 *       linked VS2010 code like VBoxBs3ObjConverter.exe.  One thing is that
     7040 *       we're leaking these indexes, but more importantely we crash during
    70417041 *       worker exit since the callback is triggered multiple times.
    70427042 */
     
    70927092            {
    70937093                pTracker->idx   = FLS_OUT_OF_INDEXES;
     7094                pTracker->pNext = NULL;
     7095                kHlpFree(pTracker);
     7096            }
     7097        }
     7098    }
     7099    return fRc;
     7100}
     7101
     7102
     7103/** Kernel32 - TlsAlloc  */
     7104DWORD WINAPI kwSandbox_Kernel32_TlsAlloc(VOID)
     7105{
     7106    DWORD idxTls = TlsAlloc();
     7107    KW_LOG(("TlsAlloc() -> %#x\n", idxTls));
     7108    if (idxTls != TLS_OUT_OF_INDEXES)
     7109    {
     7110        PKWLOCALSTORAGE pTracker = (PKWLOCALSTORAGE)kHlpAlloc(sizeof(*pTracker));
     7111        if (pTracker)
     7112        {
     7113            kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread);
     7114            pTracker->idx = idxTls;
     7115            pTracker->pNext = g_Sandbox.pTlsAllocHead;
     7116            g_Sandbox.pTlsAllocHead = pTracker;
     7117        }
     7118    }
     7119
     7120    return idxTls;
     7121}
     7122
     7123/** Kernel32 - TlsFree */
     7124BOOL WINAPI kwSandbox_Kernel32_TlsFree(DWORD idxTls)
     7125{
     7126    BOOL fRc = TlsFree(idxTls);
     7127    KW_LOG(("TlsFree(%#x) -> %d\n", idxTls, fRc));
     7128    if (fRc)
     7129    {
     7130        PKWLOCALSTORAGE pTracker;
     7131        kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread);
     7132
     7133        pTracker = g_Sandbox.pTlsAllocHead;
     7134        if (pTracker)
     7135        {
     7136            if (pTracker->idx == idxTls)
     7137                g_Sandbox.pTlsAllocHead = pTracker->pNext;
     7138            else
     7139            {
     7140                PKWLOCALSTORAGE pPrev;
     7141                do
     7142                {
     7143                    pPrev = pTracker;
     7144                    pTracker = pTracker->pNext;
     7145                } while (pTracker && pTracker->idx != idxTls);
     7146                if (pTracker)
     7147                    pPrev->pNext = pTracker->pNext;
     7148            }
     7149            if (pTracker)
     7150            {
     7151                pTracker->idx   = TLS_OUT_OF_INDEXES;
    70947152                pTracker->pNext = NULL;
    70957153                kHlpFree(pTracker);
     
    75997657    { TUPLE("FlsAlloc"),                    NULL,       (KUPTR)kwSandbox_Kernel32_FlsAlloc },
    76007658    { TUPLE("FlsFree"),                     NULL,       (KUPTR)kwSandbox_Kernel32_FlsFree },
     7659    { TUPLE("TlsAlloc"),                    NULL,       (KUPTR)kwSandbox_Kernel32_TlsAlloc },
     7660    { TUPLE("TlsFree"),                     NULL,       (KUPTR)kwSandbox_Kernel32_TlsFree },
    76017661
    76027662    { TUPLE("SetConsoleCtrlHandler"),       NULL,       (KUPTR)kwSandbox_Kernel32_SetConsoleCtrlHandler },
     
    77557815    { TUPLE("FlsAlloc"),                    NULL,       (KUPTR)kwSandbox_Kernel32_FlsAlloc },
    77567816    { TUPLE("FlsFree"),                     NULL,       (KUPTR)kwSandbox_Kernel32_FlsFree },
     7817    { TUPLE("TlsAlloc"),                    NULL,       (KUPTR)kwSandbox_Kernel32_TlsAlloc },
     7818    { TUPLE("TlsFree"),                     NULL,       (KUPTR)kwSandbox_Kernel32_TlsFree },
    77577819};
    77587820/** Number of entries in g_aSandboxGetProcReplacements. */
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