|
9 | 9 | // SIGSEGV to generate a backtrace with `info` verbosity (lowest level so
|
10 | 10 | // it's always reported).
|
11 | 11 | //
|
12 |
| -// This could be supported on windows too (SIGSEGV is one of the rare |
13 |
| -// supported signals) but with `libc::signal()` instead of |
14 |
| -// `libc::sigaction()` |
15 |
| -#[cfg(not(target_os = "windows"))] |
| 12 | +// This uses `signal()` instead of `sigaction()` for Windows support |
| 13 | +// (SIGSEGV is one of the rare supported signals) |
16 | 14 | pub fn register_trap_handlers() {
|
17 | 15 | unsafe {
|
18 |
| - let mut action: libc::sigaction = std::mem::zeroed(); |
19 |
| - action.sa_flags = libc::SA_SIGINFO | libc::SA_ONSTACK; |
20 |
| - action.sa_sigaction = backtrace_handler as libc::sighandler_t; |
21 |
| - |
22 |
| - libc::sigaction(libc::SIGBUS, &action, std::ptr::null_mut()); |
23 |
| - libc::sigaction(libc::SIGSEGV, &action, std::ptr::null_mut()); |
| 16 | + libc::signal(libc::SIGBUS, backtrace_handler as libc::sighandler_t); |
| 17 | + libc::signal(libc::SIGSEGV, backtrace_handler as libc::sighandler_t); |
24 | 18 | }
|
25 | 19 | }
|
26 | 20 |
|
27 |
| -#[cfg(not(target_os = "windows"))] |
28 |
| -pub fn reset_traps_handler() { |
| 21 | +extern "C" fn backtrace_handler(signum: libc::c_int) { |
| 22 | + // Prevent infloop into the handler |
29 | 23 | unsafe {
|
30 |
| - let mut action: libc::sigaction = std::mem::zeroed(); |
31 |
| - action.sa_sigaction = libc::SIG_DFL; |
32 |
| - |
33 |
| - libc::sigaction(libc::SIGBUS, &action, std::ptr::null_mut()); |
34 |
| - libc::sigaction(libc::SIGSEGV, &action, std::ptr::null_mut()); |
| 24 | + libc::signal(signum, libc::SIG_DFL); |
35 | 25 | }
|
36 |
| -} |
37 |
| - |
38 |
| -#[cfg(not(target_os = "windows"))] |
39 |
| -extern "C" fn backtrace_handler( |
40 |
| - signum: libc::c_int, |
41 |
| - _info: *mut libc::siginfo_t, |
42 |
| - _data: *mut libc::c_void, |
43 |
| -) { |
44 |
| - // Prevent infloop into the handler |
45 |
| - reset_traps_handler(); |
46 | 26 |
|
47 | 27 | let mut header = format!("\n>>> Backtrace for signal {}", signum);
|
48 | 28 |
|
|
0 commit comments