about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/net.rs10
-rw-r--r--src/libstd/sys/common/stack.rs11
-rw-r--r--src/libstd/sys/unix/backtrace.rs5
-rw-r--r--src/libstd/sys/unix/c.rs17
-rw-r--r--src/libstd/sys/unix/os.rs30
-rw-r--r--src/libstd/sys/unix/process.rs5
-rw-r--r--src/libstd/sys/unix/stack_overflow.rs23
-rw-r--r--src/libstd/sys/unix/sync.rs4
-rw-r--r--src/libstd/sys/unix/thread.rs50
-rw-r--r--src/libstd/sys/unix/thread_local.rs8
-rw-r--r--src/libstd/sys/unix/time.rs3
-rw-r--r--src/libstd/sys/unix/tty.rs6
12 files changed, 144 insertions, 28 deletions
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs
index 51b6e0a1c1e..c826522e5d1 100644
--- a/src/libstd/sys/common/net.rs
+++ b/src/libstd/sys/common/net.rs
@@ -1,4 +1,4 @@
-// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -694,10 +694,16 @@ impl TcpStream {
         setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
                    seconds as libc::c_int)
     }
+    #[cfg(target_os = "openbsd")]
+    fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> {
+        setsockopt(self.fd(), libc::IPPROTO_TCP, libc::SO_KEEPALIVE,
+                   seconds as libc::c_int)
+    }
     #[cfg(not(any(target_os = "macos",
                   target_os = "ios",
                   target_os = "freebsd",
-                  target_os = "dragonfly")))]
+                  target_os = "dragonfly",
+                  target_os = "openbsd")))]
     fn set_tcp_keepalive(&mut self, _seconds: uint) -> IoResult<()> {
         Ok(())
     }
diff --git a/src/libstd/sys/common/stack.rs b/src/libstd/sys/common/stack.rs
index 88bb9395cf1..cd5458a2109 100644
--- a/src/libstd/sys/common/stack.rs
+++ b/src/libstd/sys/common/stack.rs
@@ -241,6 +241,11 @@ pub unsafe fn record_sp_limit(limit: uint) {
     #[cfg(all(target_arch = "arm", target_os = "ios"))] #[inline(always)]
     unsafe fn target_record_sp_limit(_: uint) {
     }
+
+    #[cfg(target_os = "openbsd")] #[inline(always)]
+    unsafe fn target_record_sp_limit(_: uint) {
+        // segmented stack is disabled
+    }
 }
 
 /// The counterpart of the function above, this function will fetch the current
@@ -345,4 +350,10 @@ pub unsafe fn get_sp_limit() -> uint {
     unsafe fn target_get_sp_limit() -> uint {
         1024
     }
+
+    #[cfg(target_os = "openbsd")] #[inline(always)]
+    unsafe fn target_get_sp_limit() -> uint {
+        // segmented stack is disabled
+        1024
+    }
 }
diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs
index e310b8f6d90..f32d59fe3c3 100644
--- a/src/libstd/sys/unix/backtrace.rs
+++ b/src/libstd/sys/unix/backtrace.rs
@@ -1,4 +1,4 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -318,7 +318,8 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
         static mut LAST_FILENAME: [libc::c_char; 256] = [0; 256];
         if !STATE.is_null() { return STATE }
         let selfname = if cfg!(target_os = "freebsd") ||
