diff options
author | danmosemsft <danmose@microsoft.com> | 2017-02-14 21:07:49 -0800 |
---|---|---|
committer | danmosemsft <danmose@microsoft.com> | 2017-02-14 21:24:05 -0800 |
commit | 16eb7551d9f5ea8ec593dc86b789df4db2198a4b (patch) | |
tree | efec4968d631de26b785b962770e50c5874a83e8 /src/vm/pefile.cpp | |
parent | 1c1cc23cddad0eb765752d774a48dc686ae1d61f (diff) | |
download | coreclr-16eb7551d9f5ea8ec593dc86b789df4db2198a4b.tar.gz coreclr-16eb7551d9f5ea8ec593dc86b789df4db2198a4b.tar.bz2 coreclr-16eb7551d9f5ea8ec593dc86b789df4db2198a4b.zip |
Remove never defined FEATURE_MIXEDMODE
Diffstat (limited to 'src/vm/pefile.cpp')
-rw-r--r-- | src/vm/pefile.cpp | 299 |
1 files changed, 0 insertions, 299 deletions
diff --git a/src/vm/pefile.cpp b/src/vm/pefile.cpp index f833a17c36..e322b26ddb 100644 --- a/src/vm/pefile.cpp +++ b/src/vm/pefile.cpp @@ -223,215 +223,6 @@ BOOL PEFile::CanLoadLibrary() return IsILOnly(); } -#ifdef FEATURE_MIXEDMODE - -#ifndef CROSSGEN_COMPILE - -// Returns TRUE if this file references managed CRT (msvcmNN*). -BOOL PEFile::ReferencesManagedCRT() -{ - STANDARD_VM_CONTRACT; - - IMDInternalImportHolder pImport = GetMDImport(); - MDEnumHolder hEnum(pImport); - - IfFailThrow(pImport->EnumInit(mdtModuleRef, mdTokenNil, &hEnum)); - - mdModuleRef tk; - while (pImport->EnumNext(&hEnum, &tk)) - { - // we are looking for "msvcmNN*" - LPCSTR szName; - IfFailThrow(pImport->GetModuleRefProps(tk, &szName)); - - if (_strnicmp(szName, "msvcm", 5) == 0 && isdigit(szName[5]) && isdigit(szName[6])) - { - return TRUE; - } - } - - return FALSE; -} - -void PEFile::CheckForDisallowedInProcSxSLoadWorker() -{ - STANDARD_VM_CONTRACT; - - // provide an opt-out switch for now - if (CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_DisableIJWVersionCheck) != 0) - return; - - // ************************************************************************************************ - // 1. See if this file should be checked - // The following checks filter out non-mixed mode assemblies that don't reference msvcmNN*. We only - // care about non-ILONLY images (IJW) or 2.0 C++/CLI pure images. - if (IsResource() || IsDynamic()) - return; - - // check the metadata version string - COUNT_T size; - PVOID pMetaData = (PVOID)GetMetadata(&size); - if (!pMetaData) - { - // No metadata section? Well somebody should have caught this earlier so report as - // ExecutionEngine rather than BIF. - EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); - } - - LPCSTR pVersion = NULL; - IfFailThrow(GetImageRuntimeVersionString(pMetaData, &pVersion)); - - char chV; - unsigned uiMajor, uiMinor; - BOOL fLegacyImage = (sscanf_s(pVersion, "%c%u.%u", &chV, 1, &uiMajor, &uiMinor) == 3 && (chV == W('v') || chV == W('V')) && uiMajor <= 2); - - // Note that having VTFixups properly working really is limited to non-ILONLY images. In particular, - // the shim does not even attempt to patch ILONLY images in any way with bootstrap thunks. - if (IsILOnly()) - { - // all >2.0 ILONLY images are fine because >2.0 managed CRTs can be loaded in multiple runtimes - if (!fLegacyImage) - return; - - // legacy ILONLY images that don't reference the managed CRT are fine - if (!ReferencesManagedCRT()) - return; - } - - // get the version of this runtime - WCHAR wzThisRuntimeVersion[_MAX_PATH]; - DWORD cchVersion = COUNTOF(wzThisRuntimeVersion); - IfFailThrow(g_pCLRRuntime->GetVersionString(wzThisRuntimeVersion, &cchVersion)); - - // ************************************************************************************************ - // 2. For legacy assemblies, verify that legacy APIs are/would be bound to this runtime - if (fLegacyImage) - { - WCHAR wzAPIVersion[_MAX_PATH]; - bool fLegacyAPIsAreBound = false; - - { // Check if the legacy APIs have already been bound to us using the new hosting APIs. - ReleaseHolder<ICLRMetaHost> pMetaHost; - IfFailThrow(CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost)); - - ReleaseHolder<ICLRRuntimeInfo> pInfo; - // Returns S_FALSE when no runtime is currently bound, S_OK when one is. - HRESULT hr = pMetaHost->QueryLegacyV2RuntimeBinding(IID_ICLRRuntimeInfo, (LPVOID*)&pInfo); - IfFailThrow(hr); - - if (hr == S_OK) - { // Legacy APIs are bound, now check if they are bound to us. - fLegacyAPIsAreBound = true; - - cchVersion = COUNTOF(wzAPIVersion); - IfFailThrow(pInfo->GetVersionString(wzAPIVersion, &cchVersion)); - - if (SString::_wcsicmp(wzThisRuntimeVersion, wzAPIVersion) == 0) - { // This runtime is the one bound to the legacy APIs, ok to load legacy assembly. - return; - } - } - } - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4996) // we are going to call deprecated APIs -#endif - // We need the above QueryLegacyV2RuntimeBinding check because GetRequestedRuntimeInfo will not take into - // account the current binding, which could have been set by the host rather than through an EXE config. - // If, however, the legacy APIs are not bound (indicated in fLegacyAPIsAreBound) then we can assume that - // the legacy APIs would bind using the equivalent of CorBindToRuntime(NULL) as a result of loading this - // legacy IJW assembly, and so we use GetRequestedRuntimeInfo to check without actually causing the bind. - // By avoiding causing the bind, we avoid a binding side effect in the failure case. - if (!fLegacyAPIsAreBound && - SUCCEEDED(GetRequestedRuntimeInfo(NULL, NULL, NULL, 0, // pExe, pwszVersion, pConfigurationFile, startupFlags - RUNTIME_INFO_UPGRADE_VERSION | RUNTIME_INFO_DONT_RETURN_DIRECTORY | RUNTIME_INFO_DONT_SHOW_ERROR_DIALOG, - NULL, 0, NULL, // pDirectory, dwDirectory, pdwDirectoryLength - wzAPIVersion, COUNTOF(wzAPIVersion), &cchVersion))) // pVersion, cchBuffer, pdwLength - { - if (SString::_wcsicmp(wzThisRuntimeVersion, wzAPIVersion) == 0) - { - // it came back as this version - call CorBindToRuntime to actually bind it - ReleaseHolder<ICLRRuntimeHost> pHost; - IfFailThrow(CorBindToRuntime(wzAPIVersion, NULL, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&pHost)); - - // and verify that nobody beat us to it - IfFailThrow(GetCORVersion(wzAPIVersion, COUNTOF(wzAPIVersion), &cchVersion)); - - if (SString::_wcsicmp(wzThisRuntimeVersion, wzAPIVersion) == 0) - { - // we have verified that when the assembly calls CorBindToRuntime(NULL), - // it will get this runtime, so we allow it to be loaded - return; - } - } - } -#ifdef _MSC_VER -#pragma warning(pop) -#endif - - MAKE_WIDEPTR_FROMUTF8(pwzVersion, pVersion); - - ExternalLog(LF_LOADER, LL_ERROR, W("ERR: Rejecting IJW module built against %s because it could be loaded into another runtime in this process."), pwzVersion); - COMPlusThrow(kFileLoadException, IDS_EE_IJWLOAD_CROSSVERSION_DISALLOWED, pwzVersion, QUOTE_MACRO_L(VER_MAJORVERSION.VER_MINORVERSION)); - } - - // ************************************************************************************************ - // 3. For 4.0+ assemblies, verify that it hasn't been loaded into another runtime - ReleaseHolder<ICLRRuntimeHostInternal> pRuntimeHostInternal; - IfFailThrow(g_pCLRRuntime->GetInterface(CLSID_CLRRuntimeHostInternal, - IID_ICLRRuntimeHostInternal, - &pRuntimeHostInternal)); - - PTR_VOID pModuleBase = GetLoadedIL()->GetBase(); - - ReleaseHolder<ICLRRuntimeInfo> pRuntimeInfo; - HRESULT hr = pRuntimeHostInternal->LockModuleForRuntime((BYTE *)pModuleBase, IID_ICLRRuntimeInfo, &pRuntimeInfo); - - IfFailThrow(hr); - - if (hr == S_OK) - { - // this runtime was the first one to lock the module - return; - } - - // another runtime has loaded this module so we have to block the load - WCHAR wzLoadedRuntimeVersion[_MAX_PATH]; - cchVersion = COUNTOF(wzLoadedRuntimeVersion); - IfFailThrow(pRuntimeInfo->GetVersionString(wzLoadedRuntimeVersion, &cchVersion)); - - ExternalLog(LF_LOADER, LL_ERROR, W("ERR: Rejecting IJW module because it is already loaded into runtime version %s in this process."), wzLoadedRuntimeVersion); - COMPlusThrow(kFileLoadException, IDS_EE_IJWLOAD_MULTIRUNTIME_DISALLOWED, wzThisRuntimeVersion, wzLoadedRuntimeVersion); -} - -// We don't allow loading IJW and C++/CLI pure images built against <=2.0 if legacy APIs are not bound to this -// runtime. For IJW images built against >2.0, we don't allow the load if the image has already been loaded by -// another runtime in this process. -void PEFile::CheckForDisallowedInProcSxSLoad() -{ - STANDARD_VM_CONTRACT; - - // have we checked this one before? - if (!IsInProcSxSLoadVerified()) - { - CheckForDisallowedInProcSxSLoadWorker(); - - // if no exception was thrown, remember the fact that we don't have to do the check again - SetInProcSxSLoadVerified(); - } -} - -#else // CROSSGEN_COMPILE - -void PEFile::CheckForDisallowedInProcSxSLoad() -{ - // Noop for crossgen -} - -#endif // CROSSGEN_COMPILE - -#endif // FEATURE_MIXEDMODE //----------------------------------------------------------------------------------------------------- @@ -501,12 +292,6 @@ void PEFile::LoadLibrary(BOOL allowNativeSkip/*=TRUE*/) // if allowNativeSkip==F // See if we've already loaded it. if (CheckLoaded(allowNativeSkip)) { -#ifdef FEATURE_MIXEDMODE - // Prevent loading C++/CLI images into multiple runtimes in the same process. Note that if ILOnly images - // stop being LoadLibrary'ed, the check for pure 2.0 C++/CLI images will need to be done somewhere else. - if (!IsIntrospectionOnly()) - CheckForDisallowedInProcSxSLoad(); -#endif // FEATURE_MIXEDMODE RETURN; } @@ -597,11 +382,6 @@ void PEFile::LoadLibrary(BOOL allowNativeSkip/*=TRUE*/) // if allowNativeSkip==F } } -#ifdef FEATURE_MIXEDMODE - // Prevent loading C++/CLI images into multiple runtimes in the same process. Note that if ILOnly images - // stop being LoadLibrary'ed, the check for pure 2.0 C++/CLI images will need to be done somewhere else. - CheckForDisallowedInProcSxSLoad(); -#endif // FEATURE_MIXEDMODE RETURN; } @@ -2538,85 +2318,6 @@ PEAssembly *PEAssembly::DoOpenMemory( } #endif // !CROSSGEN_COMPILE -#if defined(FEATURE_MIXEDMODE) && !defined(CROSSGEN_COMPILE) -// Use for main exe loading -// This is also used for "spontaneous" (IJW) dll loading where -// we need to deliver DllMain callbacks, but we should eliminate this case - -/* static */ -PEAssembly *PEAssembly::OpenHMODULE(HMODULE hMod, - IAssembly *pFusionAssembly, - IBindResult *pNativeFusionAssembly, - IFusionBindLog *pFusionLog/*=NULL*/, - BOOL isIntrospectionOnly/*=FALSE*/) -{ - STANDARD_VM_CONTRACT; - - PEAssembly *result = NULL; - - ETWOnStartup (OpenHModule_V1, OpenHModuleEnd_V1); - - EX_TRY - { - result = DoOpenHMODULE(hMod, pFusionAssembly, pNativeFusionAssembly, pFusionLog, isIntrospectionOnly); - } - EX_HOOK - { - Exception *ex = GET_EXCEPTION(); - - // Rethrow non-transient exceptions as file load exceptions with proper - // context - if (!ex->IsTransient()) - EEFileLoadException::Throw(pFusionAssembly, NULL, ex->GetHR(), ex); - } - EX_END_HOOK; - return result; -} - -// Thread stress -class DoOpenHMODULEStress : APIThreadStress -{ -public: - HMODULE hMod; - IAssembly *pFusionAssembly; - IBindResult *pNativeFusionAssembly; - IFusionBindLog *pFusionLog; - DoOpenHMODULEStress(HMODULE hMod, IAssembly *pFusionAssembly, IBindResult *pNativeFusionAssembly, IFusionBindLog *pFusionLog) - : hMod(hMod), pFusionAssembly(pFusionAssembly), pNativeFusionAssembly(pNativeFusionAssembly),pFusionLog(pFusionLog) {LIMITED_METHOD_CONTRACT;} - void Invoke() - { - WRAPPER_NO_CONTRACT; - PEAssemblyHolder result(PEAssembly::OpenHMODULE(hMod, pFusionAssembly,pNativeFusionAssembly, pFusionLog, FALSE)); - } -}; - -/* static */ -PEAssembly *PEAssembly::DoOpenHMODULE(HMODULE hMod, - IAssembly *pFusionAssembly, - IBindResult *pNativeFusionAssembly, - IFusionBindLog *pFusionLog, - BOOL isIntrospectionOnly/*=FALSE*/) -{ - CONTRACT(PEAssembly *) - { - PRECONDITION(CheckPointer(hMod)); - PRECONDITION(CheckPointer(pFusionAssembly)); - PRECONDITION(CheckPointer(pNativeFusionAssembly,NULL_OK)); - POSTCONDITION(CheckPointer(RETVAL)); - THROWS; - GC_TRIGGERS; - MODE_ANY; - INJECT_FAULT(COMPlusThrowOM();); - } - CONTRACT_END; - - DoOpenHMODULEStress ts(hMod, pFusionAssembly, pNativeFusionAssembly, pFusionLog); - - PEImageHolder image(PEImage::LoadImage(hMod)); - - RETURN new PEAssembly(image, NULL, pFusionAssembly, pNativeFusionAssembly, NULL, pFusionLog, NULL, NULL, FALSE, isIntrospectionOnly); -} -#endif // FEATURE_MIXEDMODE && !CROSSGEN_COMPILE PEAssembly* PEAssembly::Open(CoreBindResult* pBindResult, |