From 303b196d403876f324e7456854a148e85682c2d9 Mon Sep 17 00:00:00 2001 From: daanx Date: Sun, 4 May 2025 22:09:56 -0700 Subject: [PATCH 1/2] fix MI_WIN_USE_FIXED_TLS conditions --- src/prim/windows/prim.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/prim/windows/prim.c b/src/prim/windows/prim.c index c91102a2..d0fee4c2 100644 --- a/src/prim/windows/prim.c +++ b/src/prim/windows/prim.c @@ -627,7 +627,7 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) { // Process & Thread Init/Done //---------------------------------------------------------------- -#if MI_HAS_TLS_SLOT +#if MI_WIN_USE_FIXED_TLS==1 mi_decl_cache_align size_t _mi_win_tls_offset = sizeof(void*); // use 2nd slot by default #endif @@ -635,6 +635,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) { MI_UNUSED(reserved); MI_UNUSED(module); #if MI_HAS_TLS_SLOT >= 2 // we must initialize the TLS slot before any allocation + #if MI_WIN_USE_FIXED_TLS==1 if (reason==DLL_PROCESS_ATTACH) { const DWORD tls_slot = TlsAlloc(); if (tls_slot == TLS_OUT_OF_INDEXES) { @@ -642,11 +643,12 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) { } _mi_win_tls_offset = (size_t)tls_slot * sizeof(void*); } + #endif if (reason==DLL_PROCESS_ATTACH || reason==DLL_THREAD_ATTACH) { if (mi_prim_get_default_heap() == NULL) { _mi_heap_set_default_direct((mi_heap_t*)&_mi_heap_empty); } - #if MI_DEBUG + #if MI_DEBUG && MI_WIN_USE_FIXED_TLS==1 void* const p = TlsGetValue((DWORD)(_mi_win_tls_offset / sizeof(void*))); mi_assert_internal(p == (void*)&_mi_heap_empty); #endif From e2d7c24c7362a19429f7338f0e5ed493f7c1d7b0 Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 4 May 2025 22:17:59 -0700 Subject: [PATCH 2/2] add fixed TLS slot test to pipeline on Windows --- azure-pipelines.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 25d4a6e0..b7fc59d4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -42,6 +42,14 @@ jobs: BuildType: release cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -A Win32 MSBuildConfiguration: Release + Debug Fixed TLS: + BuildType: debug + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_WIN_USE_FIXED_TLS=ON + MSBuildConfiguration: Debug + Release Fixed TLS: + BuildType: release + cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_WIN_USE_FIXED_TLS=ON + MSBuildConfiguration: Release steps: - task: CMake@1 inputs: