Enable JIT for macOS

This commit is contained in:
David Chavez 2025-03-12 18:18:25 +01:00
parent 7dd81bcb6c
commit b1fd1e798e
2 changed files with 12 additions and 1 deletions

View file

@ -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();

View file

@ -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<uint8_t*>(MAP_FAILED);
if (!alloc_failed) {
// mprotect returns -1 on failure.