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

View File

@@ -72,16 +72,16 @@ namespace ams::boot {
/* Get values from PMIC. */
{
PmicDriver pmic_driver;
R_ASSERT(pmic_driver.GetPowerIntr(&power_intr));
R_ASSERT(pmic_driver.GetNvErc(&nv_erc));
R_ASSERT(pmic_driver.GetAcOk(&ac_ok));
R_ABORT_UNLESS(pmic_driver.GetPowerIntr(&power_intr));
R_ABORT_UNLESS(pmic_driver.GetNvErc(&nv_erc));
R_ABORT_UNLESS(pmic_driver.GetAcOk(&ac_ok));
}
/* Get values from RTC. */
{
RtcDriver rtc_driver;
R_ASSERT(rtc_driver.GetRtcIntr(&rtc_intr));
R_ASSERT(rtc_driver.GetRtcIntrM(&rtc_intr_m));
R_ABORT_UNLESS(rtc_driver.GetRtcIntr(&rtc_intr));
R_ABORT_UNLESS(rtc_driver.GetRtcIntrM(&rtc_intr_m));
}
/* Set global derived boot reason. */
@@ -94,14 +94,14 @@ namespace ams::boot {
boot_reason_value.rtc_intr = rtc_intr & ~rtc_intr_m;
boot_reason_value.nv_erc = nv_erc;
boot_reason_value.boot_reason = g_boot_reason;
R_ASSERT(splSetBootReason(boot_reason_value.value));
R_ABORT_UNLESS(splSetBootReason(boot_reason_value.value));
}
g_detected_boot_reason = true;
}
u32 GetBootReason() {
AMS_ASSERT(g_detected_boot_reason);
AMS_ABORT_UNLESS(g_detected_boot_reason);
return g_boot_reason;
}

View File

