svcBreak: fix prototype, add and use BreakReason enum

This commit is contained in:
fincs 2020-08-04 13:24:50 +02:00
parent e0c1dfe2ce
commit 4c6abe1e41
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
4 changed files with 25 additions and 11 deletions

View File

@ -108,6 +108,20 @@ typedef struct {
u64 X[8]; ///< Values of X0 through X7. u64 X[8]; ///< Values of X0 through X7.
} PACKED SecmonArgs; } 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 /// Code memory mapping operations
typedef enum { typedef enum {
CodeMapOperation_MapOwner=0, ///< Map owner. CodeMapOperation_MapOwner=0, ///< Map owner.
@ -603,14 +617,14 @@ Result svcGetThreadId(u64 *threadID, Handle handle);
///@{ ///@{
/** /**
* @brief Breaks execution. Panic. * @brief Breaks execution.
* @param[in] breakReason Break reason. * @param[in] breakReason Break reason (see \ref BreakReason).
* @param[in] inval1 First break parameter. * @param[in] address Address of the buffer to pass to the debugger.
* @param[in] inval2 Second break parameter. * @param[in] size Size of the buffer to pass to the debugger.
* @return Result code. * @return Result code.
* @note Syscall number 0x26. * @note Syscall number 0x26.
*/ */
Result svcBreak(u32 breakReason, u64 inval1, u64 inval2); Result svcBreak(u32 breakReason, uintptr_t address, uintptr_t size);
///@} ///@}

View File

@ -83,7 +83,7 @@ static bool _leventWait(u32* counter, bool clear, u64 timeout_ns) {
if (R_VALUE(res) == KERNELRESULT(TimedOut)) if (R_VALUE(res) == KERNELRESULT(TimedOut))
return false; // whoops, timed out return false; // whoops, timed out
if (R_VALUE(res) != KERNELRESULT(InvalidState)) if (R_VALUE(res) != KERNELRESULT(InvalidState))
svcBreak(0, 0, 0); // should not happen svcBreak(BreakReason_Assert, 0, 0); // should not happen
} }
if (clear) { if (clear) {
@ -104,7 +104,7 @@ static bool _leventWait(u32* counter, bool clear, u64 timeout_ns) {
} }
else { else {
// Invalid state - should not happen // 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)) if (R_FAILED(res))
svcBreak(0, 0, 0); // should not happen svcBreak(BreakReason_Assert, 0, 0); // should not happen
} }
static void _leventClear(u32* counter) { static void _leventClear(u32* counter) {

View File

@ -57,7 +57,7 @@ void mutexLock(Mutex* m) {
// Ask the kernel to arbitrate the lock for us. // Ask the kernel to arbitrate the lock for us.
if (UNLIKELY(R_FAILED(svcArbitrateLock(value & ~HANDLE_WAIT_MASK, m, cur_handle)))) { if (UNLIKELY(R_FAILED(svcArbitrateLock(value & ~HANDLE_WAIT_MASK, m, cur_handle)))) {
// This should be impossible under normal circumstances. // 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. // 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. // Ask the kernel to arbitrate unlock for us.
if (UNLIKELY(R_FAILED(svcArbitrateUnlock(m)))) { if (UNLIKELY(R_FAILED(svcArbitrateUnlock(m)))) {
// This should be impossible under normal circumstances. // This should be impossible under normal circumstances.
svcBreak(0, 0, 0); svcBreak(BreakReason_Assert, 0, 0);
} }
} }
} }

View File

@ -14,7 +14,7 @@ static void _fatalCmd(Result err, FatalPolicy type, FatalCpuContext *ctx, u32 cm
if (type == FatalPolicy_ErrorScreen && !kernelAbove300()) type = FatalPolicy_ErrorReportAndErrorScreen; if (type == FatalPolicy_ErrorScreen && !kernelAbove300()) type = FatalPolicy_ErrorReportAndErrorScreen;
if (detectDebugger()) { if (detectDebugger()) {
svcBreak(0x80000000, err, 0); svcBreak(BreakReason_Panic | BreakReason_NotificationOnlyFlag, (uintptr_t)&err, sizeof(err));
} }
Handle session; Handle session;