My Project
Loading...
Searching...
No Matches
psmgr.c
Go to the documentation of this file.
1/*++
2
3Module Name:
4
5 psmgr.c
6
7Purpose:
8
9 This translation unit contains the initialization routines of the Process & Thread subsystem.
10
11Author:
12
13 slep (Matanel) 2025.
14
15Revision History:
16
17--*/
18
19#include "../../includes/ps.h"
20#include "../../includes/ob.h"
21
22// Explanation for future me or anything going over my kernel.
23// Instead of creating processes and deleting them when exiting, we use an object manager
24// To automatically do this for us when the reference count for the required thread ends.
25// It defines how should the process / thread be created (With what pool, what access rights)
26// It supplements the core functionality of security for the process & threads life, and access.
27
28// Reference count reaches 0 -> Dump Routine -> Deletion Routine (depends on kind of thread)
29
32
33static void PsTerminateProcessWrap(void* Object) {
35}
36
37static
39PsInitializeProcessThreadManager(
40 void
41)
42
43/*++
44
45 Routine description:
46
47 Initializes the process & thread subsystem.
48
49 Arguments:
50
51 None.
52
53 Return Values:
54
55 MTSTATUS Status codes representing if succeeded or not.
56 If we didn't succeed, system should bugcheck with status code.
57
58--*/
59
60{
61 // Define how each thread & process be created and deleted.
62 MTSTATUS status;
63 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
64 kmemset(&ObjectTypeInitializer, 0, sizeof(OBJECT_TYPE_INITIALIZER));
65
66 // Processes
67 char* Name = "Process";
68 ObjectTypeInitializer.PoolType = NonPagedPool;
69#ifdef DEBUG
70 ObjectTypeInitializer.DumpProcedure = NULL; // TODO DUMP PROC!
71#else
72 ObjectTypeInitializer.DumpProcedure = NULL;
73#endif
74 ObjectTypeInitializer.DeleteProcedure = NULL; // We will page fault, TODO PROCESS.
75 ObjectTypeInitializer.ValidAccessRights = MT_PROCESS_ALL_ACCESS;
76 status = ObCreateObjectType(Name, &ObjectTypeInitializer, &PsProcessType);
77 if (MT_FAILURE(status)) return status;
78
79 // Threads
80 Name = "Thread";
81 ObjectTypeInitializer.PoolType = NonPagedPool;
82#ifdef DEBUG
83 ObjectTypeInitializer.DumpProcedure = NULL; // TODO DUMP PROC!
84#else
85 ObjectTypeInitializer.DumpProcedure = NULL;
86#endif
87 ObjectTypeInitializer.DeleteProcedure = &PsDeleteThread;
88 ObjectTypeInitializer.ValidAccessRights = MT_THREAD_ALL_ACCESS;
89 status = ObCreateObjectType(Name, &ObjectTypeInitializer, &PsThreadType);
90 if (MT_FAILURE(status)) return status;
91
92 return MT_SUCCESS;
93}
94
95
98 IN enum _PS_PHASE_ROUTINE Phase
99)
100
101{
102 if (Phase == PS_PHASE_INITIALIZE_SYSTEM) {
103 // Initialize the PS Subsystem.
104 // Initialize the CID Table.
106
107 // Initialize the process & thread subsystem.
108 MTSTATUS st = PsInitializeProcessThreadManager();
109 return st;
110 }
111 else if (Phase == PS_PHASE_INITIALIZE_WORKER_THREADS) {
113 return MT_SUCCESS;
114 }
115 else {
117 }
118}
119
#define IN
Definition annotations.h:7
NORETURN void MeBugCheck(IN enum _BUGCHECK_CODES BugCheckCode)
Definition bugcheck.c:214
void PsInitializeCidTable(void)
Definition cid.c:27
EPROCESS * PEPROCESS
Definition core.h:50
@ INVALID_INITIALIZATION_PHASE
Definition me.h:124
@ NonPagedPool
Definition mm.h:316
FORCEINLINE void * kmemset(void *dest, int64_t val, uint64_t len)
Definition mm.h:540
#define MT_SUCCESS
Definition mtstatus.h:22
#define MT_FAILURE(Status)
Definition mtstatus.h:16
int32_t MTSTATUS
Definition mtstatus.h:12
MTSTATUS ObCreateObjectType(IN char *TypeName, IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer, OUT POBJECT_TYPE *ReturnedObjectType)
Definition ob.c:60
struct _OBJECT_TYPE * POBJECT_TYPE
struct _OBJECT_TYPE_INITIALIZER OBJECT_TYPE_INITIALIZER
void PsTerminateProcess(IN PEPROCESS Process)
Definition process.c:231
_PS_PHASE_ROUTINE
Definition ps.h:55
@ PS_PHASE_INITIALIZE_SYSTEM
Definition ps.h:56
@ PS_PHASE_INITIALIZE_WORKER_THREADS
Definition ps.h:57
#define MT_THREAD_ALL_ACCESS
Definition ps.h:72
#define MT_PROCESS_ALL_ACCESS
Definition ps.h:89
POBJECT_TYPE PsThreadType
Definition psmgr.c:31
POBJECT_TYPE PsProcessType
Definition psmgr.c:30
MTSTATUS PsInitializeSystem(IN enum _PS_PHASE_ROUTINE Phase)
Definition psmgr.c:97
void PsInitializeWorkerThreads(void)
Definition pswork.c:89
OB_DELETE_METHOD DeleteProcedure
Definition ob.h:43
OB_DUMP_METHOD DumpProcedure
Definition ob.h:42
POOL_TYPE PoolType
Definition ob.h:39
uint32_t ValidAccessRights
Definition ob.h:41
void PsDeleteThread(IN void *Object)
Definition thread.c:220