diff options
| author | Dave Huseby <dhuseby@mozilla.com> | 2015-01-16 23:51:04 -0800 |
|---|---|---|
| committer | Dave Huseby <dhuseby@mozilla.com> | 2015-02-11 14:49:06 -0800 |
| commit | cd8f31759fd04b9ce9c903fa00cae81dc5bba546 (patch) | |
| tree | 7c0cb181b5e808735036346cb9ce7789847111e3 /src/libstd/sys/unix | |
| parent | e29f42025513374f1a88404491d1b40386acf994 (diff) | |
| download | rust-cd8f31759fd04b9ce9c903fa00cae81dc5bba546.tar.gz rust-cd8f31759fd04b9ce9c903fa00cae81dc5bba546.zip | |
bitrig integration
Diffstat (limited to 'src/libstd/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/backtrace.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/c.rs | 46 | ||||
| -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 | 15 | ||||
| -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 |
11 files changed, 142 insertions, 13 deletions
diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs index 5e512e9261b..258e7058452 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 cf05733cc18..06e5333239e 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, @@ -176,6 +181,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 { @@ -344,3 +350,41 @@ mod signal { pub sa_mask: sigset_t, } } + +#[cfg(target_os = "bitrig")] +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 66ae018cb36..9bde7ed9d7e 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 b191eda583c..67098ac4689 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -40,6 +40,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; } @@ -192,10 +202,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 { @@ -330,6 +339,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 52a8ac9c338..4438d5d1b1f 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -593,6 +593,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..efcb92e4826 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; @@ -219,6 +222,9 @@ mod imp { #[cfg(target_os = "openbsd")] pub const SIGSTKSZ: libc::size_t = 40960; + #[cfg(target_os = "bitrig")] + pub const SIGSTKSZ: libc::size_t = 40960; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub type sigset_t = u32; @@ -237,14 +243,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 +283,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 6f030ee91fe..2a9531fa528 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -33,6 +33,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 { @@ -50,11 +51,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"))] @@ -71,7 +74,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 } @@ -189,6 +194,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) -> rust_thread { @@ -250,6 +271,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 @@ -332,6 +354,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, @@ -339,7 +370,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..7016a700dd8 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 { |
