2017-10-23 03:01:00 +00:00
|
|
|
//! System bindings for the wasm/web platform
|
|
|
|
//!
|
|
|
|
//! This module contains the facade (aka platform-specific) implementations of
|
|
|
|
//! OS level functionality for wasm. Note that this wasm is *not* the emscripten
|
|
|
|
//! wasm, so we have no runtime here.
|
|
|
|
//!
|
|
|
|
//! This is all super highly experimental and not actually intended for
|
|
|
|
//! wide/production use yet, it's still all in the experimental category. This
|
|
|
|
//! will likely change over time.
|
|
|
|
//!
|
|
|
|
//! Currently all functions here are basically stubs that immediately return
|
|
|
|
//! errors. The hope is that with a portability lint we can turn actually just
|
|
|
|
//! remove all this and just omit parts of the standard library if we're
|
|
|
|
//! compiling for wasm. That way it's a compile time error for something that's
|
|
|
|
//! guaranteed to be a runtime error!
|
|
|
|
|
2019-02-10 19:23:21 +00:00
|
|
|
use crate::os::raw::c_char;
|
2017-10-23 03:01:00 +00:00
|
|
|
|
2018-11-03 18:15:48 +00:00
|
|
|
pub mod alloc;
|
2017-10-23 03:01:00 +00:00
|
|
|
pub mod args;
|
|
|
|
pub mod cmath;
|
|
|
|
pub mod env;
|
2019-12-22 22:42:04 +00:00
|
|
|
pub mod fast_thread_local;
|
2017-10-23 03:01:00 +00:00
|
|
|
pub mod fs;
|
2019-02-08 19:42:34 +00:00
|
|
|
pub mod io;
|
2017-10-23 03:01:00 +00:00
|
|
|
pub mod memchr;
|
|
|
|
pub mod net;
|
|
|
|
pub mod os;
|
|
|
|
pub mod path;
|
|
|
|
pub mod pipe;
|
|
|
|
pub mod process;
|
|
|
|
pub mod stack_overflow;
|
|
|
|
pub mod stdio;
|
2019-12-22 22:42:04 +00:00
|
|
|
pub mod thread;
|
2019-07-19 19:02:34 +00:00
|
|
|
pub mod thread_local;
|
2019-12-22 22:42:04 +00:00
|
|
|
pub mod time;
|
2017-10-23 03:01:00 +00:00
|
|
|
|
2019-03-05 23:05:44 +00:00
|
|
|
pub use crate::sys_common::os_str_bytes as os_str;
|
|
|
|
|
2019-06-10 15:12:14 +00:00
|
|
|
cfg_if::cfg_if! {
|
2018-08-15 17:51:24 +00:00
|
|
|
if #[cfg(target_feature = "atomics")] {
|
|
|
|
#[path = "condvar_atomics.rs"]
|
|
|
|
pub mod condvar;
|
|
|
|
#[path = "mutex_atomics.rs"]
|
|
|
|
pub mod mutex;
|
|
|
|
#[path = "rwlock_atomics.rs"]
|
|
|
|
pub mod rwlock;
|
|
|
|
} else {
|
|
|
|
pub mod condvar;
|
|
|
|
pub mod mutex;
|
|
|
|
pub mod rwlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-23 03:01:00 +00:00
|
|
|
#[cfg(not(test))]
|
2019-12-22 22:42:04 +00:00
|
|
|
pub fn init() {}
|
2017-10-23 03:01:00 +00:00
|
|
|
|
2019-02-10 19:23:21 +00:00
|
|
|
pub fn unsupported<T>() -> crate::io::Result<T> {
|
2017-10-23 03:01:00 +00:00
|
|
|
Err(unsupported_err())
|
|
|
|
}
|
|
|
|
|
2019-02-10 19:23:21 +00:00
|
|
|
pub fn unsupported_err() -> crate::io::Error {
|
2019-12-22 22:42:04 +00:00
|
|
|
crate::io::Error::new(crate::io::ErrorKind::Other, "operation not supported on wasm yet")
|
2017-10-23 03:01:00 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 19:23:21 +00:00
|
|
|
pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind {
|
|
|
|
crate::io::ErrorKind::Other
|
2017-10-23 03:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 unsafe fn strlen(mut s: *const c_char) -> usize {
|
|
|
|
let mut n = 0;
|
|
|
|
while *s != 0 {
|
|
|
|
n += 1;
|
|
|
|
s = s.offset(1);
|
|
|
|
}
|
2019-12-22 22:42:04 +00:00
|
|
|
return n;
|
2017-10-23 03:01:00 +00:00
|
|
|
}
|
|
|
|
|
2020-05-17 17:37:44 +00:00
|
|
|
pub fn abort_internal() -> ! {
|
|
|
|
unsafe { crate::arch::wasm32::unreachable() }
|
2017-10-23 03:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We don't have randomness yet, but I totally used a random number generator to
|
|
|
|
// generate these numbers.
|
|
|
|
//
|
|
|
|
// More seriously though this is just for DOS protection in hash maps. It's ok
|
|
|
|
// if we don't do that on wasm just yet.
|
|
|
|
pub fn hashmap_random_keys() -> (u64, u64) {
|
|
|
|
(1, 2)
|
|
|
|
}
|