Function signal_handler

pub(in ::sys::pal::unix::stack_overflow::imp) unsafe extern "C" fn signal_handler(signum: c_int, info: *mut siginfo_t, _data: *mut c_void)

Signal handler for the SIGSEGV and SIGBUS handlers.

We've got guard pages (unmapped pages) at the end of every thread's stack, so if a thread ends up running into the guard page it'll trigger this handler. We want to detect these cases and print out a helpful error saying that the stack has overflowed. All other signals, however, should go back to what they were originally supposed to do.

This handler currently exists purely to print an informative message whenever a thread overflows its stack. We then abort to exit and indicate a crash, but to avoid a misleading SIGSEGV that might lead users to believe that unsafe code has accessed an invalid pointer; the SIGSEGV encountered when overflowing the stack is expected and well-defined.

If this is not a stack overflow, the handler un-registers itself and then returns (to allow the original signal to be delivered again). Returning from this kind of signal handler is technically not defined to work when reading the POSIX spec strictly, but in practice it turns out many large systems and all implementations allow returning from a signal handler to work. For a more detailed explanation see the comments on #26458.

Safety

Rust doesn't call this, it gets called by the kernel, which we expect to provide valid parameters. Apart from that, this function does not have any other preconditions.