CI green again: clippy clean in both builds, budget tests follow VICTORY_INDIRECT_REST

CI on main stopped at its first step (clippy, 40+ findings), so the
diagnostics clippy and the tests never ran. Locally all three steps of
.github/workflows/ci.yml now pass.

Tests: two indirect budget tests still assumed VICTORY_INDIRECT_REST on,
which 545f890 turned off by default.
- host_list_budget_starts_empty_at_each_submission: the big records now
  fill the budget exactly, so the small record after them runs empty with
  REST on or off and the test still shows that no budget carries over.
- warp_batch_charges_every_execution: the expected spend follows the REST
  rule in force (a job that does not fit takes nothing without REST).
Both pass with VICTORY_INDIRECT_REST unset and =1.

Clippy:
- mechanical: is_multiple_of, shift precedence, sort_by_key with Reverse,
  hex digit groups, contains_key, annotated transmutes, mem::take,
  from_ref, a same-type cast, an if with identical branches;
- host/indirects.rs and placed_filler_twins are only used by the
  diagnostics build and are only compiled there;
- removed the never-used `batched` in make_from and the never-read
  depth_written field; Touch::Title is only built by tests, marked so;
- book.rs: the heap that keeps the descriptor alive is a named field;
- ResourceDesc::from_level(&self) renamed levels_from;
- allowed with a reason: two 8-argument functions, the Late enum (boxing
  a flight would allocate per flight) and the CLI Command enum;
- apps/victory: default_paths moved above the test module; the match on
  a block in play.rs binds the block first.

No change in what the game runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 7331b07bde8d7beca973f24a0575ca1866d034d4)
This commit is contained in:
Togicx authored and trustno1-coder committed 2026-11-27 17:51:24 -08:00
1 parent 800dada337
commit 9b712a6ab2
31 files changed
+102 -72

No files matched your search

