1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

sys_prx/overlay: Fix disambiguator of module names opened by FD (#10340)

Don't append zero offset.
This commit is contained in:
Eladash 2021-05-26 23:38:17 +03:00 committed by GitHub
parent 5b4631dcf9
commit f103004aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 18 deletions

View File

@ -82,6 +82,7 @@ struct ppu_module
uchar sha1[20]{};
std::string name{};
std::string path{};
s64 offset = 0; // Offset of file
std::string cache{};
std::vector<ppu_reloc> relocs{};
std::vector<ppu_segment> segs{};

View File

@ -832,7 +832,7 @@ void try_spawn_ppu_if_exclusive_program(const ppu_module& m)
}
}
std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object& elf, const std::string& path)
std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object& elf, const std::string& path, s64 file_offset)
{
if (elf != elf_error::ok)
{
@ -1111,6 +1111,7 @@ std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object& elf, const std::stri
prx->epilogue.set(prx->specials[0x330f7005]);
prx->name = path.substr(path.find_last_of('/') + 1);
prx->path = path;
prx->offset = file_offset;
sha1_finish(&sha, prx->sha1);
@ -1588,7 +1589,7 @@ bool ppu_load_exec(const ppu_exec_object& elf)
{
ppu_loader.warning("Loading library: %s", name);
auto prx = ppu_load_prx(obj, lle_dir + name);
auto prx = ppu_load_prx(obj, lle_dir + name, 0);
if (prx->funcs.empty())
{
@ -1807,7 +1808,7 @@ bool ppu_load_exec(const ppu_exec_object& elf)
return true;
}
std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object& elf, const std::string& path)
std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object& elf, const std::string& path, s64 file_offset)
{
if (elf != elf_error::ok)
{
@ -1843,6 +1844,7 @@ std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_ex
// Set path (TODO)
ovlm->name = path.substr(path.find_last_of('/') + 1);
ovlm->path = path;
ovlm->offset = file_offset;
u32 end = 0;

View File

@ -126,9 +126,9 @@ extern void ppu_initialize();
extern void ppu_finalize(const ppu_module& info);
extern bool ppu_initialize(const ppu_module& info, bool = false);
static void ppu_initialize2(class jit_compiler& jit, const ppu_module& module_part, const std::string& cache_path, const std::string& obj_name);
extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object&, const std::string& path);
extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object&, const std::string& path, s64 file_offset);
extern void ppu_unload_prx(const lv2_prx&);
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&);
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&, s64 file_offset);
extern void ppu_execute_syscall(ppu_thread& ppu, u64 code);
static bool ppu_break(ppu_thread& ppu, ppu_opcode_t op);
@ -2493,7 +2493,7 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
{
std::unique_lock lock(sprx_mtx);
if (auto prx = ppu_load_prx(obj, path))
if (auto prx = ppu_load_prx(obj, path, offset))
{
lock.unlock();
obj.clear(), src.close(); // Clear decrypted file and elf object memory
@ -2517,7 +2517,7 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
// Only one thread compiles OVL atm, other can compile PRX cuncurrently
std::unique_lock lock(ovl_mtx);
auto [ovlm, error] = ppu_load_overlay(obj, path);
auto [ovlm, error] = ppu_load_overlay(obj, path, offset);
if (error)
{

View File

@ -12,14 +12,14 @@
#include "sys_overlay.h"
#include "sys_fs.h"
extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object&, const std::string& path);
extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object&, const std::string& path, s64 file_offset);
extern bool ppu_initialize(const ppu_module&, bool = false);
extern void ppu_finalize(const ppu_module&);
LOG_CHANNEL(sys_overlay);
static error_code overlay_load_module(vm::ptr<u32> ovlmid, const std::string& vpath, u64 /*flags*/, vm::ptr<u32> entry, fs::file src = {})
static error_code overlay_load_module(vm::ptr<u32> ovlmid, const std::string& vpath, u64 /*flags*/, vm::ptr<u32> entry, fs::file src = {}, s64 file_offset = 0)
{
if (!src)
{
@ -42,7 +42,7 @@ static error_code overlay_load_module(vm::ptr<u32> ovlmid, const std::string& vp
return {CELL_ENOEXEC, obj.operator elf_error()};
}
const auto [ovlm, error] = ppu_load_overlay(obj, vfs::get(vpath));
const auto [ovlm, error] = ppu_load_overlay(obj, vfs::get(vpath), file_offset);
obj.clear();
@ -108,7 +108,7 @@ error_code sys_overlay_load_module_by_fd(vm::ptr<u32> ovlmid, u32 fd, u64 offset
return CELL_EBADF;
}
return overlay_load_module(ovlmid, fmt::format("%s_x%x", file->name.data(), offset), flags, entry, lv2_file::make_view(file, offset));
return overlay_load_module(ovlmid, offset ? fmt::format("%s_x%x", file->name.data(), offset) : file->name.data(), flags, entry, lv2_file::make_view(file, offset), offset);
}
error_code sys_overlay_unload_module(u32 ovlmid)

View File

@ -15,7 +15,7 @@
#include "sys_process.h"
#include "sys_memory.h"
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&);
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&, s64);
extern void ppu_unload_prx(const lv2_prx& prx);
extern bool ppu_initialize(const ppu_module&, bool = false);
extern void ppu_finalize(const ppu_module&);
@ -169,7 +169,7 @@ extern const std::map<std::string_view, int> g_prx_list
{ "libwmadec.sprx", 0 },
};
static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<sys_prx_load_module_option_t> /*pOpt*/, fs::file src = {})
static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<sys_prx_load_module_option_t> /*pOpt*/, fs::file src = {}, s64 file_offset = 0)
{
if (flags != 0)
{
@ -192,7 +192,7 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<s
const auto existing = idm::select<lv2_obj, lv2_prx>([&](u32, lv2_prx& prx)
{
return prx.path == path;
return prx.path == path && prx.offset == file_offset;
});
if (existing)
@ -274,7 +274,7 @@ static error_code prx_load_module(const std::string& vpath, u64 flags, vm::ptr<s
return CELL_PRX_ERROR_ILLEGAL_LIBRARY;
}
const auto prx = ppu_load_prx(obj, path);
const auto prx = ppu_load_prx(obj, path, file_offset);
obj.clear();
@ -318,7 +318,7 @@ error_code _sys_prx_load_module_by_fd(ppu_thread& ppu, s32 fd, u64 offset, u64 f
return CELL_EBADF;
}
return prx_load_module(fmt::format("%s_x%x", file->name.data(), offset), flags, pOpt, lv2_file::make_view(file, offset));
return prx_load_module(offset ? fmt::format("%s_x%x", file->name.data(), offset) : file->name.data(), flags, pOpt, lv2_file::make_view(file, offset), offset);
}
error_code _sys_prx_load_module_on_memcontainer_by_fd(ppu_thread& ppu, s32 fd, u64 offset, u32 mem_ct, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)

View File

@ -63,8 +63,8 @@ extern void ppu_precompile(std::vector<std::string>& dir_queue, std::vector<lv2_
extern bool ppu_initialize(const ppu_module&, bool = false);
extern void ppu_finalize(const ppu_module&);
extern void ppu_unload_prx(const lv2_prx&);
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&);
extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object&, const std::string& path);
extern std::shared_ptr<lv2_prx> ppu_load_prx(const ppu_prx_object&, const std::string&, s64 = 0);
extern std::pair<std::shared_ptr<lv2_overlay>, CellError> ppu_load_overlay(const ppu_exec_object&, const std::string& path, s64 = 0);
fs::file g_tty;
atomic_t<s64> g_tty_size{0};