// 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. When run the handler always
// un-registers itself after running and then returns (to allow the original
// signal to be delivered again). By returning we're ensuring that segfaults
// do indeed look like segfaults.
//
// 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.
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. When run the handler always
un-registers itself after running and then returns (to allow the original
signal to be delivered again). By returning we're ensuring that segfaults
do indeed look like segfaults.

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
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 . When run the handler always un - registers itself after running and then returns ( to allow the original signal to be delivered again ) . By returning we ' re ensuring that segfaults do indeed look like segfaults . 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
unsafe extern fn signal_handler(signum: libc::c_int,
                                    info: *mut siginfo,
                                    _data: *mut libc::c_void) {
        let guard = thread_info::stack_guard().unwrap_or(0);
        let addr = (*info).si_addr as usize;
        // If the faulting address is within the guard page, then we print a
        // message saying so.
        if guard != 0 && guard - PAGE_SIZE <= addr && addr < guard {
            report_overflow();
        }
        // Unregister ourselves by reverting back to the default behavior.
        let mut action: sigaction = mem::zeroed();
        action.sa_sigaction = SIG_DFL;
        sigaction(signum, &action, ptr::null_mut());
        // See comment above for why this function returns.
    }
unsafe extern fn signal_handler ( signum : libc :: c_int , info : * mut siginfo , _data : * mut libc :: c_void ) { let guard = thread_info :: stack_guard ( ) . unwrap_or ( 0 ) ; let addr = ( * info ) . si_addr as usize ; // If the faulting address is within the guard page, then we print a // message saying so. if guard != 0 && guard - PAGE_SIZE <= addr && addr < guard { report_overflow ( ) ; } // Unregister ourselves by reverting back to the default behavior. let mut action : sigaction = mem :: zeroed ( ) ; action . sa_sigaction = SIG_DFL ; sigaction ( signum , & action , ptr :: null_mut ( ) ) ; // See comment above for why this function returns. }
Signal handler for the SIGSEGV and SIGBUS handlers.
Signal handler for the SIGSEGV and SIGBUS handlers .
signum
libc::c_int
info
*mut siginfo
_data
*mut libc::c_void
26458.
None