Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

attachSegfaultHandler

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:

debug.attachSegfaultHandler
pub fn attachSegfaultHandler() void

File

lib/std/debug.zig:1557

Code

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);
}