diff options
Diffstat (limited to 'src/core/loader/nso.cpp')
| -rw-r--r-- | src/core/loader/nso.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index b053a0d14..583b7e927 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -77,7 +77,8 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core:: | |||
| 77 | const FileSys::VfsFile& nso_file, VAddr load_base, | 77 | const FileSys::VfsFile& nso_file, VAddr load_base, |
| 78 | bool should_pass_arguments, bool load_into_process, | 78 | bool should_pass_arguments, bool load_into_process, |
| 79 | std::optional<FileSys::PatchManager> pm, | 79 | std::optional<FileSys::PatchManager> pm, |
| 80 | Core::NCE::Patcher* patch) { | 80 | std::vector<Core::NCE::Patcher>* patches, |
| 81 | s32 patch_index) { | ||
| 81 | if (nso_file.GetSize() < sizeof(NSOHeader)) { | 82 | if (nso_file.GetSize() < sizeof(NSOHeader)) { |
| 82 | return std::nullopt; | 83 | return std::nullopt; |
| 83 | } | 84 | } |
| @@ -94,8 +95,11 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core:: | |||
| 94 | // Allocate some space at the beginning if we are patching in PreText mode. | 95 | // Allocate some space at the beginning if we are patching in PreText mode. |
| 95 | const size_t module_start = [&]() -> size_t { | 96 | const size_t module_start = [&]() -> size_t { |
| 96 | #ifdef HAS_NCE | 97 | #ifdef HAS_NCE |
| 97 | if (patch && patch->GetPatchMode() == Core::NCE::PatchMode::PreText) { | 98 | if (patches && load_into_process) { |
| 98 | return patch->GetSectionSize(); | 99 | auto* patch = &patches->operator[](patch_index); |
| 100 | if (patch->GetPatchMode() == Core::NCE::PatchMode::PreText) { | ||
| 101 | return patch->GetSectionSize(); | ||
| 102 | } | ||
| 99 | } | 103 | } |
| 100 | #endif | 104 | #endif |
| 101 | return 0; | 105 | return 0; |
| @@ -160,27 +164,24 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::KProcess& process, Core:: | |||
| 160 | #ifdef HAS_NCE | 164 | #ifdef HAS_NCE |
| 161 | // If we are computing the process code layout and using nce backend, patch. | 165 | // If we are computing the process code layout and using nce backend, patch. |
| 162 | const auto& code = codeset.CodeSegment(); | 166 | const auto& code = codeset.CodeSegment(); |
| 163 | if (patch && patch->GetPatchMode() == Core::NCE::PatchMode::None) { | 167 | auto* patch = patches ? &patches->operator[](patch_index) : nullptr; |
| 168 | if (patch && !load_into_process) { | ||
| 164 | // Patch SVCs and MRS calls in the guest code | 169 | // Patch SVCs and MRS calls in the guest code |
| 165 | patch->PatchText(program_image, code); | 170 | while (!patch->PatchText(program_image, code)) { |
| 166 | 171 | patch = &patches->emplace_back(); | |
| 167 | // Add patch section size to the module size. | 172 | } |
| 168 | image_size += static_cast<u32>(patch->GetSectionSize()); | ||
| 169 | } else if (patch) { | 173 | } else if (patch) { |
| 170 | // Relocate code patch and copy to the program_image. | 174 | // Relocate code patch and copy to the program_image. |
| 171 | patch->RelocateAndCopy(load_base, code, program_image, &process.GetPostHandlers()); | 175 | if (patch->RelocateAndCopy(load_base, code, program_image, &process.GetPostHandlers())) { |
| 172 | 176 | // Update patch section. | |
| 173 | // Update patch section. | 177 | auto& patch_segment = codeset.PatchSegment(); |
| 174 | auto& patch_segment = codeset.PatchSegment(); | 178 | patch_segment.addr = |
| 175 | patch_segment.addr = | 179 | patch->GetPatchMode() == Core::NCE::PatchMode::PreText ? 0 : image_size; |
| 176 | patch->GetPatchMode() == Core::NCE::PatchMode::PreText ? 0 : image_size; | 180 | patch_segment.size = static_cast<u32>(patch->GetSectionSize()); |
| 177 | patch_segment.size = static_cast<u32>(patch->GetSectionSize()); | ||
| 178 | |||
| 179 | // Add patch section size to the module size. In PreText mode image_size | ||
| 180 | // already contains the patch segment as part of module_start. | ||
| 181 | if (patch->GetPatchMode() == Core::NCE::PatchMode::PostData) { | ||
| 182 | image_size += patch_segment.size; | ||
| 183 | } | 181 | } |
| 182 | |||
| 183 | // Refresh image_size to take account the patch section if it was added by RelocateAndCopy | ||
| 184 | image_size = static_cast<u32>(program_image.size()); | ||
| 184 | } | 185 | } |
| 185 | #endif | 186 | #endif |
| 186 | 187 | ||