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