upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/pe_loader.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-26 13:15:17 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-26 13:15:17 -0500
commit48f87a9c9bea054b0072364ebf0e51e2d59f354d (patch)
tree28bfe653dba490c592a94585e3694bd1e945bdc9 /runtime/src/pe_loader.cpp
parent95d18113f37cfd42f8d8264fc3223efd7f2d60cb (diff)
process: call the EXE's thread-local destructor callback with its real signature, before the atexit handlers (maintainer fix on #2315)
#2315 kept `_register_thread_local_exe_atexit_callback` away from the host UCRT, which fast-fails a second registration in the process (gta6rt's own startup makes the first). Review points fixed on top: - The callback is a `_tls_callback_type` (UCRT process.h: `void (__stdcall*)(void*, unsigned long, void*)`), not `void (*)()`: vcruntime's TLS destructor callback reads its reason argument, which was left as whatever rdx held. It is now called as `(nullptr, DLL_PROCESS_DETACH, nullptr)`, as the UCRT does. - `exit` and `_cexit` call it before the atexit table, as the UCRT does: the leaving thread's thread_local objects end before the static ones ([basic.start.term]). #2315 ran it after the static destructors, and not in `_cexit`. - The extra call on every thread detach is dropped, with the per-thread flag and the loader's include of the process shim: the loader already calls the same function from the executable's TLS directory with DLL_THREAD_DETACH, and the UCRT never calls the registered one there. The call after a returning entry point is dropped too (MSVC's mainCRTStartup calls exit itself). - run_tiny_atexit gains thread_local_exit and thread_local_cexit: a thread_local object of the main thread must end before the handlers and destructors. On main the --run path never ends it (Wine) or stops at the second registration (Windows). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp10
1 files changed, 0 insertions, 10 deletions
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp
index 81d2e208a..fc73f37f5 100644
--- a/runtime/src/pe_loader.cpp
+++ b/runtime/src/pe_loader.cpp
@@ -17,7 +17,6 @@
17#include <vector> 17#include <vector>
18 18
19#include "../shims/shims.h" 19#include "../shims/shims.h"
20#include "../shims/process_shim.h"
21#include "../shims/startup_trace.h" 20#include "../shims/startup_trace.h"
22#include "base_reservation.h" 21#include "base_reservation.h"
23#include "clzero_patch.h" 22#include "clzero_patch.h"
@@ -1199,15 +1198,6 @@ void __cdecl on_host_thread_event(DWORD reason) {
1199 std::fprintf(stderr, "[rt] loader: thread detach, slot %zu (%s): %s\n", i, m->name.c_str(), 1198 std::fprintf(stderr, "[rt] loader: thread detach, slot %zu (%s): %s\n", i, m->name.c_str(),
1200 e.what()); 1199 e.what());
1201 } 1200 }
1202 if (i == kMainImageSlot) {
1203 try {
1204 process::run_thread_local_exe_atexit_callback();
1205 } catch (const std::exception& e) {
1206 std::fprintf(stderr, "[rt] loader: executable thread-local destructors: %s\n", e.what());
1207 } catch (...) {
1208 std::fprintf(stderr, "[rt] loader: executable thread-local destructors threw an unknown exception\n");
1209 }
1210 }
1211 // Released even when the callbacks threw: a leaked block would be handed to the OS loader as the 1201 // Released even when the callbacks threw: a leaked block would be handed to the OS loader as the
1212 // helper's own TLS block and freed with it at thread exit. 1202 // helper's own TLS block and freed with it at thread exit.
1213 uninstall_thread_block(*m); 1203 uninstall_thread_block(*m);