diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml index 9d62be64fc4ec..5c1446d6ef502 100644 --- a/src/libpanic_abort/Cargo.toml +++ b/src/libpanic_abort/Cargo.toml @@ -9,4 +9,6 @@ test = false [dependencies] core = { path = "../libcore" } + +[target.'cfg(all(unix,not(target_os="none")))'.dependencies] libc = { path = "../rustc/libc_shim" } diff --git a/src/libpanic_abort/lib.rs b/src/libpanic_abort/lib.rs index b87160dd75d04..dab428588f9d9 100644 --- a/src/libpanic_abort/lib.rs +++ b/src/libpanic_abort/lib.rs @@ -27,8 +27,8 @@ #![panic_runtime] #![feature(panic_runtime)] -#![cfg_attr(unix, feature(libc))] -#![cfg_attr(windows, feature(core_intrinsics))] +#![cfg_attr(all(unix,not(target_os="none")), feature(libc))] +#![cfg_attr(any(windows,target_os="none"), feature(core_intrinsics))] // Rust's "try" function, but if we're aborting on panics we just call the // function as there's nothing else we need to do here. @@ -55,13 +55,13 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8), pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 { return abort(); - #[cfg(unix)] + #[cfg(all(unix,not(target_os="none")))] unsafe fn abort() -> ! { extern crate libc; libc::abort(); } - #[cfg(windows)] + #[cfg(any(windows,target_os="none"))] unsafe fn abort() -> ! { core::intrinsics::abort(); } diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 21e6acc37f3d5..f78242f3f71d4 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -11,16 +11,18 @@ crate-type = ["dylib", "rlib"] [dependencies] alloc = { path = "../liballoc" } -alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true } -alloc_system = { path = "../liballoc_system" } -panic_unwind = { path = "../libpanic_unwind" } panic_abort = { path = "../libpanic_abort" } collections = { path = "../libcollections" } core = { path = "../libcore" } -libc = { path = "../rustc/libc_shim" } rand = { path = "../librand" } compiler_builtins = { path = "../libcompiler_builtins" } rustc_unicode = { path = "../librustc_unicode" } + +[target.'cfg(not(target_os="none"))'.dependencies] +libc = { path = "../rustc/libc_shim" } +alloc_jemalloc = { path = "../liballoc_jemalloc", optional = true } +alloc_system = { path = "../liballoc_system" } +panic_unwind = { path = "../libpanic_unwind" } unwind = { path = "../libunwind" } [build-dependencies] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b3e4351e9b200..5660904ed743f 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -314,10 +314,14 @@ extern crate collections as core_collections; #[allow(deprecated)] extern crate rand as core_rand; extern crate alloc; extern crate rustc_unicode; -extern crate libc; +#[cfg(not(target_os="none"))] extern crate libc; +#[cfg(target_os="none")] +mod libc { + pub use os::none::libc::*; +} // We always need an unwinder currently for backtraces -extern crate unwind; +#[cfg(not(target_os="none"))] extern crate unwind; #[cfg(stage0)] extern crate alloc_system; @@ -457,8 +461,10 @@ mod memchr; #[macro_use] #[path = "sys/common/mod.rs"] mod sys_common; -#[cfg(unix)] +#[cfg(all(unix,not(target_os="none")))] #[path = "sys/unix/mod.rs"] mod sys; +#[cfg(target_os="none")] +#[path = "sys/none/mod.rs"] mod sys; #[cfg(windows)] #[path = "sys/windows/mod.rs"] mod sys; diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs index 7622ef886935c..fbc4523ac1cb5 100644 --- a/src/libstd/os/mod.rs +++ b/src/libstd/os/mod.rs @@ -33,5 +33,6 @@ pub use sys::ext as windows; #[cfg(target_os = "openbsd")] pub mod openbsd; #[cfg(target_os = "solaris")] pub mod solaris; #[cfg(target_os = "emscripten")] pub mod emscripten; +#[cfg(target_os = "none")] pub mod none; pub mod raw; diff --git a/src/libstd/os/none/libc.rs b/src/libstd/os/none/libc.rs new file mode 100644 index 0000000000000..d9d1f61674949 --- /dev/null +++ b/src/libstd/os/none/libc.rs @@ -0,0 +1,119 @@ +pub use os::raw::*; + +pub type size_t = usize; +pub type ssize_t = isize; + +// Process/File definitions + +pub type mode_t = u32; +pub type pid_t = u32; +pub type gid_t = u32; +pub type uid_t = u32; + +pub const S_IFBLK: mode_t = 0; +pub const S_IFCHR: mode_t = 0; +pub const S_IFIFO: mode_t = 0; +pub const S_IFSOCK: mode_t = 0; + +// Threading + +#[derive(Copy,Clone)] +pub struct pthread_t(()); +pub struct pthread_attr_t(()); + +// Time definitions + +pub type time_t = i64; + +#[derive(Copy,Clone)] +pub struct timespec { + pub tv_sec: time_t, + pub tv_nsec: c_long, +} + +pub const CLOCK_MONOTONIC: c_int = 0; +pub const CLOCK_REALTIME: c_int = 0; + +// Networking definitions + +pub type sa_family_t = u16; +pub type in_port_t = u16; + +#[derive(Copy,Clone)] +pub struct in_addr { + pub s_addr: u32, +} + +#[derive(Copy,Clone)] +pub struct sockaddr_in { + pub sin_family: sa_family_t, + pub sin_port: in_port_t, + pub sin_addr: in_addr, + pub sin_zero: [u8; 8], +} + +#[derive(Copy,Clone)] +pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, +} + +#[derive(Copy,Clone)] +pub struct in6_addr { + pub s6_addr: [u8; 16], +} + +#[derive(Copy,Clone)] +pub struct sockaddr_in6 { + pub sin6_family: sa_family_t, + pub sin6_port: in_port_t, + pub sin6_flowinfo: u32, + pub sin6_addr: in6_addr, + pub sin6_scope_id: u32, +} + +#[derive(Copy,Clone)] +pub struct ipv6_mreq { + pub ipv6mr_multiaddr: in6_addr, + pub ipv6mr_interface: c_uint, +} + +pub const AF_INET6: c_int = 0; +pub const AF_INET: c_int = 0; +pub const AF_UNIX: c_int = 0; +pub const IPPROTO_IPV6: c_int = 0; +pub const IPPROTO_IP: c_int = 0; +pub const IPV6_ADD_MEMBERSHIP: c_int = 0; +pub const IPV6_DROP_MEMBERSHIP: c_int = 0; +pub const IPV6_MULTICAST_LOOP: c_int = 0; +pub const IPV6_V6ONLY: c_int = 0; +pub const IP_ADD_MEMBERSHIP: c_int = 0; +pub const IP_DROP_MEMBERSHIP: c_int = 0; +pub const IP_MULTICAST_LOOP: c_int = 0; +pub const IP_MULTICAST_TTL: c_int = 0; +pub const IP_TTL: c_int = 0; +pub const SOCK_DGRAM: c_int = 0; +pub const SOCK_STREAM: c_int = 0; +pub const SOL_SOCKET: c_int = 0; +pub const SO_BROADCAST: c_int = 0; +pub const SO_RCVTIMEO: c_int = 0; +pub const SO_REUSEADDR: c_int = 0; +pub const SO_SNDTIMEO: c_int = 0; + +pub struct sockaddr(()); +#[derive(Clone)] +pub struct sockaddr_un(()); +pub type socklen_t = u32; +pub struct sockaddr_storage(()); + +// C functions + +pub unsafe fn strlen(s: *const c_char) -> size_t { + let mut i=0isize; + loop { + if *s.offset(i)==0 { + return i as usize + } + i+=1; + } +} \ No newline at end of file diff --git a/src/libstd/os/none/mod.rs b/src/libstd/os/none/mod.rs new file mode 100644 index 0000000000000..ad52085d06ff1 --- /dev/null +++ b/src/libstd/os/none/mod.rs @@ -0,0 +1,4 @@ +#![stable(feature = "raw_ext", since = "1.1.0")] + +#[unstable(reason = "not public", issue = "0", feature = "libc_shim")] pub mod libc; +pub mod raw; \ No newline at end of file diff --git a/src/libstd/os/none/raw.rs b/src/libstd/os/none/raw.rs new file mode 100644 index 0000000000000..77706767ffd33 --- /dev/null +++ b/src/libstd/os/none/raw.rs @@ -0,0 +1,16 @@ +#![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated(since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions")] + +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct blkcnt_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct blksize_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct dev_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct ino_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct mode_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct nlink_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct off_t; +#[stable(feature = "pthread_t", since = "1.8.0")]pub use super::libc::pthread_t; +#[stable(feature = "raw_ext", since = "1.1.0")] pub struct time_t; \ No newline at end of file diff --git a/src/libstd/sys/common/io.rs b/src/libstd/sys/common/io.rs index 0483725dd83bc..bd22b5ff2fa30 100644 --- a/src/libstd/sys/common/io.rs +++ b/src/libstd/sys/common/io.rs @@ -7,6 +7,8 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg(not(target_os = "none"))] + use io; use io::ErrorKind; use io::Read; diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 2599bb660e813..2459e77897087 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -8,17 +8,30 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(not(target_os = "none"))] use cmp; +#[cfg(not(target_os = "none"))] use ffi::CString; use fmt; -use io::{self, Error, ErrorKind}; -use libc::{c_int, c_void}; +use io; +#[cfg(not(target_os = "none"))] +use io::{Error, ErrorKind}; +use libc::c_int; +#[cfg(not(target_os = "none"))] +use libc::c_void; use mem; use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; +#[cfg(not(target_os = "none"))] use ptr; -use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t}; +use sys::net::Socket; +#[cfg(not(target_os = "none"))] +use sys::net::init; +#[cfg(not(target_os="none"))] +use sys::net::{cvt, cvt_r, cvt_gai, wrlen_t}; use sys::net::netc as c; -use sys_common::{AsInner, FromInner, IntoInner}; +use sys_common::{AsInner, FromInner}; +#[cfg(not(target_os = "none"))] +use sys_common::IntoInner; use time::Duration; #[cfg(any(target_os = "dragonfly", target_os = "freebsd", @@ -44,13 +57,14 @@ use sys::net::netc::IPV6_DROP_MEMBERSHIP; #[cfg(target_os = "linux")] use libc::MSG_NOSIGNAL; -#[cfg(not(target_os = "linux"))] +#[cfg(all(not(target_os = "linux"), not(target_os = "none")))] const MSG_NOSIGNAL: c_int = 0x0; // unused dummy value //////////////////////////////////////////////////////////////////////////////// // sockaddr and misc bindings //////////////////////////////////////////////////////////////////////////////// +#[cfg(not(target_os="none"))] pub fn setsockopt(sock: &Socket, opt: c_int, val: c_int, payload: T) -> io::Result<()> { unsafe { @@ -61,6 +75,7 @@ pub fn setsockopt(sock: &Socket, opt: c_int, val: c_int, } } +#[cfg(not(target_os="none"))] pub fn getsockopt(sock: &Socket, opt: c_int, val: c_int) -> io::Result { unsafe { @@ -74,6 +89,7 @@ pub fn getsockopt(sock: &Socket, opt: c_int, } } +#[cfg(not(target_os="none"))] fn sockname(f: F) -> io::Result where F: FnOnce(*mut c::sockaddr, *mut c::socklen_t) -> c_int { @@ -85,6 +101,7 @@ fn sockname(f: F) -> io::Result } } +#[cfg(not(target_os="none"))] fn sockaddr_to_addr(storage: &c::sockaddr_storage, len: usize) -> io::Result { match storage.ss_family as c_int { @@ -106,6 +123,24 @@ fn sockaddr_to_addr(storage: &c::sockaddr_storage, } } +#[cfg(target_os="none")] +pub fn setsockopt(_sock: &Socket, _opt: c_int, _val: c_int, + _payload: T) -> io::Result<()> { + Err(::sys::net::generic_error()) +} + +#[cfg(target_os="none")] +pub fn getsockopt(_sock: &Socket, _opt: c_int, + _val: c_int) -> io::Result { + Err(::sys::net::generic_error()) +} + +#[cfg(target_os="none")] +fn sockaddr_to_addr(_storage: &c::sockaddr_storage, + _len: usize) -> io::Result { + Err(::sys::net::generic_error()) +} + #[cfg(target_os = "android")] fn to_ipv6mr_interface(value: u32) -> c_int { value as c_int @@ -120,13 +155,18 @@ fn to_ipv6mr_interface(value: u32) -> ::libc::c_uint { // get_host_addresses //////////////////////////////////////////////////////////////////////////////// +#[cfg(not(target_os="none"))] pub struct LookupHost { original: *mut c::addrinfo, cur: *mut c::addrinfo, } +#[cfg(target_os="none")] +pub struct LookupHost; impl Iterator for LookupHost { type Item = SocketAddr; + + #[cfg(not(target_os="none"))] fn next(&mut self) -> Option { loop { unsafe { @@ -144,17 +184,27 @@ impl Iterator for LookupHost { } } } + + #[cfg(target_os="none")] + fn next(&mut self) -> Option { + None + } } unsafe impl Sync for LookupHost {} unsafe impl Send for LookupHost {} impl Drop for LookupHost { + #[cfg(not(target_os="none"))] fn drop(&mut self) { unsafe { c::freeaddrinfo(self.original) } } + + #[cfg(target_os="none")] + fn drop(&mut self) {} } +#[cfg(not(target_os="none"))] pub fn lookup_host(host: &str) -> io::Result { init(); @@ -177,6 +227,12 @@ pub fn lookup_host(host: &str) -> io::Result { } } +#[cfg(target_os="none")] +pub fn lookup_host(_host: &str) -> io::Result { + Err(::sys::net::generic_error()) +} + + //////////////////////////////////////////////////////////////////////////////// // TCP streams //////////////////////////////////////////////////////////////////////////////// @@ -186,6 +242,7 @@ pub struct TcpStream { } impl TcpStream { + #[cfg(not(target_os="none"))] pub fn connect(addr: &SocketAddr) -> io::Result { init(); @@ -196,6 +253,11 @@ impl TcpStream { Ok(TcpStream { inner: sock }) } + #[cfg(target_os="none")] + pub fn connect(_addr: &SocketAddr) -> io::Result { + Err(::sys::net::generic_error()) + } + pub fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } @@ -224,6 +286,7 @@ impl TcpStream { self.inner.read_to_end(buf) } + #[cfg(not(target_os="none"))] pub fn write(&self, buf: &[u8]) -> io::Result { let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; let ret = cvt(unsafe { @@ -235,18 +298,35 @@ impl TcpStream { Ok(ret as usize) } + #[cfg(target_os="none")] + pub fn write(&self, _buf: &[u8]) -> io::Result { + Err(::sys::net::generic_error()) + } + + #[cfg(not(target_os="none"))] pub fn peer_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getpeername(*self.inner.as_inner(), buf, len) }) } + #[cfg(target_os="none")] + pub fn peer_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + + #[cfg(not(target_os="none"))] pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getsockname(*self.inner.as_inner(), buf, len) }) } + #[cfg(target_os="none")] + pub fn socket_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { self.inner.shutdown(how) } @@ -314,6 +394,7 @@ pub struct TcpListener { } impl TcpListener { + #[cfg(not(target_os="none"))] pub fn bind(addr: &SocketAddr) -> io::Result { init(); @@ -336,16 +417,27 @@ impl TcpListener { Ok(TcpListener { inner: sock }) } + #[cfg(target_os="none")] + pub fn bind(_addr: &SocketAddr) -> io::Result { + Err(::sys::net::generic_error()) + } + pub fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } + #[cfg(not(target_os="none"))] pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getsockname(*self.inner.as_inner(), buf, len) }) } + #[cfg(target_os="none")] + pub fn socket_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> { let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() }; let mut len = mem::size_of_val(&storage) as c::socklen_t; @@ -415,6 +507,7 @@ pub struct UdpSocket { } impl UdpSocket { + #[cfg(not(target_os="none"))] pub fn bind(addr: &SocketAddr) -> io::Result { init(); @@ -424,16 +517,28 @@ impl UdpSocket { Ok(UdpSocket { inner: sock }) } + #[cfg(target_os="none")] + pub fn bind(_addr: &SocketAddr) -> io::Result { + Err(::sys::net::generic_error()) + } + pub fn socket(&self) -> &Socket { &self.inner } pub fn into_socket(self) -> Socket { self.inner } + #[cfg(not(target_os="none"))] pub fn socket_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getsockname(*self.inner.as_inner(), buf, len) }) } + #[cfg(target_os="none")] + pub fn socket_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + + #[cfg(not(target_os="none"))] pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() }; let mut addrlen = mem::size_of_val(&storage) as c::socklen_t; @@ -448,6 +553,12 @@ impl UdpSocket { Ok((n as usize, sockaddr_to_addr(&storage, addrlen as usize)?)) } + #[cfg(target_os="none")] + pub fn recv_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + Err(::sys::net::generic_error()) + } + + #[cfg(not(target_os="none"))] pub fn send_to(&self, buf: &[u8], dst: &SocketAddr) -> io::Result { let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; let (dstp, dstlen) = dst.into_inner(); @@ -459,6 +570,11 @@ impl UdpSocket { Ok(ret as usize) } + #[cfg(target_os="none")] + pub fn send_to(&self, _buf: &[u8], _dst: &SocketAddr) -> io::Result { + Err(::sys::net::generic_error()) + } + pub fn duplicate(&self) -> io::Result { self.inner.duplicate().map(|s| UdpSocket { inner: s }) } @@ -572,6 +688,7 @@ impl UdpSocket { self.inner.read(buf) } + #[cfg(not(target_os="none"))] pub fn send(&self, buf: &[u8]) -> io::Result { let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; let ret = cvt(unsafe { @@ -583,10 +700,21 @@ impl UdpSocket { Ok(ret as usize) } + #[cfg(target_os="none")] + pub fn send(&self, _buf: &[u8]) -> io::Result { + Err(::sys::net::generic_error()) + } + + #[cfg(not(target_os="none"))] pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> { let (addrp, len) = addr.into_inner(); cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(|_| ()) } + + #[cfg(target_os="none")] + pub fn connect(&self, _addr: &SocketAddr) -> io::Result<()> { + Err(::sys::net::generic_error()) + } } impl FromInner for UdpSocket { diff --git a/src/libstd/sys/common/thread.rs b/src/libstd/sys/common/thread.rs index 3ee160da5fa5b..466dad18f9371 100644 --- a/src/libstd/sys/common/thread.rs +++ b/src/libstd/sys/common/thread.rs @@ -8,10 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(not(target_os = "none"))] use alloc::boxed::FnBox; +#[cfg(not(target_os = "none"))] use libc; +#[cfg(not(target_os = "none"))] use sys::stack_overflow; +#[cfg(not(target_os = "none"))] pub unsafe fn start_thread(main: *mut libc::c_void) { // Next, set up our stack overflow handler which may get triggered if we run // out of stack. diff --git a/src/libstd/sys/common/util.rs b/src/libstd/sys/common/util.rs index b5d0357633875..d5c50e039db37 100644 --- a/src/libstd/sys/common/util.rs +++ b/src/libstd/sys/common/util.rs @@ -40,11 +40,16 @@ pub fn dumb_print(args: fmt::Arguments) { // understandable error message like "Abort trap" rather than "Illegal // instruction" that intrinsics::abort would cause, as intrinsics::abort is // implemented as an illegal instruction. -#[cfg(unix)] +#[cfg(all(unix,not(target_os = "none")))] unsafe fn abort_internal() -> ! { ::libc::abort() } +#[cfg(target_os = "none")] +unsafe fn abort_internal() -> ! { + ::intrinsics::abort() +} + // On Windows, use the processor-specific __fastfail mechanism. In Windows 8 // and later, this will terminate the process immediately without running any // in-process exception handlers. In earlier versions of Windows, this diff --git a/src/libstd/sys/none/condvar.rs b/src/libstd/sys/none/condvar.rs new file mode 100644 index 0000000000000..8d0989b551a82 --- /dev/null +++ b/src/libstd/sys/none/condvar.rs @@ -0,0 +1,17 @@ +use sys::mutex::Mutex; +use time::Duration; + +pub struct Condvar(()); + +unsafe impl Send for Condvar {} +unsafe impl Sync for Condvar {} + +impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar(()) } + #[inline] pub unsafe fn init(&mut self) {} + #[inline] pub unsafe fn notify_one(&self) {} + #[inline] pub unsafe fn notify_all(&self) {} + #[inline] pub unsafe fn wait(&self, _mutex: &Mutex) {} + #[inline] pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool { true } + #[inline] pub unsafe fn destroy(&self) {} +} diff --git a/src/libstd/sys/none/env.rs b/src/libstd/sys/none/env.rs new file mode 100644 index 0000000000000..b3745a8805797 --- /dev/null +++ b/src/libstd/sys/none/env.rs @@ -0,0 +1,15 @@ +use io; + +pub fn generic_error() -> io::Error { + io::Error::new(io::ErrorKind::Other, "environment variables not supported on this platform") +} + +pub mod os { + pub const FAMILY: &'static str = "unix"; + pub const OS: &'static str = "none"; + 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 = ""; +} diff --git a/src/libstd/sys/none/fd.rs b/src/libstd/sys/none/fd.rs new file mode 100644 index 0000000000000..4acae377c2d28 --- /dev/null +++ b/src/libstd/sys/none/fd.rs @@ -0,0 +1,40 @@ +#![unstable(reason = "not public", issue = "0", feature = "fd")] + +use io::{self, Read}; +use libc::c_int; +use sys::fs::generic_error; +use sys_common::AsInner; + +#[derive(Debug)] +pub struct FileDesc { + fd: c_int, +} + +impl FileDesc { + pub fn new(fd: c_int) -> FileDesc { + FileDesc { fd: fd } + } + + pub fn raw(&self) -> c_int { self.fd } + pub fn into_raw(self) -> c_int { self.fd} + + pub fn read(&self, _buf: &mut [u8]) -> io::Result { Err(generic_error()) } + pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { Err(generic_error()) } + pub fn write(&self, _buf: &[u8]) -> io::Result { Err(generic_error()) } + pub fn set_cloexec(&self) -> io::Result<()> { Err(generic_error()) } + pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { Err(generic_error()) } + pub fn duplicate(&self) -> io::Result { Err(generic_error()) } +} + +impl<'a> Read for &'a FileDesc { + fn read(&mut self, _buf: &mut [u8]) -> io::Result { Err(generic_error()) } + fn read_to_end(&mut self, _buf: &mut Vec) -> io::Result { Err(generic_error()) } +} + +impl AsInner for FileDesc { + fn as_inner(&self) -> &c_int { &self.fd } +} + +impl Drop for FileDesc { + fn drop(&mut self) {} +} diff --git a/src/libstd/sys/none/fs.rs b/src/libstd/sys/none/fs.rs new file mode 100644 index 0000000000000..3d772872490c5 --- /dev/null +++ b/src/libstd/sys/none/fs.rs @@ -0,0 +1,180 @@ +// Copyright 2013-2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use io; +use libc::{c_int,mode_t}; +use ffi::OsString; +use path::{Path,PathBuf}; +use sys::fd::FileDesc; +use sys::time::SystemTime; +use sys_common::FromInner; + +#[derive(Debug)] +pub struct File(FileDesc); +#[derive(Clone)] +pub struct FileAttr(()); +pub struct ReadDir(()); +pub struct DirEntry(()); +#[derive(Clone)] +pub struct OpenOptions(()); +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct FilePermissions(()); +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +pub struct FileType(()); +pub struct DirBuilder(()); + +pub fn generic_error() -> io::Error { + io::Error::new(io::ErrorKind::Other, "filesystem not supported on this platform") +} + +impl FileAttr { + pub fn size(&self) -> u64 { unimplemented!() } + pub fn perm(&self) -> FilePermissions { unimplemented!() } + pub fn file_type(&self) -> FileType { unimplemented!() } + pub fn modified(&self) -> io::Result { Err(generic_error()) } + pub fn accessed(&self) -> io::Result { Err(generic_error()) } + pub fn created(&self) -> io::Result { Err(generic_error()) } +} + +/* +impl AsInner for FileAttr { + fn as_inner(&self) -> &stat64 { ... } +} +*/ + +impl FilePermissions { + pub fn readonly(&self) -> bool { unimplemented!() } + pub fn set_readonly(&mut self, _readonly: bool) { unimplemented!() } + pub fn mode(&self) -> u32 { unimplemented!() } +} + +impl FromInner for FilePermissions { + fn from_inner(_mode: u32) -> FilePermissions { + FilePermissions(()) + } +} + +impl FileType { + pub fn is_dir(&self) -> bool { false } + pub fn is_file(&self) -> bool { false } + pub fn is_symlink(&self) -> bool { false } + pub fn is(&self, _mode: mode_t) -> bool { false } +} + +impl Iterator for ReadDir { + type Item = io::Result; + fn next(&mut self) -> Option> { Some(Err(generic_error())) } +} + +impl DirEntry { + pub fn path(&self) -> PathBuf { unimplemented!() } + pub fn file_name(&self) -> OsString { unimplemented!() } + pub fn metadata(&self) -> io::Result { Err(generic_error()) } + + pub fn file_type(&self) -> io::Result { Err(generic_error()) } + + pub fn ino(&self) -> u64 { unimplemented!() } +} + +impl OpenOptions { + pub fn new() -> OpenOptions { OpenOptions(()) } + + pub fn read(&mut self, _read: bool) {} + pub fn write(&mut self, _write: bool) {} + pub fn append(&mut self, _append: bool) {} + pub fn truncate(&mut self, _truncate: bool) {} + pub fn create(&mut self, _create: bool) {} + pub fn create_new(&mut self, _create_new: bool) {} + + pub fn custom_flags(&mut self, _flags: i32) {} + pub fn mode(&mut self, _mode: u32) {} +} + +impl File { + pub fn open(_path: &Path, _opts: &OpenOptions) -> io::Result { Err(generic_error()) } + pub fn file_attr(&self) -> io::Result { Err(generic_error()) } + pub fn fsync(&self) -> io::Result<()> { Err(generic_error()) } + pub fn datasync(&self) -> io::Result<()> { Err(generic_error()) } + pub fn truncate(&self, _size: u64) -> io::Result<()> { Err(generic_error()) } + pub fn read(&self, _buf: &mut [u8]) -> io::Result { Err(generic_error()) } + pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { Err(generic_error()) } + pub fn write(&self, _buf: &[u8]) -> io::Result { Err(generic_error()) } + pub fn flush(&self) -> io::Result<()> { Err(generic_error()) } + pub fn seek(&self, _pos: io::SeekFrom) -> io::Result { Err(generic_error()) } + pub fn duplicate(&self) -> io::Result { Err(generic_error()) } + + pub fn fd(&self) -> &FileDesc { &self.0 } + + pub fn into_fd(self) -> FileDesc { self.0 } +} + +impl FromInner for File { + fn from_inner(fd: c_int) -> File { + File(FileDesc::new(fd)) + } +} + +impl DirBuilder { + pub fn new() -> DirBuilder { DirBuilder(()) } + pub fn mkdir(&self, _p: &Path) -> io::Result<()> { Err(generic_error()) } + pub fn set_mode(&mut self, _mode: u32) {} +} + +pub fn readdir(_p: &Path) -> io::Result { Err(generic_error()) } +pub fn unlink(_p: &Path) -> io::Result<()> { Err(generic_error()) } +pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> { Err(generic_error()) } +pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> { Err(generic_error()) } +pub fn rmdir(_p: &Path) -> io::Result<()> { Err(generic_error()) } +pub fn remove_dir_all(_path: &Path) -> io::Result<()> { Err(generic_error()) } +pub fn readlink(_p: &Path) -> io::Result { Err(generic_error()) } +pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { Err(generic_error()) } +pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> { Err(generic_error()) } +pub fn stat(_p: &Path) -> io::Result { Err(generic_error()) } +pub fn lstat(_p: &Path) -> io::Result { Err(generic_error()) } +pub fn canonicalize(_p: &Path) -> io::Result { Err(generic_error()) } +pub fn copy(_from: &Path, _to: &Path) -> io::Result { Err(generic_error()) } + +pub trait MetadataExt { + fn st_dev(&self) -> u64; + fn st_ino(&self) -> u64; + fn st_mode(&self) -> u32; + fn st_nlink(&self) -> u64; + fn st_uid(&self) -> u32; + fn st_gid(&self) -> u32; + fn st_rdev(&self) -> u64; + fn st_size(&self) -> u64; + fn st_atime(&self) -> i64; + fn st_atime_nsec(&self) -> i64; + fn st_mtime(&self) -> i64; + fn st_mtime_nsec(&self) -> i64; + fn st_ctime(&self) -> i64; + fn st_ctime_nsec(&self) -> i64; + fn st_blksize(&self) -> u64; + fn st_blocks(&self) -> u64; +} + +impl MetadataExt for ::fs::Metadata { + fn st_dev(&self) -> u64 { unimplemented!() } + fn st_ino(&self) -> u64 { unimplemented!() } + fn st_mode(&self) -> u32 { unimplemented!() } + fn st_nlink(&self) -> u64 { unimplemented!() } + fn st_uid(&self) -> u32 { unimplemented!() } + fn st_gid(&self) -> u32 { unimplemented!() } + fn st_rdev(&self) -> u64 { unimplemented!() } + fn st_size(&self) -> u64 { unimplemented!() } + fn st_atime(&self) -> i64 { unimplemented!() } + fn st_atime_nsec(&self) -> i64 { unimplemented!() } + fn st_mtime(&self) -> i64 { unimplemented!() } + fn st_mtime_nsec(&self) -> i64 { unimplemented!() } + fn st_ctime(&self) -> i64 { unimplemented!() } + fn st_ctime_nsec(&self) -> i64 { unimplemented!() } + fn st_blksize(&self) -> u64 { unimplemented!() } + fn st_blocks(&self) -> u64 { unimplemented!() } +} diff --git a/src/libstd/sys/none/mod.rs b/src/libstd/sys/none/mod.rs new file mode 100644 index 0000000000000..6fe258d1a2280 --- /dev/null +++ b/src/libstd/sys/none/mod.rs @@ -0,0 +1,47 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(missing_docs, bad_style)] + +use io::ErrorKind; + +pub use os::none as platform; + +#[path = "../unix/args.rs"] pub mod args; +#[path = "../unix/android.rs"] pub mod android; +#[cfg(any(not(cargobuild), feature = "backtrace"))] +#[path = "../unix/backtrace/mod.rs"] pub mod backtrace; +#[path = "../unix/ext/mod.rs"] pub mod ext; +#[path = "../unix/memchr.rs"] pub mod memchr; +#[path = "../unix/os.rs"] pub mod os; +#[path = "../unix/os_str.rs"] pub mod os_str; +#[path = "../unix/path.rs"] pub mod path; +#[path = "../unix/pipe.rs"] pub mod pipe; +#[path = "../unix/process.rs"] pub mod process; +#[path = "../unix/rand.rs"] pub mod rand; +#[path = "../unix/stack_overflow.rs"] pub mod stack_overflow; +#[path = "../unix/time.rs"] pub mod time; + pub mod env; + pub mod fd; + pub mod fs; + pub mod net; + pub mod stdio; + pub mod condvar; + pub mod mutex; + pub mod rwlock; +#[path = "../unix/thread.rs"] pub mod thread; + pub mod thread_local; + +#[cfg(not(test))] +pub fn init() {} + +pub fn decode_error_kind(_errno: i32) -> ErrorKind { + ErrorKind::Other +} diff --git a/src/libstd/sys/none/mutex.rs b/src/libstd/sys/none/mutex.rs new file mode 100644 index 0000000000000..3158409d0c115 --- /dev/null +++ b/src/libstd/sys/none/mutex.rs @@ -0,0 +1,51 @@ +use cell::Cell; + +pub struct Mutex { locked: Cell } + +unsafe impl Send for Mutex {} +unsafe impl Sync for Mutex {} + +impl Mutex { + pub const fn new() -> Mutex { + Mutex { locked: Cell::new(false) } + } + #[inline] + pub unsafe fn init(&mut self) {} + #[inline] + pub unsafe fn lock(&self) { + // Panic if trying to re-obtain lock + debug_assert!(!self.locked.get()); + self.locked.set(true); + } + #[inline] + pub unsafe fn unlock(&self) { + debug_assert!(self.locked.get()); + self.locked.set(false); + } + #[inline] + pub unsafe fn try_lock(&self) -> bool { + let already_locked=self.locked.get(); + if !already_locked { + self.lock() + } + !already_locked + } + #[inline] + pub unsafe fn destroy(&self) { + self.lock() + } +} + +pub struct ReentrantMutex(()); + +unsafe impl Send for ReentrantMutex {} +unsafe impl Sync for ReentrantMutex {} + +impl ReentrantMutex { + #[inline] pub unsafe fn uninitialized() -> ReentrantMutex { ReentrantMutex(()) } + #[inline] pub unsafe fn init(&mut self) {} + #[inline] pub unsafe fn lock(&self) {} + #[inline] pub unsafe fn unlock(&self) {} + #[inline] pub unsafe fn try_lock(&self) -> bool { true } + #[inline] pub unsafe fn destroy(&self) {} +} diff --git a/src/libstd/sys/none/net.rs b/src/libstd/sys/none/net.rs new file mode 100644 index 0000000000000..2dad086ab704a --- /dev/null +++ b/src/libstd/sys/none/net.rs @@ -0,0 +1,48 @@ +use io; + +use libc::{c_int, sockaddr, socklen_t}; +use net::Shutdown; +use time::Duration; +use sys::fd::FileDesc; +use sys_common::{AsInner, FromInner, IntoInner}; + +pub mod netc { + pub use os::none::libc::*; +} + +pub struct Socket(FileDesc); + +pub fn generic_error() -> io::Error { + io::Error::new(io::ErrorKind::Other, "networking not supported on this platform") +} + +impl Socket { + pub fn new_raw(_fam: c_int, _ty: c_int) -> io::Result { Err(generic_error()) } + pub fn new_pair(_fam: c_int, _ty: c_int) -> io::Result<(Socket, Socket)> { Err(generic_error()) } + pub fn accept(&self, _storage: *mut sockaddr, _len: *mut socklen_t) + -> io::Result { Err(generic_error()) } + pub fn duplicate(&self) -> io::Result { Err(generic_error()) } + pub fn read(&self, _buf: &mut [u8]) -> io::Result { Err(generic_error()) } + pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { Err(generic_error()) } + pub fn write(&self, _buf: &[u8]) -> io::Result { Err(generic_error()) } + pub fn set_timeout(&self, _dur: Option, _kind: c_int) -> io::Result<()> { Err(generic_error()) } + pub fn timeout(&self, _kind: c_int) -> io::Result> { Err(generic_error()) } + pub fn shutdown(&self, _how: Shutdown) -> io::Result<()> { Err(generic_error()) } + pub fn set_nodelay(&self, _nodelay: bool) -> io::Result<()> { Err(generic_error()) } + pub fn nodelay(&self) -> io::Result { Err(generic_error()) } + pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> { Err(generic_error()) } + pub fn take_error(&self) -> io::Result> { Err(generic_error()) } +} + + +impl AsInner for Socket { + fn as_inner(&self) -> &c_int { self.0.as_inner() } +} + +impl FromInner for Socket { + fn from_inner(fd: c_int) -> Socket { Socket(FileDesc::new(fd)) } +} + +impl IntoInner for Socket { + fn into_inner(self) -> c_int { self.0.into_raw() } +} diff --git a/src/libstd/sys/none/rwlock.rs b/src/libstd/sys/none/rwlock.rs new file mode 100644 index 0000000000000..751bf55c9df2b --- /dev/null +++ b/src/libstd/sys/none/rwlock.rs @@ -0,0 +1,59 @@ +use cell::Cell; + +pub struct RWLock { + write_locked: Cell, + num_readers: Cell, +} + +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} + +impl RWLock { + pub const fn new() -> RWLock { + RWLock { + write_locked: Cell::new(false), + num_readers: Cell::new(0), + } + } + #[inline] + pub unsafe fn read(&self) { + debug_assert!(!self.write_locked.get()); + self.num_readers.set(self.num_readers.get()+1) + } + #[inline] + pub unsafe fn try_read(&self) -> bool { + let already_locked=self.write_locked.get(); + if !already_locked { + self.read() + } + !already_locked + } + #[inline] + pub unsafe fn write(&self) { + debug_assert!(!self.write_locked.get()); + debug_assert_eq!(self.num_readers.get(),0); + self.write_locked.set(true) + } + #[inline] + pub unsafe fn try_write(&self) -> bool { + let already_locked=self.write_locked.get() || self.num_readers.get()==0; + if !already_locked { + self.write() + } + !already_locked + } + #[inline] + pub unsafe fn read_unlock(&self) { + debug_assert!(self.num_readers.get()>0); + self.num_readers.set(self.num_readers.get()-1); + } + #[inline] + pub unsafe fn write_unlock(&self) { + debug_assert!(self.write_locked.get()); + self.write_locked.set(false) + } + #[inline] + pub unsafe fn destroy(&self) { + self.write() + } +} diff --git a/src/libstd/sys/none/stdio.rs b/src/libstd/sys/none/stdio.rs new file mode 100644 index 0000000000000..f42bcc3e52458 --- /dev/null +++ b/src/libstd/sys/none/stdio.rs @@ -0,0 +1,35 @@ +use io; + +pub struct Stdin(()); +pub struct Stdout(()); +pub struct Stderr(()); + +fn generic_error() -> io::Error { + io::Error::new(io::ErrorKind::Other, "standard I/O not supported on this platform") +} + +impl Stdin { + pub fn new() -> io::Result { Err(generic_error()) } + pub fn read(&self, _data: &mut [u8]) -> io::Result { Err(generic_error()) } + pub fn read_to_end(&self, _buf: &mut Vec) -> io::Result { Err(generic_error()) } +} + +impl Stdout { + pub fn new() -> io::Result { Err(generic_error()) } + pub fn write(&self, _data: &[u8]) -> io::Result { Err(generic_error()) } +} + +impl Stderr { + pub fn new() -> io::Result { Err(generic_error()) } + pub fn write(&self, _data: &[u8]) -> io::Result { Err(generic_error()) } +} + +// FIXME: right now this raw stderr handle is used in a few places because +// std::io::stderr_raw isn't exposed, but once that's exposed this impl +// should go away +impl io::Write for Stderr { + fn write(&mut self, _data: &[u8]) -> io::Result { Err(generic_error()) } + fn flush(&mut self) -> io::Result<()> { Err(generic_error()) } +} + +pub const EBADF_ERR: i32 = 0; diff --git a/src/libstd/sys/none/thread_local.rs b/src/libstd/sys/none/thread_local.rs new file mode 100644 index 0000000000000..cb56fbd5b80d9 --- /dev/null +++ b/src/libstd/sys/none/thread_local.rs @@ -0,0 +1,47 @@ +use alloc::boxed::Box; + +struct TlsKey { + value: *mut u8, + dtor: Option, +} + +pub type Key = usize; + +impl From for Key { + fn from(k: TlsKey) -> Key { + Box::into_raw(Box::new(k)) as usize + } +} + +impl From for TlsKey { + fn from(k: Key) -> TlsKey { + unsafe { *Box::from_raw(k as *mut TlsKey) } + } +} + +fn borrow_key(k: &Key) -> &mut TlsKey { + unsafe { &mut*(*k as *mut TlsKey) } +} + +#[inline] +pub unsafe fn create(dtor: Option) -> Key { + TlsKey { value: ::ptr::null_mut(), dtor: dtor }.into() +} + +#[inline] +pub unsafe fn set(key: Key, value: *mut u8) { + borrow_key(&key).value=value +} + +#[inline] +pub unsafe fn get(key: Key) -> *mut u8 { + borrow_key(&key).value +} + +#[inline] +pub unsafe fn destroy(key: Key) { + match TlsKey::from(key) { + TlsKey{value, dtor: Some(dtor)} if value!=::ptr::null_mut() => dtor(value), + _ => {}, + } +} diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs index c64db333e5106..94e9108716b01 100644 --- a/src/libstd/sys/unix/args.rs +++ b/src/libstd/sys/unix/args.rs @@ -209,3 +209,17 @@ mod imp { Args { iter: res.into_iter(), _dont_send_or_sync_me: PhantomData } } } + +#[cfg(target_os = "none")] +mod imp { + use super::Args; + use marker::PhantomData; + + pub unsafe fn init(_argc: isize, _argv: *const *const u8) {} + + pub unsafe fn cleanup() {} + + pub fn args() -> Args { + Args { iter: Vec::with_capacity(0).into_iter(), _dont_send_or_sync_me: PhantomData } + } +} diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 77587918ac94b..3a121e228a48c 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -18,7 +18,8 @@ use libc; use path::Path; use sys; use sys_common::{FromInner, AsInner, AsInnerMut}; -use sys::platform::fs::MetadataExt as UnixMetadataExt; +#[cfg(not(target_os="none"))] use sys::platform::fs::MetadataExt as UnixMetadataExt; +#[cfg(target_os="none")] use sys::fs::MetadataExt as UnixMetadataExt; /// Unix-specific extensions to `Permissions` #[stable(feature = "fs_ext", since = "1.1.0")] diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 622fd4b85a59a..f9a4a28b07a50 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -14,25 +14,29 @@ use libc; +#[cfg(not(target_os = "none"))] use ascii; +#[cfg(not(target_os = "none"))] use ffi::OsStr; use fmt; use io; use mem; use net::Shutdown; +#[cfg(not(target_os = "none"))] use os::unix::ffi::OsStrExt; use os::unix::io::{RawFd, AsRawFd, FromRawFd, IntoRawFd}; use path::Path; use time::Duration; -use sys::cvt; +#[cfg(not(target_os="none"))] use sys::cvt; use sys::net::Socket; use sys_common::{AsInner, FromInner, IntoInner}; #[cfg(target_os = "linux")] use libc::MSG_NOSIGNAL; -#[cfg(not(target_os = "linux"))] +#[cfg(all(not(target_os = "linux"),not(target_os = "none")))] const MSG_NOSIGNAL: libc::c_int = 0x0; // unused dummy value +#[cfg(not(target_os="none"))] fn sun_path_offset() -> usize { unsafe { // Work with an actual instance of the type since using a null pointer is UB @@ -43,6 +47,7 @@ fn sun_path_offset() -> usize { } } +#[cfg(not(target_os="none"))] unsafe fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::socklen_t)> { let mut addr: libc::sockaddr_un = mem::zeroed(); addr.sun_family = libc::AF_UNIX as libc::sa_family_t; @@ -72,6 +77,7 @@ unsafe fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::sockl Ok((addr, len as libc::socklen_t)) } +#[cfg(not(target_os = "none"))] enum AddressKind<'a> { Unnamed, Pathname(&'a Path), @@ -86,6 +92,7 @@ pub struct SocketAddr { len: libc::socklen_t, } +#[cfg(not(target_os="none"))] impl SocketAddr { fn new(f: F) -> io::Result where F: FnOnce(*mut libc::sockaddr, *mut libc::socklen_t) -> libc::c_int @@ -149,8 +156,28 @@ impl SocketAddr { } } +#[cfg(target_os="none")] +impl SocketAddr { + fn from_parts(_addr: libc::sockaddr_un, _len: libc::socklen_t) -> io::Result { + Err(::sys::net::generic_error()) + } + + /// Returns true if and only if the address is unnamed. + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn is_unnamed(&self) -> bool { + true + } + + /// Returns the contents of this address if it is a `pathname` address. + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn as_pathname(&self) -> Option<&Path> { + None + } +} + #[stable(feature = "unix_socket", since = "1.10.0")] impl fmt::Debug for SocketAddr { + #[cfg(not(target_os="none"))] fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match self.address() { AddressKind::Unnamed => write!(fmt, "(unnamed)"), @@ -158,10 +185,17 @@ impl fmt::Debug for SocketAddr { AddressKind::Pathname(path) => write!(fmt, "{:?} (pathname)", path), } } + + #[cfg(target_os="none")] + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "(unimplemented)") + } } +#[cfg(not(target_os = "none"))] struct AsciiEscaped<'a>(&'a [u8]); +#[cfg(not(target_os = "none"))] impl<'a> fmt::Display for AsciiEscaped<'a> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { write!(fmt, "\"")?; @@ -208,6 +242,7 @@ impl UnixStream { /// Connects to the socket named by `path`. #[stable(feature = "unix_socket", since = "1.10.0")] pub fn connect>(path: P) -> io::Result { + #[cfg(not(target_os="none"))] fn inner(path: &Path) -> io::Result { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; @@ -217,6 +252,12 @@ impl UnixStream { Ok(UnixStream(inner)) } } + + #[cfg(target_os="none")] + fn inner(_path: &Path) -> io::Result { + Err(::sys::net::generic_error()) + } + inner(path.as_ref()) } @@ -241,17 +282,33 @@ impl UnixStream { } /// Returns the socket address of the local half of this connection. + #[cfg(not(target_os="none"))] #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getsockname(*self.0.as_inner(), addr, len) }) } + /// Returns the socket address of the local half of this connection. + #[cfg(target_os="none")] + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn local_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + /// Returns the socket address of the remote half of this connection. + #[cfg(not(target_os="none"))] #[stable(feature = "unix_socket", since = "1.10.0")] pub fn peer_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getpeername(*self.0.as_inner(), addr, len) }) } + /// Returns the socket address of the remote half of this connection. + #[cfg(target_os="none")] + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn peer_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + /// Sets the read timeout for the socket. /// /// If the provided value is `None`, then `read` calls will block @@ -422,6 +479,7 @@ impl UnixListener { /// Creates a new `UnixListener` bound to the specified socket. #[stable(feature = "unix_socket", since = "1.10.0")] pub fn bind>(path: P) -> io::Result { + #[cfg(not(target_os="none"))] fn inner(path: &Path) -> io::Result { unsafe { let inner = Socket::new_raw(libc::AF_UNIX, libc::SOCK_STREAM)?; @@ -433,6 +491,12 @@ impl UnixListener { Ok(UnixListener(inner)) } } + + #[cfg(target_os="none")] + fn inner(_path: &Path) -> io::Result { + Err(::sys::net::generic_error()) + } + inner(path.as_ref()) } @@ -461,11 +525,19 @@ impl UnixListener { } /// Returns the local socket address of this listener. + #[cfg(not(target_os="none"))] #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getsockname(*self.0.as_inner(), addr, len) }) } + /// Returns the local socket address of this listener. + #[cfg(target_os="none")] + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn local_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + /// Moves the socket into or out of nonblocking mode. #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -576,6 +648,7 @@ impl UnixDatagram { /// Creates a Unix datagram socket bound to the given path. #[stable(feature = "unix_socket", since = "1.10.0")] pub fn bind>(path: P) -> io::Result { + #[cfg(not(target_os="none"))] fn inner(path: &Path) -> io::Result { unsafe { let socket = UnixDatagram::unbound()?; @@ -586,6 +659,12 @@ impl UnixDatagram { Ok(socket) } } + + #[cfg(target_os="none")] + fn inner(_path: &Path) -> io::Result { + Err(::sys::net::generic_error()) + } + inner(path.as_ref()) } @@ -611,6 +690,7 @@ impl UnixDatagram { /// `recv` and `recv_from` will only receive data from that address. #[stable(feature = "unix_socket", since = "1.10.0")] pub fn connect>(&self, path: P) -> io::Result<()> { + #[cfg(not(target_os="none"))] fn inner(d: &UnixDatagram, path: &Path) -> io::Result<()> { unsafe { let (addr, len) = sockaddr_un(path)?; @@ -620,6 +700,12 @@ impl UnixDatagram { Ok(()) } } + + #[cfg(target_os="none")] + fn inner(_d: &UnixDatagram, _path: &Path) -> io::Result<()> { + Err(::sys::net::generic_error()) + } + inner(self, path.as_ref()) } @@ -634,23 +720,42 @@ impl UnixDatagram { } /// Returns the address of this socket. + #[cfg(not(target_os="none"))] #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getsockname(*self.0.as_inner(), addr, len) }) } + /// Returns the address of this socket. + #[cfg(target_os="none")] + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn local_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + /// Returns the address of this socket's peer. /// /// The `connect` method will connect the socket to a peer. + #[cfg(not(target_os="none"))] #[stable(feature = "unix_socket", since = "1.10.0")] pub fn peer_addr(&self) -> io::Result { SocketAddr::new(|addr, len| unsafe { libc::getpeername(*self.0.as_inner(), addr, len) }) } + /// Returns the address of this socket's peer. + /// + /// The `connect` method will connect the socket to a peer. + #[cfg(target_os="none")] + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn peer_addr(&self) -> io::Result { + Err(::sys::net::generic_error()) + } + /// Receives data from the socket. /// /// On success, returns the number of bytes read and the address from /// whence the data came. + #[cfg(not(target_os="none"))] #[stable(feature = "unix_socket", since = "1.10.0")] pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { let mut count = 0; @@ -675,6 +780,17 @@ impl UnixDatagram { Ok((count as usize, addr)) } + + /// Receives data from the socket. + /// + /// On success, returns the number of bytes read and the address from + /// whence the data came. + #[cfg(target_os="none")] + #[stable(feature = "unix_socket", since = "1.10.0")] + pub fn recv_from(&self, _buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> { + Err(::sys::net::generic_error()) + } + /// Receives data from the socket. /// /// On success, returns the number of bytes read. @@ -688,6 +804,7 @@ impl UnixDatagram { /// On success, returns the number of bytes written. #[stable(feature = "unix_socket", since = "1.10.0")] pub fn send_to>(&self, buf: &[u8], path: P) -> io::Result { + #[cfg(not(target_os="none"))] fn inner(d: &UnixDatagram, buf: &[u8], path: &Path) -> io::Result { unsafe { let (addr, len) = sockaddr_un(path)?; @@ -701,6 +818,12 @@ impl UnixDatagram { Ok(count as usize) } } + + #[cfg(target_os="none")] + fn inner(_d: &UnixDatagram, _buf: &[u8], _path: &Path) -> io::Result { + Err(::sys::net::generic_error()) + } + inner(self, buf, path.as_ref()) } diff --git a/src/libstd/sys/unix/memchr.rs b/src/libstd/sys/unix/memchr.rs index 5038e0750c8d2..95177117a4534 100644 --- a/src/libstd/sys/unix/memchr.rs +++ b/src/libstd/sys/unix/memchr.rs @@ -12,19 +12,29 @@ // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch pub fn memchr(needle: u8, haystack: &[u8]) -> Option { - use libc; - - let p = unsafe { - libc::memchr( - haystack.as_ptr() as *const libc::c_void, - needle as libc::c_int, - haystack.len() as libc::size_t) - }; - if p.is_null() { - None - } else { - Some(p as usize - (haystack.as_ptr() as usize)) + #[cfg(not(target_os = "none"))] + fn memchr_specific(needle: u8, haystack: &[u8]) -> Option { + use libc; + + let p = unsafe { + libc::memchr( + haystack.as_ptr() as *const libc::c_void, + needle as libc::c_int, + haystack.len() as libc::size_t) + }; + if p.is_null() { + None + } else { + Some(p as usize - (haystack.as_ptr() as usize)) + } } + + #[cfg(target_os = "none")] + fn memchr_specific(needle: u8, haystack: &[u8]) -> Option { + ::sys_common::memchr::fallback::memchr(needle, haystack) + } + + memchr_specific(needle, haystack) } pub fn memrchr(needle: u8, haystack: &[u8]) -> Option { diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index dc410cba89e04..78899c9be8c58 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -26,6 +26,7 @@ use libc; #[cfg(target_os = "openbsd")] pub use os::openbsd as platform; #[cfg(target_os = "solaris")] pub use os::solaris as platform; #[cfg(target_os = "emscripten")] pub use os::emscripten as platform; +#[cfg(target_os = "none")] pub use os::none as platform; #[macro_use] pub mod weak; diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index c6118a333b192..3a48da6ff00ba 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -28,16 +28,15 @@ use ptr; use slice; use str; use sys_common::mutex::Mutex; -use sys::cvt; +#[cfg(not(target_os="none"))] use sys::cvt; use sys::fd; use vec; -const TMPBUF_SZ: usize = 128; static ENV_LOCK: Mutex = Mutex::new(); extern { - #[cfg(not(target_os = "dragonfly"))] + #[cfg(not(any(target_os = "dragonfly", target_os = "none")))] #[cfg_attr(any(target_os = "linux", target_os = "emscripten"), link_name = "__errno_location")] #[cfg_attr(any(target_os = "bitrig", @@ -56,7 +55,7 @@ extern { } /// Returns the platform-specific value of errno -#[cfg(not(target_os = "dragonfly"))] +#[cfg(not(any(target_os = "dragonfly", target_os = "none")))] pub fn errno() -> i32 { unsafe { (*errno_location()) as i32 @@ -81,7 +80,13 @@ pub fn errno() -> i32 { errno as i32 } +#[cfg(target_os = "none")] +pub fn errno() -> i32 { + 0 +} + /// Gets a detailed string description for the given error number. +#[cfg(not(target_os="none"))] pub fn error_string(errno: i32) -> String { extern { #[cfg_attr(any(target_os = "linux", target_env = "newlib"), @@ -90,7 +95,7 @@ pub fn error_string(errno: i32) -> String { buflen: libc::size_t) -> c_int; } - let mut buf = [0 as c_char; TMPBUF_SZ]; + let mut buf = [0 as c_char; 128]; let p = buf.as_mut_ptr(); unsafe { @@ -103,6 +108,12 @@ pub fn error_string(errno: i32) -> String { } } +#[cfg(target_os="none")] +pub fn error_string(_errno: i32) -> String { + "system error".to_owned() +} + +#[cfg(not(target_os="none"))] pub fn getcwd() -> io::Result { let mut buf = Vec::with_capacity(512); loop { @@ -129,6 +140,12 @@ pub fn getcwd() -> io::Result { } } +#[cfg(target_os="none")] +pub fn getcwd() -> io::Result { + Err(::sys::fs::generic_error()) +} + +#[cfg(not(target_os="none"))] pub fn chdir(p: &path::Path) -> io::Result<()> { let p: &OsStr = p.as_ref(); let p = CString::new(p.as_bytes())?; @@ -140,6 +157,11 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { } } +#[cfg(target_os="none")] +pub fn chdir(_p: &path::Path) -> io::Result<()> { + Err(::sys::fs::generic_error()) +} + pub struct SplitPaths<'a> { iter: iter::Map bool>, fn(&'a [u8]) -> PathBuf>, @@ -347,6 +369,11 @@ pub fn current_exe() -> io::Result { } } +#[cfg(target_os = "none")] +pub fn current_exe() -> io::Result { + Err(::sys::fs::generic_error()) +} + pub struct Env { iter: vec::IntoIter<(OsString, OsString)>, _dont_send_or_sync_me: PhantomData<*mut ()>, @@ -412,6 +439,7 @@ pub fn env() -> Env { } } +#[cfg(not(target_os="none"))] pub fn getenv(k: &OsStr) -> io::Result> { // environment variables with a nul byte can't be set, so their value is // always None as well @@ -429,6 +457,12 @@ pub fn getenv(k: &OsStr) -> io::Result> { } } +#[cfg(target_os="none")] +pub fn getenv(_k: &OsStr) -> io::Result> { + Err(::sys::env::generic_error()) +} + +#[cfg(not(target_os="none"))] pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let k = CString::new(k.as_bytes())?; let v = CString::new(v.as_bytes())?; @@ -441,6 +475,12 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { } } +#[cfg(target_os="none")] +pub fn setenv(_k: &OsStr, _v: &OsStr) -> io::Result<()> { + Err(::sys::env::generic_error()) +} + +#[cfg(not(target_os="none"))] pub fn unsetenv(n: &OsStr) -> io::Result<()> { let nbuf = CString::new(n.as_bytes())?; @@ -452,6 +492,12 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { } } +#[cfg(target_os="none")] +pub fn unsetenv(_n: &OsStr) -> io::Result<()> { + Err(::sys::env::generic_error()) +} + +#[cfg(not(target_os="none"))] pub fn page_size() -> usize { unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize @@ -468,6 +514,7 @@ pub fn temp_dir() -> PathBuf { }) } +#[cfg(not(target_os="none"))] pub fn home_dir() -> Option { return ::env::var_os("HOME").or_else(|| unsafe { fallback() @@ -522,6 +569,17 @@ pub fn home_dir() -> Option { } } +#[cfg(target_os="none")] +pub fn home_dir() -> Option { + None +} + +#[cfg(not(target_os="none"))] pub fn exit(code: i32) -> ! { unsafe { libc::exit(code as c_int) } } + +#[cfg(target_os="none")] +pub fn exit(_code: i32) -> ! { + unsafe { ::intrinsics::abort() } +} diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index ffe8032e46055..6136582f19f5c 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -8,12 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(not(target_os = "none"))] use cmp; use io; +#[cfg(not(target_os = "none"))] use libc::{self, c_int}; +#[cfg(not(target_os = "none"))] use mem; +#[cfg(not(target_os = "none"))] use ptr; -use sys::cvt_r; +#[cfg(not(target_os="none"))] use sys::cvt_r; use sys::fd::FileDesc; //////////////////////////////////////////////////////////////////////////////// @@ -22,6 +26,7 @@ use sys::fd::FileDesc; pub struct AnonPipe(FileDesc); +#[cfg(not(target_os="none"))] pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> { let mut fds = [0; 2]; @@ -52,6 +57,7 @@ pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> { } impl AnonPipe { + #[cfg(not(target_os = "none"))] pub fn from_fd(fd: FileDesc) -> io::Result { fd.set_cloexec()?; Ok(AnonPipe(fd)) @@ -73,6 +79,7 @@ impl AnonPipe { pub fn into_fd(self) -> FileDesc { self.0 } } +#[cfg(not(target_os="none"))] pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, @@ -123,3 +130,11 @@ pub fn read2(p1: AnonPipe, } } } + +#[cfg(target_os="none")] +pub fn read2(_p1: AnonPipe, + _v1: &mut Vec, + _p2: AnonPipe, + _v2: &mut Vec) -> io::Result<()> { + Err(::sys::process::generic_error()) +} diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index dafc11d9cc8e9..20a0027c911a7 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -12,17 +12,33 @@ use os::unix::prelude::*; use collections::hash_map::{HashMap, Entry}; use env; -use ffi::{OsString, OsStr, CString, CStr}; +use ffi::{OsString, OsStr, CString}; +#[cfg(not(target_os = "none"))] +use ffi::CStr; use fmt; -use io::{self, Error, ErrorKind}; -use libc::{self, pid_t, c_int, gid_t, uid_t, c_char}; +use io::{self, ErrorKind}; +#[cfg(not(target_os = "none"))] +use io::Error; +#[cfg(not(target_os = "none"))] +use libc; +use libc::{pid_t, c_int, gid_t, uid_t, c_char}; +#[cfg(not(target_os = "none"))] use mem; use ptr; use sys::fd::FileDesc; +#[cfg(not(target_os = "none"))] use sys::fs::{File, OpenOptions}; -use sys::pipe::{self, AnonPipe}; +use sys::pipe::AnonPipe; +#[cfg(not(target_os = "none"))] +use sys::pipe; +#[cfg(not(target_os="none"))] use sys::{self, cvt, cvt_r}; +#[cfg(target_os="none")] +pub fn generic_error() -> io::Error { + io::Error::new(io::ErrorKind::Other, "processes not supported on this platform") +} + //////////////////////////////////////////////////////////////////////////////// // Command //////////////////////////////////////////////////////////////////////////////// @@ -71,6 +87,7 @@ pub struct StdioPipes { // passed to do_exec() with configuration of what the child stdio should look // like +#[cfg_attr(target_os="none",allow(dead_code))] struct ChildPipes { stdin: ChildStdio, stdout: ChildStdio, @@ -78,9 +95,9 @@ struct ChildPipes { } enum ChildStdio { - Inherit, - Explicit(c_int), - Owned(FileDesc), + #[cfg(not(target_os="none"))] Inherit, + #[cfg(not(target_os="none"))] Explicit(c_int), + #[cfg(not(target_os="none"))] Owned(FileDesc), } pub enum Stdio { @@ -210,6 +227,7 @@ impl Command { self.stderr = Some(stderr); } + #[cfg(not(target_os="none"))] pub fn spawn(&mut self, default: Stdio, needs_stdin: bool) -> io::Result<(Process, StdioPipes)> { const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX"; @@ -286,6 +304,12 @@ impl Command { } } + #[cfg(target_os="none")] + pub fn spawn(&mut self, _default: Stdio, _needs_stdin: bool) + -> io::Result<(Process, StdioPipes)> { + Err(generic_error()) + } + pub fn exec(&mut self, default: Stdio) -> io::Error { if self.saw_nul { return io::Error::new(ErrorKind::InvalidInput, @@ -328,6 +352,7 @@ impl Command { // allocation). Instead we just close it manually. This will never // have the drop glue anyway because this code never returns (the // child will either exec() or invoke libc::exit) + #[cfg(not(target_os="none"))] unsafe fn do_exec(&mut self, stdio: ChildPipes) -> io::Error { macro_rules! t { ($e:expr) => (match $e { @@ -395,6 +420,10 @@ impl Command { io::Error::last_os_error() } + #[cfg(target_os="none")] + unsafe fn do_exec(&mut self, _stdio: ChildPipes) -> io::Error { + generic_error() + } fn setup_io(&self, default: Stdio, needs_stdin: bool) -> io::Result<(StdioPipes, ChildPipes)> { @@ -428,6 +457,7 @@ fn os2c(s: &OsStr, saw_nul: &mut bool) -> CString { } impl Stdio { + #[cfg(not(target_os="none"))] fn to_child_stdio(&self, readable: bool) -> io::Result<(ChildStdio, Option)> { match *self { @@ -470,8 +500,15 @@ impl Stdio { } } } + + #[cfg(target_os="none")] + fn to_child_stdio(&self, _readable: bool) + -> io::Result<(ChildStdio, Option)> { + Err(generic_error()) + } } +#[cfg(not(target_os="none"))] impl ChildStdio { fn fd(&self) -> Option { match *self { @@ -513,6 +550,7 @@ impl fmt::Debug for Command { pub struct ExitStatus(c_int); impl ExitStatus { + #[cfg(not(target_os="none"))] fn exited(&self) -> bool { unsafe { libc::WIFEXITED(self.0) } } @@ -521,6 +559,7 @@ impl ExitStatus { self.code() == Some(0) } + #[cfg(not(target_os="none"))] pub fn code(&self) -> Option { if self.exited() { Some(unsafe { libc::WEXITSTATUS(self.0) }) @@ -529,6 +568,12 @@ impl ExitStatus { } } + #[cfg(target_os="none")] + pub fn code(&self) -> Option { + None + } + + #[cfg(not(target_os="none"))] pub fn signal(&self) -> Option { if !self.exited() { Some(unsafe { libc::WTERMSIG(self.0) }) @@ -536,6 +581,11 @@ impl ExitStatus { None } } + + #[cfg(target_os="none")] + pub fn signal(&self) -> Option { + None + } } impl From for ExitStatus { @@ -558,7 +608,7 @@ impl fmt::Display for ExitStatus { /// The unique id of the process (this should never be negative). pub struct Process { pid: pid_t, - status: Option, + #[cfg(not(target_os="none"))] status: Option, } impl Process { @@ -566,6 +616,7 @@ impl Process { self.pid as u32 } + #[cfg(not(target_os="none"))] pub fn kill(&mut self) -> io::Result<()> { // If we've already waited on this process then the pid can be recycled // and used for another process, and we probably shouldn't be killing @@ -578,6 +629,12 @@ impl Process { } } + #[cfg(target_os="none")] + pub fn kill(&mut self) -> io::Result<()> { + Err(generic_error()) + } + + #[cfg(not(target_os="none"))] pub fn wait(&mut self) -> io::Result { if let Some(status) = self.status { return Ok(status) @@ -587,6 +644,11 @@ impl Process { self.status = Some(ExitStatus(status)); Ok(ExitStatus(status)) } + + #[cfg(target_os="none")] + pub fn wait(&mut self) -> io::Result { + Err(generic_error()) + } } #[cfg(all(test, not(target_os = "emscripten")))] diff --git a/src/libstd/sys/unix/rand.rs b/src/libstd/sys/unix/rand.rs index 6b50ca9bcdf6d..6554ada1c767c 100644 --- a/src/libstd/sys/unix/rand.rs +++ b/src/libstd/sys/unix/rand.rs @@ -25,6 +25,7 @@ fn next_u64(mut fill_buf: &mut FnMut(&mut [u8])) -> u64 { } #[cfg(all(unix, + not(target_os = "none"), not(target_os = "ios"), not(target_os = "openbsd"), not(target_os = "freebsd")))] @@ -339,3 +340,40 @@ mod imp { } } } + +#[cfg(target_os = "none")] +mod imp { + use super::{next_u32, next_u64}; + + use io; + use rand::Rng; + + pub struct OsRng { + // dummy field to ensure that this struct cannot be constructed outside + // of this module + _dummy: (), + } + + impl OsRng { + /// Create a new `OsRng`. + pub fn new() -> io::Result { + Ok(OsRng { _dummy: () }) + } + } + + impl Rng for OsRng { + fn next_u32(&mut self) -> u32 { + next_u32(&mut |v| self.fill_bytes(v)) + } + fn next_u64(&mut self) -> u64 { + next_u64(&mut |v| self.fill_bytes(v)) + } + fn fill_bytes(&mut self, v: &mut [u8]) { + extern { + fn getrandom(buf: *mut u8, len: usize); + } + + unsafe { getrandom(v.as_mut_ptr(), v.len()) } + } + } +} diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index 22d47ba0f620d..063495b2aa24b 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -21,6 +21,7 @@ pub struct Handler { } impl Handler { + #[cfg_attr(target_os="none",allow(dead_code))] pub unsafe fn new() -> Handler { make_handler() } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 1e879117f73ab..e684eef477a6f 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -9,15 +9,19 @@ // except according to those terms. use alloc::boxed::FnBox; +#[cfg(not(target_os="none"))] use cmp; use ffi::CStr; use io; use libc; use mem; +#[cfg(not(target_os="none"))] use ptr; +#[cfg(not(target_os="none"))] use sys::os; use time::Duration; +#[cfg(not(target_os="none"))] use sys_common::thread::*; pub struct Thread { @@ -31,19 +35,25 @@ unsafe impl Sync for Thread {} // The pthread_attr_setstacksize symbol doesn't exist in the emscripten libc, // so we have to not link to it to satisfy emcc's ERROR_ON_UNDEFINED_SYMBOLS. -#[cfg(not(target_os = "emscripten"))] +#[cfg(not(any(target_os = "emscripten", target_os = "none")))] unsafe fn pthread_attr_setstacksize(attr: *mut libc::pthread_attr_t, stack_size: libc::size_t) -> libc::c_int { libc::pthread_attr_setstacksize(attr, stack_size) } -#[cfg(target_os = "emscripten")] +#[cfg(any(target_os = "emscripten"))] unsafe fn pthread_attr_setstacksize(_attr: *mut libc::pthread_attr_t, _stack_size: libc::size_t) -> libc::c_int { panic!() } +#[cfg(target_os = "none")] +pub fn generic_error() -> io::Error { + io::Error::new(io::ErrorKind::Other, "threading not supported on this platform") +} + impl Thread { + #[cfg(not(target_os = "none"))] pub unsafe fn new<'a>(stack: usize, p: Box) -> io::Result { let p = box p; @@ -87,11 +97,21 @@ impl Thread { } } + #[cfg(target_os = "none")] + pub unsafe fn new<'a>(_stack: usize, _p: Box) + -> io::Result { + Err(generic_error()) + } + + #[cfg(not(target_os = "none"))] pub fn yield_now() { let ret = unsafe { libc::sched_yield() }; debug_assert_eq!(ret, 0); } + #[cfg(target_os = "none")] + pub fn yield_now() {} + #[cfg(any(target_os = "linux", target_os = "android"))] pub fn set_name(name: &CStr) { @@ -132,11 +152,13 @@ impl Thread { #[cfg(any(target_env = "newlib", target_os = "solaris", target_os = "haiku", + target_os = "none", target_os = "emscripten"))] pub fn set_name(_name: &CStr) { // Newlib, Illumos, Haiku, and Emscripten have no way to set a thread name. } + #[cfg(not(target_os = "none"))] pub fn sleep(dur: Duration) { let mut secs = dur.as_secs(); let mut nsecs = dur.subsec_nanos() as libc::c_long; @@ -161,6 +183,10 @@ impl Thread { } } + #[cfg(target_os = "none")] + pub fn sleep(_dur: Duration) {} + + #[cfg(not(target_os = "none"))] pub fn join(self) { unsafe { let ret = libc::pthread_join(self.id, ptr::null_mut()); @@ -169,6 +195,9 @@ impl Thread { } } + #[cfg(target_os = "none")] + pub fn join(self) {} + pub fn id(&self) -> libc::pthread_t { self.id } pub fn into_id(self) -> libc::pthread_t { @@ -179,10 +208,14 @@ impl Thread { } impl Drop for Thread { + #[cfg(not(target_os = "none"))] fn drop(&mut self) { let ret = unsafe { libc::pthread_detach(self.id) }; debug_assert_eq!(ret, 0); } + + #[cfg(target_os = "none")] + fn drop(&mut self) {} } #[cfg(all(not(all(target_os = "linux", not(target_env = "musl"))), @@ -366,12 +399,13 @@ fn min_stack_size(attr: *const libc::pthread_attr_t) -> usize { // No point in looking up __pthread_get_minstack() on non-glibc // platforms. #[cfg(all(not(target_os = "linux"), - not(target_os = "netbsd")))] + not(target_os = "netbsd"), + not(target_os = "none")))] fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { libc::PTHREAD_STACK_MIN as usize } -#[cfg(target_os = "netbsd")] +#[cfg(any(target_os = "netbsd"))] fn min_stack_size(_: *const libc::pthread_attr_t) -> usize { 2048 // just a guess } diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index a08cec38f732d..9880c110e2814 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -242,7 +242,7 @@ mod inner { mod inner { use fmt; use libc; - use sys::cvt; + #[cfg(not(target_os="none"))] use sys::cvt; use time::Duration; use super::Timespec; @@ -334,6 +334,7 @@ mod inner { #[cfg(target_os = "dragonfly")] pub type clock_t = libc::c_ulong; + #[cfg(not(target_os = "none"))] fn now(clock: clock_t) -> Timespec { let mut t = Timespec { t: libc::timespec { @@ -346,4 +347,10 @@ mod inner { }).unwrap(); t } + + + #[cfg(target_os = "none")] + fn now(_clock: clock_t) -> Timespec { + panic!("time not supported on this platform") + } }