Changeset 2934 for trunk/src


Ignore:
Timestamp:
Sep 18, 2016, 6:47:16 PM (9 years ago)
Author:
bird
Message:

kWorker: Some cleanups

Location:
trunk/src/kWorker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kWorker/Makefile.kmk

    r2894 r2934  
    4848        $(PATH_SDK_WINDDK71_LIB_WNET)/psapi.lib
    4949kWorker_LDFLAGS.win = \
    50         /BASE:0x10000 /DYNAMICBASE:NO /FIXED /SECTION:DefLdBuf,EWR
     50        /BASE:0x10000 /DYNAMICBASE:NO /FIXED
    5151
    5252
  • trunk/src/kWorker/kWorker.c

    r2933 r2934  
    45044504#endif /* WITH_TEMP_MEMORY_FILES */
    45054505
     4506/**
     4507 * Worker for kwFsIsCacheableExtensionA and kwFsIsCacheableExtensionW
     4508 *
     4509 * @returns K_TRUE if cacheable, K_FALSE if not.
     4510 * @param   wcFirst             The first extension character.
     4511 * @param   wcSecond            The second extension character.
     4512 * @param   wcThird             The third extension character.
     4513 * @param   fAttrQuery          Set if it's for an attribute query, clear if for
     4514 *                              file creation.
     4515 */
     4516static KBOOL kwFsIsCacheableExtensionCommon(wchar_t wcFirst, wchar_t wcSecond, wchar_t wcThird, KBOOL fAttrQuery)
     4517{
     4518    /* C++ header without an extension or a directory. */
     4519    if (wcFirst == '\0')
     4520    {
     4521        /** @todo exclude temporary files...  */
     4522        return K_TRUE;
     4523    }
     4524
     4525    /* C Header: .h */
     4526    if (wcFirst == 'h' || wcFirst == 'H')
     4527    {
     4528        if (wcSecond == '\0')
     4529            return K_TRUE;
     4530
     4531        /* C++ Header: .hpp, .hxx */
     4532        if (   (wcSecond == 'p' || wcSecond == 'P')
     4533            && (wcThird  == 'p' || wcThird  == 'P'))
     4534            return K_TRUE;
     4535        if (   (wcSecond == 'x' || wcSecond == 'X')
     4536            && (wcThird  == 'x' || wcThird  == 'X'))
     4537            return K_TRUE;
     4538    }
     4539    /* Misc starting with i. */
     4540    else if (wcFirst == 'i' || wcFirst == 'I')
     4541    {
     4542        if (wcSecond != '\0')
     4543        {
     4544            if (wcSecond == 'n' || wcSecond == 'N')
     4545            {
     4546                /* C++ inline header: .inl */
     4547                if (wcThird == 'l' || wcThird == 'L')
     4548                    return K_TRUE;
     4549
     4550                /* Assembly include file: .inc */
     4551                if (wcThird == 'c' || wcThird == 'C')
     4552                    return K_TRUE;
     4553            }
     4554        }
     4555    }
     4556    /* Assembly header: .mac */
     4557    else if (wcFirst == 'm' || wcFirst == 'M')
     4558    {
     4559        if (wcSecond == 'a' || wcSecond == 'A')
     4560        {
     4561            if (wcThird == 'c' || wcThird == 'C')
     4562                return K_TRUE;
     4563        }
     4564    }
     4565    else if (fAttrQuery)
     4566    {
     4567        /* Dynamic link library: .dll */
     4568        if (wcFirst == 'd' || wcFirst == 'D')
     4569        {
     4570            if (wcSecond == 'l' || wcSecond == 'L')
     4571            {
     4572                if (wcThird == 'l' || wcThird == 'L')
     4573                    return K_TRUE;
     4574            }
     4575        }
     4576        /* Executable file: .exe */
     4577        else if (wcFirst == 'e' || wcFirst == 'E')
     4578        {
     4579            if (wcSecond == 'x' || wcSecond == 'X')
     4580            {
     4581                if (wcThird == 'e' || wcThird == 'e')
     4582                    return K_TRUE;
     4583            }
     4584        }
     4585    }
     4586
     4587    return K_FALSE;
     4588}
     4589
    45064590
    45074591/**
     
    45144598 *                              file creation.
    45154599 */
    4516 static KBOOL kwFsIsCachableExtensionA(const char *pszExt, KBOOL fAttrQuery)
    4517 {
    4518     char const chFirst = *pszExt;
    4519 
    4520     /* C++ header without an extension or a directory. */
    4521     if (chFirst == '\0')
    4522     {
    4523         /** @todo exclude temporary files...  */
    4524         return K_TRUE;
    4525     }
    4526 
    4527     /* C Header: .h */
    4528     if (chFirst == 'h' || chFirst == 'H')
    4529     {
    4530         char        chThird;
    4531         char const  chSecond = pszExt[1];
    4532         if (chSecond == '\0')
    4533             return K_TRUE;
    4534         chThird = pszExt[2];
    4535 
    4536         /* C++ Header: .hpp, .hxx */
    4537         if (   (chSecond == 'p' || chSecond == 'P')
    4538             && (chThird  == 'p' || chThird  == 'P')
    4539             && pszExt[3] == '\0')
    4540             return K_TRUE;
    4541         if (   (chSecond == 'x' || chSecond == 'X')
    4542             && (chThird  == 'x' || chThird  == 'X')
    4543             && pszExt[3] == '\0')
    4544             return K_TRUE;
    4545     }
    4546     /* Misc starting with i. */
    4547     else if (chFirst == 'i' || chFirst == 'I')
    4548     {
    4549         char const chSecond = pszExt[1];
    4550         if (chSecond != '\0')
    4551         {
    4552             if (chSecond == 'n' || chSecond == 'N')
    4553             {
    4554                 char const chThird = pszExt[2];
    4555 
    4556                 /* C++ inline header: .inl */
    4557                 if (   (chThird == 'l' || chThird == 'L')
    4558                     && pszExt[3] == '\0')
    4559                     return K_TRUE;
    4560 
    4561                 /* Assembly include file: .inc */
    4562                 if (   (chThird == 'c' || chThird == 'C')
    4563                     && pszExt[3] == '\0')
    4564                     return K_TRUE;
    4565             }
    4566         }
    4567     }
    4568     /* Assembly header: .mac */
    4569     else if (chFirst == 'm' || chFirst == 'M')
    4570     {
    4571         char const  chSecond = pszExt[1];
    4572         if (chSecond == 'a' || chSecond == 'A')
    4573         {
    4574             char const chThird = pszExt[2];
    4575             if (  (chThird == 'c' || chThird == 'C')
    4576                 && pszExt[3] == '\0')
    4577                 return K_TRUE;
    4578         }
    4579     }
    4580     else if (fAttrQuery)
    4581     {
    4582         /* Dynamic link library: .dll */
    4583         if (chFirst == 'd' || chFirst == 'D')
    4584         {
    4585             char const chSecond = pszExt[1];
    4586             if (chSecond == 'l' || chSecond == 'L')
    4587             {
    4588                 char const chThird = pszExt[2];
    4589                 if (chThird == 'l' || chThird == 'L')
    4590                     return K_TRUE;
    4591             }
    4592         }
    4593         /* Executable file: .exe */
    4594         else if (chFirst == 'e' || chFirst == 'E')
    4595         {
    4596             char const chSecond = pszExt[1];
    4597             if (chSecond == 'x' || chSecond == 'X')
    4598             {
    4599                 char const chThird = pszExt[2];
    4600                 if (chThird == 'e' || chThird == 'e')
    4601                     return K_TRUE;
    4602             }
    4603         }
    4604     }
    4605 
    4606     return K_FALSE;
     4600static KBOOL kwFsIsCacheableExtensionA(const char *pszExt, KBOOL fAttrQuery)
     4601{
     4602    wchar_t const wcFirst = *pszExt;
     4603    if (wcFirst)
     4604    {
     4605        wchar_t const wcSecond = pszExt[1];
     4606        if (wcSecond)
     4607        {
     4608            wchar_t const wcThird = pszExt[2];
     4609            if (pszExt[3] == '\0')
     4610                return kwFsIsCacheableExtensionCommon(wcFirst, wcSecond, wcThird, fAttrQuery);
     4611            return K_FALSE;
     4612        }
     4613        return kwFsIsCacheableExtensionCommon(wcFirst, 0, 0, fAttrQuery);
     4614    }
     4615    return kwFsIsCacheableExtensionCommon(0, 0, 0, fAttrQuery);
    46074616}
    46084617
     
    46174626 *                              file creation.
    46184627 */
    4619 static KBOOL kwFsIsCachablePathExtensionW(const wchar_t *pwszPath, KBOOL fAttrQuery)
    4620 {
    4621     /*
    4622      * Extract the extension, check that it's in the applicable range, roughly
    4623      * convert it to ASCII/ANSI, and feed it to kwFsIsCachableExtensionA for
    4624      * the actual check.  This avoids a lot of code duplication.
    4625      */
    4626     wchar_t         wc;
    4627     char            szExt[4];
     4628static KBOOL kwFsIsCacheablePathExtensionW(const wchar_t *pwszPath, KBOOL fAttrQuery)
     4629{
    46284630    KSIZE           cwcExt;
    46294631    wchar_t const  *pwszExt = kwFsPathGetExtW(pwszPath, &cwcExt);
    46304632    switch (cwcExt)
    46314633    {
    4632         case 3: if ((wchar_t)(szExt[2] = (char)(wc = pwszExt[2])) == wc) { /*likely*/ } else break;
    4633         case 2: if ((wchar_t)(szExt[1] = (char)(wc = pwszExt[1])) == wc) { /*likely*/ } else break;
    4634         case 1: if ((wchar_t)(szExt[0] = (char)(wc = pwszExt[0])) == wc) { /*likely*/ } else break;
    4635         case 0:
    4636             szExt[cwcExt] = '\0';
    4637             return kwFsIsCachableExtensionA(szExt, fAttrQuery);
     4634        case 3: kwFsIsCacheableExtensionCommon(pwszExt[0], pwszExt[1], pwszExt[2], fAttrQuery);
     4635        case 2: kwFsIsCacheableExtensionCommon(pwszExt[0], pwszExt[1], 0,          fAttrQuery);
     4636        case 1: kwFsIsCacheableExtensionCommon(pwszExt[0], 0,          0,          fAttrQuery);
     4637        case 0: kwFsIsCacheableExtensionCommon(0,          0,          0,          fAttrQuery);
    46384638    }
    46394639    return K_FALSE;
     
    48274827                {
    48284828                    const char *pszExt = kHlpGetExt(pszFilename);
    4829                     if (kwFsIsCachableExtensionA(pszExt, K_FALSE /*fAttrQuery*/))
     4829                    if (kwFsIsCacheableExtensionA(pszExt, K_FALSE /*fAttrQuery*/))
    48304830                    {
    48314831                        KFSLOOKUPERROR enmError;
     
    49184918                        && pSecAttrs->lpSecurityDescriptor == NULL ) )
    49194919                {
    4920                     if (kwFsIsCachablePathExtensionW(pwszFilename, K_FALSE /*fAttrQuery*/))
     4920                    if (kwFsIsCacheablePathExtensionW(pwszFilename, K_FALSE /*fAttrQuery*/))
    49214921                    {
    49224922                        /** @todo rewrite in pure UTF-16. */
     
    53275327        && cchToWrite <= pOutBuf->u.Fully.cchBufAlloc - pOutBuf->u.Fully.cchBuf)
    53285328    {
    5329         memcpy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchToWrite);
     5329        kHlpMemCopy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchToWrite);
    53305330        pOutBuf->u.Fully.cchBuf += cchToWrite;
    53315331    }
     
    53435343            if (cchLine <= pOutBuf->u.Fully.cchBufAlloc - pOutBuf->u.Fully.cchBuf)
    53445344            {
    5345                 memcpy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchLine);
     5345                kHlpMemCopy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchLine);
    53465346                pOutBuf->u.Fully.cchBuf += cchLine;
    53475347            }
     
    53715371                KWOUT_LOG(("kwSandboxOutBufWrite: flushing %u bytes\n", pOutBuf->u.Fully.cchBuf));
    53725372                kwSandboxOutBufWriteIt(pOutBuf->hBackup, pOutBuf->u.Fully.pchBuf, pOutBuf->u.Fully.cchBuf);
    5373                 memcpy(&pOutBuf->u.Fully.pchBuf[0], pchBuffer, cchLine);
     5373                kHlpMemCopy(&pOutBuf->u.Fully.pchBuf[0], pchBuffer, cchLine);
    53745374                pOutBuf->u.Fully.cchBuf = cchLine;
    53755375            }
     
    60326032    DWORD       fRet;
    60336033    const char *pszExt = kHlpGetExt(pszFilename);
    6034     if (kwFsIsCachableExtensionA(pszExt, K_TRUE /*fAttrQuery*/))
     6034    if (kwFsIsCacheableExtensionA(pszExt, K_TRUE /*fAttrQuery*/))
    60356035    {
    60366036        KFSLOOKUPERROR enmError;
     
    60656065{
    60666066    DWORD fRet;
    6067     if (kwFsIsCachablePathExtensionW(pwszFilename, K_TRUE /*fAttrQuery*/))
     6067    if (kwFsIsCacheablePathExtensionW(pwszFilename, K_TRUE /*fAttrQuery*/))
    60686068    {
    60696069        KFSLOOKUPERROR enmError;
     
    61006100{
    61016101    DWORD cwcRet;
    6102     if (kwFsIsCachablePathExtensionW(pwszLongPath, K_TRUE /*fAttrQuery*/))
     6102    if (kwFsIsCacheablePathExtensionW(pwszLongPath, K_TRUE /*fAttrQuery*/))
    61036103    {
    61046104        KFSLOOKUPERROR enmError;
     
    62536253    else
    62546254    {
    6255         memcpy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf], pwcBuf, cwcBuf * sizeof(wchar_t));
     6255        kHlpMemCopy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf], pwcBuf, cwcBuf * sizeof(wchar_t));
    62566256        pSandbox->Combined.cwcBuf += cwcBuf;
    62576257    }
     
    64676467            if (offLastIncompleteLine == 0)
    64686468            {
    6469                 memcpy(&pLineBuf->u.Con.pwcBuf[pLineBuf->u.Con.cwcBuf], pwcBuffer, cwcToWrite * sizeof(wchar_t));
     6469                kHlpMemCopy(&pLineBuf->u.Con.pwcBuf[pLineBuf->u.Con.cwcBuf], pwcBuffer, cwcToWrite * sizeof(wchar_t));
    64706470                pLineBuf->u.Con.cwcBuf += cwcToWrite;
    64716471                return;
     
    64806480            if (pLineBuf->u.Con.cwcBuf > 0)
    64816481            {
    6482                 memcpy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf],
    6483                        pLineBuf->u.Con.pwcBuf, pLineBuf->u.Con.cwcBuf * sizeof(wchar_t));
     6482                kHlpMemCopy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf],
     6483                            pLineBuf->u.Con.pwcBuf, pLineBuf->u.Con.cwcBuf * sizeof(wchar_t));
    64846484                pSandbox->Combined.cwcBuf += pLineBuf->u.Con.cwcBuf;
    64856485                pLineBuf->u.Con.cwcBuf = 0;
    64866486            }
    64876487
    6488             memcpy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf],
    6489                    pwcBuffer, offLastIncompleteLine * sizeof(wchar_t));
     6488            kHlpMemCopy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf],
     6489                        pwcBuffer, offLastIncompleteLine * sizeof(wchar_t));
    64906490            pSandbox->Combined.cwcBuf += offLastIncompleteLine;
    64916491        }
     
    65106510                if (pLineBuf->u.Con.cwcBuf + offNextLine + pSandbox->Combined.cwcBuf <= K_ELEMENTS(pSandbox->Combined.wszBuf))
    65116511                {
    6512                     memcpy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf],
    6513                            pLineBuf->u.Con.pwcBuf, pLineBuf->u.Con.cwcBuf * sizeof(wchar_t));
     6512                    kHlpMemCopy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf],
     6513                                pLineBuf->u.Con.pwcBuf, pLineBuf->u.Con.cwcBuf * sizeof(wchar_t));
    65146514                    pSandbox->Combined.cwcBuf += pLineBuf->u.Con.cwcBuf;
    65156515                    pLineBuf->u.Con.cwcBuf = 0;
    65166516
    6517                     memcpy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf], pwcBuffer, offNextLine * sizeof(wchar_t));
     6517                    kHlpMemCopy(&pSandbox->Combined.wszBuf[pSandbox->Combined.cwcBuf], pwcBuffer, offNextLine * sizeof(wchar_t));
    65186518                    pSandbox->Combined.cwcBuf += offNextLine;
    65196519                }
     
    65246524                    {
    65256525                        KU32 cwcCopy = K_MIN(cwcLeft, offNextLine);
    6526                         memcpy(&pLineBuf->u.Con.pwcBuf[pLineBuf->u.Con.cwcBuf], pwcBuffer, cwcCopy * sizeof(wchar_t));
     6526                        kHlpMemCopy(&pLineBuf->u.Con.pwcBuf[pLineBuf->u.Con.cwcBuf], pwcBuffer, cwcCopy * sizeof(wchar_t));
    65276527                        pLineBuf->u.Con.cwcBuf += cwcCopy;
    65286528                        off += cwcCopy;
     
    65576557        if (offLastIncompleteLine < cwcToWrite)
    65586558        {
    6559             memcpy(&pLineBuf->u.Con.pwcBuf[0], &pwcBuffer[offLastIncompleteLine], cchLastIncompleteLine * sizeof(wchar_t));
     6559            kHlpMemCopy(&pLineBuf->u.Con.pwcBuf[0], &pwcBuffer[offLastIncompleteLine], cchLastIncompleteLine * sizeof(wchar_t));
    65606560            pLineBuf->u.Con.cwcBuf = cchLastIncompleteLine;
    65616561        }
Note: See TracChangeset for help on using the changeset viewer.