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

@@ -48,7 +48,7 @@ namespace ams::mitm {
g_throw_result = res;
g_threw = true;
R_ASSERT(g_debug_throw_thread.Start());
R_ABORT_UNLESS(g_debug_throw_thread.Start());
}
}

View File

@@ -71,7 +71,7 @@ namespace ams::mitm::fs {
}
void OpenGlobalSdCardFileSystem() {
R_ASSERT(fsOpenSdCardFileSystem(&g_sd_filesystem));
R_ABORT_UNLESS(fsOpenSdCardFileSystem(&g_sd_filesystem));
}
Result CreateSdFile(const char *path, s64 size, s32 option) {

View File

@@ -92,10 +92,10 @@ namespace ams::mitm {
/* Read the calibration binary. */
{
FsStorage calibration_binary_storage;
R_ASSERT(fsOpenBisStorage(&calibration_binary_storage, FsBisPartitionId_CalibrationBinary));
R_ABORT_UNLESS(fsOpenBisStorage(&calibration_binary_storage, FsBisPartitionId_CalibrationBinary));
ON_SCOPE_EXIT { fsStorageClose(&calibration_binary_storage); };
R_ASSERT(fsStorageRead(&calibration_binary_storage, 0, g_calibration_binary_storage_backup, CalibrationBinarySize));
R_ABORT_UNLESS(fsStorageRead(&calibration_binary_storage, 0, g_calibration_binary_storage_backup, CalibrationBinarySize));
}
/* Copy serial number from partition. */
@@ -109,16 +109,16 @@ namespace ams::mitm {
GetBackupFileName(calibration_binary_backup_name, sizeof(calibration_binary_backup_name), serial_number, "PRODINFO.bin");
mitm::fs::CreateAtmosphereSdFile(calibration_binary_backup_name, CalibrationBinarySize, ams::fs::CreateOption_None);
R_ASSERT(mitm::fs::OpenAtmosphereSdFile(&g_calibration_binary_file, calibration_binary_backup_name, ams::fs::OpenMode_ReadWrite));
R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdFile(&g_calibration_binary_file, calibration_binary_backup_name, ams::fs::OpenMode_ReadWrite));
s64 file_size = 0;
R_ASSERT(fsFileGetSize(&g_calibration_binary_file, &file_size));
R_ABORT_UNLESS(fsFileGetSize(&g_calibration_binary_file, &file_size));
bool is_file_backup_valid = file_size == CalibrationBinarySize;
if (is_file_backup_valid) {
u64 read_size = 0;
R_ASSERT(fsFileRead(&g_calibration_binary_file, 0, g_calibration_binary_file_backup, CalibrationBinarySize, FsReadOption_None, &read_size));
AMS_ASSERT(read_size == CalibrationBinarySize);
R_ABORT_UNLESS(fsFileRead(&g_calibration_binary_file, 0, g_calibration_binary_file_backup, CalibrationBinarySize, FsReadOption_None, &read_size));
AMS_ABORT_UNLESS(read_size == CalibrationBinarySize);
is_file_backup_valid &= std::memcmp(g_calibration_binary_file_backup, "CAL0", 4) == 0;
is_file_backup_valid &= std::memcmp(g_calibration_binary_file_backup + 0x250, serial_number, 0x18) == 0;
const u32 cal_bin_size = *reinterpret_cast<const u32 *>(g_calibration_binary_file_backup + 0x8);
@@ -132,8 +132,8 @@ namespace ams::mitm {
}
if (!is_file_backup_valid) {
R_ASSERT(fsFileSetSize(&g_calibration_binary_file, CalibrationBinarySize));
R_ASSERT(fsFileWrite(&g_calibration_binary_file, 0, g_calibration_binary_storage_backup, CalibrationBinarySize, FsWriteOption_Flush));
R_ABORT_UNLESS(fsFileSetSize(&g_calibration_binary_file, CalibrationBinarySize));
R_ABORT_UNLESS(fsFileWrite(&g_calibration_binary_file, 0, g_calibration_binary_storage_backup, CalibrationBinarySize, FsWriteOption_Flush));
}
/* Note: g_calibration_binary_file is intentionally not closed here. This prevents any other process from opening it. */
@@ -145,7 +145,7 @@ namespace ams::mitm {
{
u64 key_generation = 0;
if (hos::GetVersion() >= hos::Version_500) {
R_ASSERT(splGetConfig(SplConfigItem_NewKeyGeneration, &key_generation));
R_ABORT_UNLESS(splGetConfig(SplConfigItem_NewKeyGeneration, &key_generation));
}
u8 bis_keys[4][2][0x10];
@@ -155,15 +155,15 @@ namespace ams::mitm {
for (size_t partition = 0; partition < 4; partition++) {
if (partition == 0) {
for (size_t i = 0; i < 2; i++) {
R_ASSERT(splFsGenerateSpecificAesKey(BisKeySources[partition][i], key_generation, i, bis_keys[partition][i]));
R_ABORT_UNLESS(splFsGenerateSpecificAesKey(BisKeySources[partition][i], key_generation, i, bis_keys[partition][i]));
}
} else {
const u32 option = (partition == 3 && spl::IsRecoveryBoot()) ? 0x4 : 0x1;
u8 access_key[0x10];
R_ASSERT(splCryptoGenerateAesKek(BisKekSource, key_generation, option, access_key));
R_ABORT_UNLESS(splCryptoGenerateAesKek(BisKekSource, key_generation, option, access_key));
for (size_t i = 0; i < 2; i++) {
R_ASSERT(splCryptoGenerateAesKey(access_key, BisKeySources[partition][i], bis_keys[partition][i]));
R_ABORT_UNLESS(splCryptoGenerateAesKey(access_key, BisKeySources[partition][i], bis_keys[partition][i]));
}
}
}
@@ -172,9 +172,9 @@ namespace ams::mitm {
GetBackupFileName(bis_keys_backup_name, sizeof(bis_keys_backup_name), serial_number, "BISKEYS.bin");
mitm::fs::CreateAtmosphereSdFile(bis_keys_backup_name, sizeof(bis_keys), ams::fs::CreateOption_None);
R_ASSERT(mitm::fs::OpenAtmosphereSdFile(&g_bis_key_file, bis_keys_backup_name, ams::fs::OpenMode_ReadWrite));
R_ASSERT(fsFileSetSize(&g_bis_key_file, sizeof(bis_keys)));
R_ASSERT(fsFileWrite(&g_bis_key_file, 0, bis_keys, sizeof(bis_keys), FsWriteOption_Flush));
R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdFile(&g_bis_key_file, bis_keys_backup_name, ams::fs::OpenMode_ReadWrite));
R_ABORT_UNLESS(fsFileSetSize(&g_bis_key_file, sizeof(bis_keys)));
R_ABORT_UNLESS(fsFileWrite(&g_bis_key_file, 0, bis_keys, sizeof(bis_keys), FsWriteOption_Flush));
/* NOTE: g_bis_key_file is intentionally not closed here. This prevents any other process from opening it. */
}
}
@@ -226,14 +226,14 @@ namespace ams::mitm {
/* Connect to set:sys. */
sm::DoWithSession([]() {
R_ASSERT(setsysInitialize());
R_ABORT_UNLESS(setsysInitialize());
});
/* Load settings off the SD card. */
settings::fwdbg::InitializeSdCardKeyValueStore();
/* Ensure that we reboot using the user's preferred method. */
R_ASSERT(mitm::bpc::DetectPreferredRebootFunctionality());
R_ABORT_UNLESS(mitm::bpc::DetectPreferredRebootFunctionality());
/* Signal to waiters that we are ready. */
g_init_event.Signal();
@@ -242,7 +242,7 @@ namespace ams::mitm {
}
void StartInitialize() {
R_ASSERT(g_initialize_thread.Start());
R_ABORT_UNLESS(g_initialize_thread.Start());
}
bool IsInitialized() {

View File

@@ -78,10 +78,10 @@ void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ASSERT(fsInitialize());
R_ASSERT(pmdmntInitialize());
R_ASSERT(pminfoInitialize());
R_ASSERT(splFsInitialize());
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(pmdmntInitialize());
R_ABORT_UNLESS(pminfoInitialize());
R_ABORT_UNLESS(splFsInitialize());
});
ams::CheckApiVersion();

View File

@@ -72,12 +72,12 @@ namespace ams::mitm {
/* Create thread for each module. */
for (u32 i = 0; i < static_cast<u32>(ModuleId_Count); i++) {
const ModuleDefinition &cur_module = g_module_definitions[i];
R_ASSERT(g_module_threads[i].Initialize(cur_module.main, nullptr, cur_module.stack_mem, cur_module.stack_size, cur_module.priority));
R_ABORT_UNLESS(g_module_threads[i].Initialize(cur_module.main, nullptr, cur_module.stack_mem, cur_module.stack_size, cur_module.priority));
}
/* Start thread for each module. */
for (u32 i = 0; i < static_cast<u32>(ModuleId_Count); i++) {
R_ASSERT(g_module_threads[i].Start());
R_ABORT_UNLESS(g_module_threads[i].Start());
}
}

View File

@@ -44,13 +44,13 @@ namespace ams::mitm::bpc {
/* Create bpc:ams. */
{
Handle bpcams_h;
R_ASSERT(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions));
R_ABORT_UNLESS(svcManageNamedPort(&bpcams_h, AtmosphereServiceName.name, AtmosphereMaxSessions));
g_server_manager.RegisterServer<bpc::AtmosphereService>(bpcams_h);
}
/* Create bpc mitm. */
const sm::ServiceName service_name = (hos::GetVersion() >= hos::Version_200) ? MitmServiceName : DeprecatedMitmServiceName;
R_ASSERT(g_server_manager.RegisterMitmServer<BpcMitmService>(service_name));
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<BpcMitmService>(service_name));
/* Loop forever, servicing our services. */
g_server_manager.LoopProcess();

View File

@@ -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);
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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));
}
}

