startup: NOP a soft-assert site after the first continue #2485
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2493"
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 lambirou on 2026-11-25T18:33:31Z.
Change
--continue-asserts Nsteps over main-image INT3s one debug event at a time. A retail startup image can hit one site tens of thousands of times: a mapping loop traps once per 8 KiB chunk, so one 158 MiB mapping costs about 19,000 events. At roughly 0.8 ms per event this adds about 16 s and exhausts any fixed budget; raisingNonly postpones the stop.With
X2W_NOP_SOFT_ASSERTS=1, after the debugger continues a main-image INT3 for the first time it writes0x90over thecc.DBG_CONTINUEalready bypasses the image's handler, so the guest sees the same continuation, but later executions of that site no longer raise an exception. Sites listed inX2W_STOP_ATnever take this branch. The switch is off by default and documented indocs/startup-runtime.md.Refs #870.
Verification
Commit
b7af7b75, rebased ondbab5435, on Windows 11 build 26300.9974 with MSVC 19.44.35207.On the pre-rebase commit, the
releasepreset check passed:Result:
1/1 Test #522: startup_debug ... Passed 34.39 sec,100% tests passed, 0 tests failed out of 1.After the rebase, the same two targets were rebuilt directly with
cland the check was run again:Result:
startup_debug: PASS (...; 9 controls).tests/startup_debug_probe.cppgains a third, out-of-line trap site and a loop driven bySTARTUP_DEBUG_PROBE_ASSERTS(default 0, so the existing cases are unchanged).tests/startup_debug_check.pyadds:X2W_NOP_SOFT_ASSERTS=1, the probe completes its 4 repetitions and exits 0;events.txtholds exactly one breakpoint per site (3) and the summary names the patched repeated site;Evidence and follow-up
The fixture is source-built (
tests/startup_debug_probe.cpp) and needs no local data. It measures the debugger's event handling only; it does not establish how often a particular image traps.Limits: a site later armed as a hook is not covered, and
X2W_STOP_ATbehavior is unchanged. A follow-up could assert that a patched site still serves a later hook.This change was AI-assisted.
Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:56:43Z.
Review: COMMENTED
Review of head
b7af7b75(code and fixture only).What I checked:
tools/startup/debug_launch.py: the patch runs only inside the existing--continue-assertsbranch, soX2W_STOP_ATsites are skipped as stated. It checks that the byte isccbefore writing0x90.write()already restores page protection and callsFlushInstructionCache. Theex_addrkey matches howasserts_seenis keyed. Default is off.nop-repeat(3 breakpoints logged, the repeated site named in the summary) andnop-repeat-control(all 4 hits logged without the switch) guard the behavior and have a negative control.docs/startup-runtime.mdmatches the code.Known limits (non-blocking): a site later armed as a hook is not covered, as the PR says. After the NOP,
asserts_seenstops counting that site, so the--continue-asserts Nbudget no longer measures real hits at it. Worth one sentence in the doc.Commands run locally (Linux):
git diff --check origin/main...HEAD(clean),python3 tests/docs_links_check.py(pass),python3 tests/bidi_controls_check.py(pass),py_compileofdebug_launch.py(ok).startup_debug_check.pyneeds the Windows debugger APIs, so I did not run it or mutate it here. A Win2025 run is not part of this review.Merge: the PR is motivated by what a retail startup image does (about 19,000 traps in one mapping loop). We cannot verify that on the game, so the merge is left to MasterDomino or @R0Y00, who can.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T19:02:41Z.
Reading-only review — I cannot build here (the full CMake build stops in DXC with
unable to create compilation: AccessDeniedon unrelated targets), so this is not a run result.The test has the shape that makes it worth having
The pair is decisive, and it is a pair rather than a single run:
Without the switch the same site is logged
repeatstimes; with it, once.stdout.txtassertsdebug-probe repeated 4in both runs, so the difference cannot be explained by the probe skipping iterations— that is the assertion that makes the four-to-one difference mean "the INT3 was patched" rather than "the loop
did not run". Good.
Two details in the launcher that I would keep as they are, and one I would note
read(ex_addr, 1) == b"\xcc"guard is the right one: it patches only a byte that is still an INT3, so asite where the title's own first-chance handler already restored the instruction is left alone. Without it the
first continue would corrupt code the handler had fixed.
ex_addr not in nop_sitesmakes the patch idempotent per address, so the log line lists each site once ratherthan once per hit — which is what the fixture asserts (
f"{image}+{repeated[0]:#x}" in nop_line).exactly what makes a once-per-chunk trap fast, and exactly what would hide a second, different assert that
later reuses the same address (a re-JIT'd or reloaded mapping). If the launcher only ever patches main-image
RVAs, say so; the doc row at
docs/startup-runtime.md:1287describes the effect but not the scope.The one assertion I would tighten
len(hits) == 3hard-codes "the two baseline sites plus the one repeated site". If the probe ever grows anotherbreakpoint, this line keeps passing while describing a different scenario, and the failure would surface as a
confusing
3 != 4somewhere else.len(hits) == len(sites) + 1 and len(repeated) == 1says the same thingrelative to the baseline the fixture already measured.
Related:
repeated = [site for site in hits if site not in sites]identifies the repeated site by exclusion. Athird distinct site would be silently folded into
repeated, and only the laterrepeated[0]control would notice.Asserting
len(repeated) == 1already covers it, so this is a readability point, not a hole.Docs
docs/startup-runtime.md:1287gains the row and the fixture docstring names the switch (line 6), so the variable isdocumented in both places the others are. Nothing else in the tree enumerates
X2W_*names, so there is no list tosync.
AI-assisted; reviewed by reading only, no build or run on this host.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T21:56:41Z.
Review: COMMENTED
Review of head
0f664e9c(rebased onto current main; the earlier review by @tedin7 was onb7af7b75, same change). Code and fixture review only.What I checked
tools/startup/debug_launch.py: the NOP write runs only in the continue-assert branch, after theX2W_STOP_ATexclusion, so listed sites never get patched.write()already handles protection andFlushInstructionCache. Thecccheck before the write avoids patching a byte another thread already changed. Default is off.tests/startup_debug_probe.cpp/tests/startup_debug_check.py: the new case is a pair. With the switch: 4 repeats, one logged breakpoint per site, and the summary names the patched site. Without it: all 4 hits are logged. The control would fail if the NOP were not applied or if the switch were ignored.docs/startup-runtime.md.Commands run on Linux (worktree on the exact head)
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: passed (19 files, 493 links)python3 tests/bidi_controls_check.py: passedpython3 -I -m py_compile tools/startup/debug_launch.py tests/startup_debug_check.py: okNot verified here
startup_debugneeds Windows debug events; I did not run it, and CI was still pending when I looked. The Windows result in the PR body is the author's, from the pre-rebase commit plus a directclbuild after the rebase.No blocking findings in the code. Known limit, already stated by the author: a site armed later as a hook is not covered.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-25T21:55:12Z.
Rebased onto current
main(8f045aee) and updated the head to0f664e9c.Changes since
b7af7b75:tests/startup_debug_check.py: the repeated-site assertion is nowlen(hits) == len(sites) + 1withlen(repeated) == 1, instead of hard-coding 3.docs/startup-runtime.md: the switch row now states that the patch lasts for the process lifetime, only targets main-image RVAs, never patchesX2W_STOP_ATsites, and that a patched site stops incrementingasserts_seen, so--continue-asserts Nno longer measures real hits there.X2W_NOP_SOFT_ASSERTSstays off unless set to1.Verification on
0f664e9c(same tree asd10327d8):python -B tests/docs_links_check.pypasses (19 files, 493 links),tests/bidi_controls_check.pypasses, andgit diff --checkis clean.The Windows CI checks will rerun on the new head. Not covered: the retail mapping-loop frequency remains a local observation; this fixture only proves the debugger patches a repeated site once and leaves the unswitched control logging every hit.
Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-25T22:36:17Z.
Rebased onto current
main(bee07b90) after #2488 splitstartup_debuginto parallel CTest groups, and updated the head toface82ab.The conflict was in
tests/startup_debug_check.py. The NOP case is now inside thecoregroup, after the shared baseline sites, and uses the newbreakpoint_siteshelper. Thelogandhooksgroups are unchanged.Verification on
face82ab:python -B tests/docs_links_check.pypasses (19 files, 498 links),tests/bidi_controls_check.pypasses (1828 files), andgit diff --checkis clean.The Windows and Linux CI jobs will rerun on
face82ab. The retail mapping-loop frequency remains a local observation; the fixture covers the patch-once behavior and the unswitched control.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-25T22:36:20Z.
Rebased onto current
main(bee07b90) after #2488 splitstartup_debuginto parallel CTest groups, and updated the head toface82ab.The conflict was in
tests/startup_debug_check.py. The NOP case is now inside thecoregroup, after the shared baseline sites, and uses the newbreakpoint_siteshelper. Thelogandhooksgroups are unchanged.Verification on
face82ab:python -B tests/docs_links_check.pypasses (19 files, 498 links),tests/bidi_controls_check.pypasses (1828 files), andgit diff --checkis clean.The Windows and Linux CI jobs will rerun on
face82ab. The retail mapping-loop frequency remains a local observation; the fixture covers the patch-once behavior and the unswitched control.