stack overflow handler specific openbsd fix.

On this platform, when doing stack allocation, MAP_STACK is needed
 otherwise the mapping fails.
This commit is contained in:
David Carlier
2021-07-27 22:35:14 +01:00
parent fd853c00e2
commit 853ffc7400

View File

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