ams: revamp assertion system
This commit is contained in:
@@ -133,7 +133,7 @@ namespace ams::updater {
|
||||
Result GetBootImagePackageDataId(u64 *out_data_id, BootModeType mode, void *work_buffer, size_t work_buffer_size) {
|
||||
/* Ensure we can read content metas. */
|
||||
constexpr size_t MaxContentMetas = 0x40;
|
||||
AMS_ASSERT(work_buffer_size >= sizeof(NcmContentMetaKey) * MaxContentMetas);
|
||||
AMS_ABORT_UNLESS(work_buffer_size >= sizeof(NcmContentMetaKey) * MaxContentMetas);
|
||||
|
||||
/* Open NAND System meta database, list contents. */
|
||||
NcmContentMetaDatabase meta_db;
|
||||
@@ -150,7 +150,7 @@ namespace ams::updater {
|
||||
return ResultBootImagePackageNotFound();
|
||||
}
|
||||
|
||||
AMS_ASSERT(total_entries == written_entries);
|
||||
AMS_ABORT_UNLESS(total_entries == written_entries);
|
||||
|
||||
/* Output is sorted, return the lowest valid exfat entry. */
|
||||
if (total_entries > 1) {
|
||||
@@ -187,7 +187,7 @@ namespace ams::updater {
|
||||
R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) {
|
||||
R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
|
||||
/* Read and validate hashes of boot images. */
|
||||
{
|
||||
@@ -240,7 +240,7 @@ namespace ams::updater {
|
||||
R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) {
|
||||
R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
|
||||
/* Read and validate hashes of boot images. */
|
||||
{
|
||||
@@ -308,7 +308,7 @@ namespace ams::updater {
|
||||
R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) {
|
||||
R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
|
||||
{
|
||||
Boot0Accessor boot0_accessor;
|
||||
@@ -363,7 +363,7 @@ namespace ams::updater {
|
||||
R_TRY_CATCH(romfsMountFromDataArchive(data_id, NcmStorageId_BuiltInSystem, GetBootImagePackageMountPath())) {
|
||||
R_CONVERT(fs::ResultTargetNotFound, ResultBootImagePackageNotFound())
|
||||
} R_END_TRY_CATCH;
|
||||
ON_SCOPE_EXIT { R_ASSERT(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
ON_SCOPE_EXIT { R_ABORT_UNLESS(romfsUnmount(GetBootImagePackageMountPath())); };
|
||||
|
||||
{
|
||||
Boot0Accessor boot0_accessor;
|
||||
@@ -509,7 +509,7 @@ namespace ams::updater {
|
||||
|
||||
/* Get a session to ncm. */
|
||||
sm::ScopedServiceHolder<ncmInitialize, ncmExit> ncm_holder;
|
||||
R_ASSERT(ncm_holder.GetResult());
|
||||
R_ABORT_UNLESS(ncm_holder.GetResult());
|
||||
|
||||
/* Verify normal, verify safe as needed. */
|
||||
if (verification_state.needs_verify_normal) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -136,13 +136,13 @@ namespace ams::updater {
|
||||
}
|
||||
}
|
||||
|
||||
AMS_ASSERT(entry != nullptr);
|
||||
AMS_ABORT_UNLESS(entry != nullptr);
|
||||
return entry;
|
||||
}
|
||||
public:
|
||||
Result Read(size_t *out_size, void *dst, size_t size, EnumType which) {
|
||||
const auto entry = FindEntry(which);
|
||||
AMS_ASSERT(size >= entry->size);
|
||||
AMS_ABORT_UNLESS(size >= entry->size);
|
||||
|
||||
R_TRY(BisAccessor::Read(dst, entry->size, entry->offset));
|
||||
|
||||
@@ -152,8 +152,8 @@ namespace ams::updater {
|
||||
|
||||
Result Write(const void *src, size_t size, EnumType which) {
|
||||
const auto entry = FindEntry(which);
|
||||
AMS_ASSERT(size <= entry->size);
|
||||
AMS_ASSERT((size % BisAccessor::SectorAlignment) == 0);
|
||||
AMS_ABORT_UNLESS(size <= entry->size);
|
||||
AMS_ABORT_UNLESS((size % BisAccessor::SectorAlignment) == 0);
|
||||
return BisAccessor::Write(entry->offset, src, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace ams::updater {
|
||||
}
|
||||
|
||||
Result BisSave::Initialize(void *work_buffer, size_t work_buffer_size) {
|
||||
AMS_ASSERT(work_buffer_size >= SaveSize);
|
||||
AMS_ASSERT(util::IsAligned(reinterpret_cast<uintptr_t>(work_buffer), os::MemoryPageSize));
|
||||
AMS_ASSERT(util::IsAligned(work_buffer_size, 0x200));
|
||||
AMS_ABORT_UNLESS(work_buffer_size >= SaveSize);
|
||||
AMS_ABORT_UNLESS(util::IsAligned(reinterpret_cast<uintptr_t>(work_buffer), os::MemoryPageSize));
|
||||
AMS_ABORT_UNLESS(util::IsAligned(work_buffer_size, 0x200));
|
||||
|
||||
R_TRY(this->accessor.Initialize());
|
||||
this->save_buffer = work_buffer;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace ams::updater {
|
||||
constexpr const char *Package2PathA = "bip:/a/package2";
|
||||
|
||||
const char *ChooseCandidatePath(const char * const *candidates, size_t num_candidates) {
|
||||
AMS_ASSERT(num_candidates > 0);
|
||||
AMS_ABORT_UNLESS(num_candidates > 0);
|
||||
|
||||
for (size_t i = 0; i < num_candidates; i++) {
|
||||
struct stat buf;
|
||||
|
||||
Reference in New Issue
Block a user