diff options
Diffstat (limited to 'src/core/loader/elf.cpp')
| -rw-r--r-- | src/core/loader/elf.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index dca1fcb18..86d0527fc 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -220,18 +220,19 @@ public: | |||
| 220 | } | 220 | } |
| 221 | const char* GetSectionName(int section) const; | 221 | const char* GetSectionName(int section) const; |
| 222 | const u8* GetSectionDataPtr(int section) const { | 222 | const u8* GetSectionDataPtr(int section) const { |
| 223 | if (section < 0 || section >= header->e_shnum) | 223 | if (section < 0 || section >= header->e_shnum) { |
| 224 | return nullptr; | ||
| 225 | if (sections[section].sh_type != SHT_NOBITS) | ||
| 226 | return GetPtr(sections[section].sh_offset); | ||
| 227 | else | ||
| 228 | return nullptr; | 224 | return nullptr; |
| 225 | } | ||
| 226 | if (sections[section].sh_type != SHT_NOBITS) { | ||
| 227 | return GetPtr(static_cast<int>(sections[section].sh_offset)); | ||
| 228 | } | ||
| 229 | return nullptr; | ||
| 229 | } | 230 | } |
| 230 | bool IsCodeSection(int section) const { | 231 | bool IsCodeSection(int section) const { |
| 231 | return sections[section].sh_type == SHT_PROGBITS; | 232 | return sections[section].sh_type == SHT_PROGBITS; |
| 232 | } | 233 | } |
| 233 | const u8* GetSegmentPtr(int segment) { | 234 | const u8* GetSegmentPtr(int segment) { |
| 234 | return GetPtr(segments[segment].p_offset); | 235 | return GetPtr(static_cast<int>(segments[segment].p_offset)); |
| 235 | } | 236 | } |
| 236 | u32 GetSectionAddr(SectionID section) const { | 237 | u32 GetSectionAddr(SectionID section) const { |
| 237 | return sectionAddrs[section]; | 238 | return sectionAddrs[section]; |
| @@ -258,14 +259,14 @@ ElfReader::ElfReader(void* ptr) { | |||
| 258 | } | 259 | } |
| 259 | 260 | ||
| 260 | const char* ElfReader::GetSectionName(int section) const { | 261 | const char* ElfReader::GetSectionName(int section) const { |
| 261 | if (sections[section].sh_type == SHT_NULL) | 262 | if (sections[section].sh_type == SHT_NULL) { |
| 262 | return nullptr; | 263 | return nullptr; |
| 264 | } | ||
| 263 | 265 | ||
| 264 | int name_offset = sections[section].sh_name; | 266 | const auto name_offset = sections[section].sh_name; |
| 265 | const char* ptr = reinterpret_cast<const char*>(GetSectionDataPtr(header->e_shstrndx)); | 267 | if (const auto* ptr = reinterpret_cast<const char*>(GetSectionDataPtr(header->e_shstrndx))) { |
| 266 | |||
| 267 | if (ptr) | ||
| 268 | return ptr + name_offset; | 268 | return ptr + name_offset; |
| 269 | } | ||
| 269 | 270 | ||
| 270 | return nullptr; | 271 | return nullptr; |
| 271 | } | 272 | } |
| @@ -291,7 +292,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 291 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 292 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 292 | const Elf32_Phdr* p = &segments[i]; | 293 | const Elf32_Phdr* p = &segments[i]; |
| 293 | if (p->p_type == PT_LOAD) { | 294 | if (p->p_type == PT_LOAD) { |
| 294 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; | 295 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFFU; |
| 295 | } | 296 | } |
| 296 | } | 297 | } |
| 297 | 298 | ||
| @@ -300,14 +301,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 300 | 301 | ||
| 301 | Kernel::CodeSet codeset; | 302 | Kernel::CodeSet codeset; |
| 302 | 303 | ||
| 303 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 304 | for (u32 i = 0; i < header->e_phnum; ++i) { |
| 304 | const Elf32_Phdr* p = &segments[i]; | 305 | const Elf32_Phdr* p = &segments[i]; |
| 305 | LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, | 306 | LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, |
| 306 | p->p_vaddr, p->p_filesz, p->p_memsz); | 307 | p->p_vaddr, p->p_filesz, p->p_memsz); |
| 307 | 308 | ||
| 308 | if (p->p_type == PT_LOAD) { | 309 | if (p->p_type == PT_LOAD) { |
| 309 | Kernel::CodeSet::Segment* codeset_segment; | 310 | Kernel::CodeSet::Segment* codeset_segment; |
| 310 | u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); | 311 | const u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); |
| 311 | if (permission_flags == (PF_R | PF_X)) { | 312 | if (permission_flags == (PF_R | PF_X)) { |
| 312 | codeset_segment = &codeset.CodeSegment(); | 313 | codeset_segment = &codeset.CodeSegment(); |
| 313 | } else if (permission_flags == (PF_R)) { | 314 | } else if (permission_flags == (PF_R)) { |
| @@ -329,14 +330,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||
| 329 | } | 330 | } |
| 330 | 331 | ||
| 331 | const VAddr segment_addr = base_addr + p->p_vaddr; | 332 | const VAddr segment_addr = base_addr + p->p_vaddr; |
| 332 | const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; | 333 | const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFFU; |
| 333 | 334 | ||
| 334 | codeset_segment->offset = current_image_position; | 335 | codeset_segment->offset = current_image_position; |
| 335 | codeset_segment->addr = segment_addr; | 336 | codeset_segment->addr = segment_addr; |
| 336 | codeset_segment->size = aligned_size; | 337 | codeset_segment->size = aligned_size; |
| 337 | 338 | ||
| 338 | std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), | 339 | std::memcpy(program_image.data() + current_image_position, |
| 339 | p->p_filesz); | 340 | GetSegmentPtr(static_cast<int>(i)), p->p_filesz); |
| 340 | current_image_position += aligned_size; | 341 | current_image_position += aligned_size; |
| 341 | } | 342 | } |
| 342 | } | 343 | } |