diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.cpp | 13 | ||||
-rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.h | 13 | ||||
-rw-r--r-- | src/core/arm/exclusive_monitor.h | 14 | ||||
-rw-r--r-- | src/core/loader/linker.cpp | 8 | ||||
-rw-r--r-- | src/core/loader/linker.h | 3 | ||||
-rw-r--r-- | src/core/loader/loader.cpp | 2 | ||||
-rw-r--r-- | src/core/loader/nro.cpp | 37 | ||||
-rw-r--r-- | src/core/loader/nro.h | 10 |
8 files changed, 56 insertions, 44 deletions
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 83c09db2b..d23adb28a 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -257,7 +257,7 @@ void ARM_Dynarmic::PageTableChanged() { DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(size_t core_count) : monitor(core_count) {} DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; -void DynarmicExclusiveMonitor::SetExclusive(size_t core_index, u64 addr) { +void DynarmicExclusiveMonitor::SetExclusive(size_t core_index, VAddr addr) { // Size doesn't actually matter. monitor.Mark(core_index, addr, 16); } @@ -266,28 +266,27 @@ void DynarmicExclusiveMonitor::ClearExclusive() { monitor.Clear(); } -bool DynarmicExclusiveMonitor::ExclusiveWrite8(size_t core_index, u64 vaddr, u8 value) { +bool DynarmicExclusiveMonitor::ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) { return monitor.DoExclusiveOperation(core_index, vaddr, 1, [&] { Memory::Write8(vaddr, value); }); } -bool DynarmicExclusiveMonitor::ExclusiveWrite16(size_t core_index, u64 vaddr, u16 value) { +bool DynarmicExclusiveMonitor::ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) { return monitor.DoExclusiveOperation(core_index, vaddr, 2, [&] { Memory::Write16(vaddr, value); }); } -bool DynarmicExclusiveMonitor::ExclusiveWrite32(size_t core_index, u64 vaddr, u32 value) { +bool DynarmicExclusiveMonitor::ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) { return monitor.DoExclusiveOperation(core_index, vaddr, 4, [&] { Memory::Write32(vaddr, value); }); } -bool DynarmicExclusiveMonitor::ExclusiveWrite64(size_t core_index, u64 vaddr, u64 value) { +bool DynarmicExclusiveMonitor::ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) { return monitor.DoExclusiveOperation(core_index, vaddr, 8, [&] { Memory::Write64(vaddr, value); }); } -bool DynarmicExclusiveMonitor::ExclusiveWrite128(size_t core_index, u64 vaddr, - std::array<std::uint64_t, 2> value) { +bool DynarmicExclusiveMonitor::ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) { return monitor.DoExclusiveOperation(core_index, vaddr, 16, [&] { Memory::Write64(vaddr, value[0]); Memory::Write64(vaddr, value[1]); diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 0fa8b417c..350f61fd2 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -68,15 +68,14 @@ public: explicit DynarmicExclusiveMonitor(size_t core_count); ~DynarmicExclusiveMonitor(); - void SetExclusive(size_t core_index, u64 addr) override; + void SetExclusive(size_t core_index, VAddr addr) override; void ClearExclusive() override; - bool ExclusiveWrite8(size_t core_index, u64 vaddr, u8 value) override; - bool ExclusiveWrite16(size_t core_index, u64 vaddr, u16 value) override; - bool ExclusiveWrite32(size_t core_index, u64 vaddr, u32 value) override; - bool ExclusiveWrite64(size_t core_index, u64 vaddr, u64 value) override; - bool ExclusiveWrite128(size_t core_index, u64 vaddr, - std::array<std::uint64_t, 2> value) override; + bool ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) override; + bool ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) override; + bool ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) override; + bool ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) override; + bool ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) override; private: friend class ARM_Dynarmic; diff --git a/src/core/arm/exclusive_monitor.h b/src/core/arm/exclusive_monitor.h index acfcdb94c..13671ed7a 100644 --- a/src/core/arm/exclusive_monitor.h +++ b/src/core/arm/exclusive_monitor.h @@ -4,20 +4,18 @@ #pragma once -#include <array> #include "common/common_types.h" class ExclusiveMonitor { public: virtual ~ExclusiveMonitor(); - virtual void SetExclusive(size_t core_index, u64 addr) = 0; + virtual void SetExclusive(size_t core_index, VAddr addr) = 0; virtual void ClearExclusive() = 0; - virtual bool ExclusiveWrite8(size_t core_index, u64 vaddr, u8 value) = 0; - virtual bool ExclusiveWrite16(size_t core_index, u64 vaddr, u16 value) = 0; - virtual bool ExclusiveWrite32(size_t core_index, u64 vaddr, u32 value) = 0; - virtual bool ExclusiveWrite64(size_t core_index, u64 vaddr, u64 value) = 0; - virtual bool ExclusiveWrite128(size_t core_index, u64 vaddr, - std::array<std::uint64_t, 2> value) = 0; + virtual bool ExclusiveWrite8(size_t core_index, VAddr vaddr, u8 value) = 0; + virtual bool ExclusiveWrite16(size_t core_index, VAddr vaddr, u16 value) = 0; + virtual bool ExclusiveWrite32(size_t core_index, VAddr vaddr, u32 value) = 0; + virtual bool ExclusiveWrite64(size_t core_index, VAddr vaddr, u64 value) = 0; + virtual bool ExclusiveWrite128(size_t core_index, VAddr vaddr, u128 value) = 0; }; diff --git a/src/core/loader/linker.cpp b/src/core/loader/linker.cpp index 769516b6f..57ca8c3ee 100644 --- a/src/core/loader/linker.cpp +++ b/src/core/loader/linker.cpp @@ -49,8 +49,7 @@ struct Elf64_Sym { static_assert(sizeof(Elf64_Sym) == 0x18, "Elf64_Sym has incorrect size."); void Linker::WriteRelocations(std::vector<u8>& program_image, const std::vector<Symbol>& symbols, - u64 relocation_offset, u64 size, bool is_jump_relocation, - VAddr load_base) { + u64 relocation_offset, u64 size, VAddr load_base) { for (u64 i = 0; i < size; i += sizeof(Elf64_Rela)) { Elf64_Rela rela; std::memcpy(&rela, &program_image[relocation_offset + i], sizeof(Elf64_Rela)); @@ -124,12 +123,11 @@ void Linker::Relocate(std::vector<u8>& program_image, u32 dynamic_section_offset } if (dynamic.find(DT_RELA) != dynamic.end()) { - WriteRelocations(program_image, symbols, dynamic[DT_RELA], dynamic[DT_RELASZ], false, - load_base); + WriteRelocations(program_image, symbols, dynamic[DT_RELA], dynamic[DT_RELASZ], load_base); } if (dynamic.find(DT_JMPREL) != dynamic.end()) { - WriteRelocations(program_image, symbols, dynamic[DT_JMPREL], dynamic[DT_PLTRELSZ], true, + WriteRelocations(program_image, symbols, dynamic[DT_JMPREL], dynamic[DT_PLTRELSZ], load_base); } } diff --git a/src/core/loader/linker.h b/src/core/loader/linker.h index c09d382c1..107625837 100644 --- a/src/core/loader/linker.h +++ b/src/core/loader/linker.h @@ -24,8 +24,7 @@ protected: }; void WriteRelocations(std::vector<u8>& program_image, const std::vector<Symbol>& symbols, - u64 relocation_offset, u64 size, bool is_jump_relocation, - VAddr load_base); + u64 relocation_offset, u64 size, VAddr load_base); void Relocate(std::vector<u8>& program_image, u32 dynamic_section_offset, VAddr load_base); void ResolveImports(); diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 4cbd9e285..cbc4177c6 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -42,7 +42,7 @@ FileType IdentifyFile(FileSys::VirtualFile file) { } FileType IdentifyFile(const std::string& file_name) { - return IdentifyFile(FileSys::VirtualFile(std::make_shared<FileSys::RealVfsFile>(file_name))); + return IdentifyFile(std::make_shared<FileSys::RealVfsFile>(file_name)); } FileType GuessFromFilename(const std::string& name) { diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 44158655c..7d3ec2a76 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -6,6 +6,7 @@ #include <vector> #include "common/common_funcs.h" +#include "common/common_types.h" #include "common/file_util.h" #include "common/logging/log.h" #include "common/swap.h" @@ -68,22 +69,27 @@ static_assert(sizeof(AssetHeader) == 0x38, "AssetHeader has incorrect size."); AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { NroHeader nro_header{}; - if (file->ReadObject(&nro_header) != sizeof(NroHeader)) + if (file->ReadObject(&nro_header) != sizeof(NroHeader)) { return; + } if (file->GetSize() >= nro_header.file_size + sizeof(AssetHeader)) { - u64 offset = nro_header.file_size; + const u64 offset = nro_header.file_size; AssetHeader asset_header{}; - if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) + if (file->ReadObject(&asset_header, offset) != sizeof(AssetHeader)) { return; + } - if (asset_header.format_version != 0) + if (asset_header.format_version != 0) { LOG_WARNING(Loader, "NRO Asset Header has format {}, currently supported format is 0. If " "strange glitches occur with metadata, check NRO assets.", asset_header.format_version); - if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) + } + + if (asset_header.magic != Common::MakeMagic('A', 'S', 'E', 'T')) { return; + } if (asset_header.nacp.size > 0) { nacp = std::make_unique<FileSys::NACP>(std::make_shared<FileSys::OffsetVfsFile>( @@ -101,6 +107,8 @@ AppLoader_NRO::AppLoader_NRO(FileSys::VirtualFile file) : AppLoader(file) { } } +AppLoader_NRO::~AppLoader_NRO() = default; + FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { // Read NSO header NroHeader nro_header{}; @@ -130,8 +138,9 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { // Build program image Kernel::SharedPtr<Kernel::CodeSet> codeset = Kernel::CodeSet::Create(""); std::vector<u8> program_image = file->ReadBytes(PageAlignSize(nro_header.file_size)); - if (program_image.size() != PageAlignSize(nro_header.file_size)) + if (program_image.size() != PageAlignSize(nro_header.file_size)) { return {}; + } for (std::size_t i = 0; i < nro_header.segments.size(); ++i) { codeset->segments[i].addr = nro_header.segments[i].offset; @@ -187,29 +196,37 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { } ResultStatus AppLoader_NRO::ReadIcon(std::vector<u8>& buffer) { - if (icon_data.empty()) + if (icon_data.empty()) { return ResultStatus::ErrorNotUsed; + } + buffer = icon_data; return ResultStatus::Success; } ResultStatus AppLoader_NRO::ReadProgramId(u64& out_program_id) { - if (nacp == nullptr) + if (nacp == nullptr) { return ResultStatus::ErrorNotUsed; + } + out_program_id = nacp->GetTitleId(); return ResultStatus::Success; } ResultStatus AppLoader_NRO::ReadRomFS(FileSys::VirtualFile& dir) { - if (romfs == nullptr) + if (romfs == nullptr) { return ResultStatus::ErrorNotUsed; + } + dir = romfs; return ResultStatus::Success; } ResultStatus AppLoader_NRO::ReadTitle(std::string& title) { - if (nacp == nullptr) + if (nacp == nullptr) { return ResultStatus::ErrorNotUsed; + } + title = nacp->GetApplicationName(); return ResultStatus::Success; } diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 5f3fc40d2..04a0f497e 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -6,19 +6,21 @@ #include <string> #include "common/common_types.h" -#include "core/file_sys/control_metadata.h" #include "core/hle/kernel/kernel.h" #include "core/loader/linker.h" #include "core/loader/loader.h" -namespace Loader { +namespace FileSys { +class NACP; +} -struct AssetHeader; +namespace Loader { /// Loads an NRO file class AppLoader_NRO final : public AppLoader, Linker { public: - AppLoader_NRO(FileSys::VirtualFile file); + explicit AppLoader_NRO(FileSys::VirtualFile file); + ~AppLoader_NRO() override; /** * Returns the type of the file |