From 1c1757c040e1735f8e608bc383bb73b3f5f98a38 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Mon, 9 Nov 2020 16:19:44 -0800 Subject: [PATCH] Removing `g_hmodCoreCLR` and `g_hThisInst` (#43735) * g_hmodCoreCLR is Windows-only * Use 42 in MarkAsThrownByUsWorker() * replaced GetCLRModule with GetClrModulePathName * Addded PAL_GetPalHostModule to mscordac_unixexports * replaced a few cases of g_hThisInst where used to get module path. We can uise `GetClrModulePathName` instead. * more cases where used to get module path * unused `GetModuleInst()` * not using HMODULE in StressLog * removed mscoree GetModuleInst * Deleted both `g_hThisInst` and `g_hmodCoreCLR` * fix Linux build * rename `GetModuleBase` ->` GetClrModuleBase`, it was confusing with other `GetClrModuleBase` * Fix Linux build * PR feedback * Removed hMod variables in Debugger areas * standalone GC * cache GetClrModuleBase * Prevent double-read of `pImageBase` * fix linker issue * couple more link order fixes. * Remove `g_thisModule` in daccess.cpp. Fix typos. --- src/coreclr/src/debug/daccess/daccess.cpp | 20 ---- src/coreclr/src/debug/daccess/dacimpl.h | 3 - src/coreclr/src/debug/daccess/request.cpp | 12 ++- src/coreclr/src/debug/di/cordb.cpp | 20 +--- src/coreclr/src/debug/di/module.cpp | 2 +- src/coreclr/src/debug/di/rsmain.cpp | 14 +-- src/coreclr/src/debug/di/rspriv.h | 6 -- src/coreclr/src/debug/di/shimprocess.cpp | 19 +--- src/coreclr/src/debug/ee/debugger.cpp | 6 +- .../src/dlls/mscordac/mscordac_unixexports.src | 2 +- src/coreclr/src/dlls/mscoree/mscoree.cpp | 45 +-------- src/coreclr/src/dlls/mscoree/stdafx.h | 4 - src/coreclr/src/inc/clrhost.h | 2 +- src/coreclr/src/inc/corcompile.h | 4 - src/coreclr/src/inc/corpriv.h | 15 --- src/coreclr/src/inc/longfilepathwrappers.h | 2 - src/coreclr/src/inc/stresslog.h | 2 +- src/coreclr/src/inc/utilcode.h | 18 +--- src/coreclr/src/jit/dllmain.cpp | 8 -- src/coreclr/src/md/compiler/classfactory.cpp | 3 - src/coreclr/src/md/staticmd/stdafx.h | 4 - src/coreclr/src/pal/inc/pal.h | 9 -- .../src/pal/src/include/pal/stackstring.hpp | 4 - src/coreclr/src/pal/src/init/pal.cpp | 3 +- src/coreclr/src/pal/src/misc/miscpalapi.cpp | 109 --------------------- src/coreclr/src/pal/tests/palsuite/CMakeLists.txt | 1 - .../src/pal/tests/palsuite/compilableTests.txt | 1 - .../test1/PAL_GetPALDirectoryW.cpp | 77 --------------- .../tests/palsuite/paltestlist_to_be_reviewed.txt | 1 - src/coreclr/src/tools/crossgen/CMakeLists.txt | 2 +- src/coreclr/src/tools/crossgen/crossgen.cpp | 6 -- src/coreclr/src/utilcode/ccomprc.cpp | 6 +- src/coreclr/src/utilcode/clrhost.cpp | 61 ++++++------ src/coreclr/src/utilcode/ex.cpp | 7 +- src/coreclr/src/utilcode/longfilepathwrappers.cpp | 59 ----------- src/coreclr/src/utilcode/makepath.cpp | 16 ++- src/coreclr/src/utilcode/stresslog.cpp | 8 +- src/coreclr/src/utilcode/util.cpp | 10 +- src/coreclr/src/vm/ceeload.cpp | 2 +- src/coreclr/src/vm/ceemain.cpp | 24 +---- src/coreclr/src/vm/codeman.cpp | 3 +- src/coreclr/src/vm/common.h | 4 +- src/coreclr/src/vm/dwreport.cpp | 4 +- src/coreclr/src/vm/eepolicy.cpp | 4 +- src/coreclr/src/vm/eventtrace.cpp | 5 +- src/coreclr/src/vm/excep.cpp | 6 +- src/coreclr/src/vm/exceptionhandling.cpp | 8 +- src/coreclr/src/vm/gcheaputilities.cpp | 24 +++-- src/coreclr/src/vm/gcheaputilities.h | 4 +- src/coreclr/src/vm/hosting.cpp | 2 +- src/coreclr/src/vm/jithelpers.cpp | 6 +- src/coreclr/src/vm/pefile.cpp | 40 -------- src/coreclr/src/vm/proftoeeinterfaceimpl.cpp | 2 +- src/coreclr/src/vm/threads.cpp | 2 +- src/coreclr/src/vm/vars.cpp | 1 - src/coreclr/src/vm/vars.hpp | 1 - src/coreclr/src/zap/zapper.cpp | 5 +- .../corehost/cli/apphost/static/CMakeLists.txt | 2 +- 58 files changed, 126 insertions(+), 614 deletions(-) delete mode 100644 src/coreclr/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp diff --git a/src/coreclr/src/debug/daccess/daccess.cpp b/src/coreclr/src/debug/daccess/daccess.cpp index 0344ddc..424cff1 100644 --- a/src/coreclr/src/debug/daccess/daccess.cpp +++ b/src/coreclr/src/debug/daccess/daccess.cpp @@ -40,7 +40,6 @@ extern bool TryGetSymbol(ICorDebugDataTarget* dataTarget, uint64_t baseAddress, CRITICAL_SECTION g_dacCritSec; ClrDataAccess* g_dacImpl; -HINSTANCE g_thisModule; EXTERN_C #ifdef TARGET_UNIX @@ -75,9 +74,6 @@ BOOL WINAPI DllMain(HANDLE instance, DWORD reason, LPVOID reserved) #endif InitializeCriticalSection(&g_dacCritSec); - // Save the module handle. - g_thisModule = (HINSTANCE)instance; - g_procInitialized = true; break; } @@ -95,12 +91,6 @@ BOOL WINAPI DllMain(HANDLE instance, DWORD reason, LPVOID reserved) return TRUE; } -HINSTANCE -GetModuleInst(void) -{ - return g_thisModule; -} - HRESULT ConvertUtf8(__in LPCUTF8 utf8, ULONG32 bufLen, @@ -5622,16 +5612,6 @@ ClrDataAccess::Initialize(void) // Do some validation IfFailRet(VerifyDlls()); - // To support EH SxS, utilcode requires the base address of the runtime - // as part of its initialization so that functions like "WasThrownByUs" work correctly since - // they use the CLR base address to check if an exception was raised by a given instance of the runtime - // or not. - // - // Thus, when DAC is initialized, initialize utilcode with the base address of the runtime loaded in the - // target process. This is similar to work done in CorDB::SetTargetCLR for mscordbi. - - g_hmodCoreCLR = (HINSTANCE)m_globalBase; // Base address of the runtime in the target process - return S_OK; } diff --git a/src/coreclr/src/debug/daccess/dacimpl.h b/src/coreclr/src/debug/daccess/dacimpl.h index fdea071..717c6cf 100644 --- a/src/coreclr/src/debug/daccess/dacimpl.h +++ b/src/coreclr/src/debug/daccess/dacimpl.h @@ -127,9 +127,6 @@ enum DAC_USAGE_TYPE DAC_PAL, }; -// mscordacwks's module handle -extern HINSTANCE g_thisModule; - class ReflectionModule; struct DAC_MD_IMPORT diff --git a/src/coreclr/src/debug/daccess/request.cpp b/src/coreclr/src/debug/daccess/request.cpp index 99366e9..6523b40 100644 --- a/src/coreclr/src/debug/daccess/request.cpp +++ b/src/coreclr/src/debug/daccess/request.cpp @@ -3889,12 +3889,22 @@ HRESULT ClrDataAccess::GetTLSIndex(ULONG *pIndex) return hr; } +#ifndef TARGET_UNIX +extern "C" IMAGE_DOS_HEADER __ImageBase; +#endif + HRESULT ClrDataAccess::GetDacModuleHandle(HMODULE *phModule) { if(phModule == NULL) return E_INVALIDARG; - *phModule = GetModuleInst(); + +#ifndef TARGET_UNIX + *phModule = (HMODULE)&__ImageBase; return S_OK; +#else + // hModule is not available under TARGET_UNIX + return E_FAIL; +#endif } HRESULT ClrDataAccess::GetRCWData(CLRDATA_ADDRESS addr, struct DacpRCWData *rcwData) diff --git a/src/coreclr/src/debug/di/cordb.cpp b/src/coreclr/src/debug/di/cordb.cpp index 673d48c..2c11397 100644 --- a/src/coreclr/src/debug/di/cordb.cpp +++ b/src/coreclr/src/debug/di/cordb.cpp @@ -26,11 +26,6 @@ #define SUPPORT_LOCAL_DEBUGGING 1 #endif -//********** Globals. ********************************************************* -#ifndef HOST_UNIX -HINSTANCE g_hInst; // Instance handle to this piece of code. -#endif - //----------------------------------------------------------------------------- // SxS Versioning story for Mscordbi (ICorDebug + friends) //----------------------------------------------------------------------------- @@ -200,9 +195,7 @@ BOOL WINAPI DbgDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) case DLL_PROCESS_ATTACH: { -#ifndef HOST_UNIX - g_hInst = hInstance; -#else +#ifdef HOST_UNIX int err = PAL_InitializeDLL(); if(err != 0) { @@ -438,17 +431,6 @@ HRESULT STDMETHODCALLTYPE CClassFactory::LockServer( } -//***************************************************************************** -// This helper provides access to the instance handle of the loaded image. -//***************************************************************************** -#ifndef TARGET_UNIX -HINSTANCE GetModuleInst() -{ - return g_hInst; -} -#endif - - //----------------------------------------------------------------------------- // Substitute for mscoree // diff --git a/src/coreclr/src/debug/di/module.cpp b/src/coreclr/src/debug/di/module.cpp index 39f306f..88a6e36 100644 --- a/src/coreclr/src/debug/di/module.cpp +++ b/src/coreclr/src/debug/di/module.cpp @@ -2565,7 +2565,7 @@ HRESULT CordbModule::CreateReaderForInMemorySymbols(REFIID riid, void** ppObj) #ifndef TARGET_UNIX // PDB format - use diasymreader.dll with COM activation InlineSString<_MAX_PATH> ssBuf; - IfFailThrow(GetHModuleDirectory(GetModuleInst(), ssBuf)); + IfFailThrow(GetClrModuleDirectory(ssBuf)); IfFailThrow(FakeCoCreateInstanceEx(CLSID_CorSymBinder_SxS, ssBuf.GetUnicode(), IID_ISymUnmanagedBinder, diff --git a/src/coreclr/src/debug/di/rsmain.cpp b/src/coreclr/src/debug/di/rsmain.cpp index 11d5fcf..779a6ea 100644 --- a/src/coreclr/src/debug/di/rsmain.cpp +++ b/src/coreclr/src/debug/di/rsmain.cpp @@ -456,6 +456,7 @@ void LeftSideResourceCleanupList::SweepNeuterLeftSideResources(CordbProcess * pP /* ------------------------------------------------------------------------- * * CordbBase class * ------------------------------------------------------------------------- */ +extern void* GetClrModuleBase(); // Do any initialization necessary for both CorPublish and CorDebug // This includes enabling logging and adding the SEDebug priv. @@ -488,11 +489,7 @@ void CordbCommonBase::InitializeCommon() unsigned level = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_LogLevel, LL_INFO1000); unsigned bytesPerThread = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_StressLogSize, STRESSLOG_CHUNK_SIZE * 2); unsigned totalBytes = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_TotalStressLogSize, STRESSLOG_CHUNK_SIZE * 1024); -#ifndef TARGET_UNIX - StressLog::Initialize(facilities, level, bytesPerThread, totalBytes, GetModuleInst()); -#else - StressLog::Initialize(facilities, level, bytesPerThread, totalBytes, NULL); -#endif + StressLog::Initialize(facilities, level, bytesPerThread, totalBytes, GetClrModuleBase()); } } @@ -1427,13 +1424,6 @@ HRESULT Cordb::SetTargetCLR(HMODULE hmodTargetCLR) m_targetCLR = hmodTargetCLR; #endif - // @REVIEW: are we happy with this workaround? It allows us to use the existing - // infrastructure for instance name decoration, but it really doesn't fit - // the same model because coreclr.dll isn't in this process and hmodTargetCLR - // is the debuggee target, not the coreclr.dll to bind utilcode to.. - - g_hmodCoreCLR = hmodTargetCLR; - return S_OK; } diff --git a/src/coreclr/src/debug/di/rspriv.h b/src/coreclr/src/debug/di/rspriv.h index 5cbba66..5777f29 100644 --- a/src/coreclr/src/debug/di/rspriv.h +++ b/src/coreclr/src/debug/di/rspriv.h @@ -134,12 +134,6 @@ class DbgTransportSession; // These hooks must be removed before shipping. class ShimProcess; - -#ifndef TARGET_UNIX -extern HINSTANCE GetModuleInst(); -#endif - - template class CordbSafeHashTable; diff --git a/src/coreclr/src/debug/di/shimprocess.cpp b/src/coreclr/src/debug/di/shimprocess.cpp index 685c4f2..72da606 100644 --- a/src/coreclr/src/debug/di/shimprocess.cpp +++ b/src/coreclr/src/debug/di/shimprocess.cpp @@ -1824,34 +1824,19 @@ HMODULE ShimProcess::GetDacModule() HModuleHolder hDacDll; PathString wszAccessDllPath; -#ifdef TARGET_UNIX - if (!PAL_GetPALDirectoryWrapper(wszAccessDllPath)) - { - ThrowLastError(); - } - PCWSTR eeFlavor = MAKEDLLNAME_W(W("mscordaccore")); -#else // // Load the access DLL from the same directory as the the current CLR Debugging Services DLL. // - - if (!WszGetModuleFileName(GetModuleInst(), wszAccessDllPath)) + if (GetClrModuleDirectory(wszAccessDllPath) != S_OK) { ThrowLastError(); } - if (!SUCCEEDED(CopySystemDirectory(wszAccessDllPath, wszAccessDllPath))) - { - ThrowHR(E_INVALIDARG); - } - // Dac Dll is named: // mscordaccore.dll <-- coreclr // mscordacwks.dll <-- desktop - PCWSTR eeFlavor = - W("mscordaccore.dll"); + PCWSTR eeFlavor = MAKEDLLNAME_W(W("mscordaccore")); -#endif // TARGET_UNIX wszAccessDllPath.Append(eeFlavor); hDacDll.Assign(WszLoadLibrary(wszAccessDllPath)); diff --git a/src/coreclr/src/debug/ee/debugger.cpp b/src/coreclr/src/debug/ee/debugger.cpp index 79d8dd0..a84b6d6 100644 --- a/src/coreclr/src/debug/ee/debugger.cpp +++ b/src/coreclr/src/debug/ee/debugger.cpp @@ -1750,7 +1750,7 @@ void Debugger::SendRawEvent(const DebuggerIPCEvent * pManagedEvent) // The debugger can then use ReadProcessMemory to read through this array. ULONG_PTR rgData [] = { CLRDBG_EXCEPTION_DATA_CHECKSUM, - (ULONG_PTR) g_hThisInst, + (ULONG_PTR)GetClrModuleBase(), (ULONG_PTR) pManagedEvent }; @@ -5668,7 +5668,7 @@ bool Debugger::FirstChanceNativeException(EXCEPTION_RECORD *exception, // Ignore any notification exceptions sent from code:Debugger.SendRawEvent. // This is not a common case, but could happen in some cases described // in SendRawEvent. Either way, Left-Side and VM should just ignore these. - if (IsEventDebuggerNotification(exception, PTR_TO_CORDB_ADDRESS(g_hThisInst))) + if (IsEventDebuggerNotification(exception, PTR_TO_CORDB_ADDRESS(GetClrModuleBase()))) { return true; } @@ -12363,7 +12363,7 @@ void Debugger::GetAndSendTransitionStubInfo(CORDB_ADDRESS_TYPE *stubAddress) // If its not a stub, then maybe its an address in mscoree? if (result == false) { - result = (IsIPInModule(g_hThisInst, (PCODE)stubAddress) == TRUE); + result = (IsIPInModule(GetClrModuleBase(), (PCODE)stubAddress) == TRUE); } // This is a synchronous event (reply required) diff --git a/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src b/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src index a7e6a87..911ba40 100644 --- a/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src +++ b/src/coreclr/src/dlls/mscordac/mscordac_unixexports.src @@ -30,7 +30,6 @@ nativeStringResourceTable_mscorrc #PAL_fwprintf #PAL_GetLogicalCpuCountFromOS #PAL_GetNumaProcessorNode -#PAL_GetPALDirectoryW #PAL_get_stdout #PAL_get_stderr #PAL_GetApplicationGroupId @@ -38,6 +37,7 @@ nativeStringResourceTable_mscorrc #PAL_GetCurrentThread #PAL_GetCpuLimit #PAL_GetNativeExceptionHolderHead +#PAL_GetPalHostModule #PAL_GetSymbolModuleBase #PAL_GetTransportPipeName #PAL_InitializeDLL diff --git a/src/coreclr/src/dlls/mscoree/mscoree.cpp b/src/coreclr/src/dlls/mscoree/mscoree.cpp index c610e9e..4219910 100644 --- a/src/coreclr/src/dlls/mscoree/mscoree.cpp +++ b/src/coreclr/src/dlls/mscoree/mscoree.cpp @@ -47,14 +47,7 @@ BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved) #endif // !defined(CROSSGEN_COMPILE) && !defined(CORECLR_EMBEDDED) -// Globals -extern HINSTANCE g_hThisInst; - -HINSTANCE GetModuleInst() -{ - LIMITED_METHOD_CONTRACT; - return (g_hThisInst); -} +extern void* GetClrModuleBase(); // --------------------------------------------------------------------------- // %%Function: MetaDataGetDispenser @@ -222,39 +215,6 @@ STDAPI ReOpenMetaDataWithMemoryEx( return hr; } -STDAPI GetCORSystemDirectoryInternaL(SString& pBuffer) -{ - CONTRACTL { - NOTHROW; - GC_NOTRIGGER; - ENTRY_POINT; - } CONTRACTL_END; - - HRESULT hr = S_OK; - BEGIN_ENTRYPOINT_NOTHROW; - - -#ifdef CROSSGEN_COMPILE - - if (WszGetModuleFileName(NULL, pBuffer) > 0) - { - hr = CopySystemDirectory(pBuffer, pBuffer); - } - else { - hr = HRESULT_FROM_GetLastError(); - } - -#else - - if (!PAL_GetPALDirectoryWrapper(pBuffer)) { - hr = HRESULT_FROM_GetLastError(); - } -#endif - - END_ENTRYPOINT_NOTHROW; - return hr; -} - static DWORD g_dwSystemDirectory = 0; static WCHAR * g_pSystemDirectory = NULL; @@ -326,8 +286,7 @@ HRESULT SetInternalSystemDirectory() // use local buffer for thread safety PathString wzSystemDirectory; - - hr = GetCORSystemDirectoryInternaL(wzSystemDirectory); + hr = GetClrModuleDirectory(wzSystemDirectory); if (FAILED(hr)) { wzSystemDirectory.Set(W('\0')); diff --git a/src/coreclr/src/dlls/mscoree/stdafx.h b/src/coreclr/src/dlls/mscoree/stdafx.h index 1573727..1e29b9f 100644 --- a/src/coreclr/src/dlls/mscoree/stdafx.h +++ b/src/coreclr/src/dlls/mscoree/stdafx.h @@ -17,8 +17,4 @@ #include "intrinsic.h" // Functions to make intrinsic. - -// Helper function returns the instance handle of this module. -HINSTANCE GetModuleInst(); - #endif // __STDAFX_H__ diff --git a/src/coreclr/src/inc/clrhost.h b/src/coreclr/src/inc/clrhost.h index 8f5f3ff..f70382c 100644 --- a/src/coreclr/src/inc/clrhost.h +++ b/src/coreclr/src/inc/clrhost.h @@ -92,7 +92,7 @@ typedef Holder, VoidClrDeleteCriticalSection, NULL> CRITSEC_AllocationHolder; -HMODULE GetCLRModule (); +DWORD GetClrModulePathName(SString& buffer); extern thread_local int t_CantAllocCount; diff --git a/src/coreclr/src/inc/corcompile.h b/src/coreclr/src/inc/corcompile.h index 38e837a..8226fba 100644 --- a/src/coreclr/src/inc/corcompile.h +++ b/src/coreclr/src/inc/corcompile.h @@ -814,10 +814,6 @@ typedef enum extern LPCWSTR CorCompileGetRuntimeDllName(CorCompileRuntimeDlls id); -// Will always return a valid HMODULE for CLR_INFO, but will return NULL for NGEN_COMPILER_INFO -// if the DLL has not yet been loaded (it does not try to cause a load). -extern HMODULE CorCompileGetRuntimeDll(CorCompileRuntimeDlls id); - struct CORCOMPILE_RUNTIME_DLL_INFO { // This structure can only contain information not updated by authenticode signing. It is required diff --git a/src/coreclr/src/inc/corpriv.h b/src/coreclr/src/inc/corpriv.h index fb0b399..003386c 100644 --- a/src/coreclr/src/inc/corpriv.h +++ b/src/coreclr/src/inc/corpriv.h @@ -382,21 +382,6 @@ struct CORCOMPILE_VERSION_INFO; struct CORCOMPILE_DEPENDENCY; typedef GUID CORCOMPILE_NGEN_SIGNATURE; - -//********************************************************************** -// Internal versions of shim functions for use by the CLR. - -STDAPI GetCORSystemDirectoryInternaL( - SString& pBuffer - ); - -//LONGPATH:TODO: Remove this once Desktop usage has been removed -STDAPI GetCORSystemDirectoryInternal( - __out_ecount_part_opt(cchBuffer, *pdwLength) LPWSTR pBuffer, - DWORD cchBuffer, - __out_opt DWORD* pdwLength - ); - #endif // _CORPRIV_H_ // EOF ======================================================================= diff --git a/src/coreclr/src/inc/longfilepathwrappers.h b/src/coreclr/src/inc/longfilepathwrappers.h index 76aec1a..149cdcf 100644 --- a/src/coreclr/src/inc/longfilepathwrappers.h +++ b/src/coreclr/src/inc/longfilepathwrappers.h @@ -106,7 +106,5 @@ DWORD WINAPI GetEnvironmentVariableWrapper( _Out_opt_ SString& lpBuffer ); -BOOL PAL_GetPALDirectoryWrapper(SString& pbuffer); - #endif //_WIN_PATH_APIS_WRAPPER_ diff --git a/src/coreclr/src/inc/stresslog.h b/src/coreclr/src/inc/stresslog.h index e162dae..4858f6f 100644 --- a/src/coreclr/src/inc/stresslog.h +++ b/src/coreclr/src/inc/stresslog.h @@ -263,7 +263,7 @@ class ThreadStressLog; class StressLog { public: static void Initialize(unsigned facilities, unsigned level, unsigned maxBytesPerThread, - unsigned maxBytesTotal, HMODULE hMod); + unsigned maxBytesTotal, void* moduleBase); static void Terminate(BOOL fProcessDetach=FALSE); static void ThreadDetach(); // call at DllMain THREAD_DETACH if you want to recycle thread logs static int NewChunk () diff --git a/src/coreclr/src/inc/utilcode.h b/src/coreclr/src/inc/utilcode.h index 56bbd0d..84a7b89 100644 --- a/src/coreclr/src/inc/utilcode.h +++ b/src/coreclr/src/inc/utilcode.h @@ -4707,19 +4707,7 @@ FORCEINLINE void HolderSysFreeString(BSTR str) { CONTRACT_VIOLATION(ThrowsViolat typedef Wrapper BSTRHolder; -// HMODULE_TGT represents a handle to a module in the target process. In non-DAC builds this is identical -// to HMODULE (HINSTANCE), which is the base address of the module. In DAC builds this must be a target address, -// and so is represented by TADDR. - -#ifdef DACCESS_COMPILE -typedef TADDR HMODULE_TGT; -#else -typedef HMODULE HMODULE_TGT; -#endif - -BOOL IsIPInModule(HMODULE_TGT hModule, PCODE ip); - -extern HINSTANCE g_hmodCoreCLR; +BOOL IsIPInModule(PTR_VOID pModuleBaseAddress, PCODE ip); namespace UtilCode { @@ -4906,9 +4894,9 @@ inline T* InterlockedCompareExchangeT( #undef InterlockedCompareExchangePointer #define InterlockedCompareExchangePointer Use_InterlockedCompareExchangeT -// Returns the directory for HMODULE. So, if HMODULE was for "C:\Dir1\Dir2\Filename.DLL", +// Returns the directory for clr module. So, if path was for "C:\Dir1\Dir2\Filename.DLL", // then this would return "C:\Dir1\Dir2\" (note the trailing backslash). -HRESULT GetHModuleDirectory(HMODULE hMod, SString& wszPath); +HRESULT GetClrModuleDirectory(SString& wszPath); HRESULT CopySystemDirectory(const SString& pPathString, SString& pbuffer); HMODULE LoadLocalizedResourceDLLForSDK(_In_z_ LPCWSTR wzResourceDllName, _In_opt_z_ LPCWSTR modulePath=NULL, bool trySelf=true); diff --git a/src/coreclr/src/jit/dllmain.cpp b/src/coreclr/src/jit/dllmain.cpp index 7fcf274..fcc829f 100644 --- a/src/coreclr/src/jit/dllmain.cpp +++ b/src/coreclr/src/jit/dllmain.cpp @@ -14,14 +14,11 @@ extern void jitShutdown(bool processIsTerminating); -HINSTANCE g_hInst = nullptr; - /*****************************************************************************/ extern "C" DLLEXPORT BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID pvReserved) { if (dwReason == DLL_PROCESS_ATTACH) { - g_hInst = (HINSTANCE)hInstance; DisableThreadLibraryCalls((HINSTANCE)hInstance); } else if (dwReason == DLL_PROCESS_DETACH) @@ -34,8 +31,3 @@ extern "C" DLLEXPORT BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOI return TRUE; } - -HINSTANCE GetModuleInst() -{ - return (g_hInst); -} diff --git a/src/coreclr/src/md/compiler/classfactory.cpp b/src/coreclr/src/md/compiler/classfactory.cpp index 1506cb0..46b9775 100644 --- a/src/coreclr/src/md/compiler/classfactory.cpp +++ b/src/coreclr/src/md/compiler/classfactory.cpp @@ -23,9 +23,6 @@ #include "mscoree.h" #include "corhost.h" -//********** Locals. ********************************************************** -HINSTANCE GetModuleInst(); - // @telesto - why does Telesto export any Co-classes at all? // This map contains the list of coclasses which are exported from this module. diff --git a/src/coreclr/src/md/staticmd/stdafx.h b/src/coreclr/src/md/staticmd/stdafx.h index ab95ea1..65812f4 100644 --- a/src/coreclr/src/md/staticmd/stdafx.h +++ b/src/coreclr/src/md/staticmd/stdafx.h @@ -8,7 +8,3 @@ #include "intrinsic.h" // Functions to make intrinsic. - - -// Helper function returns the instance handle of this module. -HINSTANCE GetModuleInst(); diff --git a/src/coreclr/src/pal/inc/pal.h b/src/coreclr/src/pal/inc/pal.h index 19e6409..8aa0fe3 100644 --- a/src/coreclr/src/pal/inc/pal.h +++ b/src/coreclr/src/pal/inc/pal.h @@ -505,15 +505,6 @@ PAL_UnregisterModule( IN HINSTANCE hInstance); PALIMPORT -BOOL -PALAPI -PAL_GetPALDirectoryW( - OUT LPWSTR lpDirectoryName, - IN OUT UINT* cchDirectoryName); - -#define PAL_GetPALDirectory PAL_GetPALDirectoryW - -PALIMPORT VOID PALAPI PAL_Random( diff --git a/src/coreclr/src/pal/src/include/pal/stackstring.hpp b/src/coreclr/src/pal/src/include/pal/stackstring.hpp index 30aa6fa..38c4b84 100644 --- a/src/coreclr/src/pal/src/include/pal/stackstring.hpp +++ b/src/coreclr/src/pal/src/include/pal/stackstring.hpp @@ -253,10 +253,6 @@ typedef StackString PathWCharString; #endif // Some Helper Definitions -BOOL -PAL_GetPALDirectoryW( - PathWCharString& lpDirectoryName); - DWORD GetCurrentDirectoryA( PathCharString& lpBuffer); diff --git a/src/coreclr/src/pal/src/init/pal.cpp b/src/coreclr/src/pal/src/init/pal.cpp index 488ff6a..708d369 100644 --- a/src/coreclr/src/pal/src/init/pal.cpp +++ b/src/coreclr/src/pal/src/init/pal.cpp @@ -776,8 +776,7 @@ Function: Abstract: A replacement for PAL_Initialize when loading CoreCLR. Instead of taking a command line (which CoreCLR - instances aren't given anyway) the path into which the CoreCLR is installed is supplied instead. This is - cached so that PAL_GetPALDirectoryW can return it later. + instances aren't given anyway) the path into which the CoreCLR is installed is supplied instead. This routine also makes sure the psuedo dynamic libraries PALRT and mscorwks have their initialization methods called. diff --git a/src/coreclr/src/pal/src/misc/miscpalapi.cpp b/src/coreclr/src/pal/src/misc/miscpalapi.cpp index 0902611..0612921 100644 --- a/src/coreclr/src/pal/src/misc/miscpalapi.cpp +++ b/src/coreclr/src/pal/src/misc/miscpalapi.cpp @@ -43,115 +43,6 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC); static const char URANDOM_DEVICE_NAME[]="/dev/urandom"; -/*++ - -Function : - - PAL_GetPALDirectoryW - - Returns the fully qualified path name - where the PALL DLL was loaded from. - - On failure it returns FALSE and sets the - proper LastError code. - ---*/ -BOOL -PAL_GetPALDirectoryW(PathWCharString& lpDirectoryName) -{ - LPCWSTR lpFullPathAndName = NULL; - LPCWSTR lpEndPoint = NULL; - BOOL bRet = FALSE; - - PERF_ENTRY(PAL_GetPALDirectoryW); - - MODSTRUCT *module = LOADGetPalLibrary(); - if (!module) - { - SetLastError(ERROR_INTERNAL_ERROR); - goto EXIT; - } - lpFullPathAndName = module->lib_name; - if (lpFullPathAndName == NULL) - { - SetLastError(ERROR_INTERNAL_ERROR); - goto EXIT; - } - lpEndPoint = PAL_wcsrchr( lpFullPathAndName, '/' ); - if ( lpEndPoint ) - { - /* The path that we return is required to have - the trailing slash on the end.*/ - lpEndPoint++; - - - if(!lpDirectoryName.Set(lpFullPathAndName,lpEndPoint - lpFullPathAndName)) - { - ASSERT( "The buffer was not large enough.\n" ); - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - goto EXIT; - } - - bRet = TRUE; - } - else - { - ASSERT( "Unable to determine the path.\n" ); - /* Error path, should not be executed. */ - SetLastError( ERROR_INTERNAL_ERROR ); - } - -EXIT: - PERF_EXIT(PAL_GetPALDirectoryW); - return bRet; -} - -/*++ - -Function : - - PAL_GetPALDirectoryW - - Returns the fully qualified path name - where the PALL DLL was loaded from. - - On failure it returns FALSE and sets the - proper LastError code. - ---*/ -PALIMPORT -BOOL -PALAPI -PAL_GetPALDirectoryW( OUT LPWSTR lpDirectoryName, IN OUT UINT* cchDirectoryName ) -{ - PathWCharString directory; - BOOL bRet; - PERF_ENTRY(PAL_GetPALDirectoryW); - ENTRY( "PAL_GetPALDirectoryW( %p, %d )\n", lpDirectoryName, *cchDirectoryName ); - - bRet = PAL_GetPALDirectoryW(directory); - - if (bRet) { - - if (directory.GetCount() > *cchDirectoryName) - { - SetLastError( ERROR_INSUFFICIENT_BUFFER ); - bRet = FALSE; - } - else - { - PAL_wcscpy(lpDirectoryName, directory.GetString()); - } - - *cchDirectoryName = directory.GetCount(); - } - - LOGEXIT( "PAL_GetPALDirectoryW returns BOOL %d.\n", bRet); - PERF_EXIT(PAL_GetPALDirectoryW); - return bRet; - -} - VOID PALAPI PAL_Random( diff --git a/src/coreclr/src/pal/tests/palsuite/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/CMakeLists.txt index 722a32a..4f0d615 100644 --- a/src/coreclr/src/pal/tests/palsuite/CMakeLists.txt +++ b/src/coreclr/src/pal/tests/palsuite/CMakeLists.txt @@ -800,7 +800,6 @@ _add_executable(paltests miscellaneous/SetLastError/test1/test.cpp miscellaneous/_i64tow/test1/test1.cpp pal_specific/PAL_errno/test1/PAL_errno.cpp - pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp # pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp #pal_specific/PAL_get_stderr/test1/PAL_get_stderr.cpp #pal_specific/PAL_get_stdin/test1/PAL_get_stdin.cpp diff --git a/src/coreclr/src/pal/tests/palsuite/compilableTests.txt b/src/coreclr/src/pal/tests/palsuite/compilableTests.txt index 40e1d57..49b99c5 100644 --- a/src/coreclr/src/pal/tests/palsuite/compilableTests.txt +++ b/src/coreclr/src/pal/tests/palsuite/compilableTests.txt @@ -695,7 +695,6 @@ miscellaneous/SetEnvironmentVariableW/test4/paltest_setenvironmentvariablew_test miscellaneous/SetLastError/test1/paltest_setlasterror_test1 miscellaneous/_i64tow/test1/paltest_i64tow_test1 pal_specific/PAL_errno/test1/paltest_pal_errno_test1 -pal_specific/PAL_GetPALDirectoryW/test1/paltest_pal_getpaldirectoryw_test1 pal_specific/PAL_GetUserTempDirectoryW/test1/paltest_pal_getusertempdirectoryw_test1 pal_specific/PAL_Initialize_Terminate/test1/paltest_pal_initialize_terminate_test1 pal_specific/PAL_Initialize_Terminate/test2/paltest_pal_initialize_terminate_test2 diff --git a/src/coreclr/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp b/src/coreclr/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp deleted file mode 100644 index 21a1bb3..0000000 --- a/src/coreclr/src/pal/tests/palsuite/pal_specific/PAL_GetPALDirectoryW/test1/PAL_GetPALDirectoryW.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -/*============================================================= -** -** Source: pal_getpaldirectoryw.c -** -** Purpose: Positive test the PAL_GetPALDirectoryW API. -** Call this API to retrieve a fully-qualified -** directory name where the PAL DLL is loaded from. -** -** -**============================================================*/ -#define UNICODE -#include - -PALTEST(pal_specific_PAL_GetPALDirectoryW_test1_paltest_pal_getpaldirectoryw_test1, "pal_specific/PAL_GetPALDirectoryW/test1/paltest_pal_getpaldirectoryw_test1") -{ - int err; - BOOL bValue; - DWORD dwFileAttribute; - WCHAR *wpDirectoryName = NULL; - char *pDirectoryName = NULL; - - /*Initialize the PAL environment*/ - err = PAL_Initialize(argc, argv); - if(0 != err) - { - return FAIL; - } - - /*allocate momory to store the directory name*/ - wpDirectoryName = (WCHAR*)malloc(MAX_PATH*sizeof(WCHAR)); - if(NULL == wpDirectoryName) - { - Fail("\nFailed to allocate memory for storing directory name!\n"); - } - - UINT size = MAX_PATH; - /*retrieve the machine configuration directory*/ - bValue = PAL_GetPALDirectoryW(wpDirectoryName, &size); - if(FALSE == bValue) - { - free(wpDirectoryName); - Fail("Failed to call PAL_GetPALDirectoryW API, " - "error code =%u\n", GetLastError()); - } - - - /*convert wide char string to a standard one*/ - pDirectoryName = convertC(wpDirectoryName); - if(0 == strlen(pDirectoryName)) - { - free(wpDirectoryName); - free(pDirectoryName); - Fail("The retrieved directory name string is empty!\n"); - } - - /*free the memory*/ - free(pDirectoryName); - - /*retrieve the attribute of a file or directory*/ - dwFileAttribute = GetFileAttributesW(wpDirectoryName); - - /*free the memory*/ - free(wpDirectoryName); - - /*check if the attribute indicates a directory*/ - if(FILE_ATTRIBUTE_DIRECTORY != - (dwFileAttribute & FILE_ATTRIBUTE_DIRECTORY)) - { - Fail("The retrieved directory name is not a valid directory!\n"); - } - - PAL_Terminate(); - return PASS; -} diff --git a/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt b/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt index 37c7d6e..6533c5b 100644 --- a/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt +++ b/src/coreclr/src/pal/tests/palsuite/paltestlist_to_be_reviewed.txt @@ -111,7 +111,6 @@ miscellaneous/MessageBoxW/test1/paltest_messageboxw_test1 miscellaneous/MessageBoxW/test2/paltest_messageboxw_test2 miscellaneous/wsprintfW/test2/paltest_wsprintfw_test2 miscellaneous/wsprintfW/test7/paltest_wsprintfw_test7 -pal_specific/PAL_GetPALDirectoryW/test1/paltest_pal_getpaldirectoryw_test1 pal_specific/PAL_GetUserTempDirectoryW/test1/paltest_pal_getusertempdirectoryw_test1 pal_specific/PAL_get_stderr/test1/paltest_pal_get_stderr_test1 pal_specific/PAL_get_stdin/test1/paltest_pal_get_stdin_test1 diff --git a/src/coreclr/src/tools/crossgen/CMakeLists.txt b/src/coreclr/src/tools/crossgen/CMakeLists.txt index 4af88ce..eff97b0 100644 --- a/src/coreclr/src/tools/crossgen/CMakeLists.txt +++ b/src/coreclr/src/tools/crossgen/CMakeLists.txt @@ -57,8 +57,8 @@ target_link_libraries(crossgen if(CLR_CMAKE_HOST_UNIX) target_link_libraries(crossgen mscorrc - coreclrpal palrt + coreclrpal ) else() target_link_libraries(crossgen diff --git a/src/coreclr/src/tools/crossgen/crossgen.cpp b/src/coreclr/src/tools/crossgen/crossgen.cpp index 803ea5a..61faeb7 100644 --- a/src/coreclr/src/tools/crossgen/crossgen.cpp +++ b/src/coreclr/src/tools/crossgen/crossgen.cpp @@ -398,14 +398,8 @@ void ComputeTPAListFromPlatformAssembliesPath(LPCWSTR pwzPlatformAssembliesPaths } } -extern HMODULE g_hThisInst; - int _cdecl wmain(int argc, __in_ecount(argc) WCHAR **argv) { -#ifndef TARGET_UNIX - g_hThisInst = WszGetModuleHandle(NULL); -#endif - ///////////////////////////////////////////////////////////////////////// // // Parse the arguments diff --git a/src/coreclr/src/utilcode/ccomprc.cpp b/src/coreclr/src/utilcode/ccomprc.cpp index a3d669b..1b38edf 100644 --- a/src/coreclr/src/utilcode/ccomprc.cpp +++ b/src/coreclr/src/utilcode/ccomprc.cpp @@ -18,7 +18,7 @@ __attribute__((visibility("default"))) DECLARE_NATIVE_STRING_RESOURCE_TABLE(NATI #include // External prototypes. -extern HINSTANCE GetModuleInst(); +extern void* GetClrModuleBase(); //***************************************************************************** // Do the mapping from an langId to an hinstance node @@ -677,7 +677,7 @@ HRESULT CCompRC::LoadLibraryThrows(HRESOURCEDLL * pHInst) #ifdef CROSSGEN_COMPILE // The resources are embeded into the .exe itself for crossgen - *pHInst = GetModuleInst(); + *pHInst = (HINSTANCE)GetClrModuleBase(); #else #ifdef SELF_NO_HOST @@ -688,7 +688,7 @@ HRESULT CCompRC::LoadLibraryThrows(HRESOURCEDLL * pHInst) // Try first in the same directory as this dll. - hr = GetCORSystemDirectoryInternaL(rcPath); + hr = GetClrModuleDirectory(rcPath); if (FAILED(hr)) return hr; diff --git a/src/coreclr/src/utilcode/clrhost.cpp b/src/coreclr/src/utilcode/clrhost.cpp index 5aa3a35..188418f 100644 --- a/src/coreclr/src/utilcode/clrhost.cpp +++ b/src/coreclr/src/utilcode/clrhost.cpp @@ -12,7 +12,30 @@ #include "clrnt.h" #include "contract.h" -HINSTANCE g_hmodCoreCLR; +#if HOST_WINDOWS +extern "C" IMAGE_DOS_HEADER __ImageBase; +#else +static void* pImageBase = NULL; +#endif + +void* GetClrModuleBase() +{ + LIMITED_METHOD_CONTRACT; + +#if HOST_WINDOWS + return (void*)&__ImageBase; +#else // HOST_WINDOWS + // PAL_GetSymbolModuleBase defers to dladdr, which is typically a hash lookup through symbols. + // It should be fairly fast, however it may take a loader lock, so we will cache the result. + void* pRet = VolatileLoadWithoutBarrier(&pImageBase); + if (!pRet) + { + pImageBase = pRet = (void*)PAL_GetSymbolModuleBase((void*)GetClrModuleBase); + } + + return pRet; +#endif // HOST_WINDOWS +} thread_local int t_CantAllocCount; @@ -89,39 +112,15 @@ int RFS_HashStack () #endif // FAILPOINTS_ENABLED - - -//----------------------------------------------------------------------------------- -// This is the approved way to get a module handle to mscorwks.dll (or coreclr.dll). -// Never call GetModuleHandle(mscorwks) yourself as this will break side-by-side inproc. -// -// This function is safe to call before or during CRT initialization. It can not -// legally return NULL (it only does so in the case of a broken build invariant.) -// -// TODO puCLR SxS utilcode work: Since this is never supposed to return NULL, it should -// not be present in SELF_NO_HOST builds of utilcode where there isn't necessarily a -// CLR in the process. We should also ASSERT that GetModuleHandleA isn't returning -// NULL below - we've probably been getting away with this in SELF_NO_HOST cases like -// mscordbi.dll. -//----------------------------------------------------------------------------------- -HMODULE GetCLRModule () +DWORD GetClrModulePathName(SString& buffer) { - //! WARNING: At the time this function is invoked, the C Runtime has NOT been fully initialized, let alone the CLR. - //! So don't put in a runtime contract and don't invoke other functions in the CLR (not even _ASSERTE!) - - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_SUPPORTS_DAC; // DAC can call in here since we initialize the SxS callbacks in ClrDataAccess::Initialize. - - // You got here because the dll that included this copy of utilcode.lib. - // did not set g_hmodCoreCLR. The most likely cause is that you're running - // a dll (other than coreclr.dll) that links to utilcode.lib. - _ASSERTE(g_hmodCoreCLR != NULL); - - return g_hmodCoreCLR; +#ifdef HOST_WINDOWS + return WszGetModuleFileName((HINSTANCE)GetClrModuleBase(), buffer); +#else + return WszGetModuleFileName(PAL_GetPalHostModule(), buffer); +#endif } - - #if defined(SELF_NO_HOST) HMODULE CLRLoadLibrary(LPCWSTR lpLibFileName) diff --git a/src/coreclr/src/utilcode/ex.cpp b/src/coreclr/src/utilcode/ex.cpp index 56c1b55..7b15e4a 100644 --- a/src/coreclr/src/utilcode/ex.cpp +++ b/src/coreclr/src/utilcode/ex.cpp @@ -31,6 +31,9 @@ GVAL_IMPL_INIT(HRESULT, g_hrFatalError, S_OK); // and it will do nothing. void GetLastThrownObjectExceptionFromThread(Exception **ppException); +// Helper function to get pointer to clr module base +void* GetClrModuleBase(); + Exception *Exception::g_OOMException = NULL; // avoid global constructors @@ -1269,7 +1272,7 @@ static DWORD MarkAsThrownByUsWorker(UINT numArgs, /*out*/ ULONG_PTR exceptionArg exceptionArgs[0] = arg0; #if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) - exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] = (ULONG_PTR) (GetCLRModule()); + exceptionArgs[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] = (ULONG_PTR)GetClrModuleBase(); #endif // !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) return INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE; @@ -1317,7 +1320,7 @@ BOOL WasThrownByUs(const EXCEPTION_RECORD *pcER, DWORD dwExceptionCode) return FALSE; } #if!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) - if ( ((ULONG_PTR)(GetCLRModule())) != pcER->ExceptionInformation[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] ) + if ((ULONG_PTR)GetClrModuleBase() != pcER->ExceptionInformation[INSTANCE_TAGGED_SEH_PARAM_ARRAY_SIZE - 1] ) { return FALSE; } diff --git a/src/coreclr/src/utilcode/longfilepathwrappers.cpp b/src/coreclr/src/utilcode/longfilepathwrappers.cpp index 365d91b..3afc611 100644 --- a/src/coreclr/src/utilcode/longfilepathwrappers.cpp +++ b/src/coreclr/src/utilcode/longfilepathwrappers.cpp @@ -765,65 +765,6 @@ FindFirstFileExWrapper( } #endif // HOST_WINDOWS - -#ifdef HOST_WINDOWS - -#if ! defined(DACCESS_COMPILE) && !defined(SELF_NO_HOST) -extern HINSTANCE g_hThisInst; -#endif// ! defined(DACCESS_COMPILE) && !defined(SELF_NO_HOST) - -BOOL PAL_GetPALDirectoryWrapper(SString& pbuffer) -{ - - HRESULT hr = S_OK; - - PathString pPath; - DWORD dwPath; - HINSTANCE hinst = NULL; - -#if ! defined(DACCESS_COMPILE) && !defined(SELF_NO_HOST) - hinst = g_hThisInst; -#endif// ! defined(DACCESS_COMPILE) && !defined(SELF_NO_HOST) - -#ifndef CROSSGEN_COMPILE - _ASSERTE(hinst != NULL); -#endif - - dwPath = WszGetModuleFileName(hinst, pPath); - - if(dwPath == 0) - { - hr = HRESULT_FROM_GetLastErrorNA(); - } - else - { - hr = CopySystemDirectory(pPath, pbuffer); - } - - return (hr == S_OK); -} - -#else - -BOOL PAL_GetPALDirectoryWrapper(SString& pbuffer) -{ - BOOL retval = FALSE; - COUNT_T size = MAX_LONGPATH; - - if(!(retval = PAL_GetPALDirectoryW(pbuffer.OpenUnicodeBuffer(size - 1), &size))) - { - pbuffer.CloseBuffer(0); - retval = PAL_GetPALDirectoryW(pbuffer.OpenUnicodeBuffer(size - 1), &size); - } - - pbuffer.CloseBuffer(size); - - return retval; -} - -#endif // HOST_WINDOWS - - //Implementation of LongFile Helpers const WCHAR LongFile::DirectorySeparatorChar = W('\\'); const WCHAR LongFile::AltDirectorySeparatorChar = W('/'); diff --git a/src/coreclr/src/utilcode/makepath.cpp b/src/coreclr/src/utilcode/makepath.cpp index 374cda4..4bf8787 100644 --- a/src/coreclr/src/utilcode/makepath.cpp +++ b/src/coreclr/src/utilcode/makepath.cpp @@ -151,11 +151,9 @@ void MakePath ( } -// Returns the directory for HMODULE. So, if HMODULE was for "C:\Dir1\Dir2\Filename.DLL", -// then this would return "C:\Dir1\Dir2\" (note the trailing backslash). -HRESULT GetHModuleDirectory( - __in HMODULE hMod, - SString& wszPath) +// Returns the directory for clr module. So, if path was for "C:\Dir1\Dir2\Filename.DLL", +// then this would return "C:\Dir1\Dir2\" (note the trailing backslash).HRESULT GetClrModuleDirectory(SString& wszPath) +HRESULT GetClrModuleDirectory(SString& wszPath) { CONTRACTL { @@ -165,16 +163,14 @@ HRESULT GetHModuleDirectory( } CONTRACTL_END; - DWORD dwRet = WszGetModuleFileName(hMod, wszPath); + DWORD dwRet = GetClrModulePathName(wszPath); - if (dwRet == 0) + if (dwRet == 0) { // Some other error. return HRESULT_FROM_GetLastError(); } - CopySystemDirectory(wszPath, wszPath); - - + CopySystemDirectory(wszPath, wszPath); return S_OK; } diff --git a/src/coreclr/src/utilcode/stresslog.cpp b/src/coreclr/src/utilcode/stresslog.cpp index 7d5562b..7d01fc0 100644 --- a/src/coreclr/src/utilcode/stresslog.cpp +++ b/src/coreclr/src/utilcode/stresslog.cpp @@ -141,7 +141,7 @@ void StressLog::Leave(CRITSEC_COOKIE) { /*********************************************************************************/ void StressLog::Initialize(unsigned facilities, unsigned level, unsigned maxBytesPerThread, - unsigned maxBytesTotal, HMODULE hMod) + unsigned maxBytesTotal, void* moduleBase) { STATIC_CONTRACT_LEAF; @@ -173,18 +173,14 @@ void StressLog::Initialize(unsigned facilities, unsigned level, unsigned maxByt GetSystemTimeAsFileTime (&theLog.startTime); theLog.startTimeStamp = getTimeStamp(); + theLog.moduleOffset = (SIZE_T)moduleBase; #ifndef HOST_UNIX - theLog.moduleOffset = (SIZE_T)hMod; // HMODULES are base addresses. - #ifdef _DEBUG HMODULE hModNtdll = GetModuleHandleA("ntdll.dll"); theLog.RtlCaptureStackBackTrace = reinterpret_cast( GetProcAddress(hModNtdll, "RtlCaptureStackBackTrace")); #endif // _DEBUG - -#else // !HOST_UNIX - theLog.moduleOffset = (SIZE_T)PAL_GetSymbolModuleBase((void *)StressLog::Initialize); #endif // !HOST_UNIX #if !defined (STRESS_LOG_READONLY) && defined(HOST_WINDOWS) diff --git a/src/coreclr/src/utilcode/util.cpp b/src/coreclr/src/utilcode/util.cpp index d9cdedb..c034ae1 100644 --- a/src/coreclr/src/utilcode/util.cpp +++ b/src/coreclr/src/utilcode/util.cpp @@ -2951,20 +2951,18 @@ LPWSTR *SegmentCommandLine(LPCWSTR lpCmdLine, DWORD *pNumArgs) //====================================================================== // This function returns true, if it can determine that the instruction pointer // refers to a code address that belongs in the range of the given image. -// @TODO: Merge with IsIPInModule from vm\util.hpp - -BOOL IsIPInModule(HMODULE_TGT hModule, PCODE ip) +BOOL IsIPInModule(PTR_VOID pModuleBaseAddress, PCODE ip) { STATIC_CONTRACT_LEAF; SUPPORTS_DAC; struct Param { - HMODULE_TGT hModule; + PTR_VOID pModuleBaseAddress; PCODE ip; BOOL fRet; } param; - param.hModule = hModule; + param.pModuleBaseAddress = pModuleBaseAddress; param.ip = ip; param.fRet = FALSE; @@ -2972,7 +2970,7 @@ BOOL IsIPInModule(HMODULE_TGT hModule, PCODE ip) #ifdef HOST_WINDOWS PAL_TRY(Param *, pParam, ¶m) { - PTR_BYTE pBase = dac_cast(pParam->hModule); + PTR_BYTE pBase = dac_cast(pParam->pModuleBaseAddress); PTR_IMAGE_DOS_HEADER pDOS = NULL; PTR_IMAGE_NT_HEADERS pNT = NULL; diff --git a/src/coreclr/src/vm/ceeload.cpp b/src/coreclr/src/vm/ceeload.cpp index 2c74d59..2de5b75 100644 --- a/src/coreclr/src/vm/ceeload.cpp +++ b/src/coreclr/src/vm/ceeload.cpp @@ -3441,7 +3441,7 @@ ISymUnmanagedReader *Module::GetISymUnmanagedReader(void) if (FAILED(hr)) { PathString symbolReaderPath; - hr = GetHModuleDirectory(GetModuleInst(), symbolReaderPath); + hr = GetClrModuleDirectory(symbolReaderPath); if (FAILED(hr)) { RETURN (NULL); diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index e975195..914a3ee 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -637,18 +637,6 @@ void EEStartupHelper() { g_fEEInit = true; -#if CORECLR_EMBEDDED - -#ifdef TARGET_WINDOWS - HINSTANCE curModule = WszGetModuleHandle(NULL); -#else - HINSTANCE curModule = PAL_GetPalHostModule(); -#endif - - g_hmodCoreCLR = curModule; - g_hThisInst = curModule; -#endif - #ifndef CROSSGEN_COMPILE // We cache the SystemInfo for anyone to use throughout the life of the EE. @@ -717,7 +705,7 @@ void EEStartupHelper() unsigned level = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::EXTERNAL_LogLevel, LL_INFO1000); unsigned bytesPerThread = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_StressLogSize, STRESSLOG_CHUNK_SIZE * 4); unsigned totalBytes = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::UNSUPPORTED_TotalStressLogSize, STRESSLOG_CHUNK_SIZE * 1024); - StressLog::Initialize(facilities, level, bytesPerThread, totalBytes, GetModuleInst()); + StressLog::Initialize(facilities, level, bytesPerThread, totalBytes, GetClrModuleBase()); g_pStressLog = &StressLog::theLog; } #endif @@ -842,7 +830,7 @@ void EEStartupHelper() #ifndef TARGET_UNIX { // Record mscorwks geometry - PEDecoder pe(g_hThisInst); + PEDecoder pe(GetClrModuleBase()); g_runtimeLoadedBaseAddress = (SIZE_T)pe.GetBase(); g_runtimeVirtualSize = (SIZE_T)pe.GetVirtualSize(); @@ -1847,14 +1835,6 @@ BOOL STDMETHODCALLTYPE EEDllMain( // TRUE on success, FALSE on error. switch (pParam->dwReason) { - case DLL_PROCESS_ATTACH: - { - g_hmodCoreCLR = pParam->hInst; - // Save the module handle. - g_hThisInst = pParam->hInst; - break; - } - case DLL_PROCESS_DETACH: { // lpReserved is NULL if we're here because someone called FreeLibrary diff --git a/src/coreclr/src/vm/codeman.cpp b/src/coreclr/src/vm/codeman.cpp index d81e83d..8fb9fde 100644 --- a/src/coreclr/src/vm/codeman.cpp +++ b/src/coreclr/src/vm/codeman.cpp @@ -1592,10 +1592,9 @@ static void LoadAndInitializeJIT(LPCWSTR pwzJitName, OUT HINSTANCE* phJit, OUT I HRESULT hr = E_FAIL; PathString CoreClrFolderHolder; - extern HINSTANCE g_hThisInst; bool havePath = false; - if (WszGetModuleFileName(g_hThisInst, CoreClrFolderHolder)) + if (GetClrModulePathName(CoreClrFolderHolder)) { // Load JIT from next to CoreCLR binary havePath = true; diff --git a/src/coreclr/src/vm/common.h b/src/coreclr/src/vm/common.h index 992c6a7..f01ec50 100644 --- a/src/coreclr/src/vm/common.h +++ b/src/coreclr/src/vm/common.h @@ -368,7 +368,9 @@ namespace Loader #include "gcstress.h" HRESULT EnsureRtlFunctions(); -HINSTANCE GetModuleInst(); + +// Helper function returns the base of clr module. +void* GetClrModuleBase(); #if defined(TARGET_X86) || defined(TARGET_AMD64) // diff --git a/src/coreclr/src/vm/dwreport.cpp b/src/coreclr/src/vm/dwreport.cpp index 58aadd1..0370edd 100644 --- a/src/coreclr/src/vm/dwreport.cpp +++ b/src/coreclr/src/vm/dwreport.cpp @@ -139,10 +139,10 @@ BOOL RegisterOutOfProcessWatsonCallbacks() EX_TRY { PathString wszDACPath; - if (SUCCEEDED(::GetCORSystemDirectoryInternaL(wszDACPath))) + if (SUCCEEDED(::GetClrModuleDirectory(wszDACPath))) { wszDACPath.Append(wszDACName); - hr = (*pFnWerRegisterRuntimeExceptionModule)(wszDACPath, (PDWORD)g_hThisInst); + hr = (*pFnWerRegisterRuntimeExceptionModule)(wszDACPath, (PDWORD)GetClrModuleBase()); } else { hr = E_FAIL; diff --git a/src/coreclr/src/vm/eepolicy.cpp b/src/coreclr/src/vm/eepolicy.cpp index 04eea40..13645df 100644 --- a/src/coreclr/src/vm/eepolicy.cpp +++ b/src/coreclr/src/vm/eepolicy.cpp @@ -468,13 +468,13 @@ void EEPolicy::LogFatalError(UINT exitCode, UINT_PTR address, LPCWSTR pszMessage addressString.Printf(W("%p"), pExceptionInfo? (UINT_PTR)pExceptionInfo->ExceptionRecord->ExceptionAddress : address); // We should always have the reference to the runtime's instance - _ASSERTE(g_hThisInst != NULL); + _ASSERTE(GetClrModuleBase() != NULL); // Setup the string to contain the runtime's base address. Thus, when customers report FEEE with just // the event log entry containing this string, we can use the absolute and base addresses to determine // where the fault happened inside the runtime. SmallStackSString runtimeBaseAddressString; - runtimeBaseAddressString.Printf(W("%p"), g_hThisInst); + runtimeBaseAddressString.Printf(W("%p"), GetClrModuleBase()); SmallStackSString exitCodeString; exitCodeString.Printf(W("%x"), exitCode); diff --git a/src/coreclr/src/vm/eventtrace.cpp b/src/coreclr/src/vm/eventtrace.cpp index 802c521..ef7d0cd 100644 --- a/src/coreclr/src/vm/eventtrace.cpp +++ b/src/coreclr/src/vm/eventtrace.cpp @@ -5066,12 +5066,11 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type) PCWSTR lpwszCommandLine = W(""); - // if WszGetModuleFileName fails, we return an empty string - if (!WszGetModuleFileName(GetCLRModule(), dllPath)) { + // if GetClrModulePathName fails, we return an empty string + if (!GetClrModulePathName(dllPath)) { dllPath.Set(W("\0")); } - if(type == ETW::InfoLog::InfoStructs::Callback) { FireEtwRuntimeInformationDCStart( GetClrInstanceId(), diff --git a/src/coreclr/src/vm/excep.cpp b/src/coreclr/src/vm/excep.cpp index 0b5a4ad..3ca6f80 100644 --- a/src/coreclr/src/vm/excep.cpp +++ b/src/coreclr/src/vm/excep.cpp @@ -4041,7 +4041,7 @@ BuildCreateDumpCommandLine( const char* DumpGeneratorName = "createdump.exe"; PathString coreclrPath; - if (WszGetModuleFileName(GetCLRModule(), coreclrPath)) + if (GetClrModulePathName(coreclrPath)) { SString::CIterator lastBackslash = coreclrPath.End(); if (coreclrPath.FindBack(lastBackslash, W('\\'))) @@ -7306,7 +7306,7 @@ LONG WINAPI CLRVectoredExceptionHandlerPhase2(PEXCEPTION_POINTERS pExceptionInfo CONTRACT_VIOLATION(TakesLockViolation); fExternalException = (!ExecutionManager::IsManagedCode(GetIP(pExceptionInfo->ContextRecord)) && - !IsIPInModule(g_hThisInst, GetIP(pExceptionInfo->ContextRecord))); + !IsIPInModule(GetClrModuleBase(), GetIP(pExceptionInfo->ContextRecord))); } if (fExternalException) @@ -7473,7 +7473,7 @@ VEH_ACTION WINAPI CLRVectoredExceptionHandlerPhase3(PEXCEPTION_POINTERS pExcepti if ((!fAVisOk) && !(pExceptionRecord->ExceptionFlags & EXCEPTION_UNWINDING)) { PCODE ip = (PCODE)GetIP(pContext); - if (IsIPInModule(g_hThisInst, ip) || IsIPInModule(GCHeapUtilities::GetGCModule(), ip)) + if (IsIPInModule(GetClrModuleBase(), ip) || IsIPInModule(GCHeapUtilities::GetGCModuleBase(), ip)) { CONTRACT_VIOLATION(ThrowsViolation|FaultViolation); diff --git a/src/coreclr/src/vm/exceptionhandling.cpp b/src/coreclr/src/vm/exceptionhandling.cpp index 7d32990..3d3b902 100644 --- a/src/coreclr/src/vm/exceptionhandling.cpp +++ b/src/coreclr/src/vm/exceptionhandling.cpp @@ -975,7 +975,7 @@ ProcessCLRException(IN PEXCEPTION_RECORD pExceptionRecord BOOL fExternalException; fExternalException = (!ExecutionManager::IsManagedCode(ip) && - !IsIPInModule(g_hThisInst, ip)); + !IsIPInModule(GetClrModuleBase(), ip)); if (fExternalException) { @@ -6719,11 +6719,11 @@ StackFrame ExceptionTracker::FindParentStackFrameHelper(CrawlFrame* pCF, fIsCallerInVM = !ExecutionManager::IsManagedCode(callerIP); #else #if defined(DACCESS_COMPILE) - HMODULE_TGT hEE = DacGlobalBase(); + PTR_VOID eeBase = DacGlobalBase(); #else // !DACCESS_COMPILE - HMODULE_TGT hEE = g_hThisInst; + PTR_VOID eeBase = GetClrModuleBase(); #endif // !DACCESS_COMPILE - fIsCallerInVM = IsIPInModule(hEE, callerIP); + fIsCallerInVM = IsIPInModule(eeBase, callerIP); #endif // TARGET_UNIX if (!fIsCallerInVM) diff --git a/src/coreclr/src/vm/gcheaputilities.cpp b/src/coreclr/src/vm/gcheaputilities.cpp index 6067060..3432a00 100644 --- a/src/coreclr/src/vm/gcheaputilities.cpp +++ b/src/coreclr/src/vm/gcheaputilities.cpp @@ -56,7 +56,7 @@ GC_LOAD_STATUS g_gc_load_status = GC_LOAD_STATUS_BEFORE_START; VersionInfo g_gc_version_info; // The module that contains the GC. -HMODULE g_gc_module; +PTR_VOID g_gc_module_base; // GC entrypoints for the the linked-in GC. These symbols are invoked // directly if we are not using a standalone GC. @@ -70,10 +70,10 @@ extern "C" HRESULT GC_Initialize( #ifndef DACCESS_COMPILE -HMODULE GCHeapUtilities::GetGCModule() +PTR_VOID GCHeapUtilities::GetGCModuleBase() { - assert(g_gc_module); - return g_gc_module; + assert(g_gc_module_base); + return g_gc_module_base; } namespace @@ -101,7 +101,7 @@ BOOL g_gcEventTracingInitialized = FALSE; // to "publish" it by assigning it to g_pGCHeap. // // This function can proceed concurrently with StashKeywordAndLevel below. -void FinalizeLoad(IGCHeap* gcHeap, IGCHandleManager* handleMgr, HMODULE gcModule) +void FinalizeLoad(IGCHeap* gcHeap, IGCHandleManager* handleMgr, PTR_VOID pGcModuleBase) { g_pGCHeap = gcHeap; @@ -118,7 +118,7 @@ void FinalizeLoad(IGCHeap* gcHeap, IGCHandleManager* handleMgr, HMODULE gcModule g_pGCHandleManager = handleMgr; g_gcDacGlobals = &g_gc_dac_vars; g_gc_load_status = GC_LOAD_STATUS_LOAD_COMPLETE; - g_gc_module = gcModule; + g_gc_module_base = pGcModuleBase; LOG((LF_GC, LL_INFO100, "GC load successful\n")); } @@ -238,7 +238,15 @@ HRESULT LoadAndInitializeGC(LPWSTR standaloneGcLocation) HRESULT initResult = initFunc(gcToClr, &heap, &manager, &g_gc_dac_vars); if (initResult == S_OK) { - FinalizeLoad(heap, manager, hMod); + PTR_VOID pGcModuleBase; + +#if TARGET_WINDOWS + pGcModuleBase = (PTR_VOID)hMod; +#else + pGcModuleBase = (PTR_VOID)PAL_GetSymbolModuleBase((PVOID)initFunc); +#endif + + FinalizeLoad(heap, manager, pGcModuleBase); } else { @@ -277,7 +285,7 @@ HRESULT InitializeDefaultGC() HRESULT initResult = GC_Initialize(nullptr, &heap, &manager, &g_gc_dac_vars); if (initResult == S_OK) { - FinalizeLoad(heap, manager, GetModuleInst()); + FinalizeLoad(heap, manager, GetClrModuleBase()); } else { diff --git a/src/coreclr/src/vm/gcheaputilities.h b/src/coreclr/src/vm/gcheaputilities.h index ab1f931..3d64886 100644 --- a/src/coreclr/src/vm/gcheaputilities.h +++ b/src/coreclr/src/vm/gcheaputilities.h @@ -198,8 +198,8 @@ public: #endif // FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP #ifndef DACCESS_COMPILE - // Gets the module that contains the GC. - static HMODULE GetGCModule(); + // Gets a pointer to the module that contains the GC. + static PTR_VOID GetGCModuleBase(); // Loads (if using a standalone GC) and initializes the GC. static HRESULT LoadAndInitialize(); diff --git a/src/coreclr/src/vm/hosting.cpp b/src/coreclr/src/vm/hosting.cpp index 92ab961..f843926 100644 --- a/src/coreclr/src/vm/hosting.cpp +++ b/src/coreclr/src/vm/hosting.cpp @@ -173,7 +173,7 @@ BOOL ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWO CONTRACT_VIOLATION(ThrowsViolation); // Get reference to MSCORWKS image in memory... - PEDecoder pe(g_hThisInst); + PEDecoder pe(GetClrModuleBase()); // Find the UEF section from the image IMAGE_SECTION_HEADER* pUEFSection = pe.FindSection(CLR_UEF_SECTION_NAME); diff --git a/src/coreclr/src/vm/jithelpers.cpp b/src/coreclr/src/vm/jithelpers.cpp index e122cfc..435f8ca 100644 --- a/src/coreclr/src/vm/jithelpers.cpp +++ b/src/coreclr/src/vm/jithelpers.cpp @@ -5624,10 +5624,10 @@ void InitJitHelperLogging() { #ifdef TARGET_X86 - IMAGE_DOS_HEADER *pDOS = (IMAGE_DOS_HEADER *)g_hThisInst; + IMAGE_DOS_HEADER *pDOS = (IMAGE_DOS_HEADER *)GetClrModuleBase(); _ASSERTE(pDOS->e_magic == VAL16(IMAGE_DOS_SIGNATURE) && pDOS->e_lfanew != 0); - IMAGE_NT_HEADERS *pNT = (IMAGE_NT_HEADERS*)((LPBYTE)g_hThisInst + VAL32(pDOS->e_lfanew)); + IMAGE_NT_HEADERS *pNT = (IMAGE_NT_HEADERS*)((LPBYTE)GetClrModuleBase() + VAL32(pDOS->e_lfanew)); #ifdef HOST_64BIT _ASSERTE(pNT->Signature == VAL32(IMAGE_NT_SIGNATURE) && pNT->FileHeader.SizeOfOptionalHeader == VAL16(sizeof(IMAGE_OPTIONAL_HEADER64)) @@ -5731,7 +5731,7 @@ void InitJitHelperLogging() #else // TARGET_X86 // Is the address in mscoree.dll at all? (All helpers are in // mscoree.dll) - if (dynamicHlpFunc->pfnHelper >= (LPBYTE*)g_hThisInst && dynamicHlpFunc->pfnHelper < (LPBYTE*)g_hThisInst + VAL32(pNT->OptionalHeader.SizeOfImage)) + if (dynamicHlpFunc->pfnHelper >= (LPBYTE*)GetClrModuleBase() && dynamicHlpFunc->pfnHelper < (LPBYTE*)GetClrModuleBase() + VAL32(pNT->OptionalHeader.SizeOfImage)) { // See note above. How do I get the size on x86 for a static method? hlpFuncCount->helperSize = 0; diff --git a/src/coreclr/src/vm/pefile.cpp b/src/coreclr/src/vm/pefile.cpp index 9966c4c..406d76c 100644 --- a/src/coreclr/src/vm/pefile.cpp +++ b/src/coreclr/src/vm/pefile.cpp @@ -1067,46 +1067,6 @@ LPCWSTR CorCompileGetRuntimeDllName(CorCompileRuntimeDlls id) return CorCompileRuntimeDllNames[id]; } -#ifndef CROSSGEN_COMPILE - -//============================================================================== -// Will always return a valid HMODULE for CLR_INFO, but will return NULL for NGEN_COMPILER_INFO -// if the DLL has not yet been loaded (it does not try to cause a load). - -extern HMODULE CorCompileGetRuntimeDll(CorCompileRuntimeDlls id) -{ - CONTRACTL - { - THROWS; - GC_NOTRIGGER; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - // Currently special cased for every entry. - static_assert_no_msg(NUM_RUNTIME_DLLS == 2); - static_assert_no_msg(CORECLR_INFO == 0); - - HMODULE hMod = NULL; - - // Try to load the correct DLL - switch (id) - { - case CORECLR_INFO: - hMod = GetCLRModule(); - break; - - default: - COMPlusThrowNonLocalized(kExecutionEngineException, - W("Invalid runtime DLL ID")); - break; - } - - return hMod; -} -#endif // CROSSGEN_COMPILE - //=========================================================================================================== // Validates that an NI matches the running CLR, OS, CPU, etc. // diff --git a/src/coreclr/src/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/src/vm/proftoeeinterfaceimpl.cpp index 124c703..04105ce 100644 --- a/src/coreclr/src/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/src/vm/proftoeeinterfaceimpl.cpp @@ -4122,7 +4122,7 @@ HRESULT ProfToEEInterfaceImpl::GetModuleInfo2(ModuleID moduleId, // Return the parent assembly for this module if desired. if (pAssemblyId != NULL) { - // Lie and say the assembly isn't avaialable until we are loaded (even though it is.) + // Lie and say the assembly isn't available until we are loaded (even though it is.) // This is for backward compatibilty - we may want to change it if (pModule->IsProfilerNotified()) { diff --git a/src/coreclr/src/vm/threads.cpp b/src/coreclr/src/vm/threads.cpp index f6ffe1b..b013e42 100644 --- a/src/coreclr/src/vm/threads.cpp +++ b/src/coreclr/src/vm/threads.cpp @@ -6142,7 +6142,7 @@ size_t getStackHash(size_t* stackTrace, size_t* stackTop, size_t* stackStop, siz NULL ); - if (((UINT_PTR)g_hThisInst) != uImageBase) + if (((UINT_PTR)GetClrModuleBase()) != uImageBase) { break; } diff --git a/src/coreclr/src/vm/vars.cpp b/src/coreclr/src/vm/vars.cpp index 6239469..b684583 100644 --- a/src/coreclr/src/vm/vars.cpp +++ b/src/coreclr/src/vm/vars.cpp @@ -29,7 +29,6 @@ const char g_psBaseLibrarySatelliteAssemblyName[] = CoreLibSatelliteName_A; Volatile g_TrapReturningThreads; -HINSTANCE g_hThisInst; BBSweep g_BBSweep; #ifdef _DEBUG diff --git a/src/coreclr/src/vm/vars.hpp b/src/coreclr/src/vm/vars.hpp index ccf9289..3b85c93 100644 --- a/src/coreclr/src/vm/vars.hpp +++ b/src/coreclr/src/vm/vars.hpp @@ -346,7 +346,6 @@ GARY_DECL(TypeHandle, g_pPredefinedArrayTypes, ELEMENT_TYPE_MAX); extern "C" Volatile g_TrapReturningThreads; -EXTERN HINSTANCE g_hThisInst; EXTERN BBSweep g_BBSweep; EXTERN IBCLogger g_IBCLogger; diff --git a/src/coreclr/src/zap/zapper.cpp b/src/coreclr/src/zap/zapper.cpp index c2e7308..97b47cb 100644 --- a/src/coreclr/src/zap/zapper.cpp +++ b/src/coreclr/src/zap/zapper.cpp @@ -450,7 +450,6 @@ void Zapper::LoadAndInitializeJITForNgen(LPCWSTR pwzJitName, OUT HINSTANCE* phJi // Note: FEATURE_MERGE_JIT_AND_ENGINE is defined for the Desktop crossgen compilation as well. // PathString CoreClrFolder; - extern HINSTANCE g_hThisInst; #if !defined(FEATURE_MERGE_JIT_AND_ENGINE) if (m_fDontLoadJit) @@ -466,13 +465,11 @@ void Zapper::LoadAndInitializeJITForNgen(LPCWSTR pwzJitName, OUT HINSTANCE* phJi } else #endif // !defined(FEATURE_MERGE_JIT_AND_ENGINE) - if (WszGetModuleFileName(g_hThisInst, CoreClrFolder)) { - hr = CopySystemDirectory(CoreClrFolder, CoreClrFolder); + hr = GetClrModuleDirectory(CoreClrFolder); if (SUCCEEDED(hr)) { CoreClrFolder.Append(pwzJitName); - } } diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index feb7bb7..bc91c6f 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -131,8 +131,8 @@ else() set(CORECLR_LIBRARIES ${CORECLR_STATIC_LIB_LOCATION}/libcoreclr_static.a ${CORECLR_STATIC_LIB_LOCATION}/libSystem.Globalization.Native.a - ${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a ${CORECLR_STATIC_LIB_LOCATION}/libpalrt.a + ${CORECLR_STATIC_LIB_LOCATION}/libcoreclrpal.a ${CORECLR_STATIC_LIB_LOCATION}/libeventprovider.a ${CORECLR_STATIC_LIB_LOCATION}/libnativeresourcestring.a ) -- 2.7.4