From 0e404e436ba33b452e6574950f1c086c0f6a69a1 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Wed, 15 Jul 2026 21:27:20 +0000 Subject: [PATCH] ptos: thread: Bugcheck if root thread killed Signed-off-by: Chloe M. --- service/ptos/ps/thread.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/service/ptos/ps/thread.c b/service/ptos/ps/thread.c index 6136cc8..be71b56 100644 --- a/service/ptos/ps/thread.c +++ b/service/ptos/ps/thread.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -54,9 +55,22 @@ NO_RETURN VOID PsExitThread(ULONG ExitCode) { KPCR *Kpcr; + THREAD *CurrentThread; + PROCESS *CurrentProcess; Kpcr = HalKpcrCurrent(); - KeSchedEnqueue(&ReaperQueue, Kpcr->CurrentThread); + CurrentThread = Kpcr->CurrentThread; + CurrentProcess = CurrentThread->Parent; + + /* Cannot kill the root thread */ + if (CurrentThread->Tid == 1 && CurrentProcess->Pid == 1) { + KeBugCheck( + BUGCHECK_SYSTEMPROC_KILLED, + "crts.sys terminated\n" + ); + } + + KeSchedEnqueue(&ReaperQueue, CurrentThread); Kpcr->CurrentThread = NULL; HalThreadYield();