loader: stop clzero loop emulation before address wraparound #3254
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3256"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T14:46:43Z.
Depends on: #1633 (claim
CLZERO-WRAPAROUND; earlier PR #2555 closed unmerged).The emulated
clzeroloops advanced their line pointer withwrapping_add(0x40). If a loop's limit was nearu64::MAX, the pointer wrapped to a small address and the emulator kept zeroing lines instead of ending the pass. A smalladvance_linehelper now useschecked_addand both loops stop when the next line would wrap.Test:
crash::tests::clzero_loop_advance_stops_before_u64_wraparoundchecks the valid boundary (u64::MAX - 0x40→u64::MAX) and thatu64::MAX - 0x3fandu64::MAXare rejected, without touching invalid memory.Validation (Windows, Rust 1.100.0/MSVC, worktree-local
CARGO_TARGET_DIR):cargo test --locked -p victory-loader --lib -- clzero— 8 passed, 0 failed (existing loop tests unchanged).git diff --check— clean.origin/main.AI-assisted (Hy4 flash). Synthetic inputs only; no game assets, extracted shaders, logs or DRM material were used or uploaded.
Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T15:05:32Z.
Review: COMMENTED
Two things:
u64::MAX(reeledMarek closed it on that basis). Unless something has changed since, this guards an unreachable case; worth answering that triage note in the description.advance_lineis inserted betweenclzero's doc comment (/// # Safety …) andunsafe fn clzero, so the Safety section now documentsadvance_lineandclzerohas none. Moving the helper above that comment block fixes it.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:31:04Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64:
advance_line(checked_add(0x40)) in bothclzeroloop emulation paths cleanly stops beforeu64address wraparound instead of wrapping to low memory.cargo test -p victory-loader --lib crash:: -- --test-threads=1: 25 passed, 0 failed (includingclzero_loop_advance_stops_before_u64_wraparound).cargo clippy -p victory-loader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:29:07Z.
Windows 11,
63bcca4+ this PR:cargo test -p victory-loader: 36 passed / 0 failed (lib; unpatched63bcca4has 35), plus the integration suites (1 and 2 passed).crash::tests::clzero_loop_advance_stops_before_u64_wraparound.cargo clippy -p victory-loader --all-targets -- -D warnings: clean.The lib suite includes the earlier
clzero_loop_wrapping_ranges_do_not_overflow_and_fall_back_to_single_clwband the emulated-loop tests, which still pass withadvance_linereturningNoneat the wrap. Synthetic only. AI-assisted.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:28:30Z.
Review: CHANGES_REQUESTED
Tested
d990cd7abea3637964677d18bb68551e795377e3withcargo xtask policy,cargo clippy --tests -p victory-loader -- -D warnings, andcargo test --locked -p victory-loader(40/40 pass).Two issues in
crates/victory-loader/src/crash.rsneed to be addressed before merging:Second
clzeroloop skips the final in-bounds cache line on wraparound, and both loops exit with inconsistent register/EFlagsstate (crates/victory-loader/src/crash.rs:414-426, 444-459)top: mov rax, a; add a, 0x40; clzero; cmp a, b; jb top, lines 444–459), supposenext = *gpr(context, a) = u64::MAX - 0x3fandlimit = u64::MAX. Line 447 seesnext < limit, line 450 overwritescontext.Rax = next, and line 451 breaks onadvance_line(next) == Nonebeforezero(next)ever runs, silently skipping the final in-bounds cache line ([u64::MAX - 0x3f ..= u64::MAX]) — asymmetric with the first loop, which callszero()beforeadvance_line().Nonestill executescontext.Rip += 12(line 425) /context.Rip += 8(line 458) to exit pastjb top, while leavingcontext.Rax/*gpr(context, a)un-advanced and settingEFlagswithCF = 1(cmp_flags(x, limit)wherex < limit), which is impossible after a non-takenjb.clwbwraparound convention (crash.rs:1083-1120,clwb_loop_wrapping_ranges_do_not_overflow_and_fall_back_to_single_clwb): when a loop's+ 0x40step would wrap, fall back to emulating just the singleclzeroinstruction (zero(context.Rax); context.Rip += 3; return true;— or break out tocontext.Rip += 3before mutatingcontext.Rax/a/EFlags) so the CPU executesadd; cmp; jbnatively with exact architectural state instead of fabricating a loop exit.Detached
/// # Safetydoc comment (crates/victory-loader/src/crash.rs:391-399)fn advance_line(rax: u64)was inserted directly betweenunsafe fn clzero's doc comment (lines 375–393, including/// # Safety) andunsafe fn clzero(line 399), attachingclzero's documentation and# Safetycontract to the safe helperadvance_lineand leavingunsafe fn clzeroundocumented. Please placeadvance_lineaboveclzero's doc comment (or afterclzero).Also,
clzero_loop_advance_stops_before_u64_wraparound(crash.rs:1304-1309) only exercisesu64::checked_add(0x40)directly rather than theclzeroloop fallback behavior.Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T23:31:13Z.
NVIDIA full-suite run, to go with the reports above by Dukestar69, Jackster, since none of them names a GPU run. Tested exact head
d990cd7(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.clzero_loop_advance_stops_before_u64_wraparound.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.