#pragma once // ke_process.h - process model // A process owns a handle table and a list of threads. // There is one shared address space - processes do not own one. #include #include #include #include #define PROCESS_NAME_MAX 64 #define HANDLE_TABLE_SIZE 256 typedef struct PROCESS { OBJECT Header; /* must be first */ uint32_t ProcessId; char Name[PROCESS_NAME_MAX]; /* UTF-8 */ char CurrentDirectory[512]; SPINLOCK CwdLock; /* Thread list. */ LIST_ENTRY ThreadList; /* links THREAD.ProcessLink */ uint32_t ThreadCount; /* Handle table. Index 0 is always NULL (the invalid handle). Entries are OBJECT pointers, each holding a reference. */ OBJECT* Handles[HANDLE_TABLE_SIZE]; SPINLOCK HandleLock; int ExitCode; /* Signaled (manual-reset) when the process exits. Waiters block on this via KeWaitForEvent. */ EVENT* ExitEvent; LIST_ENTRY GlobalLink; /* node in the global process list */ } PROCESS; KSTATUS KeCreateProcess(const char* name, PROCESS **out); void KeExitProcess(PROCESS* process, int exitCode); KSTATUS KeGetProcessExitCode(PROCESS* process, int* exitCodeOut); /* Handle table operations. */ KSTATUS KeAllocateHandle(PROCESS* process, OBJECT* object, uint32_t* handleOut); void KeCloseHandle(PROCESS* process, uint32_t handle); OBJECT* KeLookupHandle(PROCESS* process, uint32_t handle); /* Return the global process list head (kernel-internal). */ LIST_ENTRY* KeGetProcessList(void); PROCESS* KeGetCurrentProcess(void);