runtime: own the executable TLS exit callback #2315

Merged
ZroIsHere merged 1 commit from upstream-pr/2315 into main 2026-11-26 18:30:10 +00:00
ZroIsHere commented 2026-11-26 13:45:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ZroIsHere on 2026-11-26T13:45:32Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5511164628 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2315). Originally posted by [ZroIsHere](https://github.com/ZroIsHere) on 2026-11-26T13:45:32Z. --- 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.
aslan2142 commented 2026-11-26 18:30:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-26T18:30:10Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7200535344 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2315#issuecomment-7200535344). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-26T18:30:10Z. --- 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)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!2315
No description provided.