Skip to main content

Module trap

Module trap 

Source
Expand description

Trap backend: rewrite residual Darwin svc and host hypercall entry.

Production path: freestanding libSystem → kh_hypercall_entry (alt stack + NEON tramp + [kh_trampoline_dispatch]). No SIGTRAP on that path.

Residual svc: leftover Darwin svc in fixtures / unpatched third-party code is rewritten to brk #IMM so Linux does not treat it as a host syscall. The SIGTRAP handler translates those sites. This is not a second production path — freestanding libSystem is always hypercall-wired. Former experimental svc→veneer (KAKEHASHI_TRAMPOLINE) was removed.

Live handlers require Linux aarch64. Patching works on any host.

Structs§

TrapConfig
Configuration for the trap backend.
TrapEvent
One observed trap / translated syscall event.

Enums§

TrapError
Trap subsystem errors.
TrapOutcome
Outcome of handling a trap.

Constants§

BRK_TRAP_IMM
Marker immediate for patched traps (brk #0x0F00).
PSTATE_C
AArch64 PSTATE / CPSR carry flag (bit 29 of NZCV).

Functions§

clear_expect_code
Disables the expect-code gate.
clear_trace_on_exit
Clears the trace-on-exit flag (default for plain kh run).
exit_requested
Whether the guest requested exit.
finish_with_exit_code
Terminates the host process as if the guest called BSD exit(code).
hypercall_entry_addr
install_trap_handlers
Installs the SIGTRAP handler used by the micro execution backend.
patch_svc_to_brk
Patches every AArch64 svc in executable regions to brk #IMM.
reset_trap_state
Resets exit / event state before a new run.
set_expect_code
Sets the expected guest exit code for the micro gate (--expect-code).
set_trace_on_exit
When set, the exit trap prints recorded events to stdout before _exit.
take_exit_code
Exit code from the last guest exit trap.
take_trace_events
Drains recorded trap events (for kh trace).