From 7f85a8c3887ba1be64b1eda4cc996fa543277848 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Wed, 18 Aug 2021 16:52:32 -0700 Subject: [PATCH] Some cleanups in Assembly/Loader area (#57023) * rename GAC -> TPA * remove GetAvailableImageTypes * Removed ICLRPrivAssembly * Move Assembly:: Add/Release to .inl * ApplicationContext is not implementing IUnknown * ApplicationContext does not need AppDomainId * ICLRPrivBinder is not a COM object * Assembly is not a binder and should not have BindAssemblyByName * ApplicationContext is always an embedded value and does not need reference counting. * Simplified GetBinderID and GetLoaderAllocator, since not COM * Moved AppContext to up to ICLRPrivBinder * Removed GetBinderHash * Removed a couple now pointless AddRef/Release * virtualized BindUsingAssemblyName * renamed ICLRPrivBinder --> AssemblyBinder * renamed BINDER_SPACE::AssemblyBinder --> BINDER_SPACE::AssemblyBinderCommon * Merge CCoreCLRBinderHelper into AssemblyBinderCommon * Rename CLRPrivBinderCoreCLR -->DefaultAssemblyBinder * Renamed CLRPrivBinderAssemblyLoadContext --> CustomAssemblyBinder * Renamed PTR_ICLRPrivBinder --> PTR_AssemblyBinder * Remove clrprivbinding_i.cpp * A few touch ups * fix Linux build --- src/coreclr/binder/CMakeLists.txt | 14 +- src/coreclr/binder/applicationcontext.cpp | 53 +-- src/coreclr/binder/assembly.cpp | 78 +---- ...blybinder.cpp => assemblybindercommon.cpp} | 204 ++++++++---- src/coreclr/binder/bindertracing.cpp | 30 +- src/coreclr/binder/coreclrbindercommon.cpp | 128 -------- ...adcontext.cpp => customassemblybinder.cpp} | 85 ++--- ...rcoreclr.cpp => defaultassemblybinder.cpp} | 62 ++-- src/coreclr/binder/inc/applicationcontext.hpp | 21 +- src/coreclr/binder/inc/applicationcontext.inl | 10 - src/coreclr/binder/inc/assembly.hpp | 55 +--- src/coreclr/binder/inc/assembly.inl | 43 +-- ...blybinder.hpp => assemblybindercommon.hpp} | 34 +- src/coreclr/binder/inc/bindertracing.h | 4 +- src/coreclr/binder/inc/bindresult.hpp | 9 +- src/coreclr/binder/inc/bindresult.inl | 43 ++- src/coreclr/binder/inc/clrprivbindercoreclr.h | 67 ---- src/coreclr/binder/inc/contextentry.hpp | 40 +-- src/coreclr/binder/inc/coreclrbindercommon.h | 43 --- ...lyloadcontext.h => customassemblybinder.h} | 52 ++- .../binder/inc/defaultassemblybinder.h | 55 ++++ src/coreclr/binder/inc/loadcontext.hpp | 5 - src/coreclr/binder/inc/loadcontext.inl | 22 +- src/coreclr/inc/CMakeLists.txt | 1 - ...rprivbinderutil.h => assemblybinderutil.h} | 12 +- src/coreclr/inc/clrprivbinding.idl | 99 ------ src/coreclr/inc/corerror.xml | 2 +- src/coreclr/inc/corhost.h | 2 - .../pal/prebuilt/idl/clrprivbinding_i.cpp | 75 ----- src/coreclr/pal/prebuilt/inc/clrprivbinding.h | 305 ------------------ src/coreclr/vm/CMakeLists.txt | 2 + src/coreclr/vm/appdomain.cpp | 49 ++- src/coreclr/vm/appdomain.hpp | 16 +- src/coreclr/vm/appdomainnative.cpp | 6 +- src/coreclr/vm/assembly.cpp | 13 +- src/coreclr/vm/assembly.hpp | 2 +- src/coreclr/vm/assemblybinder.cpp | 27 ++ src/coreclr/vm/assemblybinder.h | 41 +++ src/coreclr/vm/assemblyloadcontext.cpp | 13 +- src/coreclr/vm/assemblyloadcontext.h | 10 +- src/coreclr/vm/assemblynative.cpp | 59 ++-- src/coreclr/vm/assemblynative.hpp | 4 +- src/coreclr/vm/assemblyspec.cpp | 81 ++--- src/coreclr/vm/assemblyspec.hpp | 10 +- src/coreclr/vm/baseassemblyspec.h | 6 +- src/coreclr/vm/baseassemblyspec.inl | 4 +- src/coreclr/vm/ceeload.cpp | 6 +- src/coreclr/vm/ceeload.h | 2 +- src/coreclr/vm/coreassemblyspec.cpp | 18 +- src/coreclr/vm/coreclr/corebindresult.h | 6 +- src/coreclr/vm/coreclr/corebindresult.inl | 23 +- src/coreclr/vm/corhost.cpp | 2 +- src/coreclr/vm/domainfile.cpp | 4 +- src/coreclr/vm/loaderallocator.cpp | 4 +- src/coreclr/vm/loaderallocator.hpp | 8 +- src/coreclr/vm/multicorejit.cpp | 4 +- src/coreclr/vm/multicorejit.h | 2 +- src/coreclr/vm/multicorejitimpl.h | 8 +- src/coreclr/vm/multicorejitplayer.cpp | 2 +- src/coreclr/vm/nativelibrary.cpp | 31 +- src/coreclr/vm/pefile.cpp | 55 ++-- src/coreclr/vm/pefile.h | 24 +- src/coreclr/vm/pefile.inl | 2 +- src/coreclr/vm/runtimehandles.cpp | 4 +- src/coreclr/vm/typeparse.cpp | 6 +- src/coreclr/vm/typeparse.h | 6 +- src/coreclr/vm/typestring.h | 2 +- 67 files changed, 684 insertions(+), 1531 deletions(-) rename src/coreclr/binder/{assemblybinder.cpp => assemblybindercommon.cpp} (90%) delete mode 100644 src/coreclr/binder/coreclrbindercommon.cpp rename src/coreclr/binder/{clrprivbinderassemblyloadcontext.cpp => customassemblybinder.cpp} (76%) rename src/coreclr/binder/{clrprivbindercoreclr.cpp => defaultassemblybinder.cpp} (80%) rename src/coreclr/binder/inc/{assemblybinder.hpp => assemblybindercommon.hpp} (81%) delete mode 100644 src/coreclr/binder/inc/clrprivbindercoreclr.h delete mode 100644 src/coreclr/binder/inc/coreclrbindercommon.h rename src/coreclr/binder/inc/{clrprivbinderassemblyloadcontext.h => customassemblybinder.h} (57%) create mode 100644 src/coreclr/binder/inc/defaultassemblybinder.h rename src/coreclr/inc/{clrprivbinderutil.h => assemblybinderutil.h} (78%) delete mode 100644 src/coreclr/inc/clrprivbinding.idl delete mode 100644 src/coreclr/pal/prebuilt/idl/clrprivbinding_i.cpp delete mode 100644 src/coreclr/pal/prebuilt/inc/clrprivbinding.h create mode 100644 src/coreclr/vm/assemblybinder.cpp create mode 100644 src/coreclr/vm/assemblybinder.h diff --git a/src/coreclr/binder/CMakeLists.txt b/src/coreclr/binder/CMakeLists.txt index 537791412fd84..1885ea1e0957f 100644 --- a/src/coreclr/binder/CMakeLists.txt +++ b/src/coreclr/binder/CMakeLists.txt @@ -6,12 +6,11 @@ include_directories(BEFORE "inc") set(BINDER_COMMON_SOURCES applicationcontext.cpp assembly.cpp - assemblybinder.cpp + assemblybindercommon.cpp assemblyidentitycache.cpp assemblyname.cpp bindertracing.cpp - clrprivbindercoreclr.cpp - coreclrbindercommon.cpp + defaultassemblybinder.cpp failurecache.cpp stringlexer.cpp textualidentityparser.cpp @@ -23,7 +22,7 @@ set(BINDER_COMMON_HEADERS inc/applicationcontext.inl inc/assembly.hpp inc/assembly.inl - inc/assemblybinder.hpp + inc/assemblybindercommon.hpp inc/assemblyentry.hpp inc/assemblyhashtraits.hpp inc/assemblyidentity.hpp @@ -36,8 +35,7 @@ set(BINDER_COMMON_HEADERS inc/bindertracing.h inc/bindresult.hpp inc/bindresult.inl - inc/clrprivbindercoreclr.h - inc/coreclrbindercommon.h + inc/defaultassemblybinder.h inc/failurecache.hpp inc/failurecachehashtraits.hpp inc/loadcontext.hpp @@ -51,13 +49,13 @@ set(BINDER_COMMON_HEADERS set(BINDER_SOURCES ${BINDER_COMMON_SOURCES} activitytracker.cpp - clrprivbinderassemblyloadcontext.cpp + customassemblybinder.cpp ) set(BINDER_HEADERS ${BINDER_COMMON_HEADERS} inc/activitytracker.h - inc/clrprivbinderassemblyloadcontext.h + inc/customassemblybinder.h inc/contextentry.hpp ) diff --git a/src/coreclr/binder/applicationcontext.cpp b/src/coreclr/binder/applicationcontext.cpp index dd02857652b2f..77aa822bde9b3 100644 --- a/src/coreclr/binder/applicationcontext.cpp +++ b/src/coreclr/binder/applicationcontext.cpp @@ -23,63 +23,17 @@ using namespace clr::fs; namespace BINDER_SPACE { - STDMETHODIMP ApplicationContext::QueryInterface(REFIID riid, - void **ppv) - { - HRESULT hr = S_OK; - - if (ppv == NULL) - { - hr = E_POINTER; - } - else - { - if (IsEqualIID(riid, IID_IUnknown)) - { - AddRef(); - *ppv = static_cast(this); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - } - - return hr; - } - - STDMETHODIMP_(ULONG) ApplicationContext::AddRef() - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) ApplicationContext::Release() - { - ULONG ulRef = InterlockedDecrement(&m_cRef); - - if (ulRef == 0) - { - delete this; - } - - return ulRef; - } - ApplicationContext::ApplicationContext() { - m_cRef = 1; - m_dwAppDomainId = 0; m_pExecutionContext = NULL; m_pFailureCache = NULL; m_contextCS = NULL; m_pTrustedPlatformAssemblyMap = nullptr; - m_binderID = 0; } ApplicationContext::~ApplicationContext() { - SAFE_RELEASE(m_pExecutionContext); + SAFE_DELETE(m_pExecutionContext); SAFE_DELETE(m_pFailureCache); if (m_contextCS != NULL) @@ -93,11 +47,11 @@ namespace BINDER_SPACE } } - HRESULT ApplicationContext::Init(UINT_PTR binderID) + HRESULT ApplicationContext::Init() { HRESULT hr = S_OK; - ReleaseHolder pExecutionContext; + NewHolder pExecutionContext; FailureCache *pFailureCache = NULL; @@ -121,7 +75,6 @@ namespace BINDER_SPACE m_pFailureCache = pFailureCache; } - m_binderID = binderID; Exit: return hr; } diff --git a/src/coreclr/binder/assembly.cpp b/src/coreclr/binder/assembly.cpp index 09c195c0f8d09..b2459e7ae243f 100644 --- a/src/coreclr/binder/assembly.cpp +++ b/src/coreclr/binder/assembly.cpp @@ -24,49 +24,6 @@ namespace BINDER_SPACE } }; - STDMETHODIMP Assembly::QueryInterface(REFIID riid, - void **ppv) - { - HRESULT hr = S_OK; - - if (ppv == NULL) - { - hr = E_POINTER; - } - else - { - if (IsEqualIID(riid, IID_IUnknown)) - { - AddRef(); - *ppv = static_cast(this); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - } - - return hr; - } - - STDMETHODIMP_(ULONG) Assembly::AddRef() - { - return InterlockedIncrement(&m_cRef); - } - - STDMETHODIMP_(ULONG) Assembly::Release() - { - ULONG ulRef = InterlockedDecrement(&m_cRef); - - if (ulRef == 0) - { - delete this; - } - - return ulRef; - } - Assembly::Assembly() { m_cRef = 1; @@ -103,7 +60,7 @@ namespace BINDER_SPACE PEImage *pPEImage, PEImage *pNativePEImage, SString &assemblyPath, - BOOL fIsInGAC) + BOOL fIsInTPA) { HRESULT hr = S_OK; @@ -113,7 +70,7 @@ namespace BINDER_SPACE // Get assembly name def from meta data import and store it for later refs access IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind)); SetMDImport(pIMetaDataAssemblyImport); - if (!fIsInGAC) + if (!fIsInTPA) { GetPath().Set(assemblyPath); } @@ -121,7 +78,7 @@ namespace BINDER_SPACE // Safe architecture for validation PEKIND kAssemblyArchitecture; kAssemblyArchitecture = pAssemblyName->GetArchitecture(); - SetIsInGAC(fIsInGAC); + SetIsInTPA(fIsInTPA); SetPEImage(pPEImage); SetNativePEImage(pNativePEImage); pAssemblyName->SetIsDefinition(TRUE); @@ -174,7 +131,7 @@ namespace BINDER_SPACE } // -------------------------------------------------------------------- - // ICLRPrivAssembly methods + // BINDER_SPACE::Assembly methods // -------------------------------------------------------------------- LPCWSTR Assembly::GetSimpleName() { @@ -182,32 +139,9 @@ namespace BINDER_SPACE return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName()); } - HRESULT Assembly::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly ** ppAssembly) - { - return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pAssemblyNameData, ppAssembly); - } - - HRESULT Assembly::GetBinderID(UINT_PTR *pBinderId) - { - return (m_pBinder == NULL) ? E_FAIL : m_pBinder->GetBinderID(pBinderId); - } - - HRESULT Assembly::GetLoaderAllocator(LPVOID* pLoaderAllocator) - { - return (m_pBinder == NULL) ? E_FAIL : m_pBinder->GetLoaderAllocator(pLoaderAllocator); - } - - HRESULT Assembly::GetAvailableImageTypes( - LPDWORD pdwImageTypes) + AssemblyLoaderAllocator* Assembly::GetLoaderAllocator() { - HRESULT hr = E_FAIL; - - if(pdwImageTypes == nullptr) - return E_INVALIDARG; - - *pdwImageTypes = ASSEMBLY_IMAGE_TYPE_ASSEMBLY; - - return S_OK; + return m_pBinder ? m_pBinder->GetLoaderAllocator() : NULL; } } diff --git a/src/coreclr/binder/assemblybinder.cpp b/src/coreclr/binder/assemblybindercommon.cpp similarity index 90% rename from src/coreclr/binder/assemblybinder.cpp rename to src/coreclr/binder/assemblybindercommon.cpp index c4a2e85d8f5ac..b495772b4b9a3 100644 --- a/src/coreclr/binder/assemblybinder.cpp +++ b/src/coreclr/binder/assemblybindercommon.cpp @@ -11,7 +11,8 @@ // // ============================================================ -#include "assemblybinder.hpp" +#include "common.h" +#include "assemblybindercommon.hpp" #include "assemblyname.hpp" #include "assembly.hpp" #include "applicationcontext.hpp" @@ -28,12 +29,12 @@ #endif #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -#include "clrprivbindercoreclr.h" +#include "defaultassemblybinder.h" // Helper function in the VM, invoked by the Binder, to invoke the host assembly resolver extern HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, - CLRPrivBinderCoreCLR *pTPABinder, - ICLRPrivAssembly **ppLoadedAssembly); + DefaultAssemblyBinder *pTPABinder, + BINDER_SPACE::Assembly **ppLoadedAssembly); #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) @@ -170,7 +171,7 @@ namespace BINDER_SPACE pPEImage, pNativePEImage, asesmblyPath, - FALSE /* fIsInGAC */)); + FALSE /* fIsInTPA */)); pBindResult->SetResult(pAssembly); pBindResult->SetIsFirstRequest(TRUE); @@ -181,7 +182,7 @@ namespace BINDER_SPACE #endif // !CROSSGEN_COMPILE }; - HRESULT AssemblyBinder::TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind) + HRESULT AssemblyBinderCommon::TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind) { HRESULT hr = S_OK; @@ -246,10 +247,10 @@ namespace BINDER_SPACE return hr; } - // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind + // See code:BINDER_SPACE::AssemblyBinderCommon::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. - HRESULT AssemblyBinder::BindAssembly(/* in */ ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::BindAssembly(/* in */ AssemblyBinder *pBinder, /* in */ AssemblyName *pAssemblyName, /* in */ LPCWSTR szCodeBase, /* in */ PEAssembly *pParentAssembly, @@ -261,9 +262,10 @@ namespace BINDER_SPACE HRESULT hr = S_OK; LONG kContextVersion = 0; BindResult bindResult; + ApplicationContext* pApplicationContext = pBinder->GetAppContext(); // Tracing happens outside the binder lock to avoid calling into managed code within the lock - BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pApplicationContext->GetBinderID(), 0 /*managedALC*/, hr}; + BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pBinder, 0 /*managedALC*/, hr}; #ifndef CROSSGEN_COMPILE Retry: @@ -334,11 +336,11 @@ namespace BINDER_SPACE } else if (hr == S_OK) { - *ppAssembly = hostBindResult.GetAsAssembly(TRUE /* fAddRef */); + *ppAssembly = hostBindResult.GetAssembly(TRUE /* fAddRef */); } #else // CROSSGEN_COMPILE - *ppAssembly = bindResult.GetAsAssembly(TRUE /* fAddRef */); + *ppAssembly = bindResult.GetAssembly(TRUE /* fAddRef */); #endif // CROSSGEN_COMPILE } @@ -346,8 +348,32 @@ namespace BINDER_SPACE return hr; } +#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) /* static */ - HRESULT AssemblyBinder::BindToSystem(SString &systemDirectory, + HRESULT AssemblyBinderCommon::BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly, bool fBindToNativeImage) + { + HRESULT hr = S_OK; + _ASSERTE(ppSystemAssembly != NULL); + + EX_TRY + { + ReleaseHolder pAsm; + StackSString systemPath(SystemDomain::System()->SystemDirectory()); + hr = AssemblyBinderCommon::BindToSystem(systemPath, &pAsm, fBindToNativeImage); + if (SUCCEEDED(hr)) + { + _ASSERTE(pAsm != NULL); + *ppSystemAssembly = pAsm.Extract(); + } + } + EX_CATCH_HRESULT(hr); + + return hr; + } +#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) + + /* static */ + HRESULT AssemblyBinderCommon::BindToSystem(SString &systemDirectory, Assembly **ppSystemAssembly, bool fBindToNativeImage) { @@ -378,8 +404,8 @@ namespace BINDER_SPACE sCoreLib.Set(systemDirectory); CombinePath(sCoreLib, sCoreLibName, sCoreLib); - hr = AssemblyBinder::GetAssembly(sCoreLib, - TRUE /* fIsInGAC */, + hr = AssemblyBinderCommon::GetAssembly(sCoreLib, + TRUE /* fIsInTPA */, fBindToNativeImage, &pSystemAssembly, NULL /* szMDAssemblyPath */, @@ -419,8 +445,8 @@ namespace BINDER_SPACE GO_WITH_HRESULT(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); } - hr = AssemblyBinder::GetAssembly(sCoreLib, - TRUE /* fIsInGAC */, + hr = AssemblyBinderCommon::GetAssembly(sCoreLib, + TRUE /* fIsInTPA */, fBindToNativeImage, &pSystemAssembly, NULL /* szMDAssemblyPath */, @@ -439,7 +465,7 @@ namespace BINDER_SPACE /* static */ - HRESULT AssemblyBinder::BindToSystemSatellite(SString& systemDirectory, + HRESULT AssemblyBinderCommon::BindToSystemSatellite(SString& systemDirectory, SString& simpleName, SString& cultureName, Assembly** ppSystemAssembly) @@ -478,8 +504,8 @@ namespace BINDER_SPACE CombinePath(sCoreLibSatellite, relativePath, sCoreLibSatellite); ReleaseHolder pSystemAssembly; - IF_FAIL_GO(AssemblyBinder::GetAssembly(sCoreLibSatellite, - TRUE /* fIsInGAC */, + IF_FAIL_GO(AssemblyBinderCommon::GetAssembly(sCoreLibSatellite, + TRUE /* fIsInTPA */, FALSE /* fExplicitBindToNativeImage */, &pSystemAssembly, NULL /* szMDAssemblyPath */, @@ -493,7 +519,7 @@ namespace BINDER_SPACE } /* static */ - HRESULT AssemblyBinder::BindByName(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::BindByName(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, bool skipFailureCaching, bool skipVersionCompatibilityCheck, @@ -568,10 +594,10 @@ namespace BINDER_SPACE } /* static */ - // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind + // See code:BINDER_SPACE::AssemblyBinderCommon::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. - HRESULT AssemblyBinder::BindWhereRef(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::BindWhereRef(ApplicationContext *pApplicationContext, PathString &assemblyPath, BOOL fNgenExplicitBind, BOOL fExplicitBindToNativeImage, @@ -594,7 +620,7 @@ namespace BINDER_SPACE // Design decision. For now, keep the V2 model of Fusion being oblivious of the strong name. // Security team did not see any security concern with interpreting the version information. IF_FAIL_GO(GetAssembly(assemblyPath, - FALSE /* fIsInGAC */, + FALSE /* fIsInTPA */, // Pass through caller's intent of whether to bind to the // NI using an explicit path to the NI that was @@ -638,7 +664,7 @@ namespace BINDER_SPACE } /* static */ - HRESULT AssemblyBinder::BindLocked(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::BindLocked(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, bool skipVersionCompatibilityCheck, bool excludeAppPaths, @@ -691,7 +717,7 @@ namespace BINDER_SPACE { bool isCompatible = IsCompatibleAssemblyVersion(pAssemblyName, pBindResult->GetAssemblyName()); hr = isCompatible ? S_OK : FUSION_E_APP_DOMAIN_LOCKED; - pBindResult->SetAttemptResult(hr, pBindResult->GetAsAssembly()); + pBindResult->SetAttemptResult(hr, pBindResult->GetAssembly()); // TPA binder returns FUSION_E_REF_DEF_MISMATCH for incompatible version if (hr == FUSION_E_APP_DOMAIN_LOCKED && isTpaListProvided) @@ -710,12 +736,10 @@ namespace BINDER_SPACE #ifndef CROSSGEN_COMPILE /* static */ - HRESULT AssemblyBinder::FindInExecutionContext(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::FindInExecutionContext(ApplicationContext *pApplicationContext, AssemblyName *pAssemblyName, ContextEntry **ppContextEntry) { - HRESULT hr = S_OK; - _ASSERTE(pApplicationContext != NULL); _ASSERTE(pAssemblyName != NULL); _ASSERTE(ppContextEntry != NULL); @@ -784,8 +808,8 @@ namespace BINDER_SPACE } ReleaseHolder pAssembly; - hr = AssemblyBinder::GetAssembly(relativePath, - FALSE /* fIsInGAC */, + hr = AssemblyBinderCommon::GetAssembly(relativePath, + FALSE /* fIsInTPA */, FALSE /* fExplicitBindToNativeImage */, &pAssembly, NULL, // szMDAssemblyPath @@ -834,8 +858,8 @@ namespace BINDER_SPACE SString fileName(wszBindingPath); CombinePath(fileName, relativePath, fileName); - hr = AssemblyBinder::GetAssembly(fileName, - FALSE /* fIsInGAC */, + hr = AssemblyBinderCommon::GetAssembly(fileName, + FALSE /* fIsInTPA */, FALSE /* fExplicitBindToNativeImage */, &pAssembly); BinderTracing::PathProbed(fileName, pathSource, hr); @@ -943,8 +967,8 @@ namespace BINDER_SPACE // Look for a matching dll first PathString fileName(fileNameWithoutExtension); fileName.Append(useNativeImages ? W(".ni.dll") : W(".dll")); - hr = AssemblyBinder::GetAssembly(fileName, - FALSE, // fIsInGAC + hr = AssemblyBinderCommon::GetAssembly(fileName, + FALSE, // fIsInTPA useNativeImages, // fExplicitBindToNativeImage &pAssembly); BinderTracing::PathProbed(fileName, pathSource, hr); @@ -953,8 +977,8 @@ namespace BINDER_SPACE { fileName.Set(fileNameWithoutExtension); fileName.Append(useNativeImages ? W(".ni.exe") : W(".exe")); - hr = AssemblyBinder::GetAssembly(fileName, - FALSE, // fIsInGAC + hr = AssemblyBinderCommon::GetAssembly(fileName, + FALSE, // fIsInTPA useNativeImages, // fExplicitBindToNativeImage &pAssembly); BinderTracing::PathProbed(fileName, pathSource, hr); @@ -1010,7 +1034,7 @@ namespace BINDER_SPACE * */ /* static */ - HRESULT AssemblyBinder::BindByTpaList(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::BindByTpaList(ApplicationContext *pApplicationContext, AssemblyName *pRequestedAssemblyName, bool excludeAppPaths, BindResult *pBindResult) @@ -1052,7 +1076,7 @@ namespace BINDER_SPACE if (bundleFileLocation.IsValid()) { hr = GetAssembly(assemblyFilePath, - TRUE, // fIsInGAC + TRUE, // fIsInTPA FALSE, // fExplicitBindToNativeImage &pTPAAssembly, NULL, // szMDAssemblyPath @@ -1087,7 +1111,7 @@ namespace BINDER_SPACE SString fileName(pTpaEntry->m_wszNIFileName); hr = GetAssembly(fileName, - TRUE, // fIsInGAC + TRUE, // fIsInTPA TRUE, // fExplicitBindToNativeImage &pTPAAssembly); BinderTracing::PathProbed(fileName, BinderTracing::PathSource::ApplicationAssemblies, hr); @@ -1098,7 +1122,7 @@ namespace BINDER_SPACE SString fileName(pTpaEntry->m_wszILFileName); hr = GetAssembly(fileName, - TRUE, // fIsInGAC + TRUE, // fIsInTPA FALSE, // fExplicitBindToNativeImage &pTPAAssembly); BinderTracing::PathProbed(fileName, BinderTracing::PathSource::ApplicationAssemblies, hr); @@ -1192,8 +1216,8 @@ namespace BINDER_SPACE } /* static */ - HRESULT AssemblyBinder::GetAssembly(SString &assemblyPath, - BOOL fIsInGAC, + HRESULT AssemblyBinderCommon::GetAssembly(SString &assemblyPath, + BOOL fIsInTPA, // When binding to the native image, should we // assume assemblyPath explicitly specifies that @@ -1267,7 +1291,7 @@ namespace BINDER_SPACE pPEImage, pNativePEImage, assemblyPath, - fIsInGAC)); + fIsInTPA)); // We're done *ppAssembly = pAssembly.Extract(); @@ -1289,7 +1313,7 @@ namespace BINDER_SPACE #ifndef CROSSGEN_COMPILE /* static */ - HRESULT AssemblyBinder::Register(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::Register(ApplicationContext *pApplicationContext, BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1321,7 +1345,7 @@ namespace BINDER_SPACE } /* static */ - HRESULT AssemblyBinder::RegisterAndGetHostChosen(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::RegisterAndGetHostChosen(ApplicationContext *pApplicationContext, LONG kContextVersion, BindResult *pBindResult, BindResult *pHostBindResult) @@ -1343,7 +1367,7 @@ namespace BINDER_SPACE // Only perform costly validation if other binds succeded before us if (kContextVersion != pApplicationContext->GetVersion()) { - IF_FAIL_GO(AssemblyBinder::OtherBindInterfered(pApplicationContext, + IF_FAIL_GO(AssemblyBinderCommon::OtherBindInterfered(pApplicationContext, pBindResult)); if (hr == S_FALSE) @@ -1369,7 +1393,7 @@ namespace BINDER_SPACE } /* static */ - HRESULT AssemblyBinder::OtherBindInterfered(ApplicationContext *pApplicationContext, + HRESULT AssemblyBinderCommon::OtherBindInterfered(ApplicationContext *pApplicationContext, BindResult *pBindResult) { HRESULT hr = S_FALSE; @@ -1405,30 +1429,30 @@ namespace BINDER_SPACE #endif //CROSSGEN_COMPILE #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -HRESULT AssemblyBinder::BindUsingHostAssemblyResolver(/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, +HRESULT AssemblyBinderCommon::BindUsingHostAssemblyResolver(/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, /* in */ AssemblyName *pAssemblyName, - /* in */ CLRPrivBinderCoreCLR *pTPABinder, + /* in */ DefaultAssemblyBinder *pTPABinder, /* out */ Assembly **ppAssembly) { HRESULT hr = E_FAIL; _ASSERTE(pManagedAssemblyLoadContextToBindWithin != NULL); - // RuntimeInvokeHostAssemblyResolver will perform steps 2-4 of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName. - ICLRPrivAssembly *pLoadedAssembly = NULL; + // RuntimeInvokeHostAssemblyResolver will perform steps 2-4 of CustomAssemblyBinder::BindAssemblyByName. + BINDER_SPACE::Assembly *pLoadedAssembly = NULL; hr = RuntimeInvokeHostAssemblyResolver(pManagedAssemblyLoadContextToBindWithin, pAssemblyName, pTPABinder, &pLoadedAssembly); if (SUCCEEDED(hr)) { _ASSERTE(pLoadedAssembly != NULL); - *ppAssembly = static_cast(pLoadedAssembly); + *ppAssembly = pLoadedAssembly; } return hr; } /* static */ -HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicationContext, +HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder, /* in */ BINDER_SPACE::AssemblyName *pAssemblyName, /* in */ PEImage *pPEImage, /* in */ PEKIND peKind, @@ -1442,9 +1466,10 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicat // Prepare binding data *ppAssembly = NULL; + ApplicationContext* pApplicationContext = pBinder->GetAppContext(); // Tracing happens outside the binder lock to avoid calling into managed code within the lock - BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pApplicationContext->GetBinderID(), 0 /*managedALC*/, hr}; + BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, pBinder, 0 /*managedALC*/, hr}; // Attempt the actual bind (eventually more than once) Retry: @@ -1491,7 +1516,7 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicat // If we cannot get MVID, then err on side of caution and fail the // load. - IF_FAIL_GO(bindResult.GetAsAssembly()->GetMVID(&boundMVID)); + IF_FAIL_GO(bindResult.GetAssembly()->GetMVID(&boundMVID)); mvidMismatch = incomingMVID != boundMVID; if (mvidMismatch) @@ -1532,7 +1557,7 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicat } else if (hr == S_OK) { - *ppAssembly = hostBindResult.GetAsAssembly(TRUE /* fAddRef */); + *ppAssembly = hostBindResult.GetAssembly(TRUE /* fAddRef */); } } @@ -1540,6 +1565,73 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicat tracer.TraceBindResult(bindResult, mvidMismatch); return hr; } + +HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** ppTPABinder) +{ + HRESULT hr = S_OK; + EX_TRY + { + if (ppTPABinder != NULL) + { + NewHolder pBinder; + SAFE_NEW(pBinder, DefaultAssemblyBinder); + + BINDER_SPACE::ApplicationContext* pApplicationContext = pBinder->GetAppContext(); + hr = pApplicationContext->Init(); + if (SUCCEEDED(hr)) + { + pBinder->SetManagedAssemblyLoadContext(NULL); + *ppTPABinder = pBinder.Extract(); + } + } + } + EX_CATCH_HRESULT(hr); + +Exit: + return hr; +} + +HRESULT AssemblyBinderCommon::GetAssemblyIdentity(LPCSTR szTextualIdentity, + BINDER_SPACE::ApplicationContext* pApplicationContext, + NewHolder& assemblyIdentityHolder) +{ + HRESULT hr = S_OK; + _ASSERTE(szTextualIdentity != NULL); + + EX_TRY + { + AssemblyIdentityUTF8 * pAssemblyIdentity = NULL; + if (pApplicationContext != NULL) + { + // This returns a cached copy owned by application context + hr = pApplicationContext->GetAssemblyIdentity(szTextualIdentity, &pAssemblyIdentity); + if (SUCCEEDED(hr)) + { + assemblyIdentityHolder = pAssemblyIdentity; + assemblyIdentityHolder.SuppressRelease(); + } + } + else + { + SString sTextualIdentity; + + sTextualIdentity.SetUTF8(szTextualIdentity); + + // This is a private copy + pAssemblyIdentity = new AssemblyIdentityUTF8(); + hr = TextualIdentityParser::Parse(sTextualIdentity, pAssemblyIdentity); + if (SUCCEEDED(hr)) + { + pAssemblyIdentity->PopulateUTF8Fields(); + assemblyIdentityHolder = pAssemblyIdentity; + } + } + } + EX_CATCH_HRESULT(hr); + + return hr; +} + #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) }; diff --git a/src/coreclr/binder/bindertracing.cpp b/src/coreclr/binder/bindertracing.cpp index 801226e935d00..381b58dfd68a7 100644 --- a/src/coreclr/binder/bindertracing.cpp +++ b/src/coreclr/binder/bindertracing.cpp @@ -111,10 +111,11 @@ namespace #endif // CROSSGEN_COMPILE } - void GetAssemblyLoadContextNameFromBinderID(UINT_PTR binderID, AppDomain *domain, /*out*/ SString &alcName) + void GetAssemblyLoadContextNameFromBindContext(AssemblyBinder *bindContext, AppDomain *domain, /*out*/ SString &alcName) { - ICLRPrivBinder *binder = reinterpret_cast(binderID); - if (AreSameBinderInstance(binder, domain->GetTPABinderContext())) + _ASSERTE(bindContext != nullptr); + + if (bindContext == domain->GetTPABinderContext()) { alcName.Set(W("Default")); } @@ -123,30 +124,19 @@ namespace #ifdef CROSSGEN_COMPILE GetAssemblyLoadContextNameFromManagedALC(0, alcName); #else // CROSSGEN_COMPILE - CLRPrivBinderAssemblyLoadContext *alcBinder = static_cast(binder); + CustomAssemblyBinder* alcBinder = static_cast(bindContext); GetAssemblyLoadContextNameFromManagedALC(alcBinder->GetManagedAssemblyLoadContext(), alcName); #endif // CROSSGEN_COMPILE } } - void GetAssemblyLoadContextNameFromBindContext(ICLRPrivBinder *bindContext, AppDomain *domain, /*out*/ SString &alcName) - { - _ASSERTE(bindContext != nullptr); - - UINT_PTR binderID = 0; - HRESULT hr = bindContext->GetBinderID(&binderID); - _ASSERTE(SUCCEEDED(hr)); - if (SUCCEEDED(hr)) - GetAssemblyLoadContextNameFromBinderID(binderID, domain, alcName); - } - void GetAssemblyLoadContextNameFromSpec(AssemblySpec *spec, /*out*/ SString &alcName) { _ASSERTE(spec != nullptr); AppDomain *domain = spec->GetAppDomain(); - ICLRPrivBinder* bindContext = spec->GetBindingContext(); + AssemblyBinder* bindContext = spec->GetBindingContext(); if (bindContext == nullptr) bindContext = spec->GetBindingContextFromParentAssembly(domain); @@ -172,7 +162,7 @@ namespace peAssembly->GetDisplayName(request.RequestingAssembly); AppDomain *domain = parentAssembly->GetAppDomain(); - ICLRPrivBinder *bindContext = peAssembly->GetBindingContext(); + AssemblyBinder *bindContext = peAssembly->GetBindingContext(); if (bindContext == nullptr) bindContext = domain->GetTPABinderContext(); // System.Private.CoreLib returns null @@ -259,14 +249,14 @@ namespace BinderTracing namespace BinderTracing { - ResolutionAttemptedOperation::ResolutionAttemptedOperation(AssemblyName *assemblyName, UINT_PTR binderID, INT_PTR managedALC, const HRESULT& hr) + ResolutionAttemptedOperation::ResolutionAttemptedOperation(AssemblyName *assemblyName, AssemblyBinder* bindContext, INT_PTR managedALC, const HRESULT& hr) : m_hr { hr } , m_stage { Stage::NotYetStarted } , m_tracingEnabled { BinderTracing::IsEnabled() } , m_assemblyNameObject { assemblyName } , m_pFoundAssembly { nullptr } { - _ASSERTE(binderID != 0 || managedALC != 0); + _ASSERTE(bindContext != nullptr || managedALC != 0); if (!m_tracingEnabled) return; @@ -282,7 +272,7 @@ namespace BinderTracing } else { - GetAssemblyLoadContextNameFromBinderID(binderID, GetAppDomain(), m_assemblyLoadContextName); + GetAssemblyLoadContextNameFromBindContext(bindContext, GetAppDomain(), m_assemblyLoadContextName); } } diff --git a/src/coreclr/binder/coreclrbindercommon.cpp b/src/coreclr/binder/coreclrbindercommon.cpp deleted file mode 100644 index ebe3137c77f14..0000000000000 --- a/src/coreclr/binder/coreclrbindercommon.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - -#include "common.h" -#include "assemblybinder.hpp" -#include "coreclrbindercommon.h" -#include "clrprivbindercoreclr.h" -#include "bundle.h" - -using namespace BINDER_SPACE; - -HRESULT CCoreCLRBinderHelper::DefaultBinderSetupContext(DWORD dwAppDomainId,CLRPrivBinderCoreCLR **ppTPABinder) -{ - HRESULT hr = S_OK; - EX_TRY - { - if(ppTPABinder != NULL) - { - ReleaseHolder pBinder; - SAFE_NEW(pBinder, CLRPrivBinderCoreCLR); - - BINDER_SPACE::ApplicationContext *pApplicationContext = pBinder->GetAppContext(); - UINT_PTR binderId; - pBinder->GetBinderID(&binderId); - hr = pApplicationContext->Init(binderId); - if(SUCCEEDED(hr)) - { - pApplicationContext->SetAppDomainId(dwAppDomainId); - pBinder->SetManagedAssemblyLoadContext(NULL); - *ppTPABinder = clr::SafeAddRef(pBinder.Extract()); - } - } - } - EX_CATCH_HRESULT(hr); - -Exit: - return hr; -} - -HRESULT CCoreCLRBinderHelper::GetAssemblyIdentity(LPCSTR szTextualIdentity, - BINDER_SPACE::ApplicationContext *pApplicationContext, - NewHolder &assemblyIdentityHolder) -{ - HRESULT hr = S_OK; - VALIDATE_ARG_RET(szTextualIdentity != NULL); - - EX_TRY - { - AssemblyIdentityUTF8 *pAssemblyIdentity = NULL; - if (pApplicationContext != NULL) - { - // This returns a cached copy owned by application context - hr = pApplicationContext->GetAssemblyIdentity(szTextualIdentity, &pAssemblyIdentity); - if(SUCCEEDED(hr)) - { - assemblyIdentityHolder = pAssemblyIdentity; - assemblyIdentityHolder.SuppressRelease(); - } - } - else - { - SString sTextualIdentity; - - sTextualIdentity.SetUTF8(szTextualIdentity); - - // This is a private copy - pAssemblyIdentity = new AssemblyIdentityUTF8(); - hr = TextualIdentityParser::Parse(sTextualIdentity, pAssemblyIdentity); - if(SUCCEEDED(hr)) - { - pAssemblyIdentity->PopulateUTF8Fields(); - assemblyIdentityHolder = pAssemblyIdentity; - } - } - } - EX_CATCH_HRESULT(hr); - - return hr; -} - -//============================================================================= -// Functions that provides binding services beyond the ICLRPrivInterface -//----------------------------------------------------------------------------- - -HRESULT CCoreCLRBinderHelper::BindToSystem(ICLRPrivAssembly **ppSystemAssembly, bool fBindToNativeImage) -{ - HRESULT hr = S_OK; - VALIDATE_ARG_RET(ppSystemAssembly != NULL); - - EX_TRY - { - ReleaseHolder pAsm; - StackSString systemPath(SystemDomain::System()->SystemDirectory()); - hr = AssemblyBinder::BindToSystem(systemPath, &pAsm, fBindToNativeImage); - if(SUCCEEDED(hr)) - { - _ASSERTE(pAsm != NULL); - *ppSystemAssembly = pAsm.Extract(); - } - } - EX_CATCH_HRESULT(hr); - - return hr; -} - -HRESULT CCoreCLRBinderHelper::BindToSystemSatellite(SString &systemPath, - SString &sSimpleName, - SString &sCultureName, - ICLRPrivAssembly **ppSystemAssembly) -{ - HRESULT hr = S_OK; - VALIDATE_ARG_RET(ppSystemAssembly != NULL && !systemPath.IsEmpty()); - - EX_TRY - { - ReleaseHolder pAsm; - hr = AssemblyBinder::BindToSystemSatellite(systemPath, sSimpleName, sCultureName, &pAsm); - if(SUCCEEDED(hr)) - { - _ASSERTE(pAsm != NULL); - *ppSystemAssembly = pAsm.Extract(); - } - } - EX_CATCH_HRESULT(hr); - - return hr; -} diff --git a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp b/src/coreclr/binder/customassemblybinder.cpp similarity index 76% rename from src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp rename to src/coreclr/binder/customassemblybinder.cpp index 92d83d75b111a..e9d13192bead9 100644 --- a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp +++ b/src/coreclr/binder/customassemblybinder.cpp @@ -2,18 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. #include "common.h" -#include "assemblybinder.hpp" -#include "clrprivbindercoreclr.h" -#include "clrprivbinderassemblyloadcontext.h" +#include "assemblybindercommon.hpp" +#include "defaultassemblybinder.h" +#include "customassemblybinder.h" #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) using namespace BINDER_SPACE; // ============================================================================ -// CLRPrivBinderAssemblyLoadContext implementation +// CustomAssemblyBinder implementation // ============================================================================ -HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, +HRESULT CustomAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly) { VALIDATE_ARG_RET(pAssemblyName != nullptr && ppCoreCLRFoundAssembly != nullptr); @@ -25,7 +25,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE: #endif // Do we have the assembly already loaded in the context of the current binder? - hr = AssemblyBinder::BindAssembly(&m_appContext, + hr = AssemblyBinderCommon::BindAssembly(this, pAssemblyName, NULL, NULL, @@ -42,20 +42,9 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE: return hr; } -HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, - ICLRPrivAssembly **ppAssembly) +HRESULT CustomAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, + BINDER_SPACE::Assembly** ppAssembly) { - HRESULT hr = S_OK; - VALIDATE_ARG_RET(pAssemblyNameData != nullptr && ppAssembly != nullptr); - - _ASSERTE(m_pTPABinder != NULL); - - ReleaseHolder pCoreCLRFoundAssembly; - ReleaseHolder pAssemblyName; - - SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(*pAssemblyNameData)); - // When LoadContext needs to resolve an assembly reference, it will go through the following lookup order: // // 1) Lookup the assembly within the LoadContext itself. If assembly is found, use it. @@ -68,6 +57,9 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(AssemblyNameData *p // This approach enables a LoadContext to override assemblies that have been loaded in TPA context by loading // a different (or even the same!) version. + HRESULT hr = S_OK; + ReleaseHolder pCoreCLRFoundAssembly; + { // Step 1 - Try to find the assembly within the LoadContext. hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly); @@ -84,7 +76,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(AssemblyNameData *p // of what to do next. The host-overridden binder can either fail the bind or return reference to an existing assembly // that has been loaded. // - hr = AssemblyBinder::BindUsingHostAssemblyResolver(GetManagedAssemblyLoadContext(), pAssemblyName, m_pTPABinder, &pCoreCLRFoundAssembly); + hr = AssemblyBinderCommon::BindUsingHostAssemblyResolver(GetManagedAssemblyLoadContext(), pAssemblyName, m_pTPABinder, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { // We maybe returned an assembly that was bound to a different AssemblyLoadContext instance. @@ -112,9 +104,9 @@ Exit:; return hr; } -HRESULT CLRPrivBinderAssemblyLoadContext::BindUsingPEImage( /* in */ PEImage *pPEImage, +HRESULT CustomAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage, /* in */ BOOL fIsNativeImage, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly) + /* [retval][out] */ BINDER_SPACE::Assembly **ppAssembly) { HRESULT hr = S_OK; @@ -129,12 +121,12 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindUsingPEImage( /* in */ PEImage *pP // Get the Metadata interface DWORD dwPAFlags[2]; IF_FAIL_GO(BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags, fIsNativeImage)); - IF_FAIL_GO(AssemblyBinder::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); + IF_FAIL_GO(AssemblyBinderCommon::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); _ASSERTE(pIMetaDataAssemblyImport != NULL); // Using the information we just got, initialize the assemblyname - SAFE_NEW(pAssemblyName, AssemblyName); + SAFE_NEW(pAssemblyName, BINDER_SPACE::AssemblyName); IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind)); // Validate architecture @@ -150,7 +142,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindUsingPEImage( /* in */ PEImage *pP IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); } - hr = AssemblyBinder::BindUsingPEImage(&m_appContext, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); + hr = AssemblyBinderCommon::BindUsingPEImage(this, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); if (hr == S_OK) { _ASSERTE(pCoreCLRFoundAssembly != NULL); @@ -164,16 +156,9 @@ Exit:; return hr; } -HRESULT CLRPrivBinderAssemblyLoadContext::GetLoaderAllocator(LPVOID* pLoaderAllocator) +AssemblyLoaderAllocator* CustomAssemblyBinder::GetLoaderAllocator() { - _ASSERTE(pLoaderAllocator != NULL); - if (m_pAssemblyLoaderAllocator == NULL) - { - return E_FAIL; - } - - *pLoaderAllocator = m_pAssemblyLoaderAllocator; - return S_OK; + return m_pAssemblyLoaderAllocator; } //============================================================================= @@ -183,29 +168,23 @@ HRESULT CLRPrivBinderAssemblyLoadContext::GetLoaderAllocator(LPVOID* pLoaderAllo // managed AssemblyLoadContext type. //============================================================================= /* static */ -HRESULT CLRPrivBinderAssemblyLoadContext::SetupContext(DWORD dwAppDomainId, - CLRPrivBinderCoreCLR *pTPABinder, - LoaderAllocator* pLoaderAllocator, - void* loaderAllocatorHandle, - UINT_PTR ptrAssemblyLoadContext, - CLRPrivBinderAssemblyLoadContext **ppBindContext) +HRESULT CustomAssemblyBinder::SetupContext(DefaultAssemblyBinder *pTPABinder, + AssemblyLoaderAllocator* pLoaderAllocator, + void* loaderAllocatorHandle, + UINT_PTR ptrAssemblyLoadContext, + CustomAssemblyBinder **ppBindContext) { HRESULT hr = E_FAIL; EX_TRY { if(ppBindContext != NULL) { - ReleaseHolder pBinder; + NewHolder pBinder; - SAFE_NEW(pBinder, CLRPrivBinderAssemblyLoadContext); - UINT_PTR binderId; - pBinder->GetBinderID(&binderId); - hr = pBinder->m_appContext.Init(binderId); + SAFE_NEW(pBinder, CustomAssemblyBinder); + hr = pBinder->GetAppContext()->Init(); if(SUCCEEDED(hr)) { - // Save the reference to the AppDomain in which the binder lives - pBinder->m_appContext.SetAppDomainId(dwAppDomainId); - // Save reference to the TPABinder that is required to be present. _ASSERTE(pTPABinder != NULL); pBinder->m_pTPABinder = pTPABinder; @@ -229,7 +208,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::SetupContext(DWORD dwAppDomainId, } #endif // Return reference to the allocated Binder instance - *ppBindContext = clr::SafeAddRef(pBinder.Extract()); + *ppBindContext = pBinder.Extract(); } } } @@ -239,7 +218,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::SetupContext(DWORD dwAppDomainId, return hr; } -void CLRPrivBinderAssemblyLoadContext::PrepareForLoadContextRelease(INT_PTR ptrManagedStrongAssemblyLoadContext) +void CustomAssemblyBinder::PrepareForLoadContextRelease(INT_PTR ptrManagedStrongAssemblyLoadContext) { CONTRACTL { @@ -250,7 +229,7 @@ void CLRPrivBinderAssemblyLoadContext::PrepareForLoadContextRelease(INT_PTR ptrM CONTRACTL_END; // Add a strong handle so that the managed assembly load context stays alive until the - // CLRPrivBinderAssemblyLoadContext::ReleaseLoadContext is called. + // CustomAssemblyBinder::ReleaseLoadContext is called. // We keep the weak handle as well since this method can be running on one thread (e.g. the finalizer one) // and other thread can be using the weak handle. m_ptrManagedStrongAssemblyLoadContext = ptrManagedStrongAssemblyLoadContext; @@ -269,13 +248,13 @@ void CLRPrivBinderAssemblyLoadContext::PrepareForLoadContextRelease(INT_PTR ptrM m_loaderAllocatorHandle = NULL; } -CLRPrivBinderAssemblyLoadContext::CLRPrivBinderAssemblyLoadContext() +CustomAssemblyBinder::CustomAssemblyBinder() { m_pTPABinder = NULL; m_ptrManagedStrongAssemblyLoadContext = NULL; } -void CLRPrivBinderAssemblyLoadContext::ReleaseLoadContext() +void CustomAssemblyBinder::ReleaseLoadContext() { VERIFY(m_ptrManagedAssemblyLoadContext != NULL); VERIFY(m_ptrManagedStrongAssemblyLoadContext != NULL); diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/defaultassemblybinder.cpp similarity index 80% rename from src/coreclr/binder/clrprivbindercoreclr.cpp rename to src/coreclr/binder/defaultassemblybinder.cpp index fec66a7545880..8a2f819e1b17c 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/defaultassemblybinder.cpp @@ -2,8 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. #include "common.h" -#include "assemblybinder.hpp" -#include "clrprivbindercoreclr.h" +#include "assemblybindercommon.hpp" +#include "defaultassemblybinder.h" using namespace BINDER_SPACE; @@ -11,7 +11,7 @@ using namespace BINDER_SPACE; // Helper functions //----------------------------------------------------------------------------- -HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, +HRESULT DefaultAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly, bool excludeAppPaths) { @@ -23,7 +23,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam _ASSERTE(!pAssemblyName->IsCoreLib()); #endif - hr = AssemblyBinder::BindAssembly(&m_appContext, + hr = AssemblyBinderCommon::BindAssembly(this, pAssemblyName, NULL, NULL, @@ -40,28 +40,10 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam } // ============================================================================ -// CLRPrivBinderCoreCLR implementation +// DefaultAssemblyBinder implementation // ============================================================================ -HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, - ICLRPrivAssembly **ppAssembly) -{ - HRESULT hr = S_OK; - VALIDATE_ARG_RET(pAssemblyNameData != nullptr && ppAssembly != nullptr); - - *ppAssembly = nullptr; - - ReleaseHolder pAssemblyName; - SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(*pAssemblyNameData)); - - hr = BindUsingAssemblyName(pAssemblyName, ppAssembly); - -Exit: - return hr; -} - -HRESULT CLRPrivBinderCoreCLR::BindUsingAssemblyName(BINDER_SPACE::AssemblyName *pAssemblyName, - ICLRPrivAssembly **ppAssembly) +HRESULT DefaultAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName *pAssemblyName, + BINDER_SPACE::Assembly **ppAssembly) { HRESULT hr = S_OK; VALIDATE_ARG_RET(pAssemblyName != nullptr && ppAssembly != nullptr); @@ -106,7 +88,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingAssemblyName(BINDER_SPACE::AssemblyName * if (pManagedAssemblyLoadContext != NULL) { - hr = AssemblyBinder::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, + hr = AssemblyBinderCommon::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, NULL, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { @@ -132,9 +114,9 @@ Exit:; } #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage, +HRESULT DefaultAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage, /* in */ BOOL fIsNativeImage, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly) + /* [retval][out] */ BINDER_SPACE::Assembly **ppAssembly) { HRESULT hr = S_OK; @@ -149,7 +131,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage, // Get the Metadata interface DWORD dwPAFlags[2]; IF_FAIL_GO(BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags, fIsNativeImage)); - IF_FAIL_GO(AssemblyBinder::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); + IF_FAIL_GO(AssemblyBinderCommon::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); _ASSERTE(pIMetaDataAssemblyImport != NULL); @@ -181,7 +163,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage, hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, true /* excludeAppPaths */); if (SUCCEEDED(hr)) { - if (pCoreCLRFoundAssembly->GetIsInGAC()) + if (pCoreCLRFoundAssembly->GetIsInTPA()) { *ppAssembly = pCoreCLRFoundAssembly.Extract(); goto Exit; @@ -190,7 +172,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage, } } - hr = AssemblyBinder::BindUsingPEImage(&m_appContext, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); + hr = AssemblyBinderCommon::BindUsingPEImage(this, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); if (hr == S_OK) { _ASSERTE(pCoreCLRFoundAssembly != NULL); @@ -205,7 +187,7 @@ Exit:; } #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -HRESULT CLRPrivBinderCoreCLR::SetupBindingPaths(SString &sTrustedPlatformAssemblies, +HRESULT DefaultAssemblyBinder::SetupBindingPaths(SString &sTrustedPlatformAssemblies, SString &sPlatformResourceRoots, SString &sAppPaths, SString &sAppNiPaths) @@ -214,20 +196,20 @@ HRESULT CLRPrivBinderCoreCLR::SetupBindingPaths(SString &sTrustedPlatformAssemb EX_TRY { - hr = m_appContext.SetupBindingPaths(sTrustedPlatformAssemblies, sPlatformResourceRoots, sAppPaths, sAppNiPaths, TRUE /* fAcquireLock */); + hr = GetAppContext()->SetupBindingPaths(sTrustedPlatformAssemblies, sPlatformResourceRoots, sAppPaths, sAppNiPaths, TRUE /* fAcquireLock */); } EX_CATCH_HRESULT(hr); return hr; } -// See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind +// See code:BINDER_SPACE::AssemblyBinderCommon::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. -HRESULT CLRPrivBinderCoreCLR::Bind(LPCWSTR wszCodeBase, +HRESULT DefaultAssemblyBinder::Bind(LPCWSTR wszCodeBase, PEAssembly *pParentAssembly, BOOL fNgenExplicitBind, BOOL fExplicitBindToNativeImage, - ICLRPrivAssembly **ppAssembly) + BINDER_SPACE::Assembly **ppAssembly) { HRESULT hr = S_OK; VALIDATE_ARG_RET(wszCodeBase != NULL && ppAssembly != NULL); @@ -235,7 +217,7 @@ HRESULT CLRPrivBinderCoreCLR::Bind(LPCWSTR wszCodeBase, EX_TRY { ReleaseHolder pAsm; - hr = AssemblyBinder::BindAssembly(&m_appContext, + hr = AssemblyBinderCommon::BindAssembly(this, NULL, wszCodeBase, pParentAssembly, @@ -254,9 +236,3 @@ HRESULT CLRPrivBinderCoreCLR::Bind(LPCWSTR wszCodeBase, return hr; } - -HRESULT CLRPrivBinderCoreCLR::GetLoaderAllocator(LPVOID* pLoaderAllocator) -{ - // Not supported by this binder - return E_FAIL; -} diff --git a/src/coreclr/binder/inc/applicationcontext.hpp b/src/coreclr/binder/inc/applicationcontext.hpp index 7bb3b36444163..a1471bbe9e853 100644 --- a/src/coreclr/binder/inc/applicationcontext.hpp +++ b/src/coreclr/binder/inc/applicationcontext.hpp @@ -80,23 +80,14 @@ namespace BINDER_SPACE typedef SHash SimpleNameToFileNameMap; class ApplicationContext - : public IUnknown { public: - // IUnknown methods - STDMETHOD(QueryInterface)(REFIID riid, - void **ppv); - STDMETHOD_(ULONG, AddRef)(); - STDMETHOD_(ULONG, Release)(); - // ApplicationContext methods ApplicationContext(); - virtual ~ApplicationContext(); - HRESULT Init(UINT_PTR binderID); + ~ApplicationContext(); + HRESULT Init(); inline SString &GetApplicationName(); - inline DWORD GetAppDomainId(); - inline void SetAppDomainId(DWORD dwAppDomainId); HRESULT SetupBindingPaths(/* in */ SString &sTrustedPlatformAssemblies, /* in */ SString &sPlatformResourceRoots, @@ -123,13 +114,9 @@ namespace BINDER_SPACE inline LONG GetVersion(); inline void IncrementVersion(); - UINT_PTR GetBinderID() { return m_binderID; } - - protected: - LONG m_cRef; + private: Volatile m_cVersion; SString m_applicationName; - DWORD m_dwAppDomainId; ExecutionContext *m_pExecutionContext; FailureCache *m_pFailureCache; CRITSEC_COOKIE m_contextCS; @@ -141,8 +128,6 @@ namespace BINDER_SPACE StringArrayList m_appNiPaths; SimpleNameToFileNameMap * m_pTrustedPlatformAssemblyMap; - - UINT_PTR m_binderID; }; #include "applicationcontext.inl" diff --git a/src/coreclr/binder/inc/applicationcontext.inl b/src/coreclr/binder/inc/applicationcontext.inl index 4d006d5be6bcb..3a892b87540d5 100644 --- a/src/coreclr/binder/inc/applicationcontext.inl +++ b/src/coreclr/binder/inc/applicationcontext.inl @@ -29,16 +29,6 @@ SString &ApplicationContext::GetApplicationName() return m_applicationName; } -DWORD ApplicationContext::GetAppDomainId() -{ - return m_dwAppDomainId; -} - -void ApplicationContext::SetAppDomainId(DWORD dwAppDomainId) -{ - m_dwAppDomainId = dwAppDomainId; -} - ExecutionContext *ApplicationContext::GetExecutionContext() { return m_pExecutionContext; diff --git a/src/coreclr/binder/inc/assembly.hpp b/src/coreclr/binder/inc/assembly.hpp index 5f5efb6a25c4f..34679a29b53b6 100644 --- a/src/coreclr/binder/inc/assembly.hpp +++ b/src/coreclr/binder/inc/assembly.hpp @@ -18,12 +18,11 @@ #include "assemblyname.hpp" #include "corpriv.h" -#include "clrprivbinding.h" -#include "clrprivbindercoreclr.h" +#include "defaultassemblybinder.h" #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -#include "clrprivbinderassemblyloadcontext.h" +#include "customassemblybinder.h" #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) #include "bundle.h" @@ -55,31 +54,13 @@ namespace BINDER_SPACE // // This allows us to preferentially use the NGEN image if it is available. class Assembly - : public ICLRPrivAssembly { public: - // -------------------------------------------------------------------- - // IUnknown methods - // -------------------------------------------------------------------- - STDMETHOD(QueryInterface)(REFIID riid, - void ** ppv); - STDMETHOD_(ULONG, AddRef)(); - STDMETHOD_(ULONG, Release)(); + ULONG AddRef(); + ULONG Release(); - // -------------------------------------------------------------------- - // ICLRPrivAssembly methods - // -------------------------------------------------------------------- LPCWSTR GetSimpleName(); - - STDMETHOD(BindAssemblyByName)( - /* [in] */ AssemblyNameData *pAssemblyNameData, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); - - STDMETHOD(GetAvailableImageTypes)(PDWORD pdwImageTypes); - - STDMETHOD(GetBinderID)(UINT_PTR *pBinderId); - - STDMETHOD(GetLoaderAllocator)(LPVOID* pLoaderAllocator); + AssemblyLoaderAllocator* GetLoaderAllocator(); // -------------------------------------------------------------------- // Assembly methods @@ -92,10 +73,10 @@ namespace BINDER_SPACE /* in */ PEImage *pPEImage, /* in */ PEImage *pPENativeImage, /* in */ SString &assemblyPath, - /* in */ BOOL fIsInGAC); + /* in */ BOOL fIsInTPA); inline AssemblyName *GetAssemblyName(BOOL fAddRef = FALSE); - inline BOOL GetIsInGAC(); + inline BOOL GetIsInTPA(); inline SString &GetPath(); @@ -108,19 +89,17 @@ namespace BINDER_SPACE static PEKIND GetSystemArchitecture(); static BOOL IsValidArchitecture(PEKIND kArchitecture); - inline ICLRPrivBinder* GetBinder() + inline AssemblyBinder* GetBinder() { return m_pBinder; } -#ifndef CROSSGEN_COMPILE - protected: -#endif + private: // Assembly Flags enum { FLAG_NONE = 0x00, - FLAG_IS_IN_GAC = 0x02, + FLAG_IS_IN_TPA = 0x02, //FLAG_IS_DYNAMIC_BIND = 0x04, FLAG_IS_BYTE_ARRAY = 0x08, }; @@ -130,7 +109,7 @@ namespace BINDER_SPACE inline void SetAssemblyName(AssemblyName *pAssemblyName, BOOL fAddRef = TRUE); - inline void SetIsInGAC(BOOL fIsInGAC); + inline void SetIsInTPA(BOOL fIsInTPA); inline IMDInternalImport *GetMDImport(); inline void SetMDImport(IMDInternalImport *pMDImport); @@ -142,25 +121,21 @@ namespace BINDER_SPACE AssemblyName *m_pAssemblyName; SString m_assemblyPath; DWORD m_dwAssemblyFlags; - ICLRPrivBinder *m_pBinder; + AssemblyBinder *m_pBinder; - inline void SetBinder(ICLRPrivBinder *pBinder) + inline void SetBinder(AssemblyBinder *pBinder) { _ASSERTE(m_pBinder == NULL || m_pBinder == pBinder); m_pBinder = pBinder; } - friend class ::CLRPrivBinderCoreCLR; + friend class ::DefaultAssemblyBinder; #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - friend class ::CLRPrivBinderAssemblyLoadContext; + friend class ::CustomAssemblyBinder; #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) }; - // This is a fast version which goes around the COM interfaces and directly - // casts the interfaces and does't AddRef - inline BINDER_SPACE::Assembly * GetAssemblyFromPrivAssemblyFast(ICLRPrivAssembly *pPrivAssembly); - #include "assembly.inl" }; diff --git a/src/coreclr/binder/inc/assembly.inl b/src/coreclr/binder/inc/assembly.inl index ca0aa232e9063..c429241345b46 100644 --- a/src/coreclr/binder/inc/assembly.inl +++ b/src/coreclr/binder/inc/assembly.inl @@ -14,6 +14,23 @@ #ifndef __BINDER__ASSEMBLY_INL__ #define __BINDER__ASSEMBLY_INL__ +inline ULONG Assembly::AddRef() +{ + return InterlockedIncrement(&m_cRef); +} + +inline ULONG Assembly::Release() +{ + ULONG ulRef = InterlockedDecrement(&m_cRef); + + if (ulRef == 0) + { + delete this; + } + + return ulRef; +} + PEImage *Assembly::GetPEImage(BOOL fAddRef /* = FALSE */) { PEImage *pPEImage = m_pPEImage; @@ -82,20 +99,20 @@ void Assembly::SetAssemblyName(AssemblyName *pAssemblyName, } } -BOOL Assembly::GetIsInGAC() +BOOL Assembly::GetIsInTPA() { - return ((m_dwAssemblyFlags & FLAG_IS_IN_GAC) != 0); + return ((m_dwAssemblyFlags & FLAG_IS_IN_TPA) != 0); } -void Assembly::SetIsInGAC(BOOL fIsInGAC) +void Assembly::SetIsInTPA(BOOL fIsInTPA) { - if (fIsInGAC) + if (fIsInTPA) { - m_dwAssemblyFlags |= FLAG_IS_IN_GAC; + m_dwAssemblyFlags |= FLAG_IS_IN_TPA; } else { - m_dwAssemblyFlags &= ~FLAG_IS_IN_GAC; + m_dwAssemblyFlags &= ~FLAG_IS_IN_TPA; } } @@ -117,18 +134,4 @@ void Assembly::SetMDImport(IMDInternalImport *pMDImport) m_pMDImport->AddRef(); } -BINDER_SPACE::Assembly* GetAssemblyFromPrivAssemblyFast(ICLRPrivAssembly *pPrivAssembly) -{ -#ifdef _DEBUG - if(pPrivAssembly != nullptr) - { - // Ensure the pPrivAssembly we are about to cast is indeed a valid Assembly - DWORD dwImageType = 0; - pPrivAssembly->GetAvailableImageTypes(&dwImageType); - _ASSERTE((dwImageType & ASSEMBLY_IMAGE_TYPE_ASSEMBLY) == ASSEMBLY_IMAGE_TYPE_ASSEMBLY); - } -#endif - return (BINDER_SPACE::Assembly *)pPrivAssembly; -} - #endif diff --git a/src/coreclr/binder/inc/assemblybinder.hpp b/src/coreclr/binder/inc/assemblybindercommon.hpp similarity index 81% rename from src/coreclr/binder/inc/assemblybinder.hpp rename to src/coreclr/binder/inc/assemblybindercommon.hpp index 2ba11b7ac0183..e60de9712c507 100644 --- a/src/coreclr/binder/inc/assemblybinder.hpp +++ b/src/coreclr/binder/inc/assemblybindercommon.hpp @@ -11,26 +11,29 @@ // // ============================================================ -#ifndef __BINDER__ASSEMBLY_BINDER_HPP__ -#define __BINDER__ASSEMBLY_BINDER_HPP__ +#ifndef __BINDER__ASSEMBLY_BINDER_COMMON_HPP__ +#define __BINDER__ASSEMBLY_BINDER_COMMON_HPP__ #include "bindertypes.hpp" #include "bindresult.hpp" #include "bundle.h" -class CLRPrivBinderCoreCLR; +class AssemblyBinder; +class DefaultAssemblyBinder; class PEAssembly; class PEImage; namespace BINDER_SPACE { - class AssemblyBinder + class AssemblyIdentityUTF8; + + class AssemblyBinderCommon { public: - // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind + // See code:BINDER_SPACE::AssemblyBinderCommon::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. - static HRESULT BindAssembly(/* in */ ApplicationContext *pApplicationContext, + static HRESULT BindAssembly(/* in */ AssemblyBinder *pBinder, /* in */ AssemblyName *pAssemblyName, /* in */ LPCWSTR szCodeBase, /* in */ PEAssembly *pParentAssembly, @@ -39,6 +42,8 @@ namespace BINDER_SPACE /* in */ bool excludeAppPaths, /* out */ Assembly **ppAssembly); + static HRESULT BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly, bool fBindToNativeImage); + static HRESULT BindToSystem(/* in */ SString &systemDirectory, /* out */ Assembly **ppSystemAssembly, /* in */ bool fBindToNativeImage); @@ -49,7 +54,7 @@ namespace BINDER_SPACE /* out */ Assembly **ppSystemAssembly); static HRESULT GetAssembly(/* in */ SString &assemblyPath, - /* in */ BOOL fIsInGAC, + /* in */ BOOL fIsInTPA, /* in */ BOOL fExplicitBindToNativeImage, /* out */ Assembly **ppAssembly, /* in */ LPCTSTR szMDAssemblyPath = NULL, @@ -58,10 +63,10 @@ namespace BINDER_SPACE #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, /* in */ AssemblyName *pAssemblyName, - /* in */ CLRPrivBinderCoreCLR *pTPABinder, + /* in */ DefaultAssemblyBinder *pTPABinder, /* out */ Assembly **ppAssembly); - static HRESULT BindUsingPEImage(/* in */ ApplicationContext *pApplicationContext, + static HRESULT BindUsingPEImage(/* in */ AssemblyBinder *pBinder, /* in */ BINDER_SPACE::AssemblyName *pAssemblyName, /* in */ PEImage *pPEImage, /* in */ PEKIND peKind, @@ -71,6 +76,15 @@ namespace BINDER_SPACE static HRESULT TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind); + static HRESULT DefaultBinderSetupContext(DefaultAssemblyBinder** ppTPABinder); + + // TODO: The call indicates that this can come from a case where + // pDomain->GetFusionContext() is null, hence this is static function + // which handles a null binder. See if this actually happens + static HRESULT GetAssemblyIdentity(LPCSTR szTextualIdentity, + BINDER_SPACE::ApplicationContext* pApplicationContext, + NewHolder& assemblyIdentityHolder); + private: static HRESULT BindByName(/* in */ ApplicationContext *pApplicationContext, /* in */ AssemblyName *pAssemblyName, @@ -79,7 +93,7 @@ namespace BINDER_SPACE /* in */ bool excludeAppPaths, /* out */ BindResult *pBindResult); - // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind + // See code:BINDER_SPACE::AssemblyBinderCommon::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. static HRESULT BindWhereRef(/* in */ ApplicationContext *pApplicationContext, diff --git a/src/coreclr/binder/inc/bindertracing.h b/src/coreclr/binder/inc/bindertracing.h index 5d82888158a39..a677edbfad4f5 100644 --- a/src/coreclr/binder/inc/bindertracing.h +++ b/src/coreclr/binder/inc/bindertracing.h @@ -93,8 +93,8 @@ namespace BinderTracing static void TraceAppDomainAssemblyResolve(AssemblySpec *spec, PEAssembly *resultAssembly, Exception *exception = nullptr); public: - // One of binder ID and managed ALC is expected to be non-zero. If the managed ALC is set, binder ID is ignored. - ResolutionAttemptedOperation(BINDER_SPACE::AssemblyName *assemblyName, UINT_PTR binderId, INT_PTR managedALC, const HRESULT& hr); + // One of native bindContext or managedALC is expected to be non-zero. If the managed ALC is set, bindContext is ignored. + ResolutionAttemptedOperation(BINDER_SPACE::AssemblyName *assemblyName, AssemblyBinder* bindContext, INT_PTR managedALC, const HRESULT& hr); void TraceBindResult(const BINDER_SPACE::BindResult &bindResult, bool mvidMismatch = false); diff --git a/src/coreclr/binder/inc/bindresult.hpp b/src/coreclr/binder/inc/bindresult.hpp index b305c525c3b36..9a772b43c7db6 100644 --- a/src/coreclr/binder/inc/bindresult.hpp +++ b/src/coreclr/binder/inc/bindresult.hpp @@ -25,11 +25,10 @@ namespace BINDER_SPACE inline ~BindResult(); inline AssemblyName *GetAssemblyName(BOOL fAddRef = FALSE); - inline IUnknown *GetAssembly(BOOL fAddRef = FALSE); - inline Assembly *GetAsAssembly(BOOL fAddRef = FALSE); + inline Assembly *GetAssembly(BOOL fAddRef = FALSE); - inline BOOL GetIsInGAC(); - inline void SetIsInGAC(BOOL fIsInGAC); + inline BOOL GetIsInTPA(); + inline void SetIsInTPA(BOOL fIsInTPA); inline BOOL GetIsContextBound(); inline void SetIsContextBound(BOOL fIsContextBound); inline BOOL GetIsFirstRequest(); @@ -70,7 +69,7 @@ namespace BINDER_SPACE protected: DWORD m_dwResultFlags; AssemblyName *m_pAssemblyName; - ReleaseHolder m_pIUnknownAssembly; + ReleaseHolder m_pAssembly; AttemptResult m_inContextAttempt; AttemptResult m_applicationAssembliesAttempt; diff --git a/src/coreclr/binder/inc/bindresult.inl b/src/coreclr/binder/inc/bindresult.inl index 183c7807a489c..5a4c229316af5 100644 --- a/src/coreclr/binder/inc/bindresult.inl +++ b/src/coreclr/binder/inc/bindresult.inl @@ -23,7 +23,7 @@ BindResult::BindResult() { m_dwResultFlags = ContextEntry::RESULT_FLAG_NONE; m_pAssemblyName = NULL; - m_pIUnknownAssembly = NULL; + m_pAssembly = NULL; } BindResult::~BindResult() @@ -43,37 +43,32 @@ AssemblyName *BindResult::GetAssemblyName(BOOL fAddRef /* = FALSE */) return pAssemblyName; } -IUnknown *BindResult::GetAssembly(BOOL fAddRef /* = FALSE */) +Assembly *BindResult::GetAssembly(BOOL fAddRef /* = FALSE */) { - IUnknown *pIUnknownAssembly = m_pIUnknownAssembly; + Assembly* pAssembly = m_pAssembly; - if (fAddRef && (pIUnknownAssembly != NULL)) + if (fAddRef && (pAssembly != NULL)) { - pIUnknownAssembly->AddRef(); + pAssembly->AddRef(); } - return pIUnknownAssembly; -} - -Assembly *BindResult::GetAsAssembly(BOOL fAddRef /* = FALSE */) -{ - return static_cast(GetAssembly(fAddRef)); + return pAssembly; } -BOOL BindResult::GetIsInGAC() +BOOL BindResult::GetIsInTPA() { - return ((m_dwResultFlags & ContextEntry::RESULT_FLAG_IS_IN_GAC) != 0); + return ((m_dwResultFlags & ContextEntry::RESULT_FLAG_IS_IN_TPA) != 0); } -void BindResult::SetIsInGAC(BOOL fIsInGAC) +void BindResult::SetIsInTPA(BOOL fIsInTPA) { - if (fIsInGAC) + if (fIsInTPA) { - m_dwResultFlags |= ContextEntry::RESULT_FLAG_IS_IN_GAC; + m_dwResultFlags |= ContextEntry::RESULT_FLAG_IS_IN_TPA; } else { - m_dwResultFlags &= ~ContextEntry::RESULT_FLAG_IS_IN_GAC; + m_dwResultFlags &= ~ContextEntry::RESULT_FLAG_IS_IN_TPA; } } @@ -115,22 +110,22 @@ void BindResult::SetResult(ContextEntry *pContextEntry, BOOL fIsContextBound /* { _ASSERTE(pContextEntry != NULL); - SetIsInGAC(pContextEntry->GetIsInGAC()); + SetIsInTPA(pContextEntry->GetIsInTPA()); SetIsContextBound(fIsContextBound); SAFE_RELEASE(m_pAssemblyName); m_pAssemblyName = pContextEntry->GetAssemblyName(TRUE /* fAddRef */); - m_pIUnknownAssembly = pContextEntry->GetAssembly(TRUE /* fAddRef */); + m_pAssembly = pContextEntry->GetAssembly(TRUE /* fAddRef */); } void BindResult::SetResult(Assembly *pAssembly) { _ASSERTE(pAssembly != NULL); - SetIsInGAC(pAssembly->GetIsInGAC()); + SetIsInTPA(pAssembly->GetIsInTPA()); SAFE_RELEASE(m_pAssemblyName); m_pAssemblyName = pAssembly->GetAssemblyName(TRUE /* fAddRef */); pAssembly->AddRef(); - m_pIUnknownAssembly = static_cast(pAssembly); + m_pAssembly = pAssembly; } void BindResult::SetResult(BindResult *pBindResult) @@ -140,7 +135,7 @@ void BindResult::SetResult(BindResult *pBindResult) m_dwResultFlags = pBindResult->m_dwResultFlags; SAFE_RELEASE(m_pAssemblyName); m_pAssemblyName = pBindResult->GetAssemblyName(TRUE /* fAddRef */); - m_pIUnknownAssembly = pBindResult->GetAssembly(TRUE /* fAddRef */); + m_pAssembly = pBindResult->GetAssembly(TRUE /* fAddRef */); const AttemptResult *attempt = pBindResult->GetAttempt(true /*foundInContext*/); if (attempt != nullptr) @@ -164,7 +159,7 @@ BOOL BindResult::HaveResult() void BindResult::Reset() { SAFE_RELEASE(m_pAssemblyName); - m_pIUnknownAssembly = NULL; + m_pAssembly = NULL; m_dwResultFlags = ContextEntry::RESULT_FLAG_NONE; m_inContextAttempt.Reset(); m_applicationAssembliesAttempt.Reset(); @@ -174,7 +169,7 @@ void BindResult::SetAttemptResult(HRESULT hr, ContextEntry *pContextEntry) { Assembly *assembly = nullptr; if (pContextEntry != nullptr) - assembly = static_cast(pContextEntry->GetAssembly(TRUE /* fAddRef */)); + assembly = pContextEntry->GetAssembly(TRUE /* fAddRef */); m_inContextAttempt.Assembly = assembly; m_inContextAttempt.HResult = hr; diff --git a/src/coreclr/binder/inc/clrprivbindercoreclr.h b/src/coreclr/binder/inc/clrprivbindercoreclr.h deleted file mode 100644 index ff47c561d0948..0000000000000 --- a/src/coreclr/binder/inc/clrprivbindercoreclr.h +++ /dev/null @@ -1,67 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - -#ifndef __CLR_PRIV_BINDER_CORECLR_H__ -#define __CLR_PRIV_BINDER_CORECLR_H__ - -#include "applicationcontext.hpp" -#include "assemblyloadcontext.h" - -class PEAssembly; -class PEImage; - -class CLRPrivBinderCoreCLR : public AssemblyLoadContext -{ -public: - - //========================================================================= - // ICLRPrivBinder functions - //------------------------------------------------------------------------- - STDMETHOD(BindAssemblyByName)( - /* [in] */ struct AssemblyNameData *pAssemblyNameData, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); - - STDMETHOD(GetLoaderAllocator)( - /* [retval][out] */ LPVOID *pLoaderAllocator); - -public: - - HRESULT SetupBindingPaths(SString &sTrustedPlatformAssemblies, - SString &sPlatformResourceRoots, - SString &sAppPaths, - SString &sAppNiPaths); - - inline BINDER_SPACE::ApplicationContext *GetAppContext() - { - return &m_appContext; - } - - HRESULT Bind(LPCWSTR wszCodeBase, - PEAssembly *pParentAssembly, - BOOL fNgenExplicitBind, - BOOL fExplicitBindToNativeImage, - ICLRPrivAssembly **ppAssembly); - - HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName *pAssemblyName, - ICLRPrivAssembly **ppAssembly); - -#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - HRESULT BindUsingPEImage( /* in */ PEImage *pPEImage, - /* in */ BOOL fIsNativeImage, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); -#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - - HRESULT BindAssemblyByNameWorker( - BINDER_SPACE::AssemblyName *pAssemblyName, - BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly, - bool excludeAppPaths); - - //========================================================================= - // Internal implementation details - //------------------------------------------------------------------------- -private: - BINDER_SPACE::ApplicationContext m_appContext; -}; - -#endif // __CLR_PRIV_BINDER_CORECLR_H__ diff --git a/src/coreclr/binder/inc/contextentry.hpp b/src/coreclr/binder/inc/contextentry.hpp index ff3c8dba83c77..bfd901b982de5 100644 --- a/src/coreclr/binder/inc/contextentry.hpp +++ b/src/coreclr/binder/inc/contextentry.hpp @@ -26,7 +26,7 @@ namespace BINDER_SPACE { RESULT_FLAG_NONE = 0x00, //RESULT_FLAG_IS_DYNAMIC_BIND = 0x01, - RESULT_FLAG_IS_IN_GAC = 0x02, + RESULT_FLAG_IS_IN_TPA = 0x02, //RESULT_FLAG_FROM_MANIFEST = 0x04, RESULT_FLAG_CONTEXT_BOUND = 0x08, RESULT_FLAG_FIRST_REQUEST = 0x10, @@ -35,28 +35,28 @@ namespace BINDER_SPACE ContextEntry() : AssemblyEntry() { m_dwResultFlags = RESULT_FLAG_NONE; - m_pIUnknownAssembly = NULL; + m_pAssembly = NULL; } ~ContextEntry() { - SAFE_RELEASE(m_pIUnknownAssembly); + SAFE_RELEASE(m_pAssembly); } - BOOL GetIsInGAC() + BOOL GetIsInTPA() { - return ((m_dwResultFlags & RESULT_FLAG_IS_IN_GAC) != 0); + return ((m_dwResultFlags & RESULT_FLAG_IS_IN_TPA) != 0); } - void SetIsInGAC(BOOL fIsInGAC) + void SetIsInTPA(BOOL fIsInTPA) { - if (fIsInGAC) + if (fIsInTPA) { - m_dwResultFlags |= RESULT_FLAG_IS_IN_GAC; + m_dwResultFlags |= RESULT_FLAG_IS_IN_TPA; } else { - m_dwResultFlags &= ~RESULT_FLAG_IS_IN_GAC; + m_dwResultFlags &= ~RESULT_FLAG_IS_IN_TPA; } } @@ -77,33 +77,33 @@ namespace BINDER_SPACE } } - IUnknown *GetAssembly(BOOL fAddRef = FALSE) + Assembly *GetAssembly(BOOL fAddRef = FALSE) { - IUnknown *pIUnknownAssembly = m_pIUnknownAssembly; + Assembly *pAssembly = m_pAssembly; - if (fAddRef && (pIUnknownAssembly != NULL)) + if (fAddRef && (pAssembly != NULL)) { - pIUnknownAssembly->AddRef(); + pAssembly->AddRef(); } - return pIUnknownAssembly; + return pAssembly; } - void SetAssembly(IUnknown *pIUnknownAssembly) + void SetAssembly(Assembly *pAssembly) { - SAFE_RELEASE(m_pIUnknownAssembly); + SAFE_RELEASE(m_pAssembly); - if (pIUnknownAssembly != NULL) + if (pAssembly != NULL) { - pIUnknownAssembly->AddRef(); + pAssembly->AddRef(); } - m_pIUnknownAssembly = pIUnknownAssembly; + m_pAssembly = pAssembly; } protected: DWORD m_dwResultFlags; - IUnknown *m_pIUnknownAssembly; + Assembly *m_pAssembly; }; }; diff --git a/src/coreclr/binder/inc/coreclrbindercommon.h b/src/coreclr/binder/inc/coreclrbindercommon.h deleted file mode 100644 index d64b84e50b487..0000000000000 --- a/src/coreclr/binder/inc/coreclrbindercommon.h +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - -#ifndef __CORECLR_BINDER_COMMON_H__ -#define __CORECLR_BINDER_COMMON_H__ - -#include "clrprivbinding.h" -#include "applicationcontext.hpp" - -namespace BINDER_SPACE -{ - class AssemblyIdentityUTF8; -}; - -class CLRPrivBinderCoreCLR; - -// General purpose AssemblyBinder helper class -class CCoreCLRBinderHelper -{ -public: - static HRESULT DefaultBinderSetupContext(DWORD dwAppDomainId, - CLRPrivBinderCoreCLR **ppTPABinder); - - // ABHI-TODO: The call indicates that this can come from a case where - // pDomain->GetFusionContext() is null, hence this is static function - // which handles a null binder. See if this actually happens - static HRESULT GetAssemblyIdentity(LPCSTR szTextualIdentity, - BINDER_SPACE::ApplicationContext *pApplicationContext, - NewHolder &assemblyIdentityHolder); - - //============================================================================= - // Class functions that provides binding services beyond the ICLRPrivInterface - //----------------------------------------------------------------------------- - static HRESULT BindToSystem(ICLRPrivAssembly **ppSystemAssembly, bool fBindToNativeImage); - - static HRESULT BindToSystemSatellite(SString &systemPath, - SString &sSimpleName, - SString &sCultureName, - ICLRPrivAssembly **ppSystemAssembly); -}; - -#endif // __CORECLR_BINDER_COMMON_H__ diff --git a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h b/src/coreclr/binder/inc/customassemblybinder.h similarity index 57% rename from src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h rename to src/coreclr/binder/inc/customassemblybinder.h index 4573575c1b7c6..20e67b07d625a 100644 --- a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h +++ b/src/coreclr/binder/inc/customassemblybinder.h @@ -2,66 +2,56 @@ // The .NET Foundation licenses this file to you under the MIT license. -#ifndef __CLRPRIVBINDERASSEMBLYLOADCONTEXT_H__ -#define __CLRPRIVBINDERASSEMBLYLOADCONTEXT_H__ +#ifndef __CUSTOM_ASSEMBLY_BINDER_H__ +#define __CUSTOM_ASSEMBLY_BINDER_H__ #include "applicationcontext.hpp" -#include "clrprivbindercoreclr.h" +#include "defaultassemblybinder.h" #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -class LoaderAllocator; +class AssemblyLoaderAllocator; class PEImage; -class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext +class CustomAssemblyBinder final : public AssemblyLoadContext { public: //========================================================================= - // ICLRPrivBinder functions + // AssemblyBinder functions //------------------------------------------------------------------------- - STDMETHOD(BindAssemblyByName)( - /* [in] */ struct AssemblyNameData *pAssemblyNameData, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); + HRESULT BindUsingPEImage(PEImage* pPEImage, + BOOL fIsNativeImage, + BINDER_SPACE::Assembly** ppAssembly); - STDMETHOD(GetLoaderAllocator)( - /* [retval][out] */ LPVOID *pLoaderAllocator); + HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, + BINDER_SPACE::Assembly** ppAssembly); + + AssemblyLoaderAllocator* GetLoaderAllocator(); public: //========================================================================= // Class functions //------------------------------------------------------------------------- - static HRESULT SetupContext(DWORD dwAppDomainId, - CLRPrivBinderCoreCLR *pTPABinder, - LoaderAllocator* pLoaderAllocator, + CustomAssemblyBinder(); + + static HRESULT SetupContext(DefaultAssemblyBinder *pTPABinder, + AssemblyLoaderAllocator* pLoaderAllocator, void* loaderAllocatorHandle, UINT_PTR ptrAssemblyLoadContext, - CLRPrivBinderAssemblyLoadContext **ppBindContext); + CustomAssemblyBinder **ppBindContext); void PrepareForLoadContextRelease(INT_PTR ptrManagedStrongAssemblyLoadContext); void ReleaseLoadContext(); - CLRPrivBinderAssemblyLoadContext(); - - inline BINDER_SPACE::ApplicationContext *GetAppContext() - { - return &m_appContext; - } - - HRESULT BindUsingPEImage( /* in */ PEImage *pPEImage, - /* in */ BOOL fIsNativeImage, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); - //========================================================================= // Internal implementation details //------------------------------------------------------------------------- private: HRESULT BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly); - BINDER_SPACE::ApplicationContext m_appContext; - - CLRPrivBinderCoreCLR *m_pTPABinder; + DefaultAssemblyBinder *m_pTPABinder; // A strong GC handle to the managed AssemblyLoadContext. This handle is set when the unload of the AssemblyLoadContext is initiated // to keep the managed AssemblyLoadContext alive until the unload is finished. @@ -69,9 +59,9 @@ class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext // to refer to it during the whole lifetime of the AssemblyLoadContext. INT_PTR m_ptrManagedStrongAssemblyLoadContext; - LoaderAllocator* m_pAssemblyLoaderAllocator; + AssemblyLoaderAllocator* m_pAssemblyLoaderAllocator; void* m_loaderAllocatorHandle; }; #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -#endif // __CLRPRIVBINDERASSEMBLYLOADCONTEXT_H__ +#endif // __CUSTOM_ASSEMBLY_BINDER_H__ diff --git a/src/coreclr/binder/inc/defaultassemblybinder.h b/src/coreclr/binder/inc/defaultassemblybinder.h new file mode 100644 index 0000000000000..5559c282dcb9b --- /dev/null +++ b/src/coreclr/binder/inc/defaultassemblybinder.h @@ -0,0 +1,55 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + + +#ifndef __DEFAULT_ASSEMBLY_BINDER_H__ +#define __DEFAULT_ASSEMBLY_BINDER_H__ + +#include "applicationcontext.hpp" +#include "assemblyloadcontext.h" + +class PEAssembly; +class PEImage; + +class DefaultAssemblyBinder final : public AssemblyLoadContext +{ +public: + //========================================================================= + // AssemblyBinder functions + //------------------------------------------------------------------------- + + HRESULT BindUsingPEImage(PEImage* pPEImage, + BOOL fIsNativeImage, + BINDER_SPACE::Assembly** ppAssembly); + + HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, + BINDER_SPACE::Assembly** ppAssembly); + + AssemblyLoaderAllocator* GetLoaderAllocator() + { + // Not supported by this binder + return NULL; + } + +public: + + HRESULT SetupBindingPaths(SString &sTrustedPlatformAssemblies, + SString &sPlatformResourceRoots, + SString &sAppPaths, + SString &sAppNiPaths); + + HRESULT Bind(LPCWSTR wszCodeBase, + PEAssembly *pParentAssembly, + BOOL fNgenExplicitBind, + BOOL fExplicitBindToNativeImage, + BINDER_SPACE::Assembly **ppAssembly); + +private: + + HRESULT BindAssemblyByNameWorker( + BINDER_SPACE::AssemblyName *pAssemblyName, + BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly, + bool excludeAppPaths); +}; + +#endif // __DEFAULT_ASSEMBLY_BINDER_H__ diff --git a/src/coreclr/binder/inc/loadcontext.hpp b/src/coreclr/binder/inc/loadcontext.hpp index e840a405df0de..ea95bef2ef03b 100644 --- a/src/coreclr/binder/inc/loadcontext.hpp +++ b/src/coreclr/binder/inc/loadcontext.hpp @@ -29,13 +29,8 @@ namespace BINDER_SPACE LoadContext(); ~LoadContext(); - ULONG AddRef(); - ULONG Release(); ContextEntry *Lookup(/* in */ AssemblyName *pAssemblyName); HRESULT Register(BindResult *pBindResult); - - protected: - LONG m_cRef; }; #include "loadcontext.inl" diff --git a/src/coreclr/binder/inc/loadcontext.inl b/src/coreclr/binder/inc/loadcontext.inl index fb463523ebb03..71a5765c41858 100644 --- a/src/coreclr/binder/inc/loadcontext.inl +++ b/src/coreclr/binder/inc/loadcontext.inl @@ -18,7 +18,6 @@ template LoadContext::LoadContext() : SHash >::SHash() { - m_cRef = 1; } template @@ -33,25 +32,6 @@ LoadContext::~LoadContext() this->RemoveAll(); } -template -ULONG LoadContext::AddRef() -{ - return InterlockedIncrement(&m_cRef); -} - -template -ULONG LoadContext::Release() -{ - ULONG ulRef = InterlockedDecrement(&m_cRef); - - if (ulRef == 0) - { - delete this; - } - - return ulRef; -} - template ContextEntry *LoadContext::Lookup(AssemblyName *pAssemblyName) { @@ -69,7 +49,7 @@ HRESULT LoadContext::Register(BindResult *pBindResult) SAFE_NEW(pContextEntry, ContextEntry); - pContextEntry->SetIsInGAC(pBindResult->GetIsInGAC()); + pContextEntry->SetIsInTPA(pBindResult->GetIsInTPA()); pContextEntry->SetAssemblyName(pBindResult->GetAssemblyName(), TRUE /* fAddRef */); pContextEntry->SetAssembly(pBindResult->GetAssembly()); diff --git a/src/coreclr/inc/CMakeLists.txt b/src/coreclr/inc/CMakeLists.txt index 535be85af85db..eaae5d2b89d52 100644 --- a/src/coreclr/inc/CMakeLists.txt +++ b/src/coreclr/inc/CMakeLists.txt @@ -7,7 +7,6 @@ set( CORGUIDS_IDL_SOURCES corprof.idl corpub.idl mscorsvc.idl - clrprivbinding.idl corsym.idl sospriv.idl ) diff --git a/src/coreclr/inc/clrprivbinderutil.h b/src/coreclr/inc/assemblybinderutil.h similarity index 78% rename from src/coreclr/inc/clrprivbinderutil.h rename to src/coreclr/inc/assemblybinderutil.h index 591e55c8e8aef..4d6a6bcce71f7 100644 --- a/src/coreclr/inc/clrprivbinderutil.h +++ b/src/coreclr/inc/assemblybinderutil.h @@ -5,15 +5,13 @@ // // Contains helper types for assembly binding host infrastructure. -#ifndef __CLRPRIVBINDERUTIL_H__ -#define __CLRPRIVBINDERUTIL_H__ - -#include "clrprivbinding.h" +#ifndef __ASSEMBLY_BINDER_UTIL_H__ +#define __ASSEMBLY_BINDER_UTIL_H__ //===================================================================================================================== // Forward declarations -typedef DPTR(ICLRPrivAssembly) PTR_ICLRPrivAssembly; -typedef DPTR(ICLRPrivBinder) PTR_ICLRPrivBinder; +typedef DPTR(BINDER_SPACE::Assembly) PTR_BINDER_SPACE_Assembly; +typedef DPTR(AssemblyBinder) PTR_AssemblyBinder; //===================================================================================================================== #define VALIDATE_CONDITION(condition, fail_op) \ @@ -25,4 +23,4 @@ typedef DPTR(ICLRPrivBinder) PTR_ICLRPrivBinder; #define VALIDATE_ARG_RET(condition) VALIDATE_CONDITION(condition, return E_INVALIDARG) -#endif // __CLRPRIVBINDERUTIL_H__ +#endif // __ASSEMBLY_BINDER_UTIL_H__ diff --git a/src/coreclr/inc/clrprivbinding.idl b/src/coreclr/inc/clrprivbinding.idl deleted file mode 100644 index 9f4ee2f3d6ff8..0000000000000 --- a/src/coreclr/inc/clrprivbinding.idl +++ /dev/null @@ -1,99 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -import "unknwn.idl"; -import "objidl.idl"; - -// Forward declarations -interface ICLRPrivBinder; -interface ICLRPrivAssembly; - -/************************************************************************************** - ** This IDL file defines the assembly binding host interfaces. Some things to keep - ** in mind: - ** - Equality is determined by pointer equality: two interface instances - ** should be considered equal if and only if their pointer values are equal. - ** - All operations are idempotent: when a method is called more than once with - ** the same input values, it is required to return identical results. The only - ** possible exceptions center around transient errors such as E_OUTOFMEMORY. - **************************************************************************************/ - -/************************************************************************************** - ** ICLRPrivBinder - Use to bind to an assembly by name or by metadata reference. - **************************************************************************************/ -[ - uuid(2601F621-E462-404C-B299-3E1DE72F8542), - version(1.0), - local -] -interface ICLRPrivBinder : IUnknown -{ - /********************************************************************************** - ** BindAssemblyByName -- Binds an assembly by name. - ** NOTE: This method is required to be idempotent. See general comment above. - ** - ** pAssemblyFullName - name of the assembly for which a bind is being requested. - ** ppAssembly - upon success, receives the bound assembly. - **********************************************************************************/ - HRESULT BindAssemblyByName( - [in] struct AssemblyNameData* pAssemblyNameData, - [out, retval] ICLRPrivAssembly ** ppAssembly); - - /********************************************************************************** - ** GetBinderID - ** pBinderId, pointer to binder id. The binder id has the following properties - ** It is a pointer that does not change over the lifetime of a binder object - ** It points at an object in memory that will remain allocated for the lifetime of the binder. - ** This value should be the same for a set of binder objects that represent the same binder behavior. - **********************************************************************************/ - HRESULT GetBinderID( - [out, retval] UINT_PTR *pBinderId); - - /********************************************************************************** - ** GetLoaderAllocator - ** Get LoaderAllocator for binders that contain it. For other binders, return - ** E_FAIL - ** - ** pLoaderAllocator - when successful, constains the returned LoaderAllocator - **********************************************************************************/ - HRESULT GetLoaderAllocator( - [out, retval] LPVOID * pLoaderAllocator); -}; - -/************************************************************************************** - ** ASSEMBLY_IMAGE_TYPES - The set of assembly image formats. - **************************************************************************************/ -enum ASSEMBLY_IMAGE_TYPES -{ - // IL image format - ASSEMBLY_IMAGE_TYPE_IL = 0x0001, - // Native image (NGEN) format - ASSEMBLY_IMAGE_TYPE_NATIVE = 0x0002, - // Binder's preferred image type - ASSEMBLY_IMAGE_TYPE_DEFAULT = 0x0003, - // Only supported on CoreCLR - ASSEMBLY_IMAGE_TYPE_ASSEMBLY = 0x0004, -}; - -/************************************************************************************** - ** ICLRPrivAssembly - Represents an assembly bind result. Extends ICLRPrivBinder, which - ** implicitly tracks the parent binder, and enables simple assembly-relative binds. - **************************************************************************************/ -[ - uuid(2601F621-E462-404C-B299-3E1DE72F8543), - version(1.0), - local -] -interface ICLRPrivAssembly : ICLRPrivBinder -{ - /********************************************************************************** - ** GetAvailableImageTypes - Use to retrieve the set of images available for an - ** assembly. - ** NOTE: This method is required to be idempotent. See general comment above. - ** - ** pdwImageTypes - set to values from ASSEMBLY_IMAGE_TYPES to indicate - ** which image formats are available for the assembly. - **********************************************************************************/ - HRESULT GetAvailableImageTypes( - [out, retval] LPDWORD pdwImageTypes); -}; diff --git a/src/coreclr/inc/corerror.xml b/src/coreclr/inc/corerror.xml index bb25331af9c6d..fbc74db6bbda2 100644 --- a/src/coreclr/inc/corerror.xml +++ b/src/coreclr/inc/corerror.xml @@ -2226,7 +2226,7 @@ CLR_E_BIND_IMAGE_UNAVAILABLE "The requested image was not found or is unavailable." - Occurs if a request for a native image is made on an ICLRPrivAssembly interface when one is not available. + Occurs if a request for a native image is made on an BINDER_SPACE::Assembly interface when one is not available. diff --git a/src/coreclr/inc/corhost.h b/src/coreclr/inc/corhost.h index 57ffbe30c3a8b..bebeeba9ac852 100644 --- a/src/coreclr/inc/corhost.h +++ b/src/coreclr/inc/corhost.h @@ -27,8 +27,6 @@ #include "holder.h" -#include "clrprivbinding.h" - #ifdef FEATURE_COMINTEROP #include "activation.h" // WinRT activation. #endif diff --git a/src/coreclr/pal/prebuilt/idl/clrprivbinding_i.cpp b/src/coreclr/pal/prebuilt/idl/clrprivbinding_i.cpp deleted file mode 100644 index 1de6c4119bf12..0000000000000 --- a/src/coreclr/pal/prebuilt/idl/clrprivbinding_i.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - - -/* this ALWAYS GENERATED file contains the IIDs and CLSIDs */ - -/* link this file in with the server and any clients */ - - - /* File created by MIDL compiler version 8.00.0603 */ -/* @@MIDL_FILE_HEADING( ) */ - -#pragma warning( disable: 4049 ) /* more than 64k source lines */ - - -#ifdef __cplusplus -extern "C"{ -#endif - - -#include -#include - -#ifdef _MIDL_USE_GUIDDEF_ - -#ifndef INITGUID -#define INITGUID -#include -#undef INITGUID -#else -#include -#endif - -#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ - DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) - -#else // !_MIDL_USE_GUIDDEF_ - -#ifndef __IID_DEFINED__ -#define __IID_DEFINED__ - -typedef struct _IID -{ - unsigned long x; - unsigned short s1; - unsigned short s2; - unsigned char c[8]; -} IID; - -#endif // __IID_DEFINED__ - -#ifndef CLSID_DEFINED -#define CLSID_DEFINED -typedef IID CLSID; -#endif // CLSID_DEFINED - -#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ - EXTERN_C __declspec(selectany) const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} - -#endif // !_MIDL_USE_GUIDDEF_ - -MIDL_DEFINE_GUID(IID, IID_ICLRPrivBinder,0x2601F621,0xE462,0x404C,0xB2,0x99,0x3E,0x1D,0xE7,0x2F,0x85,0x42); - - -MIDL_DEFINE_GUID(IID, IID_ICLRPrivAssembly,0x2601F621,0xE462,0x404C,0xB2,0x99,0x3E,0x1D,0xE7,0x2F,0x85,0x43); - -#undef MIDL_DEFINE_GUID - -#ifdef __cplusplus -} -#endif - - - diff --git a/src/coreclr/pal/prebuilt/inc/clrprivbinding.h b/src/coreclr/pal/prebuilt/inc/clrprivbinding.h deleted file mode 100644 index 3c810676aa36c..0000000000000 --- a/src/coreclr/pal/prebuilt/inc/clrprivbinding.h +++ /dev/null @@ -1,305 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - - -/* this ALWAYS GENERATED file contains the definitions for the interfaces */ - - - /* File created by MIDL compiler version 8.00.0603 */ -/* @@MIDL_FILE_HEADING( ) */ - -#pragma warning( disable: 4049 ) /* more than 64k source lines */ - - -/* verify that the version is high enough to compile this file*/ -#ifndef __REQUIRED_RPCNDR_H_VERSION__ -#define __REQUIRED_RPCNDR_H_VERSION__ 475 -#endif - -#include "rpc.h" -#include "rpcndr.h" - -#ifndef __RPCNDR_H_VERSION__ -#error this stub requires an updated version of -#endif /* __RPCNDR_H_VERSION__ */ - -#ifndef COM_NO_WINDOWS_H -#include "windows.h" -#include "ole2.h" -#endif /*COM_NO_WINDOWS_H*/ - -#ifndef __clrprivbinding_h__ -#define __clrprivbinding_h__ - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -#pragma once -#endif - -/* Forward Declarations */ - -#ifndef __ICLRPrivBinder_FWD_DEFINED__ -#define __ICLRPrivBinder_FWD_DEFINED__ -typedef interface ICLRPrivBinder ICLRPrivBinder; - -#endif /* __ICLRPrivBinder_FWD_DEFINED__ */ - - -#ifndef __ICLRPrivAssembly_FWD_DEFINED__ -#define __ICLRPrivAssembly_FWD_DEFINED__ -typedef interface ICLRPrivAssembly ICLRPrivAssembly; - -#endif /* __ICLRPrivAssembly_FWD_DEFINED__ */ - - -/* header files for imported files */ -#include "unknwn.h" -#include "objidl.h" - -#ifdef __cplusplus -extern "C"{ -#endif - - -/* interface __MIDL_itf_clrprivbinding_0000_0000 */ -/* [local] */ - - - - - -extern RPC_IF_HANDLE __MIDL_itf_clrprivbinding_0000_0000_v0_0_c_ifspec; -extern RPC_IF_HANDLE __MIDL_itf_clrprivbinding_0000_0000_v0_0_s_ifspec; - -#ifndef __ICLRPrivBinder_INTERFACE_DEFINED__ -#define __ICLRPrivBinder_INTERFACE_DEFINED__ - -/* interface ICLRPrivBinder */ -/* [object][local][version][uuid] */ - - -EXTERN_C const IID IID_ICLRPrivBinder; - -#if defined(__cplusplus) && !defined(CINTERFACE) - - MIDL_INTERFACE("2601F621-E462-404C-B299-3E1DE72F8542") - ICLRPrivBinder : public IUnknown - { - public: - virtual HRESULT STDMETHODCALLTYPE BindAssemblyByName( - /* [in] */ struct AssemblyNameData *pAssemblyNameData, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetBinderID( - /* [retval][out] */ UINT_PTR *pBinderId) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetLoaderAllocator( - /* [retval][out] */ LPVOID *pLoaderAllocator) = 0; - - }; - - -#else /* C style interface */ - - typedef struct ICLRPrivBinderVtbl - { - BEGIN_INTERFACE - - HRESULT ( STDMETHODCALLTYPE *QueryInterface )( - ICLRPrivBinder * This, - /* [in] */ REFIID riid, - /* [annotation][iid_is][out] */ - _COM_Outptr_ void **ppvObject); - - ULONG ( STDMETHODCALLTYPE *AddRef )( - ICLRPrivBinder * This); - - ULONG ( STDMETHODCALLTYPE *Release )( - ICLRPrivBinder * This); - - HRESULT ( STDMETHODCALLTYPE *BindAssemblyByName )( - ICLRPrivBinder * This, - /* [in] */ struct AssemblyNameData *pAssemblyNameData, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); - - HRESULT ( STDMETHODCALLTYPE *GetBinderID )( - ICLRPrivBinder * This, - /* [retval][out] */ UINT_PTR *pBinderId); - - HRESULT ( STDMETHODCALLTYPE *GetLoaderAllocator )( - ICLRPrivBinder * This, - /* [retval][out] */ LPVOID *pLoaderAllocator); - - END_INTERFACE - } ICLRPrivBinderVtbl; - - interface ICLRPrivBinder - { - CONST_VTBL struct ICLRPrivBinderVtbl *lpVtbl; - }; - - - -#ifdef COBJMACROS - - -#define ICLRPrivBinder_QueryInterface(This,riid,ppvObject) \ - ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) - -#define ICLRPrivBinder_AddRef(This) \ - ( (This)->lpVtbl -> AddRef(This) ) - -#define ICLRPrivBinder_Release(This) \ - ( (This)->lpVtbl -> Release(This) ) - - -#define ICLRPrivBinder_BindAssemblyByName(This,pAssemblyNameData,ppAssembly) \ - ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyNameData,ppAssembly) ) - -#define ICLRPrivBinder_GetBinderID(This,pBinderId) \ - ( (This)->lpVtbl -> GetBinderID(This,pBinderId) ) - -#define ICLRPrivBinder_GetLoaderAllocator(This,pLoaderAllocator) \ - ( (This)->lpVtbl -> GetLoaderAllocator(This,pLoaderAllocator) ) - -#endif /* COBJMACROS */ - - -#endif /* C style interface */ - - - - -#endif /* __ICLRPrivBinder_INTERFACE_DEFINED__ */ - - -/* interface __MIDL_itf_clrprivbinding_0000_0001 */ -/* [local] */ - - -enum ASSEMBLY_IMAGE_TYPES - { - ASSEMBLY_IMAGE_TYPE_IL = 0x1, - ASSEMBLY_IMAGE_TYPE_NATIVE = 0x2, - ASSEMBLY_IMAGE_TYPE_DEFAULT = 0x3, - ASSEMBLY_IMAGE_TYPE_ASSEMBLY = 0x4 - } ; - - -extern RPC_IF_HANDLE __MIDL_itf_clrprivbinding_0000_0001_v0_0_c_ifspec; -extern RPC_IF_HANDLE __MIDL_itf_clrprivbinding_0000_0001_v0_0_s_ifspec; - -#ifndef __ICLRPrivAssembly_INTERFACE_DEFINED__ -#define __ICLRPrivAssembly_INTERFACE_DEFINED__ - -/* interface ICLRPrivAssembly */ -/* [object][local][version][uuid] */ - - -EXTERN_C const IID IID_ICLRPrivAssembly; - -#if defined(__cplusplus) && !defined(CINTERFACE) - - MIDL_INTERFACE("2601F621-E462-404C-B299-3E1DE72F8543") - ICLRPrivAssembly : public ICLRPrivBinder - { - public: - virtual HRESULT STDMETHODCALLTYPE GetAvailableImageTypes( - /* [retval][out] */ LPDWORD pdwImageTypes) = 0; - - }; - - -#else /* C style interface */ - - typedef struct ICLRPrivAssemblyVtbl - { - BEGIN_INTERFACE - - HRESULT ( STDMETHODCALLTYPE *QueryInterface )( - ICLRPrivAssembly * This, - /* [in] */ REFIID riid, - /* [annotation][iid_is][out] */ - _COM_Outptr_ void **ppvObject); - - ULONG ( STDMETHODCALLTYPE *AddRef )( - ICLRPrivAssembly * This); - - ULONG ( STDMETHODCALLTYPE *Release )( - ICLRPrivAssembly * This); - - HRESULT ( STDMETHODCALLTYPE *BindAssemblyByName )( - ICLRPrivAssembly * This, - /* [in] */ struct AssemblyNameData *pAssemblyNameData, - /* [retval][out] */ ICLRPrivAssembly **ppAssembly); - - HRESULT ( STDMETHODCALLTYPE *GetBinderID )( - ICLRPrivAssembly * This, - /* [retval][out] */ UINT_PTR *pBinderId); - - HRESULT ( STDMETHODCALLTYPE *GetLoaderAllocator )( - ICLRPrivAssembly * This, - /* [retval][out] */ LPVOID *pLoaderAllocator); - - HRESULT ( STDMETHODCALLTYPE *GetAvailableImageTypes )( - ICLRPrivAssembly * This, - /* [retval][out] */ LPDWORD pdwImageTypes); - - END_INTERFACE - } ICLRPrivAssemblyVtbl; - - interface ICLRPrivAssembly - { - CONST_VTBL struct ICLRPrivAssemblyVtbl *lpVtbl; - }; - - - -#ifdef COBJMACROS - - -#define ICLRPrivAssembly_QueryInterface(This,riid,ppvObject) \ - ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) - -#define ICLRPrivAssembly_AddRef(This) \ - ( (This)->lpVtbl -> AddRef(This) ) - -#define ICLRPrivAssembly_Release(This) \ - ( (This)->lpVtbl -> Release(This) ) - - -#define ICLRPrivAssembly_BindAssemblyByName(This,pAssemblyNameData,ppAssembly) \ - ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyNameData,ppAssembly) ) - -#define ICLRPrivAssembly_GetBinderID(This,pBinderId) \ - ( (This)->lpVtbl -> GetBinderID(This,pBinderId) ) - -#define ICLRPrivAssembly_GetLoaderAllocator(This,pLoaderAllocator) \ - ( (This)->lpVtbl -> GetLoaderAllocator(This,pLoaderAllocator) ) - - -#define ICLRPrivAssembly_GetAvailableImageTypes(This,pdwImageTypes) \ - ( (This)->lpVtbl -> GetAvailableImageTypes(This,pdwImageTypes) ) - -#endif /* COBJMACROS */ - - -#endif /* C style interface */ - - - - -#endif /* __ICLRPrivAssembly_INTERFACE_DEFINED__ */ - - -/* Additional Prototypes for ALL interfaces */ - -/* end of Additional Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif - - diff --git a/src/coreclr/vm/CMakeLists.txt b/src/coreclr/vm/CMakeLists.txt index 5cb683b92b5cf..d77869364f980 100644 --- a/src/coreclr/vm/CMakeLists.txt +++ b/src/coreclr/vm/CMakeLists.txt @@ -49,6 +49,7 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON appdomain.cpp array.cpp assembly.cpp + assemblybinder.cpp assemblyloadcontext.cpp binder.cpp bundle.cpp @@ -147,6 +148,7 @@ set(VM_HEADERS_DAC_AND_WKS_COMMON appdomain.inl array.h assembly.hpp + assemblybinder.h assemblyloadcontext.h binder.h castcache.h diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 30c5da69b54d2..669dc918df854 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -64,8 +64,8 @@ #include "stringarraylist.h" #include "../binder/inc/bindertracing.h" -#include "../binder/inc/clrprivbindercoreclr.h" -#include "../binder/inc/coreclrbindercommon.h" +#include "../binder/inc/defaultassemblybinder.h" +#include "../binder/inc/assemblybindercommon.hpp" // this file handles string conversion errors for itself #undef MAKE_TRANSLATIONFAILED @@ -745,8 +745,9 @@ void BaseDomain::ClearBinderContext() } CONTRACTL_END; - if (m_pTPABinderContext) { - m_pTPABinderContext->Release(); + if (m_pTPABinderContext) + { + delete m_pTPABinderContext; m_pTPABinderContext = NULL; } } @@ -2924,8 +2925,6 @@ Assembly *AppDomain::LoadAssembly(AssemblySpec* pIdentity, RETURN pAssembly->GetAssembly(); } -extern BOOL AreSameBinderInstance(ICLRPrivBinder *pBinderA, ICLRPrivBinder *pBinderB); - DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, PEAssembly *pFile, FileLoadLevel targetLevel) @@ -2949,8 +2948,8 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, if (!pEx->IsTransient()) { // Setup the binder reference in AssemblySpec from the PEAssembly if one is not already set. - ICLRPrivBinder* pCurrentBindingContext = pSpec->GetBindingContext(); - ICLRPrivBinder* pBindingContextFromPEAssembly = pFile->GetBindingContext(); + AssemblyBinder* pCurrentBindingContext = pSpec->GetBindingContext(); + AssemblyBinder* pBindingContextFromPEAssembly = pFile->GetBindingContext(); if (pCurrentBindingContext == NULL) { @@ -2963,7 +2962,7 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, else { // Binding context in the spec should be the same as the binding context in the PEAssembly - _ASSERTE(AreSameBinderInstance(pCurrentBindingContext, pBindingContextFromPEAssembly)); + _ASSERTE(pCurrentBindingContext == pBindingContextFromPEAssembly); } #endif // _DEBUG @@ -3018,12 +3017,12 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, LoaderAllocator *pLoaderAllocator = NULL; #ifndef CROSSGEN_COMPILE - ICLRPrivBinder *pFileBinder = pFile->GetBindingContext(); + AssemblyBinder *pFileBinder = pFile->GetBindingContext(); if (pFileBinder != NULL) { // Assemblies loaded with AssemblyLoadContext need to use a different LoaderAllocator if // marked as collectible - pFileBinder->GetLoaderAllocator((LPVOID*)&pLoaderAllocator); + pLoaderAllocator = pFileBinder->GetLoaderAllocator(); } #endif // !CROSSGEN_COMPILE @@ -3986,7 +3985,7 @@ PEAssembly * AppDomain::BindAssemblySpec( } // Setup the reference to the binder, which performed the bind, into the AssemblySpec - ICLRPrivBinder* pBinder = result->GetBindingContext(); + AssemblyBinder* pBinder = result->GetBindingContext(); _ASSERTE(pBinder != NULL); pSpec->SetBindingContext(pBinder); @@ -4318,9 +4317,9 @@ AppDomain::RaiseUnhandledExceptionEvent(OBJECTREF *pThrowable, BOOL isTerminatin #endif // CROSSGEN_COMPILE -CLRPrivBinderCoreCLR *AppDomain::CreateBinderContext() +DefaultAssemblyBinder *AppDomain::CreateBinderContext() { - CONTRACT(CLRPrivBinderCoreCLR *) + CONTRACT(DefaultAssemblyBinder *) { GC_TRIGGERS; THROWS; @@ -4337,7 +4336,7 @@ CLRPrivBinderCoreCLR *AppDomain::CreateBinderContext() GCX_PREEMP(); // Initialize the assembly binder for the default context loads for CoreCLR. - IfFailThrow(CCoreCLRBinderHelper::DefaultBinderSetupContext(DefaultADID, &m_pTPABinderContext)); + IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::DefaultBinderSetupContext(&m_pTPABinderContext)); } RETURN m_pTPABinderContext; @@ -5262,7 +5261,7 @@ AppDomain::AssemblyIterator::Next_Unlocked( #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) // Returns S_OK if the assembly was successfully loaded -HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, CLRPrivBinderCoreCLR *pTPABinder, ICLRPrivAssembly **ppLoadedAssembly) +HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, DefaultAssemblyBinder *pTPABinder, BINDER_SPACE::Assembly **ppLoadedAssembly) { CONTRACTL { @@ -5289,7 +5288,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB GCPROTECT_BEGIN(_gcRefs); - ICLRPrivAssembly *pResolvedAssembly = NULL; + BINDER_SPACE::Assembly *pResolvedAssembly = NULL; bool fResolvedAssembly = false; BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, 0 /*binderID*/, pManagedAssemblyLoadContextToBindWithin, hr}; @@ -5306,7 +5305,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB { if (pTPABinder != NULL) { - // Step 2 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) - Invoke Load method + // Step 2 (of CustomAssemblyBinder::BindAssemblyByName) - Invoke Load method // This is not invoked for TPA Binder since it always returns NULL. tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::AssemblyLoadContextLoad); @@ -5329,7 +5328,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; - // Step 3 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) + // Step 3 (of CustomAssemblyBinder::BindAssemblyByName) if (!fResolvedAssembly && !isSatelliteAssemblyRequest) { tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::DefaultAssemblyLoadContextFallback); @@ -5339,7 +5338,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB // // Switch to pre-emp mode before calling into the binder GCX_PREEMP(); - ICLRPrivAssembly *pCoreCLRFoundAssembly = NULL; + BINDER_SPACE::Assembly *pCoreCLRFoundAssembly = NULL; hr = pTPABinder->BindUsingAssemblyName(pAssemblyName, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { @@ -5352,7 +5351,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB if (!fResolvedAssembly && isSatelliteAssemblyRequest) { - // Step 4 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) + // Step 4 (of CustomAssemblyBinder::BindAssemblyByName) // // Attempt to resolve it using the ResolveSatelliteAssembly method. // Finally, setup arguments for invocation @@ -5380,7 +5379,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB if (!fResolvedAssembly) { - // Step 5 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) + // Step 5 (of CustomAssemblyBinder::BindAssemblyByName) // // If we couldn't resolve the assembly using TPA LoadContext as well, then // attempt to resolve it using the Resolving event. @@ -5432,7 +5431,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB } } - // The loaded assembly's ICLRPrivAssembly* is saved as HostAssembly in PEAssembly + // The loaded assembly's BINDER_SPACE::Assembly* is saved as HostAssembly in PEAssembly if (fFailLoad) { PathString name; @@ -5447,7 +5446,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB { _ASSERTE(pResolvedAssembly != NULL); - // Get the ICLRPrivAssembly reference to return back to. + // Get the BINDER_SPACE::Assembly reference to return back to. *ppLoadedAssembly = clr::SafeAddRef(pResolvedAssembly); hr = S_OK; @@ -5789,7 +5788,7 @@ void AppDomain::UnPublishHostedAssembly( #endif //!DACCESS_COMPILE //--------------------------------------------------------------------------------------------------------------------- -PTR_DomainAssembly AppDomain::FindAssembly(PTR_ICLRPrivAssembly pHostAssembly) +PTR_DomainAssembly AppDomain::FindAssembly(PTR_BINDER_SPACE_Assembly pHostAssembly) { CONTRACTL { diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index fb2e45682fc68..51872a5494a07 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -1103,7 +1103,7 @@ class BaseDomain #endif // DACCESS_COMPILE && !CROSSGEN_COMPILE - CLRPrivBinderCoreCLR *GetTPABinderContext() {LIMITED_METHOD_CONTRACT; return m_pTPABinderContext; } + DefaultAssemblyBinder *GetTPABinderContext() {LIMITED_METHOD_CONTRACT; return m_pTPABinderContext; } CrstExplicitInit * GetLoaderAllocatorReferencesLock() { @@ -1134,7 +1134,7 @@ class BaseDomain ListLock m_ILStubGenLock; ListLock m_NativeTypeLoadLock; - CLRPrivBinderCoreCLR *m_pTPABinderContext; // Reference to the binding context that holds TPA list details + DefaultAssemblyBinder *m_pTPABinderContext; // Reference to the binding context that holds TPA list details IGCHandleStore* m_handleStore; @@ -1987,7 +1987,7 @@ class AppDomain : public BaseDomain return m_tpIndex; } - CLRPrivBinderCoreCLR *CreateBinderContext(); + DefaultAssemblyBinder *CreateBinderContext(); void SetIgnoreUnhandledExceptions() { @@ -2392,14 +2392,14 @@ class AppDomain : public BaseDomain private: //----------------------------------------------------------- - // Static ICLRPrivAssembly -> DomainAssembly mapping functions. + // Static BINDER_SPACE::Assembly -> DomainAssembly mapping functions. // This map does not maintain a reference count to either key or value. - // PEFile maintains a reference count on the ICLRPrivAssembly through its code:PEFile::m_pHostAssembly field. + // PEFile maintains a reference count on the BINDER_SPACE::Assembly through its code:PEFile::m_pHostAssembly field. // It is removed from this hash table by code:DomainAssembly::~DomainAssembly. struct HostAssemblyHashTraits : public DefaultSHashTraits { public: - typedef PTR_ICLRPrivAssembly key_t; + typedef PTR_BINDER_SPACE_Assembly key_t; static key_t GetKey(element_t const & elem) { @@ -2446,7 +2446,7 @@ class AppDomain : public BaseDomain public: // Returns DomainAssembly. - PTR_DomainAssembly FindAssembly(PTR_ICLRPrivAssembly pHostAssembly); + PTR_DomainAssembly FindAssembly(PTR_BINDER_SPACE_Assembly pHostAssembly); #ifndef DACCESS_COMPILE private: @@ -2701,7 +2701,7 @@ class SystemDomain : public BaseDomain if (path.EqualsCaseInsensitive(m_BaseLibrary)) return TRUE; - // Or, it might be the GAC location of CoreLib + // Or, it might be the location of CoreLib if (System()->SystemAssembly() != NULL && path.EqualsCaseInsensitive(System()->SystemAssembly()->GetManifestFile()->GetPath())) return TRUE; diff --git a/src/coreclr/vm/appdomainnative.cpp b/src/coreclr/vm/appdomainnative.cpp index 6fe9099d51db7..425b786771fc4 100644 --- a/src/coreclr/vm/appdomainnative.cpp +++ b/src/coreclr/vm/appdomainnative.cpp @@ -10,7 +10,7 @@ #include "eeconfig.h" #include "appdomain.inl" #include "eventtrace.h" -#include "../binder/inc/clrprivbindercoreclr.h" +#include "../binder/inc/defaultassemblybinder.h" #include "clr/fs/path.h" using namespace clr::fs; @@ -39,13 +39,13 @@ void QCALLTYPE AppDomainNative::CreateDynamicAssembly(QCall::ObjectHandleOnStack args.stackMark = stackMark; Assembly* pAssembly = nullptr; - ICLRPrivBinder* pBinderContext = nullptr; + AssemblyBinder* pBinderContext = nullptr; if (assemblyLoadContext.Get() != NULL) { INT_PTR nativeAssemblyLoadContext = ((ASSEMBLYLOADCONTEXTREF)assemblyLoadContext.Get())->GetNativeAssemblyLoadContext(); - pBinderContext = reinterpret_cast(nativeAssemblyLoadContext); + pBinderContext = reinterpret_cast(nativeAssemblyLoadContext); } pAssembly = Assembly::CreateDynamic(GetAppDomain(), pBinderContext, &args); diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 666045b6c210a..11e271a8ef6a8 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -374,7 +374,7 @@ Assembly * Assembly::Create( #ifndef CROSSGEN_COMPILE -Assembly *Assembly::CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderContext, CreateDynamicAssemblyArgs *args) +Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderContext, CreateDynamicAssemblyArgs *args) { // WARNING: not backout clean CONTRACT(Assembly *) @@ -516,7 +516,7 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderCon &ma)); pFile = PEAssembly::Create(pCallerAssembly->GetManifestFile(), pAssemblyEmit); - ICLRPrivBinder* pFallbackLoadContextBinder = pBinderContext; + AssemblyBinder* pFallbackLoadContextBinder = pBinderContext; // If ALC is not specified if (pFallbackLoadContextBinder == nullptr) @@ -545,12 +545,10 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderCon else { // Fetch the binder from the host assembly - PTR_ICLRPrivAssembly pCallerAssemblyHostAssembly = pCallerAssemblyManifestFile->GetHostAssembly(); + PTR_BINDER_SPACE_Assembly pCallerAssemblyHostAssembly = pCallerAssemblyManifestFile->GetHostAssembly(); _ASSERTE(pCallerAssemblyHostAssembly != nullptr); - UINT_PTR assemblyBinderID = 0; - IfFailThrow(pCallerAssemblyHostAssembly->GetBinderID(&assemblyBinderID)); - pFallbackLoadContextBinder = reinterpret_cast(assemblyBinderID); + pFallbackLoadContextBinder = pCallerAssemblyHostAssembly->GetBinder(); } } else @@ -575,10 +573,9 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderCon GCX_PREEMP(); AssemblyLoaderAllocator* pBinderAssemblyLoaderAllocator = nullptr; - if (pBinderContext != nullptr) { - pBinderContext->GetLoaderAllocator((LPVOID*)&pBinderAssemblyLoaderAllocator); + pBinderAssemblyLoaderAllocator = pBinderContext->GetLoaderAllocator(); } // Create a new LoaderAllocator if appropriate diff --git a/src/coreclr/vm/assembly.hpp b/src/coreclr/vm/assembly.hpp index 3e5447ffffbee..8b51cad630ca6 100644 --- a/src/coreclr/vm/assembly.hpp +++ b/src/coreclr/vm/assembly.hpp @@ -90,7 +90,7 @@ class Assembly BOOL IsSystem() { WRAPPER_NO_CONTRACT; return m_pManifestFile->IsSystem(); } - static Assembly *CreateDynamic(AppDomain *pDomain, ICLRPrivBinder* pBinderContext, CreateDynamicAssemblyArgs *args); + static Assembly *CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderContext, CreateDynamicAssemblyArgs *args); MethodDesc *GetEntryPoint(); diff --git a/src/coreclr/vm/assemblybinder.cpp b/src/coreclr/vm/assemblybinder.cpp new file mode 100644 index 0000000000000..a4fc17669be36 --- /dev/null +++ b/src/coreclr/vm/assemblybinder.cpp @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#include "assemblybinder.h" +#include "../binder/inc/assemblyname.hpp" + +#ifndef DACCESS_COMPILE + +HRESULT AssemblyBinder::BindAssemblyByName(AssemblyNameData* pAssemblyNameData, + BINDER_SPACE::Assembly** ppAssembly) +{ + _ASSERTE(pAssemblyNameData != nullptr && ppAssembly != nullptr); + + HRESULT hr = S_OK; + *ppAssembly = nullptr; + + ReleaseHolder pAssemblyName; + SAFE_NEW(pAssemblyName, BINDER_SPACE::AssemblyName); + IF_FAIL_GO(pAssemblyName->Init(*pAssemblyNameData)); + + hr = BindUsingAssemblyName(pAssemblyName, ppAssembly); + +Exit: + return hr; +} + +#endif //DACCESS_COMPILE diff --git a/src/coreclr/vm/assemblybinder.h b/src/coreclr/vm/assemblybinder.h new file mode 100644 index 0000000000000..42d3a2ceaf9a2 --- /dev/null +++ b/src/coreclr/vm/assemblybinder.h @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#ifndef _ASSEMBLYBINDER_H +#define _ASSEMBLYBINDER_H + +#include "../binder/inc/applicationcontext.hpp" + +class PEImage; +class AssemblyLoaderAllocator; + +class AssemblyBinder +{ +public: + HRESULT BindAssemblyByName(AssemblyNameData* pAssemblyNameData, + BINDER_SPACE::Assembly** ppAssembly); + + virtual HRESULT BindUsingPEImage(PEImage* pPEImage, + BOOL fIsNativeImage, + BINDER_SPACE::Assembly** ppAssembly) = 0; + + virtual HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, + BINDER_SPACE::Assembly** ppAssembly) = 0; + + /********************************************************************************** + ** GetLoaderAllocator + ** Get LoaderAllocator for binders that contain it. For other binders, return NULL. + ** + **********************************************************************************/ + virtual AssemblyLoaderAllocator* GetLoaderAllocator() = 0; + + inline BINDER_SPACE::ApplicationContext* GetAppContext() + { + return &m_appContext; + } + +private: + BINDER_SPACE::ApplicationContext m_appContext; +}; + +#endif diff --git a/src/coreclr/vm/assemblyloadcontext.cpp b/src/coreclr/vm/assemblyloadcontext.cpp index 565292d7fb3d9..33a239c9fdbd7 100644 --- a/src/coreclr/vm/assemblyloadcontext.cpp +++ b/src/coreclr/vm/assemblyloadcontext.cpp @@ -8,14 +8,8 @@ AssemblyLoadContext::AssemblyLoadContext() { } -HRESULT AssemblyLoadContext::GetBinderID( - UINT_PTR* pBinderId) -{ - *pBinderId = reinterpret_cast(this); - return S_OK; -} - #ifndef DACCESS_COMPILE + NativeImage *AssemblyLoadContext::LoadNativeImage(Module *componentModule, LPCUTF8 nativeImageName) { STANDARD_VM_CONTRACT; @@ -39,9 +33,7 @@ NativeImage *AssemblyLoadContext::LoadNativeImage(Module *componentModule, LPCUT return nativeImage; } -#endif -#ifndef DACCESS_COMPILE void AssemblyLoadContext::AddLoadedAssembly(Assembly *loadedAssembly) { BaseDomain::LoadLockHolder lock(AppDomain::GetCurrentDomain()); @@ -51,4 +43,5 @@ void AssemblyLoadContext::AddLoadedAssembly(Assembly *loadedAssembly) m_nativeImages[nativeImageIndex]->CheckAssemblyMvid(loadedAssembly); } } -#endif + +#endif //DACCESS_COMPILE diff --git a/src/coreclr/vm/assemblyloadcontext.h b/src/coreclr/vm/assemblyloadcontext.h index 1ecdd0446d29a..ccbc12a6f7a72 100644 --- a/src/coreclr/vm/assemblyloadcontext.h +++ b/src/coreclr/vm/assemblyloadcontext.h @@ -5,25 +5,23 @@ #define _ASSEMBLYLOADCONTEXT_H #include "crst.h" -#include #include - +#include "assemblybinder.h" class NativeImage; +class PEImage; class Module; class Assembly; +class AssemblyLoaderAllocator; // // Unmanaged counter-part of System.Runtime.Loader.AssemblyLoadContext // -class AssemblyLoadContext : public IUnknownCommon +class AssemblyLoadContext : public AssemblyBinder { public: AssemblyLoadContext(); - STDMETHOD(GetBinderID)( - /* [retval][out] */ UINT_PTR* pBinderId); - NativeImage *LoadNativeImage(Module *componentModule, LPCUTF8 nativeImageName); void AddLoadedAssembly(Assembly *loadedAssembly); diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index 6819867cdd590..63846ce540111 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -30,7 +30,7 @@ #include "appdomainnative.hpp" #include "../binder/inc/bindertracing.h" -#include "../binder/inc/clrprivbindercoreclr.h" +#include "../binder/inc/defaultassemblybinder.h" /* static */ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyName, @@ -54,12 +54,12 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN DomainAssembly * pParentAssembly = NULL; Assembly * pRefAssembly = NULL; - ICLRPrivBinder *pBinderContext = NULL; + AssemblyBinder *pBinderContext = NULL; if (assemblyLoadContext.Get() != NULL) { INT_PTR nativeAssemblyLoadContext = ((ASSEMBLYLOADCONTEXTREF)assemblyLoadContext.Get())->GetNativeAssemblyLoadContext(); - pBinderContext = reinterpret_cast(nativeAssemblyLoadContext); + pBinderContext = reinterpret_cast(nativeAssemblyLoadContext); } AssemblySpec spec; @@ -127,7 +127,7 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN } /* static */ -Assembly* AssemblyNative::LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImage *pILImage, PEImage *pNIImage) +Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinderContext, PEImage *pILImage, PEImage *pNIImage) { CONTRACT(Assembly*) { @@ -139,7 +139,7 @@ Assembly* AssemblyNative::LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImag Assembly *pLoadedAssembly = NULL; - ReleaseHolder pAssembly; + ReleaseHolder pAssembly; // Get the correct PEImage to work with. BOOL fIsNativeImage = TRUE; @@ -180,18 +180,8 @@ Assembly* AssemblyNative::LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImag HRESULT hr = S_OK; PTR_AppDomain pCurDomain = GetAppDomain(); - CLRPrivBinderCoreCLR *pTPABinder = pCurDomain->GetTPABinderContext(); - if (!AreSameBinderInstance(pTPABinder, pBinderContext)) - { - // We are working with custom Assembly Load Context so bind the assembly using it. - CLRPrivBinderAssemblyLoadContext *pBinder = reinterpret_cast(pBinderContext); - hr = pBinder->BindUsingPEImage(pImage, fIsNativeImage, &pAssembly); - } - else - { - // Bind the assembly using TPA binder - hr = pTPABinder->BindUsingPEImage(pImage, fIsNativeImage, &pAssembly); - } + DefaultAssemblyBinder *pTPABinder = pCurDomain->GetTPABinderContext(); + hr = pBinderContext->BindUsingPEImage(pImage, fIsNativeImage, &pAssembly); if (hr != S_OK) { @@ -206,10 +196,7 @@ Assembly* AssemblyNative::LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImag COMPlusThrowHR(COR_E_FILELOAD, dwMessageID, name); } - BINDER_SPACE::Assembly* assem; - assem = BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(pAssembly); - - PEAssemblyHolder pPEAssembly(PEAssembly::Open(pParentAssembly, assem->GetPEImage(), assem->GetNativePEImage(), pAssembly)); + PEAssemblyHolder pPEAssembly(PEAssembly::Open(pParentAssembly, pAssembly->GetPEImage(), pAssembly->GetNativePEImage(), pAssembly)); bindOperation.SetResult(pPEAssembly.GetValue()); DomainAssembly *pDomainAssembly = pCurDomain->LoadDomainAssembly(&spec, pPEAssembly, FILE_LOADED); @@ -226,7 +213,7 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext PTR_AppDomain pCurDomain = GetAppDomain(); // Get the binder context in which the assembly will be loaded. - ICLRPrivBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); _ASSERTE(pBinderContext != NULL); // Form the PEImage for the ILAssembly. Incase of an exception, the holders will ensure @@ -243,8 +230,8 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext if (!pILImage->CheckILFormat()) THROW_BAD_FORMAT(BFA_BAD_IL, pILImage.GetValue()); - LoaderAllocator* pLoaderAllocator = NULL; - if (SUCCEEDED(pBinderContext->GetLoaderAllocator((LPVOID*)&pLoaderAllocator)) && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly()) + LoaderAllocator* pLoaderAllocator = pBinderContext->GetLoaderAllocator(); + if (pLoaderAllocator && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly()) { // Loading IJW assemblies into a collectible AssemblyLoadContext is not allowed THROW_BAD_FORMAT(BFA_IJW_IN_COLLECTIBLE_ALC, pILImage.GetValue()); @@ -315,10 +302,10 @@ void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyLoadConte ThrowHR(COR_E_BADIMAGEFORMAT, BFA_BAD_IL); // Get the binder context in which the assembly will be loaded - ICLRPrivBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); - LoaderAllocator* pLoaderAllocator = NULL; - if (SUCCEEDED(pBinderContext->GetLoaderAllocator((LPVOID*)&pLoaderAllocator)) && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly()) + LoaderAllocator* pLoaderAllocator = pBinderContext->GetLoaderAllocator(); + if (pLoaderAllocator && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly()) { // Loading IJW assemblies into a collectible AssemblyLoadContext is not allowed ThrowHR(COR_E_BADIMAGEFORMAT, BFA_IJW_IN_COLLECTIBLE_ALC); @@ -378,7 +365,7 @@ void QCALLTYPE AssemblyNative::LoadFromInMemoryModule(INT_PTR ptrNativeAssemblyL ThrowHR(COR_E_BADIMAGEFORMAT, BFA_BAD_IL); // Get the binder context in which the assembly will be loaded - ICLRPrivBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); // Pass the in memory module as IL in an attempt to bind and load it Assembly* pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinderContext, pILImage, NULL); @@ -432,7 +419,7 @@ void QCALLTYPE AssemblyNative::GetType(QCall::AssemblyHandle pAssembly, BOOL prohibitAsmQualifiedName = TRUE; - ICLRPrivBinder * pPrivHostBinder = NULL; + AssemblyBinder * pPrivHostBinder = NULL; if (*pAssemblyLoadContext.m_ppObject != NULL) { @@ -441,7 +428,7 @@ void QCALLTYPE AssemblyNative::GetType(QCall::AssemblyHandle pAssembly, INT_PTR nativeAssemblyLoadContext = (*pAssemblyLoadContextRef)->GetNativeAssemblyLoadContext(); - pPrivHostBinder = reinterpret_cast(nativeAssemblyLoadContext); + pPrivHostBinder = reinterpret_cast(nativeAssemblyLoadContext); } // Load the class from this assembly (fail if it is in a different one). @@ -1217,11 +1204,11 @@ INT_PTR QCALLTYPE AssemblyNative::InitializeAssemblyLoadContext(INT_PTR ptrManag // Initialize the assembly binder instance in the VM PTR_AppDomain pCurDomain = AppDomain::GetCurrentDomain(); - CLRPrivBinderCoreCLR *pTPABinderContext = pCurDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pTPABinderContext = pCurDomain->GetTPABinderContext(); if (!fRepresentsTPALoadContext) { // Initialize a custom Assembly Load Context - CLRPrivBinderAssemblyLoadContext *pBindContext = NULL; + CustomAssemblyBinder *pBindContext = NULL; AssemblyLoaderAllocator* loaderAllocator = NULL; OBJECTHANDLE loaderAllocatorHandle = NULL; @@ -1256,7 +1243,7 @@ INT_PTR QCALLTYPE AssemblyNative::InitializeAssemblyLoadContext(INT_PTR ptrManag loaderAllocator->ActivateManagedTracking(); } - IfFailThrow(CLRPrivBinderAssemblyLoadContext::SetupContext(DefaultADID, pTPABinderContext, loaderAllocator, loaderAllocatorHandle, ptrManagedAssemblyLoadContext, &pBindContext)); + IfFailThrow(CustomAssemblyBinder::SetupContext(pTPABinderContext, loaderAllocator, loaderAllocatorHandle, ptrManagedAssemblyLoadContext, &pBindContext)); ptrNativeAssemblyLoadContext = reinterpret_cast(pBindContext); } else @@ -1287,7 +1274,7 @@ void QCALLTYPE AssemblyNative::PrepareForAssemblyLoadContextRelease(INT_PTR ptrN { GCX_COOP(); - reinterpret_cast(ptrNativeAssemblyLoadContext)->PrepareForLoadContextRelease(ptrManagedStrongAssemblyLoadContext); + reinterpret_cast(ptrNativeAssemblyLoadContext)->PrepareForLoadContextRelease(ptrManagedStrongAssemblyLoadContext); } END_QCALL; @@ -1308,9 +1295,9 @@ INT_PTR QCALLTYPE AssemblyNative::GetLoadContextForAssembly(QCall::AssemblyHandl if (pAssemblyLoadContext != AppDomain::GetCurrentDomain()->GetTPABinderContext()) { - // Only CLRPrivBinderAssemblyLoadContext instance contains the reference to its + // Only CustomAssemblyBinder instance contains the reference to its // corresponding managed instance. - CLRPrivBinderAssemblyLoadContext* pBinder = (CLRPrivBinderAssemblyLoadContext*)(pAssemblyLoadContext); + CustomAssemblyBinder* pBinder = (CustomAssemblyBinder*)(pAssemblyLoadContext); // Fetch the managed binder reference from the native binder instance ptrManagedAssemblyLoadContext = pBinder->GetManagedAssemblyLoadContext(); diff --git a/src/coreclr/vm/assemblynative.hpp b/src/coreclr/vm/assemblynative.hpp index 54ca987a86f03..752e0e76c1b5a 100644 --- a/src/coreclr/vm/assemblynative.hpp +++ b/src/coreclr/vm/assemblynative.hpp @@ -15,7 +15,7 @@ #ifndef _ASSEMBLYNATIVE_H #define _ASSEMBLYNATIVE_H -class CLRPrivBinderAssemblyLoadContext; +class CustomAssemblyBinder; class AssemblyNative { @@ -119,7 +119,7 @@ class AssemblyNative #ifndef TARGET_UNIX static void QCALLTYPE LoadFromInMemoryModule(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR hModule, QCall::ObjectHandleOnStack retLoadedAssembly); #endif - static Assembly* LoadFromPEImage(ICLRPrivBinder* pBinderContext, PEImage *pILImage, PEImage *pNIImage); + static Assembly* LoadFromPEImage(AssemblyBinder* pBinderContext, PEImage *pILImage, PEImage *pNIImage); static INT_PTR QCALLTYPE GetLoadContextForAssembly(QCall::AssemblyHandle pAssembly); static BOOL QCALLTYPE InternalTryGetRawMetadata(QCall::AssemblyHandle assembly, UINT8 **blobRef, INT32 *lengthRef); diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index a02966ab8f328..5a802d2d24308 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -238,8 +238,8 @@ void AssemblySpec::InitializeSpec(PEAssembly * pFile) InitializeSpec(a, pImport, NULL); // Set the binding context for the AssemblySpec - ICLRPrivBinder* pCurrentBinder = GetBindingContext(); - ICLRPrivBinder* pExpectedBinder = pFile->GetBindingContext(); + AssemblyBinder* pCurrentBinder = GetBindingContext(); + AssemblyBinder* pExpectedBinder = pFile->GetBindingContext(); if (pCurrentBinder == NULL) { // We should aways having the binding context in the PEAssembly. The only exception to this are the following: @@ -678,34 +678,7 @@ Assembly *AssemblySpec::LoadAssembly(FileLoadLevel targetLevel, BOOL fThrowOnFil return pDomainAssembly->GetAssembly(); } -// Returns a BOOL indicating if the two Binder references point to the same -// binder instance. -BOOL AreSameBinderInstance(ICLRPrivBinder *pBinderA, ICLRPrivBinder *pBinderB) -{ - LIMITED_METHOD_CONTRACT; - - BOOL fIsSameInstance = (pBinderA == pBinderB); - - if (!fIsSameInstance && (pBinderA != NULL) && (pBinderB != NULL)) - { - // Get the ID for the first binder - UINT_PTR binderIDA = 0, binderIDB = 0; - HRESULT hr = pBinderA->GetBinderID(&binderIDA); - if (SUCCEEDED(hr)) - { - // Get the ID for the second binder - hr = pBinderB->GetBinderID(&binderIDB); - if (SUCCEEDED(hr)) - { - fIsSameInstance = (binderIDA == binderIDB); - } - } - } - - return fIsSameInstance; -} - -ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDomain) +AssemblyBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDomain) { CONTRACTL { @@ -716,15 +689,13 @@ ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo } CONTRACTL_END; - ICLRPrivBinder *pParentAssemblyBinder = NULL; + AssemblyBinder *pParentAssemblyBinder = NULL; DomainAssembly *pParentDomainAssembly = GetParentAssembly(); if(pParentDomainAssembly != NULL) { // Get the PEAssembly associated with the parent's domain assembly PEAssembly *pParentPEAssembly = pParentDomainAssembly->GetFile(); - - // ICLRPrivAssembly implements ICLRPrivBinder and thus, "is a" binder in a manner of semantics. pParentAssemblyBinder = pParentPEAssembly->GetBindingContext(); } @@ -755,8 +726,8 @@ ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo if (pParentAssemblyBinder != NULL) { - CLRPrivBinderCoreCLR *pTPABinder = pDomain->GetTPABinderContext(); - if (AreSameBinderInstance(pTPABinder, pParentAssemblyBinder)) + DefaultAssemblyBinder *pTPABinder = pDomain->GetTPABinderContext(); + if (pTPABinder == pParentAssemblyBinder) { // If the parent assembly is a platform (TPA) assembly, then its binding context will always be the TPABinder context. In // such case, we will return the default context for binding to allow the bind to go @@ -764,7 +735,7 @@ ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo // TPABinder context anyways. // // Get the reference to the default binding context (this could be the TPABinder context or custom AssemblyLoadContext) - pParentAssemblyBinder = static_cast(pDomain->GetTPABinderContext()); + pParentAssemblyBinder = static_cast(pDomain->GetTPABinderContext()); } } @@ -775,7 +746,7 @@ ICLRPrivBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo // // In such a case, the parent assembly (semantically) is CoreLibrary and thus, the default binding context should be // used as the parent assembly binder. - pParentAssemblyBinder = static_cast(pDomain->GetTPABinderContext()); + pParentAssemblyBinder = static_cast(pDomain->GetTPABinderContext()); } return pParentAssemblyBinder; @@ -1036,10 +1007,9 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter CONTRACTL_END; UPTR key = (UPTR)pSpec->Hash(); - UPTR lookupKey = key; // On CoreCLR, we will use the BinderID as the key - ICLRPrivBinder *pBinderContextForLookup = NULL; + AssemblyBinder *pBinderContextForLookup = NULL; AppDomain *pSpecDomain = pSpec->GetAppDomain(); bool fGetBindingContextFromParent = true; @@ -1073,13 +1043,10 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter if (pBinderContextForLookup) { - UINT_PTR binderID = 0; - HRESULT hr = pBinderContextForLookup->GetBinderID(&binderID); - _ASSERTE(SUCCEEDED(hr)); - lookupKey = key^binderID; + key = key ^ (UPTR)pBinderContextForLookup; } - AssemblyBinding* pEntry = (AssemblyBinding *)m_map.LookupValue(lookupKey, pSpec); + AssemblyBinding* pEntry = (AssemblyBinding *)m_map.LookupValue(key, pSpec); // Reset the binding context if one was originally never present in the AssemblySpec and we didnt find any entry // in the cache. @@ -1286,15 +1253,12 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly UPTR key = (UPTR)pSpec->Hash(); // On CoreCLR, we will use the BinderID as the key - ICLRPrivBinder* pBinderContextForLookup = pAssembly->GetFile()->GetBindingContext(); + AssemblyBinder* pBinderContextForLookup = pAssembly->GetFile()->GetBindingContext(); _ASSERTE(pBinderContextForLookup || pAssembly->GetFile()->IsSystem()); if (pBinderContextForLookup) { - UINT_PTR binderID = 0; - HRESULT hr = pBinderContextForLookup->GetBinderID(&binderID); - _ASSERTE(SUCCEEDED(hr)); - key = key^binderID; + key = key ^ (UPTR)pBinderContextForLookup; if (!pSpec->GetBindingContext()) { @@ -1371,15 +1335,12 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) UPTR key = (UPTR)pSpec->Hash(); // On CoreCLR, we will use the BinderID as the key - ICLRPrivBinder* pBinderContextForLookup = pFile->GetBindingContext(); + AssemblyBinder* pBinderContextForLookup = pFile->GetBindingContext(); _ASSERTE(pBinderContextForLookup || pFile->IsSystem()); if (pBinderContextForLookup) { - UINT_PTR binderID = 0; - HRESULT hr = pBinderContextForLookup->GetBinderID(&binderID); - _ASSERTE(SUCCEEDED(hr)); - key = key^binderID; + key = key ^ (UPTR)pBinderContextForLookup; if (!pSpec->GetBindingContext()) { @@ -1398,13 +1359,12 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) #ifndef CROSSGEN_COMPILE if (pBinderContextForLookup != NULL) { - LoaderAllocator* pLoaderAllocator = NULL; + LoaderAllocator* pLoaderAllocator = pBinderContextForLookup->GetLoaderAllocator(); // Assemblies loaded with AssemblyLoadContext need to use a different heap if // marked as collectible - if (SUCCEEDED(pBinderContextForLookup->GetLoaderAllocator((LPVOID*)&pLoaderAllocator))) + if (pLoaderAllocator) { - _ASSERTE(pLoaderAllocator != NULL); pHeap = pLoaderAllocator->GetHighFrequencyHeap(); } } @@ -1465,17 +1425,14 @@ BOOL AssemblySpecBindingCache::StoreException(AssemblySpec *pSpec, Exception* pE // // Since no entry was found for this assembly in any binding context, save the failure // in the TPABinder context - ICLRPrivBinder* pBinderToSaveException = NULL; + AssemblyBinder* pBinderToSaveException = NULL; pBinderToSaveException = pSpec->GetBindingContext(); if (pBinderToSaveException == NULL) { if (!pSpec->IsAssemblySpecForCoreLib()) { pBinderToSaveException = pSpec->GetBindingContextFromParentAssembly(pSpec->GetAppDomain()); - UINT_PTR binderID = 0; - HRESULT hr = pBinderToSaveException->GetBinderID(&binderID); - _ASSERTE(SUCCEEDED(hr)); - key = key^binderID; + key = key ^ (UPTR)pBinderToSaveException; } } } diff --git a/src/coreclr/vm/assemblyspec.hpp b/src/coreclr/vm/assemblyspec.hpp index 844e9399e3a57..62730af6b6a1d 100644 --- a/src/coreclr/vm/assemblyspec.hpp +++ b/src/coreclr/vm/assemblyspec.hpp @@ -32,7 +32,7 @@ class AssemblySpec : public BaseAssemblySpec DomainAssembly *m_pParentAssembly; // Contains the reference to the fallback load context associated with RefEmitted assembly requesting the load of another assembly (static or dynamic) - ICLRPrivBinder *m_pFallbackLoadContextBinder; + AssemblyBinder *m_pFallbackLoadContextBinder; // Flag to indicate if we should prefer the fallback load context binder for binding or not. bool m_fPreferFallbackLoadContextBinder; @@ -50,7 +50,7 @@ class AssemblySpec : public BaseAssemblySpec mdAssemblyRef kAssemblyRef, IMDInternalImport * pMDImportOverride, BOOL fDoNotUtilizeExtraChecks, - ICLRPrivBinder *pBindingContextForLoadedAssembly); + AssemblyBinder *pBindingContextForLoadedAssembly); public: @@ -79,7 +79,7 @@ class AssemblySpec : public BaseAssemblySpec DomainAssembly* GetParentAssembly(); - ICLRPrivBinder* GetBindingContextFromParentAssembly(AppDomain *pDomain); + AssemblyBinder* GetBindingContextFromParentAssembly(AppDomain *pDomain); bool HasParentAssembly() { WRAPPER_NO_CONTRACT; return GetParentAssembly() != NULL; } @@ -130,14 +130,14 @@ class AssemblySpec : public BaseAssemblySpec m_pParentAssembly = pAssembly; } - void SetFallbackLoadContextBinderForRequestingAssembly(ICLRPrivBinder *pFallbackLoadContextBinder) + void SetFallbackLoadContextBinderForRequestingAssembly(AssemblyBinder *pFallbackLoadContextBinder) { LIMITED_METHOD_CONTRACT; m_pFallbackLoadContextBinder = pFallbackLoadContextBinder; } - ICLRPrivBinder* GetFallbackLoadContextBinderForRequestingAssembly() + AssemblyBinder* GetFallbackLoadContextBinderForRequestingAssembly() { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/baseassemblyspec.h b/src/coreclr/vm/baseassemblyspec.h index c2111b647c58a..b8eb1a9b1daf7 100644 --- a/src/coreclr/vm/baseassemblyspec.h +++ b/src/coreclr/vm/baseassemblyspec.h @@ -27,7 +27,7 @@ class BaseAssemblySpec DWORD m_dwFlags; // CorAssemblyFlags LPCWSTR m_wszCodeBase; // URL to the code int m_ownedFlags; - ICLRPrivBinder *m_pBindingContext; + AssemblyBinder *m_pBindingContext; public: enum @@ -63,14 +63,14 @@ class BaseAssemblySpec VOID CloneFieldsToLoaderHeap(int flags, LoaderHeap *pHeap, AllocMemTracker *pamTracker); VOID CloneFieldsToStackingAllocator(StackingAllocator* alloc); - inline void SetBindingContext(ICLRPrivBinder *pBindingContext) + inline void SetBindingContext(AssemblyBinder *pBindingContext) { LIMITED_METHOD_CONTRACT; m_pBindingContext = pBindingContext; } - inline ICLRPrivBinder* GetBindingContext() + inline AssemblyBinder* GetBindingContext() { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/baseassemblyspec.inl b/src/coreclr/vm/baseassemblyspec.inl index e90d2f0d9eec1..5f92ea82cf252 100644 --- a/src/coreclr/vm/baseassemblyspec.inl +++ b/src/coreclr/vm/baseassemblyspec.inl @@ -14,8 +14,6 @@ #ifndef __BASE_ASSEMBLY_SPEC_INL__ #define __BASE_ASSEMBLY_SPEC_INL__ -BOOL AreSameBinderInstance(ICLRPrivBinder *pBinderA, ICLRPrivBinder *pBinderB); - inline int BaseAssemblySpec::CompareStrings(LPCUTF8 string1, LPCUTF8 string2) { WRAPPER_NO_CONTRACT; @@ -322,7 +320,7 @@ inline BOOL BaseAssemblySpec::CompareEx(BaseAssemblySpec *pSpec, DWORD dwCompare // If the assemblySpec contains the binding context, then check if they match. if (!(pSpec->IsAssemblySpecForCoreLib() && IsAssemblySpecForCoreLib())) { - if (!AreSameBinderInstance(pSpec->m_pBindingContext, m_pBindingContext)) + if (pSpec->m_pBindingContext != m_pBindingContext) { return FALSE; } diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 8af16d073d7a0..2af488d2d7d06 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -4259,7 +4259,7 @@ Module::GetAssemblyIfLoaded( mdAssemblyRef kAssemblyRef, IMDInternalImport * pMDImportOverride, // = NULL BOOL fDoNotUtilizeExtraChecks, // = FALSE - ICLRPrivBinder *pBindingContextForLoadedAssembly // = NULL + AssemblyBinder *pBindingContextForLoadedAssembly // = NULL ) { CONTRACT(Assembly *) @@ -4579,7 +4579,7 @@ DomainAssembly * Module::LoadAssembly(mdAssemblyRef kAssemblyRef) // Set the binding context in the AssemblySpec if one is available. This can happen if the LoadAssembly ended up // invoking the custom AssemblyLoadContext implementation that returned a reference to an assembly bound to a different // AssemblyLoadContext implementation. - ICLRPrivBinder *pBindingContext = pFile->GetBindingContext(); + AssemblyBinder *pBindingContext = pFile->GetBindingContext(); if (pBindingContext != NULL) { spec.SetBindingContext(pBindingContext); @@ -4592,7 +4592,7 @@ DomainAssembly * Module::LoadAssembly(mdAssemblyRef kAssemblyRef) _ASSERTE( pDomainAssembly->IsSystem() || // GetAssemblyIfLoaded will not find CoreLib (see AppDomain::FindCachedFile) !pDomainAssembly->IsLoaded() || // GetAssemblyIfLoaded will not find not-yet-loaded assemblies - GetAssemblyIfLoaded(kAssemblyRef, NULL, FALSE, pDomainAssembly->GetFile()->GetHostAssembly()) != NULL); // GetAssemblyIfLoaded should find all remaining cases + GetAssemblyIfLoaded(kAssemblyRef, NULL, FALSE, pDomainAssembly->GetFile()->GetHostAssembly()->GetBinder()) != NULL); // GetAssemblyIfLoaded should find all remaining cases if (pDomainAssembly->GetCurrentAssembly() != NULL) { diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 8127e369d1d34..92547019c5721 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -1970,7 +1970,7 @@ class Module mdAssemblyRef kAssemblyRef, IMDInternalImport * pMDImportOverride = NULL, BOOL fDoNotUtilizeExtraChecks = FALSE, - ICLRPrivBinder *pBindingContextForLoadedAssembly = NULL + AssemblyBinder *pBindingContextForLoadedAssembly = NULL ); private: diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 6709eed495b95..dc0b00779ae19 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -26,7 +26,7 @@ #include "../binder/inc/assembly.hpp" #include "../binder/inc/assemblyname.hpp" -#include "../binder/inc/coreclrbindercommon.h" +#include "../binder/inc/assemblybindercommon.hpp" #include "../binder/inc/applicationcontext.hpp" STDAPI BinderAddRefPEImage(PEImage *pPEImage) @@ -68,7 +68,7 @@ static VOID ThrowLoadError(AssemblySpec * pSpec, HRESULT hr) EEFileLoadException::Throw(name, hr); } -// See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind +// See code:BINDER_SPACE::AssemblyBinderCommon::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. VOID AssemblySpec::Bind(AppDomain *pAppDomain, @@ -93,12 +93,12 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, pResult->Reset(); // Have a default binding context setup - ICLRPrivBinder *pBinder = GetBindingContextFromParentAssembly(pAppDomain); + AssemblyBinder *pBinder = GetBindingContextFromParentAssembly(pAppDomain); // Get the reference to the TPABinder context - CLRPrivBinderCoreCLR *pTPABinder = pAppDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pTPABinder = pAppDomain->GetTPABinderContext(); - ReleaseHolder pPrivAsm; + ReleaseHolder pPrivAsm; _ASSERTE(pBinder != NULL); if (m_wszCodeBase == NULL && IsCoreLibSatellite()) @@ -118,7 +118,7 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, tmpString.ConvertToUnicode(sCultureName); } - hr = CCoreCLRBinderHelper::BindToSystemSatellite(sSystemDirectory, sSimpleName, sCultureName, &pPrivAsm); + hr = BINDER_SPACE::AssemblyBinderCommon::BindToSystemSatellite(sSystemDirectory, sSimpleName, sCultureName, &pPrivAsm); } else if (m_wszCodeBase == NULL) { @@ -142,7 +142,7 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, { _ASSERTE(pPrivAsm != nullptr); - result = BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(pPrivAsm.Extract()); + result = pPrivAsm.Extract(); _ASSERTE(result != nullptr); pResult->Init(result); @@ -308,13 +308,13 @@ HRESULT BaseAssemblySpec::ParseName() _ASSERTE(pDomain); BINDER_SPACE::ApplicationContext *pAppContext = NULL; - CLRPrivBinderCoreCLR *pBinder = pDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pBinder = pDomain->GetTPABinderContext(); if (pBinder != NULL) { pAppContext = pBinder->GetAppContext(); } - hr = CCoreCLRBinderHelper::GetAssemblyIdentity(m_pAssemblyName, pAppContext, pAssemblyIdentity); + hr = BINDER_SPACE::AssemblyBinderCommon::GetAssemblyIdentity(m_pAssemblyName, pAppContext, pAssemblyIdentity); if (FAILED(hr)) { diff --git a/src/coreclr/vm/coreclr/corebindresult.h b/src/coreclr/vm/coreclr/corebindresult.h index 3c8b1cb282c18..d47f84eb498da 100644 --- a/src/coreclr/vm/coreclr/corebindresult.h +++ b/src/coreclr/vm/coreclr/corebindresult.h @@ -19,7 +19,7 @@ struct CoreBindResult : public IUnknown { protected: - ReleaseHolder m_pAssembly; + ReleaseHolder m_pAssembly; HRESULT m_hrBindResult; LONG m_cRef; @@ -35,13 +35,13 @@ struct CoreBindResult : public IUnknown CoreBindResult() : m_cRef(1) {} virtual ~CoreBindResult() {} - void Init(ICLRPrivAssembly* pAssembly); + void Init(BINDER_SPACE::Assembly* pAssembly); void Reset(); BOOL Found(); PEImage* GetPEImage(); BOOL IsCoreLib(); - void GetBindAssembly(ICLRPrivAssembly** ppAssembly); + void GetBindAssembly(BINDER_SPACE::Assembly** ppAssembly); #ifdef FEATURE_PREJIT BOOL HasNativeImage(); PEImage* GetNativeImage(); diff --git a/src/coreclr/vm/coreclr/corebindresult.inl b/src/coreclr/vm/coreclr/corebindresult.inl index 10f367b3f4839..c40f3810d23dc 100644 --- a/src/coreclr/vm/coreclr/corebindresult.inl +++ b/src/coreclr/vm/coreclr/corebindresult.inl @@ -28,15 +28,14 @@ inline BOOL CoreBindResult::IsCoreLib() } CONTRACTL_END; - BINDER_SPACE::Assembly* pAssembly = BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(m_pAssembly); #ifndef CROSSGEN_COMPILE - return pAssembly->GetAssemblyName()->IsCoreLib(); + return m_pAssembly->GetAssemblyName()->IsCoreLib(); #else - return (pAssembly->GetPath()).EndsWithCaseInsensitive(SString(CoreLibName_IL_W)); + return (m_pAssembly->GetPath()).EndsWithCaseInsensitive(SString(CoreLibName_IL_W)); #endif } -inline void CoreBindResult::GetBindAssembly(ICLRPrivAssembly** ppAssembly) +inline void CoreBindResult::GetBindAssembly(BINDER_SPACE::Assembly** ppAssembly) { CONTRACTL { @@ -54,10 +53,12 @@ inline void CoreBindResult::GetBindAssembly(ICLRPrivAssembly** ppAssembly) inline PEImage* CoreBindResult::GetPEImage() { WRAPPER_NO_CONTRACT; - return m_pAssembly?BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(m_pAssembly)->GetNativeOrILPEImage():NULL; + return m_pAssembly ? + m_pAssembly->GetNativeOrILPEImage() : + NULL; }; -inline void CoreBindResult::Init(ICLRPrivAssembly* pAssembly) +inline void CoreBindResult::Init(BINDER_SPACE::Assembly* pAssembly) { WRAPPER_NO_CONTRACT; m_pAssembly=pAssembly; @@ -76,21 +77,21 @@ inline void CoreBindResult::Reset() inline BOOL CoreBindResult::HasNativeImage() { LIMITED_METHOD_CONTRACT; - BINDER_SPACE::Assembly* pAssembly = BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(m_pAssembly); - return pAssembly->GetNativePEImage() != NULL; + return m_pAssembly->GetNativePEImage() != NULL; } inline PEImage* CoreBindResult::GetNativeImage() { WRAPPER_NO_CONTRACT; _ASSERTE(HasNativeImage()); - BINDER_SPACE::Assembly* pAssembly = BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(m_pAssembly); - return pAssembly->GetNativePEImage(); + return m_pAssembly->GetNativePEImage(); } inline PEImage* CoreBindResult::GetILImage() { WRAPPER_NO_CONTRACT; - return m_pAssembly?BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(m_pAssembly)->GetPEImage():NULL; + return m_pAssembly ? + m_pAssembly->GetPEImage(): + NULL; }; #endif diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index 689cf04c89a5a..a7ae3d3445753 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -681,7 +681,7 @@ HRESULT CorHost2::CreateAppDomainWithManager( SString sAppPaths(pwzAppPaths); SString sAppNiPaths(pwzAppNiPaths); - CLRPrivBinderCoreCLR *pBinder = pDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pBinder = pDomain->GetTPABinderContext(); _ASSERTE(pBinder != NULL); IfFailThrow(pBinder->SetupBindingPaths( sTrustedPlatformAssemblies, diff --git a/src/coreclr/vm/domainfile.cpp b/src/coreclr/vm/domainfile.cpp index aed24620fd0d9..646bc10fee119 100644 --- a/src/coreclr/vm/domainfile.cpp +++ b/src/coreclr/vm/domainfile.cpp @@ -1237,7 +1237,7 @@ void DomainAssembly::Begin() AppDomain::LoadLockHolder lock(m_pDomain); m_pDomain->AddAssembly(this); } - // Make it possible to find this DomainAssembly object from associated ICLRPrivAssembly. + // Make it possible to find this DomainAssembly object from associated BINDER_SPACE::Assembly. GetAppDomain()->PublishHostedAssembly(this); m_fHostAssemblyPublished = true; } @@ -1738,7 +1738,7 @@ BOOL DomainAssembly::CheckZapDependencyIdentities(PEImage *pNativeImage) // We just initialized the assembly spec for the NI dependency. This will not have binding context // associated with it, so set it from that of the parent. _ASSERTE(!name.GetBindingContext()); - ICLRPrivBinder *pParentAssemblyBindingContext = name.GetBindingContextFromParentAssembly(name.GetAppDomain()); + AssemblyBinder *pParentAssemblyBindingContext = name.GetBindingContextFromParentAssembly(name.GetAppDomain()); _ASSERTE(pParentAssemblyBindingContext); name.SetBindingContext(pParentAssemblyBindingContext); } diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index 08ef69c1281ac..fe3444fb62469 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -1701,7 +1701,7 @@ AssemblyLoaderAllocator::~AssemblyLoaderAllocator() { if (m_binderToRelease != NULL) { - VERIFY(m_binderToRelease->Release() == 0); + delete m_binderToRelease; m_binderToRelease = NULL; } @@ -1709,7 +1709,7 @@ AssemblyLoaderAllocator::~AssemblyLoaderAllocator() m_pShuffleThunkCache = NULL; } -void AssemblyLoaderAllocator::RegisterBinder(CLRPrivBinderAssemblyLoadContext* binderToRelease) +void AssemblyLoaderAllocator::RegisterBinder(CustomAssemblyBinder* binderToRelease) { // When the binder is registered it will be released by the destructor // of this instance diff --git a/src/coreclr/vm/loaderallocator.hpp b/src/coreclr/vm/loaderallocator.hpp index 55abbd74c2f3c..326378476fca7 100644 --- a/src/coreclr/vm/loaderallocator.hpp +++ b/src/coreclr/vm/loaderallocator.hpp @@ -37,7 +37,7 @@ enum LoaderAllocatorType typedef SHash> LoaderAllocatorSet; -class CLRPrivBinderAssemblyLoadContext; +class CustomAssemblyBinder; // Iterator over a DomainAssembly in the same ALC class DomainAssemblyIterator @@ -731,12 +731,12 @@ class AssemblyLoaderAllocator : public LoaderAllocator virtual void RegisterHandleForCleanup(OBJECTHANDLE objHandle); virtual void UnregisterHandleFromCleanup(OBJECTHANDLE objHandle); virtual void CleanupHandles(); - CLRPrivBinderAssemblyLoadContext* GetBinder() + CustomAssemblyBinder* GetBinder() { return m_binderToRelease; } virtual ~AssemblyLoaderAllocator(); - void RegisterBinder(CLRPrivBinderAssemblyLoadContext* binderToRelease); + void RegisterBinder(CustomAssemblyBinder* binderToRelease); virtual void ReleaseManagedAssemblyLoadContext(); #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) @@ -754,7 +754,7 @@ class AssemblyLoaderAllocator : public LoaderAllocator SList m_handleCleanupList; #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - CLRPrivBinderAssemblyLoadContext* m_binderToRelease; + CustomAssemblyBinder* m_binderToRelease; #endif }; diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index 380a007c78085..2b6abc881561b 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -1164,7 +1164,7 @@ void MulticoreJitManager::SetProfileRoot(const WCHAR * pProfilePath) // API Function: StartProfile // Threading: protected by m_playerLock -void MulticoreJitManager::StartProfile(AppDomain * pDomain, ICLRPrivBinder *pBinderContext, const WCHAR * pProfile, int suffix) +void MulticoreJitManager::StartProfile(AppDomain * pDomain, AssemblyBinder *pBinderContext, const WCHAR * pProfile, int suffix) { CONTRACTL { @@ -1569,7 +1569,7 @@ void QCALLTYPE MultiCoreJITNative::InternalStartProfile(__in_z LPCWSTR wszProfil AppDomain * pDomain = GetAppDomain(); - ICLRPrivBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); pDomain->GetMulticoreJitManager().StartProfile( pDomain, diff --git a/src/coreclr/vm/multicorejit.h b/src/coreclr/vm/multicorejit.h index 58656ec21fd21..eeda366f9ae27 100644 --- a/src/coreclr/vm/multicorejit.h +++ b/src/coreclr/vm/multicorejit.h @@ -258,7 +258,7 @@ class MulticoreJitManager void SetProfileRoot(const WCHAR * pProfilePath); // Multicore JIT API function: StartProfile - void StartProfile(AppDomain * pDomain, ICLRPrivBinder * pBinderContext, const WCHAR * pProfile, int suffix = -1); + void StartProfile(AppDomain * pDomain, AssemblyBinder * pBinderContext, const WCHAR * pProfile, int suffix = -1); // Multicore JIT API function (internal): AbortProfile void AbortProfile(); diff --git a/src/coreclr/vm/multicorejitimpl.h b/src/coreclr/vm/multicorejitimpl.h index d1f05816788f2..50954681f901b 100644 --- a/src/coreclr/vm/multicorejitimpl.h +++ b/src/coreclr/vm/multicorejitimpl.h @@ -274,7 +274,7 @@ class MulticoreJitProfilePlayer friend class MulticoreJitRecorder; private: - ICLRPrivBinder * m_pBinderContext; + AssemblyBinder * m_pBinderContext; LONG m_nMySession; unsigned m_nStartTime; BYTE * m_pFileBuffer; @@ -319,7 +319,7 @@ friend class MulticoreJitRecorder; public: - MulticoreJitProfilePlayer(ICLRPrivBinder * pBinderContext, LONG nSession); + MulticoreJitProfilePlayer(AssemblyBinder * pBinderContext, LONG nSession); ~MulticoreJitProfilePlayer(); @@ -614,7 +614,7 @@ class MulticoreJitRecorder { private: AppDomain * m_pDomain; // AutoStartProfile could be called from SystemDomain - ICLRPrivBinder * m_pBinderContext; + AssemblyBinder * m_pBinderContext; SString m_fullFileName; MulticoreJitPlayerStat & m_stats; @@ -655,7 +655,7 @@ class MulticoreJitRecorder public: - MulticoreJitRecorder(AppDomain * pDomain, ICLRPrivBinder * pBinderContext, bool fRecorderActive) + MulticoreJitRecorder(AppDomain * pDomain, AssemblyBinder * pBinderContext, bool fRecorderActive) : m_stats(pDomain->GetMulticoreJitManager().GetStats()) , m_ModuleList(nullptr) , m_JitInfoArray(nullptr) diff --git a/src/coreclr/vm/multicorejitplayer.cpp b/src/coreclr/vm/multicorejitplayer.cpp index a26e981bb0c6a..04d9bd35c57e2 100644 --- a/src/coreclr/vm/multicorejitplayer.cpp +++ b/src/coreclr/vm/multicorejitplayer.cpp @@ -360,7 +360,7 @@ bool ModuleRecord::MatchWithModule(ModuleVersion & modVersion, bool & gotVersion } -MulticoreJitProfilePlayer::MulticoreJitProfilePlayer(ICLRPrivBinder * pBinderContext, LONG nSession) +MulticoreJitProfilePlayer::MulticoreJitProfilePlayer(AssemblyBinder * pBinderContext, LONG nSession) : m_stats(::GetAppDomain()->GetMulticoreJitManager().GetStats()), m_appdomainSession(::GetAppDomain()->GetMulticoreJitManager().GetProfileSession()) { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index 8a894f2a115f0..b7fc2dace34eb 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -319,10 +319,10 @@ namespace NATIVE_LIBRARY_HANDLE hmod = NULL; AppDomain* pDomain = GetAppDomain(); - CLRPrivBinderCoreCLR *pTPABinder = pDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pTPABinder = pDomain->GetTPABinderContext(); PEFile *pManifestFile = pAssembly->GetManifestFile(); - PTR_ICLRPrivBinder pBindingContext = pManifestFile->GetBindingContext(); + PTR_AssemblyBinder pBindingContext = pManifestFile->GetBindingContext(); //Step 0: Check if the assembly was bound using TPA. // The Binding Context can be null or an overridden TPA context @@ -332,13 +332,10 @@ namespace return NULL; } - UINT_PTR assemblyBinderID = 0; - IfFailThrow(pBindingContext->GetBinderID(&assemblyBinderID)); - - ICLRPrivBinder *pCurrentBinder = reinterpret_cast(assemblyBinderID); + AssemblyBinder *pCurrentBinder = pBindingContext; // For assemblies bound via TPA binder, we should use the standard mechanism to make the pinvoke call. - if (AreSameBinderInstance(pCurrentBinder, pTPABinder)) + if (pCurrentBinder == pTPABinder) { return NULL; } @@ -355,7 +352,7 @@ namespace GCPROTECT_BEGIN(pUnmanagedDllName); // Get the pointer to the managed assembly load context - INT_PTR ptrManagedAssemblyLoadContext = ((CLRPrivBinderAssemblyLoadContext *)pCurrentBinder)->GetManagedAssemblyLoadContext(); + INT_PTR ptrManagedAssemblyLoadContext = ((CustomAssemblyBinder *)pCurrentBinder)->GetManagedAssemblyLoadContext(); // Prepare to invoke System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll method. PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUNMANAGEDDLL); @@ -376,28 +373,14 @@ namespace { STANDARD_VM_CONTRACT; - PTR_ICLRPrivBinder pBindingContext = pAssembly->GetManifestFile()->GetBindingContext(); + PTR_AssemblyBinder pBindingContext = pAssembly->GetManifestFile()->GetBindingContext(); if (pBindingContext == NULL) { // GetBindingContext() returns NULL for System.Private.CoreLib return NULL; } - UINT_PTR assemblyBinderID = 0; - IfFailThrow(pBindingContext->GetBinderID(&assemblyBinderID)); - - AppDomain *pDomain = GetAppDomain(); - ICLRPrivBinder *pCurrentBinder = reinterpret_cast(assemblyBinderID); - - // The code here deals with two implementations of ICLRPrivBinder interface: - // - CLRPrivBinderCoreCLR for the TPA binder in the default ALC, and - // - CLRPrivBinderAssemblyLoadContext for custom ALCs. - // in order obtain the associated ALC handle. - INT_PTR ptrManagedAssemblyLoadContext = AreSameBinderInstance(pCurrentBinder, pDomain->GetTPABinderContext()) - ? ((CLRPrivBinderCoreCLR *)pCurrentBinder)->GetManagedAssemblyLoadContext() - : ((CLRPrivBinderAssemblyLoadContext *)pCurrentBinder)->GetManagedAssemblyLoadContext(); - - return ptrManagedAssemblyLoadContext; + return ((AssemblyLoadContext*)pBindingContext)->GetManagedAssemblyLoadContext(); } NATIVE_LIBRARY_HANDLE LoadNativeLibraryViaAssemblyLoadContextEvent(Assembly * pAssembly, PCWSTR wszLibName) diff --git a/src/coreclr/vm/pefile.cpp b/src/coreclr/vm/pefile.cpp index 31af194be166d..3fd27bcfc5763 100644 --- a/src/coreclr/vm/pefile.cpp +++ b/src/coreclr/vm/pefile.cpp @@ -20,8 +20,8 @@ #include "../binder/inc/applicationcontext.hpp" -#include "clrprivbinderutil.h" -#include "../binder/inc/coreclrbindercommon.h" +#include "assemblybinderutil.h" +#include "../binder/inc/assemblybindercommon.hpp" #include "sha1.h" @@ -402,17 +402,11 @@ BOOL PEFile::Equals(PEFile *pFile) // because another thread beats it; the losing thread will pick up the PEAssembly in the cache. if (pFile->HasHostAssembly() && this->HasHostAssembly()) { - UINT_PTR fileBinderId = 0; - if (FAILED(pFile->GetHostAssembly()->GetBinderID(&fileBinderId))) - return FALSE; - - UINT_PTR thisBinderId = 0; - if (FAILED(this->GetHostAssembly()->GetBinderID(&thisBinderId))) - return FALSE; + AssemblyBinder* fileBinderId = pFile->GetHostAssembly()->GetBinder(); + AssemblyBinder* thisBinderId = this->GetHostAssembly()->GetBinder(); - if (fileBinderId != thisBinderId) + if (fileBinderId != thisBinderId || fileBinderId == NULL) return FALSE; - } // Same identity is equal @@ -1757,7 +1751,7 @@ PEAssembly::PEAssembly( BOOL system, PEImage * pPEImageIL /*= NULL*/, PEImage * pPEImageNI /*= NULL*/, - ICLRPrivAssembly * pHostAssembly /*= NULL*/) + BINDER_SPACE::Assembly * pHostAssembly /*= NULL*/) : PEFile(pBindResultInfo ? (pBindResultInfo->GetPEImage() ? pBindResultInfo->GetPEImage() : (pBindResultInfo->HasNativeImage() ? pBindResultInfo->GetNativeImage() : NULL) @@ -1849,7 +1843,7 @@ PEAssembly *PEAssembly::Open( PEAssembly * pParent, PEImage * pPEImageIL, PEImage * pPEImageNI, - ICLRPrivAssembly * pHostAssembly) + BINDER_SPACE::Assembly * pHostAssembly) { STANDARD_VM_CONTRACT; @@ -1920,8 +1914,8 @@ PEAssembly *PEAssembly::DoOpenSystem(IUnknown * pAppCtx) ETWOnStartup (FusionBinding_V1, FusionBindingEnd_V1); CoreBindResult bindResult; - ReleaseHolder pPrivAsm; - IfFailThrow(CCoreCLRBinderHelper::BindToSystem(&pPrivAsm, !IsCompilationProcess() || g_fAllowNativeImages)); + ReleaseHolder pPrivAsm; + IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::BindToSystem(&pPrivAsm, !IsCompilationProcess() || g_fAllowNativeImages)); if(pPrivAsm != NULL) { bindResult.Init(pPrivAsm); @@ -2262,19 +2256,10 @@ void PEFile::EnsureImageOpened() void PEFile::SetupAssemblyLoadContext() { - PTR_ICLRPrivBinder pBindingContext = GetBindingContext(); - ICLRPrivBinder* pOpaqueBinder = NULL; - - if (pBindingContext != NULL) - { - UINT_PTR assemblyBinderID = 0; - IfFailThrow(pBindingContext->GetBinderID(&assemblyBinderID)); + PTR_AssemblyBinder pBindingContext = GetBindingContext(); - pOpaqueBinder = reinterpret_cast(assemblyBinderID); - } - - m_pAssemblyLoadContext = (pOpaqueBinder != NULL) ? - (AssemblyLoadContext*)pOpaqueBinder : + m_pAssemblyLoadContext = (pBindingContext != NULL) ? + (AssemblyLoadContext*)pBindingContext : AppDomain::GetCurrentDomain()->CreateBinderContext(); } @@ -2383,21 +2368,25 @@ TADDR PEFile::GetMDInternalRWAddress() } #endif -// Returns the ICLRPrivBinder* instance associated with the PEFile -PTR_ICLRPrivBinder PEFile::GetBindingContext() +// Returns the AssemblyBinder* instance associated with the PEFile +PTR_AssemblyBinder PEFile::GetBindingContext() { LIMITED_METHOD_CONTRACT; - PTR_ICLRPrivBinder pBindingContext = NULL; + PTR_AssemblyBinder pBindingContext = NULL; // CoreLibrary is always bound in context of the TPA Binder. However, since it gets loaded and published // during EEStartup *before* DefaultContext Binder (aka TPAbinder) is initialized, we dont have a binding context to publish against. if (!IsSystem()) { - pBindingContext = dac_cast(GetHostAssembly()); - if (!pBindingContext) + BINDER_SPACE::Assembly* pHostAssembly = GetHostAssembly(); + if (pHostAssembly) + { + pBindingContext = dac_cast(pHostAssembly->GetBinder()); + } + else { - // If we do not have any binding context, check if we are dealing with + // If we do not have a host assembly, check if we are dealing with // a dynamically emitted assembly and if so, use its fallback load context // binder reference. if (IsDynamic()) diff --git a/src/coreclr/vm/pefile.h b/src/coreclr/vm/pefile.h index 806e536a92c61..1c7ddfd236cdc 100644 --- a/src/coreclr/vm/pefile.h +++ b/src/coreclr/vm/pefile.h @@ -32,7 +32,7 @@ #include "slist.h" #include "eventtrace.h" -#include "clrprivbinderutil.h" +#include "assemblybinderutil.h" // -------------------------------------------------------------------------------- // Forward declared classes @@ -539,7 +539,7 @@ class PEFile void ConvertMDInternalToReadWrite(); protected: - PTR_ICLRPrivAssembly m_pHostAssembly; + PTR_BINDER_SPACE_Assembly m_pHostAssembly; // For certain assemblies, we do not have m_pHostAssembly since they are not bound using an actual binder. // An example is Ref-Emitted assemblies. Thus, when such assemblies trigger load of their dependencies, @@ -548,30 +548,30 @@ class PEFile // To enable this, we maintain a concept of "Fallback LoadContext", which will be set to the Binder of the // assembly that created the dynamic assembly. If the creator assembly is dynamic itself, then its fallback // load context would be propagated to the assembly being dynamically generated. - PTR_ICLRPrivBinder m_pFallbackLoadContextBinder; + PTR_AssemblyBinder m_pFallbackLoadContextBinder; protected: #ifndef DACCESS_COMPILE - void SetHostAssembly(ICLRPrivAssembly * pHostAssembly) + void SetHostAssembly(BINDER_SPACE::Assembly * pHostAssembly) { LIMITED_METHOD_CONTRACT; m_pHostAssembly = clr::SafeAddRef(pHostAssembly); } #endif //DACCESS_COMPILE public: - // Returns a non-AddRef'ed ICLRPrivAssembly* - PTR_ICLRPrivAssembly GetHostAssembly() + // Returns a non-AddRef'ed BINDER_SPACE::Assembly* + PTR_BINDER_SPACE_Assembly GetHostAssembly() { STATIC_CONTRACT_LIMITED_METHOD; return m_pHostAssembly; } - // Returns the ICLRPrivBinder* instance associated with the PEFile - PTR_ICLRPrivBinder GetBindingContext(); + // Returns the AssemblyBinder* instance associated with the PEFile + PTR_AssemblyBinder GetBindingContext(); #ifndef DACCESS_COMPILE void SetupAssemblyLoadContext(); - void SetFallbackLoadContextBinder(PTR_ICLRPrivBinder pFallbackLoadContextBinder) + void SetFallbackLoadContextBinder(PTR_AssemblyBinder pFallbackLoadContextBinder) { LIMITED_METHOD_CONTRACT; m_pFallbackLoadContextBinder = pFallbackLoadContextBinder; @@ -592,7 +592,7 @@ class PEFile bool HasHostAssembly() { STATIC_CONTRACT_WRAPPER; return GetHostAssembly() != nullptr; } - PTR_ICLRPrivBinder GetFallbackLoadContextBinder() + PTR_AssemblyBinder GetFallbackLoadContextBinder() { LIMITED_METHOD_CONTRACT; @@ -621,7 +621,7 @@ class PEAssembly : public PEFile PEAssembly * pParent, PEImage * pPEImageIL, PEImage * pPEImageNI, - ICLRPrivAssembly * pHostAssembly); + BINDER_SPACE::Assembly * pHostAssembly); // This opens the canonical System.Private.CoreLib.dll static PEAssembly *OpenSystem(IUnknown *pAppCtx); @@ -698,7 +698,7 @@ class PEAssembly : public PEFile BOOL system, PEImage * pPEImageIL = NULL, PEImage * pPEImageNI = NULL, - ICLRPrivAssembly * pHostAssembly = NULL + BINDER_SPACE::Assembly * pHostAssembly = NULL ); virtual ~PEAssembly(); #endif diff --git a/src/coreclr/vm/pefile.inl b/src/coreclr/vm/pefile.inl index a689bdaec03d9..a4faf63922672 100644 --- a/src/coreclr/vm/pefile.inl +++ b/src/coreclr/vm/pefile.inl @@ -100,7 +100,7 @@ inline ULONG PEAssembly::HashIdentity() GC_TRIGGERS; } CONTRACTL_END; - return BINDER_SPACE::GetAssemblyFromPrivAssemblyFast(m_pHostAssembly)->GetAssemblyName()->Hash(BINDER_SPACE::AssemblyName::INCLUDE_VERSION); + return m_pHostAssembly->GetAssemblyName()->Hash(BINDER_SPACE::AssemblyName::INCLUDE_VERSION); } inline void PEFile::ValidateForExecution() diff --git a/src/coreclr/vm/runtimehandles.cpp b/src/coreclr/vm/runtimehandles.cpp index 62d27295861b3..a5037ba71517b 100644 --- a/src/coreclr/vm/runtimehandles.cpp +++ b/src/coreclr/vm/runtimehandles.cpp @@ -1444,7 +1444,7 @@ void QCALLTYPE RuntimeTypeHandle::GetTypeByName(LPCWSTR pwzClassName, BOOL bThro COMPlusThrowArgumentNull(W("className"),W("ArgumentNull_String")); { - ICLRPrivBinder * pPrivHostBinder = NULL; + AssemblyBinder * pPrivHostBinder = NULL; if (*pAssemblyLoadContext.m_ppObject != NULL) { @@ -1453,7 +1453,7 @@ void QCALLTYPE RuntimeTypeHandle::GetTypeByName(LPCWSTR pwzClassName, BOOL bThro INT_PTR nativeAssemblyLoadContext = (*pAssemblyLoadContextRef)->GetNativeAssemblyLoadContext(); - pPrivHostBinder = reinterpret_cast(nativeAssemblyLoadContext); + pPrivHostBinder = reinterpret_cast(nativeAssemblyLoadContext); } diff --git a/src/coreclr/vm/typeparse.cpp b/src/coreclr/vm/typeparse.cpp index cba35a66f575a..89258b25650f4 100644 --- a/src/coreclr/vm/typeparse.cpp +++ b/src/coreclr/vm/typeparse.cpp @@ -902,7 +902,7 @@ TypeHandle TypeName::GetTypeUsingCASearchRules(LPCWSTR szTypeName, Assembly *pRe BOOL bProhibitAsmQualifiedName, Assembly* pRequestingAssembly, OBJECTREF *pKeepAlive, - ICLRPrivBinder * pPrivHostBinder) + AssemblyBinder * pPrivHostBinder) { STANDARD_VM_CONTRACT; @@ -1117,7 +1117,7 @@ TypeHandle TypeName::GetTypeFromAsm() BOOL fEnableCASearchRules, BOOL bProhibitAsmQualifiedName, Assembly* pRequestingAssembly, - ICLRPrivBinder * pPrivHostBinder, + AssemblyBinder * pPrivHostBinder, OBJECTREF *pKeepAlive) { CONTRACT(TypeHandle) @@ -1454,7 +1454,7 @@ TypeName::GetTypeHaveAssemblyHelper( DomainAssembly * LoadDomainAssembly( SString * psszAssemblySpec, Assembly * pRequestingAssembly, - ICLRPrivBinder * pPrivHostBinder, + AssemblyBinder * pPrivHostBinder, BOOL bThrowIfNotFound) { CONTRACTL diff --git a/src/coreclr/vm/typeparse.h b/src/coreclr/vm/typeparse.h index 3cf1df6ceb1e4..de036c8135f22 100644 --- a/src/coreclr/vm/typeparse.h +++ b/src/coreclr/vm/typeparse.h @@ -41,7 +41,7 @@ bool inline IsTypeNameReservedChar(WCHAR ch) DomainAssembly * LoadDomainAssembly( SString * psszAssemblySpec, Assembly * pRequestingAssembly, - ICLRPrivBinder * pPrivHostBinder, + AssemblyBinder * pPrivHostBinder, BOOL bThrowIfNotFound); class TypeName @@ -330,7 +330,7 @@ class TypeName BOOL bProhibitAssemblyQualifiedName, Assembly* pRequestingAssembly, OBJECTREF *pKeepAlive, - ICLRPrivBinder * pPrivHostBinder = nullptr); + AssemblyBinder * pPrivHostBinder = nullptr); public: @@ -393,7 +393,7 @@ class TypeName BOOL bProhibitAssemblyQualifiedName, Assembly* pRequestingAssembly, - ICLRPrivBinder * pPrivHostBinder, + AssemblyBinder * pPrivHostBinder, OBJECTREF *pKeepAlive); //---------------------------------------------------------------------------------------------------------------- diff --git a/src/coreclr/vm/typestring.h b/src/coreclr/vm/typestring.h index 994feb8358410..1fb5cb30b7a5c 100644 --- a/src/coreclr/vm/typestring.h +++ b/src/coreclr/vm/typestring.h @@ -35,7 +35,7 @@ class TypeNameBuilder friend class TypeString; friend SString* TypeName::ToString(SString*, BOOL, BOOL, BOOL); friend TypeHandle TypeName::GetTypeWorker(BOOL, BOOL, Assembly*, BOOL, BOOL, Assembly*, - ICLRPrivBinder * pPrivHostBinder, + AssemblyBinder * pPrivHostBinder, OBJECTREF *); HRESULT OpenGenericArguments(); HRESULT CloseGenericArguments();