diff --git a/src/xenia/cpu/backend/a64/a64_function.cc b/src/xenia/cpu/backend/a64/a64_function.cc index 9167bde7c..0738a1bc4 100644 --- a/src/xenia/cpu/backend/a64/a64_function.cc +++ b/src/xenia/cpu/backend/a64/a64_function.cc @@ -9,10 +9,31 @@ #include "xenia/cpu/backend/a64/a64_function.h" +#ifdef XE_PLATFORM_MAC +#include +#include +#include +#include +#endif + +#include "xenia/base/logging.h" #include "xenia/cpu/backend/a64/a64_backend.h" #include "xenia/cpu/processor.h" #include "xenia/cpu/thread_state.h" +#if XE_PLATFORM_MAC && defined(__aarch64__) +thread_local bool jit_thread_initialized = false; + +// Initialize JIT execution for the current thread +static void InitializeJITThread() { + if (!jit_thread_initialized) { + // Ensure this thread can execute JIT code by setting execute mode + pthread_jit_write_protect_np(1); // Enable execute, disable write + jit_thread_initialized = true; + } +} +#endif + namespace xe { namespace cpu { namespace backend { @@ -31,11 +52,20 @@ void A64Function::Setup(uint8_t* machine_code, size_t machine_code_length) { } bool A64Function::CallImpl(ThreadState* thread_state, uint32_t return_address) { +#if XE_PLATFORM_MAC && defined(__aarch64__) + // Initialize JIT execution for this thread + // This ensures pthread_jit_write_protect_np is set correctly for execution + InitializeJITThread(); +#endif + auto backend = reinterpret_cast(thread_state->processor()->backend()); auto thunk = backend->host_to_guest_thunk(); + + // Make the actual thunk call thunk(machine_code_, thread_state->context(), reinterpret_cast(uintptr_t(return_address))); + return true; }