1 //! System bindings for HermitCore
3 //! This module contains the facade (aka platform-specific) implementations of
4 //! OS level functionality for HermitCore.
6 //! This is all super highly experimental and not actually intended for
7 //! wide/production use yet, it's still all in the experimental category. This
8 //! will likely change over time.
10 //! Currently all functions here are basically stubs that immediately return
11 //! errors. The hope is that with a portability lint we can turn actually just
12 //! remove all this and just omit parts of the standard library if we're
13 //! compiling for wasm. That way it's a compile time error for something that's
14 //! guaranteed to be a runtime error!
16 #![allow(unsafe_op_in_unsafe_fn)]
18 use crate::intrinsics;
19 use crate::os::raw::c_char;
35 #[path = "../unsupported/pipe.rs"]
37 #[path = "../unsupported/process.rs"]
42 pub mod thread_local_dtor;
43 pub mod thread_local_key;
46 use crate::io::ErrorKind;
47 pub use crate::sys_common::os_str_bytes as os_str;
49 #[allow(unused_extern_crates)]
50 pub extern crate hermit_abi as abi;
52 pub fn unsupported<T>() -> crate::io::Result<T> {
53 Err(unsupported_err())
56 pub fn unsupported_err() -> crate::io::Error {
57 crate::io::Error::new_const(
58 crate::io::ErrorKind::Unsupported,
59 &"operation not supported on HermitCore yet",
63 pub unsafe fn strlen(start: *const c_char) -> usize {
70 (str as usize) - (start as usize)
74 pub extern "C" fn floor(x: f64) -> f64 {
75 unsafe { intrinsics::floorf64(x) }
78 pub fn abort_internal() -> ! {
84 // FIXME: just a workaround to test the system
85 pub fn hashmap_random_keys() -> (u64, u64) {
89 // This function is needed by the panic runtime. The symbol is named in
90 // pre-link args for the target specification, so keep that in sync.
93 // NB. used by both libunwind and libpanic_abort
94 pub extern "C" fn __rust_abort() {
98 // SAFETY: must be called only once during runtime initialization.
99 // NOTE: this is not guaranteed to run, for example when Rust code is called externally.
100 pub unsafe fn init(argc: isize, argv: *const *const u8) {
102 args::init(argc, argv);
105 // SAFETY: must be called only once during runtime cleanup.
106 // NOTE: this is not guaranteed to run, for example when the program aborts.
107 pub unsafe fn cleanup() {
113 pub unsafe extern "C" fn runtime_entry(
115 argv: *const *const c_char,
116 env: *const *const c_char,
118 use crate::sys::hermit::thread_local_dtor::run_dtors;
120 fn main(argc: isize, argv: *const *const c_char) -> i32;
123 // initialize environment
124 os::init_environment(env as *const *const i8);
126 let result = main(argc as isize, argv);
132 pub fn decode_error_kind(errno: i32) -> ErrorKind {
134 x if x == 13 as i32 => ErrorKind::PermissionDenied,
135 x if x == 98 as i32 => ErrorKind::AddrInUse,
136 x if x == 99 as i32 => ErrorKind::AddrNotAvailable,
137 x if x == 11 as i32 => ErrorKind::WouldBlock,
138 x if x == 103 as i32 => ErrorKind::ConnectionAborted,
139 x if x == 111 as i32 => ErrorKind::ConnectionRefused,
140 x if x == 104 as i32 => ErrorKind::ConnectionReset,
141 x if x == 17 as i32 => ErrorKind::AlreadyExists,
142 x if x == 4 as i32 => ErrorKind::Interrupted,
143 x if x == 22 as i32 => ErrorKind::InvalidInput,
144 x if x == 2 as i32 => ErrorKind::NotFound,
145 x if x == 107 as i32 => ErrorKind::NotConnected,
146 x if x == 1 as i32 => ErrorKind::PermissionDenied,
147 x if x == 32 as i32 => ErrorKind::BrokenPipe,
148 x if x == 110 as i32 => ErrorKind::TimedOut,
149 _ => ErrorKind::Other,
153 pub fn cvt(result: i32) -> crate::io::Result<usize> {
154 if result < 0 { Err(crate::io::Error::from_raw_os_error(-result)) } else { Ok(result as usize) }