mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:58:37 +00:00
BL-1 (docs/boot_leads.md) says code built with /GA reads its TLS at module index 0 and that main stops there. main already carries a fix (b7a3fed28and4710549af: load() rewrites the executable's gs:[58h] reads to a per-thread view with the image's block at [0]), but no test maps a /GA executable and a second TLS module at the same time, and no test shows that the fixture's code really has the index-0 shape: the CRT objects linked into it read gs:[58h] through _tls_index, so "some reads were rewritten" holds for a non-/GA build too. tiny_ga_tls gets ga_tls_address(), which returns where its code looks for its variable without touching it. The new case uses it three ways. With LEONIDA_TLS_GA_PATCH=0 the address lies in this test EXE's own block at index 0: the stop-4 shape, shown without reading or writing another module's TLS. By default it lies in the fixture's own block, on the loading thread and on a thread started after load(), while tiny_tls.dll mapped beside it keeps a block at its own index, gets its thread attach and detach, and this EXE's block and value stay at index 0 of each thread's real TLS array. ~Loader takes the view out again. No loader change: the case passes on main as it is, which is the finding. pe_loader.cpp and tls_host.cpp are untouched. Tested on Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, at main8f05e09e2: loader_tls_test OK (118 checks, 95 before), 40 runs in a row; with LEONIDA_TLS_GA_PATCH=0 set for the whole process, 8 checks fail, as they should (7 existing ones and "by default load() rewrites the EXE's index-0 TLS reads"). MSVC emits the index-0 read for ga_tls_address at /Od and at /O2 (checked in the listing). Full ctest: 304 of 306, the same two failures as main (d3d12_execute_indirect_validation, d3d12_depth_resolve). Not run on the retail executable: that needs game files. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR1Fv7eQNgZjM6miWPKjHf
17 lines
850 B
C++
17 lines
850 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; }
|
|
// Where this code looks for the variable on the calling thread: ThreadLocalStoragePointer[0] plus the variable's
|
|
// offset, with no read of the variable itself. The test uses it to tell whose block index 0 resolved to.
|
|
extern "C" __declspec(dllexport) void* ga_tls_address() { return &g_ga_tls_value; }
|
|
|
|
int main() {
|
|
return 0;
|
|
}
|