summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows
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/lib/Support/Windows
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/lib/Support/Windows')
-rw-r--r--llvm/lib/Support/Windows/Memory.inc80
1 files changed, 0 insertions, 80 deletions
diff --git a/llvm/lib/Support/Windows/Memory.inc b/llvm/lib/Support/Windows/Memory.inc
index 7eab9ff3afd..318e65aaa9e 100644
--- a/llvm/lib/Support/Windows/Memory.inc
+++ b/llvm/lib/Support/Windows/Memory.inc
@@ -160,85 +160,5 @@ void Memory::InvalidateInstructionCache(
FlushInstructionCache(GetCurrentProcess(), Addr, Len);
}
-
-MemoryBlock Memory::AllocateRWX(size_t NumBytes,
- const MemoryBlock *NearBlock,
- std::string *ErrMsg) {
- MemoryBlock MB;
- std::error_code EC;
- MB = allocateMappedMemory(NumBytes, NearBlock,
- MF_READ|MF_WRITE|MF_EXEC, EC);
- if (EC != std::error_code() && ErrMsg) {
- MakeErrMsg(ErrMsg, EC.message());
- }
- return MB;
-}
-
-bool Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
- std::error_code EC = releaseMappedMemory(M);
- if (EC == std::error_code())
- return false;
- MakeErrMsg(ErrMsg, EC.message());
- return true;
-}
-
-static DWORD getProtection(const void *addr) {
- MEMORY_BASIC_INFORMATION info;
- if (sizeof(info) == ::VirtualQuery(addr, &info, sizeof(info))) {
- return info.Protect;
- }
- return 0;
-}
-
-bool Memory::setWritable(MemoryBlock &M, std::string *ErrMsg) {
- if (!setRangeWritable(M.Address, M.Size)) {
- return MakeErrMsg(ErrMsg, "Cannot set memory to writeable");
- }
- return true;
-}
-
-bool Memory::setExecutable(MemoryBlock &M, std::string *ErrMsg) {
- if (!setRangeExecutable(M.Address, M.Size)) {
- return MakeErrMsg(ErrMsg, "Cannot set memory to executable");
- }
- return true;
-}
-
-bool Memory::setRangeWritable(const void *Addr, size_t Size) {
- DWORD prot = getProtection(Addr);
- if (!prot)
- return false;
-
- if (prot == PAGE_EXECUTE || prot == PAGE_EXECUTE_READ) {
- prot = PAGE_EXECUTE_READWRITE;
- } else if (prot == PAGE_NOACCESS || prot == PAGE_READONLY) {
- prot = PAGE_READWRITE;
- }
-
- DWORD oldProt;
- Memory::InvalidateInstructionCache(Addr, Size);
- return ::VirtualProtect(const_cast<LPVOID>(Addr), Size, prot, &oldProt)
- == TRUE;
-}
-
-bool Memory::setRangeExecutable(const void *Addr, size_t Size) {
- DWORD prot = getProtection(Addr);
- if (!prot)
- return false;
-
- if (prot == PAGE_NOACCESS) {
- prot = PAGE_EXECUTE;
- } else if (prot == PAGE_READONLY) {
- prot = PAGE_EXECUTE_READ;
- } else if (prot == PAGE_READWRITE) {
- prot = PAGE_EXECUTE_READWRITE;
- }
-
- DWORD oldProt;
- Memory::InvalidateInstructionCache(Addr, Size);
- return ::VirtualProtect(const_cast<LPVOID>(Addr), Size, prot, &oldProt)
- == TRUE;
-}
-
} // namespace sys
} // namespace llvm
OpenPOWER on IntegriCloud