From ff253dafe18d40b6f2859356c10d154cbf1e5b08 Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Thu, 9 Jul 2026 13:14:58 -0500 Subject: [PATCH] Fix heap_api checks (#4690) * Fix check for heap_malloc libkernel checks to see if heap_api's heap_malloc is present before calling it. In some homebrew and firmware apps, heap_api doesn't get provided, and heap_malloc can be null. * Actual fix One leftover line from some removed hacks was breaking the heap_api stuff. --- src/core/linker.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core/linker.cpp b/src/core/linker.cpp index e0a3ef1cc..f63f91141 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -89,10 +89,9 @@ void Linker::Execute(const std::vector& args) { // Relocate all modules RelocateAllImports(); - // Before we can run guest code, we need to properly initialize the heap API and - // libSceLibcInternal. libSceLibcInternal's _malloc_init serves as an additional initialization - // function called by libkernel. - heap_api = new HeapAPI{}; + // If we're running LLE libSceLibcInternal, + // we need to find the _malloc_init function and run it manually. + // This is something libkernel runs during initialization. static PS4_SYSV_ABI s32 (*malloc_init)() = nullptr; if (has_libcinternal) { @@ -491,7 +490,7 @@ void* Linker::AllocateTlsForThread(bool is_primary) { &addr_out, tls_aligned, 3, 0, "SceKernelPrimaryTcbTls"); ASSERT_MSG(ret == 0, "Unable to allocate TLS+TCB for the primary thread"); } else { - if (heap_api) { + if (heap_api && heap_api->heap_malloc) { addr_out = heap_api->heap_malloc(total_tls_size); } else { addr_out = std::malloc(total_tls_size); @@ -501,7 +500,7 @@ void* Linker::AllocateTlsForThread(bool is_primary) { } void Linker::FreeTlsForNonPrimaryThread(void* pointer) { - if (heap_api) { + if (heap_api && heap_api->heap_free) { heap_api->heap_free(pointer); } else { std::free(pointer);