]> pd.if.org Git - pdclib/blobdiff - platform/win32/functions/_PDCLIB/_tls_used.c
win32: initial pass at thread support
[pdclib] / platform / win32 / functions / _PDCLIB / _tls_used.c
diff --git a/platform/win32/functions/_PDCLIB/_tls_used.c b/platform/win32/functions/_PDCLIB/_tls_used.c
new file mode 100644 (file)
index 0000000..a7e5a69
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef REGTEST\r
+#include <stddef.h>\r
+#include <stdint.h>\r
+#include <windows.h>\r
+\r
+/* Win32 TLS support\r
+ *\r
+ * Components which depend upon TLS must express a dependency on the symbol \r
+ * _tls_used. This will cause said symbol to be emitted.\r
+ *\r
+ * The linker (in the case of both Microsoft's linker and Binutils, at least)\r
+ * will point the TLS directory entry in the PE header to _tls_used.\r
+ *\r
+ * NOTE: On Windows versions < NT 6.0, the TLS support _only_ works for \r
+ *       the main executable and any DLLs loaded as dependencies of it\r
+ */\r
+\r
+extern char __tls_start__[], __tls_end__[];\r
+ULONG _tls_index = TLS_OUT_OF_INDEXES;\r
+\r
+extern void NTAPI _PDCLIB_runTlsCallbacks(void * image, DWORD reason, PVOID pv);\r
+static PIMAGE_TLS_CALLBACK tlsCallbacks[] = {\r
+    &_PDCLIB_runTlsCallbacks,\r
+    NULL,\r
+};\r
+\r
+#ifdef __GNUC__\r
+__attribute__((__section__(".rdata$T")))\r
+#else\r
+__declspec(allocate(".rdata$T"))\r
+#endif\r
+#ifdef _WIN64\r
+const IMAGE_TLS_DIRECTORY64 _tls_used = {\r
+#else\r
+const IMAGE_TLS_DIRECTORY _tls_used = {\r
+#endif\r
+        (uintptr_t) &__tls_start__,\r
+        (uintptr_t) &__tls_end__,\r
+        (uintptr_t) &_tls_index,        // TLS index\r
+        (uintptr_t) &tlsCallbacks[0],   // TLS callback array\r
+        (ULONG) 0,                      // Size of zero fill\r
+        (ULONG) 0                       // Characteristics\r
+};\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+/* Tested in tss_get.c */\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif
\ No newline at end of file