about summary refs log tree commit diff
path: root/src/libstd/sys/sgx/mod.rs
diff options
context:
space:
mode:
authorMohsen Zohrevandi <mohsen.zohrevandi@fortanix.com>2020-07-15 15:48:36 -0700
committerMohsen Zohrevandi <mohsen.zohrevandi@fortanix.com>2020-07-15 15:48:36 -0700
commit85c25aed510ce599504b172f7c7bef280e91637b (patch)
treea80a4b1cd516f4516cb7ab85027db12ca8c4b6ac /src/libstd/sys/sgx/mod.rs
parent1466598e19321bc6b97aef8271a317e78211d54d (diff)
downloadrust-85c25aed510ce599504b172f7c7bef280e91637b.tar.gz
rust-85c25aed510ce599504b172f7c7bef280e91637b.zip
Move usercall_wait_timeout to abi::usercalls::wait_timeout
Diffstat (limited to 'src/libstd/sys/sgx/mod.rs')
-rw-r--r--src/libstd/sys/sgx/mod.rs76
1 files changed, 0 insertions, 76 deletions
diff --git a/src/libstd/sys/sgx/mod.rs b/src/libstd/sys/sgx/mod.rs
index c412053112b..7a3a3eb2049 100644
--- a/src/libstd/sys/sgx/mod.rs
+++ b/src/libstd/sys/sgx/mod.rs
@@ -110,82 +110,6 @@ pub fn decode_error_kind(code: i32) -> ErrorKind {
     }
 }
 
-// This function makes an effort to wait for a non-spurious event at least as
-// long as `duration`. Note that in general there is no guarantee about accuracy
-// of time and timeouts in SGX model. The enclave runner serving usercalls may
-// lie about current time and/or ignore timeout values.
-//
-// Once the event is observed, `should_wake_up` will be used to determine
-// whether or not the event was spurious.
-pub fn usercall_wait_timeout<F>(event_mask: u64, duration: crate::time::Duration, should_wake_up: F)
-where
-    F: Fn() -> bool,
-{
-    use self::abi::usercalls;
-    use crate::cmp;
-    use crate::io::ErrorKind;
-    use crate::time::{Duration, Instant};
-
-    // Calls the wait usercall and checks the result. Returns true if event was
-    // returned, and false if WouldBlock/TimedOut was returned.
-    // If duration is None, it will use WAIT_NO.
-    fn wait_checked(event_mask: u64, duration: Option<Duration>) -> bool {
-        let timeout = duration.map_or(usercalls::raw::WAIT_NO, |duration| {
-            cmp::min((u64::MAX - 1) as u128, duration.as_nanos()) as u64
-        });
-        match usercalls::wait(event_mask, timeout) {
-            Ok(eventset) => {
-                if event_mask == 0 {
-                    rtabort!("expected usercalls::wait() to return Err, found Ok.");
-                }
-                // A matching event is one whose bits are equal to or a subset
-                // of `event_mask`.
-                rtassert!(eventset & !event_mask == 0);
-                true
-            }
-            Err(e) => {
-                rtassert!(e.kind() == ErrorKind::TimedOut || e.kind() == ErrorKind::WouldBlock);
-                false
-            }
-        }
-    }
-
-    match wait_checked(event_mask, Some(duration)) {
-        false => return,                    // timed out
-        true if should_wake_up() => return, // woken up
-        true => {}                          // spurious event
-    }
-
-    // Drain all cached events.
-    // Note that `event_mask != 0` is implied if we get here.
-    loop {
-        match wait_checked(event_mask, None) {
-            false => break,                     // no more cached events
-            true if should_wake_up() => return, // woken up
-            true => {}                          // spurious event
-        }
-    }
-
-    // Continue waiting, but take note of time spent waiting so we don't wait
-    // forever. We intentionally don't call `Instant::now()` before this point
-    // to avoid the cost of the `insecure_time` usercall in case there are no
-    // spurious wakeups.
-
-    let start = Instant::now();
-    let mut remaining = duration;
-    loop {
-        match wait_checked(event_mask, Some(remaining)) {
-            false => return,                    // timed out
-            true if should_wake_up() => return, // woken up
-            true => {}                          // spurious event
-        }
-        remaining = match duration.checked_sub(start.elapsed()) {
-            Some(remaining) => remaining,
-            None => break,
-        }
-    }
-}
-
 // This enum is used as the storage for a bunch of types which can't actually
 // exist.
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]