@@ -40,8 +40,8 @@ namespace ams::boot::bq24193 {
constexpr u32 ChargeVoltageLimitMax = 4208;
inline u8 EncodeChargeVoltageLimit(u32 voltage) {
AMS_ASSERT(voltage >= ChargeVoltageLimitMin);
AMS_ASSERT(voltage <= ChargeVoltageLimitMax);
AMS_ABORT_UNLESS(voltage >= ChargeVoltageLimitMin);
AMS_ABORT_UNLESS(voltage <= ChargeVoltageLimitMax);
voltage -= ChargeVoltageLimitMin;
voltage >>= 4;
@@ -56,8 +56,8 @@ namespace ams::boot::bq24193 {
constexpr u32 FastChargeCurrentLimitMax = 4544;
inline u8 EncodeFastChargeCurrentLimit(u32 current) {
AMS_ASSERT(current >= FastChargeCurrentLimitMin);
AMS_ASSERT(current <= FastChargeCurrentLimitMax);
AMS_ABORT_UNLESS(current >= FastChargeCurrentLimitMin);
AMS_ABORT_UNLESS(current <= FastChargeCurrentLimitMax);
current -= FastChargeCurrentLimitMin;
current >>= 6;
@@ -83,8 +83,8 @@ namespace ams::boot::bq24193 {
constexpr u32 PreChargeCurrentLimitMax = 2048;
inline u8 EncodePreChargeCurrentLimit(u32 current) {
AMS_ASSERT(current >= PreChargeCurrentLimitMin);
AMS_ASSERT(current <= PreChargeCurrentLimitMax);
AMS_ABORT_UNLESS(current >= PreChargeCurrentLimitMin);
AMS_ABORT_UNLESS(current <= PreChargeCurrentLimitMax);
current -= PreChargeCurrentLimitMin;
current >>= 7;
@@ -99,8 +99,8 @@ namespace ams::boot::bq24193 {
constexpr u32 TerminationCurrentLimitMax = 2048;
inline u8 EncodeTerminationCurrentLimit(u32 current) {
AMS_ASSERT(current >= TerminationCurrentLimitMin);
AMS_ASSERT(current <= TerminationCurrentLimitMax);
AMS_ABORT_UNLESS(current >= TerminationCurrentLimitMin);
AMS_ABORT_UNLESS(current <= TerminationCurrentLimitMax);
current -= TerminationCurrentLimitMin;
current >>= 7;
@@ -115,8 +115,8 @@ namespace ams::boot::bq24193 {
constexpr u32 MinimumSystemVoltageLimitMax = 3700;
inline u8 EncodeMinimumSystemVoltageLimit(u32 voltage) {
AMS_ASSERT(voltage >= MinimumSystemVoltageLimitMin);
AMS_ASSERT(voltage <= MinimumSystemVoltageLimitMax);
AMS_ABORT_UNLESS(voltage >= MinimumSystemVoltageLimitMin);
AMS_ABORT_UNLESS(voltage <= MinimumSystemVoltageLimitMax);
voltage -= MinimumSystemVoltageLimitMin;
voltage /= 100;

View File

@@ -35,7 +35,7 @@ namespace ams::boot {
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
};
AMS_ASSERT(data != nullptr);
AMS_ABORT_UNLESS(data != nullptr);
u16 crc16 = 0x55AA;
const u8 *data_u8 = reinterpret_cast<const u8 *>(data);

View File

@@ -126,12 +126,12 @@ namespace ams::boot {
armDCacheFlush(g_frame_buffer, FrameBufferSize);
/* Create Address Space. */
R_ASSERT(svcCreateDeviceAddressSpace(&g_dc_das_hnd, 0, (1ul << 32)));
R_ABORT_UNLESS(svcCreateDeviceAddressSpace(&g_dc_das_hnd, 0, (1ul << 32)));
/* Attach it to the DC. */
R_ASSERT(svcAttachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
R_ABORT_UNLESS(svcAttachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
/* Map the framebuffer for the DC as read-only. */
R_ASSERT(svcMapDeviceAddressSpaceAligned(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr, 1));
R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr, 1));
}
}
@@ -140,11 +140,11 @@ namespace ams::boot {
const uintptr_t frame_buffer_aligned = reinterpret_cast<uintptr_t>(g_frame_buffer);
/* Unmap the framebuffer from the DC. */
R_ASSERT(svcUnmapDeviceAddressSpace(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr));
R_ABORT_UNLESS(svcUnmapDeviceAddressSpace(g_dc_das_hnd, dd::GetCurrentProcessHandle(), frame_buffer_aligned, FrameBufferSize, FrameBufferPaddr));
/* Detach address space from the DC. */
R_ASSERT(svcDetachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
R_ABORT_UNLESS(svcDetachDeviceAddressSpace(svc::DeviceName_Dc, g_dc_das_hnd));
/* Close the address space. */
R_ASSERT(svcCloseHandle(g_dc_das_hnd));
R_ABORT_UNLESS(svcCloseHandle(g_dc_das_hnd));
g_dc_das_hnd = INVALID_HANDLE;
g_frame_buffer = nullptr;
}

View File

@@ -42,21 +42,21 @@ namespace ams::boot {
}
Result ReadI2cRegister(i2c::driver::Session &session, u8 *dst, size_t dst_size, const u8 *cmd, size_t cmd_size) {
AMS_ASSERT(dst != nullptr && dst_size > 0);
AMS_ASSERT(cmd != nullptr && cmd_size > 0);
AMS_ABORT_UNLESS(dst != nullptr && dst_size > 0);
AMS_ABORT_UNLESS(cmd != nullptr && cmd_size > 0);
u8 cmd_list[i2c::CommandListFormatter::MaxCommandListSize];
i2c::CommandListFormatter formatter(cmd_list, sizeof(cmd_list));
R_ASSERT(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size));
R_ASSERT(formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size));
R_ABORT_UNLESS(formatter.EnqueueSendCommand(I2cTransactionOption_Start, cmd, cmd_size));
R_ABORT_UNLESS(formatter.EnqueueReceiveCommand(static_cast<I2cTransactionOption>(I2cTransactionOption_Start | I2cTransactionOption_Stop), dst_size));
return RetryUntilSuccess([&]() { return i2c::driver::ExecuteCommandList(session, dst, dst_size, cmd_list, formatter.GetCurrentSize()); });
}
Result WriteI2cRegister(i2c::driver::Session &session, const u8 *src, size_t src_size, const u8 *cmd, size_t cmd_size) {
AMS_ASSERT(src != nullptr && src_size > 0);
AMS_ASSERT(cmd != nullptr && cmd_size > 0);
AMS_ABORT_UNLESS(src != nullptr && src_size > 0);
AMS_ABORT_UNLESS(cmd != nullptr && cmd_size > 0);
u8 cmd_list[0x20];

View File

@@ -90,9 +90,9 @@ void __appInit(void) {
/* Initialize services we need (TODO: NCM) */
sm::DoWithSession([&]() {
R_ASSERT(fsInitialize());
R_ASSERT(splInitialize());
R_ASSERT(pmshellInitialize());
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(splInitialize());
R_ABORT_UNLESS(pmshellInitialize());
});
ams::CheckApiVersion();
@@ -147,7 +147,7 @@ int main(int argc, char **argv)
boot::CheckAndRepairBootImages();
/* Tell PM to start boot2. */
R_ASSERT(pmshellNotifyBootFinished());
R_ABORT_UNLESS(pmshellNotifyBootFinished());
return 0;
}

View File

@@ -32,19 +32,19 @@ namespace ams::boot {
inline u32 ReadWriteRegisterImpl(uintptr_t phys_addr, u32 value, u32 mask) {
u32 out_value;
R_ASSERT(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value)));
R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::AtmosphereReadWriteRegister(phys_addr, mask, value, &out_value)));
return out_value;
}
}
u32 ReadPmcRegister(u32 phys_addr) {
AMS_ASSERT(IsValidPmcAddress(phys_addr));
AMS_ABORT_UNLESS(IsValidPmcAddress(phys_addr));
return ReadWriteRegisterImpl(phys_addr, 0, 0);
}
void WritePmcRegister(u32 phys_addr, u32 value, u32 mask) {
AMS_ASSERT(IsValidPmcAddress(phys_addr));
AMS_ABORT_UNLESS(IsValidPmcAddress(phys_addr));
ReadWriteRegisterImpl(phys_addr, value, mask);
}

View File

@@ -19,11 +19,11 @@
namespace ams::boot {
void PmicDriver::ShutdownSystem() {
R_ASSERT(this->ShutdownSystem(false));
R_ABORT_UNLESS(this->ShutdownSystem(false));
}
void PmicDriver::RebootSystem() {
R_ASSERT(this->ShutdownSystem(true));
R_ABORT_UNLESS(this->ShutdownSystem(true));
}
Result PmicDriver::GetAcOk(bool *out) {
@@ -61,17 +61,17 @@ namespace ams::boot {
/* Get value, set or clear software reset mask. */
u8 on_off_2_val = 0;
R_ASSERT(ReadI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
R_ABORT_UNLESS(ReadI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
if (reboot) {
on_off_2_val |= 0x80;
} else {
on_off_2_val &= ~0x80;
}
R_ASSERT(WriteI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
R_ABORT_UNLESS(WriteI2cRegister(this->i2c_session, &on_off_2_val, sizeof(on_off_2_val), &on_off_2_addr, sizeof(on_off_2_addr)));
/* Get value, set software reset mask. */
u8 on_off_1_val = 0;
R_ASSERT(ReadI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
R_ABORT_UNLESS(ReadI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
on_off_1_val |= 0x80;
/* Finalize the battery. */
@@ -81,11 +81,11 @@ namespace ams::boot {
}
/* Actually write the value to trigger shutdown/reset. */
R_ASSERT(WriteI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
R_ABORT_UNLESS(WriteI2cRegister(this->i2c_session, &on_off_1_val, sizeof(on_off_1_val), &on_off_1_addr, sizeof(on_off_1_addr)));
/* Allow up to 5 seconds for shutdown/reboot to take place. */
svcSleepThread(5'000'000'000ul);
AMS_ASSERT(false);
AMS_ABORT_UNLESS(false);
}
void PmicDriver::FinalizeBattery(BatteryDriver *battery_driver) {

View File

@@ -79,7 +79,7 @@ namespace ams::gpio {
}
/* Ensure we found an appropriate config. */
AMS_ASSERT(configs != nullptr);
AMS_ABORT_UNLESS(configs != nullptr);
for (size_t i = 0; i < num_configs; i++) {
/* Configure the GPIO. */

View File

@@ -33,7 +33,7 @@ namespace ams::gpio {
/* Helpers. */
inline u32 GetPadDescriptor(u32 gpio_pad_name) {
AMS_ASSERT(gpio_pad_name < PadNameMax);
AMS_ABORT_UNLESS(gpio_pad_name < PadNameMax);
return Map[gpio_pad_name];
}

View File

@@ -83,7 +83,7 @@ namespace ams::i2c::driver {
}
inline void CheckInitialized() {
AMS_ASSERT(GetResourceManager().IsInitialized());
AMS_ABORT_UNLESS(GetResourceManager().IsInitialized());
}
}
@@ -100,7 +100,7 @@ namespace ams::i2c::driver {
/* Session management. */
void OpenSession(Session *out_session, I2cDevice device) {
CheckInitialized();
AMS_ASSERT(impl::IsDeviceSupported(device));
AMS_ABORT_UNLESS(impl::IsDeviceSupported(device));
const auto bus = impl::GetDeviceBus(device);
const auto slave_address = impl::GetDeviceSlaveAddress(device);
@@ -119,8 +119,8 @@ namespace ams::i2c::driver {
/* Communication. */
Result Send(Session &session, const void *src, size_t size, I2cTransactionOption option) {
CheckInitialized();
AMS_ASSERT(src != nullptr);
AMS_ASSERT(size > 0);
AMS_ABORT_UNLESS(src != nullptr);
AMS_ABORT_UNLESS(size > 0);
std::scoped_lock<os::Mutex &> lk(GetResourceManager().GetTransactionMutex(impl::ConvertFromIndex(session.bus_idx)));
return GetResourceManager().GetSession(session.session_id).DoTransactionWithRetry(nullptr, src, size, option, impl::Command::Send);
@@ -128,8 +128,8 @@ namespace ams::i2c::driver {
Result Receive(Session &session, void *dst, size_t size, I2cTransactionOption option) {
CheckInitialized();
AMS_ASSERT(dst != nullptr);
AMS_ASSERT(size > 0);
AMS_ABORT_UNLESS(dst != nullptr);
AMS_ABORT_UNLESS(size > 0);
std::scoped_lock<os::Mutex &> lk(GetResourceManager().GetTransactionMutex(impl::ConvertFromIndex(session.bus_idx)));
return GetResourceManager().GetSession(session.session_id).DoTransactionWithRetry(dst, nullptr, size, option, impl::Command::Receive);
@@ -137,8 +137,8 @@ namespace ams::i2c::driver {
Result ExecuteCommandList(Session &session, void *dst, size_t size, const void *cmd_list, size_t cmd_list_size) {
CheckInitialized();
AMS_ASSERT(dst != nullptr && size > 0);
AMS_ASSERT(cmd_list != nullptr && cmd_list_size > 0);
AMS_ABORT_UNLESS(dst != nullptr && size > 0);
AMS_ABORT_UNLESS(cmd_list != nullptr && cmd_list_size > 0);
u8 *cur_dst = static_cast<u8 *>(dst);
const u8 *cur_cmd = static_cast<const u8 *>(cmd_list);
@@ -146,7 +146,7 @@ namespace ams::i2c::driver {
while (cur_cmd < cmd_list_end) {
Command cmd = static_cast<Command>((*cur_cmd) & 3);
AMS_ASSERT(cmd < Command::Count);
AMS_ABORT_UNLESS(cmd < Command::Count);
R_TRY(g_cmd_handlers[static_cast<size_t>(cmd)](&cur_cmd, &cur_dst, session));
}

View File

@@ -25,7 +25,7 @@ namespace ams::i2c::driver::impl {
/* Ensure we're good if this isn't our first session. */
if (this->open_sessions > 1) {
AMS_ASSERT(this->speed_mode == speed_mode);
AMS_ABORT_UNLESS(this->speed_mode == speed_mode);
return;
}
@@ -240,8 +240,8 @@ namespace ams::i2c::driver::impl {
0x46, 0x74, 0x7C, 0x98, 0x55, 0x5F
};
const auto index = ConvertToIndex(bus);
AMS_ASSERT(index < util::size(s_interrupts));
R_ASSERT(this->interrupt_event.Initialize(s_interrupts[index], false));
AMS_ABORT_UNLESS(index < util::size(s_interrupts));
R_ABORT_UNLESS(this->interrupt_event.Initialize(s_interrupts[index], false));
}
void BusAccessor::SetClock(SpeedMode speed_mode) {
@@ -293,17 +293,17 @@ namespace ams::i2c::driver::impl {
reg::Read(&this->i2c_registers->I2C_I2C_CNFG_0);
if (this->pcv_module != PcvModule_I2C5) {
R_ASSERT(pcv::SetReset(this->pcv_module, true));
R_ASSERT(pcv::SetClockRate(this->pcv_module, (408'000'000) / (src_div + 1)));
R_ASSERT(pcv::SetReset(this->pcv_module, false));
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, true));
R_ABORT_UNLESS(pcv::SetClockRate(this->pcv_module, (408'000'000) / (src_div + 1)));
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, false));
}
}
void BusAccessor::ResetController() const {
if (this->pcv_module != PcvModule_I2C5) {
R_ASSERT(pcv::SetReset(this->pcv_module, true));
R_ASSERT(pcv::SetClockRate(this->pcv_module, 81'600'000));
R_ASSERT(pcv::SetReset(this->pcv_module, false));
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, true));
R_ABORT_UNLESS(pcv::SetClockRate(this->pcv_module, 81'600'000));
R_ABORT_UNLESS(pcv::SetReset(this->pcv_module, false));
}
}
@@ -362,7 +362,7 @@ namespace ams::i2c::driver::impl {
}
void BusAccessor::DisableClock() {
R_ASSERT(pcv::SetClockEnabled(this->pcv_module, false));
R_ABORT_UNLESS(pcv::SetClockEnabled(this->pcv_module, false));
}
void BusAccessor::SetPacketMode() {

View File

@@ -84,37 +84,37 @@ namespace ams::i2c::driver::impl {
Bus GetDeviceBus(I2cDevice dev) {
const size_t dev_idx = GetDeviceIndex(dev);
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
return g_device_configs[dev_idx].bus;
}
u32 GetDeviceSlaveAddress(I2cDevice dev) {
const size_t dev_idx = GetDeviceIndex(dev);
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
return g_device_configs[dev_idx].slave_address;
}
AddressingMode GetDeviceAddressingMode(I2cDevice dev) {
const size_t dev_idx = GetDeviceIndex(dev);
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
return g_device_configs[dev_idx].addressing_mode;
}
SpeedMode GetDeviceSpeedMode(I2cDevice dev) {
const size_t dev_idx = GetDeviceIndex(dev);
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
return g_device_configs[dev_idx].speed_mode;
}
u32 GetDeviceMaxRetries(I2cDevice dev) {
const size_t dev_idx = GetDeviceIndex(dev);
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
return g_device_configs[dev_idx].max_retries;
}
u64 GetDeviceRetryWaitTime(I2cDevice dev) {
const size_t dev_idx = GetDeviceIndex(dev);
AMS_ASSERT(dev_idx != DeviceInvalidIndex);
AMS_ABORT_UNLESS(dev_idx != DeviceInvalidIndex);
return g_device_configs[dev_idx].retry_wait_time;
}

View File

@@ -39,7 +39,7 @@ namespace ams::i2c::driver::impl {
}
constexpr inline Bus ConvertFromIndex(size_t idx) {
AMS_ASSERT(idx < static_cast<size_t>(Bus::Count));
AMS_ABORT_UNLESS(idx < static_cast<size_t>(Bus::Count));
return static_cast<Bus>(idx);
}

View File

@@ -25,7 +25,7 @@ namespace ams::i2c::driver::impl {
void ResourceManager::Finalize() {
std::scoped_lock lk(this->initialize_mutex);
AMS_ASSERT(this->ref_cnt > 0);
AMS_ABORT_UNLESS(this->ref_cnt > 0);
this->ref_cnt--;
if (this->ref_cnt > 0) {
return;
@@ -55,11 +55,11 @@ namespace ams::i2c::driver::impl {
/* Get, open session. */
{
std::scoped_lock lk(this->session_open_mutex);
AMS_ASSERT(out_session != nullptr);
AMS_ASSERT(bus < Bus::Count);
AMS_ABORT_UNLESS(out_session != nullptr);
AMS_ABORT_UNLESS(bus < Bus::Count);
session_id = GetFreeSessionId();
AMS_ASSERT(session_id != InvalidSessionId);
AMS_ABORT_UNLESS(session_id != InvalidSessionId);
if ((bus == Bus::I2C2 || bus == Bus::I2C3) && (this->bus_accessors[ConvertToIndex(Bus::I2C2)].GetOpenSessions() == 0 && this->bus_accessors[ConvertToIndex(Bus::I2C3)].GetOpenSessions() == 0)) {
@@ -74,8 +74,8 @@ namespace ams::i2c::driver::impl {
this->sessions[session_id].Start();
if (need_enable_ldo6) {
pcv::Initialize();
R_ASSERT(pcv::SetVoltageValue(10, 2'900'000));
R_ASSERT(pcv::SetVoltageEnabled(10, true));
R_ABORT_UNLESS(pcv::SetVoltageValue(10, 2'900'000));
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, true));
pcv::Finalize();
svcSleepThread(560'000ul);
}
@@ -86,7 +86,7 @@ namespace ams::i2c::driver::impl {
/* Get, open session. */
{
std::scoped_lock lk(this->session_open_mutex);
AMS_ASSERT(this->sessions[session.session_id].IsOpen());
AMS_ABORT_UNLESS(this->sessions[session.session_id].IsOpen());
this->sessions[session.session_id].Close();
@@ -98,14 +98,14 @@ namespace ams::i2c::driver::impl {
if (need_disable_ldo6) {
pcv::Initialize();
R_ASSERT(pcv::SetVoltageEnabled(10, false));
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, false));
pcv::Finalize();
}
}
void ResourceManager::SuspendBuses() {
AMS_ASSERT(this->ref_cnt > 0);
AMS_ABORT_UNLESS(this->ref_cnt > 0);
if (!this->suspended) {
{
@@ -118,19 +118,19 @@ namespace ams::i2c::driver::impl {
}
}
pcv::Initialize();
R_ASSERT(pcv::SetVoltageEnabled(10, false));
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, false));
pcv::Finalize();
}
}
void ResourceManager::ResumeBuses() {
AMS_ASSERT(this->ref_cnt > 0);
AMS_ABORT_UNLESS(this->ref_cnt > 0);
if (this->suspended) {
if (this->bus_accessors[ConvertToIndex(Bus::I2C2)].GetOpenSessions() > 0 || this->bus_accessors[ConvertToIndex(Bus::I2C3)].GetOpenSessions() > 0) {
pcv::Initialize();
R_ASSERT(pcv::SetVoltageValue(10, 2'900'000));
R_ASSERT(pcv::SetVoltageEnabled(10, true));
R_ABORT_UNLESS(pcv::SetVoltageValue(10, 2'900'000));
R_ABORT_UNLESS(pcv::SetVoltageEnabled(10, true));
pcv::Finalize();
svcSleepThread(1'560'000ul);
}
@@ -147,7 +147,7 @@ namespace ams::i2c::driver::impl {
}
void ResourceManager::SuspendPowerBus() {
AMS_ASSERT(this->ref_cnt > 0);
AMS_ABORT_UNLESS(this->ref_cnt > 0);
std::scoped_lock lk(this->session_open_mutex);
if (!this->power_bus_suspended) {
@@ -159,7 +159,7 @@ namespace ams::i2c::driver::impl {
}
void ResourceManager::ResumePowerBus() {
AMS_ASSERT(this->ref_cnt > 0);
AMS_ABORT_UNLESS(this->ref_cnt > 0);
std::scoped_lock lk(this->session_open_mutex);
if (this->power_bus_suspended) {

View File

@@ -39,7 +39,7 @@ namespace ams::i2c {
size_t cur_index = 0;
public:
CommandListFormatter(void *cmd_list, size_t cmd_list_size) : cmd_list(static_cast<u8 *>(cmd_list)), cmd_list_size(cmd_list_size) {
AMS_ASSERT(cmd_list_size <= MaxCommandListSize);
AMS_ABORT_UNLESS(cmd_list_size <= MaxCommandListSize);
}
~CommandListFormatter() {
this->cmd_list = nullptr;

View File

@@ -62,7 +62,7 @@ namespace ams::pinmux {
}
/* Ensure we found an appropriate config. */
AMS_ASSERT(configs != nullptr);
AMS_ABORT_UNLESS(configs != nullptr);
for (size_t i = 0; i < num_configs; i++) {
UpdatePad(configs[i].name, configs[i].val, configs[i].mask);

View File

@@ -30,12 +30,12 @@ namespace ams::pinmux {
/* Helpers. */
inline const Definition *GetDefinition(u32 pinmux_name) {
AMS_ASSERT(pinmux_name < PadNameMax);
AMS_ABORT_UNLESS(pinmux_name < PadNameMax);
return &Map[pinmux_name];
}
inline const DrivePadDefinition *GetDrivePadDefinition(u32 drivepad_name) {
AMS_ASSERT(drivepad_name < DrivePadNameMax);
AMS_ABORT_UNLESS(drivepad_name < DrivePadNameMax);
return &DrivePadMap[drivepad_name];
}
@@ -101,7 +101,7 @@ namespace ams::pinmux {
u32 pinmux_val = reg::Read(pinmux_reg);
/* This PINMUX register is locked */
AMS_ASSERT((pinmux_val & 0x80) == 0);
AMS_ABORT_UNLESS((pinmux_val & 0x80) == 0);
u32 pm_val = (pinmux_config_val & 0x07);

View File

@@ -71,15 +71,15 @@ void __appInit(void) {
/* Initialize services we need. */
sm::DoWithSession([&]() {
R_ASSERT(fsInitialize());
R_ASSERT(pmbmInitialize());
R_ASSERT(pminfoInitialize());
R_ASSERT(pmshellInitialize());
R_ASSERT(setsysInitialize());
R_ASSERT(gpioInitialize());
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(pmbmInitialize());
R_ABORT_UNLESS(pminfoInitialize());
R_ABORT_UNLESS(pmshellInitialize());
R_ABORT_UNLESS(setsysInitialize());
R_ABORT_UNLESS(gpioInitialize());
});
R_ASSERT(fsdevMountSdmc());
R_ABORT_UNLESS(fsdevMountSdmc());
ams::CheckApiVersion();
}

View File

@@ -72,10 +72,10 @@ void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ASSERT(fsInitialize());
R_ABORT_UNLESS(fsInitialize());
});
R_ASSERT(fsdevMountSdmc());
R_ABORT_UNLESS(fsdevMountSdmc());
}
void __appExit(void) {

View File

@@ -123,10 +123,10 @@ namespace ams::dmnt::cheat::impl {
void CloseActiveCheatProcess() {
if (this->cheat_process_debug_handle != INVALID_HANDLE) {
/* Knock out the debug events thread. */
R_ASSERT(this->debug_events_thread.CancelSynchronization());
R_ABORT_UNLESS(this->debug_events_thread.CancelSynchronization());
/* Close resources. */
R_ASSERT(svcCloseHandle(this->cheat_process_debug_handle));
R_ABORT_UNLESS(svcCloseHandle(this->cheat_process_debug_handle));
this->cheat_process_debug_handle = INVALID_HANDLE;
/* Save cheat toggles. */
@@ -176,18 +176,18 @@ namespace ams::dmnt::cheat::impl {
Handle HookToCreateApplicationProcess() const {
Handle h = INVALID_HANDLE;
R_ASSERT(pm::dmnt::HookToCreateApplicationProcess(&h));
R_ABORT_UNLESS(pm::dmnt::HookToCreateApplicationProcess(&h));
return h;
}
void StartProcess(os::ProcessId process_id) const {
R_ASSERT(pm::dmnt::StartProcess(process_id));
R_ABORT_UNLESS(pm::dmnt::StartProcess(process_id));
}
public:
CheatProcessManager() {
/* Create cheat process detection event. */
R_ASSERT(this->cheat_process_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(this->cheat_process_event.InitializeAsInterProcessEvent());
/* Learn whether we should enable cheats by default. */
{
@@ -203,14 +203,14 @@ namespace ams::dmnt::cheat::impl {
}
/* Spawn application detection thread, spawn cheat vm thread. */
R_ASSERT(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority));
R_ASSERT(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority));
R_ASSERT(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority));
R_ABORT_UNLESS(this->detect_thread.Initialize(&CheatProcessManager::DetectLaunchThread, this, this->detect_thread_stack, ThreadStackSize, DetectThreadPriority));
R_ABORT_UNLESS(this->vm_thread.Initialize(&CheatProcessManager::VirtualMachineThread, this, this->vm_thread_stack, ThreadStackSize, VirtualMachineThreadPriority));
R_ABORT_UNLESS(this->debug_events_thread.Initialize(&CheatProcessManager::DebugEventsThread, this, this->debug_events_thread_stack, ThreadStackSize, DebugEventsThreadPriority));
/* Start threads. */
R_ASSERT(this->detect_thread.Start());
R_ASSERT(this->vm_thread.Start());
R_ASSERT(this->debug_events_thread.Start());
R_ABORT_UNLESS(this->detect_thread.Start());
R_ABORT_UNLESS(this->vm_thread.Start());
R_ABORT_UNLESS(this->debug_events_thread.Start());
}
bool GetHasActiveCheatProcess() {
@@ -588,9 +588,9 @@ namespace ams::dmnt::cheat::impl {
}
}
#define R_ASSERT_IF_NEW_PROCESS(res) \
#define R_ABORT_UNLESS_IF_NEW_PROCESS(res) \
if (on_process_launch) { \
R_ASSERT(res); \
R_ABORT_UNLESS(res); \
} else { \
R_TRY(res); \
}
@@ -610,7 +610,7 @@ namespace ams::dmnt::cheat::impl {
}
/* Get the application process's ID. */
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id));
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::GetApplicationProcessId(&this->cheat_process_metadata.process_id));
auto proc_guard = SCOPE_GUARD {
if (on_process_launch) {
this->StartProcess(this->cheat_process_metadata.process_id);
@@ -623,14 +623,14 @@ namespace ams::dmnt::cheat::impl {
Handle proc_h = INVALID_HANDLE;
ncm::ProgramLocation loc = {};
cfg::OverrideStatus status = {};
ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ASSERT(svcCloseHandle(proc_h)); } };
ON_SCOPE_EXIT { if (proc_h != INVALID_HANDLE) { R_ABORT_UNLESS(svcCloseHandle(proc_h)); } };
R_ASSERT_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id));
R_ABORT_UNLESS_IF_NEW_PROCESS(pm::dmnt::AtmosphereGetProcessInfo(&proc_h, &loc, &status, this->cheat_process_metadata.process_id));
this->cheat_process_metadata.program_id = loc.program_id;
{
map::AddressSpaceInfo as_info;
R_ASSERT(map::GetProcessAddressSpaceInfo(&as_info, proc_h));
R_ABORT_UNLESS(map::GetProcessAddressSpaceInfo(&as_info, proc_h));
this->cheat_process_metadata.heap_extents.base = as_info.heap_base;
this->cheat_process_metadata.heap_extents.size = as_info.heap_size;
this->cheat_process_metadata.alias_extents.base = as_info.alias_base;
@@ -651,7 +651,7 @@ namespace ams::dmnt::cheat::impl {
s32 num_modules;
/* TODO: ldr::dmnt:: */
R_ASSERT_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules));
R_ABORT_UNLESS_IF_NEW_PROCESS(ldrDmntGetProcessModuleInfo(static_cast<u64>(this->cheat_process_metadata.process_id), proc_modules, util::size(proc_modules), &num_modules));
/* All applications must have two modules. */
/* Only accept one (which means we're attaching to HBL) */
@@ -678,7 +678,7 @@ namespace ams::dmnt::cheat::impl {
}
/* Open a debug handle. */
R_ASSERT_IF_NEW_PROCESS(svcDebugActiveProcess(&this->cheat_process_debug_handle, static_cast<u64>(this->cheat_process_metadata.process_id)));
R_ABORT_UNLESS_IF_NEW_PROCESS(svcDebugActiveProcess(&this->cheat_process_debug_handle, static_cast<u64>(this->cheat_process_metadata.process_id)));
/* Cancel process guard. */
proc_guard.Cancel();
@@ -697,7 +697,7 @@ namespace ams::dmnt::cheat::impl {
return ResultSuccess();
}
#undef R_ASSERT_IF_NEW_PROCESS
#undef R_ABORT_UNLESS_IF_NEW_PROCESS
bool CheatProcessManager::ParseCheats(const char *s, size_t len) {
/* Trigger a VM reload. */

View File

@@ -42,7 +42,7 @@ namespace ams::dmnt::cheat::impl {
Handle debug_handle = this_ptr->WaitReceiveHandle(current_core);
/* Continue events on the correct core. */
R_ASSERT(this_ptr->ContinueDebugEvent(debug_handle));
R_ABORT_UNLESS(this_ptr->ContinueDebugEvent(debug_handle));
/* Signal that we've continued. */
this_ptr->SignalContinued();
@@ -57,7 +57,7 @@ namespace ams::dmnt::cheat::impl {
if (dbg_event.type == svc::DebugEvent_AttachThread) {
u64 out64 = 0;
u32 out32 = 0;
R_ASSERT(svcGetDebugThreadParam(&out64, &out32, debug_handle, dbg_event.info.attach_thread.thread_id, DebugThreadParam_CurrentCore));
R_ABORT_UNLESS(svcGetDebugThreadParam(&out64, &out32, debug_handle, dbg_event.info.attach_thread.thread_id, DebugThreadParam_CurrentCore));
target_core = out32;
}
@@ -94,13 +94,13 @@ namespace ams::dmnt::cheat::impl {
DebugEventsManager() : message_queues{os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1), os::MessageQueue(1)}, thread_stacks{} {
for (size_t i = 0; i < NumCores; i++) {
/* Create thread. */
R_ASSERT(this->threads[i].Initialize(&DebugEventsManager::PerCoreThreadFunction, reinterpret_cast<void *>(this), this->thread_stacks[i], ThreadStackSize, ThreadPriority, i));
R_ABORT_UNLESS(this->threads[i].Initialize(&DebugEventsManager::PerCoreThreadFunction, reinterpret_cast<void *>(this), this->thread_stacks[i], ThreadStackSize, ThreadPriority, i));
/* Set core mask. */
R_ASSERT(svcSetThreadCoreMask(this->threads[i].GetHandle(), i, (1u << i)));
R_ABORT_UNLESS(svcSetThreadCoreMask(this->threads[i].GetHandle(), i, (1u << i)));
/* Start thread. */
R_ASSERT(this->threads[i].Start());
R_ABORT_UNLESS(this->threads[i].Start());
}
}

View File

@@ -630,7 +630,7 @@ namespace ams::dmnt::cheat::impl {
/* However, I don't actually believe it is possible for this to happen. */
/* I guess we'll throw a fatal error here, so as to encourage me to fix the VM */
/* in the event that someone triggers it? I don't know how you'd do that. */
R_ASSERT(ResultVirtualMachineInvalidConditionDepth());
R_ABORT_UNLESS(ResultVirtualMachineInvalidConditionDepth());
}
}

View File

@@ -63,22 +63,22 @@ void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ASSERT(pmdmntInitialize());
R_ASSERT(pminfoInitialize());
R_ASSERT(ldrDmntInitialize());
R_ABORT_UNLESS(pmdmntInitialize());
R_ABORT_UNLESS(pminfoInitialize());
R_ABORT_UNLESS(ldrDmntInitialize());
/* TODO: We provide this on every sysver via ro. Do we need a shim? */
if (hos::GetVersion() >= hos::Version_300) {
R_ASSERT(roDmntInitialize());
R_ABORT_UNLESS(roDmntInitialize());
}
R_ASSERT(nsdevInitialize());
R_ASSERT(lrInitialize());
R_ASSERT(setInitialize());
R_ASSERT(setsysInitialize());
R_ASSERT(hidInitialize());
R_ASSERT(fsInitialize());
R_ABORT_UNLESS(nsdevInitialize());
R_ABORT_UNLESS(lrInitialize());
R_ABORT_UNLESS(setInitialize());
R_ABORT_UNLESS(setsysInitialize());
R_ABORT_UNLESS(hidInitialize());
R_ABORT_UNLESS(fsInitialize());
});
R_ASSERT(fsdevMountSdmc());
R_ABORT_UNLESS(fsdevMountSdmc());
ams::CheckApiVersion();
}
@@ -132,8 +132,8 @@ int main(int argc, char **argv)
{
/* Create services. */
/* TODO: Implement rest of dmnt:- in ams.tma development branch. */
/* R_ASSERT((g_server_manager.RegisterServer<dmnt::cheat::CheatService>(DebugMonitorServiceName, DebugMonitorMaxSessions))); */
R_ASSERT((g_server_manager.RegisterServer<dmnt::cheat::CheatService>(CheatServiceName, CheatMaxSessions)));
/* R_ABORT_UNLESS((g_server_manager.RegisterServer<dmnt::cheat::CheatService>(DebugMonitorServiceName, DebugMonitorMaxSessions))); */
R_ABORT_UNLESS((g_server_manager.RegisterServer<dmnt::cheat::CheatService>(CheatServiceName, CheatMaxSessions)));
/* Loop forever, servicing our services. */
/* Nintendo loops four threads processing on the manager -- we'll loop an extra fifth for our cheat service. */
@@ -143,14 +143,14 @@ int main(int argc, char **argv)
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());
}
}
@@ -160,7 +160,7 @@ int main(int argc, char **argv)
/* 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());
}
}
}

View File

@@ -25,7 +25,7 @@ namespace ams::fatal::srv {
/* Event creator. */
Handle GetFatalDirtyEventReadableHandle() {
Event evt;
R_ASSERT(setsysBindFatalDirtyFlagEvent(&evt));
R_ABORT_UNLESS(setsysBindFatalDirtyFlagEvent(&evt));
return evt.revent;
}

View File

@@ -20,7 +20,7 @@ namespace ams::fatal::srv {
FatalEventManager::FatalEventManager() {
/* Just create all the events. */
for (size_t i = 0; i < FatalEventManager::NumFatalEvents; i++) {
R_ASSERT(eventCreate(&this->events[i], true));
R_ABORT_UNLESS(eventCreate(&this->events[i], true));
}
}

View File

@@ -76,27 +76,27 @@ void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ASSERT(setInitialize());
R_ASSERT(setsysInitialize());
R_ASSERT(pminfoInitialize());
R_ASSERT(i2cInitialize());
R_ASSERT(bpcInitialize());
R_ABORT_UNLESS(setInitialize());
R_ABORT_UNLESS(setsysInitialize());
R_ABORT_UNLESS(pminfoInitialize());
R_ABORT_UNLESS(i2cInitialize());
R_ABORT_UNLESS(bpcInitialize());
if (hos::GetVersion() >= hos::Version_800) {
R_ASSERT(clkrstInitialize());
R_ABORT_UNLESS(clkrstInitialize());
} else {
R_ASSERT(pcvInitialize());
R_ABORT_UNLESS(pcvInitialize());
}
R_ASSERT(lblInitialize());
R_ASSERT(psmInitialize());
R_ASSERT(spsmInitialize());
R_ASSERT(plInitialize());
R_ASSERT(gpioInitialize());
R_ASSERT(fsInitialize());
R_ABORT_UNLESS(lblInitialize());
R_ABORT_UNLESS(psmInitialize());
R_ABORT_UNLESS(spsmInitialize());
R_ABORT_UNLESS(plInitialize());
R_ABORT_UNLESS(gpioInitialize());
R_ABORT_UNLESS(fsInitialize());
});
R_ASSERT(fsdevMountSdmc());
R_ABORT_UNLESS(fsdevMountSdmc());
/* fatal cannot throw fatal, so don't do: ams::CheckApiVersion(); */
}
@@ -144,14 +144,14 @@ namespace {
int main(int argc, char **argv)
{
/* Load shared font. */
R_ASSERT(fatal::srv::font::InitializeSharedFont());
R_ABORT_UNLESS(fatal::srv::font::InitializeSharedFont());
/* Check whether we should throw fatal due to repair process. */
fatal::srv::CheckRepairStatus();
/* Create services. */
R_ASSERT((g_server_manager.RegisterServer<fatal::srv::PrivateService>(PrivateServiceName, PrivateMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<fatal::srv::UserService>(UserServiceName, UserMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<fatal::srv::PrivateService>(PrivateServiceName, PrivateMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<fatal::srv::UserService>(UserServiceName, UserMaxSessions)));
/* Add dirty event holder. */
/* TODO: s_server_manager.AddWaitable(ams::fatal::srv::GetFatalDirtyEvent()); */
@@ -167,7 +167,7 @@ int main(int argc, char **argv)
g_server_manager.AddUserWaitableHolder(signaled_holder);
} else {
/* A server/session was signaled. Have the manager handle it. */
R_ASSERT(g_server_manager.Process(signaled_holder));
R_ABORT_UNLESS(g_server_manager.Process(signaled_holder));
}
}

View File

@@ -39,8 +39,8 @@ namespace ams::fatal::srv {
public:
ServiceContext() {
this->context.ClearState();
R_ASSERT(eventCreate(&this->context.erpt_event, false));
R_ASSERT(eventCreate(&this->context.battery_event, false));
R_ABORT_UNLESS(eventCreate(&this->context.erpt_event, false));
R_ABORT_UNLESS(eventCreate(&this->context.battery_event, false));
this->has_thrown = false;
}

View File

@@ -42,8 +42,8 @@ namespace ams::fatal::srv {
public:
TaskThread() { /* ... */ }
void StartTask(ITask *task) {
R_ASSERT(this->thread.Initialize(&RunTaskImpl, task, task->GetStack(), task->GetStackSize(), TaskThreadPriority));
R_ASSERT(this->thread.Start());
R_ABORT_UNLESS(this->thread.Initialize(&RunTaskImpl, task, task->GetStack(), task->GetStackSize(), TaskThreadPriority));
R_ABORT_UNLESS(this->thread.Start());
}
};
@@ -57,7 +57,7 @@ namespace ams::fatal::srv {
public:
TaskManager() { /* ... */ }
void StartTask(ITask *task) {
AMS_ASSERT(this->task_count < MaxTasks);
AMS_ABORT_UNLESS(this->task_count < MaxTasks);
this->task_threads[this->task_count++].StartTask(task);
}
};

View File

@@ -182,7 +182,7 @@ namespace ams::fatal::srv {
/* Prepare screen for drawing. */
sm::DoWithSession([&]() {
R_ASSERT(PrepareScreenForDrawing());
R_ABORT_UNLESS(PrepareScreenForDrawing());
});
/* Dequeue a buffer. */

View File

@@ -56,7 +56,7 @@ namespace ams::ldr {
Result MountNspFileSystem(const char *device_name, const char *path) {
FsFileSystem fs;
R_TRY(fsOpenFileSystemWithId(&fs, 0, FsFileSystemType_ApplicationPackage, path));
AMS_ASSERT(fsdevMountDevice(device_name, fs) >= 0);
AMS_ABORT_UNLESS(fsdevMountDevice(device_name, fs) >= 0);
return ResultSuccess();
}
@@ -150,7 +150,7 @@ namespace ams::ldr {
/* Try to mount the content path. */
FsFileSystem fs;
R_TRY(fsldrOpenCodeFileSystem(static_cast<u64>(loc.program_id), path, &fs));
AMS_ASSERT(fsdevMountDevice(CodeFileSystemDeviceName, fs) != -1);
AMS_ABORT_UNLESS(fsdevMountDevice(CodeFileSystemDeviceName, fs) != -1);
/* Note that we mounted code. */
this->is_code_mounted = true;
@@ -190,7 +190,7 @@ namespace ams::ldr {
/* Check if we're ready to mount the SD card. */
if (!g_has_mounted_sd_card) {
if (is_sd_initialized) {
R_ASSERT(MountSdCardFileSystem());
R_ABORT_UNLESS(MountSdCardFileSystem());
g_has_mounted_sd_card = true;
}
}
@@ -219,7 +219,7 @@ namespace ams::ldr {
}
void ScopedCodeMount::InitializeOverrideStatus(const ncm::ProgramLocation &loc) {
AMS_ASSERT(!this->has_status);
AMS_ABORT_UNLESS(!this->has_status);
this->override_status = cfg::CaptureOverrideStatus(loc.program_id);
this->has_status = true;
}

View File

@@ -45,7 +45,7 @@ namespace ams::ldr {
}
const cfg::OverrideStatus &GetOverrideStatus() const {
AMS_ASSERT(this->has_status);
AMS_ABORT_UNLESS(this->has_status);
return this->override_status;
}

View File

@@ -92,7 +92,7 @@ namespace ams::ldr::ecs {
R_UNLESS(g_map.size() < MaxExternalContentSourceCount, ldr::ResultTooManyArguments());
/* Clear any sources. */
R_ASSERT(Clear(program_id));
R_ABORT_UNLESS(Clear(program_id));
/* Generate mountpoint. */
char device_name[DeviceNameSizeMax];

View File

@@ -102,7 +102,7 @@ namespace ams::ldr {
}
void LoaderService::AtmosphereClearExternalContentSource(ncm::ProgramId program_id) {
R_ASSERT(ecs::Clear(program_id));
R_ABORT_UNLESS(ecs::Clear(program_id));
}
void LoaderService::AtmosphereHasLaunchedProgram(sf::Out<bool> out, ncm::ProgramId program_id) {

View File

@@ -72,9 +72,9 @@ void __appInit(void) {
/* Initialize services we need. */
sm::DoWithSession([&]() {
R_ASSERT(fsInitialize());
R_ASSERT(lrInitialize());
R_ASSERT(fsldrInitialize());
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(lrInitialize());
R_ABORT_UNLESS(fsldrInitialize());
});
ams::CheckApiVersion();
@@ -115,9 +115,9 @@ namespace {
int main(int argc, char **argv)
{
/* Add services to manager. */
R_ASSERT((g_server_manager.RegisterServer<ldr::pm::ProcessManagerInterface>(ProcessManagerServiceName, ProcessManagerMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<ldr::shell::ShellInterface>(ShellServiceName, ShellMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<ldr::dmnt::DebugMonitorInterface>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::pm::ProcessManagerInterface>(ProcessManagerServiceName, ProcessManagerMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::shell::ShellInterface>(ShellServiceName, ShellMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ldr::dmnt::DebugMonitorInterface>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
/* Loop forever, servicing our services. */
g_server_manager.LoopProcess();

View File

@@ -48,7 +48,7 @@ namespace ams::ldr {
};
constexpr const char *GetNsoName(size_t idx) {
AMS_ASSERT(idx < Nso_Count);
AMS_ABORT_UNLESS(idx < Nso_Count);
constexpr const char *NsoNames[Nso_Count] = {
"rtld",
@@ -606,7 +606,7 @@ namespace ams::ldr {
}
/* Clear the ECS entry for the program. */
R_ASSERT(ecs::Clear(loc.program_id));
R_ABORT_UNLESS(ecs::Clear(loc.program_id));
/* Note that we've created the program. */
SetLaunchedProgram(loc.program_id);

View File

@@ -165,8 +165,8 @@ namespace ams::pm::impl {
std::scoped_lock lk(this->lock);
const size_t index = this->GetProcessInfoIndex(process_info);
AMS_ASSERT(index < MaxProcessInfos);
AMS_ASSERT(this->process_info_allocated[index]);
AMS_ABORT_UNLESS(index < MaxProcessInfos);
AMS_ABORT_UNLESS(this->process_info_allocated[index]);
process_info->~ProcessInfo();
this->process_info_allocated[index] = false;
@@ -308,7 +308,7 @@ namespace ams::pm::impl {
/* Make new process info. */
void *process_info_storage = g_process_info_allocator.AllocateProcessInfoStorage();
AMS_ASSERT(process_info_storage != nullptr);
AMS_ABORT_UNLESS(process_info_storage != nullptr);
ProcessInfo *process_info = new (process_info_storage) ProcessInfo(process_handle, process_id, pin_id, location, override_status);
/* Link new process info. */
@@ -374,7 +374,7 @@ namespace ams::pm::impl {
const ProcessState old_state = process_info->GetState();
{
u64 tmp = 0;
R_ASSERT(svcGetProcessInfo(&tmp, process_info->GetHandle(), ProcessInfoType_ProcessState));
R_ABORT_UNLESS(svcGetProcessInfo(&tmp, process_info->GetHandle(), ProcessInfoType_ProcessState));
process_info->SetState(static_cast<ProcessState>(tmp));
}
const ProcessState new_state = process_info->GetState();
@@ -452,16 +452,16 @@ namespace ams::pm::impl {
/* Initialization. */
Result InitializeProcessManager() {
/* Create events. */
R_ASSERT(g_process_event.InitializeAsInterProcessEvent());
R_ASSERT(g_hook_to_create_process_event.InitializeAsInterProcessEvent());
R_ASSERT(g_hook_to_create_application_process_event.InitializeAsInterProcessEvent());
R_ASSERT(g_boot_finished_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(g_process_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(g_hook_to_create_process_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(g_hook_to_create_application_process_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(g_boot_finished_event.InitializeAsInterProcessEvent());
/* Initialize resource limits. */
R_TRY(resource::InitializeResourceManager());
/* Start thread. */
R_ASSERT(g_process_track_thread.Start());
R_ABORT_UNLESS(g_process_track_thread.Start());
return ResultSuccess();
}
@@ -711,7 +711,7 @@ namespace ams::pm::impl {
/* In 8.0.0, Nintendo added this command, which signals that the boot sysmodule has finished. */
/* Nintendo only signals it in safe mode FIRM, and this function aborts on normal FIRM. */
/* We will signal it always, but only allow this function to succeed on safe mode. */
AMS_ASSERT(spl::IsRecoveryBoot());
AMS_ABORT_UNLESS(spl::IsRecoveryBoot());
*out = g_boot_finished_event.GetReadableHandle();
return ResultSuccess();
}

View File

@@ -147,7 +147,7 @@ namespace ams::pm::resource {
u64 value = 0;
while (true) {
R_ASSERT(svcGetResourceLimitCurrentValue(&value, reslimit_hnd, resource));
R_ABORT_UNLESS(svcGetResourceLimitCurrentValue(&value, reslimit_hnd, resource));
if (value == 0) {
break;
}
@@ -159,7 +159,7 @@ namespace ams::pm::resource {
void WaitApplicationMemoryAvailable() {
u64 value = 0;
while (true) {
R_ASSERT(svcGetSystemInfo(&value, SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application));
R_ABORT_UNLESS(svcGetSystemInfo(&value, SystemInfoType_UsedPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application));
if (value == 0) {
break;
}
@@ -175,10 +175,10 @@ namespace ams::pm::resource {
for (size_t i = 0; i < ResourceLimitGroup_Count; i++) {
if (i == ResourceLimitGroup_System) {
u64 value = 0;
R_ASSERT(svcGetInfo(&value, InfoType_ResourceLimit, INVALID_HANDLE, 0));
R_ABORT_UNLESS(svcGetInfo(&value, InfoType_ResourceLimit, INVALID_HANDLE, 0));
g_resource_limit_handles[i] = static_cast<Handle>(value);
} else {
R_ASSERT(svcCreateResourceLimit(&g_resource_limit_handles[i]));
R_ABORT_UNLESS(svcCreateResourceLimit(&g_resource_limit_handles[i]));
}
}
@@ -210,7 +210,7 @@ namespace ams::pm::resource {
if (hos::GetVersion() >= hos::Version_700) {
/* See how many threads we have available. */
u64 total_threads_available = 0;
R_ASSERT(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads));
R_ABORT_UNLESS(svcGetResourceLimitLimitValue(&total_threads_available, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Threads));
/* See how many threads we're expecting. */
const size_t total_threads_allocated = g_resource_limits[ResourceLimitGroup_System][LimitableResource_Threads] -
@@ -218,7 +218,7 @@ namespace ams::pm::resource {
g_resource_limits[ResourceLimitGroup_Applet][LimitableResource_Threads];
/* Ensure we don't over-commit threads. */
AMS_ASSERT(total_threads_allocated <= total_threads_available);
AMS_ABORT_UNLESS(total_threads_allocated <= total_threads_available);
/* Set number of extra threads. */
g_extra_application_threads_available = total_threads_available - total_threads_allocated;
@@ -231,18 +231,18 @@ namespace ams::pm::resource {
/* Get total memory available. */
u64 total_memory = 0;
R_ASSERT(svcGetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Memory));
R_ABORT_UNLESS(svcGetResourceLimitLimitValue(&total_memory, GetResourceLimitHandle(ResourceLimitGroup_System), LimitableResource_Memory));
/* Get and save application + applet memory. */
R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application));
R_ASSERT(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Applet));
R_ABORT_UNLESS(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Application));
R_ABORT_UNLESS(svcGetSystemInfo(&g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet], SystemInfoType_TotalPhysicalMemorySize, INVALID_HANDLE, PhysicalMemoryInfo_Applet));
const u64 application_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Application];
const u64 applet_size = g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_Applet];
const u64 reserved_non_system_size = (application_size + applet_size + ReservedMemorySize600);
/* Ensure there's enough memory for the system region. */
AMS_ASSERT(reserved_non_system_size < total_memory);
AMS_ABORT_UNLESS(reserved_non_system_size < total_memory);
g_memory_resource_limits[spl::MemoryArrangement_Dynamic][ResourceLimitGroup_System] = total_memory - reserved_non_system_size;
} else {
@@ -267,7 +267,7 @@ namespace ams::pm::resource {
std::scoped_lock lk(g_resource_limit_lock);
for (size_t group = 0; group < ResourceLimitGroup_Count; group++) {
R_ASSERT(SetResourceLimitLimitValues(static_cast<ResourceLimitGroup>(group), g_memory_resource_limits[g_memory_arrangement][group]));
R_ABORT_UNLESS(SetResourceLimitLimitValues(static_cast<ResourceLimitGroup>(group), g_memory_resource_limits[g_memory_arrangement][group]));
}
}
@@ -286,10 +286,10 @@ namespace ams::pm::resource {
/* Starting in 5.0.0, PM does not allow for only one of the sets to fail. */
if (boost_size < g_system_memory_boost_size) {
R_TRY(svcSetUnsafeLimit(boost_size));
R_ASSERT(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
R_ABORT_UNLESS(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
} else {
R_TRY(SetMemoryResourceLimitLimitValue(ResourceLimitGroup_Application, new_app_size));
R_ASSERT(svcSetUnsafeLimit(boost_size));
R_ABORT_UNLESS(svcSetUnsafeLimit(boost_size));
}
} else {
const u64 new_sys_size = g_memory_resource_limits[g_memory_arrangement][ResourceLimitGroup_System] + boost_size;
@@ -340,8 +340,8 @@ namespace ams::pm::resource {
Result GetResourceLimitValues(u64 *out_cur, u64 *out_lim, ResourceLimitGroup group, LimitableResource resource) {
/* Do not allow out of bounds access. */
AMS_ASSERT(group < ResourceLimitGroup_Count);
AMS_ASSERT(resource < LimitableResource_Count);
AMS_ABORT_UNLESS(group < ResourceLimitGroup_Count);
AMS_ABORT_UNLESS(resource < LimitableResource_Count);
const Handle reslimit_hnd = GetResourceLimitHandle(group);
R_TRY(svcGetResourceLimitCurrentValue(out_cur, reslimit_hnd, resource));

View File

@@ -87,12 +87,12 @@ namespace {
/* Get a debug handle. */
os::ManagedHandle debug_handle;
R_ASSERT(svcDebugActiveProcess(debug_handle.GetPointer(), static_cast<u64>(process_id)));
R_ABORT_UNLESS(svcDebugActiveProcess(debug_handle.GetPointer(), static_cast<u64>(process_id)));
/* Loop until we get the event that tells us about the process. */
svc::DebugEventInfo d;
while (true) {
R_ASSERT(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), debug_handle.Get()));
R_ABORT_UNLESS(svcGetDebugEvent(reinterpret_cast<u8 *>(&d), debug_handle.Get()));
if (d.type == svc::DebugEvent_AttachProcess) {
return ncm::ProgramId{d.info.attach_process.program_id};
}
@@ -117,7 +117,7 @@ namespace {
/* Get list of processes, register all privileged ones. */
u32 num_pids;
os::ProcessId pids[ProcessCountMax];
R_ASSERT(svcGetProcessList(&num_pids, reinterpret_cast<u64 *>(pids), ProcessCountMax));
R_ABORT_UNLESS(svcGetProcessList(&num_pids, reinterpret_cast<u64 *>(pids), ProcessCountMax));
for (size_t i = 0; i < num_pids; i++) {
if (min_priv_process_id <= pids[i] && pids[i] <= max_priv_process_id) {
RegisterPrivilegedProcess(pids[i]);
@@ -131,19 +131,19 @@ void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ASSERT(fsprInitialize());
R_ASSERT(smManagerInitialize());
R_ABORT_UNLESS(fsprInitialize());
R_ABORT_UNLESS(smManagerInitialize());
/* This works around a bug with process permissions on < 4.0.0. */
/* It also informs SM of privileged process information. */
RegisterPrivilegedProcesses();
/* Use AMS manager extension to tell SM that FS has been worked around. */
R_ASSERT(sm::manager::EndInitialDefers());
R_ABORT_UNLESS(sm::manager::EndInitialDefers());
R_ASSERT(lrInitialize());
R_ASSERT(ldrPmInitialize());
R_ASSERT(splInitialize());
R_ABORT_UNLESS(lrInitialize());
R_ABORT_UNLESS(ldrPmInitialize());
R_ABORT_UNLESS(splInitialize());
});
ams::CheckApiVersion();
@@ -187,20 +187,20 @@ namespace {
int main(int argc, char **argv)
{
/* Initialize process manager implementation. */
R_ASSERT(pm::impl::InitializeProcessManager());
R_ABORT_UNLESS(pm::impl::InitializeProcessManager());
/* Create Services. */
/* NOTE: Extra sessions have been added to pm:bm and pm:info to facilitate access by the rest of stratosphere. */
/* Also Note: PM was rewritten in 5.0.0, so the shell and dmnt services are different before/after. */
if (hos::GetVersion() >= hos::Version_500) {
R_ASSERT((g_server_manager.RegisterServer<pm::shell::ShellService>(ShellServiceName, ShellMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<pm::dmnt::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<pm::shell::ShellService>(ShellServiceName, ShellMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<pm::dmnt::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
} else {
R_ASSERT((g_server_manager.RegisterServer<pm::shell::ShellServiceDeprecated>(ShellServiceName, ShellMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<pm::dmnt::DebugMonitorServiceDeprecated>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<pm::shell::ShellServiceDeprecated>(ShellServiceName, ShellMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<pm::dmnt::DebugMonitorServiceDeprecated>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
}
R_ASSERT((g_server_manager.RegisterServer<pm::bm::BootModeService>(BootModeServiceName, BootModeMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<pm::info::InformationService>(InformationServiceName, InformationMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<pm::bm::BootModeService>(BootModeServiceName, BootModeMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<pm::info::InformationService>(InformationServiceName, InformationMaxSessions)));
/* Loop forever, servicing our services. */
g_server_manager.LoopProcess();

View File

@@ -37,11 +37,11 @@ namespace ams::pm::shell {
}
void ShellServiceBase::GetProcessEventHandle(sf::OutCopyHandle out) {
R_ASSERT(impl::GetProcessEventHandle(out.GetHandlePointer()));
R_ABORT_UNLESS(impl::GetProcessEventHandle(out.GetHandlePointer()));
}
void ShellServiceBase::GetProcessEventInfo(sf::Out<ProcessEventInfo> out) {
R_ASSERT(impl::GetProcessEventInfo(out.GetPointer()));
R_ABORT_UNLESS(impl::GetProcessEventInfo(out.GetPointer()));
}
Result ShellServiceBase::CleanupProcess(os::ProcessId process_id) {
@@ -53,7 +53,7 @@ namespace ams::pm::shell {
}
void ShellServiceBase::NotifyBootFinished() {
R_ASSERT(impl::NotifyBootFinished());
R_ABORT_UNLESS(impl::NotifyBootFinished());
}
Result ShellServiceBase::GetApplicationProcessIdForShell(sf::Out<os::ProcessId> out) {
@@ -69,7 +69,7 @@ namespace ams::pm::shell {
}
void ShellServiceBase::GetBootFinishedEventHandle(sf::OutCopyHandle out) {
R_ASSERT(impl::GetBootFinishedEventHandle(out.GetHandlePointer()));
R_ABORT_UNLESS(impl::GetBootFinishedEventHandle(out.GetHandlePointer()));
}
}

View File

@@ -83,10 +83,10 @@ namespace ams::ro::impl {
ncm::ProgramId program_id = ncm::ProgramId::Invalid;
if (hos::GetVersion() >= hos::Version_300) {
/* 3.0.0+: Use svcGetInfo. */
R_ASSERT(svcGetInfo(&program_id.value, InfoType_ProgramId, process_h, 0));
R_ABORT_UNLESS(svcGetInfo(&program_id.value, InfoType_ProgramId, process_h, 0));
} else {
/* 1.0.0-2.3.0: We're not inside loader, so ask pm. */
R_ASSERT(pm::info::GetProgramId(&program_id, os::GetProcessId(process_h)));
R_ABORT_UNLESS(pm::info::GetProgramId(&program_id, os::GetProcessId(process_h)));
}
return program_id;
}
@@ -240,7 +240,7 @@ namespace ams::ro::impl {
return nullptr;
}
AMS_ASSERT(context_id < MaxSessions);
AMS_ABORT_UNLESS(context_id < MaxSessions);
return &g_process_contexts[context_id];
}
@@ -267,7 +267,7 @@ namespace ams::ro::impl {
}
}
/* Failure to find a free context is actually an abort condition. */
AMS_ASSERT(false);
AMS_ABORT_UNLESS(false);
}
void FreeContext(size_t context_id) {
@@ -367,7 +367,7 @@ namespace ams::ro::impl {
Result LoadNrr(size_t context_id, Handle process_h, u64 nrr_address, u64 nrr_size, ModuleType expected_type, bool enforce_type) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ASSERT(context != nullptr);
AMS_ABORT_UNLESS(context != nullptr);
/* Get program id. */
const ncm::ProgramId program_id = context->GetProgramId(process_h);
@@ -397,7 +397,7 @@ namespace ams::ro::impl {
Result UnloadNrr(size_t context_id, u64 nrr_address) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ASSERT(context != nullptr);
AMS_ABORT_UNLESS(context != nullptr);
/* Validate address. */
R_UNLESS(util::IsAligned(nrr_address, os::MemoryPageSize), ResultInvalidAddress());
@@ -419,7 +419,7 @@ namespace ams::ro::impl {
Result LoadNro(u64 *out_address, size_t context_id, u64 nro_address, u64 nro_size, u64 bss_address, u64 bss_size) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ASSERT(context != nullptr);
AMS_ABORT_UNLESS(context != nullptr);
/* Validate address/size. */
R_TRY(ValidateAddressAndNonZeroSize(nro_address, nro_size));
@@ -465,7 +465,7 @@ namespace ams::ro::impl {
Result UnloadNro(size_t context_id, u64 nro_address) {
/* Get context. */
ProcessContext *context = GetContextById(context_id);
AMS_ASSERT(context != nullptr);
AMS_ABORT_UNLESS(context != nullptr);
/* Validate address. */
R_UNLESS(util::IsAligned(nro_address, os::MemoryPageSize), ResultInvalidAddress());

View File

@@ -62,15 +62,15 @@ void __appInit(void) {
hos::SetVersionForLibnx();
sm::DoWithSession([&]() {
R_ASSERT(setsysInitialize());
R_ASSERT(fsInitialize());
R_ASSERT(splInitialize());
R_ABORT_UNLESS(setsysInitialize());
R_ABORT_UNLESS(fsInitialize());
R_ABORT_UNLESS(splInitialize());
if (hos::GetVersion() < hos::Version_300) {
R_ASSERT(pminfoInitialize());
R_ABORT_UNLESS(pminfoInitialize());
}
});
R_ASSERT(fsdevMountSdmc());
R_ABORT_UNLESS(fsdevMountSdmc());
ams::CheckApiVersion();
}
@@ -118,11 +118,11 @@ int main(int argc, char **argv)
}
/* Create services. */
R_ASSERT((g_server_manager.RegisterServer<ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::DebugMonitorService>(DebugMonitorServiceName, DebugMonitorMaxSessions)));
R_ASSERT((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForSelf>(ForSelfServiceName, ForSelfMaxSessions)));
if (hos::GetVersion() >= hos::Version_700) {
R_ASSERT((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
R_ABORT_UNLESS((g_server_manager.RegisterServer<ro::Service, +MakeRoServiceForOthers>(ForOthersServiceName, ForOthersMaxSessions)));
}
/* Loop forever, servicing our services. */

View File

@@ -161,11 +161,11 @@ namespace ams::sm::impl {
cfg::GetInitialProcessRange(&this->min, &this->max);
/* Ensure range is sane. */
AMS_ASSERT(this->min <= this->max);
AMS_ABORT_UNLESS(this->min <= this->max);
}
bool IsInitialProcess(os::ProcessId process_id) const {
AMS_ASSERT(process_id != os::InvalidProcessId);
AMS_ABORT_UNLESS(process_id != os::InvalidProcessId);
return this->min <= process_id && process_id <= this->max;
}
};
@@ -228,7 +228,7 @@ namespace ams::sm::impl {
void GetMitmProcessInfo(MitmProcessInfo *out_info, os::ProcessId process_id) {
/* Anything that can request a mitm session must have a process info. */
const auto process_info = GetProcessInfo(process_id);
AMS_ASSERT(process_info != nullptr);
AMS_ABORT_UNLESS(process_info != nullptr);
/* Write to output. */
out_info->process_id = process_id;
@@ -383,7 +383,7 @@ namespace ams::sm::impl {
GetMitmProcessInfo(&client_info, process_id);
if (!IsMitmDisallowed(client_info.program_id)) {
/* We're mitm'd. Assert, because mitm service host dead is an error state. */
R_ASSERT(GetMitmServiceHandleImpl(out, service_info, client_info));
R_ABORT_UNLESS(GetMitmServiceHandleImpl(out, service_info, client_info));
return ResultSuccess();
}
}

View File

@@ -23,7 +23,7 @@ namespace ams::sm {
}
void DmntService::AtmosphereListRecords(const sf::OutArray<ServiceRecord> &records, sf::Out<u64> out_count, u64 offset) {
R_ASSERT(impl::ListServiceRecords(records.GetPointer(), out_count.GetPointer(), offset, records.GetSize()));
R_ABORT_UNLESS(impl::ListServiceRecords(records.GetPointer(), out_count.GetPointer(), offset, records.GetSize()));
}
void DmntService::AtmosphereGetRecordSize(sf::Out<u64> record_size) {

View File

@@ -95,14 +95,14 @@ int main(int argc, char **argv)
/* Create sm:, (and thus allow things to register to it). */
{
Handle sm_h;
R_ASSERT(svcManageNamedPort(&sm_h, "sm:", 0x40));
R_ABORT_UNLESS(svcManageNamedPort(&sm_h, "sm:", 0x40));
g_server_manager.RegisterServer<sm::UserService>(sm_h);
}
/* Create sm:m manually. */
{
Handle smm_h;
R_ASSERT(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1));
R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smm_h, sm::ServiceName::Encode("sm:m"), 1));
g_server_manager.RegisterServer<sm::ManagerService>(smm_h);
}
@@ -110,7 +110,7 @@ int main(int argc, char **argv)
/* Create sm:dmnt manually. */
{
Handle smdmnt_h;
R_ASSERT(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1));
R_ABORT_UNLESS(sm::impl::RegisterServiceForSelf(&smdmnt_h, sm::ServiceName::Encode("sm:dmnt"), 1));
g_server_manager.RegisterServer<sm::DmntService>(smdmnt_h);
}

View File

@@ -27,11 +27,11 @@ namespace ams::sm {
}
void ManagerService::AtmosphereEndInitDefers() {
R_ASSERT(impl::EndInitialDefers());
R_ABORT_UNLESS(impl::EndInitialDefers());
}
void ManagerService::AtmosphereHasMitm(sf::Out<bool> out, ServiceName service) {
R_ASSERT(impl::HasMitm(out.GetPointer(), service));
R_ABORT_UNLESS(impl::HasMitm(out.GetPointer(), service));
}
Result ManagerService::AtmosphereRegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus override_status, const sf::InBuffer &acid_sac, const sf::InBuffer &aci_sac) {

View File

@@ -88,10 +88,10 @@ namespace ams::spl::impl {
u32 perm;
public:
DeviceAddressSpaceMapHelper(Handle h, u64 dst, u64 src, size_t sz, u32 p) : das_hnd(h), dst_addr(dst), src_addr(src), size(sz), perm(p) {
R_ASSERT(svcMapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm));
R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr, this->perm));
}
~DeviceAddressSpaceMapHelper() {
R_ASSERT(svcUnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr));
R_ABORT_UNLESS(svcUnmapDeviceAddressSpace(this->das_hnd, dd::GetCurrentProcessHandle(), this->src_addr, this->size, this->dst_addr));
}
};
@@ -122,33 +122,33 @@ namespace ams::spl::impl {
/* Initialization functionality. */
void InitializeCtrDrbg() {
u8 seed[CtrDrbg::SeedSize];
AMS_ASSERT(smc::GenerateRandomBytes(seed, sizeof(seed)) == smc::Result::Success);
AMS_ABORT_UNLESS(smc::GenerateRandomBytes(seed, sizeof(seed)) == smc::Result::Success);
g_drbg.Initialize(seed);
}
void InitializeSeEvents() {
u64 irq_num;
AMS_ASSERT(smc::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber) == smc::Result::Success);
R_ASSERT(g_se_event.Initialize(irq_num));
AMS_ABORT_UNLESS(smc::GetConfig(&irq_num, 1, SplConfigItem_SecurityEngineIrqNumber) == smc::Result::Success);
R_ABORT_UNLESS(g_se_event.Initialize(irq_num));
R_ASSERT(g_se_keyslot_available_event.InitializeAsInterProcessEvent());
R_ABORT_UNLESS(g_se_keyslot_available_event.InitializeAsInterProcessEvent());
g_se_keyslot_available_event.Signal();
}
void InitializeDeviceAddressSpace() {
/* Create Address Space. */
R_ASSERT(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32)));
R_ABORT_UNLESS(svcCreateDeviceAddressSpace(&g_se_das_hnd, 0, (1ul << 32)));
/* Attach it to the SE. */
R_ASSERT(svcAttachDeviceAddressSpace(svc::DeviceName_Se, g_se_das_hnd));
R_ABORT_UNLESS(svcAttachDeviceAddressSpace(svc::DeviceName_Se, g_se_das_hnd));
const u64 work_buffer_addr = reinterpret_cast<u64>(g_work_buffer);
g_se_mapped_work_buffer_addr = WorkBufferMapBase + (work_buffer_addr % DeviceAddressSpaceAlign);
/* Map the work buffer for the SE. */
R_ASSERT(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, dd::GetCurrentProcessHandle(), work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3));
R_ABORT_UNLESS(svcMapDeviceAddressSpaceAligned(g_se_das_hnd, dd::GetCurrentProcessHandle(), work_buffer_addr, sizeof(g_work_buffer), g_se_mapped_work_buffer_addr, 3));
}
/* RSA OAEP implementation helpers. */

View File

@@ -133,18 +133,18 @@ int main(int argc, char **argv)
spl::impl::Initialize();
/* Create services. */
R_ASSERT(g_server_manager.RegisterServer<spl::RandomService>(RandomServiceName, RandomMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::RandomService>(RandomServiceName, RandomMaxSessions));
if (hos::GetVersion() >= hos::Version_400) {
R_ASSERT(g_server_manager.RegisterServer<spl::GeneralService>(GeneralServiceName, GeneralMaxSessions));
R_ASSERT(g_server_manager.RegisterServer<spl::CryptoService>(CryptoServiceName, CryptoMaxSessions));
R_ASSERT(g_server_manager.RegisterServer<spl::SslService>(SslServiceName, SslMaxSessions));
R_ASSERT(g_server_manager.RegisterServer<spl::EsService>(EsServiceName, EsMaxSessions));
R_ASSERT(g_server_manager.RegisterServer<spl::FsService>(FsServiceName, FsMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::GeneralService>(GeneralServiceName, GeneralMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::CryptoService>(CryptoServiceName, CryptoMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::SslService>(SslServiceName, SslMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::EsService>(EsServiceName, EsMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::FsService>(FsServiceName, FsMaxSessions));
if (hos::GetVersion() >= hos::Version_500) {
R_ASSERT(g_server_manager.RegisterServer<spl::ManuService>(ManuServiceName, ManuMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::ManuService>(ManuServiceName, ManuMaxSessions));
}
} else {
R_ASSERT(g_server_manager.RegisterServer<spl::DeprecatedService>(DeprecatedServiceName, DeprecatedMaxSessions));
R_ABORT_UNLESS(g_server_manager.RegisterServer<spl::DeprecatedService>(DeprecatedServiceName, DeprecatedMaxSessions));
}
/* Loop forever, servicing our services. */