about summary refs log tree commit diff
path: root/library/std/src/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorMax Wase <max.vvase@gmail.com>2021-10-13 01:33:12 +0300
committerGitHub <noreply@github.com>2021-10-13 01:33:12 +0300
commit3e0360f3d43442b9d78cb1ba777e13a58506bce6 (patch)
tree285c017219563b85f30141f972df125be5705786 /library/std/src/sys/unix/stack_overflow.rs
parent36e050b85f5fc9acd27ff5e8cda57a36070f43e2 (diff)
parent044674337a180c494b7e6fdce4b20dca93324b2a (diff)
downloadrust-3e0360f3d43442b9d78cb1ba777e13a58506bce6.tar.gz
rust-3e0360f3d43442b9d78cb1ba777e13a58506bce6.zip
Merge branch 'master' into is-symlink-stabilization
Diffstat (limited to 'library/std/src/sys/unix/stack_overflow.rs')
-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());
         }