From 5520a3aaac8040220c69ee54d1b5c8e453220390 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Fri, 2 Apr 2021 23:33:20 -0700 Subject: [PATCH 1/8] Stop using IAssemblyName in ICLRPrivBinder --- src/coreclr/binder/assembly.cpp | 4 +- src/coreclr/binder/assemblybinder.cpp | 10 +- src/coreclr/binder/assemblyname.cpp | 5 + .../clrprivbinderassemblyloadcontext.cpp | 8 +- src/coreclr/binder/clrprivbindercoreclr.cpp | 29 +- src/coreclr/binder/inc/assembly.hpp | 6 +- src/coreclr/binder/inc/assemblybinder.hpp | 1 - src/coreclr/binder/inc/assemblyidentity.hpp | 2 +- src/coreclr/binder/inc/assemblyname.hpp | 22 +- .../inc/clrprivbinderassemblyloadcontext.h | 4 +- src/coreclr/binder/inc/clrprivbindercoreclr.h | 5 +- src/coreclr/inc/clrprivbinding.idl | 7 +- src/coreclr/inc/readme.md | 9 +- src/coreclr/pal/prebuilt/inc/clrprivbinding.h | 17 +- src/coreclr/vm/appdomain.cpp | 278 +++++++++--------- src/coreclr/vm/assemblyspec.cpp | 34 ++- src/coreclr/vm/assemblyspec.hpp | 7 +- src/coreclr/vm/baseassemblyspec.cpp | 177 ----------- src/coreclr/vm/baseassemblyspec.h | 7 +- src/coreclr/vm/coreassemblyspec.cpp | 165 ++++++----- 20 files changed, 336 insertions(+), 461 deletions(-) diff --git a/src/coreclr/binder/assembly.cpp b/src/coreclr/binder/assembly.cpp index d4948c4d1ae8b..75ca4b2c265df 100644 --- a/src/coreclr/binder/assembly.cpp +++ b/src/coreclr/binder/assembly.cpp @@ -182,9 +182,9 @@ namespace BINDER_SPACE return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName()); } - HRESULT Assembly::BindAssemblyByName(IAssemblyName * pIAssemblyName, ICLRPrivAssembly ** ppAssembly) + HRESULT Assembly::BindAssemblyByName(const WCHAR *pAssemblyFullName, ICLRPrivAssembly ** ppAssembly) { - return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pIAssemblyName, ppAssembly); + return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pAssemblyFullName, ppAssembly); } HRESULT Assembly::GetBinderID(UINT_PTR *pBinderId) diff --git a/src/coreclr/binder/assemblybinder.cpp b/src/coreclr/binder/assemblybinder.cpp index aa29465af824e..75e91471fe626 100644 --- a/src/coreclr/binder/assemblybinder.cpp +++ b/src/coreclr/binder/assemblybinder.cpp @@ -38,8 +38,9 @@ BOOL IsCompilationProcess(); #include "clrprivbinderassemblyloadcontext.h" // Helper function in the VM, invoked by the Binder, to invoke the host assembly resolver extern HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, - IAssemblyName *pIAssemblyName, CLRPrivBinderCoreCLR *pTPABinder, - BINDER_SPACE::AssemblyName *pAssemblyName, ICLRPrivAssembly **ppLoadedAssembly); + BINDER_SPACE::AssemblyName *pAssemblyName, + CLRPrivBinderCoreCLR *pTPABinder, + ICLRPrivAssembly **ppLoadedAssembly); #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) @@ -1436,7 +1437,6 @@ namespace BINDER_SPACE #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) HRESULT AssemblyBinder::BindUsingHostAssemblyResolver(/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, /* in */ AssemblyName *pAssemblyName, - /* in */ IAssemblyName *pIAssemblyName, /* in */ CLRPrivBinderCoreCLR *pTPABinder, /* out */ Assembly **ppAssembly) { @@ -1446,8 +1446,8 @@ HRESULT AssemblyBinder::BindUsingHostAssemblyResolver(/* in */ INT_PTR pManagedA // RuntimeInvokeHostAssemblyResolver will perform steps 2-4 of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName. ICLRPrivAssembly *pLoadedAssembly = NULL; - hr = RuntimeInvokeHostAssemblyResolver(pManagedAssemblyLoadContextToBindWithin, pIAssemblyName, - pTPABinder, pAssemblyName, &pLoadedAssembly); + hr = RuntimeInvokeHostAssemblyResolver(pManagedAssemblyLoadContextToBindWithin, + pAssemblyName, pTPABinder, &pLoadedAssembly); if (SUCCEEDED(hr)) { _ASSERTE(pLoadedAssembly != NULL); diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 571898d75f0d0..82c08c505d763 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -321,6 +321,11 @@ namespace BINDER_SPACE return EqualsCaseInsensitive(GetSimpleName(), g_BinderVariables->corelib); } + bool AssemblyName::IsNeutralCulture() + { + return m_cultureOrLanguage.IsEmpty() || m_cultureOrLanguage.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral); + } + ULONG AssemblyName::Hash(DWORD dwIncludeFlags) { DWORD dwHash = 0; diff --git a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp b/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp index 69d8d83372893..39ef98d76248d 100644 --- a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp +++ b/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp @@ -42,11 +42,11 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE: return hr; } -HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(IAssemblyName *pIAssemblyName, +HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(const WCHAR *pAssemblyFullName, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; - VALIDATE_ARG_RET(pIAssemblyName != nullptr && ppAssembly != nullptr); + VALIDATE_ARG_RET(pAssemblyFullName != nullptr && ppAssembly != nullptr); _ASSERTE(m_pTPABinder != NULL); @@ -54,7 +54,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(IAssemblyName * ReleaseHolder pAssemblyName; SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(pIAssemblyName)); + IF_FAIL_GO(pAssemblyName->Init(SString(pAssemblyFullName))); // When LoadContext needs to resolve an assembly reference, it will go through the following lookup order: // @@ -84,7 +84,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(IAssemblyName * // of what to do next. The host-overridden binder can either fail the bind or return reference to an existing assembly // that has been loaded. // - hr = AssemblyBinder::BindUsingHostAssemblyResolver(GetManagedAssemblyLoadContext(), pAssemblyName, pIAssemblyName, m_pTPABinder, &pCoreCLRFoundAssembly); + hr = AssemblyBinder::BindUsingHostAssemblyResolver(GetManagedAssemblyLoadContext(), pAssemblyName, m_pTPABinder, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { // We maybe returned an assembly that was bound to a different AssemblyLoadContext instance. diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/clrprivbindercoreclr.cpp index 571e127d7dab2..4b4ae7140ce69 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/clrprivbindercoreclr.cpp @@ -43,19 +43,33 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam // ============================================================================ // CLRPrivBinderCoreCLR implementation // ============================================================================ -HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(IAssemblyName *pIAssemblyName, +HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(const WCHAR *pAssemblyFullName, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; - VALIDATE_ARG_RET(pIAssemblyName != nullptr && ppAssembly != nullptr); + VALIDATE_ARG_RET(pAssemblyFullName != nullptr && ppAssembly != nullptr); *ppAssembly = nullptr; - ReleaseHolder pCoreCLRFoundAssembly; ReleaseHolder pAssemblyName; - SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(pIAssemblyName)); + IF_FAIL_GO(pAssemblyName->Init(SString(pAssemblyFullName))); + + hr = BindUsingAssemblyName(pAssemblyName, ppAssembly); + +Exit: + return hr; +} + +HRESULT CLRPrivBinderCoreCLR::BindUsingAssemblyName(BINDER_SPACE::AssemblyName *pAssemblyName, + ICLRPrivAssembly **ppAssembly) +{ + HRESULT hr = S_OK; + VALIDATE_ARG_RET(pAssemblyName != nullptr && ppAssembly != nullptr); + + *ppAssembly = nullptr; + + ReleaseHolder pCoreCLRFoundAssembly; hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, false /* excludeAppPaths */); @@ -78,8 +92,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(IAssemblyName *pIAssemblyNa // should be run even if the managed default ALC has not yet been used. (For non-satellite assemblies, any // additional logic comes through a user-defined event handler which would have initialized the managed ALC, // so if the managed ALC is not set yet, there is no additional logic to run) - SString &culture = pAssemblyName->GetCulture(); - if (!culture.IsEmpty() && !culture.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral)) + if (!pAssemblyName->IsNeutralCulture()) { // Make sure the managed default ALC is initialized. GCX_COOP(); @@ -94,7 +107,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(IAssemblyName *pIAssemblyNa if (pManagedAssemblyLoadContext != NULL) { - hr = AssemblyBinder::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, pIAssemblyName, + hr = AssemblyBinder::BindUsingHostAssemblyResolver(pManagedAssemblyLoadContext, pAssemblyName, NULL, &pCoreCLRFoundAssembly); if (SUCCEEDED(hr)) { diff --git a/src/coreclr/binder/inc/assembly.hpp b/src/coreclr/binder/inc/assembly.hpp index 3f5fb87594e22..0f017a781cac0 100644 --- a/src/coreclr/binder/inc/assembly.hpp +++ b/src/coreclr/binder/inc/assembly.hpp @@ -71,9 +71,9 @@ namespace BINDER_SPACE // -------------------------------------------------------------------- LPCWSTR GetSimpleName(); - STDMETHOD(BindAssemblyByName)( - IAssemblyName * pIAssemblyName, - ICLRPrivAssembly ** ppAssembly); + STDMETHOD(BindAssemblyByName)( + /* [string][in] */ const WCHAR *pAssemblyFullName, + /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetAvailableImageTypes)(PDWORD pdwImageTypes); diff --git a/src/coreclr/binder/inc/assemblybinder.hpp b/src/coreclr/binder/inc/assemblybinder.hpp index 6fc2f2dc4574c..5dbb8ffa45f5e 100644 --- a/src/coreclr/binder/inc/assemblybinder.hpp +++ b/src/coreclr/binder/inc/assemblybinder.hpp @@ -60,7 +60,6 @@ namespace BINDER_SPACE #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, /* in */ AssemblyName *pAssemblyName, - /* in */ IAssemblyName *pIAssemblyName, /* in */ CLRPrivBinderCoreCLR *pTPABinder, /* out */ Assembly **ppAssembly); diff --git a/src/coreclr/binder/inc/assemblyidentity.hpp b/src/coreclr/binder/inc/assemblyidentity.hpp index e1fdec87b2617..cc0916c8780af 100644 --- a/src/coreclr/binder/inc/assemblyidentity.hpp +++ b/src/coreclr/binder/inc/assemblyidentity.hpp @@ -87,7 +87,7 @@ namespace BINDER_SPACE DWORD m_dwIdentityFlags; }; - class AssemblyIdentityUTF8 : public AssemblyIdentity + class AssemblyIdentityUTF8 final : public AssemblyIdentity { public: AssemblyIdentityUTF8() diff --git a/src/coreclr/binder/inc/assemblyname.hpp b/src/coreclr/binder/inc/assemblyname.hpp index fb66d9830e0a3..1e19a30a8e5ba 100644 --- a/src/coreclr/binder/inc/assemblyname.hpp +++ b/src/coreclr/binder/inc/assemblyname.hpp @@ -19,18 +19,23 @@ namespace BINDER_SPACE { - class AssemblyName : protected AssemblyIdentity + class AssemblyName final : public AssemblyIdentity { public: typedef enum { - INCLUDE_DEFAULT = 0x00, - INCLUDE_VERSION = 0x01, - INCLUDE_ARCHITECTURE = 0x02, - INCLUDE_RETARGETABLE = 0x04, - INCLUDE_CONTENT_TYPE = 0x08, - INCLUDE_PUBLIC_KEY_TOKEN = 0x10, - EXCLUDE_CULTURE = 0x20 + INCLUDE_DEFAULT = 0x00, + INCLUDE_VERSION = 0x01, + INCLUDE_ARCHITECTURE = 0x02, + INCLUDE_RETARGETABLE = 0x04, + INCLUDE_CONTENT_TYPE = 0x08, + INCLUDE_PUBLIC_KEY_TOKEN = 0x10, + EXCLUDE_CULTURE = 0x20, + INCLUDE_ALL = INCLUDE_VERSION + | INCLUDE_ARCHITECTURE + | INCLUDE_RETARGETABLE + | INCLUDE_CONTENT_TYPE + | INCLUDE_PUBLIC_KEY_TOKEN, } INCLUDE_FLAGS; AssemblyName(); @@ -66,6 +71,7 @@ namespace BINDER_SPACE inline void SetHave(DWORD dwIdentityFlags); BOOL IsCoreLib(); + bool IsNeutralCulture(); ULONG Hash(/* in */ DWORD dwIncludeFlags); BOOL Equals(/* in */ AssemblyName *pAssemblyName, diff --git a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h index 3c1c406230209..bfa1594194fc3 100644 --- a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h +++ b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h @@ -29,8 +29,8 @@ class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext //========================================================================= // ICLRPrivBinder functions //------------------------------------------------------------------------- - STDMETHOD(BindAssemblyByName)( - /* [in] */ IAssemblyName *pIAssemblyName, + STDMETHOD(BindAssemblyByName)( + /* [string][in] */ const WCHAR *pAssemblyFullName, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetLoaderAllocator)( diff --git a/src/coreclr/binder/inc/clrprivbindercoreclr.h b/src/coreclr/binder/inc/clrprivbindercoreclr.h index bf11bcf113f96..b3640514fdebb 100644 --- a/src/coreclr/binder/inc/clrprivbindercoreclr.h +++ b/src/coreclr/binder/inc/clrprivbindercoreclr.h @@ -22,7 +22,7 @@ class CLRPrivBinderCoreCLR : public AssemblyLoadContext // ICLRPrivBinder functions //------------------------------------------------------------------------- STDMETHOD(BindAssemblyByName)( - /* [in] */ IAssemblyName *pIAssemblyName, + /* [string][in] */ const WCHAR *pAssemblyFullName, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetLoaderAllocator)( @@ -47,6 +47,9 @@ class CLRPrivBinderCoreCLR : public AssemblyLoadContext BOOL fExplicitBindToNativeImage, ICLRPrivAssembly **ppAssembly); + HRESULT BindUsingAssemblyName(BINDER_SPACE::AssemblyName *pAssemblyName, + ICLRPrivAssembly **ppAssembly); + #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) HRESULT BindUsingPEImage( /* in */ PEImage *pPEImage, /* in */ BOOL fIsNativeImage, diff --git a/src/coreclr/inc/clrprivbinding.idl b/src/coreclr/inc/clrprivbinding.idl index 08743d215cc3a..9c048302bc8d0 100644 --- a/src/coreclr/inc/clrprivbinding.idl +++ b/src/coreclr/inc/clrprivbinding.idl @@ -3,14 +3,11 @@ import "unknwn.idl"; import "objidl.idl"; -import "fusion.idl"; // Forward declarations interface ICLRPrivBinder; interface ICLRPrivAssembly; -typedef LPCSTR LPCUTF8; - /************************************************************************************** ** This IDL file defines the assembly binding host interfaces. Some things to keep ** in mind: @@ -35,11 +32,11 @@ interface ICLRPrivBinder : IUnknown ** BindAssemblyByName -- Binds an assembly by name. ** NOTE: This method is required to be idempotent. See general comment above. ** - ** pAssemblyName - name of the assembly for which a bind is being requested. + ** pAssemblyFullName - name of the assembly for which a bind is being requested. ** ppAssembly - upon success, receives the bound assembly. **********************************************************************************/ HRESULT BindAssemblyByName( - [in] IAssemblyName * pAssemblyName, + [in, string] const WCHAR* pAssemblyFullName, [out, retval] ICLRPrivAssembly ** ppAssembly); /********************************************************************************** diff --git a/src/coreclr/inc/readme.md b/src/coreclr/inc/readme.md index ee47be8e514ed..bb685385d022b 100644 --- a/src/coreclr/inc/readme.md +++ b/src/coreclr/inc/readme.md @@ -4,9 +4,10 @@ This directory has a variety of .idl files (such as corprof.idl) that need a lit the build rules would automatically convert the idls into corresponding .h/.c files and include them in compilations. On non-windows platforms we don't have an equivalent for midl.exe which did that conversion so we work around the issue by doing: -- Build on Windows as normal, which will generate files in artifacts\obj\windows.x64.Debug\src\inc\idls_out\ -- Copy any updated headers into src\pal\prebuilt\inc\ -- If needed, adjust any of the .cpp files in src\pal\prebuilt\idl\ by hand, using the corresponding artifacts\obj\windows.x64.Debug\src\inc\idls_out\*_i.c as a guide. Typically -this is just adding MIDL_DEFINE_GUID(...) for any new classes/interfaces that have been added to the idl file. +- Build on Windows as normal, which will generate files in `artifacts\obj\windows.x64.Debug\inc\idls_out\` +- Copy any updated headers into `src\coreclr\pal\prebuilt\inc\` +- If needed, adjust any of the .cpp files in `src\coreclr\pal\prebuilt\idl\` by hand, using the corresponding `artifacts\obj\windows.x64.Debug\inc\idls_out\*_i.c` as a guide. + - Typically +this is just adding `MIDL_DEFINE_GUID(...)` for any new classes/interfaces that have been added to the idl file. Include these src changes with the remainder of your work when you submit a PR. diff --git a/src/coreclr/pal/prebuilt/inc/clrprivbinding.h b/src/coreclr/pal/prebuilt/inc/clrprivbinding.h index ea4cf7417074a..9d696bccdd12e 100644 --- a/src/coreclr/pal/prebuilt/inc/clrprivbinding.h +++ b/src/coreclr/pal/prebuilt/inc/clrprivbinding.h @@ -55,7 +55,6 @@ typedef interface ICLRPrivAssembly ICLRPrivAssembly; /* header files for imported files */ #include "unknwn.h" #include "objidl.h" -#include "fusion.h" #ifdef __cplusplus extern "C"{ @@ -67,8 +66,6 @@ extern "C"{ -typedef LPCSTR LPCUTF8; - extern RPC_IF_HANDLE __MIDL_itf_clrprivbinding_0000_0000_v0_0_c_ifspec; @@ -90,7 +87,7 @@ EXTERN_C const IID IID_ICLRPrivBinder; { public: virtual HRESULT STDMETHODCALLTYPE BindAssemblyByName( - /* [in] */ IAssemblyName *pAssemblyName, + /* [string][in] */ const WCHAR *pAssemblyFullName, /* [retval][out] */ ICLRPrivAssembly **ppAssembly) = 0; virtual HRESULT STDMETHODCALLTYPE GetBinderID( @@ -122,7 +119,7 @@ EXTERN_C const IID IID_ICLRPrivBinder; HRESULT ( STDMETHODCALLTYPE *BindAssemblyByName )( ICLRPrivBinder * This, - /* [in] */ IAssemblyName *pAssemblyName, + /* [string][in] */ const WCHAR *pAssemblyFullName, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); HRESULT ( STDMETHODCALLTYPE *GetBinderID )( @@ -156,8 +153,8 @@ EXTERN_C const IID IID_ICLRPrivBinder; ( (This)->lpVtbl -> Release(This) ) -#define ICLRPrivBinder_BindAssemblyByName(This,pAssemblyName,ppAssembly) \ - ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyName,ppAssembly) ) +#define ICLRPrivBinder_BindAssemblyByName(This,pAssemblyFullName,ppAssembly) \ + ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyFullName,ppAssembly) ) #define ICLRPrivBinder_GetBinderID(This,pBinderId) \ ( (This)->lpVtbl -> GetBinderID(This,pBinderId) ) @@ -233,7 +230,7 @@ EXTERN_C const IID IID_ICLRPrivAssembly; HRESULT ( STDMETHODCALLTYPE *BindAssemblyByName )( ICLRPrivAssembly * This, - /* [in] */ IAssemblyName *pAssemblyName, + /* [string][in] */ const WCHAR *pAssemblyFullName, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); HRESULT ( STDMETHODCALLTYPE *GetBinderID )( @@ -271,8 +268,8 @@ EXTERN_C const IID IID_ICLRPrivAssembly; ( (This)->lpVtbl -> Release(This) ) -#define ICLRPrivAssembly_BindAssemblyByName(This,pAssemblyName,ppAssembly) \ - ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyName,ppAssembly) ) +#define ICLRPrivAssembly_BindAssemblyByName(This,pAssemblyFullName,ppAssembly) \ + ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyFullName,ppAssembly) ) #define ICLRPrivAssembly_GetBinderID(This,pBinderId) \ ( (This)->lpVtbl -> GetBinderID(This,pBinderId) ) diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 8494ff4a6ed00..976a036d61b6e 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -5284,13 +5284,14 @@ AppDomain::AssemblyIterator::Next_Unlocked( #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) // Returns S_OK if the assembly was successfully loaded -HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, IAssemblyName *pIAssemblyName, CLRPrivBinderCoreCLR *pTPABinder, BINDER_SPACE::AssemblyName *pAssemblyName, ICLRPrivAssembly **ppLoadedAssembly) +HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, CLRPrivBinderCoreCLR *pTPABinder, ICLRPrivAssembly **ppLoadedAssembly) { CONTRACTL { THROWS; GC_TRIGGERS; MODE_ANY; + PRECONDITION(pAssemblyName != NULL); PRECONDITION(ppLoadedAssembly != NULL); } CONTRACTL_END; @@ -5312,188 +5313,179 @@ HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToB ICLRPrivAssembly *pResolvedAssembly = NULL; - // Prepare to invoke System.Runtime.Loader.AssemblyLoadContext.Resolve method. - // - // First, initialize an assembly spec for the requested assembly - // - AssemblySpec spec; - hr = spec.Init(pIAssemblyName); - if (SUCCEEDED(hr)) - { - bool fResolvedAssembly = false; - BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, 0 /*binderID*/, pManagedAssemblyLoadContextToBindWithin, hr}; + bool fResolvedAssembly = false; + BinderTracing::ResolutionAttemptedOperation tracer{pAssemblyName, 0 /*binderID*/, pManagedAssemblyLoadContextToBindWithin, hr}; - // Allocate an AssemblyName managed object - _gcRefs.oRefAssemblyName = (ASSEMBLYNAMEREF) AllocateObject(CoreLibBinder::GetClass(CLASS__ASSEMBLY_NAME)); + // Allocate an AssemblyName managed object + _gcRefs.oRefAssemblyName = (ASSEMBLYNAMEREF) AllocateObject(CoreLibBinder::GetClass(CLASS__ASSEMBLY_NAME)); - // Initialize the AssemblyName object from the AssemblySpec - spec.AssemblyNameInit(&_gcRefs.oRefAssemblyName, NULL); + // Initialize the AssemblyName object + AssemblySpec::InitializeAssemblyNameRef(pAssemblyName, &_gcRefs.oRefAssemblyName); - bool isSatelliteAssemblyRequest = !spec.IsNeutralCulture(); + bool isSatelliteAssemblyRequest = !pAssemblyName->IsNeutralCulture(); - EX_TRY + EX_TRY + { + if (pTPABinder != NULL) { - if (pTPABinder != NULL) + // Step 2 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) - Invoke Load method + // This is not invoked for TPA Binder since it always returns NULL. + tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::AssemblyLoadContextLoad); + + // Finally, setup arguments for invocation + MethodDescCallSite methLoadAssembly(METHOD__ASSEMBLYLOADCONTEXT__RESOLVE); + + // Setup the arguments for the call + ARG_SLOT args[2] = { - // Step 2 (of CLRPrivBinderAssemblyLoadContext::BindUsingAssemblyName) - Invoke Load method - // This is not invoked for TPA Binder since it always returns NULL. - tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::AssemblyLoadContextLoad); + PtrToArgSlot(pManagedAssemblyLoadContextToBindWithin), // IntPtr for managed assembly load context instance + ObjToArgSlot(_gcRefs.oRefAssemblyName), // AssemblyName instance + }; - // Finally, setup arguments for invocation - MethodDescCallSite methLoadAssembly(METHOD__ASSEMBLYLOADCONTEXT__RESOLVE); + // Make the call + _gcRefs.oRefLoadedAssembly = (ASSEMBLYREF) methLoadAssembly.Call_RetOBJECTREF(args); + if (_gcRefs.oRefLoadedAssembly != NULL) + { + fResolvedAssembly = true; + } - // Setup the arguments for the call - ARG_SLOT args[2] = - { - PtrToArgSlot(pManagedAssemblyLoadContextToBindWithin), // IntPtr for managed assembly load context instance - ObjToArgSlot(_gcRefs.oRefAssemblyName), // AssemblyName instance - }; + hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; - // Make the call - _gcRefs.oRefLoadedAssembly = (ASSEMBLYREF) methLoadAssembly.Call_RetOBJECTREF(args); - if (_gcRefs.oRefLoadedAssembly != NULL) + // Step 3 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) + if (!fResolvedAssembly && !isSatelliteAssemblyRequest) + { + tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::DefaultAssemblyLoadContextFallback); + + // If we could not resolve the assembly using Load method, then attempt fallback with TPA Binder. + // Since TPA binder cannot fallback to itself, this fallback does not happen for binds within TPA binder. + // + // Switch to pre-emp mode before calling into the binder + GCX_PREEMP(); + ICLRPrivAssembly *pCoreCLRFoundAssembly = NULL; + hr = pTPABinder->BindUsingAssemblyName(pAssemblyName, &pCoreCLRFoundAssembly); + if (SUCCEEDED(hr)) { + _ASSERTE(pCoreCLRFoundAssembly != NULL); + pResolvedAssembly = pCoreCLRFoundAssembly; fResolvedAssembly = true; } + } + } - hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; + if (!fResolvedAssembly && isSatelliteAssemblyRequest) + { + // Step 4 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) + // + // Attempt to resolve it using the ResolveSatelliteAssembly method. + // Finally, setup arguments for invocation + tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::ResolveSatelliteAssembly); - // Step 3 (of CLRPrivBinderAssemblyLoadContext::BindUsingAssemblyName) - if (!fResolvedAssembly && !isSatelliteAssemblyRequest) - { - tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::DefaultAssemblyLoadContextFallback); - - // If we could not resolve the assembly using Load method, then attempt fallback with TPA Binder. - // Since TPA binder cannot fallback to itself, this fallback does not happen for binds within TPA binder. - // - // Switch to pre-emp mode before calling into the binder - GCX_PREEMP(); - ICLRPrivAssembly *pCoreCLRFoundAssembly = NULL; - hr = pTPABinder->BindAssemblyByName(pIAssemblyName, &pCoreCLRFoundAssembly); - if (SUCCEEDED(hr)) - { - _ASSERTE(pCoreCLRFoundAssembly != NULL); - pResolvedAssembly = pCoreCLRFoundAssembly; - fResolvedAssembly = true; - } - } - } + MethodDescCallSite methResolveSatelitteAssembly(METHOD__ASSEMBLYLOADCONTEXT__RESOLVESATELLITEASSEMBLY); - if (!fResolvedAssembly && isSatelliteAssemblyRequest) + // Setup the arguments for the call + ARG_SLOT args[2] = { - // Step 4 (of CLRPrivBinderAssemblyLoadContext::BindUsingAssemblyName) - // - // Attempt to resolve it using the ResolveSatelliteAssembly method. - // Finally, setup arguments for invocation - tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::ResolveSatelliteAssembly); + PtrToArgSlot(pManagedAssemblyLoadContextToBindWithin), // IntPtr for managed assembly load context instance + ObjToArgSlot(_gcRefs.oRefAssemblyName), // AssemblyName instance + }; - MethodDescCallSite methResolveSatelitteAssembly(METHOD__ASSEMBLYLOADCONTEXT__RESOLVESATELLITEASSEMBLY); + // Make the call + _gcRefs.oRefLoadedAssembly = (ASSEMBLYREF) methResolveSatelitteAssembly.Call_RetOBJECTREF(args); + if (_gcRefs.oRefLoadedAssembly != NULL) + { + // Set the flag indicating we found the assembly + fResolvedAssembly = true; + } - // Setup the arguments for the call - ARG_SLOT args[2] = - { - PtrToArgSlot(pManagedAssemblyLoadContextToBindWithin), // IntPtr for managed assembly load context instance - ObjToArgSlot(_gcRefs.oRefAssemblyName), // AssemblyName instance - }; + hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; + } - // Make the call - _gcRefs.oRefLoadedAssembly = (ASSEMBLYREF) methResolveSatelitteAssembly.Call_RetOBJECTREF(args); - if (_gcRefs.oRefLoadedAssembly != NULL) - { - // Set the flag indicating we found the assembly - fResolvedAssembly = true; - } + if (!fResolvedAssembly) + { + // Step 5 (of CLRPrivBinderAssemblyLoadContext::BindAssemblyByName) + // + // If we couldn't resolve the assembly using TPA LoadContext as well, then + // attempt to resolve it using the Resolving event. + // Finally, setup arguments for invocation + tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::AssemblyLoadContextResolvingEvent); - hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; - } + MethodDescCallSite methResolveUsingEvent(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUSINGEVENT); - if (!fResolvedAssembly) + // Setup the arguments for the call + ARG_SLOT args[2] = { - // Step 5 (of CLRPrivBinderAssemblyLoadContext::BindUsingAssemblyName) - // - // If we couldn't resolve the assembly using TPA LoadContext as well, then - // attempt to resolve it using the Resolving event. - // Finally, setup arguments for invocation - tracer.GoToStage(BinderTracing::ResolutionAttemptedOperation::Stage::AssemblyLoadContextResolvingEvent); - - MethodDescCallSite methResolveUsingEvent(METHOD__ASSEMBLYLOADCONTEXT__RESOLVEUSINGEVENT); + PtrToArgSlot(pManagedAssemblyLoadContextToBindWithin), // IntPtr for managed assembly load context instance + ObjToArgSlot(_gcRefs.oRefAssemblyName), // AssemblyName instance + }; - // Setup the arguments for the call - ARG_SLOT args[2] = - { - PtrToArgSlot(pManagedAssemblyLoadContextToBindWithin), // IntPtr for managed assembly load context instance - ObjToArgSlot(_gcRefs.oRefAssemblyName), // AssemblyName instance - }; + // Make the call + _gcRefs.oRefLoadedAssembly = (ASSEMBLYREF) methResolveUsingEvent.Call_RetOBJECTREF(args); + if (_gcRefs.oRefLoadedAssembly != NULL) + { + // Set the flag indicating we found the assembly + fResolvedAssembly = true; + } - // Make the call - _gcRefs.oRefLoadedAssembly = (ASSEMBLYREF) methResolveUsingEvent.Call_RetOBJECTREF(args); - if (_gcRefs.oRefLoadedAssembly != NULL) - { - // Set the flag indicating we found the assembly - fResolvedAssembly = true; - } + hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; + } - hr = fResolvedAssembly ? S_OK : COR_E_FILENOTFOUND; + if (fResolvedAssembly && pResolvedAssembly == NULL) + { + // If we are here, assembly was successfully resolved via Load or Resolving events. + _ASSERTE(_gcRefs.oRefLoadedAssembly != NULL); + + // We were able to get the assembly loaded. Now, get its name since the host could have + // performed the resolution using an assembly with different name. + DomainAssembly *pDomainAssembly = _gcRefs.oRefLoadedAssembly->GetDomainAssembly(); + PEAssembly *pLoadedPEAssembly = NULL; + bool fFailLoad = false; + if (!pDomainAssembly) + { + // Reflection emitted assemblies will not have a domain assembly. + fFailLoad = true; } - - if (fResolvedAssembly && pResolvedAssembly == NULL) + else { - // If we are here, assembly was successfully resolved via Load or Resolving events. - _ASSERTE(_gcRefs.oRefLoadedAssembly != NULL); - - // We were able to get the assembly loaded. Now, get its name since the host could have - // performed the resolution using an assembly with different name. - DomainAssembly *pDomainAssembly = _gcRefs.oRefLoadedAssembly->GetDomainAssembly(); - PEAssembly *pLoadedPEAssembly = NULL; - bool fFailLoad = false; - if (!pDomainAssembly) + pLoadedPEAssembly = pDomainAssembly->GetFile(); + if (!pLoadedPEAssembly->HasHostAssembly()) { // Reflection emitted assemblies will not have a domain assembly. fFailLoad = true; } - else - { - pLoadedPEAssembly = pDomainAssembly->GetFile(); - if (!pLoadedPEAssembly->HasHostAssembly()) - { - // Reflection emitted assemblies will not have a domain assembly. - fFailLoad = true; - } - } - - // The loaded assembly's ICLRPrivAssembly* is saved as HostAssembly in PEAssembly - if (fFailLoad) - { - SString name; - spec.GetFileOrDisplayName(0, name); - COMPlusThrowHR(COR_E_INVALIDOPERATION, IDS_HOST_ASSEMBLY_RESOLVER_DYNAMICALLY_EMITTED_ASSEMBLIES_UNSUPPORTED, name); - } - - pResolvedAssembly = pLoadedPEAssembly->GetHostAssembly(); } - if (fResolvedAssembly) + // The loaded assembly's ICLRPrivAssembly* is saved as HostAssembly in PEAssembly + if (fFailLoad) { - _ASSERTE(pResolvedAssembly != NULL); + PathString name; + pAssemblyName->GetDisplayName(name, BINDER_SPACE::AssemblyName::INCLUDE_ALL); + COMPlusThrowHR(COR_E_INVALIDOPERATION, IDS_HOST_ASSEMBLY_RESOLVER_DYNAMICALLY_EMITTED_ASSEMBLIES_UNSUPPORTED, name); + } - // Get the ICLRPrivAssembly reference to return back to. - *ppLoadedAssembly = clr::SafeAddRef(pResolvedAssembly); - hr = S_OK; + pResolvedAssembly = pLoadedPEAssembly->GetHostAssembly(); + } - tracer.SetFoundAssembly(static_cast(pResolvedAssembly)); - } - else - { - hr = COR_E_FILENOTFOUND; - } + if (fResolvedAssembly) + { + _ASSERTE(pResolvedAssembly != NULL); + + // Get the ICLRPrivAssembly reference to return back to. + *ppLoadedAssembly = clr::SafeAddRef(pResolvedAssembly); + hr = S_OK; + + tracer.SetFoundAssembly(static_cast(pResolvedAssembly)); } - EX_HOOK + else { - Exception* ex = GET_EXCEPTION(); - tracer.SetException(ex); + hr = COR_E_FILENOTFOUND; } - EX_END_HOOK } + EX_HOOK + { + Exception* ex = GET_EXCEPTION(); + tracer.SetException(ex); + } + EX_END_HOOK GCPROTECT_END(); diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 946f5856f7ca2..4059a29c15ce4 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -580,6 +580,35 @@ void AssemblySpec::AssemblyNameInit(ASSEMBLYNAMEREF* pAsmName, PEImage* pImageIn GCPROTECT_END(); } +/* static */ +void AssemblySpec::InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* assemblyName, _Out_ ASSEMBLYNAMEREF* assemblyNameRef) +{ + CONTRACTL + { + THROWS; + MODE_COOPERATIVE; + GC_TRIGGERS; + PRECONDITION(assemblyName != NULL); + PRECONDITION(IsProtectedByGCFrame(assemblyNameRef)); + } + CONTRACTL_END; + + AssemblySpec spec; + spec.InitializeWithAssemblyIdentity(assemblyName); + + StackScratchBuffer nameBuffer; + spec.SetName(assemblyName->GetSimpleName().GetUTF8(nameBuffer)); + + StackScratchBuffer cultureBuffer; + if (assemblyName->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE)) + { + LPCSTR culture = assemblyName->IsNeutralCulture() ? "" : assemblyName->GetCulture().GetUTF8(cultureBuffer); + spec.SetCulture(culture); + } + + spec.AssemblyNameInit(assemblyNameRef, NULL); +} + #endif // CROSSGEN_COMPILE // Check if the supplied assembly's public key matches up with the one in the Spec, if any @@ -939,11 +968,6 @@ HRESULT AssemblySpec::EmitToken( return hr; } -//=========================================================================================== -// Constructs an AssemblySpec for the given IAssemblyName. Recognizes IAssemblyName objects -// that were built from WinRT AssemblySpec objects, extracts the encoded type name, and sets -// the type namespace and class name properties appropriately. - AssemblySpecBindingCache::AssemblySpecBindingCache() { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/assemblyspec.hpp b/src/coreclr/vm/assemblyspec.hpp index 70f7b9ac760d6..dbdaa20101b77 100644 --- a/src/coreclr/vm/assemblyspec.hpp +++ b/src/coreclr/vm/assemblyspec.hpp @@ -207,8 +207,7 @@ class AssemblySpec : public BaseAssemblySpec DomainAssembly *LoadDomainAssembly(FileLoadLevel targetLevel, BOOL fThrowOnFileNotFound = TRUE); - //**************************************************************************************** - // + public: // static // Creates and loads an assembly based on the name and context. static Assembly *LoadAssembly(LPCSTR pSimpleName, AssemblyMetaDataInternal* pContext, @@ -216,10 +215,12 @@ class AssemblySpec : public BaseAssemblySpec DWORD cbPublicKeyOrToken, DWORD dwFlags); - // Load an assembly based on an explicit path static Assembly *LoadAssembly(LPCWSTR pFilePath); + // Initialize an AssemblyName managed object based on the specified assemblyName + static void InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* assemblyName, _Out_ ASSEMBLYNAMEREF* assemblyNameRef); + public: void MatchPublicKeys(Assembly *pAssembly); diff --git a/src/coreclr/vm/baseassemblyspec.cpp b/src/coreclr/vm/baseassemblyspec.cpp index 5a57c0ba5d3e7..5a0b0c3e9240b 100644 --- a/src/coreclr/vm/baseassemblyspec.cpp +++ b/src/coreclr/vm/baseassemblyspec.cpp @@ -364,181 +364,4 @@ VOID BaseAssemblySpec::SetName(SString const & ssName) m_ownedFlags |= NAME_OWNED; } -HRESULT BaseAssemblySpec::Init(IAssemblyName *pName) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - MODE_ANY; - } - CONTRACTL_END; - - _ASSERTE(pName); - - HRESULT hr; - - // Fill out info from name, if we have it. - - DWORD cbSize = 0; - hr=pName->GetProperty(ASM_NAME_NAME, NULL, &cbSize); - if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { - hr=S_OK; - CQuickBytes qb; - LPWSTR pwName = (LPWSTR) qb.AllocNoThrow(cbSize); - if (!pwName) - return E_OUTOFMEMORY; - - IfFailRet(pName->GetProperty(ASM_NAME_NAME, pwName, &cbSize)); - - m_pAssemblyName = NULL; - - hr = FString::ConvertUnicode_Utf8(pwName, & ((LPSTR &) m_pAssemblyName)); - - if (FAILED(hr)) - { - return hr; - } - - m_ownedFlags |= NAME_OWNED; - } - IfFailRet(hr); - - // Note: cascade checks so we don't set lower priority version #'s if higher ones are missing - cbSize = sizeof(m_context.usMajorVersion); - hr=pName->GetProperty(ASM_NAME_MAJOR_VERSION, &m_context.usMajorVersion, &cbSize); - - if (hr!=S_OK || !cbSize) - m_context.usMajorVersion = (USHORT) -1; - else { - cbSize = sizeof(m_context.usMinorVersion); - hr=pName->GetProperty(ASM_NAME_MINOR_VERSION, &m_context.usMinorVersion, &cbSize); - } - - if (hr!=S_OK || !cbSize) - m_context.usMinorVersion = (USHORT) -1; - else { - cbSize = sizeof(m_context.usBuildNumber); - pName->GetProperty(ASM_NAME_BUILD_NUMBER, &m_context.usBuildNumber, &cbSize); - } - - if (hr!=S_OK || !cbSize) - m_context.usBuildNumber = (USHORT) -1; - else { - cbSize = sizeof(m_context.usRevisionNumber); - pName->GetProperty(ASM_NAME_REVISION_NUMBER, &m_context.usRevisionNumber, &cbSize); - } - - if (hr!=S_OK || !cbSize) - m_context.usRevisionNumber = (USHORT) -1; - - if (hr==E_INVALIDARG) - hr=S_FALSE; - - IfFailRet(hr); - - cbSize = 0; - hr = pName->GetProperty(ASM_NAME_CULTURE, NULL, &cbSize); - - if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { - LPWSTR pwName = (LPWSTR) alloca(cbSize); - IfFailRet(pName->GetProperty(ASM_NAME_CULTURE, pwName, &cbSize)); - - hr = FString::ConvertUnicode_Utf8(pwName, & ((LPSTR &) m_context.szLocale)); - - m_ownedFlags |= LOCALE_OWNED; - } - - IfFailRet(hr); - - m_dwFlags = 0; - - cbSize = 0; - hr=pName->GetProperty(ASM_NAME_PUBLIC_KEY_TOKEN, NULL, &cbSize); - if (hr== HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { - m_pbPublicKeyOrToken = new (nothrow) BYTE[cbSize]; - if (m_pbPublicKeyOrToken == NULL) - return E_OUTOFMEMORY; - m_cbPublicKeyOrToken = cbSize; - m_ownedFlags |= PUBLIC_KEY_OR_TOKEN_OWNED; - IfFailRet(pName->GetProperty(ASM_NAME_PUBLIC_KEY_TOKEN, m_pbPublicKeyOrToken, &cbSize)); - } - else { - if (hr!=E_INVALIDARG) - IfFailRet(hr); - hr=pName->GetProperty(ASM_NAME_PUBLIC_KEY, NULL, &cbSize); - if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { - hr=S_OK; - // @todo: we need to normalize this into a public key token so - // comparisons work correctly. But this involves binding to mscorsn. - m_pbPublicKeyOrToken = new (nothrow) BYTE[cbSize]; - if (m_pbPublicKeyOrToken == NULL) - return E_OUTOFMEMORY; - m_cbPublicKeyOrToken = cbSize; - m_dwFlags |= afPublicKey; - m_ownedFlags |= PUBLIC_KEY_OR_TOKEN_OWNED; - IfFailRet(pName->GetProperty(ASM_NAME_PUBLIC_KEY, m_pbPublicKeyOrToken, &cbSize)); - } - else { - IfFailRet(hr); - hr= pName->GetProperty(ASM_NAME_NULL_PUBLIC_KEY, NULL, &cbSize); - if (hr!=S_OK) - hr=pName->GetProperty(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, NULL, &cbSize); - if ( hr == S_OK ) { - m_pbPublicKeyOrToken = new (nothrow) BYTE[0]; - if (m_pbPublicKeyOrToken == NULL) - return E_OUTOFMEMORY; - m_cbPublicKeyOrToken = 0; - m_ownedFlags |= PUBLIC_KEY_OR_TOKEN_OWNED; - } - if (hr==E_INVALIDARG) - hr=S_FALSE; - IfFailRet(hr); - - } - } - - // Recover the afRetargetable flag - BOOL bRetarget; - cbSize = sizeof(bRetarget); - hr = pName->GetProperty(ASM_NAME_RETARGET, &bRetarget, &cbSize); - if (hr == S_OK && cbSize != 0 && bRetarget) - m_dwFlags |= afRetargetable; - - // Recover the Processor Architecture flags - PEKIND peKind; - cbSize = sizeof(PEKIND); - hr = pName->GetProperty(ASM_NAME_ARCHITECTURE, &peKind, &cbSize); - if ((hr == S_OK) && (cbSize != 0) && (peKind < (afPA_NoPlatform >> afPA_Shift)) && (peKind >= (afPA_MSIL >> afPA_Shift))) - m_dwFlags |= (((DWORD)peKind) << afPA_Shift); - - cbSize = 0; - hr=pName->GetProperty(ASM_NAME_CODEBASE_URL, NULL, &cbSize); - if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) { - m_wszCodeBase = new (nothrow) WCHAR [ cbSize/sizeof(WCHAR) ]; - if (m_wszCodeBase == NULL) - return E_OUTOFMEMORY; - m_ownedFlags |= CODE_BASE_OWNED; - IfFailRet(pName->GetProperty(ASM_NAME_CODEBASE_URL, - (void*)m_wszCodeBase, &cbSize)); - } - else - IfFailRet(hr); - - // Recover the Content Type enum - DWORD dwContentType; - cbSize = sizeof(dwContentType); - hr = pName->GetProperty(ASM_NAME_CONTENT_TYPE, &dwContentType, &cbSize); - if ((hr == S_OK) && (cbSize == sizeof(dwContentType))) - { - _ASSERTE((dwContentType == AssemblyContentType_Default) || (dwContentType == AssemblyContentType_WindowsRuntime)); - if (dwContentType == AssemblyContentType_WindowsRuntime) - { - m_dwFlags |= afContentType_WindowsRuntime; - } - } - - return S_OK; -} - #endif // !DACCESS_COMPILE diff --git a/src/coreclr/vm/baseassemblyspec.h b/src/coreclr/vm/baseassemblyspec.h index 150368c1c447c..107b025635aef 100644 --- a/src/coreclr/vm/baseassemblyspec.h +++ b/src/coreclr/vm/baseassemblyspec.h @@ -56,8 +56,6 @@ class BaseAssemblySpec HRESULT Init(mdAssembly tkAssemblyRef, IMetaDataAssemblyImport* pImport); HRESULT Init(LPCSTR pAssemblyDisplayName); - HRESULT Init(IAssemblyName *pName); - // Note that this method does not clone the fields! VOID CopyFrom(const BaseAssemblySpec *pSpec); @@ -129,9 +127,12 @@ class BaseAssemblySpec void GetFileOrDisplayName(DWORD flags, SString &result) const; void GetDisplayName(DWORD flags, SString &result) const; -protected: +protected: // static static BOOL CompareRefToDef(const BaseAssemblySpec *pRef, const BaseAssemblySpec *pDef); +protected: + void InitializeWithAssemblyIdentity(BINDER_SPACE::AssemblyIdentity *identity); + private: void GetDisplayNameInternal(DWORD flags, SString &result) const; }; diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index e9857a9b388c2..a7a7616f84339 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -139,12 +139,7 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, { // For name based binding these arguments shouldn't have been changed from default _ASSERTE(!fNgenExplicitBind && !fExplicitBindToNativeImage); - SafeComHolder pName; - hr = CreateAssemblyNameObject(&pName, assemblyDisplayName); - if (SUCCEEDED(hr)) - { - hr = pBinder->BindAssemblyByName(pName, &pPrivAsm); - } + hr = pBinder->BindAssemblyByName(assemblyDisplayName, &pPrivAsm); } else { @@ -187,7 +182,6 @@ STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, { PEImageHolder pImage = NULL; PEImageHolder pNativeImage = NULL; - AppDomain* pDomain = ::GetAppDomain(); // DEAD ? ? #ifdef FEATURE_PREJIT // fExplicitBindToNativeImage is set on Phone when we bind to a list of native images and have no IL on device for an assembly @@ -342,97 +336,116 @@ HRESULT BaseAssemblySpec::ParseName() IfFailThrow(hr); } + // Name - does not copy the data SetName(pAssemblyIdentity->GetSimpleNameUTF8()); - if (pAssemblyIdentity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_VERSION)) - { - m_context.usMajorVersion = (USHORT)pAssemblyIdentity->m_version.GetMajor(); - m_context.usMinorVersion = (USHORT)pAssemblyIdentity->m_version.GetMinor(); - m_context.usBuildNumber = (USHORT)pAssemblyIdentity->m_version.GetBuild(); - m_context.usRevisionNumber = (USHORT)pAssemblyIdentity->m_version.GetRevision(); - } - + // Culture - does not copy the data if (pAssemblyIdentity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE)) { if (!pAssemblyIdentity->m_cultureOrLanguage.IsEmpty()) + { SetCulture(pAssemblyIdentity->GetCultureOrLanguageUTF8()); + } else + { SetCulture(""); + } } - if (pAssemblyIdentity-> - Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN) || - pAssemblyIdentity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY)) - { - m_pbPublicKeyOrToken = const_cast(pAssemblyIdentity->GetPublicKeyOrTokenArray()); - m_cbPublicKeyOrToken = pAssemblyIdentity->m_publicKeyOrTokenBLOB.GetSize(); + InitializeWithAssemblyIdentity(pAssemblyIdentity); - if (pAssemblyIdentity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY)) - { - m_dwFlags |= afPublicKey; - } - } - else if (pAssemblyIdentity-> - Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL)) - { - m_pbPublicKeyOrToken = const_cast(pAssemblyIdentity->GetPublicKeyOrTokenArray()); - m_cbPublicKeyOrToken = 0; - } - else - { - m_pbPublicKeyOrToken = NULL; - m_cbPublicKeyOrToken = 0; - } + // Copy and own any fields we do not already own + CloneFields(); + } + EX_CATCH_HRESULT(hr); - if (pAssemblyIdentity-> - Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE)) - { - switch (pAssemblyIdentity->m_kProcessorArchitecture) - { - case peI386: - m_dwFlags |= afPA_x86; - break; - case peIA64: - m_dwFlags |= afPA_IA64; - break; - case peAMD64: - m_dwFlags |= afPA_AMD64; - break; - case peARM: - m_dwFlags |= afPA_ARM; - break; - case peMSIL: - m_dwFlags |= afPA_MSIL; - break; - default: - IfFailThrow(FUSION_E_INVALID_NAME); - } - } + return hr; +} +void BaseAssemblySpec::InitializeWithAssemblyIdentity(BINDER_SPACE::AssemblyIdentity *identity) +{ + CONTRACTL + { + INSTANCE_CHECK; + GC_NOTRIGGER; + NOTHROW; + } + CONTRACTL_END; - if (pAssemblyIdentity-> - Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE)) + // Version + if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_VERSION)) + { + m_context.usMajorVersion = (USHORT)identity->m_version.GetMajor(); + m_context.usMinorVersion = (USHORT)identity->m_version.GetMinor(); + m_context.usBuildNumber = (USHORT)identity->m_version.GetBuild(); + m_context.usRevisionNumber = (USHORT)identity->m_version.GetRevision(); + } + + // Public key or token - does not copy the data + if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN) + || identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY)) + { + m_pbPublicKeyOrToken = const_cast(static_cast(identity->m_publicKeyOrTokenBLOB)); + m_cbPublicKeyOrToken = identity->m_publicKeyOrTokenBLOB.GetSize(); + + if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY)) { - m_dwFlags |= afRetargetable; + m_dwFlags |= afPublicKey; } + } + else if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL)) + { + m_pbPublicKeyOrToken = const_cast(static_cast(identity->m_publicKeyOrTokenBLOB)); + m_cbPublicKeyOrToken = 0; + } + else + { + m_pbPublicKeyOrToken = NULL; + m_cbPublicKeyOrToken = 0; + } - if (pAssemblyIdentity-> - Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE)) + // Architecture + if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE)) + { + switch (identity->m_kProcessorArchitecture) { - DWORD dwContentType = pAssemblyIdentity->m_kContentType; - - _ASSERTE((dwContentType == AssemblyContentType_Default) || (dwContentType == AssemblyContentType_WindowsRuntime)); - if (dwContentType == AssemblyContentType_WindowsRuntime) - { - m_dwFlags |= afContentType_WindowsRuntime; - } + case peI386: + m_dwFlags |= afPA_x86; + break; + case peIA64: + m_dwFlags |= afPA_IA64; + break; + case peAMD64: + m_dwFlags |= afPA_AMD64; + break; + case peARM: + m_dwFlags |= afPA_ARM; + break; + case peMSIL: + m_dwFlags |= afPA_MSIL; + break; + default: + IfFailThrow(FUSION_E_INVALID_NAME); } + } - CloneFields(); + // Retargetable + if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE)) + { + m_dwFlags |= afRetargetable; } - EX_CATCH_HRESULT(hr); - return hr; + // Content type + if (identity->Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE)) + { + DWORD dwContentType = identity->m_kContentType; + + _ASSERTE((dwContentType == AssemblyContentType_Default) || (dwContentType == AssemblyContentType_WindowsRuntime)); + if (dwContentType == AssemblyContentType_WindowsRuntime) + { + m_dwFlags |= afContentType_WindowsRuntime; + } + } } #endif // DACCESS_COMPILE From 0b57d22819dbdc8f440a9f149183cd554fd053a2 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Sat, 3 Apr 2021 12:10:32 -0700 Subject: [PATCH 2/8] Remove fusion.h/idl --- src/coreclr/binder/CMakeLists.txt | 3 - src/coreclr/binder/assemblyname.cpp | 132 ---- src/coreclr/binder/fusionassemblyname.cpp | 714 ------------------ src/coreclr/binder/inc/assemblyname.hpp | 1 - src/coreclr/binder/inc/bindertypes.hpp | 60 +- .../inc/clrprivbinderassemblyloadcontext.h | 13 +- src/coreclr/binder/inc/clrprivbindercoreclr.h | 6 - src/coreclr/binder/inc/fusionassemblyname.hpp | 111 --- src/coreclr/binder/inc/fusionhelpers.hpp | 72 -- src/coreclr/ilasm/asmman.cpp | 1 - src/coreclr/inc/corpriv.h | 1 - src/coreclr/inc/fusion.idl | 137 ---- src/coreclr/inc/peinformation.h | 74 -- src/coreclr/pal/prebuilt/inc/fusion.h | 247 ------ src/coreclr/utilcode/CMakeLists.txt | 1 - src/coreclr/utilcode/peinformation.cpp | 98 --- src/coreclr/vm/appdomain.cpp | 1 + src/coreclr/vm/assemblyloadcontext.h | 2 + src/coreclr/vm/baseassemblyspec.cpp | 2 - src/coreclr/vm/coreassemblyspec.cpp | 3 - 20 files changed, 45 insertions(+), 1634 deletions(-) delete mode 100644 src/coreclr/binder/fusionassemblyname.cpp delete mode 100644 src/coreclr/binder/inc/fusionassemblyname.hpp delete mode 100644 src/coreclr/binder/inc/fusionhelpers.hpp delete mode 100644 src/coreclr/inc/fusion.idl delete mode 100644 src/coreclr/inc/peinformation.h delete mode 100644 src/coreclr/pal/prebuilt/inc/fusion.h delete mode 100644 src/coreclr/utilcode/peinformation.cpp diff --git a/src/coreclr/binder/CMakeLists.txt b/src/coreclr/binder/CMakeLists.txt index 208f1214dd0da..221f80defeb37 100644 --- a/src/coreclr/binder/CMakeLists.txt +++ b/src/coreclr/binder/CMakeLists.txt @@ -13,7 +13,6 @@ set(BINDER_COMMON_SOURCES clrprivbindercoreclr.cpp coreclrbindercommon.cpp failurecache.cpp - fusionassemblyname.cpp stringlexer.cpp textualidentityparser.cpp utils.cpp @@ -42,8 +41,6 @@ set(BINDER_COMMON_HEADERS inc/coreclrbindercommon.h inc/failurecache.hpp inc/failurecachehashtraits.hpp - inc/fusionassemblyname.hpp - inc/fusionhelpers.hpp inc/loadcontext.hpp inc/loadcontext.inl inc/stringlexer.hpp diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 82c08c505d763..13e5a1634a9d8 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -12,12 +12,9 @@ // ============================================================ #include "assemblyname.hpp" -#include "assembly.hpp" #include "utils.hpp" #include "variables.hpp" -#include "fusionassemblyname.hpp" - #include "textualidentityparser.hpp" #include "corpriv.h" @@ -171,135 +168,6 @@ namespace BINDER_SPACE return TextualIdentityParser::Parse(assemblyDisplayName, this); } - HRESULT AssemblyName::Init(IAssemblyName *pIAssemblyName) - { - HRESULT hr = S_OK; - - _ASSERTE(pIAssemblyName != NULL); - - EX_TRY - { - { - // Set the simpleName - StackSString simpleName; - hr = fusion::util::GetSimpleName(pIAssemblyName, simpleName); - IF_FAIL_GO(hr); - SetSimpleName(simpleName); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_SIMPLE_NAME); - } - - // Display version - DWORD dwVersionParts[4] = {0,0,0,0}; - DWORD cbVersionSize = sizeof(dwVersionParts[0]); - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_MAJOR_VERSION, static_cast(&dwVersionParts[0]), &cbVersionSize); - IF_FAIL_GO(hr); - if ((hr == S_OK) && (cbVersionSize != 0)) - { - // Property is present - loop to get the individual version details - for(DWORD i = 0; i < 4; i++) - { - cbVersionSize = sizeof(dwVersionParts[i]); - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_MAJOR_VERSION+i, static_cast(&dwVersionParts[i]), &cbVersionSize); - IF_FAIL_GO(hr); - } - - m_version.SetFeatureVersion(dwVersionParts[0], dwVersionParts[1]); - m_version.SetServiceVersion(dwVersionParts[2], dwVersionParts[3]); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_VERSION); - } - - { - // Display culture - StackSString culture; - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_CULTURE, culture); - IF_FAIL_GO(hr); - if (hr == S_OK) - { - SetCulture(culture); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE); - } - } - - { - // Display public key token - NewArrayHolder pPublicKeyToken; - DWORD cbPublicKeyToken = 0; - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_PUBLIC_KEY_TOKEN, static_cast(&pPublicKeyToken), &cbPublicKeyToken); - IF_FAIL_GO(hr); - if ((hr == S_OK) && (cbPublicKeyToken != 0)) - { - m_publicKeyOrTokenBLOB.Set(pPublicKeyToken, cbPublicKeyToken); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN); - } - else - { - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL); - } - } - - // Display processor architecture - DWORD peKind = 0; - DWORD cbPeKind = sizeof(peKind); - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_ARCHITECTURE, static_cast(&peKind), &cbPeKind); - IF_FAIL_GO(hr); - if ((hr == S_OK) && (cbPeKind != 0)) - { - PEKIND PeKind = (PEKIND)peKind; - if (PeKind != peNone) - { - SetArchitecture(PeKind); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE); - } - } - - // Display retarget flag - BOOL fRetarget = FALSE; - DWORD cbRetarget = sizeof(fRetarget); - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_RETARGET, static_cast(&fRetarget), &cbRetarget); - IF_FAIL_GO(hr); - if ((hr == S_OK) && (cbRetarget != 0)) - { - if (fRetarget) - { - SetIsRetargetable(fRetarget); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE); - } - } - - // Display content type - DWORD dwContentType = AssemblyContentType_Default; - DWORD cbContentType = sizeof(dwContentType); - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_CONTENT_TYPE, static_cast(&dwContentType), &cbContentType); - IF_FAIL_GO(hr); - if ((hr == S_OK) && (cbContentType != 0)) - { - if (dwContentType != AssemblyContentType_Default) - { - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE); - SetContentType((AssemblyContentType)dwContentType); - } - } - - { - // Display custom flag. Dont set it if it is not present since that will end up adding the "Custom=null" attribute - // in the displayname of the assembly that maybe generated using this AssemblyName instance. This could create conflict when - // the displayname is generated from the assembly directly as that will not have a "Custom" field set. - NewArrayHolder pCustomBLOB; - DWORD cbCustomBLOB = 0; - hr = fusion::util::GetProperty(pIAssemblyName, ASM_NAME_CUSTOM, static_cast(&pCustomBLOB), &cbCustomBLOB); - IF_FAIL_GO(hr); - if ((hr == S_OK) && (cbCustomBLOB != 0)) - { - m_customBLOB.Set(pCustomBLOB, cbCustomBLOB); - SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CUSTOM); - } - } - } - EX_CATCH_HRESULT(hr); -Exit: - return hr; - } - ULONG AssemblyName::AddRef() { return InterlockedIncrement(&m_cRef); diff --git a/src/coreclr/binder/fusionassemblyname.cpp b/src/coreclr/binder/fusionassemblyname.cpp deleted file mode 100644 index 6da1cc3a3b2bb..0000000000000 --- a/src/coreclr/binder/fusionassemblyname.cpp +++ /dev/null @@ -1,714 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// FusionAssemblyName.cpp -// -// Implements the CAssemblyName class -// -// ============================================================ - -#include -#include -#include "strongnameinternal.h" - -#include "fusionhelpers.hpp" -#include "fusionassemblyname.hpp" - -#include -#include "shlwapi.h" - -#include "assemblyidentity.hpp" -#include "textualidentityparser.hpp" - -// --------------------------------------------------------------------------- -// CPropertyArray ctor -// --------------------------------------------------------------------------- -CPropertyArray::CPropertyArray() -{ - _dwSig = 0x504f5250; /* 'PORP' */ - memset(&_rProp, 0, ASM_NAME_MAX_PARAMS * sizeof(FusionProperty)); -} - -// --------------------------------------------------------------------------- -// CPropertyArray dtor -// --------------------------------------------------------------------------- -CPropertyArray::~CPropertyArray() -{ - for (DWORD i = 0; i < ASM_NAME_MAX_PARAMS; i++) - { - if (_rProp[i].cb > sizeof(DWORD)) - { - if (_rProp[i].pv != NULL) - { - FUSION_DELETE_ARRAY((LPBYTE) _rProp[i].pv); - _rProp[i].pv = NULL; - } - } - } -} - -// --------------------------------------------------------------------------- -// CPropertyArray::Set -// --------------------------------------------------------------------------- -HRESULT CPropertyArray::Set(DWORD PropertyId, - LPCVOID pvProperty, DWORD cbProperty) -{ - HRESULT hr = S_OK; - FusionProperty *pItem = NULL; - - pItem = &(_rProp[PropertyId]); - - if (!cbProperty && !pvProperty) - { - if (pItem->cb > sizeof(DWORD)) - { - if (pItem->pv != NULL) - FUSION_DELETE_ARRAY((LPBYTE) pItem->pv); - } - pItem->pv = NULL; - } - else if (cbProperty > sizeof(DWORD)) - { - LPBYTE ptr = NEW(BYTE[cbProperty]); - if (!ptr) - { - hr = E_OUTOFMEMORY; - goto exit; - } - - if (pItem->cb > sizeof(DWORD)) - FUSION_DELETE_ARRAY((LPBYTE) pItem->pv); - - memcpy(ptr, pvProperty, cbProperty); - pItem->pv = ptr; - } - else - { - if (pItem->cb > sizeof(DWORD)) - FUSION_DELETE_ARRAY((LPBYTE) pItem->pv); - - memcpy(&(pItem->pv), pvProperty, cbProperty); - -#ifdef _DEBUG - if (PropertyId == ASM_NAME_ARCHITECTURE) { - PEKIND pe = * ((PEKIND *)pvProperty); - _ASSERTE(pe != peInvalid); - } -#endif - } - pItem->cb = cbProperty; - -exit: - return hr; -} - -// --------------------------------------------------------------------------- -// CPropertyArray::Get -// --------------------------------------------------------------------------- -HRESULT CPropertyArray::Get(DWORD PropertyId, - LPVOID pvProperty, LPDWORD pcbProperty) -{ - HRESULT hr = S_OK; - FusionProperty *pItem; - - _ASSERTE(pcbProperty); - - if (PropertyId >= ASM_NAME_MAX_PARAMS - || (!pvProperty && *pcbProperty)) - { - _ASSERTE(!"Invalid Argument! Passed in NULL buffer with size non-zero!"); - hr = E_INVALIDARG; - goto exit; - } - - pItem = &(_rProp[PropertyId]); - - if (pItem->cb > *pcbProperty) - hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); - else if (pItem->cb && pvProperty) - memcpy(pvProperty, (pItem->cb > sizeof(DWORD) ? - pItem->pv : (LPBYTE) &(pItem->pv)), pItem->cb); - - *pcbProperty = pItem->cb; - -exit: - return hr; -} - -// --------------------------------------------------------------------------- -// CPropertyArray::operator [] -// Wraps DWORD optimization test. -// --------------------------------------------------------------------------- -FusionProperty CPropertyArray::operator [] (DWORD PropertyId) -{ - FusionProperty prop; - - prop.pv = _rProp[PropertyId].cb > sizeof(DWORD) ? - _rProp[PropertyId].pv : &(_rProp[PropertyId].pv); - - prop.cb = _rProp[PropertyId].cb; - - return prop; -} - -// --------------------------------------------------------------------------- -// CAssemblyName::AddRef -// --------------------------------------------------------------------------- -STDMETHODIMP_(ULONG) -CAssemblyName::AddRef() -{ - return InterlockedIncrement(&_cRef); -} - -// --------------------------------------------------------------------------- -// CAssemblyName::Release -// --------------------------------------------------------------------------- -STDMETHODIMP_(ULONG) -CAssemblyName::Release() -{ - ULONG ulRef = InterlockedDecrement(&_cRef); - if (ulRef == 0) - { - delete this; - } - - return ulRef; -} - -// --------------------------------------------------------------------------- -// CAssemblyName::QueryInterface -// --------------------------------------------------------------------------- -STDMETHODIMP -CAssemblyName::QueryInterface(REFIID riid, void** ppv) -{ - HRESULT hr = S_OK; - - BEGIN_ENTRYPOINT_NOTHROW; - - if (!ppv) - { - hr = E_POINTER; - goto Exit; - } - - if ( IsEqualIID(riid, IID_IUnknown) - || IsEqualIID(riid, IID_IAssemblyName) - ) - { - *ppv = static_cast (this); - AddRef(); - hr = S_OK; - goto Exit; - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - goto Exit; - } - - Exit: - END_ENTRYPOINT_NOTHROW; - - return hr; -} - -// --------------------------------------------------------------------------- -// CAssemblyName::SetProperty -// --------------------------------------------------------------------------- -STDMETHODIMP -CAssemblyName::SetProperty(DWORD PropertyId, - LPCVOID pvProperty, - DWORD cbProperty) -{ - HRESULT hr = S_OK; - - BEGIN_ENTRYPOINT_NOTHROW; - - hr = SetPropertyInternal(PropertyId, pvProperty, cbProperty); - - END_ENTRYPOINT_NOTHROW; - return hr; -} - -// --------------------------------------------------------------------------- -// CAssemblyName::GetProperty -// --------------------------------------------------------------------------- -STDMETHODIMP -CAssemblyName::GetProperty(DWORD PropertyId, - LPVOID pvProperty, LPDWORD pcbProperty) -{ - HRESULT hr = S_OK; - - BEGIN_ENTRYPOINT_NOTHROW; - - // Retrieve the property. - switch(PropertyId) - { - case ASM_NAME_NULL_PUBLIC_KEY_TOKEN: - case ASM_NAME_NULL_PUBLIC_KEY: - { - hr = (_fPublicKeyToken && !_rProp[PropertyId].cb) ? S_OK : S_FALSE; - break; - } - case ASM_NAME_NULL_CUSTOM: - { - hr = (_fCustom && !_rProp[PropertyId].cb) ? S_OK : S_FALSE; - break; - } - default: - { - hr = _rProp.Get(PropertyId, pvProperty, pcbProperty); - break; - } - } - - END_ENTRYPOINT_NOTHROW; - - return hr; -} - -// --------------------------------------------------------------------------- -// CAssemblyName::SetPropertyInternal -// --------------------------------------------------------------------------- -HRESULT CAssemblyName::SetPropertyInternal(DWORD PropertyId, - LPCVOID pvProperty, - DWORD cbProperty) -{ - HRESULT hr = S_OK; - LPBYTE pbSN = NULL; - DWORD cbSN = 0; - - if (PropertyId >= ASM_NAME_MAX_PARAMS - || (!pvProperty && cbProperty)) - { - _ASSERTE(!"Invalid Argument! Passed in NULL buffer with size non-zero!"); - hr = E_INVALIDARG; - goto exit; - } - - // - make this a switch statement. - if (PropertyId == ASM_NAME_MAJOR_VERSION || - PropertyId == ASM_NAME_MINOR_VERSION || - PropertyId == ASM_NAME_BUILD_NUMBER || - PropertyId == ASM_NAME_REVISION_NUMBER) - { - if (cbProperty > sizeof(WORD)) { - hr = E_INVALIDARG; - goto exit; - } - } - - // Check if public key is being set and if so, - // set the public key token if not already set. - if (PropertyId == ASM_NAME_PUBLIC_KEY) - { - // If setting true public key, generate hash. - if (pvProperty && cbProperty) - { - // Generate the public key token from the pk. - if (FAILED(hr = StrongNameTokenFromPublicKey((LPBYTE) pvProperty, cbProperty, &pbSN, &cbSN))) - goto exit; - - // Set the public key token property. - if (FAILED(hr = SetPropertyInternal(ASM_NAME_PUBLIC_KEY_TOKEN, pbSN, cbSN))) - goto exit; - } - // Otherwise expect call to reset property. - else if (!cbProperty) - { - if (FAILED(hr = SetPropertyInternal(ASM_NAME_PUBLIC_KEY_TOKEN, pvProperty, cbProperty))) - goto exit; - } - - } - // Setting NULL public key clears values in public key, - // public key token and sets public key token flag. - else if (PropertyId == ASM_NAME_NULL_PUBLIC_KEY) - { - pvProperty = NULL; - cbProperty = 0; - hr = SetPropertyInternal(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, pvProperty, cbProperty); - goto exit; - } - // Setting or clearing public key token. - else if (PropertyId == ASM_NAME_PUBLIC_KEY_TOKEN) - { - // Defensive: invalid sized public key tokens should be avoided. - if (cbProperty > PUBLIC_KEY_TOKEN_LEN) - { - hr = SetPropertyInternal(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, NULL, 0); - hr = E_INVALIDARG; - goto exit; - } - - if (pvProperty && cbProperty) - _fPublicKeyToken = TRUE; - else if (!cbProperty) - _fPublicKeyToken = FALSE; - } - // Setting NULL public key token clears public key token and - // sets public key token flag. - else if (PropertyId == ASM_NAME_NULL_PUBLIC_KEY_TOKEN) - { - _fPublicKeyToken = TRUE; - pvProperty = NULL; - cbProperty = 0; - PropertyId = ASM_NAME_PUBLIC_KEY_TOKEN; - } - else if (PropertyId == ASM_NAME_CUSTOM) - { - if (pvProperty && cbProperty) - _fCustom = TRUE; - else if (!cbProperty) - _fCustom = FALSE; - } - else if (PropertyId == ASM_NAME_NULL_CUSTOM) - { - _fCustom = TRUE; - pvProperty = NULL; - cbProperty = 0; - PropertyId = ASM_NAME_CUSTOM; - } - - // Setting "neutral" as the culture is the same as "" culture (meaning - // culture-invariant). - else if (PropertyId == ASM_NAME_CULTURE) { - if (pvProperty && !FusionCompareStringI((LPWSTR)pvProperty, W("neutral"))) { - pvProperty = (void *)W(""); - cbProperty = sizeof(W("")); - } - } - - // Set property on array. - hr = _rProp.Set(PropertyId, pvProperty, cbProperty); - -exit: - // Free memory allocated by crypto wrapper. - if (pbSN) { - StrongNameFreeBuffer(pbSN); - } - - return hr; -} - -// --------------------------------------------------------------------------- -// CreateAssemblyNameObject -// --------------------------------------------------------------------------- - -// This is not external for CoreCLR -STDAPI -CreateAssemblyNameObject( - LPASSEMBLYNAME *ppAssemblyName, - LPCOLESTR szAssemblyName) -{ - - HRESULT hr = S_OK; - - BEGIN_ENTRYPOINT_NOTHROW; - - CAssemblyName *pName = NULL; - - if (!ppAssemblyName) - { - hr = E_INVALIDARG; - goto exit; - } - - pName = NEW(CAssemblyName); - if (!pName) - { - hr = E_OUTOFMEMORY; - goto exit; - } - - hr = pName->Parse((LPWSTR)szAssemblyName); - if (FAILED(hr)) - { - SAFERELEASE(pName); - goto exit; - } - - *ppAssemblyName = pName; - -exit: - END_ENTRYPOINT_NOTHROW; - return hr; -} - -// --------------------------------------------------------------------------- -// CAssemblyName constructor -// --------------------------------------------------------------------------- -CAssemblyName::CAssemblyName() -{ - _dwSig = 0x454d414e; /* 'EMAN' */ - _fPublicKeyToken = FALSE; - _fCustom = TRUE; - _cRef = 1; -} - -// --------------------------------------------------------------------------- -// CAssemblyName::Parse -// --------------------------------------------------------------------------- -HRESULT CAssemblyName::Parse(__in_z LPCWSTR szDisplayName) -{ - HRESULT hr = S_OK; - - if (!(szDisplayName && *szDisplayName)) - { - hr = E_INVALIDARG; - goto exit; - } - - EX_TRY { - BINDER_SPACE::AssemblyIdentity assemblyIdentity; - SString displayName(szDisplayName); - - // Parse the textual identity - hr = BINDER_SPACE::TextualIdentityParser::Parse(displayName, &assemblyIdentity); - if (FAILED(hr)) { - goto exit; - } - - // Set name. - hr = SetProperty(ASM_NAME_NAME, - (LPVOID) assemblyIdentity.m_simpleName.GetUnicode(), - (assemblyIdentity.m_simpleName.GetCount() + 1) * sizeof(WCHAR)); - if (FAILED(hr)) { - goto exit; - } - - // Set version. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_VERSION)) { - WORD wVersionPart = 0; - - wVersionPart = (WORD) assemblyIdentity.m_version.GetMajor(); - hr = SetProperty(ASM_NAME_MAJOR_VERSION, &wVersionPart, sizeof(WORD)); - if (FAILED(hr)) { - goto exit; - } - - wVersionPart = (WORD) assemblyIdentity.m_version.GetMinor(); - hr = SetProperty(ASM_NAME_MINOR_VERSION, &wVersionPart, sizeof(WORD)); - if (FAILED(hr)) { - goto exit; - } - - wVersionPart = (WORD) assemblyIdentity.m_version.GetBuild(); - hr = SetProperty(ASM_NAME_BUILD_NUMBER, &wVersionPart, sizeof(WORD)); - if (FAILED(hr)) { - goto exit; - } - - wVersionPart = (WORD) assemblyIdentity.m_version.GetRevision(); - hr = SetProperty(ASM_NAME_REVISION_NUMBER, &wVersionPart, sizeof(WORD)); - if (FAILED(hr)) { - goto exit; - } - } - - // Set culture. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE)) { - hr = SetProperty(ASM_NAME_CULTURE, - (LPVOID) assemblyIdentity.m_cultureOrLanguage.GetUnicode(), - (assemblyIdentity.m_cultureOrLanguage.GetCount()+1) * sizeof(WCHAR)); - if (FAILED(hr)) { - goto exit; - } - } - - // Set public key (token) or NULL flag. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY)) { - SBuffer &publicKeyBuffer = assemblyIdentity.m_publicKeyOrTokenBLOB; - const void *pBytes = publicKeyBuffer; - - // This also computes and sets the public key token. - hr = SetProperty(ASM_NAME_PUBLIC_KEY, (void *) pBytes, publicKeyBuffer.GetSize()); - if (FAILED(hr)) { - goto exit; - } - } - else if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN)) { - SBuffer &publicKeyTokenBuffer = assemblyIdentity.m_publicKeyOrTokenBLOB; - const void *pBytes = publicKeyTokenBuffer; - - hr = SetProperty(ASM_NAME_PUBLIC_KEY_TOKEN, - (LPVOID) pBytes, - publicKeyTokenBuffer.GetSize()); - if (FAILED(hr)) { - goto exit; - } - } - else if (assemblyIdentity. - Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL)) { - hr = SetProperty(ASM_NAME_NULL_PUBLIC_KEY_TOKEN, NULL, 0); - if (FAILED(hr)) { - goto exit; - } - } - - // Set architecture. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE)) { - PEKIND peKind = assemblyIdentity.m_kProcessorArchitecture; - - hr = SetProperty(ASM_NAME_ARCHITECTURE, (LPVOID) &peKind, sizeof(PEKIND)); - if(FAILED(hr)) { - goto exit; - } - } - - // Set retargetable flag. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE)) { - BOOL fRetarget = TRUE; - - if (FAILED(hr = SetProperty(ASM_NAME_RETARGET, &fRetarget, sizeof(BOOL)))) { - goto exit; - } - } - - // Set content type. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE)) { - DWORD dwContentType = assemblyIdentity.m_kContentType; - - hr = SetProperty(ASM_NAME_CONTENT_TYPE, &dwContentType, sizeof(dwContentType)); - IfFailGoto(hr, exit); - } - - // Set custom or NULL flag. - if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CUSTOM)) { - SBuffer &customBuffer = assemblyIdentity.m_customBLOB; - const void *pBytes = customBuffer; - - hr = SetProperty(ASM_NAME_CUSTOM, (void *) pBytes, customBuffer.GetSize()); - if (FAILED(hr)) { - goto exit; - } - } - else if (assemblyIdentity.Have(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CUSTOM_NULL)) { - hr = SetProperty(ASM_NAME_NULL_CUSTOM, NULL, 0); - if (FAILED(hr)) { - goto exit; - } - } - } - EX_CATCH_HRESULT(hr); - - exit: - return hr; -} - -namespace fusion -{ - namespace util - { - namespace priv - { - inline bool IsNullProperty(DWORD dwProperty) - { - LIMITED_METHOD_CONTRACT; - return dwProperty == ASM_NAME_NULL_PUBLIC_KEY_TOKEN || - dwProperty == ASM_NAME_NULL_PUBLIC_KEY || - dwProperty == ASM_NAME_NULL_CUSTOM; - } - } - - // Non-allocating helper. - HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, PVOID pBuf, DWORD *pcbBuf) - { - LIMITED_METHOD_CONTRACT; - HRESULT hr = S_OK; - - _ASSERTE(pName != nullptr && pcbBuf != nullptr); - if (pName == nullptr || pcbBuf == nullptr) - { - return E_INVALIDARG; - } - - hr = pName->GetProperty(dwProperty, pBuf, pcbBuf); - IfFailRet(hr); - - // Zero-length non-null property means there is no value. - if (hr == S_OK && *pcbBuf == 0 && !priv::IsNullProperty(dwProperty)) - { - hr = S_FALSE; - } - - return hr; - } - - // Allocating helper. - HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, PBYTE * ppBuf, DWORD *pcbBuf) - { - LIMITED_METHOD_CONTRACT; - HRESULT hr = S_OK; - - _ASSERTE(ppBuf != nullptr && (*ppBuf == nullptr || pcbBuf != nullptr)); - if (ppBuf == nullptr || (*ppBuf != nullptr && pcbBuf == nullptr)) - { - return E_INVALIDARG; - } - - DWORD cbBuf = 0; - if (pcbBuf == nullptr) - pcbBuf = &cbBuf; - - hr = GetProperty(pName, dwProperty, *ppBuf, pcbBuf); - - // No provided buffer constitutes a request for one to be allocated. - if (*ppBuf == nullptr) - { - // If it's a null property, allocate a single-byte array to provide consistency. - if (hr == S_OK && priv::IsNullProperty(dwProperty)) - { - *ppBuf = new (nothrow) BYTE[1]; - IfNullRet(*ppBuf); - } - // Great, get the value. - else if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) - { - NewArrayHolder pBuf = new (nothrow) BYTE[*pcbBuf]; - IfNullRet(pBuf); - hr = pName->GetProperty(dwProperty, pBuf, pcbBuf); - IfFailRet(hr); - *ppBuf = pBuf.Extract(); - hr = S_OK; - } - } - - return hr; - } - - HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, SString & ssVal) - { - LIMITED_METHOD_CONTRACT; - HRESULT hr = S_OK; - - _ASSERTE(pName != nullptr); - if (pName == nullptr) - { - return E_INVALIDARG; - } - - DWORD cbSize = 0; - hr = GetProperty(pName, dwProperty, static_cast(nullptr), &cbSize); - - if (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)) - { - EX_TRY - { - PWSTR wzNameBuf = ssVal.OpenUnicodeBuffer(cbSize / sizeof(WCHAR) - 1); - hr = GetProperty(pName, dwProperty, reinterpret_cast(wzNameBuf), &cbSize); - ssVal.CloseBuffer(); - IfFailThrow(hr); - ssVal.Normalize(); - } - EX_CATCH_HRESULT(hr); - IfFailRet(hr); - } - - return hr; - } - } -} - diff --git a/src/coreclr/binder/inc/assemblyname.hpp b/src/coreclr/binder/inc/assemblyname.hpp index 1e19a30a8e5ba..8b6b96270d3bb 100644 --- a/src/coreclr/binder/inc/assemblyname.hpp +++ b/src/coreclr/binder/inc/assemblyname.hpp @@ -46,7 +46,6 @@ namespace BINDER_SPACE /* in */ mdAssemblyRef mda = 0, /* in */ BOOL fIsDefinition = TRUE); HRESULT Init(/* in */ SString &assemblyDisplayName); - HRESULT Init(/* in */ IAssemblyName *pIAssemblyName); ULONG AddRef(); ULONG Release(); diff --git a/src/coreclr/binder/inc/bindertypes.hpp b/src/coreclr/binder/inc/bindertypes.hpp index 08159ebc84048..e55dff0167cd4 100644 --- a/src/coreclr/binder/inc/bindertypes.hpp +++ b/src/coreclr/binder/inc/bindertypes.hpp @@ -17,14 +17,6 @@ #include "clrtypes.h" #include "sstring.h" -#include "fusionhelpers.hpp" - -extern void DECLSPEC_NORETURN ThrowOutOfMemory(); - -#ifndef S_TRUE -#define S_TRUE S_OK -#endif - class PEImage; class PEAssembly; @@ -40,10 +32,48 @@ namespace BINDER_SPACE class ApplicationContext; class BindResult; - class FailureCache; - class AssemblyBinder; }; +typedef enum __AssemblyContentType +{ + AssemblyContentType_Default = 0, + AssemblyContentType_WindowsRuntime = 0x1, + AssemblyContentType_Invalid = 0xffffffff, +} AssemblyContentType; + +typedef enum __ASM_DISPLAY_FLAGS +{ + ASM_DISPLAYF_VERSION = 0x1, + ASM_DISPLAYF_CULTURE = 0x2, + ASM_DISPLAYF_PUBLIC_KEY_TOKEN = 0x4, + ASM_DISPLAYF_PUBLIC_KEY = 0x8, + ASM_DISPLAYF_CUSTOM = 0x10, + ASM_DISPLAYF_PROCESSORARCHITECTURE = 0x20, + ASM_DISPLAYF_LANGUAGEID = 0x40, + ASM_DISPLAYF_RETARGET = 0x80, + ASM_DISPLAYF_CONFIG_MASK = 0x100, + ASM_DISPLAYF_MVID = 0x200, + ASM_DISPLAYF_CONTENT_TYPE = 0x400, + ASM_DISPLAYF_FULL = ASM_DISPLAYF_VERSION + | ASM_DISPLAYF_CULTURE + | ASM_DISPLAYF_PUBLIC_KEY_TOKEN + | ASM_DISPLAYF_RETARGET + | ASM_DISPLAYF_PROCESSORARCHITECTURE + | ASM_DISPLAYF_CONTENT_TYPE, +} ASM_DISPLAY_FLAGS; + +typedef enum __PEKIND +{ + peNone = 0x00000000, + peMSIL = 0x00000001, + peI386 = 0x00000002, + peIA64 = 0x00000003, + peAMD64 = 0x00000004, + peARM = 0x00000005, + peARM64 = 0x00000006, + peInvalid = 0xffffffff, +} PEKIND; + #define IF_FAIL_GO(expr) \ hr = (expr); \ if (FAILED(hr)) \ @@ -61,16 +91,6 @@ namespace BINDER_SPACE hr = hrValue; \ goto Exit; -#define IF_WIN32_ERROR_GO(expr) \ - if (!(expr)) \ - { \ - hr = HRESULT_FROM_GetLastError(); \ - goto Exit; \ - } - -#define NEW_CONSTR(Object, Constr) \ - (Object) = new (nothrow) Constr; - #define SAFE_NEW_CONSTR(Object, Constr) \ (Object) = new (nothrow) Constr; \ if ((Object) == NULL) \ diff --git a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h index bfa1594194fc3..51dd63bc6f60d 100644 --- a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h +++ b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h @@ -5,20 +5,11 @@ #ifndef __CLRPRIVBINDERASSEMBLYLOADCONTEXT_H__ #define __CLRPRIVBINDERASSEMBLYLOADCONTEXT_H__ -#include "coreclrbindercommon.h" #include "applicationcontext.hpp" #include "clrprivbindercoreclr.h" #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -namespace BINDER_SPACE -{ - class AssemblyIdentityUTF8; -}; - -class AppDomain; - -class Object; class Assembly; class LoaderAllocator; @@ -29,7 +20,7 @@ class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext //========================================================================= // ICLRPrivBinder functions //------------------------------------------------------------------------- - STDMETHOD(BindAssemblyByName)( + STDMETHOD(BindAssemblyByName)( /* [string][in] */ const WCHAR *pAssemblyFullName, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); @@ -74,7 +65,7 @@ class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext // 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. - // We still keep the weak handle pointing to the same managed AssemblyLoadContext so that native code can use the handle above + // We still keep the weak handle pointing to the same managed AssemblyLoadContext so that native code can use the handle above // to refer to it during the whole lifetime of the AssemblyLoadContext. INT_PTR m_ptrManagedStrongAssemblyLoadContext; diff --git a/src/coreclr/binder/inc/clrprivbindercoreclr.h b/src/coreclr/binder/inc/clrprivbindercoreclr.h index b3640514fdebb..42b57311d4e2d 100644 --- a/src/coreclr/binder/inc/clrprivbindercoreclr.h +++ b/src/coreclr/binder/inc/clrprivbindercoreclr.h @@ -5,15 +5,9 @@ #ifndef __CLR_PRIV_BINDER_CORECLR_H__ #define __CLR_PRIV_BINDER_CORECLR_H__ -#include "coreclrbindercommon.h" #include "applicationcontext.hpp" #include "assemblyloadcontext.h" -namespace BINDER_SPACE -{ - class AssemblyIdentityUTF8; -}; - class CLRPrivBinderCoreCLR : public AssemblyLoadContext { public: diff --git a/src/coreclr/binder/inc/fusionassemblyname.hpp b/src/coreclr/binder/inc/fusionassemblyname.hpp deleted file mode 100644 index d5676c7c1c6f1..0000000000000 --- a/src/coreclr/binder/inc/fusionassemblyname.hpp +++ /dev/null @@ -1,111 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// FusionAssemblyName.hpp -// -// Defines the CAssemblyName class -// -// ============================================================ - -#ifndef __FUSION_ASSEMBLY_NAME_HPP__ -#define __FUSION_ASSEMBLY_NAME_HPP__ - -#include "fusionhelpers.hpp" - -struct FusionProperty -{ - union { - LPVOID pv; - WCHAR* asStr; // For debugging. - }; - DWORD cb; -}; - -class CPropertyArray -{ - friend class CAssemblyName; -private: - DWORD _dwSig; - FusionProperty _rProp[ASM_NAME_MAX_PARAMS]; - -public: - CPropertyArray(); - ~CPropertyArray(); - - inline HRESULT Set(DWORD PropertyId, LPCVOID pvProperty, DWORD cbProperty); - inline HRESULT Get(DWORD PropertyId, LPVOID pvProperty, LPDWORD pcbProperty); - inline FusionProperty operator [] (DWORD dwPropId); -}; - -class CAssemblyName final : public IAssemblyName -{ -private: - DWORD _dwSig; - Volatile _cRef; - CPropertyArray _rProp; - BOOL _fPublicKeyToken; - BOOL _fCustom; - -public: - // IUnknown methods - STDMETHODIMP QueryInterface(REFIID riid,void ** ppv); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); - - // IAssemblyName methods - STDMETHOD(SetProperty)( - /* in */ DWORD PropertyId, - /* in */ LPCVOID pvProperty, - /* in */ DWORD cbProperty); - - STDMETHOD(GetProperty)( - /* in */ DWORD PropertyId, - /* out */ LPVOID pvProperty, - /* in out */ LPDWORD pcbProperty); - - HRESULT SetPropertyInternal(/* in */ DWORD PropertyId, - /* in */ LPCVOID pvProperty, - /* in */ DWORD cbProperty); - - CAssemblyName(); - - HRESULT Parse(LPCWSTR szDisplayName); -}; - -STDAPI -CreateAssemblyNameObject( - LPASSEMBLYNAME *ppAssemblyName, - LPCOLESTR szAssemblyName); - -namespace fusion -{ - namespace util - { - // Fills the provided buffer with the contents of the property. pcbBuf is - // set to be either the required buffer space when insufficient buffer is - // provided, or the number of bytes written. - // - // Returns S_FALSE if the property has not been set, regardless of the values of pBuf and pcbBuf. - HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, PVOID pBuf, DWORD *pcbBuf); - - // Fills the provided buffer with the contents of the property. If no buffer is provided - // (*ppBuf == nullptr), then a buffer is allocated for the caller and ppBuf is set to point - // at the allocated buffer on return. pcbBuf is set to be either the required buffer space - // when insufficient buffer is provided, or the number of bytes written. - // - // Returns S_FALSE if the property has not been set, regardless of the values of pBuf and pcbBuf. - HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, PBYTE * ppBuf, DWORD *pcbBuf); - - // Fills the provided SString with the contents of the property. - // - // Returns S_FALSE if the property has not been set. - HRESULT GetProperty(IAssemblyName * pName, DWORD dwProperty, SString & ssVal); - - inline HRESULT GetSimpleName(IAssemblyName * pName, SString & ssName) - { return GetProperty(pName, ASM_NAME_NAME, ssName); } - } // namespace fusion.util -} // namespace fusion - - -#endif diff --git a/src/coreclr/binder/inc/fusionhelpers.hpp b/src/coreclr/binder/inc/fusionhelpers.hpp deleted file mode 100644 index e3e31af840677..0000000000000 --- a/src/coreclr/binder/inc/fusionhelpers.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// FusionHelpers.hpp -// -// Defines various legacy fusion types -// -// ============================================================ - -#ifndef __FUSION_HELPERS_HPP__ -#define __FUSION_HELPERS_HPP__ - -#include "clrtypes.h" -#include "sstring.h" - -#include "clrhost.h" -#include "shlwapi.h" -#include "winwrap.h" -#include "ex.h" -#include "fusion.h" - - -#include "peinformation.h" - -#define FUSION_NEW_SINGLETON(_type) new (nothrow) _type -#define FUSION_NEW_ARRAY(_type, _n) new (nothrow) _type[_n] -#define FUSION_DELETE_ARRAY(_ptr) if((_ptr)) delete [] (_ptr) -#define FUSION_DELETE_SINGLETON(_ptr) if((_ptr)) delete (_ptr) - -#define SAFEDELETE(p) if ((p) != NULL) { FUSION_DELETE_SINGLETON((p)); (p) = NULL; }; -#define SAFEDELETEARRAY(p) if ((p) != NULL) { FUSION_DELETE_ARRAY((p)); (p) = NULL; }; -#define SAFERELEASE(p) if ((p) != NULL) { (p)->Release(); (p) = NULL; }; - -#ifndef NEW -#define NEW(_type) FUSION_NEW_SINGLETON(_type) -#endif // !NEW - -#ifndef ARRAYSIZE -#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) -#endif // !ARRAYSIZE - -#define MAX_VERSION_DISPLAY_SIZE sizeof("65535.65535.65535.65535") - -#define ASM_DISPLAYF_DEFAULT (ASM_DISPLAYF_VERSION \ - |ASM_DISPLAYF_CULTURE \ - |ASM_DISPLAYF_PUBLIC_KEY_TOKEN \ - |ASM_DISPLAYF_RETARGET) - -#define SIGNATURE_BLOB_LENGTH 0x80 -#define SIGNATURE_BLOB_LENGTH_HASH 0x14 -#define MVID_LENGTH sizeof(GUID) - -#define PUBLIC_KEY_TOKEN_LEN 8 - -#define MAX_URL_LENGTH 2084 // same as INTERNET_MAX_URL_LENGTH - -// bit mask macro helpers -#define MAX_ID_FROM_MASK(size) ((size) << 3) -#define MASK_SIZE_FROM_ID(id) ((id) >> 3) -#define IS_IN_RANGE(id, size) ((id) <= ((size) << 3)) -#define IS_BIT_SET(id, mask) (mask[((id)-1)>>3] & (0x1 << (((id)-1)&0x7))) -#define SET_BIT(id, mask) (mask[((id)-1)>>3] |= (0x1<< (((id)-1)&0x7))) -#define UNSET_BIT(id, mask) (mask[((id)-1)>>3] &= (0xFF - (0x1<<(((id)-1)&0x7)))) - -inline -int FusionCompareStringI(LPCWSTR pwz1, LPCWSTR pwz2) -{ - return SString::_wcsicmp(pwz1, pwz2); -} - -#endif diff --git a/src/coreclr/ilasm/asmman.cpp b/src/coreclr/ilasm/asmman.cpp index 63d9b3694bace..87e79e51988bf 100644 --- a/src/coreclr/ilasm/asmman.cpp +++ b/src/coreclr/ilasm/asmman.cpp @@ -10,7 +10,6 @@ #include "assembler.h" #include "strongnameinternal.h" #include -#include extern WCHAR* pwzInputFiles[]; diff --git a/src/coreclr/inc/corpriv.h b/src/coreclr/inc/corpriv.h index 495440c93fccb..e480706e3d553 100644 --- a/src/coreclr/inc/corpriv.h +++ b/src/coreclr/inc/corpriv.h @@ -19,7 +19,6 @@ #include "corimage.h" #include "metadata.h" #include -#include "peinformation.h" // interface IAssemblyName; diff --git a/src/coreclr/inc/fusion.idl b/src/coreclr/inc/fusion.idl deleted file mode 100644 index 7ffa9837bbd47..0000000000000 --- a/src/coreclr/inc/fusion.idl +++ /dev/null @@ -1,137 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -//+--------------------------------------------------------------------------- -// -// Microsoft Windows -// File: fusion.idl -// -// Contents: Fusion Interfaces -// -// Classes: -// -// Functions: -// -// -//---------------------------------------------------------------------------- - -cpp_quote("") -cpp_quote("#ifdef _MSC_VER") -cpp_quote("#pragma comment(lib,\"uuid.lib\")") -cpp_quote("#endif") -cpp_quote("") -cpp_quote("//---------------------------------------------------------------------------=") -cpp_quote("// Fusion Interfaces.") -cpp_quote("") - -import "objidl.idl"; - -cpp_quote("#ifdef _MSC_VER") -cpp_quote("#pragma once") -cpp_quote("#endif") - - -typedef enum _tagAssemblyContentType -{ - AssemblyContentType_Default = 0x00000000, - AssemblyContentType_WindowsRuntime = 0x00000001, - AssemblyContentType_Invalid = 0xffffffff -} AssemblyContentType; - - -/////////////////////////////////////////////////////////////////////////////// -// -// IAssemblyName -// -/////////////////////////////////////////////////////////////////////////////// - -cpp_quote("// {CD193BC0-B4BC-11d2-9833-00C04FC31D2E}") -cpp_quote("EXTERN_GUID(IID_IAssemblyName, 0xCD193BC0, 0xB4BC, 0x11d2, 0x98, 0x33, 0x00, 0xC0, 0x4F, 0xC3, 0x1D, 0x2E);") - - -[ - local, - object, - uuid(CD193BC0-B4BC-11d2-9833-00C04FC31D2E), - pointer_default(unique) -] -interface IAssemblyName: IUnknown -{ - typedef [unique] IAssemblyName *LPASSEMBLYNAME; - - typedef enum - { - ASM_NAME_PUBLIC_KEY = 0, // 0 - ASM_NAME_PUBLIC_KEY_TOKEN, // 1 - ASM_NAME_HASH_VALUE, // 2 - ASM_NAME_NAME, // 3 - ASM_NAME_MAJOR_VERSION, // 4 - ASM_NAME_MINOR_VERSION, // 5 - ASM_NAME_BUILD_NUMBER, // 6 - ASM_NAME_REVISION_NUMBER, // 7 - ASM_NAME_CULTURE, // 8 - ASM_NAME_PROCESSOR_ID_ARRAY, // 9 - ASM_NAME_OSINFO_ARRAY, // 10 ... 0x0a - ASM_NAME_HASH_ALGID, // 11 ... 0x0b - ASM_NAME_ALIAS, // 12 ... 0x0c - ASM_NAME_CODEBASE_URL, // 13 ... 0x0d - ASM_NAME_CODEBASE_LASTMOD, // 14 ... 0x0e - ASM_NAME_NULL_PUBLIC_KEY, // 15 ... 0x0f - ASM_NAME_NULL_PUBLIC_KEY_TOKEN, // 16 ... 0x10 - ASM_NAME_CUSTOM, // 17 ... 0x11 - ASM_NAME_NULL_CUSTOM, // 18 ... 0x12 - ASM_NAME_MVID, // 19 ... 0x13 - ASM_NAME_FILE_MAJOR_VERSION, // 20 ... 0x14 - ASM_NAME_FILE_MINOR_VERSION, // 21 ... 0x15 - ASM_NAME_FILE_BUILD_NUMBER, // 22 ... 0x16 - ASM_NAME_FILE_REVISION_NUMBER, // 23 ... 0x17 - ASM_NAME_RETARGET, // 24 ... 0x18 - ASM_NAME_SIGNATURE_BLOB, // 25 ... 0x19 - ASM_NAME_CONFIG_MASK, // 26 ... 0x1a - ASM_NAME_ARCHITECTURE, // 27 ... 0x1b - ASM_NAME_CONTENT_TYPE, // 28 ... 0x1c - ASM_NAME_MAX_PARAMS // 29 ... 0x1d - } ASM_NAME; - - typedef enum - { - ASM_DISPLAYF_VERSION = 0x1, - ASM_DISPLAYF_CULTURE = 0x2, - ASM_DISPLAYF_PUBLIC_KEY_TOKEN = 0x4, - ASM_DISPLAYF_PUBLIC_KEY = 0x8, - ASM_DISPLAYF_CUSTOM = 0x10, - ASM_DISPLAYF_PROCESSORARCHITECTURE = 0x20, - ASM_DISPLAYF_LANGUAGEID = 0x40, - ASM_DISPLAYF_RETARGET = 0x80, - ASM_DISPLAYF_CONFIG_MASK = 0x100, - ASM_DISPLAYF_MVID = 0x200, - ASM_DISPLAYF_CONTENT_TYPE = 0x400, - - - // ASM_DISPLAYF_FULL shows the full identity of the assembly. - // It should be used when you are working with APIs taking - // assembly full identity, such as GAC APIs. - // - // WARNING!!! ASM_DISPLAYF_FULL will change in the future, - // when we introduce new attributes. This means the identity returned - // will change from CLR version to version. Don't ever assume - // the identity will not change. !!! - ASM_DISPLAYF_FULL = ASM_DISPLAYF_VERSION - | ASM_DISPLAYF_CULTURE - | ASM_DISPLAYF_PUBLIC_KEY_TOKEN - | ASM_DISPLAYF_RETARGET - | ASM_DISPLAYF_PROCESSORARCHITECTURE - | ASM_DISPLAYF_CONTENT_TYPE, - } ASM_DISPLAY_FLAGS; - - HRESULT SetProperty( - [in] DWORD PropertyId, - [in] void const * pvProperty, - [in] DWORD cbProperty); - - HRESULT GetProperty( - [in] DWORD PropertyId, - [out] LPVOID pvProperty, - [in, out] LPDWORD pcbProperty); -} - diff --git a/src/coreclr/inc/peinformation.h b/src/coreclr/inc/peinformation.h deleted file mode 100644 index 48039fd9fe175..0000000000000 --- a/src/coreclr/inc/peinformation.h +++ /dev/null @@ -1,74 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// -------------------------------------------------------------------------------- -// PEInformation.h -// - -// -------------------------------------------------------------------------------- - -#ifndef PEINFORMATION_H -#define PEINFORMATION_H - -#ifndef PEKIND_ENUM_DEFINED -#define PEKIND_ENUM_DEFINED -// This must match the definition of pekind in fusion.idl -typedef enum _tagPEKIND -{ - peNone = 0x00000000, - peMSIL = 0x00000001, - peI386 = 0x00000002, - peIA64 = 0x00000003, - peAMD64 = 0x00000004, - peARM = 0x00000005, - peARM64 = 0x00000006, - peInvalid = 0xffffffff -} PEKIND; - -#endif - - -inline bool IsPE64(PEKIND x) -{ - return ( (x == peIA64) || (x == peAMD64) || (x == peARM64) ); -} - -inline bool IsPE32(PEKIND x) -{ - return ( (x == peI386) || (x == peARM) ); -} - -inline bool IsPEMSIL(PEKIND x) -{ - return ( (x == peMSIL) ); -} - -#ifdef HOST_64BIT -inline bool IsProcess32() { return false; } -#else -inline bool IsProcess32() { return true; } -#endif - -#if defined(TARGET_X86) -inline PEKIND TargetNativePEKIND() { return peI386; } -#elif defined(TARGET_AMD64) -inline PEKIND TargetNativePEKIND() { return peAMD64; } -#elif defined(TARGET_ARM) -inline PEKIND TargetNativePEKIND() { return peARM; } -#elif defined(TARGET_ARM64) -inline PEKIND TargetNativePEKIND() { return peARM64; } -#else -#error Need to define valid TargetNativePEKIND() -#endif - -STDAPI RuntimeIsValidAssemblyOnThisPlatform_CheckProcessorArchitecture(PEKIND processorArchitecture, BOOL bForInstall); - -//***************************************************************************** -// Intreprets CLRPeKind and dwImageType to get PeKind as per the CLRBitness -// API, CLRPeKind and dwImageType can be recoved from GetPEKind() if you -// have the metadata, or retrieved directly from the headers as per the -// implementation in shim.cpp:_CorValidateImage. -//***************************************************************************** -HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, PEKIND * PeKind); -HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DWORD dwAssemblyFlags, PEKIND * PeKind); - -#endif // PEINFORMATION_H diff --git a/src/coreclr/pal/prebuilt/inc/fusion.h b/src/coreclr/pal/prebuilt/inc/fusion.h deleted file mode 100644 index 3129a9b1bc44e..0000000000000 --- a/src/coreclr/pal/prebuilt/inc/fusion.h +++ /dev/null @@ -1,247 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - - - -/* this ALWAYS GENERATED file contains the definitions for the interfaces */ - - - /* File created by MIDL compiler version 8.01.0622 */ -/* @@MIDL_FILE_HEADING( ) */ - -#pragma warning( disable: 4049 ) /* more than 64k source lines */ - - -/* verify that the version is high enough to compile this file*/ -#ifndef __REQUIRED_RPCNDR_H_VERSION__ -#define __REQUIRED_RPCNDR_H_VERSION__ 475 -#endif - -#include "rpc.h" -#include "rpcndr.h" - -#ifndef __RPCNDR_H_VERSION__ -#error this stub requires an updated version of -#endif /* __RPCNDR_H_VERSION__ */ - -#ifndef COM_NO_WINDOWS_H -#include "windows.h" -#include "ole2.h" -#endif /*COM_NO_WINDOWS_H*/ - -#ifndef __fusion_h__ -#define __fusion_h__ - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -#pragma once -#endif - -/* Forward Declarations */ - -#ifndef __IAssemblyName_FWD_DEFINED__ -#define __IAssemblyName_FWD_DEFINED__ -typedef interface IAssemblyName IAssemblyName; - -#endif /* __IAssemblyName_FWD_DEFINED__ */ - - -/* header files for imported files */ -#include "objidl.h" - -#ifdef __cplusplus -extern "C"{ -#endif - - -/* interface __MIDL_itf_fusion_0000_0000 */ -/* [local] */ - - -#ifdef _MSC_VER -#pragma comment(lib,"uuid.lib") -#endif - -//---------------------------------------------------------------------------= -// Fusion Interfaces. - -#ifdef _MSC_VER -#pragma once -#endif -typedef -enum _tagAssemblyContentType - { - AssemblyContentType_Default = 0, - AssemblyContentType_WindowsRuntime = 0x1, - AssemblyContentType_Invalid = 0xffffffff - } AssemblyContentType; - -// {CD193BC0-B4BC-11d2-9833-00C04FC31D2E} -EXTERN_GUID(IID_IAssemblyName, 0xCD193BC0, 0xB4BC, 0x11d2, 0x98, 0x33, 0x00, 0xC0, 0x4F, 0xC3, 0x1D, 0x2E); - - -extern RPC_IF_HANDLE __MIDL_itf_fusion_0000_0000_v0_0_c_ifspec; -extern RPC_IF_HANDLE __MIDL_itf_fusion_0000_0000_v0_0_s_ifspec; - -#ifndef __IAssemblyName_INTERFACE_DEFINED__ -#define __IAssemblyName_INTERFACE_DEFINED__ - -/* interface IAssemblyName */ -/* [unique][uuid][object][local] */ - -typedef /* [unique] */ IAssemblyName *LPASSEMBLYNAME; - -typedef /* [public] */ -enum __MIDL_IAssemblyName_0001 - { - ASM_NAME_PUBLIC_KEY = 0, - ASM_NAME_PUBLIC_KEY_TOKEN = ( ASM_NAME_PUBLIC_KEY + 1 ) , - ASM_NAME_HASH_VALUE = ( ASM_NAME_PUBLIC_KEY_TOKEN + 1 ) , - ASM_NAME_NAME = ( ASM_NAME_HASH_VALUE + 1 ) , - ASM_NAME_MAJOR_VERSION = ( ASM_NAME_NAME + 1 ) , - ASM_NAME_MINOR_VERSION = ( ASM_NAME_MAJOR_VERSION + 1 ) , - ASM_NAME_BUILD_NUMBER = ( ASM_NAME_MINOR_VERSION + 1 ) , - ASM_NAME_REVISION_NUMBER = ( ASM_NAME_BUILD_NUMBER + 1 ) , - ASM_NAME_CULTURE = ( ASM_NAME_REVISION_NUMBER + 1 ) , - ASM_NAME_PROCESSOR_ID_ARRAY = ( ASM_NAME_CULTURE + 1 ) , - ASM_NAME_OSINFO_ARRAY = ( ASM_NAME_PROCESSOR_ID_ARRAY + 1 ) , - ASM_NAME_HASH_ALGID = ( ASM_NAME_OSINFO_ARRAY + 1 ) , - ASM_NAME_ALIAS = ( ASM_NAME_HASH_ALGID + 1 ) , - ASM_NAME_CODEBASE_URL = ( ASM_NAME_ALIAS + 1 ) , - ASM_NAME_CODEBASE_LASTMOD = ( ASM_NAME_CODEBASE_URL + 1 ) , - ASM_NAME_NULL_PUBLIC_KEY = ( ASM_NAME_CODEBASE_LASTMOD + 1 ) , - ASM_NAME_NULL_PUBLIC_KEY_TOKEN = ( ASM_NAME_NULL_PUBLIC_KEY + 1 ) , - ASM_NAME_CUSTOM = ( ASM_NAME_NULL_PUBLIC_KEY_TOKEN + 1 ) , - ASM_NAME_NULL_CUSTOM = ( ASM_NAME_CUSTOM + 1 ) , - ASM_NAME_MVID = ( ASM_NAME_NULL_CUSTOM + 1 ) , - ASM_NAME_FILE_MAJOR_VERSION = ( ASM_NAME_MVID + 1 ) , - ASM_NAME_FILE_MINOR_VERSION = ( ASM_NAME_FILE_MAJOR_VERSION + 1 ) , - ASM_NAME_FILE_BUILD_NUMBER = ( ASM_NAME_FILE_MINOR_VERSION + 1 ) , - ASM_NAME_FILE_REVISION_NUMBER = ( ASM_NAME_FILE_BUILD_NUMBER + 1 ) , - ASM_NAME_RETARGET = ( ASM_NAME_FILE_REVISION_NUMBER + 1 ) , - ASM_NAME_SIGNATURE_BLOB = ( ASM_NAME_RETARGET + 1 ) , - ASM_NAME_CONFIG_MASK = ( ASM_NAME_SIGNATURE_BLOB + 1 ) , - ASM_NAME_ARCHITECTURE = ( ASM_NAME_CONFIG_MASK + 1 ) , - ASM_NAME_CONTENT_TYPE = ( ASM_NAME_ARCHITECTURE + 1 ) , - ASM_NAME_MAX_PARAMS = ( ASM_NAME_CONTENT_TYPE + 1 ) - } ASM_NAME; - -typedef /* [public] */ -enum __MIDL_IAssemblyName_0002 - { - ASM_DISPLAYF_VERSION = 0x1, - ASM_DISPLAYF_CULTURE = 0x2, - ASM_DISPLAYF_PUBLIC_KEY_TOKEN = 0x4, - ASM_DISPLAYF_PUBLIC_KEY = 0x8, - ASM_DISPLAYF_CUSTOM = 0x10, - ASM_DISPLAYF_PROCESSORARCHITECTURE = 0x20, - ASM_DISPLAYF_LANGUAGEID = 0x40, - ASM_DISPLAYF_RETARGET = 0x80, - ASM_DISPLAYF_CONFIG_MASK = 0x100, - ASM_DISPLAYF_MVID = 0x200, - ASM_DISPLAYF_CONTENT_TYPE = 0x400, - ASM_DISPLAYF_FULL = ( ( ( ( ( ASM_DISPLAYF_VERSION | ASM_DISPLAYF_CULTURE ) | ASM_DISPLAYF_PUBLIC_KEY_TOKEN ) | ASM_DISPLAYF_RETARGET ) | ASM_DISPLAYF_PROCESSORARCHITECTURE ) | ASM_DISPLAYF_CONTENT_TYPE ) - } ASM_DISPLAY_FLAGS; - - -EXTERN_C const IID IID_IAssemblyName; - -#if defined(__cplusplus) && !defined(CINTERFACE) - - MIDL_INTERFACE("CD193BC0-B4BC-11d2-9833-00C04FC31D2E") - IAssemblyName : public IUnknown - { - public: - virtual HRESULT STDMETHODCALLTYPE SetProperty( - /* [in] */ DWORD PropertyId, - /* [in] */ const void *pvProperty, - /* [in] */ DWORD cbProperty) = 0; - - virtual HRESULT STDMETHODCALLTYPE GetProperty( - /* [in] */ DWORD PropertyId, - /* [out] */ LPVOID pvProperty, - /* [out][in] */ LPDWORD pcbProperty) = 0; - - }; - - -#else /* C style interface */ - - typedef struct IAssemblyNameVtbl - { - BEGIN_INTERFACE - - HRESULT ( STDMETHODCALLTYPE *QueryInterface )( - IAssemblyName * This, - /* [in] */ REFIID riid, - /* [annotation][iid_is][out] */ - _COM_Outptr_ void **ppvObject); - - ULONG ( STDMETHODCALLTYPE *AddRef )( - IAssemblyName * This); - - ULONG ( STDMETHODCALLTYPE *Release )( - IAssemblyName * This); - - HRESULT ( STDMETHODCALLTYPE *SetProperty )( - IAssemblyName * This, - /* [in] */ DWORD PropertyId, - /* [in] */ const void *pvProperty, - /* [in] */ DWORD cbProperty); - - HRESULT ( STDMETHODCALLTYPE *GetProperty )( - IAssemblyName * This, - /* [in] */ DWORD PropertyId, - /* [out] */ LPVOID pvProperty, - /* [out][in] */ LPDWORD pcbProperty); - - END_INTERFACE - } IAssemblyNameVtbl; - - interface IAssemblyName - { - CONST_VTBL struct IAssemblyNameVtbl *lpVtbl; - }; - - - -#ifdef COBJMACROS - - -#define IAssemblyName_QueryInterface(This,riid,ppvObject) \ - ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) - -#define IAssemblyName_AddRef(This) \ - ( (This)->lpVtbl -> AddRef(This) ) - -#define IAssemblyName_Release(This) \ - ( (This)->lpVtbl -> Release(This) ) - - -#define IAssemblyName_SetProperty(This,PropertyId,pvProperty,cbProperty) \ - ( (This)->lpVtbl -> SetProperty(This,PropertyId,pvProperty,cbProperty) ) - -#define IAssemblyName_GetProperty(This,PropertyId,pvProperty,pcbProperty) \ - ( (This)->lpVtbl -> GetProperty(This,PropertyId,pvProperty,pcbProperty) ) - -#endif /* COBJMACROS */ - - -#endif /* C style interface */ - - - - -#endif /* __IAssemblyName_INTERFACE_DEFINED__ */ - - -/* Additional Prototypes for ALL interfaces */ - -/* end of Additional Prototypes */ - -#ifdef __cplusplus -} -#endif - -#endif - - diff --git a/src/coreclr/utilcode/CMakeLists.txt b/src/coreclr/utilcode/CMakeLists.txt index 0f9606d93535a..af1187a59b2aa 100644 --- a/src/coreclr/utilcode/CMakeLists.txt +++ b/src/coreclr/utilcode/CMakeLists.txt @@ -20,7 +20,6 @@ set(UTILCODE_COMMON_SOURCES stgpooli.cpp stgpoolreadonly.cpp utsem.cpp - peinformation.cpp check.cpp log.cpp arraylist.cpp diff --git a/src/coreclr/utilcode/peinformation.cpp b/src/coreclr/utilcode/peinformation.cpp deleted file mode 100644 index 78e41b11196d6..0000000000000 --- a/src/coreclr/utilcode/peinformation.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// -------------------------------------------------------------------------------- -// PEInformation.cpp -// - -// -------------------------------------------------------------------------------- - -#include "stdafx.h" -#include "utilcode.h" -#include "peinformation.h" - - -HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, PEKIND * pPeKind) -{ - return TranslatePEToArchitectureType(CLRPeKind, dwImageType, 0, pPeKind); -} - -HRESULT TranslatePEToArchitectureType(CorPEKind CLRPeKind, DWORD dwImageType, DWORD dwAssemblyFlags, PEKIND * pPeKind) -{ - HRESULT hr = S_OK; - - _ASSERTE(pPeKind != NULL); - - if (CLRPeKind == peNot) - { // Not a PE. Shouldn't ever get here. - *pPeKind = peInvalid; - hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); - goto Exit; - } - else if (IsAfPA_NoPlatform(dwAssemblyFlags)) - { - *pPeKind = peNone; - goto Exit; - } - else - { - if ((CLRPeKind & peILonly) && - !(CLRPeKind & pe32Plus) && - !(CLRPeKind & pe32BitRequired) && - (dwImageType == IMAGE_FILE_MACHINE_I386)) - { - // Processor-agnostic (MSIL) - *pPeKind = peMSIL; - } - else if (CLRPeKind & pe32Plus) - { - // 64-bit - - if (CLRPeKind & pe32BitRequired) - { - *pPeKind = peInvalid; - hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); - goto Exit; - } - - // Regardless of whether ILONLY is set or not, the architecture - // is the machine type. - - if (dwImageType == IMAGE_FILE_MACHINE_IA64) - { - *pPeKind = peIA64; - } - else if (dwImageType == IMAGE_FILE_MACHINE_AMD64) - { - *pPeKind = peAMD64; - } - else - { // We don't support other architectures - *pPeKind = peInvalid; - hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); - goto Exit; - } - } - else - { - // 32-bit, non-agnostic - - if (dwImageType == IMAGE_FILE_MACHINE_I386) - { - *pPeKind = peI386; - } - else if (dwImageType == IMAGE_FILE_MACHINE_ARMNT) - { - *pPeKind = peARM; - } - else - { // Not supported - *pPeKind = peInvalid; - hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT); - goto Exit; - } - } - } - -Exit: - return hr; -} diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 976a036d61b6e..72634148ebaaf 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -67,6 +67,7 @@ #include "../binder/inc/bindertracing.h" #include "../binder/inc/clrprivbindercoreclr.h" +#include "../binder/inc/coreclrbindercommon.h" // this file handles string conversion errors for itself #undef MAKE_TRANSLATIONFAILED diff --git a/src/coreclr/vm/assemblyloadcontext.h b/src/coreclr/vm/assemblyloadcontext.h index cf6c05ad8e7af..1ecdd0446d29a 100644 --- a/src/coreclr/vm/assemblyloadcontext.h +++ b/src/coreclr/vm/assemblyloadcontext.h @@ -5,8 +5,10 @@ #define _ASSEMBLYLOADCONTEXT_H #include "crst.h" +#include #include + class NativeImage; class Module; class Assembly; diff --git a/src/coreclr/vm/baseassemblyspec.cpp b/src/coreclr/vm/baseassemblyspec.cpp index 5a0b0c3e9240b..bab0fe7fa7776 100644 --- a/src/coreclr/vm/baseassemblyspec.cpp +++ b/src/coreclr/vm/baseassemblyspec.cpp @@ -13,8 +13,6 @@ #include "common.h" #include "thekey.h" -#include "../binder/inc/fusionassemblyname.hpp" - #include "strongnameinternal.h" #include "strongnameholders.h" diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index a7a7616f84339..c777eeef87562 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -17,7 +17,6 @@ #include "peimagelayout.inl" #include "domainfile.h" #include "holder.h" -#include "../binder/inc/assemblybinder.hpp" #include "bundle.h" #include "strongnameinternal.h" #include "strongnameholders.h" @@ -26,12 +25,10 @@ #include "compile.h" #endif - #include "../binder/inc/textualidentityparser.hpp" #include "../binder/inc/assemblyidentity.hpp" #include "../binder/inc/assembly.hpp" #include "../binder/inc/assemblyname.hpp" -#include "../binder/inc/fusionassemblyname.hpp" #include "../binder/inc/coreclrbindercommon.h" #include "../binder/inc/applicationcontext.hpp" From 5e790f3306b45dc02298206719f41f5393ff3e35 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Sun, 4 Apr 2021 18:45:41 -0700 Subject: [PATCH 3/8] Remove CCoreCLRBinderHelper::Init --- src/coreclr/binder/CMakeLists.txt | 2 - src/coreclr/binder/applicationcontext.cpp | 1 - src/coreclr/binder/assemblybinder.cpp | 43 ++-------------- src/coreclr/binder/assemblyname.cpp | 13 +++-- src/coreclr/binder/clrprivbindercoreclr.cpp | 1 - src/coreclr/binder/coreclrbindercommon.cpp | 11 ----- src/coreclr/binder/inc/assemblybinder.hpp | 6 +-- src/coreclr/binder/inc/bindertypes.hpp | 3 -- .../inc/clrprivbinderassemblyloadcontext.h | 2 +- src/coreclr/binder/inc/clrprivbindercoreclr.h | 3 ++ src/coreclr/binder/inc/coreclrbindercommon.h | 6 +-- src/coreclr/binder/inc/variables.hpp | 40 --------------- src/coreclr/binder/variables.cpp | 49 ------------------- src/coreclr/vm/ceemain.cpp | 6 --- 14 files changed, 21 insertions(+), 165 deletions(-) delete mode 100644 src/coreclr/binder/inc/variables.hpp delete mode 100644 src/coreclr/binder/variables.cpp diff --git a/src/coreclr/binder/CMakeLists.txt b/src/coreclr/binder/CMakeLists.txt index 221f80defeb37..f04c647f88f4b 100644 --- a/src/coreclr/binder/CMakeLists.txt +++ b/src/coreclr/binder/CMakeLists.txt @@ -16,7 +16,6 @@ set(BINDER_COMMON_SOURCES stringlexer.cpp textualidentityparser.cpp utils.cpp - variables.cpp ) set(BINDER_COMMON_HEADERS @@ -47,7 +46,6 @@ set(BINDER_COMMON_HEADERS inc/stringlexer.inl inc/textualidentityparser.hpp inc/utils.hpp - inc/variables.hpp ) set(BINDER_SOURCES diff --git a/src/coreclr/binder/applicationcontext.cpp b/src/coreclr/binder/applicationcontext.cpp index f865b4240490d..dd02857652b2f 100644 --- a/src/coreclr/binder/applicationcontext.cpp +++ b/src/coreclr/binder/applicationcontext.cpp @@ -17,7 +17,6 @@ #include "failurecache.hpp" #include "assemblyidentitycache.hpp" #include "utils.hpp" -#include "variables.hpp" #include "ex.h" #include "clr/fs/path.h" using namespace clr::fs; diff --git a/src/coreclr/binder/assemblybinder.cpp b/src/coreclr/binder/assemblybinder.cpp index 75e91471fe626..e69063264280e 100644 --- a/src/coreclr/binder/assemblybinder.cpp +++ b/src/coreclr/binder/assemblybinder.cpp @@ -20,19 +20,13 @@ #include "bindresult.inl" #include "failurecache.hpp" #include "utils.hpp" -#include "variables.hpp" #include "stringarraylist.h" #include "configuration.h" -#define APP_DOMAIN_LOCKED_UNLOCKED 0x02 -#define APP_DOMAIN_LOCKED_CONTEXT 0x04 - #ifndef IMAGE_FILE_MACHINE_ARM64 #define IMAGE_FILE_MACHINE_ARM64 0xAA64 // ARM64 Little-Endian #endif -BOOL IsCompilationProcess(); - #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) #include "clrprivbindercoreclr.h" #include "clrprivbinderassemblyloadcontext.h" @@ -113,12 +107,13 @@ namespace BINDER_SPACE return true; } + const WCHAR* s_httpURLPrefix = W("http://"); HRESULT URLToFullPath(PathString &assemblyPath) { HRESULT hr = S_OK; SString::Iterator pos = assemblyPath.Begin(); - if (assemblyPath.MatchCaseInsensitive(pos, g_BinderVariables->httpURLPrefix)) + if (assemblyPath.MatchCaseInsensitive(pos, s_httpURLPrefix)) { // HTTP downloads are unsupported hr = FUSION_E_CODE_DOWNLOAD_DISABLED; @@ -187,23 +182,6 @@ namespace BINDER_SPACE #endif // !CROSSGEN_COMPILE }; - /* static */ - HRESULT AssemblyBinder::Startup() - { - STATIC_CONTRACT_NOTHROW; - - HRESULT hr = S_OK; - - // This should only be called once - _ASSERTE(g_BinderVariables == NULL); - g_BinderVariables = new Variables(); - IF_FAIL_GO(g_BinderVariables->Init()); - - Exit: - return hr; - } - - HRESULT AssemblyBinder::TranslatePEToArchitectureType(DWORD *pdwPAFlags, PEKIND *PeKind) { HRESULT hr = S_OK; @@ -373,9 +351,6 @@ namespace BINDER_SPACE Assembly **ppSystemAssembly, bool fBindToNativeImage) { - // Indirect check that binder was initialized. - _ASSERTE(g_BinderVariables != NULL); - HRESULT hr = S_OK; _ASSERTE(ppSystemAssembly != NULL); @@ -469,9 +444,6 @@ namespace BINDER_SPACE SString& cultureName, Assembly** ppSystemAssembly) { - // Indirect check that binder was initialized. - _ASSERTE(g_BinderVariables != NULL); - HRESULT hr = S_OK; _ASSERTE(ppSystemAssembly != NULL); @@ -782,8 +754,7 @@ namespace BINDER_SPACE if (!tpaListAssembly) { - SString &culture = pRequestedAssemblyName->GetCulture(); - if (culture.IsEmpty() || culture.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral)) + if (pRequestedAssemblyName->IsNeutralCulture()) { dwIncludeFlags |= AssemblyName::EXCLUDE_CULTURE; } @@ -916,7 +887,7 @@ namespace BINDER_SPACE SString& simpleNameRef = pRequestedAssemblyName->GetSimpleName(); SString& cultureRef = pRequestedAssemblyName->GetCulture(); - _ASSERTE(!cultureRef.IsEmpty() && !cultureRef.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral)); + _ASSERTE(!pRequestedAssemblyName->IsNeutralCulture()); ReleaseHolder pAssembly; SString fileName; @@ -1046,10 +1017,9 @@ namespace BINDER_SPACE { HRESULT hr = S_OK; - SString &culture = pRequestedAssemblyName->GetCulture(); bool fPartialMatchOnTpa = false; - if (!culture.IsEmpty() && !culture.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral)) + if (!pRequestedAssemblyName->IsNeutralCulture()) { IF_FAIL_GO(BindSatelliteResource(pApplicationContext, pRequestedAssemblyName, pBindResult)); } @@ -1467,9 +1437,6 @@ HRESULT AssemblyBinder::BindUsingPEImage(/* in */ ApplicationContext *pApplicat { HRESULT hr = E_FAIL; - // Indirect check that binder was initialized. - _ASSERTE(g_BinderVariables != NULL); - LONG kContextVersion = 0; BindResult bindResult; diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 13e5a1634a9d8..3d9651ced512a 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -13,7 +13,6 @@ #include "assemblyname.hpp" #include "utils.hpp" -#include "variables.hpp" #include "textualidentityparser.hpp" @@ -21,6 +20,11 @@ #include "ex.h" +namespace +{ + const WCHAR* s_neutralCulture = W("neutral"); +} + namespace BINDER_SPACE { AssemblyName::AssemblyName() @@ -186,12 +190,13 @@ namespace BINDER_SPACE BOOL AssemblyName::IsCoreLib() { // TODO: Is this simple comparison enough? - return EqualsCaseInsensitive(GetSimpleName(), g_BinderVariables->corelib); + return SString::_wcsicmp(GetSimpleName(), CoreLibName_W) == 0; } bool AssemblyName::IsNeutralCulture() { - return m_cultureOrLanguage.IsEmpty() || m_cultureOrLanguage.EqualsCaseInsensitive(g_BinderVariables->cultureNeutral); + return m_cultureOrLanguage.IsEmpty() + || SString::_wcsicmp(m_cultureOrLanguage.GetUnicode(), s_neutralCulture) == 0; } ULONG AssemblyName::Hash(DWORD dwIncludeFlags) @@ -363,7 +368,7 @@ namespace BINDER_SPACE if (culture.IsEmpty()) { - culture = g_BinderVariables->cultureNeutral; + culture.SetLiteral(s_neutralCulture); } return culture; diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/clrprivbindercoreclr.cpp index 4b4ae7140ce69..0ddafdb480377 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/clrprivbindercoreclr.cpp @@ -4,7 +4,6 @@ #include "common.h" #include "assemblybinder.hpp" #include "clrprivbindercoreclr.h" -#include "variables.hpp" using namespace BINDER_SPACE; diff --git a/src/coreclr/binder/coreclrbindercommon.cpp b/src/coreclr/binder/coreclrbindercommon.cpp index 13ae1e52a577a..ebe3137c77f14 100644 --- a/src/coreclr/binder/coreclrbindercommon.cpp +++ b/src/coreclr/binder/coreclrbindercommon.cpp @@ -10,17 +10,6 @@ using namespace BINDER_SPACE; -//============================================================================= -// Init code -//----------------------------------------------------------------------------- -/* static */ -HRESULT CCoreCLRBinderHelper::Init() -{ - STATIC_CONTRACT_NOTHROW; - - return AssemblyBinder::Startup(); -} - HRESULT CCoreCLRBinderHelper::DefaultBinderSetupContext(DWORD dwAppDomainId,CLRPrivBinderCoreCLR **ppTPABinder) { HRESULT hr = S_OK; diff --git a/src/coreclr/binder/inc/assemblybinder.hpp b/src/coreclr/binder/inc/assemblybinder.hpp index 5dbb8ffa45f5e..2ba11b7ac0183 100644 --- a/src/coreclr/binder/inc/assemblybinder.hpp +++ b/src/coreclr/binder/inc/assemblybinder.hpp @@ -16,19 +16,17 @@ #include "bindertypes.hpp" #include "bindresult.hpp" -#include "coreclrbindercommon.h" #include "bundle.h" -class CLRPrivBinderAssemblyLoadContext; class CLRPrivBinderCoreCLR; +class PEAssembly; +class PEImage; namespace BINDER_SPACE { class AssemblyBinder { public: - static HRESULT Startup(); - // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. diff --git a/src/coreclr/binder/inc/bindertypes.hpp b/src/coreclr/binder/inc/bindertypes.hpp index e55dff0167cd4..0b433766784d5 100644 --- a/src/coreclr/binder/inc/bindertypes.hpp +++ b/src/coreclr/binder/inc/bindertypes.hpp @@ -17,9 +17,6 @@ #include "clrtypes.h" #include "sstring.h" -class PEImage; -class PEAssembly; - namespace BINDER_SPACE { class AssemblyVersion; diff --git a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h index 51dd63bc6f60d..a684762b97371 100644 --- a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h +++ b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h @@ -10,8 +10,8 @@ #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) -class Assembly; class LoaderAllocator; +class PEImage; class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext { diff --git a/src/coreclr/binder/inc/clrprivbindercoreclr.h b/src/coreclr/binder/inc/clrprivbindercoreclr.h index 42b57311d4e2d..026b3cd119ef5 100644 --- a/src/coreclr/binder/inc/clrprivbindercoreclr.h +++ b/src/coreclr/binder/inc/clrprivbindercoreclr.h @@ -8,6 +8,9 @@ #include "applicationcontext.hpp" #include "assemblyloadcontext.h" +class PEAssembly; +class PEImage; + class CLRPrivBinderCoreCLR : public AssemblyLoadContext { public: diff --git a/src/coreclr/binder/inc/coreclrbindercommon.h b/src/coreclr/binder/inc/coreclrbindercommon.h index 4fe3249363b61..d64b84e50b487 100644 --- a/src/coreclr/binder/inc/coreclrbindercommon.h +++ b/src/coreclr/binder/inc/coreclrbindercommon.h @@ -6,10 +6,8 @@ #define __CORECLR_BINDER_COMMON_H__ #include "clrprivbinding.h" -#include "internalunknownimpl.h" #include "applicationcontext.hpp" - namespace BINDER_SPACE { class AssemblyIdentityUTF8; @@ -21,10 +19,8 @@ class CLRPrivBinderCoreCLR; class CCoreCLRBinderHelper { public: - static HRESULT Init(); - static HRESULT DefaultBinderSetupContext(DWORD dwAppDomainId, - CLRPrivBinderCoreCLR **ppTPABinder); + CLRPrivBinderCoreCLR **ppTPABinder); // ABHI-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/variables.hpp b/src/coreclr/binder/inc/variables.hpp deleted file mode 100644 index d060a691bbecc..0000000000000 --- a/src/coreclr/binder/inc/variables.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// ============================================================ -// -// Variables.hpp -// - - -// -// Defines the Variables class -// -// ============================================================ - -#ifndef __BINDER__VARIABLES_HPP__ -#define __BINDER__VARIABLES_HPP__ - -#include "bindertypes.hpp" - -namespace BINDER_SPACE -{ - class Variables - { - public: - Variables(); - ~Variables(); - - HRESULT Init(); - - // AssemblyBinder string constants - SString httpURLPrefix; - - // AssemblyName string constants - SString cultureNeutral; - SString corelib; - }; - - extern Variables *g_BinderVariables; -}; - -#endif diff --git a/src/coreclr/binder/variables.cpp b/src/coreclr/binder/variables.cpp deleted file mode 100644 index fbdd106b4dd2f..0000000000000 --- a/src/coreclr/binder/variables.cpp +++ /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. -// ============================================================ -// -// Variables.cpp -// - - -// -// Implements the Variables class -// -// ============================================================ - -#include "variables.hpp" - -#include "ex.h" - -namespace BINDER_SPACE -{ - Variables *g_BinderVariables = NULL; - - Variables::Variables() - { - // Nothing to do here - } - - Variables::~Variables() - { - // Nothing to do here - } - - HRESULT Variables::Init() - { - HRESULT hr = S_OK; - - EX_TRY - { - // AssemblyBinder string constants - httpURLPrefix.SetLiteral(W("http://")); - - // AssemblyName string constants - cultureNeutral.SetLiteral(W("neutral")); - corelib.SetLiteral(CoreLibName_W); - } - EX_CATCH_HRESULT(hr); - - return hr; - } -}; diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index 262510e3b11f0..77120d5f81d07 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -205,9 +205,6 @@ #include "interpreter.h" #endif // FEATURE_INTERPRETER -#include "../binder/inc/coreclrbindercommon.h" - - #ifdef FEATURE_PERFMAP #include "perfmap.h" #endif @@ -759,9 +756,6 @@ void EEStartupHelper() InitEventStore(); #endif - // Initialize the default Assembly Binder and the binder infrastructure - IfFailGoLog(CCoreCLRBinderHelper::Init()); - if (g_pConfig != NULL) { IfFailGoLog(g_pConfig->sync()); From e5a29a7c71f52ea18f2a2e6a2babbd6eb87926ab Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 5 Apr 2021 10:47:12 -0700 Subject: [PATCH 4/8] Avoid re-parsing display name --- src/coreclr/binder/assembly.cpp | 4 +- src/coreclr/binder/assemblyname.cpp | 30 ++++++ .../clrprivbinderassemblyloadcontext.cpp | 6 +- src/coreclr/binder/clrprivbindercoreclr.cpp | 6 +- src/coreclr/binder/inc/assembly.hpp | 4 +- src/coreclr/binder/inc/assemblyname.hpp | 1 + src/coreclr/binder/inc/bindertypes.hpp | 19 ++++ .../inc/clrprivbinderassemblyloadcontext.h | 2 +- src/coreclr/binder/inc/clrprivbindercoreclr.h | 2 +- src/coreclr/inc/clrprivbinding.idl | 2 +- src/coreclr/pal/prebuilt/inc/clrprivbinding.h | 14 +-- src/coreclr/vm/baseassemblyspec.h | 2 +- src/coreclr/vm/baseassemblyspec.inl | 5 - src/coreclr/vm/coreassemblyspec.cpp | 96 +++++++++++++++---- 14 files changed, 148 insertions(+), 45 deletions(-) diff --git a/src/coreclr/binder/assembly.cpp b/src/coreclr/binder/assembly.cpp index 75ca4b2c265df..c48acbb0c33fd 100644 --- a/src/coreclr/binder/assembly.cpp +++ b/src/coreclr/binder/assembly.cpp @@ -182,9 +182,9 @@ namespace BINDER_SPACE return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName()); } - HRESULT Assembly::BindAssemblyByName(const WCHAR *pAssemblyFullName, ICLRPrivAssembly ** ppAssembly) + HRESULT Assembly::BindAssemblyByName(struct AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly ** ppAssembly) { - return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pAssemblyFullName, ppAssembly); + return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pAssemblyNameData, ppAssembly); } HRESULT Assembly::GetBinderID(UINT_PTR *pBinderId) diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 3d9651ced512a..75d2ff7e92688 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -172,6 +172,36 @@ namespace BINDER_SPACE return TextualIdentityParser::Parse(assemblyDisplayName, this); } + HRESULT AssemblyName::Init(const AssemblyNameData &data) + { + DWORD flags = data.IdentityFlags; + m_simpleName.SetUTF8(data.Name); + m_version.SetFeatureVersion(data.MajorVersion, data.MinorVersion); + m_version.SetServiceVersion(data.BuildNumber, data.RevisionNumber); + m_cultureOrLanguage.SetUTF8(data.Culture); + + m_publicKeyOrTokenBLOB.Set(data.PublicKeyOrToken, data.PublicKeyOrTokenLength); + if ((flags & BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY) != 0) + { + // Convert public key to token + SBuffer publicKeyToken; + HRESULT hr = GetTokenFromPublicKey(m_publicKeyOrTokenBLOB, publicKeyToken); + if (FAILED(hr)) + return hr; + + m_publicKeyOrTokenBLOB.Set(publicKeyToken); + flags &= ~BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY; + flags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN; + } + + m_kProcessorArchitecture = data.ProcessorArchitecture; + m_kContentType = data.ContentType; + + SetHave(flags); + + return S_OK; + } + ULONG AssemblyName::AddRef() { return InterlockedIncrement(&m_cRef); diff --git a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp b/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp index 39ef98d76248d..d83a00423d893 100644 --- a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp +++ b/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp @@ -42,11 +42,11 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE: return hr; } -HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(const WCHAR *pAssemblyFullName, +HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(struct AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; - VALIDATE_ARG_RET(pAssemblyFullName != nullptr && ppAssembly != nullptr); + VALIDATE_ARG_RET(pAssemblyNameData != nullptr && ppAssembly != nullptr); _ASSERTE(m_pTPABinder != NULL); @@ -54,7 +54,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(const WCHAR *pA ReleaseHolder pAssemblyName; SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(SString(pAssemblyFullName))); + IF_FAIL_GO(pAssemblyName->Init(*pAssemblyNameData)); // When LoadContext needs to resolve an assembly reference, it will go through the following lookup order: // diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/clrprivbindercoreclr.cpp index 0ddafdb480377..72faade3c8aa1 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/clrprivbindercoreclr.cpp @@ -42,17 +42,17 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam // ============================================================================ // CLRPrivBinderCoreCLR implementation // ============================================================================ -HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(const WCHAR *pAssemblyFullName, +HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(struct AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; - VALIDATE_ARG_RET(pAssemblyFullName != nullptr && ppAssembly != nullptr); + VALIDATE_ARG_RET(pAssemblyNameData != nullptr && ppAssembly != nullptr); *ppAssembly = nullptr; ReleaseHolder pAssemblyName; SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(SString(pAssemblyFullName))); + IF_FAIL_GO(pAssemblyName->Init(*pAssemblyNameData)); hr = BindUsingAssemblyName(pAssemblyName, ppAssembly); diff --git a/src/coreclr/binder/inc/assembly.hpp b/src/coreclr/binder/inc/assembly.hpp index 0f017a781cac0..24702afeba029 100644 --- a/src/coreclr/binder/inc/assembly.hpp +++ b/src/coreclr/binder/inc/assembly.hpp @@ -71,8 +71,8 @@ namespace BINDER_SPACE // -------------------------------------------------------------------- LPCWSTR GetSimpleName(); - STDMETHOD(BindAssemblyByName)( - /* [string][in] */ const WCHAR *pAssemblyFullName, + STDMETHOD(BindAssemblyByName)( + /* [in] */ struct AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetAvailableImageTypes)(PDWORD pdwImageTypes); diff --git a/src/coreclr/binder/inc/assemblyname.hpp b/src/coreclr/binder/inc/assemblyname.hpp index 8b6b96270d3bb..f984bd125c897 100644 --- a/src/coreclr/binder/inc/assemblyname.hpp +++ b/src/coreclr/binder/inc/assemblyname.hpp @@ -46,6 +46,7 @@ namespace BINDER_SPACE /* in */ mdAssemblyRef mda = 0, /* in */ BOOL fIsDefinition = TRUE); HRESULT Init(/* in */ SString &assemblyDisplayName); + HRESULT Init(/* in */ const AssemblyNameData &data); ULONG AddRef(); ULONG Release(); diff --git a/src/coreclr/binder/inc/bindertypes.hpp b/src/coreclr/binder/inc/bindertypes.hpp index 0b433766784d5..101ef3c8d9593 100644 --- a/src/coreclr/binder/inc/bindertypes.hpp +++ b/src/coreclr/binder/inc/bindertypes.hpp @@ -71,6 +71,25 @@ typedef enum __PEKIND peInvalid = 0xffffffff, } PEKIND; +struct AssemblyNameData +{ + LPCSTR Name; + LPCSTR Culture; + + const BYTE* PublicKeyOrToken; + DWORD PublicKeyOrTokenLength; + + DWORD MajorVersion; + DWORD MinorVersion; + DWORD BuildNumber; + DWORD RevisionNumber; + + PEKIND ProcessorArchitecture; + AssemblyContentType ContentType; + + DWORD IdentityFlags; +}; + #define IF_FAIL_GO(expr) \ hr = (expr); \ if (FAILED(hr)) \ diff --git a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h index a684762b97371..4573575c1b7c6 100644 --- a/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h +++ b/src/coreclr/binder/inc/clrprivbinderassemblyloadcontext.h @@ -21,7 +21,7 @@ class CLRPrivBinderAssemblyLoadContext : public AssemblyLoadContext // ICLRPrivBinder functions //------------------------------------------------------------------------- STDMETHOD(BindAssemblyByName)( - /* [string][in] */ const WCHAR *pAssemblyFullName, + /* [in] */ struct AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetLoaderAllocator)( diff --git a/src/coreclr/binder/inc/clrprivbindercoreclr.h b/src/coreclr/binder/inc/clrprivbindercoreclr.h index 026b3cd119ef5..9b5d06a117f9a 100644 --- a/src/coreclr/binder/inc/clrprivbindercoreclr.h +++ b/src/coreclr/binder/inc/clrprivbindercoreclr.h @@ -19,7 +19,7 @@ class CLRPrivBinderCoreCLR : public AssemblyLoadContext // ICLRPrivBinder functions //------------------------------------------------------------------------- STDMETHOD(BindAssemblyByName)( - /* [string][in] */ const WCHAR *pAssemblyFullName, + /* [in] */ struct AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetLoaderAllocator)( diff --git a/src/coreclr/inc/clrprivbinding.idl b/src/coreclr/inc/clrprivbinding.idl index 9c048302bc8d0..9f4ee2f3d6ff8 100644 --- a/src/coreclr/inc/clrprivbinding.idl +++ b/src/coreclr/inc/clrprivbinding.idl @@ -36,7 +36,7 @@ interface ICLRPrivBinder : IUnknown ** ppAssembly - upon success, receives the bound assembly. **********************************************************************************/ HRESULT BindAssemblyByName( - [in, string] const WCHAR* pAssemblyFullName, + [in] struct AssemblyNameData* pAssemblyNameData, [out, retval] ICLRPrivAssembly ** ppAssembly); /********************************************************************************** diff --git a/src/coreclr/pal/prebuilt/inc/clrprivbinding.h b/src/coreclr/pal/prebuilt/inc/clrprivbinding.h index 9d696bccdd12e..3c810676aa36c 100644 --- a/src/coreclr/pal/prebuilt/inc/clrprivbinding.h +++ b/src/coreclr/pal/prebuilt/inc/clrprivbinding.h @@ -87,7 +87,7 @@ EXTERN_C const IID IID_ICLRPrivBinder; { public: virtual HRESULT STDMETHODCALLTYPE BindAssemblyByName( - /* [string][in] */ const WCHAR *pAssemblyFullName, + /* [in] */ struct AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly) = 0; virtual HRESULT STDMETHODCALLTYPE GetBinderID( @@ -119,7 +119,7 @@ EXTERN_C const IID IID_ICLRPrivBinder; HRESULT ( STDMETHODCALLTYPE *BindAssemblyByName )( ICLRPrivBinder * This, - /* [string][in] */ const WCHAR *pAssemblyFullName, + /* [in] */ struct AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); HRESULT ( STDMETHODCALLTYPE *GetBinderID )( @@ -153,8 +153,8 @@ EXTERN_C const IID IID_ICLRPrivBinder; ( (This)->lpVtbl -> Release(This) ) -#define ICLRPrivBinder_BindAssemblyByName(This,pAssemblyFullName,ppAssembly) \ - ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyFullName,ppAssembly) ) +#define ICLRPrivBinder_BindAssemblyByName(This,pAssemblyNameData,ppAssembly) \ + ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyNameData,ppAssembly) ) #define ICLRPrivBinder_GetBinderID(This,pBinderId) \ ( (This)->lpVtbl -> GetBinderID(This,pBinderId) ) @@ -230,7 +230,7 @@ EXTERN_C const IID IID_ICLRPrivAssembly; HRESULT ( STDMETHODCALLTYPE *BindAssemblyByName )( ICLRPrivAssembly * This, - /* [string][in] */ const WCHAR *pAssemblyFullName, + /* [in] */ struct AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); HRESULT ( STDMETHODCALLTYPE *GetBinderID )( @@ -268,8 +268,8 @@ EXTERN_C const IID IID_ICLRPrivAssembly; ( (This)->lpVtbl -> Release(This) ) -#define ICLRPrivAssembly_BindAssemblyByName(This,pAssemblyFullName,ppAssembly) \ - ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyFullName,ppAssembly) ) +#define ICLRPrivAssembly_BindAssemblyByName(This,pAssemblyNameData,ppAssembly) \ + ( (This)->lpVtbl -> BindAssemblyByName(This,pAssemblyNameData,ppAssembly) ) #define ICLRPrivAssembly_GetBinderID(This,pBinderId) \ ( (This)->lpVtbl -> GetBinderID(This,pBinderId) ) diff --git a/src/coreclr/vm/baseassemblyspec.h b/src/coreclr/vm/baseassemblyspec.h index 107b025635aef..06ac705df06e5 100644 --- a/src/coreclr/vm/baseassemblyspec.h +++ b/src/coreclr/vm/baseassemblyspec.h @@ -92,7 +92,6 @@ class BaseAssemblySpec void SetCodeBase(LPCWSTR szCodeBase); VOID SetCulture(LPCSTR szCulture); - bool IsNeutralCulture(); VOID ConvertPublicKeyToToken(); @@ -132,6 +131,7 @@ class BaseAssemblySpec protected: void InitializeWithAssemblyIdentity(BINDER_SPACE::AssemblyIdentity *identity); + void PopulateAssemblyNameData(AssemblyNameData &data) const; private: void GetDisplayNameInternal(DWORD flags, SString &result) const; diff --git a/src/coreclr/vm/baseassemblyspec.inl b/src/coreclr/vm/baseassemblyspec.inl index 5e1496b5986e1..e90d2f0d9eec1 100644 --- a/src/coreclr/vm/baseassemblyspec.inl +++ b/src/coreclr/vm/baseassemblyspec.inl @@ -514,11 +514,6 @@ inline void BaseAssemblySpec::SetCulture(LPCSTR szCulture) m_context.szLocale=szCulture; } -inline bool BaseAssemblySpec::IsNeutralCulture() -{ - return strcmp(m_context.szLocale,"")==0; -} - inline void BaseAssemblySpec::SetContext(ASSEMBLYMETADATA* assemblyData) { LIMITED_METHOD_CONTRACT; diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index c777eeef87562..1b93449b98a2a 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -95,15 +95,8 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, ReleaseHolder result; HRESULT hr=S_OK; - SString assemblyDisplayName; - pResult->Reset(); - if (m_wszCodeBase == NULL) - { - GetDisplayName(0, assemblyDisplayName); - } - // Have a default binding context setup ICLRPrivBinder *pBinder = GetBindingContextFromParentAssembly(pAppDomain); @@ -136,11 +129,13 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, { // For name based binding these arguments shouldn't have been changed from default _ASSERTE(!fNgenExplicitBind && !fExplicitBindToNativeImage); - hr = pBinder->BindAssemblyByName(assemblyDisplayName, &pPrivAsm); + AssemblyNameData assemblyNameData = { 0 }; + PopulateAssemblyNameData(assemblyNameData); + hr = pBinder->BindAssemblyByName(&assemblyNameData, &pPrivAsm); } else { - hr = pTPABinder->Bind(assemblyDisplayName, + hr = pTPABinder->Bind(SString(), m_wszCodeBase, GetParentAssembly() ? GetParentAssembly()->GetFile() : NULL, fNgenExplicitBind, @@ -483,6 +478,29 @@ VOID BaseAssemblySpec::GetDisplayName(DWORD flags, SString &result) const GetDisplayNameInternal(flags, result); } +namespace +{ + PEKIND GetProcessorArchitectureFromAssemblyFlags(DWORD flags) + { + if (flags & afPA_MSIL) + return peMSIL; + + if (flags & afPA_x86) + return peI386; + + if (flags & afPA_IA64) + return peIA64; + + if (flags & afPA_AMD64) + return peAMD64; + + if (flags & afPA_ARM64) + return peARM64; + + return peNone; + } +} + VOID BaseAssemblySpec::GetDisplayNameInternal(DWORD flags, SString &result) const { if (flags==0) @@ -560,16 +578,7 @@ VOID BaseAssemblySpec::GetDisplayNameInternal(DWORD flags, SString &result) cons assemblyIdentity. SetHave(BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE); - if (m_dwFlags & afPA_MSIL) - assemblyIdentity.m_kProcessorArchitecture = peMSIL; - else if (m_dwFlags & afPA_x86) - assemblyIdentity.m_kProcessorArchitecture = peI386; - else if (m_dwFlags & afPA_IA64) - assemblyIdentity.m_kProcessorArchitecture = peIA64; - else if (m_dwFlags & afPA_AMD64) - assemblyIdentity.m_kProcessorArchitecture = peAMD64; - else if (m_dwFlags & afPA_ARM) - assemblyIdentity.m_kProcessorArchitecture = peARM; + assemblyIdentity.m_kProcessorArchitecture = GetProcessorArchitectureFromAssemblyFlags(m_dwFlags); } if ((flags & ASM_DISPLAYF_RETARGET) && (m_dwFlags & afRetargetable)) @@ -588,4 +597,53 @@ VOID BaseAssemblySpec::GetDisplayNameInternal(DWORD flags, SString &result) cons result)); } +void BaseAssemblySpec::PopulateAssemblyNameData(AssemblyNameData &data) const +{ + data.Name = m_pAssemblyName; + data.IdentityFlags = BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_SIMPLE_NAME; + + if (m_context.usMajorVersion != 0xFFFF) + { + data.MajorVersion = m_context.usMajorVersion; + data.MinorVersion = m_context.usMinorVersion; + data.BuildNumber = m_context.usBuildNumber; + data.RevisionNumber = m_context.usRevisionNumber; + data.IdentityFlags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_VERSION; + } + + if (m_context.szLocale != NULL && m_context.szLocale[0] != 0) + { + data.Culture = m_context.szLocale; + data.IdentityFlags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CULTURE; + } + + data.PublicKeyOrTokenLength = m_cbPublicKeyOrToken; + if (m_cbPublicKeyOrToken > 0) + { + data.PublicKeyOrToken = m_pbPublicKeyOrToken; + data.IdentityFlags |= IsAfPublicKeyToken(m_dwFlags) + ? BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN + : BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY; + } + else + { + data.IdentityFlags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL; + } + + if ((m_dwFlags & afPA_Mask) != 0) + { + data.ProcessorArchitecture = GetProcessorArchitectureFromAssemblyFlags(m_dwFlags); + data.IdentityFlags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_PROCESSOR_ARCHITECTURE; + } + if ((m_dwFlags & afRetargetable) != 0) + { + data.IdentityFlags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_RETARGETABLE; + } + + if ((m_dwFlags & afContentType_Mask) == afContentType_WindowsRuntime) + { + data.ContentType = AssemblyContentType_WindowsRuntime; + data.IdentityFlags |= BINDER_SPACE::AssemblyIdentity::IDENTITY_FLAG_CONTENT_TYPE; + } +} From 26378a75ef2e74facec5554aaaf25463cc65d532 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 5 Apr 2021 11:11:57 -0700 Subject: [PATCH 5/8] Slight cleanup of utils --- src/coreclr/binder/assemblybinder.cpp | 7 +++---- src/coreclr/binder/assemblyname.cpp | 10 +++++----- src/coreclr/binder/clrprivbindercoreclr.cpp | 2 +- src/coreclr/binder/inc/assemblyname.hpp | 2 +- src/coreclr/binder/inc/assemblyname.inl | 2 +- src/coreclr/binder/inc/failurecachehashtraits.hpp | 4 ++-- src/coreclr/binder/inc/utils.hpp | 14 ++------------ src/coreclr/binder/textualidentityparser.cpp | 6 ++---- src/coreclr/binder/utils.cpp | 4 ++-- 9 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/coreclr/binder/assemblybinder.cpp b/src/coreclr/binder/assemblybinder.cpp index e69063264280e..d3442bdb018ad 100644 --- a/src/coreclr/binder/assemblybinder.cpp +++ b/src/coreclr/binder/assemblybinder.cpp @@ -29,7 +29,6 @@ #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) #include "clrprivbindercoreclr.h" -#include "clrprivbinderassemblyloadcontext.h" // Helper function in the VM, invoked by the Binder, to invoke the host assembly resolver extern HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadContextToBindWithin, BINDER_SPACE::AssemblyName *pAssemblyName, @@ -884,7 +883,7 @@ namespace BINDER_SPACE // names as platform ones. HRESULT hr = S_OK; - SString& simpleNameRef = pRequestedAssemblyName->GetSimpleName(); + const SString& simpleNameRef = pRequestedAssemblyName->GetSimpleName(); SString& cultureRef = pRequestedAssemblyName->GetCulture(); _ASSERTE(!pRequestedAssemblyName->IsNeutralCulture()); @@ -928,7 +927,7 @@ namespace BINDER_SPACE bool useNativeImages, Assembly **ppAssembly) { - SString &simpleName = pRequestedAssemblyName->GetSimpleName(); + const SString &simpleName = pRequestedAssemblyName->GetSimpleName(); BinderTracing::PathSource pathSource = useNativeImages ? BinderTracing::PathSource::AppNativeImagePaths : BinderTracing::PathSource::AppPaths; // Loop through the binding paths looking for a matching assembly for (DWORD i = 0; i < pBindingPaths->GetCount(); i++) @@ -1026,7 +1025,7 @@ namespace BINDER_SPACE else { ReleaseHolder pTPAAssembly; - SString& simpleName = pRequestedAssemblyName->GetSimpleName(); + const SString& simpleName = pRequestedAssemblyName->GetSimpleName(); // Is assembly in the bundle? // Single-file bundle contents take precedence over TPA. diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 75d2ff7e92688..25bc951a84fc4 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -220,7 +220,7 @@ namespace BINDER_SPACE BOOL AssemblyName::IsCoreLib() { // TODO: Is this simple comparison enough? - return SString::_wcsicmp(GetSimpleName(), CoreLibName_W) == 0; + return SString::_wcsicmp(GetSimpleName().GetUnicode(), CoreLibName_W) == 0; } bool AssemblyName::IsNeutralCulture() @@ -261,7 +261,7 @@ namespace BINDER_SPACE dwUseIdentityFlags &= ~AssemblyIdentity::IDENTITY_FLAG_CULTURE; } - dwHash ^= static_cast(HashCaseInsensitive(GetSimpleName())); + dwHash ^= static_cast(GetSimpleName().HashCaseInsensitive()); dwHash = _rotl(dwHash, 4); if (AssemblyIdentity::Have(dwUseIdentityFlags, @@ -294,7 +294,7 @@ namespace BINDER_SPACE if (AssemblyIdentity::Have(dwUseIdentityFlags, AssemblyIdentity::IDENTITY_FLAG_CULTURE)) { - dwHash ^= static_cast(HashCaseInsensitive(GetNormalizedCulture())); + dwHash ^= static_cast(GetNormalizedCulture().HashCaseInsensitive()); dwHash = _rotl(dwHash, 4); } @@ -332,14 +332,14 @@ namespace BINDER_SPACE return (GetContentType() == pAssemblyName->GetContentType()); } - if (EqualsCaseInsensitive(GetSimpleName(), pAssemblyName->GetSimpleName()) && + if (GetSimpleName().EqualsCaseInsensitive(pAssemblyName->GetSimpleName()) && (GetContentType() == pAssemblyName->GetContentType())) { fEquals = TRUE; if ((dwIncludeFlags & EXCLUDE_CULTURE) == 0) { - fEquals = EqualsCaseInsensitive(GetNormalizedCulture(), pAssemblyName->GetNormalizedCulture()); + fEquals = GetNormalizedCulture().EqualsCaseInsensitive(pAssemblyName->GetNormalizedCulture()); } if (fEquals && (dwIncludeFlags & INCLUDE_PUBLIC_KEY_TOKEN) != 0) diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/clrprivbindercoreclr.cpp index 72faade3c8aa1..f32c571bb61bf 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/clrprivbindercoreclr.cpp @@ -172,7 +172,7 @@ HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage, { // Ensure we are not being asked to bind to a TPA assembly // - SString& simpleName = pAssemblyName->GetSimpleName(); + const SString& simpleName = pAssemblyName->GetSimpleName(); SimpleNameToFileNameMap* tpaMap = GetAppContext()->GetTpaList(); if (tpaMap->LookupPtr(simpleName.GetUnicode()) != NULL) { diff --git a/src/coreclr/binder/inc/assemblyname.hpp b/src/coreclr/binder/inc/assemblyname.hpp index f984bd125c897..03fcb7e6a75b9 100644 --- a/src/coreclr/binder/inc/assemblyname.hpp +++ b/src/coreclr/binder/inc/assemblyname.hpp @@ -52,7 +52,7 @@ namespace BINDER_SPACE ULONG Release(); // Getters/Setters - inline SString &GetSimpleName(); + inline const SString &GetSimpleName(); inline void SetSimpleName(SString &simpleName); inline AssemblyVersion *GetVersion(); inline void SetVersion(/* in */ AssemblyVersion *pAssemblyVersion); diff --git a/src/coreclr/binder/inc/assemblyname.inl b/src/coreclr/binder/inc/assemblyname.inl index 11d5dbbe86905..15f4c1aa0e2df 100644 --- a/src/coreclr/binder/inc/assemblyname.inl +++ b/src/coreclr/binder/inc/assemblyname.inl @@ -14,7 +14,7 @@ #ifndef __BINDER__ASSEMBLY_NAME_INL__ #define __BINDER__ASSEMBLY_NAME_INL__ -SString &AssemblyName::GetSimpleName() +const SString &AssemblyName::GetSimpleName() { return m_simpleName; } diff --git a/src/coreclr/binder/inc/failurecachehashtraits.hpp b/src/coreclr/binder/inc/failurecachehashtraits.hpp index 0d9ad26156d12..7eee29a8783ac 100644 --- a/src/coreclr/binder/inc/failurecachehashtraits.hpp +++ b/src/coreclr/binder/inc/failurecachehashtraits.hpp @@ -66,11 +66,11 @@ namespace BINDER_SPACE } static BOOL Equals(key_t pAssemblyNameOrPath1, key_t pAssemblyNameOrPath2) { - return EqualsCaseInsensitive(pAssemblyNameOrPath1, pAssemblyNameOrPath2); + return pAssemblyNameOrPath1.EqualsCaseInsensitive(pAssemblyNameOrPath2); } static count_t Hash(key_t pAssemblyNameOrPath) { - return HashCaseInsensitive(pAssemblyNameOrPath); + return pAssemblyNameOrPath.HashCaseInsensitive(); } static element_t Null() { diff --git a/src/coreclr/binder/inc/utils.hpp b/src/coreclr/binder/inc/utils.hpp index 1c8ea114f5e6c..768cf4f576f21 100644 --- a/src/coreclr/binder/inc/utils.hpp +++ b/src/coreclr/binder/inc/utils.hpp @@ -18,21 +18,11 @@ namespace BINDER_SPACE { - inline BOOL EqualsCaseInsensitive(SString &a, SString &b) - { - return a.EqualsCaseInsensitive(b); - } - - inline ULONG HashCaseInsensitive(SString &string) - { - return string.HashCaseInsensitive(); - } - void MutateUrlToPath(SString &urlOrPath); // It is safe to use either A or B as CombinedPath. - void CombinePath(SString &pathA, - SString &pathB, + void CombinePath(const SString &pathA, + const SString &pathB, SString &combinedPath); HRESULT GetTokenFromPublicKey(SBuffer &publicKeyBLOB, diff --git a/src/coreclr/binder/textualidentityparser.cpp b/src/coreclr/binder/textualidentityparser.cpp index 939ffe9f468c0..b7ef7a4f49685 100644 --- a/src/coreclr/binder/textualidentityparser.cpp +++ b/src/coreclr/binder/textualidentityparser.cpp @@ -94,11 +94,9 @@ namespace BINDER_SPACE } } - inline BOOL EqualsCaseInsensitive(SString &a, LPCWSTR wzB) + inline bool EqualsCaseInsensitive(const SString &a, LPCWSTR wzB) { - SString b(SString::Literal, wzB); - - return ::BINDER_SPACE::EqualsCaseInsensitive(a, b); + return SString::_wcsicmp(a.GetUnicode(), wzB) == 0; } BOOL ValidateHex(SString &publicKeyOrToken) diff --git a/src/coreclr/binder/utils.cpp b/src/coreclr/binder/utils.cpp index 21fc115a77662..916dd677f9106 100644 --- a/src/coreclr/binder/utils.cpp +++ b/src/coreclr/binder/utils.cpp @@ -74,8 +74,8 @@ namespace BINDER_SPACE } } - void CombinePath(SString &pathA, - SString &pathB, + void CombinePath(const SString &pathA, + const SString &pathB, SString &combinedPath) { SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator()); From ad7feac56aa0b67287cccebf7e1a6688f8fa576f Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 5 Apr 2021 15:24:13 -0700 Subject: [PATCH 6/8] Remove unused parameters --- src/coreclr/binder/assemblybinder.cpp | 1 + src/coreclr/binder/assemblyname.cpp | 10 ---------- src/coreclr/binder/clrprivbindercoreclr.cpp | 19 +++---------------- src/coreclr/binder/inc/assemblyname.hpp | 4 ---- src/coreclr/binder/inc/assemblyname.inl | 5 ----- src/coreclr/binder/inc/clrprivbindercoreclr.h | 3 +-- .../binder/inc/failurecachehashtraits.hpp | 1 - src/coreclr/binder/textualidentityparser.cpp | 1 - src/coreclr/vm/assembly.cpp | 6 +++--- src/coreclr/vm/assembly.hpp | 2 +- src/coreclr/vm/assemblyspec.cpp | 6 ++---- src/coreclr/vm/assemblyspec.hpp | 7 +------ src/coreclr/vm/coreassemblyspec.cpp | 3 +-- 13 files changed, 13 insertions(+), 55 deletions(-) diff --git a/src/coreclr/binder/assemblybinder.cpp b/src/coreclr/binder/assemblybinder.cpp index d3442bdb018ad..c4a2e85d8f5ac 100644 --- a/src/coreclr/binder/assemblybinder.cpp +++ b/src/coreclr/binder/assemblybinder.cpp @@ -274,6 +274,7 @@ namespace BINDER_SPACE if (szCodeBase == NULL) { + _ASSERTE(pAssemblyName != NULL); IF_FAIL_GO(BindByName(pApplicationContext, pAssemblyName, false, // skipFailureCaching diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 25bc951a84fc4..0c5e825901e6f 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -36,11 +36,6 @@ namespace BINDER_SPACE AssemblyIdentity::IDENTITY_FLAG_PUBLIC_KEY_TOKEN_NULL); } - AssemblyName::~AssemblyName() - { - // Nothing to do here - } - HRESULT AssemblyName::Init(IMDInternalImport *pIMetaDataAssemblyImport, PEKIND PeKind, mdAssemblyRef mdar /* = 0 */, @@ -167,11 +162,6 @@ namespace BINDER_SPACE return hr; } - HRESULT AssemblyName::Init(SString &assemblyDisplayName) - { - return TextualIdentityParser::Parse(assemblyDisplayName, this); - } - HRESULT AssemblyName::Init(const AssemblyNameData &data) { DWORD flags = data.IdentityFlags; diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/clrprivbindercoreclr.cpp index f32c571bb61bf..2951f9aade6d5 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/clrprivbindercoreclr.cpp @@ -223,32 +223,20 @@ HRESULT CLRPrivBinderCoreCLR::SetupBindingPaths(SString &sTrustedPlatformAssemb // See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind // and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath // for an example of how they're used. -HRESULT CLRPrivBinderCoreCLR::Bind(SString &assemblyDisplayName, - LPCWSTR wszCodeBase, +HRESULT CLRPrivBinderCoreCLR::Bind(LPCWSTR wszCodeBase, PEAssembly *pParentAssembly, BOOL fNgenExplicitBind, BOOL fExplicitBindToNativeImage, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; - VALIDATE_ARG_RET(ppAssembly != NULL); - - AssemblyName assemblyName; - - ReleaseHolder pAssemblyName; - - if (!assemblyDisplayName.IsEmpty()) - { - // AssemblyDisplayName can be empty if wszCodeBase is specified. - SAFE_NEW(pAssemblyName, AssemblyName); - IF_FAIL_GO(pAssemblyName->Init(assemblyDisplayName)); - } + VALIDATE_ARG_RET(wszCodeBase != NULL && ppAssembly != NULL); EX_TRY { ReleaseHolder pAsm; hr = AssemblyBinder::BindAssembly(&m_appContext, - pAssemblyName, + NULL, wszCodeBase, pParentAssembly, fNgenExplicitBind, @@ -264,7 +252,6 @@ HRESULT CLRPrivBinderCoreCLR::Bind(SString &assemblyDisplayName, } EX_CATCH_HRESULT(hr); -Exit: return hr; } diff --git a/src/coreclr/binder/inc/assemblyname.hpp b/src/coreclr/binder/inc/assemblyname.hpp index 03fcb7e6a75b9..6bec598a1646d 100644 --- a/src/coreclr/binder/inc/assemblyname.hpp +++ b/src/coreclr/binder/inc/assemblyname.hpp @@ -39,13 +39,11 @@ namespace BINDER_SPACE } INCLUDE_FLAGS; AssemblyName(); - ~AssemblyName(); HRESULT Init(/* in */ IMDInternalImport *pIMetaDataAssemblyImport, /* in */ PEKIND PeKind, /* in */ mdAssemblyRef mda = 0, /* in */ BOOL fIsDefinition = TRUE); - HRESULT Init(/* in */ SString &assemblyDisplayName); HRESULT Init(/* in */ const AssemblyNameData &data); ULONG AddRef(); @@ -68,8 +66,6 @@ namespace BINDER_SPACE inline BOOL GetIsDefinition(); inline void SetIsDefinition(BOOL fIsDefinition); - inline void SetHave(DWORD dwIdentityFlags); - BOOL IsCoreLib(); bool IsNeutralCulture(); diff --git a/src/coreclr/binder/inc/assemblyname.inl b/src/coreclr/binder/inc/assemblyname.inl index 15f4c1aa0e2df..201136f19768e 100644 --- a/src/coreclr/binder/inc/assemblyname.inl +++ b/src/coreclr/binder/inc/assemblyname.inl @@ -125,9 +125,4 @@ void AssemblyName::SetIsDefinition(BOOL fIsDefinition) } } -void AssemblyName::SetHave(DWORD dwIdentityFlags) -{ - AssemblyIdentity::SetHave(dwIdentityFlags); -} - #endif diff --git a/src/coreclr/binder/inc/clrprivbindercoreclr.h b/src/coreclr/binder/inc/clrprivbindercoreclr.h index 9b5d06a117f9a..ff47c561d0948 100644 --- a/src/coreclr/binder/inc/clrprivbindercoreclr.h +++ b/src/coreclr/binder/inc/clrprivbindercoreclr.h @@ -37,8 +37,7 @@ class CLRPrivBinderCoreCLR : public AssemblyLoadContext return &m_appContext; } - HRESULT Bind(SString &assemblyDisplayName, - LPCWSTR wszCodeBase, + HRESULT Bind(LPCWSTR wszCodeBase, PEAssembly *pParentAssembly, BOOL fNgenExplicitBind, BOOL fExplicitBindToNativeImage, diff --git a/src/coreclr/binder/inc/failurecachehashtraits.hpp b/src/coreclr/binder/inc/failurecachehashtraits.hpp index 7eee29a8783ac..1ffa96f56b198 100644 --- a/src/coreclr/binder/inc/failurecachehashtraits.hpp +++ b/src/coreclr/binder/inc/failurecachehashtraits.hpp @@ -15,7 +15,6 @@ #define __BINDER__FAILURE_CACHE_HASH_TRAITS_HPP__ #include "bindertypes.hpp" -#include "utils.hpp" #include "sstring.h" #include "shash.h" diff --git a/src/coreclr/binder/textualidentityparser.cpp b/src/coreclr/binder/textualidentityparser.cpp index b7ef7a4f49685..5d85a0a71cf37 100644 --- a/src/coreclr/binder/textualidentityparser.cpp +++ b/src/coreclr/binder/textualidentityparser.cpp @@ -13,7 +13,6 @@ #include "textualidentityparser.hpp" #include "assemblyidentity.hpp" -#include "utils.hpp" #include "ex.h" diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index a8569c0d2db95..542de57517f57 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -1251,7 +1251,7 @@ void Assembly::UpdateCachedFriendAssemblyInfo() CONTRACTL_END ReleaseHolder pOldFriendAssemblyDescriptor; - + { CrstHolder friendDescriptorLock(&g_friendAssembliesCrst); if (m_pFriendAssemblyDescriptor != NULL) @@ -1986,7 +1986,7 @@ bool Assembly::TrySetTypeLib(_In_ ITypeLib *pNew) // Add an assembly to the assemblyref list. pAssemEmitter specifies where // the AssemblyRef is emitted to. //*********************************************************** -mdAssemblyRef Assembly::AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssemblyEmit *pAssemEmitter, BOOL fUsePublicKeyToken) +mdAssemblyRef Assembly::AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssemblyEmit *pAssemEmitter) { CONTRACT(mdAssemblyRef) { @@ -2014,7 +2014,7 @@ mdAssemblyRef Assembly::AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssembl } mdAssemblyRef ar; - IfFailThrow(spec.EmitToken(pAssemEmitter, &ar, fUsePublicKeyToken)); + IfFailThrow(spec.EmitToken(pAssemEmitter, &ar)); RETURN ar; } // Assembly::AddAssemblyRef diff --git a/src/coreclr/vm/assembly.hpp b/src/coreclr/vm/assembly.hpp index 01485f6186bd3..3e5447ffffbee 100644 --- a/src/coreclr/vm/assembly.hpp +++ b/src/coreclr/vm/assembly.hpp @@ -426,7 +426,7 @@ class Assembly void AddType(Module* pModule, mdTypeDef cl); void AddExportedType(mdExportedType cl); - mdAssemblyRef AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssemblyEmit *pAssemEmitter = NULL, BOOL fUsePublicKeyToken = TRUE); + mdAssemblyRef AddAssemblyRef(Assembly *refedAssembly, IMetaDataAssemblyEmit *pAssemEmitter); //**************************************************************************************** diff --git a/src/coreclr/vm/assemblyspec.cpp b/src/coreclr/vm/assemblyspec.cpp index 4059a29c15ce4..7152b5d239342 100644 --- a/src/coreclr/vm/assemblyspec.cpp +++ b/src/coreclr/vm/assemblyspec.cpp @@ -888,9 +888,7 @@ HRESULT AssemblySpec::CheckFriendAssemblyName() HRESULT AssemblySpec::EmitToken( IMetaDataAssemblyEmit *pEmit, - mdAssemblyRef *pToken, - BOOL fUsePublicKeyToken, /*=TRUE*/ - BOOL fMustBeBindable /*=FALSE*/) + mdAssemblyRef *pToken) { CONTRACTL { @@ -931,7 +929,7 @@ HRESULT AssemblySpec::EmitToken( // If we've been asked to emit a public key token in the reference but we've // been given a public key then we need to generate the token now. - if (m_cbPublicKeyOrToken && fUsePublicKeyToken && IsAfPublicKey(m_dwFlags)) { + if (m_cbPublicKeyOrToken && IsAfPublicKey(m_dwFlags)) { StrongNameBufferHolder pbPublicKeyToken; DWORD cbPublicKeyToken; IfFailThrow(StrongNameTokenFromPublicKey(m_pbPublicKeyOrToken, diff --git a/src/coreclr/vm/assemblyspec.hpp b/src/coreclr/vm/assemblyspec.hpp index dbdaa20101b77..e7dcc4a6235e9 100644 --- a/src/coreclr/vm/assemblyspec.hpp +++ b/src/coreclr/vm/assemblyspec.hpp @@ -185,15 +185,10 @@ class AssemblySpec : public BaseAssemblySpec m_dwHashAlg = pSource->m_dwHashAlg; } - HRESULT CheckFriendAssemblyName(); - HRESULT EmitToken(IMetaDataAssemblyEmit *pEmit, - mdAssemblyRef *pToken, - BOOL fUsePublicKeyToken = TRUE, - BOOL fMustBeBindable = FALSE /*(used only by FusionBind's implementation)*/); - + mdAssemblyRef *pToken); VOID Bind( AppDomain* pAppDomain, diff --git a/src/coreclr/vm/coreassemblyspec.cpp b/src/coreclr/vm/coreassemblyspec.cpp index 1b93449b98a2a..b8312f5a365c5 100644 --- a/src/coreclr/vm/coreassemblyspec.cpp +++ b/src/coreclr/vm/coreassemblyspec.cpp @@ -135,8 +135,7 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, } else { - hr = pTPABinder->Bind(SString(), - m_wszCodeBase, + hr = pTPABinder->Bind(m_wszCodeBase, GetParentAssembly() ? GetParentAssembly()->GetFile() : NULL, fNgenExplicitBind, fExplicitBindToNativeImage, From 8c276a89fd6c523c1abad9b3759f056afc69a972 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 5 Apr 2021 16:20:54 -0700 Subject: [PATCH 7/8] Fix Unix build --- src/coreclr/inc/bbsweep.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/inc/bbsweep.h b/src/coreclr/inc/bbsweep.h index a65e9a94cbedb..03702f816f360 100644 --- a/src/coreclr/inc/bbsweep.h +++ b/src/coreclr/inc/bbsweep.h @@ -22,6 +22,10 @@ #include #endif // !TARGET_UNIX +#ifndef ARRAYSIZE +#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +#endif // !ARRAYSIZE + // The CLR headers don't allow us to use methods like SetEvent directly (instead // we need to use the host APIs). However, this file is included both in the CLR // and in the BBSweep tool, and the host API is not available in the tool. Moreover, From b5d13129addb2d93fd54cb283ea98e789fd11283 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 6 Apr 2021 14:26:14 -0700 Subject: [PATCH 8/8] PR feedback --- src/coreclr/binder/assembly.cpp | 2 +- src/coreclr/binder/assemblyname.cpp | 1 + src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp | 2 +- src/coreclr/binder/clrprivbindercoreclr.cpp | 2 +- src/coreclr/binder/inc/assembly.hpp | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coreclr/binder/assembly.cpp b/src/coreclr/binder/assembly.cpp index c48acbb0c33fd..09c195c0f8d09 100644 --- a/src/coreclr/binder/assembly.cpp +++ b/src/coreclr/binder/assembly.cpp @@ -182,7 +182,7 @@ namespace BINDER_SPACE return (pAsmName == nullptr ? nullptr : (LPCWSTR)pAsmName->GetSimpleName()); } - HRESULT Assembly::BindAssemblyByName(struct AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly ** ppAssembly) + HRESULT Assembly::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly ** ppAssembly) { return (m_pBinder == NULL) ? E_FAIL : m_pBinder->BindAssemblyByName(pAssemblyNameData, ppAssembly); } diff --git a/src/coreclr/binder/assemblyname.cpp b/src/coreclr/binder/assemblyname.cpp index 0c5e825901e6f..d7da9c73a7124 100644 --- a/src/coreclr/binder/assemblyname.cpp +++ b/src/coreclr/binder/assemblyname.cpp @@ -22,6 +22,7 @@ namespace { + // See https://docs.microsoft.com/dotnet/framework/reflection-and-codedom/specifying-fully-qualified-type-names#specifying-assembly-names const WCHAR* s_neutralCulture = W("neutral"); } diff --git a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp b/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp index d83a00423d893..92d83d75b111a 100644 --- a/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp +++ b/src/coreclr/binder/clrprivbinderassemblyloadcontext.cpp @@ -42,7 +42,7 @@ HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByNameWorker(BINDER_SPACE: return hr; } -HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(struct AssemblyNameData *pAssemblyNameData, +HRESULT CLRPrivBinderAssemblyLoadContext::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; diff --git a/src/coreclr/binder/clrprivbindercoreclr.cpp b/src/coreclr/binder/clrprivbindercoreclr.cpp index 2951f9aade6d5..fec66a7545880 100644 --- a/src/coreclr/binder/clrprivbindercoreclr.cpp +++ b/src/coreclr/binder/clrprivbindercoreclr.cpp @@ -42,7 +42,7 @@ HRESULT CLRPrivBinderCoreCLR::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam // ============================================================================ // CLRPrivBinderCoreCLR implementation // ============================================================================ -HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(struct AssemblyNameData *pAssemblyNameData, +HRESULT CLRPrivBinderCoreCLR::BindAssemblyByName(AssemblyNameData *pAssemblyNameData, ICLRPrivAssembly **ppAssembly) { HRESULT hr = S_OK; diff --git a/src/coreclr/binder/inc/assembly.hpp b/src/coreclr/binder/inc/assembly.hpp index 24702afeba029..5f5efb6a25c4f 100644 --- a/src/coreclr/binder/inc/assembly.hpp +++ b/src/coreclr/binder/inc/assembly.hpp @@ -72,7 +72,7 @@ namespace BINDER_SPACE LPCWSTR GetSimpleName(); STDMETHOD(BindAssemblyByName)( - /* [in] */ struct AssemblyNameData *pAssemblyNameData, + /* [in] */ AssemblyNameData *pAssemblyNameData, /* [retval][out] */ ICLRPrivAssembly **ppAssembly); STDMETHOD(GetAvailableImageTypes)(PDWORD pdwImageTypes);