From b51c767296e38b8fff86fb790fd20c2acdcb3f91 Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Sun, 9 Feb 2025 21:31:07 -0600 Subject: [PATCH] Better bounds checks for sceKernelDlsym (#2394) Unity, being the awful game engine it is, checks for a return value of zero to determine if sceKernelLoadStartModule failed. This results in it throwing an error code into sceKernelDlsym's handle parameter when the module it's searching for doesn't exist. --- src/core/libraries/kernel/process.cpp | 3 +++ src/core/linker.h | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/libraries/kernel/process.cpp b/src/core/libraries/kernel/process.cpp index 3a747bf16..58628867a 100644 --- a/src/core/libraries/kernel/process.cpp +++ b/src/core/libraries/kernel/process.cpp @@ -75,6 +75,9 @@ s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t arg s32 PS4_SYSV_ABI sceKernelDlsym(s32 handle, const char* symbol, void** addrp) { auto* linker = Common::Singleton::Instance(); auto* module = linker->GetModule(handle); + if (module == nullptr) { + return ORBIS_KERNEL_ERROR_ESRCH; + } *addrp = module->FindByName(symbol); if (*addrp == nullptr) { return ORBIS_KERNEL_ERROR_ESRCH; diff --git a/src/core/linker.h b/src/core/linker.h index 357b39664..9c07400c4 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -83,7 +83,10 @@ public: } Module* GetModule(s32 index) const { - return m_modules.at(index).get(); + if (index >= 0 || index < m_modules.size()) { + return m_modules.at(index).get(); + } + return nullptr; } u32 FindByName(const std::filesystem::path& name) const {