]>
Commit | Line | Data |
---|---|---|
532ac7d7 XL |
1 | //! System bindings for the wasm/web platform |
2 | //! | |
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. | |
6 | //! | |
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. | |
10 | //! | |
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! | |
16 | ||
e1599b0c | 17 | use crate::io as std_io; |
532ac7d7 | 18 | use crate::mem; |
532ac7d7 | 19 | |
1b1a35ee | 20 | #[path = "../unix/alloc.rs"] |
532ac7d7 XL |
21 | pub mod alloc; |
22 | pub mod args; | |
cdc7bbd5 | 23 | #[path = "../unix/cmath.rs"] |
532ac7d7 | 24 | pub mod cmath; |
3dfed10e | 25 | #[path = "../unsupported/condvar.rs"] |
532ac7d7 XL |
26 | pub mod condvar; |
27 | pub mod env; | |
28 | pub mod fd; | |
29 | pub mod fs; | |
dfeec247 | 30 | pub mod io; |
3dfed10e | 31 | #[path = "../unsupported/mutex.rs"] |
532ac7d7 XL |
32 | pub mod mutex; |
33 | pub mod net; | |
532ac7d7 | 34 | pub mod os; |
94222f64 XL |
35 | #[path = "../unix/os_str.rs"] |
36 | pub mod os_str; | |
1b1a35ee | 37 | #[path = "../unix/path.rs"] |
532ac7d7 | 38 | pub mod path; |
1b1a35ee | 39 | #[path = "../unsupported/pipe.rs"] |
532ac7d7 | 40 | pub mod pipe; |
1b1a35ee | 41 | #[path = "../unsupported/process.rs"] |
532ac7d7 | 42 | pub mod process; |
3dfed10e | 43 | #[path = "../unsupported/rwlock.rs"] |
532ac7d7 | 44 | pub mod rwlock; |
532ac7d7 XL |
45 | pub mod stdio; |
46 | pub mod thread; | |
3dfed10e XL |
47 | #[path = "../unsupported/thread_local_dtor.rs"] |
48 | pub mod thread_local_dtor; | |
49 | #[path = "../unsupported/thread_local_key.rs"] | |
50 | pub mod thread_local_key; | |
532ac7d7 | 51 | pub mod time; |
532ac7d7 | 52 | |
3dfed10e | 53 | #[path = "../unsupported/common.rs"] |
29967ef6 | 54 | #[deny(unsafe_op_in_unsafe_fn)] |
3dfed10e XL |
55 | #[allow(unused)] |
56 | mod common; | |
57 | pub use common::*; | |
532ac7d7 | 58 | |
e1599b0c XL |
59 | pub fn decode_error_kind(errno: i32) -> std_io::ErrorKind { |
60 | use std_io::ErrorKind::*; | |
f035d41b | 61 | if errno > u16::MAX as i32 || errno < 0 { |
136023e0 | 62 | return Uncategorized; |
e1599b0c | 63 | } |
60c5eb7d XL |
64 | match errno as u16 { |
65 | wasi::ERRNO_CONNREFUSED => ConnectionRefused, | |
66 | wasi::ERRNO_CONNRESET => ConnectionReset, | |
67 | wasi::ERRNO_PERM | wasi::ERRNO_ACCES => PermissionDenied, | |
68 | wasi::ERRNO_PIPE => BrokenPipe, | |
69 | wasi::ERRNO_NOTCONN => NotConnected, | |
70 | wasi::ERRNO_CONNABORTED => ConnectionAborted, | |
71 | wasi::ERRNO_ADDRNOTAVAIL => AddrNotAvailable, | |
72 | wasi::ERRNO_ADDRINUSE => AddrInUse, | |
73 | wasi::ERRNO_NOENT => NotFound, | |
74 | wasi::ERRNO_INTR => Interrupted, | |
75 | wasi::ERRNO_INVAL => InvalidInput, | |
76 | wasi::ERRNO_TIMEDOUT => TimedOut, | |
77 | wasi::ERRNO_EXIST => AlreadyExists, | |
78 | wasi::ERRNO_AGAIN => WouldBlock, | |
cdc7bbd5 | 79 | wasi::ERRNO_NOSYS => Unsupported, |
17df50a5 | 80 | wasi::ERRNO_NOMEM => OutOfMemory, |
136023e0 | 81 | _ => Uncategorized, |
e1599b0c | 82 | } |
532ac7d7 XL |
83 | } |
84 | ||
f9f354fc XL |
85 | pub fn abort_internal() -> ! { |
86 | unsafe { libc::abort() } | |
532ac7d7 XL |
87 | } |
88 | ||
89 | pub fn hashmap_random_keys() -> (u64, u64) { | |
90 | let mut ret = (0u64, 0u64); | |
91 | unsafe { | |
60c5eb7d | 92 | let base = &mut ret as *mut (u64, u64) as *mut u8; |
532ac7d7 | 93 | let len = mem::size_of_val(&ret); |
60c5eb7d | 94 | wasi::random_get(base, len).expect("random_get failure"); |
532ac7d7 | 95 | } |
dfeec247 | 96 | return ret; |
532ac7d7 XL |
97 | } |
98 | ||
e1599b0c | 99 | fn err2io(err: wasi::Error) -> std_io::Error { |
60c5eb7d | 100 | std_io::Error::from_raw_os_error(err.raw_error().into()) |
532ac7d7 | 101 | } |