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.
This commit is contained in:
Stephen Miller 2026-03-09 12:11:49 -05:00
parent 19a99dec41
commit ab9577c088
3 changed files with 2 additions and 101 deletions

View File

@ -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) {

View File

@ -69,80 +69,11 @@ void Linker::Execute(const std::vector<std::string>& 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<PS4_SYSV_ABI s32 (*)()>(sym.virtual_address);
}
if (sym.nid_name.compare("malloc") == 0) {
heap_api->heap_malloc =
reinterpret_cast<PS4_SYSV_ABI void* (*)(u64)>(sym.virtual_address);
}
if (sym.nid_name.compare("free") == 0) {
heap_api->heap_free =
reinterpret_cast<PS4_SYSV_ABI void (*)(void*)>(sym.virtual_address);
}
if (sym.nid_name.compare("calloc") == 0) {
heap_api->heap_calloc =
reinterpret_cast<PS4_SYSV_ABI void* (*)(u64, u64)>(sym.virtual_address);
}
if (sym.nid_name.compare("realloc") == 0) {
heap_api->heap_realloc =
reinterpret_cast<PS4_SYSV_ABI void* (*)(void*, u64)>(sym.virtual_address);
}
if (sym.nid_name.compare("memalign") == 0) {
heap_api->heap_memalign =
reinterpret_cast<PS4_SYSV_ABI void* (*)(u64, u64)>(sym.virtual_address);
}
if (sym.nid_name.compare("posix_memalign") == 0) {
heap_api->heap_posix_memalign =
reinterpret_cast<PS4_SYSV_ABI s32 (*)(void**, u64, u64)>(
sym.virtual_address);
}
if (sym.nid_name.compare("reallocalign") == 0) {
heap_api->heap_reallocalign =
reinterpret_cast<PS4_SYSV_ABI s32 (*)(void*, u64, u64)>(
sym.virtual_address);
}
if (sym.nid_name.compare("malloc_stats") == 0) {
heap_api->heap_malloc_stats =
reinterpret_cast<PS4_SYSV_ABI s32 (*)(void*)>(sym.virtual_address);
}
if (sym.nid_name.compare("malloc_stats_fast") == 0) {
heap_api->heap_malloc_stats_fast =
reinterpret_cast<PS4_SYSV_ABI s32 (*)(void*)>(sym.virtual_address);
}
if (sym.nid_name.compare("malloc_usable_size") == 0) {
heap_api->heap_malloc_usable_size =
reinterpret_cast<PS4_SYSV_ABI u64 (*)(void*)>(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<std::string>& 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();

View File

@ -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<AppHeapAPI>(func);
}