diff options
-rw-r--r-- | src/ARMJIT.cpp | 36 | ||||
-rw-r--r-- | src/ARMJIT.h | 6 | ||||
-rw-r--r-- | src/ARMJIT_A64/ARMJIT_Compiler.cpp | 6 |
3 files changed, 28 insertions, 20 deletions
diff --git a/src/ARMJIT.cpp b/src/ARMJIT.cpp index 361801b..3ffb31d 100644 --- a/src/ARMJIT.cpp +++ b/src/ARMJIT.cpp @@ -43,9 +43,6 @@ #include "Wifi.h" #include "NDSCart.h" -#if defined(__APPLE__) && defined(__aarch64__) - #include <pthread.h> -#endif #include "ARMJIT_x64/ARMJIT_Offsets.h" static_assert(offsetof(ARM, CPSR) == ARM_CPSR_offset, ""); @@ -320,9 +317,7 @@ void Init() void DeInit() { - #if defined(__APPLE__) && defined(__aarch64__) - pthread_jit_write_protect_np(false); - #endif + JitEnableWrite(); ResetBlockCache(); ARMJIT_Memory::DeInit(); @@ -331,9 +326,7 @@ void DeInit() void Reset() { - #if defined(__APPLE__) && defined(__aarch64__) - pthread_jit_write_protect_np(false); - #endif + JitEnableWrite(); ResetBlockCache(); ARMJIT_Memory::Reset(); @@ -918,13 +911,10 @@ void CompileBlock(ARM* cpu) block->StartAddrLocal = localAddr; FloodFillSetFlags(instrs, i - 1, 0xF); - #if defined(__APPLE__) && defined(__aarch64__) - pthread_jit_write_protect_np(false); - #endif + + JitEnableWrite(); block->EntryPoint = JITCompiler->CompileBlock(cpu, thumb, instrs, i, hasMemoryInstr); - #if defined(__APPLE__) && defined(__aarch64__) - pthread_jit_write_protect_np(true); - #endif + JitEnableExecute(); JIT_DEBUGPRINT("block start %p\n", block->EntryPoint); } @@ -1168,4 +1158,20 @@ void ResetBlockCache() JITCompiler->Reset(); } +void JitEnableWrite() +{ + #if defined(__APPLE__) && defined(__aarch64__) + if (__builtin_available(macOS 11.0, *)) + pthread_jit_write_protect_np(false); + #endif +} + +void JitEnableExecute() +{ + #if defined(__APPLE__) && defined(__aarch64__) + if (__builtin_available(macOS 11.0, *)) + pthread_jit_write_protect_np(true); + #endif +} + } diff --git a/src/ARMJIT.h b/src/ARMJIT.h index 381068e..43e087a 100644 --- a/src/ARMJIT.h +++ b/src/ARMJIT.h @@ -24,6 +24,10 @@ #include "ARM.h" #include "ARM_InstrInfo.h" +#if defined(__APPLE__) && defined(__aarch64__) + #include <pthread.h> +#endif + namespace ARMJIT { @@ -48,6 +52,8 @@ void ResetBlockCache(); JitBlockEntry LookUpBlock(u32 num, u64* entries, u32 offset, u32 addr); bool SetupExecutableRegion(u32 num, u32 blockAddr, u64*& entry, u32& start, u32& size); +void JitEnableWrite(); +void JitEnableExecute(); } extern "C" void ARM_Dispatch(ARM* cpu, ARMJIT::JitBlockEntry entry); diff --git a/src/ARMJIT_A64/ARMJIT_Compiler.cpp b/src/ARMJIT_A64/ARMJIT_Compiler.cpp index 7dc854a..094f324 100644 --- a/src/ARMJIT_A64/ARMJIT_Compiler.cpp +++ b/src/ARMJIT_A64/ARMJIT_Compiler.cpp @@ -33,10 +33,6 @@ extern char __start__; #include <stdlib.h> -#ifdef __APPLE__ - #include <pthread.h> -#endif - using namespace Arm64Gen; extern "C" void ARM_Ret(); @@ -266,7 +262,7 @@ Compiler::Compiler() u64 alignedSize = (((u64)JitMem + sizeof(JitMem)) & ~(pageSize - 1)) - (u64)pageAligned; #ifdef __APPLE__ pageAligned = (u8*)mmap(NULL, 1024*1024*16, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT,-1, 0); - pthread_jit_write_protect_np(false); + JitEnableWrite(); #else mprotect(pageAligned, alignedSize, PROT_EXEC | PROT_READ | PROT_WRITE); #endif |