mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 20:58:36 +00:00
load() rewrites a /GA executable's `mov r64, gs:[58h]` reads to a TlsAlloc slot whose value is a per-thread view with the image's block at [0] (pe_loader.h, tls_ga_slot). install_thread_block creates that view for the loading thread and for threads started after load(), but install_on_existing_threads gave the threads that were already running only the block in TEB->ThreadLocalStoragePointer[tls_index]. A rewritten index-0 read on such a thread then loaded null and dereferenced it: the task queue runs a title's callbacks on pool workers that predate the load, so this is the same AV the main thread had at exe+0x104075, moved to a worker. Each existing thread now also gets a view of its own in TEB->TlsSlots[ga_slot], and ~Loader, the thread's detach event and a reused thread id free it with the block. Tested: runtime/test/loader_tls_test.cpp maps a new handmade /GA EXE fixture (tiny_ga_tls) and reads its __declspec(thread) value from the loading thread, from a thread that existed before load() and from a later one, then again after a second load(). Without the pe_loader change that test dies with 0xC0000005 on the existing thread; with it all 95 checks pass. ctest -R loader: 4/4 passed (Windows 11, MSVC 19.44, RelWithDebInfo, no GPU needed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>