Skip to content
Prev Previous commit
Next Next commit
delete MappedImageLayout
  • Loading branch information
VSadov committed Dec 11, 2021
commit 49c759fbbf85eeffe20a2b14474f6cb94c0f8185
4 changes: 1 addition & 3 deletions src/coreclr/inc/pedecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ class PEDecoder
BOOL IsILOnly() const;
CHECK CheckILOnly() const;

void LayoutILOnly(void *base, bool enableExecution) const;

// Strong name & hashing support

BOOL HasStrongNameSignature() const;
Expand Down Expand Up @@ -348,6 +346,7 @@ class PEDecoder
IMAGE_SECTION_HEADER *OffsetToSection(COUNT_T fileOffset) const;

void SetRelocated();
IMAGE_NT_HEADERS* FindNTHeaders() const;

private:

Expand All @@ -364,7 +363,6 @@ class PEDecoder

static PTR_IMAGE_SECTION_HEADER FindFirstSection(IMAGE_NT_HEADERS * pNTHeaders);

IMAGE_NT_HEADERS *FindNTHeaders() const;
IMAGE_COR20_HEADER *FindCorHeader() const;
READYTORUN_HEADER *FindReadyToRunHeader() const;

Expand Down
5 changes: 2 additions & 3 deletions src/coreclr/inc/vptr_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ VPTR_CLASS(TailCallStubManager)
#endif
VPTR_CLASS(CallCountingStubManager)
VPTR_CLASS(PEAssembly)

VPTR_CLASS(PEImageLayout)
VPTR_CLASS(ConvertedImageLayout)
VPTR_CLASS(MappedImageLayout)
#if !defined(TARGET_UNIX)
VPTR_CLASS(LoadedImageLayout)
#endif // !TARGET_UNIX
VPTR_CLASS(FlatImageLayout)

#ifdef FEATURE_COMINTEROP
VPTR_CLASS(ComMethodFrame)
VPTR_CLASS(ComPlusMethodFrame)
Expand Down
7 changes: 6 additions & 1 deletion src/coreclr/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2165,9 +2165,14 @@ void * MAPMapPEFile(HANDLE hFile, off_t offset)
goto done;
}

// For compat reasons we always allow 32bit header.
// We may not get correct preferred ImageBase, but otherwise 32bit header is the same for our uses here.
// We will not patch the header into platform bitness though, since coreclr does not require that.
// NOTE: actual checks whether the PE is platform-specific or contains native code will happen later as needed.
if ((VAL16(IMAGE_DOS_SIGNATURE) != VAL16(dosHeader.e_magic))
|| (VAL32(IMAGE_NT_SIGNATURE) != VAL32(ntHeader.Signature))
|| (VAL16(IMAGE_NT_OPTIONAL_HDR_MAGIC) != VAL16(ntHeader.OptionalHeader.Magic) ) )
|| ((VAL16(IMAGE_NT_OPTIONAL_HDR_MAGIC) != VAL16(ntHeader.OptionalHeader.Magic)) &&
(VAL16(IMAGE_NT_OPTIONAL_HDR32_MAGIC) != VAL16(ntHeader.OptionalHeader.Magic))))
{
ERROR_(LOADER)( "Magic number mismatch\n" );
palError = ERROR_INVALID_PARAMETER;
Expand Down
80 changes: 0 additions & 80 deletions src/coreclr/utilcode/pedecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,86 +1659,6 @@ CHECK PEDecoder::CheckILOnlyEntryPoint() const
}
#endif // TARGET_X86

#ifndef DACCESS_COMPILE

