runtime: own the executable TLS exit callback #2315

Manually merged
github merged 1 commit from github-bot/gh-2315 into main 2026-11-26 18:35:46 +00:00 AGit
Owner

@⁠ZroIsHere on GitHub · 2026-11-26 13:45 UTC · original
ZroIsHere:fix/thread-local-exe-atexit-callback → main · +48 −6 · 4 files · 1 commits · merged 2026-11-26 18:30 UTC

During boot, the executable's _register_thread_local_exe_atexit_callback import reached the host UCRT and terminated the process with FAST_FAIL_FATAL_APP_EXIT before D3D12 initialization.

Bind the callback to the runtime. Run it after the executable's TLS thread-detach callbacks and before normal CRT exit parks the game thread. _Exit, quick_exit, ExitProcess and abort continue to skip CRT cleanup.

Validation: the Windows/MSVC RelWithDebInfo gta6rt build passed. With the Vulkan backend, translated shaders and a scripted GameInput pad for the no-SDL build, the retail package rendered non-black 3840×2160 frames and reached the Spanish onboarding UI. Captures are in _build/thread-local-shaderboot9/captures (frame_01501 and frame_02001). No tests were run.

**@⁠ZroIsHere** on GitHub · 2026-11-26 13:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2315) `ZroIsHere:fix/thread-local-exe-atexit-callback` → `main` · +48 −6 · 4 files · 1 commits · merged 2026-11-26 18:30 UTC During boot, the executable's `_register_thread_local_exe_atexit_callback` import reached the host UCRT and terminated the process with `FAST_FAIL_FATAL_APP_EXIT` before D3D12 initialization. Bind the callback to the runtime. Run it after the executable's TLS thread-detach callbacks and before normal CRT exit parks the game thread. `_Exit`, `quick_exit`, `ExitProcess` and `abort` continue to skip CRT cleanup. Validation: the Windows/MSVC RelWithDebInfo `gta6rt` build passed. With the Vulkan backend, translated shaders and a scripted GameInput pad for the no-SDL build, the retail package rendered non-black 3840×2160 frames and reached the Spanish onboarding UI. Captures are in `_build/thread-local-shaderboot9/captures` (`frame_01501` and `frame_02001`). No tests were run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:50:05 +00:00
github manually merged commit 8a600e14eb into main 2026-11-26 18:35:46 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 18:30 UTC · original

Merged through the integration PR #2395, together with #2372.

Changed on top, in one maintainer commit:

  • The callback is now called with its real type, _tls_callback_type (void (__stdcall*)(void*, unsigned long, void*) in UCRT process.h), as (nullptr, DLL_PROCESS_DETACH, nullptr). Before, it was called as void (*)(), so the reason argument vcruntime reads was whatever rdx held.
  • exit and _cexit call it before the atexit handlers, as the UCRT does: the leaving thread's thread_local objects end before the static ones.
  • The extra call on every thread detach is gone, and so is the call after the entry point returns. The loader already calls the same function from the executable's TLS directory on thread detach.
  • run_tiny_atexit has two new modes, thread_local_exit and thread_local_cexit. They fail on main and pass with the change.

Thank you for finding the fast-fail on the second registration. It stopped the title at boot on Windows.

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

**@⁠aslan2142** on GitHub · 2026-11-26 18:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2315#issuecomment-7200535344) Merged through the integration PR #2395, together with #2372. Changed on top, in one maintainer commit: - The callback is now called with its real type, `_tls_callback_type` (`void (__stdcall*)(void*, unsigned long, void*)` in UCRT `process.h`), as `(nullptr, DLL_PROCESS_DETACH, nullptr)`. Before, it was called as `void (*)()`, so the reason argument vcruntime reads was whatever `rdx` held. - `exit` and `_cexit` call it before the atexit handlers, as the UCRT does: the leaving thread's `thread_local` objects end before the static ones. - The extra call on every thread detach is gone, and so is the call after the entry point returns. The loader already calls the same function from the executable's TLS directory on thread detach. - `run_tiny_atexit` has two new modes, `thread_local_exit` and `thread_local_cexit`. They fail on `main` and pass with the change. Thank you for finding the fast-fail on the second registration. It stopped the title at boot on Windows. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
This discussion has been locked. Commenting is limited to contributors.
No description provided.