diff options
| author | 2018-02-25 16:44:51 -0800 | |
|---|---|---|
| committer | 2018-02-25 16:44:51 -0800 | |
| commit | 7e45669ccbf50139910ca6e565fbd6f4fddfdf27 (patch) | |
| tree | 3e59a99cc6a5740b42e0e279c79e0a511adb717a /src/core/loader | |
| parent | Merge pull request #212 from mailwl/stubs (diff) | |
| parent | file_sys: Style tweaks (diff) | |
| download | yuzu-7e45669ccbf50139910ca6e565fbd6f4fddfdf27.tar.gz yuzu-7e45669ccbf50139910ca6e565fbd6f4fddfdf27.tar.xz yuzu-7e45669ccbf50139910ca6e565fbd6f4fddfdf27.zip | |
Merge pull request #222 from shinyquagsire23/npdm-parsing
NPDM Parsing
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 23 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 2 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 6 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 2 |
4 files changed, 24 insertions, 9 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 661803b5f..864cf25cd 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -53,6 +53,7 @@ AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileUti | |||
| 53 | FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& file, | 53 | FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& file, |
| 54 | const std::string& filepath) { | 54 | const std::string& filepath) { |
| 55 | bool is_main_found{}; | 55 | bool is_main_found{}; |
| 56 | bool is_npdm_found{}; | ||
| 56 | bool is_rtld_found{}; | 57 | bool is_rtld_found{}; |
| 57 | bool is_sdk_found{}; | 58 | bool is_sdk_found{}; |
| 58 | 59 | ||
| @@ -67,6 +68,9 @@ FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& fil | |||
| 67 | // Verify filename | 68 | // Verify filename |
| 68 | if (Common::ToLower(virtual_name) == "main") { | 69 | if (Common::ToLower(virtual_name) == "main") { |
| 69 | is_main_found = true; | 70 | is_main_found = true; |
| 71 | } else if (Common::ToLower(virtual_name) == "main.npdm") { | ||
| 72 | is_npdm_found = true; | ||
| 73 | return true; | ||
| 70 | } else if (Common::ToLower(virtual_name) == "rtld") { | 74 | } else if (Common::ToLower(virtual_name) == "rtld") { |
| 71 | is_rtld_found = true; | 75 | is_rtld_found = true; |
| 72 | } else if (Common::ToLower(virtual_name) == "sdk") { | 76 | } else if (Common::ToLower(virtual_name) == "sdk") { |
| @@ -83,14 +87,14 @@ FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& fil | |||
| 83 | } | 87 | } |
| 84 | 88 | ||
| 85 | // We are done if we've found and verified all required NSOs | 89 | // We are done if we've found and verified all required NSOs |
| 86 | return !(is_main_found && is_rtld_found && is_sdk_found); | 90 | return !(is_main_found && is_npdm_found && is_rtld_found && is_sdk_found); |
| 87 | }; | 91 | }; |
| 88 | 92 | ||
| 89 | // Search the directory recursively, looking for the required modules | 93 | // Search the directory recursively, looking for the required modules |
| 90 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; | 94 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; |
| 91 | FileUtil::ForeachDirectoryEntry(nullptr, directory, callback); | 95 | FileUtil::ForeachDirectoryEntry(nullptr, directory, callback); |
| 92 | 96 | ||
| 93 | if (is_main_found && is_rtld_found && is_sdk_found) { | 97 | if (is_main_found && is_npdm_found && is_rtld_found && is_sdk_found) { |
| 94 | return FileType::DeconstructedRomDirectory; | 98 | return FileType::DeconstructedRomDirectory; |
| 95 | } | 99 | } |
| 96 | 100 | ||
| @@ -108,14 +112,22 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 108 | 112 | ||
| 109 | process = Kernel::Process::Create("main"); | 113 | process = Kernel::Process::Create("main"); |
| 110 | 114 | ||
| 115 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; | ||
| 116 | const std::string npdm_path = directory + DIR_SEP + "main.npdm"; | ||
| 117 | |||
| 118 | ResultStatus result = metadata.Load(npdm_path); | ||
| 119 | if (result != ResultStatus::Success) { | ||
| 120 | return result; | ||
| 121 | } | ||
| 122 | metadata.Print(); | ||
| 123 | |||
| 111 | // Load NSO modules | 124 | // Load NSO modules |
| 112 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 125 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 113 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; | ||
| 114 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | 126 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", |
| 115 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | 127 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { |
| 116 | const std::string path = directory + DIR_SEP + module; | 128 | const std::string path = directory + DIR_SEP + module; |
| 117 | const VAddr load_addr = next_load_addr; | 129 | const VAddr load_addr = next_load_addr; |
| 118 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); | 130 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr, metadata.GetTitleID()); |
| 119 | if (next_load_addr) { | 131 | if (next_load_addr) { |
| 120 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, module, load_addr); | 132 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, module, load_addr); |
| 121 | } else { | 133 | } else { |
| @@ -127,7 +139,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 127 | process->address_mappings = default_address_mappings; | 139 | process->address_mappings = default_address_mappings; |
| 128 | process->resource_limit = | 140 | process->resource_limit = |
| 129 | Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); | 141 | Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); |
| 130 | process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); | 142 | process->Run(Memory::PROCESS_IMAGE_VADDR, metadata.GetMainThreadPriority(), |
| 143 | metadata.GetMainThreadStackSize()); | ||
| 131 | 144 | ||
| 132 | // Find the RomFS by searching for a ".romfs" file in this directory | 145 | // Find the RomFS by searching for a ".romfs" file in this directory |
| 133 | filepath_romfs = FindRomFS(directory); | 146 | filepath_romfs = FindRomFS(directory); |
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 536a2dab7..23295d911 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <string> | 7 | #include <string> |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "core/file_sys/program_metadata.h" | ||
| 9 | #include "core/hle/kernel/kernel.h" | 10 | #include "core/hle/kernel/kernel.h" |
| 10 | #include "core/loader/loader.h" | 11 | #include "core/loader/loader.h" |
| 11 | 12 | ||
| @@ -41,6 +42,7 @@ public: | |||
| 41 | private: | 42 | private: |
| 42 | std::string filepath_romfs; | 43 | std::string filepath_romfs; |
| 43 | std::string filepath; | 44 | std::string filepath; |
| 45 | FileSys::ProgramMetadata metadata; | ||
| 44 | }; | 46 | }; |
| 45 | 47 | ||
| 46 | } // namespace Loader | 48 | } // namespace Loader |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 407025da0..7f8d24dd6 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -92,7 +92,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 92 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 92 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { | 95 | VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base, u64 tid) { |
| 96 | FileUtil::IOFile file(path, "rb"); | 96 | FileUtil::IOFile file(path, "rb"); |
| 97 | if (!file.IsOpen()) { | 97 | if (!file.IsOpen()) { |
| 98 | return {}; | 98 | return {}; |
| @@ -109,7 +109,7 @@ VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | // Build program image | 111 | // Build program image |
| 112 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", 0); | 112 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("", tid); |
| 113 | std::vector<u8> program_image; | 113 | std::vector<u8> program_image; |
| 114 | for (int i = 0; i < nso_header.segments.size(); ++i) { | 114 | for (int i = 0; i < nso_header.segments.size(); ++i) { |
| 115 | std::vector<u8> data = | 115 | std::vector<u8> data = |
| @@ -158,7 +158,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 158 | process = Kernel::Process::Create("main"); | 158 | process = Kernel::Process::Create("main"); |
| 159 | 159 | ||
| 160 | // Load module | 160 | // Load module |
| 161 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); | 161 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR, 0); |
| 162 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(), | 162 | LOG_DEBUG(Loader, "loaded module %s @ 0x%" PRIx64, filepath.c_str(), |
| 163 | Memory::PROCESS_IMAGE_VADDR); | 163 | Memory::PROCESS_IMAGE_VADDR); |
| 164 | 164 | ||
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 1ae30a824..14eb1d87e 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -29,7 +29,7 @@ public: | |||
| 29 | return IdentifyType(file, filepath); | 29 | return IdentifyType(file, filepath); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | static VAddr LoadModule(const std::string& path, VAddr load_base); | 32 | static VAddr LoadModule(const std::string& path, VAddr load_base, u64 tid); |
| 33 | 33 | ||
| 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 35 | 35 | ||