diff options
| author | 2022-06-05 16:52:06 -0700 | |
|---|---|---|
| committer | 2022-06-05 16:52:06 -0700 | |
| commit | c33c9c76bfdc5802180d8282327d27f25e378fa0 (patch) | |
| tree | e1eb42f4ff259331602cab85d10a324c1343d839 /src/core | |
| parent | Merge pull request #8419 from liamwhite/library-list (diff) | |
| parent | common: consolidate ELF structure definitions (diff) | |
| download | yuzu-c33c9c76bfdc5802180d8282327d27f25e378fa0.tar.gz yuzu-c33c9c76bfdc5802180d8282327d27f25e378fa0.tar.xz yuzu-c33c9c76bfdc5802180d8282327d27f25e378fa0.zip | |
Merge pull request #8426 from liamwhite/elf
common: consolidate ELF structure definitions
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/arm/symbols.cpp | 85 | ||||
| -rw-r--r-- | src/core/hle/service/jit/jit_context.cpp | 32 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 183 |
3 files changed, 37 insertions, 263 deletions
diff --git a/src/core/arm/symbols.cpp b/src/core/arm/symbols.cpp index 4aa1a1ee1..0259c7ea2 100644 --- a/src/core/arm/symbols.cpp +++ b/src/core/arm/symbols.cpp | |||
| @@ -3,73 +3,14 @@ | |||
| 3 | 3 | ||
| 4 | #include "common/bit_field.h" | 4 | #include "common/bit_field.h" |
| 5 | #include "common/common_funcs.h" | 5 | #include "common/common_funcs.h" |
| 6 | #include "common/elf.h" | ||
| 6 | #include "core/arm/symbols.h" | 7 | #include "core/arm/symbols.h" |
| 7 | #include "core/core.h" | 8 | #include "core/core.h" |
| 8 | #include "core/memory.h" | 9 | #include "core/memory.h" |
| 9 | 10 | ||
| 10 | namespace Core { | 11 | using namespace Common::ELF; |
| 11 | namespace { | ||
| 12 | |||
| 13 | constexpr u64 ELF_DYNAMIC_TAG_NULL = 0; | ||
| 14 | constexpr u64 ELF_DYNAMIC_TAG_STRTAB = 5; | ||
| 15 | constexpr u64 ELF_DYNAMIC_TAG_SYMTAB = 6; | ||
| 16 | constexpr u64 ELF_DYNAMIC_TAG_SYMENT = 11; | ||
| 17 | |||
| 18 | enum class ELFSymbolType : u8 { | ||
| 19 | None = 0, | ||
| 20 | Object = 1, | ||
| 21 | Function = 2, | ||
| 22 | Section = 3, | ||
| 23 | File = 4, | ||
| 24 | Common = 5, | ||
| 25 | TLS = 6, | ||
| 26 | }; | ||
| 27 | |||
| 28 | enum class ELFSymbolBinding : u8 { | ||
| 29 | Local = 0, | ||
| 30 | Global = 1, | ||
| 31 | Weak = 2, | ||
| 32 | }; | ||
| 33 | |||
| 34 | enum class ELFSymbolVisibility : u8 { | ||
| 35 | Default = 0, | ||
| 36 | Internal = 1, | ||
| 37 | Hidden = 2, | ||
| 38 | Protected = 3, | ||
| 39 | }; | ||
| 40 | |||
| 41 | struct ELF64Symbol { | ||
| 42 | u32 name_index; | ||
| 43 | union { | ||
| 44 | u8 info; | ||
| 45 | |||
| 46 | BitField<0, 4, ELFSymbolType> type; | ||
| 47 | BitField<4, 4, ELFSymbolBinding> binding; | ||
| 48 | }; | ||
| 49 | ELFSymbolVisibility visibility; | ||
| 50 | u16 sh_index; | ||
| 51 | u64 value; | ||
| 52 | u64 size; | ||
| 53 | }; | ||
| 54 | static_assert(sizeof(ELF64Symbol) == 0x18, "ELF64Symbol has incorrect size."); | ||
| 55 | |||
| 56 | struct ELF32Symbol { | ||
| 57 | u32 name_index; | ||
| 58 | u32 value; | ||
| 59 | u32 size; | ||
| 60 | union { | ||
| 61 | u8 info; | ||
| 62 | |||
| 63 | BitField<0, 4, ELFSymbolType> type; | ||
| 64 | BitField<4, 4, ELFSymbolBinding> binding; | ||
| 65 | }; | ||
| 66 | ELFSymbolVisibility visibility; | ||
| 67 | u16 sh_index; | ||
| 68 | }; | ||
| 69 | static_assert(sizeof(ELF32Symbol) == 0x10, "ELF32Symbol has incorrect size."); | ||
| 70 | |||
| 71 | } // Anonymous namespace | ||
| 72 | 12 | ||
| 13 | namespace Core { | ||
| 73 | namespace Symbols { | 14 | namespace Symbols { |
| 74 | 15 | ||
| 75 | template <typename Word, typename ELFSymbol, typename ByteReader> | 16 | template <typename Word, typename ELFSymbol, typename ByteReader> |
| @@ -110,15 +51,15 @@ static Symbols GetSymbols(ByteReader ReadBytes) { | |||
| 110 | const Word value = ReadWord(dynamic_index + sizeof(Word)); | 51 | const Word value = ReadWord(dynamic_index + sizeof(Word)); |
| 111 | dynamic_index += 2 * sizeof(Word); | 52 | dynamic_index += 2 * sizeof(Word); |
| 112 | 53 | ||
| 113 | if (tag == ELF_DYNAMIC_TAG_NULL) { | 54 | if (tag == ElfDtNull) { |
| 114 | break; | 55 | break; |
| 115 | } | 56 | } |
| 116 | 57 | ||
| 117 | if (tag == ELF_DYNAMIC_TAG_STRTAB) { | 58 | if (tag == ElfDtStrtab) { |
| 118 | string_table_offset = value; | 59 | string_table_offset = value; |
| 119 | } else if (tag == ELF_DYNAMIC_TAG_SYMTAB) { | 60 | } else if (tag == ElfDtSymtab) { |
| 120 | symbol_table_offset = value; | 61 | symbol_table_offset = value; |
| 121 | } else if (tag == ELF_DYNAMIC_TAG_SYMENT) { | 62 | } else if (tag == ElfDtSyment) { |
| 122 | symbol_entry_size = value; | 63 | symbol_entry_size = value; |
| 123 | } | 64 | } |
| 124 | } | 65 | } |
| @@ -134,14 +75,14 @@ static Symbols GetSymbols(ByteReader ReadBytes) { | |||
| 134 | ELFSymbol symbol{}; | 75 | ELFSymbol symbol{}; |
| 135 | ReadBytes(&symbol, symbol_index, sizeof(ELFSymbol)); | 76 | ReadBytes(&symbol, symbol_index, sizeof(ELFSymbol)); |
| 136 | 77 | ||
| 137 | VAddr string_offset = string_table_offset + symbol.name_index; | 78 | VAddr string_offset = string_table_offset + symbol.st_name; |
| 138 | std::string name; | 79 | std::string name; |
| 139 | for (u8 c = Read8(string_offset); c != 0; c = Read8(++string_offset)) { | 80 | for (u8 c = Read8(string_offset); c != 0; c = Read8(++string_offset)) { |
| 140 | name += static_cast<char>(c); | 81 | name += static_cast<char>(c); |
| 141 | } | 82 | } |
| 142 | 83 | ||
| 143 | symbol_index += symbol_entry_size; | 84 | symbol_index += symbol_entry_size; |
| 144 | out[name] = std::make_pair(symbol.value, symbol.size); | 85 | out[name] = std::make_pair(symbol.st_value, symbol.st_size); |
| 145 | } | 86 | } |
| 146 | 87 | ||
| 147 | return out; | 88 | return out; |
| @@ -152,9 +93,9 @@ Symbols GetSymbols(VAddr base, Core::Memory::Memory& memory, bool is_64) { | |||
| 152 | [&](void* ptr, size_t offset, size_t size) { memory.ReadBlock(base + offset, ptr, size); }}; | 93 | [&](void* ptr, size_t offset, size_t size) { memory.ReadBlock(base + offset, ptr, size); }}; |
| 153 | 94 | ||
| 154 | if (is_64) { | 95 | if (is_64) { |
| 155 | return GetSymbols<u64, ELF64Symbol>(ReadBytes); | 96 | return GetSymbols<u64, Elf64_Sym>(ReadBytes); |
| 156 | } else { | 97 | } else { |
| 157 | return GetSymbols<u32, ELF32Symbol>(ReadBytes); | 98 | return GetSymbols<u32, Elf32_Sym>(ReadBytes); |
| 158 | } | 99 | } |
| 159 | } | 100 | } |
| 160 | 101 | ||
| @@ -164,9 +105,9 @@ Symbols GetSymbols(std::span<const u8> data, bool is_64) { | |||
| 164 | }}; | 105 | }}; |
| 165 | 106 | ||
| 166 | if (is_64) { | 107 | if (is_64) { |
| 167 | return GetSymbols<u64, ELF64Symbol>(ReadBytes); | 108 | return GetSymbols<u64, Elf64_Sym>(ReadBytes); |
| 168 | } else { | 109 | } else { |
| 169 | return GetSymbols<u32, ELF32Symbol>(ReadBytes); | 110 | return GetSymbols<u32, Elf32_Sym>(ReadBytes); |
| 170 | } | 111 | } |
| 171 | } | 112 | } |
| 172 | 113 | ||
diff --git a/src/core/hle/service/jit/jit_context.cpp b/src/core/hle/service/jit/jit_context.cpp index 19bd85b6c..4ed3f02e2 100644 --- a/src/core/hle/service/jit/jit_context.cpp +++ b/src/core/hle/service/jit/jit_context.cpp | |||
| @@ -11,10 +11,13 @@ | |||
| 11 | #include "common/alignment.h" | 11 | #include "common/alignment.h" |
| 12 | #include "common/common_funcs.h" | 12 | #include "common/common_funcs.h" |
| 13 | #include "common/div_ceil.h" | 13 | #include "common/div_ceil.h" |
| 14 | #include "common/elf.h" | ||
| 14 | #include "common/logging/log.h" | 15 | #include "common/logging/log.h" |
| 15 | #include "core/hle/service/jit/jit_context.h" | 16 | #include "core/hle/service/jit/jit_context.h" |
| 16 | #include "core/memory.h" | 17 | #include "core/memory.h" |
| 17 | 18 | ||
| 19 | using namespace Common::ELF; | ||
| 20 | |||
| 18 | namespace Service::JIT { | 21 | namespace Service::JIT { |
| 19 | 22 | ||
| 20 | constexpr std::array<u8, 8> SVC0_ARM64 = { | 23 | constexpr std::array<u8, 8> SVC0_ARM64 = { |
| @@ -26,25 +29,6 @@ constexpr std::array HELPER_FUNCTIONS{ | |||
| 26 | "_stop", "_resolve", "_panic", "memcpy", "memmove", "memset", | 29 | "_stop", "_resolve", "_panic", "memcpy", "memmove", "memset", |
| 27 | }; | 30 | }; |
| 28 | 31 | ||
| 29 | struct Elf64_Dyn { | ||
| 30 | u64 d_tag; | ||
| 31 | u64 d_un; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct Elf64_Rela { | ||
| 35 | u64 r_offset; | ||
| 36 | u64 r_info; | ||
| 37 | s64 r_addend; | ||
| 38 | }; | ||
| 39 | |||
| 40 | static constexpr u32 Elf64_RelaType(const Elf64_Rela* rela) { | ||
| 41 | return static_cast<u32>(rela->r_info); | ||
| 42 | } | ||
| 43 | |||
| 44 | constexpr int DT_RELA = 7; /* Address of Rela relocs */ | ||
| 45 | constexpr int DT_RELASZ = 8; /* Total size of Rela relocs */ | ||
| 46 | constexpr int R_AARCH64_RELATIVE = 1027; /* Adjust by program base. */ | ||
| 47 | |||
| 48 | constexpr size_t STACK_ALIGN = 16; | 32 | constexpr size_t STACK_ALIGN = 16; |
| 49 | 33 | ||
| 50 | class JITContextImpl; | 34 | class JITContextImpl; |
| @@ -206,17 +190,17 @@ public: | |||
| 206 | if (!dyn.d_tag) { | 190 | if (!dyn.d_tag) { |
| 207 | break; | 191 | break; |
| 208 | } | 192 | } |
| 209 | if (dyn.d_tag == DT_RELA) { | 193 | if (dyn.d_tag == ElfDtRela) { |
| 210 | rela_dyn = dyn.d_un; | 194 | rela_dyn = dyn.d_un.d_ptr; |
| 211 | } | 195 | } |
| 212 | if (dyn.d_tag == DT_RELASZ) { | 196 | if (dyn.d_tag == ElfDtRelasz) { |
| 213 | num_rela = dyn.d_un / sizeof(Elf64_Rela); | 197 | num_rela = dyn.d_un.d_val / sizeof(Elf64_Rela); |
| 214 | } | 198 | } |
| 215 | } | 199 | } |
| 216 | 200 | ||
| 217 | for (size_t i = 0; i < num_rela; i++) { | 201 | for (size_t i = 0; i < num_rela; i++) { |
| 218 | const auto rela{callbacks->ReadMemory<Elf64_Rela>(rela_dyn + i * sizeof(Elf64_Rela))}; | 202 | const auto rela{callbacks->ReadMemory<Elf64_Rela>(rela_dyn + i * sizeof(Elf64_Rela))}; |
| 219 | if (Elf64_RelaType(&rela) != R_AARCH64_RELATIVE) { | 203 | if (Elf64RelType(rela.r_info) != ElfAArch64Relative) { |
| 220 | continue; | 204 | continue; |
| 221 | } | 205 | } |
| 222 | const VAddr contents{callbacks->MemoryRead64(rela.r_offset)}; | 206 | const VAddr contents{callbacks->MemoryRead64(rela.r_offset)}; |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index cf5933699..dfb10c34f 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/elf.h" | ||
| 9 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 10 | #include "core/hle/kernel/code_set.h" | 11 | #include "core/hle/kernel/code_set.h" |
| 11 | #include "core/hle/kernel/k_page_table.h" | 12 | #include "core/hle/kernel/k_page_table.h" |
| @@ -13,159 +14,7 @@ | |||
| 13 | #include "core/loader/elf.h" | 14 | #include "core/loader/elf.h" |
| 14 | #include "core/memory.h" | 15 | #include "core/memory.h" |
| 15 | 16 | ||
| 16 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | using namespace Common::ELF; |
| 17 | // ELF Header Constants | ||
| 18 | |||
| 19 | // File type | ||
| 20 | enum ElfType { | ||
| 21 | ET_NONE = 0, | ||
| 22 | ET_REL = 1, | ||
| 23 | ET_EXEC = 2, | ||
| 24 | ET_DYN = 3, | ||
| 25 | ET_CORE = 4, | ||
| 26 | ET_LOPROC = 0xFF00, | ||
| 27 | ET_HIPROC = 0xFFFF, | ||
| 28 | }; | ||
| 29 | |||
| 30 | // Machine/Architecture | ||
| 31 | enum ElfMachine { | ||
| 32 | EM_NONE = 0, | ||
| 33 | EM_M32 = 1, | ||
| 34 | EM_SPARC = 2, | ||
| 35 | EM_386 = 3, | ||
| 36 | EM_68K = 4, | ||
| 37 | EM_88K = 5, | ||
| 38 | EM_860 = 7, | ||
| 39 | EM_MIPS = 8 | ||
| 40 | }; | ||
| 41 | |||
| 42 | // File version | ||
| 43 | #define EV_NONE 0 | ||
| 44 | #define EV_CURRENT 1 | ||
| 45 | |||
| 46 | // Identification index | ||
| 47 | #define EI_MAG0 0 | ||
| 48 | #define EI_MAG1 1 | ||
| 49 | #define EI_MAG2 2 | ||
| 50 | #define EI_MAG3 3 | ||
| 51 | #define EI_CLASS 4 | ||
| 52 | #define EI_DATA 5 | ||
| 53 | #define EI_VERSION 6 | ||
| 54 | #define EI_PAD 7 | ||
| 55 | #define EI_NIDENT 16 | ||
| 56 | |||
| 57 | // Sections constants | ||
| 58 | |||
| 59 | // Section types | ||
| 60 | #define SHT_NULL 0 | ||
| 61 | #define SHT_PROGBITS 1 | ||
| 62 | #define SHT_SYMTAB 2 | ||
| 63 | #define SHT_STRTAB 3 | ||
| 64 | #define SHT_RELA 4 | ||
| 65 | #define SHT_HASH 5 | ||
| 66 | #define SHT_DYNAMIC 6 | ||
| 67 | #define SHT_NOTE 7 | ||
| 68 | #define SHT_NOBITS 8 | ||
| 69 | #define SHT_REL 9 | ||
| 70 | #define SHT_SHLIB 10 | ||
| 71 | #define SHT_DYNSYM 11 | ||
| 72 | #define SHT_LOPROC 0x70000000 | ||
| 73 | #define SHT_HIPROC 0x7FFFFFFF | ||
| 74 | #define SHT_LOUSER 0x80000000 | ||
| 75 | #define SHT_HIUSER 0xFFFFFFFF | ||
| 76 | |||
| 77 | // Section flags | ||
| 78 | enum ElfSectionFlags { | ||
| 79 | SHF_WRITE = 0x1, | ||
| 80 | SHF_ALLOC = 0x2, | ||
| 81 | SHF_EXECINSTR = 0x4, | ||
| 82 | SHF_MASKPROC = 0xF0000000, | ||
| 83 | }; | ||
| 84 | |||
| 85 | // Segment types | ||
| 86 | #define PT_NULL 0 | ||
| 87 | #define PT_LOAD 1 | ||
| 88 | #define PT_DYNAMIC 2 | ||
| 89 | #define PT_INTERP 3 | ||
| 90 | #define PT_NOTE 4 | ||
| 91 | #define PT_SHLIB 5 | ||
| 92 | #define PT_PHDR 6 | ||
| 93 | #define PT_LOPROC 0x70000000 | ||
| 94 | #define PT_HIPROC 0x7FFFFFFF | ||
| 95 | |||
| 96 | // Segment flags | ||
| 97 | #define PF_X 0x1 | ||
| 98 | #define PF_W 0x2 | ||
| 99 | #define PF_R 0x4 | ||
| 100 | #define PF_MASKPROC 0xF0000000 | ||
| 101 | |||
| 102 | typedef unsigned int Elf32_Addr; | ||
| 103 | typedef unsigned short Elf32_Half; | ||
| 104 | typedef unsigned int Elf32_Off; | ||
| 105 | typedef signed int Elf32_Sword; | ||
| 106 | typedef unsigned int Elf32_Word; | ||
| 107 | |||
| 108 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 109 | // ELF file header | ||
| 110 | |||
| 111 | struct Elf32_Ehdr { | ||
| 112 | unsigned char e_ident[EI_NIDENT]; | ||
| 113 | Elf32_Half e_type; | ||
| 114 | Elf32_Half e_machine; | ||
| 115 | Elf32_Word e_version; | ||
| 116 | Elf32_Addr e_entry; | ||
| 117 | Elf32_Off e_phoff; | ||
| 118 | Elf32_Off e_shoff; | ||
| 119 | Elf32_Word e_flags; | ||
| 120 | Elf32_Half e_ehsize; | ||
| 121 | Elf32_Half e_phentsize; | ||
| 122 | Elf32_Half e_phnum; | ||
| 123 | Elf32_Half e_shentsize; | ||
| 124 | Elf32_Half e_shnum; | ||
| 125 | Elf32_Half e_shstrndx; | ||
| 126 | }; | ||
| 127 | |||
| 128 | // Section header | ||
| 129 | struct Elf32_Shdr { | ||
| 130 | Elf32_Word sh_name; | ||
| 131 | Elf32_Word sh_type; | ||
| 132 | Elf32_Word sh_flags; | ||
| 133 | Elf32_Addr sh_addr; | ||
| 134 | Elf32_Off sh_offset; | ||
| 135 | Elf32_Word sh_size; | ||
| 136 | Elf32_Word sh_link; | ||
| 137 | Elf32_Word sh_info; | ||
| 138 | Elf32_Word sh_addralign; | ||
| 139 | Elf32_Word sh_entsize; | ||
| 140 | }; | ||
| 141 | |||
| 142 | // Segment header | ||
| 143 | struct Elf32_Phdr { | ||
| 144 | Elf32_Word p_type; | ||
| 145 | Elf32_Off p_offset; | ||
| 146 | Elf32_Addr p_vaddr; | ||
| 147 | Elf32_Addr p_paddr; | ||
| 148 | Elf32_Word p_filesz; | ||
| 149 | Elf32_Word p_memsz; | ||
| 150 | Elf32_Word p_flags; | ||
| 151 | Elf32_Word p_align; | ||
| 152 | }; | ||
| 153 | |||
| 154 | // Symbol table entry | ||
| 155 | struct Elf32_Sym { | ||
| 156 | Elf32_Word st_name; | ||
| 157 | Elf32_Addr st_value; | ||
| 158 | Elf32_Word st_size; | ||
| 159 | unsigned char st_info; | ||
| 160 | unsigned char st_other; | ||
| 161 | Elf32_Half st_shndx; | ||
| 162 | }; | ||
| 163 | |||
| 164 | // Relocation entries | ||
| 165 | struct Elf32_Rel { | ||
| 166 | Elf32_Addr r_offset; | ||
| 167 | Elf32_Word r_info; | ||
| 168 | }; | ||
| 169 | 18 | ||
| 170 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 19 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 171 | // ElfReader class | 20 | // ElfReader class |
| @@ -193,11 +42,11 @@ public: | |||
| 193 | } | 42 | } |
| 194 | 43 | ||
| 195 | // Quick accessors | 44 | // Quick accessors |
| 196 | ElfType GetType() const { | 45 | u16 GetType() const { |
| 197 | return (ElfType)(header->e_type); | 46 | return header->e_type; |
| 198 | } | 47 | } |
| 199 | ElfMachine GetMachine() const { | 48 | u16 GetMachine() const { |
| 200 | return (ElfMachine)(header->e_machine); | 49 | return header->e_machine; |
| 201 | } | 50 | } |
| 202 | VAddr GetEntryPoint() const { | 51 | VAddr GetEntryPoint() const { |
| 203 | return entryPoint; | 52 | return entryPoint; |
| @@ -220,13 +69,13 @@ public: | |||
| 220 | const u8* GetSectionDataPtr(int section) const { | 69 | const u8* GetSectionDataPtr(int section) const { |
| 221 | if (section < 0 || section >= header->e_shnum) | 70 | if (section < 0 || section >= header->e_shnum) |
| 222 | return nullptr; | 71 | return nullptr; |
| 223 | if (sections[section].sh_type != SHT_NOBITS) | 72 | if (sections[section].sh_type != ElfShtNobits) |
| 224 | return GetPtr(sections[section].sh_offset); | 73 | return GetPtr(sections[section].sh_offset); |
| 225 | else | 74 | else |
| 226 | return nullptr; | 75 | return nullptr; |
| 227 | } | 76 | } |
| 228 | bool IsCodeSection(int section) const { | 77 | bool IsCodeSection(int section) const { |
| 229 | return sections[section].sh_type == SHT_PROGBITS; | 78 | return sections[section].sh_type == ElfShtProgBits; |
| 230 | } | 79 | } |
| 231 | const u8* GetSegmentPtr(int segment) { | 80 | const u8* GetSegmentPtr(int segment) { |
| 232 | return GetPtr(segments[segment].p_offset); | 81 | return GetPtr(segments[segment].p_offset); |
| @@ -256,7 +105,7 @@ ElfReader::ElfReader(void* ptr) { | |||
| 256 | } | 105 | } |
| 257 | 106 | ||
| 258 | const char* ElfReader::GetSectionName(int section) const { | 107 | const char* ElfReader::GetSectionName(int section) const { |
| 259 | if (sections[section].sh_type == SHT_NULL) | 108 | if (sections[section].sh_type == ElfShtNull) |
| 260 | return nullptr; | 109 | return nullptr; |
| 261 | 110 | ||
| 262 | int name_offset = sections[section].sh_name; | 111 | int name_offset = sections[section].sh_name; |
| @@ -272,7 +121,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 272 | LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); | 121 | LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); |
| 273 | 122 | ||
| 274 | // Should we relocate? | 123 | // Should we relocate? |
| 275 | relocate = (header->e_type != ET_EXEC); | 124 | relocate = (header->e_type != ElfTypeExec); |
| 276 | 125 | ||
| 277 | if (relocate) { | 126 | if (relocate) { |
| 278 | LOG_DEBUG(Loader, "Relocatable module"); | 127 | LOG_DEBUG(Loader, "Relocatable module"); |
| @@ -288,7 +137,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 288 | u64 total_image_size = 0; | 137 | u64 total_image_size = 0; |
| 289 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 138 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 290 | const Elf32_Phdr* p = &segments[i]; | 139 | const Elf32_Phdr* p = &segments[i]; |
| 291 | if (p->p_type == PT_LOAD) { | 140 | if (p->p_type == ElfPtLoad) { |
| 292 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; | 141 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; |
| 293 | } | 142 | } |
| 294 | } | 143 | } |
| @@ -303,14 +152,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 303 | LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, | 152 | LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, |
| 304 | p->p_vaddr, p->p_filesz, p->p_memsz); | 153 | p->p_vaddr, p->p_filesz, p->p_memsz); |
| 305 | 154 | ||
| 306 | if (p->p_type == PT_LOAD) { | 155 | if (p->p_type == ElfPtLoad) { |
| 307 | Kernel::CodeSet::Segment* codeset_segment; | 156 | Kernel::CodeSet::Segment* codeset_segment; |
| 308 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); | 157 | u32 permission_flags = p->p_flags & (ElfPfRead | ElfPfWrite | ElfPfExec); |
| 309 | if (permission_flags == (PF_R | PF_X)) { | 158 | if (permission_flags == (ElfPfRead | ElfPfExec)) { |
| 310 | codeset_segment = &codeset.CodeSegment(); | 159 | codeset_segment = &codeset.CodeSegment(); |
| 311 | } else if (permission_flags == (PF_R)) { | 160 | } else if (permission_flags == (ElfPfRead)) { |
| 312 | codeset_segment = &codeset.RODataSegment(); | 161 | codeset_segment = &codeset.RODataSegment(); |
| 313 | } else if (permission_flags == (PF_R | PF_W)) { | 162 | } else if (permission_flags == (ElfPfRead | ElfPfWrite)) { |
| 314 | codeset_segment = &codeset.DataSegment(); | 163 | codeset_segment = &codeset.DataSegment(); |
| 315 | } else { | 164 | } else { |
| 316 | LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i, | 165 | LOG_ERROR(Loader, "Unexpected ELF PT_LOAD segment id {} with flags {:X}", i, |