-                          cfg!(target_os = "dragonfly") {
+                          cfg!(target_os = "dragonfly") ||
+                          cfg!(target_os = "openbsd") {
             os::self_exe_name()
         } else {
             None
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs
index 9016d1a2c99..4fd7218d256 100644
--- a/src/libstd/sys/unix/c.rs
+++ b/src/libstd/sys/unix/c.rs
@@ -23,7 +23,8 @@ use libc;
 #[cfg(any(target_os = "macos",
           target_os = "ios",
           target_os = "freebsd",
-          target_os = "dragonfly"))]
+          target_os = "dragonfly",
+          target_os = "openbsd"))]
 pub const FIONBIO: libc::c_ulong = 0x8004667e;
 #[cfg(any(all(target_os = "linux",
               any(target_arch = "x86",
@@ -41,7 +42,8 @@ pub const FIONBIO: libc::c_ulong = 0x667e;
 #[cfg(any(target_os = "macos",
           target_os = "ios",
           target_os = "freebsd",
-          target_os = "dragonfly"))]
+          target_os = "dragonfly",
+          target_os = "openbsd"))]
 pub const FIOCLEX: libc::c_ulong = 0x20006601;
 #[cfg(any(all(target_os = "linux",
               any(target_arch = "x86",
@@ -59,7 +61,8 @@ pub const FIOCLEX: libc::c_ulong = 0x6601;
 #[cfg(any(target_os = "macos",
           target_os = "ios",
           target_os = "freebsd",
-          target_os = "dragonfly"))]
+          target_os = "dragonfly",
+          target_os = "openbsd"))]
 pub const MSG_DONTWAIT: libc::c_int = 0x80;
 #[cfg(any(target_os = "linux", target_os = "android"))]
 pub const MSG_DONTWAIT: libc::c_int = 0x40;
@@ -111,6 +114,7 @@ mod select {
 #[cfg(any(target_os = "android",
           target_os = "freebsd",
           target_os = "dragonfly",
+          target_os = "openbsd",
           target_os = "linux"))]
 mod select {
     use uint;
@@ -235,7 +239,8 @@ mod signal {
 #[cfg(any(target_os = "macos",
           target_os = "ios",
           target_os = "freebsd",
-          target_os = "dragonfly"))]
+          target_os = "dragonfly",
+          target_os = "openbsd"))]
 mod signal {
     use libc;
 
@@ -248,7 +253,9 @@ mod signal {
     pub const SA_SIGINFO: libc::c_int = 0x0040;
     pub const SIGCHLD: libc::c_int = 20;
 
-    #[cfg(any(target_os = "macos", target_os = "ios"))]
+    #[cfg(any(target_os = "macos",
+              target_os = "ios",
+              target_os = "openbsd"))]
     pub type sigset_t = u32;
     #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
     #[repr(C)]
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index dd343baa7c9..dd39501a7cb 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -1,4 +1,4 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -50,6 +50,16 @@ pub fn errno() -> int {
         }
     }
 
+    #[cfg(target_os = "openbsd")]
+    fn errno_location() -> *const c_int {
+        extern {
+            fn __errno() -> *const c_int;
+        }
+        unsafe {
+            __errno()
+        }
+    }
+
     #[cfg(any(target_os = "linux", target_os = "android"))]
     fn errno_location() -> *const c_int {
         extern {
@@ -71,7 +81,8 @@ pub fn error_string(errno: i32) -> String {
               target_os = "ios",
               target_os = "android",
               target_os = "freebsd",
-              target_os = "dragonfly"))]
+              target_os = "dragonfly",
+              target_os = "openbsd"))]
     fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: libc::size_t)
                   -> c_int {
         extern {
@@ -204,6 +215,21 @@ pub fn load_self() -> Option<Vec<u8>> {
     }
 }
 
+#[cfg(target_os = "openbsd")]
+pub fn load_self() -> Option<Vec<u8>> {
+    extern {
+        fn __load_self() -> *const c_char;
+    }
+    unsafe {
+        let v = __load_self();
+        if v.is_null() {
+            None
+        } else {
+            Some(ffi::c_str_to_bytes(&v).to_vec())
+        }
+    }
+}
+
 #[cfg(any(target_os = "linux", target_os = "android"))]
 pub fn load_self() -> Option<Vec<u8>> {
     use old_io;
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index b004a47f8a3..20a934445ee 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -1,4 +1,4 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -604,7 +604,8 @@ fn translate_status(status: c_int) -> ProcessExit {
     #[cfg(any(target_os = "macos",
               target_os = "ios",
               target_os = "freebsd",
-              target_os = "dragonfly"))]
+              target_os = "dragonfly",
+              target_os = "openbsd"))]
     mod imp {
         pub fn WIFEXITED(status: i32) -> bool { (status & 0x7f) == 0 }
         pub fn WEXITSTATUS(status: i32) -> i32 { status >> 8 }
diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs
index a526f3393f2..3512fa36eb3 100644
--- a/src/libstd/sys/unix/stack_overflow.rs
+++ b/src/libstd/sys/unix/stack_overflow.rs
@@ -32,7 +32,9 @@ impl Drop for Handler {
     }
 }
 
