From 7d3fb87c1879e912abc196dc876d90855cf4557c Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Tue, 31 Mar 2026 02:12:45 +0900 Subject: [PATCH] [A64/macOS] Toggle W^X protection for guest trampoline writes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple Silicon enforces W^X on MAP_JIT memory — pages are either writable or executable, not both. Use pthread_jit_write_protect_np to toggle write access around BuildGuestTrampoline. --- src/xenia/cpu/backend/a64/a64_backend.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/xenia/cpu/backend/a64/a64_backend.cc b/src/xenia/cpu/backend/a64/a64_backend.cc index b19f1d401..3d3e272a1 100644 --- a/src/xenia/cpu/backend/a64/a64_backend.cc +++ b/src/xenia/cpu/backend/a64/a64_backend.cc @@ -23,6 +23,9 @@ #if XE_ARCH_ARM64 && XE_COMPILER_MSVC #include #endif +#if XE_PLATFORM_MAC +#include +#endif #include "xenia/cpu/backend/a64/a64_assembler.h" #include "xenia/cpu/backend/a64/a64_code_cache.h" #include "xenia/cpu/backend/a64/a64_emitter.h" @@ -764,9 +767,15 @@ uint32_t A64Backend::CreateGuestTrampoline(GuestTrampolineProc proc, uint8_t* write_pos = &guest_trampoline_memory_[kGuestTrampolineSize * new_index]; +#if XE_PLATFORM_MAC + pthread_jit_write_protect_np(0); +#endif BuildGuestTrampoline(write_pos, reinterpret_cast(proc), userdata1, userdata2, reinterpret_cast(guest_to_host_thunk_)); +#if XE_PLATFORM_MAC + pthread_jit_write_protect_np(1); +#endif // Flush instruction cache for the new trampoline code. #if XE_PLATFORM_WIN32