diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs index 7b663d443bb34c..77b9a935e337d1 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs @@ -15,21 +15,21 @@ public partial class AssemblyLoadContext private static extern IntPtr InitializeAssemblyLoadContext(IntPtr ptrAssemblyLoadContext, bool fRepresentsTPALoadContext, bool isCollectible); [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void PrepareForAssemblyLoadContextRelease(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyLoadContextStrong); + private static extern void PrepareForAssemblyLoadContextRelease(IntPtr ptrNativeAssemblyBinder, IntPtr ptrAssemblyLoadContextStrong); [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")] [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void LoadFromStream(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyArray, int iAssemblyArrayLen, IntPtr ptrSymbols, int iSymbolArrayLen, ObjectHandleOnStack retAssembly); + private static extern void LoadFromStream(IntPtr ptrNativeAssemblyBinder, IntPtr ptrAssemblyArray, int iAssemblyArrayLen, IntPtr ptrSymbols, int iSymbolArrayLen, ObjectHandleOnStack retAssembly); [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)] internal static extern void InternalSetProfileRoot(string directoryPath); [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)] - internal static extern void InternalStartProfile(string? profile, IntPtr ptrNativeAssemblyLoadContext); + internal static extern void InternalStartProfile(string? profile, IntPtr ptrNativeAssemblyBinder); [RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")] [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern void LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, string? ilPath, string? niPath, ObjectHandleOnStack retAssembly); + private static extern void LoadFromPath(IntPtr ptrNativeAssemblyBinder, string? ilPath, string? niPath, ObjectHandleOnStack retAssembly); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern Assembly[] GetLoadedAssemblies(); @@ -73,7 +73,7 @@ internal unsafe Assembly InternalLoad(ReadOnlySpan arrAssembly, ReadOnlySp #if TARGET_WINDOWS [DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)] - private static extern IntPtr LoadFromInMemoryModuleInternal(IntPtr ptrNativeAssemblyLoadContext, IntPtr hModule, ObjectHandleOnStack retAssembly); + private static extern IntPtr LoadFromInMemoryModuleInternal(IntPtr ptrNativeAssemblyBinder, IntPtr hModule, ObjectHandleOnStack retAssembly); /// diff --git a/src/coreclr/binder/assemblybindercommon.cpp b/src/coreclr/binder/assemblybindercommon.cpp index 2e1501f83de098..38ac60fd5e848e 100644 --- a/src/coreclr/binder/assemblybindercommon.cpp +++ b/src/coreclr/binder/assemblybindercommon.cpp @@ -33,7 +33,7 @@ // 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, - DefaultAssemblyBinder *pTPABinder, + DefaultAssemblyBinder *pDefaultBinder, BINDER_SPACE::Assembly **ppLoadedAssembly); #endif // !defined(DACCESS_COMPILE) @@ -619,10 +619,10 @@ namespace BINDER_SPACE /* static */ HRESULT AssemblyBinderCommon::BindLocked(ApplicationContext *pApplicationContext, - AssemblyName *pAssemblyName, - bool skipVersionCompatibilityCheck, - bool excludeAppPaths, - BindResult *pBindResult) + AssemblyName *pAssemblyName, + bool skipVersionCompatibilityCheck, + bool excludeAppPaths, + BindResult *pBindResult) { HRESULT hr = S_OK; @@ -688,8 +688,8 @@ namespace BINDER_SPACE /* static */ HRESULT AssemblyBinderCommon::FindInExecutionContext(ApplicationContext *pApplicationContext, - AssemblyName *pAssemblyName, - ContextEntry **ppContextEntry) + AssemblyName *pAssemblyName, + ContextEntry **ppContextEntry) { _ASSERTE(pApplicationContext != NULL); _ASSERTE(pAssemblyName != NULL); @@ -759,10 +759,10 @@ namespace BINDER_SPACE ReleaseHolder pAssembly; hr = AssemblyBinderCommon::GetAssembly(relativePath, - FALSE /* fIsInTPA */, - &pAssembly, - NULL, // szMDAssemblyPath - bundleFileLocation); + FALSE /* fIsInTPA */, + &pAssembly, + NULL, // szMDAssemblyPath + bundleFileLocation); BinderTracing::PathProbed(relativePath, BinderTracing::PathSource::Bundle, hr); @@ -808,8 +808,8 @@ namespace BINDER_SPACE CombinePath(fileName, relativePath, fileName); hr = AssemblyBinderCommon::GetAssembly(fileName, - FALSE /* fIsInTPA */, - &pAssembly); + FALSE /* fIsInTPA */, + &pAssembly); BinderTracing::PathProbed(fileName, pathSource, hr); // Missing files are okay and expected when probing @@ -979,9 +979,9 @@ namespace BINDER_SPACE */ /* static */ HRESULT AssemblyBinderCommon::BindByTpaList(ApplicationContext *pApplicationContext, - AssemblyName *pRequestedAssemblyName, - bool excludeAppPaths, - BindResult *pBindResult) + AssemblyName *pRequestedAssemblyName, + bool excludeAppPaths, + BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1152,7 +1152,6 @@ namespace BINDER_SPACE HRESULT AssemblyBinderCommon::GetAssembly(SString &assemblyPath, BOOL fIsInTPA, Assembly **ppAssembly, - // If assemblyPath refers to a native image without metadata, // szMDAssemblyPath gives the alternative file to get metadata. LPCTSTR szMDAssemblyPath, @@ -1210,7 +1209,7 @@ namespace BINDER_SPACE /* static */ HRESULT AssemblyBinderCommon::Register(ApplicationContext *pApplicationContext, - BindResult *pBindResult) + BindResult *pBindResult) { HRESULT hr = S_OK; @@ -1242,9 +1241,9 @@ namespace BINDER_SPACE /* static */ HRESULT AssemblyBinderCommon::RegisterAndGetHostChosen(ApplicationContext *pApplicationContext, - LONG kContextVersion, - BindResult *pBindResult, - BindResult *pHostBindResult) + LONG kContextVersion, + BindResult *pBindResult, + BindResult *pHostBindResult) { HRESULT hr = S_OK; @@ -1264,7 +1263,7 @@ namespace BINDER_SPACE if (kContextVersion != pApplicationContext->GetVersion()) { IF_FAIL_GO(AssemblyBinderCommon::OtherBindInterfered(pApplicationContext, - pBindResult)); + pBindResult)); if (hr == S_FALSE) { @@ -1325,9 +1324,9 @@ namespace BINDER_SPACE #if !defined(DACCESS_COMPILE) HRESULT AssemblyBinderCommon::BindUsingHostAssemblyResolver(/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, - /* in */ AssemblyName *pAssemblyName, - /* in */ DefaultAssemblyBinder *pTPABinder, - /* out */ Assembly **ppAssembly) + /* in */ AssemblyName *pAssemblyName, + /* in */ DefaultAssemblyBinder *pDefaultBinder, + /* out */ Assembly **ppAssembly) { HRESULT hr = E_FAIL; @@ -1336,7 +1335,7 @@ HRESULT AssemblyBinderCommon::BindUsingHostAssemblyResolver(/* in */ INT_PTR pMa // RuntimeInvokeHostAssemblyResolver will perform steps 2-4 of CustomAssemblyBinder::BindAssemblyByName. BINDER_SPACE::Assembly *pLoadedAssembly = NULL; hr = RuntimeInvokeHostAssemblyResolver(pManagedAssemblyLoadContextToBindWithin, - pAssemblyName, pTPABinder, &pLoadedAssembly); + pAssemblyName, pDefaultBinder, &pLoadedAssembly); if (SUCCEEDED(hr)) { _ASSERTE(pLoadedAssembly != NULL); @@ -1348,11 +1347,11 @@ HRESULT AssemblyBinderCommon::BindUsingHostAssemblyResolver(/* in */ INT_PTR pMa /* static */ HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder, - /* in */ BINDER_SPACE::AssemblyName *pAssemblyName, - /* in */ PEImage *pPEImage, - /* in */ PEKIND peKind, - /* in */ IMDInternalImport *pIMetaDataAssemblyImport, - /* [retval] [out] */ Assembly **ppAssembly) + /* in */ BINDER_SPACE::AssemblyName *pAssemblyName, + /* in */ PEImage *pPEImage, + /* in */ PEKIND peKind, + /* in */ IMDInternalImport *pIMetaDataAssemblyImport, + /* [retval] [out] */ Assembly **ppAssembly) { HRESULT hr = E_FAIL; @@ -1460,12 +1459,12 @@ HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder return hr; } -HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** ppTPABinder) +HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** ppDefaultBinder) { HRESULT hr = S_OK; EX_TRY { - if (ppTPABinder != NULL) + if (ppDefaultBinder != NULL) { NewHolder pBinder; SAFE_NEW(pBinder, DefaultAssemblyBinder); @@ -1475,7 +1474,7 @@ HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** if (SUCCEEDED(hr)) { pBinder->SetManagedAssemblyLoadContext(NULL); - *ppTPABinder = pBinder.Extract(); + *ppDefaultBinder = pBinder.Extract(); } } } @@ -1485,9 +1484,9 @@ HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** return hr; } -HRESULT AssemblyBinderCommon::GetAssemblyIdentity(LPCSTR szTextualIdentity, - BINDER_SPACE::ApplicationContext* pApplicationContext, - NewHolder& assemblyIdentityHolder) +HRESULT AssemblyBinderCommon::GetAssemblyIdentity(LPCSTR szTextualIdentity, + BINDER_SPACE::ApplicationContext* pApplicationContext, + NewHolder& assemblyIdentityHolder) { HRESULT hr = S_OK; _ASSERTE(szTextualIdentity != NULL); diff --git a/src/coreclr/binder/bindertracing.cpp b/src/coreclr/binder/bindertracing.cpp index 768b1bda8d52ca..bdef5633367ae8 100644 --- a/src/coreclr/binder/bindertracing.cpp +++ b/src/coreclr/binder/bindertracing.cpp @@ -82,7 +82,7 @@ namespace void GetAssemblyLoadContextNameFromManagedALC(INT_PTR managedALC, /* out */ SString &alcName) { - if (managedALC == GetAppDomain()->GetTPABinderContext()->GetManagedAssemblyLoadContext()) + if (managedALC == GetAppDomain()->GetDefaultBinder()->GetManagedAssemblyLoadContext()) { alcName.Set(W("Default")); return; @@ -107,19 +107,17 @@ namespace GCPROTECT_END(); } - void GetAssemblyLoadContextNameFromBindContext(AssemblyBinder *bindContext, AppDomain *domain, /*out*/ SString &alcName) + void GetAssemblyLoadContextNameFromBinder(AssemblyBinder *binder, AppDomain *domain, /*out*/ SString &alcName) { - _ASSERTE(bindContext != nullptr); + _ASSERTE(binder != nullptr); - if (bindContext == domain->GetTPABinderContext()) + if (binder->IsDefault()) { alcName.Set(W("Default")); } else { - CustomAssemblyBinder* alcBinder = static_cast(bindContext); - - GetAssemblyLoadContextNameFromManagedALC(alcBinder->GetManagedAssemblyLoadContext(), alcName); + GetAssemblyLoadContextNameFromManagedALC(binder->GetManagedAssemblyLoadContext(), alcName); } } @@ -128,11 +126,11 @@ namespace _ASSERTE(spec != nullptr); AppDomain *domain = spec->GetAppDomain(); - AssemblyBinder* bindContext = spec->GetBindingContext(); - if (bindContext == nullptr) - bindContext = spec->GetBindingContextFromParentAssembly(domain); + AssemblyBinder* binder = spec->GetBinder(); + if (binder == nullptr) + binder = spec->GetBinderFromParentAssembly(domain); - GetAssemblyLoadContextNameFromBindContext(bindContext, domain, alcName); + GetAssemblyLoadContextNameFromBinder(binder, domain, alcName); } void PopulateBindRequest(/*inout*/ BinderTracing::AssemblyBindOperation::BindRequest &request) @@ -154,11 +152,11 @@ namespace peAssembly->GetDisplayName(request.RequestingAssembly); AppDomain *domain = parentAssembly->GetAppDomain(); - AssemblyBinder *bindContext = peAssembly->GetBindingContext(); - if (bindContext == nullptr) - bindContext = domain->GetTPABinderContext(); // System.Private.CoreLib returns null + AssemblyBinder *binder = peAssembly->GetBinder(); + if (binder == nullptr) + binder = domain->GetDefaultBinder(); // System.Private.CoreLib returns null - GetAssemblyLoadContextNameFromBindContext(bindContext, domain, request.RequestingAssemblyLoadContext); + GetAssemblyLoadContextNameFromBinder(binder, domain, request.RequestingAssemblyLoadContext); } GetAssemblyLoadContextNameFromSpec(spec, request.AssemblyLoadContext); @@ -241,14 +239,14 @@ namespace BinderTracing namespace BinderTracing { - ResolutionAttemptedOperation::ResolutionAttemptedOperation(AssemblyName *assemblyName, AssemblyBinder* bindContext, INT_PTR managedALC, const HRESULT& hr) + ResolutionAttemptedOperation::ResolutionAttemptedOperation(AssemblyName *assemblyName, AssemblyBinder* binder, INT_PTR managedALC, const HRESULT& hr) : m_hr { hr } , m_stage { Stage::NotYetStarted } , m_tracingEnabled { BinderTracing::IsEnabled() } , m_assemblyNameObject { assemblyName } , m_pFoundAssembly { nullptr } { - _ASSERTE(bindContext != nullptr || managedALC != 0); + _ASSERTE(binder != nullptr || managedALC != 0); if (!m_tracingEnabled) return; @@ -264,7 +262,7 @@ namespace BinderTracing } else { - GetAssemblyLoadContextNameFromBindContext(bindContext, GetAppDomain(), m_assemblyLoadContextName); + GetAssemblyLoadContextNameFromBinder(binder, GetAppDomain(), m_assemblyLoadContextName); } } diff --git a/src/coreclr/binder/customassemblybinder.cpp b/src/coreclr/binder/customassemblybinder.cpp index 665c4c8840e6f0..5378e710b1b948 100644 --- a/src/coreclr/binder/customassemblybinder.cpp +++ b/src/coreclr/binder/customassemblybinder.cpp @@ -14,7 +14,7 @@ using namespace BINDER_SPACE; // CustomAssemblyBinder implementation // ============================================================================ HRESULT CustomAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, - BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly) + BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly) { VALIDATE_ARG_RET(pAssemblyName != nullptr && ppCoreCLRFoundAssembly != nullptr); HRESULT hr = S_OK; @@ -47,7 +47,7 @@ HRESULT CustomAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName* // // 1) Lookup the assembly within the LoadContext itself. If assembly is found, use it. // 2) Invoke the LoadContext's Load method implementation. If assembly is found, use it. - // 3) Lookup the assembly within TPABinder (except for satellite requests). If assembly is found, use it. + // 3) Lookup the assembly within DefaultBinder (except for satellite requests). If assembly is found, use it. // 4) Invoke the LoadContext's ResolveSatelliteAssembly method (for satellite requests). If assembly is found, use it. // 5) Invoke the LoadContext's Resolving event. If assembly is found, use it. // 6) Raise exception. @@ -74,11 +74,11 @@ HRESULT CustomAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName* // 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 = AssemblyBinderCommon::BindUsingHostAssemblyResolver(GetManagedAssemblyLoadContext(), pAssemblyName, m_pTPABinder, &pCoreCLRFoundAssembly); + hr = AssemblyBinderCommon::BindUsingHostAssemblyResolver(GetManagedAssemblyLoadContext(), pAssemblyName, m_pDefaultBinder, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { - // We maybe returned an assembly that was bound to a different AssemblyLoadContext instance. - // In such a case, we will not overwrite the binding context (which would be wrong since it would not + // We maybe returned an assembly that was bound to a different AssemblyBinder instance. + // In such a case, we will not overwrite the binder (which would be wrong since the assembly would not // be present in the cache of the current binding context). if (pCoreCLRFoundAssembly->GetBinder() == NULL) { @@ -92,7 +92,7 @@ HRESULT CustomAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName* // Extract the assembly reference. // - // For TPA assemblies that were bound, TPABinder + // For TPA assemblies that were bound, DefaultBinder // would have already set the binder reference for the assembly, so we just need to // extract the reference now. *ppAssembly = pCoreCLRFoundAssembly.Extract(); @@ -159,17 +159,17 @@ AssemblyLoaderAllocator* CustomAssemblyBinder::GetLoaderAllocator() } //============================================================================= -// Creates an instance of the AssemblyLoadContext Binder +// Creates an instance of the CustomAssemblyBinder // // This method does not take a lock since it is invoked from the ctor of the // managed AssemblyLoadContext type. //============================================================================= /* static */ -HRESULT CustomAssemblyBinder::SetupContext(DefaultAssemblyBinder *pTPABinder, - AssemblyLoaderAllocator* pLoaderAllocator, - void* loaderAllocatorHandle, - UINT_PTR ptrAssemblyLoadContext, - CustomAssemblyBinder **ppBindContext) +HRESULT CustomAssemblyBinder::SetupContext(DefaultAssemblyBinder *pDefaultBinder, + AssemblyLoaderAllocator* pLoaderAllocator, + void* loaderAllocatorHandle, + UINT_PTR ptrAssemblyLoadContext, + CustomAssemblyBinder **ppBindContext) { HRESULT hr = E_FAIL; EX_TRY @@ -182,13 +182,13 @@ HRESULT CustomAssemblyBinder::SetupContext(DefaultAssemblyBinder *pTPABinder, hr = pBinder->GetAppContext()->Init(); if(SUCCEEDED(hr)) { - // Save reference to the TPABinder that is required to be present. - _ASSERTE(pTPABinder != NULL); - pBinder->m_pTPABinder = pTPABinder; + // Save reference to the DefaultBinder that is required to be present. + _ASSERTE(pDefaultBinder != NULL); + pBinder->m_pDefaultBinder = pDefaultBinder; // Save the reference to the IntPtr for GCHandle for the managed // AssemblyLoadContext instance - pBinder->m_ptrManagedAssemblyLoadContext = ptrAssemblyLoadContext; + pBinder->SetManagedAssemblyLoadContext(ptrAssemblyLoadContext); if (pLoaderAllocator != NULL) { @@ -247,22 +247,22 @@ void CustomAssemblyBinder::PrepareForLoadContextRelease(INT_PTR ptrManagedStrong CustomAssemblyBinder::CustomAssemblyBinder() { - m_pTPABinder = NULL; + m_pDefaultBinder = NULL; m_ptrManagedStrongAssemblyLoadContext = NULL; } void CustomAssemblyBinder::ReleaseLoadContext() { - VERIFY(m_ptrManagedAssemblyLoadContext != NULL); + VERIFY(GetManagedAssemblyLoadContext() != NULL); VERIFY(m_ptrManagedStrongAssemblyLoadContext != NULL); // This method is called to release the weak and strong handles on the managed AssemblyLoadContext // once the Unloading event has been fired - OBJECTHANDLE handle = reinterpret_cast(m_ptrManagedAssemblyLoadContext); + OBJECTHANDLE handle = reinterpret_cast(GetManagedAssemblyLoadContext()); DestroyLongWeakHandle(handle); handle = reinterpret_cast(m_ptrManagedStrongAssemblyLoadContext); DestroyHandle(handle); - m_ptrManagedAssemblyLoadContext = NULL; + SetManagedAssemblyLoadContext(NULL); } #endif // !defined(DACCESS_COMPILE) diff --git a/src/coreclr/binder/defaultassemblybinder.cpp b/src/coreclr/binder/defaultassemblybinder.cpp index 1fe15eed60f23d..9597f8c60f4583 100644 --- a/src/coreclr/binder/defaultassemblybinder.cpp +++ b/src/coreclr/binder/defaultassemblybinder.cpp @@ -41,7 +41,7 @@ HRESULT DefaultAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNa // DefaultAssemblyBinder implementation // ============================================================================ HRESULT DefaultAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName *pAssemblyName, - BINDER_SPACE::Assembly **ppAssembly) + BINDER_SPACE::Assembly **ppAssembly) { HRESULT hr = S_OK; VALIDATE_ARG_RET(pAssemblyName != nullptr && ppAssembly != nullptr); @@ -87,7 +87,7 @@ HRESULT DefaultAssemblyBinder::BindUsingAssemblyName(BINDER_SPACE::AssemblyName if (pManagedAssemblyLoadContext != NULL) { hr = AssemblyBinderCommon::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, - NULL, &pCoreCLRFoundAssembly); + NULL, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { // We maybe returned an assembly that was bound to a different AssemblyLoadContext instance. diff --git a/src/coreclr/binder/inc/assemblybindercommon.hpp b/src/coreclr/binder/inc/assemblybindercommon.hpp index 5800fd86c200e6..8febd3a1e7a598 100644 --- a/src/coreclr/binder/inc/assemblybindercommon.hpp +++ b/src/coreclr/binder/inc/assemblybindercommon.hpp @@ -56,7 +56,7 @@ namespace BINDER_SPACE #if !defined(DACCESS_COMPILE) static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, /* in */ AssemblyName *pAssemblyName, - /* in */ DefaultAssemblyBinder *pTPABinder, + /* in */ DefaultAssemblyBinder *pDefaultBinder, /* out */ Assembly **ppAssembly); static HRESULT BindUsingPEImage(/* in */ AssemblyBinder *pBinder, @@ -69,7 +69,7 @@ namespace BINDER_SPACE static HRESULT TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind); - static HRESULT DefaultBinderSetupContext(DefaultAssemblyBinder** ppTPABinder); + static HRESULT DefaultBinderSetupContext(DefaultAssemblyBinder** ppDefaultBinder); // TODO: The call indicates that this can come from a case where // pDomain->GetFusionContext() is null, hence this is static function diff --git a/src/coreclr/binder/inc/customassemblybinder.h b/src/coreclr/binder/inc/customassemblybinder.h index bc41deffdd1633..9d59832f3c9798 100644 --- a/src/coreclr/binder/inc/customassemblybinder.h +++ b/src/coreclr/binder/inc/customassemblybinder.h @@ -13,20 +13,22 @@ class AssemblyLoaderAllocator; class PEImage; -class CustomAssemblyBinder final : public AssemblyLoadContext +class CustomAssemblyBinder final : public AssemblyBinder { public: - //========================================================================= - // AssemblyBinder functions - //------------------------------------------------------------------------- HRESULT BindUsingPEImage(PEImage* pPEImage, - BINDER_SPACE::Assembly** ppAssembly); + BINDER_SPACE::Assembly** ppAssembly) override; HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, - BINDER_SPACE::Assembly** ppAssembly); + BINDER_SPACE::Assembly** ppAssembly) override; + + AssemblyLoaderAllocator* GetLoaderAllocator() override; - AssemblyLoaderAllocator* GetLoaderAllocator(); + bool IsDefault() override + { + return false; + } public: //========================================================================= @@ -35,7 +37,7 @@ class CustomAssemblyBinder final : public AssemblyLoadContext CustomAssemblyBinder(); - static HRESULT SetupContext(DefaultAssemblyBinder *pTPABinder, + static HRESULT SetupContext(DefaultAssemblyBinder *pDefaultBinder, AssemblyLoaderAllocator* pLoaderAllocator, void* loaderAllocatorHandle, UINT_PTR ptrAssemblyLoadContext, @@ -44,13 +46,10 @@ class CustomAssemblyBinder final : public AssemblyLoadContext void PrepareForLoadContextRelease(INT_PTR ptrManagedStrongAssemblyLoadContext); void ReleaseLoadContext(); - //========================================================================= - // Internal implementation details - //------------------------------------------------------------------------- private: HRESULT BindAssemblyByNameWorker(BINDER_SPACE::AssemblyName *pAssemblyName, BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly); - DefaultAssemblyBinder *m_pTPABinder; + DefaultAssemblyBinder *m_pDefaultBinder; // 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. diff --git a/src/coreclr/binder/inc/defaultassemblybinder.h b/src/coreclr/binder/inc/defaultassemblybinder.h index 70654107c399c9..a1f72d6eb36551 100644 --- a/src/coreclr/binder/inc/defaultassemblybinder.h +++ b/src/coreclr/binder/inc/defaultassemblybinder.h @@ -6,30 +6,32 @@ #define __DEFAULT_ASSEMBLY_BINDER_H__ #include "applicationcontext.hpp" -#include "assemblyloadcontext.h" +#include "assemblybinder.h" class PEAssembly; class PEImage; -class DefaultAssemblyBinder final : public AssemblyLoadContext +class DefaultAssemblyBinder final : public AssemblyBinder { public: - //========================================================================= - // AssemblyBinder functions - //------------------------------------------------------------------------- HRESULT BindUsingPEImage(PEImage* pPEImage, - BINDER_SPACE::Assembly** ppAssembly); + BINDER_SPACE::Assembly** ppAssembly) override; HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, - BINDER_SPACE::Assembly** ppAssembly); + BINDER_SPACE::Assembly** ppAssembly) override; - AssemblyLoaderAllocator* GetLoaderAllocator() + AssemblyLoaderAllocator* GetLoaderAllocator() override { // Not supported by this binder return NULL; } + bool IsDefault() override + { + return true; + } + public: HRESULT SetupBindingPaths(SString &sTrustedPlatformAssemblies, diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 4866c106f6cb78..3deed09f707204 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -4769,9 +4769,9 @@ HRESULT ClrDataAccess::GetAssemblyLoadContext(CLRDATA_ADDRESS methodTable, CLRDA PTR_Module pModule = pMT->GetModule(); PTR_PEFile pPEFile = pModule->GetFile(); - PTR_AssemblyLoadContext pAssemblyLoadContext = pPEFile->GetAssemblyLoadContext(); + PTR_AssemblyBinder pBinder = pPEFile->GetAssemblyBinder(); - INT_PTR managedAssemblyLoadContextHandle = pAssemblyLoadContext->GetManagedAssemblyLoadContext(); + INT_PTR managedAssemblyLoadContextHandle = pBinder->GetManagedAssemblyLoadContext(); TADDR managedAssemblyLoadContextAddr = 0; if (managedAssemblyLoadContextHandle != 0) diff --git a/src/coreclr/vm/CMakeLists.txt b/src/coreclr/vm/CMakeLists.txt index 436606555796cd..da3a36468c06c5 100644 --- a/src/coreclr/vm/CMakeLists.txt +++ b/src/coreclr/vm/CMakeLists.txt @@ -50,7 +50,6 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON array.cpp assembly.cpp assemblybinder.cpp - assemblyloadcontext.cpp binder.cpp bundle.cpp castcache.cpp @@ -149,7 +148,6 @@ set(VM_HEADERS_DAC_AND_WKS_COMMON array.h assembly.hpp assemblybinder.h - assemblyloadcontext.h binder.h castcache.h callcounting.h @@ -319,7 +317,6 @@ set(VM_SOURCES_WKS comutilnative.cpp comwaithandle.cpp coreassemblyspec.cpp - corebindresult.cpp corelib.cpp # true customattribute.cpp custommarshalerinfo.cpp @@ -399,8 +396,6 @@ list(REMOVE_ITEM VM_SOURCES_WKS codeman.cpp) set(VM_HEADERS_WKS ${VM_HEADERS_DAC_AND_WKS_COMMON} ../inc/jithelpers.h - coreclr/corebindresult.h - coreclr/corebindresult.inl appdomainnative.hpp assemblyname.hpp assemblynative.hpp diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 312da4fe4ec0d8..adc21b99ef4564 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -622,7 +622,7 @@ BaseDomain::BaseDomain() } CONTRACTL_END; - m_pTPABinderContext = NULL; + m_pDefaultBinder = NULL; // Make sure the container is set to NULL so that it gets loaded when it is used. m_pPinnedHeapHandleTable = NULL; @@ -729,10 +729,10 @@ void BaseDomain::ClearBinderContext() } CONTRACTL_END; - if (m_pTPABinderContext) + if (m_pDefaultBinder) { - delete m_pTPABinderContext; - m_pTPABinderContext = NULL; + delete m_pDefaultBinder; + m_pDefaultBinder = NULL; } } @@ -2773,21 +2773,21 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, if (!pEx->IsTransient()) { // Setup the binder reference in AssemblySpec from the PEAssembly if one is not already set. - AssemblyBinder* pCurrentBindingContext = pSpec->GetBindingContext(); - AssemblyBinder* pBindingContextFromPEAssembly = pFile->GetBindingContext(); + AssemblyBinder* pCurrentBinder = pSpec->GetBinder(); + AssemblyBinder* pBinderFromPEAssembly = pFile->GetBinder(); - if (pCurrentBindingContext == NULL) + if (pCurrentBinder == NULL) { // Set the binding context we got from the PEAssembly if AssemblySpec does not // have that information - _ASSERTE(pBindingContextFromPEAssembly != NULL); - pSpec->SetBindingContext(pBindingContextFromPEAssembly); + _ASSERTE(pBinderFromPEAssembly != NULL); + pSpec->SetBinder(pBinderFromPEAssembly); } #if defined(_DEBUG) else { // Binding context in the spec should be the same as the binding context in the PEAssembly - _ASSERTE(pCurrentBindingContext == pBindingContextFromPEAssembly); + _ASSERTE(pCurrentBinder == pBinderFromPEAssembly); } #endif // _DEBUG @@ -2841,10 +2841,10 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, { LoaderAllocator *pLoaderAllocator = NULL; - AssemblyBinder *pFileBinder = pFile->GetBindingContext(); + AssemblyBinder *pFileBinder = pFile->GetBinder(); if (pFileBinder != NULL) { - // Assemblies loaded with AssemblyLoadContext need to use a different LoaderAllocator if + // Assemblies loaded with CustomAssemblyBinder need to use a different LoaderAllocator if // marked as collectible pLoaderAllocator = pFileBinder->GetLoaderAllocator(); } @@ -2904,7 +2904,7 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, if (registerNewAssembly) { - pFile->GetAssemblyLoadContext()->AddLoadedAssembly(pDomainAssembly->GetCurrentAssembly()); + pFile->GetAssemblyBinder()->AddLoadedAssembly(pDomainAssembly->GetCurrentAssembly()); } } else @@ -3695,15 +3695,12 @@ PEAssembly * AppDomain::BindAssemblySpec( { { - // Use CoreClr's fusion alternative - CoreBindResult bindResult; + ReleaseHolder boundAssembly; + hrBindResult = pSpec->Bind(this, &boundAssembly); - pSpec->Bind(this, FALSE /* fThrowOnFileNotFound */, &bindResult); - hrBindResult = bindResult.GetHRBindResult(); - - if (bindResult.Found()) + if (boundAssembly) { - if (SystemDomain::SystemFile() && bindResult.IsCoreLib()) + if (SystemDomain::SystemFile() && boundAssembly->GetAssemblyName()->IsCoreLib()) { // Avoid rebinding to another copy of CoreLib result = SystemDomain::SystemFile(); @@ -3712,14 +3709,13 @@ PEAssembly * AppDomain::BindAssemblySpec( else { // IsSystem on the PEFile should be false, even for CoreLib satellites - result = PEAssembly::Open(&bindResult, - FALSE); + result = PEAssembly::Open(boundAssembly, FALSE); } // Setup the reference to the binder, which performed the bind, into the AssemblySpec - AssemblyBinder* pBinder = result->GetBindingContext(); + AssemblyBinder* pBinder = result->GetBinder(); _ASSERTE(pBinder != NULL); - pSpec->SetBindingContext(pBinder); + pSpec->SetBinder(pBinder); // Failure to add simply means someone else beat us to it. In that case // the FindCachedFile call below (after catch block) will update result @@ -4059,17 +4055,17 @@ DefaultAssemblyBinder *AppDomain::CreateBinderContext() } CONTRACT_END; - if (!m_pTPABinderContext) + if (!m_pDefaultBinder) { ETWOnStartup (FusionAppCtx_V1, FusionAppCtxEnd_V1); GCX_PREEMP(); // Initialize the assembly binder for the default context loads for CoreCLR. - IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::DefaultBinderSetupContext(&m_pTPABinderContext)); + IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::DefaultBinderSetupContext(&m_pDefaultBinder)); } - RETURN m_pTPABinderContext; + RETURN m_pDefaultBinder; } @@ -4983,7 +4979,7 @@ AppDomain::AssemblyIterator::Next_Unlocked( #if !defined(DACCESS_COMPILE) // Returns S_OK if the assembly was successfully loaded -HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, DefaultAssemblyBinder *pTPABinder, BINDER_SPACE::Assembly **ppLoadedAssembly) +HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, DefaultAssemblyBinder *pDefaultBinder, BINDER_SPACE::Assembly **ppLoadedAssembly) { CONTRACTL { @@ -5025,7 +5021,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB EX_TRY { - if (pTPABinder != NULL) + if (pDefaultBinder != NULL) { // Step 2 (of CustomAssemblyBinder::BindAssemblyByName) - Invoke Load method // This is not invoked for TPA Binder since it always returns NULL. @@ -5061,7 +5057,7 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB // Switch to pre-emp mode before calling into the binder GCX_PREEMP(); BINDER_SPACE::Assembly *pCoreCLRFoundAssembly = NULL; - hr = pTPABinder->BindUsingAssemblyName(pAssemblyName, &pCoreCLRFoundAssembly); + hr = pDefaultBinder->BindUsingAssemblyName(pAssemblyName, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { _ASSERTE(pCoreCLRFoundAssembly != NULL); diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index f71acfeb50094c..d31dc9af6d8ab0 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -1096,7 +1096,7 @@ class BaseDomain #endif // DACCESS_COMPILE - DefaultAssemblyBinder *GetTPABinderContext() {LIMITED_METHOD_CONTRACT; return m_pTPABinderContext; } + DefaultAssemblyBinder *GetDefaultBinder() {LIMITED_METHOD_CONTRACT; return m_pDefaultBinder; } CrstExplicitInit * GetLoaderAllocatorReferencesLock() { @@ -1127,7 +1127,7 @@ class BaseDomain ListLock m_ILStubGenLock; ListLock m_NativeTypeLoadLock; - DefaultAssemblyBinder *m_pTPABinderContext; // Reference to the binding context that holds TPA list details + DefaultAssemblyBinder *m_pDefaultBinder; // Reference to the binding context that holds TPA list details IGCHandleStore* m_handleStore; diff --git a/src/coreclr/vm/appdomainnative.cpp b/src/coreclr/vm/appdomainnative.cpp index 425b786771fc44..5992976e315c20 100644 --- a/src/coreclr/vm/appdomainnative.cpp +++ b/src/coreclr/vm/appdomainnative.cpp @@ -39,16 +39,15 @@ void QCALLTYPE AppDomainNative::CreateDynamicAssembly(QCall::ObjectHandleOnStack args.stackMark = stackMark; Assembly* pAssembly = nullptr; - AssemblyBinder* pBinderContext = nullptr; + AssemblyBinder* pBinder = nullptr; if (assemblyLoadContext.Get() != NULL) { - INT_PTR nativeAssemblyLoadContext = ((ASSEMBLYLOADCONTEXTREF)assemblyLoadContext.Get())->GetNativeAssemblyLoadContext(); - - pBinderContext = reinterpret_cast(nativeAssemblyLoadContext); + INT_PTR nativeAssemblyBinder = ((ASSEMBLYLOADCONTEXTREF)assemblyLoadContext.Get())->GetNativeAssemblyBinder(); + pBinder = reinterpret_cast(nativeAssemblyBinder); } - pAssembly = Assembly::CreateDynamic(GetAppDomain(), pBinderContext, &args); + pAssembly = Assembly::CreateDynamic(GetAppDomain(), pBinder, &args); retAssembly.Set(pAssembly->GetExposedObject()); diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index c2e726ba8fa880..712852e9ab5dee 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -322,7 +322,7 @@ Assembly * Assembly::Create( return pAssembly; } // Assembly::Create -Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderContext, CreateDynamicAssemblyArgs *args) +Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, CreateDynamicAssemblyArgs *args) { // WARNING: not backout clean CONTRACT(Assembly *) @@ -464,10 +464,10 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderCon &ma)); pFile = PEAssembly::Create(pCallerAssembly->GetManifestFile(), pAssemblyEmit); - AssemblyBinder* pFallbackLoadContextBinder = pBinderContext; + AssemblyBinder* pFallbackBinder = pBinder; // If ALC is not specified - if (pFallbackLoadContextBinder == nullptr) + if (pFallbackBinder == nullptr) { // Dynamically created modules (aka RefEmit assemblies) do not have a LoadContext associated with them since they are not bound // using an actual binder. As a result, we will assume the same binding/loadcontext information for the dynamic assembly as its @@ -483,12 +483,12 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderCon if (!pCallerAssemblyManifestFile->IsDynamic()) { // Static assemblies with do not have fallback load context - _ASSERTE(pCallerAssemblyManifestFile->GetFallbackLoadContextBinder() == nullptr); + _ASSERTE(pCallerAssemblyManifestFile->GetFallbackBinder() == nullptr); if (pCallerAssemblyManifestFile->IsSystem()) { - // CoreLibrary is always bound to TPA binder - pFallbackLoadContextBinder = pDomain->GetTPABinderContext(); + // CoreLibrary is always bound with default binder + pFallbackBinder = pDomain->GetDefaultBinder(); } else { @@ -496,22 +496,22 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderCon PTR_BINDER_SPACE_Assembly pCallerAssemblyHostAssembly = pCallerAssemblyManifestFile->GetHostAssembly(); _ASSERTE(pCallerAssemblyHostAssembly != nullptr); - pFallbackLoadContextBinder = pCallerAssemblyHostAssembly->GetBinder(); + pFallbackBinder = pCallerAssemblyHostAssembly->GetBinder(); } } else { // Creator assembly is dynamic too, so use its fallback load context for the one // we are creating. - pFallbackLoadContextBinder = pCallerAssemblyManifestFile->GetFallbackLoadContextBinder(); + pFallbackBinder = pCallerAssemblyManifestFile->GetFallbackBinder(); } } // At this point, we should have a fallback load context binder to work with - _ASSERTE(pFallbackLoadContextBinder != nullptr); + _ASSERTE(pFallbackBinder != nullptr); // Set it as the fallback load context binder for the dynamic assembly being created - pFile->SetFallbackLoadContextBinder(pFallbackLoadContextBinder); + pFile->SetFallbackBinder(pFallbackBinder); } NewHolder pDomainAssembly; @@ -520,37 +520,37 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinderCon { GCX_PREEMP(); - AssemblyLoaderAllocator* pBinderAssemblyLoaderAllocator = nullptr; - if (pBinderContext != nullptr) + AssemblyLoaderAllocator* pBinderLoaderAllocator = nullptr; + if (pBinder != nullptr) { - pBinderAssemblyLoaderAllocator = pBinderContext->GetLoaderAllocator(); + pBinderLoaderAllocator = pBinder->GetLoaderAllocator(); } // Create a new LoaderAllocator if appropriate if ((args->access & ASSEMBLY_ACCESS_COLLECT) != 0) { - AssemblyLoaderAllocator *pAssemblyLoaderAllocator = new AssemblyLoaderAllocator(); - pAssemblyLoaderAllocator->SetCollectible(); - pLoaderAllocator = pAssemblyLoaderAllocator; + AssemblyLoaderAllocator *pCollectibleLoaderAllocator = new AssemblyLoaderAllocator(); + pCollectibleLoaderAllocator->SetCollectible(); + pLoaderAllocator = pCollectibleLoaderAllocator; // Some of the initialization functions are not virtual. Call through the derived class // to prevent calling the base class version. - pAssemblyLoaderAllocator->Init(pDomain); + pCollectibleLoaderAllocator->Init(pDomain); // Setup the managed proxy now, but do not actually transfer ownership to it. // Once everything is setup and nothing can fail anymore, the ownership will be // atomically transfered by call to LoaderAllocator::ActivateManagedTracking(). - pAssemblyLoaderAllocator->SetupManagedTracking(&args->loaderAllocator); + pCollectibleLoaderAllocator->SetupManagedTracking(&args->loaderAllocator); createdNewAssemblyLoaderAllocator = TRUE; - if(pBinderAssemblyLoaderAllocator != nullptr) + if(pBinderLoaderAllocator != nullptr) { - pAssemblyLoaderAllocator->EnsureReference(pBinderAssemblyLoaderAllocator); + pCollectibleLoaderAllocator->EnsureReference(pBinderLoaderAllocator); } } else { - pLoaderAllocator = pBinderAssemblyLoaderAllocator == nullptr ? pDomain->GetLoaderAllocator() : pBinderAssemblyLoaderAllocator; + pLoaderAllocator = pBinderLoaderAllocator == nullptr ? pDomain->GetLoaderAllocator() : pBinderLoaderAllocator; } if (!createdNewAssemblyLoaderAllocator) diff --git a/src/coreclr/vm/assembly.hpp b/src/coreclr/vm/assembly.hpp index 029309d5dc977e..f1f98984bd0537 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, AssemblyBinder* pBinderContext, CreateDynamicAssemblyArgs *args); + static Assembly *CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, CreateDynamicAssemblyArgs *args); MethodDesc *GetEntryPoint(); diff --git a/src/coreclr/vm/assemblybinder.cpp b/src/coreclr/vm/assemblybinder.cpp index a4fc17669be369..1ce6d2e93beb1e 100644 --- a/src/coreclr/vm/assemblybinder.cpp +++ b/src/coreclr/vm/assemblybinder.cpp @@ -1,7 +1,9 @@ // 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.h" +#include "nativeimage.h" #include "../binder/inc/assemblyname.hpp" #ifndef DACCESS_COMPILE @@ -24,4 +26,39 @@ HRESULT AssemblyBinder::BindAssemblyByName(AssemblyNameData* pAssemblyNameData, return hr; } + +NativeImage* AssemblyBinder::LoadNativeImage(Module* componentModule, LPCUTF8 nativeImageName) +{ + STANDARD_VM_CONTRACT; + + BaseDomain::LoadLockHolder lock(AppDomain::GetCurrentDomain()); + AssemblyBinder* binder = componentModule->GetFile()->GetAssemblyBinder(); + PTR_LoaderAllocator moduleLoaderAllocator = componentModule->GetLoaderAllocator(); + + bool isNewNativeImage; + NativeImage* nativeImage = NativeImage::Open(componentModule, nativeImageName, binder, moduleLoaderAllocator, &isNewNativeImage); + + if (isNewNativeImage && nativeImage != nullptr) + { + m_nativeImages.Append(nativeImage); + + for (COUNT_T assemblyIndex = 0; assemblyIndex < m_loadedAssemblies.GetCount(); assemblyIndex++) + { + nativeImage->CheckAssemblyMvid(m_loadedAssemblies[assemblyIndex]); + } + } + + return nativeImage; +} + +void AssemblyBinder::AddLoadedAssembly(Assembly* loadedAssembly) +{ + BaseDomain::LoadLockHolder lock(AppDomain::GetCurrentDomain()); + m_loadedAssemblies.Append(loadedAssembly); + for (COUNT_T nativeImageIndex = 0; nativeImageIndex < m_nativeImages.GetCount(); nativeImageIndex++) + { + m_nativeImages[nativeImageIndex]->CheckAssemblyMvid(loadedAssembly); + } +} + #endif //DACCESS_COMPILE diff --git a/src/coreclr/vm/assemblybinder.h b/src/coreclr/vm/assemblybinder.h index d5b02b0a637492..e737d92c2de7c0 100644 --- a/src/coreclr/vm/assemblybinder.h +++ b/src/coreclr/vm/assemblybinder.h @@ -4,37 +4,60 @@ #ifndef _ASSEMBLYBINDER_H #define _ASSEMBLYBINDER_H +#include #include "../binder/inc/applicationcontext.hpp" class PEImage; +class NativeImage; +class Assembly; +class Module; class AssemblyLoaderAllocator; class AssemblyBinder { public: - HRESULT BindAssemblyByName(AssemblyNameData* pAssemblyNameData, - BINDER_SPACE::Assembly** ppAssembly); - virtual HRESULT BindUsingPEImage(PEImage* pPEImage, - BINDER_SPACE::Assembly** ppAssembly) = 0; + HRESULT BindAssemblyByName(AssemblyNameData* pAssemblyNameData, BINDER_SPACE::Assembly** ppAssembly); + virtual HRESULT BindUsingPEImage(PEImage* pPEImage, BINDER_SPACE::Assembly** ppAssembly) = 0; + virtual HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName* pAssemblyName, 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. - ** - **********************************************************************************/ + /// + /// Get LoaderAllocator for binders that contain it. For other binders, return NULL. + /// virtual AssemblyLoaderAllocator* GetLoaderAllocator() = 0; + /// + /// Tells if the binder is a default binder (not a custom one) + /// + virtual bool IsDefault() = 0; + inline BINDER_SPACE::ApplicationContext* GetAppContext() { return &m_appContext; } + INT_PTR GetManagedAssemblyLoadContext() + { + return m_ptrManagedAssemblyLoadContext; + } + + void SetManagedAssemblyLoadContext(INT_PTR ptrManagedDefaultBinderInstance) + { + m_ptrManagedAssemblyLoadContext = ptrManagedDefaultBinderInstance; + } + + NativeImage* LoadNativeImage(Module* componentModule, LPCUTF8 nativeImageName); + void AddLoadedAssembly(Assembly* loadedAssembly); + private: BINDER_SPACE::ApplicationContext m_appContext; + + // A GC handle to the managed AssemblyLoadContext. + // It is a long weak handle for collectible AssemblyLoadContexts and strong handle for non-collectible ones. + INT_PTR m_ptrManagedAssemblyLoadContext; + + SArray m_nativeImages; + SArray m_loadedAssemblies; }; #endif diff --git a/src/coreclr/vm/assemblyloadcontext.cpp b/src/coreclr/vm/assemblyloadcontext.cpp deleted file mode 100644 index 33a239c9fdbd78..00000000000000 --- a/src/coreclr/vm/assemblyloadcontext.cpp +++ /dev/null @@ -1,47 +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 "nativeimage.h" - -AssemblyLoadContext::AssemblyLoadContext() -{ -} - -#ifndef DACCESS_COMPILE - -NativeImage *AssemblyLoadContext::LoadNativeImage(Module *componentModule, LPCUTF8 nativeImageName) -{ - STANDARD_VM_CONTRACT; - - BaseDomain::LoadLockHolder lock(AppDomain::GetCurrentDomain()); - AssemblyLoadContext *loadContext = componentModule->GetFile()->GetAssemblyLoadContext(); - PTR_LoaderAllocator moduleLoaderAllocator = componentModule->GetLoaderAllocator(); - - bool isNewNativeImage; - NativeImage *nativeImage = NativeImage::Open(componentModule, nativeImageName, loadContext, moduleLoaderAllocator, &isNewNativeImage); - - if (isNewNativeImage && nativeImage != nullptr) - { - m_nativeImages.Append(nativeImage); - - for (COUNT_T assemblyIndex = 0; assemblyIndex < m_loadedAssemblies.GetCount(); assemblyIndex++) - { - nativeImage->CheckAssemblyMvid(m_loadedAssemblies[assemblyIndex]); - } - } - - return nativeImage; -} - -void AssemblyLoadContext::AddLoadedAssembly(Assembly *loadedAssembly) -{ - BaseDomain::LoadLockHolder lock(AppDomain::GetCurrentDomain()); - m_loadedAssemblies.Append(loadedAssembly); - for (COUNT_T nativeImageIndex = 0; nativeImageIndex < m_nativeImages.GetCount(); nativeImageIndex++) - { - m_nativeImages[nativeImageIndex]->CheckAssemblyMvid(loadedAssembly); - } -} - -#endif //DACCESS_COMPILE diff --git a/src/coreclr/vm/assemblyloadcontext.h b/src/coreclr/vm/assemblyloadcontext.h deleted file mode 100644 index ccbc12a6f7a723..00000000000000 --- a/src/coreclr/vm/assemblyloadcontext.h +++ /dev/null @@ -1,49 +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 _ASSEMBLYLOADCONTEXT_H -#define _ASSEMBLYLOADCONTEXT_H - -#include "crst.h" -#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 AssemblyBinder -{ -public: - AssemblyLoadContext(); - - NativeImage *LoadNativeImage(Module *componentModule, LPCUTF8 nativeImageName); - - void AddLoadedAssembly(Assembly *loadedAssembly); - - INT_PTR GetManagedAssemblyLoadContext() - { - return m_ptrManagedAssemblyLoadContext; - } - - void SetManagedAssemblyLoadContext(INT_PTR ptrManagedTPABinderInstance) - { - m_ptrManagedAssemblyLoadContext = ptrManagedTPABinderInstance; - } - -protected: - // A GC handle to the managed AssemblyLoadContext. - // It is a long weak handle for collectible AssemblyLoadContexts and strong handle for non-collectible ones. - INT_PTR m_ptrManagedAssemblyLoadContext; - -private: - SArray m_nativeImages; - SArray m_loadedAssemblies; -}; - -#endif diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index 3bba41fd00b520..37d27fb1a9c252 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -54,12 +54,12 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN DomainAssembly * pParentAssembly = NULL; Assembly * pRefAssembly = NULL; - AssemblyBinder *pBinderContext = NULL; + AssemblyBinder *pBinder = NULL; if (assemblyLoadContext.Get() != NULL) { - INT_PTR nativeAssemblyLoadContext = ((ASSEMBLYLOADCONTEXTREF)assemblyLoadContext.Get())->GetNativeAssemblyLoadContext(); - pBinderContext = reinterpret_cast(nativeAssemblyLoadContext); + INT_PTR nativeAssemblyBinder = ((ASSEMBLYLOADCONTEXTREF)assemblyLoadContext.Get())->GetNativeAssemblyBinder(); + pBinder = reinterpret_cast(nativeAssemblyBinder); } AssemblySpec spec; @@ -77,7 +77,7 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN { pRefAssembly = ((ASSEMBLYREF)requestingAssembly.Get())->GetAssembly(); } - else if (pBinderContext == NULL) + else if (pBinder == NULL) { pRefAssembly = SystemDomain::GetCallersAssembly(stackMark); } @@ -99,17 +99,17 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN // Have we been passed the reference to the binder against which this load should be triggered? // If so, then use it to set the fallback load context binder. - if (pBinderContext != NULL) + if (pBinder != NULL) { - spec.SetFallbackLoadContextBinderForRequestingAssembly(pBinderContext); - spec.SetPreferFallbackLoadContextBinder(); + spec.SetFallbackBinderForRequestingAssembly(pBinder); + spec.SetPreferFallbackBinder(); } else if (pRefAssembly != NULL) { // If the requesting assembly has Fallback LoadContext binder available, // then set it up in the AssemblySpec. PEFile *pRefAssemblyManifestFile = pRefAssembly->GetManifestFile(); - spec.SetFallbackLoadContextBinderForRequestingAssembly(pRefAssemblyManifestFile->GetFallbackLoadContextBinder()); + spec.SetFallbackBinderForRequestingAssembly(pRefAssemblyManifestFile->GetFallbackBinder()); } Assembly *pAssembly; @@ -127,12 +127,12 @@ void QCALLTYPE AssemblyNative::InternalLoad(QCall::ObjectHandleOnStack assemblyN } /* static */ -Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinderContext, PEImage *pImage) +Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pImage) { CONTRACT(Assembly*) { STANDARD_VM_CHECK; - PRECONDITION(CheckPointer(pBinderContext)); + PRECONDITION(CheckPointer(pBinder)); PRECONDITION(pImage != NULL); POSTCONDITION(CheckPointer(RETVAL)); } @@ -162,14 +162,13 @@ Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinderContext, PEImag // Initialize the AssemblySpec AssemblySpec spec; spec.InitializeSpec(TokenFromRid(1, mdtAssembly), pImage->GetMDImport(), pCallersAssembly); - spec.SetBindingContext(pBinderContext); + spec.SetBinder(pBinder); BinderTracing::AssemblyBindOperation bindOperation(&spec, pImage->GetPath()); HRESULT hr = S_OK; PTR_AppDomain pCurDomain = GetAppDomain(); - DefaultAssemblyBinder *pTPABinder = pCurDomain->GetTPABinderContext(); - hr = pBinderContext->BindUsingPEImage(pImage, &pAssembly); + hr = pBinder->BindUsingPEImage(pImage, &pAssembly); if (hr != S_OK) { @@ -192,7 +191,7 @@ Assembly* AssemblyNative::LoadFromPEImage(AssemblyBinder* pBinderContext, PEImag } /* static */ -void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext, LPCWSTR pwzILPath, LPCWSTR pwzNIPath, QCall::ObjectHandleOnStack retLoadedAssembly) +void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyBinder, LPCWSTR pwzILPath, LPCWSTR pwzNIPath, QCall::ObjectHandleOnStack retLoadedAssembly) { QCALL_CONTRACT; @@ -201,10 +200,10 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext PTR_AppDomain pCurDomain = GetAppDomain(); // Get the binder context in which the assembly will be loaded. - AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); - _ASSERTE(pBinderContext != NULL); + AssemblyBinder *pBinder = reinterpret_cast(ptrNativeAssemblyBinder); + _ASSERTE(pBinder != NULL); - // Form the PEImage for the ILAssembly. Incase of an exception, the holder will ensure + // Form the PEImage for the ILAssembly. In case of an exception, the holder will ensure // the release of the image. PEImageHolder pILImage; @@ -218,7 +217,7 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext if (!pILImage->CheckILFormat()) THROW_BAD_FORMAT(BFA_BAD_IL, pILImage.GetValue()); - LoaderAllocator* pLoaderAllocator = pBinderContext->GetLoaderAllocator(); + LoaderAllocator* pLoaderAllocator = pBinder->GetLoaderAllocator(); if (pLoaderAllocator && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly()) { // Loading IJW assemblies into a collectible AssemblyLoadContext is not allowed @@ -226,7 +225,7 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext } } - Assembly *pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinderContext, pILImage); + Assembly *pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinder, pILImage); { GCX_COOP(); @@ -241,7 +240,7 @@ void QCALLTYPE AssemblyNative::LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext } /*static */ -void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrAssemblyArray, +void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyBinder, INT_PTR ptrAssemblyArray, INT32 cbAssemblyArrayLength, INT_PTR ptrSymbolArray, INT32 cbSymbolArrayLength, QCall::ObjectHandleOnStack retLoadedAssembly) { @@ -250,7 +249,7 @@ void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyLoadConte BEGIN_QCALL; // Ensure that the invariants are in place - _ASSERTE(ptrNativeAssemblyLoadContext != NULL); + _ASSERTE(ptrNativeAssemblyBinder != NULL); _ASSERTE((ptrAssemblyArray != NULL) && (cbAssemblyArrayLength > 0)); _ASSERTE((ptrSymbolArray == NULL) || (cbSymbolArrayLength > 0)); @@ -265,9 +264,9 @@ 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 - AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinder = reinterpret_cast(ptrNativeAssemblyBinder); - LoaderAllocator* pLoaderAllocator = pBinderContext->GetLoaderAllocator(); + LoaderAllocator* pLoaderAllocator = pBinder->GetLoaderAllocator(); if (pLoaderAllocator && pLoaderAllocator->IsCollectible() && !pILImage->IsILOnly()) { // Loading IJW assemblies into a collectible AssemblyLoadContext is not allowed @@ -275,7 +274,7 @@ void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyLoadConte } // Pass the stream based assembly as IL in an attempt to bind and load it - Assembly* pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinderContext, pILImage); + Assembly* pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinder, pILImage); { GCX_COOP(); retLoadedAssembly.Set(pLoadedAssembly->GetExposedObject()); @@ -311,14 +310,14 @@ void QCALLTYPE AssemblyNative::LoadFromStream(INT_PTR ptrNativeAssemblyLoadConte #ifndef TARGET_UNIX /*static */ -void QCALLTYPE AssemblyNative::LoadFromInMemoryModule(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR hModule, QCall::ObjectHandleOnStack retLoadedAssembly) +void QCALLTYPE AssemblyNative::LoadFromInMemoryModule(INT_PTR ptrNativeAssemblyBinder, INT_PTR hModule, QCall::ObjectHandleOnStack retLoadedAssembly) { QCALL_CONTRACT; BEGIN_QCALL; // Ensure that the invariants are in place - _ASSERTE(ptrNativeAssemblyLoadContext != NULL); + _ASSERTE(ptrNativeAssemblyBinder != NULL); _ASSERTE(hModule != NULL); PEImageHolder pILImage(PEImage::LoadImage((HMODULE)hModule)); @@ -328,10 +327,10 @@ 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 - AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinder = reinterpret_cast(ptrNativeAssemblyBinder); // Pass the in memory module as IL in an attempt to bind and load it - Assembly* pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinderContext, pILImage); + Assembly* pLoadedAssembly = AssemblyNative::LoadFromPEImage(pBinder, pILImage); { GCX_COOP(); retLoadedAssembly.Set(pLoadedAssembly->GetExposedObject()); @@ -382,20 +381,20 @@ void QCALLTYPE AssemblyNative::GetType(QCall::AssemblyHandle pAssembly, BOOL prohibitAsmQualifiedName = TRUE; - AssemblyBinder * pPrivHostBinder = NULL; + AssemblyBinder * pBinder = NULL; if (*pAssemblyLoadContext.m_ppObject != NULL) { GCX_COOP(); ASSEMBLYLOADCONTEXTREF * pAssemblyLoadContextRef = reinterpret_cast(pAssemblyLoadContext.m_ppObject); - INT_PTR nativeAssemblyLoadContext = (*pAssemblyLoadContextRef)->GetNativeAssemblyLoadContext(); + INT_PTR nativeAssemblyBinder = (*pAssemblyLoadContextRef)->GetNativeAssemblyBinder(); - pPrivHostBinder = reinterpret_cast(nativeAssemblyLoadContext); + pBinder = reinterpret_cast(nativeAssemblyBinder); } // Load the class from this assembly (fail if it is in a different one). - retTypeHandle = TypeName::GetTypeManaged(wszName, pAssembly, bThrowOnError, bIgnoreCase, prohibitAsmQualifiedName, pAssembly->GetAssembly(), (OBJECTREF*)keepAlive.m_ppObject, pPrivHostBinder); + retTypeHandle = TypeName::GetTypeManaged(wszName, pAssembly, bThrowOnError, bIgnoreCase, prohibitAsmQualifiedName, pAssembly->GetAssembly(), (OBJECTREF*)keepAlive.m_ppObject, pBinder); if (!retTypeHandle.IsNull()) { @@ -1157,7 +1156,7 @@ INT_PTR QCALLTYPE AssemblyNative::InitializeAssemblyLoadContext(INT_PTR ptrManag { QCALL_CONTRACT; - INT_PTR ptrNativeAssemblyLoadContext = NULL; + INT_PTR ptrNativeAssemblyBinder = NULL; BEGIN_QCALL; @@ -1167,11 +1166,11 @@ INT_PTR QCALLTYPE AssemblyNative::InitializeAssemblyLoadContext(INT_PTR ptrManag // Initialize the assembly binder instance in the VM PTR_AppDomain pCurDomain = AppDomain::GetCurrentDomain(); - DefaultAssemblyBinder *pTPABinderContext = pCurDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pDefaultBinder = pCurDomain->GetDefaultBinder(); if (!fRepresentsTPALoadContext) { - // Initialize a custom Assembly Load Context - CustomAssemblyBinder *pBindContext = NULL; + // Initialize a custom assembly binder + CustomAssemblyBinder *pCustomBinder = NULL; AssemblyLoaderAllocator* loaderAllocator = NULL; OBJECTHANDLE loaderAllocatorHandle = NULL; @@ -1206,27 +1205,27 @@ INT_PTR QCALLTYPE AssemblyNative::InitializeAssemblyLoadContext(INT_PTR ptrManag loaderAllocator->ActivateManagedTracking(); } - IfFailThrow(CustomAssemblyBinder::SetupContext(pTPABinderContext, loaderAllocator, loaderAllocatorHandle, ptrManagedAssemblyLoadContext, &pBindContext)); - ptrNativeAssemblyLoadContext = reinterpret_cast(pBindContext); + IfFailThrow(CustomAssemblyBinder::SetupContext(pDefaultBinder, loaderAllocator, loaderAllocatorHandle, ptrManagedAssemblyLoadContext, &pCustomBinder)); + ptrNativeAssemblyBinder = reinterpret_cast(pCustomBinder); } else { // We are initializing the managed instance of Assembly Load Context that would represent the TPA binder. // First, confirm we do not have an existing managed ALC attached to the TPA binder. - _ASSERTE(pTPABinderContext->GetManagedAssemblyLoadContext() == NULL); + _ASSERTE(pDefaultBinder->GetManagedAssemblyLoadContext() == NULL); // Attach the managed TPA binding context with the native one. - pTPABinderContext->SetManagedAssemblyLoadContext(ptrManagedAssemblyLoadContext); - ptrNativeAssemblyLoadContext = reinterpret_cast(pTPABinderContext); + pDefaultBinder->SetManagedAssemblyLoadContext(ptrManagedAssemblyLoadContext); + ptrNativeAssemblyBinder = reinterpret_cast(pDefaultBinder); } END_QCALL; - return ptrNativeAssemblyLoadContext; + return ptrNativeAssemblyBinder; } /*static*/ -void QCALLTYPE AssemblyNative::PrepareForAssemblyLoadContextRelease(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrManagedStrongAssemblyLoadContext) +void QCALLTYPE AssemblyNative::PrepareForAssemblyLoadContextRelease(INT_PTR ptrNativeAssemblyBinder, INT_PTR ptrManagedStrongAssemblyLoadContext) { QCALL_CONTRACT; @@ -1237,7 +1236,7 @@ void QCALLTYPE AssemblyNative::PrepareForAssemblyLoadContextRelease(INT_PTR ptrN { GCX_COOP(); - reinterpret_cast(ptrNativeAssemblyLoadContext)->PrepareForLoadContextRelease(ptrManagedStrongAssemblyLoadContext); + reinterpret_cast(ptrNativeAssemblyBinder)->PrepareForLoadContextRelease(ptrManagedStrongAssemblyLoadContext); } END_QCALL; @@ -1254,16 +1253,12 @@ INT_PTR QCALLTYPE AssemblyNative::GetLoadContextForAssembly(QCall::AssemblyHandl _ASSERTE(pAssembly != NULL); - AssemblyLoadContext* pAssemblyLoadContext = pAssembly->GetFile()->GetAssemblyLoadContext(); + AssemblyBinder* pAssemblyBinder = pAssembly->GetFile()->GetAssemblyBinder(); - if (pAssemblyLoadContext != AppDomain::GetCurrentDomain()->GetTPABinderContext()) + if (!pAssemblyBinder->IsDefault()) { - // Only CustomAssemblyBinder instance contains the reference to its - // corresponding managed instance. - CustomAssemblyBinder* pBinder = (CustomAssemblyBinder*)(pAssemblyLoadContext); - // Fetch the managed binder reference from the native binder instance - ptrManagedAssemblyLoadContext = pBinder->GetManagedAssemblyLoadContext(); + ptrManagedAssemblyLoadContext = pAssemblyBinder->GetManagedAssemblyLoadContext(); _ASSERTE(ptrManagedAssemblyLoadContext != NULL); } diff --git a/src/coreclr/vm/assemblynative.hpp b/src/coreclr/vm/assemblynative.hpp index c7beef6e4372dc..a4ecc62da9a325 100644 --- a/src/coreclr/vm/assemblynative.hpp +++ b/src/coreclr/vm/assemblynative.hpp @@ -112,14 +112,14 @@ class AssemblyNative // static INT_PTR QCALLTYPE InitializeAssemblyLoadContext(INT_PTR ptrManagedAssemblyLoadContext, BOOL fRepresentsTPALoadContext, BOOL fIsCollectible); - static void QCALLTYPE PrepareForAssemblyLoadContextRelease(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrManagedStrongAssemblyLoadContext); + static void QCALLTYPE PrepareForAssemblyLoadContextRelease(INT_PTR ptrNativeAssemblyBinder, INT_PTR ptrManagedStrongAssemblyLoadContext); static void QCALLTYPE InternalLoad(QCall::ObjectHandleOnStack assemblyName, QCall::ObjectHandleOnStack requestingAssembly, QCall::StackCrawlMarkHandle stackMark,BOOL fThrowOnFileNotFound, QCall::ObjectHandleOnStack assemblyLoadContext, QCall::ObjectHandleOnStack retAssembly); - static void QCALLTYPE LoadFromPath(INT_PTR ptrNativeAssemblyLoadContext, LPCWSTR pwzILPath, LPCWSTR pwzNIPath, QCall::ObjectHandleOnStack retLoadedAssembly); - static void QCALLTYPE LoadFromStream(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrAssemblyArray, INT32 cbAssemblyArrayLength, INT_PTR ptrSymbolArray, INT32 cbSymbolArrayLength, QCall::ObjectHandleOnStack retLoadedAssembly); + static void QCALLTYPE LoadFromPath(INT_PTR ptrNativeAssemblyBinder, LPCWSTR pwzILPath, LPCWSTR pwzNIPath, QCall::ObjectHandleOnStack retLoadedAssembly); + static void QCALLTYPE LoadFromStream(INT_PTR ptrNativeAssemblyBinder, INT_PTR ptrAssemblyArray, INT32 cbAssemblyArrayLength, INT_PTR ptrSymbolArray, INT32 cbSymbolArrayLength, QCall::ObjectHandleOnStack retLoadedAssembly); #ifndef TARGET_UNIX - static void QCALLTYPE LoadFromInMemoryModule(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR hModule, QCall::ObjectHandleOnStack retLoadedAssembly); + static void QCALLTYPE LoadFromInMemoryModule(INT_PTR ptrNativeAssemblyBinder, INT_PTR hModule, QCall::ObjectHandleOnStack retLoadedAssembly); #endif - static Assembly* LoadFromPEImage(AssemblyBinder* pBinderContext, PEImage *pImage); + static Assembly* LoadFromPEImage(AssemblyBinder* pBinder, PEImage *pImage); 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 7f2247aa0a792f..989c834563f4f0 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -238,16 +238,16 @@ void AssemblySpec::InitializeSpec(PEAssembly * pFile) InitializeSpec(a, pImport, NULL); // Set the binding context for the AssemblySpec - AssemblyBinder* pCurrentBinder = GetBindingContext(); - AssemblyBinder* pExpectedBinder = pFile->GetBindingContext(); + AssemblyBinder* pCurrentBinder = GetBinder(); + AssemblyBinder* pExpectedBinder = pFile->GetBinder(); if (pCurrentBinder == NULL) { - // We should aways having the binding context in the PEAssembly. The only exception to this are the following: + // We should aways have the binding context in the PEAssembly. The only exception to this are the following: // // 1) when we are here during EEStartup and loading CoreLib. // 2) We are dealing with dynamic assemblies _ASSERTE((pExpectedBinder != NULL) || pFile->IsSystem() || pFile->IsDynamic()); - SetBindingContext(pExpectedBinder); + SetBinder(pExpectedBinder); } } @@ -676,7 +676,7 @@ Assembly *AssemblySpec::LoadAssembly(FileLoadLevel targetLevel, BOOL fThrowOnFil return pDomainAssembly->GetAssembly(); } -AssemblyBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDomain) +AssemblyBinder* AssemblySpec::GetBinderFromParentAssembly(AppDomain *pDomain) { CONTRACTL { @@ -694,14 +694,14 @@ AssemblyBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo { // Get the PEAssembly associated with the parent's domain assembly PEAssembly *pParentPEAssembly = pParentDomainAssembly->GetFile(); - pParentAssemblyBinder = pParentPEAssembly->GetBindingContext(); + pParentAssemblyBinder = pParentPEAssembly->GetBinder(); } - if (GetPreferFallbackLoadContextBinder()) + if (GetPreferFallbackBinder()) { // If we have been asked to use the fallback load context binder (currently only supported for AssemblyLoadContext.LoadFromAssemblyName), // then pretend we do not have any binder yet available. - _ASSERTE(GetFallbackLoadContextBinderForRequestingAssembly() != NULL); + _ASSERTE(GetFallbackBinderForRequestingAssembly() != NULL); pParentAssemblyBinder = NULL; } @@ -719,22 +719,7 @@ AssemblyBinder* AssemblySpec::GetBindingContextFromParentAssembly(AppDomain *pDo // // For (3), fetch the fallback load context binder reference. - pParentAssemblyBinder = GetFallbackLoadContextBinderForRequestingAssembly(); - } - - if (pParentAssemblyBinder != NULL) - { - 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 - // via the custom binder context, if it was overridden. If it was not overridden, then we will get the expected - // 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 = GetFallbackBinderForRequestingAssembly(); } if (!pParentAssemblyBinder) @@ -744,7 +729,7 @@ AssemblyBinder* 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->GetDefaultBinder()); } return pParentAssemblyBinder; @@ -1006,22 +991,20 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter UPTR key = (UPTR)pSpec->Hash(); - // On CoreCLR, we will use the BinderID as the key - AssemblyBinder *pBinderContextForLookup = NULL; - AppDomain *pSpecDomain = pSpec->GetAppDomain(); + AssemblyBinder *pBinderForLookup = NULL; bool fGetBindingContextFromParent = true; // Check if the AssemblySpec already has specified its binding context. This will be set for assemblies that are // attempted to be explicitly bound using AssemblyLoadContext LoadFrom* methods. if(!pSpec->IsAssemblySpecForCoreLib()) - pBinderContextForLookup = pSpec->GetBindingContext(); + pBinderForLookup = pSpec->GetBinder(); else { // For System.Private.Corelib Binding context is either not set or if set then it should be TPA - _ASSERTE(pSpec->GetBindingContext() == NULL || pSpec->GetBindingContext() == pSpecDomain->GetTPABinderContext()); + _ASSERTE(pSpec->GetBinder() == NULL || pSpec->GetBinder()->IsDefault()); } - if (pBinderContextForLookup != NULL) + if (pBinderForLookup != NULL) { // We are working with the actual binding context in which the assembly was expected to be loaded. // Thus, we don't need to get it from the parent assembly. @@ -1034,14 +1017,14 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter // using its AssemblySpec hash. if (!pSpec->IsAssemblySpecForCoreLib()) { - pBinderContextForLookup = pSpec->GetBindingContextFromParentAssembly(pSpecDomain); - pSpec->SetBindingContext(pBinderContextForLookup); + pBinderForLookup = pSpec->GetBinderFromParentAssembly(pSpec->GetAppDomain()); + pSpec->SetBinder(pBinderForLookup); } } - if (pBinderContextForLookup) + if (pBinderForLookup) { - key = key ^ (UPTR)pBinderContextForLookup; + key = key ^ (UPTR)pBinderForLookup; } AssemblyBinding* pEntry = (AssemblyBinding *)m_map.LookupValue(key, pSpec); @@ -1052,7 +1035,7 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter { if (pEntry == (AssemblyBinding *) INVALIDENTRY) { - pSpec->SetBindingContext(NULL); + pSpec->SetBinder(NULL); } } @@ -1250,17 +1233,16 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly UPTR key = (UPTR)pSpec->Hash(); - // On CoreCLR, we will use the BinderID as the key - AssemblyBinder* pBinderContextForLookup = pAssembly->GetFile()->GetBindingContext(); + AssemblyBinder* pBinderContextForLookup = pAssembly->GetFile()->GetBinder(); _ASSERTE(pBinderContextForLookup || pAssembly->GetFile()->IsSystem()); if (pBinderContextForLookup) { key = key ^ (UPTR)pBinderContextForLookup; - if (!pSpec->GetBindingContext()) + if (!pSpec->GetBinder()) { - pSpec->SetBindingContext(pBinderContextForLookup); + pSpec->SetBinder(pBinderContextForLookup); } } @@ -1332,17 +1314,16 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) UPTR key = (UPTR)pSpec->Hash(); - // On CoreCLR, we will use the BinderID as the key - AssemblyBinder* pBinderContextForLookup = pFile->GetBindingContext(); + AssemblyBinder* pBinderContextForLookup = pFile->GetBinder(); _ASSERTE(pBinderContextForLookup || pFile->IsSystem()); if (pBinderContextForLookup) { key = key ^ (UPTR)pBinderContextForLookup; - if (!pSpec->GetBindingContext()) + if (!pSpec->GetBinder()) { - pSpec->SetBindingContext(pBinderContextForLookup); + pSpec->SetBinder(pBinderContextForLookup); } } @@ -1420,14 +1401,14 @@ BOOL AssemblySpecBindingCache::StoreException(AssemblySpec *pSpec, Exception* pE // TODO: Merge this with the failure lookup in the binder // // Since no entry was found for this assembly in any binding context, save the failure - // in the TPABinder context + // in the DefaultBinder context AssemblyBinder* pBinderToSaveException = NULL; - pBinderToSaveException = pSpec->GetBindingContext(); + pBinderToSaveException = pSpec->GetBinder(); if (pBinderToSaveException == NULL) { if (!pSpec->IsAssemblySpecForCoreLib()) { - pBinderToSaveException = pSpec->GetBindingContextFromParentAssembly(pSpec->GetAppDomain()); + pBinderToSaveException = pSpec->GetBinderFromParentAssembly(pSpec->GetAppDomain()); key = key ^ (UPTR)pBinderToSaveException; } } diff --git a/src/coreclr/vm/assemblyspec.hpp b/src/coreclr/vm/assemblyspec.hpp index 804bd832e2651a..63ffac82f6e7a8 100644 --- a/src/coreclr/vm/assemblyspec.hpp +++ b/src/coreclr/vm/assemblyspec.hpp @@ -32,10 +32,10 @@ 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) - AssemblyBinder *m_pFallbackLoadContextBinder; + AssemblyBinder *m_pFallbackBinder; // Flag to indicate if we should prefer the fallback load context binder for binding or not. - bool m_fPreferFallbackLoadContextBinder; + bool m_fPreferFallbackBinder; BOOL IsValidAssemblyName(); @@ -50,7 +50,7 @@ class AssemblySpec : public BaseAssemblySpec mdAssemblyRef kAssemblyRef, IMDInternalImport * pMDImportOverride, BOOL fDoNotUtilizeExtraChecks, - AssemblyBinder *pBindingContextForLoadedAssembly); + AssemblyBinder *pBinderForLoadedAssembly); public: @@ -60,8 +60,8 @@ class AssemblySpec : public BaseAssemblySpec LIMITED_METHOD_CONTRACT; m_pParentAssembly = NULL; - m_pFallbackLoadContextBinder = NULL; - m_fPreferFallbackLoadContextBinder = false; + m_pFallbackBinder = NULL; + m_fPreferFallbackBinder = false; } #endif //!DACCESS_COMPILE @@ -71,15 +71,15 @@ class AssemblySpec : public BaseAssemblySpec LIMITED_METHOD_CONTRACT m_pParentAssembly = NULL; - m_pFallbackLoadContextBinder = NULL; - m_fPreferFallbackLoadContextBinder = false; + m_pFallbackBinder = NULL; + m_fPreferFallbackBinder = false; } DomainAssembly* GetParentAssembly(); - AssemblyBinder* GetBindingContextFromParentAssembly(AppDomain *pDomain); + AssemblyBinder* GetBinderFromParentAssembly(AppDomain *pDomain); bool HasParentAssembly() { WRAPPER_NO_CONTRACT; return GetParentAssembly() != NULL; } @@ -130,32 +130,32 @@ class AssemblySpec : public BaseAssemblySpec m_pParentAssembly = pAssembly; } - void SetFallbackLoadContextBinderForRequestingAssembly(AssemblyBinder *pFallbackLoadContextBinder) + void SetFallbackBinderForRequestingAssembly(AssemblyBinder *pFallbackBinder) { LIMITED_METHOD_CONTRACT; - m_pFallbackLoadContextBinder = pFallbackLoadContextBinder; + m_pFallbackBinder = pFallbackBinder; } - AssemblyBinder* GetFallbackLoadContextBinderForRequestingAssembly() + AssemblyBinder* GetFallbackBinderForRequestingAssembly() { LIMITED_METHOD_CONTRACT; - return m_pFallbackLoadContextBinder; + return m_pFallbackBinder; } - void SetPreferFallbackLoadContextBinder() + void SetPreferFallbackBinder() { LIMITED_METHOD_CONTRACT; - m_fPreferFallbackLoadContextBinder = true; + m_fPreferFallbackBinder = true; } - bool GetPreferFallbackLoadContextBinder() + bool GetPreferFallbackBinder() { LIMITED_METHOD_CONTRACT; - return m_fPreferFallbackLoadContextBinder; + return m_fPreferFallbackBinder; } // Note that this method does not clone the fields! @@ -174,8 +174,8 @@ class AssemblySpec : public BaseAssemblySpec SetParentAssembly(pSource->GetParentAssembly()); // Copy the details of the fallback load context binder - SetFallbackLoadContextBinderForRequestingAssembly(pSource->GetFallbackLoadContextBinderForRequestingAssembly()); - m_fPreferFallbackLoadContextBinder = pSource->GetPreferFallbackLoadContextBinder(); + SetFallbackBinderForRequestingAssembly(pSource->GetFallbackBinderForRequestingAssembly()); + m_fPreferFallbackBinder = pSource->GetPreferFallbackBinder(); m_dwHashAlg = pSource->m_dwHashAlg; } @@ -185,10 +185,9 @@ class AssemblySpec : public BaseAssemblySpec HRESULT EmitToken(IMetaDataAssemblyEmit *pEmit, mdAssemblyRef *pToken); - VOID Bind( + HRESULT Bind( AppDomain* pAppDomain, - BOOL fThrowOnFileNotFound, - CoreBindResult* pBindResult); + BINDER_SPACE::Assembly** ppAssembly); Assembly *LoadAssembly(FileLoadLevel targetLevel, BOOL fThrowOnFileNotFound = TRUE); diff --git a/src/coreclr/vm/assemblyspecbase.h b/src/coreclr/vm/assemblyspecbase.h index 00cd7a1105df26..c9db2e04b9f839 100644 --- a/src/coreclr/vm/assemblyspecbase.h +++ b/src/coreclr/vm/assemblyspecbase.h @@ -15,8 +15,6 @@ #ifndef __ASSEMBLY_SPEC_BASE_H__ #define __ASSEMBLY_SPEC_BASE_H__ -#include "coreclr/corebindresult.h" -#include "coreclr/corebindresult.inl" #include "../binder/inc/assembly.hpp" #include "baseassemblyspec.h" diff --git a/src/coreclr/vm/baseassemblyspec.h b/src/coreclr/vm/baseassemblyspec.h index b8eb1a9b1daf7e..644a3c4a825f57 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; - AssemblyBinder *m_pBindingContext; + AssemblyBinder *m_pBinder; public: enum @@ -63,18 +63,18 @@ class BaseAssemblySpec VOID CloneFieldsToLoaderHeap(int flags, LoaderHeap *pHeap, AllocMemTracker *pamTracker); VOID CloneFieldsToStackingAllocator(StackingAllocator* alloc); - inline void SetBindingContext(AssemblyBinder *pBindingContext) + inline void SetBinder(AssemblyBinder *pBinder) { LIMITED_METHOD_CONTRACT; - m_pBindingContext = pBindingContext; + m_pBinder = pBinder; } - inline AssemblyBinder* GetBindingContext() + inline AssemblyBinder* GetBinder() { LIMITED_METHOD_CONTRACT; - return m_pBindingContext; + return m_pBinder; } BOOL IsAssemblySpecForCoreLib(); diff --git a/src/coreclr/vm/baseassemblyspec.inl b/src/coreclr/vm/baseassemblyspec.inl index 5f92ea82cf2522..d642c01b4973b1 100644 --- a/src/coreclr/vm/baseassemblyspec.inl +++ b/src/coreclr/vm/baseassemblyspec.inl @@ -209,7 +209,7 @@ inline void BaseAssemblySpec::CopyFrom(const BaseAssemblySpec *pSpec) } - m_pBindingContext = pSpec->m_pBindingContext; + m_pBinder = pSpec->m_pBinder; } @@ -320,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 (pSpec->m_pBindingContext != m_pBindingContext) + if (pSpec->m_pBinder != m_pBinder) { return FALSE; } diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 319e516f8845ce..c369aeaaf6080d 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -3395,7 +3395,7 @@ Module::GetAssemblyIfLoaded( mdAssemblyRef kAssemblyRef, IMDInternalImport * pMDImportOverride, // = NULL BOOL fDoNotUtilizeExtraChecks, // = FALSE - AssemblyBinder *pBindingContextForLoadedAssembly // = NULL + AssemblyBinder *pBinderForLoadedAssembly // = NULL ) { CONTRACT(Assembly *) @@ -3473,10 +3473,10 @@ Module::GetAssemblyIfLoaded( // If we have been passed the binding context for the loaded assembly that is being looked up in the // cache, then set it up in the AssemblySpec for the cache lookup to use it below. - if (pBindingContextForLoadedAssembly != NULL) + if (pBinderForLoadedAssembly != NULL) { - _ASSERTE(spec.GetBindingContext() == NULL); - spec.SetBindingContext(pBindingContextForLoadedAssembly); + _ASSERTE(spec.GetBinder() == NULL); + spec.SetBinder(pBinderForLoadedAssembly); } DomainAssembly * pDomainAssembly = nullptr; @@ -3583,10 +3583,10 @@ 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. - AssemblyBinder *pBindingContext = pFile->GetBindingContext(); - if (pBindingContext != NULL) + AssemblyBinder *pBinder = pFile->GetBinder(); + if (pBinder != NULL) { - spec.SetBindingContext(pBindingContext); + spec.SetBinder(pBinder); } pDomainAssembly = GetAppDomain()->LoadDomainAssembly(&spec, pFile, FILE_LOADED); } diff --git a/src/coreclr/vm/ceeload.h b/src/coreclr/vm/ceeload.h index 5fac1e5f4d5fde..0365c316f0a8c1 100644 --- a/src/coreclr/vm/ceeload.h +++ b/src/coreclr/vm/ceeload.h @@ -1575,7 +1575,7 @@ class Module mdAssemblyRef kAssemblyRef, IMDInternalImport * pMDImportOverride = NULL, BOOL fDoNotUtilizeExtraChecks = FALSE, - AssemblyBinder *pBindingContextForLoadedAssembly = NULL + AssemblyBinder *pBinderForLoadedAssembly = NULL ); public: diff --git a/src/coreclr/vm/common.h b/src/coreclr/vm/common.h index 6a06abad946dd0..7d2f3532219a3e 100644 --- a/src/coreclr/vm/common.h +++ b/src/coreclr/vm/common.h @@ -111,7 +111,7 @@ typedef DPTR(class ArrayBase) PTR_ArrayBase; typedef DPTR(class Assembly) PTR_Assembly; typedef DPTR(class AssemblyBaseObject) PTR_AssemblyBaseObject; typedef DPTR(class AssemblyLoadContextBaseObject) PTR_AssemblyLoadContextBaseObject; -typedef DPTR(class AssemblyLoadContext) PTR_AssemblyLoadContext; +typedef DPTR(class AssemblyBinder) PTR_AssemblyBinder; typedef DPTR(class AssemblyNameBaseObject) PTR_AssemblyNameBaseObject; typedef VPTR(class BaseDomain) PTR_BaseDomain; typedef DPTR(class ClassLoader) PTR_ClassLoader; diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index b3128be6c3827f..59eb9d30fae76d 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -68,30 +68,22 @@ static VOID ThrowLoadError(AssemblySpec * pSpec, HRESULT hr) EEFileLoadException::Throw(name, hr); } -VOID AssemblySpec::Bind(AppDomain *pAppDomain, - BOOL fThrowOnFileNotFound, - CoreBindResult *pResult) +HRESULT AssemblySpec::Bind(AppDomain *pAppDomain, BINDER_SPACE::Assembly** ppAssembly) { CONTRACTL { INSTANCE_CHECK; STANDARD_VM_CHECK; - PRECONDITION(CheckPointer(pResult)); + PRECONDITION(CheckPointer(ppAssembly)); PRECONDITION(CheckPointer(pAppDomain)); PRECONDITION(IsCoreLib() == FALSE); // This should never be called for CoreLib (explicit loading) } CONTRACTL_END; - ReleaseHolder result; HRESULT hr=S_OK; - pResult->Reset(); - // Have a default binding context setup - AssemblyBinder *pBinder = GetBindingContextFromParentAssembly(pAppDomain); - - // Get the reference to the TPABinder context - DefaultAssemblyBinder *pTPABinder = pAppDomain->GetTPABinderContext(); + AssemblyBinder *pBinder = GetBinderFromParentAssembly(pAppDomain); ReleaseHolder pPrivAsm; _ASSERTE(pBinder != NULL); @@ -123,25 +115,18 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, } else { - hr = pTPABinder->Bind(m_wszCodeBase, - GetParentAssembly() ? GetParentAssembly()->GetFile() : NULL, - &pPrivAsm); + hr = pAppDomain->GetDefaultBinder()->Bind(m_wszCodeBase, + GetParentAssembly() ? GetParentAssembly()->GetFile() : NULL, + &pPrivAsm); } - pResult->SetHRBindResult(hr); if (SUCCEEDED(hr)) { _ASSERTE(pPrivAsm != nullptr); - - result = pPrivAsm.Extract(); - _ASSERTE(result != nullptr); - - pResult->Init(result); - } - else if (FAILED(hr) && (fThrowOnFileNotFound || (!Assembly::FileNotFound(hr)))) - { - ThrowLoadError(this, hr); + *ppAssembly = pPrivAsm.Extract(); } + + return hr; } @@ -232,7 +217,7 @@ HRESULT BaseAssemblySpec::ParseName() _ASSERTE(pDomain); BINDER_SPACE::ApplicationContext *pAppContext = NULL; - DefaultAssemblyBinder *pBinder = pDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pBinder = pDomain->GetDefaultBinder(); if (pBinder != NULL) { pAppContext = pBinder->GetAppContext(); diff --git a/src/coreclr/vm/corebindresult.cpp b/src/coreclr/vm/corebindresult.cpp deleted file mode 100644 index 53bb8717d06a8c..00000000000000 --- a/src/coreclr/vm/corebindresult.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// CoreBindResult.cpp -// - -// -// Implements the CoreBindResult class -// ============================================================ - - -#include "common.h" - -#include "../binder/inc/assembly.hpp" - -STDMETHODIMP CoreBindResult::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) CoreBindResult::AddRef() -{ - return InterlockedIncrement(&m_cRef); -} - -STDMETHODIMP_(ULONG) CoreBindResult::Release() -{ - ULONG ulRef = InterlockedDecrement(&m_cRef); - - if (ulRef == 0) - { - delete this; - } - - return ulRef; -} diff --git a/src/coreclr/vm/coreclr/corebindresult.h b/src/coreclr/vm/coreclr/corebindresult.h deleted file mode 100644 index f19c75ad802bcd..00000000000000 --- a/src/coreclr/vm/coreclr/corebindresult.h +++ /dev/null @@ -1,52 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// CoreBindResult.h -// - -// -// Declares the CoreBindResult class -// BindResult represent a result of an assembly bind and might encapsulate PEImage, IAssembly, IHostAssebmly etc. -// This is CoreCLR implementation of it -// ============================================================ - -#ifndef __CORE_BIND_RESULT_H__ -#define __CORE_BIND_RESULT_H__ - -#include "../../binder/inc/assembly.hpp" - -struct CoreBindResult : public IUnknown -{ -protected: - ReleaseHolder m_pAssembly; - HRESULT m_hrBindResult; - LONG m_cRef; - -public: - - // IUnknown methods - STDMETHOD(QueryInterface)(REFIID riid, - void ** ppv); - STDMETHOD_(ULONG, AddRef)(); - STDMETHOD_(ULONG, Release)(); - - // CoreBindResult methods - CoreBindResult() : m_cRef(1) {} - virtual ~CoreBindResult() {} - - void Init(BINDER_SPACE::Assembly* pAssembly); - void Reset(); - - BOOL Found(); - PEImage* GetPEImage(); - BOOL IsCoreLib(); - void GetBindAssembly(BINDER_SPACE::Assembly** ppAssembly); - - void SetHRBindResult(HRESULT hrBindResult); - HRESULT GetHRBindResult(); -}; - - -#endif // __CORE_BIND_RESULT_H__ - diff --git a/src/coreclr/vm/coreclr/corebindresult.inl b/src/coreclr/vm/coreclr/corebindresult.inl deleted file mode 100644 index bca8355b5d1d74..00000000000000 --- a/src/coreclr/vm/coreclr/corebindresult.inl +++ /dev/null @@ -1,86 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// CoreBindResult.inl -// - -// -// Implements the CoreBindResult class -// ============================================================ - -#ifndef __CORE_BIND_RESULT_INL__ -#define __CORE_BIND_RESULT_INL__ - -inline BOOL CoreBindResult::Found() -{ - LIMITED_METHOD_CONTRACT; - return (m_pAssembly!=NULL); -}; - -inline BOOL CoreBindResult::IsCoreLib() -{ - CONTRACTL - { - THROWS; - MODE_ANY; - PRECONDITION(Found()); - } - CONTRACTL_END; - - return m_pAssembly->GetAssemblyName()->IsCoreLib(); -} - -inline void CoreBindResult::GetBindAssembly(BINDER_SPACE::Assembly** ppAssembly) -{ - CONTRACTL - { - NOTHROW; - MODE_ANY; - PRECONDITION(Found()); - } - CONTRACTL_END; - - m_pAssembly->AddRef(); - *ppAssembly = m_pAssembly; -} - - -inline PEImage* CoreBindResult::GetPEImage() -{ - WRAPPER_NO_CONTRACT; - return m_pAssembly ? - m_pAssembly->GetPEImage() : - NULL; -}; - -inline void CoreBindResult::Init(BINDER_SPACE::Assembly* pAssembly) -{ - WRAPPER_NO_CONTRACT; - m_pAssembly=pAssembly; - if(pAssembly) - pAssembly->AddRef(); - m_hrBindResult = S_OK; -} - -inline void CoreBindResult::Reset() -{ - WRAPPER_NO_CONTRACT; - m_pAssembly=NULL; - m_hrBindResult = S_OK; -} - -inline void CoreBindResult::SetHRBindResult(HRESULT hrBindResult) -{ - WRAPPER_NO_CONTRACT; - m_hrBindResult = hrBindResult; -} - -inline HRESULT CoreBindResult::GetHRBindResult() -{ - WRAPPER_NO_CONTRACT; - return m_hrBindResult; -} - -#endif // __CORE_BIND_RESULT_INL__ - diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index 1c691424d12837..a4b2bfa74a8762 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -674,7 +674,7 @@ HRESULT CorHost2::CreateAppDomainWithManager( SString sPlatformResourceRoots(pwzPlatformResourceRoots); SString sAppPaths(pwzAppPaths); - DefaultAssemblyBinder *pBinder = pDomain->GetTPABinderContext(); + DefaultAssemblyBinder *pBinder = pDomain->GetDefaultBinder(); _ASSERTE(pBinder != NULL); IfFailThrow(pBinder->SetupBindingPaths( sTrustedPlatformAssemblies, diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index 72d6b5eb4dad88..b94be184959d73 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -1031,7 +1031,7 @@ HRESULT MulticoreJitRecorder::StartProfile(const WCHAR * pRoot, const WCHAR * pF } NewHolder player(new (nothrow) MulticoreJitProfilePlayer( - m_pBinderContext, + m_pBinder, nSession)); if (player == NULL) @@ -1159,7 +1159,7 @@ void MulticoreJitManager::SetProfileRoot(const WCHAR * pProfilePath) // API Function: StartProfile // Threading: protected by m_playerLock -void MulticoreJitManager::StartProfile(AppDomain * pDomain, AssemblyBinder *pBinderContext, const WCHAR * pProfile, int suffix) +void MulticoreJitManager::StartProfile(AppDomain * pDomain, AssemblyBinder *pBinder, const WCHAR * pProfile, int suffix) { CONTRACTL { @@ -1201,7 +1201,7 @@ void MulticoreJitManager::StartProfile(AppDomain * pDomain, AssemblyBinder *pBin MulticoreJitRecorder * pRecorder = new (nothrow) MulticoreJitRecorder( pDomain, - pBinderContext, + pBinder, gatherProfile); if (pRecorder != NULL) @@ -1554,9 +1554,9 @@ DWORD MulticoreJitManager::EncodeModuleHelper(void * pModuleContext, Module * pR // // Arguments: // wszProfile - profile name -// ptrNativeAssemblyLoadContext - the binding context +// ptrNativeAssemblyBinder - the binding context // -void QCALLTYPE MultiCoreJITNative::InternalStartProfile(__in_z LPCWSTR wszProfile, INT_PTR ptrNativeAssemblyLoadContext) +void QCALLTYPE MultiCoreJITNative::InternalStartProfile(__in_z LPCWSTR wszProfile, INT_PTR ptrNativeAssemblyBinder) { QCALL_CONTRACT; @@ -1564,11 +1564,11 @@ void QCALLTYPE MultiCoreJITNative::InternalStartProfile(__in_z LPCWSTR wszProfil AppDomain * pDomain = GetAppDomain(); - AssemblyBinder *pBinderContext = reinterpret_cast(ptrNativeAssemblyLoadContext); + AssemblyBinder *pBinder = reinterpret_cast(ptrNativeAssemblyBinder); pDomain->GetMulticoreJitManager().StartProfile( pDomain, - pBinderContext, + pBinder, wszProfile); END_QCALL; diff --git a/src/coreclr/vm/multicorejit.h b/src/coreclr/vm/multicorejit.h index eeda366f9ae272..4f2b074b714f84 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, AssemblyBinder * pBinderContext, const WCHAR * pProfile, int suffix = -1); + void StartProfile(AppDomain * pDomain, AssemblyBinder * pBinder, const WCHAR * pProfile, int suffix = -1); // Multicore JIT API function (internal): AbortProfile void AbortProfile(); @@ -318,7 +318,7 @@ class MultiCoreJITNative public: static void QCALLTYPE InternalSetProfileRoot(__in_z LPCWSTR directoryPath); - static void QCALLTYPE InternalStartProfile(__in_z LPCWSTR wszProfile, INT_PTR ptrNativeAssemblyLoadContext); + static void QCALLTYPE InternalStartProfile(__in_z LPCWSTR wszProfile, INT_PTR ptrNativeAssemblyBinder); }; #endif // __MULTICORE_JIT_H__ diff --git a/src/coreclr/vm/multicorejitimpl.h b/src/coreclr/vm/multicorejitimpl.h index d970f887006a64..8e94fc91ac3641 100644 --- a/src/coreclr/vm/multicorejitimpl.h +++ b/src/coreclr/vm/multicorejitimpl.h @@ -266,7 +266,7 @@ class MulticoreJitProfilePlayer friend class MulticoreJitRecorder; private: - AssemblyBinder * m_pBinderContext; + AssemblyBinder * m_pBinder; LONG m_nMySession; unsigned m_nStartTime; BYTE * m_pFileBuffer; @@ -310,7 +310,7 @@ friend class MulticoreJitRecorder; public: - MulticoreJitProfilePlayer(AssemblyBinder * pBinderContext, LONG nSession); + MulticoreJitProfilePlayer(AssemblyBinder * pBinder, LONG nSession); ~MulticoreJitProfilePlayer(); @@ -605,7 +605,7 @@ class MulticoreJitRecorder { private: AppDomain * m_pDomain; // AutoStartProfile could be called from SystemDomain - AssemblyBinder * m_pBinderContext; + AssemblyBinder * m_pBinder; SString m_fullFileName; MulticoreJitPlayerStat & m_stats; @@ -646,34 +646,32 @@ class MulticoreJitRecorder public: - MulticoreJitRecorder(AppDomain * pDomain, AssemblyBinder * pBinderContext, bool fRecorderActive) + MulticoreJitRecorder(AppDomain * pDomain, AssemblyBinder * pBinder, bool fRecorderActive) : m_stats(pDomain->GetMulticoreJitManager().GetStats()) , m_ModuleList(nullptr) , m_JitInfoArray(nullptr) { LIMITED_METHOD_CONTRACT; - m_pDomain = pDomain; - m_pBinderContext = pBinderContext; + m_pDomain = pDomain; + m_pBinder = pBinder; if (fRecorderActive) { - m_ModuleList = new (nothrow) RecorderModuleInfo[MAX_MODULES]; + m_ModuleList = new (nothrow) RecorderModuleInfo[MAX_MODULES]; } - m_ModuleCount = 0; - m_ModuleDepCount = 0; + m_ModuleCount = 0; + m_ModuleDepCount = 0; if (fRecorderActive) { - m_JitInfoArray = new (nothrow) RecorderInfo[MAX_METHODS]; + m_JitInfoArray = new (nothrow) RecorderInfo[MAX_METHODS]; } - m_JitInfoCount = 0; - - m_fFirstMethod = true; - m_fAborted = false; - + m_JitInfoCount = 0; + m_fFirstMethod = true; + m_fAborted = false; m_stats.Clear(); } diff --git a/src/coreclr/vm/multicorejitplayer.cpp b/src/coreclr/vm/multicorejitplayer.cpp index d99f16038bd3a0..d84ed388c9c447 100644 --- a/src/coreclr/vm/multicorejitplayer.cpp +++ b/src/coreclr/vm/multicorejitplayer.cpp @@ -352,12 +352,12 @@ bool ModuleRecord::MatchWithModule(ModuleVersion & modVersion, bool & gotVersion } -MulticoreJitProfilePlayer::MulticoreJitProfilePlayer(AssemblyBinder * pBinderContext, LONG nSession) +MulticoreJitProfilePlayer::MulticoreJitProfilePlayer(AssemblyBinder * pBinder, LONG nSession) : m_stats(::GetAppDomain()->GetMulticoreJitManager().GetStats()), m_appdomainSession(::GetAppDomain()->GetMulticoreJitManager().GetProfileSession()) { LIMITED_METHOD_CONTRACT; - m_pBinderContext = pBinderContext; + m_pBinder = pBinder; m_nMySession = nSession; m_moduleCount = 0; m_headerModuleCount = 0; @@ -830,9 +830,9 @@ DomainAssembly * MulticoreJitProfilePlayer::LoadAssembly(SString & assemblyName) } // Set the binding context to the assembly load context. - if (m_pBinderContext != NULL) + if (m_pBinder != NULL) { - spec.SetBindingContext(m_pBinderContext); + spec.SetBinder(m_pBinder); } // Bind and load the assembly. diff --git a/src/coreclr/vm/nativeimage.cpp b/src/coreclr/vm/nativeimage.cpp index 8338dbc60960b4..13a39a2d4666e4 100644 --- a/src/coreclr/vm/nativeimage.cpp +++ b/src/coreclr/vm/nativeimage.cpp @@ -43,7 +43,7 @@ NativeImageIndexTraits::count_t NativeImageIndexTraits::Hash(LPCUTF8 a) return SString(SString::Utf8Literal, a).HashCaseInsensitive(); } -NativeImage::NativeImage(AssemblyLoadContext *pAssemblyLoadContext, PEImageLayout *pImageLayout, LPCUTF8 imageFileName) +NativeImage::NativeImage(AssemblyBinder *pAssemblyBinder, PEImageLayout *pImageLayout, LPCUTF8 imageFileName) : m_eagerFixupsLock(CrstNativeImageEagerFixups) { CONTRACTL @@ -55,7 +55,7 @@ NativeImage::NativeImage(AssemblyLoadContext *pAssemblyLoadContext, PEImageLayou } CONTRACTL_END; - m_pAssemblyLoadContext = pAssemblyLoadContext; + m_pAssemblyBinder = pAssemblyBinder; m_pImageLayout = pImageLayout; m_fileName = imageFileName; m_eagerFixupsHaveRun = false; @@ -113,7 +113,7 @@ NativeImage::~NativeImage() NativeImage *NativeImage::Open( Module *componentModule, LPCUTF8 nativeImageFileName, - AssemblyLoadContext *pAssemblyLoadContext, + AssemblyBinder *pAssemblyBinder, LoaderAllocator *pLoaderAllocator, /* out */ bool *isNewNativeImage) { @@ -123,7 +123,7 @@ NativeImage *NativeImage::Open( if (pExistingImage != nullptr) { *isNewNativeImage = false; - return pExistingImage->GetAssemblyLoadContext() == pAssemblyLoadContext ? pExistingImage : nullptr; + return pExistingImage->GetAssemblyBinder() == pAssemblyBinder ? pExistingImage : nullptr; } SString path = componentModule->GetPath(); @@ -221,7 +221,7 @@ NativeImage *NativeImage::Open( { COMPlusThrowHR(COR_E_BADIMAGEFORMAT); } - NewHolder image = new NativeImage(pAssemblyLoadContext, peLoadedImage.Extract(), nativeImageFileName); + NewHolder image = new NativeImage(pAssemblyBinder, peLoadedImage.Extract(), nativeImageFileName); AllocMemTracker amTracker; image->Initialize(pHeader, pLoaderAllocator, &amTracker); pExistingImage = AppDomain::GetCurrentDomain()->SetNativeImage(nativeImageFileName, image); @@ -234,7 +234,7 @@ NativeImage *NativeImage::Open( } // Return pre-existing image if it was loaded into the same ALC, null otherwise *isNewNativeImage = false; - return (pExistingImage->GetAssemblyLoadContext() == pAssemblyLoadContext ? pExistingImage : nullptr); + return (pExistingImage->GetAssemblyBinder() == pAssemblyBinder ? pExistingImage : nullptr); } #endif diff --git a/src/coreclr/vm/nativeimage.h b/src/coreclr/vm/nativeimage.h index 447e600297ae3e..bf3f7b6272edfa 100644 --- a/src/coreclr/vm/nativeimage.h +++ b/src/coreclr/vm/nativeimage.h @@ -56,7 +56,6 @@ class NativeImageIndexTraits : public NoRemoveSHashTraits& e) { return e.Key() == nullptr; } }; -class AssemblyLoadContext; class ReadyToRunInfo; class PEFile; class PEImage; @@ -77,7 +76,7 @@ class NativeImage // Points to the OwnerCompositeExecutable section content within the component MSIL module LPCUTF8 m_fileName; - AssemblyLoadContext *m_pAssemblyLoadContext; + AssemblyBinder *m_pAssemblyBinder; ReadyToRunInfo *m_pReadyToRunInfo; IMDInternalImport *m_pManifestMetadata; PEImageLayout *m_pImageLayout; @@ -93,7 +92,7 @@ class NativeImage bool m_eagerFixupsHaveRun; private: - NativeImage(AssemblyLoadContext *pAssemblyLoadContext, PEImageLayout *peImageLayout, LPCUTF8 imageFileName); + NativeImage(AssemblyBinder *pAssemblyBinder, PEImageLayout *peImageLayout, LPCUTF8 imageFileName); protected: void Initialize(READYTORUN_HEADER *header, LoaderAllocator *loaderAllocator, AllocMemTracker *pamTracker); @@ -104,7 +103,7 @@ class NativeImage static NativeImage *Open( Module *componentModule, LPCUTF8 nativeImageFileName, - AssemblyLoadContext *pAssemblyLoadContext, + AssemblyBinder *pAssemblyBinder, LoaderAllocator *pLoaderAllocator, /* out */ bool *isNewNativeImage); @@ -118,7 +117,7 @@ class NativeImage IMDInternalImport *GetManifestMetadata() const { return m_pManifestMetadata; } uint32_t GetManifestAssemblyCount() const { return m_manifestAssemblyCount; } PTR_Assembly *GetManifestMetadataAssemblyRefMap() { return m_pNativeMetadataAssemblyRefMap; } - AssemblyLoadContext *GetAssemblyLoadContext() const { return m_pAssemblyLoadContext; } + AssemblyBinder *GetAssemblyBinder() const { return m_pAssemblyBinder; } Assembly *LoadManifestAssembly(uint32_t rowid, DomainAssembly *pParentAssembly); diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index b7fc2dace34ebf..721fc89e8d37ab 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -318,24 +318,21 @@ namespace #endif // !TARGET_UNIX NATIVE_LIBRARY_HANDLE hmod = NULL; - AppDomain* pDomain = GetAppDomain(); - DefaultAssemblyBinder *pTPABinder = pDomain->GetTPABinderContext(); - PEFile *pManifestFile = pAssembly->GetManifestFile(); - PTR_AssemblyBinder pBindingContext = pManifestFile->GetBindingContext(); + PTR_AssemblyBinder pBinder = pManifestFile->GetBinder(); //Step 0: Check if the assembly was bound using TPA. // The Binding Context can be null or an overridden TPA context - if (pBindingContext == NULL) + if (pBinder == NULL) { // If we do not have any binder associated, then return to the default resolution mechanism. return NULL; } - AssemblyBinder *pCurrentBinder = pBindingContext; + AssemblyBinder *pCurrentBinder = pBinder; - // For assemblies bound via TPA binder, we should use the standard mechanism to make the pinvoke call. - if (pCurrentBinder == pTPABinder) + // For assemblies bound via default binder, we should use the standard mechanism to make the pinvoke call. + if (pCurrentBinder->IsDefault()) { return NULL; } @@ -352,7 +349,7 @@ namespace GCPROTECT_BEGIN(pUnmanagedDllName); // Get the pointer to the managed assembly load context - INT_PTR ptrManagedAssemblyLoadContext = ((CustomAssemblyBinder *)pCurrentBinder)->GetManagedAssemblyLoadContext(); + INT_PTR ptrManagedAssemblyLoadContext = pCurrentBinder->GetManagedAssemblyLoadContext(); // Prepare to invoke System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll method. PREPARE_NONVIRTUAL_CALLSITE(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUNMANAGEDDLL); @@ -373,14 +370,14 @@ namespace { STANDARD_VM_CONTRACT; - PTR_AssemblyBinder pBindingContext = pAssembly->GetManifestFile()->GetBindingContext(); - if (pBindingContext == NULL) + PTR_AssemblyBinder pBinder = pAssembly->GetManifestFile()->GetBinder(); + if (pBinder == NULL) { // GetBindingContext() returns NULL for System.Private.CoreLib return NULL; } - return ((AssemblyLoadContext*)pBindingContext)->GetManagedAssemblyLoadContext(); + return pBinder->GetManagedAssemblyLoadContext(); } NATIVE_LIBRARY_HANDLE LoadNativeLibraryViaAssemblyLoadContextEvent(Assembly * pAssembly, PCWSTR wszLibName) diff --git a/src/coreclr/vm/object.h b/src/coreclr/vm/object.h index 398b4f49030a2e..a47adb8c7985c8 100644 --- a/src/coreclr/vm/object.h +++ b/src/coreclr/vm/object.h @@ -1509,7 +1509,7 @@ class AssemblyLoadContextBaseObject : public Object ~AssemblyLoadContextBaseObject() { LIMITED_METHOD_CONTRACT; } public: - INT_PTR GetNativeAssemblyLoadContext() { LIMITED_METHOD_CONTRACT; return _nativeAssemblyLoadContext; } + INT_PTR GetNativeAssemblyBinder() { LIMITED_METHOD_CONTRACT; return _nativeAssemblyLoadContext; } }; #if defined(TARGET_X86) && !defined(TARGET_UNIX) #include "poppack.h" diff --git a/src/coreclr/vm/pefile.cpp b/src/coreclr/vm/pefile.cpp index 020d91d0e14e03..1934f58809114d 100644 --- a/src/coreclr/vm/pefile.cpp +++ b/src/coreclr/vm/pefile.cpp @@ -47,9 +47,9 @@ PEFile::PEFile(PEImage *identity) : m_pMetadataLock(::new SimpleRWLock(PREEMPTIVE, LOCK_TYPE_DEFAULT)), m_refCount(1), m_flags(0), - m_pAssemblyLoadContext(nullptr), + m_pAssemblyBinder(nullptr), m_pHostAssembly(nullptr), - m_pFallbackLoadContextBinder(nullptr) + m_pFallbackBinder(nullptr) { CONTRACTL { @@ -347,10 +347,10 @@ 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()) { - AssemblyBinder* fileBinderId = pFile->GetHostAssembly()->GetBinder(); - AssemblyBinder* thisBinderId = this->GetHostAssembly()->GetBinder(); + AssemblyBinder* fileBinder = pFile->GetHostAssembly()->GetBinder(); + AssemblyBinder* thisBinder = this->GetHostAssembly()->GetBinder(); - if (fileBinderId != thisBinderId || fileBinderId == NULL) + if (fileBinder != thisBinder || fileBinder == NULL) return FALSE; } @@ -973,7 +973,7 @@ void PEAssembly::Attach() #ifndef DACCESS_COMPILE PEAssembly::PEAssembly( - CoreBindResult* pBindResultInfo, + BINDER_SPACE::Assembly* pBindResultInfo, IMetaDataEmit* pEmit, PEFile *creator, BOOL system, @@ -1038,7 +1038,8 @@ PEAssembly::PEAssembly( { // Cannot have both pHostAssembly and a coreclr based bind _ASSERTE(pHostAssembly == nullptr); - pBindResultInfo->GetBindAssembly(&m_pHostAssembly); + pBindResultInfo = clr::SafeAddRef(pBindResultInfo); + m_pHostAssembly = pBindResultInfo; } #if _DEBUG @@ -1124,18 +1125,13 @@ PEAssembly *PEAssembly::DoOpenSystem() CONTRACT_END; ETWOnStartup (FusionBinding_V1, FusionBindingEnd_V1); - CoreBindResult bindResult; ReleaseHolder pPrivAsm; IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::BindToSystem(&pPrivAsm)); - if(pPrivAsm != NULL) - { - bindResult.Init(pPrivAsm); - } - RETURN new PEAssembly(&bindResult, NULL, NULL, TRUE); + RETURN new PEAssembly(pPrivAsm, NULL, NULL, TRUE); } -PEAssembly* PEAssembly::Open(CoreBindResult* pBindResult, +PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBindResult, BOOL isSystem) { @@ -1385,10 +1381,10 @@ void PEFile::EnsureImageOpened() void PEFile::SetupAssemblyLoadContext() { - PTR_AssemblyBinder pBindingContext = GetBindingContext(); + PTR_AssemblyBinder pBinder = GetBinder(); - m_pAssemblyLoadContext = (pBindingContext != NULL) ? - (AssemblyLoadContext*)pBindingContext : + m_pAssemblyBinder = (pBinder != NULL) ? + pBinder : AppDomain::GetCurrentDomain()->CreateBinderContext(); } @@ -1491,11 +1487,11 @@ TADDR PEFile::GetMDInternalRWAddress() #endif // Returns the AssemblyBinder* instance associated with the PEFile -PTR_AssemblyBinder PEFile::GetBindingContext() +PTR_AssemblyBinder PEFile::GetBinder() { LIMITED_METHOD_CONTRACT; - PTR_AssemblyBinder pBindingContext = NULL; + PTR_AssemblyBinder pBinder = 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. @@ -1504,7 +1500,7 @@ PTR_AssemblyBinder PEFile::GetBindingContext() BINDER_SPACE::Assembly* pHostAssembly = GetHostAssembly(); if (pHostAssembly) { - pBindingContext = dac_cast(pHostAssembly->GetBinder()); + pBinder = dac_cast(pHostAssembly->GetBinder()); } else { @@ -1513,10 +1509,10 @@ PTR_AssemblyBinder PEFile::GetBindingContext() // binder reference. if (IsDynamic()) { - pBindingContext = GetFallbackLoadContextBinder(); + pBinder = GetFallbackBinder(); } } } - return pBindingContext; + return pBinder; } diff --git a/src/coreclr/vm/pefile.h b/src/coreclr/vm/pefile.h index 0881c7b5d84af1..128dbf0f69c478 100644 --- a/src/coreclr/vm/pefile.h +++ b/src/coreclr/vm/pefile.h @@ -45,7 +45,6 @@ class PEFile; class PEModule; class PEAssembly; class SimpleRWLock; -class AssemblyLoadContext; typedef VPTR(PEModule) PTR_PEModule; typedef VPTR(PEAssembly) PTR_PEAssembly; @@ -409,8 +408,8 @@ class PEFile Volatile m_refCount; int m_flags; - // AssemblyLoadContext that this PEFile is associated with - PTR_AssemblyLoadContext m_pAssemblyLoadContext; + // AssemblyBinder that this PEFile is associated with + PTR_AssemblyBinder m_pAssemblyBinder; public: @@ -469,10 +468,10 @@ class PEFile // An example is Ref-Emitted assemblies. Thus, when such assemblies trigger load of their dependencies, // we need to ensure they are loaded in appropriate load context. // - // To enable this, we maintain a concept of "Fallback LoadContext", which will be set to the Binder of the + // To enable this, we maintain a concept of "FallbackBinder", 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_AssemblyBinder m_pFallbackLoadContextBinder; + PTR_AssemblyBinder m_pFallbackBinder; protected: @@ -490,37 +489,37 @@ class PEFile } // Returns the AssemblyBinder* instance associated with the PEFile - PTR_AssemblyBinder GetBindingContext(); + PTR_AssemblyBinder GetBinder(); #ifndef DACCESS_COMPILE void SetupAssemblyLoadContext(); - void SetFallbackLoadContextBinder(PTR_AssemblyBinder pFallbackLoadContextBinder) + void SetFallbackBinder(PTR_AssemblyBinder pFallbackBinder) { LIMITED_METHOD_CONTRACT; - m_pFallbackLoadContextBinder = pFallbackLoadContextBinder; + m_pFallbackBinder = pFallbackBinder; SetupAssemblyLoadContext(); } #endif //!DACCESS_COMPILE - // Returns AssemblyLoadContext into which the current PEFile was loaded. - PTR_AssemblyLoadContext GetAssemblyLoadContext() + // Returns AssemblyBinder which owns the context into which the current PEFile was loaded. + PTR_AssemblyBinder GetAssemblyBinder() { LIMITED_METHOD_CONTRACT; - _ASSERTE(m_pAssemblyLoadContext != NULL); - return m_pAssemblyLoadContext; + _ASSERTE(m_pAssemblyBinder != NULL); + return m_pAssemblyBinder; } bool HasHostAssembly() { STATIC_CONTRACT_WRAPPER; return GetHostAssembly() != nullptr; } - PTR_AssemblyBinder GetFallbackLoadContextBinder() + PTR_AssemblyBinder GetFallbackBinder() { LIMITED_METHOD_CONTRACT; - return m_pFallbackLoadContextBinder; + return m_pFallbackBinder; } }; // class PEFile @@ -553,7 +552,7 @@ class PEAssembly : public PEFile #endif static PEAssembly *Open( - CoreBindResult* pBindResult, + BINDER_SPACE::Assembly* pBindResult, BOOL isSystem); static PEAssembly *Create( @@ -606,7 +605,7 @@ class PEAssembly : public PEFile #ifndef DACCESS_COMPILE PEAssembly( - CoreBindResult* pBindResultInfo, + BINDER_SPACE::Assembly* pBindResultInfo, IMetaDataEmit *pEmit, PEFile *creator, BOOL system, diff --git a/src/coreclr/vm/readytoruninfo.cpp b/src/coreclr/vm/readytoruninfo.cpp index 1ab19f457514cc..4a6052b1ef1621 100644 --- a/src/coreclr/vm/readytoruninfo.cpp +++ b/src/coreclr/vm/readytoruninfo.cpp @@ -503,8 +503,8 @@ static NativeImage *AcquireCompositeImage(Module * pModule, PEImageLayout * pLay if (ownerCompositeExecutableName != NULL) { - AssemblyLoadContext *loadContext = pModule->GetFile()->GetAssemblyLoadContext(); - return loadContext->LoadNativeImage(pModule, ownerCompositeExecutableName); + AssemblyBinder *binder = pModule->GetFile()->GetAssemblyBinder(); + return binder->LoadNativeImage(pModule, ownerCompositeExecutableName); } return NULL; diff --git a/src/coreclr/vm/runtimehandles.cpp b/src/coreclr/vm/runtimehandles.cpp index 76a0c881821e22..d5f8e36b61637c 100644 --- a/src/coreclr/vm/runtimehandles.cpp +++ b/src/coreclr/vm/runtimehandles.cpp @@ -1411,23 +1411,23 @@ void QCALLTYPE RuntimeTypeHandle::GetTypeByName(LPCWSTR pwzClassName, BOOL bThro COMPlusThrowArgumentNull(W("className"),W("ArgumentNull_String")); { - AssemblyBinder * pPrivHostBinder = NULL; + AssemblyBinder * pBinder = NULL; if (*pAssemblyLoadContext.m_ppObject != NULL) { GCX_COOP(); ASSEMBLYLOADCONTEXTREF * pAssemblyLoadContextRef = reinterpret_cast(pAssemblyLoadContext.m_ppObject); - INT_PTR nativeAssemblyLoadContext = (*pAssemblyLoadContextRef)->GetNativeAssemblyLoadContext(); + INT_PTR nativeAssemblyBinder = (*pAssemblyLoadContextRef)->GetNativeAssemblyBinder(); - pPrivHostBinder = reinterpret_cast(nativeAssemblyLoadContext); + pBinder = reinterpret_cast(nativeAssemblyBinder); } typeHandle = TypeName::GetTypeManaged(pwzClassName, NULL, bThrowOnError, bIgnoreCase, /*bProhibitAsmQualifiedName =*/ FALSE, SystemDomain::GetCallersAssembly(pStackMark), (OBJECTREF*)keepAlive.m_ppObject, - pPrivHostBinder); + pBinder); } if (!typeHandle.IsNull()) diff --git a/src/coreclr/vm/typeparse.cpp b/src/coreclr/vm/typeparse.cpp index 83e44d92180df7..84ce7124c473cb 100644 --- a/src/coreclr/vm/typeparse.cpp +++ b/src/coreclr/vm/typeparse.cpp @@ -900,7 +900,7 @@ TypeHandle TypeName::GetTypeUsingCASearchRules(LPCWSTR szTypeName, Assembly *pRe BOOL bProhibitAsmQualifiedName, Assembly* pRequestingAssembly, OBJECTREF *pKeepAlive, - AssemblyBinder * pPrivHostBinder) + AssemblyBinder * pBinder) { STANDARD_VM_CONTRACT; @@ -943,7 +943,7 @@ TypeHandle TypeName::GetTypeUsingCASearchRules(LPCWSTR szTypeName, Assembly *pRe /*fEnableCASearchRules = */TRUE, bProhibitAsmQualifiedName, pRequestingAssembly, - pPrivHostBinder, + pBinder, pKeepAlive); if (bPeriodPrefix && result.IsNull()) @@ -971,7 +971,7 @@ TypeHandle TypeName::GetTypeUsingCASearchRules(LPCWSTR szTypeName, Assembly *pRe /*fEnableCASearchRules = */TRUE, bProhibitAsmQualifiedName, pRequestingAssembly, - pPrivHostBinder, + pBinder, pKeepAlive); } @@ -1115,7 +1115,7 @@ TypeHandle TypeName::GetTypeFromAsm() BOOL fEnableCASearchRules, BOOL bProhibitAsmQualifiedName, Assembly* pRequestingAssembly, - AssemblyBinder * pPrivHostBinder, + AssemblyBinder * pBinder, OBJECTREF *pKeepAlive) { CONTRACT(TypeHandle) @@ -1156,7 +1156,7 @@ TypeHandle TypeName::GetTypeFromAsm() } DomainAssembly *pDomainAssembly = LoadDomainAssembly(GetAssembly(), pRequestingAssembly, - pPrivHostBinder, + pBinder, bThrowIfNotFound); if (pDomainAssembly) { @@ -1237,7 +1237,7 @@ TypeHandle TypeName::GetTypeFromAsm() TypeHandle thGenericArg = m_genericArguments[i]->GetTypeWorker( bThrowIfNotFound, bIgnoreCase, pAssemblyGetType, fEnableCASearchRules, bProhibitAsmQualifiedName, pRequestingAssembly, - pPrivHostBinder, + pBinder, (pKeepAlive != NULL) ? &gc.keepAlive : NULL /* Only pass a keepalive parameter if we were passed a keepalive parameter */); if (thGenericArg.IsNull()) @@ -1444,7 +1444,7 @@ TypeName::GetTypeHaveAssemblyHelper( DomainAssembly * LoadDomainAssembly( SString * psszAssemblySpec, Assembly * pRequestingAssembly, - AssemblyBinder * pPrivHostBinder, + AssemblyBinder * pBinder, BOOL bThrowIfNotFound) { CONTRACTL @@ -1470,17 +1470,17 @@ DomainAssembly * LoadDomainAssembly( // Have we been passed the reference to the binder against which this load should be triggered? // If so, then use it to set the fallback load context binder. - if (pPrivHostBinder != NULL) + if (pBinder != NULL) { - spec.SetFallbackLoadContextBinderForRequestingAssembly(pPrivHostBinder); - spec.SetPreferFallbackLoadContextBinder(); + spec.SetFallbackBinderForRequestingAssembly(pBinder); + spec.SetPreferFallbackBinder(); } else if (pRequestingAssembly != NULL) { // If the requesting assembly has Fallback LoadContext binder available, // then set it up in the AssemblySpec. PEFile *pRequestingAssemblyManifestFile = pRequestingAssembly->GetManifestFile(); - spec.SetFallbackLoadContextBinderForRequestingAssembly(pRequestingAssemblyManifestFile->GetFallbackLoadContextBinder()); + spec.SetFallbackBinderForRequestingAssembly(pRequestingAssemblyManifestFile->GetFallbackBinder()); } if (bThrowIfNotFound) diff --git a/src/coreclr/vm/typeparse.h b/src/coreclr/vm/typeparse.h index 2239ee5736233a..c7728a8a9cc14f 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, - AssemblyBinder * pPrivHostBinder, + AssemblyBinder * pBinder, BOOL bThrowIfNotFound); class TypeName @@ -328,7 +328,7 @@ class TypeName BOOL bProhibitAssemblyQualifiedName, Assembly* pRequestingAssembly, OBJECTREF *pKeepAlive, - AssemblyBinder * pPrivHostBinder = nullptr); + AssemblyBinder * pBinder = nullptr); public: @@ -391,7 +391,7 @@ class TypeName BOOL bProhibitAssemblyQualifiedName, Assembly* pRequestingAssembly, - AssemblyBinder * pPrivHostBinder, + AssemblyBinder * pBinder, OBJECTREF *pKeepAlive); //---------------------------------------------------------------------------------------------------------------- diff --git a/src/coreclr/vm/typestring.h b/src/coreclr/vm/typestring.h index 1fb5cb30b7a5cc..feddc5893ac0bd 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*, - AssemblyBinder * pPrivHostBinder, + AssemblyBinder * pBinder, OBJECTREF *); HRESULT OpenGenericArguments(); HRESULT CloseGenericArguments();