Ignore:
Timestamp:
Nov 2, 2024, 2:51:30 AM (9 months ago)
Author:
bird
Message:

kWorker: VC++ 2022 build fixes.

File:
1 edited

Legend:

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

    r3522 r3634  
    892892    KSIZE       cEnvVarsAllocated;
    893893    /** The _environ msvcrt variable. */
    894     char      **environ;
     894    char      **environC;
    895895    /** The _wenviron msvcrt variable. */
    896     wchar_t   **wenviron;
     896    wchar_t   **wenvironC;
    897897    /** The shadow _environ msvcrt variable. */
    898898    char      **papszEnvVars;
     
    27642764        for (iEntry = 0; iEntry < cEntries; iEntry++)
    27652765        {
    2766             KUPTR        offIndex     = (KUPTR)paEntries[iEntry].AddressOfIndex     - (KUPTR)pMod->u.Manual.pbLoad;
    2767             KUPTR        offCallbacks = (KUPTR)paEntries[iEntry].AddressOfCallBacks - (KUPTR)pMod->u.Manual.pbLoad;
    2768             KUPTR const *puCallbacks  = (KUPTR const *)&pbImg[offCallbacks];
     2766            offIndex     = (KUPTR)paEntries[iEntry].AddressOfIndex     - (KUPTR)pMod->u.Manual.pbLoad;
     2767            offCallbacks = (KUPTR)paEntries[iEntry].AddressOfCallBacks - (KUPTR)pMod->u.Manual.pbLoad;
     2768            puCallbacks  = (KUPTR const *)&pbImg[offCallbacks];
    27692769            KWLDR_LOG(("TLS DIR #%u: %#x-%#x idx=@%#x (%#x) callbacks=@%#x (%#x) cbZero=%#x flags=%#x\n",
    27702770                       iEntry, paEntries[iEntry].StartAddressOfRawData, paEntries[iEntry].EndAddressOfRawData,
     
    46214621    *pargc = g_Sandbox.cArgs;
    46224622    *pargv = g_Sandbox.papszArgs;
    4623     *penvp = g_Sandbox.environ;
     4623    *penvp = g_Sandbox.environC;
    46244624
    46254625    /** @todo startinfo points at a newmode (setmode) value.   */
     
    46354635    *pargc = g_Sandbox.cArgs;
    46364636    *pargv = g_Sandbox.papwszArgs;
    4637     *penvp = g_Sandbox.wenviron;
     4637    *penvp = g_Sandbox.wenvironC;
    46384638
    46394639    /** @todo startinfo points at a newmode (setmode) value.   */
     
    49904990
    49914991/**
    4992  * Grows the environment vectors (KWSANDBOX::environ, KWSANDBOX::papszEnvVars,
    4993  * KWSANDBOX::wenviron, and KWSANDBOX::papwszEnvVars).
     4992 * Grows the environment vectors (KWSANDBOX::environC, KWSANDBOX::papszEnvVars,
     4993 * KWSANDBOX::wenvironC, and KWSANDBOX::papwszEnvVars).
    49944994 *
    49954995 * @returns 0 on success, non-zero on failure.
     
    50055005        cNew += 256;
    50065006
    5007     pvNew = kHlpRealloc(pSandbox->environ, cNew * sizeof(pSandbox->environ[0]));
     5007    pvNew = kHlpRealloc(pSandbox->environC, cNew * sizeof(pSandbox->environC[0]));
    50085008    if (pvNew)
    50095009    {
    5010         pSandbox->environ = (char **)pvNew;
    5011         pSandbox->environ[cOld] = NULL;
     5010        pSandbox->environC = (char **)pvNew;
     5011        pSandbox->environC[cOld] = NULL;
    50125012
    50135013        pvNew = kHlpRealloc(pSandbox->papszEnvVars, cNew * sizeof(pSandbox->papszEnvVars[0]));
     
    50175017            pSandbox->papszEnvVars[cOld] = NULL;
    50185018
    5019             pvNew = kHlpRealloc(pSandbox->wenviron, cNew * sizeof(pSandbox->wenviron[0]));
     5019            pvNew = kHlpRealloc(pSandbox->wenvironC, cNew * sizeof(pSandbox->wenvironC[0]));
    50205020            if (pvNew)
    50215021            {
    5022                 pSandbox->wenviron = (wchar_t **)pvNew;
    5023                 pSandbox->wenviron[cOld] = NULL;
     5022                pSandbox->wenvironC = (wchar_t **)pvNew;
     5023                pSandbox->wenvironC[cOld] = NULL;
    50245024
    50255025                pvNew = kHlpRealloc(pSandbox->papwszEnvVars, cNew * sizeof(pSandbox->papwszEnvVars[0]));
     
    50315031                    pSandbox->cEnvVarsAllocated = cNew;
    50325032                    KW_LOG(("kwSandboxGrowEnv: cNew=%d - crt: %p / %p; shadow: %p, %p\n",
    5033                             cNew, pSandbox->environ, pSandbox->wenviron, pSandbox->papszEnvVars, pSandbox->papwszEnvVars));
     5033                            cNew, pSandbox->environC, pSandbox->wenvironC, pSandbox->papszEnvVars, pSandbox->papwszEnvVars));
    50345034                    return 0;
    50355035                }
     
    50845084                    kHlpFree(pSandbox->papszEnvVars[iVar]);
    50855085                    pSandbox->papszEnvVars[iVar]  = pszNew;
    5086                     pSandbox->environ[iVar]       = pszNew;
     5086                    pSandbox->environC[iVar]      = pszNew;
    50875087
    50885088                    kHlpFree(pSandbox->papwszEnvVars[iVar]);
    50895089                    pSandbox->papwszEnvVars[iVar] = pwszNew;
    5090                     pSandbox->wenviron[iVar]      = pwszNew;
     5090                    pSandbox->wenvironC[iVar]     = pwszNew;
    50915091                    return 0;
    50925092                }
     
    51035103                pSandbox->papszEnvVars[iVar + 1]  = NULL;
    51045104                pSandbox->papszEnvVars[iVar]      = pszNew;
    5105                 pSandbox->environ[iVar + 1]       = NULL;
    5106                 pSandbox->environ[iVar]           = pszNew;
     5105                pSandbox->environC[iVar + 1]      = NULL;
     5106                pSandbox->environC[iVar]          = pszNew;
    51075107
    51085108                pSandbox->papwszEnvVars[iVar + 1] = NULL;
    51095109                pSandbox->papwszEnvVars[iVar]     = pwszNew;
    5110                 pSandbox->wenviron[iVar + 1]      = NULL;
    5111                 pSandbox->wenviron[iVar]          = pwszNew;
     5110                pSandbox->wenvironC[iVar + 1]     = NULL;
     5111                pSandbox->wenvironC[iVar]         = pwszNew;
    51125112                return 0;
    51135113            }
     
    51645164                    kHlpFree(pSandbox->papszEnvVars[iVar]);
    51655165                    pSandbox->papszEnvVars[iVar]  = pszNew;
    5166                     pSandbox->environ[iVar]       = pszNew;
     5166                    pSandbox->environC[iVar]      = pszNew;
    51675167
    51685168                    kHlpFree(pSandbox->papwszEnvVars[iVar]);
    51695169                    pSandbox->papwszEnvVars[iVar] = pwszNew;
    5170                     pSandbox->wenviron[iVar]      = pwszNew;
     5170                    pSandbox->wenvironC[iVar]     = pwszNew;
    51715171                    return 0;
    51725172                }
     
    51835183                pSandbox->papszEnvVars[iVar + 1]  = NULL;
    51845184                pSandbox->papszEnvVars[iVar]      = pszNew;
    5185                 pSandbox->environ[iVar + 1]       = NULL;
    5186                 pSandbox->environ[iVar]           = pszNew;
     5185                pSandbox->environC[iVar + 1]      = NULL;
     5186                pSandbox->environC[iVar]          = pszNew;
    51875187
    51885188                pSandbox->papwszEnvVars[iVar + 1] = NULL;
    51895189                pSandbox->papwszEnvVars[iVar]     = pwszNew;
    5190                 pSandbox->wenviron[iVar + 1]      = NULL;
    5191                 pSandbox->wenviron[iVar]          = pwszNew;
     5190                pSandbox->wenvironC[iVar + 1]     = NULL;
     5191                pSandbox->wenvironC[iVar]         = pwszNew;
    51925192                return 0;
    51935193            }
     
    52245224            kHlpFree(pSandbox->papszEnvVars[iVar]);
    52255225            pSandbox->papszEnvVars[iVar]    = pSandbox->papszEnvVars[cVars];
    5226             pSandbox->environ[iVar]         = pSandbox->papszEnvVars[cVars];
     5226            pSandbox->environC[iVar]        = pSandbox->papszEnvVars[cVars];
    52275227            pSandbox->papszEnvVars[cVars]   = NULL;
    5228             pSandbox->environ[cVars]        = NULL;
     5228            pSandbox->environC[cVars]       = NULL;
    52295229
    52305230            kHlpFree(pSandbox->papwszEnvVars[iVar]);
    52315231            pSandbox->papwszEnvVars[iVar]   = pSandbox->papwszEnvVars[cVars];
    5232             pSandbox->wenviron[iVar]        = pSandbox->papwszEnvVars[cVars];
     5232            pSandbox->wenvironC[iVar]       = pSandbox->papwszEnvVars[cVars];
    52335233            pSandbox->papwszEnvVars[cVars]  = NULL;
    5234             pSandbox->wenviron[cVars]       = NULL;
     5234            pSandbox->wenvironC[cVars]      = NULL;
    52355235            return 0;
    52365236        }
     
    52635263            kHlpFree(pSandbox->papszEnvVars[iVar]);
    52645264            pSandbox->papszEnvVars[iVar]    = pSandbox->papszEnvVars[cVars];
    5265             pSandbox->environ[iVar]         = pSandbox->papszEnvVars[cVars];
     5265            pSandbox->environC[iVar]        = pSandbox->papszEnvVars[cVars];
    52665266            pSandbox->papszEnvVars[cVars]   = NULL;
    5267             pSandbox->environ[cVars]        = NULL;
     5267            pSandbox->environC[cVars]       = NULL;
    52685268
    52695269            kHlpFree(pSandbox->papwszEnvVars[iVar]);
    52705270            pSandbox->papwszEnvVars[iVar]   = pSandbox->papwszEnvVars[cVars];
    5271             pSandbox->wenviron[iVar]        = pSandbox->papwszEnvVars[cVars];
     5271            pSandbox->wenvironC[iVar]       = pSandbox->papwszEnvVars[cVars];
    52725272            pSandbox->papwszEnvVars[cVars]  = NULL;
    5273             pSandbox->wenviron[cVars]       = NULL;
     5273            pSandbox->wenvironC[cVars]      = NULL;
    52745274            return 0;
    52755275        }
     
    55525552    KW_LOG(("__p__environ\n"));
    55535553    kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread);
    5554     return &g_Sandbox.environ;
     5554    return &g_Sandbox.environC;
    55555555}
    55565556
     
    55615561    KW_LOG(("__p__wenviron\n"));
    55625562    kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread);
    5563     return &g_Sandbox.wenviron;
     5563    return &g_Sandbox.wenvironC;
    55645564}
    55655565
     
    55715571    KWFS_TODO(); /** @todo check the callers expectations! */
    55725572    kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread);
    5573     *ppapszEnviron = g_Sandbox.environ;
     5573    *ppapszEnviron = g_Sandbox.environC;
    55745574    return 0;
    55755575}
     
    55825582    KWFS_TODO(); /** @todo check the callers expectations! */
    55835583    kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread);
    5584     *ppapwszEnviron = g_Sandbox.wenviron;
     5584    *ppapwszEnviron = g_Sandbox.wenvironC;
    55855585    return 0;
    55865586}
     
    63326332            //static int s_cDbgGets = 0;
    63336333            KU32 cchProc = (KU32)kHlpStrLen(pszProc);
    6334             KU32 i = g_cSandboxGetProcReplacements;
     6334            i = g_cSandboxGetProcReplacements;
    63356335            while (i-- > 0)
    63366336                if (   g_aSandboxGetProcReplacements[i].cchFunction == cchProc
     
    63506350                                if (pMod->iCrtSlot == KU8_MAX)
    63516351                                {
    6352                                     int rc = kwLdrModuleCreateCrtSlot(pMod);
     6352                                    rc = kwLdrModuleCreateCrtSlot(pMod);
    63536353                                    if (rc)
    63546354                                    {
     
    63726372            if (kHlpStrComp(pszProc, g_szInvokeCompilePassW) == 0)
    63736373            {
    6374                 KU32 i;
    63756374                for (i = 0; i < K_ELEMENTS(g_aCxInterceptorEntries); i++)
    63766375                    if ((KUPTR)g_aCxInterceptorEntries[i].pfnOrg == uValue)
     
    96709669            {
    96719670                DWORD dwErr = GetLastError();
    9672                 PKWVIRTALLOC pTracker = (PKWVIRTALLOC)kHlpAlloc(sizeof(*pTracker));
     9671                pTracker = (PKWVIRTALLOC)kHlpAlloc(sizeof(*pTracker));
    96739672                if (pTracker)
    96749673                {
     
    1107811077    { TUPLE("__p___initenv"),               NULL,       (KUPTR)kwSandbox_msvcrt___p___initenv},
    1107911078    { TUPLE("__p___winitenv"),              NULL,       (KUPTR)kwSandbox_msvcrt___p___winitenv},
    11080     { TUPLE("_environ"),                    NULL,       (KUPTR)&g_Sandbox.environ },
    11081     { TUPLE("_wenviron"),                   NULL,       (KUPTR)&g_Sandbox.wenviron },
     11079    { TUPLE("_environ"),                    NULL,       (KUPTR)&g_Sandbox.environC },
     11080    { TUPLE("_wenviron"),                   NULL,       (KUPTR)&g_Sandbox.wenvironC },
    1108211081    { TUPLE("_get_environ"),                NULL,       (KUPTR)kwSandbox_msvcrt__get_environ },
    1108311082    { TUPLE("_get_wenviron"),               NULL,       (KUPTR)kwSandbox_msvcrt__get_wenviron },
     
    1164511644                {
    1164611645                    pSandbox->papszEnvVars[iDst]  = pszCopy;
    11647                     pSandbox->environ[iDst]       = pszCopy;
     11646                    pSandbox->environC[iDst]      = pszCopy;
    1164811647                    pSandbox->papwszEnvVars[iDst] = pwszCopy;
    11649                     pSandbox->wenviron[iDst]      = pwszCopy;
     11648                    pSandbox->wenvironC[iDst]     = pwszCopy;
    1165011649
    1165111650                    /* When we see the path, we must tell the system or native exec and module loading won't work . */
     
    1167111670        }
    1167211671        pSandbox->papszEnvVars[iDst]  = NULL;
    11673         pSandbox->environ[iDst]       = NULL;
     11672        pSandbox->environC[iDst]      = NULL;
    1167411673        pSandbox->papwszEnvVars[iDst] = NULL;
    11675         pSandbox->wenviron[iDst]      = NULL;
     11674        pSandbox->wenvironC[iDst]     = NULL;
    1167611675    }
    1167711676    else
     
    1188811887        for (i = 0; pSandbox->papszEnvVars[i]; i++)
    1188911888            kHlpFree(pSandbox->papszEnvVars[i]);
    11890         pSandbox->environ[0]      = NULL;
     11889        pSandbox->environC[0]      = NULL;
    1189111890        pSandbox->papszEnvVars[0] = NULL;
    1189211891
    1189311892        for (i = 0; pSandbox->papwszEnvVars[i]; i++)
    1189411893            kHlpFree(pSandbox->papwszEnvVars[i]);
    11895         pSandbox->wenviron[0]      = NULL;
     11894        pSandbox->wenvironC[0]     = NULL;
    1189611895        pSandbox->papwszEnvVars[0] = NULL;
    1189711896    }
     
    1306613065            && fseek(pFile, 0, SEEK_SET) == 0)
    1306713066        {
    13068             char *pszFile = kHlpAllocZ(cbFile + 3);
    13069             if (pszFile)
    13070             {
    13071                 size_t cbRead = fread(pszFile, 1, cbFile + 1, pFile);
     13067            char *pszContent = kHlpAllocZ(cbFile + 3);
     13068            *ppszFileContent = pszContent;
     13069            if (pszContent)
     13070            {
     13071                size_t cbRead = fread(pszContent, 1, cbFile + 1, pFile);
    1307213072                if (   feof(pFile)
    1307313073                    && !ferror(pFile))
     
    1307813078                    char   ch;
    1307913079
    13080                     pszFile[cbRead]     = '\0';
    13081                     pszFile[cbRead + 1] = '\0';
    13082                     pszFile[cbRead + 2] = '\0';
    13083 
    13084                     while ((ch = pszFile[off]) != '\0')
     13080                    pszContent[cbRead]     = '\0';
     13081                    pszContent[cbRead + 1] = '\0';
     13082                    pszContent[cbRead + 2] = '\0';
     13083
     13084                    while ((ch = pszContent[off]) != '\0')
    1308513085                    {
    1308613086                        char *pszArg;
     
    1309513095
    1309613096                            case '\\':
    13097                                 if (pszFile[off + 1] == '\n' || pszFile[off + 1] == '\r')
     13097                                if (pszContent[off + 1] == '\n' || pszContent[off + 1] == '\r')
    1309813098                                {
    1309913099                                    off += 2;
     
    1310213102                                /* fall thru */
    1310313103                            default:
    13104                                 pszArg = &pszFile[off];
     13104                                pszArg = &pszContent[off];
    1310513105                                do
    13106                                     ch = pszFile[++off];
     13106                                    ch = pszContent[++off];
    1310713107                                while (ch != '\0' && ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r');
    13108                                 pszFile[off++] = '\0';
     13108                                pszContent[off++] = '\0';
    1310913109                                break;
    1311013110
    1311113111                            case '\'':
    13112                                 pszArg = &pszFile[++off];
    13113                                 while ((ch = pszFile[off]) != '\0' && ch != '\'')
     13112                                pszArg = &pszContent[++off];
     13113                                while ((ch = pszContent[off]) != '\0' && ch != '\'')
    1311413114                                    off++;
    13115                                 pszFile[off++] = '\0';
     13115                                pszContent[off++] = '\0';
    1311613116                                break;
    1311713117
    1311813118                            case '\"': /** @todo escape sequences */
    13119                                 pszArg = &pszFile[++off];
    13120                                 while ((ch = pszFile[off]) != '\0' && ch != '"')
     13119                                pszArg = &pszContent[++off];
     13120                                while ((ch = pszContent[off]) != '\0' && ch != '"')
    1312113121                                    off++;
    13122                                 pszFile[off++] = '\0';
     13122                                pszContent[off++] = '\0';
    1312313123                                break;
    1312413124                        }
     
    1324913249                else if (kHlpStrComp(pszArg, "default-env") == 0)
    1325013250                {
    13251                     unsigned i;
     13251                    unsigned j;
    1325213252                    pCur->cEnvVars = 0;
    13253                     for (i = 0; environ[i] && rc == 0; i++)
    13254                         rc = kwFullTestVectorAppend(&pCur->papszEnvVars, &pCur->cEnvVars, kHlpStrDup(environ[i])); /* leaks; unchecked */
     13253                    for (j = 0; environ[j] && rc == 0; j++)
     13254                        rc = kwFullTestVectorAppend(&pCur->papszEnvVars, &pCur->cEnvVars, kHlpStrDup(environ[j])); /* leaks; unchecked */
    1325513255                }
    1325613256                else if (kHlpStrComp(pszArg, "chdir") == 0)
Note: See TracChangeset for help on using the changeset viewer.