[PR #2354] [CLOSED] process: cover the game's thread-local exe-atexit callback #2357

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2354
Author: @ERROR890
Created: 11/26/2026
Status: ❌ Closed

Base: main ← Head: fix/thread-local-atexit


📝 Commits (2)

  • 7cd2265 process: cover the game's thread-local exe-atexit callback
  • d65f6af Merge branch 'main' into fix/thread-local-atexit

📊 Changes

4 files changed (+91 additions, -2 deletions)

View changed files

📝 runtime/shims/process.cpp (+27 -0)
📝 runtime/shims/process_shim.h (+5 -0)
📝 runtime/src/pe_loader.cpp (+10 -2)
📝 runtime/test/process_cmdline_test.cpp (+49 -0)

📄 Description

Claimed in the coordination issue as: BOOT-TLS-ATEXIT-CALLBACK
(https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7195615051)

Depends on: none.

Fixes: none (no issue tracks this).

What and why

shims/process.cpp answers the retail title's process-level imports (its command line, exit/abort,
_crt_atexit, ...) and its header lists what is still missing: "Not covered yet: at_quick_exit() handlers ...
and the thread-local destructor callback (_register_thread_local_exe_atexit_callback); both still reach the host
CRT."
This covers the second one.

It is also where the title stopped on a73a57e1. Running the 1.0.2.1 package through gta6rt --run there, the
process ended with 0xC0000409 in ucrtbase after the static initialisers and before any D3D12 call. An int3
planted on ucrtbase!terminate fired first, and the return address on the stack was inside
_register_thread_local_exe_atexit_callback (the call terminate of its cold path): the UCRT's own consistency
check failed in this process and its CRT ended the run. The fast-fail exception information was 0x7
(FAST_FAIL_RANGE_CHECK_FAILURE), the code that path raises. The runtime's own shim header already named the gap.

On current main (fbf100b1b) that stop is already gone - it was cleared by the TLS/thread work that landed after
a73a57e1 (#2195 and neighbours) - so please read this as the coverage the header promises plus its test, not as a
crash fix.

What changes:

  • the shim keeps the callback per thread and returns the previous one, as the UCRT does;
  • the loader runs it in the DLL_THREAD_DETACH branch of on_host_thread_event, after the DLL slots' callbacks and
    the executable's own, which is where the UCRT would run it; a throw is caught so the Windows loader lock is never
    left held;
  • process_cmdline_test gains a case that fails on main (there is no such shim) and passes with this change.

Tested

  • process_cmdline_test (cmake --build <build> --target process_cmdline_test) built and run on main plus this
    change: exit 0, including the new case (shim found; first registration returns no previous callback and runs
    nothing; the runner runs it once and not twice; a later registration returns the callback it replaces).
  • The retail 1.0.2.1 title through gta6rt --run, with the shader workspace this checkout translated, on main plus
    this change: reaches the Vulkan device and presents ([rt] d3d12_xs: PresentX ready (... client area 1904x1041)).
    Plain main on the same machine does the same, so no regression from this change.

GPUs tested: NVIDIA GeForce RTX 5070, driver 621.40, Windows 11 26H2 (build 26300.9974) - boot only; the GPU test
suite was not run for this change.

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. (No translator
    change in this pull request.)

🔄 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/2354 **Author:** [@ERROR890](https://github.com/ERROR890) **Created:** 11/26/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/thread-local-atexit` --- ### 📝 Commits (2) - [`7cd2265`](https://github.com/ubiquitarianism/leonida/commit/7cd22658315af07faa32b69b05b8ba5d96e65355) process: cover the game's thread-local exe-atexit callback - [`d65f6af`](https://github.com/ubiquitarianism/leonida/commit/d65f6af980cb274ba645e1402cf31efb15a30f8d) Merge branch 'main' into fix/thread-local-atexit ### 📊 Changes **4 files changed** (+91 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/shims/process.cpp` (+27 -0) 📝 `runtime/shims/process_shim.h` (+5 -0) 📝 `runtime/src/pe_loader.cpp` (+10 -2) 📝 `runtime/test/process_cmdline_test.cpp` (+49 -0) </details> ### 📄 Description Claimed in the coordination issue as: BOOT-TLS-ATEXIT-CALLBACK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7195615051) Depends on: none. Fixes: none (no issue tracks this). ### What and why `shims/process.cpp` answers the retail title's process-level imports (its command line, `exit`/`abort`, `_crt_atexit`, ...) and its header lists what is still missing: *"Not covered yet: at_quick_exit() handlers ... and the thread-local destructor callback (`_register_thread_local_exe_atexit_callback`); both still reach the host CRT."* This covers the second one. It is also where the title stopped on `a73a57e1`. Running the 1.0.2.1 package through `gta6rt --run` there, the process ended with `0xC0000409` in `ucrtbase` after the static initialisers and before any D3D12 call. An `int3` planted on `ucrtbase!terminate` fired first, and the return address on the stack was inside `_register_thread_local_exe_atexit_callback` (the `call terminate` of its cold path): the UCRT's own consistency check failed in this process and its CRT ended the run. The fast-fail exception information was `0x7` (`FAST_FAIL_RANGE_CHECK_FAILURE`), the code that path raises. The runtime's own shim header already named the gap. On current `main` (`fbf100b1b`) that stop is already gone - it was cleared by the TLS/thread work that landed after `a73a57e1` (#2195 and neighbours) - so please read this as the coverage the header promises plus its test, not as a crash fix. What changes: - the shim keeps the callback per thread and returns the previous one, as the UCRT does; - the loader runs it in the `DLL_THREAD_DETACH` branch of `on_host_thread_event`, after the DLL slots' callbacks and the executable's own, which is where the UCRT would run it; a throw is caught so the Windows loader lock is never left held; - `process_cmdline_test` gains a case that fails on `main` (there is no such shim) and passes with this change. ### Tested - `process_cmdline_test` (`cmake --build <build> --target process_cmdline_test`) built and run on `main` plus this change: exit 0, including the new case (shim found; first registration returns no previous callback and runs nothing; the runner runs it once and not twice; a later registration returns the callback it replaces). - The retail 1.0.2.1 title through `gta6rt --run`, with the shader workspace this checkout translated, on `main` plus this change: reaches the Vulkan device and presents (`[rt] d3d12_xs: PresentX ready (... client area 1904x1041)`). Plain `main` on the same machine does the same, so no regression from this change. GPUs tested: NVIDIA GeForce RTX 5070, driver 621.40, Windows 11 26H2 (build 26300.9974) - boot only; the GPU test suite was not run for this change. 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator change in this pull request.) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:20:58 +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#2357
No description provided.