Repository navigation
Port upstream #941: a clwb in the last bytes of a page is emulated instead of faulting - #46
Merged
DesertGamer merged 1 commit intoNov 26, 2026
Conversation
…lting emulate_amd_only copies only the bytes left in the faulting page and gated clwb_len on n >= 15 because clwb_len took a fixed [u8; 15]. A 4- to 10-byte clwb starting in the last 14 bytes of a page (or falling back from a clwb_loop that straddles the page end) was therefore skipped, leaving pre-Ice Lake Intel CPUs with an unhandled STATUS_ILLEGAL_INSTRUCTION. Change clwb_len to take &[u8], bounds-checking each byte read and returning Some(len) only when len <= code.len(), and drop the n >= 15 guard in emulate_amd_only. Fixes #924. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 60d2cf9)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
This ports Marvisak/VIctory#941 by BastienRdz. It is cherry-picked with
-x, so the commit keeps their authorship.Intel CPUs before Ice Lake have no
clwband raiseSTATUS_ILLEGAL_INSTRUCTIONon it. The loader's handler incrates/viport-loader/src/crash.rsemulates the instruction as a no-op, because the PC's memory is coherent. It copies only the bytes left in the faulting page, since the next page may be unmapped. But it callsclwb_lenonly whenn >= 15, becauseclwb_lentakes a fixed[u8; 15].So a 4- to 10-byte
clwbthat starts in the last 14 bytes of a page is never emulated. The same happens when aclwb_loopthat straddles the page end falls back toclwb_len. The title then dies with an unhandled illegal instruction on those CPUs.The fix makes
clwb_lentake&[u8], bounds-check each byte it reads, and returnSome(len)only whenlen <= code.len(). Then >= 15gate is dropped. #941's tests come with it: exact-length and cut-short slices, plus an emulation at the last 4 and 5 bytes of a page followed by aPAGE_NOACCESSpage.VIPort has the upstream merge of #941 in its history, but the change is not in the tree. It was lost in a later merge. It applied cleanly.
Checked
docs/asset-policy.mdbuild.rs, git hook,.cargoconfig, CI change or script (or an issue explains why)cargo test --workspacepasses (not run, see below)cargo clippy --workspace --all-targets --locked -- -D warningspasses (Windows target, run on Linux)rustfmt; I did not reformat lines I did not changeWhat I ran
clwb_lencompiled standalone with the non-Windows asserts ofa_clwb_at_the_end_of_a_page_is_decoded(exact-length slices decode; cut-short ones returnNonewithout panicking): all pass.cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings, cross-checked from Linux on this branch (rebased on the currentmain): clean.cargo test -p viport-loader --lib --lockedon Linux also shows 4 failures inprepare::tests. They read the test binary as a PE, which it is only on Windows, and they fail the same way onmain.Not run: the page-end emulation part of the test, or a pre-Ice Lake Intel CPU. It needs Windows exception handling. The Windows CI test step will run it.
Overlaps
None. No open PR touches
viport-loader/src/crash.rs.🤖 Generated with Claude Code