hle: fix SRW wait race and order the native waits probe #31
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/31"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by shabouwcaw on 2026-11-26T10:40:38Z.
The native waits probe exposed two distinct problems: an SRW acquisition can sleep on an unlocked word after losing a CAS race, and the critical-section try check assumes its competing thread runs within 80 ms.
Addresses #20. The reported one-in-three failure rate was not reproduced; the failures and reproducer below are the evidence for this change.
srw_tryreloads the word. If the previous owner has released it,srw_acquirecould mark that available word withWAITERSand sleep indefinitely with nobody left to wake it. Retry acquisition when the observed state permits the requested ownership, including a reader joining other readers. Keep the existing compare/exchange and address-wait protocol for incompatible ownership.TryEnterCriticalSectionthread finishes. Remove the timed holder thread and event. Require successful thread completion, rejection while owned, and successful acquisition after release (so an always-failing stub cannot pass); retain the 5-second hang guard and stop before reusing worker state on failure.This follows the documented Windows SRW shared-reader/exclusive-writer semantics, without promising fairness.
docs/native-host.mdrecords the race and the architecture requirement.Validation on Apple Silicon, explicitly using
x86_64-apple-darwinunder Rosetta:98801860, exclusiveThe natural failure reported
probe_sync: missing bits 0x0040(shiftedT_SRW) after about 21 seconds; the delay reproducer consistently reported0x0020(T_CS_TRY). The SRW state regression demonstrates the deadlock path; the natural failure did not capture the internal lock word, so attributing that particular run to this path is an inference. Each stress batch used sixniceCPU workers, cleaned up afterward; the tail of the first baseline batch briefly overlapped the next experiment. These counts are observations, not an estimate of the original failure rate. The temporary delay is not committed. A separate mutation making bothTryEnterCriticalSectioncalls always fail was correctly rejected with missing bit0x0020; that mutation was also removed.The Mach-O test executable was verified as x86_64,
--listincluded the waits test, and every stress invocation required1 passed; 0 failed. Each process rebuilt the PE/DLL fixture throughbuild-native-probe.sh; no stale C fixture was reused.Also passed (all builds under
nice, at most six jobs):cargo test -j6 --locked --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 267 passed, 0 failed, 4 ignored, including all 16 native_probe tests and the new regression.cargo test -j6 --locked -p victory-shader -p victory-hle -p victory -p victory-gpu -p xtask: 500 passed, 0 failed, 4 ignored on arm64. This supplements the Rosetta runs; it does not execute the waits test.--all-targets --locked -- -D warnings, both default and--all-featuresconfigurations.cargo run -j6 --locked --quiet -p xtask -- policy: 363 files OK.git diff --check.9880186: both Clippy configurations and workspace tests.No game content or Apple SDK binaries are included. The finite stress sample cannot rule out other independent causes of #20; this PR fixes the two demonstrated defects rather than increasing timeouts or suppressing assertions.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T10:45:23Z.
Review: APPROVED
Great catch. Sleeping on an available SRW word after a lost CAS is a real lost-wakeup, and the regression covers every state. Tested merged with current main: x86_64-apple-darwin hle/loader/victory (220 + 16 native_probe), the arm64 suites, clippy (Windows target) and policy all pass. We suspect this may also explain a 30 s main-loop stall that trips the title's hang watchdog during story loading, and we're testing that now.