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