nro: Make LoadNro method accessible outside of apploader code.

This commit is contained in:
bunnei 2018-10-23 18:35:20 -04:00
parent a141b46b5c
commit ef7b2237d9
2 changed files with 18 additions and 6 deletions

View file

@ -127,18 +127,23 @@ static constexpr u32 PageAlignSize(u32 size) {
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
} }
bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) { /*static*/ bool AppLoader_NRO::LoadNro(const std::vector<u8>& data, const std::string& name,
// Read NSO header VAddr load_base) {
NroHeader nro_header{};
if (sizeof(NroHeader) != file.ReadObject(&nro_header)) { if (data.size() < sizeof(NroHeader)) {
return {}; return {};
} }
// Read NSO header
NroHeader nro_header{};
std::memcpy(&nro_header, data.data(), sizeof(NroHeader));
if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) { if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) {
return {}; return {};
} }
// Build program image // Build program image
std::vector<u8> program_image = file.ReadBytes(PageAlignSize(nro_header.file_size)); std::vector<u8> program_image(PageAlignSize(nro_header.file_size));
std::memcpy(program_image.data(), data.data(), program_image.size());
if (program_image.size() != PageAlignSize(nro_header.file_size)) { if (program_image.size() != PageAlignSize(nro_header.file_size)) {
return {}; return {};
} }
@ -182,11 +187,15 @@ bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) {
Core::CurrentProcess()->LoadModule(std::move(codeset), load_base); Core::CurrentProcess()->LoadModule(std::move(codeset), load_base);
// Register module with GDBStub // Register module with GDBStub
GDBStub::RegisterModule(file.GetName(), load_base, load_base); GDBStub::RegisterModule(name, load_base, load_base);
return true; return true;
} }
bool AppLoader_NRO::LoadNro(const FileSys::VfsFile& file, VAddr load_base) {
return AppLoader_NRO::LoadNro(file.ReadAllBytes(), file.GetName(), load_base);
}
ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { ResultStatus AppLoader_NRO::Load(Kernel::Process& process) {
if (is_loaded) { if (is_loaded) {
return ResultStatus::ErrorAlreadyLoaded; return ResultStatus::ErrorAlreadyLoaded;

View file

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/loader/linker.h" #include "core/loader/linker.h"
#include "core/loader/loader.h" #include "core/loader/loader.h"
@ -40,6 +41,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(const FileSys::VfsFile& file, VAddr load_base);