From cf0e104b124da14010ae5238f55c1192367cbb0d Mon Sep 17 00:00:00 2001 From: Chloe M Date: Tue, 14 Jul 2026 00:47:29 -0400 Subject: [PATCH] ptos: ps: Add thread management groundwork Signed-off-by: Chloe M --- service/ptos/head/ps/process.h | 2 +- service/ptos/head/ps/thread.h | 41 ++++++++++++++++++++++++++++++++++ service/ptos/ps/thread.c | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 service/ptos/head/ps/thread.h create mode 100644 service/ptos/ps/thread.c diff --git a/service/ptos/head/ps/process.h b/service/ptos/head/ps/process.h index 2d603bc..ef179ea 100644 --- a/service/ptos/head/ps/process.h +++ b/service/ptos/head/ps/process.h @@ -28,7 +28,7 @@ * @Pid: Process ID * @Flags: Initialization flags */ -typedef struct { +typedef struct _PROCESS { CHAR Name[PS_NAME_MAX]; UQUAD Pid; ULONG Flags; diff --git a/service/ptos/head/ps/thread.h b/service/ptos/head/ps/thread.h new file mode 100644 index 0000000..ee121a9 --- /dev/null +++ b/service/ptos/head/ps/thread.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Thread management + * Author: Chloe M. + */ + +#ifndef _PS_THREAD_H_ +#define _PS_THREAD_H_ 1 + +#include +#include +#include + +#define THREAD_POOL_TAG 'TD' + +struct _PROCESS; + +/* + * Represents a runnable thread that exists within + * processes. + * + * @Tid: Thread ID + * @ThreadLink: Thread queue link + */ +typedef struct _THREAD { + UQUAD Tid; + TAILQ_ENTRY(_THREAD) ThreadLink; +} THREAD; + +/* + * Create a new thread + * + * @Parent: Parent of thread to create + * @Flags: Optional init flags + * @Result: Result is written here + */ +PT_STATUS PsCreateThread(struct _PROCESS *Parent, ULONG Flags, THREAD **Result); + +#endif /* !_PS_THREAD_H_ */ diff --git a/service/ptos/ps/thread.c b/service/ptos/ps/thread.c new file mode 100644 index 0000000..9e30397 --- /dev/null +++ b/service/ptos/ps/thread.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Thread management + * Author: Chloe M. + */ + +#include +#include +#include +#include + +/* Globals */ +static UQUAD NextThreadTid = 0; + +PT_STATUS +PsCreateThread(struct _PROCESS *Parent, ULONG Flags, THREAD **Result) +{ + THREAD *Thread; + + if (Parent == NULL || Result == NULL) { + return STATUS_INVALID_PARAM; + } + + Thread = ExAllocatePoolWithTag( + POOL_NON_PAGED, + sizeof(*Thread), + THREAD_POOL_TAG + ); + + if (Thread == NULL) { + return STATUS_NO_MEMORY; + } + + Thread->Tid = AtomicIncQuad(&NextThreadTid); + *Result = Thread; + return STATUS_SUCCESS; +}