diff options
| author | 2018-01-20 16:26:20 -0500 | |
|---|---|---|
| committer | 2018-01-20 16:26:20 -0500 | |
| commit | ff883cc56382425d4c4f572ff659ec7df6fc2cec (patch) | |
| tree | 3b7e44f33dac0384d412fed61de3c5ad40db137d /src | |
| parent | Port citra #3352 to yuzu (#103) (diff) | |
| parent | loader: Clean up ctors and includes. (diff) | |
| download | yuzu-ff883cc56382425d4c4f572ff659ec7df6fc2cec.tar.gz yuzu-ff883cc56382425d4c4f572ff659ec7df6fc2cec.tar.xz yuzu-ff883cc56382425d4c4f572ff659ec7df6fc2cec.zip | |
Merge pull request #119 from bunnei/desconstucted-loader
Separate NSO loading from DesconstuctedRomLoader
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 106 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 42 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 5 | ||||
| -rw-r--r-- | src/core/loader/elf.h | 8 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 22 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 9 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 6 | ||||
| -rw-r--r-- | src/core/loader/nro.h | 10 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 27 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 14 |
11 files changed, 200 insertions, 51 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 540d290f2..7153c4f3f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -149,6 +149,8 @@ add_library(core STATIC | |||
| 149 | hw/hw.h | 149 | hw/hw.h |
| 150 | hw/lcd.cpp | 150 | hw/lcd.cpp |
| 151 | hw/lcd.h | 151 | hw/lcd.h |
| 152 | loader/deconstructed_rom_directory.cpp | ||
| 153 | loader/deconstructed_rom_directory.h | ||
| 152 | loader/elf.cpp | 154 | loader/elf.cpp |
| 153 | loader/elf.h | 155 | loader/elf.h |
| 154 | loader/linker.cpp | 156 | loader/linker.cpp |
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp new file mode 100644 index 000000000..086ec11c8 --- /dev/null +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common_funcs.h" | ||
| 6 | #include "common/common_paths.h" | ||
| 7 | #include "common/file_util.h" | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "common/string_util.h" | ||
| 10 | #include "core/hle/kernel/process.h" | ||
| 11 | #include "core/hle/kernel/resource_limit.h" | ||
| 12 | #include "core/loader/deconstructed_rom_directory.h" | ||
| 13 | #include "core/loader/nso.h" | ||
| 14 | #include "core/memory.h" | ||
| 15 | |||
| 16 | namespace Loader { | ||
| 17 | |||
| 18 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, | ||
| 19 | std::string filepath) | ||
| 20 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 21 | |||
| 22 | FileType AppLoader_DeconstructedRomDirectory::IdentifyType(FileUtil::IOFile& file, | ||
| 23 | const std::string& filepath) { | ||
| 24 | bool is_main_found{}; | ||
| 25 | bool is_rtld_found{}; | ||
| 26 | bool is_sdk_found{}; | ||
| 27 | |||
| 28 | const auto callback = [&](unsigned* num_entries_out, const std::string& directory, | ||
| 29 | const std::string& virtual_name) -> bool { | ||
| 30 | |||
| 31 | // Skip directories | ||
| 32 | std::string physical_name = directory + virtual_name; | ||
| 33 | if (FileUtil::IsDirectory(physical_name)) { | ||
| 34 | return true; | ||
| 35 | } | ||
| 36 | |||
| 37 | // Verify filename | ||
| 38 | if (Common::ToLower(virtual_name) == "main") { | ||
| 39 | is_main_found = true; | ||
| 40 | } else if (Common::ToLower(virtual_name) == "rtld") { | ||
| 41 | is_rtld_found = true; | ||
| 42 | } else if (Common::ToLower(virtual_name) == "sdk") { | ||
| 43 | is_sdk_found = true; | ||
| 44 | } else { | ||
| 45 | // Contrinue searching | ||
| 46 | return true; | ||
| 47 | } | ||
| 48 | |||
| 49 | // Verify file is an NSO | ||
| 50 | FileUtil::IOFile file(physical_name, "rb"); | ||
| 51 | if (AppLoader_NSO::IdentifyType(file, physical_name) != FileType::NSO) { | ||
| 52 | return false; | ||
| 53 | } | ||
| 54 | |||
| 55 | // We are done if we've found and verified all required NSOs | ||
| 56 | return !(is_main_found && is_rtld_found && is_sdk_found); | ||
| 57 | }; | ||
| 58 | |||
| 59 | // Search the directory recursively, looking for the required modules | ||
| 60 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; | ||
| 61 | FileUtil::ForeachDirectoryEntry(nullptr, directory, callback); | ||
| 62 | |||
| 63 | if (is_main_found && is_rtld_found && is_sdk_found) { | ||
| 64 | return FileType::DeconstructedRomDirectory; | ||
| 65 | } | ||
| 66 | |||
| 67 | return FileType::Error; | ||
| 68 | } | ||
| 69 | |||
| 70 | ResultStatus AppLoader_DeconstructedRomDirectory::Load( | ||
| 71 | Kernel::SharedPtr<Kernel::Process>& process) { | ||
| 72 | if (is_loaded) { | ||
| 73 | return ResultStatus::ErrorAlreadyLoaded; | ||
| 74 | } | ||
| 75 | if (!file.IsOpen()) { | ||
| 76 | return ResultStatus::Error; | ||
| 77 | } | ||
| 78 | |||
| 79 | process = Kernel::Process::Create("main"); | ||
| 80 | |||
| 81 | // Load NSO modules | ||
| 82 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | ||
| 83 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | ||
| 84 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | ||
| 85 | const std::string path = | ||
| 86 | filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP + module; | ||
| 87 | const VAddr load_addr = next_load_addr; | ||
| 88 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); | ||
| 89 | if (next_load_addr) { | ||
| 90 | LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", module, load_addr); | ||
| 91 | } else { | ||
| 92 | next_load_addr = load_addr; | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | process->svc_access_mask.set(); | ||
| 97 | process->address_mappings = default_address_mappings; | ||
| 98 | process->resource_limit = | ||
| 99 | Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); | ||
| 100 | process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); | ||
| 101 | |||
| 102 | is_loaded = true; | ||
| 103 | return ResultStatus::Success; | ||
| 104 | } | ||
| 105 | |||
| 106 | } // namespace Loader | ||
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h new file mode 100644 index 000000000..162541d54 --- /dev/null +++ b/src/core/loader/deconstructed_rom_directory.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "core/hle/kernel/kernel.h" | ||
| 10 | #include "core/loader/loader.h" | ||
| 11 | |||
| 12 | namespace Loader { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * This class loads a "deconstructed ROM directory", which are the typical format we see for Switch | ||
| 16 | * game dumps. The path should be a "main" NSO, which must be in a directory that contains the other | ||
| 17 | * standard ExeFS NSOs (e.g. rtld, sdk, etc.). It will automatically find and load these. | ||
| 18 | * Furthermore, it will look for the first .istorage file (optionally) and use this for the RomFS. | ||
| 19 | */ | ||
| 20 | class AppLoader_DeconstructedRomDirectory final : public AppLoader { | ||
| 21 | public: | ||
| 22 | AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, std::string filepath); | ||
| 23 | |||
| 24 | /** | ||
| 25 | * Returns the type of the file | ||
| 26 | * @param file FileUtil::IOFile open file | ||
| 27 | * @param filepath Path of the file that we are opening. | ||
| 28 | * @return FileType found, or FileType::Error if this loader doesn't know it | ||
| 29 | */ | ||
| 30 | static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); | ||
| 31 | |||
| 32 | FileType GetFileType() override { | ||
| 33 | return IdentifyType(file, filepath); | ||
| 34 | } | ||
| 35 | |||
| 36 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | ||
| 37 | |||
| 38 | private: | ||
| 39 | std::string filepath; | ||
| 40 | }; | ||
| 41 | |||
| 42 | } // namespace Loader | ||
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 9ba913dbe..2f87346d0 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -364,7 +364,10 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const | |||
| 364 | 364 | ||
| 365 | namespace Loader { | 365 | namespace Loader { |
| 366 | 366 | ||
| 367 | FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) { | 367 | AppLoader_ELF::AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) |
| 368 | : AppLoader(std::move(file)), filename(std::move(filename)) {} | ||
| 369 | |||
| 370 | FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file, const std::string&) { | ||
| 368 | static constexpr u16 ELF_MACHINE_ARM{0x28}; | 371 | static constexpr u16 ELF_MACHINE_ARM{0x28}; |
| 369 | 372 | ||
| 370 | u32 magic = 0; | 373 | u32 magic = 0; |
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 113da5917..ee741a789 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h | |||
| @@ -16,18 +16,18 @@ namespace Loader { | |||
| 16 | /// Loads an ELF/AXF file | 16 | /// Loads an ELF/AXF file |
| 17 | class AppLoader_ELF final : public AppLoader { | 17 | class AppLoader_ELF final : public AppLoader { |
| 18 | public: | 18 | public: |
| 19 | AppLoader_ELF(FileUtil::IOFile&& file, std::string filename) | 19 | AppLoader_ELF(FileUtil::IOFile&& file, std::string filename); |
| 20 | : AppLoader(std::move(file)), filename(std::move(filename)) {} | ||
| 21 | 20 | ||
| 22 | /** | 21 | /** |
| 23 | * Returns the type of the file | 22 | * Returns the type of the file |
| 24 | * @param file FileUtil::IOFile open file | 23 | * @param file FileUtil::IOFile open file |
| 24 | * @param filepath Path of the file that we are opening. | ||
| 25 | * @return FileType found, or FileType::Error if this loader doesn't know it | 25 | * @return FileType found, or FileType::Error if this loader doesn't know it |
| 26 | */ | 26 | */ |
| 27 | static FileType IdentifyType(FileUtil::IOFile& file); | 27 | static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); |
| 28 | 28 | ||
| 29 | FileType GetFileType() override { | 29 | FileType GetFileType() override { |
| 30 | return IdentifyType(file); | 30 | return IdentifyType(file, filename); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 33 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 92defd381..2ec08506d 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2018 yuzu emulator team |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| @@ -7,12 +7,11 @@ | |||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/string_util.h" | 8 | #include "common/string_util.h" |
| 9 | #include "core/hle/kernel/process.h" | 9 | #include "core/hle/kernel/process.h" |
| 10 | #include "core/loader/deconstructed_rom_directory.h" | ||
| 10 | #include "core/loader/elf.h" | 11 | #include "core/loader/elf.h" |
| 11 | #include "core/loader/nro.h" | 12 | #include "core/loader/nro.h" |
| 12 | #include "core/loader/nso.h" | 13 | #include "core/loader/nso.h" |
| 13 | 14 | ||
| 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 15 | |||
| 16 | namespace Loader { | 15 | namespace Loader { |
| 17 | 16 | ||
| 18 | const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { | 17 | const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { |
| @@ -21,14 +20,15 @@ const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { | |||
| 21 | {0x1F000000, 0x600000, false}, // entire VRAM | 20 | {0x1F000000, 0x600000, false}, // entire VRAM |
| 22 | }; | 21 | }; |
| 23 | 22 | ||
| 24 | FileType IdentifyFile(FileUtil::IOFile& file) { | 23 | FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath) { |
| 25 | FileType type; | 24 | FileType type; |
| 26 | 25 | ||
| 27 | #define CHECK_TYPE(loader) \ | 26 | #define CHECK_TYPE(loader) \ |
| 28 | type = AppLoader_##loader::IdentifyType(file); \ | 27 | type = AppLoader_##loader::IdentifyType(file, filepath); \ |
| 29 | if (FileType::Error != type) \ | 28 | if (FileType::Error != type) \ |
| 30 | return type; | 29 | return type; |
| 31 | 30 | ||
| 31 | CHECK_TYPE(DeconstructedRomDirectory) | ||
| 32 | CHECK_TYPE(ELF) | 32 | CHECK_TYPE(ELF) |
| 33 | CHECK_TYPE(NSO) | 33 | CHECK_TYPE(NSO) |
| 34 | CHECK_TYPE(NRO) | 34 | CHECK_TYPE(NRO) |
| @@ -45,13 +45,13 @@ FileType IdentifyFile(const std::string& file_name) { | |||
| 45 | return FileType::Unknown; | 45 | return FileType::Unknown; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | return IdentifyFile(file); | 48 | return IdentifyFile(file, file_name); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | FileType GuessFromExtension(const std::string& extension_) { | 51 | FileType GuessFromExtension(const std::string& extension_) { |
| 52 | std::string extension = Common::ToLower(extension_); | 52 | std::string extension = Common::ToLower(extension_); |
| 53 | 53 | ||
| 54 | if (extension == ".elf" || extension == ".axf") | 54 | if (extension == ".elf") |
| 55 | return FileType::ELF; | 55 | return FileType::ELF; |
| 56 | else if (extension == ".nro") | 56 | else if (extension == ".nro") |
| 57 | return FileType::NRO; | 57 | return FileType::NRO; |
| @@ -69,6 +69,8 @@ const char* GetFileTypeString(FileType type) { | |||
| 69 | return "NRO"; | 69 | return "NRO"; |
| 70 | case FileType::NSO: | 70 | case FileType::NSO: |
| 71 | return "NSO"; | 71 | return "NSO"; |
| 72 | case FileType::DeconstructedRomDirectory: | ||
| 73 | return "Directory"; | ||
| 72 | case FileType::Error: | 74 | case FileType::Error: |
| 73 | case FileType::Unknown: | 75 | case FileType::Unknown: |
| 74 | break; | 76 | break; |
| @@ -102,6 +104,10 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileUtil::IOFile&& file, FileTyp | |||
| 102 | case FileType::NRO: | 104 | case FileType::NRO: |
| 103 | return std::make_unique<AppLoader_NRO>(std::move(file), filepath); | 105 | return std::make_unique<AppLoader_NRO>(std::move(file), filepath); |
| 104 | 106 | ||
| 107 | // NX deconstructed ROM directory. | ||
| 108 | case FileType::DeconstructedRomDirectory: | ||
| 109 | return std::make_unique<AppLoader_DeconstructedRomDirectory>(std::move(file), filepath); | ||
| 110 | |||
| 105 | default: | 111 | default: |
| 106 | return nullptr; | 112 | return nullptr; |
| 107 | } | 113 | } |
| @@ -117,7 +123,7 @@ std::unique_ptr<AppLoader> GetLoader(const std::string& filename) { | |||
| 117 | std::string filename_filename, filename_extension; | 123 | std::string filename_filename, filename_extension; |
| 118 | Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); | 124 | Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); |
| 119 | 125 | ||
| 120 | FileType type = IdentifyFile(file); | 126 | FileType type = IdentifyFile(file, filename); |
| 121 | FileType filename_type = GuessFromExtension(filename_extension); | 127 | FileType filename_type = GuessFromExtension(filename_extension); |
| 122 | 128 | ||
| 123 | if (type != filename_type) { | 129 | if (type != filename_type) { |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index dd6bb4e64..dd44ee9a6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2018 yuzu emulator team |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| @@ -20,9 +20,6 @@ struct AddressMapping; | |||
| 20 | class Process; | 20 | class Process; |
| 21 | } // namespace Kernel | 21 | } // namespace Kernel |
| 22 | 22 | ||
| 23 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 24 | // Loader namespace | ||
| 25 | |||
| 26 | namespace Loader { | 23 | namespace Loader { |
| 27 | 24 | ||
| 28 | /// File types supported by CTR | 25 | /// File types supported by CTR |
| @@ -32,14 +29,16 @@ enum class FileType { | |||
| 32 | ELF, | 29 | ELF, |
| 33 | NSO, | 30 | NSO, |
| 34 | NRO, | 31 | NRO, |
| 32 | DeconstructedRomDirectory, | ||
| 35 | }; | 33 | }; |
| 36 | 34 | ||
| 37 | /** | 35 | /** |
| 38 | * Identifies the type of a bootable file based on the magic value in its header. | 36 | * Identifies the type of a bootable file based on the magic value in its header. |
| 39 | * @param file open file | 37 | * @param file open file |
| 38 | * @param filepath Path of the file that we are opening. | ||
| 40 | * @return FileType of file | 39 | * @return FileType of file |
| 41 | */ | 40 | */ |
| 42 | FileType IdentifyFile(FileUtil::IOFile& file); | 41 | FileType IdentifyFile(FileUtil::IOFile& file, const std::string& filepath); |
| 43 | 42 | ||
| 44 | /** | 43 | /** |
| 45 | * Identifies the type of a bootable file based on the magic value in its header. | 44 | * Identifies the type of a bootable file based on the magic value in its header. |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 6864a1926..0a087153f 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <vector> | 5 | #include <vector> |
| 6 | 6 | ||
| 7 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | #include "common/file_util.h" | ||
| 8 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 9 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 10 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| @@ -45,7 +46,10 @@ struct ModHeader { | |||
| 45 | }; | 46 | }; |
| 46 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); | 47 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); |
| 47 | 48 | ||
| 48 | FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file) { | 49 | AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) |
| 50 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 51 | |||
| 52 | FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) { | ||
| 49 | // Read NSO header | 53 | // Read NSO header |
| 50 | NroHeader nro_header{}; | 54 | NroHeader nro_header{}; |
| 51 | file.Seek(0, SEEK_SET); | 55 | file.Seek(0, SEEK_SET); |
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index e20fa1555..599adb253 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h | |||
| @@ -4,10 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <map> | ||
| 8 | #include <string> | 7 | #include <string> |
| 9 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 10 | #include "common/file_util.h" | ||
| 11 | #include "core/hle/kernel/kernel.h" | 9 | #include "core/hle/kernel/kernel.h" |
| 12 | #include "core/loader/linker.h" | 10 | #include "core/loader/linker.h" |
| 13 | #include "core/loader/loader.h" | 11 | #include "core/loader/loader.h" |
| @@ -17,18 +15,18 @@ namespace Loader { | |||
| 17 | /// Loads an NRO file | 15 | /// Loads an NRO file |
| 18 | class AppLoader_NRO final : public AppLoader, Linker { | 16 | class AppLoader_NRO final : public AppLoader, Linker { |
| 19 | public: | 17 | public: |
| 20 | AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) | 18 | AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath); |
| 21 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 22 | 19 | ||
| 23 | /** | 20 | /** |
| 24 | * Returns the type of the file | 21 | * Returns the type of the file |
| 25 | * @param file FileUtil::IOFile open file | 22 | * @param file FileUtil::IOFile open file |
| 23 | * @param filepath Path of the file that we are opening. | ||
| 26 | * @return FileType found, or FileType::Error if this loader doesn't know it | 24 | * @return FileType found, or FileType::Error if this loader doesn't know it |
| 27 | */ | 25 | */ |
| 28 | static FileType IdentifyType(FileUtil::IOFile& file); | 26 | static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); |
| 29 | 27 | ||
| 30 | FileType GetFileType() override { | 28 | FileType GetFileType() override { |
| 31 | return IdentifyType(file); | 29 | return IdentifyType(file, filepath); |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 32 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index ef769dd91..3ccbbb824 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #include <vector> | 5 | #include <vector> |
| 6 | #include <lz4.h> | 6 | #include <lz4.h> |
| 7 | |||
| 8 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | #include "common/file_util.h" | ||
| 9 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 10 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 11 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| @@ -47,7 +47,10 @@ struct ModHeader { | |||
| 47 | }; | 47 | }; |
| 48 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); | 48 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); |
| 49 | 49 | ||
| 50 | FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file) { | 50 | AppLoader_NSO::AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath) |
| 51 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 52 | |||
| 53 | FileType AppLoader_NSO::IdentifyType(FileUtil::IOFile& file, const std::string&) { | ||
| 51 | u32 magic = 0; | 54 | u32 magic = 0; |
| 52 | file.Seek(0, SEEK_SET); | 55 | file.Seek(0, SEEK_SET); |
| 53 | if (1 != file.ReadArray<u32>(&magic, 1)) { | 56 | if (1 != file.ReadArray<u32>(&magic, 1)) { |
| @@ -88,7 +91,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 88 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 91 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 89 | } | 92 | } |
| 90 | 93 | ||
| 91 | VAddr AppLoader_NSO::LoadNso(const std::string& path, VAddr load_base) { | 94 | VAddr AppLoader_NSO::LoadModule(const std::string& path, VAddr load_base) { |
| 92 | FileUtil::IOFile file(path, "rb"); | 95 | FileUtil::IOFile file(path, "rb"); |
| 93 | if (!file.IsOpen()) { | 96 | if (!file.IsOpen()) { |
| 94 | return {}; | 97 | return {}; |
| @@ -153,21 +156,9 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 153 | 156 | ||
| 154 | process = Kernel::Process::Create("main"); | 157 | process = Kernel::Process::Create("main"); |
| 155 | 158 | ||
| 156 | // Load NSO modules | 159 | // Load module |
| 157 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 160 | LoadModule(filepath, Memory::PROCESS_IMAGE_VADDR); |
| 158 | for (const auto& module : | 161 | LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", filepath.c_str(), Memory::PROCESS_IMAGE_VADDR); |
| 159 | {"rtld", "sdk", "subsdk0", "subsdk1", "subsdk2", "subsdk3", "subsdk4"}) { | ||
| 160 | const std::string path = filepath.substr(0, filepath.find_last_of("/\\")) + "/" + module; | ||
| 161 | const VAddr load_addr = next_load_addr; | ||
| 162 | next_load_addr = LoadNso(path, load_addr); | ||
| 163 | if (next_load_addr) { | ||
| 164 | LOG_DEBUG(Loader, "loaded module %s @ 0x%llx", module, load_addr); | ||
| 165 | } else { | ||
| 166 | next_load_addr = load_addr; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | // Load "main" module | ||
| 170 | LoadNso(filepath, next_load_addr); | ||
| 171 | 162 | ||
| 172 | process->svc_access_mask.set(); | 163 | process->svc_access_mask.set(); |
| 173 | process->address_mappings = default_address_mappings; | 164 | process->address_mappings = default_address_mappings; |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index a24bcdc24..1ae30a824 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -4,10 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <map> | ||
| 8 | #include <string> | 7 | #include <string> |
| 9 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 10 | #include "common/file_util.h" | ||
| 11 | #include "core/hle/kernel/kernel.h" | 9 | #include "core/hle/kernel/kernel.h" |
| 12 | #include "core/loader/linker.h" | 10 | #include "core/loader/linker.h" |
| 13 | #include "core/loader/loader.h" | 11 | #include "core/loader/loader.h" |
| @@ -17,25 +15,25 @@ namespace Loader { | |||
| 17 | /// Loads an NSO file | 15 | /// Loads an NSO file |
| 18 | class AppLoader_NSO final : public AppLoader, Linker { | 16 | class AppLoader_NSO final : public AppLoader, Linker { |
| 19 | public: | 17 | public: |
| 20 | AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath) | 18 | AppLoader_NSO(FileUtil::IOFile&& file, std::string filepath); |
| 21 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 22 | 19 | ||
| 23 | /** | 20 | /** |
| 24 | * Returns the type of the file | 21 | * Returns the type of the file |
| 25 | * @param file FileUtil::IOFile open file | 22 | * @param file FileUtil::IOFile open file |
| 23 | * @param filepath Path of the file that we are opening. | ||
| 26 | * @return FileType found, or FileType::Error if this loader doesn't know it | 24 | * @return FileType found, or FileType::Error if this loader doesn't know it |
| 27 | */ | 25 | */ |
| 28 | static FileType IdentifyType(FileUtil::IOFile& file); | 26 | static FileType IdentifyType(FileUtil::IOFile& file, const std::string& filepath); |
| 29 | 27 | ||
| 30 | FileType GetFileType() override { | 28 | FileType GetFileType() override { |
| 31 | return IdentifyType(file); | 29 | return IdentifyType(file, filepath); |
| 32 | } | 30 | } |
| 33 | 31 | ||
| 32 | static VAddr LoadModule(const std::string& path, VAddr load_base); | ||
| 33 | |||
| 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 34 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 35 | 35 | ||
| 36 | private: | 36 | private: |
| 37 | VAddr LoadNso(const std::string& path, VAddr load_base); | ||
| 38 | |||
| 39 | std::string filepath; | 37 | std::string filepath; |
| 40 | }; | 38 | }; |
| 41 | 39 | ||