diff options
Diffstat (limited to 'src')
5 files changed, 28 insertions, 54 deletions
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp index b2e031d5f..4a75b5308 100644 --- a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp | |||
| @@ -17,8 +17,6 @@ Result HierarchicalIntegrityVerificationStorage::Initialize( | |||
| 17 | const HierarchicalIntegrityVerificationInformation& info, | 17 | const HierarchicalIntegrityVerificationInformation& info, |
| 18 | HierarchicalStorageInformation storage, int max_data_cache_entries, int max_hash_cache_entries, | 18 | HierarchicalStorageInformation storage, int max_data_cache_entries, int max_hash_cache_entries, |
| 19 | s8 buffer_level) { | 19 | s8 buffer_level) { |
| 20 | using AlignedStorage = AlignmentMatchingStoragePooledBuffer<1>; | ||
| 21 | |||
| 22 | // Validate preconditions. | 20 | // Validate preconditions. |
| 23 | ASSERT(IntegrityMinLayerCount <= info.max_layers && info.max_layers <= IntegrityMaxLayerCount); | 21 | ASSERT(IntegrityMinLayerCount <= info.max_layers && info.max_layers <= IntegrityMaxLayerCount); |
| 24 | 22 | ||
| @@ -38,8 +36,7 @@ Result HierarchicalIntegrityVerificationStorage::Initialize( | |||
| 38 | }; | 36 | }; |
| 39 | 37 | ||
| 40 | // Initialize the top level buffer storage. | 38 | // Initialize the top level buffer storage. |
| 41 | m_buffer_storages[0] = std::make_shared<AlignedStorage>( | 39 | m_buffer_storages[0] = m_verify_storages[0]; |
| 42 | m_verify_storages[0], static_cast<s64>(1) << info.info[0].block_order); | ||
| 43 | R_UNLESS(m_buffer_storages[0] != nullptr, ResultAllocationMemoryFailedAllocateShared); | 40 | R_UNLESS(m_buffer_storages[0] != nullptr, ResultAllocationMemoryFailedAllocateShared); |
| 44 | 41 | ||
| 45 | // Prepare to initialize the level storages. | 42 | // Prepare to initialize the level storages. |
| @@ -65,8 +62,7 @@ Result HierarchicalIntegrityVerificationStorage::Initialize( | |||
| 65 | static_cast<s64>(1) << info.info[level].block_order, false); | 62 | static_cast<s64>(1) << info.info[level].block_order, false); |
| 66 | 63 | ||
| 67 | // Initialize the buffer storage. | 64 | // Initialize the buffer storage. |
| 68 | m_buffer_storages[level + 1] = std::make_shared<AlignedStorage>( | 65 | m_buffer_storages[level + 1] = m_verify_storages[level + 1]; |
| 69 | m_verify_storages[level + 1], static_cast<s64>(1) << info.info[level + 1].block_order); | ||
| 70 | R_UNLESS(m_buffer_storages[level + 1] != nullptr, | 66 | R_UNLESS(m_buffer_storages[level + 1] != nullptr, |
| 71 | ResultAllocationMemoryFailedAllocateShared); | 67 | ResultAllocationMemoryFailedAllocateShared); |
| 72 | } | 68 | } |
| @@ -82,8 +78,7 @@ Result HierarchicalIntegrityVerificationStorage::Initialize( | |||
| 82 | static_cast<s64>(1) << info.info[level].block_order, true); | 78 | static_cast<s64>(1) << info.info[level].block_order, true); |
| 83 | 79 | ||
| 84 | // Initialize the buffer storage. | 80 | // Initialize the buffer storage. |
| 85 | m_buffer_storages[level + 1] = std::make_shared<AlignedStorage>( | 81 | m_buffer_storages[level + 1] = m_verify_storages[level + 1]; |
| 86 | m_verify_storages[level + 1], static_cast<s64>(1) << info.info[level + 1].block_order); | ||
| 87 | R_UNLESS(m_buffer_storages[level + 1] != nullptr, | 82 | R_UNLESS(m_buffer_storages[level + 1] != nullptr, |
| 88 | ResultAllocationMemoryFailedAllocateShared); | 83 | ResultAllocationMemoryFailedAllocateShared); |
| 89 | } | 84 | } |
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h index 5e0a1d143..3d216e4ae 100644 --- a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h +++ b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h | |||
| @@ -123,7 +123,7 @@ private: | |||
| 123 | 123 | ||
| 124 | private: | 124 | private: |
| 125 | std::shared_ptr<IntegrityVerificationStorage> m_verify_storages[MaxLayers - 1]; | 125 | std::shared_ptr<IntegrityVerificationStorage> m_verify_storages[MaxLayers - 1]; |
| 126 | std::shared_ptr<AlignmentMatchingStoragePooledBuffer<1>> m_buffer_storages[MaxLayers - 1]; | 126 | VirtualFile m_buffer_storages[MaxLayers - 1]; |
| 127 | s64 m_data_size; | 127 | s64 m_data_size; |
| 128 | s32 m_max_layers; | 128 | s32 m_max_layers; |
| 129 | 129 | ||
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp index 357fa7741..caea0b8f8 100644 --- a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.cpp | |||
| @@ -73,31 +73,8 @@ size_t HierarchicalSha256Storage::Read(u8* buffer, size_t size, size_t offset) c | |||
| 73 | // Validate that we have a buffer to read into. | 73 | // Validate that we have a buffer to read into. |
| 74 | ASSERT(buffer != nullptr); | 74 | ASSERT(buffer != nullptr); |
| 75 | 75 | ||
| 76 | // Validate preconditions. | ||
| 77 | ASSERT(Common::IsAligned(offset, m_hash_target_block_size)); | ||
| 78 | ASSERT(Common::IsAligned(size, m_hash_target_block_size)); | ||
| 79 | |||
| 80 | // Read the data. | 76 | // Read the data. |
| 81 | const size_t reduced_size = static_cast<size_t>( | 77 | return m_base_storage->Read(buffer, size, offset); |
| 82 | std::min<s64>(m_base_storage_size, | ||
| 83 | Common::AlignUp(offset + size, m_hash_target_block_size)) - | ||
| 84 | offset); | ||
| 85 | m_base_storage->Read(buffer, reduced_size, offset); | ||
| 86 | |||
| 87 | // Setup tracking variables. | ||
| 88 | auto cur_offset = offset; | ||
| 89 | auto remaining_size = reduced_size; | ||
| 90 | while (remaining_size > 0) { | ||
| 91 | const auto cur_size = | ||
| 92 | static_cast<size_t>(std::min<s64>(m_hash_target_block_size, remaining_size)); | ||
| 93 | ASSERT(static_cast<size_t>(cur_offset >> m_log_size_ratio) < m_hash_buffer_size); | ||
| 94 | |||
| 95 | // Advance. | ||
| 96 | cur_offset += cur_size; | ||
| 97 | remaining_size -= cur_size; | ||
| 98 | } | ||
| 99 | |||
| 100 | return size; | ||
| 101 | } | 78 | } |
| 102 | 79 | ||
| 103 | } // namespace FileSys | 80 | } // namespace FileSys |
diff --git a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp index ef36b755e..0dba0c8d9 100644 --- a/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_integrity_verification_storage.cpp | |||
| @@ -48,10 +48,6 @@ void IntegrityVerificationStorage::Finalize() { | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const { | 50 | size_t IntegrityVerificationStorage::Read(u8* buffer, size_t size, size_t offset) const { |
| 51 | // Validate preconditions. | ||
| 52 | ASSERT(Common::IsAligned(offset, static_cast<size_t>(m_verification_block_size))); | ||
| 53 | ASSERT(Common::IsAligned(size, static_cast<size_t>(m_verification_block_size))); | ||
| 54 | |||
| 55 | // Succeed if zero size. | 51 | // Succeed if zero size. |
| 56 | if (size == 0) { | 52 | if (size == 0) { |
| 57 | return size; | 53 | return size; |
diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp index b1b5fb156..450135ae0 100644 --- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp +++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp | |||
| @@ -508,12 +508,15 @@ Result NcaFileSystemDriver::CreateSparseStorageMetaStorage(VirtualFile* out, | |||
| 508 | offset + meta_offset, sparse_info.MakeAesCtrUpperIv(upper_iv), | 508 | offset + meta_offset, sparse_info.MakeAesCtrUpperIv(upper_iv), |
| 509 | AlignmentStorageRequirement::None)); | 509 | AlignmentStorageRequirement::None)); |
| 510 | 510 | ||
| 511 | // Create meta storage. | 511 | // Create buffered storage. |
| 512 | auto meta_storage = std::make_shared<OffsetVfsFile>(decrypted_storage, meta_size, 0); | 512 | std::vector<u8> meta_data(meta_size); |
| 513 | R_UNLESS(meta_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | 513 | decrypted_storage->Read(meta_data.data(), meta_size, 0); |
| 514 | |||
| 515 | auto buffered_storage = std::make_shared<VectorVfsFile>(std::move(meta_data)); | ||
| 516 | R_UNLESS(buffered_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | ||
| 514 | 517 | ||
| 515 | // Set the output. | 518 | // Set the output. |
| 516 | *out = std::move(meta_storage); | 519 | *out = std::move(buffered_storage); |
| 517 | R_SUCCEED(); | 520 | R_SUCCEED(); |
| 518 | } | 521 | } |
| 519 | 522 | ||
| @@ -817,13 +820,15 @@ Result NcaFileSystemDriver::CreateAesCtrExStorageMetaStorage( | |||
| 817 | auto meta_storage = std::make_shared<OffsetVfsFile>(decrypted_storage, meta_size, 0); | 820 | auto meta_storage = std::make_shared<OffsetVfsFile>(decrypted_storage, meta_size, 0); |
| 818 | R_UNLESS(meta_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | 821 | R_UNLESS(meta_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); |
| 819 | 822 | ||
| 820 | // Create an alignment-matching storage. | 823 | // Create buffered storage. |
| 821 | using AlignedStorage = AlignmentMatchingStorage<NcaHeader::CtrBlockSize, 1>; | 824 | std::vector<u8> meta_data(meta_size); |
| 822 | auto aligned_storage = std::make_shared<AlignedStorage>(std::move(meta_storage)); | 825 | meta_storage->Read(meta_data.data(), meta_size, 0); |
| 823 | R_UNLESS(aligned_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | 826 | |
| 827 | auto buffered_storage = std::make_shared<VectorVfsFile>(std::move(meta_data)); | ||
| 828 | R_UNLESS(buffered_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | ||
| 824 | 829 | ||
| 825 | // Set the output. | 830 | // Set the output. |
| 826 | *out = std::move(aligned_storage); | 831 | *out = std::move(buffered_storage); |
| 827 | R_SUCCEED(); | 832 | R_SUCCEED(); |
| 828 | } | 833 | } |
| 829 | 834 | ||
| @@ -937,8 +942,15 @@ Result NcaFileSystemDriver::CreateIndirectStorageMetaStorage(VirtualFile* out, | |||
| 937 | patch_info.indirect_offset); | 942 | patch_info.indirect_offset); |
| 938 | R_UNLESS(meta_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | 943 | R_UNLESS(meta_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); |
| 939 | 944 | ||
| 945 | // Create buffered storage. | ||
| 946 | std::vector<u8> meta_data(patch_info.indirect_size); | ||
| 947 | meta_storage->Read(meta_data.data(), patch_info.indirect_size, 0); | ||
| 948 | |||
| 949 | auto buffered_storage = std::make_shared<VectorVfsFile>(std::move(meta_data)); | ||
| 950 | R_UNLESS(buffered_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | ||
| 951 | |||
| 940 | // Set the output. | 952 | // Set the output. |
| 941 | *out = std::move(meta_storage); | 953 | *out = std::move(buffered_storage); |
| 942 | R_SUCCEED(); | 954 | R_SUCCEED(); |
| 943 | } | 955 | } |
| 944 | 956 | ||
| @@ -1090,7 +1102,6 @@ Result NcaFileSystemDriver::CreateSha256Storage( | |||
| 1090 | 1102 | ||
| 1091 | // Define storage types. | 1103 | // Define storage types. |
| 1092 | using VerificationStorage = HierarchicalSha256Storage; | 1104 | using VerificationStorage = HierarchicalSha256Storage; |
| 1093 | using AlignedStorage = AlignmentMatchingStoragePooledBuffer<1>; | ||
| 1094 | 1105 | ||
| 1095 | // Validate the hash data. | 1106 | // Validate the hash data. |
| 1096 | R_UNLESS(Common::IsPowerOfTwo(hash_data.hash_block_size), | 1107 | R_UNLESS(Common::IsPowerOfTwo(hash_data.hash_block_size), |
| @@ -1141,13 +1152,8 @@ Result NcaFileSystemDriver::CreateSha256Storage( | |||
| 1141 | hash_data.hash_block_size, | 1152 | hash_data.hash_block_size, |
| 1142 | buffer_hold_storage->GetBuffer(), hash_buffer_size)); | 1153 | buffer_hold_storage->GetBuffer(), hash_buffer_size)); |
| 1143 | 1154 | ||
| 1144 | // Make the aligned storage. | ||
| 1145 | auto aligned_storage = std::make_shared<AlignedStorage>(std::move(verification_storage), | ||
| 1146 | hash_data.hash_block_size); | ||
| 1147 | R_UNLESS(aligned_storage != nullptr, ResultAllocationMemoryFailedAllocateShared); | ||
| 1148 | |||
| 1149 | // Set the output. | 1155 | // Set the output. |
| 1150 | *out = std::move(aligned_storage); | 1156 | *out = std::move(verification_storage); |
| 1151 | R_SUCCEED(); | 1157 | R_SUCCEED(); |
| 1152 | } | 1158 | } |
| 1153 | 1159 | ||