diff options
| author | bors <bors@rust-lang.org> | 2016-02-03 22:40:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-03 22:40:32 +0000 |
| commit | e3bcddb44bc810ddf5b0443e45e42a835d17d868 (patch) | |
| tree | d1b24022bb34fe5a3d8851dee5b8a8291c47bb12 /src/libstd | |
| parent | 18c1781a4c8aaaeb11285e0099edfff2043b62a5 (diff) | |
| parent | fae883c113031805cedb853c4176ecfef0b62bbc (diff) | |
| download | rust-e3bcddb44bc810ddf5b0443e45e42a835d17d868.tar.gz rust-e3bcddb44bc810ddf5b0443e45e42a835d17d868.zip | |
Auto merge of #31078 - nbaksalyar:illumos, r=alexcrichton
This pull request adds support for [Illumos](http://illumos.org/)-based operating systems: SmartOS, OpenIndiana, and others. For now it's x86-64 only, as I'm not sure if 32-bit installations are widespread. This PR is based on #28589 by @potatosalad, and also closes #21000, #25845, and #25846. Required changes in libc are already merged: https://github.com/rust-lang-nursery/libc/pull/138 Here's a snapshot required to build a stage0 compiler: https://s3-eu-west-1.amazonaws.com/nbaksalyar/rustc-sunos-snapshot.tar.gz It passes all checks from `make check`. There are some changes I'm not quite sure about, e.g. macro usage in `src/libstd/num/f64.rs` and `DirEntry` structure in `src/libstd/sys/unix/fs.rs`, so any comments on how to rewrite it better would be greatly appreciated. Also, LLVM configure script might need to be patched to build it successfully, or a pre-built libLLVM should be used. Some details can be found here: https://llvm.org/bugs/show_bug.cgi?id=25409 Thanks! r? @brson
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/dynamic_lib.rs | 6 | ||||
| -rw-r--r-- | src/libstd/env.rs | 12 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 31 | ||||
| -rw-r--r-- | src/libstd/os/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/os/solaris/mod.rs | 21 | ||||
| -rw-r--r-- | src/libstd/os/solaris/raw.rs | 68 | ||||
| -rw-r--r-- | src/libstd/rtdeps.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/common/args.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/common/libunwind.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fd.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 56 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 64 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/stack_overflow.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 24 |
16 files changed, 272 insertions, 30 deletions
diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 585051a98e5..12edc9ffc64 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -172,7 +172,8 @@ mod tests { target_os = "dragonfly", target_os = "bitrig", target_os = "netbsd", - target_os = "openbsd"))] + target_os = "openbsd", + target_os = "solaris"))] #[allow(deprecated)] fn test_errors_do_not_crash() { use path::Path; @@ -195,7 +196,8 @@ mod tests { target_os = "dragonfly", target_os = "bitrig", target_os = "netbsd", - target_os = "openbsd"))] + target_os = "openbsd", + target_os = "solaris"))] mod dl { use prelude::v1::*; diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 410d7a6c91f..d21e37a012a 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -640,6 +640,7 @@ pub mod consts { /// - bitrig /// - netbsd /// - openbsd + /// - solaris /// - android /// - windows #[stable(feature = "env", since = "1.0.0")] @@ -800,6 +801,17 @@ mod os { pub const EXE_EXTENSION: &'static str = ""; } +#[cfg(target_os = "solaris")] +mod os { + pub const FAMILY: &'static str = "unix"; + pub const OS: &'static str = "solaris"; + pub const DLL_PREFIX: &'static str = "lib"; + pub const DLL_SUFFIX: &'static str = ".so"; + pub const DLL_EXTENSION: &'static str = "so"; + pub const EXE_SUFFIX: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; +} + #[cfg(target_os = "windows")] mod os { pub const FAMILY: &'static str = "windows"; diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index b6a85ee0e9f..a39311f7d10 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -511,7 +511,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ln(self) -> f64 { - unsafe { intrinsics::logf64(self) } + self.log_wrapper(|n| { unsafe { intrinsics::logf64(n) } }) } /// Returns the logarithm of the number with respect to an arbitrary base. @@ -546,7 +546,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log2(self) -> f64 { - unsafe { intrinsics::log2f64(self) } + self.log_wrapper(|n| { unsafe { intrinsics::log2f64(n) } }) } /// Returns the base 10 logarithm of the number. @@ -562,7 +562,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn log10(self) -> f64 { - unsafe { intrinsics::log10f64(self) } + self.log_wrapper(|n| { unsafe { intrinsics::log10f64(n) } }) } /// Converts radians to degrees. @@ -1065,6 +1065,31 @@ impl f64 { pub fn atanh(self) -> f64 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() } + + // Solaris/Illumos requires a wrapper around log, log2, and log10 functions + // because of their non-standard behavior (e.g. log(-n) returns -Inf instead + // of expected NaN). + fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 { + if !cfg!(target_os = "solaris") { + log_fn(self) + } else { + if self.is_finite() { + if self > 0.0 { + log_fn(self) + } else if self == 0.0 { + NEG_INFINITY // log(0) = -Inf + } else { + NAN // log(-n) = NaN + } + } else if self.is_nan() { + self // log(NaN) = NaN + } else if self > 0.0 { + self // log(Inf) = Inf + } else { + NAN // log(-Inf) = NaN + } + } + } } #[cfg(test)] diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs index 84b7d9fbeec..5606c127dcb 100644 --- a/src/libstd/os/mod.rs +++ b/src/libstd/os/mod.rs @@ -30,5 +30,6 @@ pub use sys::ext as windows; #[cfg(target_os = "nacl")] pub mod nacl; #[cfg(target_os = "netbsd")] pub mod netbsd; #[cfg(target_os = "openbsd")] pub mod openbsd; +#[cfg(target_os = "solaris")] pub mod solaris; pub mod raw; diff --git a/src/libstd/os/solaris/mod.rs b/src/libstd/os/solaris/mod.rs new file mode 100644 index 00000000000..f265233bd54 --- /dev/null +++ b/src/libstd/os/solaris/mod.rs @@ -0,0 +1,21 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Solaris-specific definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] + +pub mod raw; + +#[stable(feature = "raw_ext", since = "1.1.0")] +pub mod fs { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub use sys::fs::MetadataExt; +} diff --git a/src/libstd/os/solaris/raw.rs b/src/libstd/os/solaris/raw.rs new file mode 100644 index 00000000000..cf46ae4a360 --- /dev/null +++ b/src/libstd/os/solaris/raw.rs @@ -0,0 +1,68 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Solaris-specific raw type definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] + +use os::raw::c_long; +use os::unix::raw::{uid_t, gid_t}; + +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64; +#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; + +#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize; + +#[repr(C)] +#[derive(Clone)] +#[stable(feature = "raw_ext", since = "1.1.0")] +pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: dev_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: ino_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: mode_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: nlink_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: uid_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: gid_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: dev_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: off_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: blksize_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: blkcnt_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __unused: [u8; 16] +} diff --git a/src/libstd/rtdeps.rs b/src/libstd/rtdeps.rs index 9b1046f39a7..b1b9ffc4dc6 100644 --- a/src/libstd/rtdeps.rs +++ b/src/libstd/rtdeps.rs @@ -39,6 +39,12 @@ extern {} #[link(name = "pthread")] extern {} +#[cfg(target_os = "solaris")] +#[link(name = "socket")] +#[link(name = "posix4")] +#[link(name = "pthread")] +extern {} + // For PNaCl targets, nacl_io is a Pepper wrapper for some IO functions // missing (ie always error) in Newlib. #[cfg(all(target_os = "nacl", not(test)))] diff --git a/src/libstd/sys/common/args.rs b/src/libstd/sys/common/args.rs index 4cfddb036e9..4600983eb3b 100644 --- a/src/libstd/sys/common/args.rs +++ b/src/libstd/sys/common/args.rs @@ -38,7 +38,8 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() } target_os = "dragonfly", target_os = "bitrig", target_os = "netbsd", - target_os = "openbsd"))] + target_os = "openbsd", + target_os = "solaris"))] mod imp { use prelude::v1::*; diff --git a/src/libstd/sys/common/libunwind.rs b/src/libstd/sys/common/libunwind.rs index f44a8cb21e9..956f6005f1c 100644 --- a/src/libstd/sys/common/libunwind.rs +++ b/src/libstd/sys/common/libunwind.rs @@ -101,6 +101,7 @@ pub type _Unwind_Exception_Cleanup_Fn = #[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")), target_os = "freebsd", + target_os = "solaris", all(target_os = "linux", target_env = "musl", not(target_arch = "x86_64"))), link(name = "gcc_s"))] #[cfg_attr(all(target_os = "linux", target_env = "musl", target_arch = "x86_64", not(test)), diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index e09f4ca27bc..94775341c38 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -50,14 +50,14 @@ impl FileDesc { Ok(ret as usize) } - #[cfg(not(target_env = "newlib"))] + #[cfg(not(any(target_env = "newlib", target_os = "solaris")))] pub fn set_cloexec(&self) { unsafe { let ret = libc::ioctl(self.fd, libc::FIOCLEX); debug_assert_eq!(ret, 0); } } - #[cfg(target_env = "newlib")] + #[cfg(any(target_env = "newlib", target_os = "solaris"))] pub fn set_cloexec(&self) { unsafe { let previous = libc::fcntl(self.fd, libc::F_GETFD); diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 91931811234..f5d03cad657 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -8,14 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; use io::prelude::*; use os::unix::prelude::*; use ffi::{CString, CStr, OsString, OsStr}; use fmt; use io::{self, Error, ErrorKind, SeekFrom}; -use libc::{dirent, readdir_r}; -use libc::{self, c_int, off_t, mode_t}; +use libc::{self, dirent, c_int, off_t, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; @@ -24,7 +24,6 @@ use sys::fd::FileDesc; use sys::platform::raw; use sys::{cvt, cvt_r}; use sys_common::{AsInner, FromInner}; -use vec::Vec; pub struct File(FileDesc); @@ -46,6 +45,12 @@ unsafe impl Sync for Dir {} pub struct DirEntry { entry: dirent, root: Arc<PathBuf>, + // We need to store an owned copy of the directory name + // on Solaris because a) it uses a zero-length array to + // store the name, b) its lifetime between readdir calls + // is not guaranteed. + #[cfg(target_os = "solaris")] + name: Box<[u8]> } #[derive(Clone)] @@ -132,6 +137,36 @@ impl FromInner<raw::mode_t> for FilePermissions { impl Iterator for ReadDir { type Item = io::Result<DirEntry>; + #[cfg(target_os = "solaris")] + fn next(&mut self) -> Option<io::Result<DirEntry>> { + unsafe { + loop { + // Although readdir_r(3) would be a correct function to use here because + // of the thread safety, on Illumos the readdir(3C) function is safe to use + // in threaded applications and it is generally preferred over the + // readdir_r(3C) function. + let entry_ptr = libc::readdir(self.dirp.0); + if entry_ptr.is_null() { + return None + } + + let name = (*entry_ptr).d_name.as_ptr(); + let namelen = libc::strlen(name) as usize; + + let ret = DirEntry { + entry: *entry_ptr, + name: ::slice::from_raw_parts(name as *const u8, + namelen as usize).to_owned().into_boxed_slice(), + root: self.root.clone() + }; + if ret.name_bytes() != b"." && ret.name_bytes() != b".." { + return Some(Ok(ret)) + } + } + } + } + + #[cfg(not(target_os = "solaris"))] fn next(&mut self) -> Option<io::Result<DirEntry>> { unsafe { let mut ret = DirEntry { @@ -140,7 +175,7 @@ impl Iterator for ReadDir { }; let mut entry_ptr = ptr::null_mut(); loop { - if readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { + if libc::readdir_r(self.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 { return Some(Err(Error::last_os_error())) } if entry_ptr.is_null() { @@ -174,6 +209,12 @@ impl DirEntry { lstat(&self.path()) } + #[cfg(target_os = "solaris")] + pub fn file_type(&self) -> io::Result<FileType> { + stat(&self.path()).map(|m| m.file_type()) + } + + #[cfg(not(target_os = "solaris"))] pub fn file_type(&self) -> io::Result<FileType> { match self.entry.d_type { libc::DT_CHR => Ok(FileType { mode: libc::S_IFCHR }), @@ -189,7 +230,8 @@ impl DirEntry { #[cfg(any(target_os = "macos", target_os = "ios", - target_os = "linux"))] + target_os = "linux", + target_os = "solaris"))] pub fn ino(&self) -> raw::ino_t { self.entry.d_ino } @@ -228,6 +270,10 @@ impl DirEntry { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() } } + #[cfg(target_os = "solaris")] + fn name_bytes(&self) -> &[u8] { + &*self.name + } } impl OpenOptions { diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 2e89becfa67..f8a4bcdecd7 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -25,6 +25,7 @@ use ops::Neg; #[cfg(target_os = "nacl")] pub use os::nacl as platform; #[cfg(target_os = "netbsd")] pub use os::netbsd as platform; #[cfg(target_os = "openbsd")] pub use os::openbsd as platform; +#[cfg(target_os = "solaris")] pub use os::solaris as platform; pub mod backtrace; pub mod condvar; diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index c62960d74cb..da770514593 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -45,6 +45,7 @@ pub fn errno() -> i32 { target_os = "android", target_env = "newlib"), link_name = "__errno")] + #[cfg_attr(target_os = "solaris", link_name = "___errno")] #[cfg_attr(target_os = "dragonfly", link_name = "__dfly_error")] #[cfg_attr(any(target_os = "macos", target_os = "ios", @@ -257,6 +258,30 @@ pub fn current_exe() -> io::Result<PathBuf> { } } +#[cfg(any(target_os = "solaris"))] +pub fn current_exe() -> io::Result<PathBuf> { + extern { + fn getexecname() -> *const c_char; + } + unsafe { + let path = getexecname(); + if path.is_null() { + Err(io::Error::last_os_error()) + } else { + let filename = CStr::from_ptr(path).to_bytes(); + let path = PathBuf::from(<OsStr as OsStrExt>::from_bytes(filename)); + + // Prepend a current working directory to the path if + // it doesn't contain an absolute pathname. + if filename[0] == b'/' { + Ok(path) + } else { + getcwd().map(|cwd| cwd.join(path)) + } + } + } +} + pub struct Args { iter: vec::IntoIter<OsString>, _dont_send_or_sync_me: *mut (), @@ -359,6 +384,7 @@ pub fn args() -> Args { target_os = "bitrig", target_os = "netbsd", target_os = "openbsd", + target_os = "solaris", target_os = "nacl"))] pub fn args() -> Args { use sys_common; @@ -489,6 +515,28 @@ pub fn home_dir() -> Option<PathBuf> { target_os = "ios", target_os = "nacl")))] unsafe fn fallback() -> Option<OsString> { + #[cfg(not(target_os = "solaris"))] + unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, + buf: &mut Vec<c_char>) -> Option<()> { + let mut result = ptr::null_mut(); + match libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), + buf.capacity() as libc::size_t, + &mut result) { + 0 if !result.is_null() => Some(()), + _ => None + } + } + + #[cfg(target_os = "solaris")] + unsafe fn getpwduid_r(me: libc::uid_t, passwd: &mut libc::passwd, + buf: &mut Vec<c_char>) -> Option<()> { + // getpwuid_r semantics is different on Illumos/Solaris: + // http://illumos.org/man/3c/getpwuid_r + let result = libc::getpwuid_r(me, passwd, buf.as_mut_ptr(), + buf.capacity() as libc::size_t); + if result.is_null() { None } else { Some(()) } + } + let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, @@ -497,16 +545,14 @@ pub fn home_dir() -> Option<PathBuf> { loop { let mut buf = Vec::with_capacity(amt); let mut passwd: libc::passwd = mem::zeroed(); - let mut result = ptr::null_mut(); - match libc::getpwuid_r(me, &mut passwd, buf.as_mut_ptr(), - buf.capacity() as libc::size_t, - &mut result) { - 0 if !result.is_null() => {} - _ => return None + + if getpwduid_r(me, &mut passwd, &mut buf).is_some() { + let ptr = passwd.pw_dir as *const _; + let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); + return Some(OsStringExt::from_vec(bytes)) + } else { + return None; } - let ptr = passwd.pw_dir as *const _; - let bytes = CStr::from_ptr(ptr).to_bytes().to_vec(); - return Some(OsStringExt::from_vec(bytes)) } } } diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 04b39f0851a..3ce2c684f07 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -131,7 +131,7 @@ impl fmt::Debug for Command { pub struct ExitStatus(c_int); #[cfg(any(target_os = "linux", target_os = "android", - target_os = "nacl"))] + target_os = "nacl", target_os = "solaris"))] mod status_imp { pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 } pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff } diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index b5cbcaa44d5..84407b3bee8 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -39,6 +39,7 @@ impl Drop for Handler { target_os = "bitrig", target_os = "dragonfly", target_os = "freebsd", + target_os = "solaris", all(target_os = "netbsd", not(target_vendor = "rumprun")), target_os = "openbsd"))] mod imp { @@ -179,6 +180,7 @@ mod imp { target_os = "bitrig", target_os = "dragonfly", target_os = "freebsd", + target_os = "solaris", all(target_os = "netbsd", not(target_vendor = "rumprun")), target_os = "openbsd")))] mod imp { diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 0faa1465c32..277aa5f19f0 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -12,7 +12,7 @@ use prelude::v1::*; use alloc::boxed::FnBox; use cmp; -#[cfg(not(target_env = "newlib"))] +#[cfg(not(any(target_env = "newlib", target_os = "solaris")))] use ffi::CString; use io; use libc; @@ -122,9 +122,9 @@ impl Thread { carg.as_ptr() as *mut libc::c_void); } } - #[cfg(target_env = "newlib")] - pub unsafe fn set_name(_name: &str) { - // Newlib has no way to set a thread name. + #[cfg(any(target_env = "newlib", target_os = "solaris"))] + pub fn set_name(_name: &str) { + // Newlib and Illumos has no way to set a thread name. } pub fn sleep(dur: Duration) { @@ -170,7 +170,8 @@ impl Drop for Thread { not(target_os = "macos"), not(target_os = "bitrig"), not(all(target_os = "netbsd", not(target_vendor = "rumprun"))), - not(target_os = "openbsd")))] + not(target_os = "openbsd"), + not(target_os = "solaris")))] #[cfg_attr(test, allow(dead_code))] pub mod guard { pub unsafe fn current() -> Option<usize> { None } @@ -182,7 +183,8 @@ pub mod guard { target_os = "macos", target_os = "bitrig", all(target_os = "netbsd", not(target_vendor = "rumprun")), - target_os = "openbsd"))] + target_os = "openbsd", + target_os = "solaris"))] #[cfg_attr(test, allow(dead_code))] pub mod guard { use prelude::v1::*; @@ -194,7 +196,8 @@ pub mod guard { #[cfg(any(target_os = "macos", target_os = "bitrig", - target_os = "openbsd"))] + target_os = "openbsd", + target_os = "solaris"))] unsafe fn get_stack_start() -> Option<*mut libc::c_void> { current().map(|s| s as *mut libc::c_void) } @@ -253,6 +256,13 @@ pub mod guard { Some(stackaddr as usize + offset * psize) } + #[cfg(target_os = "solaris")] + pub unsafe fn current() -> Option<usize> { + let mut current_stack: libc::stack_t = ::mem::zeroed(); + assert_eq!(libc::stack_getbounds(&mut current_stack), 0); + Some(current_stack.ss_sp as usize) + } + #[cfg(target_os = "macos")] pub unsafe fn current() -> Option<usize> { Some((libc::pthread_get_stackaddr_np(libc::pthread_self()) as libc::size_t - |
