diff --git a/src/tools/miri/src/shims/time.rs b/src/tools/miri/src/shims/time.rs index c49aa9f20f6c..865a80251e31 100644 --- a/src/tools/miri/src/shims/time.rs +++ b/src/tools/miri/src/shims/time.rs @@ -275,26 +275,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { interp_ok(Scalar::from_i32(-1)) // Return non-zero on success } - #[allow(non_snake_case, clippy::arithmetic_side_effects)] + #[allow(clippy::arithmetic_side_effects)] fn system_time_since_windows_epoch(&self, time: &SystemTime) -> InterpResult<'tcx, Duration> { - let this = self.eval_context_ref(); - - let INTERVALS_PER_SEC = this.eval_windows_u64("time", "INTERVALS_PER_SEC"); - let INTERVALS_TO_UNIX_EPOCH = this.eval_windows_u64("time", "INTERVALS_TO_UNIX_EPOCH"); - let SECONDS_TO_UNIX_EPOCH = INTERVALS_TO_UNIX_EPOCH / INTERVALS_PER_SEC; + // The amount of seconds between 1601/1/1 and 1970/1/1. + // See https://learn.microsoft.com/en-us/windows/win32/sysinfo/converting-a-time-t-value-to-a-file-time + // (just divide by the number of 100 ns intervals per second). + const SECONDS_TO_UNIX_EPOCH: u64 = 11_644_473_600; interp_ok(system_time_to_duration(time)? + Duration::from_secs(SECONDS_TO_UNIX_EPOCH)) } #[allow(non_snake_case, clippy::arithmetic_side_effects)] fn windows_ticks_for(&self, duration: Duration) -> InterpResult<'tcx, u64> { - let this = self.eval_context_ref(); + // 1 interval = 100 ns. + // See https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime + const NANOS_PER_INTERVAL: u128 = 100; - let NANOS_PER_SEC = this.eval_windows_u64("time", "NANOS_PER_SEC"); - let INTERVALS_PER_SEC = this.eval_windows_u64("time", "INTERVALS_PER_SEC"); - let NANOS_PER_INTERVAL = NANOS_PER_SEC / INTERVALS_PER_SEC; - - let ticks = u64::try_from(duration.as_nanos() / u128::from(NANOS_PER_INTERVAL)) + let ticks = u64::try_from(duration.as_nanos() / NANOS_PER_INTERVAL) .map_err(|_| err_unsup_format!("programs running more than 2^64 Windows ticks after the Windows epoch are not supported"))?; interp_ok(ticks) }