Loader/TLS: use memchr::memmem SIMD scan in tls::patch #2954

Open
RVZO6 wants to merge 1 commit from upstream-pr/2956 into main
RVZO6 commented 2026-11-26 01:30:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T01:30:07Z.


Replace the byte-by-byte .text scan in crates/victory-loader/src/tls.rs::patch for mov r64, gs:[0x58] with memchr::memmem::Finder targeting the 5-byte [0x25, 0x58, 0, 0, 0] suffix, using the existing workspace memchr dependency.

Output is bit-identical to the bytewise scanner (verified by memmem_patch_matches_bytewise_oracle across mixed encodings, prefixes, false-positive suffixes, and boundary offsets).

Measured (--release, median of 3 runs)

  • bench_tls_patch_64mb (64 MiB buffer with 32,768 mov r64, gs:[0x58] sites): 39.79 ms → 5.51 ms (7.22×, -86.2%)

Verification

  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, --locked, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45734072839 (green, combined Wave 7 check on 63bcca4).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5502278925 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T01:30:07Z. --- Replace the byte-by-byte `.text` scan in `crates/victory-loader/src/tls.rs::patch` for `mov r64, gs:[0x58]` with `memchr::memmem::Finder` targeting the 5-byte `[0x25, 0x58, 0, 0, 0]` suffix, using the existing workspace `memchr` dependency. Output is bit-identical to the bytewise scanner (verified by `memmem_patch_matches_bytewise_oracle` across mixed encodings, prefixes, false-positive suffixes, and boundary offsets). ### Measured (`--release`, median of 3 runs) - `bench_tls_patch_64mb` (64 MiB buffer with 32,768 `mov r64, gs:[0x58]` sites): **39.79 ms → 5.51 ms (7.22×, -86.2%)** ### Verification - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, `--locked`, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45734072839](https://github.com/RVZO6/VIctory/actions/runs/45734072839) (green, combined Wave 7 check on `63bcca4`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
fuzeofficlal commented 2026-11-26 01:50:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:50:58Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 — clean, mathematically equivalent to the byte-by-byte scan, and ready to merge (note: functionally overlaps with #188's SSE2 scanner, and based on main without #1192's short/empty-section guard):

  • Reuses memchr = "2.8.3" already present in Cargo.lock (passes --locked with zero new external crates).
  • crates/victory-loader/src/tls.rs:78-115 searches for the 5-byte invariant tail [0x25, 0x58, 0, 0, 0] starting at pos = 4, recovers i = hit - 4, checks the exact same 9-byte pattern (LOAD_LEN = 9), and advances pos = i + LOAD_LEN + 4 on match or hit + 1 on mismatch — matching the previous scan byte-for-byte.

Local verification:

  • cargo test --locked -p victory-loader: 40/40 passed (36 unit + crash_log + load_probe + title_dlls)
  • cargo test --locked --release -p victory-loader --lib bench_tls_patch_64mb -- --ignored --nocapture: 2.20 ms
  • cargo clippy --locked -p victory-loader --tests -- -D warnings: 0 warnings
  • cargo xtask policy: 191 files ok
<!-- greyfinch-sync:Marvisak/VIctory:review:6067487148 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956#pullrequestreview-6067487148). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:50:58Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 — clean, mathematically equivalent to the byte-by-byte scan, and ready to merge (note: functionally overlaps with #188's SSE2 scanner, and based on `main` without #1192's short/empty-section guard): - Reuses `memchr = "2.8.3"` already present in `Cargo.lock` (passes `--locked` with zero new external crates). - `crates/victory-loader/src/tls.rs:78-115` searches for the 5-byte invariant tail `[0x25, 0x58, 0, 0, 0]` starting at `pos = 4`, recovers `i = hit - 4`, checks the exact same 9-byte pattern (`LOAD_LEN = 9`), and advances `pos = i + LOAD_LEN + 4` on match or `hit + 1` on mismatch — matching the previous scan byte-for-byte. **Local verification**: - `cargo test --locked -p victory-loader`: **40/40 passed** (`36` unit + `crash_log` + `load_probe` + `title_dlls`) - `cargo test --locked --release -p victory-loader --lib bench_tls_patch_64mb -- --ignored --nocapture`: **`2.20 ms`** - `cargo clippy --locked -p victory-loader --tests -- -D warnings`: 0 warnings - `cargo xtask policy`: 191 files ok
kotekompotek commented 2026-11-26 02:24:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:24:18Z.

Review: COMMENTED


Verified the scan equivalence: needle starts at pos>=4 so hit-4 can't underflow; the loop bound pos+5<=len preserves the old i+9<=len check; on-match pos=i+13 aligns with the next instruction's needle field, and non-match pos=hit+1 keeps overlapping-needle coverage identical to the bytewise oracle — which the test diffs byte-for-byte including the patched output. The len<LOAD_LEN early-out covers the code[pos..] slice.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067731274 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956#pullrequestreview-6067731274). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:24:18Z. **Review:** COMMENTED --- Verified the scan equivalence: needle starts at pos>=4 so hit-4 can't underflow; the loop bound pos+5<=len preserves the old i+9<=len check; on-match pos=i+13 aligns with the next instruction's needle field, and non-match pos=hit+1 keeps overlapping-needle coverage identical to the bytewise oracle — which the test diffs byte-for-byte including the patched output. The len<LOAD_LEN early-out covers the code[pos..] slice.
Marvisak commented 2026-11-26 06:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:47:14Z.


Automated triage for the maintainers.

Needs the maintainer's decision. Thanks for 47880d3. The benchmark and its figures from the title's binary are gone, and memmem_patch_matches_bytewise_oracle remains. I re-read tls::patch (crates/victory-loader/src/tls.rs): it is still equivalent to the byte-by-byte scan, and the code.len() < LOAD_LEN early return matches the old loop bound.

What's left is not a code issue. The PR adds memchr as a new dependency of victory-loader (Cargo.toml, Cargo.lock) to save about 35 ms once per launch, and whether that trade is worth it is the maintainer's call.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183804751 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7183804751). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:47:14Z. --- <!-- victory-triage v1 head=47880d38dc7ec09e65c7dda9ef184ec060a4ef3f verdict=needs-work at=2026-11-26T07:19:08Z --> Automated triage for the maintainers. **Needs the maintainer's decision.** Thanks for 47880d3. The benchmark and its figures from the title's binary are gone, and `memmem_patch_matches_bytewise_oracle` remains. I re-read `tls::patch` (`crates/victory-loader/src/tls.rs`): it is still equivalent to the byte-by-byte scan, and the `code.len() < LOAD_LEN` early return matches the old loop bound. What's left is not a code issue. The PR adds `memchr` as a new dependency of `victory-loader` (`Cargo.toml`, `Cargo.lock`) to save about 35 ms once per launch, and whether that trade is worth it is the maintainer's call. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
RVZO6 commented 2026-11-26 07:01:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T06:56:41Z.


