ams: avoid UB infinite loops

This commit is contained in:
Michael Scire 2020-08-13 17:28:29 -07:00
parent 874208b44a
commit 51b5c3d87d
9 changed files with 17 additions and 10 deletions

View file

@ -90,7 +90,7 @@ namespace ams::sc7fw {
reg::ReadWrite(PMC + APBDEV_PMC_DPD_ENABLE, PMC_REG_BITS_ENUM(DPD_ENABLE_ON, ENABLE)); reg::ReadWrite(PMC + APBDEV_PMC_DPD_ENABLE, PMC_REG_BITS_ENUM(DPD_ENABLE_ON, ENABLE));
/* Wait forever until we're asleep. */ /* Wait forever until we're asleep. */
while (true) { /* ... */ } AMS_INFINITE_LOOP();
} }
} }
@ -102,7 +102,9 @@ namespace ams::sc7fw {
NORETURN void ExceptionHandler() { NORETURN void ExceptionHandler() {
/* Write enable to MAIN_RESET. */ /* Write enable to MAIN_RESET. */
reg::Write(PMC + APBDEV_PMC_CNTRL, PMC_REG_BITS_ENUM(CNTRL_MAIN_RESET, ENABLE)); reg::Write(PMC + APBDEV_PMC_CNTRL, PMC_REG_BITS_ENUM(CNTRL_MAIN_RESET, ENABLE));
while (true) { /* ... */ }
/* Wait forever until we're reset. */
AMS_INFINITE_LOOP();
} }
} }

View file

@ -90,7 +90,9 @@ namespace ams::warmboot {
NORETURN void ExceptionHandler() { NORETURN void ExceptionHandler() {
/* Write enable to MAIN_RESET. */ /* Write enable to MAIN_RESET. */
reg::Write(PMC + APBDEV_PMC_CNTRL, PMC_REG_BITS_ENUM(CNTRL_MAIN_RESET, ENABLE)); reg::Write(PMC + APBDEV_PMC_CNTRL, PMC_REG_BITS_ENUM(CNTRL_MAIN_RESET, ENABLE));
while (true) { /* ... */ }
/* Wait forever until we're reset. */
AMS_INFINITE_LOOP();
} }
} }

View file

@ -81,7 +81,8 @@ namespace ams::wdt {
/* Enable the counters. */ /* Enable the counters. */
reg::Write(registers + 0x188, 0x1); reg::Write(registers + 0x188, 0x1);
while (true) { /* ... */ } /* Wait forever until the reboot takes. */
AMS_INFINITE_LOOP();
} }
#endif #endif

View file

@ -69,7 +69,7 @@ namespace ams::kern {
#define MESOSPHERE_UNIMPLEMENTED() MESOSPHERE_PANIC("%s: Unimplemented\n", __PRETTY_FUNCTION__) #define MESOSPHERE_UNIMPLEMENTED() MESOSPHERE_PANIC("%s: Unimplemented\n", __PRETTY_FUNCTION__)
#define MESOSPHERE_ABORT() MESOSPHERE_PANIC("Abort()\n"); #define MESOSPHERE_ABORT() MESOSPHERE_PANIC("Abort()\n");
#define MESOSPHERE_INIT_ABORT() do { /* ... */ } while (true) #define MESOSPHERE_INIT_ABORT() AMS_INFINITE_LOOP()
#define MESOSPHERE_ABORT_UNLESS(expr) \ #define MESOSPHERE_ABORT_UNLESS(expr) \
({ \ ({ \

View file

@ -517,7 +517,7 @@ namespace ams::kern::board::nintendo::nx {
} }
u32 dummy; u32 dummy;
smc::init::ReadWriteRegister(std::addressof(dummy), 0x7000E400, 0x10, 0x10); smc::init::ReadWriteRegister(std::addressof(dummy), 0x7000E400, 0x10, 0x10);
while (true) { /* ... */ } AMS_INFINITE_LOOP();
} }
/* User access. */ /* User access. */

View file

@ -227,7 +227,7 @@ namespace ams::kern::board::nintendo::nx::smc {
void NORETURN Panic(u32 color) { void NORETURN Panic(u32 color) {
SecureMonitorArguments args = { FunctionId_Panic, color }; SecureMonitorArguments args = { FunctionId_Panic, color };
CallPrivilegedSecureMonitorFunction(args); CallPrivilegedSecureMonitorFunction(args);
while (true) { /* ... */ } AMS_INFINITE_LOOP();
} }
void CallSecureMonitorFromUser(ams::svc::lp64::SecureMonitorArguments *args) { void CallSecureMonitorFromUser(ams::svc::lp64::SecureMonitorArguments *args) {

View file

@ -139,7 +139,7 @@ namespace ams::kern {
/* Main() is done, and we should never get to this point. */ /* Main() is done, and we should never get to this point. */
MESOSPHERE_PANIC("Main Thread continued after exit."); MESOSPHERE_PANIC("Main Thread continued after exit.");
while (true) { /* ... */ } AMS_INFINITE_LOOP();
} }
} }

View file

@ -33,7 +33,7 @@ namespace ams::result::impl {
/* TODO: ams::fatal:: */ /* TODO: ams::fatal:: */
fatalThrow(result.GetValue()); fatalThrow(result.GetValue());
while (true) { /* ... */ } AMS_INFINITE_LOOP();
} }
NORETURN WEAK_SYMBOL void OnResultAbort(Result result) { NORETURN WEAK_SYMBOL void OnResultAbort(Result result) {
@ -50,7 +50,7 @@ namespace ams::result::impl {
/* TODO: ams::fatal:: */ /* TODO: ams::fatal:: */
fatalThrow(result.GetValue()); fatalThrow(result.GetValue());
while (true) { /* ... */ } AMS_INFINITE_LOOP();
} }
NORETURN WEAK_SYMBOL void OnResultAssertion(Result result) { NORETURN WEAK_SYMBOL void OnResultAssertion(Result result) {

View file

@ -65,3 +65,5 @@
#define AMS_ASSUME(expr) do { if (!static_cast<bool>((expr))) { __builtin_unreachable(); } } while (0) #define AMS_ASSUME(expr) do { if (!static_cast<bool>((expr))) { __builtin_unreachable(); } } while (0)
#define AMS_CURRENT_FUNCTION_NAME __FUNCTION__ #define AMS_CURRENT_FUNCTION_NAME __FUNCTION__
#define AMS_INFINITE_LOOP() do { __asm__ __volatile__("" ::: "memory"); } while (1)