Register libcinternal symbols if the module isn't present (#4660)

Forgot to properly handle this when I moved the libcinternal module load to linker.
This commit is contained in:
Stephen Miller 2026-07-02 11:41:50 -05:00 committed by GitHub
parent 0a51093d28
commit ebb126c43c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 19 deletions

View File

@ -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},

View File

@ -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<std::string>& 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<std::string>& 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<PS4_SYSV_ABI s32 (*)()>(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<PS4_SYSV_ABI s32 (*)()>(sym.virtual_address);
}
}
}
}
@ -139,7 +146,7 @@ void Linker::Execute(const std::vector<std::string>& 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<std::string>& 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.