diff --git a/service/ptos/head/ps/thread.h b/service/ptos/head/ps/thread.h index e32afce..7bf1624 100644 --- a/service/ptos/head/ps/thread.h +++ b/service/ptos/head/ps/thread.h @@ -36,6 +36,13 @@ typedef struct _THREAD { TAILQ_ENTRY(_THREAD) ThreadLink; } THREAD; +/* + * Exit the current thread + * + * @ExitCode: Exit code to terminate with + */ +NO_RETURN VOID PsExitThread(ULONG ExitCode); + /* * Create a new thread * diff --git a/service/ptos/ps/thread.c b/service/ptos/ps/thread.c index c5dc25d..c9ef638 100644 --- a/service/ptos/ps/thread.c +++ b/service/ptos/ps/thread.c @@ -9,11 +9,14 @@ #include #include #include +#include +#include #include #include /* Globals */ static UQUAD NextThreadTid = 0; +static SCHED_QUEUE ReaperQueue; PT_STATUS PsCreateThread(struct _PROCESS *Parent, ULONG Flags, UPTR Ip, THREAD **Result) @@ -46,3 +49,18 @@ PsCreateThread(struct _PROCESS *Parent, ULONG Flags, UPTR Ip, THREAD **Result) *Result = Thread; return STATUS_SUCCESS; } + +NO_RETURN VOID +PsExitThread(ULONG ExitCode) +{ + KPCR *Kpcr; + + Kpcr = HalKpcrCurrent(); + KeSchedEnqueue(&ReaperQueue, Kpcr->CurrentThread); + Kpcr->CurrentThread = NULL; + HalThreadYield(); + + for (;;) { + HalCpuSuspend(); + } +}