From 6ce4be859f1875814b70413ca56e3eb17e66ca37 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 17 Dec 2019 15:02:59 -0800 Subject: [PATCH] mesosphere: refactor Elf vs Elf64 distinction --- .../include/mesosphere/init/kern_init_elf.hpp | 20 +++++++++++++------ .../{arch/arm64 => }/init/kern_init_elf64.hpp | 10 +--------- .../kern_init_elf.cpp} | 18 ++++++++--------- 3 files changed, 24 insertions(+), 24 deletions(-) rename libmesosphere/include/mesosphere/{arch/arm64 => }/init/kern_init_elf64.hpp (93%) rename libmesosphere/source/{arch/arm64/init/kern_init_elf64.cpp => init/kern_init_elf.cpp} (78%) diff --git a/libmesosphere/include/mesosphere/init/kern_init_elf.hpp b/libmesosphere/include/mesosphere/init/kern_init_elf.hpp index 2ee1e001..1e226cca 100644 --- a/libmesosphere/include/mesosphere/init/kern_init_elf.hpp +++ b/libmesosphere/include/mesosphere/init/kern_init_elf.hpp @@ -17,17 +17,25 @@ #include #ifdef ATMOSPHERE_ARCH_ARM64 - - #include "../arch/arm64/init/kern_init_elf64.hpp" - + #include "kern_init_elf64.hpp" #else - #error "Unknown Architecture" - #endif namespace ams::kern::init::Elf { - /* TODO: Anything we want inside this namespace? */ + #ifdef ATMOSPHERE_ARCH_ARM64 + using namespace ams::kern::init::Elf::Elf64; + + enum RelocationType { + R_ARCHITECTURE_RELATIVE = 0x403, /* Real name R_AARCH64_RELATIVE */ + }; + #else + #error "Unknown Architecture" + #endif + + /* API to apply relocations or call init array. */ + void ApplyRelocations(uintptr_t base_address, const Dyn *dynamic); + void CallInitArrayFuncs(uintptr_t init_array_start, uintptr_t init_array_end); } \ No newline at end of file diff --git a/libmesosphere/include/mesosphere/arch/arm64/init/kern_init_elf64.hpp b/libmesosphere/include/mesosphere/init/kern_init_elf64.hpp similarity index 93% rename from libmesosphere/include/mesosphere/arch/arm64/init/kern_init_elf64.hpp rename to libmesosphere/include/mesosphere/init/kern_init_elf64.hpp index 33ef192f..84a0b254 100644 --- a/libmesosphere/include/mesosphere/arch/arm64/init/kern_init_elf64.hpp +++ b/libmesosphere/include/mesosphere/init/kern_init_elf64.hpp @@ -125,12 +125,4 @@ namespace ams::kern::init::Elf::Elf64 { DT_RELCOUNT = 0x6ffffffa }; - enum RelocationType { - R_AARCH64_RELATIVE = 0x403, - }; - - /* API to apply relocations or call init array. */ - void ApplyRelocations(uintptr_t base_address, const Dyn *dynamic); - void CallInitArrayFuncs(uintptr_t init_array_start, uintptr_t init_array_end); - -} \ No newline at end of file +} diff --git a/libmesosphere/source/arch/arm64/init/kern_init_elf64.cpp b/libmesosphere/source/init/kern_init_elf.cpp similarity index 78% rename from libmesosphere/source/arch/arm64/init/kern_init_elf64.cpp rename to libmesosphere/source/init/kern_init_elf.cpp index 6f846763..1eb6df6a 100644 --- a/libmesosphere/source/arch/arm64/init/kern_init_elf64.cpp +++ b/libmesosphere/source/init/kern_init_elf.cpp @@ -15,7 +15,7 @@ */ #include -namespace ams::kern::init::Elf::Elf64 { +namespace ams::kern::init::Elf { /* API to apply relocations or call init array. */ void ApplyRelocations(uintptr_t base_address, const Dyn *dynamic) { @@ -52,25 +52,25 @@ namespace ams::kern::init::Elf::Elf64 { /* Apply all Rel relocations */ for (size_t i = 0; i < rel_count; i++) { - const auto &rel = *reinterpret_cast(dyn_rel + rel_ent * i); + const auto &rel = *reinterpret_cast(dyn_rel + rel_ent * i); - /* Only allow R_AARCH64_RELATIVE relocations. */ - while (rel.GetType() != R_AARCH64_RELATIVE) { /* ... */ } + /* Only allow architecture-specific relocations. */ + while (rel.GetType() != R_ARCHITECTURE_RELATIVE) { /* ... */ } /* Apply the relocation. */ - Elf64::Addr *target_address = reinterpret_cast(base_address + rel.GetOffset()); + Elf::Addr *target_address = reinterpret_cast(base_address + rel.GetOffset()); *target_address += base_address; } /* Apply all Rela relocations. */ for (size_t i = 0; i < rela_count; i++) { - const auto &rela = *reinterpret_cast(dyn_rela + rela_ent * i); + const auto &rela = *reinterpret_cast(dyn_rela + rela_ent * i); - /* Only allow R_AARCH64_RELATIVE relocations. */ - while (rela.GetType() != R_AARCH64_RELATIVE) { /* ... */ } + /* Only allow architecture-specific relocations. */ + while (rela.GetType() != R_ARCHITECTURE_RELATIVE) { /* ... */ } /* Apply the relocation. */ - Elf64::Addr *target_address = reinterpret_cast(base_address + rela.GetOffset()); + Elf::Addr *target_address = reinterpret_cast(base_address + rela.GetOffset()); *target_address = base_address + rela.GetAddend(); } }