diff --git a/nx/include/switch/kernel/svc.h b/nx/include/switch/kernel/svc.h index f10383f4..046345d0 100644 --- a/nx/include/switch/kernel/svc.h +++ b/nx/include/switch/kernel/svc.h @@ -108,6 +108,20 @@ typedef struct { u64 X[8]; ///< Values of X0 through X7. } PACKED SecmonArgs; +/// Break reasons +typedef enum { + BreakReason_Panic = 0, + BreakReason_Assert = 1, + BreakReason_User = 2, + BreakReason_PreLoadDll = 3, + BreakReason_PostLoadDll = 4, + BreakReason_PreUnloadDll = 5, + BreakReason_PostUnloadDll = 6, + BreakReason_CppException = 7, + + BreakReason_NotificationOnlyFlag = 0x80000000, +} BreakReason; + /// Code memory mapping operations typedef enum { CodeMapOperation_MapOwner=0, ///< Map owner. @@ -603,14 +617,14 @@ Result svcGetThreadId(u64 *threadID, Handle handle); ///@{ /** - * @brief Breaks execution. Panic. - * @param[in] breakReason Break reason. - * @param[in] inval1 First break parameter. - * @param[in] inval2 Second break parameter. + * @brief Breaks execution. + * @param[in] breakReason Break reason (see \ref BreakReason). + * @param[in] address Address of the buffer to pass to the debugger. + * @param[in] size Size of the buffer to pass to the debugger. * @return Result code. * @note Syscall number 0x26. */ -Result svcBreak(u32 breakReason, u64 inval1, u64 inval2); +Result svcBreak(u32 breakReason, uintptr_t address, uintptr_t size); ///@} diff --git a/nx/source/kernel/levent.c b/nx/source/kernel/levent.c index 0dfcc21b..771607ae 100644 --- a/nx/source/kernel/levent.c +++ b/nx/source/kernel/levent.c @@ -83,7 +83,7 @@ static bool _leventWait(u32* counter, bool clear, u64 timeout_ns) { if (R_VALUE(res) == KERNELRESULT(TimedOut)) return false; // whoops, timed out if (R_VALUE(res) != KERNELRESULT(InvalidState)) - svcBreak(0, 0, 0); // should not happen + svcBreak(BreakReason_Assert, 0, 0); // should not happen } if (clear) { @@ -104,7 +104,7 @@ static bool _leventWait(u32* counter, bool clear, u64 timeout_ns) { } else { // Invalid state - should not happen - svcBreak(0, 0, 0); + svcBreak(BreakReason_Assert, 0, 0); } } @@ -155,7 +155,7 @@ static void _leventSignal(u32* counter, bool autoclear) { } if (R_FAILED(res)) - svcBreak(0, 0, 0); // should not happen + svcBreak(BreakReason_Assert, 0, 0); // should not happen } static void _leventClear(u32* counter) { diff --git a/nx/source/kernel/mutex.c b/nx/source/kernel/mutex.c index c90957da..86ae2628 100644 --- a/nx/source/kernel/mutex.c +++ b/nx/source/kernel/mutex.c @@ -57,7 +57,7 @@ void mutexLock(Mutex* m) { // Ask the kernel to arbitrate the lock for us. if (UNLIKELY(R_FAILED(svcArbitrateLock(value & ~HANDLE_WAIT_MASK, m, cur_handle)))) { // This should be impossible under normal circumstances. - svcBreak(0, 0, 0); + svcBreak(BreakReason_Assert, 0, 0); } // Reload the value, and check if we got the lock. @@ -126,7 +126,7 @@ void mutexUnlock(Mutex* m) { // Ask the kernel to arbitrate unlock for us. if (UNLIKELY(R_FAILED(svcArbitrateUnlock(m)))) { // This should be impossible under normal circumstances. - svcBreak(0, 0, 0); + svcBreak(BreakReason_Assert, 0, 0); } } } diff --git a/nx/source/services/fatal.c b/nx/source/services/fatal.c index bcfa33cd..fd114404 100644 --- a/nx/source/services/fatal.c +++ b/nx/source/services/fatal.c @@ -14,7 +14,7 @@ static void _fatalCmd(Result err, FatalPolicy type, FatalCpuContext *ctx, u32 cm if (type == FatalPolicy_ErrorScreen && !kernelAbove300()) type = FatalPolicy_ErrorReportAndErrorScreen; if (detectDebugger()) { - svcBreak(0x80000000, err, 0); + svcBreak(BreakReason_Panic | BreakReason_NotificationOnlyFlag, (uintptr_t)&err, sizeof(err)); } Handle session;