-#[cfg(any(target_os = "linux", target_os = "macos"))]
+#[cfg(any(target_os = "linux",
+          target_os = "macos",
+          target_os = "openbsd"))]
 mod imp {
     use core::prelude::*;
     use sys_common::stack;
@@ -203,7 +205,7 @@ mod imp {
 
     }
 
-    #[cfg(target_os = "macos")]
+    #[cfg(any(target_os = "macos", target_os = "openbsd"))]
     mod signal {
         use libc;
         use super::sighandler_t;
@@ -212,7 +214,10 @@ mod imp {
         pub const SA_SIGINFO: libc::c_int = 0x0040;
         pub const SIGBUS: libc::c_int = 10;
 
+        #[cfg(target_os = "macos")]
         pub const SIGSTKSZ: libc::size_t = 131072;
+        #[cfg(target_os = "openbsd")]
+        pub const SIGSTKSZ: libc::size_t = 40960;
 
         pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
 
@@ -220,6 +225,7 @@ mod imp {
 
         // This structure has more fields, but we're not all that interested in
         // them.
+        #[cfg(target_os = "macos")]
         #[repr(C)]
         pub struct siginfo {
             pub si_signo: libc::c_int,
@@ -231,6 +237,16 @@ mod imp {
             pub si_addr: *mut libc::c_void
         }
 
+        #[cfg(target_os = "openbsd")]
+        #[repr(C)]
+        pub struct siginfo {
+            pub si_signo: libc::c_int,
+            pub si_code: libc::c_int,
+            pub si_errno: libc::c_int,
+            // union
+            pub si_addr: *mut libc::c_void,
+        }
+
         #[repr(C)]
         pub struct sigaltstack {
             pub ss_sp: *mut libc::c_void,
@@ -260,7 +276,8 @@ mod imp {
 }
 
 #[cfg(not(any(target_os = "linux",
-              target_os = "macos")))]
+              target_os = "macos",
+              target_os = "openbsd")))]
 mod imp {
     use libc;
 
diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs
index c1e3fc88794..bc93513af63 100644
--- a/src/libstd/sys/unix/sync.rs
+++ b/src/libstd/sys/unix/sync.rs
@@ -44,7 +44,9 @@ extern {
     pub fn pthread_rwlock_unlock(lock: *mut pthread_rwlock_t) -> libc::c_int;
 }
 
-#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+#[cfg(any(target_os = "freebsd",
+          target_os = "dragonfly",
+          target_os = "openbsd"))]
 mod os {
     use libc;
 
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index 26a450b8599..433c37a97f3 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -1,4 +1,4 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -31,7 +31,9 @@ pub extern fn thread_start(main: *mut libc::c_void) -> rust_thread_return {
     return start_thread(main);
 }
 
-#[cfg(all(not(target_os = "linux"), not(target_os = "macos")))]
+#[cfg(all(not(target_os = "linux"),
+          not(target_os = "macos"),
+          not(target_os = "openbsd")))]
 pub mod guard {
     pub unsafe fn current() -> uint {
         0
@@ -45,10 +47,15 @@ pub mod guard {
     }
 }
 
-#[cfg(any(target_os = "linux", target_os = "macos"))]
+
+#[cfg(any(target_os = "linux",
+          target_os = "macos",
+          target_os = "openbsd"))]
 pub mod guard {
     use super::*;
-    #[cfg(any(target_os = "linux", target_os = "android"))]
+    #[cfg(any(target_os = "linux",
+              target_os = "android",
+              target_os = "openbsd"))]
     use mem;
     #[cfg(any(target_os = "linux", target_os = "android"))]
     use ptr;
@@ -64,7 +71,7 @@ pub mod guard {
     static mut PAGE_SIZE: uint = 0;
     static mut GUARD_PAGE: uint = 0;
 
-    #[cfg(target_os = "macos")]
+    #[cfg(any(target_os = "macos", target_os = "openbsd"))]
     unsafe fn get_stack_start() -> *mut libc::c_void {
         current() as *mut libc::c_void
     }
@@ -141,6 +148,23 @@ pub mod guard {
          pthread_get_stacksize_np(pthread_self())) as uint
     }
 
