summaryrefslogtreecommitdiff
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.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 6ded0b707..2721d85b1 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -7,8 +7,10 @@
7#include <lz4.h> 7#include <lz4.h>
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9#include "common/file_util.h" 9#include "common/file_util.h"
10#include "common/hex_util.h"
10#include "common/logging/log.h" 11#include "common/logging/log.h"
11#include "common/swap.h" 12#include "common/swap.h"
13#include "core/core.h"
12#include "core/file_sys/patch_manager.h" 14#include "core/file_sys/patch_manager.h"
13#include "core/gdbstub/gdbstub.h" 15#include "core/gdbstub/gdbstub.h"
14#include "core/hle/kernel/process.h" 16#include "core/hle/kernel/process.h"
@@ -95,6 +97,7 @@ static constexpr u32 PageAlignSize(u32 size) {
95std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, 97std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
96 const FileSys::VfsFile& file, VAddr load_base, 98 const FileSys::VfsFile& file, VAddr load_base,
97 bool should_pass_arguments, 99 bool should_pass_arguments,
100 bool should_register_data_region,
98 std::optional<FileSys::PatchManager> pm) { 101 std::optional<FileSys::PatchManager> pm) {
99 if (file.GetSize() < sizeof(NsoHeader)) 102 if (file.GetSize() < sizeof(NsoHeader))
100 return {}; 103 return {};
@@ -153,6 +156,10 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
153 const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)}; 156 const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)};
154 program_image.resize(image_size); 157 program_image.resize(image_size);
155 158
159 if (should_register_data_region) {
160 process.VMManager().SetMainCodeRegion(load_base, load_base + program_image.size());
161 }
162
156 // Apply patches if necessary 163 // Apply patches if necessary
157 if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) { 164 if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) {
158 std::vector<u8> pi_header(program_image.size() + 0x100); 165 std::vector<u8> pi_header(program_image.size() + 0x100);
@@ -164,6 +171,15 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
164 std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size()); 171 std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size());
165 } 172 }
166 173
174 // Apply cheats if they exist and the program has a valid title ID
175 if (pm) {
176 const auto cheats = pm->CreateCheatList(nso_header.build_id);
177 if (!cheats.empty()) {
178 Core::System::GetInstance().RegisterCheatList(
179 cheats, Common::HexArrayToString(nso_header.build_id));
180 }
181 }
182
167 // Load codeset for current process 183 // Load codeset for current process
168 codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image)); 184 codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image));
169 process.LoadModule(std::move(codeset), load_base); 185 process.LoadModule(std::move(codeset), load_base);
@@ -181,7 +197,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
181 197
182 // Load module 198 // Load module
183 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); 199 const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
184 if (!LoadModule(process, *file, base_address, true)) { 200 if (!LoadModule(process, *file, base_address, true, true)) {
185 return ResultStatus::ErrorLoadingNSO; 201 return ResultStatus::ErrorLoadingNSO;
186 } 202 }
187 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); 203 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);