diff options
Diffstat (limited to 'src/vm/assemblyspec.cpp')
-rw-r--r-- | src/vm/assemblyspec.cpp | 453 |
1 files changed, 0 insertions, 453 deletions
diff --git a/src/vm/assemblyspec.cpp b/src/vm/assemblyspec.cpp index 00f0efd18f..13b1992b4a 100644 --- a/src/vm/assemblyspec.cpp +++ b/src/vm/assemblyspec.cpp @@ -18,21 +18,11 @@ #include <stdlib.h> -#ifdef FEATURE_FUSION -#include "actasm.h" -#include "appctx.h" -#endif #include "assemblyspec.hpp" #include "security.h" #include "eeconfig.h" #include "strongname.h" #include "strongnameholders.h" -#ifdef FEATURE_FUSION -#include "assemblysink.h" -#include "dbglog.h" -#include "bindinglog.hpp" -#include "assemblyfilehash.h" -#endif #include "mdaassistants.h" #include "eventtrace.h" @@ -261,41 +251,6 @@ HRESULT AssemblySpec::InitializeSpecInternal(mdToken kAssemblyToken, return hr; } // AssemblySpec::InitializeSpecInternal -#ifdef FEATURE_FUSION -void AssemblySpec::InitializeSpec(IAssemblyName *pName, - DomainAssembly *pStaticParent /*=NULL*/ , - BOOL fIntrospectionOnly /*=FALSE*/ ) -{ - CONTRACTL - { - INSTANCE_CHECK; - GC_TRIGGERS; - THROWS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - // Normalize this boolean as it tends to be used for comparisons - m_fIntrospectionOnly = !!fIntrospectionOnly; - IfFailThrow(Init(pName)); - - // For static binds, we cannot reference a strongly named assembly from a weakly named one. - // (Note that this constraint doesn't apply to dynamic binds which is why this check is - // not farther down the stack.) - - if (pStaticParent != NULL) { - if (pStaticParent->GetFile()->IsStrongNamed() && !IsStrongNamed()) - { - EEFileLoadException::Throw(this, FUSION_E_PRIVATE_ASM_DISALLOWED); - } - SetParentAssembly(pStaticParent); - } - - // Extract embedded WinRT name, if present. - ParseEncodedName(); -} -#endif //FEATURE_FUSION #ifdef FEATURE_MIXEDMODE void AssemblySpec::InitializeSpec(HMODULE hMod, @@ -388,146 +343,6 @@ void AssemblySpec::InitializeSpec(PEAssembly * pFile) #ifndef CROSSGEN_COMPILE // This uses thread storage to allocate space. Please use Checkpoint and release it. -#ifdef FEATURE_FUSION -HRESULT AssemblySpec::InitializeSpec(StackingAllocator* alloc, ASSEMBLYNAMEREF* pName, - BOOL fParse /*=TRUE*/, BOOL fIntrospectionOnly /*=FALSE*/) -{ - CONTRACTL - { - INSTANCE_CHECK; - THROWS; - MODE_COOPERATIVE; - GC_TRIGGERS; - PRECONDITION(CheckPointer(alloc)); - PRECONDITION(CheckPointer(pName)); - PRECONDITION(IsProtectedByGCFrame(pName)); - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - // Simple name - if ((*pName)->GetSimpleName() != NULL) { - WCHAR* pString; - int iString; - ((STRINGREF) (*pName)->GetSimpleName())->RefInterpretGetStringValuesDangerousForGC(&pString, &iString); - DWORD lgth = WszWideCharToMultiByte(CP_UTF8, 0, pString, iString, NULL, 0, NULL, NULL); - if (lgth + 1 < lgth) - ThrowHR(E_INVALIDARG); - LPSTR lpName = (LPSTR) alloc->Alloc(S_UINT32(lgth) + S_UINT32(1)); - WszWideCharToMultiByte(CP_UTF8, 0, pString, iString, - lpName, lgth+1, NULL, NULL); - lpName[lgth] = '\0'; - m_pAssemblyName = lpName; - } - - if (fParse) { - HRESULT hr = ParseName(); - // Sometimes Fusion flags invalid characters in the name, sometimes it doesn't - // depending on where the invalid characters are - // We want to Raise the assembly resolve event on all invalid characters - // but calling ParseName before checking for invalid characters gives Fusion a chance to - // parse the rest of the name (to get a public key token, etc.) - if ((hr == FUSION_E_INVALID_NAME) || (!IsValidAssemblyName())) { - // This is the only case where we do not throw on an error - // We don't want to throw so as to give the caller a chance to call RaiseAssemblyResolveEvent - // The only caller that cares is System.Reflection.Assembly.InternalLoad which calls us through - // AssemblyNameNative::Init - return FUSION_E_INVALID_NAME; - } - else - IfFailThrow(hr); - } - else { - // Flags - m_dwFlags = (*pName)->GetFlags(); - - // Version - VERSIONREF version = (VERSIONREF) (*pName)->GetVersion(); - if(version == NULL) { - m_context.usMajorVersion = (USHORT)-1; - m_context.usMinorVersion = (USHORT)-1; - m_context.usBuildNumber = (USHORT)-1; - m_context.usRevisionNumber = (USHORT)-1; - } - else { - m_context.usMajorVersion = (USHORT)version->GetMajor(); - m_context.usMinorVersion = (USHORT)version->GetMinor(); - m_context.usBuildNumber = (USHORT)version->GetBuild(); - m_context.usRevisionNumber = (USHORT)version->GetRevision(); - } - - m_context.szLocale = 0; - - if ((*pName)->GetCultureInfo() != NULL) - { - struct _gc { - OBJECTREF cultureinfo; - STRINGREF pString; - } gc; - - gc.cultureinfo = (*pName)->GetCultureInfo(); - gc.pString = NULL; - - GCPROTECT_BEGIN(gc); - - MethodDescCallSite getName(METHOD__CULTURE_INFO__GET_NAME, &gc.cultureinfo); - - ARG_SLOT args[] = { - ObjToArgSlot(gc.cultureinfo) - }; - gc.pString = getName.Call_RetSTRINGREF(args); - if (gc.pString != NULL) { - WCHAR* pString; - int iString; - gc.pString->RefInterpretGetStringValuesDangerousForGC(&pString, &iString); - DWORD lgth = WszWideCharToMultiByte(CP_UTF8, 0, pString, iString, NULL, 0, NULL, NULL); - LPSTR lpLocale = (LPSTR) alloc->Alloc(S_UINT32(lgth) + S_UINT32(1)); - WszWideCharToMultiByte(CP_UTF8, 0, pString, iString, - lpLocale, lgth+1, NULL, NULL); - lpLocale[lgth] = '\0'; - m_context.szLocale = lpLocale; - } - GCPROTECT_END(); - } - - // Strong name - // Note that we prefer to take a public key token if present, - // even if flags indicate a full public key - if ((*pName)->GetPublicKeyToken() != NULL) { - m_dwFlags &= ~afPublicKey; - PBYTE pArray = NULL; - pArray = (*pName)->GetPublicKeyToken()->GetDirectPointerToNonObjectElements(); - m_cbPublicKeyOrToken = (*pName)->GetPublicKeyToken()->GetNumComponents(); - m_pbPublicKeyOrToken = new (alloc) BYTE[m_cbPublicKeyOrToken]; - memcpy(m_pbPublicKeyOrToken, pArray, m_cbPublicKeyOrToken); - } - else if ((*pName)->GetPublicKey() != NULL) { - m_dwFlags |= afPublicKey; - PBYTE pArray = NULL; - pArray = (*pName)->GetPublicKey()->GetDirectPointerToNonObjectElements(); - m_cbPublicKeyOrToken = (*pName)->GetPublicKey()->GetNumComponents(); - m_pbPublicKeyOrToken = new (alloc) BYTE[m_cbPublicKeyOrToken]; - memcpy(m_pbPublicKeyOrToken, pArray, m_cbPublicKeyOrToken); - } - } - - // Hash for control - // <TODO>@TODO cts, can we use unsafe in this case!!!</TODO> - if ((*pName)->GetHashForControl() != NULL) - SetHashForControl((*pName)->GetHashForControl()->GetDataPtr(), - (*pName)->GetHashForControl()->GetNumComponents(), - (*pName)->GetHashAlgorithmForControl()); - - // Normalize this boolean as it tends to be used for comparisons - m_fIntrospectionOnly = !!fIntrospectionOnly; - - // Extract embedded WinRT name, if present. - ParseEncodedName(); - - return S_OK; -} - -#else // FEATURE_FUSION HRESULT AssemblySpec::InitializeSpec(StackingAllocator* alloc, ASSEMBLYNAMEREF* pName, BOOL fParse /*=TRUE*/, BOOL fIntrospectionOnly /*=FALSE*/) { @@ -687,7 +502,6 @@ HRESULT AssemblySpec::InitializeSpec(StackingAllocator* alloc, ASSEMBLYNAMEREF* return S_OK; } -#endif // FEATURE_FUSION void AssemblySpec::AssemblyNameInit(ASSEMBLYNAMEREF* pAsmName, PEImage* pImageInfo) { @@ -851,213 +665,6 @@ void AssemblySpec::SetCodeBase(StackingAllocator* alloc, STRINGREF *pCodeBase) #endif // CROSSGEN_COMPILE -#ifdef FEATURE_FUSION - -/* static */ -void AssemblySpec::DemandFileIOPermission(PEAssembly *pFile) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - PRECONDITION(CheckPointer(pFile)); - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - // should have already checked permission if the codebase is set - if (!GetCodeBase()) { - - if (pFile->IsBindingCodeBase()) { - if (pFile->IsSourceDownloadCache()) { - StackSString check; - pFile->GetCodeBase(check); - - DemandFileIOPermission(check, FALSE, FILE_WEBPERM); - } - else - DemandFileIOPermission(pFile->GetPath(), TRUE, FILE_READANDPATHDISC); - } - } -} - -STDAPI RuntimeCheckLocationAccess(LPCWSTR wszLocation) -{ - - if (GetThread()==NULL) - return S_FALSE; - - CONTRACTL - { - NOTHROW; - MODE_ANY; - GC_TRIGGERS; - PRECONDITION(CheckPointer(wszLocation)); - } - CONTRACTL_END; - OVERRIDE_LOAD_LEVEL_LIMIT(FILE_ACTIVE); - HRESULT hr=S_OK; - DWORD dwDemand = 0; - - if (SString::_wcsnicmp(wszLocation, W("file"), 4)) - dwDemand = AssemblySpec::FILE_WEBPERM; - else - dwDemand = AssemblySpec::FILE_READANDPATHDISC; - - EX_TRY - { - AssemblySpec::DemandFileIOPermission(wszLocation, - FALSE, - dwDemand); - } - EX_CATCH_HRESULT(hr); - return hr; - -} - -/* static */ -void AssemblySpec::DemandFileIOPermission(LPCWSTR wszCodeBase, - BOOL fHavePath, - DWORD dwDemandFlag) -{ - CONTRACTL - { - THROWS; - GC_TRIGGERS; - MODE_ANY; - PRECONDITION(CheckPointer(wszCodeBase)); - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - GCX_COOP(); - - MethodDescCallSite demandPermission(METHOD__ASSEMBLY__DEMAND_PERMISSION); - - STRINGREF codeBase = NULL; - GCPROTECT_BEGIN(codeBase); - - codeBase = StringObject::NewString(wszCodeBase); - ARG_SLOT args[3] = - { - ObjToArgSlot(codeBase), - BoolToArgSlot(fHavePath), - dwDemandFlag - }; - demandPermission.Call(args); - GCPROTECT_END(); -} - -BOOL AssemblySpec::FindAssemblyFile(AppDomain* pAppDomain, BOOL fThrowOnFileNotFound, - IAssembly** ppIAssembly, IHostAssembly **ppIHostAssembly, IBindResult** ppNativeFusionAssembly, - IFusionBindLog** ppFusionLog, HRESULT *pHRBindResult, StackCrawlMark *pCallerStackMark /* = NULL */, - AssemblyLoadSecurity *pLoadSecurity /* = NULL */) -{ - CONTRACTL - { - INSTANCE_CHECK; - THROWS; - GC_TRIGGERS; - MODE_ANY; - PRECONDITION(CheckPointer(pAppDomain)); - PRECONDITION(CheckPointer(pHRBindResult)); - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACTL_END; - - GCX_PREEMP(); - - IApplicationContext *pFusionContext = pAppDomain->GetFusionContext(); - - AssemblySink* pSink = pAppDomain->AllocateAssemblySink(this); - SafeComHolderPreemp<IAssemblyBindSink> sinkholder(pSink); - - BOOL fSuppressSecurityChecks = pLoadSecurity != NULL && pLoadSecurity->m_fSuppressSecurityChecks; - - if (!GetCodeBase() && !fSuppressSecurityChecks) - pSink->RequireCodebaseSecurityCheck(); - - BOOL fIsWellKnown = FALSE; - HRESULT hr = S_OK; - - IfFailGo(AssemblySpec::LoadAssembly(pFusionContext, - pSink, - ppIAssembly, - ppIHostAssembly, - ppNativeFusionAssembly, - IsIntrospectionOnly(), - fSuppressSecurityChecks)); - - // Host should have already done appropriate permission demand - if (!(*ppIHostAssembly)) { - DWORD dwLocation; - IfFailGo((*ppIAssembly)->GetAssemblyLocation(&dwLocation)); - - fIsWellKnown = (dwLocation == ASMLOC_UNKNOWN); - - // check if it was cached, where a codebase had originally loaded it - if (pSink->DoCodebaseSecurityCheck() && - !fSuppressSecurityChecks && - (dwLocation & ASMLOC_CODEBASE_HINT)) { - if ((dwLocation & ASMLOC_LOCATION_MASK) == ASMLOC_DOWNLOAD_CACHE) { - StackSString codeBase; - SafeComHolderPreemp<IAssemblyName> pNameDef; - - // <TODO>We could be caching the IAssemblyName and codebase</TODO> - IfFailGo((*ppIAssembly)->GetAssemblyNameDef(&pNameDef)); - - FusionBind::GetAssemblyNameStringProperty(pNameDef, ASM_NAME_CODEBASE_URL, codeBase); - - DemandFileIOPermission(codeBase, FALSE, FILE_WEBPERM); - } - else if ((dwLocation & ASMLOC_LOCATION_MASK) != ASMLOC_GAC) { - StackSString path; - FusionBind::GetAssemblyManifestModulePath((*ppIAssembly), path); - - DemandFileIOPermission(path, TRUE, FILE_READANDPATHDISC); - } - } - - // Verify control hash - if (m_HashForControl.GetSize() > 0) { - StackSString path; - - FusionBind::GetAssemblyManifestModulePath((*ppIAssembly), path); - - AssemblyFileHash fileHash; - IfFailGo(fileHash.SetFileName(path)); - IfFailGo(fileHash.CalculateHash(m_dwHashAlg)); - - if (!m_HashForControl.Equals(fileHash.GetHash(), fileHash.GetHashSize())) - IfFailGo(FUSION_E_REF_DEF_MISMATCH); - } - } - -#ifdef MDA_SUPPORTED - MdaLoadFromContext* pProbe = MDA_GET_ASSISTANT(LoadFromContext); - if (pProbe) { - pProbe->NowLoading(ppIAssembly, pCallerStackMark); - } -#endif - - *ppFusionLog = pSink->m_pFusionLog; - if (*ppFusionLog) - (*ppFusionLog)->AddRef(); - return fIsWellKnown; - - ErrExit: - { - - *pHRBindResult = hr; - - if (fThrowOnFileNotFound || (!Assembly::FileNotFound(hr))) - EEFileLoadException::Throw(this, pSink->m_pFusionLog, hr); - } - - return FALSE; -} -#endif // FEATURE_FUSION void AssemblySpec::MatchRetargetedPublicKeys(Assembly *pAssembly) { @@ -1070,28 +677,6 @@ void AssemblySpec::MatchRetargetedPublicKeys(Assembly *pAssembly) PRECONDITION(CheckPointer(pAssembly)); } CONTRACTL_END; -#ifdef FEATURE_FUSION - GCX_PREEMP(); - - // Manually apply fusion policy to obtain retargeted public key - SafeComHolderPreemp<IAssemblyName> pRequestedAssemblyName(NULL); - SafeComHolderPreemp<IAssemblyName> pPostPolicyAssemblyName(NULL); - IfFailThrow(CreateFusionName(&pRequestedAssemblyName)); - HRESULT hr = PreBindAssembly(GetAppDomain()->GetFusionContext(), - pRequestedAssemblyName, - NULL, // pAsmParent - &pPostPolicyAssemblyName, - NULL // pvReserved - ); - if (SUCCEEDED(hr) - || (FAILED(hr) && (hr == FUSION_E_REF_DEF_MISMATCH))) { - IAssemblyName *pResultAssemblyName = pAssembly->GetFusionAssemblyName(); - if (pResultAssemblyName - && pPostPolicyAssemblyName - && pResultAssemblyName->IsEqual(pPostPolicyAssemblyName, ASM_CMPF_PUBLIC_KEY_TOKEN) == S_OK) - return; - } -#endif // FEATURE_FUSION ThrowHR(FUSION_E_REF_DEF_MISMATCH); } @@ -1164,11 +749,6 @@ PEAssembly *AssemblySpec::ResolveAssemblyFile(AppDomain *pDomain, BOOL fPreBind) Assembly *pAssembly = pDomain->RaiseAssemblyResolveEvent(this, IsIntrospectionOnly(), fPreBind); if (pAssembly != NULL) { -#ifdef FEATURE_FUSION - if (!IsIntrospectionOnly() && IsLoggingNeeded()) { - BinderLogging::BindingLog::CacheResultOfAssemblyResolveEvent(pDomain->GetFusionContext(), GetParentLoadContext(), pAssembly); - } -#endif PEAssembly *pFile = pAssembly->GetManifestFile(); pFile->AddRef(); @@ -1457,7 +1037,6 @@ Assembly *AssemblySpec::LoadAssembly(LPCWSTR pFilePath) RETURN spec.LoadAssembly(FILE_LOADED); } -#ifndef FEATURE_FUSION HRESULT AssemblySpec::CheckFriendAssemblyName() { WRAPPER_NO_CONTRACT; @@ -1475,7 +1054,6 @@ HRESULT AssemblySpec::CheckFriendAssemblyName() return S_OK; } } -#endif //FEATURE_FUSION HRESULT AssemblySpec::EmitToken( IMetaDataAssemblyEmit *pEmit, @@ -2241,12 +1819,6 @@ BOOL DomainAssemblyCache::CompareBindingSpec(UPTR spec1, UPTR spec2) AssemblySpec* pSpec1 = (AssemblySpec*) (spec1 << 1); AssemblyEntry* pEntry2 = (AssemblyEntry*) spec2; -#if defined(FEATURE_FUSION) - AssemblySpec* pSpec2 = &pEntry2->spec; - _ASSERTE(pSpec1->GetAppDomain() == pSpec2->GetAppDomain()); - if (pSpec1->GetAppDomain()->HasLoadContextHostBinder()) - return (CLRPrivBinderUtil::CompareHostBinderSpecs(pSpec1,pSpec2)); -#endif if ((!pSpec1->CompareEx(&pEntry2->spec)) || @@ -2324,31 +1896,6 @@ VOID DomainAssemblyCache::InsertEntry(AssemblySpec* pSpec, LPVOID pData1, LPVOID } -#ifdef FEATURE_FUSION - -IAssembly * AssemblySpec::GetParentIAssembly() -{ - LIMITED_METHOD_CONTRACT; - if(m_pParentAssembly) - return m_pParentAssembly->GetFile()->GetFusionAssembly(); - - return NULL; -} - -LPCVOID AssemblySpec::GetParentAssemblyPtr() -{ - LIMITED_METHOD_CONTRACT; - if(m_pParentAssembly) - { - if (m_pParentAssembly->GetFile()->HasHostAssembly()) - return m_pParentAssembly->GetFile()->GetHostAssembly(); - else - return m_pParentAssembly->GetFile()->GetFusionAssembly(); - } - return NULL; -} - -#endif //FEATURE_FUSION |