Overview
ReXGlue provides unified exception handling for recompiled PowerPC code running on AMD64 and ARM64 host architectures. The exception handler system captures access violations, illegal instructions, and other runtime exceptions that occur during execution of recompiled code.Exception Handler Generation
Configuration Option
Enable exception handler generation in your recompiler config:How It Works
The exception handler system provides:- Access Violation Handling: Captures read/write violations and determines the faulting address
- Illegal Instruction Detection: Catches invalid opcodes and unimplemented instructions
- Thread Context Preservation: Maintains full CPU state at the point of exception
- Cross-Platform Abstraction: Unified API across Windows (SEH) and Linux (signal handlers)
Architecture Support
AMD64 (x86-64)
The AMD64 implementation (rex::arch::X64ThreadContextMembers) captures:
- General-purpose registers: RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, R8-R15
- XMM registers: XMM0-XMM15 (128-bit SIMD)
- Control registers: RIP (instruction pointer), EFLAGS
/home/daytona/workspace/source/include/rex/exception_handler.h:186-231
ARM64 (AArch64)
The ARM64 implementation (rex::arch::Arm64ThreadContextMembers) captures:
- General-purpose registers: X0-X30, SP (stack pointer)
- Vector registers: V0-V31 (128-bit NEON)
- Control registers: PC (program counter), PSTATE, FPSR, FPCR
- Special registers: X29 (frame pointer), X30 (link register)
/home/daytona/workspace/source/include/rex/exception_handler.h:121-129
Exception Types
Access Violation
fault_address(): Returns the address that caused the violationaccess_violation_operation(): ReturnskRead,kWrite, orkUnknown
Illegal Instruction
Using Exception Handlers
Installing a Handler
Inspecting Thread Context
Access CPU state at the point of exception:Modifying Registers
You can modify registers to recover from exceptions:Uninstalling a Handler
ARM64 Load/Store Decoding
For ARM64 platforms, ReXGlue includes VIXL-derived load/store instruction decoding to determine whether a faulting instruction was a load or store:/home/daytona/workspace/source/include/rex/exception_handler.h:345-399 for load/store operation constants.
Platform-Specific Notes
Windows
- Uses Structured Exception Handling (SEH)
- Requires
/EHacompiler flag (enabled automatically by ReXGlue) - Handlers are called on the same thread that raised the exception
Linux
- Uses POSIX signal handlers (SIGSEGV, SIGILL)
- Handlers run in signal context with restricted operations
- Avoid allocations and locks inside handlers
Best Practices
- Keep handlers fast: Exception handlers run in a critical context
- Minimal logging: Avoid complex I/O operations
- Return false for unknown exceptions: Let the OS handle what you can’t
- Test on both architectures: AMD64 and ARM64 have different semantics
- Use for debugging: Exception handlers are invaluable for diagnosing crashes
Common Use Cases
Memory-Mapped I/O
Capture access violations to emulate hardware registers:Lazy Memory Mapping
Map pages on-demand when accessed:Related APIs
rex::arch::HostThreadContext- Thread context structurerex::arch::Exception- Exception informationrex::arch::ExceptionHandler- Handler registration