VirtualBox

Changeset 2867 in kBuild for trunk/src/kWorker/kWorker.c


Ignore:
Timestamp:
Sep 3, 2016 10:08:56 PM (8 years ago)
Author:
bird
Message:

Made 32-bit kWorker work.

File:
1 edited

Legend:

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

    r2865 r2867  
    209209
    210210/**
     211 * GetModuleHandle cache for system modules frequently queried.
     212 */
     213typedef struct KWGETMODULEHANDLECACHE
     214{
     215    const char     *pszName;
     216    KU8             cchName;
     217    KU8             cwcName;
     218    const wchar_t  *pwszName;
     219    HANDLE          hmod;
     220} KWGETMODULEHANDLECACHE;
     221typedef KWGETMODULEHANDLECACHE *PKWGETMODULEHANDLECACHE;
     222
     223
     224/**
    211225 * A cached file.
    212226 */
     
    361375    /** Copy of the NT TIB of the main thread. */
    362376    NT_TIB      TibMainThread;
     377    /** The NT_TIB::ExceptionList value inside the try case.
     378     * We restore this prior to the longjmp.  */
     379    void       *pOutXcptListHead;
    363380    /** The exit code in case of longjmp.   */
    364381    int         rcExitCode;
     
    446463/** Module hash table. */
    447464static PKWMODULE    g_apModules[127];
     465
     466/** GetModuleHandle cache. */
     467static KWGETMODULEHANDLECACHE g_aGetModuleHandleCache[] =
     468{
     469#define MOD_CACHE_STRINGS(str) str, sizeof(str) - 1, (sizeof(L##str) / sizeof(wchar_t)) - 1, L##str
     470    { MOD_CACHE_STRINGS("KERNEL32.DLL"),    NULL },
     471    { MOD_CACHE_STRINGS("mscoree.dll"),     NULL },
     472};
     473
    448474
    449475/** The file system cache. */
     
    967993static void kwLdrModuleDoNativeImportReplacements(PKWMODULE pMod)
    968994{
    969     KSIZE const                 cbImage = kLdrModSize(pMod->pLdrMod);
     995    KSIZE const                 cbImage = (KSIZE)kLdrModSize(pMod->pLdrMod);
    970996    KU8 const * const           pbImage = (KU8 const *)pMod->hOurMod;
    971997    IMAGE_DOS_HEADER const     *pMzHdr  = (IMAGE_DOS_HEADER const *)pbImage;
     
    9811007    if (pMzHdr->e_magic == IMAGE_DOS_SIGNATURE)
    9821008    {
    983         kHlpAssertReturnVoid(pMzHdr->e_lfanew <= cbImage - sizeof(*pNtHdrs));
     1009        kHlpAssertReturnVoid((KU32)pMzHdr->e_lfanew <= cbImage - sizeof(*pNtHdrs));
    9841010        pNtHdrs = (IMAGE_NT_HEADERS const *)&pbImage[pMzHdr->e_lfanew];
    9851011    }
     
    11151141
    11161142/**
     1143 * Creates a module from a native kLdr module handle.
     1144 *
     1145 * @returns Module w/ 1 reference on success, NULL on failure.
     1146 * @param   pLdrMod             The native kLdr module.
     1147 * @param   pszPath             The normalized path to the module.
     1148 * @param   cbPath              The module path length with terminator.
     1149 * @param   uHashPath           The module path hash.
     1150 * @param   fDoReplacements     Whether to do import replacements on this
     1151 *                              module.
     1152 */
     1153static PKWMODULE kwLdrModuleCreateForNativekLdrModule(PKLDRMOD pLdrMod, const char *pszPath, KSIZE cbPath, KU32 uHashPath,
     1154                                                      KBOOL fDoReplacements)
     1155{
     1156    /*
     1157     * Create the entry.
     1158     */
     1159    PKWMODULE pMod   = (PKWMODULE)kHlpAllocZ(sizeof(*pMod) + cbPath + cbPath * 2 * sizeof(wchar_t));
     1160    if (pMod)
     1161    {
     1162        pMod->pwszPath      = (wchar_t *)(pMod + 1);
     1163        kwStrToUtf16(pszPath, (wchar_t *)pMod->pwszPath, cbPath * 2);
     1164        pMod->pszPath       = (char *)kHlpMemCopy((char *)&pMod->pwszPath[cbPath * 2], pszPath, cbPath);
     1165        pMod->uHashPath     = uHashPath;
     1166        pMod->cRefs         = 1;
     1167        pMod->offFilename   = (KU16)(kHlpGetFilename(pszPath) - pszPath);
     1168        pMod->fExe          = K_FALSE;
     1169        pMod->fNative       = K_TRUE;
     1170        pMod->pLdrMod       = pLdrMod;
     1171        pMod->hOurMod       = (HMODULE)(KUPTR)pLdrMod->aSegments[0].MapAddress;
     1172
     1173        if (fDoReplacements)
     1174        {
     1175            DWORD const dwSavedErr = GetLastError();
     1176            kwLdrModuleDoNativeImportReplacements(pMod);
     1177            SetLastError(dwSavedErr);
     1178        }
     1179
     1180        KW_LOG(("New module: %p LB %#010x %s (native)\n",
     1181                (KUPTR)pMod->pLdrMod->aSegments[0].MapAddress, kLdrModSize(pMod->pLdrMod), pMod->pszPath));
     1182        return kwLdrModuleLink(pMod);
     1183    }
     1184    return NULL;
     1185}
     1186
     1187
     1188
     1189/**
    11171190 * Creates a module using the native loader.
    11181191 *
     
    11321205    if (rc == 0)
    11331206    {
    1134         /*
    1135          * Create the entry.
    1136          */
    1137         KSIZE     cbPath = kHlpStrLen(pszPath) + 1;
    1138         PKWMODULE pMod   = (PKWMODULE)kHlpAllocZ(sizeof(*pMod) + cbPath + 1 + cbPath * 2 * sizeof(wchar_t));
     1207        PKWMODULE pMod = kwLdrModuleCreateForNativekLdrModule(pLdrMod, pszPath, kHlpStrLen(pszPath) + 1,
     1208                                                              uHashPath, fDoReplacements);
    11391209        if (pMod)
    1140         {
    1141             pMod->pszPath       = (char *)kHlpMemCopy(pMod + 1, pszPath, cbPath);
    1142             pMod->pwszPath      = (wchar_t *)(pMod->pszPath + cbPath + (cbPath & 1));
    1143             kwStrToUtf16(pMod->pszPath, (wchar_t *)pMod->pwszPath, cbPath * 2);
    1144             pMod->uHashPath     = uHashPath;
    1145             pMod->cRefs         = 1;
    1146             pMod->offFilename   = (KU16)(kHlpGetFilename(pszPath) - pszPath);
    1147             pMod->fExe          = K_FALSE;
    1148             pMod->fNative       = K_TRUE;
    1149             pMod->pLdrMod       = pLdrMod;
    1150             pMod->hOurMod       = (HMODULE)(KUPTR)pLdrMod->aSegments[0].MapAddress;
    1151 
    1152             if (fDoReplacements)
    1153             {
    1154                 DWORD const dwSavedErr = GetLastError();
    1155                 kwLdrModuleDoNativeImportReplacements(pMod);
    1156                 SetLastError(dwSavedErr);
    1157             }
    1158 
    1159             KW_LOG(("New module: %p LB %#010x %s (native)\n",
    1160                     (KUPTR)pMod->pLdrMod->aSegments[0].MapAddress, kLdrModSize(pMod->pLdrMod), pMod->pszPath));
    1161             return kwLdrModuleLink(pMod);
    1162         }
    1163         //kLdrModClose(pLdrMod);
     1210            return pMod;
     1211        kLdrModClose(pLdrMod);
    11641212    }
    11651213    return NULL;
     
    12461294                          || pLdrMod->enmType == KLDRTYPE_SHARED_LIBRARY_FIXED;
    12471295                    pMod->u.Manual.pvLoad = fFixed ? (void *)(KUPTR)pLdrMod->aSegments[0].LinkAddress : NULL;
    1248                     pMod->u.Manual.cbImage = kLdrModSize(pLdrMod);
     1296                    pMod->u.Manual.cbImage = (KSIZE)kLdrModSize(pLdrMod);
    12491297                    if (   !fFixed
    12501298                        || pLdrMod->enmType != KLDRTYPE_EXECUTABLE_FIXED /* only allow fixed executables */
     
    19291977           exception chain stuff installed by the sandboxed executable. */
    19301978        *pTib = g_Sandbox.TibMainThread;
     1979        pTib->ExceptionList = g_Sandbox.pOutXcptListHead;
    19311980
    19321981        longjmp(g_Sandbox.JmpBuf, 1);
     
    20392088static VOID WINAPI kwSandbox_Kernel32_GetStartupInfoA(LPSTARTUPINFOA pStartupInfo)
    20402089{
    2041     __debugbreak();
     2090    KW_LOG(("GetStartupInfoA\n"));
     2091    GetStartupInfoA(pStartupInfo);
     2092    pStartupInfo->lpReserved  = NULL;
     2093    pStartupInfo->lpTitle     = NULL;
     2094    pStartupInfo->lpReserved2 = NULL;
     2095    pStartupInfo->cbReserved2 = 0;
    20422096}
    20432097
    20442098
    20452099/** Kernel32 - GetStartupInfoW()  */
    2046 static VOID WINAPI kwSandbox_Kernel32_GetStartupInfoW(LPSTARTUPINFOW lpStartupInfo)
    2047 {
    2048     __debugbreak();
     2100static VOID WINAPI kwSandbox_Kernel32_GetStartupInfoW(LPSTARTUPINFOW pStartupInfo)
     2101{
     2102    KW_LOG(("GetStartupInfoW\n"));
     2103    GetStartupInfoW(pStartupInfo);
     2104    pStartupInfo->lpReserved  = NULL;
     2105    pStartupInfo->lpTitle     = NULL;
     2106    pStartupInfo->lpReserved2 = NULL;
     2107    pStartupInfo->cbReserved2 = 0;
    20492108}
    20502109
     
    23062365 */
    23072366
    2308 
    2309 /** Kernel32 - LoadLibraryExA()   */
     2367/**
     2368 * Kernel32 - LoadLibraryExA() worker that loads resource files and such.
     2369 */
     2370static HMODULE WINAPI kwSandbox_Kernel32_LoadLibraryExA_Resource(LPCSTR pszFilename, HANDLE hFile, DWORD fFlags)
     2371{
     2372    HMODULE     hmod;
     2373    PKWDYNLOAD  pDynLoad;
     2374    KU32        uHashPath;
     2375    char        szNormPath[4096];
     2376
     2377    /* Normalize the path. */
     2378    int rc = kwPathNormalize(pszFilename, szNormPath, sizeof(szNormPath));
     2379    if (rc != 0)
     2380    {
     2381        __debugbreak();
     2382        return LoadLibraryExA(pszFilename, hFile, fFlags);
     2383    }
     2384
     2385    /* Try look it up. */
     2386    uHashPath = kwStrHash(szNormPath);
     2387    for (pDynLoad = g_Sandbox.pTool->u.Sandboxed.pDynLoadHead; pDynLoad != NULL; pDynLoad = pDynLoad->pNext)
     2388        if (   pDynLoad->uHashPath == uHashPath
     2389            && kHlpStrComp(pDynLoad->pszPath, szNormPath) == 0)
     2390        {
     2391            if (pDynLoad->pMod == NULL)
     2392                return pDynLoad->hmod;
     2393            __debugbreak();
     2394        }
     2395
     2396    /* Then try load it. */
     2397    hmod = LoadLibraryExA(szNormPath, hFile, fFlags);
     2398    if (hmod)
     2399    {
     2400        KSIZE cbNormPath = kHlpStrLen(szNormPath) + 1;
     2401        pDynLoad = (PKWDYNLOAD)kHlpAlloc(sizeof(*pDynLoad) + cbNormPath + cbNormPath * 2 * sizeof(wchar_t));
     2402        if (pDynLoad)
     2403        {
     2404            pDynLoad->pszPath           = (char *)kHlpMemCopy(pDynLoad + 1, szNormPath, cbNormPath);
     2405            pDynLoad->pwszPath          = (wchar_t *)(pDynLoad->pszPath + cbNormPath + (cbNormPath & 1));
     2406            kwStrToUtf16(pDynLoad->pszPath, (wchar_t *)pDynLoad->pwszPath, cbNormPath * 2);
     2407            pDynLoad->pszModName        = kHlpGetFilename(pDynLoad->pszPath);
     2408            pDynLoad->uHashPath         = uHashPath;
     2409            pDynLoad->pMod              = NULL; /* indicates special  */
     2410            pDynLoad->hmod              = hmod;
     2411
     2412            pDynLoad->pNext = g_Sandbox.pTool->u.Sandboxed.pDynLoadHead;
     2413            g_Sandbox.pTool->u.Sandboxed.pDynLoadHead = pDynLoad;
     2414        }
     2415        else
     2416            __debugbreak();
     2417    }
     2418    return hmod;
     2419}
     2420
     2421
     2422/**
     2423 * Kernel32 - LoadLibraryExA() worker that deals with the api-ms-xxx modules.
     2424 */
     2425static HMODULE WINAPI kwSandbox_Kernel32_LoadLibraryExA_VirtualApiModule(LPCSTR pszFilename, HANDLE hFile, DWORD fFlags)
     2426{
     2427    HMODULE     hmod;
     2428    PKWDYNLOAD  pDynLoad;
     2429    KU32        uHashPath;
     2430    char        szNormPath[256];
     2431    KSIZE       cbFilename = kHlpStrLen(pszFilename) + 1;
     2432
     2433    /* Lower case it. */
     2434    if (cbFilename <= sizeof(szNormPath))
     2435    {
     2436        kHlpMemCopy(szNormPath, pszFilename, cbFilename);
     2437        _strlwr(szNormPath);
     2438    }
     2439    else
     2440    {
     2441        SetLastError(ERROR_FILENAME_EXCED_RANGE);
     2442        return NULL;
     2443    }
     2444
     2445    /* Try look it up. */
     2446    uHashPath = kwStrHash(szNormPath);
     2447    for (pDynLoad = g_Sandbox.pTool->u.Sandboxed.pDynLoadHead; pDynLoad != NULL; pDynLoad = pDynLoad->pNext)
     2448        if (   pDynLoad->uHashPath == uHashPath
     2449            && kHlpStrComp(pDynLoad->pszPath, szNormPath) == 0)
     2450        {
     2451            if (pDynLoad->pMod != NULL)
     2452                return pDynLoad->hmod;
     2453            __debugbreak();
     2454        }
     2455
     2456    /* Then try load it and make a kLdr module for it. */
     2457    hmod = LoadLibraryExA(szNormPath, hFile, fFlags);
     2458    if (hmod)
     2459    {
     2460        PKLDRMOD pLdrMod;
     2461        int rc = kLdrModOpenNativeByHandle((KUPTR)hmod, &pLdrMod);
     2462        if (rc == 0)
     2463        {
     2464            PKWMODULE pMod = kwLdrModuleCreateForNativekLdrModule(pLdrMod, szNormPath, cbFilename, uHashPath,
     2465                                                                  K_FALSE /*fDoReplacements*/);
     2466            if (pMod)
     2467            {
     2468                pDynLoad = (PKWDYNLOAD)kHlpAlloc(sizeof(*pDynLoad) + cbFilename + cbFilename * sizeof(wchar_t));
     2469                if (pDynLoad)
     2470                {
     2471                    pDynLoad->pwszPath      = (wchar_t *)(pDynLoad + 1);
     2472                    kwStrToUtf16(szNormPath, (wchar_t *)pDynLoad->pwszPath, cbFilename);
     2473                    pDynLoad->pszPath       = (char *)kHlpMemCopy((char *)&pDynLoad->pwszPath[cbFilename], szNormPath, cbFilename);
     2474                    pDynLoad->pszModName    = pDynLoad->pszPath;
     2475                    pDynLoad->uHashPath     = uHashPath;
     2476                    pDynLoad->pMod          = pMod;
     2477                    pDynLoad->hmod          = hmod;
     2478
     2479                    pDynLoad->pNext = g_Sandbox.pTool->u.Sandboxed.pDynLoadHead;
     2480                    g_Sandbox.pTool->u.Sandboxed.pDynLoadHead = pDynLoad;
     2481                    return hmod;
     2482                }
     2483
     2484                __debugbreak();
     2485            }
     2486            else
     2487                __debugbreak();
     2488        }
     2489        else
     2490            __debugbreak();
     2491    }
     2492    return hmod;
     2493}
     2494
     2495
     2496/** Kernel32 - LoadLibraryExA() */
    23102497static HMODULE WINAPI kwSandbox_Kernel32_LoadLibraryExA(LPCSTR pszFilename, HANDLE hFile, DWORD fFlags)
    23112498{
     
    23282515                  | LOAD_LIBRARY_AS_IMAGE_RESOURCE) )
    23292516    {
    2330         HMODULE hmod;
    2331         char    szNormPath[4096];
    2332         KU32    uHashPath;
    2333 
    23342517        /* currently, only deal with those that has a path. */
    23352518        if (kHlpIsFilenameOnly(pszFilename))
     
    23392522        }
    23402523
    2341         /* Normalize the path. */
    2342         rc = kwPathNormalize(pszFilename, szNormPath, sizeof(szNormPath));
    2343         if (rc != 0)
    2344         {
    2345             __debugbreak();
    2346             return LoadLibraryExA(pszFilename, hFile, fFlags);
    2347         }
    2348 
    2349         /* Try look it up. */
    2350         uHashPath = kwStrHash(szNormPath);
    2351         for (pDynLoad = g_Sandbox.pTool->u.Sandboxed.pDynLoadHead; pDynLoad != NULL; pDynLoad = pDynLoad->pNext)
    2352             if (   pDynLoad->uHashPath == uHashPath
    2353                 && kHlpStrComp(pDynLoad->pszPath, szNormPath) == 0)
    2354             {
    2355                 if (pDynLoad->pMod == NULL)
    2356                     return pDynLoad->hmod;
    2357                 __debugbreak();
    2358             }
    2359 
    2360         /* Then try load it. */
    2361         hmod = LoadLibraryExA(szNormPath, hFile, fFlags);
    2362         if (hmod)
    2363         {
    2364             KSIZE cbNormPath = kHlpStrLen(szNormPath) + 1;
    2365             pDynLoad = (PKWDYNLOAD)kHlpAlloc(sizeof(*pDynLoad) + cbNormPath + cbNormPath * 2 * sizeof(wchar_t));
    2366             if (pDynLoad)
    2367             {
    2368                 pDynLoad->pszPath           = (char *)kHlpMemCopy(pDynLoad + 1, szNormPath, cbNormPath);
    2369                 pDynLoad->pwszPath          = (wchar_t *)(pDynLoad->pszPath + cbNormPath + (cbNormPath & 1));
    2370                 kwStrToUtf16(pDynLoad->pszPath, (wchar_t *)pDynLoad->pwszPath, cbNormPath * 2);
    2371                 pDynLoad->pszModName        = kHlpGetFilename(pDynLoad->pszPath);
    2372                 pDynLoad->uHashPath         = uHashPath;
    2373                 pDynLoad->pMod              = NULL; /* indicates special  */
    2374                 pDynLoad->hmod              = hmod;
    2375 
    2376                 pDynLoad->pNext = g_Sandbox.pTool->u.Sandboxed.pDynLoadHead;
    2377                 g_Sandbox.pTool->u.Sandboxed.pDynLoadHead = pDynLoad;
    2378             }
    2379             else
    2380                 __debugbreak();
    2381         }
    2382         return hmod;
     2524        return kwSandbox_Kernel32_LoadLibraryExA_Resource(pszFilename, hFile, fFlags);
    23832525    }
    23842526
     
    23892531    if (!kHlpIsFilenameOnly(pszFilename))
    23902532        pMod = kwLdrModuleTryLoadDll(pszFilename, KWLOCATION_UNKNOWN, g_Sandbox.pTool->u.Sandboxed.pExe);
     2533    /* Special case: api-ms-win-core-synch-l1-2-0 and friends (32-bit yasm, built with VS2015). */
     2534    else if (strnicmp(pszFilename, TUPLE("api-ms-")) == 0)
     2535        return kwSandbox_Kernel32_LoadLibraryExA_VirtualApiModule(pszFilename, hFile, fFlags);
    23912536    else
    23922537    {
     
    24802625static HMODULE WINAPI kwSandbox_Kernel32_GetModuleHandleA(LPCSTR pszModule)
    24812626{
     2627    KSIZE i;
     2628    KSIZE cchModule;
     2629
     2630    /*
     2631     * The executable.
     2632     */
    24822633    if (pszModule == NULL)
    24832634        return (HMODULE)g_Sandbox.pTool->u.Sandboxed.pExe->hOurMod;
     2635
     2636    /*
     2637     * Cache of system modules we've seen queried.
     2638     */
     2639    cchModule = kHlpStrLen(pszModule);
     2640    for (i = 0; i < K_ELEMENTS(g_aGetModuleHandleCache); i++)
     2641        if (   g_aGetModuleHandleCache[i].cchName == cchModule
     2642            && stricmp(pszModule, g_aGetModuleHandleCache[i].pszName) == 0)
     2643        {
     2644            if (g_aGetModuleHandleCache[i].hmod != NULL)
     2645                return g_aGetModuleHandleCache[i].hmod;
     2646            return g_aGetModuleHandleCache[i].hmod = GetModuleHandleA(pszModule);
     2647        }
     2648
    24842649    __debugbreak();
    24852650    return NULL;
     
    24902655static HMODULE WINAPI kwSandbox_Kernel32_GetModuleHandleW(LPCWSTR pwszModule)
    24912656{
     2657    KSIZE i;
     2658    KSIZE cwcModule;
     2659
     2660    /*
     2661     * The executable.
     2662     */
    24922663    if (pwszModule == NULL)
    24932664        return (HMODULE)g_Sandbox.pTool->u.Sandboxed.pExe->hOurMod;
     2665
     2666    /*
     2667     * Cache of system modules we've seen queried.
     2668     */
     2669    cwcModule = kwUtf16Len(pwszModule);
     2670    for (i = 0; i < K_ELEMENTS(g_aGetModuleHandleCache); i++)
     2671        if (   g_aGetModuleHandleCache[i].cwcName == cwcModule
     2672            && _wcsicmp(pwszModule, g_aGetModuleHandleCache[i].pwszName) == 0)
     2673        {
     2674            if (g_aGetModuleHandleCache[i].hmod != NULL)
     2675                return g_aGetModuleHandleCache[i].hmod;
     2676            return g_aGetModuleHandleCache[i].hmod = GetModuleHandleW(pwszModule);
     2677        }
     2678
    24942679    __debugbreak();
    24952680    return NULL;
     
    25312716static FARPROC WINAPI kwSandbox_Kernel32_GetProcAddress(HMODULE hmod, LPCSTR pszProc)
    25322717{
     2718    KSIZE i;
     2719
    25332720    /*
    25342721     * Try locate the module.
     
    25642751        return NULL;
    25652752    }
     2753
     2754    /*
     2755     * Hmm... could be a cached module-by-name.
     2756     */
     2757    for (i = 0; i < K_ELEMENTS(g_aGetModuleHandleCache); i++)
     2758        if (g_aGetModuleHandleCache[i].hmod == hmod)
     2759            return GetProcAddress(hmod, pszProc);
    25662760
    25672761    __debugbreak();
     
    44824676    pSandbox->pTool         = pTool;
    44834677    pSandbox->idMainThread  = GetCurrentThreadId();
    4484     pSandbox->TibMainThread = *(PNT_TIB)NtCurrentTeb();
    44854678    pSandbox->pgmptr        = (char *)pTool->pszPath;
    44864679    pSandbox->wpgmptr       = (wchar_t *)pTool->pwszPath;
     
    45854778            if (rc == 0)
    45864779            {
     4780#if K_ARCH == K_ARCH_AMD64
    45874781                int (*pfnWin64Entrypoint)(void *pvPeb, void *, void *, void *);
    4588                 *(KUPTR *)&pfnWin64Entrypoint = uAddrMain;
    4589 
    4590                 __try
    4591                 {
    4592                     if (setjmp(g_Sandbox.JmpBuf) == 0)
    4593                     {
    4594 #if K_ARCH == K_ARCH_AMD64
    4595                         *(KU64*)(g_Sandbox.JmpBuf) = 0; /** @todo find other way to prevent longjmp from doing unwind! */
     4782#elif K_ARCH == K_ARCH_X86_32
     4783                int (__cdecl *pfnWin32Entrypoint)(void *pvPeb);
    45964784#else
    45974785# error "Port me!"
    45984786#endif
     4787
     4788                /* Save the NT TIB first (should do that here, not in some other function). */
     4789                PNT_TIB pTib = (PNT_TIB)NtCurrentTeb();
     4790                g_Sandbox.TibMainThread = *pTib;
     4791
     4792                /* Make the call in a guarded fashion. */
     4793#if K_ARCH == K_ARCH_AMD64
     4794                /* AMD64 */
     4795                *(KUPTR *)&pfnWin64Entrypoint = uAddrMain;
     4796                __try
     4797                {
     4798                    pSandbox->pOutXcptListHead = pTib->ExceptionList;
     4799                    if (setjmp(g_Sandbox.JmpBuf) == 0)
     4800                    {
     4801                        *(KU64*)(g_Sandbox.JmpBuf) = 0; /** @todo find other way to prevent longjmp from doing unwind! */
    45994802                        rcExit = pfnWin64Entrypoint(kwSandboxGetProcessEnvironmentBlock(), NULL, NULL, NULL);
    46004803                    }
     
    46024805                        rcExit = g_Sandbox.rcExitCode;
    46034806                }
     4807#elif K_ARCH == K_ARCH_X86_32
     4808                /* x86 (see _tmainCRTStartup) */
     4809                *(KUPTR *)&pfnWin32Entrypoint = uAddrMain;
     4810                __try
     4811                {
     4812                    pSandbox->pOutXcptListHead = pTib->ExceptionList;
     4813                    if (setjmp(g_Sandbox.JmpBuf) == 0)
     4814                    {
     4815                        //*(KU64*)(g_Sandbox.JmpBuf) = 0; /** @todo find other way to prevent longjmp from doing unwind! */
     4816                        rcExit = pfnWin32Entrypoint(kwSandboxGetProcessEnvironmentBlock());
     4817                    }
     4818                    else
     4819                        rcExit = g_Sandbox.rcExitCode;
     4820                }
     4821#endif
    46044822                __except (EXCEPTION_EXECUTE_HANDLER)
    46054823                {
     
    46074825                }
    46084826
    4609                 /*
    4610                  * Restore the TIB and later some other stuff.
    4611                  */
    4612                 *(PNT_TIB)NtCurrentTeb() = g_Sandbox.TibMainThread;
     4827                /* Now, restore the NT TIB. */
     4828                *pTib = g_Sandbox.TibMainThread;
    46134829            }
    46144830            else
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