]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
jit: add ARM host mapping hooks
authorDimitris Panokostas <midwan@gmail.com>
Mon, 8 Jun 2026 20:18:30 +0000 (13:18 -0700)
committerStefan Reinauer <stefan.reinauer@coreboot.org>
Mon, 8 Jun 2026 22:20:52 +0000 (15:20 -0700)
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.

include/sysdeps.h
include/uae/vm.h
vm.cpp

index 714c280e3046a83716327acbcc303ea457ef7101..10e09c9398fc0ec88bbf74e8d5017cab2ecc2f99 100644 (file)
@@ -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)))
index 210df2c4124adbd2b7fb49d1189d281b6e113c8f..5bafb1c63e49a890c8e5cbb824296b303f4e886d 100644 (file)
@@ -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 d844b4c60077f178f01f3b399ea9e7076045ee1a..d086411882ab31307c3e1164d3b8059e820854ab 100644 (file)
--- a/vm.cpp
+++ b/vm.cpp
@@ -22,6 +22,9 @@
 #endif
 #if defined(__APPLE__)
 #include <sys/sysctl.h>
+#if defined(CPU_AARCH64)
+#include <pthread.h>
+#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;