Skip to content

Commit 376c81c

Browse files
authored
Rollup merge of #102854 - semarie:openbsd-immutablestack, r=m-ou-se
openbsd: don't reallocate a guard page on the stack. the kernel currently enforce that a stack is immutable. calling mmap(2) or mprotect(2) to change it will result in EPERM, which generate a panic!(). so just do like for Linux, and trust the kernel to do the right thing.
2 parents ad45dd1 + b3c21ef commit 376c81c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

library/std/src/sys/unix/thread.rs

+10
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,16 @@ pub mod guard {
766766
const GUARD_PAGES: usize = 1;
767767
let guard = guardaddr..guardaddr + GUARD_PAGES * page_size;
768768
Some(guard)
769+
} else if cfg!(target_os = "openbsd") {
770+
// OpenBSD stack already includes a guard page, and stack is
771+
// immutable.
772+
//
773+
// We'll just note where we expect rlimit to start
774+
// faulting, so our handler can report "stack overflow", and
775+
// trust that the kernel's own stack guard will work.
776+
let stackptr = get_stack_start_aligned()?;
777+
let stackaddr = stackptr.addr();
778+
Some(stackaddr - page_size..stackaddr)
769779
} else {
770780
// Reallocate the last page of the stack.
771781
// This ensures SIGBUS will be raised on

0 commit comments

Comments
 (0)