mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 13:30:43 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22b6da1865 | ||
|
|
2ea75603be | ||
|
|
6fc06dccff | ||
|
|
94732d90ca | ||
|
|
1e8893a6bf |
No files matched your search
@@ -32,6 +32,7 @@ remains unsupported.
|
||||
- Added a Python 3 fallback for `timeout` in `scripts/test-gpu.sh`, so the native Metal suite runs on stock macOS without GNU coreutils while preserving bounded execution and the usual timeout exit status.
|
||||
|
||||
### 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 opt-in shader IR constant folding (`CompileOptions::fold_constants` / `compile_with`) for pure vector unary and binary ops whose operands are already constants (#141). Floating-point ops still use the exact positive-normal rules; loads, stores, lane masks, merges and branches are never folded. Default `compile` keeps the historical IR. Covered by hand-computed known-answer compiler tests (shifts by 32/33, ashr, min_i32 vs min_u32, mul_hi_i32_i24, ffbh_i32, exact float fold, load-derived float non-fold, and verify rejection of inexact constant float add) with a fold-on versus fold-off check, plus an MSL template drift check over every foldable op.
|
||||
- The loader now maps an image's PE headers at its image base (#333): the first `SizeOfHeaders` bytes of the file, read-only, in whole 4 KiB pages that are zero past `SizeOfHeaders`. Programs read their own headers this way; the mingw-w64 C runtime does so before `main`, and until now that read faulted. When startup relocates an image it writes the load base into the mapped `ImageBase` field after the relocations, so an entry aimed at that field cannot move it twice; this is Xenora's policy and has not been compared with Windows. A load is refused with the new `PeError::InvalidHeaderSize` when `SizeOfHeaders` is zero, ends before the section table, runs past the file, or its pages would reach into a section, and when the bytes handed to the loader are not the PE32+ headers that were parsed. The page rule refuses images with sub-page section alignment whose first section starts inside the header page, which loaded before. The header pages count toward the 256 MiB mapping budget, which is checked before anything is mapped. `ParsedPe::parse` and the static probe are unchanged. `tests/pe_headers.rs` covers guest reads at the preferred and a relocated base, a relocation aimed at `ImageBase`, the write and execute faults and each refusal with original hand-built images; the image in `pe_mapping_limits.rs` now carries a valid `SizeOfHeaders`. Awaiting independent re-review.
|
||||
- Added 35 known-answer cases for MOV with an immediate operand, opcodes C6 /0 and C7 /0 (#194), to `cpu_known_answers.rs`: byte, word, dword and qword stores through base, SIB, R12, R13, RSP and RBP addressing with 8-bit and 32-bit displacements; the imm32 sign extension of the 64-bit form; the register forms, including AH and a REX-selected SIL; unmapped and read-only store faults at each width; and #UD for reg field 1. Expected values come from the Intel SDM and were worked out by hand. The interpreter and the DBT already agreed with all of them, so this is new coverage and fixes no defect. The 16-bit forms covered are those that already run, and #118 stays open. Not compared with x86 hardware; awaiting independent review.
|
||||
@@ -230,6 +231,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).
|
||||
- Fixed `DuplicateHandle` and `GetThreadId` naming the main thread from other guest threads, `OwningThread` in critical sections always holding the main thread's ID, the callback-depth limit being shared by all guest threads, and pending one-time initializations being unbounded.
|
||||
- Fixed the address reported when a guest memory access faults part-way across a 4 KiB page boundary (#175). An access that starts in a mapped page and runs into an unmapped or forbidden one now reports the first byte it may not touch; it used to report the start of the access. An access whose first byte fails reports the same address as before, and a failed access still reads and writes nothing. Three Intel SDM page-fault cases in `cpu_known_answers.rs` moved from open defect to verified on both engines. `crates/loader/tests/memory_page_boundaries.rs` checks permissions, adjacent pages, address overflow and the fault address at every 4 KiB guest boundary across two host pages (16 KiB each on Apple Silicon). Guest memory is checked in software, so the host page size does not affect these results. Four #82 expectations and one CRT `memmove` expectation that pinned the start address were corrected. Not compared with x86 hardware; awaiting independent review.
|
||||
- Fixed the native dependency audit reading Cargo JSON and inspection-tool output in the process locale encoding; it now reads and reports UTF-8 paths and diagnostics under an ASCII locale (#363).
|
||||
|
||||
@@ -95,8 +95,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