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:
authorRoberto0953 <Roberto0953@users.noreply.github.com>2026-11-23 17:48:36 +0100
committerRoberto0953 <Roberto0953@users.noreply.github.com>2026-11-23 17:48:54 +0100
commitb2902830d48ee44530f8f3be113ec477b49da1ff (patch)
tree088c0128c3be2a5631461132f3e75359e8dae60a /runtime/src/pe_loader.cpp
parent5a8dc9af6673e43113d0d53012b632531b8c2653 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/pe_loader.cpp')
-rw-r--r--runtime/src/pe_loader.cpp2
1 files changed, 1 insertions, 1 deletions
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;
835// load(): every other running thread gets its own copy of m's template. Not fatal where it cannot be done. 835// load(): every other running thread gets its own copy of m's template. Not fatal where it cannot be done.
836void install_on_existing_threads(Module& m) { 836void install_on_existing_threads(Module& m) {
837 const uint64_t total = static_cast<uint64_t>(m.tls_raw_size) + m.tls_zero_fill; 837 const uint64_t total = static_cast<uint64_t>(m.tls_raw_size) + m.tls_zero_fill;
838 if (!total || m.tls_index >= kMaxModuleTlsSlots || m.tls_slot >= kMaxMappedTlsModules) return; 838 if (!total || m.tls_index >= kMaxModuleTlsSlots || m.tls_slot >= kTlsSlotCount) return;
839 // Stays ahead of the TLS lock: the first call resolves the function with GetModuleHandle and GetProcAddress, which 839 // Stays ahead of the TLS lock: the first call resolves the function with GetModuleHandle and GetProcAddress, which
840 // take the Windows loader lock, and a thread inside its attach event holds that lock while it waits for ours. 840 // take the Windows loader lock, and a thread inside its attach event holds that lock while it waits for ours.
841 if (!query_thread_fn()) return; 841 if (!query_thread_fn()) return;