diff options
author | Aaron Robinson <arobins@microsoft.com> | 2018-11-30 10:06:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-30 10:06:28 -0800 |
commit | 87ac2b53d4618f994e67266fd99f479531018059 (patch) | |
tree | bc90a9cb089b05abf93c78540fa8dd9add1d85e4 | |
parent | 7972722e3a3788fe96056d0a5398f90466588b8f (diff) | |
download | coreclr-87ac2b53d4618f994e67266fd99f479531018059.tar.gz coreclr-87ac2b53d4618f994e67266fd99f479531018059.tar.bz2 coreclr-87ac2b53d4618f994e67266fd99f479531018059.zip |
Update how CoreDisTools is discovered (#21261)
* Update Disassembler logic to search for CoreDisTools next to binary _or_ under the path specified by CORE_ROOT
* Update GCCover critical section
-rw-r--r-- | src/inc/CrstTypes.def | 11 | ||||
-rw-r--r-- | src/inc/crsttypes.h | 2 | ||||
-rwxr-xr-x | src/vm/disassembler.cpp | 177 | ||||
-rw-r--r-- | tests/src/Interop/COM/NativeClients/Primitives.csproj | 2 |
4 files changed, 104 insertions, 88 deletions
diff --git a/src/inc/CrstTypes.def b/src/inc/CrstTypes.def index 537134ab3c..180171ed3a 100644 --- a/src/inc/CrstTypes.def +++ b/src/inc/CrstTypes.def @@ -69,14 +69,7 @@ // running our test suites). Feel free to add meaningful comments to existing rules if you feel they can // usefully clarify the reasons for particular dependencies. // -// CrstTypeTool is a csScript file at file:..\..\bin\CrstTypeTool.csScript. Simply typing "CrstTypeTool" from a -// clrenv command window prompt should rebuild file:CrstTypes.h from the current CrstTypes.def (again, -// remember to check out CrstTypes.h first). -// Note: If you cannot run the script from command line, because of this error: -// Script language type is unsupported. -// Use /? for more help on usage. -// Or because .csscript extension is not associated with anything on your machine, -// Then use "csc.exe CrstTypeTool.csscript" from ClrEnv environment and run the resulting executable. +// See CrstTypeTool.cs for how to consume this file. // // Each Crst type definition is currently in alphabetical order. Please maintain this convention. // @@ -291,7 +284,7 @@ Crst NativeImageCache End Crst GCCover - AcquiredBefore LoaderHeap + AcquiredBefore LoaderHeap ReJITDomainTable End Crst GCMemoryPressure diff --git a/src/inc/crsttypes.h b/src/inc/crsttypes.h index 2dc6a2064c..23358432c2 100644 --- a/src/inc/crsttypes.h +++ b/src/inc/crsttypes.h @@ -227,7 +227,7 @@ int g_rgCrstLevelMap[] = 7, // CrstFriendAccessCache 7, // CrstFuncPtrStubs 5, // CrstFusionAppCtx - 3, // CrstGCCover + 9, // CrstGCCover 0, // CrstGCMemoryPressure 11, // CrstGlobalStrLiteralMap 1, // CrstHandleTable diff --git a/src/vm/disassembler.cpp b/src/vm/disassembler.cpp index 86a277ad62..6bb80f1d44 100755 --- a/src/vm/disassembler.cpp +++ b/src/vm/disassembler.cpp @@ -67,6 +67,76 @@ bool Disassembler::IsAvailable() #endif // USE_COREDISTOOLS_DISASSEMBLER } +#if _DEBUG +#define DISPLAYERROR(FMT, ...) wprintf(FMT, __VA_ARGS__) +#else +#define DISPLAYERROR(FMT, ...) (void)0 +#endif + +namespace +{ + HMODULE LoadCoreDisToolsModule(PathString &libPath) + { + 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 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; + + 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; + } +} + void Disassembler::StaticInitialize() { LIMITED_METHOD_CONTRACT; @@ -74,92 +144,47 @@ void Disassembler::StaticInitialize() #if USE_COREDISTOOLS_DISASSEMBLER _ASSERTE(!IsAvailable()); - HMODULE libraryHandle = nullptr; PathString libPath; - DWORD result = WszGetModuleFileName(nullptr, libPath); - if (result == 0) { -#ifdef _DEBUG - wprintf( - W("GetModuleFileName failed, function 'DisasmInstruction': error %u\n"), + HMODULE libraryHandle = LoadCoreDisToolsModule(libPath); + if (libraryHandle == nullptr) + return; + + External_InitDisasm = + reinterpret_cast<decltype(External_InitDisasm)>(GetProcAddress(libraryHandle, "InitDisasm")); + if (External_InitDisasm == nullptr) + { + DISPLAYERROR( + W("GetProcAddress failed for library '%s', function 'InitDisasm': error %u\n"), + libPath.GetUnicode(), GetLastError()); -#endif // _DEBUG return; } -#if defined(FEATURE_PAL) - WCHAR delim = W('/'); -#else - WCHAR delim = W('\\'); -#endif - LPCWSTR libFileName = MAKEDLLNAME(W("coredistools")); - PathString::Iterator iter = libPath.End(); - if (libPath.FindBack(iter, delim)) { - libPath.Truncate(++iter); - libPath.Append(libFileName); - } - else { - _ASSERTE(!"unreachable"); + External_DisasmInstruction = + reinterpret_cast<decltype(External_DisasmInstruction)>(GetProcAddress(libraryHandle, "DisasmInstruction")); + if (External_DisasmInstruction == nullptr) + { + DISPLAYERROR( + W("GetProcAddress failed for library '%s', function 'DisasmInstruction': error %u\n"), + libPath.GetUnicode(), + GetLastError()); + return; } - LPCWSTR libraryName = libPath.GetUnicode(); - libraryHandle = CLRLoadLibrary(libraryName); - do + External_FinishDisasm = + reinterpret_cast<decltype(External_FinishDisasm)>(GetProcAddress(libraryHandle, "FinishDisasm")); + if (External_FinishDisasm == nullptr) { - if (libraryHandle == nullptr) - { - #ifdef _DEBUG - wprintf(W("LoadLibrary failed for '%s': error %u\n"), libraryName, GetLastError()); - #endif // _DEBUG - break; - } - - External_InitDisasm = - reinterpret_cast<decltype(External_InitDisasm)>(GetProcAddress(libraryHandle, "InitDisasm")); - if (External_InitDisasm == nullptr) - { - #ifdef _DEBUG - wprintf( - W("GetProcAddress failed for library '%s', function 'InitDisasm': error %u\n"), - libraryName, - GetLastError()); - #endif // _DEBUG - break; - } - - External_DisasmInstruction = - reinterpret_cast<decltype(External_DisasmInstruction)>(GetProcAddress(libraryHandle, "DisasmInstruction")); - if (External_DisasmInstruction == nullptr) - { - #ifdef _DEBUG - wprintf( - W("GetProcAddress failed for library '%s', function 'DisasmInstruction': error %u\n"), - libraryName, - GetLastError()); - #endif // _DEBUG - break; - } - - External_FinishDisasm = - reinterpret_cast<decltype(External_FinishDisasm)>(GetProcAddress(libraryHandle, "FinishDisasm")); - if (External_FinishDisasm == nullptr) - { - #ifdef _DEBUG - wprintf( - W("GetProcAddress failed for library '%s', function 'FinishDisasm': error %u\n"), - libraryName, - GetLastError()); - #endif // _DEBUG - break; - } - - // Set this last to indicate successful load of the library and all exports - s_libraryHandle = libraryHandle; - _ASSERTE(IsAvailable()); + DISPLAYERROR( + W("GetProcAddress failed for library '%s', function 'FinishDisasm': error %u\n"), + libPath.GetUnicode(), + GetLastError()); return; - } while (false); + } - _ASSERTE(!IsAvailable()); - + // Set this last to indicate successful load of the library and all exports + s_libraryHandle = libraryHandle; + _ASSERTE(IsAvailable()); #endif // USE_COREDISTOOLS_DISASSEMBLER } diff --git a/tests/src/Interop/COM/NativeClients/Primitives.csproj b/tests/src/Interop/COM/NativeClients/Primitives.csproj index a8d8e01887..2aa9343ffd 100644 --- a/tests/src/Interop/COM/NativeClients/Primitives.csproj +++ b/tests/src/Interop/COM/NativeClients/Primitives.csproj @@ -9,8 +9,6 @@ <TestUnsupportedOutsideWindows>true</TestUnsupportedOutsideWindows> <DisableProjectBuild Condition="'$(TargetsUnix)' == 'true'">true</DisableProjectBuild> <DefineConstants>BLOCK_WINDOWS_NANO</DefineConstants> - <!-- Issue 21221, https://github.com/dotnet/coreclr/issues/21221 --> - <GCStressIncompatible>true</GCStressIncompatible> </PropertyGroup> <ItemGroup> <Compile Include="$(InteropCommonDir)ExeLauncherProgram.cs" /> |