@@ -18,6 +18,7 @@ Port of the corresponding Rust code (see links below).
18
18
#include < cstdlib>
19
19
#include < cstring>
20
20
#include < lean/lean.h>
21
+ #include < initializer_list>
21
22
#include " runtime/stack_overflow.h"
22
23
23
24
namespace lean {
@@ -45,7 +46,7 @@ stack_guard::stack_guard() {
45
46
stack_guard::~stack_guard () {}
46
47
#else
47
48
// Install a segfault signal handler and abort with custom message if address is within stack guard.
48
- // https://github.com/rust-lang/rust/blob/master/src/libstd/ sys/unix/stack_overflow.rs
49
+ // https://github.com/rust-lang/rust/blob/master/library/std/src/ sys/pal /unix/stack_overflow.rs
49
50
50
51
51
52
// https://github.com/rust-lang/rust/blob/7c8dbd969dd0ef2af6d8bab9e03ba7ce6cac41a2/src/libstd/sys/unix/thread.rs#L293
@@ -102,12 +103,17 @@ void initialize_stack_overflow() {
102
103
#ifdef LEAN_WINDOWS
103
104
AddVectoredExceptionHandler (0 , stack_overflow_handler);
104
105
#else
105
- struct sigaction action;
106
- memset (&action, 0 , sizeof (struct sigaction ));
107
- action.sa_flags = SA_SIGINFO | SA_ONSTACK;
108
- action.sa_sigaction = segv_handler;
109
- sigaction (SIGSEGV, &action, nullptr );
110
- sigaction (SIGBUS, &action, nullptr );
106
+ for (auto signum : {SIGSEGV, SIGBUS}) {
107
+ struct sigaction action;
108
+ memset (&action, 0 , sizeof (struct sigaction ));
109
+ sigaction (signum, nullptr , &action);
110
+ // Configure our signal handler if one is not already set.
111
+ if (action.sa_handler == SIG_DFL) {
112
+ action.sa_flags = SA_SIGINFO | SA_ONSTACK;
113
+ action.sa_sigaction = segv_handler;
114
+ sigaction (signum, &action, nullptr );
115
+ }
116
+ }
111
117
#endif
112
118
}
113
119
0 commit comments