From b2902830d48ee44530f8f3be113ec477b49da1ff Mon Sep 17 00:00:00 2001 From: Roberto0953 Date: Mon, 23 Nov 2026 17:48:36 +0100 Subject: loader: load() gives already-running threads the executable's slot-0 block too After #3671 a thread that was already running when load() ran gets each module's TLS block from load() itself, and install_tls_for_thread is a no-op there. install_on_existing_threads stopped at kMaxMappedTlsModules, so the executable in kMainImageSlot (#4313) was skipped: such a thread, a thread-pool worker for instance, kept slot 0 as it was and /GA code on it read the wrong block. The check now covers kTlsSlotCount. loader_tls_index0's early thread checks the new contract; without the change it fails (reads no 42 in slot 0 before any install call). Co-Authored-By: Claude Opus 5.5 --- runtime/src/pe_loader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/src/pe_loader.cpp') diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index ecf44a221..45f3fc671 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp @@ -835,7 +835,7 @@ constexpr size_t kMaxEndedThreads = 1024; // load(): every other running thread gets its own copy of m's template. Not fatal where it cannot be done. void install_on_existing_threads(Module& m) { const uint64_t total = static_cast(m.tls_raw_size) + m.tls_zero_fill; - if (!total || m.tls_index >= kMaxModuleTlsSlots || m.tls_slot >= kMaxMappedTlsModules) return; + if (!total || m.tls_index >= kMaxModuleTlsSlots || m.tls_slot >= kTlsSlotCount) return; // Stays ahead of the TLS lock: the first call resolves the function with GetModuleHandle and GetProcAddress, which // take the Windows loader lock, and a thread inside its attach event holds that lock while it waits for ours. if (!query_thread_fn()) return; -- cgit v1.2.3