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"]
25 #[path = "../unsupported/condvar.rs"]
31 #[path = "../unsupported/mutex.rs"]
35 pub use crate::sys_common::os_str_bytes as os_str;
36 #[path = "../unix/path.rs"]
38 #[path = "../unsupported/pipe.rs"]
40 #[path = "../unsupported/process.rs"]
42 #[path = "../unsupported/rwlock.rs"]
46 #[path = "../unsupported/thread_local_dtor.rs"]
47 pub mod thread_local_dtor;
48 #[path = "../unsupported/thread_local_key.rs"]
49 pub mod thread_local_key;
52 #[path = "../unsupported/common.rs"]
53 #[deny(unsafe_op_in_unsafe_fn)]
58 pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind {
59 use std_io::ErrorKind::*;
60 if errno > u16::MAX as i32 || errno < 0 {
64 wasi::ERRNO_CONNREFUSED => ConnectionRefused,
65 wasi::ERRNO_CONNRESET => ConnectionReset,
66 wasi::ERRNO_PERM | wasi::ERRNO_ACCES => PermissionDenied,
67 wasi::ERRNO_PIPE => BrokenPipe,
68 wasi::ERRNO_NOTCONN => NotConnected,
69 wasi::ERRNO_CONNABORTED => ConnectionAborted,
70 wasi::ERRNO_ADDRNOTAVAIL => AddrNotAvailable,
71 wasi::ERRNO_ADDRINUSE => AddrInUse,
72 wasi::ERRNO_NOENT => NotFound,
73 wasi::ERRNO_INTR => Interrupted,
74 wasi::ERRNO_INVAL => InvalidInput,
75 wasi::ERRNO_TIMEDOUT => TimedOut,
76 wasi::ERRNO_EXIST => AlreadyExists,
77 wasi::ERRNO_AGAIN => WouldBlock,
78 wasi::ERRNO_NOSYS => Unsupported,
79 wasi::ERRNO_NOMEM => OutOfMemory,
84 pub fn abort_internal() -> ! {
85 unsafe { libc::abort() }
88 pub fn hashmap_random_keys() -> (u64, u64) {
89 let mut ret = (0u64, 0u64);
91 let base = &mut ret as *mut (u64, u64) as *mut u8;
92 let len = mem::size_of_val(&ret);
93 wasi::random_get(base, len).expect("random_get failure");
98 fn err2io(err: wasi::Error) -> std_io::Error {
99 std_io::Error::from_raw_os_error(err.raw_error().into())