summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2008-10-03 16:17:20 +0000
committerJim Grosbach <grosbach@apple.com>2008-10-03 16:17:20 +0000
commitb22ef71d46f0f583dc1401f20df809d1da8d1831 (patch)
treecdb15da7dd03d15b3bc71aeaad0572c8c16e68a0 /llvm/lib/System/Unix
parent332ad5e01630e1d8c1b976dd7bf1a5a893df8e94 (diff)
downloadbcm5719-llvm-b22ef71d46f0f583dc1401f20df809d1da8d1831.tar.gz
bcm5719-llvm-b22ef71d46f0f583dc1401f20df809d1da8d1831.zip
On Darwin ARM, memory needs special handling to do JIT. This patch expands
this handling to work properly for modifying stub functions, relocations back to entry points after JIT compilation, etc.. llvm-svn: 57013
Diffstat (limited to 'llvm/lib/System/Unix')
-rw-r--r--llvm/lib/System/Unix/Memory.inc26
1 files changed, 25 insertions, 1 deletions
diff --git a/llvm/lib/System/Unix/Memory.inc b/llvm/lib/System/Unix/Memory.inc
index cf0157d5778..646311d8cd6 100644
--- a/llvm/lib/System/Unix/Memory.inc
+++ b/llvm/lib/System/Unix/Memory.inc
@@ -76,7 +76,7 @@ llvm::sys::Memory::AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock,
(vm_size_t)(pageSize*NumPages), 0,
VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY);
if (KERN_SUCCESS != kr) {
- MakeErrMsg(ErrMsg, "vm_protect max RWX failed\n");
+ MakeErrMsg(ErrMsg, "vm_protect max RX failed\n");
return sys::MemoryBlock();
}
@@ -103,3 +103,27 @@ bool llvm::sys::Memory::ReleaseRWX(MemoryBlock &M, std::string *ErrMsg) {
return false;
}
+bool llvm::sys::Memory::setWritable (MemoryBlock &M, std::string *ErrMsg) {
+#if defined(__APPLE__) && defined(__arm__)
+ if (M.Address == 0 || M.Size == 0) return false;
+ sys::Memory::InvalidateInstructionCache(M.Address, M.Size);
+ kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)M.Address,
+ (vm_size_t)M.Size, 0, VM_PROT_READ | VM_PROT_WRITE);
+ return KERN_SUCCESS == kr;
+#else
+ return true;
+#endif
+}
+
+bool llvm::sys::Memory::setExecutable (MemoryBlock &M, std::string *ErrMsg) {
+#if defined(__APPLE__) && defined(__arm__)
+ if (M.Address == 0 || M.Size == 0) return false;
+ sys::Memory::InvalidateInstructionCache(M.Address, M.Size);
+ kern_return_t kr = vm_protect(mach_task_self(), (vm_address_t)M.Address,
+ (vm_size_t)M.Size, 0, VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY);
+ return KERN_SUCCESS == kr;
+#else
+ return false;
+#endif
+}
+
OpenPOWER on IntegriCloud