I am trying to understand the stack overflow handler in Rust. I have written the function recursive_stack() which declares some local variables again and again to exhaust the stack space.
extern crate nix;
use nix::sys::signal;
extern "C" fn handle_sigsegv(_: i32) {
    //Do something here
}
fn main() {
    let sig_action = signal::SigAction::new(
        signal::SigHandler::Handler(handle_sigsegv),
        signal::SaFlags::SA_NODEFER,
        signal::SigSet::empty(),
    );
    unsafe {
        signal::sigaction(signal::SIGSEGV, &sig_action);
    }
    println!("Before function");
    recursive_stack();
    println!("After function");
}
fn recursive_stack() {
    let _array: [i64; 50] = [0; 50];
    recursive_stack();
}
I want to catch the signal and execute my signal handler. If I register my signal handler, I get a "Segmentation fault (core dumped)" message. If I don't register a signal handler than I get a stack overflow message.
This signal handler works fine if I register it for SIGINT signal but gives strange results for SIGSEGV. What am I missing?
I am running this program on Ubuntu 18.04.
