1
0
Fork 0
forked from suyu/suyu

nso: Make LoadModule take a VfsFile by const reference

This commit is contained in:
Lioncash 2018-10-14 20:36:57 -04:00
parent 0732786ddc
commit bb9cf8a127
3 changed files with 9 additions and 11 deletions

View file

@ -141,7 +141,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
const FileSys::VirtualFile module_file = dir->GetFile(module); const FileSys::VirtualFile module_file = dir->GetFile(module);
if (module_file != nullptr) { if (module_file != nullptr) {
const VAddr load_addr = next_load_addr; const VAddr load_addr = next_load_addr;
next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, next_load_addr = AppLoader_NSO::LoadModule(*module_file, load_addr,
std::strcmp(module, "rtld") == 0, pm); std::strcmp(module, "rtld") == 0, pm);
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
// Register module with GDBStub // Register module with GDBStub

View file

@ -93,17 +93,14 @@ static constexpr u32 PageAlignSize(u32 size) {
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
} }
VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, VAddr AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAddr load_base,
bool should_pass_arguments, bool should_pass_arguments,
boost::optional<FileSys::PatchManager> pm) { boost::optional<FileSys::PatchManager> pm) {
if (file == nullptr) if (file.GetSize() < sizeof(NsoHeader))
return {};
if (file->GetSize() < sizeof(NsoHeader))
return {}; return {};
NsoHeader nso_header{}; NsoHeader nso_header{};
if (sizeof(NsoHeader) != file->ReadObject(&nso_header)) if (sizeof(NsoHeader) != file.ReadObject(&nso_header))
return {}; return {};
if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0')) if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0'))
@ -114,7 +111,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
std::vector<u8> program_image; std::vector<u8> program_image;
for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { for (std::size_t i = 0; i < nso_header.segments.size(); ++i) {
std::vector<u8> data = std::vector<u8> data =
file->ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset); file.ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset);
if (nso_header.IsSegmentCompressed(i)) { if (nso_header.IsSegmentCompressed(i)) {
data = DecompressSegment(data, nso_header.segments[i]); data = DecompressSegment(data, nso_header.segments[i]);
} }
@ -172,7 +169,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); Core::CurrentProcess()->LoadModule(std::move(codeset), load_base);
// Register module with GDBStub // Register module with GDBStub
GDBStub::RegisterModule(file->GetName(), load_base, load_base); GDBStub::RegisterModule(file.GetName(), load_base, load_base);
return load_base + image_size; return load_base + image_size;
} }
@ -184,7 +181,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
// Load module // Load module
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
LoadModule(file, base_address, true); LoadModule(*file, base_address, true);
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);

View file

@ -36,7 +36,8 @@ public:
return IdentifyType(file); return IdentifyType(file);
} }
static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, bool should_pass_arguments, static VAddr LoadModule(const FileSys::VfsFile& file, VAddr load_base,
bool should_pass_arguments,
boost::optional<FileSys::PatchManager> pm = boost::none); boost::optional<FileSys::PatchManager> pm = boost::none);
ResultStatus Load(Kernel::Process& process) override; ResultStatus Load(Kernel::Process& process) override;