loader: a clzero on free memory is left to the title #642

Open
qnjk wants to merge 1 commit from qnjk/Darner:clzero-legacy-claim into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the vectored handler asks the console-only instruction emulation first and, when it answers zero, falls through to the legacy emulate_amd_only. That zero means two different things — "not a console-only instruction" and "this one is the title's": a clzero whose line has nothing mapped at it, which console_insn's zero_through_fault declines so that the exception stays the title's. The 0f 01 fc arm then claimed the same fault, and clzero's first act is a blind 64-byte store into the line rax names: on free memory that store faults inside the vectored handler, at our own RIP, and the re-entered handler reports that fault instead of the instruction the title faulted on, whose own handlers never see it.

  • This change makes clzero ask the question zero_through_fault asks — is the line committed or reserved — and return false when nothing is mapped there, so the handler goes on to EXCEPTION_CONTINUE_SEARCH and the fault is left where the newer emulation meant it to be. Only the legacy paths ask it; every clzero the newer emulation handles returns before this one.

How it was tested

  • Tested revision: f0fae20 (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-loader --lib -- crash — 25 passed, 0 failed.
    • The new test frees a page and pins the shape: the one-line clzero and the 12-byte loop whose first line is that one are both refused. Fail-before, with the refusal taken out, the test's own store faults the test process (0xc0000005) — the defect itself, reproduced.
    • cargo clippy --locked -p darner-loader --all-targets -- -D warnings passes.
  • Changes a default: no. A clzero on a mapped line is emulated exactly as before; one on free memory is left to the title, which is what the newer emulation already decided.
  • A/B result: not applicable — no default change and no speed claim.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3: darner-loader's suite is green (25 crash tests among it); the whole-workspace run is not green on this machine for the pre-existing darner-gpu reasons (#224, #150), which this does not touch.
  • Gameplay, when relevant: no gameplay run. The fault needs a title that runs clzero on a page it then frees while the exception is pending; the test supplies that state directly.
  • Shader wave sizes tested, when relevant: not applicable (CPU-side emulation).
  • Hardware dependence: none.
  • Coverage gaps: only the 0f 01 fc single and the 12-byte loop shape are pinned; the other clzero forms in that report are untouched.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the shape is rare and the test reproduces the fault deterministically. No gameplay claim is made.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: passes).
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #493 changes crates/darner-loader/src/crash.rs; this change adds to the same file's clzero path only. The sibling fix for the loop recogniser (#593, mine, open) touches console_insn_decode.rs, not this file.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the vectored handler asks the console-only instruction emulation first and, when it answers zero, falls through to the legacy `emulate_amd_only`. That zero means two different things — "not a console-only instruction" and "this one is the title's": a `clzero` whose line has nothing mapped at it, which `console_insn`'s `zero_through_fault` declines so that the exception stays the title's. The `0f 01 fc` arm then claimed the same fault, and `clzero`'s first act is a blind 64-byte store into the line `rax` names: on free memory that store faults **inside** the vectored handler, at our own RIP, and the re-entered handler reports that fault instead of the instruction the title faulted on, whose own handlers never see it. - This change makes `clzero` ask the question `zero_through_fault` asks — is the line committed or reserved — and return false when nothing is mapped there, so the handler goes on to `EXCEPTION_CONTINUE_SEARCH` and the fault is left where the newer emulation meant it to be. Only the legacy paths ask it; every `clzero` the newer emulation handles returns before this one. ## How it was tested - Tested revision: `f0fae20` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-loader --lib -- crash` — 25 passed, 0 failed. - The new test frees a page and pins the shape: the one-line `clzero` and the 12-byte loop whose first line is that one are both refused. Fail-before, with the refusal taken out, the test's own store faults the test process (`0xc0000005`) — the defect itself, reproduced. - `cargo clippy --locked -p darner-loader --all-targets -- -D warnings` passes. - Changes a default: no. A `clzero` on a mapped line is emulated exactly as before; one on free memory is left to the title, which is what the newer emulation already decided. - A/B result: not applicable — no default change and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3: `darner-loader`'s suite is green (25 crash tests among it); the whole-workspace run is not green on this machine for the pre-existing `darner-gpu` reasons (#224, #150), which this does not touch. - Gameplay, when relevant: no gameplay run. The fault needs a title that runs `clzero` on a page it then frees while the exception is pending; the test supplies that state directly. - Shader wave sizes tested, when relevant: not applicable (CPU-side emulation). - Hardware dependence: none. - Coverage gaps: only the `0f 01 fc` single and the 12-byte loop shape are pinned; the other `clzero` forms in that report are untouched. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the shape is rare and the test reproduces the fault deterministically. No gameplay claim is made. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: passes). - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #493 changes `crates/darner-loader/src/crash.rs`; this change adds to the same file's `clzero` path only. The sibling fix for the loop recogniser (#593, mine, open) touches `console_insn_decode.rs`, not this file. - Replaces or overlaps: none found
The handler asks the console-only instruction emulation first and, when it answers
zero, falls through to `emulate_amd_only`. That zero means two different things:
"not a console-only instruction" and "this one is the title's" — a `clzero` whose
line has nothing mapped at it, which `console_insn`'s `zero_through_fault` declines
so that the exception stays the title's. The `0f 01 fc` arm then claimed the same
fault, and `clzero`'s first act is a blind 64-byte store into the line `rax` names:
on free memory that store faults inside the vectored handler, at our own RIP, and
the re-entered handler reports that fault in place of the instruction the title
faulted on, whose own handlers never see it.

