From b1fd1e798e34416f2d09ca965ceb1f19d0c19b4f Mon Sep 17 00:00:00 2001 From: David Chavez Date: Wed, 12 Mar 2025 18:18:25 +0100 Subject: [PATCH] Enable JIT for macOS --- librecomp/src/mods.cpp | 6 ++++++ librecomp/src/recomp.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/librecomp/src/mods.cpp b/librecomp/src/mods.cpp index 4b2ea0d..db20e39 100644 --- a/librecomp/src/mods.cpp +++ b/librecomp/src/mods.cpp @@ -227,6 +227,9 @@ private: }; void unprotect(void* target_func, uint64_t* old_flags) { +#if defined(__APPLE__) + pthread_jit_write_protect_np(false); +#endif // Align the address to a page boundary. uintptr_t page_start = (uintptr_t)target_func; int page_size = getpagesize(); @@ -238,6 +241,9 @@ void unprotect(void* target_func, uint64_t* old_flags) { } void protect(void* target_func, uint64_t old_flags) { +#if defined(__APPLE__) + pthread_jit_write_protect_np(true); +#endif // Align the address to a page boundary. uintptr_t page_start = (uintptr_t)target_func; int page_size = getpagesize(); diff --git a/librecomp/src/recomp.cpp b/librecomp/src/recomp.cpp index 2ac8d46..107a0e9 100644 --- a/librecomp/src/recomp.cpp +++ b/librecomp/src/recomp.cpp @@ -707,7 +707,12 @@ void recomp::start( } } #else - rdram = (uint8_t*)mmap(NULL, allocation_size, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0); + int map_flags = MAP_ANONYMOUS | MAP_PRIVATE; +#if defined(__APPLE__) && defined(__aarch64__) + map_flags |= MAP_JIT; +#endif + + rdram = (uint8_t*)mmap(NULL, allocation_size, PROT_NONE, map_flags, -1, 0); alloc_failed = rdram == reinterpret_cast(MAP_FAILED); if (!alloc_failed) { // mprotect returns -1 on failure.