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