diff options
| author | 2018-10-15 17:48:36 -0400 | |
|---|---|---|
| committer | 2018-10-15 17:48:36 -0400 | |
| commit | 50e6205c21e398da6554b8c70b801f98035cc456 (patch) | |
| tree | 4929a2300446ae6965191ac5c600a3f767468089 /src/core/loader/nso.cpp | |
| parent | Merge pull request #1500 from DarkLordZach/key-derivation-6.0.0 (diff) | |
| parent | nso: Return an optional address from LoadModule (diff) | |
| download | yuzu-50e6205c21e398da6554b8c70b801f98035cc456.tar.gz yuzu-50e6205c21e398da6554b8c70b801f98035cc456.tar.xz yuzu-50e6205c21e398da6554b8c70b801f98035cc456.zip | |
Merge pull request #1499 from lioncash/nro
nro/nso: Minor error handling changes
Diffstat (limited to 'src/core/loader/nso.cpp')
| -rw-r--r-- | src/core/loader/nso.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index ba57db9bf..68efca5c0 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -93,17 +93,14 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 93 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | 96 | std::optional<VAddr> AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAddr load_base, |
| 97 | bool should_pass_arguments, | 97 | bool should_pass_arguments, |
| 98 | boost::optional<FileSys::PatchManager> pm) { | 98 | std::optional<FileSys::PatchManager> pm) { |
| 99 | if (file == nullptr) | 99 | if (file.GetSize() < sizeof(NsoHeader)) |
| 100 | return {}; | ||
| 101 | |||
| 102 | if (file->GetSize() < sizeof(NsoHeader)) | ||
| 103 | return {}; | 100 | return {}; |
| 104 | 101 | ||
| 105 | NsoHeader nso_header{}; | 102 | NsoHeader nso_header{}; |
| 106 | if (sizeof(NsoHeader) != file->ReadObject(&nso_header)) | 103 | if (sizeof(NsoHeader) != file.ReadObject(&nso_header)) |
| 107 | return {}; | 104 | return {}; |
| 108 | 105 | ||
| 109 | if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0')) | 106 | if (nso_header.magic != Common::MakeMagic('N', 'S', 'O', '0')) |
| @@ -114,7 +111,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | |||
| 114 | std::vector<u8> program_image; | 111 | std::vector<u8> program_image; |
| 115 | for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { | 112 | for (std::size_t i = 0; i < nso_header.segments.size(); ++i) { |
| 116 | std::vector<u8> data = | 113 | std::vector<u8> data = |
| 117 | file->ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset); | 114 | file.ReadBytes(nso_header.segments_compressed_size[i], nso_header.segments[i].offset); |
| 118 | if (nso_header.IsSegmentCompressed(i)) { | 115 | if (nso_header.IsSegmentCompressed(i)) { |
| 119 | data = DecompressSegment(data, nso_header.segments[i]); | 116 | data = DecompressSegment(data, nso_header.segments[i]); |
| 120 | } | 117 | } |
| @@ -157,7 +154,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | |||
| 157 | program_image.resize(image_size); | 154 | program_image.resize(image_size); |
| 158 | 155 | ||
| 159 | // Apply patches if necessary | 156 | // Apply patches if necessary |
| 160 | if (pm != boost::none && pm->HasNSOPatch(nso_header.build_id)) { | 157 | if (pm && pm->HasNSOPatch(nso_header.build_id)) { |
| 161 | std::vector<u8> pi_header(program_image.size() + 0x100); | 158 | std::vector<u8> pi_header(program_image.size() + 0x100); |
| 162 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); | 159 | std::memcpy(pi_header.data(), &nso_header, sizeof(NsoHeader)); |
| 163 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); | 160 | std::memcpy(pi_header.data() + 0x100, program_image.data(), program_image.size()); |
| @@ -172,7 +169,7 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | |||
| 172 | Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); | 169 | Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); |
| 173 | 170 | ||
| 174 | // Register module with GDBStub | 171 | // Register module with GDBStub |
| 175 | GDBStub::RegisterModule(file->GetName(), load_base, load_base); | 172 | GDBStub::RegisterModule(file.GetName(), load_base, load_base); |
| 176 | 173 | ||
| 177 | return load_base + image_size; | 174 | return load_base + image_size; |
| 178 | } | 175 | } |
| @@ -184,7 +181,9 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { | |||
| 184 | 181 | ||
| 185 | // Load module | 182 | // Load module |
| 186 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 183 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| 187 | LoadModule(file, base_address, true); | 184 | if (!LoadModule(*file, base_address, true)) { |
| 185 | return ResultStatus::ErrorLoadingNSO; | ||
| 186 | } | ||
| 188 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); | 187 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); |
| 189 | 188 | ||
| 190 | process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); | 189 | process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); |