diff options
Diffstat (limited to 'src/core/loader')
-rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 21 | ||||
-rw-r--r-- | src/core/loader/deconstructed_rom_directory.h | 3 | ||||
-rw-r--r-- | src/core/loader/elf.cpp | 38 | ||||
-rw-r--r-- | src/core/loader/elf.h | 5 | ||||
-rw-r--r-- | src/core/loader/loader.h | 3 | ||||
-rw-r--r-- | src/core/loader/nax.cpp | 2 | ||||
-rw-r--r-- | src/core/loader/nax.h | 2 | ||||
-rw-r--r-- | src/core/loader/nca.cpp | 2 | ||||
-rw-r--r-- | src/core/loader/nca.h | 3 | ||||
-rw-r--r-- | src/core/loader/nro.cpp | 14 | ||||
-rw-r--r-- | src/core/loader/nro.h | 3 | ||||
-rw-r--r-- | src/core/loader/nso.cpp | 16 | ||||
-rw-r--r-- | src/core/loader/nso.h | 4 | ||||
-rw-r--r-- | src/core/loader/nsp.cpp | 4 | ||||
-rw-r--r-- | src/core/loader/nsp.h | 2 | ||||
-rw-r--r-- | src/core/loader/xci.cpp | 4 | ||||
-rw-r--r-- | src/core/loader/xci.h | 2 |
17 files changed, 48 insertions, 80 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 2b8f78136..c1824b9c3 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -14,11 +14,9 @@ #include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/process.h" -#include "core/hle/kernel/resource_limit.h" #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 { @@ -88,8 +86,7 @@ FileType AppLoader_DeconstructedRomDirectory::IdentifyType(const FileSys::Virtua return FileType::Error; } -ResultStatus AppLoader_DeconstructedRomDirectory::Load( - Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } @@ -127,12 +124,16 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( metadata.Print(); const FileSys::ProgramAddressSpaceType arch_bits{metadata.GetAddressSpaceType()}; - if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit) { + if (arch_bits == FileSys::ProgramAddressSpaceType::Is32Bit || + arch_bits == FileSys::ProgramAddressSpaceType::Is32BitNoMap) { return ResultStatus::Error32BitISA; } + process.LoadFromMetadata(metadata); + // Load NSO modules - VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; + const VAddr base_address = process.VMManager().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); @@ -145,13 +146,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( } } - auto& kernel = Core::System::GetInstance().Kernel(); - process->program_id = metadata.GetTitleID(); - process->svc_access_mask.set(); - process->resource_limit = - kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); - 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/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 8a0dc1b1e..d109ed2b5 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h @@ -7,7 +7,6 @@ #include <string> #include "common/common_types.h" #include "core/file_sys/program_metadata.h" -#include "core/hle/kernel/object.h" #include "core/loader/loader.h" namespace Loader { @@ -38,7 +37,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 0e2af20b4..e67b49fc9 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -12,7 +12,7 @@ #include "core/core.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/process.h" -#include "core/hle/kernel/resource_limit.h" +#include "core/hle/kernel/vm_manager.h" #include "core/loader/elf.h" #include "core/memory.h" @@ -189,7 +189,7 @@ private: u32* sectionAddrs; bool relocate; - u32 entryPoint; + VAddr entryPoint; public: explicit ElfReader(void* ptr); @@ -205,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); @@ -274,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? @@ -289,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; } @@ -306,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); @@ -333,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; @@ -387,7 +387,7 @@ FileType AppLoader_ELF::IdentifyType(const FileSys::VirtualFile& file) { return FileType::Error; } -ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_ELF::Load(Kernel::Process& process) { if (is_loaded) return ResultStatus::ErrorAlreadyLoaded; @@ -395,19 +395,13 @@ ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) { if (buffer.size() != file->GetSize()) return ResultStatus::ErrorIncorrectELFFileSize; + const VAddr base_address = process.VMManager().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); - process->svc_access_mask.set(); - - // Attach the default resource limit (APPLICATION) to the process - auto& kernel = Core::System::GetInstance().Kernel(); - process->resource_limit = - kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); - - process->Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE); + process.LoadModule(codeset, codeset->entrypoint); + process.Run(codeset->entrypoint, 48, Memory::DEFAULT_STACK_SIZE); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index b8fb982d0..6af76441c 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -8,9 +8,6 @@ #include "common/common_types.h" #include "core/loader/loader.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Loader namespace - namespace Loader { /// Loads an ELF/AXF file @@ -29,7 +26,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; }; } // namespace Loader diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 843c4bb91..20e66109b 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -12,7 +12,6 @@ #include <boost/optional.hpp> #include "common/common_types.h" #include "core/file_sys/vfs.h" -#include "core/hle/kernel/object.h" namespace Kernel { struct AddressMapping; @@ -136,7 +135,7 @@ public: * @param process The newly created process. * @return The status result of the operation. */ - virtual ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) = 0; + virtual ResultStatus Load(Kernel::Process& process) = 0; /** * Loads the system mode that this application needs. diff --git a/src/core/loader/nax.cpp b/src/core/loader/nax.cpp index 5d4380684..073fb9d2f 100644 --- a/src/core/loader/nax.cpp +++ b/src/core/loader/nax.cpp @@ -41,7 +41,7 @@ FileType AppLoader_NAX::GetFileType() { return IdentifyTypeImpl(*nax); } -ResultStatus AppLoader_NAX::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_NAX::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index 56605fe45..fc3c01876 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h @@ -33,7 +33,7 @@ public: FileType GetFileType() override; - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; ResultStatus ReadProgramId(u64& out_program_id) override; diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index 6aaffae59..7e1b0d84f 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp @@ -30,7 +30,7 @@ FileType AppLoader_NCA::IdentifyType(const FileSys::VirtualFile& file) { return FileType::Error; } -ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_NCA::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h index 10be197c4..95d9b73a1 100644 --- a/src/core/loader/nca.h +++ b/src/core/loader/nca.h @@ -6,7 +6,6 @@ #include "common/common_types.h" #include "core/file_sys/vfs.h" -#include "core/hle/kernel/object.h" #include "core/loader/loader.h" namespace FileSys { @@ -34,7 +33,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; u64 ReadRomFSIVFCOffset() const override; diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index c49ec34ab..c10f826a4 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -16,7 +16,7 @@ #include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/process.h" -#include "core/hle/kernel/resource_limit.h" +#include "core/hle/kernel/vm_manager.h" #include "core/loader/nro.h" #include "core/memory.h" @@ -175,23 +175,19 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { return true; } -ResultStatus AppLoader_NRO::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_NRO::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } // Load NRO - static constexpr VAddr base_addr{Memory::PROCESS_IMAGE_VADDR}; + const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); - if (!LoadNro(file, base_addr)) { + if (!LoadNro(file, base_address)) { return ResultStatus::ErrorLoadingNRO; } - auto& kernel = Core::System::GetInstance().Kernel(); - process->svc_access_mask.set(); - process->resource_limit = - kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); - 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/nro.h b/src/core/loader/nro.h index 96d2de305..04b46119a 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -6,7 +6,6 @@ #include <string> #include "common/common_types.h" -#include "core/hle/kernel/object.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -33,7 +32,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; ResultStatus ReadProgramId(u64& out_program_id) override; diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 78a4438c4..cbe2a3e53 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -13,7 +13,7 @@ #include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/process.h" -#include "core/hle/kernel/resource_limit.h" +#include "core/hle/kernel/vm_manager.h" #include "core/loader/nso.h" #include "core/memory.h" @@ -153,21 +153,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base) { return load_base + image_size; } -ResultStatus AppLoader_NSO::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } // 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.VMManager().GetCodeRegionBaseAddress(); + LoadModule(file, base_address); + LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); - auto& kernel = Core::System::GetInstance().Kernel(); - process->svc_access_mask.set(); - process->resource_limit = - kernel.ResourceLimitForCategory(Kernel::ResourceLimitCategory::APPLICATION); - 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; diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index aaeb1f2a9..7f142405b 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -4,9 +4,7 @@ #pragma once -#include <string> #include "common/common_types.h" -#include "core/hle/kernel/object.h" #include "core/loader/linker.h" #include "core/loader/loader.h" @@ -30,7 +28,7 @@ public: static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base); - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; }; } // namespace Loader diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index 291a9876d..b7ba77ef4 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -10,8 +10,6 @@ #include "core/file_sys/control_metadata.h" #include "core/file_sys/nca_metadata.h" #include "core/file_sys/patch_manager.h" -#include "core/file_sys/registered_cache.h" -#include "core/file_sys/romfs.h" #include "core/file_sys/submission_package.h" #include "core/hle/kernel/process.h" #include "core/loader/deconstructed_rom_directory.h" @@ -62,7 +60,7 @@ FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& file) { return FileType::Error; } -ResultStatus AppLoader_NSP::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_NSP::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index 7ef810499..eac9b819a 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -35,7 +35,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; ResultStatus ReadProgramId(u64& out_program_id) override; diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 16509229f..eda67a8c8 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -9,8 +9,6 @@ #include "core/file_sys/content_archive.h" #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" -#include "core/file_sys/romfs.h" -#include "core/file_sys/submission_package.h" #include "core/hle/kernel/process.h" #include "core/loader/nca.h" #include "core/loader/xci.h" @@ -46,7 +44,7 @@ FileType AppLoader_XCI::IdentifyType(const FileSys::VirtualFile& file) { return FileType::Error; } -ResultStatus AppLoader_XCI::Load(Kernel::SharedPtr<Kernel::Process>& process) { +ResultStatus AppLoader_XCI::Load(Kernel::Process& process) { if (is_loaded) { return ResultStatus::ErrorAlreadyLoaded; } diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index cc4287e17..17e47b658 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -35,7 +35,7 @@ public: return IdentifyType(file); } - ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override; + ResultStatus Load(Kernel::Process& process) override; ResultStatus ReadRomFS(FileSys::VirtualFile& dir) override; ResultStatus ReadProgramId(u64& out_program_id) override; |