Auto merge of #47268 - EdSchouten:cloudabi-libstd, r=alexcrichton
Implement libstd for CloudABI. Though CloudABI is strongly inspired by POSIX, its absence of features that don't work well with capability-based sandboxing makes it different enough that adding bits to `sys/unix` will make things a mess. This change therefore adds CloudABI specific platform code under `sys/cloudabi`. One of the goals of this implementation is to build as much as possible directly on top of CloudABI's system call layer, as opposed to using the C library. This is preferred, as the system call layer is supposed to be stable, whereas the C library ABI technically is not. An advantage of this approach is that it allows us to implement certain interfaces, such as mutexes and condition variables more optimally. They can be lighter than the ones provided by pthreads. This change disables some modules that cannot realistically be implemented right now. For example, libstd's pathname abstraction is not designed with POSIX `*at()` (e.g., `openat()`) in mind. The `*at()` functions are the only set of file system APIs available on CloudABI. There is no global file system namespace, nor a process working directory. Discussions on how to port these modules over are outside the scope of this change.
This commit is contained in:
commit
48ab4cde54
30 changed files with 5057 additions and 14 deletions
|
@ -956,8 +956,7 @@ mod arch {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use ffi::OsStr;
|
||||
use path::{Path, PathBuf};
|
||||
use path::Path;
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(target_os = "emscripten", ignore)]
|
||||
|
@ -980,6 +979,8 @@ mod tests {
|
|||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn split_paths_windows() {
|
||||
use path::PathBuf;
|
||||
|
||||
fn check_parse(unparsed: &str, parsed: &[&str]) -> bool {
|
||||
split_paths(unparsed).collect::<Vec<_>>() ==
|
||||
parsed.iter().map(|s| PathBuf::from(*s)).collect::<Vec<_>>()
|
||||
|
@ -1000,6 +1001,8 @@ mod tests {
|
|||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn split_paths_unix() {
|
||||
use path::PathBuf;
|
||||
|
||||
fn check_parse(unparsed: &str, parsed: &[&str]) -> bool {
|
||||
split_paths(unparsed).collect::<Vec<_>>() ==
|
||||
parsed.iter().map(|s| PathBuf::from(*s)).collect::<Vec<_>>()
|
||||
|
@ -1015,6 +1018,8 @@ mod tests {
|
|||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn join_paths_unix() {
|
||||
use ffi::OsStr;
|
||||
|
||||
fn test_eq(input: &[&str], output: &str) -> bool {
|
||||
&*join_paths(input.iter().cloned()).unwrap() ==
|
||||
OsStr::new(output)
|
||||
|
@ -1031,6 +1036,8 @@ mod tests {
|
|||
#[test]
|
||||
#[cfg(windows)]
|
||||
fn join_paths_windows() {
|
||||
use ffi::OsStr;
|
||||
|
||||
fn test_eq(input: &[&str], output: &str) -> bool {
|
||||
&*join_paths(input.iter().cloned()).unwrap() ==
|
||||
OsStr::new(output)
|
||||
|
|
|
@ -1989,7 +1989,7 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_os = "emscripten")))]
|
||||
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
|
||||
mod tests {
|
||||
use io::prelude::*;
|
||||
|
||||
|
|
|
@ -885,7 +885,7 @@ impl fmt::Debug for TcpListener {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_os = "emscripten")))]
|
||||
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
|
||||
mod tests {
|
||||
use io::ErrorKind;
|
||||
use io::prelude::*;
|
||||
|
|
|
@ -786,7 +786,7 @@ impl fmt::Debug for UdpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_os = "emscripten")))]
|
||||
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
|
||||
mod tests {
|
||||
use io::ErrorKind;
|
||||
use net::*;
|
||||
|
|
|
@ -1392,7 +1392,7 @@ pub fn id() -> u32 {
|
|||
::sys::os::getpid()
|
||||
}
|
||||
|
||||
#[cfg(all(test, not(target_os = "emscripten")))]
|
||||
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
|
||||
mod tests {
|
||||
use io::prelude::*;
|
||||
|
||||
|
|
51
src/libstd/sys/cloudabi/abi/bitflags.rs
Normal file
51
src/libstd/sys/cloudabi/abi/bitflags.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
// Copyright (c) 2018 Nuxi (https://nuxi.nl/) and contributors.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
// SUCH DAMAGE.
|
||||
|
||||
// Appease Rust's tidy.
|
||||
// ignore-license
|
||||
|
||||
#[cfg(feature = "bitflags")]
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
|
||||
// Minimal implementation of bitflags! in case we can't depend on the bitflags
|
||||
// crate. Only implements `bits()` and a `from_bits_truncate()` that doesn't
|
||||
// actually truncate.
|
||||
#[cfg(not(feature = "bitflags"))]
|
||||
macro_rules! bitflags {
|
||||
(
|
||||
$(#[$attr:meta])*
|
||||
pub struct $name:ident: $type:ty {
|
||||
$($(#[$const_attr:meta])* const $const:ident = $val:expr;)*
|
||||
}
|
||||
) => {
|
||||
$(#[$attr])*
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
|
||||
pub struct $name { bits: $type }
|
||||
impl $name {
|
||||
$($(#[$const_attr])* pub const $const: $name = $name{ bits: $val };)*
|
||||
pub fn bits(&self) -> $type { self.bits }
|
||||
pub fn from_bits_truncate(bits: $type) -> Self { $name{ bits } }
|
||||
}
|
||||
}
|
||||
}
|
2847
src/libstd/sys/cloudabi/abi/cloudabi.rs
Normal file
2847
src/libstd/sys/cloudabi/abi/cloudabi.rs
Normal file
File diff suppressed because it is too large
Load diff
13
src/libstd/sys/cloudabi/abi/mod.rs
Normal file
13
src/libstd/sys/cloudabi/abi/mod.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
#[allow(warnings)]
|
||||
mod cloudabi;
|
||||
pub use self::cloudabi::*;
|
17
src/libstd/sys/cloudabi/args.rs
Normal file
17
src/libstd/sys/cloudabi/args.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
pub use sys::cloudabi::shims::args::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn init(_: isize, _: *const *const u8) {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn cleanup() {}
|
121
src/libstd/sys/cloudabi/backtrace.rs
Normal file
121
src/libstd/sys/cloudabi/backtrace.rs
Normal file
|
@ -0,0 +1,121 @@
|
|||
// Copyright 2014-2018 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.
|
||||
|
||||
use error::Error;
|
||||
use ffi::CStr;
|
||||
use intrinsics;
|
||||
use io;
|
||||
use libc;
|
||||
use sys_common::backtrace::Frame;
|
||||
use unwind as uw;
|
||||
|
||||
pub struct BacktraceContext;
|
||||
|
||||
struct Context<'a> {
|
||||
idx: usize,
|
||||
frames: &'a mut [Frame],
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct UnwindError(uw::_Unwind_Reason_Code);
|
||||
|
||||
impl Error for UnwindError {
|
||||
fn description(&self) -> &'static str {
|
||||
"unexpected return value while unwinding"
|
||||
}
|
||||
}
|
||||
|
||||
impl ::fmt::Display for UnwindError {
|
||||
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
|
||||
write!(f, "{}: {:?}", self.description(), self.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(never)] // if we know this is a function call, we can skip it when
|
||||
// tracing
|
||||
pub fn unwind_backtrace(frames: &mut [Frame]) -> io::Result<(usize, BacktraceContext)> {
|
||||
let mut cx = Context { idx: 0, frames };
|
||||
let result_unwind =
|
||||
unsafe { uw::_Unwind_Backtrace(trace_fn, &mut cx as *mut Context as *mut libc::c_void) };
|
||||
// See libunwind:src/unwind/Backtrace.c for the return values.
|
||||
// No, there is no doc.
|
||||
match result_unwind {
|
||||
// These return codes seem to be benign and need to be ignored for backtraces
|
||||
// to show up properly on all tested platforms.
|
||||
uw::_URC_END_OF_STACK | uw::_URC_FATAL_PHASE1_ERROR | uw::_URC_FAILURE => {
|
||||
Ok((cx.idx, BacktraceContext))
|
||||
}
|
||||
_ => Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
UnwindError(result_unwind),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn trace_fn(
|
||||
ctx: *mut uw::_Unwind_Context,
|
||||
arg: *mut libc::c_void,
|
||||
) -> uw::_Unwind_Reason_Code {
|
||||
let cx = unsafe { &mut *(arg as *mut Context) };
|
||||
let mut ip_before_insn = 0;
|
||||
let mut ip = unsafe { uw::_Unwind_GetIPInfo(ctx, &mut ip_before_insn) as *mut libc::c_void };
|
||||
if !ip.is_null() && ip_before_insn == 0 {
|
||||
// this is a non-signaling frame, so `ip` refers to the address
|
||||
// after the calling instruction. account for that.
|
||||
ip = (ip as usize - 1) as *mut _;
|
||||
}
|
||||
|
||||
let symaddr = unsafe { uw::_Unwind_FindEnclosingFunction(ip) };
|
||||
if cx.idx < cx.frames.len() {
|
||||
cx.frames[cx.idx] = Frame {
|
||||
symbol_addr: symaddr as *mut u8,
|
||||
exact_position: ip as *mut u8,
|
||||
};
|
||||
cx.idx += 1;
|
||||
}
|
||||
|
||||
uw::_URC_NO_REASON
|
||||
}
|
||||
|
||||
pub fn foreach_symbol_fileline<F>(_: Frame, _: F, _: &BacktraceContext) -> io::Result<bool>
|
||||
where
|
||||
F: FnMut(&[u8], u32) -> io::Result<()>,
|
||||
{
|
||||
// No way to obtain this information on CloudABI.
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn resolve_symname<F>(frame: Frame, callback: F, _: &BacktraceContext) -> io::Result<()>
|
||||
where
|
||||
F: FnOnce(Option<&str>) -> io::Result<()>,
|
||||
{
|
||||
unsafe {
|
||||
let mut info: Dl_info = intrinsics::init();
|
||||
let symname =
|
||||
if dladdr(frame.exact_position as *mut _, &mut info) == 0 || info.dli_sname.is_null() {
|
||||
None
|
||||
} else {
|
||||
CStr::from_ptr(info.dli_sname).to_str().ok()
|
||||
};
|
||||
callback(symname)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Dl_info {
|
||||
dli_fname: *const libc::c_char,
|
||||
dli_fbase: *mut libc::c_void,
|
||||
dli_sname: *const libc::c_char,
|
||||
dli_saddr: *mut libc::c_void,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn dladdr(addr: *const libc::c_void, info: *mut Dl_info) -> libc::c_int;
|
||||
}
|
169
src/libstd/sys/cloudabi/condvar.rs
Normal file
169
src/libstd/sys/cloudabi/condvar.rs
Normal file
|
@ -0,0 +1,169 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use cell::UnsafeCell;
|
||||
use mem;
|
||||
use sync::atomic::{AtomicU32, Ordering};
|
||||
use sys::cloudabi::abi;
|
||||
use sys::mutex::{self, Mutex};
|
||||
use sys::time::dur2intervals;
|
||||
use time::Duration;
|
||||
|
||||
extern "C" {
|
||||
#[thread_local]
|
||||
static __pthread_thread_id: abi::tid;
|
||||
}
|
||||
|
||||
pub struct Condvar {
|
||||
condvar: UnsafeCell<AtomicU32>,
|
||||
}
|
||||
|
||||
unsafe impl Send for Condvar {}
|
||||
unsafe impl Sync for Condvar {}
|
||||
|
||||
impl Condvar {
|
||||
pub const fn new() -> Condvar {
|
||||
Condvar {
|
||||
condvar: UnsafeCell::new(AtomicU32::new(abi::CONDVAR_HAS_NO_WAITERS.0)),
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn init(&mut self) {}
|
||||
|
||||
pub unsafe fn notify_one(&self) {
|
||||
let condvar = self.condvar.get();
|
||||
if (*condvar).load(Ordering::Relaxed) != abi::CONDVAR_HAS_NO_WAITERS.0 {
|
||||
let ret = abi::condvar_signal(condvar as *mut abi::condvar, abi::scope::PRIVATE, 1);
|
||||
assert_eq!(
|
||||
ret,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to signal on condition variable"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn notify_all(&self) {
|
||||
let condvar = self.condvar.get();
|
||||
if (*condvar).load(Ordering::Relaxed) != abi::CONDVAR_HAS_NO_WAITERS.0 {
|
||||
let ret = abi::condvar_signal(
|
||||
condvar as *mut abi::condvar,
|
||||
abi::scope::PRIVATE,
|
||||
abi::nthreads::max_value(),
|
||||
);
|
||||
assert_eq!(
|
||||
ret,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to broadcast on condition variable"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn wait(&self, mutex: &Mutex) {
|
||||
let mutex = mutex::raw(mutex);
|
||||
assert_eq!(
|
||||
(*mutex).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
"This lock is not write-locked by this thread"
|
||||
);
|
||||
|
||||
// Call into the kernel to wait on the condition variable.
|
||||
let condvar = self.condvar.get();
|
||||
let subscription = abi::subscription {
|
||||
type_: abi::eventtype::CONDVAR,
|
||||
union: abi::subscription_union {
|
||||
condvar: abi::subscription_condvar {
|
||||
condvar: condvar as *mut abi::condvar,
|
||||
condvar_scope: abi::scope::PRIVATE,
|
||||
lock: mutex as *mut abi::lock,
|
||||
lock_scope: abi::scope::PRIVATE,
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
};
|
||||
let mut event: abi::event = mem::uninitialized();
|
||||
let mut nevents: usize = mem::uninitialized();
|
||||
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
|
||||
assert_eq!(
|
||||
ret,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to wait on condition variable"
|
||||
);
|
||||
assert_eq!(
|
||||
event.error,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to wait on condition variable"
|
||||
);
|
||||
}
|
||||
|
||||
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
|
||||
let mutex = mutex::raw(mutex);
|
||||
assert_eq!(
|
||||
(*mutex).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
"This lock is not write-locked by this thread"
|
||||
);
|
||||
|
||||
// Call into the kernel to wait on the condition variable.
|
||||
let condvar = self.condvar.get();
|
||||
let subscriptions = [
|
||||
abi::subscription {
|
||||
type_: abi::eventtype::CONDVAR,
|
||||
union: abi::subscription_union {
|
||||
condvar: abi::subscription_condvar {
|
||||
condvar: condvar as *mut abi::condvar,
|
||||
condvar_scope: abi::scope::PRIVATE,
|
||||
lock: mutex as *mut abi::lock,
|
||||
lock_scope: abi::scope::PRIVATE,
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
},
|
||||
abi::subscription {
|
||||
type_: abi::eventtype::CLOCK,
|
||||
union: abi::subscription_union {
|
||||
clock: abi::subscription_clock {
|
||||
clock_id: abi::clockid::MONOTONIC,
|
||||
timeout: dur2intervals(&dur),
|
||||
..mem::zeroed()
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
},
|
||||
];
|
||||
let mut events: [abi::event; 2] = mem::uninitialized();
|
||||
let mut nevents: usize = mem::uninitialized();
|
||||
let ret = abi::poll(subscriptions.as_ptr(), events.as_mut_ptr(), 2, &mut nevents);
|
||||
assert_eq!(
|
||||
ret,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to wait on condition variable"
|
||||
);
|
||||
for i in 0..nevents {
|
||||
assert_eq!(
|
||||
events[i].error,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to wait on condition variable"
|
||||
);
|
||||
if events[i].type_ == abi::eventtype::CONDVAR {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub unsafe fn destroy(&self) {
|
||||
let condvar = self.condvar.get();
|
||||
assert_eq!(
|
||||
(*condvar).load(Ordering::Relaxed),
|
||||
abi::CONDVAR_HAS_NO_WAITERS.0,
|
||||
"Attempted to destroy a condition variable with blocked threads"
|
||||
);
|
||||
}
|
||||
}
|
76
src/libstd/sys/cloudabi/mod.rs
Normal file
76
src/libstd/sys/cloudabi/mod.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use io;
|
||||
use libc;
|
||||
use mem;
|
||||
|
||||
pub mod args;
|
||||
#[cfg(feature = "backtrace")]
|
||||
pub mod backtrace;
|
||||
#[path = "../unix/cmath.rs"]
|
||||
pub mod cmath;
|
||||
pub mod condvar;
|
||||
#[path = "../unix/memchr.rs"]
|
||||
pub mod memchr;
|
||||
pub mod mutex;
|
||||
pub mod os;
|
||||
#[path = "../unix/os_str.rs"]
|
||||
pub mod os_str;
|
||||
pub mod rwlock;
|
||||
pub mod stack_overflow;
|
||||
pub mod stdio;
|
||||
pub mod thread;
|
||||
#[path = "../unix/thread_local.rs"]
|
||||
pub mod thread_local;
|
||||
pub mod time;
|
||||
|
||||
mod abi;
|
||||
|
||||
mod shims;
|
||||
pub use self::shims::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn init() {}
|
||||
|
||||
pub fn decode_error_kind(errno: i32) -> io::ErrorKind {
|
||||
match errno {
|
||||
x if x == abi::errno::ACCES as i32 => io::ErrorKind::PermissionDenied,
|
||||
x if x == abi::errno::ADDRINUSE as i32 => io::ErrorKind::AddrInUse,
|
||||
x if x == abi::errno::ADDRNOTAVAIL as i32 => io::ErrorKind::AddrNotAvailable,
|
||||
x if x == abi::errno::AGAIN as i32 => io::ErrorKind::WouldBlock,
|
||||
x if x == abi::errno::CONNABORTED as i32 => io::ErrorKind::ConnectionAborted,
|
||||
x if x == abi::errno::CONNREFUSED as i32 => io::ErrorKind::ConnectionRefused,
|
||||
x if x == abi::errno::CONNRESET as i32 => io::ErrorKind::ConnectionReset,
|
||||
x if x == abi::errno::EXIST as i32 => io::ErrorKind::AlreadyExists,
|
||||
x if x == abi::errno::INTR as i32 => io::ErrorKind::Interrupted,
|
||||
x if x == abi::errno::INVAL as i32 => io::ErrorKind::InvalidInput,
|
||||
x if x == abi::errno::NOENT as i32 => io::ErrorKind::NotFound,
|
||||
x if x == abi::errno::NOTCONN as i32 => io::ErrorKind::NotConnected,
|
||||
x if x == abi::errno::PERM as i32 => io::ErrorKind::PermissionDenied,
|
||||
x if x == abi::errno::PIPE as i32 => io::ErrorKind::BrokenPipe,
|
||||
x if x == abi::errno::TIMEDOUT as i32 => io::ErrorKind::TimedOut,
|
||||
_ => io::ErrorKind::Other,
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn abort_internal() -> ! {
|
||||
::core::intrinsics::abort();
|
||||
}
|
||||
|
||||
pub use libc::strlen;
|
||||
|
||||
pub fn hashmap_random_keys() -> (u64, u64) {
|
||||
unsafe {
|
||||
let mut v = mem::uninitialized();
|
||||
libc::arc4random_buf(&mut v as *mut _ as *mut libc::c_void, mem::size_of_val(&v));
|
||||
v
|
||||
}
|
||||
}
|
158
src/libstd/sys/cloudabi/mutex.rs
Normal file
158
src/libstd/sys/cloudabi/mutex.rs
Normal file
|
@ -0,0 +1,158 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use cell::UnsafeCell;
|
||||
use mem;
|
||||
use sync::atomic::{AtomicU32, Ordering};
|
||||
use sys::cloudabi::abi;
|
||||
use sys::rwlock::{self, RWLock};
|
||||
|
||||
extern "C" {
|
||||
#[thread_local]
|
||||
static __pthread_thread_id: abi::tid;
|
||||
}
|
||||
|
||||
// Implement Mutex using an RWLock. This doesn't introduce any
|
||||
// performance overhead in this environment, as the operations would be
|
||||
// implemented identically.
|
||||
pub struct Mutex(RWLock);
|
||||
|
||||
pub unsafe fn raw(m: &Mutex) -> *mut AtomicU32 {
|
||||
rwlock::raw(&m.0)
|
||||
}
|
||||
|
||||
impl Mutex {
|
||||
pub const fn new() -> Mutex {
|
||||
Mutex(RWLock::new())
|
||||
}
|
||||
|
||||
pub unsafe fn init(&mut self) {
|
||||
// This function should normally reinitialize the mutex after
|
||||
// moving it to a different memory address. This implementation
|
||||
// does not require adjustments after moving.
|
||||
}
|
||||
|
||||
pub unsafe fn try_lock(&self) -> bool {
|
||||
self.0.try_write()
|
||||
}
|
||||
|
||||
pub unsafe fn lock(&self) {
|
||||
self.0.write()
|
||||
}
|
||||
|
||||
pub unsafe fn unlock(&self) {
|
||||
self.0.write_unlock()
|
||||
}
|
||||
|
||||
pub unsafe fn destroy(&self) {
|
||||
self.0.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReentrantMutex {
|
||||
lock: UnsafeCell<AtomicU32>,
|
||||
recursion: UnsafeCell<u32>,
|
||||
}
|
||||
|
||||
impl ReentrantMutex {
|
||||
pub unsafe fn uninitialized() -> ReentrantMutex {
|
||||
mem::uninitialized()
|
||||
}
|
||||
|
||||
pub unsafe fn init(&mut self) {
|
||||
self.lock = UnsafeCell::new(AtomicU32::new(abi::LOCK_UNLOCKED.0));
|
||||
self.recursion = UnsafeCell::new(0);
|
||||
}
|
||||
|
||||
pub unsafe fn try_lock(&self) -> bool {
|
||||
// Attempt to acquire the lock.
|
||||
let lock = self.lock.get();
|
||||
let recursion = self.recursion.get();
|
||||
if let Err(old) = (*lock).compare_exchange(
|
||||
abi::LOCK_UNLOCKED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
Ordering::Acquire,
|
||||
Ordering::Relaxed,
|
||||
) {
|
||||
// If we fail to acquire the lock, it may be the case
|
||||
// that we've already acquired it and may need to recurse.
|
||||
if old & !abi::LOCK_KERNEL_MANAGED.0 == __pthread_thread_id.0 | abi::LOCK_WRLOCKED.0 {
|
||||
*recursion += 1;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} else {
|
||||
// Success.
|
||||
assert_eq!(*recursion, 0, "Mutex has invalid recursion count");
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn lock(&self) {
|
||||
if !self.try_lock() {
|
||||
// Call into the kernel to acquire a write lock.
|
||||
let lock = self.lock.get();
|
||||
let subscription = abi::subscription {
|
||||
type_: abi::eventtype::LOCK_WRLOCK,
|
||||
union: abi::subscription_union {
|
||||
lock: abi::subscription_lock {
|
||||
lock: lock as *mut abi::lock,
|
||||
lock_scope: abi::scope::PRIVATE,
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
};
|
||||
let mut event: abi::event = mem::uninitialized();
|
||||
let mut nevents: usize = mem::uninitialized();
|
||||
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to acquire mutex");
|
||||
assert_eq!(event.error, abi::errno::SUCCESS, "Failed to acquire mutex");
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn unlock(&self) {
|
||||
let lock = self.lock.get();
|
||||
let recursion = self.recursion.get();
|
||||
assert_eq!(
|
||||
(*lock).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
"This mutex is locked by a different thread"
|
||||
);
|
||||
|
||||
if *recursion > 0 {
|
||||
*recursion -= 1;
|
||||
} else if !(*lock)
|
||||
.compare_exchange(
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
abi::LOCK_UNLOCKED.0,
|
||||
Ordering::Release,
|
||||
Ordering::Relaxed,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
// Lock is managed by kernelspace. Call into the kernel
|
||||
// to unblock waiting threads.
|
||||
let ret = abi::lock_unlock(lock as *mut abi::lock, abi::scope::PRIVATE);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to unlock a mutex");
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn destroy(&self) {
|
||||
let lock = self.lock.get();
|
||||
let recursion = self.recursion.get();
|
||||
assert_eq!(
|
||||
(*lock).load(Ordering::Relaxed),
|
||||
abi::LOCK_UNLOCKED.0,
|
||||
"Attempted to destroy locked mutex"
|
||||
);
|
||||
assert_eq!(*recursion, 0, "Recursion counter invalid");
|
||||
}
|
||||
}
|
37
src/libstd/sys/cloudabi/os.rs
Normal file
37
src/libstd/sys/cloudabi/os.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use ffi::CStr;
|
||||
use libc::{self, c_int};
|
||||
use str;
|
||||
|
||||
pub use sys::cloudabi::shims::os::*;
|
||||
|
||||
pub fn errno() -> i32 {
|
||||
extern "C" {
|
||||
#[thread_local]
|
||||
static errno: c_int;
|
||||
}
|
||||
|
||||
unsafe { errno as i32 }
|
||||
}
|
||||
|
||||
/// Gets a detailed string description for the given error number.
|
||||
pub fn error_string(errno: i32) -> String {
|
||||
// cloudlibc's strerror() is guaranteed to be thread-safe. There is
|
||||
// thus no need to use strerror_r().
|
||||
str::from_utf8(unsafe { CStr::from_ptr(libc::strerror(errno)) }.to_bytes())
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
unsafe { libc::exit(code as c_int) }
|
||||
}
|
237
src/libstd/sys/cloudabi/rwlock.rs
Normal file
237
src/libstd/sys/cloudabi/rwlock.rs
Normal file
|
@ -0,0 +1,237 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use cell::UnsafeCell;
|
||||
use mem;
|
||||
use sync::atomic::{AtomicU32, Ordering};
|
||||
use sys::cloudabi::abi;
|
||||
|
||||
extern "C" {
|
||||
#[thread_local]
|
||||
static __pthread_thread_id: abi::tid;
|
||||
}
|
||||
|
||||
#[thread_local]
|
||||
static mut RDLOCKS_ACQUIRED: u32 = 0;
|
||||
|
||||
pub struct RWLock {
|
||||
lock: UnsafeCell<AtomicU32>,
|
||||
}
|
||||
|
||||
pub unsafe fn raw(r: &RWLock) -> *mut AtomicU32 {
|
||||
r.lock.get()
|
||||
}
|
||||
|
||||
unsafe impl Send for RWLock {}
|
||||
unsafe impl Sync for RWLock {}
|
||||
|
||||
impl RWLock {
|
||||
pub const fn new() -> RWLock {
|
||||
RWLock {
|
||||
lock: UnsafeCell::new(AtomicU32::new(abi::LOCK_UNLOCKED.0)),
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn try_read(&self) -> bool {
|
||||
let lock = self.lock.get();
|
||||
let mut old = abi::LOCK_UNLOCKED.0;
|
||||
while let Err(cur) =
|
||||
(*lock).compare_exchange_weak(old, old + 1, Ordering::Acquire, Ordering::Relaxed)
|
||||
{
|
||||
if (cur & abi::LOCK_WRLOCKED.0) != 0 {
|
||||
// Another thread already has a write lock.
|
||||
assert_ne!(
|
||||
old & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
"Attempted to acquire a read lock while holding a write lock"
|
||||
);
|
||||
return false;
|
||||
} else if (old & abi::LOCK_KERNEL_MANAGED.0) != 0 && RDLOCKS_ACQUIRED == 0 {
|
||||
// Lock has threads waiting for the lock. Only acquire
|
||||
// the lock if we have already acquired read locks. In
|
||||
// that case, it is justified to acquire this lock to
|
||||
// prevent a deadlock.
|
||||
return false;
|
||||
}
|
||||
old = cur;
|
||||
}
|
||||
|
||||
RDLOCKS_ACQUIRED += 1;
|
||||
true
|
||||
}
|
||||
|
||||
pub unsafe fn read(&self) {
|
||||
if !self.try_read() {
|
||||
// Call into the kernel to acquire a read lock.
|
||||
let lock = self.lock.get();
|
||||
let subscription = abi::subscription {
|
||||
type_: abi::eventtype::LOCK_RDLOCK,
|
||||
union: abi::subscription_union {
|
||||
lock: abi::subscription_lock {
|
||||
lock: lock as *mut abi::lock,
|
||||
lock_scope: abi::scope::PRIVATE,
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
};
|
||||
let mut event: abi::event = mem::uninitialized();
|
||||
let mut nevents: usize = mem::uninitialized();
|
||||
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to acquire read lock");
|
||||
assert_eq!(
|
||||
event.error,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to acquire read lock"
|
||||
);
|
||||
|
||||
RDLOCKS_ACQUIRED += 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn read_unlock(&self) {
|
||||
// Perform a read unlock. We can do this in userspace, except when
|
||||
// other threads are blocked and we are performing the last unlock.
|
||||
// In that case, call into the kernel.
|
||||
//
|
||||
// Other threads may attempt to increment the read lock count,
|
||||
// meaning that the call into the kernel could be spurious. To
|
||||
// prevent this from happening, upgrade to a write lock first. This
|
||||
// allows us to call into the kernel, having the guarantee that the
|
||||
// lock value will not change in the meantime.
|
||||
assert!(RDLOCKS_ACQUIRED > 0, "Bad lock count");
|
||||
let mut old = 1;
|
||||
loop {
|
||||
let lock = self.lock.get();
|
||||
if old == 1 | abi::LOCK_KERNEL_MANAGED.0 {
|
||||
// Last read lock while threads are waiting. Attempt to upgrade
|
||||
// to a write lock before calling into the kernel to unlock.
|
||||
if let Err(cur) = (*lock).compare_exchange_weak(
|
||||
old,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0 | abi::LOCK_KERNEL_MANAGED.0,
|
||||
Ordering::Acquire,
|
||||
Ordering::Relaxed,
|
||||
) {
|
||||
old = cur;
|
||||
} else {
|
||||
// Call into the kernel to unlock.
|
||||
let ret = abi::lock_unlock(lock as *mut abi::lock, abi::scope::PRIVATE);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to write unlock a rwlock");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No threads waiting or not the last read lock. Just decrement
|
||||
// the read lock count.
|
||||
assert_ne!(
|
||||
old & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
0,
|
||||
"This rwlock is not locked"
|
||||
);
|
||||
assert_eq!(
|
||||
old & abi::LOCK_WRLOCKED.0,
|
||||
0,
|
||||
"Attempted to read-unlock a write-locked rwlock"
|
||||
);
|
||||
if let Err(cur) = (*lock).compare_exchange_weak(
|
||||
old,
|
||||
old - 1,
|
||||
Ordering::Acquire,
|
||||
Ordering::Relaxed,
|
||||
) {
|
||||
old = cur;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RDLOCKS_ACQUIRED -= 1;
|
||||
}
|
||||
|
||||
pub unsafe fn try_write(&self) -> bool {
|
||||
// Attempt to acquire the lock.
|
||||
let lock = self.lock.get();
|
||||
if let Err(old) = (*lock).compare_exchange(
|
||||
abi::LOCK_UNLOCKED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
Ordering::Acquire,
|
||||
Ordering::Relaxed,
|
||||
) {
|
||||
// Failure. Crash upon recursive acquisition.
|
||||
assert_ne!(
|
||||
old & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
"Attempted to recursive write-lock a rwlock",
|
||||
);
|
||||
false
|
||||
} else {
|
||||
// Success.
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn write(&self) {
|
||||
if !self.try_write() {
|
||||
// Call into the kernel to acquire a write lock.
|
||||
let lock = self.lock.get();
|
||||
let subscription = abi::subscription {
|
||||
type_: abi::eventtype::LOCK_WRLOCK,
|
||||
union: abi::subscription_union {
|
||||
lock: abi::subscription_lock {
|
||||
lock: lock as *mut abi::lock,
|
||||
lock_scope: abi::scope::PRIVATE,
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
};
|
||||
let mut event: abi::event = mem::uninitialized();
|
||||
let mut nevents: usize = mem::uninitialized();
|
||||
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to acquire write lock");
|
||||
assert_eq!(
|
||||
event.error,
|
||||
abi::errno::SUCCESS,
|
||||
"Failed to acquire write lock"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn write_unlock(&self) {
|
||||
let lock = self.lock.get();
|
||||
assert_eq!(
|
||||
(*lock).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
"This rwlock is not write-locked by this thread"
|
||||
);
|
||||
|
||||
if !(*lock)
|
||||
.compare_exchange(
|
||||
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
|
||||
abi::LOCK_UNLOCKED.0,
|
||||
Ordering::Release,
|
||||
Ordering::Relaxed,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
// Lock is managed by kernelspace. Call into the kernel
|
||||
// to unblock waiting threads.
|
||||
let ret = abi::lock_unlock(lock as *mut abi::lock, abi::scope::PRIVATE);
|
||||
assert_eq!(ret, abi::errno::SUCCESS, "Failed to write unlock a rwlock");
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn destroy(&self) {
|
||||
let lock = self.lock.get();
|
||||
assert_eq!(
|
||||
(*lock).load(Ordering::Relaxed),
|
||||
abi::LOCK_UNLOCKED.0,
|
||||
"Attempted to destroy locked rwlock"
|
||||
);
|
||||
}
|
||||
}
|
45
src/libstd/sys/cloudabi/shims/args.rs
Normal file
45
src/libstd/sys/cloudabi/shims/args.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use ffi::OsString;
|
||||
|
||||
pub struct Args(());
|
||||
|
||||
impl Args {
|
||||
pub fn inner_debug(&self) -> &[OsString] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for Args {
|
||||
type Item = OsString;
|
||||
fn next(&mut self) -> Option<OsString> {
|
||||
None
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl ExactSizeIterator for Args {
|
||||
fn len(&self) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl DoubleEndedIterator for Args {
|
||||
fn next_back(&mut self) -> Option<OsString> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn args() -> Args {
|
||||
Args(())
|
||||
}
|
19
src/libstd/sys/cloudabi/shims/env.rs
Normal file
19
src/libstd/sys/cloudabi/shims/env.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
pub mod os {
|
||||
pub const FAMILY: &'static str = "cloudabi";
|
||||
pub const OS: &'static str = "cloudabi";
|
||||
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 = "";
|
||||
}
|
302
src/libstd/sys/cloudabi/shims/fs.rs
Normal file
302
src/libstd/sys/cloudabi/shims/fs.rs
Normal file
|
@ -0,0 +1,302 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
use ffi::OsString;
|
||||
use fmt;
|
||||
use hash::{Hash, Hasher};
|
||||
use io::{self, SeekFrom};
|
||||
use path::{Path, PathBuf};
|
||||
use sys::time::SystemTime;
|
||||
use sys::{unsupported, Void};
|
||||
|
||||
pub struct File(Void);
|
||||
|
||||
pub struct FileAttr(Void);
|
||||
|
||||
pub struct ReadDir(Void);
|
||||
|
||||
pub struct DirEntry(Void);
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OpenOptions {}
|
||||
|
||||
pub struct FilePermissions(Void);
|
||||
|
||||
pub struct FileType(Void);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DirBuilder {}
|
||||
|
||||
impl FileAttr {
|
||||
pub fn size(&self) -> u64 {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn perm(&self) -> FilePermissions {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn file_type(&self) -> FileType {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn modified(&self) -> io::Result<SystemTime> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn accessed(&self) -> io::Result<SystemTime> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn created(&self) -> io::Result<SystemTime> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for FileAttr {
|
||||
fn clone(&self) -> FileAttr {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl FilePermissions {
|
||||
pub fn readonly(&self) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_readonly(&mut self, _readonly: bool) {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for FilePermissions {
|
||||
fn clone(&self) -> FilePermissions {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for FilePermissions {
|
||||
fn eq(&self, _other: &FilePermissions) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for FilePermissions {}
|
||||
|
||||
impl fmt::Debug for FilePermissions {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl FileType {
|
||||
pub fn is_dir(&self) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn is_file(&self) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn is_symlink(&self) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for FileType {
|
||||
fn clone(&self) -> FileType {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Copy for FileType {}
|
||||
|
||||
impl PartialEq for FileType {
|
||||
fn eq(&self, _other: &FileType) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for FileType {}
|
||||
|
||||
impl Hash for FileType {
|
||||
fn hash<H: Hasher>(&self, _h: &mut H) {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for FileType {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ReadDir {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Iterator for ReadDir {
|
||||
type Item = io::Result<DirEntry>;
|
||||
|
||||
fn next(&mut self) -> Option<io::Result<DirEntry>> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl DirEntry {
|
||||
pub fn path(&self) -> PathBuf {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn file_name(&self) -> OsString {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> io::Result<FileAttr> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn file_type(&self) -> io::Result<FileType> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
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) {}
|
||||
}
|
||||
|
||||
impl File {
|
||||
pub fn open(_path: &Path, _opts: &OpenOptions) -> io::Result<File> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn file_attr(&self) -> io::Result<FileAttr> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn fsync(&self) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn datasync(&self) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn truncate(&self, _size: u64) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn read(&self, _buf: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn flush(&self) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn seek(&self, _pos: SeekFrom) -> io::Result<u64> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn duplicate(&self) -> io::Result<File> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_permissions(&self, _perm: FilePermissions) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn diverge(&self) -> ! {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl DirBuilder {
|
||||
pub fn new() -> DirBuilder {
|
||||
DirBuilder {}
|
||||
}
|
||||
|
||||
pub fn mkdir(&self, _p: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for File {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn readdir(_p: &Path) -> io::Result<ReadDir> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn unlink(_p: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> {
|
||||
match perm.0 {}
|
||||
}
|
||||
|
||||
pub fn rmdir(_p: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn remove_dir_all(_path: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn readlink(_p: &Path) -> io::Result<PathBuf> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn stat(_p: &Path) -> io::Result<FileAttr> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn lstat(_p: &Path) -> io::Result<FileAttr> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn copy(_from: &Path, _to: &Path) -> io::Result<u64> {
|
||||
unsupported()
|
||||
}
|
32
src/libstd/sys/cloudabi/shims/mod.rs
Normal file
32
src/libstd/sys/cloudabi/shims/mod.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use io;
|
||||
|
||||
pub mod args;
|
||||
pub mod env;
|
||||
pub mod fs;
|
||||
pub mod net;
|
||||
#[path = "../../unix/path.rs"]
|
||||
pub mod path;
|
||||
pub mod pipe;
|
||||
pub mod process;
|
||||
pub mod os;
|
||||
|
||||
// This enum is used as the storage for a bunch of types which can't actually exist.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
pub enum Void {}
|
||||
|
||||
pub fn unsupported<T>() -> io::Result<T> {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"This function is not available on CloudABI.",
|
||||
))
|
||||
}
|
296
src/libstd/sys/cloudabi/shims/net.rs
Normal file
296
src/libstd/sys/cloudabi/shims/net.rs
Normal file
|
@ -0,0 +1,296 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
use fmt;
|
||||
use io;
|
||||
use net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
|
||||
use time::Duration;
|
||||
use sys::{unsupported, Void};
|
||||
|
||||
pub extern crate libc as netc;
|
||||
|
||||
pub struct TcpStream(Void);
|
||||
|
||||
impl TcpStream {
|
||||
pub fn connect(_: &SocketAddr) -> io::Result<TcpStream> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn write(&self, _: &[u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn duplicate(&self) -> io::Result<TcpStream> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn nodelay(&self) -> io::Result<bool> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_ttl(&self, _: u32) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn ttl(&self) -> io::Result<u32> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpStream {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TcpListener(Void);
|
||||
|
||||
impl TcpListener {
|
||||
pub fn bind(_: &SocketAddr) -> io::Result<TcpListener> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn duplicate(&self) -> io::Result<TcpListener> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_ttl(&self, _: u32) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn ttl(&self) -> io::Result<u32> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn only_v6(&self) -> io::Result<bool> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpListener {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UdpSocket(Void);
|
||||
|
||||
impl UdpSocket {
|
||||
pub fn bind(_: &SocketAddr) -> io::Result<UdpSocket> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn duplicate(&self) -> io::Result<UdpSocket> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn broadcast(&self) -> io::Result<bool> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn multicast_loop_v4(&self) -> io::Result<bool> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn multicast_loop_v6(&self) -> io::Result<bool> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_ttl(&self, _: u32) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn ttl(&self) -> io::Result<u32> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn send(&self, _: &[u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn connect(&self, _: &SocketAddr) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for UdpSocket {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LookupHost(Void);
|
||||
|
||||
impl Iterator for LookupHost {
|
||||
type Item = SocketAddr;
|
||||
fn next(&mut self) -> Option<SocketAddr> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup_host(_: &str) -> io::Result<LookupHost> {
|
||||
unsupported()
|
||||
}
|
95
src/libstd/sys/cloudabi/shims/os.rs
Normal file
95
src/libstd/sys/cloudabi/shims/os.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use error::Error as StdError;
|
||||
use ffi::{OsStr, OsString};
|
||||
use fmt;
|
||||
use io;
|
||||
use iter;
|
||||
use path::{self, PathBuf};
|
||||
use sys::{unsupported, Void};
|
||||
|
||||
pub fn getcwd() -> io::Result<PathBuf> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn chdir(_: &path::Path) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub type Env = iter::Empty<(OsString, OsString)>;
|
||||
|
||||
pub fn env() -> Env {
|
||||
iter::empty()
|
||||
}
|
||||
|
||||
pub fn getenv(_: &OsStr) -> io::Result<Option<OsString>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn unsetenv(_: &OsStr) -> io::Result<()> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub struct SplitPaths<'a>(&'a Void);
|
||||
|
||||
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths {
|
||||
panic!("unsupported")
|
||||
}
|
||||
|
||||
impl<'a> Iterator for SplitPaths<'a> {
|
||||
type Item = PathBuf;
|
||||
fn next(&mut self) -> Option<PathBuf> {
|
||||
match *self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct JoinPathsError;
|
||||
|
||||
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
T: AsRef<OsStr>,
|
||||
{
|
||||
Err(JoinPathsError)
|
||||
}
|
||||
|
||||
impl fmt::Display for JoinPathsError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
"not supported on CloudABI yet".fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl StdError for JoinPathsError {
|
||||
fn description(&self) -> &str {
|
||||
"not supported on CloudABI yet"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn temp_dir() -> PathBuf {
|
||||
PathBuf::from("/tmp")
|
||||
}
|
||||
|
||||
pub fn current_exe() -> io::Result<PathBuf> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
1
|
||||
}
|
32
src/libstd/sys/cloudabi/shims/pipe.rs
Normal file
32
src/libstd/sys/cloudabi/shims/pipe.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
use io;
|
||||
use sys::Void;
|
||||
|
||||
pub struct AnonPipe(Void);
|
||||
|
||||
impl AnonPipe {
|
||||
pub fn read(&self, _buf: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn diverge(&self) -> ! {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read2(p1: AnonPipe, _v1: &mut Vec<u8>, _p2: AnonPipe, _v2: &mut Vec<u8>) -> io::Result<()> {
|
||||
match p1.0 {}
|
||||
}
|
147
src/libstd/sys/cloudabi/shims/process.rs
Normal file
147
src/libstd/sys/cloudabi/shims/process.rs
Normal file
|
@ -0,0 +1,147 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
use ffi::OsStr;
|
||||
use fmt;
|
||||
use io;
|
||||
use sys::fs::File;
|
||||
use sys::pipe::AnonPipe;
|
||||
use sys::{unsupported, Void};
|
||||
use sys_common::process::{CommandEnv, DefaultEnvKey};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Command
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct Command {
|
||||
env: CommandEnv<DefaultEnvKey>,
|
||||
}
|
||||
|
||||
// passed back to std::process with the pipes connected to the child, if any
|
||||
// were requested
|
||||
pub struct StdioPipes {
|
||||
pub stdin: Option<AnonPipe>,
|
||||
pub stdout: Option<AnonPipe>,
|
||||
pub stderr: Option<AnonPipe>,
|
||||
}
|
||||
|
||||
pub enum Stdio {
|
||||
Inherit,
|
||||
Null,
|
||||
MakePipe,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn new(_program: &OsStr) -> Command {
|
||||
Command {
|
||||
env: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arg(&mut self, _arg: &OsStr) {}
|
||||
|
||||
pub fn env_mut(&mut self) -> &mut CommandEnv<DefaultEnvKey> {
|
||||
&mut self.env
|
||||
}
|
||||
|
||||
pub fn cwd(&mut self, _dir: &OsStr) {}
|
||||
|
||||
pub fn stdin(&mut self, _stdin: Stdio) {}
|
||||
|
||||
pub fn stdout(&mut self, _stdout: Stdio) {}
|
||||
|
||||
pub fn stderr(&mut self, _stderr: Stdio) {}
|
||||
|
||||
pub fn spawn(
|
||||
&mut self,
|
||||
_default: Stdio,
|
||||
_needs_stdin: bool,
|
||||
) -> io::Result<(Process, StdioPipes)> {
|
||||
unsupported()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AnonPipe> for Stdio {
|
||||
fn from(pipe: AnonPipe) -> Stdio {
|
||||
pipe.diverge()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<File> for Stdio {
|
||||
fn from(file: File) -> Stdio {
|
||||
file.diverge()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Command {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExitStatus(Void);
|
||||
|
||||
impl ExitStatus {
|
||||
pub fn success(&self) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn code(&self) -> Option<i32> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for ExitStatus {
|
||||
fn clone(&self) -> ExitStatus {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Copy for ExitStatus {}
|
||||
|
||||
impl PartialEq for ExitStatus {
|
||||
fn eq(&self, _other: &ExitStatus) -> bool {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for ExitStatus {}
|
||||
|
||||
impl fmt::Debug for ExitStatus {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ExitStatus {
|
||||
fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Process(Void);
|
||||
|
||||
impl Process {
|
||||
pub fn id(&self) -> u32 {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn kill(&mut self) -> io::Result<()> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn wait(&mut self) -> io::Result<ExitStatus> {
|
||||
match self.0 {}
|
||||
}
|
||||
|
||||
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
|
||||
match self.0 {}
|
||||
}
|
||||
}
|
23
src/libstd/sys/cloudabi/stack_overflow.rs
Normal file
23
src/libstd/sys/cloudabi/stack_overflow.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
#![cfg_attr(test, allow(dead_code))]
|
||||
|
||||
pub struct Handler;
|
||||
|
||||
impl Handler {
|
||||
pub unsafe fn new() -> Handler {
|
||||
Handler
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn init() {}
|
||||
|
||||
pub unsafe fn cleanup() {}
|
79
src/libstd/sys/cloudabi/stdio.rs
Normal file
79
src/libstd/sys/cloudabi/stdio.rs
Normal file
|
@ -0,0 +1,79 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use io;
|
||||
use sys::cloudabi::abi;
|
||||
|
||||
pub struct Stdin(());
|
||||
pub struct Stdout(());
|
||||
pub struct Stderr(());
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin(()))
|
||||
}
|
||||
|
||||
pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout(()))
|
||||
}
|
||||
|
||||
pub fn write(&self, _: &[u8]) -> io::Result<usize> {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::BrokenPipe,
|
||||
"Stdout is not connected to any output in this environment",
|
||||
))
|
||||
}
|
||||
|
||||
pub fn flush(&self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr(()))
|
||||
}
|
||||
|
||||
pub fn write(&self, _: &[u8]) -> io::Result<usize> {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::BrokenPipe,
|
||||
"Stderr is not connected to any output in this environment",
|
||||
))
|
||||
}
|
||||
|
||||
pub fn flush(&self) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// 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<usize> {
|
||||
Stderr::write(self, data)
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
Stderr::flush(self)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
err.raw_os_error() == Some(abi::errno::BADF as i32)
|
||||
}
|
||||
|
||||
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
|
124
src/libstd/sys/cloudabi/thread.rs
Normal file
124
src/libstd/sys/cloudabi/thread.rs
Normal file
|
@ -0,0 +1,124 @@
|
|||
// Copyright 2014-2018 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.
|
||||
|
||||
use alloc::boxed::FnBox;
|
||||
use cmp;
|
||||
use ffi::CStr;
|
||||
use io;
|
||||
use libc;
|
||||
use mem;
|
||||
use ptr;
|
||||
use sys::cloudabi::abi;
|
||||
use sys::time::dur2intervals;
|
||||
use sys_common::thread::*;
|
||||
use time::Duration;
|
||||
|
||||
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
|
||||
|
||||
pub struct Thread {
|
||||
id: libc::pthread_t,
|
||||
}
|
||||
|
||||
// CloudABI has pthread_t as a pointer in which case we still want
|
||||
// a thread to be Send/Sync
|
||||
unsafe impl Send for Thread {}
|
||||
unsafe impl Sync for Thread {}
|
||||
|
||||
impl Thread {
|
||||
pub unsafe fn new<'a>(stack: usize, p: Box<FnBox() + 'a>) -> io::Result<Thread> {
|
||||
let p = box p;
|
||||
let mut native: libc::pthread_t = mem::zeroed();
|
||||
let mut attr: libc::pthread_attr_t = mem::zeroed();
|
||||
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
|
||||
|
||||
let stack_size = cmp::max(stack, min_stack_size(&attr));
|
||||
assert_eq!(libc::pthread_attr_setstacksize(&mut attr, stack_size), 0);
|
||||
|
||||
let ret = libc::pthread_create(&mut native, &attr, thread_start, &*p as *const _ as *mut _);
|
||||
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
|
||||
|
||||
return if ret != 0 {
|
||||
Err(io::Error::from_raw_os_error(ret))
|
||||
} else {
|
||||
mem::forget(p); // ownership passed to pthread_create
|
||||
Ok(Thread { id: native })
|
||||
};
|
||||
|
||||
extern "C" fn thread_start(main: *mut libc::c_void) -> *mut libc::c_void {
|
||||
unsafe {
|
||||
start_thread(main as *mut u8);
|
||||
}
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn yield_now() {
|
||||
let ret = unsafe { abi::thread_yield() };
|
||||
debug_assert_eq!(ret, abi::errno::SUCCESS);
|
||||
}
|
||||
|
||||
pub fn set_name(_name: &CStr) {
|
||||
// CloudABI has no way to set a thread name.
|
||||
}
|
||||
|
||||
pub fn sleep(dur: Duration) {
|
||||
unsafe {
|
||||
let subscription = abi::subscription {
|
||||
type_: abi::eventtype::CLOCK,
|
||||
union: abi::subscription_union {
|
||||
clock: abi::subscription_clock {
|
||||
clock_id: abi::clockid::MONOTONIC,
|
||||
timeout: dur2intervals(&dur),
|
||||
..mem::zeroed()
|
||||
},
|
||||
},
|
||||
..mem::zeroed()
|
||||
};
|
||||
let mut event: abi::event = mem::uninitialized();
|
||||
let mut nevents: usize = mem::uninitialized();
|
||||
let ret = abi::poll(&subscription, &mut event, 1, &mut nevents);
|
||||
assert_eq!(ret, abi::errno::SUCCESS);
|
||||
assert_eq!(event.error, abi::errno::SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join(self) {
|
||||
unsafe {
|
||||
let ret = libc::pthread_join(self.id, ptr::null_mut());
|
||||
mem::forget(self);
|
||||
assert!(
|
||||
ret == 0,
|
||||
"failed to join thread: {}",
|
||||
io::Error::from_raw_os_error(ret)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Thread {
|
||||
fn drop(&mut self) {
|
||||
let ret = unsafe { libc::pthread_detach(self.id) };
|
||||
debug_assert_eq!(ret, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
pub mod guard {
|
||||
pub unsafe fn current() -> Option<usize> {
|
||||
None
|
||||
}
|
||||
pub unsafe fn init() -> Option<usize> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn min_stack_size(_: *const libc::pthread_attr_t) -> usize {
|
||||
libc::PTHREAD_STACK_MIN
|
||||
}
|
111
src/libstd/sys/cloudabi/time.rs
Normal file
111
src/libstd/sys/cloudabi/time.rs
Normal file
|
@ -0,0 +1,111 @@
|
|||
// Copyright 2018 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.
|
||||
|
||||
use mem;
|
||||
use sys::cloudabi::abi;
|
||||
use time::Duration;
|
||||
|
||||
const NSEC_PER_SEC: abi::timestamp = 1_000_000_000;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
pub struct Instant {
|
||||
t: abi::timestamp,
|
||||
}
|
||||
|
||||
pub fn dur2intervals(dur: &Duration) -> abi::timestamp {
|
||||
dur.as_secs()
|
||||
.checked_mul(NSEC_PER_SEC)
|
||||
.and_then(|nanos| nanos.checked_add(dur.subsec_nanos() as abi::timestamp))
|
||||
.expect("overflow converting duration to nanoseconds")
|
||||
}
|
||||
|
||||
impl Instant {
|
||||
pub fn now() -> Instant {
|
||||
unsafe {
|
||||
let mut t = mem::uninitialized();
|
||||
let ret = abi::clock_time_get(abi::clockid::MONOTONIC, 0, &mut t);
|
||||
assert_eq!(ret, abi::errno::SUCCESS);
|
||||
Instant { t: t }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
||||
let diff = self.t
|
||||
.checked_sub(other.t)
|
||||
.expect("second instant is later than self");
|
||||
Duration::new(diff / NSEC_PER_SEC, (diff % NSEC_PER_SEC) as u32)
|
||||
}
|
||||
|
||||
pub fn add_duration(&self, other: &Duration) -> Instant {
|
||||
Instant {
|
||||
t: self.t
|
||||
.checked_add(dur2intervals(other))
|
||||
.expect("overflow when adding duration to instant"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sub_duration(&self, other: &Duration) -> Instant {
|
||||
Instant {
|
||||
t: self.t
|
||||
.checked_sub(dur2intervals(other))
|
||||
.expect("overflow when subtracting duration from instant"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
pub struct SystemTime {
|
||||
t: abi::timestamp,
|
||||
}
|
||||
|
||||
impl SystemTime {
|
||||
pub fn now() -> SystemTime {
|
||||
unsafe {
|
||||
let mut t = mem::uninitialized();
|
||||
let ret = abi::clock_time_get(abi::clockid::REALTIME, 0, &mut t);
|
||||
assert_eq!(ret, abi::errno::SUCCESS);
|
||||
SystemTime { t: t }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
|
||||
if self.t >= other.t {
|
||||
let diff = self.t - other.t;
|
||||
Ok(Duration::new(
|
||||
diff / NSEC_PER_SEC,
|
||||
(diff % NSEC_PER_SEC) as u32,
|
||||
))
|
||||
} else {
|
||||
let diff = other.t - self.t;
|
||||
Err(Duration::new(
|
||||
diff / NSEC_PER_SEC,
|
||||
(diff % NSEC_PER_SEC) as u32,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_duration(&self, other: &Duration) -> SystemTime {
|
||||
SystemTime {
|
||||
t: self.t
|
||||
.checked_add(dur2intervals(other))
|
||||
.expect("overflow when adding duration to instant"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sub_duration(&self, other: &Duration) -> SystemTime {
|
||||
SystemTime {
|
||||
t: self.t
|
||||
.checked_sub(dur2intervals(other))
|
||||
.expect("overflow when subtracting duration from instant"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const UNIX_EPOCH: SystemTime = SystemTime { t: 0 };
|
|
@ -39,6 +39,9 @@ cfg_if! {
|
|||
} else if #[cfg(windows)] {
|
||||
mod windows;
|
||||
pub use self::windows::*;
|
||||
} else if #[cfg(target_os = "cloudabi")] {
|
||||
mod cloudabi;
|
||||
pub use self::cloudabi::*;
|
||||
} else if #[cfg(target_os = "redox")] {
|
||||
mod redox;
|
||||
pub use self::redox::*;
|
||||
|
@ -59,9 +62,10 @@ cfg_if! {
|
|||
if #[cfg(any(unix, target_os = "redox"))] {
|
||||
// On unix we'll document what's already available
|
||||
pub use self::ext as unix_ext;
|
||||
} else if #[cfg(target_arch = "wasm32")] {
|
||||
// On wasm right now the module below doesn't compile (missing things
|
||||
// in `libc` which is empty) so just omit everything with an empty module
|
||||
} else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
|
||||
// On CloudABI and wasm right now the module below doesn't compile
|
||||
// (missing things in `libc` which is empty) so just omit everything
|
||||
// with an empty module
|
||||
#[unstable(issue = "0", feature = "std_internals")]
|
||||
pub mod unix_ext {}
|
||||
} else {
|
||||
|
@ -77,8 +81,9 @@ cfg_if! {
|
|||
if #[cfg(windows)] {
|
||||
// On windows we'll just be documenting what's already available
|
||||
pub use self::ext as windows_ext;
|
||||
} else if #[cfg(target_arch = "wasm32")] {
|
||||
// On wasm right now the shim below doesn't compile, so just omit it
|
||||
} else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
|
||||
// On CloudABI and wasm right now the shim below doesn't compile, so
|
||||
// just omit it
|
||||
#[unstable(issue = "0", feature = "std_internals")]
|
||||
pub mod windows_ext {}
|
||||
} else {
|
||||
|
|
|
@ -46,7 +46,7 @@ pub mod bytestring;
|
|||
pub mod process;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(any(target_os = "redox", target_os = "l4re"))] {
|
||||
if #[cfg(any(target_os = "cloudabi", target_os = "l4re", target_os = "redox"))] {
|
||||
pub use sys::net;
|
||||
} else if #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] {
|
||||
pub use sys::net;
|
||||
|
|
|
@ -168,8 +168,8 @@ fn find_test_mod(contents: &str) -> usize {
|
|||
let prev_newline_idx = contents[..prev_newline_idx].rfind('\n');
|
||||
if let Some(nl) = prev_newline_idx {
|
||||
let prev_line = &contents[nl + 1 .. mod_tests_idx];
|
||||
let emcc_cfg = "cfg(all(test, not(target_os";
|
||||
if prev_line.contains(emcc_cfg) {
|
||||
if prev_line.contains("cfg(all(test, not(target_os")
|
||||
|| prev_line.contains("cfg(all(test, not(any(target_os") {
|
||||
nl
|
||||
} else {
|
||||
mod_tests_idx
|
||||
|
|
Loading…
Add table
Reference in a new issue