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