diff options
| author | Sebastian Wicki <gandro@gmx.net> | 2015-09-20 17:39:52 +0200 |
|---|---|---|
| committer | Sebastian Wicki <gandro@gmx.net> | 2015-09-21 21:50:54 +0200 |
| commit | 318cd843d1103579291a9f6c9eab8aacce7e9f82 (patch) | |
| tree | c2a4554e009be7ad14425df59694f7aacb0258b6 /src/libstd/sys | |
| parent | 25aaeb40b11a5983ed6000a8e466c08a701dfb99 (diff) | |
| download | rust-318cd843d1103579291a9f6c9eab8aacce7e9f82.tar.gz rust-318cd843d1103579291a9f6c9eab8aacce7e9f82.zip | |
Various fixes for NetBSD/amd64
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/c.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/sync.rs | 58 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 31 | ||||
| -rw-r--r-- | src/libstd/sys/unix/time.rs | 2 |
6 files changed, 99 insertions, 12 deletions
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs index eeecf7f50f7..051b3d8897d 100644 --- a/src/libstd/sys/unix/c.rs +++ b/src/libstd/sys/unix/c.rs @@ -61,9 +61,10 @@ pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70; target_os = "dragonfly"))] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71; #[cfg(any(target_os = "bitrig", - target_os = "netbsd", target_os = "openbsd"))] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101; +#[cfg(target_os = "netbsd")] +pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 48; #[cfg(target_os = "android")] pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048; @@ -131,26 +132,31 @@ extern { pub fn raise(signum: libc::c_int) -> libc::c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__sigaction14")] pub fn sigaction(signum: libc::c_int, act: *const sigaction, oldact: *mut sigaction) -> libc::c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__sigaltstack14")] pub fn sigaltstack(ss: *const sigaltstack, oss: *mut sigaltstack) -> libc::c_int; #[cfg(not(target_os = "android"))] + #[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")] pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int; pub fn pthread_sigmask(how: libc::c_int, set: *const sigset_t, oldset: *mut sigset_t) -> libc::c_int; #[cfg(not(target_os = "ios"))] + #[cfg_attr(target_os = "netbsd", link_name = "__getpwuid_r50")] pub fn getpwuid_r(uid: libc::uid_t, pwd: *mut passwd, buf: *mut libc::c_char, buflen: libc::size_t, result: *mut *mut passwd) -> libc::c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__utimes50")] pub fn utimes(filename: *const libc::c_char, times: *const libc::timeval) -> libc::c_int; pub fn gai_strerror(errcode: libc::c_int) -> *const libc::c_char; @@ -347,12 +353,12 @@ mod signal_os { #[cfg(any(target_os = "macos", target_os = "ios"))] pub type sigset_t = u32; - #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] + #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))] #[repr(C)] pub struct sigset_t { bits: [u32; 4], } - #[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))] + #[cfg(any(target_os = "bitrig", target_os = "openbsd"))] pub type sigset_t = libc::c_uint; // This structure has more fields, but we're not all that interested in diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 94c4d04ea30..c0e75368f74 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -213,7 +213,12 @@ pub fn current_exe() -> io::Result<PathBuf> { ::fs::read_link("/proc/curproc/file") } -#[cfg(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"))] +#[cfg(target_os = "netbsd")] +pub fn current_exe() -> io::Result<PathBuf> { + ::fs::read_link("/proc/curproc/exe") +} + +#[cfg(any(target_os = "bitrig", target_os = "openbsd"))] pub fn current_exe() -> io::Result<PathBuf> { use sync::StaticMutex; static LOCK: StaticMutex = StaticMutex::new(); diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 12ca31ce5e1..ce6e5609ce7 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -452,6 +452,7 @@ mod tests { #[cfg(not(target_os = "android"))] extern { + #[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")] fn sigaddset(set: *mut c::sigset_t, signum: libc::c_int) -> libc::c_int; } diff --git a/src/libstd/sys/unix/sync.rs b/src/libstd/sys/unix/sync.rs index 4e49b6473c9..aabeb41a369 100644 --- a/src/libstd/sys/unix/sync.rs +++ b/src/libstd/sys/unix/sync.rs @@ -40,6 +40,7 @@ extern { pub fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int; pub fn pthread_cond_broadcast(cond: *mut pthread_cond_t) -> libc::c_int; pub fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__gettimeofday50")] pub fn gettimeofday(tp: *mut libc::timeval, tz: *mut libc::c_void) -> libc::c_int; @@ -55,7 +56,6 @@ extern { #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "bitrig", - target_os = "netbsd", target_os = "openbsd"))] mod os { use libc; @@ -249,3 +249,59 @@ mod os { }; pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 1; } + +#[cfg(target_os = "netbsd")] +mod os { + use libc; + + // size of the type minus width of the magic int field + #[cfg(target_arch = "x86_64")] + const __PTHREAD_MUTEX_SIZE__: usize = 48 - 4; + + #[cfg(target_arch = "x86_64")] + const __PTHREAD_COND_SIZE__: usize = 40 - 4; + + #[cfg(target_arch = "x86_64")] + const __PTHREAD_RWLOCK_SIZE__: usize = 64 - 4; + + const _PTHREAD_MUTEX_MAGIC_INIT: libc::c_uint = 0x33330003; + const _PTHREAD_COND_MAGIC_INIT: libc::c_uint = 0x55550005; + const _PTHREAD_RWLOCK_MAGIC_INIT: libc::c_uint = 0x99990009; + + // note the actual structs are smaller + + #[repr(C, packed)] + pub struct pthread_mutex_t { + __magic: libc::c_uint, + __opaque: [u8; __PTHREAD_MUTEX_SIZE__], + } + #[repr(C, packed)] + pub struct pthread_mutexattr_t { + __opaque: [u8; 16], + } + #[repr(C, packed)] + pub struct pthread_cond_t { + __magic: libc::c_uint, + __opaque: [u8; __PTHREAD_COND_SIZE__], + } + #[repr(C, packed)] + pub struct pthread_rwlock_t { + __magic: libc::c_uint, + __opaque: [u8; __PTHREAD_RWLOCK_SIZE__], + } + + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + __magic: _PTHREAD_MUTEX_MAGIC_INIT, + __opaque: [0; __PTHREAD_MUTEX_SIZE__], + }; + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + __magic: _PTHREAD_COND_MAGIC_INIT, + __opaque: [0; __PTHREAD_COND_SIZE__], + }; + pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t { + __magic: _PTHREAD_RWLOCK_MAGIC_INIT, + __opaque: [0; __PTHREAD_RWLOCK_SIZE__], + }; + + pub const PTHREAD_MUTEX_RECURSIVE: libc::c_int = 2; +} diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 268ec7fe356..83e0a03a234 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -102,7 +102,6 @@ impl Thread { #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "bitrig", - target_os = "netbsd", target_os = "openbsd"))] pub fn set_name(name: &str) { extern { @@ -126,6 +125,21 @@ impl Thread { } } + #[cfg(target_os = "netbsd")] + pub fn set_name(name: &str) { + extern { + fn pthread_setname_np(thread: libc::pthread_t, + name: *const libc::c_char, + arg: *mut libc::c_void) -> libc::c_int; + } + let cname = CString::new(&b"%s"[..]).unwrap(); + let carg = CString::new(name).unwrap(); + unsafe { + pthread_setname_np(pthread_self(), cname.as_ptr(), + carg.as_ptr() as *mut libc::c_void); + } + } + pub fn sleep(dur: Duration) { let mut ts = libc::timespec { tv_sec: dur.as_secs() as libc::time_t, @@ -191,13 +205,12 @@ pub mod guard { #[cfg(any(target_os = "macos", target_os = "bitrig", - target_os = "netbsd", target_os = "openbsd"))] unsafe fn get_stack_start() -> Option<*mut libc::c_void> { current().map(|s| s as *mut libc::c_void) } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] unsafe fn get_stack_start() -> Option<*mut libc::c_void> { use super::pthread_attr_init; @@ -263,7 +276,7 @@ pub mod guard { pthread_get_stacksize_np(pthread_self())) as usize) } - #[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "bitrig"))] + #[cfg(any(target_os = "openbsd", target_os = "bitrig"))] pub unsafe fn current() -> Option<usize> { #[repr(C)] struct stack_t { @@ -290,7 +303,7 @@ pub mod guard { }) } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] pub unsafe fn current() -> Option<usize> { use super::pthread_attr_init; @@ -307,13 +320,17 @@ pub mod guard { let mut size = 0; assert_eq!(pthread_attr_getstack(&attr, &mut stackaddr, &mut size), 0); - ret = Some(stackaddr as usize + guardsize as usize); + ret = if cfg!(target_os = "netbsd") { + Some(stackaddr as usize) + } else { + Some(stackaddr as usize + guardsize as usize) + }; } assert_eq!(pthread_attr_destroy(&mut attr), 0); ret } - #[cfg(any(target_os = "linux", target_os = "android"))] + #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] extern { fn pthread_getattr_np(native: libc::pthread_t, attr: *mut libc::pthread_attr_t) -> libc::c_int; diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index db0d0f15061..73b66877588 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -86,7 +86,9 @@ mod inner { #[link(name = "rt")] extern {} + extern { + #[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")] fn clock_gettime(clk_id: libc::c_int, tp: *mut libc::timespec) -> libc::c_int; } |
