From 39c8d18feba8eafcd43fbb55e73ae150a1947aad Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 13 Oct 2020 08:10:50 -0400 Subject: core/CMakeLists: Make some warnings errors Makes our error coverage a little more consistent across the board by applying it to Linux side of things as well. This also makes it more consistent with the warning settings in other libraries in the project. This also updates httplib to 0.7.9, as there are several warning cleanups made that allow us to enable several warnings as errors. --- src/core/loader/kip.cpp | 2 +- src/core/loader/nro.cpp | 2 +- src/core/loader/nso.cpp | 2 +- src/core/loader/nso.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp index 5981bcd21..2a905d3e4 100644 --- a/src/core/loader/kip.cpp +++ b/src/core/loader/kip.cpp @@ -16,7 +16,7 @@ namespace Loader { namespace { constexpr u32 PageAlignSize(u32 size) { - return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; + return static_cast((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); } } // Anonymous namespace diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 9fb5eddad..5f4b3104b 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -127,7 +127,7 @@ FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) { } static constexpr u32 PageAlignSize(u32 size) { - return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; + return static_cast((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); } static bool LoadNroImpl(Kernel::Process& process, const std::vector& data, diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 1e70f6e11..497f438a1 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -47,7 +47,7 @@ std::vector DecompressSegment(const std::vector& compressed_data, } constexpr u32 PageAlignSize(u32 size) { - return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; + return static_cast((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK); } } // Anonymous namespace diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 4bd47787d..d331096ae 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -59,7 +59,7 @@ struct NSOHeader { static_assert(sizeof(NSOHeader) == 0x100, "NSOHeader has incorrect size."); static_assert(std::is_trivially_copyable_v, "NSOHeader must be trivially copyable."); -constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000; +constexpr u32 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000; struct NSOArgumentHeader { u32_le allocated_size; -- cgit v1.2.3 From be1954e04cb5a0c3a526f78ed5490a5e65310280 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Oct 2020 14:49:45 -0400 Subject: core: Fix clang build Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795 --- src/core/loader/elf.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index dca1fcb18..86d0527fc 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp @@ -220,18 +220,19 @@ public: } const char* GetSectionName(int section) const; const u8* GetSectionDataPtr(int section) const { - if (section < 0 || section >= header->e_shnum) - return nullptr; - if (sections[section].sh_type != SHT_NOBITS) - return GetPtr(sections[section].sh_offset); - else + if (section < 0 || section >= header->e_shnum) { return nullptr; + } + if (sections[section].sh_type != SHT_NOBITS) { + return GetPtr(static_cast(sections[section].sh_offset)); + } + return nullptr; } bool IsCodeSection(int section) const { return sections[section].sh_type == SHT_PROGBITS; } const u8* GetSegmentPtr(int segment) { - return GetPtr(segments[segment].p_offset); + return GetPtr(static_cast(segments[segment].p_offset)); } u32 GetSectionAddr(SectionID section) const { return sectionAddrs[section]; @@ -258,14 +259,14 @@ ElfReader::ElfReader(void* ptr) { } const char* ElfReader::GetSectionName(int section) const { - if (sections[section].sh_type == SHT_NULL) + if (sections[section].sh_type == SHT_NULL) { return nullptr; + } - int name_offset = sections[section].sh_name; - const char* ptr = reinterpret_cast(GetSectionDataPtr(header->e_shstrndx)); - - if (ptr) + const auto name_offset = sections[section].sh_name; + if (const auto* ptr = reinterpret_cast(GetSectionDataPtr(header->e_shstrndx))) { return ptr + name_offset; + } return nullptr; } @@ -291,7 +292,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { for (unsigned int i = 0; i < header->e_phnum; ++i) { const Elf32_Phdr* p = &segments[i]; if (p->p_type == PT_LOAD) { - total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; + total_image_size += (p->p_memsz + 0xFFF) & ~0xFFFU; } } @@ -300,14 +301,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { Kernel::CodeSet codeset; - for (unsigned int i = 0; i < header->e_phnum; ++i) { + for (u32 i = 0; i < header->e_phnum; ++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); if (p->p_type == PT_LOAD) { Kernel::CodeSet::Segment* codeset_segment; - u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); + const u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); if (permission_flags == (PF_R | PF_X)) { codeset_segment = &codeset.CodeSegment(); } else if (permission_flags == (PF_R)) { @@ -329,14 +330,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { } const VAddr segment_addr = base_addr + p->p_vaddr; - const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; + const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFFU; codeset_segment->offset = current_image_position; codeset_segment->addr = segment_addr; codeset_segment->size = aligned_size; - std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), - p->p_filesz); + std::memcpy(program_image.data() + current_image_position, + GetSegmentPtr(static_cast(i)), p->p_filesz); current_image_position += aligned_size; } } -- cgit v1.2.3 From 3d592972dc3fd61cc88771b889eff237e4e03e0f Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 20 Oct 2020 19:07:39 -0700 Subject: Revert "core: Fix clang build" --- src/core/loader/elf.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'src/core/loader') 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: } const char* GetSectionName(int section) const; const u8* GetSectionDataPtr(int section) const { - if (section < 0 || section >= header->e_shnum) { + if (section < 0 || section >= header->e_shnum) + return nullptr; + if (sections[section].sh_type != SHT_NOBITS) + return GetPtr(sections[section].sh_offset); + else return nullptr; - } - if (sections[section].sh_type != SHT_NOBITS) { - return GetPtr(static_cast(sections[section].sh_offset)); - } - return nullptr; } bool IsCodeSection(int section) const { return sections[section].sh_type == SHT_PROGBITS; } const u8* GetSegmentPtr(int segment) { - return GetPtr(static_cast(segments[segment].p_offset)); + return GetPtr(segments[segment].p_offset); } u32 GetSectionAddr(SectionID section) const { return sectionAddrs[section]; @@ -259,14 +258,14 @@ ElfReader::ElfReader(void* ptr) { } const char* ElfReader::GetSectionName(int section) const { - if (sections[section].sh_type == SHT_NULL) { + if (sections[section].sh_type == SHT_NULL) return nullptr; - } - const auto name_offset = sections[section].sh_name; - if (const auto* ptr = reinterpret_cast(GetSectionDataPtr(header->e_shstrndx))) { + int name_offset = sections[section].sh_name; + const char* ptr = reinterpret_cast(GetSectionDataPtr(header->e_shstrndx)); + + if (ptr) return ptr + name_offset; - } return nullptr; } @@ -292,7 +291,7 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { for (unsigned int i = 0; i < header->e_phnum; ++i) { const Elf32_Phdr* p = &segments[i]; if (p->p_type == PT_LOAD) { - total_image_size += (p->p_memsz + 0xFFF) & ~0xFFFU; + total_image_size += (p->p_memsz + 0xFFF) & ~0xFFF; } } @@ -301,14 +300,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { Kernel::CodeSet codeset; - for (u32 i = 0; i < header->e_phnum; ++i) { + for (unsigned int i = 0; i < header->e_phnum; ++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); if (p->p_type == PT_LOAD) { Kernel::CodeSet::Segment* codeset_segment; - const u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); + u32 permission_flags = p->p_flags & (PF_R | PF_W | PF_X); if (permission_flags == (PF_R | PF_X)) { codeset_segment = &codeset.CodeSegment(); } else if (permission_flags == (PF_R)) { @@ -330,14 +329,14 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { } const VAddr segment_addr = base_addr + p->p_vaddr; - const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFFU; + const u32 aligned_size = (p->p_memsz + 0xFFF) & ~0xFFF; codeset_segment->offset = current_image_position; codeset_segment->addr = segment_addr; codeset_segment->size = aligned_size; - std::memcpy(program_image.data() + current_image_position, - GetSegmentPtr(static_cast(i)), p->p_filesz); + std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), + p->p_filesz); current_image_position += aligned_size; } } -- cgit v1.2.3 From 6f8a06bac58790d20dae3c1adb4de3b441f07b30 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Nov 2020 07:53:10 -0500 Subject: patch_manager: Remove usages of the global system instance With this, only 19 usages of the global system instance remain within the core library. We're almost there. --- src/core/loader/deconstructed_rom_directory.cpp | 6 ++++-- src/core/loader/loader.cpp | 27 ++++++++++++++----------- src/core/loader/loader.h | 9 ++++++--- src/core/loader/nso.cpp | 2 +- src/core/loader/nsp.cpp | 19 +++++++++++------ src/core/loader/nsp.h | 13 +++++++----- src/core/loader/xci.cpp | 16 ++++++++++----- src/core/loader/xci.h | 13 +++++++----- 8 files changed, 66 insertions(+), 39 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 394a1bf26..2002dc4f2 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -114,7 +114,8 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect } if (override_update) { - const FileSys::PatchManager patch_manager(metadata.GetTitleID()); + const FileSys::PatchManager patch_manager( + metadata.GetTitleID(), system.GetFileSystemController(), system.GetContentProvider()); dir = patch_manager.PatchExeFS(dir); } @@ -160,7 +161,8 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect modules.clear(); const VAddr base_address{process.PageTable().GetCodeRegionStart()}; VAddr next_load_addr{base_address}; - const FileSys::PatchManager pm{metadata.GetTitleID()}; + const FileSys::PatchManager pm{metadata.GetTitleID(), system.GetFileSystemController(), + system.GetContentProvider()}; for (const auto& module : static_modules) { const FileSys::VirtualFile module_file{dir->GetFile(module)}; if (!module_file) { diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 9bc3a8840..deffe7379 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -10,6 +10,7 @@ #include "common/file_util.h" #include "common/logging/log.h" #include "common/string_util.h" +#include "core/core.h" #include "core/hle/kernel/process.h" #include "core/loader/deconstructed_rom_directory.h" #include "core/loader/elf.h" @@ -194,15 +195,14 @@ AppLoader::~AppLoader() = default; /** * Get a loader for a file with a specific type - * @param file The file to load - * @param type The type of the file - * @param file the file to retrieve the loader for - * @param type the file type + * @param system The system context to use. + * @param file The file to retrieve the loader for + * @param type The file type * @return std::unique_ptr a pointer to a loader object; nullptr for unsupported type */ -static std::unique_ptr GetFileLoader(FileSys::VirtualFile file, FileType type) { +static std::unique_ptr GetFileLoader(Core::System& system, FileSys::VirtualFile file, + FileType type) { switch (type) { - // Standard ELF file format. case FileType::ELF: return std::make_unique(std::move(file)); @@ -221,7 +221,8 @@ static std::unique_ptr GetFileLoader(FileSys::VirtualFile file, FileT // NX XCI (nX Card Image) file format. case FileType::XCI: - return std::make_unique(std::move(file)); + return std::make_unique(std::move(file), system.GetFileSystemController(), + system.GetContentProvider()); // NX NAX (NintendoAesXts) file format. case FileType::NAX: @@ -229,7 +230,8 @@ static std::unique_ptr GetFileLoader(FileSys::VirtualFile file, FileT // NX NSP (Nintendo Submission Package) file format case FileType::NSP: - return std::make_unique(std::move(file)); + return std::make_unique(std::move(file), system.GetFileSystemController(), + system.GetContentProvider()); // NX KIP (Kernel Internal Process) file format case FileType::KIP: @@ -244,20 +246,21 @@ static std::unique_ptr GetFileLoader(FileSys::VirtualFile file, FileT } } -std::unique_ptr GetLoader(FileSys::VirtualFile file) { +std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile file) { FileType type = IdentifyFile(file); - FileType filename_type = GuessFromFilename(file->GetName()); + const FileType filename_type = GuessFromFilename(file->GetName()); // Special case: 00 is either a NCA or NAX. if (type != filename_type && !(file->GetName() == "00" && type == FileType::NAX)) { LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); - if (FileType::Unknown == type) + if (FileType::Unknown == type) { type = filename_type; + } } LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); - return GetFileLoader(std::move(file), type); + return GetFileLoader(system, std::move(file), type); } } // namespace Loader diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index ac60b097a..8dc2d7615 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -290,9 +290,12 @@ protected: /** * Identifies a bootable file and return a suitable loader - * @param file The bootable file - * @return the best loader for this file + * + * @param system The system context. + * @param file The bootable file. + * + * @return the best loader for this file. */ -std::unique_ptr GetLoader(FileSys::VirtualFile file); +std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile file); } // namespace Loader diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 497f438a1..aa85c1a29 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -149,7 +149,7 @@ std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S // Apply cheats if they exist and the program has a valid title ID if (pm) { system.SetCurrentProcessBuildID(nso_header.build_id); - const auto cheats = pm->CreateCheatList(system, nso_header.build_id); + const auto cheats = pm->CreateCheatList(nso_header.build_id); if (!cheats.empty()) { system.RegisterCheatList(cheats, nso_header.build_id, load_base, image_size); } diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index 15e528fa8..e821937fd 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -21,26 +21,33 @@ namespace Loader { -AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file) +AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file, + const Service::FileSystem::FileSystemController& fsc, + const FileSys::ContentProvider& content_provider) : AppLoader(file), nsp(std::make_unique(file)), title_id(nsp->GetProgramTitleID()) { - if (nsp->GetStatus() != ResultStatus::Success) + if (nsp->GetStatus() != ResultStatus::Success) { return; + } if (nsp->IsExtractedType()) { secondary_loader = std::make_unique(nsp->GetExeFS()); } else { const auto control_nca = nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Control); - if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) + if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) { return; + } - std::tie(nacp_file, icon_file) = - FileSys::PatchManager(nsp->GetProgramTitleID()).ParseControlNCA(*control_nca); + std::tie(nacp_file, icon_file) = [this, &content_provider, &control_nca, &fsc] { + const FileSys::PatchManager pm{nsp->GetProgramTitleID(), fsc, content_provider}; + return pm.ParseControlNCA(*control_nca); + }(); - if (title_id == 0) + if (title_id == 0) { return; + } secondary_loader = std::make_unique( nsp->GetNCAFile(title_id, FileSys::ContentRecordType::Program)); diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index b27deb686..36e8e3533 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -9,15 +9,16 @@ #include "core/file_sys/vfs.h" #include "core/loader/loader.h" -namespace Core { -class System; -} - namespace FileSys { +class ContentProvider; class NACP; class NSP; } // namespace FileSys +namespace Service::FileSystem { +class FileSystemController; +} + namespace Loader { class AppLoader_NCA; @@ -25,7 +26,9 @@ class AppLoader_NCA; /// Loads an XCI file class AppLoader_NSP final : public AppLoader { public: - explicit AppLoader_NSP(FileSys::VirtualFile file); + explicit AppLoader_NSP(FileSys::VirtualFile file, + const Service::FileSystem::FileSystemController& fsc, + const FileSys::ContentProvider& content_provider); ~AppLoader_NSP() override; /** diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 25e83af0f..536e721fc 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -20,18 +20,24 @@ namespace Loader { -AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file) +AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file, + const Service::FileSystem::FileSystemController& fsc, + const FileSys::ContentProvider& content_provider) : AppLoader(file), xci(std::make_unique(file)), nca_loader(std::make_unique(xci->GetProgramNCAFile())) { - if (xci->GetStatus() != ResultStatus::Success) + if (xci->GetStatus() != ResultStatus::Success) { return; + } const auto control_nca = xci->GetNCAByType(FileSys::NCAContentType::Control); - if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) + if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) { return; + } - std::tie(nacp_file, icon_file) = - FileSys::PatchManager(xci->GetProgramTitleID()).ParseControlNCA(*control_nca); + std::tie(nacp_file, icon_file) = [this, &content_provider, &control_nca, &fsc] { + const FileSys::PatchManager pm{xci->GetProgramTitleID(), fsc, content_provider}; + return pm.ParseControlNCA(*control_nca); + }(); } AppLoader_XCI::~AppLoader_XCI() = default; diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 04aea286f..6dc1f9243 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -9,15 +9,16 @@ #include "core/file_sys/vfs.h" #include "core/loader/loader.h" -namespace Core { -class System; -} - namespace FileSys { +class ContentProvider; class NACP; class XCI; } // namespace FileSys +namespace Service::FileSystem { +class FileSystemController; +} + namespace Loader { class AppLoader_NCA; @@ -25,7 +26,9 @@ class AppLoader_NCA; /// Loads an XCI file class AppLoader_XCI final : public AppLoader { public: - explicit AppLoader_XCI(FileSys::VirtualFile file); + explicit AppLoader_XCI(FileSys::VirtualFile file, + const Service::FileSystem::FileSystemController& fsc, + const FileSys::ContentProvider& content_provider); ~AppLoader_XCI() override; /** -- cgit v1.2.3 From 5f75d9712540d53ad779babff8edd75627882006 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 24 Nov 2020 15:16:24 -0800 Subject: core: loader: Implement support for loading indexed programs. --- src/core/loader/loader.cpp | 12 +++++++----- src/core/loader/loader.h | 4 +++- src/core/loader/nsp.cpp | 5 +++-- src/core/loader/nsp.h | 3 ++- src/core/loader/xci.cpp | 5 +++-- src/core/loader/xci.h | 3 ++- 6 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index deffe7379..d91c15561 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -198,10 +198,11 @@ AppLoader::~AppLoader() = default; * @param system The system context to use. * @param file The file to retrieve the loader for * @param type The file type + * @param program_index Specifies the index within the container of the program to launch. * @return std::unique_ptr a pointer to a loader object; nullptr for unsupported type */ static std::unique_ptr GetFileLoader(Core::System& system, FileSys::VirtualFile file, - FileType type) { + FileType type, std::size_t program_index) { switch (type) { // Standard ELF file format. case FileType::ELF: @@ -222,7 +223,7 @@ static std::unique_ptr GetFileLoader(Core::System& system, FileSys::V // NX XCI (nX Card Image) file format. case FileType::XCI: return std::make_unique(std::move(file), system.GetFileSystemController(), - system.GetContentProvider()); + system.GetContentProvider(), program_index); // NX NAX (NintendoAesXts) file format. case FileType::NAX: @@ -231,7 +232,7 @@ static std::unique_ptr GetFileLoader(Core::System& system, FileSys::V // NX NSP (Nintendo Submission Package) file format case FileType::NSP: return std::make_unique(std::move(file), system.GetFileSystemController(), - system.GetContentProvider()); + system.GetContentProvider(), program_index); // NX KIP (Kernel Internal Process) file format case FileType::KIP: @@ -246,7 +247,8 @@ static std::unique_ptr GetFileLoader(Core::System& system, FileSys::V } } -std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile file) { +std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile file, + std::size_t program_index) { FileType type = IdentifyFile(file); const FileType filename_type = GuessFromFilename(file->GetName()); @@ -260,7 +262,7 @@ std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); - return GetFileLoader(system, std::move(file), type); + return GetFileLoader(system, std::move(file), type, program_index); } } // namespace Loader diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 8dc2d7615..36e79e71d 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -293,9 +293,11 @@ protected: * * @param system The system context. * @param file The bootable file. + * @param program_index Specifies the index within the container of the program to launch. * * @return the best loader for this file. */ -std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile file); +std::unique_ptr GetLoader(Core::System& system, FileSys::VirtualFile file, + std::size_t program_index = 0); } // namespace Loader diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index e821937fd..928f64c8c 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -23,8 +23,9 @@ namespace Loader { AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider) - : AppLoader(file), nsp(std::make_unique(file)), + const FileSys::ContentProvider& content_provider, + std::size_t program_index) + : AppLoader(file), nsp(std::make_unique(file, program_index)), title_id(nsp->GetProgramTitleID()) { if (nsp->GetStatus() != ResultStatus::Success) { diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index 36e8e3533..f0518ac47 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -28,7 +28,8 @@ class AppLoader_NSP final : public AppLoader { public: explicit AppLoader_NSP(FileSys::VirtualFile file, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider); + const FileSys::ContentProvider& content_provider, + std::size_t program_index); ~AppLoader_NSP() override; /** diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 536e721fc..aaa250cea 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -22,8 +22,9 @@ namespace Loader { AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider) - : AppLoader(file), xci(std::make_unique(file)), + const FileSys::ContentProvider& content_provider, + std::size_t program_index) + : AppLoader(file), xci(std::make_unique(file, program_index)), nca_loader(std::make_unique(xci->GetProgramNCAFile())) { if (xci->GetStatus() != ResultStatus::Success) { return; diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 6dc1f9243..764dc8328 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -28,7 +28,8 @@ class AppLoader_XCI final : public AppLoader { public: explicit AppLoader_XCI(FileSys::VirtualFile file, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider); + const FileSys::ContentProvider& content_provider, + std::size_t program_index); ~AppLoader_XCI() override; /** -- cgit v1.2.3 From 5bc4eabe36b7ef4dcd5ad8db1e944705655be432 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 27 Nov 2020 10:50:48 -0500 Subject: core: Eliminate remaining usages of the global system instance Removes all remaining usages of the global system instance. After this, migration can begin to migrate to being constructed and managed entirely by the various frontends. --- src/core/loader/deconstructed_rom_directory.cpp | 3 --- src/core/loader/kip.cpp | 3 --- src/core/loader/nro.cpp | 6 +----- src/core/loader/nso.cpp | 5 +---- 4 files changed, 2 insertions(+), 15 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 2002dc4f2..79ebf11de 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -12,7 +12,6 @@ #include "core/file_sys/control_metadata.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/romfs_factory.h" -#include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/memory/page_table.h" #include "core/hle/kernel/process.h" @@ -180,8 +179,6 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect next_load_addr = *tentative_next_load_addr; modules.insert_or_assign(load_addr, module); LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); - // Register module with GDBStub - GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); } // Find the RomFS by searching for a ".romfs" file in this directory diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp index 2a905d3e4..e162c4ff0 100644 --- a/src/core/loader/kip.cpp +++ b/src/core/loader/kip.cpp @@ -5,7 +5,6 @@ #include #include "core/file_sys/kernel_executable.h" #include "core/file_sys/program_metadata.h" -#include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/code_set.h" #include "core/hle/kernel/memory/page_table.h" #include "core/hle/kernel/process.h" @@ -91,8 +90,6 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::Process& process, program_image.resize(PageAlignSize(kip->GetBSSOffset()) + kip->GetBSSSize()); codeset.DataSegment().size += kip->GetBSSSize(); - GDBStub::RegisterModule(kip->GetName(), base_address, base_address + program_image.size()); - codeset.memory = std::move(program_image); process.LoadModule(std::move(codeset), base_address); diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 5f4b3104b..ccf8cc153 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -14,10 +14,10 @@ #include "core/file_sys/control_metadata.h" #include "core/file_sys/romfs_factory.h" #include "core/file_sys/vfs_offset.h" -#include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/code_set.h" #include "core/hle/kernel/memory/page_table.h" #include "core/hle/kernel/process.h" +#include "core/hle/kernel/thread.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/loader/nro.h" #include "core/loader/nso.h" @@ -197,10 +197,6 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector& data, codeset.memory = std::move(program_image); process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart()); - // Register module with GDBStub - GDBStub::RegisterModule(name, process.PageTable().GetCodeRegionStart(), - process.PageTable().GetCodeRegionEnd()); - return true; } diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index aa85c1a29..95b6f339a 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -14,10 +14,10 @@ #include "common/swap.h" #include "core/core.h" #include "core/file_sys/patch_manager.h" -#include "core/gdbstub/gdbstub.h" #include "core/hle/kernel/code_set.h" #include "core/hle/kernel/memory/page_table.h" #include "core/hle/kernel/process.h" +#include "core/hle/kernel/thread.h" #include "core/loader/nso.h" #include "core/memory.h" #include "core/settings.h" @@ -159,9 +159,6 @@ std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S codeset.memory = std::move(program_image); process.LoadModule(std::move(codeset), load_base); - // Register module with GDBStub - GDBStub::RegisterModule(file.GetName(), load_base, load_base); - return load_base + image_size; } -- cgit v1.2.3 From b1657b8c6b4ef07dd6eea92f4559a32ca3e0894a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 10 Dec 2020 01:31:58 -0500 Subject: vfs: Use existing type aliases consistently Makes use of the VirtualDir and VirtualFile aliases across the board instead of having a few isolated places that don't use it. --- src/core/loader/deconstructed_rom_directory.h | 2 +- src/core/loader/elf.h | 2 +- src/core/loader/kip.h | 2 +- src/core/loader/nax.h | 2 +- src/core/loader/nca.h | 2 +- src/core/loader/nro.h | 2 +- src/core/loader/nso.h | 2 +- src/core/loader/nsp.h | 2 +- src/core/loader/xci.h | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/core/loader') diff --git a/src/core/loader/deconstructed_rom_directory.h b/src/core/loader/deconstructed_rom_directory.h index 35d340317..3c968580f 100644 --- a/src/core/loader/deconstructed_rom_directory.h +++ b/src/core/loader/deconstructed_rom_directory.h @@ -32,7 +32,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 3527933ad..2067932c7 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -21,7 +21,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/kip.h b/src/core/loader/kip.h index dee05a7b5..14a85e295 100644 --- a/src/core/loader/kip.h +++ b/src/core/loader/kip.h @@ -23,7 +23,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/nax.h b/src/core/loader/nax.h index c2b7722b5..a5b5e2ae1 100644 --- a/src/core/loader/nax.h +++ b/src/core/loader/nax.h @@ -28,7 +28,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/nca.h b/src/core/loader/nca.h index 711070294..918792800 100644 --- a/src/core/loader/nca.h +++ b/src/core/loader/nca.h @@ -28,7 +28,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index a2aab2ecc..a82b66221 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h @@ -32,7 +32,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index d331096ae..3af461b5f 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h @@ -75,7 +75,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index f0518ac47..d48d87f2c 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -34,7 +34,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 764dc8328..9f0ceb5ef 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -34,7 +34,7 @@ public: /** * Returns the type of the file - * @param file std::shared_ptr open file + * @param file open file * @return FileType found, or FileType::Error if this loader doesn't know it */ static FileType IdentifyType(const FileSys::VirtualFile& file); -- cgit v1.2.3 From 86592b274e228708cf0f9e1f4063e917f1bb3bd5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 3 Jan 2021 13:18:02 -0500 Subject: main: Resolve error string not displaying During the transition to make the error dialog translatable, I accidentally got rid of the conversion to ResultStatus, which prevented operator<< from being invoked during formatting. This adds a function to directly retrieve the result status string instead so that it displays again. --- src/core/loader/loader.cpp | 4 ++++ src/core/loader/loader.h | 1 + 2 files changed, 5 insertions(+) (limited to 'src/core/loader') diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index d91c15561..e4f5fd40c 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -185,6 +185,10 @@ constexpr std::array RESULT_MESSAGES{ "The INI file contains more than the maximum allowable number of KIP files.", }; +std::string GetResultStatusString(ResultStatus status) { + return RESULT_MESSAGES.at(static_cast(status)); +} + std::ostream& operator<<(std::ostream& os, ResultStatus status) { os << RESULT_MESSAGES.at(static_cast(status)); return os; diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 36e79e71d..b2e5b13de 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -135,6 +135,7 @@ enum class ResultStatus : u16 { ErrorINITooManyKIPs, }; +std::string GetResultStatusString(ResultStatus status); std::ostream& operator<<(std::ostream& os, ResultStatus status); /// Interface for loading an application -- cgit v1.2.3