diff options
| author | 2018-08-05 18:27:05 -0400 | |
|---|---|---|
| committer | 2018-08-05 18:28:15 -0400 | |
| commit | 7f9430f7aee9e7ef11d1bd86a2b98ae239c5be06 (patch) | |
| tree | 340579d4ed7768dc4866102916fc449b6e601164 /src/core/loader/nca.cpp | |
| parent | Merge pull request #927 from bunnei/fix-texs (diff) | |
| download | yuzu-7f9430f7aee9e7ef11d1bd86a2b98ae239c5be06.tar.gz yuzu-7f9430f7aee9e7ef11d1bd86a2b98ae239c5be06.tar.xz yuzu-7f9430f7aee9e7ef11d1bd86a2b98ae239c5be06.zip | |
loader: Make AppLoader_NCA rely on directory loading code
Eliminates duplicate code shared between their Load methods, after all the only difference is how the romfs is handled.
Diffstat (limited to 'src/core/loader/nca.cpp')
| -rw-r--r-- | src/core/loader/nca.cpp | 44 |
1 files changed, 8 insertions, 36 deletions
diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index a1f8235d1..dbc67c0b5 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp | |||
| @@ -22,7 +22,8 @@ | |||
| 22 | 22 | ||
| 23 | namespace Loader { | 23 | namespace Loader { |
| 24 | 24 | ||
| 25 | AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file) : AppLoader(std::move(file)) {} | 25 | AppLoader_NCA::AppLoader_NCA(FileSys::VirtualFile file_) |
| 26 | : AppLoader(std::move(file_)), nca(std::make_unique<FileSys::NCA>(file)) {} | ||
| 26 | 27 | ||
| 27 | FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) { | 28 | FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) { |
| 28 | FileSys::NCA nca(file); | 29 | FileSys::NCA nca(file); |
| @@ -39,8 +40,7 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 39 | return ResultStatus::ErrorAlreadyLoaded; | 40 | return ResultStatus::ErrorAlreadyLoaded; |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | nca = std::make_unique<FileSys::NCA>(file); | 43 | const auto result = nca->GetStatus(); |
| 43 | ResultStatus result = nca->GetStatus(); | ||
| 44 | if (result != ResultStatus::Success) { | 44 | if (result != ResultStatus::Success) { |
| 45 | return result; | 45 | return result; |
| 46 | } | 46 | } |
| @@ -48,44 +48,16 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 48 | if (nca->GetType() != FileSys::NCAContentType::Program) | 48 | if (nca->GetType() != FileSys::NCAContentType::Program) |
| 49 | return ResultStatus::ErrorInvalidFormat; | 49 | return ResultStatus::ErrorInvalidFormat; |
| 50 | 50 | ||
| 51 | auto exefs = nca->GetExeFS(); | 51 | const auto exefs = nca->GetExeFS(); |
| 52 | 52 | ||
| 53 | if (exefs == nullptr) | 53 | if (exefs == nullptr) |
| 54 | return ResultStatus::ErrorInvalidFormat; | 54 | return ResultStatus::ErrorInvalidFormat; |
| 55 | 55 | ||
| 56 | result = metadata.Load(exefs->GetFile("main.npdm")); | 56 | directory_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(exefs); |
| 57 | if (result != ResultStatus::Success) { | ||
| 58 | return result; | ||
| 59 | } | ||
| 60 | metadata.Print(); | ||
| 61 | |||
| 62 | const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; | ||
| 63 | if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit) { | ||
| 64 | return ResultStatus::ErrorUnsupportedArch; | ||
| 65 | } | ||
| 66 | |||
| 67 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | ||
| 68 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | ||
| 69 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | ||
| 70 | const VAddr load_addr = next_load_addr; | ||
| 71 | |||
| 72 | next_load_addr = AppLoader_NSO::LoadModule(exefs->GetFile(module), load_addr); | ||
| 73 | if (next_load_addr) { | ||
| 74 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); | ||
| 75 | // Register module with GDBStub | ||
| 76 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); | ||
| 77 | } else { | ||
| 78 | next_load_addr = load_addr; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | 57 | ||
| 82 | process->program_id = metadata.GetTitleID(); | 58 | const auto load_result = directory_loader->Load(process); |
| 83 | process->svc_access_mask.set(); | 59 | if (load_result != ResultStatus::Success) |
| 84 | process->address_mappings = default_address_mappings; | 60 | return load_result; |
| 85 | process->resource_limit = | ||
| 86 | Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); | ||
| 87 | process->Run(Memory::PROCESS_IMAGE_VADDR, metadata.GetMainThreadPriority(), | ||
| 88 | metadata.GetMainThreadStackSize()); | ||
| 89 | 61 | ||
| 90 | if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) | 62 | if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) |
| 91 | Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this)); | 63 | Service::FileSystem::RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(*this)); |