From f3297d8cd1b8e25f5f2dc887053c8b6001dcdf66 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 22 Mar 2019 14:00:01 -0400 Subject: [PATCH] loader/nso: Place translation unit specific functions into an anonymous namespace Makes it impossible to indirectly violate the ODR in some other translation unit due to these existing. --- src/core/loader/nso.cpp | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index fc71ad1899..381530addb 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -21,7 +21,7 @@ #include "core/settings.h" namespace Loader { - +namespace { struct MODHeader { u32_le magic; u32_le dynamic_offset; @@ -33,6 +33,26 @@ struct MODHeader { }; static_assert(sizeof(MODHeader) == 0x1c, "MODHeader has incorrect size."); +std::vector DecompressSegment(const std::vector& compressed_data, + const NSOSegmentHeader& header) { + std::vector uncompressed_data(header.size); + const int bytes_uncompressed = + LZ4_decompress_safe(reinterpret_cast(compressed_data.data()), + reinterpret_cast(uncompressed_data.data()), + static_cast(compressed_data.size()), header.size); + + ASSERT_MSG(bytes_uncompressed == static_cast(header.size) && + bytes_uncompressed == static_cast(uncompressed_data.size()), + "{} != {} != {}", bytes_uncompressed, header.size, uncompressed_data.size()); + + return uncompressed_data; +} + +constexpr u32 PageAlignSize(u32 size) { + return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; +} +} // Anonymous namespace + bool NSOHeader::IsSegmentCompressed(size_t segment_num) const { ASSERT_MSG(segment_num < 3, "Invalid segment {}", segment_num); return ((flags >> segment_num) & 1) != 0; @@ -53,25 +73,6 @@ FileType AppLoader_NSO::IdentifyType(const FileSys::VirtualFile& file) { return FileType::NSO; } -static std::vector DecompressSegment(const std::vector& compressed_data, - const NSOSegmentHeader& header) { - std::vector uncompressed_data(header.size); - const int bytes_uncompressed = - LZ4_decompress_safe(reinterpret_cast(compressed_data.data()), - reinterpret_cast(uncompressed_data.data()), - static_cast(compressed_data.size()), header.size); - - ASSERT_MSG(bytes_uncompressed == static_cast(header.size) && - bytes_uncompressed == static_cast(uncompressed_data.size()), - "{} != {} != {}", bytes_uncompressed, header.size, uncompressed_data.size()); - - return uncompressed_data; -} - -static constexpr u32 PageAlignSize(u32 size) { - return (size + Memory::PAGE_MASK) & ~Memory::PAGE_MASK; -} - std::optional AppLoader_NSO::LoadModule(Kernel::Process& process, const FileSys::VfsFile& file, VAddr load_base, bool should_pass_arguments,