Skip to content

Commit

Permalink
Rollup merge of #102854 - semarie:openbsd-immutablestack, r=m-ou-se
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dylan-DPC authored Oct 13, 2022
2 parents ad45dd1 + b3c21ef commit 376c81c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,16 @@ pub mod guard {
const GUARD_PAGES: usize = 1;
let guard = guardaddr..guardaddr + GUARD_PAGES * page_size;
Some(guard)
} else if cfg!(target_os = "openbsd") {
// OpenBSD stack already includes a guard page, and stack is
// immutable.
//
// We'll just note where we expect rlimit to start
// faulting, so our handler can report "stack overflow", and
// trust that the kernel's own stack guard will work.
let stackptr = get_stack_start_aligned()?;
let stackaddr = stackptr.addr();
Some(stackaddr - page_size..stackaddr)
} else {
// Reallocate the last page of the stack.
// This ensures SIGBUS will be raised on
Expand Down

0 comments on commit 376c81c

Please sign in to comment.