My Project
Loading...
Searching...
No Matches
cid.c
Go to the documentation of this file.
1/*++
2
3Module Name:
4
5 cid.c
6
7Purpose:
8
9 This translation unit contains the implementation of client IDS of processes and threads. (PID/TID)
10
11Author:
12
13 slep (Matanel) 2025.
14
15Revision History:
16
17--*/
18
19#include "../../includes/ps.h"
20#include "../../includes/ob.h"
21#include "../../includes/ht.h"
22#include "../../assert.h"
23
24PHANDLE_TABLE PspCidTable = NULL; // The main table.
25
26void
28 void
29)
30
31/*++
32
33 Routine description:
34
35 Initializes the CID Table.
36
37 Arguments:
38
39 None.
40
41 Return Values:
42
43 None, on failure it bugchecks.
44
45--*/
46
47{
49 assert(PspCidTable != NULL);
51
52 // Claim the first handle, HANDLE 4 (pid) is the PID of the SystemProcess, it must not be used.
54
55 // Set the system process's handle table to the CID Table.
56}
57
60 IN PEPROCESS Process
61)
62
63/*++
64
65 Routine description:
66
67 Creates a PID for the specified Process.
68
69 Arguments:
70
71 [IN] PEPROCESS Process - The process to create the PID for.
72
73 Return Values:
74
75 The HANDLE (pid) for the process.
76
77--*/
78
79{
80 // Basically, return the handle from the PspCidTable.
81 // The PID/TID is a NULL access, it is only used to identify a process
82 // But to NOT authenticate it, routines like MtOpenProcess (future) would check the HANDLE of a process itself
83 // (e.g PspCreateProcess returns it), but not the PID, dumbo bumbo.
84 return HtCreateHandle(PspCidTable, (void*)Process, 0);
85}
86
89 IN PETHREAD Thread
90)
91
92/*++
93
94 Routine description:
95
96 Creates a TID for the specified thread.
97
98 Arguments:
99
100 [IN] PETHREAD Thread - The thread to create the TID for.
101
102 Return Values:
103
104 The HANDLE (tid) for the thread.
105
106--*/
107
108{
109 return HtCreateHandle(PspCidTable, (void*)Thread, 0);
110}
111
114 IN HANDLE ProcessId
115)
116
117/*++
118
119 Routine description:
120
121 Finds the process associated with the PID given.
122
123 Arguments:
124
125 [IN] HANDLE ProcessId - The PID of the process.
126
127 Return Values:
128
129 Pointer to Process associated with the PID, or NULL if none.
130
131--*/
132
133{
134 return HtGetObject(PspCidTable, ProcessId, NULL);
135}
136
139 IN HANDLE ThreadId
140)
141
142/*++
143
144 Routine description:
145
146 Finds the thread associated with the TID given.
147
148 Arguments:
149
150 [IN] HANDLE ThreadId - The TID of the thread.
151
152 Return Values:
153
154 Pointer to Thread associated with the TID, or NULL if none.
155
156--*/
157
158{
159 return HtGetObject(PspCidTable, ThreadId, NULL);
160}
161
162void
164 IN HANDLE Cid
165)
166
167/*++
168
169 Routine description:
170
171 Frees the CID (PID,TID)
172
173 Arguments:
174
175 [IN] HANDLE Cid - CID Allocated.
176
177 Return Values:
178
179 None.
180
181--*/
182
183{
185}
#define IN
Definition annotations.h:7
#define assert(...)
Definition assert.h:57
NORETURN void MeBugCheck(IN enum _BUGCHECK_CODES BugCheckCode)
Definition bugcheck.c:214
void PsInitializeCidTable(void)
Definition cid.c:27
PETHREAD PsLookupThreadByThreadId(IN HANDLE ThreadId)
Definition cid.c:138
HANDLE PsAllocateThreadId(IN PETHREAD Thread)
Definition cid.c:88
PHANDLE_TABLE PspCidTable
Definition cid.c:24
PEPROCESS PsLookupProcessByProcessId(IN HANDLE ProcessId)
Definition cid.c:113
HANDLE PsAllocateProcessId(IN PEPROCESS Process)
Definition cid.c:59
void PsFreeCid(IN HANDLE Cid)
Definition cid.c:163
EPROCESS * PEPROCESS
Definition core.h:50
ETHREAD * PETHREAD
Definition core.h:42
void * HtGetObject(PHANDLE_TABLE Table, HANDLE Handle, PHANDLE_TABLE_ENTRY *OutEntry)
Definition handle.c:389
PHANDLE_TABLE HtCreateHandleTable(IN PEPROCESS Process)
Definition handle.c:87
HANDLE HtCreateHandle(PHANDLE_TABLE Table, void *Object, uint32_t Access)
Definition handle.c:269
void HtDeleteHandle(PHANDLE_TABLE Table, HANDLE Handle)
Definition handle.c:333
struct _HANDLE_TABLE * PHANDLE_TABLE
int32_t HANDLE
Definition ht.h:59
@ CID_TABLE_NULL
Definition me.h:133
#define MT_PROCESS_ALL_ACCESS
Definition ps.h:89
EPROCESS PsInitialSystemProcess
Definition kernel.c:162