libstrat: enable -Wextra, -Werror

This caught an embarrassingly large number of bugs.
This commit is contained in:
Michael Scire
2021-10-06 15:20:48 -07:00
parent e1fbf27398
commit 7ca83c9d3b
160 changed files with 691 additions and 152 deletions

View File

@@ -127,6 +127,8 @@ namespace ams::fssystem {
}
bool FileSystemBufferManager::CacheHandleTable::UnregisterOldest(uintptr_t *out_address, size_t *out_size, const BufferAttribute &attr, size_t required_size) {
AMS_UNUSED(attr, required_size);
/* Validate pre-conditions. */
AMS_ASSERT(this->entries != nullptr);
AMS_ASSERT(out_address != nullptr);

View File

@@ -261,6 +261,7 @@ namespace ams::fssystem {
AMS_ASSERT(enc_key_size == KeySize);
AMS_ASSERT(iv != nullptr);
AMS_ASSERT(iv_size == IvSize);
AMS_UNUSED(iv_size);
/* Copy the ctr. */
u8 ctr[IvSize];

View File

@@ -22,6 +22,7 @@ namespace ams::fssystem {
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(dst_size == IvSize);
AMS_ASSERT(offset >= 0);
AMS_UNUSED(dst_size);
const uintptr_t out_addr = reinterpret_cast<uintptr_t>(dst);
@@ -35,6 +36,7 @@ namespace ams::fssystem {
AMS_ASSERT(iv != nullptr);
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(iv_size == IvSize);
AMS_UNUSED(key_size, iv_size);
std::memcpy(this->key, key, KeySize);
std::memcpy(this->iv, iv, IvSize);
@@ -127,6 +129,7 @@ namespace ams::fssystem {
}
Result AesCtrStorage::SetSize(s64 size) {
AMS_UNUSED(size);
return fs::ResultUnsupportedOperationInAesCtrStorageA();
}

View File

@@ -25,6 +25,7 @@ namespace ams::fssystem {
AMS_ASSERT(key_size == KeySize);
AMS_ASSERT(iv_size == IvSize);
AMS_ASSERT(util::IsAligned(this->block_size, AesBlockSize));
AMS_UNUSED(key_size, iv_size);
std::memcpy(this->key[0], key1, KeySize);
std::memcpy(this->key[1], key2, KeySize);

View File

@@ -39,6 +39,7 @@ namespace ams::fssystem {
Result AlignmentMatchingStorageImpl::Read(fs::IStorage *base_storage, char *work_buf, size_t work_buf_size, size_t data_alignment, size_t buffer_alignment, s64 offset, char *buffer, size_t size) {
/* Check preconditions. */
AMS_ASSERT(work_buf_size >= data_alignment);
AMS_UNUSED(work_buf_size);
/* Succeed if zero size. */
R_SUCCEED_IF(size == 0);
@@ -120,6 +121,7 @@ namespace ams::fssystem {
Result AlignmentMatchingStorageImpl::Write(fs::IStorage *base_storage, char *work_buf, size_t work_buf_size, size_t data_alignment, size_t buffer_alignment, s64 offset, const char *buffer, size_t size) {
/* Check preconditions. */
AMS_ASSERT(work_buf_size >= data_alignment);
AMS_UNUSED(work_buf_size);
/* Succeed if zero size. */
R_SUCCEED_IF(size == 0);

View File

@@ -29,6 +29,7 @@ namespace ams::fssystem {
}
void DefaultDeallocate(void *ptr, size_t size) {
AMS_UNUSED(size);
std::free(ptr);
}

View File

@@ -130,6 +130,8 @@ namespace ams::fssystem {
}
void GenerateNcaKey(void *dst, size_t dst_size, const void *src, size_t src_size, s32 key_type, const NcaCryptoConfiguration &cfg) {
AMS_UNUSED(cfg);
R_ABORT_UNLESS(spl::GenerateAesKey(dst, dst_size, GetNcaKekAccessKey(key_type), src, src_size));
}

View File

@@ -240,6 +240,7 @@ namespace ams::fssystem {
/* Overridden from IPathResolutionFileSystem but not commands. */
Result DirectorySaveDataFileSystem::DoCommitProvisionally(s64 counter) {
/* Nintendo does nothing here. */
AMS_UNUSED(counter);
return ResultSuccess();
}
@@ -250,18 +251,22 @@ namespace ams::fssystem {
/* Explicitly overridden to be not implemented. */
Result DirectorySaveDataFileSystem::DoGetFreeSpaceSize(s64 *out, const char *path) {
AMS_UNUSED(out, path);
return fs::ResultNotImplemented();
}
Result DirectorySaveDataFileSystem::DoGetTotalSpaceSize(s64 *out, const char *path) {
AMS_UNUSED(out, path);
return fs::ResultNotImplemented();
}
Result DirectorySaveDataFileSystem::DoGetFileTimeStampRaw(fs::FileTimeStampRaw *out, const char *path) {
AMS_UNUSED(out, path);
return fs::ResultNotImplemented();
}
Result DirectorySaveDataFileSystem::DoQueryEntry(char *dst, size_t dst_size, const char *src, size_t src_size, fs::fsa::QueryId query, const char *path) {
AMS_UNUSED(dst, dst_size, src, src_size, query, path);
return fs::ResultNotImplemented();
}

View File

@@ -38,6 +38,7 @@ namespace ams::fssystem {
AMS_ASSERT(layer_count == LayerCount);
AMS_ASSERT(util::IsPowerOfTwo(htbs));
AMS_ASSERT(hash_buf != nullptr);
AMS_UNUSED(layer_count);
/* Set size tracking members. */
this->hash_target_block_size = htbs;

View File

@@ -50,6 +50,7 @@ namespace ams::fssystem {
}
virtual Result SetSize(s64 size) override {
AMS_UNUSED(size);
return fs::ResultUnsupportedOperationInHierarchicalSha256StorageA();
}
};

View File

@@ -131,6 +131,7 @@ namespace ams::fssystem {
/* Operate on our entries. */
R_TRY(this->OperatePerEntry<false>(offset, size, [=](fs::IStorage *storage, s64 data_offset, s64 cur_offset, s64 cur_size) -> Result {
AMS_UNUSED(cur_offset);
R_TRY(storage->OperateRange(dst, dst_size, op_id, data_offset, cur_size, src, src_size));
return ResultSuccess();
}));
@@ -155,6 +156,8 @@ namespace ams::fssystem {
/* Operate on our entries. */
R_TRY(this->OperatePerEntry<false>(offset, size, [=, &merged_info](fs::IStorage *storage, s64 data_offset, s64 cur_offset, s64 cur_size) -> Result {
AMS_UNUSED(cur_offset);
fs::QueryRangeInfo cur_info;
R_TRY(storage->OperateRange(std::addressof(cur_info), sizeof(cur_info), op_id, data_offset, cur_size, src, src_size));
merged_info.Merge(cur_info);

View File

@@ -46,6 +46,8 @@ namespace ams::fssystem {
bool Contains(const void *key, size_t key_size, s32 key2) const {
AMS_ASSERT(key_size == KeySize);
AMS_UNUSED(key_size);
return key2 == this->key2 && std::memcmp(this->key1, key, KeySize) == 0;
}

View File

@@ -149,6 +149,7 @@ namespace ams::fssystem {
AMS_ASSERT(enc_key_size == KeySize);
AMS_ASSERT(iv != nullptr);
AMS_ASSERT(iv_size == IvSize);
AMS_UNUSED(iv_size);
std::memcpy(this->iv, iv, IvSize);
std::memcpy(this->encrypted_key, enc_key, enc_key_size);
@@ -221,6 +222,10 @@ namespace ams::fssystem {
fs::QueryRangeInfo new_info;
new_info.Clear();
new_info.aes_ctr_key_type = static_cast<s32>(this->key_index >= 0 ? fs::AesCtrKeyTypeFlag::InternalKeyForHardwareAes : fs::AesCtrKeyTypeFlag::ExternalKeyForHardwareAes);
/* Merge the new info in. */
reinterpret_cast<fs::QueryRangeInfo *>(dst)->Merge(new_info);
return ResultSuccess();
}
default:
{
@@ -240,10 +245,12 @@ namespace ams::fssystem {
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
AMS_UNUSED(offset, buffer, size);
return fs::ResultUnsupportedOperationInAesCtrStorageExternalA();
}
virtual Result SetSize(s64 size) override {
AMS_UNUSED(size);
return fs::ResultUnsupportedOperationInAesCtrStorageExternalB();
}
};

View File

@@ -187,6 +187,8 @@ namespace ams::fssystem {
void NcaReader::GetRightsId(u8 *dst, size_t dst_size) const {
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(dst_size >= NcaHeader::RightsIdSize);
AMS_UNUSED(dst_size);
std::memcpy(dst, this->header.rights_id, NcaHeader::RightsIdSize);
}
@@ -247,6 +249,8 @@ namespace ams::fssystem {
AMS_ASSERT(this->body_storage != nullptr);
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(size >= NcaHeader::EncryptedKeyAreaSize);
AMS_UNUSED(size);
std::memcpy(dst, this->header.encrypted_key_area, NcaHeader::EncryptedKeyAreaSize);
}
@@ -291,6 +295,8 @@ namespace ams::fssystem {
void NcaReader::SetExternalDecryptionKey(const void *src, size_t size) {
AMS_ASSERT(src != nullptr);
AMS_ASSERT(size == sizeof(this->external_decryption_key));
AMS_UNUSED(size);
std::memcpy(this->external_decryption_key, src, sizeof(this->external_decryption_key));
}
@@ -298,6 +304,7 @@ namespace ams::fssystem {
AMS_ASSERT(this->body_storage != nullptr);
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(dst_size >= sizeof(NcaHeader));
AMS_UNUSED(dst_size);
std::memcpy(dst, std::addressof(this->header), sizeof(NcaHeader));
}
@@ -363,6 +370,8 @@ namespace ams::fssystem {
AMS_ASSERT(this->IsInitialized());
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(dst_size >= sizeof(NcaFsHeader));
AMS_UNUSED(dst_size);
std::memcpy(dst, std::addressof(this->data), sizeof(NcaFsHeader));
}

View File

@@ -22,10 +22,12 @@ namespace ams::fssystem {
class PartitionFileSystemDefaultAllocator : public MemoryResource {
private:
virtual void *AllocateImpl(size_t size, size_t alignment) override {
AMS_UNUSED(alignment);
return ::ams::fs::impl::Allocate(size);
}
virtual void DeallocateImpl(void *buffer, size_t size, size_t alignment) override {
AMS_UNUSED(alignment);
::ams::fs::impl::Deallocate(buffer, size);
}
@@ -401,46 +403,55 @@ namespace ams::fssystem {
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoCleanDirectoryRecursively(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoCreateDirectory(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoCreateFile(const char *path, s64 size, int option) {
AMS_UNUSED(path, size, option);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoDeleteDirectory(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoDeleteDirectoryRecursively(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoDeleteFile(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoRenameDirectory(const char *old_path, const char *new_path) {
AMS_UNUSED(old_path, new_path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoRenameFile(const char *old_path, const char *new_path) {
AMS_UNUSED(old_path, new_path);
return fs::ResultUnsupportedOperationInPartitionFileSystemA();
}
template <typename MetaType>
Result PartitionFileSystemCore<MetaType>::DoCommitProvisionally(s64 counter) {
AMS_UNUSED(counter);
return fs::ResultUnsupportedOperationInPartitionFileSystemB();
}

View File

@@ -35,7 +35,7 @@ namespace ams::fssystem {
if (!this->is_registered) {
this->is_registered = true;
this->address = addr;
this->size = size;
this->size = sz;
}
}

View File

@@ -36,6 +36,7 @@ namespace ams::fssystem {
AMS_ASSERT(util::IsPowerOfTwo(this->block_size));
AMS_ASSERT(cache_block_count > 0);
AMS_ASSERT(buf_size >= static_cast<size_t>(this->block_size * cache_block_count));
AMS_UNUSED(buf_size);
/* Create a node for each cache block. */
for (auto i = 0; i < cache_block_count; i++) {
@@ -128,10 +129,12 @@ namespace ams::fssystem {
}
virtual Result Write(s64 offset, const void *buffer, size_t size) override {
AMS_UNUSED(offset, buffer, size);
return fs::ResultUnsupportedOperationInReadOnlyBlockCacheStorageA();
}
virtual Result SetSize(s64 size) override {
AMS_UNUSED(size);
return fs::ResultUnsupportedOperationInReadOnlyBlockCacheStorageB();
}
};

View File

@@ -60,9 +60,12 @@ namespace ams::fssystem {
}
virtual Result DoWrite(s64 offset, const void *buffer, size_t size, const fs::WriteOption &option) override {
AMS_UNUSED(buffer);
bool needs_append;
R_TRY(this->DryWrite(std::addressof(needs_append), offset, size, option, fs::OpenMode_Read));
AMS_ASSERT(needs_append == false);
return fs::ResultUnsupportedOperationInRomFsFileA();
}
@@ -297,30 +300,37 @@ namespace ams::fssystem {
}
Result RomFsFileSystem::DoCreateFile(const char *path, s64 size, int flags) {
AMS_UNUSED(path, size, flags);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoDeleteFile(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoCreateDirectory(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoDeleteDirectory(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoDeleteDirectoryRecursively(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoRenameFile(const char *old_path, const char *new_path) {
AMS_UNUSED(old_path, new_path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoRenameDirectory(const char *old_path, const char *new_path) {
AMS_UNUSED(old_path, new_path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
@@ -381,15 +391,19 @@ namespace ams::fssystem {
}
Result RomFsFileSystem::DoGetFreeSpaceSize(s64 *out, const char *path) {
AMS_UNUSED(path);
*out = 0;
return ResultSuccess();
}
Result RomFsFileSystem::DoCleanDirectoryRecursively(const char *path) {
AMS_UNUSED(path);
return fs::ResultUnsupportedOperationInRomFsFileSystemA();
}
Result RomFsFileSystem::DoCommitProvisionally(s64 counter) {
AMS_UNUSED(counter);
return fs::ResultUnsupportedOperationInRomFsFileSystemB();
}

View File

@@ -19,6 +19,7 @@ namespace ams::fssystem {
s32 ScopedThreadPriorityChangerByAccessPriority::GetThreadPriorityByAccessPriority(AccessMode mode) {
/* TODO: Actually implement this for real. */
AMS_UNUSED(mode);
return os::GetThreadPriority(os::GetCurrentThread());
}

View File

@@ -108,12 +108,16 @@ namespace ams::fssystem {
return IterateDirectoryRecursively(src_fs, src_path,
[&](const char *path, const fs::DirectoryEntry &entry) -> Result { /* On Enter Directory */
AMS_UNUSED(path);
/* Update path, create new dir. */
std::strncat(dst_path_buf, entry.name, sizeof(dst_path_buf) - strnlen(dst_path_buf, sizeof(dst_path_buf) - 1) - 1);
std::strncat(dst_path_buf, "/", sizeof(dst_path_buf) - strnlen(dst_path_buf, sizeof(dst_path_buf) - 1) - 1);
return dst_fs->CreateDirectory(dst_path_buf);
},
[&](const char *path, const fs::DirectoryEntry &entry) -> Result { /* On Exit Directory */
AMS_UNUSED(path, entry);
/* Check we have a parent directory. */
const size_t len = strnlen(dst_path_buf, sizeof(dst_path_buf));
R_UNLESS(len >= 2, fs::ResultInvalidPathFormat());

View File

@@ -385,6 +385,8 @@ namespace ams::fssystem::save {
}
Result BlockCacheBufferedStorage::OperateRange(void *dst, size_t dst_size, fs::OperationId op_id, s64 offset, s64 size, const void *src, size_t src_size) {
AMS_UNUSED(src, src_size);
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
@@ -636,6 +638,8 @@ namespace ams::fssystem::save {
}
Result BlockCacheBufferedStorage::GetAssociateBuffer(MemoryRange *out_range, CacheEntry *out_entry, s64 offset, size_t ideal_size, bool is_allocate_for_write) {
AMS_UNUSED(is_allocate_for_write);
/* Validate pre-conditions. */
AMS_ASSERT(this->data_storage != nullptr);
AMS_ASSERT(this->buffer_manager != nullptr);

View File

@@ -315,6 +315,7 @@ namespace ams::fssystem::save {
this->CalcFetchParameter(std::addressof(fetch_param), offset);
AMS_ASSERT(fetch_param.offset == offset);
AMS_ASSERT(fetch_param.size <= buffer_size);
AMS_UNUSED(buffer_size);
std::memcpy(fetch_param.buffer, buffer, fetch_param.size);
this->offset = fetch_param.offset;

View File

@@ -390,6 +390,7 @@ namespace ams::fssystem::save {
const s64 sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = static_cast<size_t>((size >> this->verification_block_order) * HashSize);
AMS_ASSERT(dst_size >= sign_size);
AMS_UNUSED(dst_size);
/* Create a guard in the event of failure. */
auto clear_guard = SCOPE_GUARD { std::memset(dst, 0, sign_size); };
@@ -418,6 +419,7 @@ namespace ams::fssystem::save {
const s64 sign_offset = (offset >> this->verification_block_order) * HashSize;
const auto sign_size = static_cast<size_t>((size >> this->verification_block_order) * HashSize);
AMS_ASSERT(src_size >= sign_size);
AMS_UNUSED(src_size);
/* Write the signature. */
R_TRY(this->hash_storage.Write(sign_offset, src, sign_size));