mirror of
https://gitlab.com/suyu-emu/suyu.git
synced 2024-03-15 23:15:44 +00:00
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.
This commit is contained in:
parent
b952a30555
commit
c100a4b8d4
|
@ -147,8 +147,10 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process)
|
||||||
|
|
||||||
const VAddr load_addr = next_load_addr;
|
const VAddr load_addr = next_load_addr;
|
||||||
const bool should_pass_arguments = std::strcmp(module, "rtld") == 0;
|
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 =
|
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) {
|
if (!tentative_next_load_addr) {
|
||||||
return ResultStatus::ErrorLoadingNSO;
|
return ResultStatus::ErrorLoadingNSO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
#include <lz4.h>
|
#include <lz4.h>
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
|
#include "common/hex_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
|
#include "core/core.h"
|
||||||
#include "core/file_sys/patch_manager.h"
|
#include "core/file_sys/patch_manager.h"
|
||||||
#include "core/gdbstub/gdbstub.h"
|
#include "core/gdbstub/gdbstub.h"
|
||||||
#include "core/hle/kernel/process.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,
|
std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
|
||||||
const FileSys::VfsFile& file, VAddr load_base,
|
const FileSys::VfsFile& file, VAddr load_base,
|
||||||
bool should_pass_arguments,
|
bool should_pass_arguments,
|
||||||
|
bool should_register_data_region,
|
||||||
std::optional<FileSys::PatchManager> pm) {
|
std::optional<FileSys::PatchManager> pm) {
|
||||||
if (file.GetSize() < sizeof(NsoHeader))
|
if (file.GetSize() < sizeof(NsoHeader))
|
||||||
return {};
|
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)};
|
const u32 image_size{PageAlignSize(static_cast<u32>(program_image.size()) + bss_size)};
|
||||||
program_image.resize(image_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
|
// Apply patches if necessary
|
||||||
if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) {
|
if (pm && (pm->HasNSOPatch(nso_header.build_id) || Settings::values.dump_nso)) {
|
||||||
std::vector<u8> pi_header(program_image.size() + 0x100);
|
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());
|
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
|
// Load codeset for current process
|
||||||
codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image));
|
codeset.memory = std::make_shared<std::vector<u8>>(std::move(program_image));
|
||||||
process.LoadModule(std::move(codeset), load_base);
|
process.LoadModule(std::move(codeset), load_base);
|
||||||
|
@ -181,7 +197,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) {
|
||||||
|
|
||||||
// Load module
|
// Load module
|
||||||
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
|
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;
|
return ResultStatus::ErrorLoadingNSO;
|
||||||
}
|
}
|
||||||
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
|
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
|
|
||||||
static std::optional<VAddr> LoadModule(Kernel::Process& process, const FileSys::VfsFile& file,
|
static std::optional<VAddr> LoadModule(Kernel::Process& process, const FileSys::VfsFile& file,
|
||||||
VAddr load_base, bool should_pass_arguments,
|
VAddr load_base, bool should_pass_arguments,
|
||||||
|
bool should_register_data_segment,
|
||||||
std::optional<FileSys::PatchManager> pm = {});
|
std::optional<FileSys::PatchManager> pm = {});
|
||||||
|
|
||||||
ResultStatus Load(Kernel::Process& process) override;
|
ResultStatus Load(Kernel::Process& process) override;
|
||||||
|
|
Loading…
Reference in a new issue