Merge pull request #1845 from lioncash/nro
loader/{nro, nso}: Remove dependency on the System class
This commit is contained in:
commit
465f486160
|
@ -7,7 +7,6 @@
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core.h"
|
|
||||||
#include "core/file_sys/content_archive.h"
|
#include "core/file_sys/content_archive.h"
|
||||||
#include "core/file_sys/control_metadata.h"
|
#include "core/file_sys/control_metadata.h"
|
||||||
#include "core/file_sys/patch_manager.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 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 auto tentative_next_load_addr =
|
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) {
|
if (!tentative_next_load_addr) {
|
||||||
return ResultStatus::ErrorLoadingNSO;
|
return ResultStatus::ErrorLoadingNSO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "common/file_util.h"
|
#include "common/file_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/control_metadata.h"
|
#include "core/file_sys/control_metadata.h"
|
||||||
#include "core/file_sys/romfs_factory.h"
|
#include "core/file_sys/romfs_factory.h"
|
||||||
#include "core/file_sys/vfs_offset.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;
|
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*static*/ bool AppLoader_NRO::LoadNro(const std::vector<u8>& data, const std::string& name,
|
static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
|
||||||
VAddr load_base) {
|
const std::string& name, VAddr load_base) {
|
||||||
|
|
||||||
if (data.size() < sizeof(NroHeader)) {
|
if (data.size() < sizeof(NroHeader)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -189,7 +187,7 @@ static constexpr u32 PageAlignSize(u32 size) {
|
||||||
|
|
||||||
// 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));
|
||||||
Core::CurrentProcess()->LoadModule(std::move(codeset), load_base);
|
process.LoadModule(std::move(codeset), load_base);
|
||||||
|
|
||||||
// Register module with GDBStub
|
// Register module with GDBStub
|
||||||
GDBStub::RegisterModule(name, load_base, load_base);
|
GDBStub::RegisterModule(name, load_base, load_base);
|
||||||
|
@ -197,8 +195,9 @@ static constexpr u32 PageAlignSize(u32 size) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) {
|
bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file,
|
||||||
return AppLoader_NRO::LoadNro(file.ReadAllBytes(), file.GetName(), load_base);
|
VAddr load_base) {
|
||||||
|
return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultStatus AppLoader_NRO::Load(Kernel::Process& process) {
|
ResultStatus AppLoader_NRO::Load(Kernel::Process& process) {
|
||||||
|
@ -209,7 +208,7 @@ ResultStatus AppLoader_NRO::Load(Kernel::Process& process) {
|
||||||
// Load NRO
|
// Load NRO
|
||||||
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
|
const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress();
|
||||||
|
|
||||||
if (!LoadNro(*file, base_address)) {
|
if (!LoadNro(process, *file, base_address)) {
|
||||||
return ResultStatus::ErrorLoadingNRO;
|
return ResultStatus::ErrorLoadingNRO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@ namespace FileSys {
|
||||||
class NACP;
|
class NACP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class Process;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Loader {
|
namespace Loader {
|
||||||
|
|
||||||
/// Loads an NRO file
|
/// Loads an NRO file
|
||||||
|
@ -41,10 +45,8 @@ public:
|
||||||
ResultStatus ReadTitle(std::string& title) override;
|
ResultStatus ReadTitle(std::string& title) override;
|
||||||
bool IsRomFSUpdatable() const override;
|
bool IsRomFSUpdatable() const override;
|
||||||
|
|
||||||
static bool LoadNro(const std::vector<u8>& data, const std::string& name, VAddr load_base);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool LoadNro(const FileSys::VfsFile& file, VAddr load_base);
|
bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base);
|
||||||
|
|
||||||
std::vector<u8> icon_data;
|
std::vector<u8> icon_data;
|
||||||
std::unique_ptr<FileSys::NACP> nacp;
|
std::unique_ptr<FileSys::NACP> nacp;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "common/file_util.h"
|
#include "common/file_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"
|
||||||
|
@ -93,7 +92,8 @@ static constexpr u32 PageAlignSize(u32 size) {
|
||||||
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
|
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<VAddr> AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAddr load_base,
|
std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process,
|
||||||
|
const FileSys::VfsFile& file, VAddr load_base,
|
||||||
bool should_pass_arguments,
|
bool should_pass_arguments,
|
||||||
std::optional<FileSys::PatchManager> pm) {
|
std::optional<FileSys::PatchManager> pm) {
|
||||||
if (file.GetSize() < sizeof(NsoHeader))
|
if (file.GetSize() < sizeof(NsoHeader))
|
||||||
|
@ -166,7 +166,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(const FileSys::VfsFile& file, VAd
|
||||||
|
|
||||||
// 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));
|
||||||
Core::CurrentProcess()->LoadModule(std::move(codeset), load_base);
|
process.LoadModule(std::move(codeset), load_base);
|
||||||
|
|
||||||
// Register module with GDBStub
|
// Register module with GDBStub
|
||||||
GDBStub::RegisterModule(file.GetName(), load_base, load_base);
|
GDBStub::RegisterModule(file.GetName(), load_base, load_base);
|
||||||
|
@ -181,7 +181,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(*file, base_address, true)) {
|
if (!LoadModule(process, *file, base_address, 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);
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
#include "core/loader/linker.h"
|
#include "core/loader/linker.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class Process;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Loader {
|
namespace Loader {
|
||||||
|
|
||||||
constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000;
|
constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000;
|
||||||
|
@ -37,8 +41,8 @@ public:
|
||||||
return IdentifyType(file);
|
return IdentifyType(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::optional<VAddr> LoadModule(const FileSys::VfsFile& file, VAddr load_base,
|
static std::optional<VAddr> LoadModule(Kernel::Process& process, const FileSys::VfsFile& file,
|
||||||
bool should_pass_arguments,
|
VAddr load_base, bool should_pass_arguments,
|
||||||
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 New Issue