loader: VICTORY_TRAP_WRITES can be silent — arm loudly, report faults on a trapped page, round a watched address to its word #641
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS#641
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@AnastasisKon on GitHub · 2026-11-28 19:57 UTC · original
VICTORY_TRAP_WRITESis the diagnostic the boot investigation leans on (item 3, the SGD5 write trap), and in two diagnostics-build runs it logged nothing at all — including a control page this repo records as written once by the main thread (docs/native-host.md, theVICTORY_TRAP_WRITES=0x181796000,0x181796a28bullet). A silent trap is not a negative: today three different situations print exactly the same nothing.What was measured, rather than assumed
The fault record the trap discriminates on is sound on this machine. A store to a
PROT_READpage, delivered under Rosetta to an x86_64 handler, arrives withsi_code2 (SEGV_ACCERR) and__err0x6; the load of aPROT_NONEpage with__err0x4. The loader's synthesized record (crates/victory-loader/src/native/seh/signal.rs:630,information[0] = err & 2) therefore turns those into1(write) and0(read), andwrite_trap'sr.information[0] != 1check does not swallow writes.(The same source does not compile for the native arm64 host:
__darwin_arm_exception_state64has no__err. The title's x86_64 process is the one that matters, and it is the one measured.)So the cause is in the arms, not in the record. Three ways to get silence, all of them currently invisible:
start_write_trapcalledmprotect(page, 0x1000, PROT_READ)and dropped the result. A spec at the wrong base (the image is relocated; a VA from a different run, or an address outside the mapping) answersENOMEM, nothing is trapped, and the run reports no writer for a page that is written.write_traplogs only whenwatched.contains(&(at & !7)); every other fault on that page is dropped after re-opening it. "Page is written elsewhere" and "page is never written" read the same.mprotect(page, 0x1000, PROT_READ|PROT_WRITE)after a fault also dropped its result. If it fails, the faulting store faults again on return, forever: the run looks hung, and again nothing is logged.A fourth, smaller one:
parse_trap_specstored watched addresses as written, while the match looks atat & !7, so0x…a2ccould never match anything.The change (one PR)
start_write_trapsays what it armed, per page:write trap: <page> is read-only, N watched, orwrite trap: <page> is not mapped, so it is not trapped, or a note when the page is outside the title image (wrong base). Pages that did not arm are left out, so the closer thread does not spinmprotecton an unmapped page at 3 kHz (which on its own perturbs a profiling run).write_traplogs a fault on a trapped page named or not (the first eight unwatched ones), so "written elsewhere" is distinguishable from "never written".docs/native-host.mdcarries the measurement above with its command line.Two unit tests: the rounding/dedup of a spec, and arming a real anonymous page (arm, open, unmap, and the unmapped page must not arm) — the syscall path the silent runs depended on, exercised on this host.
This does not by itself say which of the three the two silent runs hit; it makes the next run say it in the first second, instead of after 30 s of nothing.
@AnastasisKon on GitHub · 2026-11-28 20:03 UTC · original
Duplicate of what PR #75 already does (and it does more: it ran the game on it, and it answers part of the writer-state question in docs/native-host.md). Everything still usable from my version — a watched address stored as written but compared at
at & !7, the dropped result of the open after a fault, and the measurement showing the x86__errdoes distinguish a write from a load under Rosetta — is in a comment on https://github.com/AnastasisKon/Native-Victory-macOS/pull/75 so it is not lost. No second PR.