mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
loader: stop the mock clock wrapping and test time services against one clock (#204)
Signed-off-by: LanaCodes-Boop <139008131+LanaCodes-Boop@users.noreply.github.com>
This commit is contained in:
1 parent
1d363c3c34
commit
1e8893a6bf
3 files changed
+179
-1
No files matched your search
@@ -17,6 +17,7 @@ remains unsupported.
|
||||
- Extended the read-only RDNA2 planning CLI (`python3 -m qa rdna2`) with family/status filters, compact summaries, Codex-ready manifests under `artifacts/`, active-claim exclusion (family claims exclude those families; path-only claims block overlapping permitted files), coverage reconcile against `semantic_coverage` without inflating counts, and inventory diffs. Covered by `tests/qa/test_rdna2_plan.py`; planning only, no GPU production edits.
|
||||
|
||||
### Added
|
||||
- Added `tests/runtime_clock.rs`, which reads the performance counter, its frequency, both tick counts, the unbiased interrupt time and the system time from one injected clock and checks that they report the same elapsed time in their own units, after a host advance and after a guest `Sleep`, and that none of them decreases up to and past the end of the clock (#204). Expected values are worked out by hand from the documented units. Timed waits still return without consuming clock time.
|
||||
- Added four Wave32 gfx1030 VOP2 select and carry forms through the semantic registry. Conditional select, add with carry and both subtract orders with borrow use a per-lane VCC bit and have a guide-derived oracle that passes on both CPU interpreters and on native Metal (local Apple M5, API and shader validation); independent acceptance is pending. Part of #215.
|
||||
- Added decoding and Metal shader translation for twelve Wave32 VOPC 16-bit integer compares (#215). The signed and unsigned forms compare the low 16 bits of each source and write the Wave32 VCC mask. CPU verification covers 1,572 compiler acceptance cases and 408 rejections from the guide-derived oracle, which also passes on native Metal (1,572 cases in 1,420 programs on a local Apple M5 under API and shader validation); acceptance is pending.
|
||||
- Added MOVS and STOS for 8- to 64-bit elements, with and without REP, and the direction flag with CLD and STD (#129). A REP form runs one element per step and stays on the instruction until RCX is zero, so every element counts against the step budget, a repeat can stop part-way and resume, a zero count touches nothing, and a fault keeps the elements already done with RSI, RDI and RCX at the one that faulted. An FS or GS override applies to the MOVS source only. Both engines run these on the shared semantics with no bulk-copy path, so large copies are slow. LODS, CMPS, SCAS, REPE, REPNE and the address-size override stay rejected. Fourteen SDM-derived cases already in `cpu_known_answers.rs` moved from refused to verified, and `tests/cpu_rep.rs` adds a byte-array model over every form, direction and count; not compared with x86 hardware and awaiting independent review.
|
||||
@@ -185,6 +186,7 @@ remains unsupported.
|
||||
native DBT.
|
||||
|
||||
### Fixed
|
||||
- `MockClock::advance` no longer wraps the FILETIME. A large advance made the synthetic wall clock run backwards while the performance count beside it stopped at its maximum; both now stop at their maximum (#204).
|
||||
- Made the static probe and the binder share one bounded import parser, after the truncated-name fix for #270. Truncated, unterminated, empty or non-ASCII names, reserved bits and endless tables are reported by the probe and refused by the binder.
|
||||
- Fixed import binding writing some slots before finding an unresolved import, and service calls taking effect before an unreadable return address was noticed. A service that changes a nonvolatile register, including XMM6 to XMM15, now stops the guest (part of #201).
|
||||
- Fixed older import-generator templates that reported success for unimplemented wrappers, used a nonexistent exit reason, and read floating-point arguments from integer registers.
|
||||
|
||||
@@ -92,8 +92,14 @@ impl MockClock {
|
||||
}
|
||||
}
|
||||
|
||||
/// Move both readings forward by `intervals` 100-nanosecond ticks. Each
|
||||
/// stops at its maximum, so neither ever runs backwards.
|
||||
pub fn advance(&self, intervals: u64) {
|
||||
self.current.fetch_add(intervals, Ordering::SeqCst);
|
||||
self.current
|
||||
.try_update(Ordering::SeqCst, Ordering::SeqCst, |current| {
|
||||
Some(current.saturating_add(intervals))
|
||||
})
|
||||
.expect("clock update always returns a value");
|
||||
self.performance_count
|
||||
.try_update(Ordering::SeqCst, Ordering::SeqCst, |count| {
|
||||
Some(count.saturating_add(intervals).min(MAX_PERFORMANCE_COUNT))
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! The injected guest clock read through every time service at once.
|
||||
//!
|
||||
//! Units come from the public Windows documentation: a FILETIME and the
|
||||
//! unbiased interrupt time count 100-nanosecond intervals, the tick counts are
|
||||
//! milliseconds, and a performance count divided by the reported frequency is
|
||||
//! seconds. Expected values are worked out by hand from those units, not taken
|
||||
//! from the service code.
|
||||
|
||||
mod support;
|
||||
|
||||
use std::sync::Arc;
|
||||
use support::*;
|
||||
use xenora_loader::services::{MockClock, ServicesState};
|
||||
|
||||
const KERNEL32: &str = "kernel32.dll";
|
||||
|
||||
const IMPORTS: &[(&str, &str)] = &[
|
||||
(KERNEL32, "QueryPerformanceCounter"),
|
||||
(KERNEL32, "QueryPerformanceFrequency"),
|
||||
(KERNEL32, "GetTickCount"),
|
||||
(KERNEL32, "GetTickCount64"),
|
||||
(KERNEL32, "QueryUnbiasedInterruptTime"),
|
||||
(KERNEL32, "GetSystemTimeAsFileTime"),
|
||||
(KERNEL32, "Sleep"),
|
||||
];
|
||||
|
||||
/// 2026-11-24 12:34:56 UTC as a FILETIME: 1,795,523,696 Unix seconds plus the
|
||||
/// 11,644,473,600 seconds between 1601 and 1970, times ten million.
|
||||
const START_FILETIME: u64 = 134_399_972_960_000_000;
|
||||
/// Clock time that passes before the guest process starts.
|
||||
const BEFORE_START: u64 = 1_234;
|
||||
|
||||
/// One reading of every time service.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct Reading {
|
||||
counter: u64,
|
||||
frequency: u64,
|
||||
tick: u64,
|
||||
tick64: u64,
|
||||
interrupt: u64,
|
||||
filetime: u64,
|
||||
}
|
||||
|
||||
fn guest() -> (Guest, Arc<MockClock>) {
|
||||
let clock = Arc::new(MockClock::new(START_FILETIME));
|
||||
clock.advance(BEFORE_START);
|
||||
let guest = Guest::with_state(IMPORTS, &[], ServicesState::new(clock.clone()));
|
||||
(guest, clock)
|
||||
}
|
||||
|
||||
fn read(guest: &mut Guest) -> Reading {
|
||||
let output = |guest: &mut Guest, symbol: &str| {
|
||||
guest.memory.write_u64(SCRATCH, 0).unwrap();
|
||||
guest.call(symbol, &[SCRATCH]);
|
||||
guest.u64_at(SCRATCH)
|
||||
};
|
||||
Reading {
|
||||
counter: output(guest, "QueryPerformanceCounter"),
|
||||
frequency: output(guest, "QueryPerformanceFrequency"),
|
||||
interrupt: output(guest, "QueryUnbiasedInterruptTime"),
|
||||
filetime: output(guest, "GetSystemTimeAsFileTime"),
|
||||
tick: guest.call("GetTickCount", &[]),
|
||||
tick64: guest.call("GetTickCount64", &[]),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_time_service_reports_the_same_elapsed_time_in_its_own_unit() {
|
||||
let (mut guest, clock) = guest();
|
||||
// Uptime starts with the process; the counter and the calendar do not.
|
||||
assert_eq!(
|
||||
read(&mut guest),
|
||||
Reading {
|
||||
counter: 1_234,
|
||||
frequency: 10_000_000,
|
||||
tick: 0,
|
||||
tick64: 0,
|
||||
interrupt: 0,
|
||||
filetime: 134_399_972_960_001_234,
|
||||
}
|
||||
);
|
||||
|
||||
// 3 s + 7 ms + 3 intervals.
|
||||
clock.advance(30_070_003);
|
||||
let after = read(&mut guest);
|
||||
assert_eq!(
|
||||
after,
|
||||
Reading {
|
||||
counter: 30_071_237,
|
||||
frequency: 10_000_000,
|
||||
tick: 3_007,
|
||||
tick64: 3_007,
|
||||
interrupt: 30_070_003,
|
||||
filetime: 134_399_972_990_071_237,
|
||||
}
|
||||
);
|
||||
assert_eq!((after.counter - 1_234) / after.frequency, 3);
|
||||
|
||||
// A guest sleep is the same time as a host advance: 250 ms.
|
||||
assert_eq!(guest.call("Sleep", &[250]), 0);
|
||||
assert_eq!(
|
||||
read(&mut guest),
|
||||
Reading {
|
||||
counter: 32_571_237,
|
||||
frequency: 10_000_000,
|
||||
tick: 3_257,
|
||||
tick64: 3_257,
|
||||
interrupt: 32_570_003,
|
||||
filetime: 134_399_972_992_571_237,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_reading_decreases_up_to_and_past_the_end_of_the_clock() {
|
||||
let (mut guest, clock) = guest();
|
||||
let mut last = read(&mut guest);
|
||||
let steps = [
|
||||
0,
|
||||
1,
|
||||
9_998,
|
||||
1,
|
||||
10_000_000,
|
||||
1 << 40,
|
||||
i64::MAX as u64 / 2,
|
||||
i64::MAX as u64 / 2,
|
||||
u64::MAX / 2,
|
||||
u64::MAX,
|
||||
1,
|
||||
];
|
||||
for step in steps {
|
||||
clock.advance(step);
|
||||
let now = read(&mut guest);
|
||||
assert!(
|
||||
now.counter >= last.counter,
|
||||
"{step}: {now:?} after {last:?}"
|
||||
);
|
||||
assert!(now.tick64 >= last.tick64, "{step}: {now:?} after {last:?}");
|
||||
assert!(
|
||||
now.interrupt >= last.interrupt,
|
||||
"{step}: {now:?} after {last:?}"
|
||||
);
|
||||
assert!(
|
||||
now.filetime >= last.filetime,
|
||||
"{step}: {now:?} after {last:?}"
|
||||
);
|
||||
// The 32-bit count is the low half of the 64-bit one and may wrap.
|
||||
assert_eq!(now.tick, now.tick64 & 0xFFFF_FFFF, "{step}");
|
||||
assert_eq!(now.frequency, 10_000_000, "{step}");
|
||||
last = now;
|
||||
}
|
||||
|
||||
// Both readings stop at their maximum; neither wraps.
|
||||
let end = Reading {
|
||||
counter: 0x7FFF_FFFF_FFFF_FFFF,
|
||||
frequency: 10_000_000,
|
||||
// (2^63 - 1 - 1,234) intervals, in whole milliseconds.
|
||||
tick: 922_337_203_685_477 & 0xFFFF_FFFF,
|
||||
tick64: 922_337_203_685_477,
|
||||
interrupt: 0x7FFF_FFFF_FFFF_FFFF - 1_234,
|
||||
filetime: u64::MAX,
|
||||
};
|
||||
assert_eq!(last, end);
|
||||
|
||||
// Sleeping at the end of the clock still returns and changes nothing.
|
||||
assert_eq!(guest.call("Sleep", &[1]), 0);
|
||||
assert_eq!(read(&mut guest), end);
|
||||
}
|
||||
Reference in new issue
Block a user