From c100a4b8d45d09494d79b5f5e3ece7dee9f841e9 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sat, 22 Dec 2018 21:31:07 -0500 Subject: loader/nso: Set main code region in VMManager For rom directories (and by extension, XCI/NSP/NAX/NCA) this is for the NSO with name 'main', for regular NSOs, this is the NSO. --- src/core/loader/nso.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/core/loader/nso.cpp') 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 #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 AppLoader_NSO::LoadModule(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base, bool should_pass_arguments, + bool should_register_data_region, std::optional pm) { if (file.GetSize() < sizeof(NsoHeader)) return {}; @@ -153,6 +156,10 @@ std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, const u32 image_size{PageAlignSize(static_cast(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 pi_header(program_image.size() + 0x100); @@ -164,6 +171,15 @@ std::optional 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::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); -- cgit v1.2.3 From 52ac6419dafb84b10369226d3746b3b5b761d33b Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 5 Mar 2019 10:09:27 -0500 Subject: vm_manager: Remove cheat-specific ranges from VMManager --- src/core/loader/nso.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/core/loader/nso.cpp') diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 2721d85b1..5f6a6c0cf 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -97,7 +97,6 @@ static constexpr u32 PageAlignSize(u32 size) { std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base, bool should_pass_arguments, - bool should_register_data_region, std::optional pm) { if (file.GetSize() < sizeof(NsoHeader)) return {}; @@ -156,10 +155,6 @@ std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, const u32 image_size{PageAlignSize(static_cast(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 pi_header(program_image.size() + 0x100); @@ -176,7 +171,8 @@ std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, const auto cheats = pm->CreateCheatList(nso_header.build_id); if (!cheats.empty()) { Core::System::GetInstance().RegisterCheatList( - cheats, Common::HexArrayToString(nso_header.build_id)); + cheats, Common::HexArrayToString(nso_header.build_id), load_base, + load_base + program_image.size()); } } @@ -197,7 +193,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { // Load module const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); - if (!LoadModule(process, *file, base_address, true, true)) { + if (!LoadModule(process, *file, base_address, true)) { return ResultStatus::ErrorLoadingNSO; } LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); -- cgit v1.2.3