]> git.lizzy.rs Git - rust.git/blob - src/test/ui/signal-alternate-stack-cleanup.rs
Rollup merge of #75177 - JohnTitor:broken-mir-test, r=eddyb
[rust.git] / src / test / ui / signal-alternate-stack-cleanup.rs
1 // run-pass
2 // Previously memory for alternate signal stack have been unmapped during
3 // main thread exit while still being in use by signal handlers. This test
4 // triggers this situation by sending signal from atexit handler.
5 //
6 // ignore-cloudabi no signal handling support
7 // ignore-wasm32-bare no libc
8 // ignore-windows
9 // ignore-sgx no libc
10 // ignore-vxworks no SIGWINCH in user space
11
12 #![feature(rustc_private)]
13 extern crate libc;
14
15 use libc::*;
16
17 unsafe extern fn signal_handler(signum: c_int, _: *mut siginfo_t, _: *mut c_void) {
18     assert_eq!(signum, SIGWINCH);
19 }
20
21 extern fn send_signal() {
22     unsafe {
23         raise(SIGWINCH);
24     }
25 }
26
27 fn main() {
28     unsafe {
29         // Install signal handler that runs on alternate signal stack.
30         let mut action: sigaction = std::mem::zeroed();
31         action.sa_flags = (SA_ONSTACK | SA_SIGINFO) as _;
32         action.sa_sigaction = signal_handler as sighandler_t;
33         sigaction(SIGWINCH, &action, std::ptr::null_mut());
34
35         // Send SIGWINCH on exit.
36         atexit(send_signal);
37     }
38 }