SGX target: implement time
This commit is contained in:
parent
59b79f71e9
commit
6650f43a3f
2 changed files with 9 additions and 3 deletions
|
@ -11,6 +11,7 @@
|
||||||
pub use fortanix_sgx_abi::*;
|
pub use fortanix_sgx_abi::*;
|
||||||
|
|
||||||
use io::{Error as IoError, Result as IoResult};
|
use io::{Error as IoError, Result as IoResult};
|
||||||
|
use time::Duration;
|
||||||
|
|
||||||
pub mod alloc;
|
pub mod alloc;
|
||||||
#[macro_use]
|
#[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() }
|
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> {
|
pub fn alloc(size: usize, alignment: usize) -> IoResult<*mut u8> {
|
||||||
unsafe { raw::alloc(size, alignment).from_sgx_result() }
|
unsafe { raw::alloc(size, alignment).from_sgx_result() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
use sys::unsupported_err;
|
use super::abi::usercalls;
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||||
pub struct Instant(Duration);
|
pub struct Instant(Duration);
|
||||||
|
@ -21,7 +21,7 @@ pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
|
||||||
|
|
||||||
impl Instant {
|
impl Instant {
|
||||||
pub fn now() -> Instant {
|
pub fn now() -> Instant {
|
||||||
panic!("{}", unsupported_err());
|
Instant(usercalls::insecure_time())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
pub fn sub_instant(&self, other: &Instant) -> Duration {
|
||||||
|
@ -39,7 +39,7 @@ impl Instant {
|
||||||
|
|
||||||
impl SystemTime {
|
impl SystemTime {
|
||||||
pub fn now() -> SystemTime {
|
pub fn now() -> SystemTime {
|
||||||
panic!("{}", unsupported_err());
|
SystemTime(usercalls::insecure_time())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sub_time(&self, other: &SystemTime)
|
pub fn sub_time(&self, other: &SystemTime)
|
||||||
|
|
Loading…
Reference in a new issue