fix(gpu/watch): restore read-write if open_unlocked races with VirtualProtect(PAGE_READONLY) #297
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: launcher
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
run report
security: hold
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs gpu test
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Androtim--MiniVI!297
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-297"
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?
@Androtim on GitHub · 2026-12-01 23:07 UTC · original
Androtim:fix/watch-protect-vs-open-unlocked-race→main· +130 −12 · 1 files · 1 commits · merged 2026-12-01 23:19 UTCSummary
Fixes the intermittent
STATUS_ACCESS_VIOLATION(0xc0000005) race incrates/victory-gpu/src/watch.rsreproduced in CI (land::tests::landings_beside_the_title_and_its_refreshes_lose_nothing).Root Cause
protect_hereandprotect_aliassetPROTECTED.set(block)before callingVirtualProtect(..., PAGE_READONLY).on_writesawPROTECTED == 1and enteredopen_unlocked(block): setOPENING(block) = 1, calledVirtualProtect(block, PAGE_READWRITE)beforeprotect_here/protect_alias'sVirtualProtect(PAGE_READONLY)completed, setOPEN_DONE(block) = 1, and queuedOpened { block }.protect_here/protect_aliasthen overwrote the block's protection back toPAGE_READONLYand insertedblockintog.protected.Opened { block }, removingblockfromg.protectedand clearingPROTECTED/OPENINGwithout restoringPAGE_READWRITE— leaving the block permanentlyPAGE_READONLYin Windows while untracked ing.protected, so the next write fault (AtomicU32::swapatland/tests.rs:297) fell throughon_writeasEXCEPTION_CONTINUE_SEARCH(0xc0000005).(Reproduced locally
2/100times under default settings and reliably underVICTORY_STORE_BESIDE=0; symbolized viaaddr2lineon0x989c29->core::sync::atomic::AtomicU32::swap.)Fix (
crates/victory-gpu/src/watch.rs)restore_rw_block(block)helper and a Dekker post-check afterVirtualProtect(..., PAGE_READONLY)in bothprotect_hereandprotect_alias:protect_here,!OPENING.any(from, to)adds zero extra syscalls on the uncontended path; if any block infrom..tohasOPENINGset, only the raced block is restored toPAGE_READWRITEand excluded fromg.protected/g.clean/PROTECTED.protect_here's per-block path andprotect_alias.open_unlocked, ifVirtualProtect(PAGE_READWRITE)fails or encounters non-RO/RW protection, undoTOLDandOPENINGand returnfalsewithout pushing a bogusOpenedrecord sosettlecannot stripg.protectedwithout unprotecting.protect_here_and_protect_alias_restore_rw_when_opening_races.Verification
cargo +1.98.1-x86_64-pc-windows-gnu xtask policy:asset policy: 319 files okcargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --locked watch:: -- --test-threads=1:56 passed; 0 failedcargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --locked land:: -- --test-threads=1:7 passed; 0 failed(1 ignoredbenchmark)land::tests::landings_beside_the_title_and_its_refreshes_lose_nothing --exact):100 / 100passed (0crashes)VICTORY_STORE_BESIDE=0:100 / 100passed (0crashes)cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --locked --all-targets -- -D warnings: 0 warningscargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --locked --all-targets --features diagnostics -- -D warnings: 0 warnings--release --bin MiniVI --locked: compiled cleanly,objdump -pimports standard Windows DLLs only.@Androtim on GitHub · 2026-12-01 23:18 UTC · original
Audited full diff (
1517a0a5) and Dekker ordering acrossopen_unlocked,protect_here,protect_alias, andsettle:gpreventssettlefrom clearingOPENINGwhileprotect_here/protect_aliasexecute, and theVirtualProtect(PAGE_READONLY)syscall orders the protection change before theOPENING.any(...)check.!OPENING.any(from, to)), clean rollback ofTOLD/OPENINGwhenVirtualProtect(PAGE_READWRITE)rejects non-RO/RW memory inopen_unlocked, and solid unit + 200-run stress verification (100/100default +100/100VICTORY_STORE_BESIDE=0).46766764774), no conflicts, zero newVICTORY_*toggles. Merging now.