summaryrefslogtreecommitdiff
path: root/src/core/loader/nso.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2020-04-09 16:12:31 -0400
committerGravatar bunnei2020-04-17 00:59:35 -0400
commitbebfb05c1b19d879dcaec7a331b14ccff78d3796 (patch)
tree6c43611bf951317689e5b011615cf1149f4b8d1b /src/core/loader/nso.cpp
parentloader: elf/kip/nro: Updates for new VMM. (diff)
downloadyuzu-bebfb05c1b19d879dcaec7a331b14ccff78d3796.tar.gz
yuzu-bebfb05c1b19d879dcaec7a331b14ccff78d3796.tar.xz
yuzu-bebfb05c1b19d879dcaec7a331b14ccff78d3796.zip
loader: nso: Fix loader size and arguments.
Diffstat (limited to 'src/core/loader/nso.cpp')
-rw-r--r--src/core/loader/nso.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index ce9d52309..612ff9bf6 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -16,8 +16,8 @@
16#include "core/file_sys/patch_manager.h" 16#include "core/file_sys/patch_manager.h"
17#include "core/gdbstub/gdbstub.h" 17#include "core/gdbstub/gdbstub.h"
18#include "core/hle/kernel/code_set.h" 18#include "core/hle/kernel/code_set.h"
19#include "core/hle/kernel/memory/page_table.h"
19#include "core/hle/kernel/process.h" 20#include "core/hle/kernel/process.h"
20#include "core/hle/kernel/vm_manager.h"
21#include "core/loader/nso.h" 21#include "core/loader/nso.h"
22#include "core/memory.h" 22#include "core/memory.h"
23#include "core/settings.h" 23#include "core/settings.h"
@@ -73,7 +73,7 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) {
73 73
74std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, 74std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
75 const FileSys::VfsFile& file, VAddr load_base, 75 const FileSys::VfsFile& file, VAddr load_base,
76 bool should_pass_arguments, 76 bool should_pass_arguments, bool load_into_process,
77 std::optional<FileSys::PatchManager> pm) { 77 std::optional<FileSys::PatchManager> pm) {
78 if (file.GetSize() < sizeof(NSOHeader)) { 78 if (file.GetSize() < sizeof(NSOHeader)) {
79 return {}; 79 return {};
@@ -105,12 +105,9 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
105 codeset.segments[i].size = nso_header.segments[i].size; 105 codeset.segments[i].size = nso_header.segments[i].size;
106 } 106 }
107 107
108 if (should_pass_arguments) { 108 if (should_pass_arguments && !Settings::values.program_args.empty()) {
109 std::vector<u8> arg_data{Settings::values.program_args.begin(), 109 const auto arg_data{Settings::values.program_args};
110 Settings::values.program_args.end()}; 110
111 if (arg_data.empty()) {
112 arg_data.resize(NSO_ARGUMENT_DEFAULT_SIZE);
113 }
114 codeset.DataSegment().size += NSO_ARGUMENT_DATA_ALLOCATION_SIZE; 111 codeset.DataSegment().size += NSO_ARGUMENT_DATA_ALLOCATION_SIZE;
115 NSOArgumentHeader args_header{ 112 NSOArgumentHeader args_header{
116 NSO_ARGUMENT_DATA_ALLOCATION_SIZE, static_cast<u32_le>(arg_data.size()), {}}; 113 NSO_ARGUMENT_DATA_ALLOCATION_SIZE, static_cast<u32_le>(arg_data.size()), {}};
@@ -144,6 +141,11 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
144 std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.data()); 141 std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.data());
145 } 142 }
146 143
144 // If we aren't actually loading (i.e. just computing the process code layout), we are done
145 if (!load_into_process) {
146 return load_base + image_size;
147 }
148
147 // Apply cheats if they exist and the program has a valid title ID 149 // Apply cheats if they exist and the program has a valid title ID
148 if (pm) { 150 if (pm) {
149 auto& system = Core::System::GetInstance(); 151 auto& system = Core::System::GetInstance();
@@ -172,8 +174,8 @@ AppLoader_NSO::LoadResult AppLoader_NSO::Load(Kernel::Process& process) {
172 modules.clear(); 174 modules.clear();
173 175
174 // Load module 176 // Load module
175 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); 177 const VAddr base_address = process.PageTable().GetCodeRegionStart();
176 if (!LoadModule(process, *file, base_address, true)) { 178 if (!LoadModule(process, *file, base_address, true, true)) {
177 return {ResultStatus::ErrorLoadingNSO, {}}; 179 return {ResultStatus::ErrorLoadingNSO, {}};
178 } 180 }
179 181