Skip to content

Commit b3c21ef

Browse files
committed
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.
1 parent 1de5b22 commit b3c21ef

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

0 commit comments

Comments
 (0)