Loader: clear XMM0 in ReturnZero thunk stubs for floating-point imports #2991

Open
github-bot wants to merge 1 commit from github-bot/gh-2991 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 02:32 UTC · original
fuzeofficlal:fix/loader-thunks-zero-xmm0 → main · +97 −5 · 1 files · 1 commits · open

Problem

With --unimplemented zero (UnimplementedPolicy::ReturnZero), ThunkBlock::emit in crates/victory-loader/src/thunks.rs tail-jumped directly to unimplemented_import (extern "system" fn(&'static ImportSite) -> u64). That returns 0 in RAX only, leaving XMM0 unspecified per the Win64 ABI. Any missing import whose signature returns f32 or f64 therefore handed arbitrary floating-point register contents back to the title instead of 0.0.

Fix

  • On Windows x86-64, add a minimal global_asm! trampoline (victory_loader_return_zero) with Win64 shadow space, 16-byte stack alignment (sub rsp, 40), and .seh_proc/.seh_stackalloc 40/.seh_endprologue unwind metadata that calls handle_unimplemented_import, zeroes XMM0 with xorps xmm0, xmm0 (leaving RAX = 0 intact), and returns.
  • Route UnimplementedPolicy::ReturnZero stubs to the trampoline while keeping UnimplementedPolicy::Trap stubs tail-jumping directly to handle_unimplemented_import.

Verification

  • Added thunks::tests::return_zero_clears_integer_and_float_returns (child-process isolated), emitting a sealed ReturnZero thunk and invoking it through Win64 u64, f64 (seeded with 1.25 in XMM0), and f32 (seeded with -2.5 in XMM0) call signatures, asserting exact zero bit patterns (0, 0.0_f64, 0.0_f32) and call-counter increments.
  • cargo test --locked -p victory-loader: 40/40 passed.
  • cargo test --locked -p victory-loader --features diagnostics: 42/42 passed.
  • cargo clippy --locked -p victory-loader --tests -- -D warnings (default & --features diagnostics): 0 warnings.
  • cargo xtask policy: 191 files ok.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 02:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2991) `fuzeofficlal:fix/loader-thunks-zero-xmm0` → `main` · +97 −5 · 1 files · 1 commits · open ## Problem With `--unimplemented zero` (`UnimplementedPolicy::ReturnZero`), `ThunkBlock::emit` in `crates/victory-loader/src/thunks.rs` tail-jumped directly to `unimplemented_import` (`extern "system" fn(&'static ImportSite) -> u64`). That returns `0` in `RAX` only, leaving `XMM0` unspecified per the Win64 ABI. Any missing import whose signature returns `f32` or `f64` therefore handed arbitrary floating-point register contents back to the title instead of `0.0`. ## Fix - On Windows x86-64, add a minimal `global_asm!` trampoline (`victory_loader_return_zero`) with Win64 shadow space, 16-byte stack alignment (`sub rsp, 40`), and `.seh_proc`/`.seh_stackalloc 40`/`.seh_endprologue` unwind metadata that calls `handle_unimplemented_import`, zeroes `XMM0` with `xorps xmm0, xmm0` (leaving `RAX = 0` intact), and returns. - Route `UnimplementedPolicy::ReturnZero` stubs to the trampoline while keeping `UnimplementedPolicy::Trap` stubs tail-jumping directly to `handle_unimplemented_import`. ## Verification - Added `thunks::tests::return_zero_clears_integer_and_float_returns` (child-process isolated), emitting a sealed `ReturnZero` thunk and invoking it through Win64 `u64`, `f64` (seeded with `1.25` in `XMM0`), and `f32` (seeded with `-2.5` in `XMM0`) call signatures, asserting exact zero bit patterns (`0`, `0.0_f64`, `0.0_f32`) and call-counter increments. - `cargo test --locked -p victory-loader`: **40/40 passed**. - `cargo test --locked -p victory-loader --features diagnostics`: **42/42 passed**. - `cargo clippy --locked -p victory-loader --tests -- -D warnings` (default & `--features diagnostics`): 0 warnings. - `cargo xtask policy`: 191 files ok.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:31 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 04:53 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head c9b383c (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: return_zero_clears_integer_and_float_returns.
  • --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.
**@⁠futurepro62** on GitHub · 2026-11-26 04:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2991#issuecomment-7182996628) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `c9b383c` (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: `return_zero_clears_integer_and_float_returns`. - `--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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:29 UTC · original

Automated triage for the maintainers.

Under UnimplementedPolicy::ReturnZero, an unimplemented import returned 0 in RAX only, so imports returning f32/f64 gave the title whatever was in XMM0. In crates/victory-loader/src/thunks.rs, ThunkBlock::emit now routes ReturnZero stubs to a small global_asm! trampoline. The trampoline reserves 40 bytes (shadow space plus alignment, with matching .seh_stackalloc), calls the handler, clears XMM0 and returns. Trap stubs still jump straight to the handler. I checked the stack math: RSP is 8 mod 16 on entry and 16-aligned at the call. RCX still holds the site pointer the stub loaded. The test runs in a child process of the test binary, the same pattern a_trapped_import_is_in_the_crash_log already uses, and checks the u64, f64 and f32 returns plus the call counters. CI: passing.

Verdict: merge candidate. Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2991#issuecomment-7183537152) <!-- victory-triage v1 head=c9b383c7932f292db2de7cee58cac02646e14705 verdict=merge-candidate at=2026-11-26T05:29:38Z --> Automated triage for the maintainers. Under `UnimplementedPolicy::ReturnZero`, an unimplemented import returned 0 in RAX only, so imports returning `f32`/`f64` gave the title whatever was in XMM0. In `crates/victory-loader/src/thunks.rs`, `ThunkBlock::emit` now routes ReturnZero stubs to a small `global_asm!` trampoline. The trampoline reserves 40 bytes (shadow space plus alignment, with matching `.seh_stackalloc`), calls the handler, clears XMM0 and returns. Trap stubs still jump straight to the handler. I checked the stack math: RSP is 8 mod 16 on entry and 16-aligned at the call. RCX still holds the site pointer the stub loaded. The test runs in a child process of the test binary, the same pattern `a_trapped_import_is_in_the_crash_log` already uses, and checks the u64, f64 and f32 returns plus the call counters. CI: passing. **Verdict: merge candidate.** Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 08:50 UTC · original

Independent local verification of head c9b383c on Windows 11, Rust 1.100.0/MSVC:

  • cargo test --locked -p victory-loader --lib thunks::tests::return_zero_clears_integer_and_float_returns — 1 passed, 0 failed.
  • git diff --check origin/main HEAD — clean.

Synthetic child-process test; no game assets or DRM material used. AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2991#issuecomment-7187086798) Independent local verification of head `c9b383c` on Windows 11, Rust 1.100.0/MSVC: - `cargo test --locked -p victory-loader --lib thunks::tests::return_zero_clears_integer_and_float_returns` — 1 passed, 0 failed. - `git diff --check origin/main HEAD` — clean. Synthetic child-process test; no game assets or DRM material used. AI-assisted (Hy4 flash).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2991/head:github-bot/gh-2991'
git switch 'github-bot/gh-2991'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2991'
git switch 'github-bot/gh-2991'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2991'
git switch 'github-bot/gh-2991'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2991'
git switch 'main'
git merge --squash 'github-bot/gh-2991'
git switch 'main'
git merge --ff-only 'github-bot/gh-2991'
git switch 'main'
git merge 'github-bot/gh-2991'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2991
No description provided.