summaryrefslogtreecommitdiffstats
path: root/src/core/loader
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-09-25 02:01:45 +0200
committerLioncash <mathew1800@gmail.com>2018-09-25 04:16:03 +0200
commit83377113bfe7791483a1b67e06dd0f51620c04ec (patch)
treed766a2d2f20d247e8663c1a76d5c41fcf7f643d4 /src/core/loader
parentsvc: Report correct memory-related values within some of the cases in svcGetInfo() (diff)
downloadyuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.gz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.bz2
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.lz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.xz
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.tar.zst
yuzu-83377113bfe7791483a1b67e06dd0f51620c04ec.zip
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp7
-rw-r--r--src/core/loader/elf.cpp24
-rw-r--r--src/core/loader/nro.cpp7
-rw-r--r--src/core/loader/nso.cpp9
4 files changed, 25 insertions, 22 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index 44d62ab7f..7e8035d0f 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -17,7 +17,6 @@
#include "core/hle/service/filesystem/filesystem.h"
#include "core/loader/deconstructed_rom_directory.h"
#include "core/loader/nso.h"
-#include "core/memory.h"
namespace Loader {
@@ -134,7 +133,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
process->LoadFromMetadata(metadata);
// Load NSO modules
- VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR};
+ const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
+ VAddr next_load_addr = base_address;
for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3",
"subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) {
const FileSys::VirtualFile module_file = dir->GetFile(module);
@@ -147,8 +147,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
}
}
- process->Run(Memory::PROCESS_IMAGE_VADDR, metadata.GetMainThreadPriority(),
- metadata.GetMainThreadStackSize());
+ process->Run(base_address, metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize());
// Find the RomFS by searching for a ".romfs" file in this directory
const auto& files = dir->GetFiles();
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 @@
#include "core/core.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/kernel/vm_manager.h"
#include "core/loader/elf.h"
#include "core/memory.h"
@@ -188,7 +189,7 @@ private:
u32* sectionAddrs;
bool relocate;
- u32 entryPoint;
+ VAddr entryPoint;
public:
explicit ElfReader(void* ptr);
@@ -204,13 +205,13 @@ public:
ElfMachine GetMachine() const {
return (ElfMachine)(header->e_machine);
}
- u32 GetEntryPoint() const {
+ VAddr GetEntryPoint() const {
return entryPoint;
}
u32 GetFlags() const {
return (u32)(header->e_flags);
}
- SharedPtr<CodeSet> LoadInto(u32 vaddr);
+ SharedPtr<CodeSet> LoadInto(VAddr vaddr);
int GetNumSegments() const {
return (int)(header->e_phnum);
@@ -273,7 +274,7 @@ const char* ElfReader::GetSectionName(int section) const {
return nullptr;
}
-SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
+SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) {
LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx);
// Should we relocate?
@@ -288,11 +289,11 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
LOG_DEBUG(Loader, "{} segments:", header->e_phnum);
// First pass : Get the bits into RAM
- u32 base_addr = relocate ? vaddr : 0;
+ const VAddr base_addr = relocate ? vaddr : 0;
- u32 total_image_size = 0;
+ u64 total_image_size = 0;
for (unsigned int i = 0; i < header->e_phnum; ++i) {
- Elf32_Phdr* p = &segments[i];
+ const Elf32_Phdr* p = &segments[i];
if (p->p_type == PT_LOAD) {
total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF;
}
@@ -305,7 +306,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, "");
for (unsigned int i = 0; i < header->e_phnum; ++i) {
- Elf32_Phdr* p = &segments[i];
+ const Elf32_Phdr* p = &segments[i];
LOG_DEBUG(Loader, "Type: {} Vaddr: {:08X} Filesz: {:08X} Memsz: {:08X} ", p->p_type,
p->p_vaddr, p->p_filesz, p->p_memsz);
@@ -332,8 +333,8 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) {
continue;
}
- u32 segment_addr = base_addr + p->p_vaddr;
- u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF;
+ const VAddr segment_addr = base_addr + p->p_vaddr;
+ const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF;
codeset_segment->offset = current_image_position;
codeset_segment->addr = segment_addr;
@@ -394,8 +395,9 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
if (buffer.size() != file->GetSize())
return ResultStatus::ErrorIncorrectELFFileSize;
+ const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
ElfReader elf_reader(&buffer[0]);
- SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
+ SharedPtr<CodeSet> codeset = elf_reader.LoadInto(base_address);
codeset->name = file->GetName();
process->LoadModule(codeset, codeset->entrypoint);
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 2385012eb..b72871efa 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -16,6 +16,7 @@
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/kernel/vm_manager.h"
#include "core/loader/nro.h"
#include "core/memory.h"
@@ -180,13 +181,13 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
}
// Load NRO
- static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR};
+ const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
- if (!LoadNro(file, base_addr)) {
+ if (!LoadNro(file, base_address)) {
return ResultStatus::ErrorLoadingNRO;
}
- process->Run(base_addr, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
+ process->Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
is_loaded = true;
return ResultStatus::Success;
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 9fd9933fb..1a6876a22 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -13,6 +13,7 @@
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/kernel/vm_manager.h"
#include "core/loader/nso.h"
#include "core/memory.h"
@@ -158,11 +159,11 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) {
}
// Load module
- LoadModule(file, Memory::PROCESS_IMAGE_VADDR);
- LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), Memory::PROCESS_IMAGE_VADDR);
+ const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress();
+ LoadModule(file, base_address);
+ LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address);
- process->Run(Memory::PROCESS_IMAGE_VADDR, Kernel::THREADPRIO_DEFAULT,
- Memory::DEFAULT_STACK_SIZE);
+ process->Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE);
is_loaded = true;
return ResultStatus::Success;