diff options
| author | 2019-04-19 19:09:20 -0400 | |
|---|---|---|
| committer | 2019-04-19 19:09:20 -0400 | |
| commit | 40dc893c372c81c687eca2d0b964220a8f8aeab4 (patch) | |
| tree | 1c05675d446978752a749f2cb18a797c6b737998 /src/core/loader | |
| parent | Merge pull request #2397 from lioncash/thread-unused (diff) | |
| parent | core/core: Move process execution start to System's Load() (diff) | |
| download | yuzu-40dc893c372c81c687eca2d0b964220a8f8aeab4.tar.gz yuzu-40dc893c372c81c687eca2d0b964220a8f8aeab4.tar.xz yuzu-40dc893c372c81c687eca2d0b964220a8f8aeab4.zip | |
Merge pull request #2374 from lioncash/pagetable
core: Reorganize boot order
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 40 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 2 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 15 | ||||
| -rw-r--r-- | src/core/loader/elf.h | 2 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 8 | ||||
| -rw-r--r-- | src/core/loader/nax.cpp | 30 | ||||
| -rw-r--r-- | src/core/loader/nax.h | 2 | ||||
| -rw-r--r-- | src/core/loader/nca.cpp | 26 | ||||
| -rw-r--r-- | src/core/loader/nca.h | 2 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 14 | ||||
| -rw-r--r-- | src/core/loader/nro.h | 2 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 11 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 2 | ||||
| -rw-r--r-- | src/core/loader/nsp.cpp | 38 | ||||
| -rw-r--r-- | src/core/loader/nsp.h | 2 | ||||
| -rw-r--r-- | src/core/loader/xci.cpp | 28 | ||||
| -rw-r--r-- | src/core/loader/xci.h | 2 |
17 files changed, 128 insertions, 98 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 07aa7a1cd..10b13fb1d 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -86,25 +86,29 @@ FileType AppLoader_DeconstructedRomDirectory::IdentifyType(const FileSys::Virtua | |||
| 86 | return FileType::Error; | 86 | return FileType::Error; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) { | 89 | AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirectory::Load( |
| 90 | Kernel::Process& process) { | ||
| 90 | if (is_loaded) { | 91 | if (is_loaded) { |
| 91 | return ResultStatus::ErrorAlreadyLoaded; | 92 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | if (dir == nullptr) { | 95 | if (dir == nullptr) { |
| 95 | if (file == nullptr) | 96 | if (file == nullptr) { |
| 96 | return ResultStatus::ErrorNullFile; | 97 | return {ResultStatus::ErrorNullFile, {}}; |
| 98 | } | ||
| 99 | |||
| 97 | dir = file->GetContainingDirectory(); | 100 | dir = file->GetContainingDirectory(); |
| 98 | } | 101 | } |
| 99 | 102 | ||
| 100 | // Read meta to determine title ID | 103 | // Read meta to determine title ID |
| 101 | FileSys::VirtualFile npdm = dir->GetFile("main.npdm"); | 104 | FileSys::VirtualFile npdm = dir->GetFile("main.npdm"); |
| 102 | if (npdm == nullptr) | 105 | if (npdm == nullptr) { |
| 103 | return ResultStatus::ErrorMissingNPDM; | 106 | return {ResultStatus::ErrorMissingNPDM, {}}; |
| 107 | } | ||
| 104 | 108 | ||
| 105 | ResultStatus result = metadata.Load(npdm); | 109 | const ResultStatus result = metadata.Load(npdm); |
| 106 | if (result != ResultStatus::Success) { | 110 | if (result != ResultStatus::Success) { |
| 107 | return result; | 111 | return {result, {}}; |
| 108 | } | 112 | } |
| 109 | 113 | ||
| 110 | if (override_update) { | 114 | if (override_update) { |
| @@ -114,23 +118,24 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 114 | 118 | ||
| 115 | // Reread in case PatchExeFS affected the main.npdm | 119 | // Reread in case PatchExeFS affected the main.npdm |
| 116 | npdm = dir->GetFile("main.npdm"); | 120 | npdm = dir->GetFile("main.npdm"); |
| 117 | if (npdm == nullptr) | 121 | if (npdm == nullptr) { |
| 118 | return ResultStatus::ErrorMissingNPDM; | 122 | return {ResultStatus::ErrorMissingNPDM, {}}; |
| 123 | } | ||
| 119 | 124 | ||
| 120 | ResultStatus result2 = metadata.Load(npdm); | 125 | const ResultStatus result2 = metadata.Load(npdm); |
| 121 | if (result2 != ResultStatus::Success) { | 126 | if (result2 != ResultStatus::Success) { |
| 122 | return result2; | 127 | return {result2, {}}; |
| 123 | } | 128 | } |
| 124 | metadata.Print(); | 129 | metadata.Print(); |
| 125 | 130 | ||
| 126 | const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; | 131 | const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; |
| 127 | if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit || | 132 | if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit || |
| 128 | arch_bits == FileSys::ProgramAddressSpaceType::Is32BitNoMap) { | 133 | arch_bits == FileSys::ProgramAddressSpaceType::Is32BitNoMap) { |
| 129 | return ResultStatus::Error32BitISA; | 134 | return {ResultStatus::Error32BitISA, {}}; |
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | if (process.LoadFromMetadata(metadata).IsError()) { | 137 | if (process.LoadFromMetadata(metadata).IsError()) { |
| 133 | return ResultStatus::ErrorUnableToParseKernelMetadata; | 138 | return {ResultStatus::ErrorUnableToParseKernelMetadata, {}}; |
| 134 | } | 139 | } |
| 135 | 140 | ||
| 136 | const FileSys::PatchManager pm(metadata.GetTitleID()); | 141 | const FileSys::PatchManager pm(metadata.GetTitleID()); |
| @@ -150,7 +155,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 150 | const auto tentative_next_load_addr = | 155 | const auto tentative_next_load_addr = |
| 151 | AppLoader_NSO::LoadModule(process, *module_file, load_addr, should_pass_arguments, pm); | 156 | AppLoader_NSO::LoadModule(process, *module_file, load_addr, should_pass_arguments, pm); |
| 152 | if (!tentative_next_load_addr) { | 157 | if (!tentative_next_load_addr) { |
| 153 | return ResultStatus::ErrorLoadingNSO; | 158 | return {ResultStatus::ErrorLoadingNSO, {}}; |
| 154 | } | 159 | } |
| 155 | 160 | ||
| 156 | next_load_addr = *tentative_next_load_addr; | 161 | next_load_addr = *tentative_next_load_addr; |
| @@ -159,8 +164,6 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 159 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); | 164 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); |
| 160 | } | 165 | } |
| 161 | 166 | ||
| 162 | process.Run(base_address, metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize()); | ||
| 163 | |||
| 164 | // Find the RomFS by searching for a ".romfs" file in this directory | 167 | // Find the RomFS by searching for a ".romfs" file in this directory |
| 165 | const auto& files = dir->GetFiles(); | 168 | const auto& files = dir->GetFiles(); |
| 166 | const auto romfs_iter = | 169 | const auto romfs_iter = |
| @@ -175,7 +178,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 175 | } | 178 | } |
| 176 | 179 | ||
| 177 | is_loaded = true; | 180 | is_loaded = true; |
| 178 | return ResultStatus::Success; | 181 | return {ResultStatus::Success, |
| 182 | LoadParameters{metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize()}}; | ||
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& dir) { | 185 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(FileSys::VirtualFile& dir) { |
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 1615cb5a8..1a65c16a4 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h | |||
| @@ -37,7 +37,7 @@ public: | |||
| 37 | return IdentifyType(file); | 37 | return IdentifyType(file); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | ResultStatus Load(Kernel::Process& process) override; | 40 | LoadResult Load(Kernel::Process& process) override; |
| 41 | 41 | ||
| 42 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 42 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 43 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 43 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 46ac372f6..6d4b02375 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -382,13 +382,15 @@ FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 382 | return FileType::Error; | 382 | return FileType::Error; |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | ResultStatus AppLoader_ELF::Load(Kernel::Process& process) { | 385 | AppLoader_ELF::LoadResult AppLoader_ELF::Load(Kernel::Process& process) { |
| 386 | if (is_loaded) | 386 | if (is_loaded) { |
| 387 | return ResultStatus::ErrorAlreadyLoaded; | 387 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 388 | } | ||
| 388 | 389 | ||
| 389 | std::vector<u8> buffer = file->ReadAllBytes(); | 390 | std::vector<u8> buffer = file->ReadAllBytes(); |
| 390 | if (buffer.size() != file->GetSize()) | 391 | if (buffer.size() != file->GetSize()) { |
| 391 | return ResultStatus::ErrorIncorrectELFFileSize; | 392 | return {ResultStatus::ErrorIncorrectELFFileSize, {}}; |
| 393 | } | ||
| 392 | 394 | ||
| 393 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 395 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| 394 | ElfReader elf_reader(&buffer[0]); | 396 | ElfReader elf_reader(&buffer[0]); |
| @@ -396,10 +398,9 @@ ResultStatus AppLoader_ELF::Load(Kernel::Process& process) { | |||
| 396 | const VAddr entry_point = codeset.entrypoint; | 398 | const VAddr entry_point = codeset.entrypoint; |
| 397 | 399 | ||
| 398 | process.LoadModule(std::move(codeset), entry_point); | 400 | process.LoadModule(std::move(codeset), entry_point); |
| 399 | process.Run(entry_point, 48, Memory::DEFAULT_STACK_SIZE); | ||
| 400 | 401 | ||
| 401 | is_loaded = true; | 402 | is_loaded = true; |
| 402 | return ResultStatus::Success; | 403 | return {ResultStatus::Success, LoadParameters{48, Memory::DEFAULT_STACK_SIZE}}; |
| 403 | } | 404 | } |
| 404 | 405 | ||
| 405 | } // namespace Loader | 406 | } // namespace Loader |
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index a2d33021c..7ef7770a6 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h | |||
| @@ -26,7 +26,7 @@ public: | |||
| 26 | return IdentifyType(file); | 26 | return IdentifyType(file); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | ResultStatus Load(Kernel::Process& process) override; | 29 | LoadResult Load(Kernel::Process& process) override; |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | } // namespace Loader | 32 | } // namespace Loader |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index bb925f4a6..f7846db52 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -131,6 +131,12 @@ std::ostream& operator<<(std::ostream& os, ResultStatus status); | |||
| 131 | /// Interface for loading an application | 131 | /// Interface for loading an application |
| 132 | class AppLoader : NonCopyable { | 132 | class AppLoader : NonCopyable { |
| 133 | public: | 133 | public: |
| 134 | struct LoadParameters { | ||
| 135 | s32 main_thread_priority; | ||
| 136 | u64 main_thread_stack_size; | ||
| 137 | }; | ||
| 138 | using LoadResult = std::pair<ResultStatus, std::optional<LoadParameters>>; | ||
| 139 | |||
| 134 | explicit AppLoader(FileSys::VirtualFile file); | 140 | explicit AppLoader(FileSys::VirtualFile file); |
| 135 | virtual ~AppLoader(); | 141 | virtual ~AppLoader(); |
| 136 | 142 | ||
| @@ -145,7 +151,7 @@ public: | |||
| 145 | * @param process The newly created process. | 151 | * @param process The newly created process. |
| 146 | * @return The status result of the operation. | 152 | * @return The status result of the operation. |
| 147 | */ | 153 | */ |
| 148 | virtual ResultStatus Load(Kernel::Process& process) = 0; | 154 | virtual LoadResult Load(Kernel::Process& process) = 0; |
| 149 | 155 | ||
| 150 | /** | 156 | /** |
| 151 | * Loads the system mode that this application needs. | 157 | * Loads the system mode that this application needs. |
diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 93a970d10..34efef09a 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp | |||
| @@ -41,31 +41,37 @@ FileType AppLoader_NAX::GetFileType() const { | |||
| 41 | return IdentifyTypeImpl(*nax); | 41 | return IdentifyTypeImpl(*nax); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | ResultStatus AppLoader_NAX::Load(Kernel::Process& process) { | 44 | AppLoader_NAX::LoadResult AppLoader_NAX::Load(Kernel::Process& process) { |
| 45 | if (is_loaded) { | 45 | if (is_loaded) { |
| 46 | return ResultStatus::ErrorAlreadyLoaded; | 46 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | if (nax->GetStatus() != ResultStatus::Success) | 49 | const auto nax_status = nax->GetStatus(); |
| 50 | return nax->GetStatus(); | 50 | if (nax_status != ResultStatus::Success) { |
| 51 | return {nax_status, {}}; | ||
| 52 | } | ||
| 51 | 53 | ||
| 52 | const auto nca = nax->AsNCA(); | 54 | const auto nca = nax->AsNCA(); |
| 53 | if (nca == nullptr) { | 55 | if (nca == nullptr) { |
| 54 | if (!Core::Crypto::KeyManager::KeyFileExists(false)) | 56 | if (!Core::Crypto::KeyManager::KeyFileExists(false)) { |
| 55 | return ResultStatus::ErrorMissingProductionKeyFile; | 57 | return {ResultStatus::ErrorMissingProductionKeyFile, {}}; |
| 56 | return ResultStatus::ErrorNAXInconvertibleToNCA; | 58 | } |
| 59 | |||
| 60 | return {ResultStatus::ErrorNAXInconvertibleToNCA, {}}; | ||
| 57 | } | 61 | } |
| 58 | 62 | ||
| 59 | if (nca->GetStatus() != ResultStatus::Success) | 63 | const auto nca_status = nca->GetStatus(); |
| 60 | return nca->GetStatus(); | 64 | if (nca_status != ResultStatus::Success) { |
| 65 | return {nca_status, {}}; | ||
| 66 | } | ||
| 61 | 67 | ||
| 62 | const auto result = nca_loader->Load(process); | 68 | const auto result = nca_loader->Load(process); |
| 63 | if (result != ResultStatus::Success) | 69 | if (result.first != ResultStatus::Success) { |
| 64 | return result; | 70 | return result; |
| 71 | } | ||
| 65 | 72 | ||
| 66 | is_loaded = true; | 73 | is_loaded = true; |
| 67 | 74 | return result; | |
| 68 | return ResultStatus::Success; | ||
| 69 | } | 75 | } |
| 70 | 76 | ||
| 71 | ResultStatus AppLoader_NAX::ReadRomFS(FileSys::VirtualFile& dir) { | 77 | ResultStatus AppLoader_NAX::ReadRomFS(FileSys::VirtualFile& dir) { |
diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index f40079574..00f1659c1 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h | |||
| @@ -33,7 +33,7 @@ public: | |||
| 33 | 33 | ||
| 34 | FileType GetFileType() const override; | 34 | FileType GetFileType() const override; |
| 35 | 35 | ||
| 36 | ResultStatus Load(Kernel::Process& process) override; | 36 | LoadResult Load(Kernel::Process& process) override; |
| 37 | 37 | ||
| 38 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 38 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 39 | u64 ReadRomFSIVFCOffset() const override; | 39 | u64 ReadRomFSIVFCOffset() const override; |
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index ce8196fcf..b3f8f1083 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp | |||
| @@ -30,36 +30,38 @@ FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 30 | return FileType::Error; | 30 | return FileType::Error; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | ResultStatus AppLoader_NCA::Load(Kernel::Process& process) { | 33 | AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::Process& process) { |
| 34 | if (is_loaded) { | 34 | if (is_loaded) { |
| 35 | return ResultStatus::ErrorAlreadyLoaded; | 35 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | const auto result = nca->GetStatus(); | 38 | const auto result = nca->GetStatus(); |
| 39 | if (result != ResultStatus::Success) { | 39 | if (result != ResultStatus::Success) { |
| 40 | return result; | 40 | return {result, {}}; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | if (nca->GetType() != FileSys::NCAContentType::Program) | 43 | if (nca->GetType() != FileSys::NCAContentType::Program) { |
| 44 | return ResultStatus::ErrorNCANotProgram; | 44 | return {ResultStatus::ErrorNCANotProgram, {}}; |
| 45 | } | ||
| 45 | 46 | ||
| 46 | const auto exefs = nca->GetExeFS(); | 47 | const auto exefs = nca->GetExeFS(); |
| 47 | 48 | if (exefs == nullptr) { | |
| 48 | if (exefs == nullptr) | 49 | return {ResultStatus::ErrorNoExeFS, {}}; |
| 49 | return ResultStatus::ErrorNoExeFS; | 50 | } |
| 50 | 51 | ||
| 51 | directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs, true); | 52 | directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs, true); |
| 52 | 53 | ||
| 53 | const auto load_result = directory_loader->Load(process); | 54 | const auto load_result = directory_loader->Load(process); |
| 54 | if (load_result != ResultStatus::Success) | 55 | if (load_result.first != ResultStatus::Success) { |
| 55 | return load_result; | 56 | return load_result; |
| 57 | } | ||
| 56 | 58 | ||
| 57 | if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) | 59 | if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) { |
| 58 | Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this)); | 60 | Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this)); |
| 61 | } | ||
| 59 | 62 | ||
| 60 | is_loaded = true; | 63 | is_loaded = true; |
| 61 | 64 | return load_result; | |
| 62 | return ResultStatus::Success; | ||
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { | 67 | ResultStatus AppLoader_NCA::ReadRomFS(FileSys::VirtualFile& dir) { |
diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h index b9f077468..94f0ed677 100644 --- a/src/core/loader/nca.h +++ b/src/core/loader/nca.h | |||
| @@ -33,7 +33,7 @@ public: | |||
| 33 | return IdentifyType(file); | 33 | return IdentifyType(file); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | ResultStatus Load(Kernel::Process& process) override; | 36 | LoadResult Load(Kernel::Process& process) override; |
| 37 | 37 | ||
| 38 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; | 38 | ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; |
| 39 | u64 ReadRomFSIVFCOffset() const override; | 39 | u64 ReadRomFSIVFCOffset() const override; |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 31e4a0c84..6a0ca389b 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -201,25 +201,25 @@ bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& fi | |||
| 201 | return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base); | 201 | return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { | 204 | AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) { |
| 205 | if (is_loaded) { | 205 | if (is_loaded) { |
| 206 | return ResultStatus::ErrorAlreadyLoaded; | 206 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | // Load NRO | 209 | // Load NRO |
| 210 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 210 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| 211 | 211 | ||
| 212 | if (!LoadNro(process, *file, base_address)) { | 212 | if (!LoadNro(process, *file, base_address)) { |
| 213 | return ResultStatus::ErrorLoadingNRO; | 213 | return {ResultStatus::ErrorLoadingNRO, {}}; |
| 214 | } | 214 | } |
| 215 | 215 | ||
| 216 | if (romfs != nullptr) | 216 | if (romfs != nullptr) { |
| 217 | Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this)); | 217 | Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this)); |
| 218 | 218 | } | |
| 219 | process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); | ||
| 220 | 219 | ||
| 221 | is_loaded = true; | 220 | is_loaded = true; |
| 222 | return ResultStatus::Success; | 221 | return {ResultStatus::Success, |
| 222 | LoadParameters{Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE}}; | ||
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { | 225 | ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { |
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 85b0ed644..1ffdae805 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h | |||
| @@ -37,7 +37,7 @@ public: | |||
| 37 | return IdentifyType(file); | 37 | return IdentifyType(file); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | ResultStatus Load(Kernel::Process& process) override; | 40 | LoadResult Load(Kernel::Process& process) override; |
| 41 | 41 | ||
| 42 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; | 42 | ResultStatus ReadIcon(std::vector<u8>& buffer) override; |
| 43 | ResultStatus ReadProgramId(u64& out_program_id) override; | 43 | ResultStatus ReadProgramId(u64& out_program_id) override; |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index d7c47c197..a86653204 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -169,22 +169,21 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, | |||
| 169 | return load_base + image_size; | 169 | return load_base + image_size; |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { | 172 | AppLoader_NSO::LoadResult AppLoader_NSO::Load(Kernel::Process& process) { |
| 173 | if (is_loaded) { | 173 | if (is_loaded) { |
| 174 | return ResultStatus::ErrorAlreadyLoaded; | 174 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | // Load module | 177 | // Load module |
| 178 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 178 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| 179 | if (!LoadModule(process, *file, base_address, true)) { | 179 | if (!LoadModule(process, *file, base_address, true)) { |
| 180 | return ResultStatus::ErrorLoadingNSO; | 180 | return {ResultStatus::ErrorLoadingNSO, {}}; |
| 181 | } | 181 | } |
| 182 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); | 182 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); |
| 183 | 183 | ||
| 184 | process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); | ||
| 185 | |||
| 186 | is_loaded = true; | 184 | is_loaded = true; |
| 187 | return ResultStatus::Success; | 185 | return {ResultStatus::Success, |
| 186 | LoadParameters{Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE}}; | ||
| 188 | } | 187 | } |
| 189 | 188 | ||
| 190 | } // namespace Loader | 189 | } // namespace Loader |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 4674c3724..fdce9191c 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -84,7 +84,7 @@ public: | |||
| 84 | VAddr load_base, bool should_pass_arguments, | 84 | VAddr load_base, bool should_pass_arguments, |
| 85 | std::optional<FileSys::PatchManager> pm = {}); | 85 | std::optional<FileSys::PatchManager> pm = {}); |
| 86 | 86 | ||
| 87 | ResultStatus Load(Kernel::Process& process) override; | 87 | LoadResult Load(Kernel::Process& process) override; |
| 88 | }; | 88 | }; |
| 89 | 89 | ||
| 90 | } // namespace Loader | 90 | } // namespace Loader |
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index 7da1f8960..ad56bbb38 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp | |||
| @@ -72,37 +72,45 @@ FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 72 | return FileType::Error; | 72 | return FileType::Error; |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | ResultStatus AppLoader_NSP::Load(Kernel::Process& process) { | 75 | AppLoader_NSP::LoadResult AppLoader_NSP::Load(Kernel::Process& process) { |
| 76 | if (is_loaded) { | 76 | if (is_loaded) { |
| 77 | return ResultStatus::ErrorAlreadyLoaded; | 77 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | if (title_id == 0) | 80 | if (title_id == 0) { |
| 81 | return ResultStatus::ErrorNSPMissingProgramNCA; | 81 | return {ResultStatus::ErrorNSPMissingProgramNCA, {}}; |
| 82 | } | ||
| 82 | 83 | ||
| 83 | if (nsp->GetStatus() != ResultStatus::Success) | 84 | const auto nsp_status = nsp->GetStatus(); |
| 84 | return nsp->GetStatus(); | 85 | if (nsp_status != ResultStatus::Success) { |
| 86 | return {nsp_status, {}}; | ||
| 87 | } | ||
| 85 | 88 | ||
| 86 | if (nsp->GetProgramStatus(title_id) != ResultStatus::Success) | 89 | const auto nsp_program_status = nsp->GetProgramStatus(title_id); |
| 87 | return nsp->GetProgramStatus(title_id); | 90 | if (nsp_program_status != ResultStatus::Success) { |
| 91 | return {nsp_program_status, {}}; | ||
| 92 | } | ||
| 88 | 93 | ||
| 89 | if (nsp->GetNCA(title_id, FileSys::ContentRecordType::Program) == nullptr) { | 94 | if (nsp->GetNCA(title_id, FileSys::ContentRecordType::Program) == nullptr) { |
| 90 | if (!Core::Crypto::KeyManager::KeyFileExists(false)) | 95 | if (!Core::Crypto::KeyManager::KeyFileExists(false)) { |
| 91 | return ResultStatus::ErrorMissingProductionKeyFile; | 96 | return {ResultStatus::ErrorMissingProductionKeyFile, {}}; |
| 92 | return ResultStatus::ErrorNSPMissingProgramNCA; | 97 | } |
| 98 | |||
| 99 | return {ResultStatus::ErrorNSPMissingProgramNCA, {}}; | ||
| 93 | } | 100 | } |
| 94 | 101 | ||
| 95 | const auto result = secondary_loader->Load(process); | 102 | const auto result = secondary_loader->Load(process); |
| 96 | if (result != ResultStatus::Success) | 103 | if (result.first != ResultStatus::Success) { |
| 97 | return result; | 104 | return result; |
| 105 | } | ||
| 98 | 106 | ||
| 99 | FileSys::VirtualFile update_raw; | 107 | FileSys::VirtualFile update_raw; |
| 100 | if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) | 108 | if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) { |
| 101 | Service::FileSystem::SetPackedUpdate(std::move(update_raw)); | 109 | Service::FileSystem::SetPackedUpdate(std::move(update_raw)); |
| 110 | } | ||
| 102 | 111 | ||
| 103 | is_loaded = true; | 112 | is_loaded = true; |
| 104 | 113 | return result; | |
| 105 | return ResultStatus::Success; | ||
| 106 | } | 114 | } |
| 107 | 115 | ||
| 108 | ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& file) { | 116 | ResultStatus AppLoader_NSP::ReadRomFS(FileSys::VirtualFile& file) { |
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index 953a1b508..85e870bdf 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h | |||
| @@ -35,7 +35,7 @@ public: | |||
| 35 | return IdentifyType(file); | 35 | return IdentifyType(file); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | ResultStatus Load(Kernel::Process& process) override; | 38 | LoadResult Load(Kernel::Process& process) override; |
| 39 | 39 | ||
| 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; | 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; |
| 41 | u64 ReadRomFSIVFCOffset() const override; | 41 | u64 ReadRomFSIVFCOffset() const override; |
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 89f7bbf77..1e285a053 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp | |||
| @@ -48,31 +48,35 @@ FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 48 | return FileType::Error; | 48 | return FileType::Error; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | ResultStatus AppLoader_XCI::Load(Kernel::Process& process) { | 51 | AppLoader_XCI::LoadResult AppLoader_XCI::Load(Kernel::Process& process) { |
| 52 | if (is_loaded) { | 52 | if (is_loaded) { |
| 53 | return ResultStatus::ErrorAlreadyLoaded; | 53 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | if (xci->GetStatus() != ResultStatus::Success) | 56 | if (xci->GetStatus() != ResultStatus::Success) { |
| 57 | return xci->GetStatus(); | 57 | return {xci->GetStatus(), {}}; |
| 58 | } | ||
| 58 | 59 | ||
| 59 | if (xci->GetProgramNCAStatus() != ResultStatus::Success) | 60 | if (xci->GetProgramNCAStatus() != ResultStatus::Success) { |
| 60 | return xci->GetProgramNCAStatus(); | 61 | return {xci->GetProgramNCAStatus(), {}}; |
| 62 | } | ||
| 61 | 63 | ||
| 62 | if (!xci->HasProgramNCA() && !Core::Crypto::KeyManager::KeyFileExists(false)) | 64 | if (!xci->HasProgramNCA() && !Core::Crypto::KeyManager::KeyFileExists(false)) { |
| 63 | return ResultStatus::ErrorMissingProductionKeyFile; | 65 | return {ResultStatus::ErrorMissingProductionKeyFile, {}}; |
| 66 | } | ||
| 64 | 67 | ||
| 65 | const auto result = nca_loader->Load(process); | 68 | const auto result = nca_loader->Load(process); |
| 66 | if (result != ResultStatus::Success) | 69 | if (result.first != ResultStatus::Success) { |
| 67 | return result; | 70 | return result; |
| 71 | } | ||
| 68 | 72 | ||
| 69 | FileSys::VirtualFile update_raw; | 73 | FileSys::VirtualFile update_raw; |
| 70 | if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) | 74 | if (ReadUpdateRaw(update_raw) == ResultStatus::Success && update_raw != nullptr) { |
| 71 | Service::FileSystem::SetPackedUpdate(std::move(update_raw)); | 75 | Service::FileSystem::SetPackedUpdate(std::move(update_raw)); |
| 76 | } | ||
| 72 | 77 | ||
| 73 | is_loaded = true; | 78 | is_loaded = true; |
| 74 | 79 | return result; | |
| 75 | return ResultStatus::Success; | ||
| 76 | } | 80 | } |
| 77 | 81 | ||
| 78 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { | 82 | ResultStatus AppLoader_XCI::ReadRomFS(FileSys::VirtualFile& file) { |
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 436f7387c..ae7145b14 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h | |||
| @@ -35,7 +35,7 @@ public: | |||
| 35 | return IdentifyType(file); | 35 | return IdentifyType(file); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | ResultStatus Load(Kernel::Process& process) override; | 38 | LoadResult Load(Kernel::Process& process) override; |
| 39 | 39 | ||
| 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; | 40 | ResultStatus ReadRomFS(FileSys::VirtualFile& file) override; |
| 41 | u64 ReadRomFSIVFCOffset() const override; | 41 | u64 ReadRomFSIVFCOffset() const override; |