Skip to content

Commit 6650f43

Browse files
author
Jethro Beekman
committed
SGX target: implement time
1 parent 59b79f7 commit 6650f43

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/libstd/sys/sgx/abi/usercalls/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
pub use fortanix_sgx_abi::*;
1212

1313
use io::{Error as IoError, Result as IoResult};
14+
use time::Duration;
1415

1516
pub mod alloc;
1617
#[macro_use]
@@ -126,6 +127,11 @@ pub fn send(event_set: u64, tcs: Option<Tcs>) -> IoResult<()> {
126127
unsafe { raw::send(event_set, tcs).from_sgx_result() }
127128
}
128129

130+
pub fn insecure_time() -> Duration {
131+
let t = unsafe { raw::insecure_time() };
132+
Duration::new(t / 1_000_000_000, (t % 1_000_000_000) as _)
133+
}
134+
129135
pub fn alloc(size: usize, alignment: usize) -> IoResult<*mut u8> {
130136
unsafe { raw::alloc(size, alignment).from_sgx_result() }
131137
}

src/libstd/sys/sgx/time.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use time::Duration;
12-
use sys::unsupported_err;
12+
use super::abi::usercalls;
1313

1414
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
1515
pub struct Instant(Duration);
@@ -21,7 +21,7 @@ pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
2121

2222
impl Instant {
2323
pub fn now() -> Instant {
24-
panic!("{}", unsupported_err());
24+
Instant(usercalls::insecure_time())
2525
}
2626

2727
pub fn sub_instant(&self, other: &Instant) -> Duration {
@@ -39,7 +39,7 @@ impl Instant {
3939

4040
impl SystemTime {
4141
pub fn now() -> SystemTime {
42-
panic!("{}", unsupported_err());
42+
SystemTime(usercalls::insecure_time())
4343
}
4444

4545
pub fn sub_time(&self, other: &SystemTime)

0 commit comments

Comments
 (0)