`clzero` now asks the question `zero_through_fault` asks — committed or reserved at
the line — and returns false for a line with nothing mapped there, so the handler
goes on to `EXCEPTION_CONTINUE_SEARCH` and the fault is left where the newer
emulation already meant it to be. Only the legacy paths ask: every `clzero` the
newer emulation handles returns before this one.

The test frees a page and pins the shape: the one-line `clzero` and the 12-byte loop
whose first line is that one are both refused. With the refusal taken out the test's
store faults the test process (0xc0000005), the defect itself.
TrustNo1 changed title from [pr-fix][startup] loader: a clzero on free memory is left to the title to loader: a clzero on free memory is left to the title 2026-12-06 03:25:40 +00:00
Owner

Test needed — commit f0fae208; what to check:

  • The problem on main: the vectored handler asks the console-only instruction emulation first and, when it answers zero, falls through to the legacy emulate_amd_only. That zero means two different things — "not a console-only instruction" and "this one is the title's": a clzero whose line has nothing mapped at it, which console_insn's zero_through_fault declines so that the exception stays the title's. The 0f 01 fc arm then claimed the same fault, and clzero's first act is a blind 64-byte store into the line rax names: on free memory that store faults inside the vectored handler, at our own RIP, and the re-entered handler reports that fault instead of the instruction the title faulted on, whose own handlers never see it.

  • This change makes clzero ask the question zero_through_fault asks — is the line committed or reserved — and return false when nothing is mapped there, so the handler goes on to EXCEPTION_CONTINUE_SEARCH and the fault is left where the newer emulation meant it to be. Only the legacy paths ask it; every clzero the newer emulation handles returns before this one.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `f0fae208`; what to check: - The problem on main: the vectored handler asks the console-only instruction emulation first and, when it answers zero, falls through to the legacy `emulate_amd_only`. That zero means two different things — "not a console-only instruction" and "this one is the title's": a `clzero` whose line has nothing mapped at it, which `console_insn`'s `zero_through_fault` declines so that the exception stays the title's. The `0f 01 fc` arm then claimed the same fault, and `clzero`'s first act is a blind 64-byte store into the line `rax` names: on free memory that store faults **inside** the vectored handler, at our own RIP, and the re-entered handler reports that fault instead of the instruction the title faulted on, whose own handlers never see it. - This change makes `clzero` ask the question `zero_through_fault` asks — is the line committed or reserved — and return false when nothing is mapped there, so the handler goes on to `EXCEPTION_CONTINUE_SEARCH` and the fault is left where the newer emulation meant it to be. Only the legacy paths ask it; every `clzero` the newer emulation handles returns before this one. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 'clzero-legacy-claim:qnjk-clzero-legacy-claim'
git switch 'qnjk-clzero-legacy-claim'

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.

git switch 'Main'
git merge --no-ff 'qnjk-clzero-legacy-claim'
git switch 'qnjk-clzero-legacy-claim'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-clzero-legacy-claim'
git switch 'qnjk-clzero-legacy-claim'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-clzero-legacy-claim'
git switch 'Main'
git merge --squash 'qnjk-clzero-legacy-claim'
git switch 'Main'
git merge --ff-only 'qnjk-clzero-legacy-claim'
git switch 'Main'
git merge 'qnjk-clzero-legacy-claim'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!642
No description provided.