summaryrefslogtreecommitdiff
path: root/src/core/loader
diff options
context:
space:
mode:
authorGravatar Levi2021-01-10 22:09:56 -0700
committerGravatar Levi2021-01-10 22:09:56 -0700
commit7a3c884e39fccfbb498b855080bffabc9ce2e7f1 (patch)
tree5056f9406dec188439cb0deb87603498243a9412 /src/core/loader
parentMore forgetting... duh (diff)
parentMerge pull request #5229 from Morph1984/fullscreen-opt (diff)
downloadyuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.gz
yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.tar.xz
yuzu-7a3c884e39fccfbb498b855080bffabc9ce2e7f1.zip
Merge remote-tracking branch 'upstream/master' into int-flags
Diffstat (limited to 'src/core/loader')
-rw-r--r--src/core/loader/deconstructed_rom_directory.cpp9
-rw-r--r--src/core/loader/deconstructed_rom_directory.h2
-rw-r--r--src/core/loader/elf.h2
-rw-r--r--src/core/loader/kip.cpp5
-rw-r--r--src/core/loader/kip.h2
-rw-r--r--src/core/loader/loader.cpp33
-rw-r--r--src/core/loader/loader.h12
-rw-r--r--src/core/loader/nax.h2
-rw-r--r--src/core/loader/nca.h2
-rw-r--r--src/core/loader/nro.cpp8
-rw-r--r--src/core/loader/nro.h2
-rw-r--r--src/core/loader/nso.cpp9
-rw-r--r--src/core/loader/nso.h4
-rw-r--r--src/core/loader/nsp.cpp22
-rw-r--r--src/core/loader/nsp.h16
-rw-r--r--src/core/loader/xci.cpp19
-rw-r--r--src/core/loader/xci.h16
17 files changed, 96 insertions, 69 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp
index 394a1bf26..79ebf11de 100644
--- a/src/core/loader/deconstructed_rom_directory.cpp
+++ b/src/core/loader/deconstructed_rom_directory.cpp
@@ -12,7 +12,6 @@
12#include "core/file_sys/control_metadata.h" 12#include "core/file_sys/control_metadata.h"
13#include "core/file_sys/patch_manager.h" 13#include "core/file_sys/patch_manager.h"
14#include "core/file_sys/romfs_factory.h" 14#include "core/file_sys/romfs_factory.h"
15#include "core/gdbstub/gdbstub.h"
16#include "core/hle/kernel/kernel.h" 15#include "core/hle/kernel/kernel.h"
17#include "core/hle/kernel/memory/page_table.h" 16#include "core/hle/kernel/memory/page_table.h"
18#include "core/hle/kernel/process.h" 17#include "core/hle/kernel/process.h"
@@ -114,7 +113,8 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
114 } 113 }
115 114
116 if (override_update) { 115 if (override_update) {
117 const FileSys::PatchManager patch_manager(metadata.GetTitleID()); 116 const FileSys::PatchManager patch_manager(
117 metadata.GetTitleID(), system.GetFileSystemController(), system.GetContentProvider());
118 dir = patch_manager.PatchExeFS(dir); 118 dir = patch_manager.PatchExeFS(dir);
119 } 119 }
120 120
@@ -160,7 +160,8 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
160 modules.clear(); 160 modules.clear();
161 const VAddr base_address{process.PageTable().GetCodeRegionStart()}; 161 const VAddr base_address{process.PageTable().GetCodeRegionStart()};
162 VAddr next_load_addr{base_address}; 162 VAddr next_load_addr{base_address};
163 const FileSys::PatchManager pm{metadata.GetTitleID()}; 163 const FileSys::PatchManager pm{metadata.GetTitleID(), system.GetFileSystemController(),
164 system.GetContentProvider()};
164 for (const auto& module : static_modules) { 165 for (const auto& module : static_modules) {
165 const FileSys::VirtualFile module_file{dir->GetFile(module)}; 166 const FileSys::VirtualFile module_file{dir->GetFile(module)};
166 if (!module_file) { 167 if (!module_file) {
@@ -178,8 +179,6 @@ AppLoader_DeconstructedRomDirectory::LoadResult AppLoader_DeconstructedRomDirect
178 next_load_addr = *tentative_next_load_addr; 179 next_load_addr = *tentative_next_load_addr;
179 modules.insert_or_assign(load_addr, module); 180 modules.insert_or_assign(load_addr, module);
180 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); 181 LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
181 // Register module with GDBStub
182 GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false);
183 } 182 }
184 183
185 // Find the RomFS by searching for a ".romfs" file in this directory 184 // Find the RomFS by searching for a ".romfs" file in this directory
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:
32 32
33 /** 33 /**
34 * Returns the type of the file 34 * Returns the type of the file
35 * @param file std::shared_ptr<VfsFile> open file 35 * @param file open file
36 * @return FileType found, or FileType::Error if this loader doesn't know it 36 * @return FileType found, or FileType::Error if this loader doesn't know it
37 */ 37 */
38 static FileType IdentifyType(const FileSys::VirtualFile& file); 38 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:
21 21
22 /** 22 /**
23 * Returns the type of the file 23 * Returns the type of the file
24 * @param file std::shared_ptr<VfsFile> open file 24 * @param file open file
25 * @return FileType found, or FileType::Error if this loader doesn't know it 25 * @return FileType found, or FileType::Error if this loader doesn't know it
26 */ 26 */
27 static FileType IdentifyType(const FileSys::VirtualFile& file); 27 static FileType IdentifyType(const FileSys::VirtualFile& file);
diff --git a/src/core/loader/kip.cpp b/src/core/loader/kip.cpp
index 5981bcd21..e162c4ff0 100644
--- a/src/core/loader/kip.cpp
+++ b/src/core/loader/kip.cpp
@@ -5,7 +5,6 @@
5#include <cstring> 5#include <cstring>
6#include "core/file_sys/kernel_executable.h" 6#include "core/file_sys/kernel_executable.h"
7#include "core/file_sys/program_metadata.h" 7#include "core/file_sys/program_metadata.h"
8#include "core/gdbstub/gdbstub.h"
9#include "core/hle/kernel/code_set.h" 8#include "core/hle/kernel/code_set.h"
10#include "core/hle/kernel/memory/page_table.h" 9#include "core/hle/kernel/memory/page_table.h"
11#include "core/hle/kernel/process.h" 10#include "core/hle/kernel/process.h"
@@ -16,7 +15,7 @@ namespace Loader {
16 15
17namespace { 16namespace {
18constexpr u32 PageAlignSize(u32 size) { 17constexpr u32 PageAlignSize(u32 size) {
19 return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; 18 return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK);
20} 19}
21} // Anonymous namespace 20} // Anonymous namespace
22 21
@@ -91,8 +90,6 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::Process& process,
91 program_image.resize(PageAlignSize(kip->GetBSSOffset()) + kip->GetBSSSize()); 90 program_image.resize(PageAlignSize(kip->GetBSSOffset()) + kip->GetBSSSize());
92 codeset.DataSegment().size += kip->GetBSSSize(); 91 codeset.DataSegment().size += kip->GetBSSSize();
93 92
94 GDBStub::RegisterModule(kip->GetName(), base_address, base_address + program_image.size());
95
96 codeset.memory = std::move(program_image); 93 codeset.memory = std::move(program_image);
97 process.LoadModule(std::move(codeset), base_address); 94 process.LoadModule(std::move(codeset), base_address);
98 95
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:
23 23
24 /** 24 /**
25 * Returns the type of the file 25 * Returns the type of the file
26 * @param file std::shared_ptr<VfsFile> open file 26 * @param file open file
27 * @return FileType found, or FileType::Error if this loader doesn't know it 27 * @return FileType found, or FileType::Error if this loader doesn't know it
28 */ 28 */
29 static FileType IdentifyType(const FileSys::VirtualFile& file); 29 static FileType IdentifyType(const FileSys::VirtualFile& file);
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index 9bc3a8840..e4f5fd40c 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -10,6 +10,7 @@
10#include "common/file_util.h" 10#include "common/file_util.h"
11#include "common/logging/log.h" 11#include "common/logging/log.h"
12#include "common/string_util.h" 12#include "common/string_util.h"
13#include "core/core.h"
13#include "core/hle/kernel/process.h" 14#include "core/hle/kernel/process.h"
14#include "core/loader/deconstructed_rom_directory.h" 15#include "core/loader/deconstructed_rom_directory.h"
15#include "core/loader/elf.h" 16#include "core/loader/elf.h"
@@ -184,6 +185,10 @@ constexpr std::array<const char*, 66> RESULT_MESSAGES{
184 "The INI file contains more than the maximum allowable number of KIP files.", 185 "The INI file contains more than the maximum allowable number of KIP files.",
185}; 186};
186 187
188std::string GetResultStatusString(ResultStatus status) {
189 return RESULT_MESSAGES.at(static_cast<std::size_t>(status));
190}
191
187std::ostream& operator<<(std::ostream& os, ResultStatus status) { 192std::ostream& operator<<(std::ostream& os, ResultStatus status) {
188 os << RESULT_MESSAGES.at(static_cast<std::size_t>(status)); 193 os << RESULT_MESSAGES.at(static_cast<std::size_t>(status));
189 return os; 194 return os;
@@ -194,15 +199,15 @@ AppLoader::~AppLoader() = default;
194 199
195/** 200/**
196 * Get a loader for a file with a specific type 201 * Get a loader for a file with a specific type
197 * @param file The file to load 202 * @param system The system context to use.
198 * @param type The type of the file 203 * @param file The file to retrieve the loader for
199 * @param file the file to retrieve the loader for 204 * @param type The file type
200 * @param type the file type 205 * @param program_index Specifies the index within the container of the program to launch.
201 * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type 206 * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type
202 */ 207 */
203static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileType type) { 208static std::unique_ptr<AppLoader> GetFileLoader(Core::System& system, FileSys::VirtualFile file,
209 FileType type, std::size_t program_index) {
204 switch (type) { 210 switch (type) {
205
206 // Standard ELF file format. 211 // Standard ELF file format.
207 case FileType::ELF: 212 case FileType::ELF:
208 return std::make_unique<AppLoader_ELF>(std::move(file)); 213 return std::make_unique<AppLoader_ELF>(std::move(file));
@@ -221,7 +226,8 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
221 226
222 // NX XCI (nX Card Image) file format. 227 // NX XCI (nX Card Image) file format.
223 case FileType::XCI: 228 case FileType::XCI:
224 return std::make_unique<AppLoader_XCI>(std::move(file)); 229 return std::make_unique<AppLoader_XCI>(std::move(file), system.GetFileSystemController(),
230 system.GetContentProvider(), program_index);
225 231
226 // NX NAX (NintendoAesXts) file format. 232 // NX NAX (NintendoAesXts) file format.
227 case FileType::NAX: 233 case FileType::NAX:
@@ -229,7 +235,8 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
229 235
230 // NX NSP (Nintendo Submission Package) file format 236 // NX NSP (Nintendo Submission Package) file format
231 case FileType::NSP: 237 case FileType::NSP:
232 return std::make_unique<AppLoader_NSP>(std::move(file)); 238 return std::make_unique<AppLoader_NSP>(std::move(file), system.GetFileSystemController(),
239 system.GetContentProvider(), program_index);
233 240
234 // NX KIP (Kernel Internal Process) file format 241 // NX KIP (Kernel Internal Process) file format
235 case FileType::KIP: 242 case FileType::KIP:
@@ -244,20 +251,22 @@ static std::unique_ptr<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
244 } 251 }
245} 252}
246 253
247std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file) { 254std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile file,
255 std::size_t program_index) {
248 FileType type = IdentifyFile(file); 256 FileType type = IdentifyFile(file);
249 FileType filename_type = GuessFromFilename(file->GetName()); 257 const FileType filename_type = GuessFromFilename(file->GetName());
250 258
251 // Special case: 00 is either a NCA or NAX. 259 // Special case: 00 is either a NCA or NAX.
252 if (type != filename_type && !(file->GetName() == "00" && type == FileType::NAX)) { 260 if (type != filename_type && !(file->GetName() == "00" && type == FileType::NAX)) {
253 LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); 261 LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName());
254 if (FileType::Unknown == type) 262 if (FileType::Unknown == type) {
255 type = filename_type; 263 type = filename_type;
264 }
256 } 265 }
257 266
258 LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); 267 LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type));
259 268
260 return GetFileLoader(std::move(file), type); 269 return GetFileLoader(system, std::move(file), type, program_index);
261} 270}
262 271
263} // namespace Loader 272} // namespace Loader
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index ac60b097a..b2e5b13de 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -135,6 +135,7 @@ enum class ResultStatus : u16 {
135 ErrorINITooManyKIPs, 135 ErrorINITooManyKIPs,
136}; 136};
137 137
138std::string GetResultStatusString(ResultStatus status);
138std::ostream& operator<<(std::ostream& os, ResultStatus status); 139std::ostream& operator<<(std::ostream& os, ResultStatus status);
139 140
140/// Interface for loading an application 141/// Interface for loading an application
@@ -290,9 +291,14 @@ protected:
290 291
291/** 292/**
292 * Identifies a bootable file and return a suitable loader 293 * Identifies a bootable file and return a suitable loader
293 * @param file The bootable file 294 *
294 * @return the best loader for this file 295 * @param system The system context.
296 * @param file The bootable file.
297 * @param program_index Specifies the index within the container of the program to launch.
298 *
299 * @return the best loader for this file.
295 */ 300 */
296std::unique_ptr<AppLoader> GetLoader(FileSys::VirtualFile file); 301std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile file,
302 std::size_t program_index = 0);
297 303
298} // namespace Loader 304} // namespace Loader
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:
28 28
29 /** 29 /**
30 * Returns the type of the file 30 * Returns the type of the file
31 * @param file std::shared_ptr<VfsFile> open file 31 * @param file open file
32 * @return FileType found, or FileType::Error if this loader doesn't know it 32 * @return FileType found, or FileType::Error if this loader doesn't know it
33 */ 33 */
34 static FileType IdentifyType(const FileSys::VirtualFile& file); 34 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:
28 28
29 /** 29 /**
30 * Returns the type of the file 30 * Returns the type of the file
31 * @param file std::shared_ptr<VfsFile> open file 31 * @param file open file
32 * @return FileType found, or FileType::Error if this loader doesn't know it 32 * @return FileType found, or FileType::Error if this loader doesn't know it
33 */ 33 */
34 static FileType IdentifyType(const FileSys::VirtualFile& file); 34 static FileType IdentifyType(const FileSys::VirtualFile& file);
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp
index 9fb5eddad..ccf8cc153 100644
--- a/src/core/loader/nro.cpp
+++ b/src/core/loader/nro.cpp
@@ -14,10 +14,10 @@
14#include "core/file_sys/control_metadata.h" 14#include "core/file_sys/control_metadata.h"
15#include "core/file_sys/romfs_factory.h" 15#include "core/file_sys/romfs_factory.h"
16#include "core/file_sys/vfs_offset.h" 16#include "core/file_sys/vfs_offset.h"
17#include "core/gdbstub/gdbstub.h"
18#include "core/hle/kernel/code_set.h" 17#include "core/hle/kernel/code_set.h"
19#include "core/hle/kernel/memory/page_table.h" 18#include "core/hle/kernel/memory/page_table.h"
20#include "core/hle/kernel/process.h" 19#include "core/hle/kernel/process.h"
20#include "core/hle/kernel/thread.h"
21#include "core/hle/service/filesystem/filesystem.h" 21#include "core/hle/service/filesystem/filesystem.h"
22#include "core/loader/nro.h" 22#include "core/loader/nro.h"
23#include "core/loader/nso.h" 23#include "core/loader/nso.h"
@@ -127,7 +127,7 @@ FileType AppLoader_NRO::IdentifyType(const FileSys::VirtualFile& file) {
127} 127}
128 128
129static constexpr u32 PageAlignSize(u32 size) { 129static constexpr u32 PageAlignSize(u32 size) {
130 return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; 130 return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK);
131} 131}
132 132
133static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, 133static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
@@ -197,10 +197,6 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data,
197 codeset.memory = std::move(program_image); 197 codeset.memory = std::move(program_image);
198 process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart()); 198 process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart());
199 199
200 // Register module with GDBStub
201 GDBStub::RegisterModule(name, process.PageTable().GetCodeRegionStart(),
202 process.PageTable().GetCodeRegionEnd());
203
204 return true; 200 return true;
205} 201}
206 202
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:
32 32
33 /** 33 /**
34 * Returns the type of the file 34 * Returns the type of the file
35 * @param file std::shared_ptr<VfsFile> open file 35 * @param file open file
36 * @return FileType found, or FileType::Error if this loader doesn't know it 36 * @return FileType found, or FileType::Error if this loader doesn't know it
37 */ 37 */
38 static FileType IdentifyType(const FileSys::VirtualFile& file); 38 static FileType IdentifyType(const FileSys::VirtualFile& file);
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp
index 1e70f6e11..95b6f339a 100644
--- a/src/core/loader/nso.cpp
+++ b/src/core/loader/nso.cpp
@@ -14,10 +14,10 @@
14#include "common/swap.h" 14#include "common/swap.h"
15#include "core/core.h" 15#include "core/core.h"
16#include "core/file_sys/patch_manager.h" 16#include "core/file_sys/patch_manager.h"
17#include "core/gdbstub/gdbstub.h"
18#include "core/hle/kernel/code_set.h" 17#include "core/hle/kernel/code_set.h"
19#include "core/hle/kernel/memory/page_table.h" 18#include "core/hle/kernel/memory/page_table.h"
20#include "core/hle/kernel/process.h" 19#include "core/hle/kernel/process.h"
20#include "core/hle/kernel/thread.h"
21#include "core/loader/nso.h" 21#include "core/loader/nso.h"
22#include "core/memory.h" 22#include "core/memory.h"
23#include "core/settings.h" 23#include "core/settings.h"
@@ -47,7 +47,7 @@ std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data,
47} 47}
48 48
49constexpr u32 PageAlignSize(u32 size) { 49constexpr u32 PageAlignSize(u32 size) {
50 return (size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK; 50 return static_cast<u32>((size + Core::Memory::PAGE_MASK) & ~Core::Memory::PAGE_MASK);
51} 51}
52} // Anonymous namespace 52} // Anonymous namespace
53 53
@@ -149,7 +149,7 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S
149 // Apply cheats if they exist and the program has a valid title ID 149 // Apply cheats if they exist and the program has a valid title ID
150 if (pm) { 150 if (pm) {
151 system.SetCurrentProcessBuildID(nso_header.build_id); 151 system.SetCurrentProcessBuildID(nso_header.build_id);
152 const auto cheats = pm->CreateCheatList(system, nso_header.build_id); 152 const auto cheats = pm->CreateCheatList(nso_header.build_id);
153 if (!cheats.empty()) { 153 if (!cheats.empty()) {
154 system.RegisterCheatList(cheats, nso_header.build_id, load_base, image_size); 154 system.RegisterCheatList(cheats, nso_header.build_id, load_base, image_size);
155 } 155 }
@@ -159,9 +159,6 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, Core::S
159 codeset.memory = std::move(program_image); 159 codeset.memory = std::move(program_image);
160 process.LoadModule(std::move(codeset), load_base); 160 process.LoadModule(std::move(codeset), load_base);
161 161
162 // Register module with GDBStub
163 GDBStub::RegisterModule(file.GetName(), load_base, load_base);
164
165 return load_base + image_size; 162 return load_base + image_size;
166} 163}
167 164
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h
index 4bd47787d..3af461b5f 100644
--- a/src/core/loader/nso.h
+++ b/src/core/loader/nso.h
@@ -59,7 +59,7 @@ struct NSOHeader {
59static_assert(sizeof(NSOHeader) == 0x100, "NSOHeader has incorrect size."); 59static_assert(sizeof(NSOHeader) == 0x100, "NSOHeader has incorrect size.");
60static_assert(std::is_trivially_copyable_v<NSOHeader>, "NSOHeader must be trivially copyable."); 60static_assert(std::is_trivially_copyable_v<NSOHeader>, "NSOHeader must be trivially copyable.");
61 61
62constexpr u64 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000; 62constexpr u32 NSO_ARGUMENT_DATA_ALLOCATION_SIZE = 0x9000;
63 63
64struct NSOArgumentHeader { 64struct NSOArgumentHeader {
65 u32_le allocated_size; 65 u32_le allocated_size;
@@ -75,7 +75,7 @@ public:
75 75
76 /** 76 /**
77 * Returns the type of the file 77 * Returns the type of the file
78 * @param file std::shared_ptr<VfsFile> open file 78 * @param file open file
79 * @return FileType found, or FileType::Error if this loader doesn't know it 79 * @return FileType found, or FileType::Error if this loader doesn't know it
80 */ 80 */
81 static FileType IdentifyType(const FileSys::VirtualFile& file); 81 static FileType IdentifyType(const FileSys::VirtualFile& file);
diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp
index 15e528fa8..928f64c8c 100644
--- a/src/core/loader/nsp.cpp
+++ b/src/core/loader/nsp.cpp
@@ -21,26 +21,34 @@
21 21
22namespace Loader { 22namespace Loader {
23 23
24AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file) 24AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file,
25 : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file)), 25 const Service::FileSystem::FileSystemController& fsc,
26 const FileSys::ContentProvider& content_provider,
27 std::size_t program_index)
28 : AppLoader(file), nsp(std::make_unique<FileSys::NSP>(file, program_index)),
26 title_id(nsp->GetProgramTitleID()) { 29 title_id(nsp->GetProgramTitleID()) {
27 30
28 if (nsp->GetStatus() != ResultStatus::Success) 31 if (nsp->GetStatus() != ResultStatus::Success) {
29 return; 32 return;
33 }
30 34
31 if (nsp->IsExtractedType()) { 35 if (nsp->IsExtractedType()) {
32 secondary_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(nsp->GetExeFS()); 36 secondary_loader = std::make_unique<AppLoader_DeconstructedRomDirectory>(nsp->GetExeFS());
33 } else { 37 } else {
34 const auto control_nca = 38 const auto control_nca =
35 nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Control); 39 nsp->GetNCA(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Control);
36 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) 40 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) {
37 return; 41 return;
42 }
38 43
39 std::tie(nacp_file, icon_file) = 44 std::tie(nacp_file, icon_file) = [this, &content_provider, &control_nca, &fsc] {
40 FileSys::PatchManager(nsp->GetProgramTitleID()).ParseControlNCA(*control_nca); 45 const FileSys::PatchManager pm{nsp->GetProgramTitleID(), fsc, content_provider};
46 return pm.ParseControlNCA(*control_nca);
47 }();
41 48
42 if (title_id == 0) 49 if (title_id == 0) {
43 return; 50 return;
51 }
44 52
45 secondary_loader = std::make_unique<AppLoader_NCA>( 53 secondary_loader = std::make_unique<AppLoader_NCA>(
46 nsp->GetNCAFile(title_id, FileSys::ContentRecordType::Program)); 54 nsp->GetNCAFile(title_id, FileSys::ContentRecordType::Program));
diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h
index b27deb686..d48d87f2c 100644
--- a/src/core/loader/nsp.h
+++ b/src/core/loader/nsp.h
@@ -9,15 +9,16 @@
9#include "core/file_sys/vfs.h" 9#include "core/file_sys/vfs.h"
10#include "core/loader/loader.h" 10#include "core/loader/loader.h"
11 11
12namespace Core {
13class System;
14}
15
16namespace FileSys { 12namespace FileSys {
13class ContentProvider;
17class NACP; 14class NACP;
18class NSP; 15class NSP;
19} // namespace FileSys 16} // namespace FileSys
20 17
18namespace Service::FileSystem {
19class FileSystemController;
20}
21
21namespace Loader { 22namespace Loader {
22 23
23class AppLoader_NCA; 24class AppLoader_NCA;
@@ -25,12 +26,15 @@ class AppLoader_NCA;
25/// Loads an XCI file 26/// Loads an XCI file
26class AppLoader_NSP final : public AppLoader { 27class AppLoader_NSP final : public AppLoader {
27public: 28public:
28 explicit AppLoader_NSP(FileSys::VirtualFile file); 29 explicit AppLoader_NSP(FileSys::VirtualFile file,
30 const Service::FileSystem::FileSystemController& fsc,
31 const FileSys::ContentProvider& content_provider,
32 std::size_t program_index);
29 ~AppLoader_NSP() override; 33 ~AppLoader_NSP() override;
30 34
31 /** 35 /**
32 * Returns the type of the file 36 * Returns the type of the file
33 * @param file std::shared_ptr<VfsFile> open file 37 * @param file open file
34 * @return FileType found, or FileType::Error if this loader doesn't know it 38 * @return FileType found, or FileType::Error if this loader doesn't know it
35 */ 39 */
36 static FileType IdentifyType(const FileSys::VirtualFile& file); 40 static FileType IdentifyType(const FileSys::VirtualFile& file);
diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp
index 25e83af0f..aaa250cea 100644
--- a/src/core/loader/xci.cpp
+++ b/src/core/loader/xci.cpp
@@ -20,18 +20,25 @@
20 20
21namespace Loader { 21namespace Loader {
22 22
23AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file) 23AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file,
24 : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file)), 24 const Service::FileSystem::FileSystemController& fsc,
25 const FileSys::ContentProvider& content_provider,
26 std::size_t program_index)
27 : AppLoader(file), xci(std::make_unique<FileSys::XCI>(file, program_index)),
25 nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) { 28 nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) {
26 if (xci->GetStatus() != ResultStatus::Success) 29 if (xci->GetStatus() != ResultStatus::Success) {
27 return; 30 return;
31 }
28 32
29 const auto control_nca = xci->GetNCAByType(FileSys::NCAContentType::Control); 33 const auto control_nca = xci->GetNCAByType(FileSys::NCAContentType::Control);
30 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) 34 if (control_nca == nullptr || control_nca->GetStatus() != ResultStatus::Success) {
31 return; 35 return;
36 }
32 37
33 std::tie(nacp_file, icon_file) = 38 std::tie(nacp_file, icon_file) = [this, &content_provider, &control_nca, &fsc] {
34 FileSys::PatchManager(xci->GetProgramTitleID()).ParseControlNCA(*control_nca); 39 const FileSys::PatchManager pm{xci->GetProgramTitleID(), fsc, content_provider};
40 return pm.ParseControlNCA(*control_nca);
41 }();
35} 42}
36 43
37AppLoader_XCI::~AppLoader_XCI() = default; 44AppLoader_XCI::~AppLoader_XCI() = default;
diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h
index 04aea286f..9f0ceb5ef 100644
--- a/src/core/loader/xci.h
+++ b/src/core/loader/xci.h
@@ -9,15 +9,16 @@
9#include "core/file_sys/vfs.h" 9#include "core/file_sys/vfs.h"
10#include "core/loader/loader.h" 10#include "core/loader/loader.h"
11 11
12namespace Core {
13class System;
14}
15
16namespace FileSys { 12namespace FileSys {
13class ContentProvider;
17class NACP; 14class NACP;
18class XCI; 15class XCI;
19} // namespace FileSys 16} // namespace FileSys
20 17
18namespace Service::FileSystem {
19class FileSystemController;
20}
21
21namespace Loader { 22namespace Loader {
22 23
23class AppLoader_NCA; 24class AppLoader_NCA;
@@ -25,12 +26,15 @@ class AppLoader_NCA;
25/// Loads an XCI file 26/// Loads an XCI file
26class AppLoader_XCI final : public AppLoader { 27class AppLoader_XCI final : public AppLoader {
27public: 28public:
28 explicit AppLoader_XCI(FileSys::VirtualFile file); 29 explicit AppLoader_XCI(FileSys::VirtualFile file,
30 const Service::FileSystem::FileSystemController& fsc,
31 const FileSys::ContentProvider& content_provider,
32 std::size_t program_index);
29 ~AppLoader_XCI() override; 33 ~AppLoader_XCI() override;
30 34
31 /** 35 /**
32 * Returns the type of the file 36 * Returns the type of the file
33 * @param file std::shared_ptr<VfsFile> open file 37 * @param file open file
34 * @return FileType found, or FileType::Error if this loader doesn't know it 38 * @return FileType found, or FileType::Error if this loader doesn't know it
35 */ 39 */
36 static FileType IdentifyType(const FileSys::VirtualFile& file); 40 static FileType IdentifyType(const FileSys::VirtualFile& file);