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!
17 use crate::io as std_io;
20 #[path = "../unix/alloc.rs"]
23 #[path = "../unix/cmath.rs"]
29 #[path = "../wasm/atomics/futex.rs"]
32 #[path = "../unsupported/locks/mod.rs"]
35 #[path = "../unsupported/once.rs"]
38 #[path = "../unix/os_str.rs"]
40 #[path = "../unix/path.rs"]
42 #[path = "../unsupported/pipe.rs"]
44 #[path = "../unsupported/process.rs"]
48 #[path = "../unsupported/thread_local_dtor.rs"]
49 pub mod thread_local_dtor;
50 #[path = "../unsupported/thread_local_key.rs"]
51 pub mod thread_local_key;
54 #[path = "../unsupported/common.rs"]
55 #[deny(unsafe_op_in_unsafe_fn)]
60 pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
61 use std_io::ErrorKind::*;
62 if errno > u16::MAX as i32 || errno < 0 {
67 e if e == wasi::ERRNO_CONNREFUSED.raw().into() => ConnectionRefused,
68 e if e == wasi::ERRNO_CONNRESET.raw().into() => ConnectionReset,
69 e if e == wasi::ERRNO_PERM.raw().into() || e == wasi::ERRNO_ACCES.raw().into() => {
72 e if e == wasi::ERRNO_PIPE.raw().into() => BrokenPipe,
73 e if e == wasi::ERRNO_NOTCONN.raw().into() => NotConnected,
74 e if e == wasi::ERRNO_CONNABORTED.raw().into() => ConnectionAborted,
75 e if e == wasi::ERRNO_ADDRNOTAVAIL.raw().into() => AddrNotAvailable,
76 e if e == wasi::ERRNO_ADDRINUSE.raw().into() => AddrInUse,
77 e if e == wasi::ERRNO_NOENT.raw().into() => NotFound,
78 e if e == wasi::ERRNO_INTR.raw().into() => Interrupted,
79 e if e == wasi::ERRNO_INVAL.raw().into() => InvalidInput,
80 e if e == wasi::ERRNO_TIMEDOUT.raw().into() => TimedOut,
81 e if e == wasi::ERRNO_EXIST.raw().into() => AlreadyExists,
82 e if e == wasi::ERRNO_AGAIN.raw().into() => WouldBlock,
83 e if e == wasi::ERRNO_NOSYS.raw().into() => Unsupported,
84 e if e == wasi::ERRNO_NOMEM.raw().into() => OutOfMemory,
89 pub fn abort_internal() -> ! {
90 unsafe { libc::abort() }
93 pub fn hashmap_random_keys() -> (u64, u64) {
94 let mut ret = (0u64, 0u64);
96 let base = &mut ret as *mut (u64, u64) as *mut u8;
97 let len = mem::size_of_val(&ret);
98 wasi::random_get(base, len).expect("random_get failure");
103 fn err2io(err: wasi::Errno) -> std_io::Error {
104 std_io::Error::from_raw_os_error(err.raw().into())