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

Closed
github-bot wants to merge 1 commit from gh-pr/1773/head into gh-pr/1773/base
Owner

@⁠imjustprism on GitHub · 2026-11-24 22:19 UTC · original
imjustprism:fix/clzero-unwritable-line → main · +734 −39 · 1 files · 1 commits · closed without merging

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.

**@⁠imjustprism** on GitHub · 2026-11-24 22:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1773) `imjustprism:fix/clzero-unwritable-line` → `main` · +734 −39 · 1 files · 1 commits · closed without merging 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.
a store of the emulated write that faults is caught by the handler, and
its code and parameters go into the title's record, so later handlers see
the fault at the title's clzero. the clzero loops stop at the line that
faults, with the registers and flags their passes leave there.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:44:12 +00:00
github-bot closed this pull request 2026-11-26 04:44:12 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 22:23 UTC · original

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.

**@⁠DesertGamer** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7146174176) ### 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.*
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:21 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 06:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7154708218) <!-- 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)_
Author
Owner

@⁠imjustprism on GitHub · 2026-11-25 13:28 UTC · original

@⁠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.

**@⁠imjustprism** on GitHub · 2026-11-25 13:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7163829786) @⁠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.
Author
Owner

@⁠imjustprism on GitHub · 2026-11-25 14:49 UTC · original

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.

**@⁠imjustprism** on GitHub · 2026-11-25 14:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1773#issuecomment-7165877621) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1773
No description provided.