diff options
author | Lang Hames <lhames@gmail.com> | 2017-11-16 23:04:44 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2017-11-16 23:04:44 +0000 |
commit | 6e1e5aaef04d58c9eb543eec5ba961f593ac27d3 (patch) | |
tree | 7175c7544fedabc117a675a33e99f81d81acf3be /tools/llvm-rtdyld | |
parent | a98c2a27eb6190fdab55fd27995cbeeccd3e9dd4 (diff) |
[Support] Support NetBSD PaX MPROTECT in sys::Memory.
Removes AllocateRWX, setWritable and setExecutable from sys::Memory and
standardizes on allocateMappedMemory / protectMappedMemory. The
allocateMappedMemory method is updated to request full permissions for memory
blocks so that they can be marked executable later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318464 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-rtdyld')
-rw-r--r-- | tools/llvm-rtdyld/llvm-rtdyld.cpp | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp index daafcdfcc95..f48c3f0d957 100644 --- a/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -178,10 +178,14 @@ public: void deregisterEHFrames() override {} void preallocateSlab(uint64_t Size) { - std::string Err; - sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err); + std::error_code EC; + sys::MemoryBlock MB = + sys::Memory::allocateMappedMemory(Size, nullptr, + sys::Memory::MF_READ | + sys::Memory::MF_WRITE, + EC); if (!MB.base()) - report_fatal_error("Can't allocate enough memory: " + Err); + report_fatal_error("Can't allocate enough memory: " + EC.message()); PreallocSlab = MB; UsePreallocation = true; @@ -222,10 +226,14 @@ uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size, if (UsePreallocation) return allocateFromSlab(Size, Alignment, true /* isCode */); - std::string Err; - sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err); + std::error_code EC; + sys::MemoryBlock MB = + sys::Memory::allocateMappedMemory(Size, nullptr, + sys::Memory::MF_READ | + sys::Memory::MF_WRITE, + EC); if (!MB.base()) - report_fatal_error("MemoryManager allocation failed: " + Err); + report_fatal_error("MemoryManager allocation failed: " + EC.message()); FunctionMemory.push_back(MB); return (uint8_t*)MB.base(); } @@ -242,10 +250,14 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size, if (UsePreallocation) return allocateFromSlab(Size, Alignment, false /* isCode */); - std::string Err; - sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, nullptr, &Err); + std::error_code EC; + sys::MemoryBlock MB = + sys::Memory::allocateMappedMemory(Size, nullptr, + sys::Memory::MF_READ | + sys::Memory::MF_WRITE, + EC); if (!MB.base()) - report_fatal_error("MemoryManager allocation failed: " + Err); + report_fatal_error("MemoryManager allocation failed: " + EC.message()); DataMemory.push_back(MB); return (uint8_t*)MB.base(); } @@ -453,9 +465,11 @@ static int executeInput() { // Make sure the memory is executable. // setExecutable will call InvalidateInstructionCache. - std::string ErrorStr; - if (!sys::Memory::setExecutable(FM, &ErrorStr)) - ErrorAndExit("unable to mark function executable: '" + ErrorStr + "'"); + if (auto EC = sys::Memory::protectMappedMemory(FM, + sys::Memory::MF_READ | + sys::Memory::MF_EXEC)) + ErrorAndExit("unable to mark function executable: '" + EC.message() + + "'"); } // Dispatch to _main(). |