diff --git a/rpcs3/Emu/Cell/PPUModule.cpp b/rpcs3/Emu/Cell/PPUModule.cpp index f4532111bf..3ad5626537 100644 --- a/rpcs3/Emu/Cell/PPUModule.cpp +++ b/rpcs3/Emu/Cell/PPUModule.cpp @@ -809,6 +809,11 @@ void try_spawn_ppu_if_exclusive_program(const ppu_module& m) std::shared_ptr ppu_load_prx(const ppu_prx_object& elf, const std::string& path) { + if (elf != elf_error::ok) + { + return nullptr; + } + // Create new PRX object const auto prx = idm::make_ptr(); @@ -1161,6 +1166,11 @@ void ppu_unload_prx(const lv2_prx& prx) bool ppu_load_exec(const ppu_exec_object& elf) { + if (elf != elf_error::ok) + { + return false; + } + // Check if it is a standalone executable first for (const auto& prog : elf.progs) { @@ -1740,6 +1750,11 @@ bool ppu_load_exec(const ppu_exec_object& elf) std::pair, CellError> ppu_load_overlay(const ppu_exec_object& elf, const std::string& path) { + if (elf != elf_error::ok) + { + return {nullptr, CELL_ENOENT}; + } + // Access linkage information object const auto link = g_fxo->get(); diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 4fdadf4c39..c4f124b992 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -2423,13 +2423,14 @@ extern void ppu_precompile(std::vector& dir_queue, std::vector(idm::last_id()); lock.lock(); @@ -2443,7 +2444,7 @@ extern void ppu_precompile(std::vector& dir_queue, std::vector& dir_queue, std::vectorsegs) diff --git a/rpcs3/Emu/Cell/lv2/sys_overlay.cpp b/rpcs3/Emu/Cell/lv2/sys_overlay.cpp index 3c7609dc9f..bff88aaa00 100644 --- a/rpcs3/Emu/Cell/lv2/sys_overlay.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_overlay.cpp @@ -35,7 +35,7 @@ static error_code overlay_load_module(vm::ptr ovlmid, const std::string& vp u128 klic = g_fxo->get()->devKlic.load(); - const ppu_exec_object obj = decrypt_self(std::move(src), reinterpret_cast(&klic)); + ppu_exec_object obj = decrypt_self(std::move(src), reinterpret_cast(&klic)); if (obj != elf_error::ok) { @@ -44,6 +44,8 @@ static error_code overlay_load_module(vm::ptr ovlmid, const std::string& vp const auto [ovlm, error] = ppu_load_overlay(obj, vfs::get(vpath)); + obj.clear(); + if (error) { return error; diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.cpp b/rpcs3/Emu/Cell/lv2/sys_prx.cpp index 1f74cdaab0..4d54456a77 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_prx.cpp @@ -266,7 +266,7 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptrget()->devKlic.load(); - const ppu_prx_object obj = decrypt_self(std::move(src), reinterpret_cast(&klic)); + ppu_prx_object obj = decrypt_self(std::move(src), reinterpret_cast(&klic)); if (obj != elf_error::ok) { @@ -275,6 +275,8 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr class en_t, typename sz_t, elf_machine Machine, elf_os OS, elf_type Type> class elf_object { - elf_error m_error{}; - - elf_error set_error(elf_error e) - { - return m_error = e; - } + elf_error m_error = elf_error::stream; // Set initial error to "file not found" error public: using ehdr_t = elf_ehdr; @@ -329,6 +324,31 @@ public: } } + elf_object& clear() + { + // Do not use clear() in order to dealloc memory + progs = {}; + shdrs = {}; + header.e_magic = 0; + m_error = elf_error::stream; + return *this; + } + + elf_object& set_error(elf_error error) + { + // Setting an error causes the state to clear if there was no error before + // Trying to set elf_error::ok is ignored + if (error != elf_error::ok) + { + if (m_error == elf_error::ok) + clear(); + + m_error = error; + } + + return *this; + } + // Return error code operator elf_error() const {