Loader/Prepare: zero-alloc block-filtered DIR64 relocation clearing for TLS callbacks #2980
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2982"
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 RVZO6 on 2026-11-26T02:09:04Z.
prepare()previously calleddir64_relocations(), which decoded everyIMAGE_REL_BASED_DIR64entry across the entire PE.reloctable into aVec<(usize, u32)>(hundreds of thousands to ~1M entries on a retail title executable) solely to clear the single entry targeting the TLSAddressOfCallBacksfield.Replace it with
clear_dir64_relocations(bytes, info, target_rva):.relocblock whose[page, page + 0xFFF]window does not containtarget_rvain O(1) without decoding its entries or allocating memory.u16comparison ((DIR64 << 12) | wanted_off).Measured (
--release bench_clear_dir64_relocations, median of 3 runs, 3,000 blocks × 250 entries × 50 iters)600.24 ms → 0.6024 ms(996×, -99.90%), zero heap allocations.Verification
--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45738573777 (green, combined Wave 8 check on63bcca4).clear_dir64_relocations_matches_full_scan_and_preserves_neighborscomparing bit-for-bit against the full-table scan across first/middle/last/absent blocks and non-DIR64entries; existingpatches_own_test_binarycontinues to verify with the full-table scan.AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:28:24Z.
Review: COMMENTED
Verified the equivalence: a block only decodes when target_rva lands in its page, and the exact u16 match (DIR64<<12 | offset) selects the same entries the full scan would. The saturating end clamp to bytes.len() is a small robustness win over the old code, and checked_add on field_rva turns a hypothetical overflow into a PrepareError. Oracle test diffs outputs byte-for-byte across first/middle/last/absent-page targets.
Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-26T02:44:38Z.
Independent Windows-target Wine check on a 16 GiB Linux host, exact head
46ebcb1f: relocation parity fixture 1/1 pass andpatches_own_test_binary1/1 pass. The ignored retail-sized synthetic benchmark (3,000 blocks × 250 entries × 50 iterations; debug build) printed old=1256.36 ms, new=19.2844 ms (65.1×). This did not instrument allocations or measure the late-title RAM peak; it does not yet establish that our guarded loading stop at 2,036 MiB available (2,048 MiB floor) is cleared. Logs.compat-runtime/logs/verify-pr2982-wine-{reloc-parity,patch-own-pe,reloc-bench}.log.Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T05:12:00Z.
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
46ebcb1(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, 11 ignored.clear_dir64_relocations_matches_full_scan_and_preserves_neighbors.--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
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:23:10Z.
Automated triage for the maintainers.
Needs work. Thanks for
ff0bf23. The benchmark is gone and there are edge cases foru32::MAXtargets and a corrupt block size.clear_dir64_relocations(crates/victory-loader/src/prepare.rs) still reads as equivalent to the old scan.The question from last time is still open. This step runs once per launch and costs about 12 ms, and no run shows an effect on startup time or peak memory. Without that, the PR replaces a simple scan with a more involved one and adds about 150 lines of test scaffolding: a hand-built PE and a reference scan. Note that this reference is not the removed code; it already includes the new checked arithmetic. The
corruptcase also has no assertion. If a startup-time or memory gain can't be shown, a much smaller PR with only thechecked_addon the TLS field RVA would be the part worth keeping.CI: passing (
check).Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T06:56:42Z.
Addressed triage feedback in
ff0bf23:#[ignore]bench_clear_dir64_relocationsmicrobenchmark from unit tests.target = u32::MAXand corruptblock_size = u32::MAX) toclear_dir64_relocations_matches_full_scan_and_preserves_neighbors.victory-loader, both clippy profiles, andxtask policy. Not run: the title; any hardware GPU.Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-27T05:11:07Z.
Independent CPU-only verification of PR #2982 (
Loader/Prepare: zero-alloc block-filtered DIR64 relocation clearing for TLS callbacks).CARGO_TARGET_DIR(D:\Victory-Contrib\target-2982-watch),CARGO_BUILD_JOBS=2.ff0bf23591052e69f3ac78c229f5d20223e5e37a, merge base63bcca43c6a00a758510398fa43096ce7e4f7df0.cargo test --locked -p victory-loader --lib -- prepare::tests::clear_dir64_relocations_matches_full_scan_and_preserves_neighbors --exact --test-threads=1 --quiet->1 passed; 0 failed; 35 filtered.git grep -Ffor the new test name on63bcca4returned no hits (test absent on base).git diff --check 63bcca4 HEADexit 0 (clean).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.