1 //! System bindings for the wasm/web platform
3 //! This module contains the facade (aka platform-specific) implementations of
4 //! OS level functionality for wasm. Note that this wasm is *not* the emscripten
5 //! wasm, so we have no runtime here.
7 //! This is all super highly experimental and not actually intended for
8 //! wide/production use yet, it's still all in the experimental category. This
9 //! will likely change over time.
11 //! Currently all functions here are basically stubs that immediately return
12 //! errors. The hope is that with a portability lint we can turn actually just
13 //! remove all this and just omit parts of the standard library if we're
14 //! compiling for wasm. That way it's a compile time error for something that's
15 //! guaranteed to be a runtime error!
18 use crate::io::{Error, ErrorKind};
20 use crate::os::raw::c_char;
24 #[path = "../wasm/cmath.rs"]
26 #[path = "../wasm/condvar.rs"]
31 #[path = "../wasm/memchr.rs"]
33 #[path = "../wasm/mutex.rs"]
38 pub use crate::sys_common::os_str_bytes as os_str;
42 #[path = "../wasm/rwlock.rs"]
44 #[path = "../wasm/stack_overflow.rs"]
45 pub mod stack_overflow;
48 #[path = "../wasm/thread_local.rs"]
50 #[path = "../wasm/fast_thread_local.rs"]
51 pub mod fast_thread_local;
59 pub fn unsupported<T>() -> crate::io::Result<T> {
60 Err(unsupported_err())
63 pub fn unsupported_err() -> Error {
64 Error::new(ErrorKind::Other, "operation not supported on wasm yet")
67 pub fn decode_error_kind(_code: i32) -> ErrorKind {
71 // This enum is used as the storage for a bunch of types which can't actually
73 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
76 pub unsafe fn strlen(mut s: *const c_char) -> usize {
85 pub unsafe fn abort_internal() -> ! {
89 pub fn hashmap_random_keys() -> (u64, u64) {
90 let mut ret = (0u64, 0u64);
92 let base = &mut ret as *mut (u64, u64) as *mut libc::c_void;
93 let len = mem::size_of_val(&ret);
94 cvt_wasi(libc::__wasi_random_get(base, len)).unwrap();
100 pub trait IsMinusOne {
101 fn is_minus_one(&self) -> bool;
104 macro_rules! impl_is_minus_one {
105 ($($t:ident)*) => ($(impl IsMinusOne for $t {
106 fn is_minus_one(&self) -> bool {
112 impl_is_minus_one! { i8 i16 i32 i64 isize }
114 pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
115 if t.is_minus_one() {
116 Err(Error::last_os_error())
122 pub fn cvt_wasi(r: u16) -> crate::io::Result<()> {
123 if r != libc::__WASI_ESUCCESS {
124 Err(Error::from_raw_os_error(r as i32))