From 300f420f01aeeb00a2683f0de5dc8b766737b9e5 Mon Sep 17 00:00:00 2001 From: "Herman S." <429230+has207@users.noreply.github.com> Date: Tue, 21 Apr 2026 13:21:33 +0900 Subject: [PATCH] [x64/macOS] Use MAP_JIT for code cache and skip fast indirection --- src/xenia/cpu/backend/code_cache_base.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/xenia/cpu/backend/code_cache_base.h b/src/xenia/cpu/backend/code_cache_base.h index 405c6a95e..f270642a0 100644 --- a/src/xenia/cpu/backend/code_cache_base.h +++ b/src/xenia/cpu/backend/code_cache_base.h @@ -168,7 +168,14 @@ class CodeCacheBase : public CodeCache { const bool wx_preferred = xe::memory::IsWritableExecutableMemoryPreferred(); // Fast path: fixed-VA table + code cache, slots hold raw 32-bit targets. - if (allow_fast_indirection_) { + // Disabled on macOS x86_64 (Rosetta): shm+PROT_EXEC mapping appears to + // succeed but the page isn't actually executable. The encoded path + // uses an anonymous MAP_JIT mapping which works. + bool try_fast_indirection = allow_fast_indirection_; +#if XE_PLATFORM_MAC && XE_ARCH_AMD64 + try_fast_indirection = false; +#endif + if (try_fast_indirection) { indirection_table_base_ = reinterpret_cast(xe::memory::AllocFixed( reinterpret_cast(kIndirectionTableBase), @@ -233,10 +240,9 @@ class CodeCacheBase : public CodeCache { // Try the preferred fixed address first; fall back to OS-chosen on fail. if (wx_preferred) { -#if XE_PLATFORM_MAC && XE_ARCH_ARM64 - // macOS allows RWX only on anonymous MAP_JIT regions, so the cache is - // a single anonymous mapping; writes are gated by - // pthread_jit_write_protect_np in PlaceGuestCode/PlaceData. +#if XE_PLATFORM_MAC + // macOS allows RWX only on anonymous MAP_JIT regions; the W^X gate + // happens via pthread_jit_write_protect_np in PlaceGuestCode/PlaceData. generated_code_execute_base_ = reinterpret_cast( xe::memory::AllocFixed(nullptr, kGeneratedCodeSize, xe::memory::AllocationType::kReserveCommit,