mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-08-09 08:59:32 +02:00
mesosphere: refactor Elf vs Elf64 distinction
This commit is contained in:
parent
92671af569
commit
6ce4be859f
@ -17,17 +17,25 @@
|
||||
#include <vapours.hpp>
|
||||
|
||||
#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);
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
#include <mesosphere.hpp>
|
||||
|
||||
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<const Elf64::Rel *>(dyn_rel + rel_ent * i);
|
||||
const auto &rel = *reinterpret_cast<const Elf::Rel *>(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<Elf64::Addr *>(base_address + rel.GetOffset());
|
||||
Elf::Addr *target_address = reinterpret_cast<Elf::Addr *>(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<const Elf64::Rela *>(dyn_rela + rela_ent * i);
|
||||
const auto &rela = *reinterpret_cast<const Elf::Rela *>(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<Elf64::Addr *>(base_address + rela.GetOffset());
|
||||
Elf::Addr *target_address = reinterpret_cast<Elf::Addr *>(base_address + rela.GetOffset());
|
||||
*target_address = base_address + rela.GetAddend();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user