]> git.proxmox.com Git - rustc.git/blob - library/std/src/sys/teeos/mod.rs
New upstream version 1.76.0+dfsg1
[rustc.git] / library / std / src / sys / teeos / mod.rs
1 //! System bindings for the Teeos platform
2 //!
3 //! This module contains the facade (aka platform-specific) implementations of
4 //! OS level functionality for Teeos.
5 #![allow(unsafe_op_in_unsafe_fn)]
6 #![allow(unused_variables)]
7 #![allow(dead_code)]
8
9 pub use self::rand::hashmap_random_keys;
10
11 pub mod alloc;
12 #[path = "../unsupported/args.rs"]
13 pub mod args;
14 #[path = "../unix/cmath.rs"]
15 pub mod cmath;
16 #[path = "../unsupported/env.rs"]
17 pub mod env;
18 pub mod locks;
19 //pub mod fd;
20 #[path = "../unsupported/fs.rs"]
21 pub mod fs;
22 #[path = "../unsupported/io.rs"]
23 pub mod io;
24 #[path = "../unix/memchr.rs"]
25 pub mod memchr;
26 pub mod net;
27 #[path = "../unsupported/once.rs"]
28 pub mod once;
29 pub mod os;
30 #[path = "../unix/os_str.rs"]
31 pub mod os_str;
32 #[path = "../unix/path.rs"]
33 pub mod path;
34 #[path = "../unsupported/pipe.rs"]
35 pub mod pipe;
36 #[path = "../unsupported/process.rs"]
37 pub mod process;
38 mod rand;
39 pub mod stdio;
40 pub mod thread;
41 pub mod thread_local_dtor;
42 #[path = "../unix/thread_local_key.rs"]
43 pub mod thread_local_key;
44 #[path = "../unsupported/thread_parking.rs"]
45 pub mod thread_parking;
46 #[allow(non_upper_case_globals)]
47 #[path = "../unix/time.rs"]
48 pub mod time;
49
50 use crate::io::ErrorKind;
51
52 pub fn abort_internal() -> ! {
53 unsafe { libc::abort() }
54 }
55
56 // Trusted Applications are loaded as dynamic libraries on Teeos,
57 // so this should never be called.
58 pub fn init(argc: isize, argv: *const *const u8, sigpipe: u8) {}
59
60 // SAFETY: must be called only once during runtime cleanup.
61 // this is not guaranteed to run, for example when the program aborts.
62 pub unsafe fn cleanup() {
63 unimplemented!()
64 // We do NOT have stack overflow handler, because TEE OS will kill TA when it happens.
65 // So cleanup is commented
66 // stack_overflow::cleanup();
67 }
68
69 #[inline]
70 pub(crate) fn is_interrupted(errno: i32) -> bool {
71 errno == libc::EINTR
72 }
73
74 // Note: code below is 1:1 copied from unix/mod.rs
75 pub fn decode_error_kind(errno: i32) -> ErrorKind {
76 use ErrorKind::*;
77 match errno as libc::c_int {
78 libc::E2BIG => ArgumentListTooLong,
79 libc::EADDRINUSE => AddrInUse,
80 libc::EADDRNOTAVAIL => AddrNotAvailable,
81 libc::EBUSY => ResourceBusy,
82 libc::ECONNABORTED => ConnectionAborted,
83 libc::ECONNREFUSED => ConnectionRefused,
84 libc::ECONNRESET => ConnectionReset,
85 libc::EDEADLK => Deadlock,
86 libc::EDQUOT => FilesystemQuotaExceeded,
87 libc::EEXIST => AlreadyExists,
88 libc::EFBIG => FileTooLarge,
89 libc::EHOSTUNREACH => HostUnreachable,
90 libc::EINTR => Interrupted,
91 libc::EINVAL => InvalidInput,
92 libc::EISDIR => IsADirectory,
93 libc::ELOOP => FilesystemLoop,
94 libc::ENOENT => NotFound,
95 libc::ENOMEM => OutOfMemory,
96 libc::ENOSPC => StorageFull,
97 libc::ENOSYS => Unsupported,
98 libc::EMLINK => TooManyLinks,
99 libc::ENAMETOOLONG => InvalidFilename,
100 libc::ENETDOWN => NetworkDown,
101 libc::ENETUNREACH => NetworkUnreachable,
102 libc::ENOTCONN => NotConnected,
103 libc::ENOTDIR => NotADirectory,
104 libc::ENOTEMPTY => DirectoryNotEmpty,
105 libc::EPIPE => BrokenPipe,
106 libc::EROFS => ReadOnlyFilesystem,
107 libc::ESPIPE => NotSeekable,
108 libc::ESTALE => StaleNetworkFileHandle,
109 libc::ETIMEDOUT => TimedOut,
110 libc::ETXTBSY => ExecutableFileBusy,
111 libc::EXDEV => CrossesDevices,
112
113 libc::EACCES | libc::EPERM => PermissionDenied,
114
115 // These two constants can have the same value on some systems,
116 // but different values on others, so we can't use a match
117 // clause
118 x if x == libc::EAGAIN || x == libc::EWOULDBLOCK => WouldBlock,
119
120 _ => Uncategorized,
121 }
122 }
123
124 #[doc(hidden)]
125 pub trait IsMinusOne {
126 fn is_minus_one(&self) -> bool;
127 }
128
129 macro_rules! impl_is_minus_one {
130 ($($t:ident)*) => ($(impl IsMinusOne for $t {
131 fn is_minus_one(&self) -> bool {
132 *self == -1
133 }
134 })*)
135 }
136
137 impl_is_minus_one! { i8 i16 i32 i64 isize }
138
139 pub fn cvt<T: IsMinusOne>(t: T) -> crate::io::Result<T> {
140 if t.is_minus_one() { Err(crate::io::Error::last_os_error()) } else { Ok(t) }
141 }
142
143 pub fn cvt_r<T, F>(mut f: F) -> crate::io::Result<T>
144 where
145 T: IsMinusOne,
146 F: FnMut() -> T,
147 {
148 loop {
149 match cvt(f()) {
150 Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
151 other => return other,
152 }
153 }
154 }
155
156 pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
157 if error == 0 { Ok(()) } else { Err(crate::io::Error::from_raw_os_error(error)) }
158 }
159
160 use crate::io as std_io;
161 pub fn unsupported<T>() -> std_io::Result<T> {
162 Err(unsupported_err())
163 }
164
165 pub fn unsupported_err() -> std_io::Error {
166 std_io::Error::new(std_io::ErrorKind::Unsupported, "operation not supported on this platform")
167 }