4
4
pub use fortanix_sgx_abi::*;
5
5
6
6
use ptr::NonNull;
7
+ use num::NonZeroU64;
7
8
8
9
#[repr(C)]
9
10
struct UsercallReturn(u64, u64);
10
11
11
12
extern "C" {
12
- fn usercall(nr: u64 , p1: u64, p2: u64, _ignore : u64, p3: u64, p4: u64) -> UsercallReturn;
13
+ fn usercall(nr: NonZeroU64 , p1: u64, p2: u64, abort : u64, p3: u64, p4: u64) -> UsercallReturn;
13
14
}
14
15
15
16
/// Performs the raw usercall operation as defined in the ABI calling convention.
@@ -23,9 +24,11 @@ extern "C" {
23
24
///
24
25
/// Panics if `nr` is `0`.
25
26
#[unstable(feature = "sgx_platform", issue = "56975")]
26
- pub unsafe fn do_usercall(nr: u64, p1: u64, p2: u64, p3: u64, p4: u64) -> (u64, u64) {
27
- if nr==0 { panic!("Invalid usercall number {}",nr) }
28
- let UsercallReturn(a, b) = usercall(nr,p1,p2,0,p3,p4);
27
+ #[inline]
28
+ pub unsafe fn do_usercall(nr: NonZeroU64, p1: u64, p2: u64, p3: u64, p4: u64, abort: bool)
29
+ -> (u64, u64)
30
+ {
31
+ let UsercallReturn(a, b) = usercall(nr, p1, p2, abort as _, p3, p4);
29
32
(a, b)
30
33
}
31
34
@@ -41,7 +44,6 @@ trait ReturnValue {
41
44
}
42
45
43
46
macro_rules! define_usercalls {
44
- // Using `$r:tt` because `$r:ty` doesn't match ! in `clobber_diverging`
45
47
($(fn $f:ident($($n:ident: $t:ty),*) $(-> $r:tt)*; )*) => {
46
48
/// Usercall numbers as per the ABI.
47
49
#[repr(u64)]
@@ -59,22 +61,6 @@ macro_rules! define_usercalls {
59
61
};
60
62
}
61
63
62
- macro_rules! define_usercalls_asm {
63
- ($(fn $f:ident($($n:ident: $t:ty),*) $(-> $r:ty)*; )*) => {
64
- macro_rules! usercalls_asm {
65
- () => {
66
- concat!(
67
- ".equ usercall_nr_LAST, 0\n",
68
- $(
69
- ".equ usercall_nr_", stringify!($f), ", usercall_nr_LAST+1\n",
70
- ".equ usercall_nr_LAST, usercall_nr_", stringify!($f), "\n"
71
- ),*
72
- )
73
- }
74
- }
75
- };
76
- }
77
-
78
64
macro_rules! define_ra {
79
65
(< $i:ident > $t:ty) => {
80
66
impl<$i> RegisterArgument for $t {
@@ -173,74 +159,90 @@ impl<T: RegisterArgument, U: RegisterArgument> ReturnValue for (T, U) {
173
159
}
174
160
}
175
161
162
+ macro_rules! return_type_is_abort {
163
+ (!) => { true };
164
+ ($r:ty) => { false };
165
+ }
166
+
167
+ // In this macro: using `$r:tt` because `$r:ty` doesn't match ! in `return_type_is_abort`
176
168
macro_rules! enclave_usercalls_internal_define_usercalls {
177
169
(def fn $f:ident($n1:ident: $t1:ty, $n2:ident: $t2:ty,
178
- $n3:ident: $t3:ty, $n4:ident: $t4:ty) -> $r:ty ) => (
170
+ $n3:ident: $t3:ty, $n4:ident: $t4:ty) -> $r:tt ) => (
179
171
/// This is the raw function definition, see the ABI documentation for
180
172
/// more information.
181
173
#[unstable(feature = "sgx_platform", issue = "56975")]
182
174
#[inline(always)]
183
175
pub unsafe fn $f($n1: $t1, $n2: $t2, $n3: $t3, $n4: $t4) -> $r {
184
176
ReturnValue::from_registers(stringify!($f), do_usercall(
185
- Usercalls::$f as Register,
177
+ NonZeroU64::new(Usercalls::$f as Register)
178
+ .expect("Usercall number must be non-zero"),
186
179
RegisterArgument::into_register($n1),
187
180
RegisterArgument::into_register($n2),
188
181
RegisterArgument::into_register($n3),
189
182
RegisterArgument::into_register($n4),
183
+ return_type_is_abort!($r)
190
184
))
191
185
}
192
186
);
193
- (def fn $f:ident($n1:ident: $t1:ty, $n2:ident: $t2:ty, $n3:ident: $t3:ty) -> $r:ty ) => (
187
+ (def fn $f:ident($n1:ident: $t1:ty, $n2:ident: $t2:ty, $n3:ident: $t3:ty) -> $r:tt ) => (
194
188
/// This is the raw function definition, see the ABI documentation for
195
189
/// more information.
196
190
#[unstable(feature = "sgx_platform", issue = "56975")]
197
191
#[inline(always)]
198
192
pub unsafe fn $f($n1: $t1, $n2: $t2, $n3: $t3) -> $r {
199
193
ReturnValue::from_registers(stringify!($f), do_usercall(
200
- Usercalls::$f as Register,
194
+ NonZeroU64::new(Usercalls::$f as Register)
195
+ .expect("Usercall number must be non-zero"),
201
196
RegisterArgument::into_register($n1),
202
197
RegisterArgument::into_register($n2),
203
198
RegisterArgument::into_register($n3),
204
- 0
199
+ 0,
200
+ return_type_is_abort!($r)
205
201
))
206
202
}
207
203
);
208
- (def fn $f:ident($n1:ident: $t1:ty, $n2:ident: $t2:ty) -> $r:ty ) => (
204
+ (def fn $f:ident($n1:ident: $t1:ty, $n2:ident: $t2:ty) -> $r:tt ) => (
209
205
/// This is the raw function definition, see the ABI documentation for
210
206
/// more information.
211
207
#[unstable(feature = "sgx_platform", issue = "56975")]
212
208
#[inline(always)]
213
209
pub unsafe fn $f($n1: $t1, $n2: $t2) -> $r {
214
210
ReturnValue::from_registers(stringify!($f), do_usercall(
215
- Usercalls::$f as Register,
211
+ NonZeroU64::new(Usercalls::$f as Register)
212
+ .expect("Usercall number must be non-zero"),
216
213
RegisterArgument::into_register($n1),
217
214
RegisterArgument::into_register($n2),
218
- 0,0
215
+ 0,0,
216
+ return_type_is_abort!($r)
219
217
))
220
218
}
221
219
);
222
- (def fn $f:ident($n1:ident: $t1:ty) -> $r:ty ) => (
220
+ (def fn $f:ident($n1:ident: $t1:ty) -> $r:tt ) => (
223
221
/// This is the raw function definition, see the ABI documentation for
224
222
/// more information.
225
223
#[unstable(feature = "sgx_platform", issue = "56975")]
226
224
#[inline(always)]
227
225
pub unsafe fn $f($n1: $t1) -> $r {
228
226
ReturnValue::from_registers(stringify!($f), do_usercall(
229
- Usercalls::$f as Register,
227
+ NonZeroU64::new(Usercalls::$f as Register)
228
+ .expect("Usercall number must be non-zero"),
230
229
RegisterArgument::into_register($n1),
231
- 0,0,0
230
+ 0,0,0,
231
+ return_type_is_abort!($r)
232
232
))
233
233
}
234
234
);
235
- (def fn $f:ident() -> $r:ty ) => (
235
+ (def fn $f:ident() -> $r:tt ) => (
236
236
/// This is the raw function definition, see the ABI documentation for
237
237
/// more information.
238
238
#[unstable(feature = "sgx_platform", issue = "56975")]
239
239
#[inline(always)]
240
240
pub unsafe fn $f() -> $r {
241
241
ReturnValue::from_registers(stringify!($f), do_usercall(
242
- Usercalls::$f as Register,
243
- 0,0,0,0
242
+ NonZeroU64::new(Usercalls::$f as Register)
243
+ .expect("Usercall number must be non-zero"),
244
+ 0,0,0,0,
245
+ return_type_is_abort!($r)
244
246
))
245
247
}
246
248
);
@@ -250,4 +252,3 @@ macro_rules! enclave_usercalls_internal_define_usercalls {
250
252
}
251
253
252
254
invoke_with_usercalls!(define_usercalls);
253
- invoke_with_usercalls!(define_usercalls_asm);
0 commit comments