Expand description
TPOM
Allows replacing time-related functions in the vDSO (1, 2) with user-provided functions.
Only works on Linux. Is currently limited to x86_64, though it could be extended for other architectures.
Replaces these functions, if provided:
User Function | vDSO |
---|---|
ClockGetTime | clock_gettime |
ClockGetTimeOfDay | gettimeofday |
ClockGetRes | clock_getres |
ClockGetTime | time |
Examples
use tpom::*;
use std::time::SystemTime;
ClockController::overwrite(
Some(|_| TimeSpec {
seconds: 1,
nanos: 1,
}),
None,
None,
None,
);
// Clock is frozen; all calls to time return the same values
let time_a = SystemTime::now();
let time_b = SystemTime::now();
assert_eq!(time_a, time_b);
// Restore clock; all calls to time return unique values
ClockController::restore();
let time_c = SystemTime::now();
let time_d = SystemTime::now();
assert_ne!(time_c, time_d);
Structs
Return type for
ClockGetTimeOfDay
; maps to
libc::timeval.Type Definitions
Considered infallible
Considered infallible
Considered infallible