View 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) {

View File

@@ -58,7 +58,7 @@ namespace ams::mitm::hid {
}
/* Create hid mitm. */
R_ASSERT(g_server_manager.RegisterMitmServer<HidMitmService>(MitmServiceName));
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<HidMitmService>(MitmServiceName));
/* Loop forever, servicing our services. */
g_server_manager.LoopProcess();

View File

@@ -38,9 +38,9 @@ namespace ams::mitm::ns {
/* Create mitm servers. */
if (hos::GetVersion() < hos::Version_300) {
R_ASSERT(g_server_manager.RegisterMitmServer<NsAmMitmService>(NsAmMitmServiceName));
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<NsAmMitmService>(NsAmMitmServiceName));
} else {
R_ASSERT(g_server_manager.RegisterMitmServer<NsWebMitmService>(NsWebMitmServiceName));
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<NsWebMitmService>(NsWebMitmServiceName));
}
/* Loop forever, servicing our services. */

View File

@@ -42,8 +42,8 @@ namespace ams::mitm::settings {
mitm::WaitInitialized();
/* Create mitm servers. */
R_ASSERT(g_server_manager.RegisterMitmServer<SetMitmService>(SetMitmServiceName));
R_ASSERT(g_server_manager.RegisterMitmServer<SetSysMitmService>(SetSysMitmServiceName));
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<SetMitmService>(SetMitmServiceName));
R_ABORT_UNLESS(g_server_manager.RegisterMitmServer<SetSysMitmService>(SetSysMitmServiceName));
/* Loop forever, servicing our services. */
g_server_manager.LoopProcess();

