From 9d7ff0461f2a3aad621123b849067c475f95f9c2 Mon Sep 17 00:00:00 2001 From: Chloe M Date: Mon, 13 Jul 2026 22:01:39 -0400 Subject: [PATCH] ptos: ps: Add process init logic Signed-off-by: Chloe M --- service/ptos/head/ps/process.h | 46 ++++++++++++++++++++++++++++++ service/ptos/ps/process.c | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 service/ptos/head/ps/process.h create mode 100644 service/ptos/ps/process.c diff --git a/service/ptos/head/ps/process.h b/service/ptos/head/ps/process.h new file mode 100644 index 0000000..2d603bc --- /dev/null +++ b/service/ptos/head/ps/process.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Process management + * Author: Chloe M. + */ + +#ifndef _PS_PROCESS_H_ +#define _PS_PROCESS_H_ 1 + +#include +#include + +/* Maximum length of process name */ +#define PS_NAME_MAX 64 + +/* Pool tag for process allocations */ +#define PS_POOL_TAG 'PS' + +/* Process flags */ +#define PS_USER BIT(0) /* Set if user-level */ + +/* + * Represents a running process on the machine + * + * @Name: Name of process + * @Pid: Process ID + * @Flags: Initialization flags + */ +typedef struct { + CHAR Name[PS_NAME_MAX]; + UQUAD Pid; + ULONG Flags; +} PROCESS; + +/* + * Allocate and create a new process descriptor + * + * @Name: Name of process + * @Flags: Initialization flags of process + * @Result: Result is written here + */ +PT_STATUS PsCreateProcess(const CHAR *Name, ULONG Flags, PROCESS **Result); + +#endif /* !_PS_PROCESS_H_ */ diff --git a/service/ptos/ps/process.c b/service/ptos/ps/process.c new file mode 100644 index 0000000..38884e5 --- /dev/null +++ b/service/ptos/ps/process.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Process management + * Author: Chloe M. + */ + +#include +#include +#include +#include + +static UQUAD ProcessId = 0; + +PT_STATUS +PsCreateProcess(const CHAR *Name, ULONG Flags, PROCESS **Result) +{ + USIZE NameLen; + PROCESS *Process; + + if (Name == NULL || Result == NULL) { + return STATUS_INVALID_PARAM; + } + + /* TODO: Support user-level processes */ + if (ISSET(Flags, PS_USER)) { + return STATUS_NOT_SUPPORTED; + } + + NameLen = RtlStrLen(Name); + if (NameLen >= PS_NAME_MAX - 1) { + return STATUS_NAME_TOO_LONG; + } + + Process = ExAllocatePoolWithTag( + POOL_NON_PAGED, + sizeof(*Process), + PS_POOL_TAG + ); + + if (Process == NULL) { + return STATUS_NO_MEMORY; + } + + RtlMemCpy(Process->Name, Name, NameLen); + Process->Pid = AtomicIncQuad(&ProcessId); + Process->Flags = Flags; + *Result = Process; + return STATUS_SUCCESS; +}