sts: add STS_UNREACHABLE_DEFAULT_CASE()

This commit is contained in:
Michael Scire 2019-09-28 15:13:20 -07:00 committed by SciresM
parent 609a302e16
commit add18d868f
23 changed files with 50 additions and 87 deletions

View file

@ -109,7 +109,7 @@ Result DirectorySaveDataFileSystem::AllocateWorkBuffer(void **out_buf, size_t *o
size_t try_size = ideal_size; size_t try_size = ideal_size;
/* Repeatedly try to allocate until success. */ /* Repeatedly try to allocate until success. */
while (try_size > 0x200) { while (true) {
void *buf = malloc(try_size); void *buf = malloc(try_size);
if (buf != nullptr) { if (buf != nullptr) {
*out_buf = buf; *out_buf = buf;
@ -119,11 +119,11 @@ Result DirectorySaveDataFileSystem::AllocateWorkBuffer(void **out_buf, size_t *o
/* Divide size by two. */ /* Divide size by two. */
try_size >>= 1; try_size >>= 1;
STS_ASSERT(try_size > 0x200);
} }
/* TODO: Return a result here? Nintendo does not, but they have other allocation failed results. */ /* TODO: Return a result here? Nintendo does not, but they have other allocation failed results. */
/* Consider returning ResultFsAllocationFailureInDirectorySaveDataFileSystem? */ /* Consider returning ResultFsAllocationFailureInDirectorySaveDataFileSystem? */
std::abort();
} }
Result DirectorySaveDataFileSystem::GetFullPath(char *out, size_t out_size, const char *relative_path) { Result DirectorySaveDataFileSystem::GetFullPath(char *out, size_t out_size, const char *relative_path) {

View file

@ -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))); 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; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
break;
} }
read_so_far += cur_read_size; read_so_far += cur_read_size;
offset += cur_read_size; offset += cur_read_size;

View file

@ -100,8 +100,7 @@ namespace sts::boot {
return &BatteryChargeParameters1; return &BatteryChargeParameters1;
case 2: case 2:
return &BatteryChargeParameters2; return &BatteryChargeParameters2;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -281,8 +280,7 @@ namespace sts::boot {
case CheckBatteryResult::Reboot: case CheckBatteryResult::Reboot:
RebootSystem(); RebootSystem();
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }

View file

@ -110,8 +110,7 @@ namespace sts::boot {
case DsiSleepOrRegisterWriteKind_Sleep: case DsiSleepOrRegisterWriteKind_Sleep:
svcSleepThread(1'000'000ul * u64(reg_writes[i].offset)); svcSleepThread(1'000'000ul * u64(reg_writes[i].offset));
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
} }

View file

@ -89,7 +89,7 @@ namespace sts::boot {
/* Allow up to 5 seconds for shutdown/reboot to take place. */ /* Allow up to 5 seconds for shutdown/reboot to take place. */
svcSleepThread(5'000'000'000ul); svcSleepThread(5'000'000'000ul);
std::abort(); STS_ASSERT(false);
} }
void PmicDriver::FinalizeBattery(BatteryDriver *battery_driver) { void PmicDriver::FinalizeBattery(BatteryDriver *battery_driver) {

View file

@ -69,9 +69,8 @@ namespace sts::gpio {
configs = InitialConfigsIowa; configs = InitialConfigsIowa;
num_configs = NumInitialConfigsIowa; num_configs = NumInitialConfigsIowa;
break; break;
default: /* Unknown hardware type, we can't proceed. */
/* Unknown hardware type, we can't proceed. */ STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} else { } else {
/* Until 2.0.0, the GPIO map for Icosa was used for all hardware types. */ /* Until 2.0.0, the GPIO map for Icosa was used for all hardware types. */

View file

@ -70,8 +70,7 @@ namespace sts::i2c::driver {
svcSleepThread(us * 1'000ul); svcSleepThread(us * 1'000ul);
} }
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
return ResultSuccess; return ResultSuccess;
} }

View file

