ams: revamp assertion system
This commit is contained in:
@@ -60,7 +60,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
bool GetSettingsItemBooleanValue(const char *name, const char *key) {
|
||||
u8 tmp = 0;
|
||||
AMS_ASSERT(settings::fwdbg::GetSettingsItemValue(&tmp, sizeof(tmp), name, key) == sizeof(tmp));
|
||||
AMS_ABORT_UNLESS(settings::fwdbg::GetSettingsItemValue(&tmp, sizeof(tmp), name, key) == sizeof(tmp));
|
||||
return (tmp != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,14 +45,14 @@ namespace ams::mitm::fs {
|
||||
std::scoped_lock lk(g_mq_lock);
|
||||
|
||||
if (!g_started_req_thread) {
|
||||
R_ASSERT(g_romfs_initializer_thread.Start());
|
||||
R_ABORT_UNLESS(g_romfs_initializer_thread.Start());
|
||||
g_started_req_thread = true;
|
||||
}
|
||||
|
||||
g_req_mq.Send(storage_uptr);
|
||||
uintptr_t ack = 0;
|
||||
g_ack_mq.Receive(&ack);
|
||||
AMS_ASSERT(ack == storage_uptr);
|
||||
AMS_ABORT_UNLESS(ack == storage_uptr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -70,7 +70,7 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
void LayeredRomfsStorage::BeginInitialize() {
|
||||
AMS_ASSERT(!this->started_initialize);
|
||||
AMS_ABORT_UNLESS(!this->started_initialize);
|
||||
RequestInitializeStorage(reinterpret_cast<uintptr_t>(this));
|
||||
this->started_initialize = true;
|
||||
}
|
||||
@@ -123,27 +123,27 @@ namespace ams::mitm::fs {
|
||||
size_t read_so_far = 0;
|
||||
while (read_so_far < size) {
|
||||
const auto &cur_source = *it;
|
||||
AMS_ASSERT(offset >= cur_source.virtual_offset);
|
||||
AMS_ABORT_UNLESS(offset >= cur_source.virtual_offset);
|
||||
|
||||
if (offset < cur_source.virtual_offset + cur_source.size) {
|
||||
const s64 offset_within_source = offset - cur_source.virtual_offset;
|
||||
const size_t cur_read_size = std::min(size - read_so_far, size_t(cur_source.size - offset_within_source));
|
||||
switch (cur_source.source_type) {
|
||||
case romfs::DataSourceType::Storage:
|
||||
R_ASSERT(this->storage_romfs->Read(cur_source.storage_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
R_ABORT_UNLESS(this->storage_romfs->Read(cur_source.storage_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
break;
|
||||
case romfs::DataSourceType::File:
|
||||
R_ASSERT(this->file_romfs->Read(cur_source.file_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
R_ABORT_UNLESS(this->file_romfs->Read(cur_source.file_source_info.offset + offset_within_source, cur_dst, cur_read_size));
|
||||
break;
|
||||
case romfs::DataSourceType::LooseSdFile:
|
||||
{
|
||||
FsFile file;
|
||||
R_ASSERT(mitm::fs::OpenAtmosphereSdRomfsFile(&file, this->program_id, cur_source.loose_source_info.path, OpenMode_Read));
|
||||
R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdRomfsFile(&file, this->program_id, cur_source.loose_source_info.path, OpenMode_Read));
|
||||
ON_SCOPE_EXIT { fsFileClose(&file); };
|
||||
|
||||
u64 out_read = 0;
|
||||
R_ASSERT(fsFileRead(&file, offset_within_source, cur_dst, cur_read_size, FsReadOption_None, &out_read));
|
||||
AMS_ASSERT(out_read == cur_read_size);
|
||||
R_ABORT_UNLESS(fsFileRead(&file, offset_within_source, cur_dst, cur_read_size, FsReadOption_None, &out_read));
|
||||
AMS_ABORT_UNLESS(out_read == cur_read_size);
|
||||
}
|
||||
break;
|
||||
case romfs::DataSourceType::Memory:
|
||||
@@ -152,8 +152,8 @@ namespace ams::mitm::fs {
|
||||
case romfs::DataSourceType::Metadata:
|
||||
{
|
||||
size_t out_read = 0;
|
||||
R_ASSERT(cur_source.metadata_source_info.file->Read(&out_read, offset_within_source, cur_dst, cur_read_size));
|
||||
AMS_ASSERT(out_read == cur_read_size);
|
||||
R_ABORT_UNLESS(cur_source.metadata_source_info.file->Read(&out_read, offset_within_source, cur_dst, cur_read_size));
|
||||
AMS_ABORT_UNLESS(out_read == cur_read_size);
|
||||
}
|
||||
break;
|
||||
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||
|
||||
@@ -51,14 +51,14 @@ namespace ams::mitm::fs {
|
||||
if constexpr (NumExtraThreads > 0) {
|
||||
const u32 priority = os::GetCurrentThreadPriority();
|
||||
for (size_t i = 0; i < NumExtraThreads; i++) {
|
||||
R_ASSERT(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority));
|
||||
R_ABORT_UNLESS(g_extra_threads[i].Initialize(LoopServerThread, nullptr, g_extra_thread_stacks[i], ThreadStackSize, priority));
|
||||
}
|
||||
}
|
||||
|
||||
/* Start extra threads. */
|
||||
if constexpr (NumExtraThreads > 0) {
|
||||
for (size_t i = 0; i < NumExtraThreads; i++) {
|
||||
R_ASSERT(g_extra_threads[i].Start());
|
||||
R_ABORT_UNLESS(g_extra_threads[i].Start());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace ams::mitm::fs {
|
||||
/* Wait for extra threads to finish. */
|
||||
if constexpr (NumExtraThreads > 0) {
|
||||
for (size_t i = 0; i < NumExtraThreads; i++) {
|
||||
R_ASSERT(g_extra_threads[i].Join());
|
||||
R_ABORT_UNLESS(g_extra_threads[i].Join());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
void MitmModule::ThreadFunction(void *arg) {
|
||||
/* Create fs mitm. */
|
||||
R_ASSERT(g_server_manager.RegisterMitmServer<FsMitmService>(MitmServiceName));
|
||||
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<FsMitmService>(MitmServiceName));
|
||||
|
||||
/* Process for the server. */
|
||||
ProcessForServerOnAllThreads();
|
||||
|
||||
@@ -117,14 +117,14 @@ namespace ams::mitm::fs {
|
||||
__attribute__((noinline)) void OpenFileSystemRomfsDirectory(FsDir *out, ncm::ProgramId program_id, BuildDirectoryContext *parent, fs::OpenDirectoryMode mode, FsFileSystem *fs) {
|
||||
std::scoped_lock lk(g_fs_romfs_path_lock);
|
||||
parent->GetPath(g_fs_romfs_path_buffer);
|
||||
R_ASSERT(mitm::fs::OpenAtmosphereRomfsDirectory(out, program_id, g_fs_romfs_path_buffer, mode, fs));
|
||||
R_ABORT_UNLESS(mitm::fs::OpenAtmosphereRomfsDirectory(out, program_id, g_fs_romfs_path_buffer, mode, fs));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Builder::Builder(ncm::ProgramId pr_id) : program_id(pr_id), num_dirs(0), num_files(0), dir_table_size(0), file_table_size(0), dir_hash_table_size(0), file_hash_table_size(0), file_partition_size(0) {
|
||||
auto res = this->directories.emplace(std::make_unique<BuildDirectoryContext>(BuildDirectoryContext::RootTag{}));
|
||||
AMS_ASSERT(res.second);
|
||||
AMS_ABORT_UNLESS(res.second);
|
||||
this->root = res.first->get();
|
||||
this->num_dirs = 1;
|
||||
this->dir_table_size = 0x18;
|
||||
@@ -172,14 +172,14 @@ namespace ams::mitm::fs {
|
||||
{
|
||||
OpenFileSystemRomfsDirectory(&dir, this->program_id, parent, OpenDirectoryMode_Directory, fs);
|
||||
ON_SCOPE_EXIT { fsDirClose(&dir); };
|
||||
R_ASSERT(fsDirGetEntryCount(&dir, &num_child_dirs));
|
||||
R_ABORT_UNLESS(fsDirGetEntryCount(&dir, &num_child_dirs));
|
||||
}
|
||||
AMS_ASSERT(num_child_dirs >= 0);
|
||||
AMS_ABORT_UNLESS(num_child_dirs >= 0);
|
||||
|
||||
{
|
||||
BuildDirectoryContext **child_dirs = reinterpret_cast<BuildDirectoryContext **>(std::malloc(sizeof(BuildDirectoryContext *) * num_child_dirs));
|
||||
ON_SCOPE_EXIT { std::free(child_dirs); };
|
||||
AMS_ASSERT(child_dirs != nullptr);
|
||||
AMS_ABORT_UNLESS(child_dirs != nullptr);
|
||||
s64 cur_child_dir_ind = 0;
|
||||
|
||||
{
|
||||
@@ -188,25 +188,25 @@ namespace ams::mitm::fs {
|
||||
|
||||
s64 read_entries = 0;
|
||||
while (true) {
|
||||
R_ASSERT(fsDirRead(&dir, &read_entries, 1, &this->dir_entry));
|
||||
R_ABORT_UNLESS(fsDirRead(&dir, &read_entries, 1, &this->dir_entry));
|
||||
if (read_entries != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
AMS_ASSERT(this->dir_entry.type == FsDirEntryType_Dir || this->dir_entry.type == FsDirEntryType_File);
|
||||
AMS_ABORT_UNLESS(this->dir_entry.type == FsDirEntryType_Dir || this->dir_entry.type == FsDirEntryType_File);
|
||||
if (this->dir_entry.type == FsDirEntryType_Dir) {
|
||||
BuildDirectoryContext *real_child = nullptr;
|
||||
this->AddDirectory(&real_child, parent, std::make_unique<BuildDirectoryContext>(this->dir_entry.name, strlen(this->dir_entry.name)));
|
||||
AMS_ASSERT(real_child != nullptr);
|
||||
AMS_ABORT_UNLESS(real_child != nullptr);
|
||||
child_dirs[cur_child_dir_ind++] = real_child;
|
||||
AMS_ASSERT(cur_child_dir_ind <= num_child_dirs);
|
||||
AMS_ABORT_UNLESS(cur_child_dir_ind <= num_child_dirs);
|
||||
} else /* if (this->dir_entry.type == FsDirEntryType_File) */ {
|
||||
this->AddFile(parent, std::make_unique<BuildFileContext>(this->dir_entry.name, strlen(this->dir_entry.name), this->dir_entry.file_size, 0, this->cur_source_type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AMS_ASSERT(num_child_dirs == cur_child_dir_ind);
|
||||
AMS_ABORT_UNLESS(num_child_dirs == cur_child_dir_ind);
|
||||
for (s64 i = 0; i < num_child_dirs; i++) {
|
||||
this->VisitDirectory(fs, child_dirs[i]);
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace ams::mitm::fs {
|
||||
while (true) {
|
||||
BuildDirectoryContext *real_child = nullptr;
|
||||
this->AddDirectory(&real_child, parent, std::make_unique<BuildDirectoryContext>(cur_child->name, cur_child->name_size));
|
||||
AMS_ASSERT(real_child != nullptr);
|
||||
AMS_ABORT_UNLESS(real_child != nullptr);
|
||||
|
||||
this->VisitDirectory(real_child, cur_child_offset, dir_table, dir_table_size, file_table, file_table_size);
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace ams::mitm::fs {
|
||||
void Builder::AddSdFiles() {
|
||||
/* Open Sd Card filesystem. */
|
||||
FsFileSystem sd_filesystem;
|
||||
R_ASSERT(fsOpenSdCardFileSystem(&sd_filesystem));
|
||||
R_ABORT_UNLESS(fsOpenSdCardFileSystem(&sd_filesystem));
|
||||
ON_SCOPE_EXIT { fsFsClose(&sd_filesystem); };
|
||||
|
||||
/* If there is no romfs folder on the SD, don't bother continuing. */
|
||||
@@ -267,16 +267,16 @@ namespace ams::mitm::fs {
|
||||
|
||||
void Builder::AddStorageFiles(ams::fs::IStorage *storage, DataSourceType source_type) {
|
||||
Header header;
|
||||
R_ASSERT(storage->Read(0, &header, sizeof(Header)));
|
||||
AMS_ASSERT(header.header_size == sizeof(Header));
|
||||
R_ABORT_UNLESS(storage->Read(0, &header, sizeof(Header)));
|
||||
AMS_ABORT_UNLESS(header.header_size == sizeof(Header));
|
||||
|
||||
/* Read tables. */
|
||||
void *tables = std::malloc(header.dir_table_size + header.file_table_size);
|
||||
ON_SCOPE_EXIT { std::free(tables); };
|
||||
void *dir_table = tables;
|
||||
void *file_table = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(tables) + header.dir_table_size);
|
||||
R_ASSERT(storage->Read(header.dir_table_ofs, dir_table, size_t(header.dir_table_size)));
|
||||
R_ASSERT(storage->Read(header.file_table_ofs, file_table, size_t(header.file_table_size)));
|
||||
R_ABORT_UNLESS(storage->Read(header.dir_table_ofs, dir_table, size_t(header.dir_table_size)));
|
||||
R_ABORT_UNLESS(storage->Read(header.file_table_ofs, file_table, size_t(header.file_table_size)));
|
||||
|
||||
this->cur_source_type = source_type;
|
||||
this->VisitDirectory(this->root, 0x0, dir_table, size_t(header.dir_table_size), file_table, size_t(header.file_table_size));
|
||||
@@ -288,7 +288,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Open an SD card filesystem. */
|
||||
FsFileSystem sd_filesystem;
|
||||
R_ASSERT(fsOpenSdCardFileSystem(&sd_filesystem));
|
||||
R_ABORT_UNLESS(fsOpenSdCardFileSystem(&sd_filesystem));
|
||||
ON_SCOPE_EXIT { fsFsClose(&sd_filesystem); };
|
||||
|
||||
/* Calculate hash table sizes. */
|
||||
@@ -304,7 +304,7 @@ namespace ams::mitm::fs {
|
||||
/* Open metadata file. */
|
||||
const size_t metadata_size = this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size + this->file_table_size;
|
||||
FsFile metadata_file;
|
||||
R_ASSERT(mitm::fs::CreateAndOpenAtmosphereSdFile(&metadata_file, this->program_id, "romfs_metadata.bin", metadata_size));
|
||||
R_ABORT_UNLESS(mitm::fs::CreateAndOpenAtmosphereSdFile(&metadata_file, this->program_id, "romfs_metadata.bin", metadata_size));
|
||||
|
||||
/* Ensure later hash tables will have correct defaults. */
|
||||
static_assert(EmptyEntry == 0xFFFFFFFF);
|
||||
@@ -328,7 +328,7 @@ namespace ams::mitm::fs {
|
||||
if (prev_file != nullptr && prev_file->source_type == cur_file->source_type && is_storage_or_file) {
|
||||
const s64 expected = this->file_partition_size - prev_file->offset + prev_file->orig_offset;
|
||||
if (expected != cur_file->orig_offset) {
|
||||
AMS_ASSERT(expected <= cur_file->orig_offset);
|
||||
AMS_ABORT_UNLESS(expected <= cur_file->orig_offset);
|
||||
this->file_partition_size += cur_file->orig_offset - expected;
|
||||
}
|
||||
}
|
||||
@@ -431,8 +431,8 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
/* Write to file. */
|
||||
R_ASSERT(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size, file_hash_table, this->file_hash_table_size, FsWriteOption_None));
|
||||
R_ASSERT(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size, file_table, this->file_table_size, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size, file_hash_table, this->file_hash_table_size, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(&metadata_file, this->dir_hash_table_size + this->dir_table_size + this->file_hash_table_size, file_table, this->file_table_size, FsWriteOption_None));
|
||||
}
|
||||
|
||||
/* Populate directory tables. */
|
||||
@@ -472,8 +472,8 @@ namespace ams::mitm::fs {
|
||||
}
|
||||
|
||||
/* Write to file. */
|
||||
R_ASSERT(fsFileWrite(&metadata_file, 0, dir_hash_table, this->dir_hash_table_size, FsWriteOption_None));
|
||||
R_ASSERT(fsFileWrite(&metadata_file, this->dir_hash_table_size, dir_table, this->dir_table_size, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(&metadata_file, 0, dir_hash_table, this->dir_hash_table_size, FsWriteOption_None));
|
||||
R_ABORT_UNLESS(fsFileWrite(&metadata_file, this->dir_hash_table_size, dir_table, this->dir_table_size, FsWriteOption_None));
|
||||
}
|
||||
|
||||
/* Delete maps. */
|
||||
@@ -495,7 +495,7 @@ namespace ams::mitm::fs {
|
||||
|
||||
/* Save metadata to the SD card, to save on memory space. */
|
||||
{
|
||||
R_ASSERT(fsFileFlush(&metadata_file));
|
||||
R_ABORT_UNLESS(fsFileFlush(&metadata_file));
|
||||
out_infos->emplace_back(header->dir_hash_table_ofs, metadata_size, DataSourceType::Metadata, new RemoteFile(metadata_file));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace ams::mitm::fs::romfs {
|
||||
}
|
||||
|
||||
void Cleanup() {
|
||||
AMS_ASSERT(!this->cleaned_up);
|
||||
AMS_ABORT_UNLESS(!this->cleaned_up);
|
||||
this->cleaned_up = true;
|
||||
|
||||
switch (this->source_type) {
|
||||
|
||||
Reference in New Issue
Block a user