diff options
| author | 2018-09-30 14:04:48 -0400 | |
|---|---|---|
| committer | 2018-10-07 14:30:15 -0400 | |
| commit | e09505ff6147815d7d3c7adcc0d260638cf49706 (patch) | |
| tree | a430bbf3af585ac0e117c28b5782ee9556a2895a /src/core/loader | |
| parent | Merge pull request #1396 from DarkLordZach/packed-updates (diff) | |
| download | yuzu-e09505ff6147815d7d3c7adcc0d260638cf49706.tar.gz yuzu-e09505ff6147815d7d3c7adcc0d260638cf49706.tar.xz yuzu-e09505ff6147815d7d3c7adcc0d260638cf49706.zip | |
nso/nro: Add NSO arguments structure to data section
Only added if arguments string is non-empty and a pass is requested by loader.
Diffstat (limited to 'src/core/loader')
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 4 | ||||
| -rw-r--r-- | src/core/loader/nro.cpp | 13 | ||||
| -rw-r--r-- | src/core/loader/nso.cpp | 15 | ||||
| -rw-r--r-- | src/core/loader/nso.h | 9 |
4 files changed, 38 insertions, 3 deletions
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 9a86e5824..61808d094 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <cinttypes> | 5 | #include <cinttypes> |
| 6 | #include <cstring> | ||
| 6 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 7 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| 8 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| @@ -140,7 +141,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(Kernel::Process& process) | |||
| 140 | const FileSys::VirtualFile module_file = dir->GetFile(module); | 141 | const FileSys::VirtualFile module_file = dir->GetFile(module); |
| 141 | if (module_file != nullptr) { | 142 | if (module_file != nullptr) { |
| 142 | const VAddr load_addr = next_load_addr; | 143 | const VAddr load_addr = next_load_addr; |
| 143 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr, pm); | 144 | next_load_addr = |
| 145 | AppLoader_NSO::LoadModule(module_file, load_addr, std::strcmp(module, "rtld") == 0, pm); | ||
| 144 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); | 146 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); |
| 145 | // Register module with GDBStub | 147 | // Register module with GDBStub |
| 146 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); | 148 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); |
diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index c10f826a4..4109b9974 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp | |||
| @@ -18,7 +18,9 @@ | |||
| 18 | #include "core/hle/kernel/process.h" | 18 | #include "core/hle/kernel/process.h" |
| 19 | #include "core/hle/kernel/vm_manager.h" | 19 | #include "core/hle/kernel/vm_manager.h" |
| 20 | #include "core/loader/nro.h" | 20 | #include "core/loader/nro.h" |
| 21 | #include "core/loader/nso.h" | ||
| 21 | #include "core/memory.h" | 22 | #include "core/memory.h" |
| 23 | #include "core/settings.h" | ||
| 22 | 24 | ||
| 23 | namespace Loader { | 25 | namespace Loader { |
| 24 | 26 | ||
| @@ -150,6 +152,17 @@ bool AppLoader_NRO::LoadNro(FileSys::VirtualFile file, VAddr load_base) { | |||
| 150 | codeset->segments[i].size = PageAlignSize(nro_header.segments[i].size); | 152 | codeset->segments[i].size = PageAlignSize(nro_header.segments[i].size); |
| 151 | } | 153 | } |
| 152 | 154 | ||
| 155 | if (!Settings::values.program_args.empty()) { | ||
| 156 | const auto arg_data = Settings::values.program_args; | ||
| 157 | codeset->DataSegment().size += 0x9000; | ||
| 158 | NSOArgumentHeader args_header{0x9000, arg_data.size(), {}}; | ||
| 159 | program_image.resize(static_cast<u32>(program_image.size()) + 0x9000); | ||
| 160 | std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header, | ||
| 161 | sizeof(NSOArgumentHeader)); | ||
| 162 | std::memcpy(program_image.data() + program_image.size() - 0x8FE0, arg_data.data(), | ||
| 163 | arg_data.size()); | ||
| 164 | } | ||
| 165 | |||
| 153 | // Read MOD header | 166 | // Read MOD header |
| 154 | ModHeader mod_header{}; | 167 | ModHeader mod_header{}; |
| 155 | // Default .bss to NRO header bss size if MOD0 section doesn't exist | 168 | // Default .bss to NRO header bss size if MOD0 section doesn't exist |
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 2186b02af..8ee2c6f2b 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "core/hle/kernel/vm_manager.h" | 17 | #include "core/hle/kernel/vm_manager.h" |
| 18 | #include "core/loader/nso.h" | 18 | #include "core/loader/nso.h" |
| 19 | #include "core/memory.h" | 19 | #include "core/memory.h" |
| 20 | #include "core/settings.h" | ||
| 20 | 21 | ||
| 21 | namespace Loader { | 22 | namespace Loader { |
| 22 | 23 | ||
| @@ -94,6 +95,7 @@ static constexpr u32 PageAlignSize(u32 size) { | |||
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | 97 | VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, |
| 98 | bool should_pass_arguments, | ||
| 97 | boost::optional<FileSys::PatchManager> pm) { | 99 | boost::optional<FileSys::PatchManager> pm) { |
| 98 | if (file == nullptr) | 100 | if (file == nullptr) |
| 99 | return {}; | 101 | return {}; |
| @@ -125,6 +127,17 @@ VAddr AppLoader_NSO::LoadModule(FileSys::VirtualFile file, VAddr load_base, | |||
| 125 | codeset->segments[i].size = PageAlignSize(static_cast<u32>(data.size())); | 127 | codeset->segments[i].size = PageAlignSize(static_cast<u32>(data.size())); |
| 126 | } | 128 | } |
| 127 | 129 | ||
| 130 | if (should_pass_arguments && !Settings::values.program_args.empty()) { | ||
| 131 | const auto arg_data = Settings::values.program_args; | ||
| 132 | codeset->DataSegment().size += 0x9000; | ||
| 133 | NSOArgumentHeader args_header{0x9000, arg_data.size(), {}}; | ||
| 134 | program_image.resize(static_cast<u32>(program_image.size()) + 0x9000); | ||
| 135 | std::memcpy(program_image.data() + program_image.size() - 0x9000, &args_header, | ||
| 136 | sizeof(NSOArgumentHeader)); | ||
| 137 | std::memcpy(program_image.data() + program_image.size() - 0x8FE0, arg_data.data(), | ||
| 138 | arg_data.size()); | ||
| 139 | } | ||
| 140 | |||
| 128 | // MOD header pointer is at .text offset + 4 | 141 | // MOD header pointer is at .text offset + 4 |
| 129 | u32 module_offset; | 142 | u32 module_offset; |
| 130 | std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32)); | 143 | std::memcpy(&module_offset, program_image.data() + 4, sizeof(u32)); |
| @@ -172,7 +185,7 @@ ResultStatus AppLoader_NSO::Load(Kernel::Process& process) { | |||
| 172 | 185 | ||
| 173 | // Load module | 186 | // Load module |
| 174 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); | 187 | const VAddr base_address = process.VMManager().GetCodeRegionBaseAddress(); |
| 175 | LoadModule(file, base_address); | 188 | LoadModule(file, base_address, true); |
| 176 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); | 189 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", file->GetName(), base_address); |
| 177 | 190 | ||
| 178 | process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); | 191 | process.Run(base_address, Kernel::THREADPRIO_DEFAULT, Memory::DEFAULT_STACK_SIZE); |
diff --git a/src/core/loader/nso.h b/src/core/loader/nso.h index 05353d4d9..7833af6ee 100644 --- a/src/core/loader/nso.h +++ b/src/core/loader/nso.h | |||
| @@ -11,6 +11,13 @@ | |||
| 11 | 11 | ||
| 12 | namespace Loader { | 12 | namespace Loader { |
| 13 | 13 | ||
| 14 | struct NSOArgumentHeader { | ||
| 15 | u32_le allocated_size; | ||
| 16 | u32_le actual_size; | ||
| 17 | INSERT_PADDING_BYTES(0x18); | ||
| 18 | }; | ||
| 19 | static_assert(sizeof(NSOArgumentHeader) == 0x20, "NSOArgumentHeader has incorrect size."); | ||
| 20 | |||
| 14 | /// Loads an NSO file | 21 | /// Loads an NSO file |
| 15 | class AppLoader_NSO final : public AppLoader, Linker { | 22 | class AppLoader_NSO final : public AppLoader, Linker { |
| 16 | public: | 23 | public: |
| @@ -27,7 +34,7 @@ public: | |||
| 27 | return IdentifyType(file); | 34 | return IdentifyType(file); |
| 28 | } | 35 | } |
| 29 | 36 | ||
| 30 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, | 37 | static VAddr LoadModule(FileSys::VirtualFile file, VAddr load_base, bool should_pass_arguments, |
| 31 | boost::optional<FileSys::PatchManager> pm = boost::none); | 38 | boost::optional<FileSys::PatchManager> pm = boost::none); |
| 32 | 39 | ||
| 33 | ResultStatus Load(Kernel::Process& process) override; | 40 | ResultStatus Load(Kernel::Process& process) override; |