@ -282,8 +282,7 @@ namespace sts::i2c::driver::impl {
src_div = 0x02; src_div = 0x02;
debounce = 0; debounce = 0;
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
if (speed_mode == SpeedMode::HighSpeed) { if (speed_mode == SpeedMode::HighSpeed) {

View file

@ -61,8 +61,7 @@ namespace sts::i2c::driver::impl {
return PcvModule_I2C5; return PcvModule_I2C5;
case Bus::I2C6: case Bus::I2C6:
return PcvModule_I2C6; return PcvModule_I2C6;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -80,8 +79,7 @@ namespace sts::i2c::driver::impl {
return Bus::I2C5; return Bus::I2C5;
case PcvModule_I2C6: case PcvModule_I2C6:
return Bus::I2C6; return Bus::I2C6;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }

View file

@ -76,8 +76,7 @@ namespace sts::i2c::driver::impl {
case Command::Receive: case Command::Receive:
R_TRY(this->bus_accessor->Receive(reinterpret_cast<u8 *>(dst), num_bytes, option, this->addressing_mode, this->slave_address)); R_TRY(this->bus_accessor->Receive(reinterpret_cast<u8 *>(dst), num_bytes, option, this->addressing_mode, this->slave_address));
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
return ResultSuccess; return ResultSuccess;

View file

@ -60,9 +60,8 @@ namespace sts::pinmux {
configs = InitialConfigsIowa; configs = InitialConfigsIowa;
num_configs = NumInitialConfigsIowa; num_configs = NumInitialConfigsIowa;
break; break;
default: /* Unknown hardware type, we can't proceed. */
/* Unknown hardware type, we can't proceed. */ STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
/* Ensure we found an appropriate config. */ /* Ensure we found an appropriate config. */

View file

@ -122,9 +122,8 @@ namespace sts::fatal::srv {
RunTasks(&this->context); RunTasks(&this->context);
} }
break; break;
default: /* N aborts here. Should we just return an error code? */
/* N aborts here. Should we just return an error code? */ STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
return ResultSuccess; return ResultSuccess;

View file

@ -21,6 +21,8 @@
#define STS_ASSERT(expr) do { if (!(expr)) { std::abort(); } } while (0) #define STS_ASSERT(expr) do { if (!(expr)) { std::abort(); } } while (0)
#define STS_UNREACHABLE_DEFAULT_CASE() default: std::abort()
#define NON_COPYABLE(cls) \ #define NON_COPYABLE(cls) \
cls(const cls&) = delete; \ cls(const cls&) = delete; \
cls& operator=(const cls&) = delete cls& operator=(const cls&) = delete

View file

@ -77,9 +77,7 @@ static void _CacheValues(void)
case AtmosphereTargetFirmware_900: case AtmosphereTargetFirmware_900:
g_firmware_version = FirmwareVersion_900; g_firmware_version = FirmwareVersion_900;
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
break;
} }
__atomic_store_n(&g_HasCached, true, __ATOMIC_SEQ_CST); __atomic_store_n(&g_HasCached, true, __ATOMIC_SEQ_CST);
@ -145,9 +143,7 @@ void SetFirmwareVersionForLibnx() {
minor = 0; minor = 0;
micro = 0; micro = 0;
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
break;
} }
hosversionSet(MAKEHOSVERSION(major, minor, micro)); hosversionSet(MAKEHOSVERSION(major, minor, micro));
} }

View file

