Skip to content

Commit 853ffc7

Browse files
committed
stack overflow handler specific openbsd fix.
On this platform, when doing stack allocation, MAP_STACK is needed otherwise the mapping fails.
1 parent fd853c0 commit 853ffc7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,15 @@ mod imp {
143143
}
144144

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

0 commit comments

Comments
 (0)