nso: Optimize loading of IPS patches

Avoid resource-heavy classes and remove quasi-duplicated code.
This commit is contained in:
Zach Hilman 2018-10-02 17:03:34 -04:00
parent 6d441828e6
commit 215b65fe75
5 changed files with 43 additions and 51 deletions

View file

@ -130,6 +130,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
}
process.LoadFromMetadata(metadata);
const FileSys::PatchManager pm(metadata.GetTitleID());
// Load NSO modules
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
@ -139,9 +140,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
const FileSys::VirtualFile module_file = dir->GetFile(module);
if (module_file != nullptr) {
const VAddr load_addr = next_load_addr;
next_load_addr = AppLoader_NSO::LoadModule(
module_file, load_addr,
std::make_shared<FileSys::PatchManager>(metadata.GetTitleID()));
next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm);
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
// Register module with GDBStub
GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false);

View file

@ -94,7 +94,7 @@ static constexpr u32 PageAlignSize(u32 size) {
}
VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
std::shared_ptr<FileSys::PatchManager> pm) {
boost::optional<FileSys::PatchManager> pm) {
if (file == nullptr)
return {};
@ -144,7 +144,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
program_image.resize(image_size);
// Apply patches if necessary
if (pm != nullptr && pm->HasNSOPatch(nso_header.build_id)) {
if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) {
std::vector<u8> pi_header(program_image.size() + 0x100);
std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader));
std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size());

View file

@ -28,7 +28,7 @@ public:
}
static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base,
std::shared_ptr<FileSys::PatchManager> pm = nullptr);
boost::optional<FileSys::PatchManager> pm = boost::none);
ResultStatus Load(Kernel::Process& process) override;
};