diff options
| author | 2018-09-29 10:54:39 -0400 | |
|---|---|---|
| committer | 2018-09-29 10:54:39 -0400 | |
| commit | f7b69d61f2a871e8afcd9819b014e873f6e0b80d (patch) | |
| tree | ab6fa797e0a0edd41cc84138ac56aaba0c5238fe /src/core/loader | |
| parent | Merge pull request #1360 from FearlessTobi/port-3979 (diff) | |
| parent | memory: Dehardcode the use of fixed memory range constants (diff) | |
| download | yuzu-f7b69d61f2a871e8afcd9819b014e873f6e0b80d.tar.gz yuzu-f7b69d61f2a871e8afcd9819b014e873f6e0b80d.tar.xz yuzu-f7b69d61f2a871e8afcd9819b014e873f6e0b80d.zip | |
Merge pull request #1395 from lioncash/vm
process/vm_manager: Initial modifications to load NPDM metadata
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 18 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 32 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 12 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 14 |
4 files changed, 29 insertions, 47 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 2b8f78136..7e8035d0f 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -14,11 +14,9 @@ | |||
| 14 | #include "core/gdbstub/gdbstub.h" | 14 | #include "core/gdbstub/gdbstub.h" |
| 15 | #include "core/hle/kernel/kernel.h" | 15 | #include "core/hle/kernel/kernel.h" |
| 16 | #include "core/hle/kernel/process.h" | 16 | #include "core/hle/kernel/process.h" |
| 17 | #include "core/hle/kernel/resource_limit.h" | ||
| 18 | #include "core/hle/service/filesystem/filesystem.h" | 17 | #include "core/hle/service/filesystem/filesystem.h" |
| 19 | #include "core/loader/deconstructed_rom_directory.h" | 18 | #include "core/loader/deconstructed_rom_directory.h" |
| 20 | #include "core/loader/nso.h" | 19 | #include "core/loader/nso.h" |
| 21 | #include "core/memory.h" | ||
| 22 | 20 | ||
| 23 | namespace Loader { | 21 | namespace Loader { |
| 24 | 22 | ||
| @@ -127,12 +125,16 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 127 | metadata.Print(); | 125 | metadata.Print(); |
| 128 | 126 | ||
| 129 | const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; | 127 | const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; |
| 130 | if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit) { | 128 | if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit || |
| 129 | arch_bits == FileSys::ProgramAddressSpaceType::Is32BitNoMap) { | ||
| 131 | return ResultStatus::Error32BitISA; | 130 | return ResultStatus::Error32BitISA; |
| 132 | } | 131 | } |
| 133 | 132 | ||
| 133 | process->LoadFromMetadata(metadata); | ||
| 134 | |||
| 134 | // Load NSO modules | 135 | // Load NSO modules |
| 135 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 136 | const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress(); |
| 137 | VAddr next_load_addr = base_address; | ||
| 136 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | 138 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", |
| 137 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | 139 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { |
| 138 | const FileSys::VirtualFile module_file = dir->GetFile(module); | 140 | const FileSys::VirtualFile module_file = dir->GetFile(module); |
| @@ -145,13 +147,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 145 | } | 147 | } |
| 146 | } | 148 | } |
| 147 | 149 | ||
| 148 | auto& kernel = Core::System::GetInstance().Kernel(); | 150 | process->Run(base_address, metadata.GetMainThreadPriority(), metadata.GetMainThreadStackSize()); |
| 149 | process->program_id = metadata.GetTitleID(); | ||
| 150 | process->svc_access_mask.set(); | ||
| 151 | process->resource_limit = | ||
| 152 | kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); | ||
| 153 | process->Run(Memory::PROCESS_IMAGE_VADDR, metadata.GetMainThreadPriority(), | ||
| 154 | metadata.GetMainThreadStackSize()); | ||
| 155 | 151 | ||
| 156 | // Find the RomFS by searching for a ".romfs" file in this directory | 152 | // Find the RomFS by searching for a ".romfs" file in this directory |
| 157 | const auto& files = dir->GetFiles(); | 153 | const auto& files = dir->GetFiles(); |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 0e2af20b4..ff1221574 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -12,7 +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/resource_limit.h" | 15 | #include "core/hle/kernel/vm_manager.h" |
| 16 | #include "core/loader/elf.h" | 16 | #include "core/loader/elf.h" |
| 17 | #include "core/memory.h" | 17 | #include "core/memory.h" |
| 18 | 18 | ||
| @@ -189,7 +189,7 @@ private: | |||
| 189 | 189 | ||
| 190 | u32* sectionAddrs; | 190 | u32* sectionAddrs; |
| 191 | bool relocate; | 191 | bool relocate; |
| 192 | u32 entryPoint; | 192 | VAddr entryPoint; |
| 193 | 193 | ||
| 194 | public: | 194 | public: |
| 195 | explicit ElfReader(void* ptr); | 195 | explicit ElfReader(void* ptr); |
| @@ -205,13 +205,13 @@ public: | |||
| 205 | ElfMachine GetMachine() const { | 205 | ElfMachine GetMachine() const { |
| 206 | return (ElfMachine)(header->e_machine); | 206 | return (ElfMachine)(header->e_machine); |
| 207 | } | 207 | } |
| 208 | u32 GetEntryPoint() const { | 208 | VAddr GetEntryPoint() const { |
| 209 | return entryPoint; | 209 | return entryPoint; |
| 210 | } | 210 | } |
| 211 | u32 GetFlags() const { | 211 | u32 GetFlags() const { |
| 212 | return (u32)(header->e_flags); | 212 | return (u32)(header->e_flags); |
| 213 | } | 213 | } |
| 214 | SharedPtr<CodeSet> LoadInto(u32 vaddr); | 214 | SharedPtr<CodeSet> LoadInto(VAddr vaddr); |
| 215 | 215 | ||
| 216 | int GetNumSegments() const { | 216 | int GetNumSegments() const { |
| 217 | return (int)(header->e_phnum); | 217 | return (int)(header->e_phnum); |
| @@ -274,7 +274,7 @@ const char* ElfReader::GetSectionName(int section) const { | |||
| 274 | return nullptr; | 274 | return nullptr; |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { | 277 | SharedPtr<CodeSet> ElfReader::LoadInto(VAddr vaddr) { |
| 278 | LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); | 278 | LOG_DEBUG(Loader, "String section: {}", header->e_shstrndx); |
| 279 | 279 | ||
| 280 | // Should we relocate? | 280 | // Should we relocate? |
| @@ -289,11 +289,11 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { | |||
| 289 | LOG_DEBUG(Loader, "{} segments:", header->e_phnum); | 289 | LOG_DEBUG(Loader, "{} segments:", header->e_phnum); |
| 290 | 290 | ||
| 291 | // First pass : Get the bits into RAM | 291 | // First pass : Get the bits into RAM |
| 292 | u32 base_addr = relocate ? vaddr : 0; | 292 | const VAddr base_addr = relocate ? vaddr : 0; |
| 293 | 293 | ||
| 294 | u32 total_image_size = 0; | 294 | u64 total_image_size = 0; |
| 295 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 295 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 296 | Elf32_Phdr* p = &segments[i]; | 296 | const Elf32_Phdr* p = &segments[i]; |
| 297 | if (p->p_type == PT_LOAD) { | 297 | if (p->p_type == PT_LOAD) { |
| 298 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; | 298 | total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; |
| 299 | } | 299 | } |
| @@ -306,7 +306,7 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { | |||
| 306 | SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, ""); | 306 | SharedPtr<CodeSet> codeset = CodeSet::Create(kernel, ""); |
| 307 | 307 | ||
| 308 | for (unsigned int i = 0; i < header->e_phnum; ++i) { | 308 | for (unsigned int i = 0; i < header->e_phnum; ++i) { |
| 309 | Elf32_Phdr* p = &segments[i]; | 309 | const Elf32_Phdr* p = &segments[i]; |
| 310 | 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, |
| 311 | p->p_vaddr, p->p_filesz, p->p_memsz); | 311 | p->p_vaddr, p->p_filesz, p->p_memsz); |
| 312 | 312 | ||
| @@ -333,8 +333,8 @@ SharedPtr<CodeSet> ElfReader::LoadInto(u32 vaddr) { | |||
| 333 | continue; | 333 | continue; |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | u32 segment_addr = base_addr + p->p_vaddr; | 336 | const VAddr segment_addr = base_addr + p->p_vaddr; |
| 337 | u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; | 337 | const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; |
| 338 | 338 | ||
| 339 | codeset_segment->offset = current_image_position; | 339 | codeset_segment->offset = current_image_position; |
| 340 | codeset_segment->addr = segment_addr; | 340 | codeset_segment->addr = segment_addr; |
| @@ -395,18 +395,12 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 395 | if (buffer.size() != file->GetSize()) | 395 | if (buffer.size() != file->GetSize()) |
| 396 | return ResultStatus::ErrorIncorrectELFFileSize; | 396 | return ResultStatus::ErrorIncorrectELFFileSize; |
| 397 | 397 | ||
| 398 | const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress(); | ||
| 398 | ElfReader elf_reader(&buffer[0]); | 399 | ElfReader elf_reader(&buffer[0]); |
| 399 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); | 400 | SharedPtr<CodeSet> codeset = elf_reader.LoadInto(base_address); |
| 400 | codeset->name = file->GetName(); | 401 | codeset->name = file->GetName(); |
| 401 | 402 | ||
| 402 | process->LoadModule(codeset, codeset->entrypoint); | 403 | process->LoadModule(codeset, codeset->entrypoint); |
| 403 | process->svc_access_mask.set(); | ||
| 404 | |||
| 405 | // Attach the default resource limit (APPLICATION) to the process | ||
| 406 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 407 | process->resource_limit = | ||
| 408 | kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); | ||
| 409 | |||
| 410 | process->Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE); | 404 | process->Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE); |
| 411 | 405 | ||
| 412 | is_loaded = true; | 406 | is_loaded = true; |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index c49ec34ab..b72871efa 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | #include "core/gdbstub/gdbstub.h" | 16 | #include "core/gdbstub/gdbstub.h" |
| 17 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/kernel/process.h" | 18 | #include "core/hle/kernel/process.h" |
| 19 | #include "core/hle/kernel/resource_limit.h" | 19 | #include "core/hle/kernel/vm_manager.h" |
| 20 | #include "core/loader/nro.h" | 20 | #include "core/loader/nro.h" |
| 21 | #include "core/memory.h" | 21 | #include "core/memory.h" |
| 22 | 22 | ||
| @@ -181,17 +181,13 @@ ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | // Load NRO | 183 | // Load NRO |
| 184 | static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; | 184 | const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress(); |
| 185 | 185 | ||
| 186 | if (!LoadNro(file, base_addr)) { | 186 | if (!LoadNro(file, base_address)) { |
| 187 | return ResultStatus::ErrorLoadingNRO; | 187 | return ResultStatus::ErrorLoadingNRO; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | auto& kernel = Core::System::GetInstance().Kernel(); | 190 | process->Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); |
| 191 | process->svc_access_mask.set(); | ||
| 192 | process->resource_limit = | ||
| 193 | kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); | ||
| 194 | process->Run(base_addr, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); | ||
| 195 | 191 | ||
| 196 | is_loaded = true; | 192 | is_loaded = true; |
| 197 | return ResultStatus::Success; | 193 | return ResultStatus::Success; |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 78a4438c4..1a6876a22 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -13,7 +13,7 @@ | |||
| 13 | #include "core/gdbstub/gdbstub.h" | 13 | #include "core/gdbstub/gdbstub.h" |
| 14 | #include "core/hle/kernel/kernel.h" | 14 | #include "core/hle/kernel/kernel.h" |
| 15 | #include "core/hle/kernel/process.h" | 15 | #include "core/hle/kernel/process.h" |
| 16 | #include "core/hle/kernel/resource_limit.h" | 16 | #include "core/hle/kernel/vm_manager.h" |
| 17 | #include "core/loader/nso.h" | 17 | #include "core/loader/nso.h" |
| 18 | #include "core/memory.h" | 18 | #include "core/memory.h" |
| 19 | 19 | ||
| @@ -159,15 +159,11 @@ ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { | |||
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | // Load module | 161 | // Load module |
| 162 | LoadModule(file, Memory::PROCESS_IMAGE_VADDR); | 162 | const VAddr base_address = process->vm_manager.GetCodeRegionBaseAddress(); |
| 163 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), Memory::PROCESS_IMAGE_VADDR); | 163 | LoadModule(file, base_address); |
| 164 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); | ||
| 164 | 165 | ||
| 165 | auto& kernel = Core::System::GetInstance().Kernel(); | 166 | process->Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); |
| 166 | process->svc_access_mask.set(); | ||
| 167 | process->resource_limit = | ||
| 168 | kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); | ||
| 169 | process->Run(Memory::PROCESS_IMAGE_VADDR, Kernel::THREADPRIO_DEFAULT, | ||
| 170 | Memory::DEFAULT_STACK_SIZE); | ||
| 171 | 167 | ||
| 172 | is_loaded = true; | 168 | is_loaded = true; |
| 173 | return ResultStatus::Success; | 169 | return ResultStatus::Success; |