Loader: clear XMM0 in ReturnZero thunk stubs for floating-point imports #2991
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2991
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-26 02:32 UTC · original
fuzeofficlal:fix/loader-thunks-zero-xmm0→main· +97 −5 · 1 files · 1 commits · openProblem
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.@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 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
@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 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
@cloph-dsp on GitHub · 2026-11-26 08:50 UTC · original
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.