@@ -115,9 +115,15 @@ pub fn decode_error_kind(code: i32) -> ErrorKind {
115115// timeouts in SGX model. The enclave runner serving usercalls may lie about
116116// current time and/or ignore timeout values.
117117//
118+ // Once the event is observed, `stop` will be used to determine whether or not
119+ // we should continue to wait.
120+ //
118121// FIXME: note these caveats in documentation of all public types that use this
119122// function in their execution path.
120- pub fn wait_timeout_sgx ( event_mask : u64 , duration : crate :: time:: Duration ) {
123+ pub fn wait_timeout_sgx < F > ( event_mask : u64 , duration : crate :: time:: Duration , stop : F )
124+ where
125+ F : Fn ( ) -> bool ,
126+ {
121127 use self :: abi:: usercalls;
122128 use crate :: cmp;
123129 use crate :: io:: ErrorKind ;
@@ -129,11 +135,13 @@ pub fn wait_timeout_sgx(event_mask: u64, duration: crate::time::Duration) {
129135 let timeout = cmp:: min ( ( u64:: MAX - 1 ) as u128 , remaining. as_nanos ( ) ) as u64 ;
130136 match usercalls:: wait ( event_mask, timeout) {
131137 Ok ( eventset) => {
132- if event_mask != 0 {
133- rtassert ! ( eventset & event_mask == event_mask) ;
138+ if event_mask == 0 {
139+ rtabort ! ( "expected usercalls::wait() to return Err, found Ok." ) ;
140+ }
141+ rtassert ! ( eventset & event_mask == event_mask) ;
142+ if stop ( ) {
134143 return ;
135144 }
136- rtabort ! ( "expected usercalls::wait() to return Err, found Ok." ) ;
137145 }
138146 Err ( e) => {
139147 rtassert ! ( e. kind( ) == ErrorKind :: TimedOut || e. kind( ) == ErrorKind :: WouldBlock )
0 commit comments