From 0a8bd5554a736de337ca6c24eba3de3ec0decfd1 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Mon, 9 Oct 2017 22:07:54 +0200 Subject: [PATCH] Fix zap and ready to run disabling (#14389) * Fix zap and ready to run disabling While the COMPlus_ZapDisable and COMPlus_ReadyToRun config settings can be used to disable using crossgened / ready to run images, loading IL from such images fails. This change foxes that. * Reflect PR feedback Remove ReadyToRunInfo::IsReadyToRunEnabled from Module::Initialize again and move the same check in the ReadyToRunInfo::Initialize before we start checking the PE file properties. --- src/vm/peimagelayout.cpp | 4 ++-- src/vm/readytoruninfo.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index 94810a0..2096a9b 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -445,7 +445,7 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner) // if (!HasNativeHeader()) // ThrowHR(COR_E_BADIMAGEFORMAT); - if (HasNativeHeader()) + if (HasNativeHeader() && g_fAllowNativeImages) { if (!IsNativeMachineFormat()) ThrowHR(COR_E_BADIMAGEFORMAT); @@ -501,7 +501,7 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner) if (!HasCorHeader()) ThrowHR(COR_E_BADIMAGEFORMAT); - if (HasNativeHeader() || HasReadyToRunHeader()) + if ((HasNativeHeader() || HasReadyToRunHeader()) && g_fAllowNativeImages) { //Do base relocation for PE, if necessary. if (!IsNativeMachineFormat()) diff --git a/src/vm/readytoruninfo.cpp b/src/vm/readytoruninfo.cpp index 5ac1eb1..bcb8e83 100644 --- a/src/vm/readytoruninfo.cpp +++ b/src/vm/readytoruninfo.cpp @@ -456,6 +456,13 @@ PTR_ReadyToRunInfo ReadyToRunInfo::Initialize(Module * pModule, AllocMemTracker PEFile * pFile = pModule->GetFile(); + if (!IsReadyToRunEnabled()) + { + // Log message is ignored in this case. + DoLog(NULL); + return NULL; + } + // Ignore ReadyToRun for introspection-only loads if (pFile->IsIntrospectionOnly()) { @@ -476,13 +483,6 @@ PTR_ReadyToRunInfo ReadyToRunInfo::Initialize(Module * pModule, AllocMemTracker return NULL; } - if (!IsReadyToRunEnabled()) - { - // Log message is ignored in this case. - DoLog(NULL); - return NULL; - } - if (CORProfilerDisableAllNGenImages() || CORProfilerUseProfileImages()) { DoLog("Ready to Run disabled - profiler disabled native images"); -- 2.7.4