ams: revamp assertion system

This commit is contained in:
Michael Scire
2020-02-22 23:05:14 -08:00
parent 9572fb2ce3
commit 40400aee1f
168 changed files with 1014 additions and 696 deletions

View File

@@ -31,18 +31,18 @@ namespace ams::updater {
}
Result BisAccessor::Read(void *dst, size_t size, u64 offset) {
AMS_ASSERT((offset % SectorAlignment) == 0);
AMS_ABORT_UNLESS((offset % SectorAlignment) == 0);
return fsStorageRead(&this->storage, offset, dst, size);
}
Result BisAccessor::Write(u64 offset, const void *src, size_t size) {
AMS_ASSERT((offset % SectorAlignment) == 0);
AMS_ABORT_UNLESS((offset % SectorAlignment) == 0);
return fsStorageWrite(&this->storage, offset, src, size);
}
Result BisAccessor::Write(u64 offset, size_t size, const char *bip_path, void *work_buffer, size_t work_buffer_size) {
AMS_ASSERT((offset % SectorAlignment) == 0);
AMS_ASSERT((work_buffer_size % SectorAlignment) == 0);
AMS_ABORT_UNLESS((offset % SectorAlignment) == 0);
AMS_ABORT_UNLESS((work_buffer_size % SectorAlignment) == 0);
FILE *bip_fp = fopen(bip_path, "rb");
if (bip_fp == NULL) {
@@ -59,7 +59,7 @@ namespace ams::updater {
return fsdevGetLastResult();
}
}
AMS_ASSERT(written + read_size <= size);
AMS_ABORT_UNLESS(written + read_size <= size);
size_t aligned_size = ((read_size + SectorAlignment - 1) / SectorAlignment) * SectorAlignment;
R_TRY(this->Write(offset + written, work_buffer, aligned_size));
@@ -73,8 +73,8 @@ namespace ams::updater {
}
Result BisAccessor::Clear(u64 offset, u64 size, void *work_buffer, size_t work_buffer_size) {
AMS_ASSERT((offset % SectorAlignment) == 0);
AMS_ASSERT((work_buffer_size % SectorAlignment) == 0);
AMS_ABORT_UNLESS((offset % SectorAlignment) == 0);
AMS_ABORT_UNLESS((work_buffer_size % SectorAlignment) == 0);
std::memset(work_buffer, 0, work_buffer_size);
@@ -88,8 +88,8 @@ namespace ams::updater {
}
Result BisAccessor::GetHash(void *dst, u64 offset, u64 size, u64 hash_size, void *work_buffer, size_t work_buffer_size) {
AMS_ASSERT((offset % SectorAlignment) == 0);
AMS_ASSERT((work_buffer_size % SectorAlignment) == 0);
AMS_ABORT_UNLESS((offset % SectorAlignment) == 0);
AMS_ABORT_UNLESS((work_buffer_size % SectorAlignment) == 0);
Sha256Context sha_ctx;
sha256ContextCreate(&sha_ctx);
@@ -109,12 +109,12 @@ namespace ams::updater {
size_t Boot0Accessor::GetBootloaderVersion(void *bct) {
u32 version = *reinterpret_cast<u32 *>(reinterpret_cast<uintptr_t>(bct) + BctVersionOffset);
AMS_ASSERT(version <= BctVersionMax);
AMS_ABORT_UNLESS(version <= BctVersionMax);
return static_cast<size_t>(version);
}
size_t Boot0Accessor::GetEksIndex(size_t bootloader_version) {
AMS_ASSERT(bootloader_version <= BctVersionMax);
AMS_ABORT_UNLESS(bootloader_version <= BctVersionMax);
return (bootloader_version > 0) ? bootloader_version - 1 : 0;
}