+16 -14
View File
@@ -192,6 +192,8 @@ struct Cli {
command: Command,
}
// Parsed once at start: the size of its largest variant does not matter.
#[allow(clippy::large_enum_variant)]
#[derive(Subcommand)]
enum Command {
/// Summarise one PE image: headers, sections, imports, TLS, build id.
@@ -575,6 +577,20 @@ fn show_config() -> Result<()> {
Ok(())
}
/// Paths given on the command line, or the configured game + test titles.
pub(crate) fn default_paths(paths: Vec<PathBuf>) -> Result<Vec<PathBuf>> {
if !paths.is_empty() {
return Ok(paths);
}
let cfg = victory_core::Config::load()?;
let all: Vec<PathBuf> = cfg.game_dir.into_iter().chain(cfg.test_titles).collect();
anyhow::ensure!(
!all.is_empty(),
"no paths given and none configured (see victory.example.toml)"
);
Ok(all)
}
#[cfg(test)]
mod tests {
/// A D3D12Core.dll's VS_FIXEDFILEINFO: signature, structure version, then
@@ -611,17 +627,3 @@ mod tests {
assert_eq!(super::exported_sdk_version(b"MZ"), None);
}
}
/// Paths given on the command line, or the configured game + test titles.
pub(crate) fn default_paths(paths: Vec<PathBuf>) -> Result<Vec<PathBuf>> {
if !paths.is_empty() {
return Ok(paths);
}
let cfg = victory_core::Config::load()?;
let all: Vec<PathBuf> = cfg.game_dir.into_iter().chain(cfg.test_titles).collect();
anyhow::ensure!(
!all.is_empty(),
"no paths given and none configured (see victory.example.toml)"
);
Ok(all)
}
+11 -11
View File
@@ -730,20 +730,20 @@ fn check_shader_model() -> Result<()> {
};
if yes {
match fetch_d3d12(&to) {
Ok(()) => match {
Ok(()) => {
// This process is yet to load Direct3D 12: it asks for the file now there.
crate::match_d3d12_core();
shader_model()
} {
Some(now) if now >= needed => {
println!("Shader model {}.{} with Microsoft's runtime. Starting the game.", now.0, now.1);
return Ok(());
match shader_model() {
Some(now) if now >= needed => {
println!("Shader model {}.{} with Microsoft's runtime. Starting the game.", now.0, now.1);
return Ok(());
}
now => {
let now = now.unwrap_or(found);
println!("With Microsoft's runtime the GPU still runs shader model {}.{}.", now.0, now.1);
}
}
now => {
let now = now.unwrap_or(found);
println!("With Microsoft's runtime the GPU still runs shader model {}.{}.", now.0, now.1);
}
},
}
Err(e) => println!("{e:#}"),
}
}
+1 -1
View File
@@ -105,7 +105,7 @@ pub fn run(jobs: Option<usize>, limit: Option<usize>, again: bool, used: bool, t
state.0.push(ms);
state.1 += usize::from(!there);
let count = state.0.len();
if count % 1000 == 0 {
if count.is_multiple_of(1000) {
println!("{count} of {}, {:.0} s", all.len(), began.elapsed().as_secs_f64());
}
drop(state);
+1 -1
View File
@@ -1431,7 +1431,7 @@ mod tests {
let needs: Vec<u64> = (0..9).map(|mip| l.bytes_from(mip)).collect();
assert!(needs.windows(2).all(|w| w[0] >= w[1]), "{needs:?}");
assert!(needs[3] * 4 < l.size, "{needs:?}");
let tiled: Vec<u8> = (0..l.size).map(|i| (i * 7 >> 3) as u8).collect();
let tiled: Vec<u8> = (0..l.size).map(|i| ((i * 7) >> 3) as u8).collect();
for mip in 1..9 {
let m = l.mips[mip as usize];
let pitch = m.width as usize * 8;
+7 -3
View File
@@ -257,7 +257,11 @@ pub(crate) fn address(texture: &ID3D12Resource) -> Option<u64> {
/// The address of a texture: the base its descriptor has.
fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Option<u64> {
struct Slot(ID3D12DescriptorHeap, usize);
struct Slot {
/// Kept alive: `at` is in it.
_heap: ID3D12DescriptorHeap,
at: usize,
}
// SAFETY: a descriptor heap, used under the lock.
unsafe impl Send for Slot {}
static SLOT: Mutex<Option<Slot>> = Mutex::new(None);
@@ -278,9 +282,9 @@ fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Opti
.ok()?;
// SAFETY: a live heap.
let at = unsafe { heap.GetCPUDescriptorHandleForHeapStart().ptr };
*slot = Some(Slot(heap, at));
*slot = Some(Slot { _heap: heap, at });
}
let at = slot.as_ref()?.1;
let at = slot.as_ref()?.at;
let format = viewable(desc.Format.0)?;
let mut view = D3D12_SHADER_RESOURCE_VIEW_DESC {
Format: DXGI_FORMAT(format),
+1 -1
View File
@@ -1236,7 +1236,7 @@ pub(crate) fn log(frames: f64) {
);
tracing::info!(
"waits for the write trackers' locks per frame, all threads (number, time): {}",
crate::watch::lock_waits(frames as f64)
crate::watch::lock_waits(frames)
);
let [copies, blocks, opened, stores, unknown, full, stayed, copied_same, records] =
[0, 1, 2, 3, 4, 5, 6, 7, 8].map(|n| crate::titlewrite::DONE[n].load(std::sync::atomic::Ordering::Relaxed));
+2 -2
View File
@@ -1342,8 +1342,8 @@ impl Due {
fn ordered(self, max: usize) -> (Vec<(u32, u64)>, Vec<Option<Checked>>) {
let Due { mut again, mut fresh } = self;
// By the number of the write, counted over the run.
again.sort_unstable_by(|a, b| b.2.cmp(&a.2));
fresh.sort_unstable_by(|a, b| b.2.cmp(&a.2));
again.sort_unstable_by_key(|e| std::cmp::Reverse(e.2));
fresh.sort_unstable_by_key(|e| std::cmp::Reverse(e.2));
let mut order: Vec<(u32, u64)> = again.iter().map(|&(_, index, write, _)| (index, write)).collect();
let mut known: Vec<Option<Checked>> = again.iter().map(|a| a.3).collect();
let (mut new, mut old) = (0, fresh.len());
+2 -2
View File
@@ -1979,7 +1979,7 @@ impl State {
} else {
crate::memory::Use::Reads
};
let Some(ready) = self.memory_ready(list, &t, compute, use_) else {
let Some(ready) = self.memory_ready(list, t, compute, use_) else {
once!("a shader that reads title memory by address without a view heap to hold its views: the draw is dropped");
return false;
};
@@ -4410,7 +4410,7 @@ impl State {
let draws: u32 = census.1.values().sum();
if draws > 0 {
let mut rects: Vec<([i32; 4], u32)> = census.1.iter().map(|(r, n)| (*r, *n)).collect();
rects.sort_unstable_by(|a, b| b.1.cmp(&a.1));
rects.sort_unstable_by_key(|r| std::cmp::Reverse(r.1));
let scissors: Vec<String> = rects
.iter()
.take(5)
+8 -2
View File
@@ -3095,6 +3095,9 @@ struct Flight {
}
/// One thing in the line of what waits for the card, in order.
// A flight is far larger than the other variants; boxing it would add an
// allocation per flight on the submission path, so it stays inline.
#[allow(clippy::large_enum_variant)]
enum Late {
Run(Flight),
/// A bottom-of-pipe write of the flight before it: address, what, bytes.
@@ -3321,7 +3324,7 @@ fn blame_stale(stale: &[(std::sync::Arc<crate::shadow::Shadow>, usize, usize)])
/// title memory read, took `us`.
#[cfg(feature = "diagnostics")]
fn blamed(why: usize, us: u64) {
let (named, refused) = std::mem::replace(&mut *BLAMED.lock().unwrap_or_else(|e| e.into_inner()), (None, ""));
let (named, refused) = std::mem::take(&mut *BLAMED.lock().unwrap_or_else(|e| e.into_inner()));
let (key, at) = match (why, named) {
(WHY_READ | WHY_STALE, Some(named)) => named,
(WHY_READ, None) => (("a host copy of what a copy done on the card wrote", refused, 0, 0, 0), 0),
@@ -4193,6 +4196,7 @@ fn late_line(frames: f64) {
pub(crate) mod aside;
pub(crate) mod awake;
mod card_steps;
#[cfg(feature = "diagnostics")]
pub(crate) mod indirects;
mod font;
mod menu;
@@ -8638,7 +8642,9 @@ enum Touch {
Refresh(usize, usize, usize),
/// The copy is given to shaders.
Write(usize),
/// Title memory is written.
/// Title memory is written. The callers stop their walk there instead
/// (`refresh_ahead`); the tests of [`written_spans`] use it.
#[cfg_attr(not(test), allow(dead_code))]
Title,
Nothing,
/// Another part of the submission begins.
+1 -1
View File
@@ -32,7 +32,7 @@ const SHORT: usize = 256;
/// Whether a run of `len` bytes at offset `at` of a copy goes as pairs.
fn short(at: usize, len: usize) -> bool {
len <= SHORT && at % 4 == 0 && len % 4 == 0
len <= SHORT && at.is_multiple_of(4) && len.is_multiple_of(4)
}
/// Whether a run of `len` bytes at offset `at` of a copy in the card's memory
+19 -7
View File
@@ -305,8 +305,6 @@ fn rest() -> u32 {
/// The clamp compiled from `source` (ours, or in the benchmark the one it
/// replaced).
fn make_from(device: &ID3D12Device, source: &str) -> windows::core::Result<Clamp> {
#[cfg(feature = "diagnostics")]
let batched = source == batch::SOURCE;
let source = &format!("#define WIDEST {}u\n#define REST {}\n{source}", widest(amd(device)), rest());
let mut code: Option<ID3DBlob> = None;
let mut errors: Option<ID3DBlob> = None;
@@ -2697,7 +2695,10 @@ void main(uint3 g : SV_GroupID, uint i : SV_GroupIndex) {
}
sig.unwrap()
};
// Three records of 65,535 x 16 groups: about half the budget each.
// Two records of 65,535 x 16 groups (64 threads each, 2^26 - 2,048
// threads), then one of 32 groups (2,048 threads): together exactly
// the budget, so the small record after them does not fit whether
// or not a record that does not fit takes the rest (`rest`).
let Some((big, big_ptr)) = host.shared_buffer(3 * u64::from(STRIDE)) else {
return;
};
@@ -2710,7 +2711,7 @@ void main(uint3 g : SV_GroupID, uint i : SV_GroupIndex) {
// SAFETY: mapped buffers of these sizes; nothing runs yet.
unsafe {
for i in 0..3 {
let words = [65535u32, 16, 1];
let words = if i < 2 { [65535u32, 16, 1] } else { [32, 1, 1] };
std::ptr::copy_nonoverlapping(
words.as_ptr().cast::<u8>(),
big_ptr.add(i * STRIDE as usize),
@@ -3193,7 +3194,20 @@ void main(uint3 group : SV_GroupID, uint3 thread : SV_DispatchThreadID) {
};
assert_eq!(out.iter().filter(|&&v| v == 1 << 22).count(), filled, "{times} times {records}: {out:?}");
assert!(out.iter().all(|&v| v == 0 || v == 1 << 22));
assert_eq!(spent, BUDGET.min((1 << 26) * times * records as u32));
// Each record's job charges 2^26 for every execution, in order:
// one that does not fit takes the rest with `REST`, else nothing.
let rest = super::rest() != 0;
let expected = (0..records).fold(0u32, |at, _| {
let cost = (1u32 << 26) * times;
if BUDGET - at >= cost {
at + cost
} else if rest {
BUDGET
} else {
at
}
});
assert_eq!(spent, expected, "{times} times {records}");
}
}
@@ -3530,7 +3544,6 @@ void work() {
heap_pairs: [[Option<ID3D12DescriptorHeap>; 2]; 2],
tables: [D3D12_GPU_DESCRIPTOR_HANDLE; 2],
targets: [D3D12_CPU_DESCRIPTOR_HANDLE; 2],
depth_written: D3D12_CPU_DESCRIPTOR_HANDLE,
depth_tested: D3D12_CPU_DESCRIPTOR_HANDLE,
stamps: ID3D12QueryHeap,
back: ID3D12Resource,
@@ -3877,7 +3890,6 @@ void work() {
heap_pairs,
tables,
targets,
depth_written,
depth_tested,
stamps,
back,
+1
View File
@@ -572,6 +572,7 @@ pub(crate) unsafe fn piece(
///
/// # Safety
/// [`piece`]'s.
#[allow(clippy::too_many_arguments)]
unsafe fn piece_at(
title: usize,
now: *const u8,
+2 -2
View File
@@ -293,7 +293,7 @@ fn landings_beside_the_title_and_its_refreshes_lose_nothing() {
while !stop.load(Ordering::Relaxed) {
// Its own dwords, in every other block (in the rest
// only landings change anything).
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| i * 4 / BLOCK % 2 == 0) {
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| (i * 4 / BLOCK).is_multiple_of(2)) {
assert_eq!(dword(i).swap(value, Ordering::Relaxed), value - 1, "dword {i}: undone");
}
value += 1;
@@ -343,7 +343,7 @@ fn landings_beside_the_title_and_its_refreshes_lose_nothing() {
stop.store(true, Ordering::Relaxed);
for (w, writer) in writers.into_iter().enumerate() {
let last = writer.join().expect("nothing undone");
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| i * 4 / BLOCK % 2 == 0) {
for i in (w..LEN / 4).step_by(4 * 97).filter(|i| (i * 4 / BLOCK).is_multiple_of(2)) {
assert_eq!(dword(i).load(Ordering::Relaxed), last);
}
}
+1 -1
View File
@@ -970,7 +970,7 @@ mod tests {
fn a_target_is_the_one_at_the_call() {
let mut slot = [0x5256_5476u64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let kept = record(slot.as_ptr() as u64);
slot[1] = 99;
std::hint::black_box(&mut slot)[1] = 99;
assert_eq!(kept[1], 2);
assert_eq!(record(0), [0; RECORD]);
}
+6 -2
View File
@@ -61,7 +61,9 @@ fn book() -> Option<&'static Mutex<Book>> {
let mut keys = HashSet::new();
let mut shaders = HashSet::new();
let ends = [
walk_shaders(&dir, |_, hash, _, _| drop(shaders.insert(hash))),
walk_shaders(&dir, |_, hash, _, _| {
shaders.insert(hash);
}),
walk_pipelines(&dir, |_, bytes| {
keys.extend(bytes.first_chunk::<16>().copied());
}),
@@ -234,7 +236,9 @@ pub fn keep_library() {
/// there is one.
pub fn make(dir: &Path, which: &[usize], mut each: impl FnMut(usize, Option<(f64, bool)>)) {
let mut places = HashMap::new();
walk_shaders(dir, |stage, hash, at, len| drop(places.insert(hash, (stage, at, len))));
walk_shaders(dir, |stage, hash, at, len| {
places.insert(hash, (stage, at, len));
});
let Ok(mut file) = std::fs::File::open(dir.join(SHADERS)) else { return };
let wanted: HashSet<usize> = which.iter().copied().collect();
let mut entries = HashMap::new();
+1 -1
View File
@@ -326,7 +326,7 @@ mod tests {
let low = |at: u64, len: u64| at.checked_add(len).is_some_and(|end| end <= LOW && len > 0);
assert!(low(0x34e1_0000, 0xae0_0000));
assert!(!low(0xffff_0000, 0x2_0000));
assert!(!low(0xe1c80_0000, 0x1000));
assert!(!low(0x000e_1c80_0000, 0x1000));
assert!(!low(u64::MAX, 2));
}
+1 -1
View File
@@ -1377,7 +1377,7 @@ mod tests {
#[test]
fn a_pair_of_timestamps_shows_the_load_it_is_given() {
let (start, end) = (0xd0419_6698, 0xd0419_6690);
let (start, end) = (0x000d_0419_6698, 0x000d_0419_6690);
assert_eq!(as_loaded(5_000_000, end, 4_000_000) - as_loaded(5_000_000, start, 4_000_000), 4_000_000);
assert_eq!(as_loaded(5_000_000, start, 0), 5_000_000);
assert_eq!(as_loaded(5, start, 100), 1);
+1 -1
View File
@@ -3154,7 +3154,7 @@ impl Player {
continue;
}
for l in all {
self.worker.queue.ExecuteCommandLists(&[l.clone()]);
self.worker.queue.ExecuteCommandLists(std::slice::from_ref(l));
self.worker.idle()?;
}
}
@@ -1212,7 +1212,7 @@ impl Player {
word(if s.kind == slot::SRV { 4 } else { 2 }),
word(if s.kind == slot::SRV { 6 } else { 4 }),
word(if s.kind == slot::SRV { 7 } else { 5 }),
word(if s.kind == slot::SRV { 8 } else { 8 }),
word(8),
),
}
}
+1 -1
View File
@@ -277,7 +277,7 @@ impl Player {
.map(|i| (all[i * 3 + 2], i))
.filter(|w| w.0 > 0)
.collect();
worst.sort_by(|a, b| b.0.cmp(&a.0));
worst.sort_by_key(|w| std::cmp::Reverse(w.0));
for (n, i) in worst.into_iter().take(8) {
let (id, at, len) = calls[i];
out.push(format!(
@@ -488,6 +488,7 @@ impl Player {
/// The commands that copy the texels of `spots` to [`PROBE`] from `first`
/// on; `copied`: a copy to them went before.
#[allow(clippy::too_many_arguments)]
fn take(
&self,
spots: &[Spot],
+3 -3
View File
@@ -101,7 +101,7 @@ pub(crate) struct ResourceDesc {
#[cfg(windows)]
impl ResourceDesc {
/// The texture of this one's levels from `base` on.
fn from_level(&self, base: u32) -> ResourceDesc {
fn levels_from(&self, base: u32) -> ResourceDesc {
let mut d = *self;
if base > 0 {
d.width = (d.width >> base).max(1);
@@ -1765,7 +1765,7 @@ fn hosted(this: This, make: bool) -> Option<Made> {
}
let texture = match texture {
Some(texture) => Some(texture),
None => host_texture(&r.desc.from_level(base), r.host.state, clear),
None => host_texture(&r.desc.levels_from(base), r.host.state, clear),
};
let Some(texture) = texture else {
r.host.refused.store(true, Relaxed);
@@ -3076,7 +3076,7 @@ fn host_texture_as(
}
};
if let Err(e) = &made {
crate::residency::allocation_error(&e);
crate::residency::allocation_error(e);
tracing::warn!(error = %e, desc = ?d, reserved, "no host texture");
}
if !reserved
+2 -2
View File
@@ -2542,7 +2542,7 @@ fn dword_runs(at: usize, title: &[u8], merged: &[u8], gap: usize) -> Vec<(usize,
/// 12 MB this way and finds 80,000 runs.
fn word_runs(at: usize, title: &[u8], held: &[u8]) -> Vec<(usize, usize)> {
#[cfg(target_arch = "x86_64")]
if at % 4 == 0 && title.len() % 4 == 0 && title.len() == held.len() && std::arch::is_x86_feature_detected!("avx2") {
if at.is_multiple_of(4) && title.len().is_multiple_of(4) && title.len() == held.len() && std::arch::is_x86_feature_detected!("avx2") {
// SAFETY: the processor has AVX2, and the lengths are the same.
return unsafe { word_runs_avx2(title, held) };
}
@@ -5192,7 +5192,7 @@ mod land_tests {
});
let mut now = vec![0u8; LEN];
for round in 1..200u32 {
for block in (0..BLOCKS).filter(|b| (*b as u32 * 5 + round) % 3 != 0) {
for block in (0..BLOCKS).filter(|b| !(*b as u32 * 5 + round).is_multiple_of(3)) {
for i in (block * PIECE / 4 + 3..(block + 1) * PIECE / 4).step_by(4) {
now[i * 4..i * 4 + 4].copy_from_slice(&(round << 20 | i as u32).to_le_bytes());
}
+1 -1
View File
@@ -1802,7 +1802,7 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option<Presentin
if every > 0 {
static PRESENTS: AtomicU32 = AtomicU32::new(0);
let n = PRESENTS.fetch_add(1, Relaxed);
if n % every == 0 {
if n.is_multiple_of(every) {
set_framegen([2, 4, 0, 6][(n / every % 4) as usize]);
}
}
+1 -1
View File
@@ -2570,7 +2570,7 @@ mod allocation_costs {
seen.push(digest(&bytes));
}
}
let text: Vec<u8> = (0..400u32).map(|i| (i * 37 >> 2) as u8).collect();
let text: Vec<u8> = (0..400u32).map(|i| ((i * 37) >> 2) as u8).collect();
for at in 0..399 {
let mut bytes = text.clone();
bytes.swap(at, at + 1);
+1 -1
View File
@@ -604,7 +604,7 @@ mod tests {
f.extend([0x9c, 0x41, 0x5a, 0x48, 0x8b, 0x4c, 0x24, 0x28]);
f.extend([0x4c, 0x89, 0x11, 0x48, 0x89, 0x51, 0x08, 0x48, 0x89, 0x41, 0x10, 0xc3]);
type F = unsafe extern "system" fn(*mut u64, u64, u64, u64, *mut [u64; 3]);
let (there, operand, compared) = (spread(1), spread(2), if seed % 3 == 0 { spread(1) } else { spread(3) });
let (there, operand, compared) = (spread(1), spread(2), if seed.is_multiple_of(3) { spread(1) } else { spread(3) });
let flags = 0x202 | (spread(4) & 0x8d5) as u32;
let (mut memory, mut out) = (there, [0; 3]);
// SAFETY: the code above, which keeps to the calling convention.
+1 -1
View File
@@ -476,7 +476,7 @@ fn ask_early(every: std::time::Duration) {
idle = 0;
}
round += 1;
if round % 64 == 0 {
if round.is_multiple_of(64) {
hot.retain(|_, n| {
*n /= 2;
*n > 0
@@ -91,7 +91,7 @@ pub(super) struct Convolver {
impl Convolver {
/// `None` when the response is not in the layout described above.
pub(super) fn new(ir: &[f32]) -> Option<Self> {
if ir.is_empty() || ir.len() % N != 0 {
if ir.is_empty() || !ir.len().is_multiple_of(N) {
return None;
}
let mut blocks = ir.len() / N;
+2 -2
View File
@@ -439,7 +439,7 @@ fn read_direct(file: &std::fs::File, out: &mut [u8], offset: u64) -> std::io::Re
/// Read at a time.
const MOST: usize = 1 << 20;
let sector = SECTOR as u64;
if offset % sector == 0 && out.len() % SECTOR == 0 && out.as_ptr() as usize % SECTOR == 0 {
if offset.is_multiple_of(sector) && out.len().is_multiple_of(SECTOR) && (out.as_ptr() as usize).is_multiple_of(SECTOR) {
return read_overlapped(file, out, offset);
}
thread_local! {
@@ -2168,7 +2168,7 @@ mod tests {
for round in 0..2 {
for mode in [Io::One, Io::Handles, Io::Overlapped, Io::Direct] {
let file = Files::open_for_test(&path, mode);
let at: Vec<u64> = (0..READS).map(|_| random() % (len - SIZE as u64) & !15).collect();
let at: Vec<u64> = (0..READS).map(|_| (random() % (len - SIZE as u64)) & !15).collect();
for pass in ["cold", "again"] {
let next = std::sync::atomic::AtomicUsize::new(0);
let busy = AtomicU64::new(0);
+3 -3
View File
@@ -3155,7 +3155,7 @@ mod tests {
assert!(lazy(c));
assert_eq!(map_pages(c, 3, std::ptr::null(), true), c);
assert!(!lazy(c));
assert!(physical().views.get(&(c as usize)).is_none());
assert!(!physical().views.contains_key(&(c as usize)));
assert_eq!(host(c), MEM_RESERVE);
assert_eq!(map_pages(c, 3, pages.as_ptr(), false), c);
// SAFETY: mapped.
@@ -3166,7 +3166,7 @@ mod tests {
assert_eq!(map_pages(d, 3, pages.as_ptr(), true), d);
assert_eq!(map_pages(at(d, 1), 1, std::ptr::null(), true), at(d, 1));
assert!(lazy(d) && lazy(at(d, 2)));
assert!(physical().views.get(&(at(d, 1) as usize)).is_none());
assert!(!physical().views.contains_key(&(at(d, 1) as usize)));
assert!(materialize(at(d, 2) as usize, 1));
assert!(!lazy(at(d, 2)) && lazy(d));
// SAFETY: mapped now.
@@ -3259,7 +3259,7 @@ mod tests {
assert_eq!(read(heap, 1), ((true, 1), vec![2]));
// Unmapped: gone, with no view of the host's ever there.
assert!(alias_as((heap + PAGE) as u64, 0, PAGE as u64, false, true));
assert!(!lazy(heap + PAGE) && physical().views.get(&(heap + PAGE)).is_none());
assert!(!lazy(heap + PAGE) && !physical().views.contains_key(&(heap + PAGE)));
assert_eq!(soft_runs(heap, 4 * PAGE), [(heap, PAGE), (heap + 2 * PAGE, PAGE)]);
assert_eq!(read(heap + PAGE, 2 * PAGE).0, (false, PAGE));
// The CPU touches one: the handler maps it with its page's bytes,
+2 -2
View File
@@ -346,7 +346,7 @@ mod tests {
let list = format!("other.dll {:x}\nT.dll 0x{at:x}\nt.dll {at:x}\nt.dll 5\nt.dll\n", at);
assert_eq!(apply("t.dll", second, 0x1000, &list), 1);
assert_eq!(std::ptr::read((second + at) as *const u8), 0xe9);
let (plain, changed): (F, F) = (std::mem::transmute(place), std::mem::transmute(second));
let (plain, changed) = (std::mem::transmute::<usize, F>(place), std::mem::transmute::<usize, F>(second));
for was in 0..=255u8 {
let mut bytes = [[0u8; 0x40]; 2];
bytes[0][0x31] = was;
@@ -422,7 +422,7 @@ mod tests {
if size == 0 {
continue;
}
let (plain, changed): (F, F) = (std::mem::transmute(place), std::mem::transmute(second));
let (plain, changed) = (std::mem::transmute::<usize, F>(place), std::mem::transmute::<usize, F>(second));
let data = VirtualAlloc(std::ptr::null(), 4096, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE) as *mut u8;
for seed in 0..200u64 {
let value = seed.wrapping_mul(0x9e37_79b9_7f4a_7c15);