1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! System bindings for the wasm/web platform
13 //! This module contains the facade (aka platform-specific) implementations of
14 //! OS level functionality for wasm. Note that this wasm is *not* the emscripten
15 //! wasm, so we have no runtime here.
17 //! This is all super highly experimental and not actually intended for
18 //! wide/production use yet, it's still all in the experimental category. This
19 //! will likely change over time.
21 //! Currently all functions here are basically stubs that immediately return
22 //! errors. The hope is that with a portability lint we can turn actually just
23 //! remove all this and just omit parts of the standard library if we're
24 //! compiling for wasm. That way it's a compile time error for something that's
25 //! guaranteed to be a runtime error!
30 // Right now the wasm backend doesn't even have the ability to print to the
31 // console by default. Wasm can't import anything from JS! (you have to
32 // explicitly provide it).
34 // Sometimes that's a real bummer, though, so this flag can be set to `true` to
35 // enable calling various shims defined in `src/etc/wasm32-shim.js` which should
36 // help receive debug output and see what's going on. In general this flag
37 // currently controls "will we call out to our own defined shims in node.js",
38 // and this flag should always be `false` for release builds.
39 const DEBUG: bool = false;
56 pub mod stack_overflow;
66 pub fn unsupported<T>() -> io::Result<T> {
67 Err(unsupported_err())
70 pub fn unsupported_err() -> io::Error {
71 io::Error::new(io::ErrorKind::Other,
72 "operation not supported on wasm yet")
75 pub fn decode_error_kind(_code: i32) -> io::ErrorKind {
79 // This enum is used as the storage for a bunch of types which can't actually
81 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
84 pub unsafe fn strlen(mut s: *const c_char) -> usize {
93 pub unsafe fn abort_internal() -> ! {
94 ::intrinsics::abort();
97 // We don't have randomness yet, but I totally used a random number generator to
98 // generate these numbers.
100 // More seriously though this is just for DOS protection in hash maps. It's ok
101 // if we don't do that on wasm just yet.
102 pub fn hashmap_random_keys() -> (u64, u64) {