Merge branch 'dev' into dev3

This commit is contained in:
Daan 2025-05-04 22:19:46 -07:00
commit 1aa832873b
4 changed files with 29 additions and 18 deletions

View file

@ -646,22 +646,29 @@ bool _mi_prim_random_buf(void* buf, size_t buf_len) {
// Process & Thread Init/Done
//----------------------------------------------------------------
#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
static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
MI_UNUSED(reserved);
MI_UNUSED(module);
#if MI_TLS_SLOT >= 2
#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 != 1) {
_mi_error_message(EFAULT, "unable to allocate the second TLS slot (rebuild without MI_WIN_USE_FIXED_TLS?)\n");
if (tls_slot == TLS_OUT_OF_INDEXES) {
_mi_error_message(EFAULT, "unable to allocate the a TLS slot (rebuild without MI_WIN_USE_FIXED_TLS?)\n");
}
_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
void* const p = TlsGetValue(1);
#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
}
@ -827,7 +834,7 @@ static void NTAPI mi_win_main(PVOID module, DWORD reason, LPVOID reserved) {
#endif
mi_decl_export void _mi_redirect_entry(DWORD reason) {
// called on redirection; careful as this may be called before DllMain
#if MI_TLS_SLOT >= 2
#if MI_HAS_TLS_SLOT >= 2 // we must initialize the TLS slot before any allocation
if ((reason==DLL_PROCESS_ATTACH || reason==DLL_THREAD_ATTACH) && mi_prim_get_default_heap() == NULL) {
_mi_heap_set_default_direct((mi_heap_t*)&_mi_heap_empty);
}