Configures the per-thread alternative signal stack requested by std.options.signal_stack_size.
pub fn maybeAttachSignalStack() void
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,
};
}