1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#![deny(unsafe_op_in_unsafe_fn)]
use crate::io::ErrorKind;
use crate::os::raw::c_char;
use crate::sync::atomic::{AtomicBool, Ordering};
pub mod abi;
mod waitqueue;
pub mod alloc;
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
pub mod condvar;
pub mod env;
pub mod fd;
#[path = "../unsupported/fs.rs"]
pub mod fs;
#[path = "../unsupported/io.rs"]
pub mod io;
pub mod memchr;
pub mod mutex;
pub mod net;
pub mod os;
#[path = "../unix/os_str.rs"]
pub mod os_str;
pub mod path;
#[path = "../unsupported/pipe.rs"]
pub mod pipe;
#[path = "../unsupported/process.rs"]
pub mod process;
pub mod rwlock;
pub mod stdio;
pub mod thread;
pub mod thread_local_key;
pub mod time;
pub unsafe fn init(argc: isize, argv: *const *const u8) {
unsafe {
args::init(argc, argv);
}
}
pub unsafe fn cleanup() {}
pub fn unsupported<T>() -> crate::io::Result<T> {
Err(unsupported_err())
}
pub fn unsupported_err() -> crate::io::Error {
crate::io::Error::new_const(ErrorKind::Unsupported, &"operation not supported on SGX yet")
}
pub fn sgx_ineffective<T>(v: T) -> crate::io::Result<T> {
static SGX_INEFFECTIVE_ERROR: AtomicBool = AtomicBool::new(false);
if SGX_INEFFECTIVE_ERROR.load(Ordering::Relaxed) {
Err(crate::io::Error::new_const(
ErrorKind::Uncategorized,
&"operation can't be trusted to have any effect on SGX",
))
} else {
Ok(v)
}
}
pub fn decode_error_kind(code: i32) -> ErrorKind {
use fortanix_sgx_abi::Error;
if code == Error::NotFound as _ {
ErrorKind::NotFound
} else if code == Error::PermissionDenied as _ {
ErrorKind::PermissionDenied
} else if code == Error::ConnectionRefused as _ {
ErrorKind::ConnectionRefused
} else if code == Error::ConnectionReset as _ {
ErrorKind::ConnectionReset
} else if code == Error::ConnectionAborted as _ {
ErrorKind::ConnectionAborted
} else if code == Error::NotConnected as _ {
ErrorKind::NotConnected
} else if code == Error::AddrInUse as _ {
ErrorKind::AddrInUse
} else if code == Error::AddrNotAvailable as _ {
ErrorKind::AddrNotAvailable
} else if code == Error::BrokenPipe as _ {
ErrorKind::BrokenPipe
} else if code == Error::AlreadyExists as _ {
ErrorKind::AlreadyExists
} else if code == Error::WouldBlock as _ {
ErrorKind::WouldBlock
} else if code == Error::InvalidInput as _ {
ErrorKind::InvalidInput
} else if code == Error::InvalidData as _ {
ErrorKind::InvalidData
} else if code == Error::TimedOut as _ {
ErrorKind::TimedOut
} else if code == Error::WriteZero as _ {
ErrorKind::WriteZero
} else if code == Error::Interrupted as _ {
ErrorKind::Interrupted
} else if code == Error::Other as _ {
ErrorKind::Uncategorized
} else if code == Error::UnexpectedEof as _ {
ErrorKind::UnexpectedEof
} else {
ErrorKind::Uncategorized
}
}
pub unsafe fn strlen(mut s: *const c_char) -> usize {
let mut n = 0;
while unsafe { *s } != 0 {
n += 1;
s = unsafe { s.offset(1) };
}
return n;
}
pub fn abort_internal() -> ! {
abi::usercalls::exit(true)
}
#[cfg(not(test))]
#[no_mangle]
pub extern "C" fn __rust_abort() {
abort_internal();
}
pub mod rand {
pub fn rdrand64() -> u64 {
unsafe {
let mut ret: u64 = 0;
for _ in 0..10 {
if crate::arch::x86_64::_rdrand64_step(&mut ret) == 1 {
return ret;
}
}
rtabort!("Failed to obtain random data");
}
}
}
pub fn hashmap_random_keys() -> (u64, u64) {
(self::rand::rdrand64(), self::rand::rdrand64())
}
pub use crate::sys_common::{AsInner, FromInner, IntoInner};
pub trait TryIntoInner<Inner>: Sized {
fn try_into_inner(self) -> Result<Inner, Self>;
}