diff options
Diffstat (limited to 'src/ToolBox/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp')
-rw-r--r-- | src/ToolBox/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/src/ToolBox/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp b/src/ToolBox/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp index 1a6d73da0a..c8af7a0c26 100644 --- a/src/ToolBox/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp +++ b/src/ToolBox/superpmi/superpmi-shim-collector/superpmi-shim-collector.cpp @@ -16,18 +16,18 @@ #include "spmiutil.h" #include "jithost.h" -//Assumptions: +// Assumptions: // -We'll never be unloaded - we leak memory and have no facility to unload libraries // -printf output to console is okay -HMODULE g_hRealJit = 0; //We leak this currently (could do the proper shutdown in process_detach) -WCHAR* g_realJitPath = nullptr; //We leak this (could do the proper shutdown in process_detach) -WCHAR* g_logPath = nullptr; //Again, we leak this one too... -WCHAR* g_dataFileName = nullptr; //We leak this -char* g_logFilePath = nullptr; //We *don't* leak this, hooray! -WCHAR* g_HomeDirectory = nullptr; -WCHAR* g_DefaultRealJitPath = nullptr; -MethodContext* g_globalContext = nullptr; +HMODULE g_hRealJit = 0; // We leak this currently (could do the proper shutdown in process_detach) +WCHAR* g_realJitPath = nullptr; // We leak this (could do the proper shutdown in process_detach) +WCHAR* g_logPath = nullptr; // Again, we leak this one too... +WCHAR* g_dataFileName = nullptr; // We leak this +char* g_logFilePath = nullptr; // We *don't* leak this, hooray! +WCHAR* g_HomeDirectory = nullptr; +WCHAR* g_DefaultRealJitPath = nullptr; +MethodContext* g_globalContext = nullptr; void SetDefaultPaths() { @@ -38,7 +38,7 @@ void SetDefaultPaths() if (g_DefaultRealJitPath == nullptr) { - size_t len = wcslen(g_HomeDirectory) + 1 + wcslen(DEFAULT_REAL_JIT_NAME_W) + 1; + size_t len = wcslen(g_HomeDirectory) + 1 + wcslen(DEFAULT_REAL_JIT_NAME_W) + 1; g_DefaultRealJitPath = new WCHAR[len]; wcscpy_s(g_DefaultRealJitPath, len, g_HomeDirectory); wcscat_s(g_DefaultRealJitPath, len, DIRECTORY_SEPARATOR_STR_W); @@ -64,30 +64,33 @@ void SetLogPath() void SetLogPathName() { - // NOTE: under PAL, we don't get the comand line, so we depend on the random number generator to give us a unique filename. - WCHAR *OriginalExecutableName = GetCommandLineW();//TODO-Cleanup: not cool to write to the process view of commandline.... - size_t len = wcslen(OriginalExecutableName); - WCHAR *ExecutableName = new WCHAR[len+1]; - wcscpy_s(ExecutableName, len+1, OriginalExecutableName); + // NOTE: under PAL, we don't get the comand line, so we depend on the random number generator to give us a unique + // filename. + WCHAR* OriginalExecutableName = + GetCommandLineW(); // TODO-Cleanup: not cool to write to the process view of commandline.... + size_t len = wcslen(OriginalExecutableName); + WCHAR* ExecutableName = new WCHAR[len + 1]; + wcscpy_s(ExecutableName, len + 1, OriginalExecutableName); ExecutableName[len] = W('\0'); - WCHAR *quote1 = NULL; + WCHAR* quote1 = NULL; - //if there are any quotes in filename convert them to spaces. + // if there are any quotes in filename convert them to spaces. while ((quote1 = wcsstr(ExecutableName, W("\""))) != NULL) *quote1 = W(' '); - //remove any illegal or annoying characters from file name by converting them to underscores + // remove any illegal or annoying characters from file name by converting them to underscores while ((quote1 = wcspbrk(ExecutableName, W("=<>:\"/\\|?! *.,"))) != NULL) *quote1 = W('_'); - const WCHAR *DataFileExtension = W(".mc"); - size_t ExecutableNameLength = wcslen(ExecutableName); - size_t DataFileExtensionLength = wcslen(DataFileExtension); - size_t logPathLength = wcslen(g_logPath); + const WCHAR* DataFileExtension = W(".mc"); + size_t ExecutableNameLength = wcslen(ExecutableName); + size_t DataFileExtensionLength = wcslen(DataFileExtension); + size_t logPathLength = wcslen(g_logPath); size_t dataFileNameLength = logPathLength + 1 + ExecutableNameLength + 1 + DataFileExtensionLength + 1; - const size_t MaxAcceptablePathLength = MAX_PATH - 20; // subtract 20 to leave buffer, for possible random number addition + const size_t MaxAcceptablePathLength = + MAX_PATH - 20; // subtract 20 to leave buffer, for possible random number addition if (dataFileNameLength >= MaxAcceptablePathLength) { // The path name is too long; creating the file will fail. This can happen because we use the command line, @@ -99,17 +102,17 @@ void SetLogPathName() dataFileNameLength = MaxAcceptablePathLength; } - // Always add a random number, just in case the above doesn't give us a unique filename. +// Always add a random number, just in case the above doesn't give us a unique filename. #ifdef FEATURE_PAL - unsigned __int64 randNumber = 0; - const size_t RandNumberLength = sizeof(randNumber) * 2 + 1; // 16 hex digits + null - WCHAR RandNumberString[RandNumberLength]; + unsigned __int64 randNumber = 0; + const size_t RandNumberLength = sizeof(randNumber) * 2 + 1; // 16 hex digits + null + WCHAR RandNumberString[RandNumberLength]; PAL_Random(/* bStrong */ FALSE, &randNumber, sizeof(randNumber)); swprintf_s(RandNumberString, RandNumberLength, W("%016llX"), randNumber); -#else // !FEATURE_PAL - unsigned int randNumber = 0; +#else // !FEATURE_PAL + unsigned int randNumber = 0; const size_t RandNumberLength = sizeof(randNumber) * 2 + 1; // 8 hex digits + null - WCHAR RandNumberString[RandNumberLength]; + WCHAR RandNumberString[RandNumberLength]; rand_s(&randNumber); swprintf_s(RandNumberString, RandNumberLength, W("%08X"), randNumber); #endif // !FEATURE_PAL @@ -117,7 +120,7 @@ void SetLogPathName() dataFileNameLength += RandNumberLength - 1; // Construct the full pathname we're going to use. - g_dataFileName = new WCHAR[dataFileNameLength]; + g_dataFileName = new WCHAR[dataFileNameLength]; g_dataFileName[0] = 0; wcsncat_s(g_dataFileName, dataFileNameLength, g_logPath, logPathLength); wcsncat_s(g_dataFileName, dataFileNameLength, DIRECTORY_SEPARATOR_STR_W, 1); @@ -141,52 +144,50 @@ void SetLogFilePath() } } -extern "C" -BOOL +extern "C" BOOL #ifndef FEATURE_PAL -APIENTRY + APIENTRY #endif // !FEATURE_PAL -DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) + DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH: + case DLL_PROCESS_ATTACH: #ifdef FEATURE_PAL - if (0 != PAL_InitializeDLL()) - { - fprintf(stderr, "Error: Fail to PAL_InitializeDLL\n"); - exit(1); - } + if (0 != PAL_InitializeDLL()) + { + fprintf(stderr, "Error: Fail to PAL_InitializeDLL\n"); + exit(1); + } #endif // FEATURE_PAL - Logger::Initialize(); - SetLogFilePath(); - Logger::OpenLogFile(g_logFilePath); - break; + Logger::Initialize(); + SetLogFilePath(); + Logger::OpenLogFile(g_logFilePath); + break; - case DLL_PROCESS_DETACH: - Logger::Shutdown(); + case DLL_PROCESS_DETACH: + Logger::Shutdown(); - delete[] g_logFilePath; - g_logFilePath = nullptr; + delete[] g_logFilePath; + g_logFilePath = nullptr; - break; + break; - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - break; + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + break; } return TRUE; } // Exported via def file -extern "C" -void __stdcall jitStartup(ICorJitHost* host) +extern "C" void __stdcall jitStartup(ICorJitHost* host) { SetDefaultPaths(); SetLibName(); - //Load Library + // Load Library if (g_hRealJit == 0) { g_hRealJit = ::LoadLibraryW(g_realJitPath); @@ -206,55 +207,55 @@ void __stdcall jitStartup(ICorJitHost* host) } g_globalContext = new MethodContext(); - g_ourJitHost = new JitHost(host, g_globalContext); + g_ourJitHost = new JitHost(host, g_globalContext); pnjitStartup(g_ourJitHost); } -//Exported via def file -extern "C" -ICorJitCompiler* __stdcall getJit() +// Exported via def file +extern "C" ICorJitCompiler* __stdcall getJit() { - DWORD dwRetVal = 0; - PgetJit pngetJit; - interceptor_ICJC *pJitInstance = nullptr; - ICorJitCompiler *tICJI = nullptr; + DWORD dwRetVal = 0; + PgetJit pngetJit; + interceptor_ICJC* pJitInstance = nullptr; + ICorJitCompiler* tICJI = nullptr; SetDefaultPaths(); SetLibName(); SetLogPath(); SetLogPathName(); - //Load Library - if(g_hRealJit == 0) + // Load Library + if (g_hRealJit == 0) { g_hRealJit = ::LoadLibraryW(g_realJitPath); - if(g_hRealJit == 0) + if (g_hRealJit == 0) { LogError("getJit() - LoadLibrary failed to load '%ws' (0x%08x)", g_realJitPath, ::GetLastError()); return nullptr; } } - //get the required entrypoints + // get the required entrypoints pngetJit = (PgetJit)::GetProcAddress(g_hRealJit, "getJit"); - if(pngetJit == 0) + if (pngetJit == 0) { LogError("getJit() - GetProcAddress 'getJit' failed (0x%08x)", ::GetLastError()); return nullptr; } tICJI = pngetJit(); - if(tICJI == nullptr) + if (tICJI == nullptr) { LogError("getJit() - pngetJit gave us null"); return nullptr; } - pJitInstance = new interceptor_ICJC(); + pJitInstance = new interceptor_ICJC(); pJitInstance->original_ICorJitCompiler = tICJI; - //create our datafile - pJitInstance->hFile = CreateFileW(g_dataFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN, NULL); + // create our datafile + pJitInstance->hFile = CreateFileW(g_dataFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (pJitInstance->hFile == INVALID_HANDLE_VALUE) { LogError("Couldn't open file '%ws': error %d", g_dataFileName, GetLastError()); @@ -263,42 +264,41 @@ ICorJitCompiler* __stdcall getJit() return pJitInstance; } -//Exported via def file -extern "C" -void __stdcall sxsJitStartup(CoreClrCallbacks const & original_cccallbacks) +// Exported via def file +extern "C" void __stdcall sxsJitStartup(CoreClrCallbacks const& original_cccallbacks) { PsxsJitStartup pnsxsJitStartup; SetDefaultPaths(); SetLibName(); - //Load Library - if(g_hRealJit == 0) + // Load Library + if (g_hRealJit == 0) { g_hRealJit = ::LoadLibraryW(g_realJitPath); - if(g_hRealJit == 0) + if (g_hRealJit == 0) { LogError("sxsJitStartup() - LoadLibrary failed to load '%ws' (0x%08x)", g_realJitPath, ::GetLastError()); return; } } - //get entry point + // get entry point pnsxsJitStartup = (PsxsJitStartup)::GetProcAddress(g_hRealJit, "sxsJitStartup"); - if(pnsxsJitStartup == 0) + if (pnsxsJitStartup == 0) { LogError("sxsJitStartup() - GetProcAddress 'sxsJitStartup' failed (0x%08x)", ::GetLastError()); return; } - //Setup CoreClrCallbacks and call sxsJitStartup - original_CoreClrCallbacks = new CoreClrCallbacks(); + // Setup CoreClrCallbacks and call sxsJitStartup + original_CoreClrCallbacks = new CoreClrCallbacks(); original_CoreClrCallbacks->m_hmodCoreCLR = original_cccallbacks.m_hmodCoreCLR; original_CoreClrCallbacks->m_pfnIEE = original_cccallbacks.m_pfnIEE; original_CoreClrCallbacks->m_pfnGetCORSystemDirectory = original_cccallbacks.m_pfnGetCORSystemDirectory; original_CoreClrCallbacks->m_pfnGetCLRFunction = original_cccallbacks.m_pfnGetCLRFunction; - CoreClrCallbacks *temp = new CoreClrCallbacks(); + CoreClrCallbacks* temp = new CoreClrCallbacks(); temp->m_hmodCoreCLR = original_cccallbacks.m_hmodCoreCLR; temp->m_pfnIEE = IEE_t; |