core/loaders: Simplify PhysicalMemory usage.
It is currently a std::vector, however we might want to replace it with a more fancy allocator. So we can't use the C++ iterators any more.
This commit is contained in:
		| @@ -335,7 +335,8 @@ Kernel::CodeSet ElfReader::LoadInto(VAddr vaddr) { | |||||||
|             codeset_segment->addr = segment_addr; |             codeset_segment->addr = segment_addr; | ||||||
|             codeset_segment->size = aligned_size; |             codeset_segment->size = aligned_size; | ||||||
|  |  | ||||||
|             memcpy(&program_image[current_image_position], GetSegmentPtr(i), p->p_filesz); |             std::memcpy(program_image.data() + current_image_position, GetSegmentPtr(i), | ||||||
|  |                         p->p_filesz); | ||||||
|             current_image_position += aligned_size; |             current_image_position += aligned_size; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ | |||||||
| // Licensed under GPLv2 or any later version | // Licensed under GPLv2 or any later version | ||||||
| // Refer to the license.txt file included. | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
|  | #include <cstring> | ||||||
| #include "core/file_sys/kernel_executable.h" | #include "core/file_sys/kernel_executable.h" | ||||||
| #include "core/file_sys/program_metadata.h" | #include "core/file_sys/program_metadata.h" | ||||||
| #include "core/gdbstub/gdbstub.h" | #include "core/gdbstub/gdbstub.h" | ||||||
| @@ -76,8 +77,8 @@ AppLoader::LoadResult AppLoader_KIP::Load(Kernel::Process& process) { | |||||||
|         segment.addr = offset; |         segment.addr = offset; | ||||||
|         segment.offset = offset; |         segment.offset = offset; | ||||||
|         segment.size = PageAlignSize(static_cast<u32>(data.size())); |         segment.size = PageAlignSize(static_cast<u32>(data.size())); | ||||||
|         program_image.resize(offset); |         program_image.resize(offset + data.size()); | ||||||
|         program_image.insert(program_image.end(), data.begin(), data.end()); |         std::memcpy(program_image.data() + offset, data.data(), data.size()); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     load_segment(codeset.CodeSegment(), kip->GetTextSection(), kip->GetTextOffset()); |     load_segment(codeset.CodeSegment(), kip->GetTextSection(), kip->GetTextOffset()); | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| // Refer to the license.txt file included. | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
| #include <cinttypes> | #include <cinttypes> | ||||||
|  | #include <cstring> | ||||||
| #include <vector> | #include <vector> | ||||||
|  |  | ||||||
| #include "common/common_funcs.h" | #include "common/common_funcs.h" | ||||||
| @@ -96,8 +97,9 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, | |||||||
|         if (nso_header.IsSegmentCompressed(i)) { |         if (nso_header.IsSegmentCompressed(i)) { | ||||||
|             data = DecompressSegment(data, nso_header.segments[i]); |             data = DecompressSegment(data, nso_header.segments[i]); | ||||||
|         } |         } | ||||||
|         program_image.resize(nso_header.segments[i].location); |         program_image.resize(nso_header.segments[i].location + data.size()); | ||||||
|         program_image.insert(program_image.end(), data.begin(), data.end()); |         std::memcpy(program_image.data() + nso_header.segments[i].location, data.data(), | ||||||
|  |                     data.size()); | ||||||
|         codeset.segments[i].addr = nso_header.segments[i].location; |         codeset.segments[i].addr = nso_header.segments[i].location; | ||||||
|         codeset.segments[i].offset = nso_header.segments[i].location; |         codeset.segments[i].offset = nso_header.segments[i].location; | ||||||
|         codeset.segments[i].size = PageAlignSize(static_cast<u32>(data.size())); |         codeset.segments[i].size = PageAlignSize(static_cast<u32>(data.size())); | ||||||
| @@ -139,12 +141,12 @@ std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, | |||||||
|         std::vector<u8> pi_header; |         std::vector<u8> pi_header; | ||||||
|         pi_header.insert(pi_header.begin(), reinterpret_cast<u8*>(&nso_header), |         pi_header.insert(pi_header.begin(), reinterpret_cast<u8*>(&nso_header), | ||||||
|                          reinterpret_cast<u8*>(&nso_header) + sizeof(NSOHeader)); |                          reinterpret_cast<u8*>(&nso_header) + sizeof(NSOHeader)); | ||||||
|         pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.begin(), |         pi_header.insert(pi_header.begin() + sizeof(NSOHeader), program_image.data(), | ||||||
|                          program_image.end()); |                          program_image.data() + program_image.size()); | ||||||
|  |  | ||||||
|         pi_header = pm->PatchNSO(pi_header, file.GetName()); |         pi_header = pm->PatchNSO(pi_header, file.GetName()); | ||||||
|  |  | ||||||
|         std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.begin()); |         std::copy(pi_header.begin() + sizeof(NSOHeader), pi_header.end(), program_image.data()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Apply cheats if they exist and the program has a valid title ID |     // Apply cheats if they exist and the program has a valid title ID | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user