diff options
author | Kamil Rytarowski <n54@gmx.com> | 2017-06-18 16:52:32 +0000 |
---|---|---|
committer | Kamil Rytarowski <n54@gmx.com> | 2017-06-18 16:52:32 +0000 |
commit | a841233a7645d11ccb4311fb6c52e228fce9e3da (patch) | |
tree | 78b864df0bf8b8fc673026c355a40726360f63ce /llvm/lib/Support/Unix | |
parent | 878cf8fbd418c86396e8aef0636f3347905059ac (diff) | |
download | bcm5719-llvm-a841233a7645d11ccb4311fb6c52e228fce9e3da.tar.gz bcm5719-llvm-a841233a7645d11ccb4311fb6c52e228fce9e3da.zip |
Implement AllocateRWX and ReleaseRWX for NetBSD
Summary:
NetBSD ships with PaX MPROTECT disallowing RWX mappings.
There is a solution to bypass this restriction with double mapping
RX (code) and RW (data) using mremap(2) MAP_REMAPDUP.
The initial mapping must be mmap(2)ed with protection:
PROT_MPROTECT(PROT_EXEC).
This functionality to bypass PaX MPROTECT appeared in NetBSD-7.99.72.
This patch fixes 20 failing tests:
- LLVM :: DebugInfo/debuglineinfo-macho.test
- LLVM :: DebugInfo/debuglineinfo.test
- LLVM :: ExecutionEngine/RuntimeDyld/Mips/ELF_Mips64r2N64_PIC_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/Mips/ELF_N32_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/Mips/ELF_N64R6_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/Mips/ELF_O32R6_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/Mips/ELF_O32_PIC_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/COFF_x86_64.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF-relaxed.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF_STT_FILE.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF_x64-64_PC8_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF_x64-64_PIC_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF_x86-64_PIC-small-relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF_x86-64_debug_frame.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/ELF_x86_64_StubBuf.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/MachO_empty_ehframe.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/MachO_i386_DynNoPIC_relocations.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/MachO_i386_eh_frame.s
- LLVM :: ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s
Sponsored by <The NetBSD Foundation>
Reviewers: joerg, lhames
Reviewed By: joerg
Subscribers: sdardis, llvm-commits, arichardson
Differential Revision: https://reviews.llvm.org/D33874
llvm-svn: 305650
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r-- | llvm/lib/Support/Unix/Memory.inc | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc index edbc7938f0c..dd39ef935bf 100644 --- a/llvm/lib/Support/Unix/Memory.inc +++ b/llvm/lib/Support/Unix/Memory.inc @@ -195,6 +195,10 @@ Memory::AllocateRWX(size_t NumBytes, const MemoryBlock* NearBlock, #if defined(__APPLE__) && (defined(__arm__) || defined(__arm64__)) void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_EXEC, flags, fd, 0); +#elif defined(__NetBSD__) && defined(PROT_MPROTECT) + void *pa = + ::mmap(start, PageSize * NumPages, + PROT_READ | PROT_WRITE | PROT_MPROTECT(PROT_EXEC), flags, fd, 0); #else void *pa = ::mmap(start, PageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC, flags, fd, 0); |