SGX target: implement time

This commit is contained in:
Jethro Beekman 2018-09-19 16:48:04 -07:00
parent 59b79f71e9
commit 6650f43a3f
2 changed files with 9 additions and 3 deletions

View 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() }
}

View 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 @@ 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)