Skip to content

Commit

Permalink
Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplett
Browse files Browse the repository at this point in the history
stack overflow handler specific openbsd change.
  • Loading branch information
GuillaumeGomez authored Oct 9, 2021
2 parents 86bf3ce + 853ffc7 commit 3e4f956
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions library/std/src/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ mod imp {
}

unsafe fn get_stackp() -> *mut libc::c_void {
let stackp = mmap(
ptr::null_mut(),
SIGSTKSZ + page_size(),
PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON,
-1,
0,
);
// OpenBSD requires this flag for stack mapping
// otherwise the said mapping will fail as a no-op on most systems
// and has a different meaning on FreeBSD
#[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "linux",))]
let flags = MAP_PRIVATE | MAP_ANON | libc::MAP_STACK;
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "linux",)))]
let flags = MAP_PRIVATE | MAP_ANON;
let stackp =
mmap(ptr::null_mut(), SIGSTKSZ + page_size(), PROT_READ | PROT_WRITE, flags, -1, 0);
if stackp == MAP_FAILED {
panic!("failed to allocate an alternative stack: {}", io::Error::last_os_error());
}
Expand Down

0 comments on commit 3e4f956

Please sign in to comment.