fix: x86-64 JIT SIGSEGV handler crash with comp_catchfault on Linux#1816
fix: x86-64 JIT SIGSEGV handler crash with comp_catchfault on Linux#1816
Conversation
…1815) Fix silent crash when starting A4000 config with 68040 + JIT + A4091 SCSI controller + comp_catchfault=true on Linux x86-64. Three root causes: 1. POSIX sigsegv_handler had no comp_catchfault fallback (unlike Windows __except block). When handle_access() failed, it silently called exit(). Added diagnostic logging and a fallback that stores Amiga fault info via exception2_setup(), sets jit_exception_pending=2, and redirects PC to popall_do_nothing to unwind the JIT stack frame. The pending exception is picked up by m68k_run_jit() which calls Exception(2) for a proper Amiga bus error. 2. handle_access() rejected valid Amiga addresses when the host fault address exceeded 32 bits (e.g., natmem at 0x80000000 + Amiga addr 0x80000004 = host 0x100000004). Fixed by computing the Amiga address first, then range-checking the result. 3. dummy_bank handler called from signal context triggered undefined behavior: dummy_get() -> gary_nonrange() -> hardware_exception2() -> THROW(2) (longjmp from signal handler). Added dummy_bank bypass in all SIGSEGV handlers (x86-64 Windows/POSIX, ARM64, 32-bit ARM) that returns 0 for reads and ignores writes, matching committed natmem gap behavior. Also fixed SIB byte handling in x86-64 decode_instruction() which produced wrong instruction length for MOV r32,[R15+reg*1+disp32] encoding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0473b32b5d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Move the variable definition to newcpu.cpp (compiled on all platforms) and the extern declaration to jit/compemu.h (shared JIT header), fixing the build failure on Linux aarch64 where the x86-only header was not included. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The threaded JIT loop (cpu_thread_run_jit) was missing the pending exception check after pushall_call_handler() returns. Without this, when the SIGSEGV comp_catchfault fallback sets jit_exception_pending in threaded CPU mode, the thread would never call Exception(2) and could keep re-entering the same faulting JIT block. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@claude give me a code review on this PR |
|
Claude finished @midwan's task in 4m 6s —— View job Code Review: PR #1816 — x86-64 JIT SIGSEGV handler crash with comp_catchfaultTasks:
Overall this is a solid, well-reasoned fix to a real crash. The root cause diagnosis is correct and the multi-layer approach (fix address math → add dummy_bank bypass → add comp_catchfault fallback) is the right strategy. Below are my findings ordered by severity. Correctness Issues1. SIB byte fix does not handle
|
Wrap the two jit_exception_pending blocks in m68k_run_jit() and cpu_thread_run_jit() with #if defined(CPU_x86_64) || defined(_M_AMD64) since the comp_catchfault SIGSEGV fallback that sets this flag is x86-64 only. Avoids dead code on ARM64 builds. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Document SIB byte decode limitation (mod=00, base=101 not handled; safe because JIT only generates mod=0x80 patterns) - Use consistent address formula in comp_catchfault path: replace uae_p32() with (uae_u32)(address - (uintptr_t) NATMEM_OFFSET) to match handle_access() - Fix indentation of dummy_bank comment in ARM64 sigsegv_handler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
comp_catchfault=trueon Linux x86-64comp_catchfaultfallback to POSIX SIGSEGV handler (matching Windows__exceptbehavior) withjit_exception_pendingmechanismhandle_access()rejecting valid Amiga addresses when host fault address exceeds 32 bitsdummy_bankbypass in all SIGSEGV handlers (x86-64, ARM64, 32-bit ARM) to prevent signal-unsafeTHROW(2)fromgary_nonrange()decode_instruction()Fixes #1815
Test plan
🤖 Generated with Claude Code