void PEDecoder::LayoutILOnly(void *base, bool enableExecution) const
{
CONTRACT_VOID
{
INSTANCE_CHECK;
PRECONDITION(CheckZeroedMemory(base, VAL32(FindNTHeaders()->OptionalHeader.SizeOfImage)));
// Ideally we would require the layout address to honor the section alignment constraints.
// However, we do have 8K aligned IL only images which we load on 32 bit platforms. In this
// case, we can only guarantee OS page alignment (which after all, is good enough.)
PRECONDITION(CheckAligned((SIZE_T)base, GetOsPageSize()));
THROWS;
GC_NOTRIGGER;
}
CONTRACT_END;

// We're going to copy everything first, and write protect what we need to later.

// First, copy headers
CopyMemory(base, (void *)m_base, VAL32(FindNTHeaders()->OptionalHeader.SizeOfHeaders));

// Now, copy all sections to appropriate virtual address

IMAGE_SECTION_HEADER *sectionStart = IMAGE_FIRST_SECTION(FindNTHeaders());
IMAGE_SECTION_HEADER *sectionEnd = sectionStart + VAL16(FindNTHeaders()->FileHeader.NumberOfSections);

IMAGE_SECTION_HEADER *section = sectionStart;
while (section < sectionEnd)
{
// Raw data may be less than section size if tail is zero, but may be more since VirtualSize is
// not padded.
DWORD size = min(VAL32(section->SizeOfRawData), VAL32(section->Misc.VirtualSize));

CopyMemory((BYTE *) base + VAL32(section->VirtualAddress), (BYTE *) m_base + VAL32(section->PointerToRawData), size);

// Note that our memory is zeroed already, so no need to initialize any tail.

section++;
}

// Apply write protection to copied headers
DWORD oldProtection;
if (!ClrVirtualProtect((void *) base, VAL32(FindNTHeaders()->OptionalHeader.SizeOfHeaders),
PAGE_READONLY, &oldProtection))
ThrowLastError();

// Finally, apply proper protection to copied sections
for (section = sectionStart; section < sectionEnd; section++)
{
// Add appropriate page protection.
DWORD newProtection;
if (!enableExecution)
{
if (section->Characteristics & IMAGE_SCN_MEM_WRITE)
continue;

newProtection = PAGE_READONLY;
}
else
{
newProtection = section->Characteristics & IMAGE_SCN_MEM_EXECUTE ?
PAGE_EXECUTE_READ :
section->Characteristics & IMAGE_SCN_MEM_WRITE ?
PAGE_READWRITE :
PAGE_READONLY;
}

if (!ClrVirtualProtect((void*)((BYTE*)base + VAL32(section->VirtualAddress)),
VAL32(section->Misc.VirtualSize),
newProtection, &oldProtection))
{
ThrowLastError();
}
}

RETURN;
}

#endif // #ifndef DACCESS_COMPILE

bool ReadResourceDirectoryHeader(const PEDecoder *pDecoder, DWORD rvaOfResourceSection, DWORD rva, IMAGE_RESOURCE_DIRECTORY_ENTRY** ppDirectoryEntries, IMAGE_RESOURCE_DIRECTORY **ppResourceDirectory)
{
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/vm/peimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,13 @@ PTR_PEImageLayout PEImage::GetOrCreateLayoutInternal(DWORD imageLayoutMask)
if (bIsLoadedLayoutPreferred)
{
_ASSERTE(bIsLoadedLayoutSuitable);
pRetVal = PEImage::CreateLayoutMapped(!bIsFlatLayoutSuitable);
pRetVal = PEImage::CreateLoadedLayout(!bIsFlatLayoutSuitable);
}

if (pRetVal == NULL)
{
_ASSERTE(bIsFlatLayoutSuitable);
pRetVal = PEImage::CreateLayoutFlat();
pRetVal = PEImage::CreateFlatLayout();
_ASSERTE(pRetVal != NULL);
}
}
Expand All @@ -854,7 +854,7 @@ PTR_PEImageLayout PEImage::GetOrCreateLayoutInternal(DWORD imageLayoutMask)
return pRetVal;
}

PTR_PEImageLayout PEImage::CreateLayoutMapped(bool throwOnFailure)
PTR_PEImageLayout PEImage::CreateLoadedLayout(bool throwOnFailure)
{
CONTRACTL
{
Expand Down Expand Up @@ -889,7 +889,7 @@ PTR_PEImageLayout PEImage::CreateLayoutMapped(bool throwOnFailure)
return pLoadLayout;
}

PTR_PEImageLayout PEImage::CreateLayoutFlat()
PTR_PEImageLayout PEImage::CreateFlatLayout()
{
CONTRACTL
{
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/peimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ class PEImage final
PTR_PEImageLayout GetOrCreateLayoutInternal(DWORD imageLayoutMask);

// Create the mapped layout
PTR_PEImageLayout CreateLayoutMapped(bool throwOnFailure);
PTR_PEImageLayout CreateLoadedLayout(bool throwOnFailure);

// Create the flat layout
PTR_PEImageLayout CreateLayoutFlat();
PTR_PEImageLayout CreateFlatLayout();

void SetLayout(DWORD dwLayout, PTR_PEImageLayout pLayout);
#endif
Expand Down
Loading