From 265a27c75cada08509a5f0474cdb2938902370c0 Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Tue, 17 May 2016 09:05:04 -0700 Subject: [PATCH] Remove jitOnDllProcess{Attach,Detach}. These functions have been obviated by a more clearly-defined JIT startup and shutdown interface. This fixes a crash in coreclr.dll during DLL unload: the runtime was calling jitOnDllProcessDetach (which calls jitShutdown) without having called jitStartup to initialized the JIT. --- src/dlls/mscoree/mscoree.cpp | 15 ------------ src/jit/ee_il_dll.cpp | 57 ++++++++++++++++---------------------------- src/vm/ceemain.cpp | 8 ------- 3 files changed, 21 insertions(+), 59 deletions(-) diff --git a/src/dlls/mscoree/mscoree.cpp b/src/dlls/mscoree/mscoree.cpp index 3756835..3d33337 100644 --- a/src/dlls/mscoree/mscoree.cpp +++ b/src/dlls/mscoree/mscoree.cpp @@ -69,12 +69,6 @@ HINSTANCE g_hThisInst; // This library. // Handle lifetime of loaded library. //***************************************************************************** -#ifdef FEATURE_MERGE_JIT_AND_ENGINE -void jitOnDllProcessAttach(); -void jitOnDllProcessDetach(); -#endif // FEATURE_MERGE_JIT_AND_ENGINE - - #ifdef FEATURE_CORECLR #include @@ -181,21 +175,12 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved) { return FALSE; } - -#ifdef FEATURE_MERGE_JIT_AND_ENGINE - jitOnDllProcessAttach(); -#endif // FEATURE_MERGE_JIT_AND_ENGINE } break; case DLL_PROCESS_DETACH: { EEDllMain((HINSTANCE)hInstance, dwReason, lpReserved); - -#ifdef FEATURE_MERGE_JIT_AND_ENGINE - jitOnDllProcessDetach(); -#endif // FEATURE_MERGE_JIT_AND_ENGINE - } break; diff --git a/src/jit/ee_il_dll.cpp b/src/jit/ee_il_dll.cpp index a41b147..b97c10c 100644 --- a/src/jit/ee_il_dll.cpp +++ b/src/jit/ee_il_dll.cpp @@ -31,9 +31,9 @@ FILE* jitstdout = nullptr; ICorJitHost* g_jitHost = nullptr; static CILJit* ILJitter = 0; // The one and only JITTER I return +bool g_jitInitialized = false; #ifndef FEATURE_MERGE_JIT_AND_ENGINE HINSTANCE g_hInst = NULL; -BOOL g_fClrCallbacksInit = FALSE; #endif // FEATURE_MERGE_JIT_AND_ENGINE /*****************************************************************************/ @@ -57,16 +57,16 @@ JitOptions jitOpts = extern "C" void __stdcall jitStartup(ICorJitHost* jitHost) { - g_jitHost = jitHost; - - // `jitStartup` may be called multiple times - // when pre-jitting. We should not reinitialize - // config values each time. - if (!JitConfig.isInitialized()) + if (g_jitInitialized) { - JitConfig.initialize(jitHost); + return; } + g_jitHost = jitHost; + + assert(!JitConfig.isInitialized()); + JitConfig.initialize(jitHost); + #if defined(PLATFORM_UNIX) jitstdout = procstdout(); #else @@ -83,10 +83,17 @@ void __stdcall jitStartup(ICorJitHost* jitHost) JitTelemetry::NotifyDllProcessAttach(); #endif Compiler::compStartup(); + + g_jitInitialized = true; } void jitShutdown() { + if (!g_jitInitialized) + { + return; + } + Compiler::compShutdown(); if (jitstdout != procstdout()) @@ -99,27 +106,6 @@ void jitShutdown() #endif } - -/***************************************************************************** - * jitOnDllProcessAttach() called by DllMain() when jit.dll is loaded - */ - -void jitOnDllProcessAttach() -{ -#if COR_JIT_EE_VERSION <= 460 - jitStartup(JitHost::getJitHost()); -#endif -} - -/***************************************************************************** - * jitOnDllProcessDetach() called by DllMain() when jit.dll is unloaded - */ - -void jitOnDllProcessDetach() -{ - jitShutdown(); -} - #ifndef FEATURE_MERGE_JIT_AND_ENGINE extern "C" @@ -129,15 +115,13 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID pvReserved) { g_hInst = (HINSTANCE)hInstance; DisableThreadLibraryCalls((HINSTANCE)hInstance); -#ifdef SELF_NO_HOST - jitOnDllProcessAttach(); - g_fClrCallbacksInit = TRUE; +#if defined(SELF_NO_HOST) && COR_JIT_EE_VERSION <= 460 + jitStartup(JitHost::getJitHost()); #endif } else if (dwReason == DLL_PROCESS_DETACH) { - if (g_fClrCallbacksInit) - jitOnDllProcessDetach(); + jitShutdown(); } return TRUE; @@ -153,9 +137,10 @@ void __stdcall sxsJitStartup(CoreClrCallbacks const & cccallbacks) { #ifndef SELF_NO_HOST InitUtilcode(cccallbacks); +#endif - jitOnDllProcessAttach(); - g_fClrCallbacksInit = TRUE; +#if COR_JIT_EE_VERSION <= 460 + jitStartup(JitHost::getJitHost()); #endif } diff --git a/src/vm/ceemain.cpp b/src/vm/ceemain.cpp index cc2e438..9963e7c 100644 --- a/src/vm/ceemain.cpp +++ b/src/vm/ceemain.cpp @@ -803,10 +803,6 @@ do { \ #define IfFailGoLog(EXPR) IfFailGotoLog(EXPR, ErrExit) #endif -#if defined(FEATURE_MERGE_JIT_AND_ENGINE) -void jitOnDllProcessAttach(); -#endif // defined(FEATURE_MERGE_JIT_AND_ENGINE) - void EEStartupHelper(COINITIEE fFlags) { CONTRACTL @@ -855,10 +851,6 @@ void EEStartupHelper(COINITIEE fFlags) #endif // !FEATURE_CORECLR && !CROSSGEN_COMPILE } -#if defined(CROSSGEN_COMPILE) && defined(FEATURE_MERGE_JIT_AND_ENGINE) - jitOnDllProcessAttach(); -#endif // defined(CROSSGEN_COMPILE) && defined(FEATURE_MERGE_JIT_AND_ENGINE) - #ifndef CROSSGEN_COMPILE // Initialize Numa and CPU group information // Need to do this as early as possible. Used by creating object handle -- 2.7.4