diff options
author | Gaurav Khanna (CLR) <gaurav.khanna@microsoft.com> | 2016-01-11 17:26:13 -0800 |
---|---|---|
committer | Gaurav Khanna <gkhanna@microsoft.com> | 2016-01-12 07:27:58 -0800 |
commit | 0bca85d9a7eec19b24fa45886dfa2eb0cf3b25cf (patch) | |
tree | 9d974d05084d3e983d3fa081e205e0d3e8fedd7b /src/binder | |
parent | d0aafd0aa96ba85e76463967a445aa777bc24fad (diff) | |
download | coreclr-0bca85d9a7eec19b24fa45886dfa2eb0cf3b25cf.tar.gz coreclr-0bca85d9a7eec19b24fa45886dfa2eb0cf3b25cf.tar.bz2 coreclr-0bca85d9a7eec19b24fa45886dfa2eb0cf3b25cf.zip |
Add support Load assemblies from explicit path/streams into default load context
Diffstat (limited to 'src/binder')
-rw-r--r-- | src/binder/clrprivbindercoreclr.cpp | 74 | ||||
-rw-r--r-- | src/binder/inc/clrprivbindercoreclr.h | 17 |
2 files changed, 91 insertions, 0 deletions
diff --git a/src/binder/clrprivbindercoreclr.cpp b/src/binder/clrprivbindercoreclr.cpp index 570fc43392..6235072f11 100644 --- a/src/binder/clrprivbindercoreclr.cpp +++ b/src/binder/clrprivbindercoreclr.cpp @@ -72,7 +72,81 @@ Exit:; return hr; } + +#if !defined(CROSSGEN_COMPILE) +HRESULT CLRPrivBinderCoreCLR::BindUsingPEImage( /* in */ PEImage *pPEImage, + /* in */ BOOL fIsNativeImage, + /* [retval][out] */ ICLRPrivAssembly **ppAssembly) +{ + HRESULT hr = S_OK; + + EX_TRY + { + ReleaseHolder<BINDER_SPACE::Assembly> pCoreCLRFoundAssembly; + ReleaseHolder<BINDER_SPACE::AssemblyName> pAssemblyName; + ReleaseHolder<IMDInternalImport> pIMetaDataAssemblyImport; + + PEKIND PeKind = peNone; + + // Get the Metadata interface + DWORD dwPAFlags[2]; + IF_FAIL_GO(BinderAcquireImport(pPEImage, &pIMetaDataAssemblyImport, dwPAFlags, fIsNativeImage)); + IF_FAIL_GO(AssemblyBinder::TranslatePEToArchitectureType(dwPAFlags, &PeKind)); + + _ASSERTE(pIMetaDataAssemblyImport != NULL); + + // Using the information we just got, initialize the assemblyname + SAFE_NEW(pAssemblyName, AssemblyName); + IF_FAIL_GO(pAssemblyName->Init(pIMetaDataAssemblyImport, PeKind)); + + // Validate architecture + if (!BINDER_SPACE::Assembly::IsValidArchitecture(pAssemblyName->GetArchitecture())) + { + IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BAD_FORMAT)); + } + // Ensure we are not being asked to bind to a TPA assembly + // + // Easy out for mscorlib + if (pAssemblyName->IsMscorlib()) + { + IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); + } + + { + SString& simpleName = pAssemblyName->GetSimpleName(); + SimpleNameToFileNameMap * tpaMap = GetAppContext()->GetTpaList(); + if (tpaMap->LookupPtr(simpleName.GetUnicode()) != NULL) + { + // The simple name of the assembly being requested to be bound was found in the TPA list. + // Now, perform the actual bind to see if the assembly was really in the TPA assembly list or not. + hr = BindAssemblyByNameWorker(pAssemblyName, &pCoreCLRFoundAssembly, true /* excludeAppPaths */); + if (SUCCEEDED(hr)) + { + if (pCoreCLRFoundAssembly->GetIsInGAC()) + { + // If we were able to bind to a TPA assembly, then fail the load + IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); + } + } + } + + hr = AssemblyBinder::BindUsingPEImage(&m_appContext, pAssemblyName, pPEImage, PeKind, pIMetaDataAssemblyImport, &pCoreCLRFoundAssembly); + if (hr == S_OK) + { + _ASSERTE(pCoreCLRFoundAssembly != NULL); + pCoreCLRFoundAssembly->SetBinder(this); + *ppAssembly = pCoreCLRFoundAssembly.Extract(); + } + } +Exit:; + } + EX_CATCH_HRESULT(hr); + + return hr; +} +#endif // !defined(CROSSGEN_COMPILE) + HRESULT CLRPrivBinderCoreCLR::VerifyBind(IAssemblyName *AssemblyName, ICLRPrivAssembly *pAssembly, ICLRPrivAssemblyInfo *pAssemblyInfo) diff --git a/src/binder/inc/clrprivbindercoreclr.h b/src/binder/inc/clrprivbindercoreclr.h index 38e43f706c..36ecaf4195 100644 --- a/src/binder/inc/clrprivbindercoreclr.h +++ b/src/binder/inc/clrprivbindercoreclr.h @@ -66,6 +66,9 @@ public: #ifndef CROSSGEN_COMPILE HRESULT PreBindByteArray(PEImage *pPEImage, BOOL fInspectionOnly); + HRESULT BindUsingPEImage( /* in */ PEImage *pPEImage, + /* in */ BOOL fIsNativeImage, + /* [retval][out] */ ICLRPrivAssembly **ppAssembly); #endif // CROSSGEN_COMPILE HRESULT BindAssemblyByNameWorker( @@ -73,11 +76,25 @@ public: BINDER_SPACE::Assembly **ppCoreCLRFoundAssembly, bool excludeAppPaths); + INT_PTR GetManagedTPABinderInstance() + { + return m_ptrManagedAssemblyLoadContext; + } + + void SetManagedTPABinderInstance(INT_PTR ptrManagedTPABinderInstance) + { + _ASSERTE(m_ptrManagedAssemblyLoadContext == NULL); + + m_ptrManagedAssemblyLoadContext = ptrManagedTPABinderInstance; + } + //========================================================================= // Internal implementation details //------------------------------------------------------------------------- private: BINDER_SPACE::ApplicationContext m_appContext; + + INT_PTR m_ptrManagedAssemblyLoadContext; }; #endif // __CLR_PRIV_BINDER_CORECLR_H__ |