rewrite comments into one, unified style
This commit is contained in:
1 parent
6260de0085
commit
467a58c9c6
163 files changed
+3560
-2556
No files matched your search
+27
-22
@@ -1,4 +1,5 @@
|
||||
// ke_process.c - process model
|
||||
// Kernel process model. This file owns address-space metadata, handle tables, and process lifetime transitions.
|
||||
|
||||
#include <string.h>
|
||||
#include <intrin.h>
|
||||
#include <kernel/ke_process.h>
|
||||
@@ -12,14 +13,13 @@
|
||||
#include <kernel/hal/hal_apic.h>
|
||||
#include <ntlite/syscall.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global process list
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global process list.
|
||||
static LIST_ENTRY gProcessList;
|
||||
static SPINLOCK gProcessListLock;
|
||||
static uint32_t gNextProcessId = 0;
|
||||
static PROCESS* gSystemProcess = (PROCESS*)0;
|
||||
|
||||
// Processes init.
|
||||
static void KiProcessInit(void) {
|
||||
static int inited = 0;
|
||||
if (!inited) {
|
||||
@@ -29,11 +29,13 @@ static void KiProcessInit(void) {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns process List.
|
||||
LIST_ENTRY* KeGetProcessList(void) {
|
||||
KiProcessInit();
|
||||
return &gProcessList;
|
||||
}
|
||||
|
||||
// Returns current Process.
|
||||
PROCESS* KeGetCurrentProcess(void) {
|
||||
THREAD* currentThread = KeGetCurrentThread();
|
||||
if (currentThread) {
|
||||
@@ -42,10 +44,12 @@ PROCESS* KeGetCurrentProcess(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns system Process.
|
||||
PROCESS* KeGetSystemProcess(void) {
|
||||
return gSystemProcess;
|
||||
}
|
||||
|
||||
// Creates system Process.
|
||||
KSTATUS KeCreateSystemProcess(PROCESS** out) {
|
||||
if (!out) return STATUS_INVALID_PARAMETER;
|
||||
if (gSystemProcess) {
|
||||
@@ -65,6 +69,7 @@ KSTATUS KeCreateSystemProcess(PROCESS** out) {
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Implements the count Process Handles Locked operation.
|
||||
static uint32_t KiCountProcessHandlesLocked(PROCESS* process) {
|
||||
uint32_t count = 0;
|
||||
if (!process) return 0;
|
||||
@@ -75,6 +80,7 @@ static uint32_t KiCountProcessHandlesLocked(PROCESS* process) {
|
||||
return count;
|
||||
}
|
||||
|
||||
// Copies truncated String.
|
||||
static void KiCopyTruncatedString(char* dst, size_t dstSize, const char* src, size_t srcLen) {
|
||||
if (!dst || dstSize == 0) return;
|
||||
size_t n = 0;
|
||||
@@ -87,6 +93,7 @@ static void KiCopyTruncatedString(char* dst, size_t dstSize, const char* src, si
|
||||
dst[n] = '\0';
|
||||
}
|
||||
|
||||
// Copies process Info.
|
||||
size_t KeCopyProcessInfo(struct SYS_PROCESS_INFO* infoOut, size_t maxCount) {
|
||||
KiProcessInit();
|
||||
|
||||
@@ -151,9 +158,7 @@ size_t KeCopyProcessInfo(struct SYS_PROCESS_INFO* infoOut, size_t maxCount) {
|
||||
return count;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Destructor (called by ObDereferenceObject when RefCount hits zero)
|
||||
// ---------------------------------------------------------------------------
|
||||
// Destructor (called by ObDereferenceObject when RefCount hits zero).
|
||||
static void KiProcessDestroy(OBJECT* obj) {
|
||||
PROCESS* proc = CONTAINING_RECORD(obj, PROCESS, Header);
|
||||
|
||||
@@ -201,9 +206,7 @@ static void KiProcessDestroy(OBJECT* obj) {
|
||||
// Destroy returns.
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// KeCreateProcess
|
||||
// ---------------------------------------------------------------------------
|
||||
// KeCreateProcess.
|
||||
KSTATUS KeCreateProcess(const char* name, PROCESS **out) {
|
||||
KiProcessInit();
|
||||
|
||||
@@ -262,9 +265,7 @@ KSTATUS KeCreateProcess(const char* name, PROCESS **out) {
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// KeSetupUserProcessEnvironment
|
||||
// ---------------------------------------------------------------------------
|
||||
// KeSetupUserProcessEnvironment.
|
||||
static KSTATUS KiCopyEnvironmentStringView(PROCESS* proc,
|
||||
SYS_STRING_VIEW src,
|
||||
uintptr_t* baseOut,
|
||||
@@ -314,6 +315,7 @@ static KSTATUS KiCopyEnvironmentStringViewFixed(PROCESS* proc,
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Releases partial Process Environment.
|
||||
static void KiFreePartialProcessEnvironment(PROCESS* proc) {
|
||||
if (!proc) return;
|
||||
|
||||
@@ -424,9 +426,7 @@ fail:
|
||||
return s;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Process exit / termination
|
||||
// ---------------------------------------------------------------------------
|
||||
// Process exit / termination.
|
||||
static void KiCompleteProcessExitIfLastThread(PROCESS* process) {
|
||||
if (!process) return;
|
||||
|
||||
@@ -439,6 +439,7 @@ static void KiCompleteProcessExitIfLastThread(PROCESS* process) {
|
||||
}
|
||||
}
|
||||
|
||||
// Implements the exit Process operation.
|
||||
void KeExitProcess(PROCESS* process, int exitCode) {
|
||||
if (!process) return;
|
||||
process->ExitCode = exitCode;
|
||||
@@ -450,6 +451,7 @@ void KeExitProcess(PROCESS* process, int exitCode) {
|
||||
KiCompleteProcessExitIfLastThread(process);
|
||||
}
|
||||
|
||||
// Implements the terminate Process operation.
|
||||
KSTATUS KeTerminateProcess(PROCESS* process, int exitCode) {
|
||||
if (!process) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
@@ -483,22 +485,19 @@ KSTATUS KeTerminateProcess(PROCESS* process, int exitCode) {
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Checks whether process Terminating.
|
||||
int KeIsProcessTerminating(PROCESS* process) {
|
||||
return process && process->Terminating != 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// KeGetProcessExitCode
|
||||
// ---------------------------------------------------------------------------
|
||||
// KeGetProcessExitCode.
|
||||
KSTATUS KeGetProcessExitCode(PROCESS* process, int* exitCodeOut) {
|
||||
if (!process || !exitCodeOut) return STATUS_INVALID_PARAMETER;
|
||||
*exitCodeOut = process->ExitCode;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handle table
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handle table.
|
||||
KSTATUS KeAllocateHandleWithRights(PROCESS* process, OBJECT* object, uint32_t rights, uint32_t* handleOut) {
|
||||
if (!process || !object || !handleOut || rights == 0) return STATUS_INVALID_PARAMETER;
|
||||
|
||||
@@ -520,10 +519,12 @@ KSTATUS KeAllocateHandleWithRights(PROCESS* process, OBJECT* object, uint32_t ri
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
// Creates handle.
|
||||
KSTATUS KeAllocateHandle(PROCESS* process, OBJECT* object, uint32_t* handleOut) {
|
||||
return KeAllocateHandleWithRights(process, object, HANDLE_RIGHT_ALL, handleOut);
|
||||
}
|
||||
|
||||
// Releases handle.
|
||||
void KeCloseHandle(PROCESS* process, uint32_t handle) {
|
||||
if (!process || handle == 0 || handle >= HANDLE_TABLE_SIZE) return;
|
||||
|
||||
@@ -540,6 +541,7 @@ void KeCloseHandle(PROCESS* process, uint32_t handle) {
|
||||
KeReleaseSpinlock(&process->HandleLock, flags);
|
||||
}
|
||||
|
||||
// Returns handle With Rights.
|
||||
OBJECT* KeLookupHandleWithRights(PROCESS* process, uint32_t handle, uint32_t requiredRights) {
|
||||
if (!process || handle == 0 || handle >= HANDLE_TABLE_SIZE)
|
||||
return (OBJECT*)0;
|
||||
@@ -554,10 +556,12 @@ OBJECT* KeLookupHandleWithRights(PROCESS* process, uint32_t handle, uint32_t req
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Returns handle.
|
||||
OBJECT* KeLookupHandle(PROCESS* process, uint32_t handle) {
|
||||
return KeLookupHandleWithRights(process, handle, 0);
|
||||
}
|
||||
|
||||
// Returns handle Rights.
|
||||
uint32_t KeGetHandleRights(PROCESS* process, uint32_t handle) {
|
||||
if (!process || handle == 0 || handle >= HANDLE_TABLE_SIZE) return 0;
|
||||
|
||||
@@ -567,6 +571,7 @@ uint32_t KeGetHandleRights(PROCESS* process, uint32_t handle) {
|
||||
return rights;
|
||||
}
|
||||
|
||||
// Returns process By Id.
|
||||
PROCESS* KeGetProcessById(uint32_t pid) {
|
||||
KiProcessInit();
|
||||
uintptr_t flags = KeAcquireSpinlock(&gProcessListLock);
|
||||
|
||||
Reference in new issue
Block a user