clzero on a guarded line faults into the guard instead of ending the run #1380
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1380
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1380"
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?
@arbelonson-source on GitHub · 2026-11-26 19:38 UTC · original
arbelonson-source:clzero-protected-lines→main· +151 −13 · 1 files · 1 commits · merged 2026-11-26 23:06 UTCScenario
The
clzeroemulation inconsole_insn.rsdeclines a line thatwritablerefuses ("the real instruction faults there too"). On the console that fault is an access violation, and the write-watch guard's vectored handler (watch.rs, first in the chain) resolves it for a guarded block like any other store of the title. Here the exception isSTATUS_ILLEGAL_INSTRUCTION, which the guard never sees, so aclzeroon a guarded line is left unhandled and the run ends.Seen as
0xc000001don the 12-byte loopclzero; add rax, 40h; cmp rax, r10; jb(0f 01 fc 48 83 c0 40 4c 39 d0 72 f4), 22 minutes into the opening, on an Intel i9-9900K (no CLZERO). That run used a build derived from this tree (Kelvaroq 0.2.0, which has its own copy of the emulation with the same early return); the code path here is the same.Change
zero_through_fault). They fault, the guard opens the block, and they complete.writable_to's remembered regions already rely on this ("the write then faults inside the handler, which the guard on view memory opens").Proof
New test
clzero_on_guarded_or_uncommitted_lines_faults_into_the_runtime_s_handlers: a read-only line, a reserved line, and the 12-byte loop starting on reserved memory, with a stand-in handler at the front of the chain that opens the test's pages. Free memory is still refused.victory-loadertests 28/28 pass.zero_through_faultforced to refuse (the old behaviour): the new test fails at its first emulation.cargo clippy -p victory-loader --all-targets: no warnings.Tested by cross-building with
cargo xwin(Rust 1.98.1,x86_64-pc-windows-msvc) and running the test binary under Wine 11.22 on Linux. It has not been run on Windows.In the derived build, the same fix (to its own copy of the emulation) ran a 22-minute session in which 77 lines went through the fault; each had been a crash before.
@ -229,0 +255,4 @@for i in 0..8 {// SAFETY: see the function's contract; a fault here is resolved by the runtime's// handlers or ends the run, as the title's own store would.unsafe { words.add(i).write_volatile(0) };@JayFoxRox on GitHub · 2026-11-26 20:11 UTC · original
I believe this PR attempts to generate a fault for the emulated
clzeroinstruction for writes into guarded pages (as other subsystems like the GPU buffer update depend on it)?I think there's an issue with the planned instruction emulation where they will cause more page faults than a real CPU would.
A single 64 byte line clear (which would be a single page fault) must be emulated using multiple accesses (each of which could fail with its own page fault).
In #1305 I propose 2 views on most memory, where an all-access page could be used for every access except one, which goes through the normal page. That individual access could be used to trigger a real page fault (or just pass, no special handling necessary to separate the guard page case).
@ -396,4 +429,2 @@let a32 = code[..len - 3].contains(&0x67);let line = (if a32 { ctx.Rax & 0xFFFF_FFFF } else { ctx.Rax } as usize) & !63;if !writable(line, 64) {return 0; // the real instruction faults there too@JayFoxRox on GitHub · 2026-11-26 20:15 UTC · original · edited 2026-11-26 20:17 UTC
I think this entire PR bascially boils down to "this
writablecheck must be removed"?Just let the second fault handler deal with the page faults?
Why is all the other new code suddenly necessary?
It pretty much looks like the
zero_through_faultis the same asunsafe { std::ptr::write_bytes(line as *mut u8, 0, 64) };with extra steps and bloat.If there's an issue with double-faults, then look into #1363 which would avoid it (as emulated instructions would get patched into the game code, and run outside the exception handler/state).