raise the fault of an emulated clzero at the title's instruction #1772

Closed
imjustprism wants to merge 1 commit from upstream-pr/1773 into main
imjustprism commented 2026-11-24 22:19:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-24T22:19:35Z.


an emulated clzero whose write faults (unwritable line, guard page, non-canonical rax) died inside our handler as a fatal crash at our own store, so a later handler never saw it and the report named the wrong address. the stores now sit in one small asm routine; a fault in it is caught and its code and parameters go into the title's record at its clzero, so later handlers see the fault the real instruction raises and can fix the page and retry.

rebased over #214: the two clzero loops go through the same routine and stop at the line that faults, with the registers and flags their passes leave there (nothing touched when the first line faults).

fault records of a single clzero were compared with a real clzero on a ryzen 7 9800x3d (zen 5); the loop state follows from the instruction order and was not compared with a real loop. zen 2 was not measured, and the handler has not run on an intel host; the tests reach it through a ud2 stub. handlers registered ahead of ours still only see the nested fault in our routine, and a clzero into the thread's own last stack guard page is not recovered. gate green on windows, 708 passed.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6592549167 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773). Originally posted by [imjustprism](https://github.com/imjustprism) on 2026-11-24T22:19:35Z. --- an emulated clzero whose write faults (unwritable line, guard page, non-canonical rax) died inside our handler as a fatal crash at our own store, so a later handler never saw it and the report named the wrong address. the stores now sit in one small asm routine; a fault in it is caught and its code and parameters go into the title's record at its clzero, so later handlers see the fault the real instruction raises and can fix the page and retry. rebased over #214: the two clzero loops go through the same routine and stop at the line that faults, with the registers and flags their passes leave there (nothing touched when the first line faults). fault records of a single clzero were compared with a real clzero on a ryzen 7 9800x3d (zen 5); the loop state follows from the instruction order and was not compared with a real loop. zen 2 was not measured, and the handler has not run on an intel host; the tests reach it through a ud2 stub. handlers registered ahead of ours still only see the nested fault in our routine, and a clzero into the thread's own last stack guard page is not recovered. gate green on windows, 708 passed.
DenRakEiw commented 2026-11-24 23:05:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T22:27:05Z.

Review: APPROVED


Verified locally merged onto origin/main (70564ae, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-loader — all 30 tests passed, 0 failed (including zero_line_zeroes_the_whole_line_that_holds_its_address, a_single_step_inside_the_line_stores_is_not_a_store_fault, and a_store_fault_keeps_its_whole_record)
  • cargo clippy -p victory-loader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean fault recovery and exception-record preservation for emulated clzero cache-line zeroing with thorough unit tests. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6048389660 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773#pullrequestreview-6048389660). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T22:27:05Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`70564ae`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-loader` — all 30 tests passed, 0 failed (including `zero_line_zeroes_the_whole_line_that_holds_its_address`, `a_single_step_inside_the_line_stores_is_not_a_store_fault`, and `a_store_fault_keeps_its_whole_record`) - `cargo clippy -p victory-loader --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean fault recovery and exception-record preservation for emulated `clzero` cache-line zeroing with thorough unit tests. Looks good. AI-assisted (Gemini 4 Neon).
DesertGamer commented 2026-11-24 23:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DesertGamer on 2026-11-24T22:23:39Z.


VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146174176 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7146174176). Originally posted by [DesertGamer](https://github.com/DesertGamer) on 2026-11-24T22:23:39Z. --- ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
catminou4 commented 2026-11-25 00:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:05:51Z.

Review: COMMENTED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae).

cargo test -p victory-loader --locked → 0 passed, 3 failed — the 3 failures are the PRE-EXISTING macOS loader ones (prepare::tests parse Mach-O as PE, broken on main for months), not this PR. Static read of the 28K diff: emulate_with_record + victory_zero_line raise the fault of an emulated clzero at the title's instruction pointer via AddVectoredExceptionHandler — the zero_line_zeroes_the_whole_line_that_holds_its_address test names the semantics. Windows-only path; a real clzero fault test on Windows would be the proof.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048826537 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773#pullrequestreview-6048826537). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T23:05:51Z. **Review:** COMMENTED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae). cargo test -p victory-loader --locked → 0 passed, 3 failed — the 3 failures are the PRE-EXISTING macOS loader ones (prepare::tests parse Mach-O as PE, broken on main for months), not this PR. Static read of the 28K diff: emulate_with_record + victory_zero_line raise the fault of an emulated clzero at the title's instruction pointer via AddVectoredExceptionHandler — the zero_line_zeroes_the_whole_line_that_holds_its_address test names the semantics. Windows-only path; a real clzero fault test on Windows would be the proof.
Marvisak commented 2026-11-25 07:03:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:21:30Z.


Automated triage for the maintainers.

