VirtualBox

Changeset 2874 in kBuild


Ignore:
Timestamp:
Sep 4, 2016 7:45:29 PM (9 years ago)
Author:
bird
Message:

Deal with FlSAlloc leak.

File:
1 edited

Legend:

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

    r2871 r2874  
    331331} KWVIRTALLOC;
    332332
     333
     334/** Pointer to a FlsAlloc/TlsAlloc tracker entry. */
     335typedef struct KWLOCALSTORAGE *PKWLOCALSTORAGE;
     336/**
     337 * Tracking an FlsAlloc/TlsAlloc index.
     338 */
     339typedef struct KWLOCALSTORAGE
     340{
     341    PKWLOCALSTORAGE     pNext;
     342    KU32                idx;
     343} KWLOCALSTORAGE;
     344
     345
    333346typedef enum KWTOOLTYPE
    334347{
     
    440453    /** Head of the virtual alloc allocations. */
    441454    PKWVIRTALLOC    pVirtualAllocHead;
     455    /** Head of the FlsAlloc indexes. */
     456    PKWLOCALSTORAGE pFlsAllocHead;
     457    /** Head of the TlsAlloc indexes. */
     458    PKWLOCALSTORAGE pTlsAllocHead;
    442459
    443460    UNICODE_STRING  SavedCommandLine;
     
    43614378
    43624379
     4380
    43634381/*
    43644382 *
    4365  * Virtual memory management.
    4366  * Virtual memory management.
    4367  * Virtual memory management.
    4368  *
    4369  */
    4370 
     4383 * Virtual memory leak prevension.
     4384 * Virtual memory leak prevension.
     4385 * Virtual memory leak prevension.
     4386 *
     4387 */
    43714388
    43724389/** Kernel32 - VirtualAlloc - for c1[xx].dll 78GB leaks.   */
     
    44404457/*
    44414458 *
     4459 * Thread/Fiber local storage leak prevention.
     4460 * Thread/Fiber local storage leak prevention.
     4461 * Thread/Fiber local storage leak prevention.
     4462 *
     4463 * Note! The FlsAlloc/Free causes problems for statically linked VS2010
     4464 *       code like VBoxBs3ObjConverter.exe.  One thing is that we're
     4465 *       leaking these indexes, but more importantely we crash during
     4466 *       worker exit since the callback is triggered multiple times.
     4467 */
     4468
     4469
     4470/** Kernel32 - FlsAlloc  */
     4471DWORD WINAPI kwSandbox_Kernel32_FlsAlloc(PFLS_CALLBACK_FUNCTION pfnCallback)
     4472{
     4473    DWORD idxFls = FlsAlloc(pfnCallback);
     4474    KW_LOG(("FlsAlloc(%p) -> %#x\n", pfnCallback, idxFls));
     4475    if (idxFls != FLS_OUT_OF_INDEXES)
     4476    {
     4477        PKWLOCALSTORAGE pTracker = (PKWLOCALSTORAGE)kHlpAlloc(sizeof(*pTracker));
     4478        if (pTracker)
     4479        {
     4480            pTracker->idx = idxFls;
     4481            pTracker->pNext = g_Sandbox.pFlsAllocHead;
     4482            g_Sandbox.pFlsAllocHead = pTracker;
     4483        }
     4484    }
     4485
     4486    return idxFls;
     4487}
     4488
     4489/** Kernel32 - FlsFree */
     4490BOOL WINAPI kwSandbox_Kernel32_FlsFree(DWORD idxFls)
     4491{
     4492    BOOL fRc = FlsFree(idxFls);
     4493    KW_LOG(("FlsFree(%#x) -> %d\n", idxFls, fRc));
     4494    if (fRc)
     4495    {
     4496        PKWLOCALSTORAGE pTracker = g_Sandbox.pFlsAllocHead;
     4497        if (pTracker)
     4498        {
     4499            if (pTracker->idx == idxFls)
     4500                g_Sandbox.pFlsAllocHead = pTracker->pNext;
     4501            else
     4502            {
     4503                PKWLOCALSTORAGE pPrev;
     4504                do
     4505                {
     4506                    pPrev = pTracker;
     4507                    pTracker = pTracker->pNext;
     4508                } while (pTracker && pTracker->idx != idxFls);
     4509                if (pTracker)
     4510                    pPrev->pNext = pTracker->pNext;
     4511            }
     4512            if (pTracker)
     4513            {
     4514                pTracker->idx   = FLS_OUT_OF_INDEXES;
     4515                pTracker->pNext = NULL;
     4516                kHlpFree(pTracker);
     4517            }
     4518        }
     4519    }
     4520    return fRc;
     4521}
     4522
     4523
     4524
     4525/*
     4526 *
    44424527 * Misc function only intercepted while debugging.
    44434528 * Misc function only intercepted while debugging.
     
    45234608    { TUPLE("VirtualAlloc"),                NULL,       (KUPTR)kwSandbox_Kernel32_VirtualAlloc },
    45244609    { TUPLE("VirtualFree"),                 NULL,       (KUPTR)kwSandbox_Kernel32_VirtualFree },
     4610
     4611    { TUPLE("FlsAlloc"),                    NULL,       (KUPTR)kwSandbox_Kernel32_FlsAlloc },
     4612    { TUPLE("FlsFree"),                     NULL,       (KUPTR)kwSandbox_Kernel32_FlsFree },
    45254613
    45264614    /*
     
    49265014{
    49275015    PKWVIRTALLOC pTracker;
     5016    PKWLOCALSTORAGE pLocalStorage;
    49285017#ifdef WITH_TEMP_MEMORY_FILES
    49295018    PKWFSTEMPFILE pTempFile;
     
    49615050        pTracker = pNext;
    49625051    }
     5052
     5053    /* Free left behind FlsAlloc leaks. */
     5054    pLocalStorage = g_Sandbox.pFlsAllocHead;
     5055    g_Sandbox.pFlsAllocHead = NULL;
     5056    while (pLocalStorage)
     5057    {
     5058        PKWLOCALSTORAGE pNext = pLocalStorage->pNext;
     5059        KW_LOG(("Freeing leaded FlsAlloc index %#x\n", pLocalStorage->idx));
     5060        FlsFree(pLocalStorage->idx);
     5061        kHlpFree(pLocalStorage);
     5062        pLocalStorage = pNext;
     5063    }
     5064
     5065    /* Free left behind TlsAlloc leaks. */
     5066    pLocalStorage = g_Sandbox.pTlsAllocHead;
     5067    g_Sandbox.pTlsAllocHead = NULL;
     5068    while (pLocalStorage)
     5069    {
     5070        PKWLOCALSTORAGE pNext = pLocalStorage->pNext;
     5071        KW_LOG(("Freeing leaded TlsAlloc index %#x\n", pLocalStorage->idx));
     5072        TlsFree(pLocalStorage->idx);
     5073        kHlpFree(pLocalStorage);
     5074        pLocalStorage = pNext;
     5075    }
     5076
    49635077}
    49645078
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