diff options
| author | David Carlier <devnexen@gmail.com> | 2021-07-27 22:35:14 +0100 |
|---|---|---|
| committer | David Carlier <devnexen@gmail.com> | 2021-07-28 13:19:15 +0100 |
| commit | 853ffc7400bae30881a03adb74efc2ac3f48590f (patch) | |
| tree | 7f232f2a53fb3dcedf8acb99a39c814a71a8fcdc /library/std/src/sys/unix/stack_overflow.rs | |
| parent | fd853c00e255559255885aadff9e93a1760c8728 (diff) | |
| download | rust-853ffc7400bae30881a03adb74efc2ac3f48590f.tar.gz rust-853ffc7400bae30881a03adb74efc2ac3f48590f.zip | |
stack overflow handler specific openbsd fix.
On this platform, when doing stack allocation, MAP_STACK is needed otherwise the mapping fails.
Diffstat (limited to 'library/std/src/sys/unix/stack_overflow.rs')
| -rw-r--r-- | library/std/src/sys/unix/stack_overflow.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/library/std/src/sys/unix/stack_overflow.rs b/library/std/src/sys/unix/stack_overflow.rs index 81f47a779d3..c61449f168d 100644 --- a/library/std/src/sys/unix/stack_overflow.rs +++ b/library/std/src/sys/unix/stack_overflow.rs @@ -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()); } |
