]> git.proxmox.com Git - rustc.git/blame - src/libstd/sys/hermit/mod.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / libstd / sys / hermit / mod.rs
CommitLineData
e74abb32
XL
1//! System bindings for HermitCore
2//!
3//! This module contains the facade (aka platform-specific) implementations of
4//! OS level functionality for HermitCore.
5//!
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.
9//!
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!
15
e74abb32 16use crate::intrinsics;
60c5eb7d 17use crate::os::raw::c_char;
e74abb32
XL
18
19pub mod alloc;
20pub mod args;
e74abb32 21pub mod cmath;
60c5eb7d 22pub mod condvar;
e74abb32 23pub mod env;
60c5eb7d 24pub mod fast_thread_local;
e74abb32 25pub mod fd;
60c5eb7d
XL
26pub mod fs;
27pub mod io;
28pub mod memchr;
29pub mod mutex;
e74abb32 30pub mod net;
60c5eb7d 31pub mod os;
e74abb32
XL
32pub mod path;
33pub mod pipe;
34pub mod process;
60c5eb7d 35pub mod rwlock;
e74abb32 36pub mod stack_overflow;
60c5eb7d
XL
37pub mod stdio;
38pub mod thread;
e74abb32 39pub mod thread_local;
60c5eb7d 40pub mod time;
e74abb32 41
e74abb32 42use crate::io::ErrorKind;
60c5eb7d 43pub use crate::sys_common::os_str_bytes as os_str;
e74abb32
XL
44
45#[allow(unused_extern_crates)]
46pub extern crate hermit_abi as abi;
47
48pub fn unsupported<T>() -> crate::io::Result<T> {
49 Err(unsupported_err())
50}
51
52pub fn unsupported_err() -> crate::io::Error {
60c5eb7d 53 crate::io::Error::new(crate::io::ErrorKind::Other, "operation not supported on HermitCore yet")
e74abb32
XL
54}
55
56// This enum is used as the storage for a bunch of types which can't actually
57// exist.
58#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
59pub enum Void {}
60
61pub unsafe fn strlen(start: *const c_char) -> usize {
62 let mut str = start;
63
64 while *str != 0 {
65 str = str.offset(1);
66 }
67
68 (str as usize) - (start as usize)
69}
70
71#[no_mangle]
72pub extern "C" fn floor(x: f64) -> f64 {
60c5eb7d 73 unsafe { intrinsics::floorf64(x) }
e74abb32
XL
74}
75
76pub unsafe fn abort_internal() -> ! {
77 abi::abort();
78}
79
80// FIXME: just a workaround to test the system
81pub fn hashmap_random_keys() -> (u64, u64) {
82 (1, 2)
83}
84
85// This function is needed by the panic runtime. The symbol is named in
86// pre-link args for the target specification, so keep that in sync.
87#[cfg(not(test))]
88#[no_mangle]
89// NB. used by both libunwind and libpanic_abort
90pub unsafe extern "C" fn __rust_abort() {
91 abort_internal();
92}
93
94#[cfg(not(test))]
95pub fn init() {
96 unsafe {
97 let _ = net::init();
98 }
99}
100
101#[cfg(not(test))]
102#[no_mangle]
60c5eb7d
XL
103pub unsafe extern "C" fn runtime_entry(
104 argc: i32,
105 argv: *const *const c_char,
106 env: *const *const c_char,
107) -> ! {
e74abb32
XL
108 extern "C" {
109 fn main(argc: isize, argv: *const *const c_char) -> i32;
110 }
111
112 // initialize environment
113 os::init_environment(env as *const *const i8);
114
115 let result = main(argc as isize, argv);
116
117 abi::exit(result);
118}
119
120pub fn decode_error_kind(errno: i32) -> ErrorKind {
121 match errno {
122 x if x == 13 as i32 => ErrorKind::PermissionDenied,
123 x if x == 98 as i32 => ErrorKind::AddrInUse,
124 x if x == 99 as i32 => ErrorKind::AddrNotAvailable,
125 x if x == 11 as i32 => ErrorKind::WouldBlock,
126 x if x == 103 as i32 => ErrorKind::ConnectionAborted,
127 x if x == 111 as i32 => ErrorKind::ConnectionRefused,
128 x if x == 104 as i32 => ErrorKind::ConnectionReset,
129 x if x == 17 as i32 => ErrorKind::AlreadyExists,
130 x if x == 4 as i32 => ErrorKind::Interrupted,
131 x if x == 22 as i32 => ErrorKind::InvalidInput,
132 x if x == 2 as i32 => ErrorKind::NotFound,
133 x if x == 107 as i32 => ErrorKind::NotConnected,
134 x if x == 1 as i32 => ErrorKind::PermissionDenied,
135 x if x == 32 as i32 => ErrorKind::BrokenPipe,
136 x if x == 110 as i32 => ErrorKind::TimedOut,
137 _ => ErrorKind::Other,
138 }
139}
140
141pub fn cvt(result: i32) -> crate::io::Result<usize> {
60c5eb7d 142 if result < 0 { Err(crate::io::Error::from_raw_os_error(-result)) } else { Ok(result as usize) }
e74abb32 143}