Update how CoreDisTools is discovered (dotnet/coreclr#21261)
authorAaron Robinson <arobins@microsoft.com>
Fri, 30 Nov 2018 18:06:28 +0000 (10:06 -0800)
committerGitHub <noreply@github.com>
Fri, 30 Nov 2018 18:06:28 +0000 (10:06 -0800)
* Update Disassembler logic to search for CoreDisTools next to binary _or_ under the path specified by CORE_ROOT

* Update GCCover critical section

Commit migrated from https://github.com/dotnet/coreclr/commit/87ac2b53d4618f994e67266fd99f479531018059

src/coreclr/src/inc/CrstTypes.def
src/coreclr/src/inc/crsttypes.h
src/coreclr/src/vm/disassembler.cpp
src/coreclr/tests/src/Interop/COM/NativeClients/Primitives.csproj

index 537134a..180171e 100644 (file)
 // 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
index 2dc6a20..2335843 100644 (file)
@@ -227,7 +227,7 @@ int g_rgCrstLevelMap[] =
     7,          // CrstFriendAccessCache
     7,          // CrstFuncPtrStubs
     5,          // CrstFusionAppCtx
-    3,          // CrstGCCover
+    9,          // CrstGCCover
     0,          // CrstGCMemoryPressure
     11,         // CrstGlobalStrLiteralMap
     1,          // CrstHandleTable
index 86a277a..6bb80f1 100755 (executable)
@@ -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
 }
 
index a8d8e01..2aa9343 100644 (file)
@@ -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" />