From add18d868ff6dfb9c39a2f2483e669d60d0fd222 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sat, 28 Sep 2019 15:13:20 -0700 Subject: [PATCH] sts: add STS_UNREACHABLE_DEFAULT_CASE() --- .../fs_directory_savedata_filesystem.cpp | 4 ++-- .../source/fs_mitm/fsmitm_layeredrom.cpp | 4 +--- .../boot/source/boot_check_battery.cpp | 6 ++---- stratosphere/boot/source/boot_display.cpp | 3 +-- stratosphere/boot/source/boot_pmic_driver.cpp | 2 +- .../source/gpio/gpio_initial_configuration.cpp | 5 ++--- .../boot/source/i2c/driver/i2c_api.cpp | 3 +-- .../i2c/driver/impl/i2c_bus_accessor.cpp | 3 +-- .../i2c/driver/impl/i2c_driver_types.hpp | 6 ++---- .../source/i2c/driver/impl/i2c_session.cpp | 3 +-- .../pinmux/pinmux_initial_configuration.cpp | 5 ++--- stratosphere/fatal/source/fatal_service.cpp | 5 ++--- .../include/stratosphere/defines.hpp | 2 ++ .../source/firmware_version.cpp | 8 ++------ .../source/os/os_system_event.cpp | 18 ++++++------------ .../source/os/os_waitable_holder.cpp | 6 ++---- .../libstratosphere/source/spl/spl_api.cpp | 3 +-- .../source/updater/updater_api.cpp | 18 ++++++------------ .../source/updater/updater_bis_management.hpp | 11 +++++++---- .../source/updater/updater_paths.cpp | 9 +++------ .../loader/source/ldr_process_creation.cpp | 3 +-- stratosphere/pm/source/boot2/boot2_api.cpp | 7 +------ .../pm/source/impl/pm_process_manager.cpp | 3 +-- 23 files changed, 50 insertions(+), 87 deletions(-) diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_directory_savedata_filesystem.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_directory_savedata_filesystem.cpp index bc50a0892..54f1aa66a 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_directory_savedata_filesystem.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_directory_savedata_filesystem.cpp @@ -109,7 +109,7 @@ Result DirectorySaveDataFileSystem::AllocateWorkBuffer(void **out_buf, size_t *o size_t try_size = ideal_size; /* Repeatedly try to allocate until success. */ - while (try_size > 0x200) { + while (true) { void *buf = malloc(try_size); if (buf != nullptr) { *out_buf = buf; @@ -119,11 +119,11 @@ Result DirectorySaveDataFileSystem::AllocateWorkBuffer(void **out_buf, size_t *o /* Divide size by two. */ try_size >>= 1; + STS_ASSERT(try_size > 0x200); } /* TODO: Return a result here? Nintendo does not, but they have other allocation failed results. */ /* Consider returning ResultFsAllocationFailureInDirectorySaveDataFileSystem? */ - std::abort(); } Result DirectorySaveDataFileSystem::GetFullPath(char *out, size_t out_size, const char *relative_path) { diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layeredrom.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layeredrom.cpp index f5abdde40..2378445d2 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layeredrom.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_layeredrom.cpp @@ -122,9 +122,7 @@ Result LayeredRomFS::Read(void *buffer, size_t size, u64 offset) { R_ASSERT(this->file_romfs->Read((void *)((uintptr_t)buffer + read_so_far), cur_read_size, cur_source->base_source_info.offset + (offset - cur_source->virtual_offset))); } break; - default: - std::abort(); - break; + STS_UNREACHABLE_DEFAULT_CASE(); } read_so_far += cur_read_size; offset += cur_read_size; diff --git a/stratosphere/boot/source/boot_check_battery.cpp b/stratosphere/boot/source/boot_check_battery.cpp index 97c39eba2..c4aa3443d 100644 --- a/stratosphere/boot/source/boot_check_battery.cpp +++ b/stratosphere/boot/source/boot_check_battery.cpp @@ -100,8 +100,7 @@ namespace sts::boot { return &BatteryChargeParameters1; case 2: return &BatteryChargeParameters2; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -281,8 +280,7 @@ namespace sts::boot { case CheckBatteryResult::Reboot: RebootSystem(); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/stratosphere/boot/source/boot_display.cpp b/stratosphere/boot/source/boot_display.cpp index bb4cdb354..b608a6c9b 100644 --- a/stratosphere/boot/source/boot_display.cpp +++ b/stratosphere/boot/source/boot_display.cpp @@ -110,8 +110,7 @@ namespace sts::boot { case DsiSleepOrRegisterWriteKind_Sleep: svcSleepThread(1'000'000ul * u64(reg_writes[i].offset)); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } } diff --git a/stratosphere/boot/source/boot_pmic_driver.cpp b/stratosphere/boot/source/boot_pmic_driver.cpp index b57967258..d1de3c678 100644 --- a/stratosphere/boot/source/boot_pmic_driver.cpp +++ b/stratosphere/boot/source/boot_pmic_driver.cpp @@ -89,7 +89,7 @@ namespace sts::boot { /* Allow up to 5 seconds for shutdown/reboot to take place. */ svcSleepThread(5'000'000'000ul); - std::abort(); + STS_ASSERT(false); } void PmicDriver::FinalizeBattery(BatteryDriver *battery_driver) { diff --git a/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp b/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp index efccbf28c..0f254b995 100644 --- a/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp +++ b/stratosphere/boot/source/gpio/gpio_initial_configuration.cpp @@ -69,9 +69,8 @@ namespace sts::gpio { configs = InitialConfigsIowa; num_configs = NumInitialConfigsIowa; break; - default: - /* Unknown hardware type, we can't proceed. */ - std::abort(); + /* Unknown hardware type, we can't proceed. */ + STS_UNREACHABLE_DEFAULT_CASE(); } } else { /* Until 2.0.0, the GPIO map for Icosa was used for all hardware types. */ diff --git a/stratosphere/boot/source/i2c/driver/i2c_api.cpp b/stratosphere/boot/source/i2c/driver/i2c_api.cpp index 47824ebf8..21f959e81 100644 --- a/stratosphere/boot/source/i2c/driver/i2c_api.cpp +++ b/stratosphere/boot/source/i2c/driver/i2c_api.cpp @@ -70,8 +70,7 @@ namespace sts::i2c::driver { svcSleepThread(us * 1'000ul); } break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } return ResultSuccess; } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp index cedc570a8..2a7ea42dc 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_bus_accessor.cpp @@ -282,8 +282,7 @@ namespace sts::i2c::driver::impl { src_div = 0x02; debounce = 0; break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } if (speed_mode == SpeedMode::HighSpeed) { diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp b/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp index d6d014870..0848246b4 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_driver_types.hpp @@ -61,8 +61,7 @@ namespace sts::i2c::driver::impl { return PcvModule_I2C5; case Bus::I2C6: return PcvModule_I2C6; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -80,8 +79,7 @@ namespace sts::i2c::driver::impl { return Bus::I2C5; case PcvModule_I2C6: return Bus::I2C6; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/stratosphere/boot/source/i2c/driver/impl/i2c_session.cpp b/stratosphere/boot/source/i2c/driver/impl/i2c_session.cpp index 5efd04988..4e39dd106 100644 --- a/stratosphere/boot/source/i2c/driver/impl/i2c_session.cpp +++ b/stratosphere/boot/source/i2c/driver/impl/i2c_session.cpp @@ -76,8 +76,7 @@ namespace sts::i2c::driver::impl { case Command::Receive: R_TRY(this->bus_accessor->Receive(reinterpret_cast(dst), num_bytes, option, this->addressing_mode, this->slave_address)); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } return ResultSuccess; diff --git a/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp b/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp index 03a70eb62..f54f1c630 100644 --- a/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp +++ b/stratosphere/boot/source/pinmux/pinmux_initial_configuration.cpp @@ -60,9 +60,8 @@ namespace sts::pinmux { configs = InitialConfigsIowa; num_configs = NumInitialConfigsIowa; break; - default: - /* Unknown hardware type, we can't proceed. */ - std::abort(); + /* Unknown hardware type, we can't proceed. */ + STS_UNREACHABLE_DEFAULT_CASE(); } /* Ensure we found an appropriate config. */ diff --git a/stratosphere/fatal/source/fatal_service.cpp b/stratosphere/fatal/source/fatal_service.cpp index e59b02c3e..45fa9a631 100644 --- a/stratosphere/fatal/source/fatal_service.cpp +++ b/stratosphere/fatal/source/fatal_service.cpp @@ -122,9 +122,8 @@ namespace sts::fatal::srv { RunTasks(&this->context); } break; - default: - /* N aborts here. Should we just return an error code? */ - std::abort(); + /* N aborts here. Should we just return an error code? */ + STS_UNREACHABLE_DEFAULT_CASE(); } return ResultSuccess; diff --git a/stratosphere/libstratosphere/include/stratosphere/defines.hpp b/stratosphere/libstratosphere/include/stratosphere/defines.hpp index aecf6aa7e..3cd70b67a 100644 --- a/stratosphere/libstratosphere/include/stratosphere/defines.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/defines.hpp @@ -21,6 +21,8 @@ #define STS_ASSERT(expr) do { if (!(expr)) { std::abort(); } } while (0) +#define STS_UNREACHABLE_DEFAULT_CASE() default: std::abort() + #define NON_COPYABLE(cls) \ cls(const cls&) = delete; \ cls& operator=(const cls&) = delete diff --git a/stratosphere/libstratosphere/source/firmware_version.cpp b/stratosphere/libstratosphere/source/firmware_version.cpp index c444ad496..cc1344a78 100644 --- a/stratosphere/libstratosphere/source/firmware_version.cpp +++ b/stratosphere/libstratosphere/source/firmware_version.cpp @@ -77,9 +77,7 @@ static void _CacheValues(void) case AtmosphereTargetFirmware_900: g_firmware_version = FirmwareVersion_900; break; - default: - std::abort(); - break; + STS_UNREACHABLE_DEFAULT_CASE(); } __atomic_store_n(&g_HasCached, true, __ATOMIC_SEQ_CST); @@ -145,9 +143,7 @@ void SetFirmwareVersionForLibnx() { minor = 0; micro = 0; break; - default: - std::abort(); - break; + STS_UNREACHABLE_DEFAULT_CASE(); } hosversionSet(MAKEHOSVERSION(major, minor, micro)); } diff --git a/stratosphere/libstratosphere/source/os/os_system_event.cpp b/stratosphere/libstratosphere/source/os/os_system_event.cpp index 1e64fa031..2e596a9ca 100644 --- a/stratosphere/libstratosphere/source/os/os_system_event.cpp +++ b/stratosphere/libstratosphere/source/os/os_system_event.cpp @@ -116,8 +116,7 @@ namespace sts::os { case SystemEventState::InterProcessEvent: this->GetInterProcessEvent().~InterProcessEvent(); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } this->state = SystemEventState::Uninitialized; } @@ -131,8 +130,7 @@ namespace sts::os { this->GetInterProcessEvent().Signal(); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -145,8 +143,7 @@ namespace sts::os { this->GetInterProcessEvent().Reset(); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } void SystemEvent::Wait() { @@ -158,8 +155,7 @@ namespace sts::os { this->GetInterProcessEvent().Wait(); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -170,8 +166,7 @@ namespace sts::os { case SystemEventState::InterProcessEvent: return this->GetInterProcessEvent().TryWait(); case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -182,8 +177,7 @@ namespace sts::os { case SystemEventState::InterProcessEvent: return this->GetInterProcessEvent().TimedWait(ns); case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } } diff --git a/stratosphere/libstratosphere/source/os/os_waitable_holder.cpp b/stratosphere/libstratosphere/source/os/os_waitable_holder.cpp index c44b65f51..b908f3d07 100644 --- a/stratosphere/libstratosphere/source/os/os_waitable_holder.cpp +++ b/stratosphere/libstratosphere/source/os/os_waitable_holder.cpp @@ -48,8 +48,7 @@ namespace sts::os { new (GetPointer(this->impl_storage)) impl::WaitableHolderOfInterProcessEvent(&event->GetInterProcessEvent()); break; case SystemEventState::Uninitialized: - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } /* Set user-data. */ @@ -81,8 +80,7 @@ namespace sts::os { case MessageQueueWaitKind::ForNotEmpty: new (GetPointer(this->impl_storage)) impl::WaitableHolderOfMessageQueueForNotEmpty(message_queue); break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } /* Set user-data. */ diff --git a/stratosphere/libstratosphere/source/spl/spl_api.cpp b/stratosphere/libstratosphere/source/spl/spl_api.cpp index 140d44a17..23c3eb2ba 100644 --- a/stratosphere/libstratosphere/source/spl/spl_api.cpp +++ b/stratosphere/libstratosphere/source/spl/spl_api.cpp @@ -70,8 +70,7 @@ namespace sts::spl { case HardwareType::Hoag: case HardwareType::Iowa: return true; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/stratosphere/libstratosphere/source/updater/updater_api.cpp b/stratosphere/libstratosphere/source/updater/updater_api.cpp index d078b9650..7481d533b 100644 --- a/stratosphere/libstratosphere/source/updater/updater_api.cpp +++ b/stratosphere/libstratosphere/source/updater/updater_api.cpp @@ -72,8 +72,7 @@ namespace sts::updater { return true; case BootImageUpdateType::Mariko: return false; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -83,8 +82,7 @@ namespace sts::updater { return true; case BootImageUpdateType::Mariko: return false; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -94,8 +92,7 @@ namespace sts::updater { return NcmContentMetaType_BootImagePackage; case BootModeType::Safe: return NcmContentMetaType_BootImagePackageSafe; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -185,8 +182,7 @@ namespace sts::updater { return VerifyBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type); case BootModeType::Safe: return VerifyBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type); - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -311,8 +307,7 @@ namespace sts::updater { return UpdateBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type); case BootModeType::Safe: return UpdateBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type); - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -505,8 +500,7 @@ namespace sts::updater { case spl::HardwareType::Hoag: case spl::HardwareType::Iowa: return BootImageUpdateType::Mariko; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/stratosphere/libstratosphere/source/updater/updater_bis_management.hpp b/stratosphere/libstratosphere/source/updater/updater_bis_management.hpp index 83078e21e..829d465df 100644 --- a/stratosphere/libstratosphere/source/updater/updater_bis_management.hpp +++ b/stratosphere/libstratosphere/source/updater/updater_bis_management.hpp @@ -130,12 +130,16 @@ namespace sts::updater { PartitionAccessor(FsBisStorageId id) : BisAccessor(id) { } private: constexpr const OffsetSizeType *FindEntry(EnumType which) { + const OffsetSizeType *entry = nullptr; for (size_t i = 0; i < Meta::NumEntries; i++) { if (Meta::Entries[i].which == which) { - return &Meta::Entries[i]; + entry = &Meta::Entries[i]; + break; } } - std::abort(); + + STS_ASSERT(entry != nullptr); + return entry; } public: Result Read(size_t *out_size, void *dst, size_t size, EnumType which) { @@ -194,8 +198,7 @@ namespace sts::updater { return FsBisStorageId_BootConfigAndPackage2RepairMain; case Package2Type::RepairSub: return FsBisStorageId_BootConfigAndPackage2RepairSub; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } diff --git a/stratosphere/libstratosphere/source/updater/updater_paths.cpp b/stratosphere/libstratosphere/source/updater/updater_paths.cpp index 228d89c4b..01c90612e 100644 --- a/stratosphere/libstratosphere/source/updater/updater_paths.cpp +++ b/stratosphere/libstratosphere/source/updater/updater_paths.cpp @@ -72,8 +72,7 @@ namespace sts::updater { constexpr const char *candidates[] = {BctPathA, BctPathNx}; return ChooseCandidatePath(candidates, util::size(candidates)); } - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -89,8 +88,7 @@ namespace sts::updater { constexpr const char *candidates[] = {Package1PathA, Package1PathNx}; return ChooseCandidatePath(candidates, util::size(candidates)); } - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } @@ -106,8 +104,7 @@ namespace sts::updater { constexpr const char *candidates[] = {Package2PathA, Package2PathNx}; return ChooseCandidatePath(candidates, util::size(candidates)); } - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE();; } } diff --git a/stratosphere/loader/source/ldr_process_creation.cpp b/stratosphere/loader/source/ldr_process_creation.cpp index 148060652..5f4d35294 100644 --- a/stratosphere/loader/source/ldr_process_creation.cpp +++ b/stratosphere/loader/source/ldr_process_creation.cpp @@ -515,8 +515,7 @@ namespace sts::ldr { aslr_start = map::AslrBase64Bit; aslr_size = map::AslrSize64Bit; break; - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } } else { /* On 1.0.0, only 2 address space types existed. */ diff --git a/stratosphere/pm/source/boot2/boot2_api.cpp b/stratosphere/pm/source/boot2/boot2_api.cpp index 524776d49..385a3d816 100644 --- a/stratosphere/pm/source/boot2/boot2_api.cpp +++ b/stratosphere/pm/source/boot2/boot2_api.cpp @@ -144,14 +144,9 @@ namespace sts::boot2 { switch (pm::shell::LaunchTitle(&process_id, loc, launch_flags)) { case ResultKernelResourceExhausted: - /* Out of resource! */ - std::abort(); case ResultKernelOutOfMemory: - /* Out of memory! */ - std::abort(); case ResultKernelLimitReached: - /* Limit Reached! */ - std::abort(); + STS_ASSERT(false); default: /* We don't care about other issues. */ break; diff --git a/stratosphere/pm/source/impl/pm_process_manager.cpp b/stratosphere/pm/source/impl/pm_process_manager.cpp index 271af34fe..6ddd31eb5 100644 --- a/stratosphere/pm/source/impl/pm_process_manager.cpp +++ b/stratosphere/pm/source/impl/pm_process_manager.cpp @@ -134,8 +134,7 @@ namespace sts::pm::impl { return static_cast(ProcessEventDeprecated::DebugRunning); case ProcessEvent::DebugSuspended: return static_cast(ProcessEventDeprecated::DebugSuspended); - default: - std::abort(); + STS_UNREACHABLE_DEFAULT_CASE(); } }