OLD-7824: restore old upstream PR 7824 - startup_trace: LEONIDA_SKIP_INT3 works on title threads and with Wine's breakpoint address #638

Manually merged
github merged 4 commits from gh-pr/638/head into gh-pr/638/base 2026-11-26 09:13:11 +00:00
Owner

@⁠aslan2142 on GitHub · 2026-11-24 10:41 UTC · original
aslan2142:skip-int3-wine → main · +283 −54 · 6 files · 4 commits · merged 2026-11-25 22:59 UTC

Claimed in the coordination issue as: OLD-7824 #14

Restoration of my original pull request, old upstream PR 7824 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at 21625bca8; the code is unchanged, and the old #7599 references in the comments and the commit message now read "old upstream 7599" (old numbers link nowhere here), with the three comments that got longer rewrapped to 120 columns.

What and why

Spacecer2 measured under Wine 11.22 (old upstream 7599) that LEONIDA_SKIP_INT3 never took effect. The flag was a block-scope static first read on a title thread, and its MSVC thread-safe-static guard passed while the object was still zero. The handler's int3 set and the trace lock had the same shape. Two changes fix that:

  • What startup_trace's exception handler touches is no longer a block-scope static:
    • startup_trace::open() reads LEONIDA_SKIP_INT3, on the thread that opens the trace, into a constant-initialized atomic.
    • The trace lock is a constant-initialized SRW lock (no constructor, never destroyed).
    • The logged int3 sites are a constant-initialized open-addressing table of atomics.
  • The int3 is found at Rip (the Windows form) or at Rip - 1 (Spacecer2's Wine run). Either way, Rip ends one byte past the 0xCC.

Also:

  • skip_int3 returns false for a null EXCEPTION_POINTERS, record or context.
  • LEONIDA_LOG_GAME_EVENTS and LEONIDA_HDR are read on title threads, so xgameruntime_offline.cpp now caches them in namespace-scope atomics instead of block-scope statics.
  • docs/boot.md, runtime/README.md and the CMakeLists.txt comment now say that the variable is read when the trace opens.

int3_skip_test now runs each case in a child process with its own environment. The cases are real int3s, the Windows and the Wine breakpoint forms, the null pointers, the flag read at open(), and the flag off.

Tested

These runs were on Linux, with the Windows tests built with clang 23 for x86_64-w64-mingw32 and run under Wine 11.22 (Staging). The MSVC /W4 /permissive- build is left to CI.

  • int3_skip_test before, on main: the new test does not compile there, because it reads detail::skip_int3_on, which main does not have. With those two checks stubbed out:
    • real, windows and off pass;
    • wine fails 4 checks;
    • null crashes with an access violation;
    • init fails 1 check.
  • int3_skip_test after, on this branch: all 6 cases pass, 30 checks and 0 failures.
  • xgameruntime_offline_test: 58 checks and 0 failures both before and after, with and without LEONIDA_HDR=1.
  • Checks: git diff --check and python -I scripts/check_no_game_data.py on the changed files are both clean.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 10:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/638) `aslan2142:skip-int3-wine` → `main` · +283 −54 · 6 files · 4 commits · merged 2026-11-25 22:59 UTC Claimed in the coordination issue as: OLD-7824 https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 Restoration of my original pull request, old upstream PR 7824 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Rebased onto main at `21625bca8`; the code is unchanged, and the old `#7599` references in the comments and the commit message now read "old upstream 7599" (old numbers link nowhere here), with the three comments that got longer rewrapped to 120 columns. ### What and why Spacecer2 measured under Wine 11.22 (old upstream 7599) that `LEONIDA_SKIP_INT3` never took effect. The flag was a block-scope static first read on a title thread, and its MSVC thread-safe-static guard passed while the object was still zero. The handler's int3 set and the trace lock had the same shape. Two changes fix that: - What `startup_trace`'s exception handler touches is no longer a block-scope static: - `startup_trace::open()` reads `LEONIDA_SKIP_INT3`, on the thread that opens the trace, into a constant-initialized atomic. - The trace lock is a constant-initialized SRW lock (no constructor, never destroyed). - The logged int3 sites are a constant-initialized open-addressing table of atomics. - The int3 is found at `Rip` (the Windows form) or at `Rip - 1` (Spacecer2's Wine run). Either way, `Rip` ends one byte past the `0xCC`. Also: - `skip_int3` returns false for a null `EXCEPTION_POINTERS`, record or context. - `LEONIDA_LOG_GAME_EVENTS` and `LEONIDA_HDR` are read on title threads, so `xgameruntime_offline.cpp` now caches them in namespace-scope atomics instead of block-scope statics. - `docs/boot.md`, `runtime/README.md` and the `CMakeLists.txt` comment now say that the variable is read when the trace opens. `int3_skip_test` now runs each case in a child process with its own environment. The cases are real int3s, the Windows and the Wine breakpoint forms, the null pointers, the flag read at `open()`, and the flag off. ### Tested These runs were on Linux, with the Windows tests built with clang 23 for `x86_64-w64-mingw32` and run under Wine 11.22 (Staging). The MSVC `/W4 /permissive-` build is left to CI. - **`int3_skip_test` before, on `main`:** the new test does not compile there, because it reads `detail::skip_int3_on`, which `main` does not have. With those two checks stubbed out: - `real`, `windows` and `off` pass; - `wine` fails 4 checks; - `null` crashes with an access violation; - `init` fails 1 check. - **`int3_skip_test` after, on this branch:** all 6 cases pass, 30 checks and 0 failures. - **`xgameruntime_offline_test`:** 58 checks and 0 failures both before and after, with and without `LEONIDA_HDR=1`. - **Checks:** `git diff --check` and `python -I scripts/check_no_game_data.py` on the changed files are both clean. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) AI-assisted (Claude Code, Claude Opus 5.5).
