]> git.proxmox.com Git - rustc.git/blobdiff - src/libstd/sys/unix/stack_overflow.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / libstd / sys / unix / stack_overflow.rs
index f5fd11b61b1e67efef59b9c50f31075b3fc8836a..9a7f98d24cd5df733617cc416f13f7223e1e7aff 100644 (file)
@@ -34,6 +34,8 @@ impl Drop for Handler {
 #[cfg(any(target_os = "linux",
           target_os = "macos",
           target_os = "bitrig",
+          target_os = "dragonfly",
+          target_os = "freebsd",
           all(target_os = "netbsd", not(target_vendor = "rumprun")),
           target_os = "openbsd"))]
 mod imp {
@@ -41,11 +43,11 @@ mod imp {
     use sys_common::util::report_overflow;
     use mem;
     use ptr;
-    use sys::c::{siginfo, sigaction, SIGBUS, SIG_DFL,
-                 SA_SIGINFO, SA_ONSTACK, sigaltstack,
-                 SIGSTKSZ, sighandler_t};
+    use libc::{sigaction, SIGBUS, SIG_DFL,
+               SA_SIGINFO, SA_ONSTACK, sigaltstack,
+               SIGSTKSZ, sighandler_t};
     use libc;
-    use libc::funcs::posix88::mman::{mmap, munmap};
+    use libc::{mmap, munmap};
     use libc::{SIGSEGV, PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANON};
     use libc::MAP_FAILED;
 
@@ -55,6 +57,22 @@ mod imp {
     // This is initialized in init() and only read from after
     static mut PAGE_SIZE: usize = 0;
 
+    #[cfg(any(target_os = "linux", target_os = "android"))]
+    unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void {
+        #[repr(C)]
+        struct siginfo_t {
+            a: [libc::c_int; 3], // si_signo, si_code, si_errno,
+            si_addr: *mut libc::c_void,
+        }
+
+        (*(info as *const siginfo_t)).si_addr
+    }
+
+    #[cfg(not(any(target_os = "linux", target_os = "android")))]
+    unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> *mut libc::c_void {
+        (*info).si_addr
+    }
+
     // Signal handler for the SIGSEGV and SIGBUS handlers. We've got guard pages
     // (unmapped pages) at the end of every thread's stack, so if a thread ends
     // up running into the guard page it'll trigger this handler. We want to
@@ -74,10 +92,10 @@ mod imp {
     // handler to work. For a more detailed explanation see the comments on
     // #26458.
     unsafe extern fn signal_handler(signum: libc::c_int,
-                                    info: *mut siginfo,
+                                    info: *mut libc::siginfo_t,
                                     _data: *mut libc::c_void) {
         let guard = thread_info::stack_guard().unwrap_or(0);
-        let addr = (*info).si_addr as usize;
+        let addr = siginfo_si_addr(info) as usize;
 
         // If the faulting address is within the guard page, then we print a
         // message saying so.
@@ -124,7 +142,7 @@ mod imp {
             panic!("failed to allocate an alternative stack");
         }
 
-        let mut stack: sigaltstack = mem::zeroed();
+        let mut stack: libc::stack_t = mem::zeroed();
 
         stack.ss_sp = alt_stack;
         stack.ss_flags = 0;
@@ -143,6 +161,8 @@ mod imp {
 #[cfg(not(any(target_os = "linux",
               target_os = "macos",
               target_os = "bitrig",
+              target_os = "dragonfly",
+              target_os = "freebsd",
               all(target_os = "netbsd", not(target_vendor = "rumprun")),
               target_os = "openbsd")))]
 mod imp {