Loader: a clwb in the last bytes of a page is emulated instead of faulting #941
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!941
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/941/head"
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?
@BastienRodz on GitHub · 2026-11-24 14:23 UTC · original
BastienRodz:loader/clwb-near-page-end→main· +68 −28 · 1 files · 1 commits · merged 2026-11-25 00:15 UTCWhat's wrong
As #924 describes,
emulate_amd_only(crates/victory-loader/src/crash.rs) copies only the bytes left in the faulting instruction's page, then callsclwb_lenonly when at least 15 were copied, becauseclwb_lentook a[u8; 15]:A
clwb m8is 4 to 10 bytes. One that starts in the last 14 bytes of a page is not emulated, and on Intel CPUs before Ice Lake the title dies withSTATUS_ILLEGAL_INSTRUCTION. The same happens to a write-back loop that straddles the page end:clwb_loopcannot match the cut bytes, and the single-instruction fallback is skipped too.What the fix does
clwb_lentakes&[u8], asclwb_loopalready does. It reads every byte throughfirst/get, so a prefix, ModRM, SIB or displacement past the slice givesNoneinstead of a panic. It returnsSome(len)only whenlen <= code.len().emulate_amd_onlydrops then >= 15guard and passes&bytes[..n]. The decoding is otherwise unchanged.Tests
crash::tests::clwb_lengths: the existing cases, now passing slices.crash::tests::a_clwb_at_the_end_of_a_page_is_decoded, which has three parts:Nonewithout panicking: disp32 6 of 8 bytes, disp8 4 of 5, SIB missing, SIB with disp32 cut short, ModRM missing, 1 byte, and empty.emulate_amd_onlyon a 4-byte and a 5-byteclwbplaced at the very end of a page, followed by aPAGE_NOACCESSpage, steps over each one.main, the page-endemulate_amd_onlycase fails atassert!(emulate_amd_only(&mut pointers)):n = 4 < 15skipsclwb_len, and the handler returnsfalse.On GitHub's
windows-latestwith the upstream CI's commands (clippy-D warningswith and without--all-features, thencargo test --workspace --locked), everything passes, andvictory-loaderhas 23 passed, 0 failed: https://github.com/BastienRodz/VIctory/actions/runs/45413158495On a real pre-Ice Lake CPU (@hadrianhola, comment): i7-5820K (Haswell-E, no
clwb), Windows 10, a realclwbraising#UDthrough the installed handler, placed in the last 4 and 5 bytes of a page. Onmainthe process dies with0xc000001d. With this PR it passes, 10 of 10 runs. The control, the sameclwbmid-page, passes on both.No game data used. AI-assisted: implemented with Gemini 4 Neon, reviewed and verified with Claude Code.
Fixes #924.
🤖 Generated with Claude Code
@Zipettte on GitHub · 2026-11-24 15:40 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
60d2cf9:cargo test -p victory-loaderpasses, 26 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@hadrianhola on GitHub · 2026-11-24 18:39 UTC · original
Tested on a real pre-Ice Lake CPU: Intel Core i7-5820K (Haswell-E; CPUID leaf 7 EBX bit 24 = 0, so no
clwb), Windows 10 22H2 (19045.7846), Rust 1.98.1, debug. No game data used.The tests in this PR call
emulate_amd_onlywith a built context, so I added a local test (not part of this PR) that runs a realclwband lets the CPU raise#UDthrough the installed handler. TwoPAGE_EXECUTE_READWRITEpages; theclwb(66 0f ae 30and66 41 0f ae 31) sits in the last 4/5 bytes of the first page, withretas the first byte of the second, and is called on a local variable:mainffe310e, the sameclwbat page offset0x800(control)mainffe310e,clwbin the last bytes of the page0xc000001d(STATUS_ILLEGAL_INSTRUCTION)60d2cf9, merged ontoffe310etogether with #214 and #362), same casecargo test -p victory-loader --libon that merge: everything else passes exceptunwinds_like_the_system_walk, which fails the same way onmainhere (#742).The local test (in
crash.rs'smod tests)The control run is the same test with
page.add(0x800)for theclwband theretright after it.AI-assisted (Claude Code); run on my machine.