Addressed triage feedback in 47880d3:

  • Removed the #[ignore] bench_tls_patch_64mb benchmark test and its comment referencing binary sizes/hit counts (docs/asset-policy.md), keeping memmem_patch_matches_bytewise_oracle.
  • Verified green on Windows MSVC + WARP SM 6.6 CI (run 45768895488): 37 passed, 0 failed in victory-loader, both clippy profiles, and xtask policy. Not run: the title; any hardware GPU.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7184937035 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7184937035). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T06:56:41Z. --- Addressed triage feedback in `47880d3`: - Removed the `#[ignore]` `bench_tls_patch_64mb` benchmark test and its comment referencing binary sizes/hit counts (`docs/asset-policy.md`), keeping `memmem_patch_matches_bytewise_oracle`. - Verified green on Windows MSVC + WARP SM 6.6 CI ([run 45768895488](https://github.com/RVZO6/VIctory/actions/runs/45768895488)): 37 passed, 0 failed in `victory-loader`, both clippy profiles, and `xtask policy`. **Not run:** the title; any hardware GPU.
futurepro62 commented 2026-11-26 20:30:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T20:30:19Z.


NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head 47880d3 (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo 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.
  • The new tests ran and passed: memmem_patch_matches_bytewise_oracle.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#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_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7202760925 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7202760925). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T20:30:19Z. --- NVIDIA full-suite run, to go with the reports above by fuzeofficlal, since none of them names a GPU run. Tested exact head `47880d3` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo 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**. - The new tests ran and passed: `memmem_patch_matches_bytewise_oracle`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#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_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
cloph-dsp commented 2026-11-26 23:37:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T23:37:10Z.


Independent Windows verification of PR #2956 (Loader/TLS: use memchr::memmem SIMD scan in tls::patch).

  • Head: 47880d3, base main, merge-base 63bcca4. OPEN, MERGEABLE/CLEAN, non-draft, no formal approval, no prior comment from me.
  • Toolchain: Windows, Rust 1.100.0/MSVC, cargo test --locked, worktree-local CARGO_TARGET_DIR, CARGO_BUILD_JOBS=2 (repo pins 1.98.1; no clippy/rustup). No game data, synthetic byte patterns only, GPU/driver N/A.
  • Command: cargo test --locked -p victory-loader --lib -- tls::tests::memmem_patch_matches_bytewise_oracle --exact --quiet
  • Result: test result: ok. 1 passed; 0 failed; 0 ignored; 35 filtered out.
  • git diff --check against merge-base 63bcca4: clean (exit 0).
  • Negative control: test name absent from origin/main (0 hits).

Note: I am aware of the existing triage: needs the maintainer's decision verdict; this comment reports only the local CPU test result and does not contest that verdict. Real title .text sections were not exercised.

AI-assisted (Hy4 flash). No game assets, extracted shaders, keys or DRM content used or uploaded.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205699627 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2956#issuecomment-7205699627). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T23:37:10Z. --- Independent Windows verification of PR #2956 (Loader/TLS: use memchr::memmem SIMD scan in tls::patch). - Head: `47880d3`, base `main`, merge-base `63bcca4`. OPEN, MERGEABLE/CLEAN, non-draft, no formal approval, no prior comment from me. - Toolchain: Windows, Rust 1.100.0/MSVC, `cargo test --locked`, worktree-local `CARGO_TARGET_DIR`, `CARGO_BUILD_JOBS=2` (repo pins 1.98.1; no clippy/rustup). No game data, synthetic byte patterns only, GPU/driver N/A. - Command: `cargo test --locked -p victory-loader --lib -- tls::tests::memmem_patch_matches_bytewise_oracle --exact --quiet` - Result: `test result: ok. 1 passed; 0 failed; 0 ignored; 35 filtered out`. - `git diff --check` against merge-base `63bcca4`: clean (exit 0). - Negative control: test name absent from `origin/main` (0 hits). Note: I am aware of the existing `triage: needs the maintainer's decision` verdict; this comment reports only the local CPU test result and does not contest that verdict. Real title `.text` sections were not exercised. AI-assisted (Hy4 flash). No game assets, extracted shaders, keys or DRM content used or uploaded.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2956:upstream-pr/2956'
git switch 'upstream-pr/2956'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/2956'
git switch 'upstream-pr/2956'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2956'
git switch 'upstream-pr/2956'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2956'
git switch 'main'
git merge --squash 'upstream-pr/2956'
git switch 'main'
git merge --ff-only 'upstream-pr/2956'
git switch 'main'
git merge 'upstream-pr/2956'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2954
No description provided.