upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/tls_host.cpp
diff options
context:
space:
mode:
authorKam471 <kam471@users.noreply.github.com>2026-11-21 22:19:03 +0000
committerKam471 <kam471@users.noreply.github.com>2026-11-21 23:29:24 +0000
commit993a2cbf72a9509ca730e509ea38e455d35f5a74 (patch)
treea3d6dc8481bfeabb7e5a94840ef4474504add23d /runtime/src/tls_host.cpp
parentd7cbc3e7cb4d031c790dddd265a83fb6a1a1a7a5 (diff)
Runtime: install static TLS for mapped images
Diffstat (limited to 'runtime/src/tls_host.cpp')
-rw-r--r--runtime/src/tls_host.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/runtime/src/tls_host.cpp b/runtime/src/tls_host.cpp
new file mode 100644
index 000000000..54322be4f
--- /dev/null
+++ b/runtime/src/tls_host.cpp
@@ -0,0 +1,15 @@
1// Minimal TLS anchor DLL for the native loader.
2//
3// Loading this image makes the Windows loader assign it a per-module TLS index and allocate a block for that index in
4// every thread's TEB. Loader::initialize_tls reuses that reserved index for the manually mapped image, so
5// __declspec(thread) access in mapped code reads a valid TEB slot. The anchor itself is never used; the loader saves
6// and restores the helper's own block, so the helper's CRT TLS state is not disturbed.
7#include <windows.h>
8
9__declspec(thread) unsigned char g_tls_host_anchor = 0;
10
11// Never called. The export keeps the TLS variable (and therefore the image's TLS directory) from being dropped by
12// the linker without making DllMain touch TLS during thread attach/detach.
13extern "C" __declspec(dllexport) void gta6rt_tls_host_keep() { g_tls_host_anchor = 1; }
14
15BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID) { return TRUE; }