From f6ad90fab8e577bbb9dbb443c61f7a26a55b957f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 14 Mar 2021 16:52:48 -0700 Subject: [PATCH] Module: Correctly handle modules with -1 entry. It should not try to run, options or not. --- Core/ELF/ElfReader.cpp | 3 ++- Core/HLE/sceKernelModule.cpp | 14 +++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Core/ELF/ElfReader.cpp b/Core/ELF/ElfReader.cpp index 917bcb48f1..69328d49e2 100644 --- a/Core/ELF/ElfReader.cpp +++ b/Core/ELF/ElfReader.cpp @@ -445,7 +445,8 @@ int ElfReader::LoadInto(u32 loadAddress, bool fromTop) if (bRelocate) { DEBUG_LOG(LOADER,"Relocatable module"); - entryPoint += vaddr; + if (entryPoint != (u32)-1) + entryPoint += vaddr; } else { DEBUG_LOG(LOADER,"Prerelocated executable"); } diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index cd98ce0b00..b6b270d916 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -2085,16 +2085,6 @@ int KernelStartModule(SceUID moduleId, u32 argsize, u32 argAddr, u32 returnValue entryAddr = module->nm.module_start_func; if (module->nm.module_start_thread_attr != 0) attribute = module->nm.module_start_thread_attr; - } else if (entryAddr == (u32)-1 || entryAddr == module->memoryBlockAddr - 1) { - if (smoption) { - // TODO: Does sceKernelStartModule() really give an error when no entry only if you pass options? - attribute = smoption->attribute; - } else { - // TODO: Why are we just returning the module ID in this case? - WARN_LOG(SCEMODULE, "sceKernelStartModule(): module has no start or entry func"); - module->nm.status = MODULE_STATUS_STARTED; - return moduleId; - } } if (Memory::IsValidAddress(entryAddr)) { @@ -2110,6 +2100,8 @@ int KernelStartModule(SceUID moduleId, u32 argsize, u32 argAddr, u32 returnValue stacksize = module->nm.module_start_thread_stacksize; } + // TODO: Why do we skip smoption->attribute here? + SceUID threadID = __KernelCreateThread(module->nm.name, moduleId, entryAddr, priority, stacksize, attribute, 0, (module->nm.attribute & 0x1000) != 0); __KernelStartThreadValidate(threadID, argsize, argAddr); __KernelSetThreadRA(threadID, NID_MODULERETURN); @@ -2117,7 +2109,7 @@ int KernelStartModule(SceUID moduleId, u32 argsize, u32 argAddr, u32 returnValue if (needsWait) { *needsWait = true; } - } else if (entryAddr == 0) { + } else if (entryAddr == 0 || entryAddr == (u32)-1) { INFO_LOG(SCEMODULE, "sceKernelStartModule(%d,asize=%08x,aptr=%08x,retptr=%08x): no entry address", moduleId, argsize, argAddr, returnValueAddr); module->nm.status = MODULE_STATUS_STARTED; } else {