Fix zap and ready to run disabling (#14389)
authorJan Vorlicek <janvorli@microsoft.com>
Mon, 9 Oct 2017 20:07:54 +0000 (22:07 +0200)
committerGitHub <noreply@github.com>
Mon, 9 Oct 2017 20:07:54 +0000 (22:07 +0200)
* 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
src/vm/readytoruninfo.cpp

index 94810a0..2096a9b 100644 (file)
@@ -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())
index 5ac1eb1..bcb8e83 100644 (file)
@@ -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");