Allow to disable clocks in WasiCtx (#6007)

Takes the approach described in #6004, but also creates a wrapper for the monotonic time that encapsulates the `creation_time` field as well, since they logically belong and are always used together.

This makes it easier to configure `WasiCtx` with custom clocks as well as disable them for security or determinism reasons.

Closes #6004.
This commit is contained in:
Ingvar Stepanyan
2023-03-13 23:47:04 +00:00
committed by GitHub
parent d6ce632b5b
commit 873d3b50a0
5 changed files with 92 additions and 56 deletions

View File

@@ -35,13 +35,7 @@ impl WasiMonotonicClock for MonotonicClock {
}
pub fn clocks_ctx() -> WasiClocks {
let system = Box::new(SystemClock::new(ambient_authority()));
let monotonic = cap_std::time::MonotonicClock::new(ambient_authority());
let creation_time = monotonic.now();
let monotonic = Box::new(MonotonicClock(monotonic));
WasiClocks {
system,
monotonic,
creation_time,
}
WasiClocks::new()
.with_system(SystemClock::new(ambient_authority()))
.with_monotonic(MonotonicClock::new(ambient_authority()))
}