View File

@@ -35,17 +35,17 @@ namespace ams::mitm::settings {
}
/* Mount firmware version data archive. */
R_ASSERT(romfsMountFromDataArchive(static_cast<u64>(ncm::ProgramId::ArchiveSystemVersion), NcmStorageId_BuiltInSystem, "sysver"));
R_ABORT_UNLESS(romfsMountFromDataArchive(static_cast<u64>(ncm::ProgramId::ArchiveSystemVersion), NcmStorageId_BuiltInSystem, "sysver"));
{
ON_SCOPE_EXIT { romfsUnmount("sysver"); };
/* Firmware version file must exist. */
FILE *fp = fopen("sysver:/file", "rb");
AMS_ASSERT(fp != nullptr);
AMS_ABORT_UNLESS(fp != nullptr);
ON_SCOPE_EXIT { fclose(fp); };
/* Must be possible to read firmware version from file. */
AMS_ASSERT(fread(&g_firmware_version, sizeof(g_firmware_version), 1, fp) == 1);
AMS_ABORT_UNLESS(fread(&g_firmware_version, sizeof(g_firmware_version), 1, fp) == 1);
g_ams_firmware_version = g_firmware_version;
}

View File

@@ -25,7 +25,7 @@ namespace ams::settings::fwdbg {
return size;
}
R_ASSERT(setsysGetSettingsItemValueSize(name, key, &size));
R_ABORT_UNLESS(setsysGetSettingsItemValueSize(name, key, &size));
return size;
}
@@ -36,7 +36,7 @@ namespace ams::settings::fwdbg {
return size;
}
R_ASSERT(setsysGetSettingsItemValue(name, key, dst, dst_size, &size));
R_ABORT_UNLESS(setsysGetSettingsItemValue(name, key, dst, dst_size, &size));
return size;
}

View File

