]> git.lizzy.rs Git - rust.git/commitdiff
SGX target: implement time
authorJethro Beekman <jethro@fortanix.com>
Wed, 19 Sep 2018 23:48:04 +0000 (16:48 -0700)
committerJethro Beekman <jethro@fortanix.com>
Fri, 7 Dec 2018 05:56:51 +0000 (11:26 +0530)
src/libstd/sys/sgx/abi/usercalls/mod.rs
src/libstd/sys/sgx/time.rs

index 3614e1293c11219cb4a9cfb1b988cc38d5d0f689..2bc32c9fefbb73a933bbaf180be5be0f4d377883 100644 (file)
@@ -11,6 +11,7 @@
 pub use fortanix_sgx_abi::*;
 
 use io::{Error as IoError, Result as IoResult};
+use time::Duration;
 
 pub mod alloc;
 #[macro_use]
@@ -126,6 +127,11 @@ pub fn send(event_set: u64, tcs: Option<Tcs>) -> IoResult<()> {
     unsafe { raw::send(event_set, tcs).from_sgx_result() }
 }
 
+pub fn insecure_time() -> Duration {
+    let t = unsafe { raw::insecure_time() };
+    Duration::new(t / 1_000_000_000, (t % 1_000_000_000) as _)
+}
+
 pub fn alloc(size: usize, alignment: usize) -> IoResult<*mut u8> {
     unsafe { raw::alloc(size, alignment).from_sgx_result() }
 }
index 894680b0b65dd403c96d755043364c6906ed3aa8..b01c992768e71dc54e02841d1fef7225dc1609a5 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use time::Duration;
-use sys::unsupported_err;
+use super::abi::usercalls;
 
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
 pub struct Instant(Duration);
@@ -21,7 +21,7 @@
 
 impl Instant {
     pub fn now() -> Instant {
-        panic!("{}", unsupported_err());
+        Instant(usercalls::insecure_time())
     }
 
     pub fn sub_instant(&self, other: &Instant) -> Duration {
@@ -39,7 +39,7 @@ pub fn sub_duration(&self, other: &Duration) -> Instant {
 
 impl SystemTime {
     pub fn now() -> SystemTime {
-        panic!("{}", unsupported_err());
+        SystemTime(usercalls::insecure_time())
     }
 
     pub fn sub_time(&self, other: &SystemTime)