diff options
| -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 fc71ad189..381530add 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | #include "core/settings.h" | 21 | #include "core/settings.h" |
| 22 | 22 | ||
| 23 | namespace Loader { | 23 | namespace Loader { |
| 24 | 24 | namespace { | |
| 25 | struct MODHeader { | 25 | struct MODHeader { |
| 26 | u32_le magic; | 26 | u32_le magic; |
| 27 | u32_le dynamic_offset; | 27 | u32_le dynamic_offset; |
| @@ -33,6 +33,26 @@ struct MODHeader { | |||
| 33 | }; | 33 | }; |
| 34 | static_assert(sizeof(MODHeader) == 0x1c, "MODHeader has incorrect size."); | 34 | static_assert(sizeof(MODHeader) == 0x1c, "MODHeader has incorrect size."); |
| 35 | 35 | ||
| 36 | std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data, | ||
| 37 | const NSOSegmentHeader& header) { | ||
| 38 | std::vector<u8> uncompressed_data(header.size); | ||
| 39 | const int bytes_uncompressed = | ||
| 40 | LZ4_decompress_safe(reinterpret_cast<const char*>(compressed_data.data()), | ||
| 41 | reinterpret_cast<char*>(uncompressed_data.data()), | ||
| 42 | static_cast<int>(compressed_data.size()), header.size); | ||
| 43 | |||
| 44 | ASSERT_MSG(bytes_uncompressed == static_cast<int>(header.size) && | ||
| 45 | bytes_uncompressed == static_cast<int>(uncompressed_data.size()), | ||
| 46 | "{} != {} != {}", bytes_uncompressed, header.size, uncompressed_data.size()); | ||
| 47 | |||
| 48 | return uncompressed_data; | ||
| 49 | } | ||
| 50 | |||
| 51 | constexpr u32 PageAlignSize(u32 size) { | ||
| 52 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | ||
| 53 | } | ||
| 54 | } // Anonymous namespace | ||
| 55 | |||
| 36 | bool NSOHeader::IsSegmentCompressed(size_t segment_num) const { | 56 | bool NSOHeader::IsSegmentCompressed(size_t segment_num) const { |
| 37 | ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num); | 57 | ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num); |
| 38 | return ((flags >> segment_num) & 1) != 0; | 58 | return ((flags >> segment_num) & 1) != 0; |
| @@ -53,25 +73,6 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { | |||
| 53 | return FileType::NSO; | 73 | return FileType::NSO; |
| 54 | } | 74 | } |
| 55 | 75 | ||
| 56 | static std::vector<u8> DecompressSegment(const std::vector<u8>& compressed_data, | ||
| 57 | const NSOSegmentHeader& header) { | ||
| 58 | std::vector<u8> uncompressed_data(header.size); | ||
| 59 | const int bytes_uncompressed = | ||
| 60 | LZ4_decompress_safe(reinterpret_cast<const char*>(compressed_data.data()), | ||
| 61 | reinterpret_cast<char*>(uncompressed_data.data()), | ||
| 62 | static_cast<int>(compressed_data.size()), header.size); | ||
| 63 | |||
| 64 | ASSERT_MSG(bytes_uncompressed == static_cast<int>(header.size) && | ||
| 65 | bytes_uncompressed == static_cast<int>(uncompressed_data.size()), | ||
| 66 | "{} != {} != {}", bytes_uncompressed, header.size, uncompressed_data.size()); | ||
| 67 | |||
| 68 | return uncompressed_data; | ||
| 69 | } | ||
| 70 | |||
| 71 | static constexpr u32 PageAlignSize(u32 size) { | ||
| 72 | return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; | ||
| 73 | } | ||
| 74 | |||
| 75 | std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, | 76 | std::optional<VAddr> AppLoader_NSO::LoadModule(Kernel::Process& process, |
| 76 | const FileSys::VfsFile& file, VAddr load_base, | 77 | const FileSys::VfsFile& file, VAddr load_base, |
| 77 | bool should_pass_arguments, | 78 | bool should_pass_arguments, |