summaryrefslogtreecommitdiffstats
path: root/tests/ui/runtime/signal-alternate-stack-cleanup.rs
blob: 37c602ae0b03924d1184062ec02fe89929f2ea52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// run-pass
// Previously memory for alternate signal stack have been unmapped during
// main thread exit while still being in use by signal handlers. This test
// triggers this situation by sending signal from atexit handler.
//
// ignore-wasm32-bare no libc
// ignore-windows
// ignore-sgx no libc
// ignore-vxworks no SIGWINCH in user space
// ignore-nto no SA_ONSTACK

#![feature(rustc_private)]
extern crate libc;

use libc::*;

unsafe extern "C" fn signal_handler(signum: c_int, _: *mut siginfo_t, _: *mut c_void) {
    assert_eq!(signum, SIGWINCH);
}

extern "C" fn send_signal() {
    unsafe {
        raise(SIGWINCH);
    }
}

fn main() {
    unsafe {
        // Install signal handler that runs on alternate signal stack.
        let mut action: sigaction = std::mem::zeroed();
        action.sa_flags = (SA_ONSTACK | SA_SIGINFO) as _;
        action.sa_sigaction = signal_handler as sighandler_t;
        sigaction(SIGWINCH, &action, std::ptr::null_mut());

        // Send SIGWINCH on exit.
        atexit(send_signal);
    }
}