]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys/wasm/mod.rs
New upstream version 1.45.0+dfsg1
[rustc.git] / src / libstd / sys / wasm / mod.rs
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
17 use crate::os::raw::c_char;
18
19 pub mod alloc;
20 pub mod args;
21 pub mod cmath;
22 pub mod env;
23 pub mod fast_thread_local;
24 pub mod fs;
25 pub mod io;
26 pub mod memchr;
27 pub mod net;
28 pub mod os;
29 pub mod path;
30 pub mod pipe;
31 pub mod process;
32 pub mod stack_overflow;
33 pub mod stdio;
34 pub mod thread;
35 pub mod thread_local;
36 pub mod time;
37
38 pub use crate::sys_common::os_str_bytes as os_str;
39
40 cfg_if::cfg_if! {
41 if #[cfg(target_feature = "atomics")] {
42 #[path = "condvar_atomics.rs"]
43 pub mod condvar;
44 #[path = "mutex_atomics.rs"]
45 pub mod mutex;
46 #[path = "rwlock_atomics.rs"]
47 pub mod rwlock;
48 } else {
49 pub mod condvar;
50 pub mod mutex;
51 pub mod rwlock;
52 }
53 }
54
55 #[cfg(not(test))]
56 pub fn init() {}
57
58 pub fn unsupported<T>() -> crate::io::Result<T> {
59 Err(unsupported_err())
60 }
61
62 pub fn unsupported_err() -> crate::io::Error {
63 crate::io::Error::new(crate::io::ErrorKind::Other, "operation not supported on wasm yet")
64 }
65
66 pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind {
67 crate::io::ErrorKind::Other
68 }
69
70 // This enum is used as the storage for a bunch of types which can't actually
71 // exist.
72 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
73 pub enum Void {}
74
75 pub unsafe fn strlen(mut s: *const c_char) -> usize {
76 let mut n = 0;
77 while *s != 0 {
78 n += 1;
79 s = s.offset(1);
80 }
81 return n;
82 }
83
84 pub fn abort_internal() -> ! {
85 unsafe { crate::arch::wasm32::unreachable() }
86 }
87
88 // We don't have randomness yet, but I totally used a random number generator to
89 // generate these numbers.
90 //
91 // More seriously though this is just for DOS protection in hash maps. It's ok
92 // if we don't do that on wasm just yet.
93 pub fn hashmap_random_keys() -> (u64, u64) {
94 (1, 2)
95 }