ams: avoid UB infinite loops

This commit is contained in:
Michael Scire 2020-08-13 17:28:29 -07:00
parent 9f765dd4ee
commit 9f7bc49438
7 changed files with 10 additions and 7 deletions

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)