1 //! System bindings for the Teeos platform
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)]
9 pub use self::rand
::hashmap_random_keys
;
12 #[path = "../unsupported/args.rs"]
14 #[path = "../unix/cmath.rs"]
16 #[path = "../unsupported/env.rs"]
20 #[path = "../unsupported/fs.rs"]
22 #[path = "../unsupported/io.rs"]
24 #[path = "../unix/memchr.rs"]
27 #[path = "../unsupported/once.rs"]
30 #[path = "../unix/os_str.rs"]
32 #[path = "../unix/path.rs"]
34 #[path = "../unsupported/pipe.rs"]
36 #[path = "../unsupported/process.rs"]
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"]
50 use crate::io
::ErrorKind
;
52 pub fn abort_internal() -> ! {
53 unsafe { libc::abort() }
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) {}
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() {
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();
70 pub(crate) fn is_interrupted(errno
: i32) -> bool
{
74 // Note: code below is 1:1 copied from unix/mod.rs
75 pub fn decode_error_kind(errno
: i32) -> 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
,
113 libc
::EACCES
| libc
::EPERM
=> PermissionDenied
,
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
118 x
if x
== libc
::EAGAIN
|| x
== libc
::EWOULDBLOCK
=> WouldBlock
,
125 pub trait IsMinusOne
{
126 fn is_minus_one(&self) -> bool
;
129 macro_rules
! impl_is_minus_one
{
130 ($
($t
:ident
)*) => ($
(impl IsMinusOne
for $t
{
131 fn is_minus_one(&self) -> bool
{
137 impl_is_minus_one
! { i8 i16 i32 i64 isize }
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) }
143 pub fn cvt_r
<T
, F
>(mut f
: F
) -> crate::io
::Result
<T
>
150 Err(ref e
) if e
.kind() == ErrorKind
::Interrupted
=> {}
151 other
=> return other
,
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)) }
160 use crate::io
as std_io
;
161 pub fn unsupported
<T
>() -> std_io
::Result
<T
> {
162 Err(unsupported_err())
165 pub fn unsupported_err() -> std_io
::Error
{
166 std_io
::Error
::new(std_io
::ErrorKind
::Unsupported
, "operation not supported on this platform")