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.

maybeAttachSignalStack

Configures the per-thread alternative signal stack requested by std.options.signal_stack_size.

Thread.maybeAttachSignalStack
pub fn maybeAttachSignalStack() void

File

lib/std/Thread.zig:1757

Code

pub fn maybeAttachSignalStack() void {
    const size = std.options.signal_stack_size orelse return;
    switch (builtin.target.os.tag) {
        // TODO: Windows vectored exception handlers always run on the main stack, but we could use
        // some target-specific inline assembly to swap the stack pointer.
        .windows => return,
        .wasi => return,
        else => {},
    }
    const global = struct {
        threadlocal var signal_stack: [size]u8 = undefined;
    };
    std.posix.sigaltstack(&.{
        .sp = &global.signal_stack,
        .flags = 0,
        .size = size,
    }, null) catch |err| switch (err) {
        error.SizeTooSmall => unreachable, // `std.options.signal_stack_size` must be sufficient for the target
        error.PermissionDenied => unreachable, // called `maybeAttachSignalStack` from a signal handler
        error.Unexpected => unreachable,
    };
}