diff options
| author | Jethro Beekman <jethro@fortanix.com> | 2018-09-19 16:48:04 -0700 |
|---|---|---|
| committer | Jethro Beekman <jethro@fortanix.com> | 2018-12-07 11:26:51 +0530 |
| commit | 6650f43a3f603e32ceba884aaa92bc491972a75b (patch) | |
| tree | e2d1a95868fd6d3c8c65d3b3b8d6eb3a7349d4f6 /src/libstd/sys | |
| parent | 59b79f71e98fa96ce632d87dfb8cad0d9707bf9d (diff) | |
| download | rust-6650f43a3f603e32ceba884aaa92bc491972a75b.tar.gz rust-6650f43a3f603e32ceba884aaa92bc491972a75b.zip | |
SGX target: implement time
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/sgx/abi/usercalls/mod.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/sgx/time.rs | 6 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/libstd/sys/sgx/abi/usercalls/mod.rs b/src/libstd/sys/sgx/abi/usercalls/mod.rs index 3614e1293c1..2bc32c9fefb 100644 --- a/src/libstd/sys/sgx/abi/usercalls/mod.rs +++ b/src/libstd/sys/sgx/abi/usercalls/mod.rs @@ -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() } } diff --git a/src/libstd/sys/sgx/time.rs b/src/libstd/sys/sgx/time.rs index 894680b0b65..b01c992768e 100644 --- a/src/libstd/sys/sgx/time.rs +++ b/src/libstd/sys/sgx/time.rs @@ -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 @@ pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); 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 @@ impl Instant { impl SystemTime { pub fn now() -> SystemTime { - panic!("{}", unsupported_err()); + SystemTime(usercalls::insecure_time()) } pub fn sub_time(&self, other: &SystemTime) |
