summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-12-23 03:31:07 +0100
committerZach Hilman <zachhilman@gmail.com>2019-03-05 00:39:58 +0100
commitc100a4b8d45d09494d79b5f5e3ece7dee9f841e9 (patch)
treeb21aa41bbd7c5e81e0960e1524d393f4e7b2c030 /src/core
parentvm_manager: Add support for storing and getting main code region (diff)
downloadyuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.tar
yuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.tar.gz
yuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.tar.bz2
yuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.tar.lz
yuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.tar.xz
yuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.tar.zst
yuzu-c100a4b8d45d09494d79b5f5e3ece7dee9f841e9.zip
Diffstat (limited to 'src/core')
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp4
-rw-r--r--src/core/loader/nso.cpp18
-rw-r--r--src/core/loader/nso.h1
3 files changed, 21 insertions, 2 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index 07aa7a1cd..ef9a577e3 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -147,8 +147,10 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
const VAddr load_addr = next_load_addr;
const bool should_pass_arguments = std::strcmp(module, "rtld") == 0;
+ const bool should_register_data_segment = std::strcmp(module, "main") == 0;
const auto tentative_next_load_addr =
- AppLoader_NSO::LoadModule(process, *module_file, load_addr, should_pass_arguments, pm);
+ AppLoader_NSO::LoadModule(process, *module_file, load_addr, should_pass_arguments,
+ should_register_data_segment, pm);
if (!tentative_next_load_addr) {
return ResultStatus::ErrorLoadingNSO;
}
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 @@
#include <lz4.h>
#include "common/common_funcs.h"
#include "common/file_util.h"
+#include "common/hex_util.h"
#include "common/logging/log.h"
#include "common/swap.h"
+#include "core/core.h"
#include "core/file_sys/patch_manager.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/process.h"
@@ -95,6 +97,7 @@ static constexpr u32 PageAlignSize(u32 size) {
std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
const FileSys::VfsFile& file, VAddr load_base,
bool should_pass_arguments,
+ bool should_register_data_region,
std::optional<FileSys::PatchManager> pm) {
if (file.GetSize() < sizeof(NsoHeader))
return {};
@@ -153,6 +156,10 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)};
program_image.resize(image_size);
+ if (should_register_data_region) {
+ process.VMManager().SetMainCodeRegion(load_base, load_base + program_image.size());
+ }
+
// Apply patches if necessary
if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) {
std::vector<u8> pi_header(program_image.size() + 0x100);
@@ -164,6 +171,15 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
std::memcpy(program_image.data(), pi_header.data() + 0x100, program_image.size());
}
+ // Apply cheats if they exist and the program has a valid title ID
+ if (pm) {
+ const auto cheats = pm->CreateCheatList(nso_header.build_id);
+ if (!cheats.empty()) {
+ Core::System::GetInstance().RegisterCheatList(
+ cheats, Common::HexArrayToString(nso_header.build_id));
+ }
+ }
+
// Load codeset for current process
codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image));
process.LoadModule(std::move(codeset), load_base);
@@ -181,7 +197,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
// Load module
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
- if (!LoadModule(process, *file, base_address, true)) {
+ if (!LoadModule(process, *file, base_address, true, true)) {
return ResultStatus::ErrorLoadingNSO;
}
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h
index 135b6ea5a..858e346c6 100644
--- a/src/core/loader/nso.h
+++ b/src/core/loader/nso.h
@@ -43,6 +43,7 @@ public:
static std::optional<VAddr> LoadModule(Kernel::Process& process, const FileSys::VfsFile& file,
VAddr load_base, bool should_pass_arguments,
+ bool should_register_data_segment,
std::optional<FileSys::PatchManager> pm = {});
ResultStatus Load(Kernel::Process& process) override;