Lab / SEP 27 2026 / failure

mprotect said yes, then the process died

Getting executable memory for Weft's native code on Apple silicon: the first probe reported success on a page that killed the process on its first instruction.

Compilers & SIMDWeft

When Weft started emitting its own machine code, it needed executable memory. The plan was the usual one: map a page read-write, copy the code in, flip it to read-execute, never write it again.

On Apple silicon that isn't enough. You need MAP_JIT and a per-thread write toggle, and flipping that toggle from managed code crashed the CI test host on the M4, because the managed caller is itself running out of the runtime's own JIT memory.

My first version gave up on macOS, on the theory that the signed dotnet host lacked an entitlement. It didn't. The fix is a small C shim that opens the toggle, writes and closes it inside one native call.

Building it, I found the old probe had never been a safe check anyway. A plain anonymous page flipped to read-execute reports success from mprotect, and the process is killed on its first instruction.