diff options
| author | 2018-07-18 21:07:11 -0400 | |
|---|---|---|
| committer | 2018-07-18 18:07:11 -0700 | |
| commit | 29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef (patch) | |
| tree | 3202e2ce55ab6387a4ca366a509eccdd963434c3 /src/core/loader/nro.cpp | |
| parent | Merge pull request #683 from DarkLordZach/touch (diff) | |
| download | yuzu-29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef.tar.gz yuzu-29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef.tar.xz yuzu-29aff8d5ab46c8d0199aa4bfa7eeff5d4fa2d7ef.zip | |
Virtual Filesystem 2: Electric Boogaloo (#676)
* Virtual Filesystem
* Fix delete bug and documentate
* Review fixes + other stuff
* Fix puyo regression
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 4d7c69a22..a007d3e6e 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -48,14 +48,12 @@ struct ModHeader { | |||
| 48 | }; | 48 | }; |
| 49 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); | 49 | static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); |
| 50 | 50 | ||
| 51 | AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath) | 51 | AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) {} |
| 52 | : AppLoader(std::move(file)), filepath(std::move(filepath)) {} | ||
| 53 | 52 | ||
| 54 | FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) { | 53 | FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { |
| 55 | // Read NSO header | 54 | // Read NSO header |
| 56 | NroHeader nro_header{}; | 55 | NroHeader nro_header{}; |
| 57 | file.Seek(0, SEEK_SET); | 56 | if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { |
| 58 | if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) { | ||
| 59 | return FileType::Error; | 57 | return FileType::Error; |
| 60 | } | 58 | } |
| 61 | if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { | 59 | if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { |
| @@ -68,16 +66,10 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 68 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | 66 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; |
| 69 | } | 67 | } |
| 70 | 68 | ||
| 71 | bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | 69 | bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { |
| 72 | FileUtil::IOFile file(path, "rb"); | ||
| 73 | if (!file.IsOpen()) { | ||
| 74 | return {}; | ||
| 75 | } | ||
| 76 | |||
| 77 | // Read NSO header | 70 | // Read NSO header |
| 78 | NroHeader nro_header{}; | 71 | NroHeader nro_header{}; |
| 79 | file.Seek(0, SEEK_SET); | 72 | if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { |
| 80 | if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) { | ||
| 81 | return {}; | 73 | return {}; |
| 82 | } | 74 | } |
| 83 | if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { | 75 | if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { |
| @@ -86,10 +78,9 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | |||
| 86 | 78 | ||
| 87 | // Build program image | 79 | // Build program image |
| 88 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); | 80 | Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); |
| 89 | std::vector<u8> program_image; | 81 | std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); |
| 90 | program_image.resize(PageAlignSize(nro_header.file_size)); | 82 | if (program_image.size() != PageAlignSize(nro_header.file_size)) |
| 91 | file.Seek(0, SEEK_SET); | 83 | return {}; |
| 92 | file.ReadBytes(program_image.data(), nro_header.file_size); | ||
| 93 | 84 | ||
| 94 | for (int i = 0; i < nro_header.segments.size(); ++i) { | 85 | for (int i = 0; i < nro_header.segments.size(); ++i) { |
| 95 | codeset->segments[i].addr = nro_header.segments[i].offset; | 86 | codeset->segments[i].addr = nro_header.segments[i].offset; |
| @@ -112,7 +103,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { | |||
| 112 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); | 103 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); |
| 113 | 104 | ||
| 114 | // Load codeset for current process | 105 | // Load codeset for current process |
| 115 | codeset->name = path; | 106 | codeset->name = file->GetName(); |
| 116 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); | 107 | codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); |
| 117 | Core::CurrentProcess()->LoadModule(codeset, load_base); | 108 | Core::CurrentProcess()->LoadModule(codeset, load_base); |
| 118 | 109 | ||
| @@ -126,14 +117,11 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 126 | if (is_loaded) { | 117 | if (is_loaded) { |
| 127 | return ResultStatus::ErrorAlreadyLoaded; | 118 | return ResultStatus::ErrorAlreadyLoaded; |
| 128 | } | 119 | } |
| 129 | if (!file.IsOpen()) { | ||
| 130 | return ResultStatus::Error; | ||
| 131 | } | ||
| 132 | 120 | ||
| 133 | // Load NRO | 121 | // Load NRO |
| 134 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; | 122 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 135 | 123 | ||
| 136 | if (!LoadNro(filepath, base_addr)) { | 124 | if (!LoadNro(file, base_addr)) { |
| 137 | return ResultStatus::ErrorInvalidFormat; | 125 | return ResultStatus::ErrorInvalidFormat; |
| 138 | } | 126 | } |
| 139 | 127 | ||