]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys/wasi/mod.rs
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
;
19 use crate::os
::raw
::c_char
;
23 #[path = "../wasm/cmath.rs"]
25 #[path = "../wasm/condvar.rs"]
30 #[path = "../wasm/memchr.rs"]
32 #[path = "../wasm/mutex.rs"]
37 pub use crate::sys_common
::os_str_bytes
as os_str
;
41 #[path = "../wasm/rwlock.rs"]
43 #[path = "../wasm/stack_overflow.rs"]
44 pub mod stack_overflow
;
47 #[path = "../wasm/thread_local.rs"]
49 #[path = "../wasm/fast_thread_local.rs"]
50 pub mod fast_thread_local
;
58 pub fn unsupported
<T
>() -> std_io
::Result
<T
> {
59 Err(unsupported_err())
62 pub fn unsupported_err() -> std_io
::Error
{
64 std_io
::ErrorKind
::Other
,
65 "operation not supported on wasm yet",
69 pub fn decode_error_kind(errno
: i32) -> std_io
::ErrorKind
{
70 use std_io
::ErrorKind
::*;
71 if errno
> u16::max_value() as i32 || errno
< 0 {
75 wasi
::ERRNO_CONNREFUSED
=> ConnectionRefused
,
76 wasi
::ERRNO_CONNRESET
=> ConnectionReset
,
77 wasi
::ERRNO_PERM
| wasi
::ERRNO_ACCES
=> PermissionDenied
,
78 wasi
::ERRNO_PIPE
=> BrokenPipe
,
79 wasi
::ERRNO_NOTCONN
=> NotConnected
,
80 wasi
::ERRNO_CONNABORTED
=> ConnectionAborted
,
81 wasi
::ERRNO_ADDRNOTAVAIL
=> AddrNotAvailable
,
82 wasi
::ERRNO_ADDRINUSE
=> AddrInUse
,
83 wasi
::ERRNO_NOENT
=> NotFound
,
84 wasi
::ERRNO_INTR
=> Interrupted
,
85 wasi
::ERRNO_INVAL
=> InvalidInput
,
86 wasi
::ERRNO_TIMEDOUT
=> TimedOut
,
87 wasi
::ERRNO_EXIST
=> AlreadyExists
,
88 wasi
::ERRNO_AGAIN
=> WouldBlock
,
93 // This enum is used as the storage for a bunch of types which can't actually
95 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
98 pub unsafe fn strlen(mut s
: *const c_char
) -> usize {
107 pub unsafe fn abort_internal() -> ! {
111 pub fn hashmap_random_keys() -> (u64, u64) {
112 let mut ret
= (0u64, 0u64);
114 let base
= &mut ret
as *mut (u64, u64) as *mut u8;
115 let len
= mem
::size_of_val(&ret
);
116 wasi
::random_get(base
, len
).expect("random_get failure");
121 fn err2io(err
: wasi
::Error
) -> std_io
::Error
{
122 std_io
::Error
::from_raw_os_error(err
.raw_error().into())