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/// Performs the raw usercall operation as defined in the ABI calling convention.
@@ -23,9 +24,11 @@ extern "C" {
2324///
2425/// Panics if `nr` is `0`.
2526#[ 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) ;
2932 ( a, b)
3033}
3134
@@ -41,7 +44,6 @@ trait ReturnValue {
4144}
4245
4346macro_rules! define_usercalls {
44- // Using `$r:tt` because `$r:ty` doesn't match ! in `clobber_diverging`
4547 ( $( fn $f: ident( $( $n: ident: $t: ty) ,* ) $( -> $r: tt) * ; ) * ) => {
4648 /// Usercall numbers as per the ABI.
4749 #[ repr( u64 ) ]
@@ -59,22 +61,6 @@ macro_rules! define_usercalls {
5961 } ;
6062}
6163
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-
7864macro_rules! define_ra {
7965 ( < $i: ident > $t: ty) => {
8066 impl <$i> RegisterArgument for $t {
@@ -173,74 +159,90 @@ impl<T: RegisterArgument, U: RegisterArgument> ReturnValue for (T, U) {
173159 }
174160}
175161
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`
176168macro_rules! enclave_usercalls_internal_define_usercalls {
177169 ( 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 ) => (
179171 /// This is the raw function definition, see the ABI documentation for
180172 /// more information.
181173 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
182174 #[ inline( always) ]
183175 pub unsafe fn $f( $n1: $t1, $n2: $t2, $n3: $t3, $n4: $t4) -> $r {
184176 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" ) ,
186179 RegisterArgument :: into_register( $n1) ,
187180 RegisterArgument :: into_register( $n2) ,
188181 RegisterArgument :: into_register( $n3) ,
189182 RegisterArgument :: into_register( $n4) ,
183+ return_type_is_abort!( $r)
190184 ) )
191185 }
192186 ) ;
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 ) => (
194188 /// This is the raw function definition, see the ABI documentation for
195189 /// more information.
196190 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
197191 #[ inline( always) ]
198192 pub unsafe fn $f( $n1: $t1, $n2: $t2, $n3: $t3) -> $r {
199193 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" ) ,
201196 RegisterArgument :: into_register( $n1) ,
202197 RegisterArgument :: into_register( $n2) ,
203198 RegisterArgument :: into_register( $n3) ,
204- 0
199+ 0 ,
200+ return_type_is_abort!( $r)
205201 ) )
206202 }
207203 ) ;
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 ) => (
209205 /// This is the raw function definition, see the ABI documentation for
210206 /// more information.
211207 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
212208 #[ inline( always) ]
213209 pub unsafe fn $f( $n1: $t1, $n2: $t2) -> $r {
214210 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" ) ,
216213 RegisterArgument :: into_register( $n1) ,
217214 RegisterArgument :: into_register( $n2) ,
218- 0 , 0
215+ 0 , 0 ,
216+ return_type_is_abort!( $r)
219217 ) )
220218 }
221219 ) ;
222- ( def fn $f: ident( $n1: ident: $t1: ty) -> $r: ty ) => (
220+ ( def fn $f: ident( $n1: ident: $t1: ty) -> $r: tt ) => (
223221 /// This is the raw function definition, see the ABI documentation for
224222 /// more information.
225223 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
226224 #[ inline( always) ]
227225 pub unsafe fn $f( $n1: $t1) -> $r {
228226 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" ) ,
230229 RegisterArgument :: into_register( $n1) ,
231- 0 , 0 , 0
230+ 0 , 0 , 0 ,
231+ return_type_is_abort!( $r)
232232 ) )
233233 }
234234 ) ;
235- ( def fn $f: ident( ) -> $r: ty ) => (
235+ ( def fn $f: ident( ) -> $r: tt ) => (
236236 /// This is the raw function definition, see the ABI documentation for
237237 /// more information.
238238 #[ unstable( feature = "sgx_platform" , issue = "56975" ) ]
239239 #[ inline( always) ]
240240 pub unsafe fn $f( ) -> $r {
241241 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)
244246 ) )
245247 }
246248 ) ;
@@ -250,4 +252,3 @@ macro_rules! enclave_usercalls_internal_define_usercalls {
250252}
251253
252254invoke_with_usercalls ! ( define_usercalls) ;
253- invoke_with_usercalls ! ( define_usercalls_asm) ;
0 commit comments