From 97b295acbc27fc76303970d262e4eda49d322e5b Mon Sep 17 00:00:00 2001 From: SciresM Date: Tue, 26 Jun 2018 08:28:07 -0700 Subject: [PATCH] Fatal: Only exit process if required, exit cleanly. (#127) * Fatal: Only exit process if required, exit cleanly. --- nx/include/switch/services/fatal.h | 5 +++-- nx/source/services/fatal.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nx/include/switch/services/fatal.h b/nx/include/switch/services/fatal.h index e446fb99..38475494 100644 --- a/nx/include/switch/services/fatal.h +++ b/nx/include/switch/services/fatal.h @@ -7,6 +7,7 @@ #pragma once #include "../types.h" +/// Type of thrown fatal error. typedef enum { FatalType_ErrorReportAndErrorScreen = 0, FatalType_ErrorReport = 1, @@ -24,6 +25,6 @@ void NORETURN fatalSimple(Result err); * @brief Triggers a system fatal error with a custom FatalType. * @param err[in] Result code to throw. * @param err[in] Type of fatal error to throw. - * @note This function does not return. + * @note This function may not return, depending on \ref FatalType. */ -void NORETURN fatalWithType(Result err, FatalType type); +void fatalWithType(Result err, FatalType type); diff --git a/nx/source/services/fatal.c b/nx/source/services/fatal.c index 12c3e686..c3efd037 100644 --- a/nx/source/services/fatal.c +++ b/nx/source/services/fatal.c @@ -10,9 +10,11 @@ void NORETURN fatalSimple(Result err) { /* By default, do not generate an error report. */ fatalWithType(err, FatalType_ErrorScreen); + svcExitProcess(); + __builtin_unreachable(); } -void NORETURN fatalWithType(Result err, FatalType type) { +void fatalWithType(Result err, FatalType type) { Result rc = 0; if (detectDebugger()) { @@ -49,7 +51,14 @@ void NORETURN fatalWithType(Result err, FatalType type) { ipcDispatch(srv); } } - - ((void(*)())0xBADC0DE)(); - __builtin_unreachable(); + + switch (type) { + case FatalType_ErrorReport: + break; + case FatalType_ErrorReportAndErrorScreen: + case FatalType_ErrorScreen: + default: + svcExitProcess(); + __builtin_unreachable(); + } }