From 70fa3cadcc482aed415f81674bb3aa418041676e Mon Sep 17 00:00:00 2001 From: microsoftv <6063922+microsoftv@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:15:29 -0400 Subject: [PATCH] resolve suggestions - `using` definition replacement for AppHeapAPI - linux uses heap_malloc, windows uses std::malloc --- src/core/linker.cpp | 10 ++++++++-- src/core/linker.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 1da88dd4d..d4a15825b 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -305,6 +305,7 @@ void* Linker::TlsGetAddr(u64 module_index, u64 offset) { // Module was just loaded by above code. Allocate TLS block for it. Module* module = m_modules[module_index - 1].get(); const u32 init_image_size = module->tls.init_image_size; + // TODO: Determine if Windows will crash from this u8* dest = reinterpret_cast(heap_api->heap_malloc(module->tls.image_size)); const u8* src = reinterpret_cast(module->tls.image_virtual_addr); std::memcpy(dest, src, init_image_size); @@ -336,9 +337,13 @@ 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 + 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"); - // TODO: ref rtld_tls_block_malloc, tls malloc replacement - // addr_out = heap_api->heap_malloc(total_tls_size); addr_out = std::malloc(total_tls_size); if (!addr_out) { auto pth_id = pthread_self(); @@ -347,6 +352,7 @@ void Linker::InitTlsForThread(bool is_primary) { "Cannot allocate TLS block defined for handle=%x, index=%d size=%d", handle, pth_id, total_tls_size); } +#endif } } diff --git a/src/core/linker.h b/src/core/linker.h index 4ac6861f5..ed1fe400c 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -60,7 +60,7 @@ struct HeapAPI { PS4_SYSV_ABI size_t (*heap_malloc_usable_size)(void*); }; -typedef HeapAPI* AppHeapAPI; +using AppHeapAPI = HeapAPI*; class Linker { public: