summaryrefslogtreecommitdiff
path: root/src/core/loader/nso.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2018-10-08 01:19:39 -0400
committerGravatar GitHub2018-10-08 01:19:39 -0400
commitae982a9bdf75970de1e612d824df3f9cf7f5026b (patch)
tree1a03308eaa5c3c6bf55d6eee761446b925ae04f6 /src/core/loader/nso.cpp
parentMerge pull request #1396 from DarkLordZach/packed-updates (diff)
parentnso/nro: Use default allocation size for arg_data (diff)
downloadyuzu-ae982a9bdf75970de1e612d824df3f9cf7f5026b.tar.gz
yuzu-ae982a9bdf75970de1e612d824df3f9cf7f5026b.tar.xz
yuzu-ae982a9bdf75970de1e612d824df3f9cf7f5026b.zip
Merge pull request #1419 from DarkLordZach/homebrew-args
nso/nro: Add support for passing command-line arguments to executable
Diffstat (limited to 'src/core/loader/nso.cpp')
-rw-r--r--src/core/loader/nso.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 2186b02af..28c6dd9b7 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,19 @@ 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 += NSO_ARGUMENT_DATA_ALLOCATION_SIZE;
133 NSOArgumentHeader args_header{
134 NSO_ARGUMENT_DATA_ALLOCATION_SIZE, static_cast<u32_le>(arg_data.size()), {}};
135 const auto end_offset = program_image.size();
136 program_image.resize(static_cast<u32>(program_image.size()) +
137 NSO_ARGUMENT_DATA_ALLOCATION_SIZE);
138 std::memcpy(program_image.data() + end_offset, &args_header, sizeof(NSOArgumentHeader));
139 std::memcpy(program_image.data() + end_offset + sizeof(NSOArgumentHeader), arg_data.data(),
140 arg_data.size());
141 }
142
128 // MOD header pointer is at .text offset + 4 143 // MOD header pointer is at .text offset + 4
129 u32 module_offset; 144 u32 module_offset;
130 std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32)); 145 std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32));
@@ -172,7 +187,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
172 187
173 // Load module 188 // Load module
174 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); 189 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
175 LoadModule(file, base_address); 190 LoadModule(file, base_address, true);
176 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); 191 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
177 192
178 process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); 193 process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);