From dbdae9cc324a97ebc9199b973abe9a21b1177f01 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Mon, 14 Jan 2019 18:41:00 -0800 Subject: Finding Standalone GC and CoreDisTools in non-standard host testing (#21983) * Use GetInternalSystemDirectory() as the directory for standalone GC * Use GetInternalSystemDirectory() as the directory for coredistools --- src/vm/disassembler.cpp | 57 ++++------------------------------------------ src/vm/gcheaputilities.cpp | 24 +++++++++++++++---- 2 files changed, 24 insertions(+), 57 deletions(-) diff --git a/src/vm/disassembler.cpp b/src/vm/disassembler.cpp index 6bb80f1d44..77497f66da 100755 --- a/src/vm/disassembler.cpp +++ b/src/vm/disassembler.cpp @@ -79,61 +79,14 @@ namespace { LIMITED_METHOD_CONTRACT; - // - // Look for the coredistools module next to the hosting binary - // - - DWORD result = WszGetModuleFileName(nullptr, libPath); - if (result == 0) - { - DISPLAYERROR( - W("GetModuleFileName failed, function 'DisasmInstruction': error %u\n"), - GetLastError()); - return nullptr; - } - + LPCWSTR sysDirectory = GetInternalSystemDirectory(); LPCWSTR libFileName = MAKEDLLNAME(W("coredistools")); - PathString::Iterator iter = libPath.End(); - if (libPath.FindBack(iter, DIRECTORY_SEPARATOR_CHAR_W)) - { - libPath.Truncate(++iter); - libPath.Append(libFileName); - } - else - { - _ASSERTE(false && "unreachable"); - } - LPCWSTR libraryName = libPath.GetUnicode(); - HMODULE libraryHandle = CLRLoadLibrary(libraryName); - if (libraryHandle != nullptr) - return libraryHandle; - - DISPLAYERROR(W("LoadLibrary failed for '%s': error %u\n"), libraryName, GetLastError()); - - // - // Fallback to the CORE_ROOT path - // - - DWORD pathLen = GetEnvironmentVariableW(W("CORE_ROOT"), nullptr, 0); - if (pathLen == 0) // not set - return nullptr; + // Look for the coredistools module next to the clr binary + libPath.AppendPrintf(W("%s%s"), sysDirectory, libFileName); - pathLen += 1; // Add 1 for null - PathString coreRoot; - WCHAR *coreRootRaw = coreRoot.OpenUnicodeBuffer(pathLen); - GetEnvironmentVariableW(W("CORE_ROOT"), coreRootRaw, pathLen); - - libPath.Clear(); - libPath.AppendPrintf(W("%s%s%s"), coreRootRaw, DIRECTORY_SEPARATOR_STR_W, libFileName); - - libraryName = libPath.GetUnicode(); - libraryHandle = CLRLoadLibrary(libraryName); - if (libraryHandle != nullptr) - return libraryHandle; - - DISPLAYERROR(W("LoadLibrary failed for '%s': error %u\n"), libraryName, GetLastError()); - return nullptr; + LPCWSTR libraryName = libPath.GetUnicode(); + return CLRLoadLibrary(libraryName); } } diff --git a/src/vm/gcheaputilities.cpp b/src/vm/gcheaputilities.cpp index fda07ce675..9f13eff75b 100644 --- a/src/vm/gcheaputilities.cpp +++ b/src/vm/gcheaputilities.cpp @@ -152,6 +152,21 @@ void StashKeywordAndLevel(bool isPublicProvider, GCEventKeyword keywords, GCEven } } +#ifdef FEATURE_STANDALONE_GC +HMODULE LoadStandaloneGc(LPCWSTR libFileName) +{ + LIMITED_METHOD_CONTRACT; + + // Look for the standalone GC module next to the clr binary + PathString libPath = GetInternalSystemDirectory(); + libPath.Append(libFileName); + + LPCWSTR libraryName = libPath.GetUnicode(); + LOG((LF_GC, LL_INFO100, "Loading standalone GC from path %S\n", libraryName)); + return CLRLoadLibrary(libraryName); +} +#endif // FEATURE_STANDALONE_GC + // Loads and initializes a standalone GC, given the path to the GC // that we should load. Returns S_OK on success and the failed HRESULT // on failure. @@ -166,13 +181,12 @@ HRESULT LoadAndInitializeGC(LPWSTR standaloneGcLocation) LOG((LF_GC, LL_FATALERROR, "EE not built with the ability to load standalone GCs")); return E_FAIL; #else - LOG((LF_GC, LL_INFO100, "Loading standalone GC from path %S\n", standaloneGcLocation)); - HMODULE hMod = CLRLoadLibrary(standaloneGcLocation); + HMODULE hMod = LoadStandaloneGc(standaloneGcLocation); if (!hMod) { HRESULT err = GetLastError(); LOG((LF_GC, LL_FATALERROR, "Load of %S failed\n", standaloneGcLocation)); - return err; + return __HRESULT_FROM_WIN32(err); } // a standalone GC dispatches virtually on GCToEEInterface, so we must instantiate @@ -189,7 +203,7 @@ HRESULT LoadAndInitializeGC(LPWSTR standaloneGcLocation) { HRESULT err = GetLastError(); LOG((LF_GC, LL_FATALERROR, "Load of `GC_VersionInfo` from standalone GC failed\n")); - return err; + return __HRESULT_FROM_WIN32(err); } g_gc_load_status = GC_LOAD_STATUS_GET_VERSIONINFO; @@ -216,7 +230,7 @@ HRESULT LoadAndInitializeGC(LPWSTR standaloneGcLocation) { HRESULT err = GetLastError(); LOG((LF_GC, LL_FATALERROR, "Load of `GC_Initialize` from standalone GC failed\n")); - return err; + return __HRESULT_FROM_WIN32(err); } g_gc_load_status = GC_LOAD_STATUS_GET_INITIALIZE; -- cgit v1.2.3