summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2017-11-16 23:04:44 +0000
committerLang Hames <lhames@gmail.com>2017-11-16 23:04:44 +0000
commitafcb70d0319a6e1b97cd74157e61f095cbc769c6 (patch)
treeee3d3f50ea1b08613a9a1a8aab6ec670de7b2646 /llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
parent854a8743e8e1af8636b250834f8d69226d7e2166 (diff)
downloadbcm5719-llvm-afcb70d0319a6e1b97cd74157e61f095cbc769c6.tar.gz
bcm5719-llvm-afcb70d0319a6e1b97cd74157e61f095cbc769c6.zip
[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. llvm-svn: 318464
Diffstat (limited to 'llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp')
-rw-r--r--llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp38
1 files changed, 26 insertions, 12 deletions
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
index daafcdfcc95..f48c3f0d957 100644
--- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/llvm/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().
OpenPOWER on IntegriCloud