From 3452efb58d2f3be867080f8627417b264fcbd73c Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Thu, 14 Sep 2017 16:43:13 +0200 Subject: [PATCH] Fix crossgen memory mappings (#13972) This change removes executable memory mappings from crossgen. Now it can be run on systems with PAX set to prevent executable mappings without any marking using the paxctl. --- src/utilcode/loaderheap.cpp | 4 ++++ src/vm/peimagelayout.cpp | 12 ++++++++++-- src/vm/stublink.cpp | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utilcode/loaderheap.cpp b/src/utilcode/loaderheap.cpp index 2603a8e..ca1ed66 100644 --- a/src/utilcode/loaderheap.cpp +++ b/src/utilcode/loaderheap.cpp @@ -944,8 +944,12 @@ UnlockedLoaderHeap::UnlockedLoaderHeap(DWORD dwReserveBlockSize, m_pPrivatePerfCounter_LoaderBytes = pPrivatePerfCounter_LoaderBytes; m_Options = 0; + +#ifndef CROSSGEN_COMPILE if (fMakeExecutable) m_Options |= LHF_EXECUTABLE; +#endif // CROSSGEN_COMPILE + if (fZeroInit) m_Options |= LHF_ZEROINIT; diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index 93ab77c..94810a0 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -195,14 +195,14 @@ void PEImageLayout::ApplyBaseRelocations() if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_WRITE)) == 0)) { DWORD dwNewProtection = PAGE_READWRITE; -#ifdef FEATURE_PAL +#if defined(FEATURE_PAL) && !defined(CROSSGEN_COMPILE) if (((pSection->Characteristics & VAL32(IMAGE_SCN_MEM_EXECUTE)) != 0)) { // On SELinux, we cannot change protection that doesn't have execute access rights // to one that has it, so we need to set the protection to RWX instead of RW dwNewProtection = PAGE_EXECUTE_READWRITE; } -#endif // FEATURE_PAL +#endif // FEATURE_PAL && !CROSSGEN_COMPILE if (!ClrVirtualProtect(pWriteableRegion, cbWriteableRegion, dwNewProtection, &dwOldProtection)) ThrowLastError(); @@ -243,6 +243,7 @@ void PEImageLayout::ApplyBaseRelocations() } _ASSERTE(dirSize == dirPos); +#ifndef CROSSGEN_COMPILE if (dwOldProtection != 0) { // Restore the protection @@ -250,6 +251,7 @@ void PEImageLayout::ApplyBaseRelocations() dwOldProtection, &dwOldProtection)) ThrowLastError(); } +#endif // CROSSGEN_COMPILE } #endif // FEATURE_PREJIT @@ -478,7 +480,9 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner) #else //!FEATURE_PAL +#ifndef CROSSGEN_COMPILE m_FileView = PAL_LOADLoadPEFile(hFile); + if (m_FileView == NULL) { // For CoreCLR, try to load all files via LoadLibrary first. If LoadLibrary did not work, retry using @@ -507,6 +511,10 @@ MappedImageLayout::MappedImageLayout(HANDLE hFile, PEImage* pOwner) SetRelocated(); } +#else // !CROSSGEN_COMPILE + m_FileView = NULL; +#endif // !CROSSGEN_COMPILE + #endif // !FEATURE_PAL } diff --git a/src/vm/stublink.cpp b/src/vm/stublink.cpp index d183326..631f511 100644 --- a/src/vm/stublink.cpp +++ b/src/vm/stublink.cpp @@ -888,7 +888,9 @@ Stub *StubLinker::Link(LoaderHeap *pHeap, DWORD flags) int globalsize = 0; int size = CalculateSize(&globalsize); +#ifndef CROSSGEN_COMPILE _ASSERTE(!pHeap || pHeap->IsExecutable()); +#endif StubHolder pStub; -- 2.7.4