From: Dimitris Panokostas Date: Mon, 8 Jun 2026 20:18:30 +0000 (-0700) Subject: jit: add ARM host mapping hooks X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=1cd99d1d364d1681533fbabf9737c3922c679013;p=francis%2Fwinuae.git jit: add ARM host mapping hooks Add the host ABI marker needed by ARM JIT backends. Teach the VM allocator how to request host JIT mappings. The platform backend still owns executable memory policy. Shared JIT code only needs a portable call convention and mapping hook. --- diff --git a/include/sysdeps.h b/include/sysdeps.h index 714c280e..10e09c93 100644 --- a/include/sysdeps.h +++ b/include/sysdeps.h @@ -69,6 +69,9 @@ using namespace std; #elif defined(CPU_x86_64) /* Parameters are passed in RDI, RSI by default (System V AMD64 ABI). */ #define JITCALL +#elif defined(CPU_arm) || defined(CPU_AARCH64) +/* ARM/ARM64: parameters are passed in registers by default. */ +#define JITCALL #elif defined(HAVE_FUNC_ATTRIBUTE_REGPARM) /* Parameters are passed in EAX, EDX on x86 with regparm(2). */ #define JITCALL __attribute__((regparm(2))) diff --git a/include/uae/vm.h b/include/uae/vm.h index 210df2c4..5bafb1c6 100644 --- a/include/uae/vm.h +++ b/include/uae/vm.h @@ -16,6 +16,7 @@ #define UAE_VM_32BIT (1 << 8) #define UAE_VM_WRITE_WATCH (1 << 9) +#define UAE_VM_JIT (1 << 10) #define UAE_VM_ALLOC_FAILED NULL /* Even though it looks like you can OR together vm protection values, @@ -36,6 +37,7 @@ void *uae_vm_alloc(uae_u32 size, int flags); void *uae_vm_alloc(size_t size, int flags, int protect); bool uae_vm_protect(void *address, size_t size, int protect); bool uae_vm_free(void *address, size_t size); +void uae_vm_jit_write_protect(bool enable_execute_mode); void *uae_vm_reserve(size_t size, int flags); void *uae_vm_reserve_fixed(void *address, size_t size, int flags); diff --git a/vm.cpp b/vm.cpp index d844b4c6..d0864118 100644 --- a/vm.cpp +++ b/vm.cpp @@ -22,6 +22,9 @@ #endif #if defined(__APPLE__) #include +#if defined(CPU_AARCH64) +#include +#endif #endif //#if defined(LINUX) && defined(CPU_x86_64) @@ -156,6 +159,15 @@ static void *uae_vm_alloc_with_flags(size_t size, int flags, int protect) #else int mmap_flags = MAP_PRIVATE | MAP_ANON; int mmap_prot = protect_to_native(protect); +#if defined(__APPLE__) && defined(CPU_AARCH64) + if (flags & UAE_VM_JIT) { +#ifdef MAP_JIT + mmap_flags |= MAP_JIT; +#else + uae_log("VM: UAE_VM_JIT requested but MAP_JIT is unavailable on this SDK\n"); +#endif + } +#endif #endif #if !defined(CPU_64_BIT) || defined(__APPLE__) @@ -278,6 +290,15 @@ bool uae_vm_free(void *address, size_t size) return do_free(address, size); } +void uae_vm_jit_write_protect(bool enable_execute_mode) +{ +#if defined(__APPLE__) && defined(CPU_AARCH64) + pthread_jit_write_protect_np(enable_execute_mode ? 1 : 0); +#else + (void)enable_execute_mode; +#endif +} + static void *try_reserve(uintptr_t try_addr, size_t size, int flags) { void *address = NULL; @@ -299,6 +320,15 @@ static void *try_reserve(uintptr_t try_addr, size_t size, int flags) } #else int mmap_flags = MAP_PRIVATE | MAP_ANON; +#if defined(__APPLE__) && defined(CPU_AARCH64) + if (flags & UAE_VM_JIT) { +#ifdef MAP_JIT + mmap_flags |= MAP_JIT; +#else + uae_log("VM: UAE_VM_JIT reserve requested but MAP_JIT is unavailable on this SDK\n"); +#endif + } +#endif address = mmap((void *) try_addr, size, PROT_NONE, mmap_flags, -1, 0); if (address == MAP_FAILED) { return NULL;