summaryrefslogtreecommitdiff
path: root/src/core/loader/elf.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-09-24 20:01:45 -0400
committerGravatar Lioncash2018-09-24 22:16:03 -0400
commit83377113bfe7791483a1b67e06dd0f51620c04ec (patch)
treed766a2d2f20d247e8663c1a76d5c41fcf7f643d4 /src/core/loader/elf.cpp
parentsvc: Report correct memory-related values within some of the cases in svcGetI... (diff)
downloadyuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.gz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.xz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.zip
memory: Dehardcode the use of fixed memory range constants
The locations of these can actually vary depending on the address space layout, so we shouldn't be using these when determining where to map memory or be using them as offsets for calculations. This keeps all the memory ranges flexible and malleable based off of the virtual memory manager instance state.
Diffstat (limited to 'src/core/loader/elf.cpp')
-rw-r--r--src/core/loader/elf.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 00d8a82b8..ff1221574 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -12,6 +12,7 @@
12#include "core/core.h" 12#include "core/core.h"
13#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/kernel.h"
14#include "core/hle/kernel/process.h" 14#include "core/hle/kernel/process.h"
15#include "core/hle/kernel/vm_manager.h"
15#include "core/loader/elf.h" 16#include "core/loader/elf.h"
16#include "core/memory.h" 17#include "core/memory.h"
17 18
@@ -188,7 +189,7 @@ private:
188 189
189 u32* sectionAddrs; 190 u32* sectionAddrs;
190 bool relocate; 191 bool relocate;
191 u32 entryPoint; 192 VAddr entryPoint;
192 193
193public: 194public:
194 explicit ElfReader(void* ptr); 195 explicit ElfReader(void* ptr);
@@ -204,13 +205,13 @@ public:
204 ElfMachine GetMachine() const { 205 ElfMachine GetMachine() const {
205 return (ElfMachine)(header->e_machine); 206 return (ElfMachine)(header->e_machine);
206 } 207 }
207 u32 GetEntryPoint() const { 208 VAddr GetEntryPoint() const {
208 return entryPoint; 209 return entryPoint;
209 } 210 }
210 u32 GetFlags() const { 211 u32 GetFlags() const {
211 return (u32)(header->e_flags); 212 return (u32)(header->e_flags);
212 } 213 }
213 SharedPtr<CodeSet> LoadInto(u32 vaddr); 214 SharedPtr<CodeSet> LoadInto(VAddr vaddr);
214 215
215 int GetNumSegments() const { 216 int GetNumSegments() const {
216 return (int)(header->e_phnum); 217 return (int)(header->e_phnum);
@@ -273,7 +274,7 @@ const char* ElfReader::GetSectionName(int section) const {
273 return nullptr; 274 return nullptr;
274} 275}
275 276
276SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { 277SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) {
277 LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); 278 LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx);
278 279
279 // Should we relocate? 280 // Should we relocate?
@@ -288,11 +289,11 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
288 LOG_DEBUG(Loader, "{} segments:", header->e_phnum); 289 LOG_DEBUG(Loader, "{} segments:", header->e_phnum);
289 290
290 // First pass : Get the bits into RAM 291 // First pass : Get the bits into RAM
291 u32 base_addr = relocate ? vaddr : 0; 292 const VAddr base_addr = relocate ? vaddr : 0;
292 293
293 u32 total_image_size = 0; 294 u64 total_image_size = 0;
294 for (unsigned int i = 0; i < header->e_phnum; ++i) { 295 for (unsigned int i = 0; i < header->e_phnum; ++i) {
295 Elf32_Phdr* p = &segments[i]; 296 const Elf32_Phdr* p = &segments[i];
296 if (p->p_type == PT_LOAD) { 297 if (p->p_type == PT_LOAD) {
297 total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; 298 total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF;
298 } 299 }
@@ -305,7 +306,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
305 SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, ""); 306 SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, "");
306 307
307 for (unsigned int i = 0; i < header->e_phnum; ++i) { 308 for (unsigned int i = 0; i < header->e_phnum; ++i) {
308 Elf32_Phdr* p = &segments[i]; 309 const Elf32_Phdr* p = &segments[i];
309 LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type, 310 LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type,
310 p->p_vaddr, p->p_filesz, p->p_memsz); 311 p->p_vaddr, p->p_filesz, p->p_memsz);
311 312
@@ -332,8 +333,8 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
332 continue; 333 continue;
333 } 334 }
334 335
335 u32 segment_addr = base_addr + p->p_vaddr; 336 const VAddr segment_addr = base_addr + p->p_vaddr;
336 u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; 337 const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF;
337 338
338 codeset_segment->offset = current_image_position; 339 codeset_segment->offset = current_image_position;
339 codeset_segment->addr = segment_addr; 340 codeset_segment->addr = segment_addr;
@@ -394,8 +395,9 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
394 if (buffer.size() != file->GetSize()) 395 if (buffer.size() != file->GetSize())
395 return ResultStatus::ErrorIncorrectELFFileSize; 396 return ResultStatus::ErrorIncorrectELFFileSize;
396 397
398 const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
397 ElfReader elf_reader(&buffer[0]); 399 ElfReader elf_reader(&buffer[0]);
398 SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); 400 SharedPtr<CodeSet> codeset = elf_reader.LoadInto(base_address);
399 codeset->name = file->GetName(); 401 codeset->name = file->GetName();
400 402
401 process->LoadModule(codeset, codeset->entrypoint); 403 process->LoadModule(codeset, codeset->entrypoint);