From 0661c59eb1848efb62347c7975075c59fe81d2b5 Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Wed, 25 Sep 2024 10:44:00 -0500 Subject: [PATCH] Disable Heap Malloc on Linux Disables heap malloc calls on Linux, as there are games where the heap malloc causes a crash. Note that the assert had to be modified, as pthread_gethandle is a winpthreads specific method. Also fixes a minor oversight that caused games not to perform TLS mallocs on Windows when there was no heap api. --- src/core/linker.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/linker.cpp b/src/core/linker.cpp index e8aab673d..5796cac55 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -356,22 +356,21 @@ void Linker::InitTlsForThread(bool is_primary) { ASSERT_MSG(ret == 0, "Unable to allocate TLS+TCB for the primary thread"); } else { if (heap_api) { -#ifndef WIN32 +#ifdef __APPLE__ addr_out = heap_api->heap_malloc(total_tls_size); - } else { - addr_out = std::malloc(total_tls_size); #else // TODO: Windows tls malloc replacement, refer to rtld_tls_block_malloc LOG_ERROR(Core_Linker, "TLS user malloc called, using std::malloc"); addr_out = std::malloc(total_tls_size); if (!addr_out) { + // TODO: Properly log thread handle on assert. auto pth_id = pthread_self(); - auto handle = pthread_gethandle(pth_id); - ASSERT_MSG(addr_out, - "Cannot allocate TLS block defined for handle=%x, index=%d size=%d", - handle, pth_id, total_tls_size); + ASSERT_MSG(addr_out, "Cannot allocate TLS block of size = {:#x} for thread {}", + total_tls_size, pth_id); } #endif + } else { + addr_out = std::malloc(total_tls_size); } }