runtime: make divide-by-zero and nil dereference panics recoverable

Modify the Unix signal handler to redirect execution to a Go sigpanic
function instead of printing an error and re-raising the signal.
The C signal handler modifies the ucontext to make the faulting
instruction appear to have called tinygo_sigpanic, which then calls
runtimePanic with the appropriate message.

Supported on all architectures TinyGo targets on Linux and Darwin:
x86_64, i386, aarch64, ARM, and MIPS. Also registers SIGFPE, which
was previously not handled at all.
This commit is contained in:
Jake Bailey
2026-05-10 15:56:07 -07:00
committed by Ron Evans
parent 039f48f3d2
commit 29b4c6723f
12 changed files with 138 additions and 0 deletions
+1
View File
@@ -24,6 +24,7 @@ const (
// https://opensource.apple.com/source/xnu/xnu-7195.141.2/bsd/sys/signal.h.auto.html
const (
sig_SIGBUS = 10
sig_SIGFPE = 8
sig_SIGILL = 4
sig_SIGSEGV = 11
)