@@ -631,29 +631,32 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) {
631
631
mi_decl_cache_align size_t _mi_win_tls_offset = 0 ;
632
632
#endif
633
633
634
+ //static void mi_debug_out(const char* s) {
635
+ // HANDLE h = GetStdHandle(STD_ERROR_HANDLE);
636
+ // WriteConsole(h, s, (DWORD)_mi_strlen(s), NULL, NULL);
637
+ //}
638
+
634
639
static void mi_win_tls_init (DWORD reason ) {
635
- #if MI_HAS_TLS_SLOT >= 2 // we must initialize the TLS slot before any allocation
636
- #if MI_WIN_USE_FIXED_TLS == 1
637
- if (reason == DLL_PROCESS_ATTACH && _mi_win_tls_offset == 0 ) {
638
- const DWORD tls_slot = TlsAlloc (); // usually returns slot 1
639
- if (tls_slot == TLS_OUT_OF_INDEXES ) {
640
- _mi_error_message (EFAULT , "unable to allocate the a TLS slot (rebuild without MI_WIN_USE_FIXED_TLS?)\n" );
641
- }
642
- _mi_win_tls_offset = (size_t )tls_slot * sizeof (void * );
643
- }
644
- #endif
645
640
if (reason == DLL_PROCESS_ATTACH || reason == DLL_THREAD_ATTACH ) {
641
+ #if MI_WIN_USE_FIXED_TLS == 1 // we must allocate a TLS slot dynamically
642
+ if (_mi_win_tls_offset == 0 && reason = DLL_PROCESS_ATTACH ) {
643
+ const DWORD tls_slot = TlsAlloc (); // usually returns slot 1
644
+ if (tls_slot == TLS_OUT_OF_INDEXES ) {
645
+ _mi_error_message (EFAULT , "unable to allocate the a TLS slot (rebuild without MI_WIN_USE_FIXED_TLS?)\n" );
646
+ }
647
+ _mi_win_tls_offset = (size_t )tls_slot * sizeof (void * );
648
+ }
649
+ #endif
650
+ #if MI_HAS_TLS_SLOT >= 2 // we must initialize the TLS slot before any allocation
646
651
if (mi_prim_get_default_heap () == NULL ) {
647
652
_mi_heap_set_default_direct ((mi_heap_t * )& _mi_heap_empty );
648
653
#if MI_DEBUG && MI_WIN_USE_FIXED_TLS == 1
649
654
void * const p = TlsGetValue ((DWORD )(_mi_win_tls_offset / sizeof (void * )));
650
655
mi_assert_internal (p == (void * )& _mi_heap_empty );
651
656
#endif
652
657
}
653
- }
654
- #else
655
- MI_UNUSED (reason );
656
- #endif
658
+ #endif
659
+ }
657
660
}
658
661
659
662
static void NTAPI mi_win_main (PVOID module , DWORD reason , LPVOID reserved ) {
@@ -676,7 +679,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
676
679
#define MI_PRIM_HAS_PROCESS_ATTACH 1
677
680
678
681
// Windows DLL: easy to hook into process_init and thread_done
679
- BOOL WINAPI DllMain (HINSTANCE inst , DWORD reason , LPVOID reserved ) {
682
+ BOOL WINAPI DllMain (HINSTANCE inst , DWORD reason , LPVOID reserved ) {
680
683
mi_win_main ((PVOID )inst ,reason ,reserved );
681
684
return TRUE;
682
685
}
0 commit comments