summary refs log tree commit diff
path: root/src/libstd/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-03 06:38:01 +0000
committerbors <bors@rust-lang.org>2016-02-03 06:38:01 +0000
commit54664f188403a5bb72634b5e3ba9b2f7b60b4d9f (patch)
tree6c680499f3822c50f9e900b2acc079bf4ca0f0b1 /src/libstd/sys/unix/stack_overflow.rs
parent50df6b9dc5144df09ef6b8519afd3657abdab03f (diff)
parentca6f9203461f57a1f1a88266efeb61a5aa47d66b (diff)
downloadrust-54664f188403a5bb72634b5e3ba9b2f7b60b4d9f.tar.gz
rust-54664f188403a5bb72634b5e3ba9b2f7b60b4d9f.zip
Auto merge of #31263 - dhuseby:fixing_bsd_builds, r=alexcrichton
Something went haywire with github last night and the old PR https://github.com/rust-lang/rust/pull/31230 got closed somehow.  This new PR is to replace the old one.  This incorporates all of the feedback from the other PR.

@alexcrichton I incorporated the suggestion from @semarie and the result is cleaner and clearer.  I think this is ready to go.
Diffstat (limited to 'src/libstd/sys/unix/stack_overflow.rs')
-rw-r--r--src/libstd/sys/unix/stack_overflow.rs40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs
index c7614db3299..b5cbcaa44d5 100644
--- a/src/libstd/sys/unix/stack_overflow.rs
+++ b/src/libstd/sys/unix/stack_overflow.rs
@@ -135,26 +135,38 @@ mod imp {
         Handler { _data: MAIN_ALTSTACK };
     }
 
-    pub unsafe fn make_handler() -> Handler {
-        let alt_stack = mmap(ptr::null_mut(),
-                             SIGSTKSZ,
-                             PROT_READ | PROT_WRITE,
-                             MAP_PRIVATE | MAP_ANON,
-                             -1,
-                             0);
-        if alt_stack == MAP_FAILED {
+    unsafe fn get_stackp() -> *mut libc::c_void {
+        let stackp = mmap(ptr::null_mut(),
+                          SIGSTKSZ,
+                          PROT_READ | PROT_WRITE,
+                          MAP_PRIVATE | MAP_ANON,
+                          -1,
+                          0);
+        if stackp == MAP_FAILED {
             panic!("failed to allocate an alternative stack");
         }
+        stackp
+    }
 
-        let mut stack: libc::stack_t = mem::zeroed();
+    #[cfg(any(target_os = "linux",
+              target_os = "macos",
+              target_os = "bitrig",
+              target_os = "netbsd",
+              target_os = "openbsd"))]
+    unsafe fn get_stack() -> libc::stack_t {
+        libc::stack_t { ss_sp: get_stackp(), ss_flags: 0, ss_size: SIGSTKSZ }
+    }
 
-        stack.ss_sp = alt_stack;
-        stack.ss_flags = 0;
-        stack.ss_size = SIGSTKSZ;
+    #[cfg(any(target_os = "freebsd",
+              target_os = "dragonfly"))]
+    unsafe fn get_stack() -> libc::stack_t {
+        libc::stack_t { ss_sp: get_stackp() as *mut i8, ss_flags: 0, ss_size: SIGSTKSZ }
+    }
 
+    pub unsafe fn make_handler() -> Handler {
+        let stack = get_stack();
         sigaltstack(&stack, ptr::null_mut());
-
-        Handler { _data: alt_stack }
+        Handler { _data: stack.ss_sp as *mut libc::c_void }
     }
 
     pub unsafe fn drop_handler(handler: &mut Handler) {