@ -116,8 +116,7 @@ namespace sts::os {
case SystemEventState::InterProcessEvent: case SystemEventState::InterProcessEvent:
this->GetInterProcessEvent().~InterProcessEvent(); this->GetInterProcessEvent().~InterProcessEvent();
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
this->state = SystemEventState::Uninitialized; this->state = SystemEventState::Uninitialized;
} }
@ -131,8 +130,7 @@ namespace sts::os {
this->GetInterProcessEvent().Signal(); this->GetInterProcessEvent().Signal();
break; break;
case SystemEventState::Uninitialized: case SystemEventState::Uninitialized:
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -145,8 +143,7 @@ namespace sts::os {
this->GetInterProcessEvent().Reset(); this->GetInterProcessEvent().Reset();
break; break;
case SystemEventState::Uninitialized: case SystemEventState::Uninitialized:
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
void SystemEvent::Wait() { void SystemEvent::Wait() {
@ -158,8 +155,7 @@ namespace sts::os {
this->GetInterProcessEvent().Wait(); this->GetInterProcessEvent().Wait();
break; break;
case SystemEventState::Uninitialized: case SystemEventState::Uninitialized:
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -170,8 +166,7 @@ namespace sts::os {
case SystemEventState::InterProcessEvent: case SystemEventState::InterProcessEvent:
return this->GetInterProcessEvent().TryWait(); return this->GetInterProcessEvent().TryWait();
case SystemEventState::Uninitialized: case SystemEventState::Uninitialized:
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -182,8 +177,7 @@ namespace sts::os {
case SystemEventState::InterProcessEvent: case SystemEventState::InterProcessEvent:
return this->GetInterProcessEvent().TimedWait(ns); return this->GetInterProcessEvent().TimedWait(ns);
case SystemEventState::Uninitialized: case SystemEventState::Uninitialized:
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
} }

View file

@ -48,8 +48,7 @@ namespace sts::os {
new (GetPointer(this->impl_storage)) impl::WaitableHolderOfInterProcessEvent(&event->GetInterProcessEvent()); new (GetPointer(this->impl_storage)) impl::WaitableHolderOfInterProcessEvent(&event->GetInterProcessEvent());
break; break;
case SystemEventState::Uninitialized: case SystemEventState::Uninitialized:
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
/* Set user-data. */ /* Set user-data. */
@ -81,8 +80,7 @@ namespace sts::os {
case MessageQueueWaitKind::ForNotEmpty: case MessageQueueWaitKind::ForNotEmpty:
new (GetPointer(this->impl_storage)) impl::WaitableHolderOfMessageQueueForNotEmpty(message_queue); new (GetPointer(this->impl_storage)) impl::WaitableHolderOfMessageQueueForNotEmpty(message_queue);
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
/* Set user-data. */ /* Set user-data. */

View file

@ -70,8 +70,7 @@ namespace sts::spl {
case HardwareType::Hoag: case HardwareType::Hoag:
case HardwareType::Iowa: case HardwareType::Iowa:
return true; return true;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }

View file

@ -72,8 +72,7 @@ namespace sts::updater {
return true; return true;
case BootImageUpdateType::Mariko: case BootImageUpdateType::Mariko:
return false; return false;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -83,8 +82,7 @@ namespace sts::updater {
return true; return true;
case BootImageUpdateType::Mariko: case BootImageUpdateType::Mariko:
return false; return false;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -94,8 +92,7 @@ namespace sts::updater {
return NcmContentMetaType_BootImagePackage; return NcmContentMetaType_BootImagePackage;
case BootModeType::Safe: case BootModeType::Safe:
return NcmContentMetaType_BootImagePackageSafe; return NcmContentMetaType_BootImagePackageSafe;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -185,8 +182,7 @@ namespace sts::updater {
return VerifyBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type); return VerifyBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type);
case BootModeType::Safe: case BootModeType::Safe:
return VerifyBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type); return VerifyBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type);
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -311,8 +307,7 @@ namespace sts::updater {
return UpdateBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type); return UpdateBootImagesNormal(data_id, work_buffer, work_buffer_size, boot_image_update_type);
case BootModeType::Safe: case BootModeType::Safe:
return UpdateBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type); return UpdateBootImagesSafe(data_id, work_buffer, work_buffer_size, boot_image_update_type);
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -505,8 +500,7 @@ namespace sts::updater {
case spl::HardwareType::Hoag: case spl::HardwareType::Hoag:
case spl::HardwareType::Iowa: case spl::HardwareType::Iowa:
return BootImageUpdateType::Mariko; return BootImageUpdateType::Mariko;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }

View file

@ -130,12 +130,16 @@ namespace sts::updater {
PartitionAccessor(FsBisStorageId id) : BisAccessor(id) { } PartitionAccessor(FsBisStorageId id) : BisAccessor(id) { }
private: private:
constexpr const OffsetSizeType *FindEntry(EnumType which) { constexpr const OffsetSizeType *FindEntry(EnumType which) {
const OffsetSizeType *entry = nullptr;
for (size_t i = 0; i < Meta::NumEntries; i++) { for (size_t i = 0; i < Meta::NumEntries; i++) {
if (Meta::Entries[i].which == which) { if (Meta::Entries[i].which == which) {
return &Meta::Entries[i]; entry = &Meta::Entries[i];
break;
} }
} }
std::abort();
STS_ASSERT(entry != nullptr);
return entry;
} }
public: public:
Result Read(size_t *out_size, void *dst, size_t size, EnumType which) { Result Read(size_t *out_size, void *dst, size_t size, EnumType which) {
@ -194,8 +198,7 @@ namespace sts::updater {
return FsBisStorageId_BootConfigAndPackage2RepairMain; return FsBisStorageId_BootConfigAndPackage2RepairMain;
case Package2Type::RepairSub: case Package2Type::RepairSub:
return FsBisStorageId_BootConfigAndPackage2RepairSub; return FsBisStorageId_BootConfigAndPackage2RepairSub;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }

View file

@ -72,8 +72,7 @@ namespace sts::updater {
constexpr const char *candidates[] = {BctPathA, BctPathNx}; constexpr const char *candidates[] = {BctPathA, BctPathNx};
return ChooseCandidatePath(candidates, util::size(candidates)); return ChooseCandidatePath(candidates, util::size(candidates));
} }
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -89,8 +88,7 @@ namespace sts::updater {
constexpr const char *candidates[] = {Package1PathA, Package1PathNx}; constexpr const char *candidates[] = {Package1PathA, Package1PathNx};
return ChooseCandidatePath(candidates, util::size(candidates)); return ChooseCandidatePath(candidates, util::size(candidates));
} }
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }
@ -106,8 +104,7 @@ namespace sts::updater {
constexpr const char *candidates[] = {Package2PathA, Package2PathNx}; constexpr const char *candidates[] = {Package2PathA, Package2PathNx};
return ChooseCandidatePath(candidates, util::size(candidates)); return ChooseCandidatePath(candidates, util::size(candidates));
} }
default: STS_UNREACHABLE_DEFAULT_CASE();;
std::abort();
} }
} }

View file

@ -515,8 +515,7 @@ namespace sts::ldr {
aslr_start = map::AslrBase64Bit; aslr_start = map::AslrBase64Bit;
aslr_size = map::AslrSize64Bit; aslr_size = map::AslrSize64Bit;
break; break;
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} else { } else {
/* On 1.0.0, only 2 address space types existed. */ /* On 1.0.0, only 2 address space types existed. */

View file

@ -144,14 +144,9 @@ namespace sts::boot2 {
switch (pm::shell::LaunchTitle(&process_id, loc, launch_flags)) { switch (pm::shell::LaunchTitle(&process_id, loc, launch_flags)) {
case ResultKernelResourceExhausted: case ResultKernelResourceExhausted:
/* Out of resource! */
std::abort();
case ResultKernelOutOfMemory: case ResultKernelOutOfMemory:
/* Out of memory! */
std::abort();
case ResultKernelLimitReached: case ResultKernelLimitReached:
/* Limit Reached! */ STS_ASSERT(false);
std::abort();
default: default:
/* We don't care about other issues. */ /* We don't care about other issues. */
break; break;

View file

@ -134,8 +134,7 @@ namespace sts::pm::impl {
return static_cast<u32>(ProcessEventDeprecated::DebugRunning); return static_cast<u32>(ProcessEventDeprecated::DebugRunning);
case ProcessEvent::DebugSuspended: case ProcessEvent::DebugSuspended:
return static_cast<u32>(ProcessEventDeprecated::DebugSuspended); return static_cast<u32>(ProcessEventDeprecated::DebugSuspended);
default: STS_UNREACHABLE_DEFAULT_CASE();
std::abort();
} }
} }