Remove ConvertILOnlyPE32ToPE64 and ConvertILOnlyPE32ToPE64Worker (#16676)
authorEgor Chesakov <Egor.Chesakov@microsoft.com>
Thu, 1 Mar 2018 06:25:16 +0000 (22:25 -0800)
committerJan Kotas <jkotas@microsoft.com>
Thu, 1 Mar 2018 06:25:16 +0000 (22:25 -0800)
src/vm/peimagelayout.cpp
src/vm/peimagelayout.h

index 034b30e..ea3d888 100644 (file)
@@ -590,113 +590,3 @@ PEImageLayout::EnumMemoryRegions(CLRDataEnumMemoryFlags flags)
     PEDecoder::EnumMemoryRegions(flags,false);
 }
 #endif //DACCESS_COMPILE
-
-#if defined(_WIN64) && !defined(DACCESS_COMPILE)
-
-#define IMAGE_HEADER_3264_SIZE_DIFF (sizeof(IMAGE_NT_HEADERS64) - sizeof(IMAGE_NT_HEADERS32)) 
-
-// This function is expected to be in sync with LdrpCorFixupImage in the OS loader implementation (//depot/winmain/minkernel/ntdll/ldrcor.c).
-bool PEImageLayout::ConvertILOnlyPE32ToPE64Worker()
-{
-    CONTRACTL
-    {
-        NOTHROW;
-        GC_NOTRIGGER;
-        MODE_ANY;
-        PRECONDITION(IsILOnly()); // This should be called for IL-Only images
-        PRECONDITION(Has32BitNTHeaders()); // // Image should be marked to have a PE32 header only.
-        PRECONDITION(IsPlatformNeutral());
-    }
-    CONTRACTL_END;
-    
-    PBYTE pImage = (PBYTE)GetBase();
-    
-    IMAGE_DOS_HEADER *pDosHeader = (IMAGE_DOS_HEADER*)pImage;
-    IMAGE_NT_HEADERS32 *pHeader32 = GetNTHeaders32();
-    IMAGE_NT_HEADERS64 *pHeader64 = GetNTHeaders64();
-
-    _ASSERTE(&pHeader32->OptionalHeader.Magic == &pHeader64->OptionalHeader.Magic);
-    _ASSERTE(pHeader32->OptionalHeader.Magic == VAL16(IMAGE_NT_OPTIONAL_HDR32_MAGIC));
-
-    // Move the data directory and section headers down IMAGE_HEADER_3264_SIZE_DIFF bytes.
-    PBYTE pStart32 = (PBYTE) &pHeader32->OptionalHeader.DataDirectory[0];
-    PBYTE pStart64 = (PBYTE) &pHeader64->OptionalHeader.DataDirectory[0];
-    _ASSERTE(pStart64 - pStart32 == IMAGE_HEADER_3264_SIZE_DIFF);
-
-    PBYTE pEnd32 = (PBYTE) (IMAGE_FIRST_SECTION(pHeader32)
-                            + VAL16(pHeader32->FileHeader.NumberOfSections));
-    
-    // On AMD64, used for a 12-byte jump thunk + the original entry point offset.
-    if (((pEnd32 + IMAGE_HEADER_3264_SIZE_DIFF /* delta in headers to compute end of 64bit header */) - pImage) > GetOsPageSize() ) {
-        // This should never happen.  An IL_ONLY image should at most 3 sections.  
-        _ASSERTE(!"ConvertILOnlyPE32ToPE64Worker: Insufficient room to rewrite headers as PE64");
-        return false;
-    }
-
-    memmove(pStart64, pStart32, pEnd32 - pStart32);
-
-    // Move the tail fields in reverse order.
-    pHeader64->OptionalHeader.NumberOfRvaAndSizes = pHeader32->OptionalHeader.NumberOfRvaAndSizes;
-    pHeader64->OptionalHeader.LoaderFlags = pHeader32->OptionalHeader.LoaderFlags;
-    pHeader64->OptionalHeader.SizeOfHeapCommit = VAL64(VAL32(pHeader32->OptionalHeader.SizeOfHeapCommit));
-    pHeader64->OptionalHeader.SizeOfHeapReserve = VAL64(VAL32(pHeader32->OptionalHeader.SizeOfHeapReserve));
-    pHeader64->OptionalHeader.SizeOfStackCommit = VAL64(VAL32(pHeader32->OptionalHeader.SizeOfStackCommit));
-    pHeader64->OptionalHeader.SizeOfStackReserve = VAL64(VAL32(pHeader32->OptionalHeader.SizeOfStackReserve));
-
-    // One more field that's not the same
-    pHeader64->OptionalHeader.ImageBase = VAL64(VAL32(pHeader32->OptionalHeader.ImageBase));
-
-    // The optional header changed size.
-    pHeader64->FileHeader.SizeOfOptionalHeader = VAL16(VAL16(pHeader64->FileHeader.SizeOfOptionalHeader) + 16);
-    pHeader64->OptionalHeader.Magic = VAL16(IMAGE_NT_OPTIONAL_HDR64_MAGIC);
-
-    // Now we just have to make a new 16-byte PPLABEL_DESCRIPTOR for the new entry point address & gp
-    PBYTE pEnd64 = (PBYTE) (IMAGE_FIRST_SECTION(pHeader64) + VAL16(pHeader64->FileHeader.NumberOfSections));
-    pHeader64->OptionalHeader.AddressOfEntryPoint = VAL32((ULONG) (pEnd64 - pImage));
-    
-    // Should be PE32+ now
-    _ASSERTE(!Has32BitNTHeaders());
-    
-    return true;
-}
-
-bool PEImageLayout::ConvertILOnlyPE32ToPE64()
-{
-    CONTRACTL
-    {
-        NOTHROW;
-        GC_NOTRIGGER;
-        MODE_ANY;
-        PRECONDITION(IsILOnly()); // This should be called for IL-Only images
-        PRECONDITION(Has32BitNTHeaders()); 
-    }
-    CONTRACTL_END;
-    
-    bool fConvertedToPE64 = false;
-
-    // Only handle platform neutral IL assemblies
-    if (!IsPlatformNeutral())
-    {
-        return false;
-    }
-
-    PBYTE pageBase = (PBYTE)GetBase();
-    DWORD oldProtect;
-
-    if (!ClrVirtualProtect(pageBase, GetOsPageSize(), PAGE_READWRITE, &oldProtect))
-    {
-        // We are not going to be able to update header.
-        return false;
-    }
-        
-    fConvertedToPE64 = ConvertILOnlyPE32ToPE64Worker();
-    
-    DWORD ignore;
-    if (!ClrVirtualProtect(pageBase, GetOsPageSize(), oldProtect, &ignore))
-    {
-        // This is not so bad; just ignore it
-    }
-    
-    return fConvertedToPE64;
-}
-#endif // defined(_WIN64) && !defined(DACCESS_COMPILE)
index 79df992..557a2a5 100644 (file)
@@ -77,12 +77,6 @@ public:
     void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
 #endif
 
-#if defined(_WIN64) && !defined(DACCESS_COMPILE)
-    bool ConvertILOnlyPE32ToPE64();
-private:
-    bool ConvertILOnlyPE32ToPE64Worker();
-#endif // defined(_WIN64) && !defined(DACCESS_COMPILE)
-    
 private:
     Volatile<LONG> m_refCount;
 public: