Loader: clear XMM0 in ReturnZero thunk stubs for floating-point imports #2989
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2991"
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 fuzeofficlal on 2026-11-26T02:32:22Z.
Problem
With
--unimplemented zero(UnimplementedPolicy::ReturnZero),ThunkBlock::emitincrates/victory-loader/src/thunks.rstail-jumped directly tounimplemented_import(extern "system" fn(&'static ImportSite) -> u64). That returns0inRAXonly, leavingXMM0unspecified per the Win64 ABI. Any missing import whose signature returnsf32orf64therefore handed arbitrary floating-point register contents back to the title instead of0.0.Fix
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_endprologueunwind metadata that callshandle_unimplemented_import, zeroesXMM0withxorps xmm0, xmm0(leavingRAX = 0intact), and returns.UnimplementedPolicy::ReturnZerostubs to the trampoline while keepingUnimplementedPolicy::Trapstubs tail-jumping directly tohandle_unimplemented_import.Verification
thunks::tests::return_zero_clears_integer_and_float_returns(child-process isolated), emitting a sealedReturnZerothunk and invoking it through Win64u64,f64(seeded with1.25inXMM0), andf32(seeded with-2.5inXMM0) 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.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:35:48Z.
Review: COMMENTED
Verified the stub: sub rsp,40 gives 32-byte shadow space plus 8 to realign RSP (entry rsp=8 mod 16, after sub =0 mod 16), xorps runs after the handler so RAX=0 and XMM0=0 both reach the caller, and the .seh directives keep the frame unwindable. Only the ReturnZero policy routes through it — Trap still calls the handler directly. The child-process test isolating the global counters is careful, and asserting both f64 and f32 returns as 0 bits covers the actual ABI hazard.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T04:53:44Z.
Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head
c9b383c(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.return_zero_clears_integer_and_float_returns.--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:29:49Z.
Automated triage for the maintainers.
Under
UnimplementedPolicy::ReturnZero, an unimplemented import returned 0 in RAX only, so imports returningf32/f64gave the title whatever was in XMM0. Incrates/victory-loader/src/thunks.rs,ThunkBlock::emitnow routes ReturnZero stubs to a smallglobal_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 patterna_trapped_import_is_in_the_crash_logalready 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
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:59:12Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-loader thunks::tests -- --test-threads=1: all tests passed (including the new XMM0-clearing ReturnZero thunk test).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 cloph-dsp on 2026-11-26T08:50:33Z.
Independent local verification of head
c9b383con 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).
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.