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.
This commit is contained in:
Stephen Miller 2026-07-09 13:14:58 -05:00 committed by GitHub
parent aa18760e5e
commit ff253dafe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -89,10 +89,9 @@ void Linker::Execute(const std::vector<std::string>& 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);