From ee91063bbb49be5805f5bd725fc3b0b189a5e716 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 7 Apr 2021 14:53:12 -0700 Subject: [PATCH] kern: update kdebug process management semantics --- .../libmesosphere/source/kern_k_debug_base.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libraries/libmesosphere/source/kern_k_debug_base.cpp b/libraries/libmesosphere/source/kern_k_debug_base.cpp index bd49cab2c..cdd2e9b70 100644 --- a/libraries/libmesosphere/source/kern_k_debug_base.cpp +++ b/libraries/libmesosphere/source/kern_k_debug_base.cpp @@ -355,6 +355,15 @@ namespace ams::kern { } else if (state == KProcess::State_DebugBreak) { /* If the process is debug breaked, transition it accordingly. */ new_state = KProcess::State_Crashed; + + /* Suspend all the threads in the process. */ + { + auto end = target->GetThreadList().end(); + for (auto it = target->GetThreadList().begin(); it != end; ++it) { + /* Request that we suspend the thread. */ + it->RequestSuspend(KThread::SuspendType_Debug); + } + } } else { /* Otherwise, don't transition. */ new_state = state; @@ -840,9 +849,6 @@ namespace ams::kern { /* If the process isn't null, detach. */ if (process.IsNotNull()) { - /* When we're done detaching, clear the reference we opened when we attached. */ - ON_SCOPE_EXIT { process->Close(); }; - /* Detach. */ { /* Lock both ourselves and the target process. */ @@ -877,6 +883,9 @@ namespace ams::kern { /* Clear our process. */ m_process = nullptr; } + + /* We're done detaching, so clear the reference we opened when we attached. */ + process->Close(); } } }