Needs work. In crates/victory-loader/src/crash.rs, an emulated clzero that faults now hands its fault back to the title's exception record instead of faulting inside our handler. It does this with a global_asm! store routine (victory_zero_line) and a second recovery path (recover_line_fault) that rewrites Rip/Rdx when one of its stores faults. The goal makes sense. As it stands, though, it is hard to accept:

  • Two changes in one. Besides the fault path, the PR changes the flags the emulated loops leave: cmp_flags gains OF, there is a new add_flags, and flags are now set per pass. That is emulation behaviour, and the PR gives no evidence for it (the instruction-set reference for the exact loop sequence the title uses, or the title's own code at the loop). Please split it into its own PR with that evidence.
  • Risk against benefit. A fault during the emulated zeroing means the title wrote to memory it cannot write, so it crashes either way. What this changes is mainly where the crash is reported. For that, a hand-written asm recovery path in the vectored handler is a lot of new unsafe surface. Please say which case this fixes in practice: a guard-page touch the title relies on, or an in-page error it handles. A smaller design may then fit, such as probing the line with VirtualQuery before zeroing.
  • recover_line_fault trusts context.Rdx to point at the StoreFault slot. That holds only while the fault is inside victory_zero_line_stores..stored. Please add a comment or test that pins this.

CI: no check runs on the head commit.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154708218 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7154708218). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T06:21:30Z. --- <!-- victory-triage v1 head=962dd5ce607d903541069d6ae0bc746bb374efd6 verdict=needs-work at=2026-11-25T06:49:00Z --> Automated triage for the maintainers. **Needs work.** In `crates/victory-loader/src/crash.rs`, an emulated `clzero` that faults now hands its fault back to the title's exception record instead of faulting inside our handler. It does this with a `global_asm!` store routine (`victory_zero_line`) and a second recovery path (`recover_line_fault`) that rewrites `Rip`/`Rdx` when one of its stores faults. The goal makes sense. As it stands, though, it is hard to accept: - **Two changes in one.** Besides the fault path, the PR changes the flags the emulated loops leave: `cmp_flags` gains OF, there is a new `add_flags`, and flags are now set per pass. That is emulation behaviour, and the PR gives no evidence for it (the instruction-set reference for the exact loop sequence the title uses, or the title's own code at the loop). Please split it into its own PR with that evidence. - **Risk against benefit.** A fault during the emulated zeroing means the title wrote to memory it cannot write, so it crashes either way. What this changes is mainly where the crash is reported. For that, a hand-written asm recovery path in the vectored handler is a lot of new unsafe surface. Please say which case this fixes in practice: a guard-page touch the title relies on, or an in-page error it handles. A smaller design may then fit, such as probing the line with `VirtualQuery` before zeroing. - `recover_line_fault` trusts `context.Rdx` to point at the `StoreFault` slot. That holds only while the fault is inside `victory_zero_line_stores..stored`. Please add a comment or test that pins this. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
imjustprism commented 2026-11-25 14:07:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-25T13:28:29Z.


@Marvisak a question on the triage note before i rework this.

it asks to split the flags change into its own pull request. reading the diff again, a loop that runs to its end leaves the same flags as on main: cmp_flags already had OF there (the mask was 0x8d5 on main too, it is only renamed), its body moved into result_flags, and both loops still end with the flags of their last cmp. add_flags and the flags set on each pass are there only for a loop that stops at a line whose write faults, so the context shows what the title's instructions had done up to that clzero. compare_sets_flags_like_the_cpu and add_sets_flags_like_the_cpu check both helpers against the cpu's own cmp and add. split out, add_flags would have no caller. do you still want that part separate, or can it stay here?

the other two points (which case this fixes in practice, and pinning Rdx) i will answer here after checking what the title does around its clzero loops.

ci did run on 962dd5c and is green.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163829786 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7163829786). Originally posted by [imjustprism](https://github.com/imjustprism) on 2026-11-25T13:28:29Z. --- @Marvisak a question on the triage note before i rework this. it asks to split the flags change into its own pull request. reading the diff again, a loop that runs to its end leaves the same flags as on main: `cmp_flags` already had OF there (the mask was 0x8d5 on main too, it is only renamed), its body moved into `result_flags`, and both loops still end with the flags of their last `cmp`. `add_flags` and the flags set on each pass are there only for a loop that stops at a line whose write faults, so the context shows what the title's instructions had done up to that `clzero`. `compare_sets_flags_like_the_cpu` and `add_sets_flags_like_the_cpu` check both helpers against the cpu's own `cmp` and `add`. split out, `add_flags` would have no caller. do you still want that part separate, or can it stay here? the other two points (which case this fixes in practice, and pinning `Rdx`) i will answer here after checking what the title does around its clzero loops. ci did run on 962dd5c and is green.
upstream-sync closed this pull request 2026-11-25 15:02:25 +00:00
imjustprism commented 2026-11-25 15:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-25T14:49:41Z.


closing this one. while reviewing the shrunk version (a report line naming the title's instruction) i checked what the report already prints: its backtrace walks through the exception dispatcher back into the title, so the frame right after the ntdll frames is already the title's clzero. the extra line would only repeat that, at the cost of per-thread state in the handler.

the recovery path is off the table per the triage note, so nothing is left here. no need to answer my question above. thanks for the look.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165877621 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7165877621). Originally posted by [imjustprism](https://github.com/imjustprism) on 2026-11-25T14:49:41Z. --- closing this one. while reviewing the shrunk version (a report line naming the title's instruction) i checked what the report already prints: its backtrace walks through the exception dispatcher back into the title, so the frame right after the ntdll frames is already the title's clzero. the extra line would only repeat that, at the cost of per-thread state in the handler. the recovery path is off the table per the triage note, so nothing is left here. no need to answer my question above. thanks for the look.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!1772
No description provided.