diff options
| author | bors <bors@rust-lang.org> | 2015-02-21 09:20:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-21 09:20:48 +0000 |
| commit | 2b01a37ec38db9301239f0c0abcf3c695055b0ff (patch) | |
| tree | a8fbf2329325d51716f163780d5e932989d04e06 /src/libstd/sys | |
| parent | 522d09dfecbeca1595f25ac58c6d0178bbd21d7d (diff) | |
| parent | 551304015bac6f8424fcc6827855d3c61fe167c9 (diff) | |
| download | rust-2b01a37ec38db9301239f0c0abcf3c695055b0ff.tar.gz rust-2b01a37ec38db9301239f0c0abcf3c695055b0ff.zip | |
Auto merge of #21959 - dhuseby:bitrig-support, r=brson
This patch adds the necessary pieces to support rust on Bitrig https://bitrig.org
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/common/net.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/common/stack.rs | 9 | ||||
| -rw-r--r-- | src/libstd/sys/unix/backtrace.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/c.rs | 52 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 33 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 14 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/stack_overflow.rs | 14 | ||||
| -rw-r--r-- | src/libstd/sys/unix/sync.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 35 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread_local.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/time.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/unix/tty.rs | 2 |
13 files changed, 150 insertions, 22 deletions
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index e2ac5ac24f8..b5cd42219e1 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -694,7 +694,8 @@ impl TcpStream { setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, seconds as libc::c_int) } - #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] + #[cfg(any(target_os = "freebsd", + target_os = "dragonfly"))] fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> { setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, seconds as libc::c_int) diff --git a/src/libstd/sys/common/stack.rs b/src/libstd/sys/common/stack.rs index 8dd2f154fa8..5ebc851e194 100644 --- a/src/libstd/sys/common/stack.rs +++ b/src/libstd/sys/common/stack.rs @@ -189,7 +189,8 @@ pub unsafe fn record_sp_limit(limit: uint) { unsafe fn target_record_sp_limit(limit: uint) { asm!("movq $0, %fs:24" :: "r"(limit) :: "volatile") } - #[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))] #[inline(always)] + #[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))] + #[inline(always)] unsafe fn target_record_sp_limit(limit: uint) { asm!("movq $0, %fs:32" :: "r"(limit) :: "volatile") } @@ -233,6 +234,7 @@ pub unsafe fn record_sp_limit(limit: uint) { #[cfg(any(target_arch = "aarch64", target_arch = "powerpc", all(target_arch = "arm", target_os = "ios"), + target_os = "bitrig", target_os = "openbsd"))] unsafe fn target_record_sp_limit(_: uint) { } @@ -276,14 +278,14 @@ pub unsafe fn get_sp_limit() -> uint { asm!("movq %fs:24, $0" : "=r"(limit) ::: "volatile"); return limit; } - #[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))] #[inline(always)] + #[cfg(all(target_arch = "x86_64", target_os = "dragonfly"))] + #[inline(always)] unsafe fn target_get_sp_limit() -> uint { let limit; asm!("movq %fs:32, $0" : "=r"(limit) ::: "volatile"); return limit; } - // x86 #[cfg(all(target_arch = "x86", any(target_os = "macos", target_os = "ios")))] @@ -331,6 +333,7 @@ pub unsafe fn get_sp_limit() -> uint { #[cfg(any(target_arch = "aarch64", target_arch = "powerpc", all(target_arch = "arm", target_os = "ios"), + target_os = "bitrig", target_os = "openbsd"))] #[inline(always)] unsafe fn target_get_sp_limit() -> uint { diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs index 8b560339f30..6f07dea5279 100644 --- a/src/libstd/sys/unix/backtrace.rs +++ b/src/libstd/sys/unix/backtrace.rs @@ -319,6 +319,7 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> { if !STATE.is_null() { return STATE } let selfname = if cfg!(target_os = "freebsd") || cfg!(target_os = "dragonfly") || + cfg!(target_os = "bitrig") || cfg!(target_os = "openbsd") { env::current_exe().ok() } else { diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs index 345808189a0..14394a653b0 100644 --- a/src/libstd/sys/unix/c.rs +++ b/src/libstd/sys/unix/c.rs @@ -24,6 +24,7 @@ use libc; target_os = "ios", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] pub const FIONBIO: libc::c_ulong = 0x8004667e; #[cfg(any(all(target_os = "linux", @@ -43,6 +44,7 @@ pub const FIONBIO: libc::c_ulong = 0x667e; target_os = "ios", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] pub const FIOCLEX: libc::c_ulong = 0x20006601; #[cfg(any(all(target_os = "linux", @@ -62,6 +64,7 @@ pub const FIOCLEX: libc::c_ulong = 0x6601; target_os = "ios", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] pub const MSG_DONTWAIT: libc::c_int = 0x80; #[cfg(any(target_os = "linux", target_os = "android"))] @@ -75,7 +78,8 @@ pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70; target_os = "freebsd", target_os = "dragonfly"))] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71; -#[cfg(target_os = "openbsd")] +#[cfg(any(target_os = "bitrig", + target_os = "openbsd"))] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101; #[cfg(target_os = "android")] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048; @@ -96,6 +100,7 @@ pub struct passwd { #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] pub struct passwd { pub pw_name: *mut libc::c_char, @@ -177,6 +182,7 @@ mod select { #[cfg(any(target_os = "android", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd", target_os = "linux"))] mod select { @@ -302,8 +308,7 @@ mod signal { #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", - target_os = "dragonfly", - target_os = "openbsd"))] + target_os = "dragonfly"))] mod signal { use libc; @@ -317,8 +322,7 @@ mod signal { pub const SIGCHLD: libc::c_int = 20; #[cfg(any(target_os = "macos", - target_os = "ios", - target_os = "openbsd"))] + target_os = "ios"))] pub type sigset_t = u32; #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] #[repr(C)] @@ -345,3 +349,41 @@ mod signal { pub sa_mask: sigset_t, } } + +#[cfg(any(target_os = "bitrig", target_os = "openbsd"))] +mod signal { + use libc; + + pub const SA_ONSTACK: libc::c_int = 0x0001; + pub const SA_RESTART: libc::c_int = 0x0002; + pub const SA_RESETHAND: libc::c_int = 0x0004; + pub const SA_NOCLDSTOP: libc::c_int = 0x0008; + pub const SA_NODEFER: libc::c_int = 0x0010; + pub const SA_NOCLDWAIT: libc::c_int = 0x0020; + pub const SA_SIGINFO: libc::c_int = 0x0040; + pub const SIGCHLD: libc::c_int = 20; + + pub type sigset_t = libc::c_uint; + + // This structure has more fields, but we're not all that interested in + // them. + #[repr(C)] + pub struct siginfo { + pub si_signo: libc::c_int, + pub si_code: libc::c_int, + pub si_errno: libc::c_int, + // FIXME: Bitrig has a crazy union here in the siginfo, I think this + // layout will still work tho. The status might be off by the size of + // a clock_t by my reading, but we can fix this later. + pub pid: libc::pid_t, + pub uid: libc::uid_t, + pub status: libc::c_int, + } + + #[repr(C)] + pub struct sigaction { + pub sa_handler: extern fn(libc::c_int), + pub sa_mask: sigset_t, + pub sa_flags: libc::c_int, + } +} diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 5c847002d23..1c28d629d40 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -291,6 +291,33 @@ fn mkstat(stat: &libc::stat) -> FileStat { // FileStat times are in milliseconds fn mktime(secs: u64, nsecs: u64) -> u64 { secs * 1000 + nsecs / 1000000 } + #[cfg(target_os = "bitrig")] + fn ctime(stat: &libc::stat) -> u64 { + mktime(stat.st_ctim.tv_sec as u64, stat.st_ctim.tv_nsec as u64) + } + #[cfg(not(target_os = "bitrig"))] + fn ctime(stat: &libc::stat) -> u64 { + mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64) + } + + #[cfg(target_os = "bitrig")] + fn atime(stat: &libc::stat) -> u64 { + mktime(stat.st_atim.tv_sec as u64, stat.st_atim.tv_nsec as u64) + } + #[cfg(not(target_os = "bitrig"))] + fn atime(stat: &libc::stat) -> u64 { + mktime(stat.st_atime as u64, stat.st_atime_nsec as u64) + } + + #[cfg(target_os = "bitrig")] + fn mtime(stat: &libc::stat) -> u64 { + mktime(stat.st_mtim.tv_sec as u64, stat.st_mtim.tv_nsec as u64) + } + #[cfg(not(target_os = "bitrig"))] + fn mtime(stat: &libc::stat) -> u64 { + mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64) + } + #[cfg(not(any(target_os = "linux", target_os = "android")))] fn flags(stat: &libc::stat) -> u64 { stat.st_flags as u64 } #[cfg(any(target_os = "linux", target_os = "android"))] @@ -312,9 +339,9 @@ fn mkstat(stat: &libc::stat) -> FileStat { _ => old_io::FileType::Unknown, }, perm: FilePermission::from_bits_truncate(stat.st_mode as u32), - created: mktime(stat.st_ctime as u64, stat.st_ctime_nsec as u64), - modified: mktime(stat.st_mtime as u64, stat.st_mtime_nsec as u64), - accessed: mktime(stat.st_atime as u64, stat.st_atime_nsec as u64), + created: ctime(stat), + modified: mtime(stat), + accessed: atime(stat), unstable: UnstableFileStat { device: stat.st_dev as u64, inode: stat.st_ino as u64, diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 3d1ef3a2c37..1f82d9a3d79 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -42,6 +42,16 @@ pub fn errno() -> i32 { __error() } + #[cfg(target_os = "bitrig")] + fn errno_location() -> *const c_int { + extern { + fn __errno() -> *const c_int; + } + unsafe { + __errno() + } + } + #[cfg(target_os = "dragonfly")] unsafe fn errno_location() -> *const c_int { extern { fn __dfly_error() -> *const c_int; } @@ -194,10 +204,9 @@ pub fn current_exe() -> IoResult<Path> { fs::readlink(&Path::new("/proc/curproc/file")) } -#[cfg(target_os = "openbsd")] +#[cfg(any(target_os = "bitrig", target_os = "openbsd"))] pub fn current_exe() -> IoResult<Path> { use sync::{StaticMutex, MUTEX_INIT}; - static LOCK: StaticMutex = MUTEX_INIT; extern { @@ -336,6 +345,7 @@ pub fn args() -> Args { target_os = "android", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] pub fn args() -> Args { use rt; diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index b30ac889120..582fff2a26b 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -856,6 +856,7 @@ fn translate_status(status: c_int) -> ProcessExit { target_os = "ios", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] mod imp { pub fn WIFEXITED(status: i32) -> bool { (status & 0x7f) == 0 } diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 3512fa36eb3..c2044c502b7 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -34,6 +34,7 @@ impl Drop for Handler { #[cfg(any(target_os = "linux", target_os = "macos", + target_os = "bitrig", target_os = "openbsd"))] mod imp { use core::prelude::*; @@ -205,7 +206,9 @@ mod imp { } - #[cfg(any(target_os = "macos", target_os = "openbsd"))] + #[cfg(any(target_os = "macos", + target_os = "bitrig", + target_os = "openbsd"))] mod signal { use libc; use super::sighandler_t; @@ -216,7 +219,7 @@ mod imp { #[cfg(target_os = "macos")] pub const SIGSTKSZ: libc::size_t = 131072; - #[cfg(target_os = "openbsd")] + #[cfg(any(target_os = "bitrig", target_os = "openbsd"))] pub const SIGSTKSZ: libc::size_t = 40960; pub const SIG_DFL: sighandler_t = 0 as sighandler_t; @@ -237,14 +240,14 @@ mod imp { pub si_addr: *mut libc::c_void } - #[cfg(target_os = "openbsd")] + #[cfg(any(target_os = "bitrig", 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, + //union + pub si_addr: *mut libc::c_void } #[repr(C)] @@ -277,6 +280,7 @@ mod imp { #[cfg(not(any(target_os = "linux", target_os = "macos", + target_os = "bitrig", target_os = "openbsd")))] mod imp { use libc; diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs index bc93513af63..c7d704922cb 100644 --- a/src/libstd/sys/unix/sync.rs +++ b/src/libstd/sys/unix/sync.rs @@ -46,6 +46,7 @@ extern { #[cfg(any(target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] mod os { use libc; diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index c90ba7645fe..c42d6d0e641 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -34,6 +34,7 @@ pub extern fn thread_start(main: *mut libc::c_void) -> rust_thread_return { #[cfg(all(not(target_os = "linux"), not(target_os = "macos"), + not(target_os = "bitrig"), not(target_os = "openbsd")))] pub mod guard { pub unsafe fn current() -> uint { @@ -51,11 +52,13 @@ pub mod guard { #[cfg(any(target_os = "linux", target_os = "macos", + target_os = "bitrig", target_os = "openbsd"))] pub mod guard { use super::*; #[cfg(any(target_os = "linux", target_os = "android", + target_os = "bitrig", target_os = "openbsd"))] use mem; #[cfg(any(target_os = "linux", target_os = "android"))] @@ -72,7 +75,9 @@ pub mod guard { static mut PAGE_SIZE: uint = 0; static mut GUARD_PAGE: uint = 0; - #[cfg(any(target_os = "macos", target_os = "openbsd"))] + #[cfg(any(target_os = "macos", + target_os = "bitrig", + target_os = "openbsd"))] unsafe fn get_stack_start() -> *mut libc::c_void { current() as *mut libc::c_void } @@ -190,6 +195,22 @@ pub mod guard { stackaddr as uint + guardsize as uint } + + #[cfg(target_os = "bitrig")] + 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 + } + } } pub unsafe fn create(stack: uint, p: Thunk) -> io::Result<rust_thread> { @@ -252,6 +273,7 @@ pub unsafe fn set_name(name: &str) { #[cfg(any(target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] pub unsafe fn set_name(name: &str) { // pthread_set_name_np() since almost forever on all BSDs @@ -334,6 +356,15 @@ extern { fn pthread_setname_np(name: *const libc::c_char) -> libc::c_int; } +#[cfg(target_os = "bitrig")] +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; + fn pthread_set_name_np(tid: libc::pthread_t, name: *const libc::c_char); +} + #[cfg(target_os = "openbsd")] extern { pub fn pthread_stackseg_np(thread: libc::pthread_t, @@ -341,7 +372,7 @@ extern { pub fn pthread_main_np() -> libc::c_uint; } -#[cfg(target_os = "openbsd")] +#[cfg(any(target_os = "bitrig", target_os = "openbsd"))] #[repr(C)] pub struct stack_t { pub ss_sp: *mut libc::c_void, diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs index 62d9a33c83d..9b7079ee108 100644 --- a/src/libstd/sys/unix/thread_local.rs +++ b/src/libstd/sys/unix/thread_local.rs @@ -43,6 +43,7 @@ type pthread_key_t = ::libc::c_ulong; #[cfg(any(target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd"))] type pthread_key_t = ::libc::c_int; @@ -50,6 +51,7 @@ type pthread_key_t = ::libc::c_int; target_os = "ios", target_os = "freebsd", target_os = "dragonfly", + target_os = "bitrig", target_os = "openbsd")))] type pthread_key_t = ::libc::c_uint; diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index bddf7b075df..1104bc995c6 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -80,8 +80,11 @@ mod inner { } // Apparently android provides this in some other library? + // Bitrig's RT extensions are in the C library, not a separate librt // OpenBSD provide it via libc - #[cfg(not(any(target_os = "android", target_os = "openbsd")))] + #[cfg(not(any(target_os = "android", + target_os = "bitrig", + target_os = "openbsd")))] #[link(name = "rt")] extern {} diff --git a/src/libstd/sys/unix/tty.rs b/src/libstd/sys/unix/tty.rs index 3a79047445c..8e60bbf4cbd 100644 --- a/src/libstd/sys/unix/tty.rs +++ b/src/libstd/sys/unix/tty.rs @@ -22,6 +22,7 @@ pub struct TTY { #[cfg(any(target_os = "macos", target_os = "freebsd", + target_os = "bitrig", target_os = "openbsd"))] const TIOCGWINSZ: c_ulong = 0x40087468; @@ -55,6 +56,7 @@ impl TTY { target_os = "android", target_os = "macos", target_os = "freebsd", + target_os = "bitrig", target_os = "openbsd"))] pub fn get_winsize(&mut self) -> IoResult<(int, int)> { unsafe { |
