startup: resume threads that fault on a host-cpu site another thread rewrote #2189
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2197"
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 R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-25T04:00:35Z.
Change
With
X2W_HOST_CPU=1the startup debugger rewrites a missing instruction on its first fault. A second thread that ran the same instruction before the rewrite reports its fault afterwards. Until now that fault went to the process as a second chance, and the run stopped. Fixes #2196.tools/startup/debug_launch.pynow records the sites it rewrote. A first-chance illegal instruction at such a site, where nothing is left to rewrite, is continued once per thread, so the thread runs the replacement. A fault that stays at the site is still reported. The summary prints how many threads were resumed.tests/startup_host_cpu_probe.cppadds 32 RDPID sites. A barrier before each site makes eight threads reach it together.startup_host_cpu_debugnow also requires all eight threads to finish.Related, but a different mechanism: #1281 and its PRs #1408 and #1951 (hooked-function breakpoints).
Verification
Commit
6429104aona116c379, Windows 10 22H2 (build 19045), i7-4790K (no RDPID, no SHA), Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7.Negative control, the new probe without the
debug_launch.pychange, 3 runs:With the change, 5 runs:
CTest:
A full startup run with this change (and #1277 for Windows 10) rewrote the same sites as before (
clflushopt-nop x1, clwb x1, clwb-nop x4, clzero x5, insertq x2, monitorx x1, mwaitx x1). The race did not occur in that run, so nothing was resumed.Evidence and follow-up
Checklist
AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:04:41Z.
Review: COMMENTED
Review of head
6429104adc5c9a2c29afa8042b63c2615dd94a4d(comment only).Summary: the change is small and sound. A thread that faulted on a host-cpu site before another thread rewrote it is continued once, so it runs the replacement. No P1/P2 findings.
Checked:
tools/startup/debug_launch.py:rewrite_for_hostandsha_for_hostare tried first, so a fresh site is always handled the old way. Only an already-rewritten address that nobody can rewrite again reaches the new branch. The(site, tid)set bounds it to one resume per thread, so a fault that persists after the replacement is still reported and not looped on.+Nkeeps the linker from merging them) and a spin barrier before each site make every thread reach the site together. The check assertsrdpid threads 8 of 8.Commands executed locally (Linux):
git diff --stat origin/main...HEAD: 3 files, +62/-3python3 tests/docs_links_check.py: self-test passed, 18 files, 405 linkspython3 tests/bidi_controls_check.py: 1480 files, no bidirectional controlsgit diff --check origin/main...HEAD: cleanpython3 -I -m py_compile tools/startup/debug_launch.py tests/startup_host_cpu_debug_check.py: ok(ex_addr, tid) not in host_cpu_resumedguard): the check needs the Windows probe binary (IndexErroron argv on Linux), so it cannot kill or confirm the mutation here. Reverted withgit checkout -- ..python3 x2w_pipe.py win2025 2197 --targets startup_host_cpu_probe --regex startup_host_cpu --wait 3300: dev 2/2 passed (startup_host_cpu,startup_host_cpu_debug), release 2/2 passed, exit 0.Nits (non-blocking):
tests/startup_host_cpu_debug_check.py: on a host that has RDPID nothing is rewritten, so the resume branch is not exercised and8 of 8passes trivially. It only guards the fix on hosts without RDPID. Worth a comment, or asserting the resumed count whensummarymentions rdpid.tests/startup_host_cpu_debug_check.py: the resumed count is reported but not asserted. It is timing dependent, so this is a reasonable choice; the8 of 8assert is the real guard.AI-assisted; commands listed were executed locally.