Spacecer2 measured under Wine 11.22 (old upstream 7599) that LEONIDA_SKIP_INT3 never took
effect: the flag was a block-scope static first read on a title thread, whose
MSVC thread-safe-static guard passed with the object still zero, and the
handler's int3 set and the trace lock had the same shape.

- The flag is read by startup_trace::open(), on the thread that opens the trace,
  into a constant-initialized atomic.
- The trace lock is a constant-initialized SRW lock (no constructor, never
  destroyed), and the logged int3 sites are a constant-initialized table of
  atomics: the handler touches no block-scope static.
- The int3 is found from Rip (Windows) or Rip - 1 (Spacecer2's Wine run), and
  Rip always ends one byte past the 0xCC.
- skip_int3 returns false for a null EXCEPTION_POINTERS, record or context.
- LEONIDA_LOG_GAME_EVENTS and LEONIDA_HDR, read on title threads, are cached in
  namespace-scope atomics instead of block-scope statics.

int3_skip_test runs each case in a child process: real int3s, the Windows and
the Wine breakpoint forms, the null pointers, the flag read at open() and the
flag off. The wine, null and init cases fail on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
int3_from tried the byte at Rip first and only then checked
ExceptionAddress against it. With Rip one past the 0xCC and
ExceptionAddress on it (a mixed form), a second 0xCC at Rip (int3
padding) was taken first and then refused by the address check, so that
int3 was not skipped. Each candidate (Rip, then Rip - 1) now has to agree
with ExceptionAddress before it is taken. Main did not skip it either,
so this closes a gap rather than a regression. int3_skip_test gets a
"padding" case for it.

The std::set the old dedupe used is gone, so its include goes too; the
candidate loop needs <initializer_list>. Both raised in review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dedupe is a fixed table of 4096 addresses; past that a new site is
logged each time it is hit, as startup_trace.h says. Raised in review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:10 +00:00
github manually merged commit 2a79af5a81 into gh-pr/638/base 2026-11-26 09:13:11 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 01:47 UTC · original

Reviewed 60fce7a: read the rewrite and replayed its core logic (skip_int3 / first_int3_at / int3_from, extracted verbatim from both main and this head) in a sandboxed Linux probe. The Wine form and both mixed breakpoint forms now skip (main returned 0). The three null cases return false (main segfaulted on the first one). The flag is latched in open(): removing the variable afterwards still skips, where main stopped. Per-address dedupe matches a set until the 4096-slot table fills; after that a site logs again each time, as the header says. Docs tests, test_boot_trace.py, compileall and the portable runtime ctest pass on both trees. int3_skip_test is Windows-only; the windows CI job on this head passes. The failing Linux/macOS jobs ran on the old base (e.g. cs_imgload_d16_tfe, which passes on current main), and the branch merges cleanly into main.

Non-blocking notes:

  • #include <set> in startup_trace.h is now unused.
  • runtime/README's "first int3 at each address" is exact only until the table fills.
  • One edge in int3_from: if Rip is one past the 0xCC while ExceptionAddress is on it (a mixed form), and the next byte is also 0xCC (a run of int3 padding), the byte at Rip is taken first and the address check rejects it, so that int3 is not skipped. Main did not skip it either, so this is no regression. Picking the candidate that agrees with ExceptionAddress would cover it.

No findings. AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 01:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/638#issuecomment-7149966156) Reviewed 60fce7a: read the rewrite and replayed its core logic (`skip_int3` / `first_int3_at` / `int3_from`, extracted verbatim from both main and this head) in a sandboxed Linux probe. The Wine form and both mixed breakpoint forms now skip (main returned 0). The three null cases return false (main segfaulted on the first one). The flag is latched in `open()`: removing the variable afterwards still skips, where main stopped. Per-address dedupe matches a set until the 4096-slot table fills; after that a site logs again each time, as the header says. Docs tests, `test_boot_trace.py`, compileall and the portable runtime ctest pass on both trees. `int3_skip_test` is Windows-only; the `windows` CI job on this head passes. The failing Linux/macOS jobs ran on the old base (e.g. `cs_imgload_d16_tfe`, which passes on current main), and the branch merges cleanly into main. Non-blocking notes: - `#include <set>` in `startup_trace.h` is now unused. - runtime/README's "first int3 at each address" is exact only until the table fills. - One edge in `int3_from`: if Rip is one past the 0xCC while `ExceptionAddress` is on it (a mixed form), and the next byte is also 0xCC (a run of int3 padding), the byte at Rip is taken first and the address check rejects it, so that int3 is not skipped. Main did not skip it either, so this is no regression. Picking the candidate that agrees with `ExceptionAddress` would cover it. No findings. AI-assisted review. **Recommendation:** Merge
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 22:59 UTC · original

Merged: startup_trace: LEONIDA_SKIP_INT3 works on title threads and with Wine's breakpoint address.

  • Review points:
    • int3_from now takes the candidate (Rip, then Rip - 1) that ExceptionAddress agrees with. In the mixed form followed by int3 padding, the int3 is now skipped. A new padding case in int3_skip_test covers it.
    • The unused <set> include is gone.
    • The int3_skipped row in runtime/README.md now says the dedupe holds until 4096 addresses (1d0bf24dc, 2a79af5a8).
  • Tested: the full Windows suite under Wine on main 5fab93967 with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail. int3_skip and startup_trace pass on both.
  • Checked on main 696d70da1 + 2a79af5a8: it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass; check_no_game_data.py is clean on the 6 changed files.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 22:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/638#issuecomment-7177014174) Merged: `startup_trace`: `LEONIDA_SKIP_INT3` works on title threads and with Wine's breakpoint address. - **Review points:** - `int3_from` now takes the candidate (Rip, then Rip - 1) that `ExceptionAddress` agrees with. In the mixed form followed by int3 padding, the int3 is now skipped. A new `padding` case in `int3_skip_test` covers it. - The unused `<set>` include is gone. - The `int3_skipped` row in `runtime/README.md` now says the dedupe holds until 4096 addresses (`1d0bf24dc`, `2a79af5a8`). - **Tested:** the full Windows suite under Wine on `main` `5fab93967` with all nine of these runtime PRs merged together (#634, #643, #684, #657, #677, #638, #710, #688, #671), on llvmpipe and the gfx1036 iGPU (RADV): no test went from pass to fail. `int3_skip` and `startup_trace` pass on both. - **Checked on `main` `696d70da1` + `2a79af5a8`:** it merges cleanly; the semantic suite passes (493 files, 6,318 tests, 0 files failed); the 15 docs and writer tests pass; `check_no_game_data.py` is clean on the 6 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.