[PR #1564] process: the game's at_quick_exit handlers and thread-local exit callback are the run's own (RT-CRT-QUICK-EXIT-TLS) #1588

Open
opened 2026-11-26 20:21:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1564
Author: @Mike7581
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: rt-crt-quick-exit-tls


📝 Commits (2)

  • c5b51e9 process: the game's at_quick_exit handlers and thread-local exit callback are the run's own
  • 27a2711 process: the run's cleanup holds one lock, as the UCRT's exit lock; a throwing handler terminates

📊 Changes

5 files changed (+295 additions, -36 deletions)

View changed files

📝 runtime/CMakeLists.txt (+1 -1)
📝 runtime/README.md (+9 -5)
📝 runtime/shims/process.cpp (+123 -25)
📝 runtime/test/check_atexit.cmake (+30 -2)
📝 runtime/test/fixtures/tiny_atexit.cpp (+132 -3)

📄 Description

Claimed in the coordination issue as: RT-CRT-QUICK-EXIT-TLS (#1562, since #14 is at the 2,500-comment cap)

What and why

runtime/shims/process.cpp and runtime/README.md listed two gaps: the game's at_quick_exit() handlers and its thread-local destructor callback (_register_thread_local_exe_atexit_callback) still reached the host CRT, which the game shares with gta6rt. Measured under gta6rt --run before this change:

  • quick_exit() ran none of the game's at_quick_exit handlers;
  • exit() and _cexit() never ran the exiting thread's thread_local destructors (and a second registration in the host's one-slot callback would terminate gta6rt).

Now:

  • _crt_at_quick_exit goes to a second table of the run's own. quick_exit() runs it newest first under the exit lock; _exit() and _Exit() run nothing (they get their own function instead of sharing game_quick_exit).
  • The thread-local callback is the run's own: exit() and _cexit() call it with DLL_PROCESS_DETACH before the atexit handlers, as the UCRT does. A second registration aborts, as the UCRT's terminate() does. Both reset per run.

Tested

  • tiny_atexit gains five modes: at_quick_exit, at_quick_exit_exit, at_quick_exit__exit, thread_local_exit, thread_local_cexit. Their expected sequences in check_atexit.cmake come from running the fixture natively on Windows 11 (the test also holds the native run to them). Before the fix, --run differed on at_quick_exit (no handler ran), thread_local_exit and thread_local_cexit (no dtor thread_local).
  • run_tiny_atexit: 13 termination paths match the Windows sequence.
  • ctest -R "run_tiny|process|loader|exit": 29/29 passed.

GPUs tested: n/a (CPU only). Built with MSVC (VS 2022 Build Tools 17.14) + Ninja via scripts\build_runtime.ps1, Windows 11 Pro 10.0.26200.

AI-assisted: yes (Claude Code)

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)

🔄 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/1564 **Author:** [@Mike7581](https://github.com/Mike7581) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `rt-crt-quick-exit-tls` --- ### 📝 Commits (2) - [`c5b51e9`](https://github.com/ubiquitarianism/leonida/commit/c5b51e9a65ff73fe47dddbb0b9456d944988553d) process: the game's at_quick_exit handlers and thread-local exit callback are the run's own - [`27a2711`](https://github.com/ubiquitarianism/leonida/commit/27a2711e157efad9678cddbbf2a7475c2b95f951) process: the run's cleanup holds one lock, as the UCRT's exit lock; a throwing handler terminates ### 📊 Changes **5 files changed** (+295 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+1 -1) 📝 `runtime/README.md` (+9 -5) 📝 `runtime/shims/process.cpp` (+123 -25) 📝 `runtime/test/check_atexit.cmake` (+30 -2) 📝 `runtime/test/fixtures/tiny_atexit.cpp` (+132 -3) </details> ### 📄 Description Claimed in the coordination issue as: RT-CRT-QUICK-EXIT-TLS (#1562, since #14 is at the 2,500-comment cap) ### What and why `runtime/shims/process.cpp` and `runtime/README.md` listed two gaps: the game's `at_quick_exit()` handlers and its thread-local destructor callback (`_register_thread_local_exe_atexit_callback`) still reached the host CRT, which the game shares with gta6rt. Measured under `gta6rt --run` before this change: - `quick_exit()` ran none of the game's `at_quick_exit` handlers; - `exit()` and `_cexit()` never ran the exiting thread's `thread_local` destructors (and a second registration in the host's one-slot callback would terminate gta6rt). Now: - `_crt_at_quick_exit` goes to a second table of the run's own. `quick_exit()` runs it newest first under the exit lock; `_exit()` and `_Exit()` run nothing (they get their own function instead of sharing `game_quick_exit`). - The thread-local callback is the run's own: `exit()` and `_cexit()` call it with `DLL_PROCESS_DETACH` before the atexit handlers, as the UCRT does. A second registration aborts, as the UCRT's `terminate()` does. Both reset per run. ### Tested - `tiny_atexit` gains five modes: `at_quick_exit`, `at_quick_exit_exit`, `at_quick_exit__exit`, `thread_local_exit`, `thread_local_cexit`. Their expected sequences in `check_atexit.cmake` come from running the fixture natively on Windows 11 (the test also holds the native run to them). Before the fix, `--run` differed on `at_quick_exit` (no handler ran), `thread_local_exit` and `thread_local_cexit` (no `dtor thread_local`). - `run_tiny_atexit`: 13 termination paths match the Windows sequence. - `ctest -R "run_tiny|process|loader|exit"`: 29/29 passed. GPUs tested: n/a (CPU only). Built with MSVC (VS 2022 Build Tools 17.14) + Ninja via `scripts\build_runtime.ps1`, Windows 11 Pro 10.0.26200. AI-assisted: yes (Claude Code) ### 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1588
No description provided.