[PR #2395] [MERGED] [integration] Runtime: the EXE's thread-local exit callback (#2315) and scripted input between reads (#2372) (INTEGRATION-ZRO-DRAFTS) #2397

Closed
opened 2026-11-26 21:21:06 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2395
Author: @aslan2142
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: integration/tls-exit-and-scripted-input


📝 Commits (7)

  • 338dc11 runtime: own the executable TLS exit callback
  • 4e93ea9 gameinput: advance scripted input clock without SDL3
  • ee47019 Improve first-run input diagnostics
  • 8a600e1 Merge #2315 (ZroIsHere): runtime: own the executable TLS exit callback
  • 95d1811 Merge #2372 (ZroIsHere): advance scripted input and improve boot diagnostics
  • 48f87a9 process: call the EXE's thread-local destructor callback with its real signature, before the atexit handlers (maintainer fix on #2315)
  • 657808a gameinput (no SDL3): take the script's changes between two reads at their own time instead of a clock thread (maintainer fix on #2372)

📊 Changes

9 files changed (+205 additions, -39 deletions)

View changed files

📝 docs/gameinput.md (+9 -4)
📝 runtime/README.md (+9 -3)
📝 runtime/shims/gameinput.cpp (+10 -5)
📝 runtime/shims/gameinput_no_sdl.cpp (+88 -8)
📝 runtime/shims/process.cpp (+32 -3)
📝 runtime/test/check_atexit.cmake (+8 -2)
📝 runtime/test/fixtures/tiny_atexit.cpp (+13 -0)
📝 runtime/test/gameinput_no_sdl_test.cpp (+30 -13)
📝 scripts/windows-boot/boot.ps1 (+6 -1)

📄 Description

This merges two of ZroIsHere's draft runtime PRs, each with a maintainer fix on top and a new test.

Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7200103121 (item INTEGRATION-ZRO-DRAFTS)

Included

  • #2315 by ZroIsHere: the runtime now owns the executable's thread-local exit callback (_register_thread_local_exe_atexit_callback). The host UCRT accepts one callback per process and fast-fails on the second one. gta6rt's own startup registers the first, so on Windows the title stopped at boot. Under Wine, the title's callback replaced gta6rt's own and was never called. This removes the cause.
  • #2372 by ZroIsHere: scripted input in the build without SDL3 keeps every press in the reading history, even when the title does not read in between. Also adds LEONIDA_INPUT_TRACE (a reading trace), an A count in LEONIDA_INPUT_STATS, and -FirstRunUi in scripts/windows-boot/boot.ps1.

Maintainer changes

On #2315:

  • The callback is called with its real type, _tls_callback_type (void (__stdcall*)(void*, unsigned long, void*) in UCRT process.h), as (nullptr, DLL_PROCESS_DETACH, nullptr). The PR called it as void (*)(), so the reason argument was whatever rdx held.
  • exit and _cexit call it once, before the atexit handlers, as the UCRT does. The leaving thread's thread_local objects end before the static ones. The PR ran it after the static destructors, and not in _cexit.
  • The extra call on every thread detach is dropped. The loader already calls the same function from the executable's TLS directory on thread detach, and the UCRT never calls the registered copy there. The call after a returning entry point is dropped too.
  • Test: run_tiny_atexit gains thread_local_exit and thread_local_cexit.

On #2372:

  • The detached 8 ms clock thread is replaced. That thread never ended, took the input lock every 8 ms, and kept more or fewer edges depending on how the host scheduled it. update() now adds one reading for every start and end of a press since the last update, stamped with the script's time. The history is the same however often the title reads, and no thread runs. This removes the cause; the thread worked around it.
  • LEONIDA_INPUT_TRACE is documented in docs/gameinput.md and runtime/README.md.
  • Test: gameinput_no_sdl_script gains y@10, a press the title never reads while it is down.

Left out

Nothing.

Tests

On Linux, Mesa 26.3.1 RADV, Ryzen 9 7950X3D integrated GPU (gfx1036):

  • New tests fail on main bdbc7e923 and pass on this branch: run_tiny_atexit (on main, the thread_local destructor never runs under --run) and gameinput_no_sdl_script (4 history checks fail on main).
  • Windows suite under Wine: wine-staging 11.22, clang-cl + xwin build. 422 pass, 23 fail, 39 skip. The baseline on main bdbc7e923 is 421 pass, 24 fail. No test went from pass to fail. The one change is xmem_no_write_watch, from fail to pass, a known flake.
  • Linux runtime build and ctest: 112 of 112 pass, 2 skipped.
  • Python checks: tests/test_ci_registration.py, all tests/test_docs_*.py, tests/test_text_write_line_endings.py, scripts/check_no_game_data.py on the changed files and git diff --check all pass.

Not tested

  • Real Windows and MSVC.
  • The title through --run (a game run follows from this build).
  • boot.ps1 -FirstRunUi.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2395 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `integration/tls-exit-and-scripted-input` --- ### 📝 Commits (7) - [`338dc11`](https://github.com/ubiquitarianism/leonida/commit/338dc11ea622cb3ab0406cafd9af3f08a3740e50) runtime: own the executable TLS exit callback - [`4e93ea9`](https://github.com/ubiquitarianism/leonida/commit/4e93ea9ef3fd48431bee7d17705f62a69023ab57) gameinput: advance scripted input clock without SDL3 - [`ee47019`](https://github.com/ubiquitarianism/leonida/commit/ee470192461a2911aa204cfecf9fdccb265a8b5f) Improve first-run input diagnostics - [`8a600e1`](https://github.com/ubiquitarianism/leonida/commit/8a600e14ebb7e4b1df31fb004c1c137b5797566b) Merge #2315 (ZroIsHere): runtime: own the executable TLS exit callback - [`95d1811`](https://github.com/ubiquitarianism/leonida/commit/95d18113f37cfd42f8d8264fc3223efd7f2d60cb) Merge #2372 (ZroIsHere): advance scripted input and improve boot diagnostics - [`48f87a9`](https://github.com/ubiquitarianism/leonida/commit/48f87a9c9bea054b0072364ebf0e51e2d59f354d) process: call the EXE's thread-local destructor callback with its real signature, before the atexit handlers (maintainer fix on #2315) - [`657808a`](https://github.com/ubiquitarianism/leonida/commit/657808a7df4d7f1ea636d29dda8127ec65575f1b) gameinput (no SDL3): take the script's changes between two reads at their own time instead of a clock thread (maintainer fix on #2372) ### 📊 Changes **9 files changed** (+205 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `docs/gameinput.md` (+9 -4) 📝 `runtime/README.md` (+9 -3) 📝 `runtime/shims/gameinput.cpp` (+10 -5) 📝 `runtime/shims/gameinput_no_sdl.cpp` (+88 -8) 📝 `runtime/shims/process.cpp` (+32 -3) 📝 `runtime/test/check_atexit.cmake` (+8 -2) 📝 `runtime/test/fixtures/tiny_atexit.cpp` (+13 -0) 📝 `runtime/test/gameinput_no_sdl_test.cpp` (+30 -13) 📝 `scripts/windows-boot/boot.ps1` (+6 -1) </details> ### 📄 Description This merges two of ZroIsHere's draft runtime PRs, each with a maintainer fix on top and a new test. Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7200103121 (item `INTEGRATION-ZRO-DRAFTS`) ## Included - **#2315** by ZroIsHere: the runtime now owns the executable's thread-local exit callback (`_register_thread_local_exe_atexit_callback`). The host UCRT accepts one callback per process and fast-fails on the second one. gta6rt's own startup registers the first, so on Windows the title stopped at boot. Under Wine, the title's callback replaced gta6rt's own and was never called. This removes the cause. - **#2372** by ZroIsHere: scripted input in the build without SDL3 keeps every press in the reading history, even when the title does not read in between. Also adds `LEONIDA_INPUT_TRACE` (a reading trace), an `A` count in `LEONIDA_INPUT_STATS`, and `-FirstRunUi` in `scripts/windows-boot/boot.ps1`. ## Maintainer changes On #2315: - The callback is called with its real type, `_tls_callback_type` (`void (__stdcall*)(void*, unsigned long, void*)` in UCRT `process.h`), as `(nullptr, DLL_PROCESS_DETACH, nullptr)`. The PR called it as `void (*)()`, so the reason argument was whatever `rdx` held. - `exit` and `_cexit` call it once, before the atexit handlers, as the UCRT does. The leaving thread's `thread_local` objects end before the static ones. The PR ran it after the static destructors, and not in `_cexit`. - The extra call on every thread detach is dropped. The loader already calls the same function from the executable's TLS directory on thread detach, and the UCRT never calls the registered copy there. The call after a returning entry point is dropped too. - Test: `run_tiny_atexit` gains `thread_local_exit` and `thread_local_cexit`. On #2372: - The detached 8 ms clock thread is replaced. That thread never ended, took the input lock every 8 ms, and kept more or fewer edges depending on how the host scheduled it. `update()` now adds one reading for every start and end of a press since the last update, stamped with the script's time. The history is the same however often the title reads, and no thread runs. This removes the cause; the thread worked around it. - `LEONIDA_INPUT_TRACE` is documented in `docs/gameinput.md` and `runtime/README.md`. - Test: `gameinput_no_sdl_script` gains `y@10`, a press the title never reads while it is down. ## Left out Nothing. ## Tests On Linux, Mesa 26.3.1 RADV, Ryzen 9 7950X3D integrated GPU (gfx1036): - **New tests fail on `main` bdbc7e923 and pass on this branch:** `run_tiny_atexit` (on `main`, the `thread_local` destructor never runs under `--run`) and `gameinput_no_sdl_script` (4 history checks fail on `main`). - **Windows suite under Wine:** wine-staging 11.22, clang-cl + xwin build. 422 pass, 23 fail, 39 skip. The baseline on `main` bdbc7e923 is 421 pass, 24 fail. No test went from pass to fail. The one change is `xmem_no_write_watch`, from fail to pass, a known flake. - **Linux runtime build and ctest:** 112 of 112 pass, 2 skipped. - **Python checks:** `tests/test_ci_registration.py`, all `tests/test_docs_*.py`, `tests/test_text_write_line_endings.py`, `scripts/check_no_game_data.py` on the changed files and `git diff --check` all pass. ## Not tested - Real Windows and MSVC. - The title through `--run` (a game run follows from this build). - `boot.ps1 -FirstRunUi`. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 closed this issue 2026-11-26 21:21:06 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2397
No description provided.