]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/signal-alternate-stack-cleanup.rs
New upstream version 1.36.0+dfsg1
[rustc.git] / src / test / run-pass / signal-alternate-stack-cleanup.rs
CommitLineData
7453a54e
SL
1// Previously memory for alternate signal stack have been unmapped during
2// main thread exit while still being in use by signal handlers. This test
3// triggers this situation by sending signal from atexit handler.
4//
2c00a5a8 5// ignore-cloudabi no signal handling support
abe05a73 6// ignore-wasm32-bare no libc
2c00a5a8 7// ignore-windows
48663c56 8// ignore-sgx no libc
7453a54e 9
0731742a 10#![feature(rustc_private)]
7453a54e
SL
11extern crate libc;
12
13use libc::*;
14
15unsafe extern fn signal_handler(signum: c_int, _: *mut siginfo_t, _: *mut c_void) {
16 assert_eq!(signum, SIGWINCH);
17}
18
19extern fn send_signal() {
20 unsafe {
21 raise(SIGWINCH);
22 }
23}
24
25fn main() {
26 unsafe {
b7449926 27 // Install signal handler that runs on alternate signal stack.
7453a54e 28 let mut action: sigaction = std::mem::zeroed();
2c00a5a8 29 action.sa_flags = (SA_ONSTACK | SA_SIGINFO) as _;
7453a54e
SL
30 action.sa_sigaction = signal_handler as sighandler_t;
31 sigaction(SIGWINCH, &action, std::ptr::null_mut());
32
33 // Send SIGWINCH on exit.
34 atexit(send_signal);
35 }
36}