diff options
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/peimagelayout.cpp | 110 | ||||
-rw-r--r-- | src/vm/peimagelayout.h | 6 |
2 files changed, 0 insertions, 116 deletions
diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index 034b30ed38..ea3d888ebe 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -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) diff --git a/src/vm/peimagelayout.h b/src/vm/peimagelayout.h index 79df992822..557a2a5ffc 100644 --- a/src/vm/peimagelayout.h +++ b/src/vm/peimagelayout.h @@ -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: |