diff --git a/src/coreclr/binder/assembly.cpp b/src/coreclr/binder/assembly.cpp index f8b693593bea1..d13c20b90ef6d 100644 --- a/src/coreclr/binder/assembly.cpp +++ b/src/coreclr/binder/assembly.cpp @@ -13,44 +13,26 @@ #include "common.h" #include "assembly.hpp" #include "utils.hpp" +#include "assemblybindercommon.hpp" namespace BINDER_SPACE { - namespace - { - BOOL IsPlatformArchitecture(PEKIND kArchitecture) - { - return ((kArchitecture != peMSIL) && (kArchitecture != peNone)); - } - }; - Assembly::Assembly() { m_cRef = 1; m_pPEImage = NULL; m_pAssemblyName = NULL; - m_pMDImport = NULL; - m_dwAssemblyFlags = FLAG_NONE; + m_isInTPA = false; m_pBinder = NULL; } Assembly::~Assembly() { - if (m_pPEImage != NULL) - { - BinderReleasePEImage(m_pPEImage); - m_pPEImage = NULL; - } - + SAFE_RELEASE(m_pPEImage); SAFE_RELEASE(m_pAssemblyName); - SAFE_RELEASE(m_pMDImport); } - HRESULT Assembly::Init(IMDInternalImport *pIMetaDataAssemblyImport, - PEKIND PeKind, - PEImage *pPEImage, - SString &assemblyPath, - BOOL fIsInTPA) + HRESULT Assembly::Init(PEImage *pPEImage, BOOL fIsInTPA) { HRESULT hr = S_OK; @@ -58,79 +40,37 @@ namespace BINDER_SPACE SAFE_NEW(pAssemblyName, AssemblyName); // Get assembly name def from meta data import and store it for later refs access - IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind)); - SetMDImport(pIMetaDataAssemblyImport); - if (!fIsInTPA) - { - GetPath().Set(assemblyPath); - } - - // Safe architecture for validation - PEKIND kAssemblyArchitecture; - kAssemblyArchitecture = pAssemblyName->GetArchitecture(); - SetIsInTPA(fIsInTPA); - SetPEImage(pPEImage); + IF_FAIL_GO(pAssemblyName->Init(pPEImage)); pAssemblyName->SetIsDefinition(TRUE); - // Now take ownership of assembly names - SetAssemblyName(pAssemblyName.Extract(), FALSE /* fAddRef */); - - // Finally validate architecture - if (!IsValidArchitecture(kAssemblyArchitecture)) + // validate architecture + if (!AssemblyBinderCommon::IsValidArchitecture(pAssemblyName->GetArchitecture())) { // Assembly image can't be executed on this platform IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT)); } - Exit: - return hr; - } + m_isInTPA = fIsInTPA; - HRESULT Assembly::GetMVID(GUID *pMVID) - { - // Zero init the GUID incase we fail - ZeroMemory(pMVID, sizeof(GUID)); + pPEImage->AddRef(); + m_pPEImage = pPEImage; - return m_pMDImport->GetScopeProps(NULL, pMVID); - } + // Now take ownership of assembly name + m_pAssemblyName = pAssemblyName.Extract(); - /* static */ - PEKIND Assembly::GetSystemArchitecture() - { -#if defined(TARGET_X86) - return peI386; -#elif defined(TARGET_AMD64) - return peAMD64; -#elif defined(TARGET_ARM) - return peARM; -#elif defined(TARGET_ARM64) - return peARM64; -#else - PORTABILITY_ASSERT("Assembly::GetSystemArchitecture"); -#endif + Exit: + return hr; } - /* static */ - BOOL Assembly::IsValidArchitecture(PEKIND kArchitecture) + PEImage* Assembly::GetPEImage() { - if (!IsPlatformArchitecture(kArchitecture)) - return TRUE; - - return (kArchitecture == GetSystemArchitecture()); + return m_pPEImage; } - // -------------------------------------------------------------------- - // BINDER_SPACE::Assembly methods - // -------------------------------------------------------------------- LPCWSTR Assembly::GetSimpleName() { AssemblyName *pAsmName = GetAssemblyName(); return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName()); } - - AssemblyLoaderAllocator* Assembly::GetLoaderAllocator() - { - return m_pBinder ? m_pBinder->GetLoaderAllocator() : NULL; - } } diff --git a/src/coreclr/binder/assemblybindercommon.cpp b/src/coreclr/binder/assemblybindercommon.cpp index 38ac60fd5e848..830c673ea06a6 100644 --- a/src/coreclr/binder/assemblybindercommon.cpp +++ b/src/coreclr/binder/assemblybindercommon.cpp @@ -38,6 +38,10 @@ extern HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadCon #endif // !defined(DACCESS_COMPILE) +STDAPI BinderAcquirePEImage(LPCTSTR szAssemblyPath, + PEImage** ppPEImage, + BundleFileLocation bundleFileLocation); + namespace BINDER_SPACE { namespace @@ -154,21 +158,14 @@ namespace BINDER_SPACE return hr; } - HRESULT CreateImageAssembly(IMDInternalImport *pIMetaDataAssemblyImport, - PEKIND PeKind, - PEImage *pPEImage, + HRESULT CreateImageAssembly(PEImage *pPEImage, BindResult *pBindResult) { HRESULT hr = S_OK; ReleaseHolder pAssembly; - PathString asesmblyPath; SAFE_NEW(pAssembly, Assembly); - IF_FAIL_GO(pAssembly->Init(pIMetaDataAssemblyImport, - PeKind, - pPEImage, - asesmblyPath, - FALSE /* fIsInTPA */)); + IF_FAIL_GO(pAssembly->Init(pPEImage, /* fIsInTPA */ FALSE )); pBindResult->SetResult(pAssembly); pBindResult->SetIsFirstRequest(TRUE); @@ -246,7 +243,6 @@ namespace BINDER_SPACE HRESULT AssemblyBinderCommon::BindAssembly(/* in */ AssemblyBinder *pBinder, /* in */ AssemblyName *pAssemblyName, /* in */ LPCWSTR szCodeBase, - /* in */ PEAssembly *pParentAssembly, /* in */ bool excludeAppPaths, /* out */ Assembly **ppAssembly) { @@ -320,30 +316,6 @@ namespace BINDER_SPACE return hr; } -#if !defined(DACCESS_COMPILE) - /* static */ - HRESULT AssemblyBinderCommon::BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly) - { - HRESULT hr = S_OK; - _ASSERTE(ppSystemAssembly != NULL); - - EX_TRY - { - ReleaseHolder pAsm; - StackSString systemPath(SystemDomain::System()->SystemDirectory()); - hr = AssemblyBinderCommon::BindToSystem(systemPath, &pAsm); - if (SUCCEEDED(hr)) - { - _ASSERTE(pAsm != NULL); - *ppSystemAssembly = pAsm.Extract(); - } - } - EX_CATCH_HRESULT(hr); - - return hr; - } -#endif // !defined(DACCESS_COMPILE) - /* static */ HRESULT AssemblyBinderCommon::BindToSystem(SString &systemDirectory, Assembly **ppSystemAssembly) @@ -354,7 +326,6 @@ namespace BINDER_SPACE ReleaseHolder pSystemAssembly; - // At run-time, System.Private.CoreLib.dll is expected to be the NI image. // System.Private.CoreLib.dll is expected to be found at one of the following locations: // * Non-single-file app: In systemDirectory, beside coreclr.dll // * Framework-dependent single-file app: In systemDirectory, beside coreclr.dll @@ -378,8 +349,8 @@ namespace BINDER_SPACE hr = AssemblyBinderCommon::GetAssembly(sCoreLib, TRUE /* fIsInTPA */, &pSystemAssembly, - NULL /* szMDAssemblyPath */, bundleFileLocation); + BinderTracing::PathProbed(sCoreLib, pathSource, hr); if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) @@ -418,7 +389,6 @@ namespace BINDER_SPACE hr = AssemblyBinderCommon::GetAssembly(sCoreLib, TRUE /* fIsInTPA */, &pSystemAssembly, - NULL /* szMDAssemblyPath */, bundleFileLocation); BinderTracing::PathProbed(sCoreLib, BinderTracing::PathSource::ApplicationAssemblies, hr); @@ -476,7 +446,6 @@ namespace BINDER_SPACE IF_FAIL_GO(AssemblyBinderCommon::GetAssembly(sCoreLibSatellite, TRUE /* fIsInTPA */, &pSystemAssembly, - NULL /* szMDAssemblyPath */, bundleFileLocation)); BinderTracing::PathProbed(sCoreLibSatellite, pathSource, hr); @@ -519,7 +488,7 @@ namespace BINDER_SPACE hr = S_OK; } - if (!Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture())) + if (!IsValidArchitecture(pAssemblyName->GetArchitecture())) { // Assembly reference contains wrong architecture IF_FAIL_GO(FUSION_E_INVALID_NAME); @@ -585,7 +554,6 @@ namespace BINDER_SPACE IF_FAIL_GO(GetAssembly(assemblyPath, FALSE /* fIsInTPA */, &pAssembly, - NULL /* szMDAssemblyPath */, Bundle::ProbeAppBundle(assemblyPath))); AssemblyName *pAssemblyName; @@ -761,7 +729,6 @@ namespace BINDER_SPACE hr = AssemblyBinderCommon::GetAssembly(relativePath, FALSE /* fIsInTPA */, &pAssembly, - NULL, // szMDAssemblyPath bundleFileLocation); BinderTracing::PathProbed(relativePath, BinderTracing::PathSource::Bundle, hr); @@ -1022,7 +989,6 @@ namespace BINDER_SPACE hr = GetAssembly(assemblyFilePath, TRUE, // fIsInTPA &pTPAAssembly, - NULL, // szMDAssemblyPath bundleFileLocation); BinderTracing::PathProbed(assemblyFilePath, BinderTracing::PathSource::Bundle, hr); @@ -1152,9 +1118,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, BundleFileLocation bundleFileLocation) { HRESULT hr = S_OK; @@ -1162,9 +1125,6 @@ namespace BINDER_SPACE _ASSERTE(ppAssembly != NULL); ReleaseHolder pAssembly; - ReleaseHolder pIMetaDataAssemblyImport; - DWORD dwPAFlags[2]; - PEKIND PeKind = peNone; PEImage *pPEImage = NULL; // Allocate assembly object @@ -1176,26 +1136,17 @@ namespace BINDER_SPACE hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, bundleFileLocation); IF_FAIL_GO(hr); - - hr = BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags); - IF_FAIL_GO(hr); - - IF_FAIL_GO(TranslatePEToArchitectureType(dwPAFlags, &PeKind)); } // Initialize assembly object - IF_FAIL_GO(pAssembly->Init(pIMetaDataAssemblyImport, - PeKind, - pPEImage, - assemblyPath, - fIsInTPA)); + IF_FAIL_GO(pAssembly->Init(pPEImage, fIsInTPA)); // We're done *ppAssembly = pAssembly.Extract(); Exit: - BinderReleasePEImage(pPEImage); + SAFE_RELEASE(pPEImage); // Normalize file not found if ((FAILED(hr)) && IsFileNotFound(hr)) @@ -1349,8 +1300,6 @@ HRESULT AssemblyBinderCommon::BindUsingHostAssemblyResolver(/* in */ INT_PTR pMa HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder, /* in */ BINDER_SPACE::AssemblyName *pAssemblyName, /* in */ PEImage *pPEImage, - /* in */ PEKIND peKind, - /* in */ IMDInternalImport *pIMetaDataAssemblyImport, /* [retval] [out] */ Assembly **ppAssembly) { HRESULT hr = E_FAIL; @@ -1384,10 +1333,7 @@ HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { - IF_FAIL_GO(CreateImageAssembly(pIMetaDataAssemblyImport, - peKind, - pPEImage, - &bindResult)); + IF_FAIL_GO(CreateImageAssembly(pPEImage, &bindResult)); } else if (hr == S_OK) { @@ -1396,20 +1342,23 @@ HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder // Attempt was made to load an assembly that has the same name as a previously loaded one. Since same name // does not imply the same assembly, we will need to check the MVID to confirm it is the same assembly as being // requested. - // - GUID incomingMVID; - ZeroMemory(&incomingMVID, sizeof(GUID)); - - // If we cannot get MVID, then err on side of caution and fail the - // load. - IF_FAIL_GO(pIMetaDataAssemblyImport->GetScopeProps(NULL, &incomingMVID)); + GUID incomingMVID; GUID boundMVID; - ZeroMemory(&boundMVID, sizeof(GUID)); - // If we cannot get MVID, then err on side of caution and fail the - // load. - IF_FAIL_GO(bindResult.GetAssembly()->GetMVID(&boundMVID)); + // GetMVID can throw exception + EX_TRY + { + pPEImage->GetMVID(&incomingMVID); + bindResult.GetAssembly()->GetPEImage()->GetMVID(&boundMVID); + } + EX_CATCH + { + hr = GET_EXCEPTION()->GetHR(); + goto Exit; + } + EX_END_CATCH(SwallowAllExceptions); + mvidMismatch = incomingMVID != boundMVID; if (mvidMismatch) @@ -1459,7 +1408,7 @@ HRESULT AssemblyBinderCommon::BindUsingPEImage(/* in */ AssemblyBinder* pBinder return hr; } -HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** ppDefaultBinder) +HRESULT AssemblyBinderCommon::CreateDefaultBinder(DefaultAssemblyBinder** ppDefaultBinder) { HRESULT hr = S_OK; EX_TRY @@ -1484,45 +1433,25 @@ HRESULT AssemblyBinderCommon::DefaultBinderSetupContext(DefaultAssemblyBinder** return hr; } -HRESULT AssemblyBinderCommon::GetAssemblyIdentity(LPCSTR szTextualIdentity, - BINDER_SPACE::ApplicationContext* pApplicationContext, - NewHolder& assemblyIdentityHolder) +BOOL AssemblyBinderCommon::IsValidArchitecture(PEKIND kArchitecture) { - HRESULT hr = S_OK; - _ASSERTE(szTextualIdentity != NULL); - - EX_TRY - { - AssemblyIdentityUTF8 * pAssemblyIdentity = NULL; - if (pApplicationContext != NULL) - { - // This returns a cached copy owned by application context - hr = pApplicationContext->GetAssemblyIdentity(szTextualIdentity, &pAssemblyIdentity); - if (SUCCEEDED(hr)) - { - assemblyIdentityHolder = pAssemblyIdentity; - assemblyIdentityHolder.SuppressRelease(); - } - } - else - { - SString sTextualIdentity; - - sTextualIdentity.SetUTF8(szTextualIdentity); - - // This is a private copy - pAssemblyIdentity = new AssemblyIdentityUTF8(); - hr = TextualIdentityParser::Parse(sTextualIdentity, pAssemblyIdentity); - if (SUCCEEDED(hr)) - { - pAssemblyIdentity->PopulateUTF8Fields(); - assemblyIdentityHolder = pAssemblyIdentity; - } - } - } - EX_CATCH_HRESULT(hr); + if ((kArchitecture == peMSIL) || (kArchitecture == peNone)) + return TRUE; + + PEKIND processArchitecture = +#if defined(TARGET_X86) + peI386; +#elif defined(TARGET_AMD64) + peAMD64; +#elif defined(TARGET_ARM) + peARM; +#elif defined(TARGET_ARM64) + peARM64; +#else + PORTABILITY_ASSERT("processArchitecture"); +#endif - return hr; + return (kArchitecture == processArchitecture); } #endif // !defined(DACCESS_COMPILE) diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index d7da9c73a7124..9eea2ee8ba736 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -12,6 +12,9 @@ // ============================================================ #include "assemblyname.hpp" +#include "assemblybindercommon.hpp" + +#include "common.h" #include "utils.hpp" #include "textualidentityparser.hpp" @@ -26,21 +29,22 @@ namespace const WCHAR* s_neutralCulture = W("neutral"); } +STDAPI BinderAcquireImport(PEImage* pPEImage, + IMDInternalImport** pIMetaDataAssemblyImport, + DWORD* pdwPAFlags); + namespace BINDER_SPACE { AssemblyName::AssemblyName() { m_cRef = 1; - m_dwNameFlags = NAME_FLAG_NONE; + m_isDefinition = false; // Default values present in every assembly name SetHave(AssemblyIdentity::IDENTITY_FLAG_CULTURE | AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL); } - HRESULT AssemblyName::Init(IMDInternalImport *pIMetaDataAssemblyImport, - PEKIND PeKind, - mdAssemblyRef mdar /* = 0 */, - BOOL fIsDefinition /* = TRUE */) + HRESULT AssemblyName::Init(PEImage* pPEImage) { HRESULT hr = S_OK; mdAssembly mda = 0; @@ -51,38 +55,29 @@ namespace BINDER_SPACE DWORD dwRefOrDefFlags = 0; DWORD dwHashAlgId = 0; - if (fIsDefinition) - { - // Get the assembly token - IF_FAIL_GO(pIMetaDataAssemblyImport->GetAssemblyFromScope(&mda)); - } + ReleaseHolder pIMetaDataAssemblyImport; + + PEKIND PeKind = peNone; + DWORD dwPAFlags[2]; + IF_FAIL_GO(BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags)); + IF_FAIL_GO(AssemblyBinderCommon::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); + SetArchitecture(PeKind); + + _ASSERTE(pIMetaDataAssemblyImport != NULL); + + // Get the assembly token + IF_FAIL_GO(pIMetaDataAssemblyImport->GetAssemblyFromScope(&mda)); // Get name and metadata - if (fIsDefinition) - { - IF_FAIL_GO(pIMetaDataAssemblyImport->GetAssemblyProps( - mda, // [IN] The Assembly for which to get the properties. - &pvPublicKeyToken, // [OUT] Pointer to the PublicKeyToken blob. - &dwPublicKeyToken, // [OUT] Count of bytes in the PublicKeyToken Blob. - &dwHashAlgId, // [OUT] Hash Algorithm. - &pAssemblyName, // [OUT] Name. - &amd, // [OUT] Assembly MetaData. - &dwRefOrDefFlags // [OUT] Flags. - )); - } - else - { - IF_FAIL_GO(pIMetaDataAssemblyImport->GetAssemblyRefProps( - mdar, // [IN] The Assembly for which to get the properties. - &pvPublicKeyToken, // [OUT] Pointer to the PublicKeyToken blob. - &dwPublicKeyToken, // [OUT] Count of bytes in the PublicKeyToken Blob. - &pAssemblyName, // [OUT] Name. - &amd, // [OUT] Assembly MetaData. - NULL, // [OUT] Hash blob. - NULL, // [OUT] Count of bytes in hash blob. - &dwRefOrDefFlags // [OUT] Flags. - )); - } + IF_FAIL_GO(pIMetaDataAssemblyImport->GetAssemblyProps( + mda, // [IN] The Assembly for which to get the properties. + &pvPublicKeyToken, // [OUT] Pointer to the PublicKeyToken blob. + &dwPublicKeyToken, // [OUT] Count of bytes in the PublicKeyToken Blob. + &dwHashAlgId, // [OUT] Hash Algorithm. + &pAssemblyName, // [OUT] Name. + &amd, // [OUT] Assembly MetaData. + &dwRefOrDefFlags // [OUT] Flags. + )); { StackSString culture; @@ -157,8 +152,6 @@ namespace BINDER_SPACE SetHave(AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN); } - SetArchitecture(PeKind); - Exit: return hr; } diff --git a/src/coreclr/binder/bindertracing.cpp b/src/coreclr/binder/bindertracing.cpp index bdef5633367ae..b03eb2f66db5f 100644 --- a/src/coreclr/binder/bindertracing.cpp +++ b/src/coreclr/binder/bindertracing.cpp @@ -152,9 +152,7 @@ namespace peAssembly->GetDisplayName(request.RequestingAssembly); AppDomain *domain = parentAssembly->GetAppDomain(); - AssemblyBinder *binder = peAssembly->GetBinder(); - if (binder == nullptr) - binder = domain->GetDefaultBinder(); // System.Private.CoreLib returns null + AssemblyBinder *binder = peAssembly->GetAssemblyBinder(); GetAssemblyLoadContextNameFromBinder(binder, domain, request.RequestingAssemblyLoadContext); } diff --git a/src/coreclr/binder/customassemblybinder.cpp b/src/coreclr/binder/customassemblybinder.cpp index 5378e710b1b94..13d10d94fbb63 100644 --- a/src/coreclr/binder/customassemblybinder.cpp +++ b/src/coreclr/binder/customassemblybinder.cpp @@ -28,7 +28,6 @@ HRESULT CustomAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam hr = AssemblyBinderCommon::BindAssembly(this, pAssemblyName, NULL, // szCodeBase - NULL, // pParentAssembly false, //excludeAppPaths, ppCoreCLRFoundAssembly); if (!FAILED(hr)) @@ -111,23 +110,13 @@ HRESULT CustomAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage, { ReleaseHolder pCoreCLRFoundAssembly; ReleaseHolder pAssemblyName; - ReleaseHolder pIMetaDataAssemblyImport; - - PEKIND PeKind = peNone; - - // Get the Metadata interface - DWORD dwPAFlags[2]; - IF_FAIL_GO(BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags)); - IF_FAIL_GO(AssemblyBinderCommon::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); - - _ASSERTE(pIMetaDataAssemblyImport != NULL); // Using the information we just got, initialize the assemblyname SAFE_NEW(pAssemblyName, BINDER_SPACE::AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind)); + IF_FAIL_GO(pAssemblyName->Init(pPEImage)); // Validate architecture - if (!BINDER_SPACE::Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture())) + if (!AssemblyBinderCommon::IsValidArchitecture(pAssemblyName->GetArchitecture())) { IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT)); } @@ -139,7 +128,7 @@ HRESULT CustomAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage, IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); } - hr = AssemblyBinderCommon::BindUsingPEImage(this, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); + hr = AssemblyBinderCommon::BindUsingPEImage(this, pAssemblyName, pPEImage, &pCoreCLRFoundAssembly); if (hr == S_OK) { _ASSERTE(pCoreCLRFoundAssembly != NULL); diff --git a/src/coreclr/binder/defaultassemblybinder.cpp b/src/coreclr/binder/defaultassemblybinder.cpp index 9597f8c60f458..33eb404164d51 100644 --- a/src/coreclr/binder/defaultassemblybinder.cpp +++ b/src/coreclr/binder/defaultassemblybinder.cpp @@ -26,7 +26,6 @@ HRESULT DefaultAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNa hr = AssemblyBinderCommon::BindAssembly(this, pAssemblyName, NULL, // szCodeBase - NULL, // pParentAssembly excludeAppPaths, ppCoreCLRFoundAssembly); if (!FAILED(hr)) @@ -121,23 +120,13 @@ HRESULT DefaultAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage, { ReleaseHolder pCoreCLRFoundAssembly; ReleaseHolder pAssemblyName; - ReleaseHolder pIMetaDataAssemblyImport; - - PEKIND PeKind = peNone; - - // Get the Metadata interface - DWORD dwPAFlags[2]; - IF_FAIL_GO(BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags)); - IF_FAIL_GO(AssemblyBinderCommon::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); - - _ASSERTE(pIMetaDataAssemblyImport != NULL); // Using the information we just got, initialize the assemblyname SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind)); + IF_FAIL_GO(pAssemblyName->Init(pPEImage)); // Validate architecture - if (!BINDER_SPACE::Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture())) + if (!AssemblyBinderCommon::IsValidArchitecture(pAssemblyName->GetArchitecture())) { IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT)); } @@ -169,7 +158,7 @@ HRESULT DefaultAssemblyBinder::BindUsingPEImage( /* in */ PEImage *pPEImage, } } - hr = AssemblyBinderCommon::BindUsingPEImage(this, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); + hr = AssemblyBinderCommon::BindUsingPEImage(this, pAssemblyName, pPEImage, &pCoreCLRFoundAssembly); if (hr == S_OK) { _ASSERTE(pCoreCLRFoundAssembly != NULL); @@ -199,7 +188,6 @@ HRESULT DefaultAssemblyBinder::SetupBindingPaths(SString &sTrustedPlatformAssem } HRESULT DefaultAssemblyBinder::Bind(LPCWSTR wszCodeBase, - PEAssembly *pParentAssembly, BINDER_SPACE::Assembly **ppAssembly) { HRESULT hr = S_OK; @@ -211,7 +199,6 @@ HRESULT DefaultAssemblyBinder::Bind(LPCWSTR wszCodeBase, hr = AssemblyBinderCommon::BindAssembly(this, NULL, // pAssemblyName wszCodeBase, - pParentAssembly, false, // excludeAppPaths &pAsm); if(SUCCEEDED(hr)) @@ -225,3 +212,27 @@ HRESULT DefaultAssemblyBinder::Bind(LPCWSTR wszCodeBase, return hr; } + +HRESULT DefaultAssemblyBinder::BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly) +{ + HRESULT hr = S_OK; + _ASSERTE(ppSystemAssembly != NULL); + + EX_TRY + { + ReleaseHolder pAsm; + StackSString systemPath(SystemDomain::System()->SystemDirectory()); + hr = AssemblyBinderCommon::BindToSystem(systemPath, &pAsm); + if (SUCCEEDED(hr)) + { + _ASSERTE(pAsm != NULL); + *ppSystemAssembly = pAsm.Extract(); + } + + (*ppSystemAssembly)->SetBinder(this); + } + EX_CATCH_HRESULT(hr); + + return hr; +} + diff --git a/src/coreclr/binder/inc/assembly.hpp b/src/coreclr/binder/inc/assembly.hpp index 2f2fa5ae58b62..19cf15ed402d2 100644 --- a/src/coreclr/binder/inc/assembly.hpp +++ b/src/coreclr/binder/inc/assembly.hpp @@ -27,58 +27,26 @@ #include "bundle.h" -STDAPI BinderAcquirePEImage(LPCTSTR szAssemblyPath, - PEImage **ppPEImage, - BundleFileLocation bundleFileLocation); - -STDAPI BinderAcquireImport(PEImage *pPEImage, - IMDInternalImport **pIMetaDataAssemblyImport, - DWORD *pdwPAFlags); - -STDAPI BinderReleasePEImage(PEImage *pPEImage); - -STDAPI BinderAddRefPEImage(PEImage *pPEImage); - namespace BINDER_SPACE { - - // An assembly represents a particular set of bits. However we extend this to - // also include whether those bits have precompiled information (NGEN). Thus - // and assembly knows whether it has an NGEN image or not. - // - // This allows us to preferentially use the NGEN image if it is available. + // BINDER_SPACE::Assembly represents a result of binding to an actual assembly (PEImage) + // It is basically a tuple of 1) physical assembly and 2) binder which created/owns this binding + // We also store whether it was bound using TPA list class Assembly { public: ULONG AddRef(); ULONG Release(); - LPCWSTR GetSimpleName(); - AssemblyLoaderAllocator* GetLoaderAllocator(); - - // -------------------------------------------------------------------- - // Assembly methods - // -------------------------------------------------------------------- Assembly(); virtual ~Assembly(); - HRESULT Init(/* in */ IMDInternalImport *pIMetaDataAssemblyImport, - /* in */ PEKIND PeKind, - /* in */ PEImage *pPEImage, - /* in */ SString &assemblyPath, - /* in */ BOOL fIsInTPA); - - inline AssemblyName *GetAssemblyName(BOOL fAddRef = FALSE); - inline BOOL GetIsInTPA(); - - inline SString &GetPath(); + HRESULT Init(PEImage *pPEImage, BOOL fIsInTPA); - inline PEImage *GetPEImage(BOOL fAddRef = FALSE); - - HRESULT GetMVID(GUID *pMVID); - - static PEKIND GetSystemArchitecture(); - static BOOL IsValidArchitecture(PEKIND kArchitecture); + LPCWSTR GetSimpleName(); + AssemblyName *GetAssemblyName(BOOL fAddRef = FALSE); + PEImage* GetPEImage(); + BOOL GetIsInTPA(); inline AssemblyBinder* GetBinder() { @@ -86,31 +54,11 @@ namespace BINDER_SPACE } private: - // Assembly Flags - enum - { - FLAG_NONE = 0x00, - FLAG_IS_IN_TPA = 0x02, - //FLAG_IS_DYNAMIC_BIND = 0x04, - FLAG_IS_BYTE_ARRAY = 0x08, - }; - - inline void SetPEImage(PEImage *pPEImage); - - inline void SetAssemblyName(AssemblyName *pAssemblyName, - BOOL fAddRef = TRUE); - inline void SetIsInTPA(BOOL fIsInTPA); - - inline IMDInternalImport *GetMDImport(); - inline void SetMDImport(IMDInternalImport *pMDImport); - LONG m_cRef; PEImage *m_pPEImage; - IMDInternalImport *m_pMDImport; AssemblyName *m_pAssemblyName; - SString m_assemblyPath; - DWORD m_dwAssemblyFlags; AssemblyBinder *m_pBinder; + bool m_isInTPA; inline void SetBinder(AssemblyBinder *pBinder) { diff --git a/src/coreclr/binder/inc/assembly.inl b/src/coreclr/binder/inc/assembly.inl index dfc38bcdf44d4..a256be8ff5196 100644 --- a/src/coreclr/binder/inc/assembly.inl +++ b/src/coreclr/binder/inc/assembly.inl @@ -31,25 +31,7 @@ inline ULONG Assembly::Release() return ulRef; } -PEImage *Assembly::GetPEImage(BOOL fAddRef /* = FALSE */) -{ - PEImage *pPEImage = m_pPEImage; - - if (fAddRef) - { - BinderAddRefPEImage(pPEImage); - } - - return pPEImage; -} - -void Assembly::SetPEImage(PEImage *pPEImage) -{ - BinderAddRefPEImage(pPEImage); - m_pPEImage = pPEImage; -} - -AssemblyName *Assembly::GetAssemblyName(BOOL fAddRef /* = FALSE */) +inline AssemblyName *Assembly::GetAssemblyName(BOOL fAddRef /* = FALSE */) { AssemblyName *pAssemblyName = m_pAssemblyName; @@ -60,52 +42,9 @@ AssemblyName *Assembly::GetAssemblyName(BOOL fAddRef /* = FALSE */) return pAssemblyName; } -void Assembly::SetAssemblyName(AssemblyName *pAssemblyName, - BOOL fAddRef /* = TRUE */) -{ - SAFE_RELEASE(m_pAssemblyName); - - m_pAssemblyName = pAssemblyName; - - if (fAddRef && (pAssemblyName != NULL)) - { - pAssemblyName->AddRef(); - } -} - -BOOL Assembly::GetIsInTPA() -{ - return ((m_dwAssemblyFlags & FLAG_IS_IN_TPA) != 0); -} - -void Assembly::SetIsInTPA(BOOL fIsInTPA) -{ - if (fIsInTPA) - { - m_dwAssemblyFlags |= FLAG_IS_IN_TPA; - } - else - { - m_dwAssemblyFlags &= ~FLAG_IS_IN_TPA; - } -} - -SString &Assembly::GetPath() -{ - return m_assemblyPath; -} - -IMDInternalImport *Assembly::GetMDImport() +inline BOOL Assembly::GetIsInTPA() { - return m_pMDImport; -} - -void Assembly::SetMDImport(IMDInternalImport *pMDImport) -{ - SAFE_RELEASE(m_pMDImport); - - m_pMDImport = pMDImport; - m_pMDImport->AddRef(); + return m_isInTPA; } #endif diff --git a/src/coreclr/binder/inc/assemblybindercommon.hpp b/src/coreclr/binder/inc/assemblybindercommon.hpp index 8febd3a1e7a59..b708d6d204e57 100644 --- a/src/coreclr/binder/inc/assemblybindercommon.hpp +++ b/src/coreclr/binder/inc/assemblybindercommon.hpp @@ -33,12 +33,9 @@ namespace BINDER_SPACE static HRESULT BindAssembly(/* in */ AssemblyBinder *pBinder, /* in */ AssemblyName *pAssemblyName, /* in */ LPCWSTR szCodeBase, - /* in */ PEAssembly *pParentAssembly, /* in */ bool excludeAppPaths, /* out */ Assembly **ppAssembly); - static HRESULT BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly); - static HRESULT BindToSystem(/* in */ SString &systemDirectory, /* out */ Assembly **ppSystemAssembly); @@ -50,7 +47,6 @@ namespace BINDER_SPACE static HRESULT GetAssembly(/* in */ SString &assemblyPath, /* in */ BOOL fIsInTPA, /* out */ Assembly **ppAssembly, - /* in */ LPCTSTR szMDAssemblyPath = NULL, /* in */ BundleFileLocation bundleFileLocation = BundleFileLocation::Invalid()); #if !defined(DACCESS_COMPILE) @@ -62,21 +58,14 @@ namespace BINDER_SPACE static HRESULT BindUsingPEImage(/* in */ AssemblyBinder *pBinder, /* in */ BINDER_SPACE::AssemblyName *pAssemblyName, /* in */ PEImage *pPEImage, - /* in */ PEKIND peKind, - /* in */ IMDInternalImport *pIMetaDataAssemblyImport, /* [retval] [out] */ Assembly **ppAssembly); #endif // !defined(DACCESS_COMPILE) static HRESULT TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind); - static HRESULT DefaultBinderSetupContext(DefaultAssemblyBinder** ppDefaultBinder); + static HRESULT CreateDefaultBinder(DefaultAssemblyBinder** ppDefaultBinder); - // TODO: The call indicates that this can come from a case where - // pDomain->GetFusionContext() is null, hence this is static function - // which handles a null binder. See if this actually happens - static HRESULT GetAssemblyIdentity(LPCSTR szTextualIdentity, - BINDER_SPACE::ApplicationContext* pApplicationContext, - NewHolder& assemblyIdentityHolder); + static BOOL IsValidArchitecture(PEKIND kArchitecture); private: static HRESULT BindByName(/* in */ ApplicationContext *pApplicationContext, diff --git a/src/coreclr/binder/inc/assemblyname.hpp b/src/coreclr/binder/inc/assemblyname.hpp index 6bec598a1646d..0b878102e9740 100644 --- a/src/coreclr/binder/inc/assemblyname.hpp +++ b/src/coreclr/binder/inc/assemblyname.hpp @@ -17,6 +17,8 @@ #include "bindertypes.hpp" #include "assemblyidentity.hpp" +class PEImage; + namespace BINDER_SPACE { class AssemblyName final : public AssemblyIdentity @@ -40,11 +42,8 @@ namespace BINDER_SPACE AssemblyName(); - HRESULT Init(/* in */ IMDInternalImport *pIMetaDataAssemblyImport, - /* in */ PEKIND PeKind, - /* in */ mdAssemblyRef mda = 0, - /* in */ BOOL fIsDefinition = TRUE); - HRESULT Init(/* in */ const AssemblyNameData &data); + HRESULT Init(PEImage* pPEImage); + HRESULT Init(const AssemblyNameData &data); ULONG AddRef(); ULONG Release(); @@ -76,18 +75,11 @@ namespace BINDER_SPACE void GetDisplayName(/* out */ PathString &displayName, /* in */ DWORD dwIncludeFlags); - protected: - enum - { - NAME_FLAG_NONE = 0x00, - NAME_FLAG_RETARGETABLE = 0x01, - NAME_FLAG_DEFINITION = 0x02, - }; - + private: SString &GetNormalizedCulture(); LONG m_cRef; - DWORD m_dwNameFlags; + bool m_isDefinition; }; #include "assemblyname.inl" diff --git a/src/coreclr/binder/inc/assemblyname.inl b/src/coreclr/binder/inc/assemblyname.inl index 201136f19768e..5946a7e3ed77c 100644 --- a/src/coreclr/binder/inc/assemblyname.inl +++ b/src/coreclr/binder/inc/assemblyname.inl @@ -98,31 +98,21 @@ void AssemblyName::SetIsRetargetable(BOOL fIsRetargetable) { if (fIsRetargetable) { - m_dwNameFlags |= NAME_FLAG_RETARGETABLE; SetHave(AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE); } else { - m_dwNameFlags &= ~NAME_FLAG_RETARGETABLE; SetClear(AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE); } } BOOL AssemblyName::GetIsDefinition() { - return ((m_dwNameFlags & NAME_FLAG_DEFINITION) != 0); + return m_isDefinition; } void AssemblyName::SetIsDefinition(BOOL fIsDefinition) { - if (fIsDefinition) - { - m_dwNameFlags |= NAME_FLAG_DEFINITION; - } - else - { - m_dwNameFlags &= ~NAME_FLAG_DEFINITION; - } + m_isDefinition = fIsDefinition; } - #endif diff --git a/src/coreclr/binder/inc/defaultassemblybinder.h b/src/coreclr/binder/inc/defaultassemblybinder.h index a1f72d6eb3655..9394fd9b7f8b5 100644 --- a/src/coreclr/binder/inc/defaultassemblybinder.h +++ b/src/coreclr/binder/inc/defaultassemblybinder.h @@ -38,9 +38,9 @@ class DefaultAssemblyBinder final : public AssemblyBinder SString &sPlatformResourceRoots, SString &sAppPaths); - HRESULT Bind(LPCWSTR wszCodeBase, - PEAssembly *pParentAssembly, - BINDER_SPACE::Assembly **ppAssembly); + HRESULT Bind(LPCWSTR wszCodeBase, BINDER_SPACE::Assembly **ppAssembly); + + HRESULT BindToSystem(BINDER_SPACE::Assembly **ppSystemAssembly); private: diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index f902f3e0d6a6d..d76db29301529 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -1041,6 +1041,7 @@ void SystemDomain::Attach() // Create the one and only app domain AppDomain::Create(); + AppDomain::GetCurrentDomain()->CreateBinderContext(); // Each domain gets its own ReJitManager, and ReJitManager has its own static // initialization to run @@ -2774,7 +2775,7 @@ DomainAssembly* AppDomain::LoadDomainAssembly(AssemblySpec* pSpec, { // Setup the binder reference in AssemblySpec from the PEAssembly if one is not already set. AssemblyBinder* pCurrentBinder = pSpec->GetBinder(); - AssemblyBinder* pBinderFromPEAssembly = pFile->GetBinder(); + AssemblyBinder* pBinderFromPEAssembly = pFile->GetAssemblyBinder(); if (pCurrentBinder == NULL) { @@ -2841,14 +2842,10 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, { LoaderAllocator *pLoaderAllocator = NULL; - AssemblyBinder *pFileBinder = pFile->GetBinder(); - if (pFileBinder != NULL) - { - // Assemblies loaded with CustomAssemblyBinder need to use a different LoaderAllocator if - // marked as collectible - pLoaderAllocator = pFileBinder->GetLoaderAllocator(); - } - + AssemblyBinder *pFileBinder = pFile->GetAssemblyBinder(); + // Assemblies loaded with CustomAssemblyBinder need to use a different LoaderAllocator if + // marked as collectible + pLoaderAllocator = pFileBinder->GetLoaderAllocator(); if (pLoaderAllocator == NULL) { pLoaderAllocator = this->GetLoaderAllocator(); @@ -3713,7 +3710,7 @@ PEAssembly * AppDomain::BindAssemblySpec( } // Setup the reference to the binder, which performed the bind, into the AssemblySpec - AssemblyBinder* pBinder = result->GetBinder(); + AssemblyBinder* pBinder = result->GetAssemblyBinder(); _ASSERTE(pBinder != NULL); pSpec->SetBinder(pBinder); @@ -4062,7 +4059,7 @@ DefaultAssemblyBinder *AppDomain::CreateBinderContext() GCX_PREEMP(); // Initialize the assembly binder for the default context loads for CoreCLR. - IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::DefaultBinderSetupContext(&m_pDefaultBinder)); + IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::CreateDefaultBinder(&m_pDefaultBinder)); } RETURN m_pDefaultBinder; diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 712852e9ab5de..c0fe297fc1ecc 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -485,19 +485,11 @@ Assembly *Assembly::CreateDynamic(AppDomain *pDomain, AssemblyBinder* pBinder, C // Static assemblies with do not have fallback load context _ASSERTE(pCallerAssemblyManifestFile->GetFallbackBinder() == nullptr); - if (pCallerAssemblyManifestFile->IsSystem()) - { - // CoreLibrary is always bound with default binder - pFallbackBinder = pDomain->GetDefaultBinder(); - } - else - { - // Fetch the binder from the host assembly - PTR_BINDER_SPACE_Assembly pCallerAssemblyHostAssembly = pCallerAssemblyManifestFile->GetHostAssembly(); - _ASSERTE(pCallerAssemblyHostAssembly != nullptr); + // Fetch the binder from the host assembly + PTR_BINDER_SPACE_Assembly pCallerAssemblyHostAssembly = pCallerAssemblyManifestFile->GetHostAssembly(); + _ASSERTE(pCallerAssemblyHostAssembly != nullptr); - pFallbackBinder = pCallerAssemblyHostAssembly->GetBinder(); - } + pFallbackBinder = pCallerAssemblyHostAssembly->GetBinder(); } else { diff --git a/src/coreclr/vm/assembly.hpp b/src/coreclr/vm/assembly.hpp index f1f98984bd053..db972f0ccf149 100644 --- a/src/coreclr/vm/assembly.hpp +++ b/src/coreclr/vm/assembly.hpp @@ -227,8 +227,6 @@ class Assembly PTR_BaseDomain GetDomain(); PTR_LoaderAllocator GetLoaderAllocator() { LIMITED_METHOD_DAC_CONTRACT; return m_pLoaderAllocator; } - BOOL GetModuleZapFile(LPCWSTR name, SString &path); - #ifdef LOGGING LPCWSTR GetDebugName() { diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 989c834563f4f..af5862a9ac5ff 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -239,14 +239,11 @@ void AssemblySpec::InitializeSpec(PEAssembly * pFile) // Set the binding context for the AssemblySpec AssemblyBinder* pCurrentBinder = GetBinder(); - AssemblyBinder* pExpectedBinder = pFile->GetBinder(); if (pCurrentBinder == NULL) { - // 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()); + AssemblyBinder* pExpectedBinder = pFile->GetAssemblyBinder(); + // We should aways have the binding context in the PEAssembly. + _ASSERTE(pExpectedBinder != NULL); SetBinder(pExpectedBinder); } } @@ -694,7 +691,7 @@ AssemblyBinder* AssemblySpec::GetBinderFromParentAssembly(AppDomain *pDomain) { // Get the PEAssembly associated with the parent's domain assembly PEAssembly *pParentPEAssembly = pParentDomainAssembly->GetFile(); - pParentAssemblyBinder = pParentPEAssembly->GetBinder(); + pParentAssemblyBinder = pParentPEAssembly->GetAssemblyBinder(); } if (GetPreferFallbackBinder()) @@ -996,13 +993,7 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter // 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()) - pBinderForLookup = pSpec->GetBinder(); - else - { - // For System.Private.Corelib Binding context is either not set or if set then it should be TPA - _ASSERTE(pSpec->GetBinder() == NULL || pSpec->GetBinder()->IsDefault()); - } + pBinderForLookup = pSpec->GetBinder(); if (pBinderForLookup != NULL) { @@ -1013,13 +1004,8 @@ AssemblySpecBindingCache::AssemblyBinding* AssemblySpecBindingCache::LookupInter if (fGetBindingContextFromParent) { - // CoreLib does not have a binding context associated with it and its lookup will only be done - // using its AssemblySpec hash. - if (!pSpec->IsAssemblySpecForCoreLib()) - { - pBinderForLookup = pSpec->GetBinderFromParentAssembly(pSpec->GetAppDomain()); - pSpec->SetBinder(pBinderForLookup); - } + pBinderForLookup = pSpec->GetBinderFromParentAssembly(pSpec->GetAppDomain()); + pSpec->SetBinder(pBinderForLookup); } if (pBinderForLookup) @@ -1233,17 +1219,12 @@ BOOL AssemblySpecBindingCache::StoreAssembly(AssemblySpec *pSpec, DomainAssembly UPTR key = (UPTR)pSpec->Hash(); - AssemblyBinder* pBinderContextForLookup = pAssembly->GetFile()->GetBinder(); + AssemblyBinder* pBinderContextForLookup = pAssembly->GetFile()->GetAssemblyBinder(); + key = key ^ (UPTR)pBinderContextForLookup; - _ASSERTE(pBinderContextForLookup || pAssembly->GetFile()->IsSystem()); - if (pBinderContextForLookup) + if (!pSpec->GetBinder()) { - key = key ^ (UPTR)pBinderContextForLookup; - - if (!pSpec->GetBinder()) - { - pSpec->SetBinder(pBinderContextForLookup); - } + pSpec->SetBinder(pBinderContextForLookup); } AssemblyBinding *entry = (AssemblyBinding *) m_map.LookupValue(key, pSpec); @@ -1314,17 +1295,12 @@ BOOL AssemblySpecBindingCache::StoreFile(AssemblySpec *pSpec, PEAssembly *pFile) UPTR key = (UPTR)pSpec->Hash(); - AssemblyBinder* pBinderContextForLookup = pFile->GetBinder(); + AssemblyBinder* pBinderContextForLookup = pFile->GetAssemblyBinder(); + key = key ^ (UPTR)pBinderContextForLookup; - _ASSERTE(pBinderContextForLookup || pFile->IsSystem()); - if (pBinderContextForLookup) + if (!pSpec->GetBinder()) { - key = key ^ (UPTR)pBinderContextForLookup; - - if (!pSpec->GetBinder()) - { - pSpec->SetBinder(pBinderContextForLookup); - } + pSpec->SetBinder(pBinderContextForLookup); } AssemblyBinding *entry = (AssemblyBinding *) m_map.LookupValue(key, pSpec); @@ -1406,11 +1382,8 @@ BOOL AssemblySpecBindingCache::StoreException(AssemblySpec *pSpec, Exception* pE pBinderToSaveException = pSpec->GetBinder(); if (pBinderToSaveException == NULL) { - if (!pSpec->IsAssemblySpecForCoreLib()) - { - pBinderToSaveException = pSpec->GetBinderFromParentAssembly(pSpec->GetAppDomain()); - key = key ^ (UPTR)pBinderToSaveException; - } + pBinderToSaveException = pSpec->GetBinderFromParentAssembly(pSpec->GetAppDomain()); + key = key ^ (UPTR)pBinderToSaveException; } } diff --git a/src/coreclr/vm/baseassemblyspec.cpp b/src/coreclr/vm/baseassemblyspec.cpp index 49e5418a2f54a..10951a8b082f5 100644 --- a/src/coreclr/vm/baseassemblyspec.cpp +++ b/src/coreclr/vm/baseassemblyspec.cpp @@ -103,32 +103,6 @@ BOOL BaseAssemblySpec::IsCoreLib() ( (iNameLen == CoreLibNameLen) || (m_pAssemblyName[CoreLibNameLen] == ',') ) ) ) ); } -BOOL BaseAssemblySpec::IsAssemblySpecForCoreLib() -{ - CONTRACTL - { - NOTHROW; - INSTANCE_CHECK; - GC_NOTRIGGER; - MODE_ANY; - PRECONDITION(strlen(g_psBaseLibraryName) == CoreLibNameLen); - } - CONTRACTL_END; - - BOOL fIsAssemblySpecForCoreLib = FALSE; - - if (m_pAssemblyName) - { - size_t iNameLen = strlen(m_pAssemblyName); - fIsAssemblySpecForCoreLib = ( (iNameLen >= CoreLibNameLen) && - ( (!_stricmp(m_pAssemblyName, g_psBaseLibrary)) || - ( (!_strnicmp(m_pAssemblyName, g_psBaseLibraryName, CoreLibNameLen)) && - ( (iNameLen == CoreLibNameLen) || (m_pAssemblyName[CoreLibNameLen] == ',') ) ) ) ); - } - - return fIsAssemblySpecForCoreLib; -} - #define CORELIB_PUBLICKEY g_rbTheSilverlightPlatformKey diff --git a/src/coreclr/vm/baseassemblyspec.h b/src/coreclr/vm/baseassemblyspec.h index 644a3c4a825f5..871bb47b1e95d 100644 --- a/src/coreclr/vm/baseassemblyspec.h +++ b/src/coreclr/vm/baseassemblyspec.h @@ -77,8 +77,6 @@ class BaseAssemblySpec return m_pBinder; } - BOOL IsAssemblySpecForCoreLib(); - HRESULT ParseName(); DWORD Hash(); diff --git a/src/coreclr/vm/baseassemblyspec.inl b/src/coreclr/vm/baseassemblyspec.inl index d642c01b4973b..0fc2274acb19c 100644 --- a/src/coreclr/vm/baseassemblyspec.inl +++ b/src/coreclr/vm/baseassemblyspec.inl @@ -318,15 +318,11 @@ 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_pBinder != m_pBinder) { - if (pSpec->m_pBinder != m_pBinder) - { - return FALSE; - } + return FALSE; } - return TRUE; } diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 0fcca71b95d1a..3ffb9a83b1511 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -3421,7 +3421,7 @@ DomainAssembly * Module::LoadAssembly(mdAssemblyRef kAssemblyRef) // Set the binding context in the AssemblySpec if one is available. This can happen if the LoadAssembly ended up // invoking the custom AssemblyLoadContext implementation that returned a reference to an assembly bound to a different // AssemblyLoadContext implementation. - AssemblyBinder *pBinder = pFile->GetBinder(); + AssemblyBinder *pBinder = pFile->GetAssemblyBinder(); if (pBinder != NULL) { spec.SetBinder(pBinder); diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 59eb9d30fae76..9d1547cda8edd 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -29,30 +29,6 @@ #include "../binder/inc/assemblybindercommon.hpp" #include "../binder/inc/applicationcontext.hpp" -STDAPI BinderAddRefPEImage(PEImage *pPEImage) -{ - HRESULT hr = S_OK; - - if (pPEImage != NULL) - { - pPEImage->AddRef(); - } - - return hr; -} - -STDAPI BinderReleasePEImage(PEImage *pPEImage) -{ - HRESULT hr = S_OK; - - if (pPEImage != NULL) - { - pPEImage->Release(); - } - - return hr; -} - static VOID ThrowLoadError(AssemblySpec * pSpec, HRESULT hr) { CONTRACTL @@ -115,9 +91,7 @@ HRESULT AssemblySpec::Bind(AppDomain *pAppDomain, BINDER_SPACE::Assembly** ppAs } else { - hr = pAppDomain->GetDefaultBinder()->Bind(m_wszCodeBase, - GetParentAssembly() ? GetParentAssembly()->GetFile() : NULL, - &pPrivAsm); + hr = pAppDomain->GetDefaultBinder()->Bind(m_wszCodeBase, &pPrivAsm); } if (SUCCEEDED(hr)) @@ -212,18 +186,14 @@ HRESULT BaseAssemblySpec::ParseName() EX_TRY { - NewHolder pAssemblyIdentity; + BINDER_SPACE::AssemblyIdentityUTF8* pAssemblyIdentity; AppDomain *pDomain = ::GetAppDomain(); _ASSERTE(pDomain); BINDER_SPACE::ApplicationContext *pAppContext = NULL; DefaultAssemblyBinder *pBinder = pDomain->GetDefaultBinder(); - if (pBinder != NULL) - { - pAppContext = pBinder->GetAppContext(); - } - hr = BINDER_SPACE::AssemblyBinderCommon::GetAssemblyIdentity(m_pAssemblyName, pAppContext, pAssemblyIdentity); + hr = pBinder->GetAppContext()->GetAssemblyIdentity(m_pAssemblyName, &pAssemblyIdentity); if (FAILED(hr)) { diff --git a/src/coreclr/vm/nativelibrary.cpp b/src/coreclr/vm/nativelibrary.cpp index 721fc89e8d37a..43fa330c08f76 100644 --- a/src/coreclr/vm/nativelibrary.cpp +++ b/src/coreclr/vm/nativelibrary.cpp @@ -319,16 +319,9 @@ namespace NATIVE_LIBRARY_HANDLE hmod = NULL; PEFile *pManifestFile = pAssembly->GetManifestFile(); - PTR_AssemblyBinder pBinder = pManifestFile->GetBinder(); + PTR_AssemblyBinder pBinder = pManifestFile->GetAssemblyBinder(); //Step 0: Check if the assembly was bound using TPA. - // The Binding Context can be null or an overridden TPA context - if (pBinder == NULL) - { - // If we do not have any binder associated, then return to the default resolution mechanism. - return NULL; - } - AssemblyBinder *pCurrentBinder = pBinder; // For assemblies bound via default binder, we should use the standard mechanism to make the pinvoke call. @@ -370,13 +363,7 @@ namespace { STANDARD_VM_CONTRACT; - PTR_AssemblyBinder pBinder = pAssembly->GetManifestFile()->GetBinder(); - if (pBinder == NULL) - { - // GetBindingContext() returns NULL for System.Private.CoreLib - return NULL; - } - + PTR_AssemblyBinder pBinder = pAssembly->GetManifestFile()->GetAssemblyBinder(); return pBinder->GetManagedAssemblyLoadContext(); } diff --git a/src/coreclr/vm/pefile.cpp b/src/coreclr/vm/pefile.cpp index 1934f58809114..8e7d70732a27f 100644 --- a/src/coreclr/vm/pefile.cpp +++ b/src/coreclr/vm/pefile.cpp @@ -29,8 +29,7 @@ #ifndef DACCESS_COMPILE // ================================================================================ -// PEFile class - this is an abstract base class for PEModule and PEAssembly -// @todo: rename TargetFile +// PEFile class - this is an abstract base class for PEAssembly // ================================================================================ PEFile::PEFile(PEImage *identity) : @@ -47,7 +46,6 @@ PEFile::PEFile(PEImage *identity) : m_pMetadataLock(::new SimpleRWLock(PREEMPTIVE, LOCK_TYPE_DEFAULT)), m_refCount(1), m_flags(0), - m_pAssemblyBinder(nullptr), m_pHostAssembly(nullptr), m_pFallbackBinder(nullptr) { @@ -113,7 +111,6 @@ PEFile *PEFile::Open(PEImage *image) PRECONDITION(image != NULL); PRECONDITION(image->CheckFormat()); POSTCONDITION(RETVAL != NULL); - POSTCONDITION(!RETVAL->IsModule()); POSTCONDITION(!RETVAL->IsAssembly()); THROWS; GC_TRIGGERS; @@ -1047,8 +1044,6 @@ PEAssembly::PEAssembly( m_debugName.Normalize(); m_pDebugName = m_debugName; #endif - - SetupAssemblyLoadContext(); } #endif // !DACCESS_COMPILE @@ -1125,10 +1120,10 @@ PEAssembly *PEAssembly::DoOpenSystem() CONTRACT_END; ETWOnStartup (FusionBinding_V1, FusionBindingEnd_V1); - ReleaseHolder pPrivAsm; - IfFailThrow(BINDER_SPACE::AssemblyBinderCommon::BindToSystem(&pPrivAsm)); + ReleaseHolder pBoundAssembly; + IfFailThrow(GetAppDomain()->GetDefaultBinder()->BindToSystem(&pBoundAssembly)); - RETURN new PEAssembly(pPrivAsm, NULL, NULL, TRUE); + RETURN new PEAssembly(pBoundAssembly, NULL, NULL, TRUE); } PEAssembly* PEAssembly::Open(BINDER_SPACE::Assembly* pBindResult, @@ -1379,15 +1374,6 @@ void PEFile::EnsureImageOpened() GetILimage()->GetLayout(PEImageLayout::LAYOUT_ANY,PEImage::LAYOUT_CREATEIFNEEDED)->Release(); } -void PEFile::SetupAssemblyLoadContext() -{ - PTR_AssemblyBinder pBinder = GetBinder(); - - m_pAssemblyBinder = (pBinder != NULL) ? - pBinder : - AppDomain::GetCurrentDomain()->CreateBinderContext(); -} - #endif // #ifndef DACCESS_COMPILE #ifdef DACCESS_COMPILE @@ -1487,30 +1473,25 @@ TADDR PEFile::GetMDInternalRWAddress() #endif // Returns the AssemblyBinder* instance associated with the PEFile -PTR_AssemblyBinder PEFile::GetBinder() +PTR_AssemblyBinder PEFile::GetAssemblyBinder() { LIMITED_METHOD_CONTRACT; 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. - if (!IsSystem()) + BINDER_SPACE::Assembly* pHostAssembly = GetHostAssembly(); + if (pHostAssembly) { - BINDER_SPACE::Assembly* pHostAssembly = GetHostAssembly(); - if (pHostAssembly) - { - pBinder = dac_cast(pHostAssembly->GetBinder()); - } - else + pBinder = dac_cast(pHostAssembly->GetBinder()); + } + else + { + // If we do not have a host assembly, check if we are dealing with + // a dynamically emitted assembly and if so, use its fallback load context + // binder reference. + if (IsDynamic()) { - // If we do not have a host assembly, check if we are dealing with - // a dynamically emitted assembly and if so, use its fallback load context - // binder reference. - if (IsDynamic()) - { - pBinder = GetFallbackBinder(); - } + pBinder = GetFallbackBinder(); } } diff --git a/src/coreclr/vm/pefile.h b/src/coreclr/vm/pefile.h index b32bece42e258..317c9c544228f 100644 --- a/src/coreclr/vm/pefile.h +++ b/src/coreclr/vm/pefile.h @@ -42,11 +42,9 @@ class Module; class EditAndContinueModule; class PEFile; -class PEModule; class PEAssembly; class SimpleRWLock; -typedef VPTR(PEModule) PTR_PEModule; typedef VPTR(PEAssembly) PTR_PEAssembly; // -------------------------------------------------------------------------------- @@ -79,9 +77,6 @@ typedef VPTR(PEAssembly) PTR_PEAssembly; // 4. Dynamic - these are not actual PE images at all, but are placeholders // for reflection-based modules. // -// PEFiles are segmented into two subtypes: PEAssembly and PEModule. The formere -// is a file to be loaded as an assembly, and the latter is to be loaded as a module. -// // See also file:..\inc\corhdr.h#ManagedHeader for more on the format of managed images. // See code:Module for more on modules // -------------------------------------------------------------------------------- @@ -120,7 +115,6 @@ class PEFile // ------------------------------------------------------------ friend class DomainFile; - friend class PEModule; public: void LoadLibrary(BOOL allowNativeSkip = TRUE); @@ -199,8 +193,6 @@ class PEFile BOOL IsAssembly() const; PTR_PEAssembly AsAssembly(); - BOOL IsModule() const; - PTR_PEModule AsModule(); BOOL IsSystem() const; BOOL IsDynamic() const; BOOL IsResource() const; @@ -346,7 +338,6 @@ class PEFile { PEFILE_SYSTEM = 0x01, PEFILE_ASSEMBLY = 0x02, - PEFILE_MODULE = 0x04, }; // ------------------------------------------------------------ @@ -406,9 +397,6 @@ class PEFile Volatile m_refCount; int m_flags; - // AssemblyBinder that this PEFile is associated with - PTR_AssemblyBinder m_pAssemblyBinder; - public: PTR_PEImage GetILimage() @@ -480,29 +468,18 @@ class PEFile } // Returns the AssemblyBinder* instance associated with the PEFile - PTR_AssemblyBinder GetBinder(); + // which owns the context into which the current PEFile was loaded. + PTR_AssemblyBinder GetAssemblyBinder(); #ifndef DACCESS_COMPILE - void SetupAssemblyLoadContext(); - void SetFallbackBinder(PTR_AssemblyBinder pFallbackBinder) { LIMITED_METHOD_CONTRACT; m_pFallbackBinder = pFallbackBinder; - SetupAssemblyLoadContext(); } #endif //!DACCESS_COMPILE - // Returns AssemblyBinder which owns the context into which the current PEFile was loaded. - PTR_AssemblyBinder GetAssemblyBinder() - { - LIMITED_METHOD_CONTRACT; - - _ASSERTE(m_pAssemblyBinder != NULL); - return m_pAssemblyBinder; - } - bool HasHostAssembly() { STATIC_CONTRACT_WRAPPER; return GetHostAssembly() != nullptr; } diff --git a/src/coreclr/vm/pefile.inl b/src/coreclr/vm/pefile.inl index 3b8289f80d06a..e00136064bc1e 100644 --- a/src/coreclr/vm/pefile.inl +++ b/src/coreclr/vm/pefile.inl @@ -262,24 +262,6 @@ inline PTR_PEAssembly PEFile::AsAssembly() return dac_cast(nullptr); } -inline BOOL PEFile::IsModule() const -{ - LIMITED_METHOD_CONTRACT; - SUPPORTS_DAC; - - return (m_flags & PEFILE_MODULE) != 0; -} - -inline PTR_PEModule PEFile::AsModule() -{ - LIMITED_METHOD_DAC_CONTRACT; - - if (IsModule()) - return dac_cast(this); - else - return dac_cast(nullptr); -} - inline BOOL PEFile::IsSystem() const { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/peimage.cpp b/src/coreclr/vm/peimage.cpp index 0deaeec230b72..412d67c938f5e 100644 --- a/src/coreclr/vm/peimage.cpp +++ b/src/coreclr/vm/peimage.cpp @@ -50,8 +50,6 @@ void PEImage::Startup() s_ijwFixupDataHash = ::new PtrHashMap; s_ijwFixupDataHash->Init(CompareIJWDataBase, FALSE, &ijwLock); - PEImageLayout::Startup(); - RETURN; } diff --git a/src/coreclr/vm/peimage.h b/src/coreclr/vm/peimage.h index acd5b4e6abab6..af86e35ccaec4 100644 --- a/src/coreclr/vm/peimage.h +++ b/src/coreclr/vm/peimage.h @@ -58,7 +58,6 @@ typedef DPTR(class PEImage) PTR_PEImage; class PEImage { - friend class PEModule; public: // ------------------------------------------------------------ // Public constants diff --git a/src/coreclr/vm/peimagelayout.h b/src/coreclr/vm/peimagelayout.h index 4050c0bf948c6..69e46160466af 100644 --- a/src/coreclr/vm/peimagelayout.h +++ b/src/coreclr/vm/peimagelayout.h @@ -31,7 +31,6 @@ typedef VPTR(class PEImageLayout) PTR_PEImageLayout; class PEImageLayout : public PEDecoder { VPTR_BASE_CONCRETE_VTABLE_CLASS(PEImageLayout) - friend class PEModule; public: // ------------------------------------------------------------ // Public constants @@ -59,8 +58,6 @@ class PEImageLayout : public PEDecoder #endif PEImageLayout(); virtual ~PEImageLayout(); - static void Startup(); - static CHECK CheckStartup(); static BOOL CompareBase(UPTR path, UPTR mapping); // Refcount above images. diff --git a/src/coreclr/vm/peimagelayout.inl b/src/coreclr/vm/peimagelayout.inl index 5b5cc7ba2b65f..17cebf77398d7 100644 --- a/src/coreclr/vm/peimagelayout.inl +++ b/src/coreclr/vm/peimagelayout.inl @@ -75,30 +75,6 @@ inline PEImageLayout::PEImageLayout() LIMITED_METHOD_CONTRACT; } -inline void PEImageLayout::Startup() -{ - CONTRACT_VOID - { - THROWS; - GC_NOTRIGGER; - MODE_ANY; - POSTCONDITION(CheckStartup()); - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACT_END; - - if (CheckStartup()) - RETURN; - - RETURN; -} - -inline CHECK PEImageLayout::CheckStartup() -{ - WRAPPER_NO_CONTRACT; - CHECK_OK; -} - inline BOOL PEImageLayout::CompareBase(UPTR base, UPTR mapping) { CONTRACTL