mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 15:18:38 +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>
14 lines
546 B
C++
14 lines
546 B
C++
// Tiny fixture EXE for the /GA TLS path. It is built with /GA, so its __declspec(thread) reads go through
|
|
// TEB->ThreadLocalStoragePointer[0] directly, as the retail executable's do. It is never executed; rt::Loader maps
|
|
// it and the test calls its exports from threads it chooses.
|
|
#include <windows.h>
|
|
|
|
__declspec(thread) int g_ga_tls_value = 7;
|
|
|
|
extern "C" __declspec(dllexport) int ga_tls_get() { return g_ga_tls_value; }
|
|
extern "C" __declspec(dllexport) void ga_tls_set(int value) { g_ga_tls_value = value; }
|
|
|
|
int main() {
|
|
return 0;
|
|
}
|