- Timestamp:
- Sep 18, 2016, 6:47:16 PM (9 years ago)
- Location:
- trunk/src/kWorker
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/Makefile.kmk
r2894 r2934 48 48 $(PATH_SDK_WINDDK71_LIB_WNET)/psapi.lib 49 49 kWorker_LDFLAGS.win = \ 50 /BASE:0x10000 /DYNAMICBASE:NO /FIXED /SECTION:DefLdBuf,EWR50 /BASE:0x10000 /DYNAMICBASE:NO /FIXED 51 51 52 52 -
trunk/src/kWorker/kWorker.c
r2933 r2934 4504 4504 #endif /* WITH_TEMP_MEMORY_FILES */ 4505 4505 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 */ 4516 static 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 4506 4590 4507 4591 /** … … 4514 4598 * file creation. 4515 4599 */ 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; 4600 static 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); 4607 4616 } 4608 4617 … … 4617 4626 * file creation. 4618 4627 */ 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]; 4628 static KBOOL kwFsIsCacheablePathExtensionW(const wchar_t *pwszPath, KBOOL fAttrQuery) 4629 { 4628 4630 KSIZE cwcExt; 4629 4631 wchar_t const *pwszExt = kwFsPathGetExtW(pwszPath, &cwcExt); 4630 4632 switch (cwcExt) 4631 4633 { 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); 4638 4638 } 4639 4639 return K_FALSE; … … 4827 4827 { 4828 4828 const char *pszExt = kHlpGetExt(pszFilename); 4829 if (kwFsIsCach ableExtensionA(pszExt, K_FALSE /*fAttrQuery*/))4829 if (kwFsIsCacheableExtensionA(pszExt, K_FALSE /*fAttrQuery*/)) 4830 4830 { 4831 4831 KFSLOOKUPERROR enmError; … … 4918 4918 && pSecAttrs->lpSecurityDescriptor == NULL ) ) 4919 4919 { 4920 if (kwFsIsCach ablePathExtensionW(pwszFilename, K_FALSE /*fAttrQuery*/))4920 if (kwFsIsCacheablePathExtensionW(pwszFilename, K_FALSE /*fAttrQuery*/)) 4921 4921 { 4922 4922 /** @todo rewrite in pure UTF-16. */ … … 5327 5327 && cchToWrite <= pOutBuf->u.Fully.cchBufAlloc - pOutBuf->u.Fully.cchBuf) 5328 5328 { 5329 memcpy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchToWrite);5329 kHlpMemCopy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchToWrite); 5330 5330 pOutBuf->u.Fully.cchBuf += cchToWrite; 5331 5331 } … … 5343 5343 if (cchLine <= pOutBuf->u.Fully.cchBufAlloc - pOutBuf->u.Fully.cchBuf) 5344 5344 { 5345 memcpy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchLine);5345 kHlpMemCopy(&pOutBuf->u.Fully.pchBuf[pOutBuf->u.Fully.cchBuf], pchBuffer, cchLine); 5346 5346 pOutBuf->u.Fully.cchBuf += cchLine; 5347 5347 } … … 5371 5371 KWOUT_LOG(("kwSandboxOutBufWrite: flushing %u bytes\n", pOutBuf->u.Fully.cchBuf)); 5372 5372 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); 5374 5374 pOutBuf->u.Fully.cchBuf = cchLine; 5375 5375 } … … 6032 6032 DWORD fRet; 6033 6033 const char *pszExt = kHlpGetExt(pszFilename); 6034 if (kwFsIsCach ableExtensionA(pszExt, K_TRUE /*fAttrQuery*/))6034 if (kwFsIsCacheableExtensionA(pszExt, K_TRUE /*fAttrQuery*/)) 6035 6035 { 6036 6036 KFSLOOKUPERROR enmError; … … 6065 6065 { 6066 6066 DWORD fRet; 6067 if (kwFsIsCach ablePathExtensionW(pwszFilename, K_TRUE /*fAttrQuery*/))6067 if (kwFsIsCacheablePathExtensionW(pwszFilename, K_TRUE /*fAttrQuery*/)) 6068 6068 { 6069 6069 KFSLOOKUPERROR enmError; … … 6100 6100 { 6101 6101 DWORD cwcRet; 6102 if (kwFsIsCach ablePathExtensionW(pwszLongPath, K_TRUE /*fAttrQuery*/))6102 if (kwFsIsCacheablePathExtensionW(pwszLongPath, K_TRUE /*fAttrQuery*/)) 6103 6103 { 6104 6104 KFSLOOKUPERROR enmError; … … 6253 6253 else 6254 6254 { 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)); 6256 6256 pSandbox->Combined.cwcBuf += cwcBuf; 6257 6257 } … … 6467 6467 if (offLastIncompleteLine == 0) 6468 6468 { 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)); 6470 6470 pLineBuf->u.Con.cwcBuf += cwcToWrite; 6471 6471 return; … … 6480 6480 if (pLineBuf->u.Con.cwcBuf > 0) 6481 6481 { 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)); 6484 6484 pSandbox->Combined.cwcBuf += pLineBuf->u.Con.cwcBuf; 6485 6485 pLineBuf->u.Con.cwcBuf = 0; 6486 6486 } 6487 6487 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)); 6490 6490 pSandbox->Combined.cwcBuf += offLastIncompleteLine; 6491 6491 } … … 6510 6510 if (pLineBuf->u.Con.cwcBuf + offNextLine + pSandbox->Combined.cwcBuf <= K_ELEMENTS(pSandbox->Combined.wszBuf)) 6511 6511 { 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)); 6514 6514 pSandbox->Combined.cwcBuf += pLineBuf->u.Con.cwcBuf; 6515 6515 pLineBuf->u.Con.cwcBuf = 0; 6516 6516 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)); 6518 6518 pSandbox->Combined.cwcBuf += offNextLine; 6519 6519 } … … 6524 6524 { 6525 6525 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)); 6527 6527 pLineBuf->u.Con.cwcBuf += cwcCopy; 6528 6528 off += cwcCopy; … … 6557 6557 if (offLastIncompleteLine < cwcToWrite) 6558 6558 { 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)); 6560 6560 pLineBuf->u.Con.cwcBuf = cchLastIncompleteLine; 6561 6561 }
Note:
See TracChangeset
for help on using the changeset viewer.