44pub use fortanix_sgx_abi:: * ;
55
66use ptr:: NonNull ;
7+ use num:: NonZeroU64 ;
78
89#[ repr( C ) ]
910struct UsercallReturn ( u64 , u64 ) ;
1011
1112extern "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 ;
1314}
1415
1516/// Perform the raw usercall operation as defined in the ABI calling convention.
@@ -21,9 +22,11 @@ extern "C" {
2122/// # Panics
2223/// Panics if `nr` is 0.
2324#[ 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) ;
2730 ( a, b)
2831}
2932
@@ -39,7 +42,6 @@ trait ReturnValue {
3942}
4043
4144macro_rules! define_usercalls {
42- // Using `$r:tt` because `$r:ty` doesn't match ! in `clobber_diverging`
4345 ( $( fn $f: ident( $( $n: ident: $t: ty) ,* ) $( -> $r: tt) * ; ) * ) => {
4446 /// Usercall numbers as per the ABI.
4547 #[ repr( u64 ) ]
@@ -57,22 +59,6 @@ macro_rules! define_usercalls {
5759 } ;
5860}
5961
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-
7662macro_rules! define_ra {
7763 ( < $i: ident > $t: ty) => {
7864 impl <$i> RegisterArgument for $t {
@@ -171,74 +157,90 @@ impl<T: RegisterArgument, U: RegisterArgument> ReturnValue for (T, U) {
171157 }
172158}
173159
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`
174166macro_rules! enclave_usercalls_internal_define_usercalls {
175167 ( 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 ) => (
177169 /// This is the raw function definition, see the ABI documentation for
178170 /// more information.
179171 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
180172 #[ inline( always) ]
181173 pub unsafe fn $f( $n1: $t1, $n2: $t2, $n3: $t3, $n4: $t4) -> $r {
182174 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" ) ,
184177 RegisterArgument :: into_register( $n1) ,
185178 RegisterArgument :: into_register( $n2) ,
186179 RegisterArgument :: into_register( $n3) ,
187180 RegisterArgument :: into_register( $n4) ,
181+ return_type_is_abort!( $r)
188182 ) )
189183 }
190184 ) ;
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 ) => (
192186 /// This is the raw function definition, see the ABI documentation for
193187 /// more information.
194188 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
195189 #[ inline( always) ]
196190 pub unsafe fn $f( $n1: $t1, $n2: $t2, $n3: $t3) -> $r {
197191 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" ) ,
199194 RegisterArgument :: into_register( $n1) ,
200195 RegisterArgument :: into_register( $n2) ,
201196 RegisterArgument :: into_register( $n3) ,
202- 0
197+ 0 ,
198+ return_type_is_abort!( $r)
203199 ) )
204200 }
205201 ) ;
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 ) => (
207203 /// This is the raw function definition, see the ABI documentation for
208204 /// more information.
209205 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
210206 #[ inline( always) ]
211207 pub unsafe fn $f( $n1: $t1, $n2: $t2) -> $r {
212208 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" ) ,
214211 RegisterArgument :: into_register( $n1) ,
215212 RegisterArgument :: into_register( $n2) ,
216- 0 , 0
213+ 0 , 0 ,
214+ return_type_is_abort!( $r)
217215 ) )
218216 }
219217 ) ;
220- ( def fn $f: ident( $n1: ident: $t1: ty) -> $r: ty ) => (
218+ ( def fn $f: ident( $n1: ident: $t1: ty) -> $r: tt ) => (
221219 /// This is the raw function definition, see the ABI documentation for
222220 /// more information.
223221 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
224222 #[ inline( always) ]
225223 pub unsafe fn $f( $n1: $t1) -> $r {
226224 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" ) ,
228227 RegisterArgument :: into_register( $n1) ,
229- 0 , 0 , 0
228+ 0 , 0 , 0 ,
229+ return_type_is_abort!( $r)
230230 ) )
231231 }
232232 ) ;
233- ( def fn $f: ident( ) -> $r: ty ) => (
233+ ( def fn $f: ident( ) -> $r: tt ) => (
234234 /// This is the raw function definition, see the ABI documentation for
235235 /// more information.
236236 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
237237 #[ inline( always) ]
238238 pub unsafe fn $f( ) -> $r {
239239 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)
242244 ) )
243245 }
244246 ) ;
@@ -248,4 +250,3 @@ macro_rules! enclave_usercalls_internal_define_usercalls {
248250}
249251
250252invoke_with_usercalls ! ( define_usercalls) ;
251- invoke_with_usercalls ! ( define_usercalls_asm) ;
0 commit comments