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:
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; }