diff --git a/src/core/libraries/sysmodule/sysmodule_internal.cpp b/src/core/libraries/sysmodule/sysmodule_internal.cpp index 4a4fb63a7..9099817ee 100644 --- a/src/core/libraries/sysmodule/sysmodule_internal.cpp +++ b/src/core/libraries/sysmodule/sysmodule_internal.cpp @@ -222,7 +222,6 @@ s32 loadModuleInternal(s32 index, s32 argc, const void* argv, s32* res_out) { {"libScePngEnc.sprx", &Libraries::PngEnc::RegisterLib}, {"libSceJson.sprx", nullptr}, {"libSceJson2.sprx", nullptr}, - {"libSceLibcInternal.sprx", &Libraries::LibcInternal::RegisterLib}, {"libSceCesCs.sprx", nullptr}, {"libSceAudiodec.sprx", nullptr}, {"libSceAudiodecCpu.sprx", nullptr}, diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 4ae002c68..198c024c9 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -17,6 +17,7 @@ #include "core/libraries/kernel/kernel.h" #include "core/libraries/kernel/memory.h" #include "core/libraries/kernel/threads.h" +#include "core/libraries/libc_internal/libc_internal.h" #include "core/libraries/sysmodule/sysmodule.h" #include "core/linker.h" #include "core/memory.h" @@ -75,14 +76,18 @@ void Linker::Execute(const std::vector& args) { // Map libSceLibcInternal const auto& libc_internal_path = EmulatorSettings.GetSysModulesDir() / "libSceLibcInternal.sprx"; + bool has_libcinternal = false; if (std::filesystem::exists(libc_internal_path)) { LoadModule(libc_internal_path); + has_libcinternal = true; + } else { + // Need to load HLE, LLE isn't present + LOG_INFO(Core_Linker, "Can't Load libSceLibcInternal.sprx switching to HLE"); + Libraries::LibcInternal::RegisterLib(&GetHLESymbols()); } // Relocate all modules - for (const auto& m : m_modules) { - Relocate(m.get()); - } + 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 @@ -90,15 +95,17 @@ void Linker::Execute(const std::vector& args) { 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 (has_libcinternal) { + 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); + } } } } @@ -139,7 +146,7 @@ void Linker::Execute(const std::vector& args) { memory->SetupMemoryRegions(fmem_size, use_extended_mem1, use_extended_mem2); - main_thread.Run([this, module, &args](std::stop_token) { + main_thread.Run([this, module, &args, has_libcinternal](std::stop_token) { Common::SetCurrentThreadName("Game:Main"); std::set_terminate(Common::Log::Terminate); @@ -153,12 +160,14 @@ void Linker::Execute(const std::vector& args) { } // Load libSceLibcInternal, run malloc_init. - LoadLibcInternal(); + if (has_libcinternal) { + LoadLibcInternal(); - if (malloc_init != nullptr) { - // Call _malloc_init - s32 ret = malloc_init(); - ASSERT_MSG(ret == 0, "malloc_init failed"); + if (malloc_init != nullptr) { + // Call _malloc_init + s32 ret = malloc_init(); + ASSERT_MSG(ret == 0, "malloc_init failed"); + } } // Have libSceSysmodule preload our libraries.