From b110d2176c68d8efe572766e9b7edd80e3dd4298 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 2 Dec 2018 22:13:50 -0500 Subject: [PATCH 1/3] loader/nro: Remove dependency on the System class Load() is already given the process instance as a parameter, so instead of coupling the class to the System class, we can just forward that parameter to LoadNro() --- src/core/loader/nro.cpp | 14 ++++++-------- src/core/loader/nro.h | 9 +++++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index fbbd6b0de2..16d5883ee2 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -10,7 +10,6 @@ #include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" -#include "core/core.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/romfs_factory.h" #include "core/file_sys/vfs_offset.h" @@ -129,9 +128,8 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -/*static*/ bool AppLoader_NRO::LoadNro(const std::vector& data, const std::string& name, - VAddr load_base) { - +/*static*/ bool AppLoader_NRO::LoadNro(Kernel::Process& process, const std::vector& data, + const std::string& name, VAddr load_base) { if (data.size() < sizeof(NroHeader)) { return {}; } @@ -189,7 +187,7 @@ static constexpr u32 PageAlignSize(u32 size) { // Load codeset for current process codeset.memory = std::make_shared>(std::move(program_image)); - Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); + process.LoadModule(std::move(codeset), load_base); // Register module with GDBStub GDBStub::RegisterModule(name, load_base, load_base); @@ -197,8 +195,8 @@ static constexpr u32 PageAlignSize(u32 size) { return true; } -bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { - return AppLoader_NRO::LoadNro(file.ReadAllBytes(), file.GetName(), load_base); +bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base) { + return LoadNro(process, file.ReadAllBytes(), file.GetName(), load_base); } ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { @@ -209,7 +207,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { // Load NRO const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); - if (!LoadNro(*file, base_address)) { + if (!LoadNro(process, *file, base_address)) { return ResultStatus::ErrorLoadingNRO; } diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 3e69593024..6a63d1a7ad 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -14,6 +14,10 @@ namespace FileSys { class NACP; } +namespace Kernel { +class Process; +} + namespace Loader { /// Loads an NRO file @@ -41,10 +45,11 @@ public: ResultStatus ReadTitle(std::string& title) override; bool IsRomFSUpdatable() const override; - static bool LoadNro(const std::vector& data, const std::string& name, VAddr load_base); + static bool LoadNro(Kernel::Process& process, const std::vector& data, + const std::string& name, VAddr load_base); private: - bool LoadNro(const FileSys::VfsFile& file, VAddr load_base); + bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base); std::vector icon_data; std::unique_ptr nacp; From fc32d6256adb479e3e990a0f3221d02ef09b1744 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 2 Dec 2018 22:17:09 -0500 Subject: [PATCH 2/3] loader/nro: Make the static LoadNro function internally linked This simply acts as a forwarding function for the Load() function, so this doesn't need to be directly exposed. --- src/core/loader/nro.cpp | 9 +++++---- src/core/loader/nro.h | 3 --- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 16d5883ee2..4fad0c0dd2 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -128,8 +128,8 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -/*static*/ bool AppLoader_NRO::LoadNro(Kernel::Process& process, const std::vector& data, - const std::string& name, VAddr load_base) { +static bool LoadNroImpl(Kernel::Process& process, const std::vector& data, + const std::string& name, VAddr load_base) { if (data.size() < sizeof(NroHeader)) { return {}; } @@ -195,8 +195,9 @@ static constexpr u32 PageAlignSize(u32 size) { return true; } -bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base) { - return LoadNro(process, file.ReadAllBytes(), file.GetName(), load_base); +bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, + VAddr load_base) { + return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base); } ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 6a63d1a7ad..6deff3a51e 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -45,9 +45,6 @@ public: ResultStatus ReadTitle(std::string& title) override; bool IsRomFSUpdatable() const override; - static bool LoadNro(Kernel::Process& process, const std::vector& data, - const std::string& name, VAddr load_base); - private: bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base); From 7695febfa1f3ef45fbac5fe674c1371c88f483b6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 2 Dec 2018 22:24:43 -0500 Subject: [PATCH 3/3] loader/nso: Remove dependency on the System class Similar to the NRO changes, we can also pass the process explicitly as a parameter from Load instead of indirecting through the System class. --- src/core/loader/deconstructed_rom_directory.cpp | 3 +-- src/core/loader/nso.cpp | 8 ++++---- src/core/loader/nso.h | 8 ++++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 8518dddcbb..ac04d72d79 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -7,7 +7,6 @@ #include "common/common_funcs.h" #include "common/file_util.h" #include "common/logging/log.h" -#include "core/core.h" #include "core/file_sys/content_archive.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" @@ -146,7 +145,7 @@ 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 auto tentative_next_load_addr = - AppLoader_NSO::LoadModule(*module_file, load_addr, should_pass_arguments, pm); + AppLoader_NSO::LoadModule(process, *module_file, load_addr, should_pass_arguments, pm); if (!tentative_next_load_addr) { return ResultStatus::ErrorLoadingNSO; } diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index aaf0063092..6ded0b7073 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -9,7 +9,6 @@ #include "common/file_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" @@ -93,7 +92,8 @@ static constexpr u32 PageAlignSize(u32 size) { return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; } -std::optional AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAddr load_base, +std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, + const FileSys::VfsFile& file, VAddr load_base, bool should_pass_arguments, std::optional pm) { if (file.GetSize() < sizeof(NsoHeader)) @@ -166,7 +166,7 @@ std::optional AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAd // Load codeset for current process codeset.memory = std::make_shared>(std::move(program_image)); - Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); + process.LoadModule(std::move(codeset), load_base); // Register module with GDBStub GDBStub::RegisterModule(file.GetName(), load_base, load_base); @@ -181,7 +181,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { // Load module const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); - if (!LoadModule(*file, base_address, true)) { + if (!LoadModule(process, *file, base_address, 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 4333061390..0c1defbb68 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -10,6 +10,10 @@ #include "core/loader/linker.h" #include "core/loader/loader.h" +namespace Kernel { +class Process; +} + namespace Loader { constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000; @@ -37,8 +41,8 @@ public: return IdentifyType(file); } - static std::optional LoadModule(const FileSys::VfsFile& file, VAddr load_base, - bool should_pass_arguments, + static std::optional LoadModule(Kernel::Process& process, const FileSys::VfsFile& file, + VAddr load_base, bool should_pass_arguments, std::optional pm = {}); ResultStatus Load(Kernel::Process& process) override;