summaryrefslogtreecommitdiff
path: root/src/core/loader/nro.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2020-04-21 18:59:16 -0400
committerGravatar GitHub2020-04-21 18:59:16 -0400
commitcd47ccec496c9a961abf1dc58f8d2a4165c1bf2b (patch)
treeec4adafd6b8f513a4d37e4594dfa864df4d6bb17 /src/core/loader/nro.cpp
parentMerge pull request #3718 from ReinUsesLisp/better-pipeline-state (diff)
parentloader: nro: Fix process initialization using ProgramMetadata default. (diff)
downloadyuzu-cd47ccec496c9a961abf1dc58f8d2a4165c1bf2b.tar.gz
yuzu-cd47ccec496c9a961abf1dc58f8d2a4165c1bf2b.tar.xz
yuzu-cd47ccec496c9a961abf1dc58f8d2a4165c1bf2b.zip
Merge pull request #3745 from bunnei/fix-homebrew-load
Fix process memory initialization for ELF and NRO
Diffstat (limited to 'src/core/loader/nro.cpp')
-rw-r--r--src/core/loader/nro.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 5d7e8136e..906544bc9 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -131,7 +131,7 @@ static constexpr u32 PageAlignSize(u32 size) {
131} 131}
132 132
133static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, 133static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
134 const std::string& name, VAddr load_base) { 134 const std::string& name) {
135 if (data.size() < sizeof(NroHeader)) { 135 if (data.size() < sizeof(NroHeader)) {
136 return {}; 136 return {};
137 } 137 }
@@ -187,19 +187,25 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
187 codeset.DataSegment().size += bss_size; 187 codeset.DataSegment().size += bss_size;
188 program_image.resize(static_cast<u32>(program_image.size()) + bss_size); 188 program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
189 189
190 // Setup the process code layout
191 if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), program_image.size())
192 .IsError()) {
193 return false;
194 }
195
190 // Load codeset for current process 196 // Load codeset for current process
191 codeset.memory = std::move(program_image); 197 codeset.memory = std::move(program_image);
192 process.LoadModule(std::move(codeset), load_base); 198 process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart());
193 199
194 // Register module with GDBStub 200 // Register module with GDBStub
195 GDBStub::RegisterModule(name, load_base, load_base); 201 GDBStub::RegisterModule(name, process.PageTable().GetCodeRegionStart(),
202 process.PageTable().GetCodeRegionEnd());
196 203
197 return true; 204 return true;
198} 205}
199 206
200bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, 207bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file) {
201 VAddr load_base) { 208 return LoadNroImpl(process, file.ReadAllBytes(), file.GetName());
202 return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base);
203} 209}
204 210
205AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) { 211AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) {
@@ -207,10 +213,7 @@ AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) {
207 return {ResultStatus::ErrorAlreadyLoaded, {}}; 213 return {ResultStatus::ErrorAlreadyLoaded, {}};
208 } 214 }
209 215
210 // Load NRO 216 if (!LoadNro(process, *file)) {
211 const VAddr base_address = process.PageTable().GetCodeRegionStart();
212
213 if (!LoadNro(process, *file, base_address)) {
214 return {ResultStatus::ErrorLoadingNRO, {}}; 217 return {ResultStatus::ErrorLoadingNRO, {}};
215 } 218 }
216 219