6 /* Pull in TLS support */
\r
7 extern char _tls_used[];
\r
9 struct _PDCLIB_tss * _PDCLIB_tss_first = NULL;
\r
11 int tss_create( tss_t *key, tss_dtor_t dtor )
\r
13 *key = malloc( sizeof *key );
\r
18 (*key)->_Key = TlsAlloc();
\r
19 if((*key)->_Key == TLS_OUT_OF_INDEXES) {
\r
22 (*key)->_Destructor = dtor;
\r
23 (*key)->_Next = _PDCLIB_tss_first;
\r
25 // TODO: make this atomic (& validate no other TLS blocks have been
\r
26 // simultaneously allocated)
\r
27 _PDCLIB_tss_first = *key;
\r
29 return thrd_success;
\r
32 static void NTAPI runTlsDestructors( void * image, DWORD reason, PVOID pv )
\r
34 if( reason == DLL_THREAD_DETACH ) {
\r
35 for(unsigned i = 0; i < TSS_DTOR_ITERATIONS; i++) {
\r
36 struct _PDCLIB_tss * tss = _PDCLIB_tss_first;
\r
37 bool destructorsRan = false;
\r
39 void * val = TlsGetValue( tss->_Key );
\r
41 TlsSetValue( tss->_Key, NULL );
\r
42 if( tss->_Destructor ) {
\r
43 tss->_Destructor( val );
\r
44 destructorsRan = true;
\r
50 if(!destructorsRan) break;
\r
56 __attribute__((__section__(".CRT$XLC")))
\r
58 __declspec(allocate(".CRT$XLC"))
\r
60 PIMAGE_TLS_CALLBACK _PDCLIB_runTlsDestructors = runTlsDestructors;
\r
65 #include <_PDCLIB_test.h>
\r
67 /* Tested in tss_get.c */
\r
70 return TEST_RESULTS;
\r