Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rpcs3/Emu/Cell/PPUAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down
8 changes: 5 additions & 3 deletions rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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)
{
Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/lv2/sys_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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();

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions rpcs3/Emu/Cell/lv2/sys_prx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down