Attaches a global handler for several signals which, when triggered, prints output to stderr similar to the default panic handler, with a message containing the type of signal and a stack trace if possible. This implementation does not just call the panic handler, because unwinding the stack (for a stack trace) when a signal is received requires special target-specific logic.
On POSIX targets, the signal handler is configured to use the alternative signal stack. Such a
stack is configured by the Zig Standard Library if std.options.signal_stack_size is set.
The signals for which a handler is installed are:
pub fn attachSegfaultHandler() void
pub fn attachSegfaultHandler() void {
if (!have_segfault_handling_support) {
@compileError("segfault handler not supported for this target");
}
if (native_os == .windows) {
windows_segfault_handle = windows.ntdll.RtlAddVectoredExceptionHandler(0, handleSegfaultWindows);
return;
}
const act: posix.Sigaction = .{
.handler = .{ .sigaction = handleSegfaultPosix },
.mask = posix.sigemptyset(),
.flags = (posix.SA.SIGINFO | posix.SA.RESTART | posix.SA.RESETHAND | posix.SA.ONSTACK),
};
updateSegfaultHandler(&act);
}