Skip to content

Commit 0e30763

Browse files
unix: lift sigaltstack setup to before first install
1 parent d055a0d commit 0e30763

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/std/src/sys/pal/unix/stack_overflow.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,19 @@ mod imp {
140140
unsafe { sigaction(signal, ptr::null_mut(), &mut action) };
141141
// Configure our signal handler if one is not already set.
142142
if action.sa_sigaction == SIG_DFL {
143+
if !NEED_ALTSTACK.load(Ordering::Relaxed) {
144+
// haven't set up our sigaltstack yet
145+
NEED_ALTSTACK.store(true, Ordering::Relaxed);
146+
let handler = unsafe { make_handler(true) };
147+
MAIN_ALTSTACK.store(handler.data, Ordering::Relaxed);
148+
mem::forget(handler);
149+
}
143150
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
144151
action.sa_sigaction = signal_handler as sighandler_t;
145152
// SAFETY: only overriding signals if the default is set
146153
unsafe { sigaction(signal, &action, ptr::null_mut()) };
147-
NEED_ALTSTACK.store(true, Ordering::Relaxed);
148154
}
149155
}
150-
151-
// SAFETY: mutates our signal stack. shouldn't we install this first?
152-
let handler = unsafe { make_handler(true) };
153-
MAIN_ALTSTACK.store(handler.data, Ordering::Relaxed);
154-
mem::forget(handler);
155156
}
156157

157158
/// # Safety

0 commit comments

Comments
 (0)