summaryrefslogtreecommitdiffstats
path: root/src/core/loader/elf.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-07-08 05:24:51 +0200
committerbunnei <bunneidev@gmail.com>2018-07-08 05:24:51 +0200
commit913896cbd99e414c325c9d47a987376ed6d9fffd (patch)
treeb660920a49f538f0ee00486c50a0d153d53c423d /src/core/loader/elf.cpp
parentMerge pull request #632 from FearlessTobi/add-discord-link (diff)
downloadyuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.gz
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.bz2
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.lz
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.xz
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.tar.zst
yuzu-913896cbd99e414c325c9d47a987376ed6d9fffd.zip
Diffstat (limited to 'src/core/loader/elf.cpp')
-rw-r--r--src/core/loader/elf.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 4bfd5f536..b69e5c6ef 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -365,17 +365,20 @@ SectionID ElfReader::GetSectionByName(const char* name, int firstSection) const
namespace Loader {
-AppLoader_ELF::AppLoader_ELF(FileSys::VirtualFile file) : AppLoader(std::move(file)) {}
+AppLoader_ELF::AppLoader_ELF(FileUtil::IOFile&& file, std::string filename)
+ : AppLoader(std::move(file)), filename(std::move(filename)) {}
-FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& file) {
+FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file, const std::string&) {
static constexpr u16 ELF_MACHINE_ARM{0x28};
u32 magic = 0;
- if (4 != file->ReadObject(&magic))
+ file.Seek(0, SEEK_SET);
+ if (1 != file.ReadArray<u32>(&magic, 1))
return FileType::Error;
u16 machine = 0;
- if (2 != file->ReadObject(&machine, 18))
+ file.Seek(18, SEEK_SET);
+ if (1 != file.ReadArray<u16>(&machine, 1))
return FileType::Error;
if (Common::MakeMagic('\x7f', 'E', 'L', 'F') == magic && ELF_MACHINE_ARM == machine)
@@ -388,13 +391,20 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
if (is_loaded)
return ResultStatus::ErrorAlreadyLoaded;
- std::vector<u8> buffer = file->ReadAllBytes();
- if (buffer.size() != file->GetSize())
+ if (!file.IsOpen())
+ return ResultStatus::Error;
+
+ // Reset read pointer in case this file has been read before.
+ file.Seek(0, SEEK_SET);
+
+ size_t size = file.GetSize();
+ std::unique_ptr<u8[]> buffer(new u8[size]);
+ if (file.ReadBytes(&buffer[0], size) != size)
return ResultStatus::Error;
ElfReader elf_reader(&buffer[0]);
SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
- codeset->name = file->GetName();
+ codeset->name = filename;
process->LoadModule(codeset, codeset->entrypoint);
process->svc_access_mask.set();