]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_tls_used.c
PDCLib includes with quotes, not <>.
[pdclib] / platform / win32 / functions / _PDCLIB / _tls_used.c
1 #ifndef REGTEST\r
2 #include <stddef.h>\r
3 #include <stdint.h>\r
4 #include <windows.h>\r
5 \r
6 /* Win32 TLS support\r
7  *\r
8  * Components which depend upon TLS must express a dependency on the symbol \r
9  * _tls_used. This will cause said symbol to be emitted.\r
10  *\r
11  * The linker (in the case of both Microsoft's linker and Binutils, at least)\r
12  * will point the TLS directory entry in the PE header to _tls_used.\r
13  *\r
14  * NOTE: On Windows versions < NT 6.0, the TLS support _only_ works for \r
15  *       the main executable and any DLLs loaded as dependencies of it\r
16  */\r
17 \r
18 extern char __tls_start__[], __tls_end__[];\r
19 ULONG _tls_index = TLS_OUT_OF_INDEXES;\r
20 \r
21 extern void NTAPI _PDCLIB_runTlsCallbacks(void * image, DWORD reason, PVOID pv);\r
22 static PIMAGE_TLS_CALLBACK tlsCallbacks[] = {\r
23     &_PDCLIB_runTlsCallbacks,\r
24     NULL,\r
25 };\r
26 \r
27 #ifdef __GNUC__\r
28 __attribute__((__section__(".rdata$T")))\r
29 #else\r
30 __declspec(allocate(".rdata$T"))\r
31 #endif\r
32 #ifdef _WIN64\r
33 const IMAGE_TLS_DIRECTORY64 _tls_used = {\r
34 #else\r
35 const IMAGE_TLS_DIRECTORY _tls_used = {\r
36 #endif\r
37         (uintptr_t) &__tls_start__,\r
38         (uintptr_t) &__tls_end__,\r
39         (uintptr_t) &_tls_index,        // TLS index\r
40         (uintptr_t) &tlsCallbacks[0],   // TLS callback array\r
41         (ULONG) 0,                      // Size of zero fill\r
42         (ULONG) 0                       // Characteristics\r
43 };\r
44 #endif\r
45 \r
46 #ifdef TEST\r
47 #include "_PDCLIB_test.h"\r
48 \r
49 /* Tested in tss_get.c */\r
50 int main( void )\r
51 {\r
52     return TEST_RESULTS;\r
53 }\r
54 \r
55 #endif