Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

spike/rosetta-trap-cost: the three programs behind Apple Feedback FB25100017 (Forza Horizon 6's hitch about once a second), the exact report text, and results from the M4 and the M1 Pro (ud2 under Rosetta 19.8 us against 2.4 us native on the M1 Pro, macOS 27.0). The players' guide at gethighball.com/docs/rosetta-feedback links here.

Gauthier Piarrettec16eb6084d53
diff --git a/spike/rosetta-trap-cost/README.md b/spike/rosetta-trap-cost/README.md
new file mode 100644
index 0000000..e19b608
--- /dev/null
+++ b/spike/rosetta-trap-cost/README.md
@@ -0,0 +1,94 @@
+# Rosetta exception cost (Apple Feedback FB25100017)
+
+These three small programs measure what a hardware exception costs in x86_64 code running under Rosetta,
+next to the same exception in native Apple silicon code. They back the report we sent Apple, FB25100017,
+about the hitch Forza Horizon 6 shows about once a second on every Mac we have heard from.
+
+If you play Forza Horizon 6 and see the hitch, the guide at
+https://gethighball.com/docs/rosetta-feedback/ shows how to send Apple a short report that points to ours.
+You do not need these programs for that.
+
+## What they measure
+
+- `sigbench` (x86_64, runs under Rosetta) catches `ud2` with a SIGILL handler that steps over it, `int3`
+ with SIGTRAP, and a `pthread_kill` round trip.
+- `sigbench_arm64` (native) does the same SIGILL round trip with `udf #0`, for comparison.
+- `smcbench` (x86_64) writes a byte into a 4 KB page that holds code which already ran, then calls that code.
+
+## Run them
+
+You need the Xcode command line tools (`xcode-select --install`).
+
+```
+./build.sh
+./sigbench 200000
+./sigbench 100000 4
+./sigbench_arm64 200000
+./sigbench_arm64 200000 4
+./smcbench
+```
+
+The first number is how many exceptions to time, the second how many threads to keep busy meanwhile, the way
+a game keeps the cores busy.
+
+## Results so far
+
+| Mac | macOS | ud2 under Rosetta | int3 under Rosetta | native udf | write into a code page |
+|---|---|---|---|---|---|
+| Mac mini M4, 32 GB, idle | 27.0 | 14.8 µs | 15.6 µs | 1.5 to 1.8 µs | 11.7 to 12.8 µs |
+| Mac mini M4, 4 busy threads | 27.0 | 31.7 µs | 32.8 µs | 1.86 µs | |
+| MacBook Pro M1 Pro, idle | 27.0 | 19.8 µs | 22.9 µs | 2.4 µs | 16.9 µs |
+
+A write into a different 4 KB page costs nothing on either Mac.
+
+In the game, the copy protection runs a job about every 1.1 seconds that executes about 2,000 instructions
+which trap on purpose, and its handler emulates each one while holding a lock the frame needs. Each trap
+costs about 57 µs there, so the job takes about a tenth of a second instead of a few milliseconds on a PC.
+Wine's own share of that time is about 5%.
+
+## The report we filed
+
+<details>
+<summary>The text of FB25100017, sent to Apple on 9 October 2026 with these programs attached</summary>
+
+#### Title
+
+Rosetta: a trapped x86 instruction costs about 15 µs (1.5 µs natively), which stalls games that emulate instructions in a signal handler
+
+#### Description
+
+x86_64 code running under Rosetta that takes a hardware exception and resumes from a signal handler (ud2 to SIGILL, int3 to SIGTRAP) spends about 15 µs per exception on an M4 Mac mini with macOS 27.0, idle. With four other threads busy, as in any game, it doubles to about 32 µs. The same round trip in native arm64 code (udf #0 to SIGILL) takes 1.8 µs idle and 1.9 µs with four busy threads, so the extra time is in Rosetta's path. In the game, Rosetta's exception server thread (com.apple.rosetta.exceptionserver) is busy in step with the traps. A software signal (pthread_kill, SIGUSR2) costs 7 µs under Rosetta, 16.5 µs with four busy threads.
+
+A second cost adds to it. Writing to any byte of a 4 KB page that holds code which already ran, then running that code, costs about 12 µs per write. A write to another 4 KB page, even inside the same 16 KB host page, costs nothing.
+
+Impact: Forza Horizon 6 (Steam, a Windows game running under Wine through Rosetta) stalls for 100 to 130 ms about once a second. Its copy protection runs a job every 1.1 s that executes about 2,000 instructions which trap on purpose and are emulated by the game's exception handler, and it holds a lock the frame needs for the whole job. Each trap costs about 57 µs here: the exception round trip, one or two of the code page writes above (the handler writes into a page it executes), and the handler's own work. On x86 hardware the same job takes a few milliseconds. Players see a hitch every second on M4 and M5 Macs.
+
+What we ruled out: Wine's own share of the cost is about 5%. The sigaction flags, the signal mask, an alternate signal stack, MAP_JIT and the ROSETTA_* environment variables change nothing. Raising Rosetta's exception server thread (com.apple.rosetta.exceptionserver) and the trapping thread, even to real-time priority, shortens the game's stall by only about 18%.
+
+#### Steps to reproduce
+
+1. Unzip the attachment and run `./build.sh` (Xcode command line tools). Prebuilt binaries are included.
+2. Run `./sigbench` (x86_64, runs under Rosetta) and `./sigbench_arm64` (native). Add a second argument for busy threads, for example `./sigbench 100000 4` and `./sigbench_arm64 200000 4`.
+3. Run `./smcbench` (x86_64).
+
+#### Expected results
+
+An exception delivered to translated code costs within a small factor of the native round trip. A write to data that shares a 4 KB page with translated code does not cost a full invalidation each time.
+
+#### Actual results
+
+M4 Mac mini (10-core GPU, 32 GB), macOS 27.0, idle:
+
+- ud2 caught by a SIGILL handler that steps over it: 14.8 µs per exception (18.9 µs without an alternate signal stack)
+- int3 caught by SIGTRAP: 15.6 µs
+- pthread_kill with SIGUSR2: 7.0 µs
+- native arm64, udf #0 caught by SIGILL: 1.5 to 1.8 µs (2.4 µs on an M1 Pro)
+
+With busy threads (2026-10-08, same Mac): ud2/SIGILL 31.7 µs with 4 and 27.9 µs with 8 busy threads, int3/SIGTRAP 32.8 and 29.4 µs, pthread_kill 16.5 and 14.8 µs. Native arm64 udf: 1.86 µs with 4 and 2.18 µs with 8.
+- smcbench, write one data byte in the 4 KB page of a function that already ran, then call it: 11.7 to 12.8 µs per iteration. The same write in another 4 KB page: 0 µs.
+
+#### Configuration
+
+Mac mini (M4, 2024), 32 GB, macOS 27.0. The game numbers come from Wine 11 (CrossOver 26.3 sources) with Highball, an open source Wine front end.
+
+</details>
diff --git a/spike/rosetta-trap-cost/build.sh b/spike/rosetta-trap-cost/build.sh
new file mode 100755
index 0000000..fdd2196
--- /dev/null
+++ b/spike/rosetta-trap-cost/build.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Builds the three programs. sigbench and smcbench are x86_64 (they run under Rosetta), sigbench_arm64 is native.
+set -e
+clang -arch x86_64 -O2 -mmacosx-version-min=13.0 -o sigbench sigbench.c
+clang -arch x86_64 -O2 -mmacosx-version-min=13.0 -o smcbench smcbench.c
+clang -arch arm64 -O2 -mmacosx-version-min=13.0 -o sigbench_arm64 sigbench_arm64.c
+echo built
diff --git a/spike/rosetta-trap-cost/sigbench.c b/spike/rosetta-trap-cost/sigbench.c
new file mode 100644
index 0000000..21e7ae5
--- /dev/null
+++ b/spike/rosetta-trap-cost/sigbench.c
@@ -0,0 +1,63 @@
+/* sigbench.c: the floor under Wine's exception cost on Rosetta (2026-10-07, the Forza stall).
+ * An x86_64 macOS program: ud2 caught by a SIGILL handler that steps over it (on an alternate signal
+ * stack, with a signal mask like Wine's), int3 caught by SIGTRAP, and pthread_sigmask round trips.
+ * A second argument starts that many threads spinning first, like a game keeping the cores busy (2026-10-08).
+ * Build: clang -arch x86_64 -O2 -o sigbench sigbench.c ; run under Rosetta. */
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/ucontext.h>
+#include <mach/mach_time.h>
+
+static double now_us(void) {
+ static mach_timebase_info_data_t tb; if (!tb.denom) mach_timebase_info(&tb);
+ return (double)mach_absolute_time() * tb.numer / tb.denom / 1000.0;
+}
+
+static void on_ill(int sig, siginfo_t *si, void *ctx) { ((ucontext_t *)ctx)->uc_mcontext->__ss.__rip += 2; }
+static void on_trap(int sig, siginfo_t *si, void *ctx) { (void)ctx; }
+static volatile int stop;
+static void *spin(void *p) { volatile unsigned long x = 0; while (!stop) x++; return NULL; }
+
+int main(int argc, char **argv) {
+ int n = argc > 1 ? atoi(argv[1]) : 200000;
+ int load = argc > 2 ? atoi(argv[2]) : 0;
+ for (int i = 0; i < load; i++) { pthread_t t; pthread_create(&t, NULL, spin, NULL); }
+ stack_t ss = { .ss_sp = malloc(1 << 16), .ss_size = 1 << 16, .ss_flags = 0 };
+ sigaltstack(&ss, NULL);
+ struct sigaction sa; memset(&sa, 0, sizeof sa);
+ sa.sa_sigaction = on_ill; sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
+ sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGUSR1); sigaddset(&sa.sa_mask, SIGUSR2); sigaddset(&sa.sa_mask, SIGALRM); sigaddset(&sa.sa_mask, SIGIO);
+ sigaction(SIGILL, &sa, NULL);
+ sa.sa_sigaction = on_trap; sigaction(SIGTRAP, &sa, NULL);
+
+ double t = now_us();
+ for (int i = 0; i < n; i++) __asm__ volatile("ud2");
+ double ud = (now_us() - t) / n;
+
+ t = now_us();
+ for (int i = 0; i < n; i++) __asm__ volatile("int3");
+ double bp = (now_us() - t) / n;
+
+ sigset_t block, old; sigemptyset(&block); sigaddset(&block, SIGUSR1); sigaddset(&block, SIGIO);
+ t = now_us();
+ for (int i = 0; i < n; i++) { pthread_sigmask(SIG_BLOCK, &block, &old); pthread_sigmask(SIG_SETMASK, &old, NULL); }
+ double sm = (now_us() - t) / n;
+
+ sa.sa_sigaction = on_trap; sigaction(SIGUSR2, &sa, NULL);
+ t = now_us();
+ for (int i = 0; i < n; i++) pthread_kill(pthread_self(), SIGUSR2);
+ double sw = (now_us() - t) / n;
+
+ /* the same ud2 without the alternate stack */
+ sa.sa_sigaction = on_ill; sa.sa_flags = SA_SIGINFO; sigaction(SIGILL, &sa, NULL);
+ t = now_us();
+ for (int i = 0; i < n; i++) __asm__ volatile("ud2");
+ double ud2 = (now_us() - t) / n;
+
+ stop = 1;
+ printf("per signal: ud2/SIGILL %.2f us (no altstack %.2f), int3/SIGTRAP %.2f us, pthread_kill/SIGUSR2 %.2f us; pthread_sigmask block+restore %.2f us (n=%d, busy threads %d)\n", ud, ud2, bp, sw, sm, n, load);
+ return 0;
+}
diff --git a/spike/rosetta-trap-cost/sigbench_arm64.c b/spike/rosetta-trap-cost/sigbench_arm64.c
new file mode 100644
index 0000000..801a000
--- /dev/null
+++ b/spike/rosetta-trap-cost/sigbench_arm64.c
@@ -0,0 +1,27 @@
+/* sigbench_arm64.c: the same SIGILL round trip as sigbench.c, natively on arm64, for comparison.
+ * udf #0 caught by a SIGILL handler that steps over it (pc += 4), on an alternate signal stack.
+ * A second argument starts that many threads spinning first (2026-10-08).
+ * Build: clang -arch arm64 -O2 -o sigbench_arm64 sigbench_arm64.c */
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ucontext.h>
+#include <mach/mach_time.h>
+#include <pthread.h>
+static volatile int stop;
+static void *spin(void *p) { volatile unsigned long x = 0; while (!stop) x++; return NULL; }
+static double now_us(void) { static mach_timebase_info_data_t tb; if (!tb.denom) mach_timebase_info(&tb); return (double)mach_absolute_time() * tb.numer / tb.denom / 1000.0; }
+static void on_ill(int sig, siginfo_t *si, void *ctx) { ((ucontext_t *)ctx)->uc_mcontext->__ss.__pc += 4; }
+int main(int argc, char **argv) {
+ int n = argc > 1 ? atoi(argv[1]) : 200000;
+ int load = argc > 2 ? atoi(argv[2]) : 0;
+ for (int i = 0; i < load; i++) { pthread_t th; pthread_create(&th, NULL, spin, NULL); }
+ stack_t ss = { .ss_sp = malloc(1 << 16), .ss_size = 1 << 16, .ss_flags = 0 }; sigaltstack(&ss, NULL);
+ struct sigaction sa; memset(&sa, 0, sizeof sa); sa.sa_sigaction = on_ill; sa.sa_flags = SA_SIGINFO | SA_ONSTACK; sigaction(SIGILL, &sa, NULL);
+ for (int i = 0; i < 1000; i++) __asm__ volatile("udf #0");
+ double t = now_us(); for (int i = 0; i < n; i++) __asm__ volatile("udf #0");
+ double us = (now_us() - t) / n; stop = 1;
+ printf("arm64 native: %.2f us per udf trapped by SIGILL (%d traps, busy threads %d)\n", us, n, load);
+ return 0;
+}
diff --git a/spike/rosetta-trap-cost/smcbench.c b/spike/rosetta-trap-cost/smcbench.c
new file mode 100644
index 0000000..da591b3
--- /dev/null
+++ b/spike/rosetta-trap-cost/smcbench.c
@@ -0,0 +1,35 @@
+/* smcbench.c: what code written at run time costs under Rosetta (2026-10-07, the Forza stall).
+ * An RWX page holds "mov eax, imm32; ret". Per iteration: (a) call only, (b) write a data byte elsewhere in
+ * the same page then call, (c) rewrite the function's immediate then call, (d) write a byte in another page
+ * then call, (e) rewrite a fresh 4 KB of code (64 functions) then call one.
+ * clang -arch x86_64 -O2 -o smcbench smcbench.c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <mach/mach_time.h>
+static double now_us(void) { static mach_timebase_info_data_t tb; if (!tb.denom) mach_timebase_info(&tb); return (double)mach_absolute_time() * tb.numer / tb.denom / 1000.0; }
+typedef int (*fn)(void);
+static void emit(unsigned char *p, int v) { p[0] = 0xb8; memcpy(p + 1, &v, 4); p[5] = 0xc3; }
+int main(int argc, char **argv) {
+ int n = argc > 1 ? atoi(argv[1]) : 20000;
+ int jit = argc > 2 && atoi(argv[2]);
+ unsigned char *code = mmap(NULL, 1 << 16, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON | (jit ? MAP_JIT : 0), -1, 0);
+ printf("%s\n", jit ? "MAP_JIT" : "plain RWX");
+ unsigned char *other = code + 0x8000;
+ if (code == MAP_FAILED) { perror("mmap"); return 1; }
+ emit(code, 1); fn f = (fn)code; volatile int sink = 0;
+ double t = now_us(); for (int i = 0; i < n; i++) sink += f(); double a = (now_us() - t) / n;
+ t = now_us(); for (int i = 0; i < n; i++) { code[2048] = (unsigned char)i; sink += f(); } double b = (now_us() - t) / n;
+ t = now_us(); for (int i = 0; i < n; i++) { memcpy(code + 1, &i, 4); sink += f(); } double c = (now_us() - t) / n;
+ t = now_us(); for (int i = 0; i < n; i++) { other[0] = (unsigned char)i; sink += f(); } double d = (now_us() - t) / n;
+ /* the region is 16 KB aligned (mmap on Apple silicon): code at +0, writes at +0x1000, +0x2000, +0x3000 (other 4 KB pages, same
+ 16 KB host page) and +0x4000 (the next host page) */
+ double w4[5]; int offs[5] = { 0x800, 0x1000, 0x2000, 0x3000, 0x4000 };
+ for (int k = 0; k < 5; k++) { t = now_us(); for (int i = 0; i < n; i++) { code[offs[k]] = (unsigned char)i; sink += f(); } w4[k] = (now_us() - t) / n; }
+ printf("write then call, by write offset from the code: +0x800 %.2f, +0x1000 %.2f, +0x2000 %.2f, +0x3000 %.2f, +0x4000 %.2f us\n", w4[0], w4[1], w4[2], w4[3], w4[4]);
+ unsigned char *big = code + 0x4000;
+ t = now_us(); for (int i = 0; i < n / 10; i++) { for (int k = 0; k < 64; k++) emit(big + k * 64, i + k); sink += ((fn)(big + (i % 64) * 64))(); } double e = (now_us() - t) / (n / 10);
+ printf("per iteration: call %.2f us, data write in the code page + call %.2f us, code rewrite + call %.2f us, write in another page + call %.2f us, rewrite 64 functions + call one %.2f us (sink %d)\n", a, b, c, d, e, sink);
+ return 0;
+}