Changeset 2869 for trunk/src


Ignore:
Timestamp:
Sep 4, 2016, 3:48:28 PM (9 years ago)
Author:
bird
Message:

updates

Location:
trunk/src
Files:
2 edited

Legend:

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

    r2868 r2869  
    9494#endif
    9595
     96/** Marks unfinished code.  */
     97#if 1
     98# define KWFS_TODO()    do { kwErrPrintf("\nHit TODO on line %u in %s!\n", __LINE__, __FUNCTION__); __debugbreak(); } while (0)
     99#else
     100# define KWFS_TODO()    do { kwErrPrintf("\nHit TODO on line %u in %s!\n", __LINE__, __FUNCTION__); } while (0)
     101#endif
    96102
    97103/** User data key for tools. */
     
    313319
    314320
     321/** Pointer to a VirtualAlloc tracker entry. */
     322typedef struct KWVIRTALLOC *PKWVIRTALLOC;
     323/**
     324 * Tracking an VirtualAlloc allocation.
     325 */
     326typedef struct KWVIRTALLOC
     327{
     328    PKWVIRTALLOC        pNext;
     329    void               *pvAlloc;
     330    KSIZE               cbAlloc;
     331} KWVIRTALLOC;
     332
    315333typedef enum KWTOOLTYPE
    316334{
     
    417435    /** Head of the list of temporary file. */
    418436    PKWFSTEMPFILE   pTempFileHead;
     437
     438    /** Head of the virtual alloc allocations. */
     439    PKWVIRTALLOC    pVirtualAllocHead;
    419440
    420441    UNICODE_STRING  SavedCommandLine;
     
    19812002        longjmp(g_Sandbox.JmpBuf, 1);
    19822003    }
    1983     __debugbreak();
     2004    KWFS_TODO();
    19842005}
    19852006
     
    19902011    if (hProcess == GetCurrentProcess())
    19912012        kwSandbox_Kernel32_ExitProcess(uExitCode);
    1992     __debugbreak();
     2013    KWFS_TODO();
    19932014    return TerminateProcess(hProcess, uExitCode);
    19942015}
     
    21762197static void kwSandbox_msvcrt__wincmdln(void)
    21772198{
    2178     __debugbreak();
     2199    KWFS_TODO();
    21792200}
    21802201
     
    21832204static void kwSandbox_msvcrt__wwincmdln(void)
    21842205{
    2185     __debugbreak();
     2206    KWFS_TODO();
    21862207}
    21872208
     
    21912212                                                     DWORD fFlags, PDWORD pidThread)
    21922213{
    2193     __debugbreak();
     2214    KWFS_TODO();
    21942215    return NULL;
    21952216}
     
    21992220static uintptr_t __cdecl kwSandbox_msvcrt__beginthread(void (__cdecl *pfnThreadProc)(void *), unsigned cbStack, void *pvUser)
    22002221{
    2201     __debugbreak();
     2222    KWFS_TODO();
    22022223    return 0;
    22032224}
     
    22092230                                                         unsigned fCreate, unsigned *pidThread)
    22102231{
    2211     __debugbreak();
     2232    KWFS_TODO();
    22122233    return 0;
    22132234}
     
    22252246static DWORD WINAPI kwSandbox_Kernel32_GetEnvironmentVariableA(LPCSTR pwszVar, LPSTR pszValue, DWORD cbValue)
    22262247{
    2227     __debugbreak();
     2248    KWFS_TODO();
    22282249    return 0;
    22292250}
     
    22342255{
    22352256    KW_LOG(("GetEnvironmentVariableW: '%ls'\n", pwszVar));
    2236     //__debugbreak();
     2257    //KWFS_TODO();
    22372258    //SetLastError(ERROR_ENVVAR_NOT_FOUND);
    22382259    //return 0;
     
    22442265static BOOL WINAPI kwSandbox_Kernel32_SetEnvironmentVariableA(LPCSTR pszVar, LPCSTR pszValue)
    22452266{
    2246     __debugbreak();
     2267    KWFS_TODO();
    22472268    return FALSE;
    22482269}
     
    22542275    KW_LOG(("SetEnvironmentVariableW: '%ls' = '%ls'\n", pwszVar, pwszValue));
    22552276    return SetEnvironmentVariableW(pwszVar, pwszValue);
    2256     //__debugbreak();
     2277    //KWFS_TODO();
    22572278    //return FALSE;
    22582279}
     
    22622283static DWORD WINAPI kwSandbox_Kernel32_ExpandEnvironmentStringsA(LPCSTR pszSrc, LPSTR pwszDst, DWORD cbDst)
    22632284{
    2264     __debugbreak();
     2285    KWFS_TODO();
    22652286    return 0;
    22662287}
     
    22702291static DWORD WINAPI kwSandbox_Kernel32_ExpandEnvironmentStringsW(LPCWSTR pwszSrc, LPWSTR pwszDst, DWORD cbDst)
    22712292{
    2272     __debugbreak();
     2293    KWFS_TODO();
    22732294    return 0;
    22742295}
     
    22782299static int __cdecl kwSandbox_msvcrt__putenv(const char *pszVarEqualValue)
    22792300{
    2280     __debugbreak();
     2301    KWFS_TODO();
    22812302    return 0;
    22822303}
     
    22862307static int __cdecl kwSandbox_msvcrt__wputenv(const wchar_t *pwszVarEqualValue)
    22872308{
    2288     __debugbreak();
     2309    KWFS_TODO();
    22892310    return 0;
    22902311}
     
    22942315static errno_t __cdecl kwSandbox_msvcrt__putenv_s(const char *pszVar, const char *pszValue)
    22952316{
    2296     __debugbreak();
     2317    KWFS_TODO();
    22972318    return 0;
    22982319}
     
    23032324{
    23042325    KW_LOG(("_wputenv_s: '%ls' = '%ls'\n", pwszVar, pwszValue));
    2305     //__debugbreak();
     2326    //KWFS_TODO();
    23062327    return SetEnvironmentVariableW(pwszVar, pwszValue) ? 0 : -1;
    23072328}
     
    23402361static KUPTR /*void*/ __cdecl kwSandbox_msvcrt__get_environ(char ***ppapszEnviron)
    23412362{
    2342     __debugbreak(); /** @todo check the callers expecations! */
     2363    KWFS_TODO(); /** @todo check the callers expecations! */
    23432364    *ppapszEnviron = g_Sandbox.environ;
    23442365    return 0;
     
    23502371static KUPTR /*void*/ __cdecl kwSandbox_msvcrt__get_wenviron(wchar_t ***ppapwszEnviron)
    23512372{
    2352     __debugbreak(); /** @todo check the callers expecations! */
     2373    KWFS_TODO(); /** @todo check the callers expecations! */
    23532374    *ppapwszEnviron = g_Sandbox.wenviron;
    23542375    return 0;
     
    23792400    if (rc != 0)
    23802401    {
    2381         __debugbreak();
     2402        KWFS_TODO();
    23822403        return LoadLibraryExA(pszFilename, hFile, fFlags);
    23832404    }
     
    23912412            if (pDynLoad->pMod == NULL)
    23922413                return pDynLoad->hmod;
    2393             __debugbreak();
     2414            KWFS_TODO();
    23942415        }
    23952416
     
    24142435        }
    24152436        else
    2416             __debugbreak();
     2437            KWFS_TODO();
    24172438    }
    24182439    return hmod;
     
    24512472            if (pDynLoad->pMod != NULL)
    24522473                return pDynLoad->hmod;
    2453             __debugbreak();
     2474            KWFS_TODO();
    24542475        }
    24552476
     
    24822503                }
    24832504
    2484                 __debugbreak();
     2505                KWFS_TODO();
    24852506            }
    24862507            else
    2487                 __debugbreak();
     2508                KWFS_TODO();
    24882509        }
    24892510        else
    2490             __debugbreak();
     2511            KWFS_TODO();
    24912512    }
    24922513    return hmod;
     
    25042525        || (hFile != NULL && hFile != INVALID_HANDLE_VALUE) )
    25052526    {
    2506         __debugbreak();
     2527        KWFS_TODO();
    25072528        return LoadLibraryExA(pszFilename, hFile, fFlags);
    25082529    }
     
    25182539        if (kHlpIsFilenameOnly(pszFilename))
    25192540        {
    2520             __debugbreak();
     2541            KWFS_TODO();
    25212542            return LoadLibraryExA(pszFilename, hFile, fFlags);
    25222543        }
     
    25362557    else
    25372558    {
    2538 __debugbreak();
     2559        KWFS_TODO();
    25392560        rc = kwLdrModuleResolveAndLookup(pszFilename, g_Sandbox.pTool->u.Sandboxed.pExe, NULL /*pImporter*/, &pMod);
    25402561        if (rc != 0)
     
    25432564    if (!pMod)
    25442565    {
    2545         __debugbreak();
     2566        KWFS_TODO();
    25462567        SetLastError(ERROR_MOD_NOT_FOUND);
    25472568        return NULL;
     
    25742595    }
    25752596
    2576     __debugbreak();
     2597    KWFS_TODO();
    25772598    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
    25782599    kwLdrModuleRelease(pMod);
     
    25892610        return kwSandbox_Kernel32_LoadLibraryExA(szTmp, hFile, fFlags);
    25902611
    2591     __debugbreak();
     2612    KWFS_TODO();
    25922613    SetLastError(ERROR_FILENAME_EXCED_RANGE);
    25932614    return NULL;
     
    26082629    if (cchTmp < sizeof(szTmp))
    26092630        return kwSandbox_Kernel32_LoadLibraryExA(szTmp, NULL /*hFile*/, 0 /*fFlags*/);
    2610     __debugbreak();
     2631    KWFS_TODO();
    26112632    SetLastError(ERROR_FILENAME_EXCED_RANGE);
    26122633    return NULL;
     
    26472668        }
    26482669
    2649     __debugbreak();
     2670    KWFS_TODO();
    26502671    return NULL;
    26512672}
     
    26772698        }
    26782699
    2679     __debugbreak();
     2700    KWFS_TODO();
    26802701    return NULL;
    26812702}
     
    26972718            if (pDynLoad->pMod)
    26982719                return kwLdrModuleRetain(pDynLoad->pMod);
    2699             __debugbreak();
     2720            KWFS_TODO();
    27002721            return NULL;
    27012722        }
     
    27082729static UINT WINAPI kwSandbox_BreakIntoDebugger(void *pv1, void *pv2, void *pv3, void *pv4)
    27092730{
    2710     __debugbreak();
     2731    KWFS_TODO();
    27112732    return -1;
    27122733}
     
    27462767        }
    27472768
    2748         __debugbreak();
     2769        KWFS_TODO();
    27492770        SetLastError(ERROR_PROC_NOT_FOUND);
    27502771        kwLdrModuleRelease(pMod);
     
    27592780            return GetProcAddress(hmod, pszProc);
    27602781
    2761     __debugbreak();
     2782    KWFS_TODO();
    27622783    return GetProcAddress(hmod, pszProc);
    27632784}
     
    27742795        return cbRet;
    27752796    }
    2776     __debugbreak();
     2797    KWFS_TODO();
    27772798    return 0;
    27782799}
     
    27902811    }
    27912812
    2792     __debugbreak();
     2813    KWFS_TODO();
    27932814    return 0;
    27942815}
     
    37653786                else
    37663787                {
    3767                     cbNewSeg = 64*1024*1024;
     3788                    cbNewSeg = 64*1024;
    37683789                    rc = kHlpPageAlloc((void **)&pTempFile->paSegs[cSegs].pbData, cbNewSeg, KPROT_READWRITE, K_FALSE);
    37693790                    if (rc != 0)
     3791                    {
     3792                        kHlpAssertFailed();
    37703793                        return K_FALSE;
     3794                    }
    37713795                }
    37723796                pTempFile->paSegs[cSegs].offData     = pTempFile->cbFileAllocated;
     
    38473871                    }
    38483872
     3873                    kHlpAssertFailed();
    38493874                    *pcbActuallyWritten = 0;
    38503875                    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
     
    42824307
    42834308
    4284 /** Kernel32 - GetShortPathNameW - cl1[xx].dll of VS2010 does this to the
     4309/** Kernel32 - GetShortPathNameW - c1[xx].dll of VS2010 does this to the
    42854310 * directory containing each include file.  We cache the result to speed
    42864311 * things up a little. */
     
    43314356              pwszLongPath, K_MIN(cwcShortPath, cwcRet), K_MIN(cwcShortPath, cwcRet), pwszShortPath, cwcRet));
    43324357    return cwcRet;
     4358}
     4359
     4360
     4361/*
     4362 *
     4363 * Virtual memory management.
     4364 * Virtual memory management.
     4365 * Virtual memory management.
     4366 *
     4367 */
     4368
     4369
     4370/** Kernel32 - VirtualAlloc - for c1[xx].dll 78GB leaks.   */
     4371static PVOID WINAPI kwSandbox_Kernel32_VirtualAlloc(PVOID pvAddr, SIZE_T cb, DWORD fAllocType, DWORD fProt)
     4372{
     4373    PVOID pvMem = VirtualAlloc(pvAddr, cb, fAllocType, fProt);
     4374    KW_LOG(("VirtualAlloc: pvAddr=%p cb=%p type=%#x prot=%#x -> %p (last=%d)\n",
     4375            pvAddr, cb, fAllocType, fProt, pvMem, GetLastError()));
     4376    if (   g_Sandbox.pTool->u.Sandboxed.enmHint == KWTOOLHINT_VISUAL_CPP_CL
     4377        && pvMem)
     4378    {
     4379        PKWVIRTALLOC pTracker = g_Sandbox.pVirtualAllocHead;
     4380        while (   pTracker
     4381               && (KUPTR)pvMem - (KUPTR)pTracker->pvAlloc >= pTracker->cbAlloc)
     4382            pTracker = pTracker->pNext;
     4383        if (!pTracker)
     4384        {
     4385            DWORD dwErr = GetLastError();
     4386            PKWVIRTALLOC pTracker = (PKWVIRTALLOC)kHlpAlloc(sizeof(*pTracker));
     4387            if (pTracker)
     4388            {
     4389                pTracker->pvAlloc = pvMem;
     4390                pTracker->cbAlloc = cb;
     4391                pTracker->pNext   = g_Sandbox.pVirtualAllocHead;
     4392                g_Sandbox.pVirtualAllocHead = pTracker;
     4393            }
     4394            SetLastError(dwErr);
     4395        }
     4396    }
     4397    return pvMem;
     4398}
     4399
     4400
     4401/** Kernel32 - VirtualFree.   */
     4402static BOOL WINAPI kwSandbox_Kernel32_VirtualFree(PVOID pvAddr, SIZE_T cb, DWORD dwFreeType)
     4403{
     4404    BOOL fRc = VirtualFree(pvAddr, cb, dwFreeType);
     4405    KW_LOG(("VirtualFree: pvAddr=%p cb=%p type=%#x -> %d\n", pvAddr, cb, dwFreeType, fRc));
     4406    if (g_Sandbox.pTool->u.Sandboxed.enmHint == KWTOOLHINT_VISUAL_CPP_CL)
     4407    {
     4408        if (dwFreeType & MEM_RELEASE)
     4409        {
     4410            PKWVIRTALLOC pTracker = g_Sandbox.pVirtualAllocHead;
     4411            if (pTracker)
     4412            {
     4413                if (pTracker->pvAlloc == pvAddr)
     4414                    g_Sandbox.pVirtualAllocHead = pTracker->pNext;
     4415                else
     4416                {
     4417                    PKWVIRTALLOC pPrev;
     4418                    do
     4419                    {
     4420                        pPrev = pTracker;
     4421                        pTracker = pTracker->pNext;
     4422                    } while (pTracker && pTracker->pvAlloc != pvAddr);
     4423                    if (pTracker)
     4424                        pPrev->pNext = pTracker->pNext;
     4425                }
     4426                if (pTracker)
     4427                    kHlpFree(pTracker);
     4428                else
     4429                    KW_LOG(("VirtualFree: pvAddr=%p not found!\n", pvAddr));
     4430            }
     4431        }
     4432    }
     4433    return fRc;
    43334434}
    43344435
     
    44184519    { TUPLE("GetShortPathNameW"),           NULL,       (KUPTR)kwSandbox_Kernel32_GetShortPathNameW },
    44194520
     4521    { TUPLE("VirtualAlloc"),                NULL,       (KUPTR)kwSandbox_Kernel32_VirtualAlloc },
     4522    { TUPLE("VirtualFree"),                 NULL,       (KUPTR)kwSandbox_Kernel32_VirtualFree },
     4523
    44204524    /*
    44214525     * MS Visual C++ CRTs.
     
    47264830static void kwSandboxCleanup(PKWSANDBOX pSandbox)
    47274831{
     4832    PKWVIRTALLOC pTracker;
    47284833#ifdef WITH_TEMP_MEMORY_FILES
    47294834    PKWFSTEMPFILE pTempFile;
     
    47504855#endif
    47514856
     4857    /* Free left behind VirtualAlloc leaks. */
     4858    pTracker = g_Sandbox.pVirtualAllocHead;
     4859    g_Sandbox.pVirtualAllocHead = NULL;
     4860    while (pTracker)
     4861    {
     4862        PKWVIRTALLOC pNext = pTracker->pNext;
     4863        KW_LOG(("Freeing VirtualFree leak %p LB %#x\n", pTracker->pvAlloc, pTracker->cbAlloc));
     4864        VirtualFree(pTracker->pvAlloc, 0, MEM_RELEASE);
     4865        kHlpFree(pTracker);
     4866        pTracker = pNext;
     4867    }
    47524868}
    47534869
  • trunk/src/kmk/incdep.c

    r2861 r2869  
    501501  size_t const cbFile = (size_t)cur->pFileObj->Stats.st_size;
    502502
    503   assert(cur->pFileObj->fFlags);
     503  assert(cur->pFileObj->fHaveStats);
    504504  cur->file_base = incdep_xmalloc (cur, cbFile + 1);
    505505  if (cur->file_base)
Note: See TracChangeset for help on using the changeset viewer.