Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Feb 23, 2025
1 parent b08273b commit 96ec6ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions rpcs3/Emu/Cell/Modules/sceNp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ error_code sceNpDrmProcessExitSpawn(ppu_thread& ppu, vm::cptr<u8> klicensee, vm:

error_code sceNpDrmProcessExitSpawn2(ppu_thread& ppu, vm::cptr<u8> klicensee, vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32 data, u32 data_size, s32 prio, u64 flags)
{
ppu.state += cpu_flag::dbg_pause;
sceNp.warning("sceNpDrmProcessExitSpawn2(klicensee=*0x%x, path=*0x%x, argv=**0x%x, envp=**0x%x, data=*0x%x, data_size=0x%x, prio=%d, flags=0x%x)", klicensee, path, argv, envp, data, data_size, prio, flags);
ppu.check_state();

if (s32 error = npDrmIsAvailable(klicensee, path))
{
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/Cell/PPUAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ struct ppu_module : public Type
std::vector<ppu_segment> segs{}; // Segments
std::vector<ppu_segment> secs{}; // Segment sections
std::vector<ppu_function> funcs{}; // Function list
std::unordered_map<u32, u32> nid_to_use_addr
std::vector<u32> applied_patches; // Patch addresses
std::deque<std::shared_ptr<void>> allocations; // Segment memory allocations
std::map<u32, u32> addr_to_seg_index; // address->segment ordered translator map
Expand Down
33 changes: 21 additions & 12 deletions rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ struct ppu_linkage_info
// FNID -> (export; [imports...])
std::map<u32, info> functions{};
std::map<u32, info> variables{};

// Obsolete
bool imported = false;
};

// Module map
Expand Down Expand Up @@ -940,9 +937,16 @@ static auto ppu_load_exports(const ppu_module<lv2_obj>& _module, ppu_linkage_inf
return result;
}

static auto ppu_load_imports(const ppu_module<lv2_obj>& _module, std::vector<ppu_reloc>& relocs, ppu_linkage_info* link, u32 imports_start, u32 imports_end)
struct import_result_t
{
std::unordered_map<u32, void*> result;
std::unordered_map<u32, void*> import_table;
std::unordered_map<u32, u32> nid_to_use_addr;
};

static import_result_t ppu_load_imports(const ppu_module<lv2_obj>& _module, std::vector<ppu_reloc>& relocs, ppu_linkage_info* link, u32 imports_start, u32 imports_end)
{
import_result_t result;
auto& [import_table, nid_to_use_addr] = result;

std::lock_guard lock(link->mutex);

Expand Down Expand Up @@ -976,12 +980,18 @@ static auto ppu_load_imports(const ppu_module<lv2_obj>& _module, std::vector<ppu
ppu_loader.notice("**** %s import: [%s] (0x%08x) -> 0x%x", module_name, ppu_get_function_name(module_name, fnid), fnid, fstub);

// Function linkage info
auto& flink = link->modules[module_name].functions[fnid];
auto& flink = mlink.functions[fnid];

// Add new import
result.emplace(faddr, &flink);
import_table.emplace(faddr, &flink);
flink.imports.emplace(faddr);
mlink.imported = true;

// Check address
// TODO: The address of use should be extracted from analyser instead
if (fstub && fstub >= _module.segs[0].addr && fstub <= _module.segs[0].addr + _module.segs[0].size)
{
fnid_to_stub_use.emplace(fnid, fstub);
}

// Link address (special HLE function by default)
const u32 link_addr = flink.export_addr ? flink.export_addr : g_fxo->get<ppu_function_manager>().addr;
Expand All @@ -992,7 +1002,7 @@ static auto ppu_load_imports(const ppu_module<lv2_obj>& _module, std::vector<ppu
// Patch refs if necessary (0x2000 seems to be correct flag indicating the presence of additional info)
if (const u32 frefs = (lib.attributes & 0x2000) ? +_module.get_ref<u32>(fnids, i + lib.num_func) : 0)
{
result.emplace(frefs, &flink);
import_table.emplace(frefs, &flink);
flink.frefss.emplace(frefs);
ppu_patch_refs(_module, &relocs, frefs, link_addr);
}
Expand All @@ -1010,12 +1020,11 @@ static auto ppu_load_imports(const ppu_module<lv2_obj>& _module, std::vector<ppu
ppu_loader.notice("**** %s import: &[%s] (ref=*0x%x)", module_name, ppu_get_variable_name(module_name, vnid), vref);

// Variable linkage info
auto& vlink = link->modules[module_name].variables[vnid];
auto& vlink = mlink.variables[vnid];

// Add new import
result.emplace(vref, &vlink);
import_table.emplace(vref, &vlink);
vlink.imports.emplace(vref);
mlink.imported = true;

// Link if available
ppu_patch_refs(_module, &relocs, vref, vlink.export_addr);
Expand Down

0 comments on commit 96ec6ed

Please sign in to comment.