summaryrefslogtreecommitdiff
path: root/src/core/loader/nro.cpp
diff options
context:
space:
mode:
authorZach Hilman <DarkLordZach@users.noreply.github.com>2018-07-06 10:51:32 -0400
committerbunnei <bunneidev@gmail.com>2018-07-06 10:51:32 -0400
commit77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2 (patch)
tree38ef6451732c5eecb0efdd198f3db4d33848453c /src/core/loader/nro.cpp
parent51bd76a5fda00b0ad9c6791193a15d83dfbadac3 (diff)
Virtual Filesystem (#597)
* Add VfsFile and VfsDirectory classes * Finish abstract Vfs classes * Implement RealVfsFile (computer fs backend) * Finish RealVfsFile and RealVfsDirectory * Finished OffsetVfsFile * More changes * Fix import paths * Major refactor * Remove double const * Use experimental/filesystem or filesystem depending on compiler * Port partition_filesystem * More changes * More Overhaul * FSP_SRV fixes * Fixes and testing * Try to get filesystem to compile * Filesystem on linux * Remove std::filesystem and document/test * Compile fixes * Missing include * Bug fixes * Fixes * Rename v_file and v_dir * clang-format fix * Rename NGLOG_* to LOG_* * Most review changes * Fix TODO * Guess 'main' to be Directory by filename
Diffstat (limited to 'src/core/loader/nro.cpp')
-rw-r--r--src/core/loader/nro.cpp32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 3853cfa1a..08b7aad7a 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -47,14 +47,12 @@ struct ModHeader {
};
static_assert(sizeof(ModHeader) == 0x1c, "ModHeader has incorrect size.");
-AppLoader_NRO::AppLoader_NRO(FileUtil::IOFile&& file, std::string filepath)
- : AppLoader(std::move(file)), filepath(std::move(filepath)) {}
+AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) {}
-FileType AppLoader_NRO::IdentifyType(FileUtil::IOFile& file, const std::string&) {
+FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) {
// Read NSO header
NroHeader nro_header{};
- file.Seek(0, SEEK_SET);
- if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) {
+ if (sizeof(NroHeader) != file->ReadObject(&nro_header)) {
return FileType::Error;
}
if (nro_header.magic == Common::MakeMagic('N', 'R', 'O', '0')) {
@@ -67,16 +65,10 @@ static constexpr u32 PageAlignSize(u32 size) {
return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK;
}
-bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
- FileUtil::IOFile file(path, "rb");
- if (!file.IsOpen()) {
- return {};
- }
-
+bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) {
// Read NSO header
NroHeader nro_header{};
- file.Seek(0, SEEK_SET);
- if (sizeof(NroHeader) != file.ReadBytes(&nro_header, sizeof(NroHeader))) {
+ if (sizeof(NroHeader) != file->ReadObject(&nro_header)) {
return {};
}
if (nro_header.magic != Common::MakeMagic('N', 'R', 'O', '0')) {
@@ -85,10 +77,9 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
// Build program image
Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create("");
- std::vector<u8> program_image;
- program_image.resize(PageAlignSize(nro_header.file_size));
- file.Seek(0, SEEK_SET);
- file.ReadBytes(program_image.data(), nro_header.file_size);
+ std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size));
+ if (program_image.size() != PageAlignSize(nro_header.file_size))
+ return {};
for (int i = 0; i < nro_header.segments.size(); ++i) {
codeset->segments[i].addr = nro_header.segments[i].offset;
@@ -111,7 +102,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
program_image.resize(static_cast<u32>(program_image.size()) + bss_size);
// Load codeset for current process
- codeset->name = path;
+ codeset->name = file->GetName();
codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image));
Core::CurrentProcess()->LoadModule(codeset, load_base);
@@ -122,14 +113,11 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
if (is_loaded) {
return ResultStatus::ErrorAlreadyLoaded;
}
- if (!file.IsOpen()) {
- return ResultStatus::Error;
- }
// Load NRO
static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR};
- if (!LoadNro(filepath, base_addr)) {
+ if (!LoadNro(file, base_addr)) {
return ResultStatus::ErrorInvalidFormat;
}