+    #[cfg(target_os = "openbsd")]
+    pub unsafe fn current() -> uint {
+        let mut current_stack: stack_t = mem::zeroed();
+        if pthread_stackseg_np(pthread_self(), &mut current_stack) != 0 {
+            panic!("failed to get current stack: pthread_stackseg_np")
+        }
+
+        if pthread_main_np() == 1 {
+            // main thread
+            current_stack.ss_sp as uint - current_stack.ss_size as uint + 3 * PAGE_SIZE as uint
+
+        } else {
+            // new thread
+            current_stack.ss_sp as uint - current_stack.ss_size as uint
+        }
+    }
+
     #[cfg(any(target_os = "linux", target_os = "android"))]
     pub unsafe fn current() -> uint {
         let mut attr: libc::pthread_attr_t = mem::zeroed();
@@ -304,6 +328,22 @@ extern {
     fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int;
 }
 
+#[cfg(target_os = "openbsd")]
+extern {
+        pub fn pthread_self() -> libc::pthread_t;
+        pub fn pthread_stackseg_np(thread: libc::pthread_t,
+                                   sinfo: *mut stack_t) -> libc::c_uint;
+        pub fn pthread_main_np() -> libc::c_uint;
+}
+
+#[cfg(target_os = "openbsd")]
+#[repr(C)]
+pub struct stack_t {
+    pub ss_sp: *mut libc::c_void,
+    pub ss_size: libc::size_t,
+    pub ss_flags: libc::c_int,
+}
+
 extern {
     fn pthread_create(native: *mut libc::pthread_t,
                       attr: *const libc::pthread_attr_t,
diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs
index ea1e9c261fe..62d9a33c83d 100644
--- a/src/libstd/sys/unix/thread_local.rs
+++ b/src/libstd/sys/unix/thread_local.rs
@@ -1,4 +1,4 @@
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -42,13 +42,15 @@ pub unsafe fn destroy(key: Key) {
 type pthread_key_t = ::libc::c_ulong;
 
 #[cfg(any(target_os = "freebsd",
-          target_os = "dragonfly"))]
+          target_os = "dragonfly",
+          target_os = "openbsd"))]
 type pthread_key_t = ::libc::c_int;
 
 #[cfg(not(any(target_os = "macos",
               target_os = "ios",
               target_os = "freebsd",
-              target_os = "dragonfly")))]
+              target_os = "dragonfly",
+              target_os = "openbsd")))]
 type pthread_key_t = ::libc::c_uint;
 
 extern {
diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs
index cc1e23fbca9..bddf7b075df 100644
--- a/src/libstd/sys/unix/time.rs
+++ b/src/libstd/sys/unix/time.rs
@@ -80,7 +80,8 @@ mod inner {
     }
 
     // Apparently android provides this in some other library?
-    #[cfg(not(target_os = "android"))]
+    // OpenBSD provide it via libc
+    #[cfg(not(any(target_os = "android", target_os = "openbsd")))]
     #[link(name = "rt")]
     extern {}
 
diff --git a/src/libstd/sys/unix/tty.rs b/src/libstd/sys/unix/tty.rs
index d414f70152d..3a79047445c 100644
--- a/src/libstd/sys/unix/tty.rs
+++ b/src/libstd/sys/unix/tty.rs
@@ -21,7 +21,8 @@ pub struct TTY {
 }
 
 #[cfg(any(target_os = "macos",
-          target_os = "freebsd"))]
+          target_os = "freebsd",
+          target_os = "openbsd"))]
 const TIOCGWINSZ: c_ulong = 0x40087468;
 
 #[cfg(any(target_os = "linux", target_os = "android"))]
@@ -53,7 +54,8 @@ impl TTY {
     #[cfg(any(target_os = "linux",
               target_os = "android",
               target_os = "macos",
-              target_os = "freebsd"))]
+              target_os = "freebsd",
+              target_os = "openbsd"))]
     pub fn get_winsize(&mut self) -> IoResult<(int, int)> {
         unsafe {
             #[repr(C)]