From ab9577c08870bb671ab8793a1e5d70fc56030f26 Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:11:49 -0500 Subject: [PATCH] Remove malloc_init stuff Keeping my heap API definition fixes though, since that's a valid change. Also adding back libScePadTracker LLE, shadow removed it during rebase, but it should still "work" with these changes. --- .../sysmodule/sysmodule_internal.cpp | 9 +-- src/core/linker.cpp | 78 ------------------- src/core/linker.h | 16 ---- 3 files changed, 2 insertions(+), 101 deletions(-) diff --git a/src/core/libraries/sysmodule/sysmodule_internal.cpp b/src/core/libraries/sysmodule/sysmodule_internal.cpp index 5658b7c4c..bebf64c65 100644 --- a/src/core/libraries/sysmodule/sysmodule_internal.cpp +++ b/src/core/libraries/sysmodule/sysmodule_internal.cpp @@ -223,7 +223,8 @@ s32 loadModuleInternal(s32 index, s32 argc, const void* argv, s32* res_out) { {"libSceAudiodec.sprx", nullptr}, {"libSceFont.sprx", &Libraries::Font::RegisterlibSceFont}, {"libSceFontFt.sprx", &Libraries::FontFt::RegisterlibSceFontFt}, - {"libSceFreeTypeOt.sprx", nullptr}}); + {"libSceFreeTypeOt.sprx", nullptr}, + {"libScePadTracker.sprx", nullptr}}); // Iterate through the allowed array const auto it = std::ranges::find_if( @@ -425,12 +426,6 @@ s32 preloadModulesForLibkernel() { continue; } - if (module_index == 1 || module_index == 2) { - // libkernel and libSceLibcInternal aren't directly loaded here. - // All we do for those is increment is_loaded - g_modules_array[module_index].is_loaded++; - } - // Load the actual module s32 result = loadModuleInternal(module_index, 0, nullptr, nullptr); if (result != ORBIS_OK) { diff --git a/src/core/linker.cpp b/src/core/linker.cpp index d9f85e770..a8a97b2a6 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -69,80 +69,11 @@ void Linker::Execute(const std::vector& args) { Module* module = m_modules[0].get(); static_tls_size = module->tls.offset = module->tls.image_size; - // Map libSceLibcInternal - const auto& libc_internal_path = - EmulatorSettings.GetSysModulesDir() / "libSceLibcInternal.sprx"; - if (std::filesystem::exists(libc_internal_path)) { - LoadModule(libc_internal_path); - } - // Relocate all modules for (const auto& m : m_modules) { Relocate(m.get()); } - // 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{}; - static PS4_SYSV_ABI s32 (*malloc_init)() = nullptr; - - for (const auto& m : m_modules) { - const auto& mod = m.get(); - if (mod->name.contains("libSceLibcInternal.sprx")) { - // Found libSceLibcInternal, now search through function exports. - // Looking for _malloc_init to init libSceLibcInternal properly - // and for all the memory allocating functions, so we can initialize our heap API - for (const auto& sym : mod->export_sym.GetSymbols()) { - if (sym.nid_name.compare("_malloc_init") == 0) { - malloc_init = reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("malloc") == 0) { - heap_api->heap_malloc = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("free") == 0) { - heap_api->heap_free = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("calloc") == 0) { - heap_api->heap_calloc = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("realloc") == 0) { - heap_api->heap_realloc = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("memalign") == 0) { - heap_api->heap_memalign = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("posix_memalign") == 0) { - heap_api->heap_posix_memalign = - reinterpret_cast( - sym.virtual_address); - } - if (sym.nid_name.compare("reallocalign") == 0) { - heap_api->heap_reallocalign = - reinterpret_cast( - sym.virtual_address); - } - if (sym.nid_name.compare("malloc_stats") == 0) { - heap_api->heap_malloc_stats = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("malloc_stats_fast") == 0) { - heap_api->heap_malloc_stats_fast = - reinterpret_cast(sym.virtual_address); - } - if (sym.nid_name.compare("malloc_usable_size") == 0) { - heap_api->heap_malloc_usable_size = - reinterpret_cast(sym.virtual_address); - } - } - } - } - // Configure the direct and flexible memory regions. u64 fmem_size = ORBIS_FLEXIBLE_MEMORY_SIZE; bool use_extended_mem1 = true, use_extended_mem2 = true; @@ -189,15 +120,6 @@ void Linker::Execute(const std::vector& args) { ipc.WaitForStart(); } - // Load libSceLibcInternal, run malloc_init. - LoadLibcInternal(); - - if (malloc_init != nullptr) { - // Call _malloc_init - s32 ret = malloc_init(); - ASSERT_MSG(ret == 0, "malloc_init failed"); - } - // Have libSceSysmodule preload our libraries. Libraries::SysModule::sceSysmodulePreloadModuleForLibkernel(); diff --git a/src/core/linker.h b/src/core/linker.h index e2efccbb0..0f6b19d83 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -124,22 +124,6 @@ public: } } - void LoadLibcInternal() { - for (auto& module : m_modules) { - if (module->name.contains("libSceLibcInternal")) { - module->Start(0, nullptr, nullptr); - } - } - } - - void LoadSharedLibraries() { - for (auto& module : m_modules) { - if (module->IsSharedLib() && !module->name.contains("libSceLibcInternal")) { - module->Start(0, nullptr, nullptr); - } - } - } - void SetHeapAPI(void* func[]) { heap_api = reinterpret_cast(func); }