@@ -52,8 +52,8 @@ namespace ams::settings::fwdbg {
}
inline bool operator<(const SdKeyValueStoreEntry &lhs, const SdKeyValueStoreEntry &rhs) {
AMS_ASSERT(lhs.HasValue());
AMS_ASSERT(rhs.HasValue());
AMS_ABORT_UNLESS(lhs.HasValue());
AMS_ABORT_UNLESS(rhs.HasValue());
char lhs_name_key[SettingsNameLengthMax + 1 + SettingsItemKeyLengthMax + 1];
char rhs_name_key[SettingsNameLengthMax + 1 + SettingsItemKeyLengthMax + 1];
@@ -76,7 +76,7 @@ namespace ams::settings::fwdbg {
size_t g_num_entries;
constexpr bool IsValidSettingsFormat(const char *str, size_t len) {
AMS_ASSERT(str != nullptr);
AMS_ABORT_UNLESS(str != nullptr);
if (len > 0 && str[len - 1] == '.') {
return false;
@@ -306,63 +306,63 @@ namespace ams::settings::fwdbg {
void LoadDefaultCustomSettings() {
/* Disable uploading error reports to Nintendo. */
R_ASSERT(ParseSettingsItemValue("eupld", "upload_enabled", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("eupld", "upload_enabled", "u8!0x0"));
/* Control whether RO should ease its validation of NROs. */
/* (note: this is normally not necessary, and ips patches can be used.) */
R_ASSERT(ParseSettingsItemValue("ro", "ease_nro_restriction", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("ro", "ease_nro_restriction", "u8!0x0"));
/* Atmosphere custom settings. */
/* Reboot from fatal automatically after some number of milliseconds. */
/* If field is not present or 0, fatal will wait indefinitely for user input. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", "u64!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", "u64!0x0"));
/* Make the power menu's "reboot" button reboot to payload. */
/* Set to "normal" for normal reboot, "rcm" for rcm reboot. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "power_menu_reboot_function", "str!payload"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "power_menu_reboot_function", "str!payload"));
/* Enable writing to BIS partitions for HBL. */
/* This is probably undesirable for normal usage. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "enable_hbl_bis_write", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_hbl_bis_write", "u8!0x0"));
/* Enable HBL to read the CAL0 partition. */
/* This is probably undesirable for normal usage. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "enable_hbl_cal_read", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_hbl_cal_read", "u8!0x0"));
/* Controls whether dmnt cheats should be toggled on or off by */
/* default. 1 = toggled on by default, 0 = toggled off by default. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "dmnt_cheats_enabled_by_default", "u8!0x1"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "dmnt_cheats_enabled_by_default", "u8!0x1"));
/* Controls whether dmnt should always save cheat toggle state */
/* for restoration on new game launch. 1 = always save toggles, */
/* 0 = only save toggles if toggle file exists. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "dmnt_always_save_cheat_toggles", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "dmnt_always_save_cheat_toggles", "u8!0x0"));
/* Controls whether fs.mitm should redirect save files */
/* to directories on the sd card. */
/* 0 = Do not redirect, 1 = Redirect. */
/* NOTE: EXPERIMENTAL */
/* If you do not know what you are doing, do not touch this yet. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "fsmitm_redirect_saves_to_sd", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "fsmitm_redirect_saves_to_sd", "u8!0x0"));
/* Controls whether to enable the deprecated hid mitm */
/* to fix compatibility with old homebrew. */
/* 0 = Do not enable, 1 = Enable. */
/* Please note this setting may be removed in a future release of Atmosphere. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "enable_deprecated_hid_mitm", "u8!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "enable_deprecated_hid_mitm", "u8!0x0"));
/* Hbloader custom settings. */
/* Controls the size of the homebrew heap when running as applet. */
/* If set to zero, all available applet memory is used as heap. */
/* The default is zero. */
R_ASSERT(ParseSettingsItemValue("hbloader", "applet_heap_size", "u64!0x0"));
R_ABORT_UNLESS(ParseSettingsItemValue("hbloader", "applet_heap_size", "u64!0x0"));
/* Controls the amount of memory to reserve when running as applet */
/* for usage by other applets. This setting has no effect if */
/* applet_heap_size is non-zero. The default is 0x8600000. */
R_ASSERT(ParseSettingsItemValue("hbloader", "applet_heap_reservation_size", "u64!0x8600000"));
R_ABORT_UNLESS(ParseSettingsItemValue("hbloader", "applet_heap_reservation_size", "u64!0x8600000"));
}
}