about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-10-09 17:08:38 +0200
committerGitHub <noreply@github.com>2021-10-09 17:08:38 +0200
commit3e4f95612e5e4d2c7e8e0a21b3ff703c580ac15c (patch)
tree0df3cfd06b88fa638660833e5bf4d9aaf81e2991
parent86bf3ce8591343bcc2442e95d6432f3b78e07cc5 (diff)
parent853ffc7400bae30881a03adb74efc2ac3f48590f (diff)
downloadrust-3e4f95612e5e4d2c7e8e0a21b3ff703c580ac15c.tar.gz
rust-3e4f95612e5e4d2c7e8e0a21b3ff703c580ac15c.zip
Rollup merge of #87528 - :stack_overflow_obsd, r=joshtriplett
stack overflow handler specific openbsd change.
-rw-r--r--library/std/src/sys/unix/stack_overflow.rs17
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 e8747e39bcb..db1a2a26a89 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());
         }