summaryrefslogtreecommitdiff
path: root/src/core/loader/nso.cpp
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-09-30 14:04:48 -0400
committerGravatar Zach Hilman2018-10-07 14:30:15 -0400
commite09505ff6147815d7d3c7adcc0d260638cf49706 (patch)
treea430bbf3af585ac0e117c28b5782ee9556a2895a /src/core/loader/nso.cpp
parentMerge pull request #1396 from DarkLordZach/packed-updates (diff)
downloadyuzu-e09505ff6147815d7d3c7adcc0d260638cf49706.tar.gz
yuzu-e09505ff6147815d7d3c7adcc0d260638cf49706.tar.xz
yuzu-e09505ff6147815d7d3c7adcc0d260638cf49706.zip
nso/nro: Add NSO arguments structure to data section
Only added if arguments string is non-empty and a pass is requested by loader.
Diffstat (limited to 'src/core/loader/nso.cpp')
-rw-r--r--src/core/loader/nso.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 2186b02af..8ee2c6f2b 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -17,6 +17,7 @@
17#include "core/hle/kernel/vm_manager.h" 17#include "core/hle/kernel/vm_manager.h"
18#include "core/loader/nso.h" 18#include "core/loader/nso.h"
19#include "core/memory.h" 19#include "core/memory.h"
20#include "core/settings.h"
20 21
21namespace Loader { 22namespace Loader {
22 23
@@ -94,6 +95,7 @@ static constexpr u32 PageAlignSize(u32 size) {
94} 95}
95 96
96VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, 97VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
98 bool should_pass_arguments,
97 boost::optional<FileSys::PatchManager> pm) { 99 boost::optional<FileSys::PatchManager> pm) {
98 if (file == nullptr) 100 if (file == nullptr)
99 return {}; 101 return {};
@@ -125,6 +127,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
125 codeset->segments[i].size = PageAlignSize(static_cast<u32>(data.size())); 127 codeset->segments[i].size = PageAlignSize(static_cast<u32>(data.size()));
126 } 128 }
127 129
130 if (should_pass_arguments && !Settings::values.program_args.empty()) {
131 const auto arg_data = Settings::values.program_args;
132 codeset->DataSegment().size += 0x9000;
133 NSOArgumentHeader args_header{0x9000, arg_data.size(), {}};
134 program_image.resize(static_cast<u32>(program_image.size()) + 0x9000);
135 std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header,
136 sizeof(NSOArgumentHeader));
137 std::memcpy(program_image.data() + program_image.size() - 0x8FE0, arg_data.data(),
138 arg_data.size());
139 }
140
128 // MOD header pointer is at .text offset + 4 141 // MOD header pointer is at .text offset + 4
129 u32 module_offset; 142 u32 module_offset;
130 std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32)); 143 std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32));
@@ -172,7 +185,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
172 185
173 // Load module 186 // Load module
174 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); 187 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
175 LoadModule(file, base_address); 188 LoadModule(file, base_address, true);
176 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); 189 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
177 190
178 process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); 191 process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);