summaryrefslogtreecommitdiff
path: root/src/core/loader/nro.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-07-07 20:24:51 -0700
committerGravatar bunnei2018-07-07 20:24:51 -0700
commit913896cbd99e414c325c9d47a987376ed6d9fffd (patch)
treeb660920a49f538f0ee00486c50a0d153d53c423d /src/core/loader/nro.cpp
parentMerge pull request #632 from FearlessTobi/add-discord-link (diff)
downloadyuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.gz
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.xz
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.zip
Revert "Virtual Filesystem (#597)"
This reverts commit 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.
Diffstat (limited to 'src/core/loader/nro.cpp')
-rw-r--r--src/core/loader/nro.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 08b7aad7a..3853cfa1a 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -47,12 +47,14 @@ struct ModHeader {
47}; 47};
48static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size."); 48static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size.");
49 49
50AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) {} 50AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath)
51 : AppLoader(std::move(file)), filepath(std::move(filepath)) {}
51 52
52FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { 53FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) {
53 // Read NSO header 54 // Read NSO header
54 NroHeader nro_header{}; 55 NroHeader nro_header{};
55 if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { 56 file.Seek(0, SEEK_SET);
57 if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) {
56 return FileType::Error; 58 return FileType::Error;
57 } 59 }
58 if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) { 60 if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) {
@@ -65,10 +67,16 @@ static constexpr u32 PageAlignSize(u32 size) {
65 return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; 67 return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
66} 68}
67 69
68bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { 70bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
71 FileUtil::IOFile file(path, "rb");
72 if (!file.IsOpen()) {
73 return {};
74 }
75
69 // Read NSO header 76 // Read NSO header
70 NroHeader nro_header{}; 77 NroHeader nro_header{};
71 if (sizeof(NroHeader) != file->ReadObject(&nro_header)) { 78 file.Seek(0, SEEK_SET);
79 if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) {
72 return {}; 80 return {};
73 } 81 }
74 if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { 82 if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) {
@@ -77,9 +85,10 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
77 85
78 // Build program image 86 // Build program image
79 Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); 87 Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("");
80 std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); 88 std::vector<u8> program_image;
81 if (program_image.size() != PageAlignSize(nro_header.file_size)) 89 program_image.resize(PageAlignSize(nro_header.file_size));
82 return {}; 90 file.Seek(0, SEEK_SET);
91 file.ReadBytes(program_image.data(), nro_header.file_size);
83 92
84 for (int i = 0; i < nro_header.segments.size(); ++i) { 93 for (int i = 0; i < nro_header.segments.size(); ++i) {
85 codeset->segments[i].addr = nro_header.segments[i].offset; 94 codeset->segments[i].addr = nro_header.segments[i].offset;
@@ -102,7 +111,7 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
102 program_image.resize(static_cast<u32>(program_image.size()) + bss_size); 111 program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
103 112
104 // Load codeset for current process 113 // Load codeset for current process
105 codeset->name = file->GetName(); 114 codeset->name = path;
106 codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image)); 115 codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image));
107 Core::CurrentProcess()->LoadModule(codeset, load_base); 116 Core::CurrentProcess()->LoadModule(codeset, load_base);
108 117
@@ -113,11 +122,14 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
113 if (is_loaded) { 122 if (is_loaded) {
114 return ResultStatus::ErrorAlreadyLoaded; 123 return ResultStatus::ErrorAlreadyLoaded;
115 } 124 }
125 if (!file.IsOpen()) {
126 return ResultStatus::Error;
127 }
116 128
117 // Load NRO 129 // Load NRO
118 static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; 130 static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR};
119 131
120 if (!LoadNro(file, base_addr)) { 132 if (!LoadNro(filepath, base_addr)) {
121 return ResultStatus::ErrorInvalidFormat; 133 return ResultStatus::ErrorInvalidFormat;
122 } 134 }
123 135