diff options
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 69 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 4 |
2 files changed, 71 insertions, 2 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 4bee5fb86..37030683b 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -7,14 +7,44 @@ | |||
| 7 | #include "common/file_util.h" | 7 | #include "common/file_util.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | #include "core/file_sys/romfs_factory.h" | ||
| 10 | #include "core/hle/kernel/process.h" | 11 | #include "core/hle/kernel/process.h" |
| 11 | #include "core/hle/kernel/resource_limit.h" | 12 | #include "core/hle/kernel/resource_limit.h" |
| 13 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 12 | #include "core/loader/deconstructed_rom_directory.h" | 14 | #include "core/loader/deconstructed_rom_directory.h" |
| 13 | #include "core/loader/nso.h" | 15 | #include "core/loader/nso.h" |
| 14 | #include "core/memory.h" | 16 | #include "core/memory.h" |
| 15 | 17 | ||
| 16 | namespace Loader { | 18 | namespace Loader { |
| 17 | 19 | ||
| 20 | static std::string FindRomFS(const std::string& directory) { | ||
| 21 | std::string filepath_romfs; | ||
| 22 | const auto callback = [&filepath_romfs](unsigned*, const std::string& directory, | ||
| 23 | const std::string& virtual_name) -> bool { | ||
| 24 | const std::string physical_name = directory + virtual_name; | ||
| 25 | if (FileUtil::IsDirectory(physical_name)) { | ||
| 26 | // Skip directories | ||
| 27 | return true; | ||
| 28 | } | ||
| 29 | |||
| 30 | // Verify extension | ||
| 31 | const std::string extension = physical_name.substr(physical_name.find_last_of(".") + 1); | ||
| 32 | if (Common::ToLower(extension) != "istorage") { | ||
| 33 | return true; | ||
| 34 | } | ||
| 35 | |||
| 36 | // Found it - we are done | ||
| 37 | filepath_romfs = std::move(physical_name); | ||
| 38 | return false; | ||
| 39 | }; | ||
| 40 | |||
| 41 | // Search the specified directory recursively, looking for the first .istorage file, which will | ||
| 42 | // be used for the RomFS | ||
| 43 | FileUtil::ForeachDirectoryEntry(nullptr, directory, callback); | ||
| 44 | |||
| 45 | return filepath_romfs; | ||
| 46 | } | ||
| 47 | |||
| 18 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, | 48 | AppLoader_DeconstructedRomDirectory::AppLoader_DeconstructedRomDirectory(FileUtil::IOFile&& file, |
| 19 | std::string filepath) | 49 | std::string filepath) |
| 20 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | 50 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} |
| @@ -79,10 +109,10 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 79 | 109 | ||
| 80 | // Load NSO modules | 110 | // Load NSO modules |
| 81 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 111 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 112 | const std::string directory = filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP; | ||
| 82 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | 113 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", |
| 83 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | 114 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { |
| 84 | const std::string path = | 115 | const std::string path = directory + DIR_SEP + module; |
| 85 | filepath.substr(0, filepath.find_last_of("/\\")) + DIR_SEP + module; | ||
| 86 | const VAddr load_addr = next_load_addr; | 116 | const VAddr load_addr = next_load_addr; |
| 87 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); | 117 | next_load_addr = AppLoader_NSO::LoadModule(path, load_addr); |
| 88 | if (next_load_addr) { | 118 | if (next_load_addr) { |
| @@ -98,8 +128,43 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 98 | Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); | 128 | Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); |
| 99 | process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); | 129 | process->Run(Memory::PROCESS_IMAGE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); |
| 100 | 130 | ||
| 131 | // Find the RomFS by searching for a ".istorage" file in this directory | ||
| 132 | filepath_romfs = FindRomFS(directory); | ||
| 133 | |||
| 134 | // Register the RomFS if a ".istorage" file was found | ||
| 135 | if (!filepath_romfs.empty()) { | ||
| 136 | Service::FileSystem::RegisterFileSystem(std::make_unique<FileSys::RomFS_Factory>(*this), | ||
| 137 | Service::FileSystem::Type::RomFS); | ||
| 138 | } | ||
| 139 | |||
| 101 | is_loaded = true; | 140 | is_loaded = true; |
| 102 | return ResultStatus::Success; | 141 | return ResultStatus::Success; |
| 103 | } | 142 | } |
| 104 | 143 | ||
| 144 | ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS( | ||
| 145 | std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) { | ||
| 146 | |||
| 147 | if (filepath_romfs.empty()) { | ||
| 148 | LOG_DEBUG(Loader, "No RomFS available"); | ||
| 149 | return ResultStatus::ErrorNotUsed; | ||
| 150 | } | ||
| 151 | |||
| 152 | // We reopen the file, to allow its position to be independent | ||
| 153 | romfs_file = std::make_shared<FileUtil::IOFile>(filepath_romfs, "rb"); | ||
| 154 | if (!romfs_file->IsOpen()) { | ||
| 155 | return ResultStatus::Error; | ||
| 156 | } | ||
| 157 | |||
| 158 | offset = 0; | ||
| 159 | size = romfs_file->GetSize(); | ||
| 160 | |||
| 161 | LOG_DEBUG(Loader, "RomFS offset: 0x%08X", offset); | ||
| 162 | LOG_DEBUG(Loader, "RomFS size: 0x%08X", size); | ||
| 163 | |||
| 164 | // Reset read pointer | ||
| 165 | file.Seek(0, SEEK_SET); | ||
| 166 | |||
| 167 | return ResultStatus::Success; | ||
| 168 | } | ||
| 169 | |||
| 105 | } // namespace Loader | 170 | } // namespace Loader |
diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 162541d54..26493de5e 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h | |||
| @@ -35,7 +35,11 @@ public: | |||
| 35 | 35 | ||
| 36 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; | 36 | ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; |
| 37 | 37 | ||
| 38 | ResultStatus ReadRomFS(std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, | ||
| 39 | u64& size) override; | ||
| 40 | |||
| 38 | private: | 41 | private: |
| 42 | std::string filepath_romfs; | ||
| 39 | std::string filepath; | 43 | std::string filepath; |
| 40 | }; | 44 | }; |
| 41 | 45 | ||