From 0464565baee4b9a1b660aafb70778db571730edc Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 20 Feb 2013 18:24:30 +0000 Subject: On PowerPC, the cache-flush instructions dcbf and icbi are treated as loads. On FreeBSD, add PROT_READ page protection flag before flushing cache. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175646 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Memory.inc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/Support/Unix/Memory.inc') diff --git a/lib/Support/Unix/Memory.inc b/lib/Support/Unix/Memory.inc index 40d6b3fefd..a66e3c7aee 100644 --- a/lib/Support/Unix/Memory.inc +++ b/lib/Support/Unix/Memory.inc @@ -51,7 +51,11 @@ int getPosixProtectionFlags(unsigned Flags) { llvm::sys::Memory::MF_EXEC: return PROT_READ | PROT_WRITE | PROT_EXEC; case llvm::sys::Memory::MF_EXEC: +#if defined(__FreeBSD__) + return PROT_READ | PROT_EXEC; +#else return PROT_EXEC; +#endif default: llvm_unreachable("Illegal memory protection flag specified!"); } -- cgit v1.2.3-18-g5258 From 033ee0f111b572ad4f167676e3c4bb4b71fe2da8 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 20 Feb 2013 19:25:09 +0000 Subject: Add comment in Memory.inc explaining r175646. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175650 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Unix/Memory.inc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/Support/Unix/Memory.inc') diff --git a/lib/Support/Unix/Memory.inc b/lib/Support/Unix/Memory.inc index a66e3c7aee..e00394ec6a 100644 --- a/lib/Support/Unix/Memory.inc +++ b/lib/Support/Unix/Memory.inc @@ -52,6 +52,13 @@ int getPosixProtectionFlags(unsigned Flags) { return PROT_READ | PROT_WRITE | PROT_EXEC; case llvm::sys::Memory::MF_EXEC: #if defined(__FreeBSD__) + // On PowerPC, having an executable page that has no read permission + // can have unintended consequences. The function InvalidateInstruction- + // Cache uses instructions dcbf and icbi, both of which are treated by + // the processor as loads. If the page has no read permissions, + // executing these instructions will result in a segmentation fault. + // Somehow, this problem is not present on Linux, but it does happen + // on FreeBSD. return PROT_READ | PROT_EXEC; #else return PROT_EXEC; -- cgit v1.2.3-18-g5258