- Timestamp:
- Jun 8, 2020 11:35:21 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/kWorker.c
r3361 r3365 646 646 KWHANDLETYPE_FSOBJ_READ_CACHE, 647 647 KWHANDLETYPE_FSOBJ_READ_CACHE_MAPPING, 648 #ifdef WITH_TEMP_MEMORY_FILES 648 649 KWHANDLETYPE_TEMP_FILE, 649 650 KWHANDLETYPE_TEMP_FILE_MAPPING, 651 #endif 650 652 KWHANDLETYPE_OUTPUT_BUF 651 653 } KWHANDLETYPE; … … 669 671 /** The file system object. */ 670 672 PKFSWCACHEDFILE pCachedFile; 673 #ifdef WITH_TEMP_MEMORY_FILES 671 674 /** Temporary file handle or mapping handle. */ 672 675 PKWFSTEMPFILE pTempFile; 676 #endif 673 677 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING 674 678 /** Buffered output stream. */ … … 696 700 /** The file system object. */ 697 701 PKFSWCACHEDFILE pCachedFile; 702 #ifdef WITH_TEMP_MEMORY_FILES 698 703 /** Temporary file handle or mapping handle. */ 699 704 PKWFSTEMPFILE pTempFile; 705 #endif 700 706 } u; 701 707 } KWMEMMAPPING; … … 888 894 PKWMEMMAPPING paMemMappings; 889 895 896 #ifdef WITH_TEMP_MEMORY_FILES 890 897 /** Head of the list of temporary file. */ 891 898 PKWFSTEMPFILE pTempFileHead; 899 #endif 892 900 893 901 /** Critical section protecting pVirtualAllocHead. */ … … 6956 6964 kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread); 6957 6965 6958 pFsObj = kFsCacheLookup NoMissingA(g_pFsCache, pszFilename, &enmError);6966 pFsObj = kFsCacheLookupA(g_pFsCache, pszFilename, &enmError); 6959 6967 if (pFsObj) 6960 6968 { 6961 KBOOL fRc = kwFsObjCacheCreateFile(pFsObj, dwDesiredAccess, pSecAttrs && pSecAttrs->bInheritHandle, 6962 &hFile); 6963 kFsCacheObjRelease(g_pFsCache, pFsObj); 6964 if (fRc) 6969 if (pFsObj->bObjType != KFSOBJ_TYPE_MISSING) 6965 6970 { 6966 KWFS_LOG(("CreateFileA(%s) -> %p [cached]\n", pszFilename, hFile)); 6967 return hFile; 6971 KBOOL fRc = kwFsObjCacheCreateFile(pFsObj, dwDesiredAccess, 6972 pSecAttrs && pSecAttrs->bInheritHandle, &hFile); 6973 kFsCacheObjRelease(g_pFsCache, pFsObj); 6974 if (fRc) 6975 { 6976 KWFS_LOG(("CreateFileA(%s) -> %p [cached]\n", pszFilename, hFile)); 6977 return hFile; 6978 } 6968 6979 } 6980 else if (!(pFsObj->fFlags & KFSOBJ_F_USE_CUSTOM_GEN)) 6981 { 6982 KWFS_LOG(("CreateFileA(%ls) -> INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND\n", pszFilename)); 6983 return INVALID_HANDLE_VALUE; 6984 } 6985 /* Always fall back on missing files in volatile areas. */ 6969 6986 } 6970 6987 /* These are for nasm and yasm header searching. Cache will already … … 7055 7072 kHlpAssert(GetCurrentThreadId() == g_Sandbox.idMainThread); 7056 7073 7057 pFsObj = kFsCacheLookup NoMissingW(g_pFsCache, pwszFilename, &enmError);7074 pFsObj = kFsCacheLookupW(g_pFsCache, pwszFilename, &enmError); 7058 7075 if (pFsObj) 7059 7076 { 7060 KBOOL fRc = kwFsObjCacheCreateFile(pFsObj, dwDesiredAccess, pSecAttrs && pSecAttrs->bInheritHandle, 7061 &hFile); 7062 kFsCacheObjRelease(g_pFsCache, pFsObj); 7063 if (fRc) 7077 if (pFsObj->bObjType != KFSOBJ_TYPE_MISSING) 7064 7078 { 7065 KWFS_LOG(("CreateFileW(%ls) -> %p [cached]\n", pwszFilename, hFile)); 7066 return hFile; 7079 KBOOL fRc = kwFsObjCacheCreateFile(pFsObj, dwDesiredAccess, 7080 pSecAttrs && pSecAttrs->bInheritHandle, &hFile); 7081 kFsCacheObjRelease(g_pFsCache, pFsObj); 7082 if (fRc) 7083 { 7084 KWFS_LOG(("CreateFileW(%ls) -> %p [cached]\n", pwszFilename, hFile)); 7085 return hFile; 7086 } 7067 7087 } 7088 else if (!(pFsObj->fFlags & KFSOBJ_F_USE_CUSTOM_GEN)) 7089 { 7090 KWFS_LOG(("CreateFileW(%ls) -> INVALID_HANDLE_VALUE, ERROR_FILE_NOT_FOUND\n", pwszFilename)); 7091 return INVALID_HANDLE_VALUE; 7092 } 7093 /* Always fall back on missing files in volatile areas. */ 7068 7094 } 7069 7095 /* These are for nasm and yasm style header searching. Cache will … … 7138 7164 cbFile = pHandle->u.pTempFile->cbFile; 7139 7165 break; 7166 case KWHANDLETYPE_TEMP_FILE_MAPPING: 7140 7167 #endif 7141 case KWHANDLETYPE_TEMP_FILE_MAPPING:7142 7168 case KWHANDLETYPE_OUTPUT_BUF: 7143 7169 default: … … 7166 7192 if (offMove >= (KSSIZE)cbFile) 7167 7193 { 7194 #ifdef WITH_TEMP_MEMORY_FILES 7168 7195 /* For read-only files, seeking beyond the end isn't useful to us, so clamp it. */ 7169 7196 if (pHandle->enmType != KWHANDLETYPE_TEMP_FILE) 7197 #endif 7170 7198 offMove = (KSSIZE)cbFile; 7199 #ifdef WITH_TEMP_MEMORY_FILES 7171 7200 /* For writable files, seeking beyond the end is fine, but check that we've got 7172 7201 the type range for the request. */ … … 7177 7206 return INVALID_SET_FILE_POINTER; 7178 7207 } 7208 #endif 7179 7209 } 7180 7210 pHandle->offFile = (KU32)offMove; … … 7221 7251 cbFile = pHandle->u.pTempFile->cbFile; 7222 7252 break; 7253 case KWHANDLETYPE_TEMP_FILE_MAPPING: 7223 7254 #endif 7224 case KWHANDLETYPE_TEMP_FILE_MAPPING:7225 7255 case KWHANDLETYPE_OUTPUT_BUF: 7226 7256 default: … … 7249 7279 if (offMyMove >= (KSSIZE)cbFile) 7250 7280 { 7281 #ifdef WITH_TEMP_MEMORY_FILES 7251 7282 /* For read-only files, seeking beyond the end isn't useful to us, so clamp it. */ 7252 7283 if (pHandle->enmType != KWHANDLETYPE_TEMP_FILE) 7284 #endif 7253 7285 offMyMove = (KSSIZE)cbFile; 7286 #ifdef WITH_TEMP_MEMORY_FILES 7254 7287 /* For writable files, seeking beyond the end is fine, but check that we've got 7255 7288 the type range for the request. */ … … 7260 7293 return INVALID_SET_FILE_POINTER; 7261 7294 } 7295 #endif 7262 7296 } 7263 7297 pHandle->offFile = (KU32)offMyMove; … … 7388 7422 return TRUE; 7389 7423 } 7424 7425 case KWHANDLETYPE_TEMP_FILE_MAPPING: 7390 7426 #endif /* WITH_TEMP_MEMORY_FILES */ 7391 7392 case KWHANDLETYPE_TEMP_FILE_MAPPING:7393 7427 case KWHANDLETYPE_OUTPUT_BUF: 7394 7428 default: … … 7732 7766 7733 7767 default: 7768 #ifdef WITH_TEMP_MEMORY_FILES 7734 7769 case KWHANDLETYPE_TEMP_FILE_MAPPING: 7770 #endif 7735 7771 kHlpAssertFailed(); 7736 7772 SetLastError(ERROR_INVALID_FUNCTION); … … 7805 7841 return FALSE; 7806 7842 7843 # ifdef WITH_CONSOLE_OUTPUT_BUFFERING 7807 7844 case KWHANDLETYPE_OUTPUT_BUF: 7808 7845 kHlpAssertFailed(); 7809 7846 SetLastError(pHandle->u.pOutBuf->fIsConsole ? ERROR_INVALID_OPERATION : ERROR_ACCESS_DENIED); 7810 7847 return FALSE; 7848 # endif 7811 7849 7812 7850 default: … … 7844 7882 return FILE_TYPE_DISK; 7845 7883 7884 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING 7846 7885 case KWHANDLETYPE_OUTPUT_BUF: 7847 7886 { … … 7860 7899 return fRet; 7861 7900 } 7901 #endif 7862 7902 7863 7903 } … … 8374 8414 else 8375 8415 { 8416 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING 8376 8417 KWFS_LOG(("CloseHandle(%p) -> TRUE [intercepted handle] Ignored closing of std%s!\n", 8377 8418 hObject, hObject == g_Sandbox.StdErr.hOutput ? "err" : "out")); 8419 #else 8420 KWFS_LOG(("CloseHandle(%p) -> TRUE [intercepted handle] Ignored closing of stdXXX!\n", hObject)); 8421 #endif 8378 8422 fRet = TRUE; 8379 8423 } … … 10463 10507 #endif 10464 10508 10509 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING 10465 10510 { TUPLE("WriteConsoleA"), NULL, (KUPTR)kwSandbox_Kernel32_WriteConsoleA }, 10466 10511 { TUPLE("WriteConsoleW"), NULL, (KUPTR)kwSandbox_Kernel32_WriteConsoleW }, 10512 #endif 10467 10513 10468 10514 { TUPLE("VirtualAlloc"), NULL, (KUPTR)kwSandbox_Kernel32_VirtualAlloc }, … … 10606 10652 { TUPLE("LoadLibraryExA"), NULL, (KUPTR)kwSandbox_Kernel32_Native_LoadLibraryExA }, 10607 10653 10654 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING 10608 10655 { TUPLE("WriteConsoleA"), NULL, (KUPTR)kwSandbox_Kernel32_WriteConsoleA }, 10609 10656 { TUPLE("WriteConsoleW"), NULL, (KUPTR)kwSandbox_Kernel32_WriteConsoleW }, 10657 #endif 10610 10658 10611 10659 #ifdef WITH_HASH_MD5_CACHE … … 11196 11244 idxHandle, pHandle->hHandle, pHandle->cRefs)); 11197 11245 break; 11246 #ifdef WITH_TEMP_MEMORY_FILES 11198 11247 case KWHANDLETYPE_TEMP_FILE: 11199 11248 KWFS_LOG(("Closing leaked temp file handle: %#x/%p cRefs=%d\n", … … 11206 11255 pHandle->u.pTempFile->cActiveHandles--; 11207 11256 break; 11257 #endif 11208 11258 default: 11209 11259 kHlpAssertFailed(); … … 11404 11454 PMY_RTL_USER_PROCESS_PARAMETERS pProcParams = (PMY_RTL_USER_PROCESS_PARAMETERS)pPeb->ProcessParameters; 11405 11455 pProcParams->CommandLine = pSandbox->SavedCommandLine; 11456 #ifdef WITH_CONSOLE_OUTPUT_BUFFERING 11406 11457 pProcParams->StandardOutput = pSandbox->StdOut.hOutput; 11407 11458 pProcParams->StandardError = pSandbox->StdErr.hOutput; /* CL.EXE messes with this one. */ 11459 #endif 11408 11460 } 11409 11461 … … 12848 12900 const char *pszTmp; 12849 12901 KFSLOOKUPERROR enmIgnored; 12902 DWORD dwType; 12850 12903 #if defined(KBUILD_OS_WINDOWS) && defined(KBUILD_ARCH_X86) 12851 12904 PVOID pvVecXcptHandler = AddVectoredExceptionHandler(0 /*called last*/, … … 12856 12909 PPEB pPeb = kwSandboxGetProcessEnvironmentBlock(); 12857 12910 PMY_RTL_USER_PROCESS_PARAMETERS pProcessParams = (PMY_RTL_USER_PROCESS_PARAMETERS)pPeb->ProcessParameters; 12858 DWORD dwType;12859 12911 #endif 12860 12912
Note:
See TracChangeset
for help on using the changeset viewer.