Skip to content

Fix Apple Silicon W^X SIGBUS in setf_jit_lookup_t (FFI callbacks)#1786

Open
dg1sbg wants to merge 1 commit into
clasp-developers:mainfrom
dg1sbg:fix/apple-silicon-jit-wx-callback
Open

Fix Apple Silicon W^X SIGBUS in setf_jit_lookup_t (FFI callbacks)#1786
dg1sbg wants to merge 1 commit into
clasp-developers:mainfrom
dg1sbg:fix/apple-silicon-jit-wx-callback

Conversation

@dg1sbg

@dg1sbg dg1sbg commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Problem

On Apple Silicon, JIT'd code/data lives in MAP_JIT memory that is write-protected (execute mode) by default. A thread must switch it to write mode (pthread_jit_write_protect_np) around any store, or the store faults with SIGBUS (KERN_PROTECTION_FAILURE).

setf_jit_lookup_t (llvmo:jit-lookup-t setf, src/llvmo/llvmoPackage.cc) stores a Lisp function pointer into a JIT-emitted global. make-callback / clasp-ffi:%defcallback reach it via (setf (llvm-sys:jit-lookup-t dylib varname) function), and on arm64-darwin this store SIGBUSes at compile time — which is what makes the defcallback-native regression test (CFFI-DEFCALLBACK) crash during compile-file.

Fix

Wrap the store in JITDataReadWriteMaybeExecute() / JITDataReadExecute(), matching the existing W^X guards on the other JIT-literal write sites (core__literals_vset in compiler.cc, op_setf_literals / attr_clasp_module_native in loadltv.cc). This is the one remaining unguarded JIT-data store, unique to the FFI-callback path.

Verification

macOS arm64, native boehmprecise image: CFFI-DEFCALLBACK now passes (previously a Bus error during compile-file). Full regression suite: no regressions.

🤖 Generated with Claude Code

On Apple Silicon, JIT'd code/data lives in MAP_JIT memory that is
write-protected (execute mode) by default; a thread must switch it to
write mode (pthread_jit_write_protect_np) around any store or the store
faults with SIGBUS (KERN_PROTECTION_FAILURE).

setf_jit_lookup_t (llvmo:jit-lookup-t setf) stores a Lisp function
pointer into a JIT-emitted global. make-callback / clasp-ffi:%defcallback
reach it via (setf (llvm-sys:jit-lookup-t dylib varname) function), and
on arm64-darwin it SIGBUSes at compile time -- this is what makes the
defcallback-native regression test (CFFI-DEFCALLBACK) crash during
compile-file.

Wrap the store in JITDataReadWriteMaybeExecute()/JITDataReadExecute(),
matching the existing W^X guards on the other JIT-literal write sites
(core__literals_vset, loadltv op_setf_literals / attr_clasp_module_native).

Verified on macOS arm64 (native boehmprecise image): CFFI-DEFCALLBACK now
passes (previously a Bus error at compile time); no regressions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant