summaryrefslogtreecommitdiffstats
path: root/src/core/loader/nso.cpp
diff options
context:
space:
mode:
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 @@
#include "core/hle/kernel/vm_manager.h"
#include "core/loader/nso.h"
#include "core/memory.h"
+#include "core/settings.h"
namespace Loader {
@@ -94,6 +95,7 @@ static constexpr u32 PageAlignSize(u32 size) {
}
VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
+ bool should_pass_arguments,
boost::optional<FileSys::PatchManager> pm) {
if (file == nullptr)
return {};
@@ -125,6 +127,19 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base,
codeset->segments[i].size = PageAlignSize(static_cast<u32>(data.size()));
}
+ if (should_pass_arguments && !Settings::values.program_args.empty()) {
+ const auto arg_data = Settings::values.program_args;
+ codeset->DataSegment().size += NSO_ARGUMENT_DATA_ALLOCATION_SIZE;
+ NSOArgumentHeader args_header{
+ NSO_ARGUMENT_DATA_ALLOCATION_SIZE, static_cast<u32_le>(arg_data.size()), {}};
+ const auto end_offset = program_image.size();
+ program_image.resize(static_cast<u32>(program_image.size()) +
+ NSO_ARGUMENT_DATA_ALLOCATION_SIZE);
+ std::memcpy(program_image.data() + end_offset, &args_header, sizeof(NSOArgumentHeader));
+ std::memcpy(program_image.data() + end_offset + sizeof(NSOArgumentHeader), arg_data.data(),
+ arg_data.size());
+ }
+
// MOD header pointer is at .text offset + 4
u32 module_offset;
std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32));
@@ -172,7 +187,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
// Load module
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
- LoadModule(file, base_address);
+ LoadModule(file, base_address, true);
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);