summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp4
-rw-r--r--src/core/loader/nro.cpp15
-rw-r--r--src/core/loader/nso.cpp17
-rw-r--r--src/core/loader/nso.h11
-rw-r--r--src/core/settings.h1
5 files changed, 45 insertions, 3 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index 9a86e5824..951fd8257 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cinttypes> 5#include <cinttypes>
6#include <cstring>
6#include "common/common_funcs.h" 7#include "common/common_funcs.h"
7#include "common/file_util.h" 8#include "common/file_util.h"
8#include "common/logging/log.h" 9#include "common/logging/log.h"
@@ -140,7 +141,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
140 const FileSys::VirtualFile module_file = dir->GetFile(module); 141 const FileSys::VirtualFile module_file = dir->GetFile(module);
141 if (module_file != nullptr) { 142 if (module_file != nullptr) {
142 const VAddr load_addr = next_load_addr; 143 const VAddr load_addr = next_load_addr;
143 next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm); 144 next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr,
145 std::strcmp(module, "rtld") == 0, pm);
144 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); 146 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
145 // Register module with GDBStub 147 // Register module with GDBStub
146 GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); 148 GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false);
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index c10f826a4..25dd3f04e 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -18,7 +18,9 @@
18#include "core/hle/kernel/process.h" 18#include "core/hle/kernel/process.h"
19#include "core/hle/kernel/vm_manager.h" 19#include "core/hle/kernel/vm_manager.h"
20#include "core/loader/nro.h" 20#include "core/loader/nro.h"
21#include "core/loader/nso.h"
21#include "core/memory.h" 22#include "core/memory.h"
23#include "core/settings.h"
22 24
23namespace Loader { 25namespace Loader {
24 26
@@ -150,6 +152,19 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
150 codeset->segments[i].size = PageAlignSize(nro_header.segments[i].size); 152 codeset->segments[i].size = PageAlignSize(nro_header.segments[i].size);
151 } 153 }
152 154
155 if (!Settings::values.program_args.empty()) {
156 const auto arg_data = Settings::values.program_args;
157 codeset->DataSegment().size += NSO_ARGUMENT_DATA_ALLOCATION_SIZE;
158 NSOArgumentHeader args_header{
159 NSO_ARGUMENT_DATA_ALLOCATION_SIZE, static_cast<u32_le>(arg_data.size()), {}};
160 const auto end_offset = program_image.size();
161 program_image.resize(static_cast<u32>(program_image.size()) +
162 NSO_ARGUMENT_DATA_ALLOCATION_SIZE);
163 std::memcpy(program_image.data() + end_offset, &args_header, sizeof(NSOArgumentHeader));
164 std::memcpy(program_image.data() + end_offset + sizeof(NSOArgumentHeader), arg_data.data(),
165 arg_data.size());
166 }
167
153 // Read MOD header 168 // Read MOD header
154 ModHeader mod_header{}; 169 ModHeader mod_header{};
155 // Default .bss to NRO header bss size if MOD0 section doesn't exist 170 // Default .bss to NRO header bss size if MOD0 section doesn't exist
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);
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h
index 05353d4d9..70ab3b718 100644
--- a/src/core/loader/nso.h
+++ b/src/core/loader/nso.h
@@ -11,6 +11,15 @@
11 11
12namespace Loader { 12namespace Loader {
13 13
14constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000;
15
16struct NSOArgumentHeader {
17 u32_le allocated_size;
18 u32_le actual_size;
19 INSERT_PADDING_BYTES(0x18);
20};
21static_assert(sizeof(NSOArgumentHeader) == 0x20, "NSOArgumentHeader has incorrect size.");
22
14/// Loads an NSO file 23/// Loads an NSO file
15class AppLoader_NSO final : public AppLoader, Linker { 24class AppLoader_NSO final : public AppLoader, Linker {
16public: 25public:
@@ -27,7 +36,7 @@ public:
27 return IdentifyType(file); 36 return IdentifyType(file);
28 } 37 }
29 38
30 static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, 39 static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, bool should_pass_arguments,
31 boost::optional<FileSys::PatchManager> pm = boost::none); 40 boost::optional<FileSys::PatchManager> pm = boost::none);
32 41
33 ResultStatus Load(Kernel::Process& process) override; 42 ResultStatus Load(Kernel::Process& process) override;
diff --git a/src/core/settings.h b/src/core/settings.h
index 1808f5937..83b9a04c8 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -155,6 +155,7 @@ struct Values {
155 // Debugging 155 // Debugging
156 bool use_gdbstub; 156 bool use_gdbstub;
157 u16 gdbstub_port; 157 u16 gdbstub_port;
158 std::string program_args;
158 159
159 // WebService 160 // WebService
160 bool enable_telemetry; 161 bool enable_telemetry;