diff --git a/nx/include/switch/kernel/svc.h b/nx/include/switch/kernel/svc.h index 516fbf07..64a0a4fa 100644 --- a/nx/include/switch/kernel/svc.h +++ b/nx/include/switch/kernel/svc.h @@ -861,12 +861,30 @@ Result svcContinueDebugEvent(Handle debug, u32 flags, u64* tid_list, u32 num_tid Result svcLegacyContinueDebugEvent(Handle debug, u32 flags, u64 threadID); /** - * @brief Gets the context of a thread in a debugging session. + * @brief Gets the context (dump the registers) of a thread in a debugging session. * @return Result code. + * @param[out] ctx Output thread context (register dump). + * @param[in] debug Debug handle. + * @param[in] threadId ID of the thread to dump the context of. + * @param[in] flags Register groups to select, combination of @ref RegisterGroup flags. * @note Syscall number 0x67. + * @warning Official kernel will not dump any CPU GPR if the thread is currently executing a system call (except @ref svcBreak and @ref svcReturnFromException). * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. */ -Result svcGetDebugThreadContext(u8* out, Handle debug, u64 threadID, u32 flags); +Result svcGetDebugThreadContext(ThreadContext* ctx, Handle debug, u64 threadID, u32 flags); + +/** + * @brief Gets the context (dump the registers) of a thread in a debugging session. + * @return Result code. + * @param[in] debug Debug handle. + * @param[in] threadId ID of the thread to set the context of. + * @param[in] ctx Input thread context (register dump). + * @param[in] flags Register groups to select, combination of @ref RegisterGroup flags. + * @note Syscall number 0x68. + * @warning Official kernel will return an error if the thread is currently executing a system call (except @ref svcBreak and @ref svcReturnFromException). + * @warning This is a privileged syscall. Use \ref envIsSyscallHinted to check if it is available. + */ +Result svcSetDebugThreadContext(Handle debug, u64 threadID, const ThreadContext* ctx, u32 flags); ///@} diff --git a/nx/source/kernel/svc.s b/nx/source/kernel/svc.s index 3263e9a9..bad320b6 100644 --- a/nx/source/kernel/svc.s +++ b/nx/source/kernel/svc.s @@ -482,6 +482,11 @@ SVC_BEGIN svcGetDebugThreadContext ret SVC_END +SVC_BEGIN svcSetDebugThreadContext + svc 0x68 + ret +SVC_END + SVC_BEGIN svcQueryDebugProcessMemory str x1, [sp, #-16]! svc 0x69 diff --git a/nx/source/kernel/thread.c b/nx/source/kernel/thread.c index d47ad21d..fa81f4b9 100644 --- a/nx/source/kernel/thread.c +++ b/nx/source/kernel/thread.c @@ -134,3 +134,7 @@ Result threadPause(Thread* t) { Result threadResume(Thread* t) { return svcSetThreadActivity(t->handle, 0); } + +Result threadDumpContext(ThreadContext* ctx, Thread* t) { + return svcGetThreadContext3(ctx, t->handle); +}