diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/file_sys/program_metadata.cpp | 11 | ||||
| -rw-r--r-- | src/core/file_sys/program_metadata.h | 6 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 5 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 23 | ||||
| -rw-r--r-- | src/core/loader/nro.h | 2 |
5 files changed, 35 insertions, 12 deletions
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp index 1d6c30962..43169bf9f 100644 --- a/src/core/file_sys/program_metadata.cpp +++ b/src/core/file_sys/program_metadata.cpp | |||
| @@ -51,6 +51,17 @@ Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { | |||
| 51 | return Loader::ResultStatus::Success; | 51 | return Loader::ResultStatus::Success; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | /*static*/ ProgramMetadata ProgramMetadata::GetDefault() { | ||
| 55 | ProgramMetadata result; | ||
| 56 | |||
| 57 | result.LoadManual( | ||
| 58 | true /*is_64_bit*/, FileSys::ProgramAddressSpaceType::Is39Bit /*address_space*/, | ||
| 59 | 0x2c /*main_thread_prio*/, 0 /*main_thread_core*/, 0x00100000 /*main_thread_stack_size*/, | ||
| 60 | {}, 0xFFFFFFFFFFFFFFFF /*filesystem_permissions*/, {} /*capabilities*/); | ||
| 61 | |||
| 62 | return result; | ||
| 63 | } | ||
| 64 | |||
| 54 | void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, | 65 | void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, |
| 55 | s32 main_thread_prio, u32 main_thread_core, | 66 | s32 main_thread_prio, u32 main_thread_core, |
| 56 | u32 main_thread_stack_size, u64 title_id, | 67 | u32 main_thread_stack_size, u64 title_id, |
diff --git a/src/core/file_sys/program_metadata.h b/src/core/file_sys/program_metadata.h index f8759a396..35069972b 100644 --- a/src/core/file_sys/program_metadata.h +++ b/src/core/file_sys/program_metadata.h | |||
| @@ -44,9 +44,13 @@ public: | |||
| 44 | ProgramMetadata(); | 44 | ProgramMetadata(); |
| 45 | ~ProgramMetadata(); | 45 | ~ProgramMetadata(); |
| 46 | 46 | ||
| 47 | /// Gets a default ProgramMetadata configuration, should only be used for homebrew formats where | ||
| 48 | /// we do not have an NPDM file | ||
| 49 | static ProgramMetadata GetDefault(); | ||
| 50 | |||
| 47 | Loader::ResultStatus Load(VirtualFile file); | 51 | Loader::ResultStatus Load(VirtualFile file); |
| 48 | 52 | ||
| 49 | // Load from parameters instead of NPDM file, used for KIP | 53 | /// Load from parameters instead of NPDM file, used for KIP |
| 50 | void LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, s32 main_thread_prio, | 54 | void LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, s32 main_thread_prio, |
| 51 | u32 main_thread_core, u32 main_thread_stack_size, u64 title_id, | 55 | u32 main_thread_core, u32 main_thread_stack_size, u64 title_id, |
| 52 | u64 filesystem_permissions, KernelCapabilityDescriptors capabilities); | 56 | u64 filesystem_permissions, KernelCapabilityDescriptors capabilities); |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 1e9ed2837..8f7615115 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -398,6 +398,11 @@ AppLoader_ELF::LoadResult AppLoader_ELF::Load(Kernel::Process& process) { | |||
| 398 | Kernel::CodeSet codeset = elf_reader.LoadInto(base_address); | 398 | Kernel::CodeSet codeset = elf_reader.LoadInto(base_address); |
| 399 | const VAddr entry_point = codeset.entrypoint; | 399 | const VAddr entry_point = codeset.entrypoint; |
| 400 | 400 | ||
| 401 | // Setup the process code layout | ||
| 402 | if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), buffer.size()).IsError()) { | ||
| 403 | return {ResultStatus::ErrorNotInitialized, {}}; | ||
| 404 | } | ||
| 405 | |||
| 401 | process.LoadModule(std::move(codeset), entry_point); | 406 | process.LoadModule(std::move(codeset), entry_point); |
| 402 | 407 | ||
| 403 | is_loaded = true; | 408 | is_loaded = true; |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 5d7e8136e..906544bc9 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -131,7 +131,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, | 133 | static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, |
| 134 | const std::string& name, VAddr load_base) { | 134 | const std::string& name) { |
| 135 | if (data.size() < sizeof(NroHeader)) { | 135 | if (data.size() < sizeof(NroHeader)) { |
| 136 | return {}; | 136 | return {}; |
| 137 | } | 137 | } |
| @@ -187,19 +187,25 @@ static bool LoadNroImpl(Kernel::Process& process, const std::vector<u8>& data, | |||
| 187 | codeset.DataSegment().size += bss_size; | 187 | codeset.DataSegment().size += bss_size; |
| 188 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); | 188 | program_image.resize(static_cast<u32>(program_image.size()) + bss_size); |
| 189 | 189 | ||
| 190 | // Setup the process code layout | ||
| 191 | if (process.LoadFromMetadata(FileSys::ProgramMetadata::GetDefault(), program_image.size()) | ||
| 192 | .IsError()) { | ||
| 193 | return false; | ||
| 194 | } | ||
| 195 | |||
| 190 | // Load codeset for current process | 196 | // Load codeset for current process |
| 191 | codeset.memory = std::move(program_image); | 197 | codeset.memory = std::move(program_image); |
| 192 | process.LoadModule(std::move(codeset), load_base); | 198 | process.LoadModule(std::move(codeset), process.PageTable().GetCodeRegionStart()); |
| 193 | 199 | ||
| 194 | // Register module with GDBStub | 200 | // Register module with GDBStub |
| 195 | GDBStub::RegisterModule(name, load_base, load_base); | 201 | GDBStub::RegisterModule(name, process.PageTable().GetCodeRegionStart(), |
| 202 | process.PageTable().GetCodeRegionEnd()); | ||
| 196 | 203 | ||
| 197 | return true; | 204 | return true; |
| 198 | } | 205 | } |
| 199 | 206 | ||
| 200 | bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, | 207 | bool AppLoader_NRO::LoadNro(Kernel::Process& process, const FileSys::VfsFile& file) { |
| 201 | VAddr load_base) { | 208 | return LoadNroImpl(process, file.ReadAllBytes(), file.GetName()); |
| 202 | return LoadNroImpl(process, file.ReadAllBytes(), file.GetName(), load_base); | ||
| 203 | } | 209 | } |
| 204 | 210 | ||
| 205 | AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) { | 211 | AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) { |
| @@ -207,10 +213,7 @@ AppLoader_NRO::LoadResult AppLoader_NRO::Load(Kernel::Process& process) { | |||
| 207 | return {ResultStatus::ErrorAlreadyLoaded, {}}; | 213 | return {ResultStatus::ErrorAlreadyLoaded, {}}; |
| 208 | } | 214 | } |
| 209 | 215 | ||
| 210 | // Load NRO | 216 | if (!LoadNro(process, *file)) { |
| 211 | const VAddr base_address = process.PageTable().GetCodeRegionStart(); | ||
| 212 | |||
| 213 | if (!LoadNro(process, *file, base_address)) { | ||
| 214 | return {ResultStatus::ErrorLoadingNRO, {}}; | 217 | return {ResultStatus::ErrorLoadingNRO, {}}; |
| 215 | } | 218 | } |
| 216 | 219 | ||
diff --git a/src/core/loader/nro.h b/src/core/loader/nro.h index 71811bc29..4593d48fb 100644 --- a/src/core/loader/nro.h +++ b/src/core/loader/nro.h | |||
| @@ -47,7 +47,7 @@ public: | |||
| 47 | bool IsRomFSUpdatable() const override; | 47 | bool IsRomFSUpdatable() const override; |
| 48 | 48 | ||
| 49 | private: | 49 | private: |
| 50 | bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base); | 50 | bool LoadNro(Kernel::Process& process, const FileSys::VfsFile& file); |
| 51 | 51 | ||
| 52 | std::vector<u8> icon_data; | 52 | std::vector<u8> icon_data; |
| 53 | std::unique_ptr<FileSys::NACP> nacp; | 53 | std::unique_ptr<FileSys::NACP> nacp; |