diff options
| author | 2018-07-06 10:51:32 -0400 | |
|---|---|---|
| committer | 2018-07-06 10:51:32 -0400 | |
| commit | 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2 (patch) | |
| tree | 38ef6451732c5eecb0efdd198f3db4d33848453c /src/core/loader/nro.cpp | |
| parent | Merge pull request #629 from Subv/depth_test (diff) | |
| download | yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.gz yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.tar.xz yuzu-77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.zip | |
Virtual Filesystem (#597)
* Add VfsFile and VfsDirectory classes
* Finish abstract Vfs classes
* Implement RealVfsFile (computer fs backend)
* Finish RealVfsFile and RealVfsDirectory
* Finished OffsetVfsFile
* More changes
* Fix import paths
* Major refactor
* Remove double const
* Use experimental/filesystem or filesystem depending on compiler
* Port partition_filesystem
* More changes
* More Overhaul
* FSP_SRV fixes
* Fixes and testing
* Try to get filesystem to compile
* Filesystem on linux
* Remove std::filesystem and document/test
* Compile fixes
* Missing include
* Bug fixes
* Fixes
* Rename v_file and v_dir
* clang-format fix
* Rename NGLOG_* to LOG_*
* Most review changes
* Fix TODO
* Guess 'main' to be Directory by filename
Diffstat (limited to 'src/core/loader/nro.cpp')
| -rw-r--r-- | src/core/loader/nro.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 3853cfa1a..08b7aad7a 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -47,14 +47,12 @@ 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 | AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) | 50 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) {} |
| 51 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 52 | 51 | ||
| 53 | FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) { | 52 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { |
| 54 | // Read NSO header | 53 | // Read NSO header |
| 55 | NroHeader nro_header{}; | 54 | NroHeader nro_header{}; |
| 56 | file.Seek(0, SEEK_SET); | 55 | if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { |
| 57 | if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) { | ||
| 58 | return FileType::Error; | 56 | return FileType::Error; |
| 59 | } | 57 | } |
| 60 | if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { | 58 | if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { |
| @@ -67,16 +65,10 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 67 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 65 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 68 | } | 66 | } |
| 69 | 67 | ||
| 70 | bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | 68 | bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { |
| 71 | FileUtil::IOFile file(path, "rb"); | ||
| 72 | if (!file.IsOpen()) { | ||
| 73 | return {}; | ||
| 74 | } | ||
| 75 | |||
| 76 | // Read NSO header | 69 | // Read NSO header |
| 77 | NroHeader nro_header{}; | 70 | NroHeader nro_header{}; |
| 78 | file.Seek(0, SEEK_SET); | 71 | if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { |
| 79 | if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) { | ||
| 80 | return {}; | 72 | return {}; |
| 81 | } | 73 | } |
| 82 | if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { | 74 | if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { |
| @@ -85,10 +77,9 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | |||
| 85 | 77 | ||
| 86 | // Build program image | 78 | // Build program image |
| 87 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); | 79 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); |
| 88 | std::vector<u8> program_image; | 80 | std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); |
| 89 | program_image.resize(PageAlignSize(nro_header.file_size)); | 81 | if (program_image.size() != PageAlignSize(nro_header.file_size)) |
| 90 | file.Seek(0, SEEK_SET); | 82 | return {}; |
| 91 | file.ReadBytes(program_image.data(), nro_header.file_size); | ||
| 92 | 83 | ||
| 93 | for (int i = 0; i < nro_header.segments.size(); ++i) { | 84 | for (int i = 0; i < nro_header.segments.size(); ++i) { |
| 94 | codeset->segments[i].addr = nro_header.segments[i].offset; | 85 | codeset->segments[i].addr = nro_header.segments[i].offset; |
| @@ -111,7 +102,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | |||
| 111 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); | 102 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); |
| 112 | 103 | ||
| 113 | // Load codeset for current process | 104 | // Load codeset for current process |
| 114 | codeset->name = path; | 105 | codeset->name = file->GetName(); |
| 115 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 106 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
| 116 | Core::CurrentProcess()->LoadModule(codeset, load_base); | 107 | Core::CurrentProcess()->LoadModule(codeset, load_base); |
| 117 | 108 | ||
| @@ -122,14 +113,11 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 122 | if (is_loaded) { | 113 | if (is_loaded) { |
| 123 | return ResultStatus::ErrorAlreadyLoaded; | 114 | return ResultStatus::ErrorAlreadyLoaded; |
| 124 | } | 115 | } |
| 125 | if (!file.IsOpen()) { | ||
| 126 | return ResultStatus::Error; | ||
| 127 | } | ||
| 128 | 116 | ||
| 129 | // Load NRO | 117 | // Load NRO |
| 130 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; | 118 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 131 | 119 | ||
| 132 | if (!LoadNro(filepath, base_addr)) { | 120 | if (!LoadNro(file, base_addr)) { |
| 133 | return ResultStatus::ErrorInvalidFormat; | 121 | return ResultStatus::ErrorInvalidFormat; |
| 134 | } | 122 | } |
| 135 | 123 | ||