1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/internal/ps_x.h
5 * PURPOSE: Internal Inlined Functions for the Process Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Thomas Weidenmueller (w3seek@reactos.org)
8 */
9
10 //
11 // Extract Quantum Settings from the Priority Separation Mask
12 //
13 #define PspPrioritySeparationFromMask(Mask) \
14 ((Mask) & 3)
15
16 #define PspQuantumTypeFromMask(Mask) \
17 ((Mask) & 12)
18
19 #define PspQuantumLengthFromMask(Mask) \
20 ((Mask) & 48)
21
22 //
23 // Cross Thread Flag routines
24 //
25 #define PspSetCrossThreadFlag(Thread, Flag) \
26 InterlockedOr((PLONG)&Thread->CrossThreadFlags, Flag)
27 #define PspClearCrossThreadFlag(Thread, Flag) \
28 InterlockedAnd((PLONG)&Thread->CrossThreadFlags, ~Flag)
29
30 //
31 // Process flag routines
32 //
33 #define PspSetProcessFlag(Process, Flag) \
34 InterlockedOr((PLONG)&Process->Flags, Flag)
35 #define PspClearProcessFlag(Process, Flag) \
36 InterlockedAnd((PLONG)&Process->Flags, ~Flag)
37
38 FORCEINLINE
39 VOID
PspRunCreateThreadNotifyRoutines(IN PETHREAD CurrentThread,IN BOOLEAN Create)40 PspRunCreateThreadNotifyRoutines(IN PETHREAD CurrentThread,
41 IN BOOLEAN Create)
42 {
43 ULONG i;
44
45 /* Check if we have registered routines */
46 if (PspThreadNotifyRoutineCount)
47 {
48 /* Loop callbacks */
49 for (i = 0; i < PSP_MAX_CREATE_THREAD_NOTIFY; i++)
50 {
51 /* Do the callback */
52 ExDoCallBack(&PspThreadNotifyRoutine[i],
53 CurrentThread->Cid.UniqueProcess,
54 CurrentThread->Cid.UniqueThread,
55 (PVOID)(ULONG_PTR)Create);
56 }
57 }
58 }
59
60 FORCEINLINE
61 VOID
PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess,IN BOOLEAN Create)62 PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess,
63 IN BOOLEAN Create)
64 {
65 ULONG i;
66
67 /* Check if we have registered routines */
68 if (PspProcessNotifyRoutineCount)
69 {
70 /* Loop callbacks */
71 for (i = 0; i < PSP_MAX_CREATE_PROCESS_NOTIFY; i++)
72 {
73 /* Do the callback */
74 ExDoCallBack(&PspProcessNotifyRoutine[i],
75 CurrentProcess->InheritedFromUniqueProcessId,
76 CurrentProcess->UniqueProcessId,
77 (PVOID)(ULONG_PTR)Create);
78 }
79 }
80 }
81
82 FORCEINLINE
83 VOID
PspRunLoadImageNotifyRoutines(PUNICODE_STRING FullImageName,HANDLE ProcessId,PIMAGE_INFO ImageInfo)84 PspRunLoadImageNotifyRoutines(PUNICODE_STRING FullImageName,
85 HANDLE ProcessId,
86 PIMAGE_INFO ImageInfo)
87 {
88 ULONG i;
89
90 /* Loop the notify routines */
91 for (i = 0; i < PSP_MAX_LOAD_IMAGE_NOTIFY; ++ i)
92 {
93 /* Do the callback */
94 ExDoCallBack(&PspLoadImageNotifyRoutine[i],
95 FullImageName,
96 ProcessId,
97 ImageInfo);
98 }
99 }
100
101 FORCEINLINE
102 VOID
PspRunLegoRoutine(IN PKTHREAD Thread)103 PspRunLegoRoutine(IN PKTHREAD Thread)
104 {
105 /* Call it */
106 if (PspLegoNotifyRoutine) PspLegoNotifyRoutine(Thread);
107 }
108
109 FORCEINLINE
110 VOID
PspLockProcessSecurityShared(IN PEPROCESS Process)111 PspLockProcessSecurityShared(IN PEPROCESS Process)
112 {
113 /* Enter a Critical Region */
114 KeEnterCriticalRegion();
115
116 /* Lock the Process */
117 ExAcquirePushLockShared(&Process->ProcessLock);
118 }
119
120 FORCEINLINE
121 VOID
PspUnlockProcessSecurityShared(IN PEPROCESS Process)122 PspUnlockProcessSecurityShared(IN PEPROCESS Process)
123 {
124 /* Unlock the Process */
125 ExReleasePushLockShared(&Process->ProcessLock);
126
127 /* Leave Critical Region */
128 KeLeaveCriticalRegion();
129 }
130
131 FORCEINLINE
132 VOID
PspLockProcessSecurityExclusive(IN PEPROCESS Process)133 PspLockProcessSecurityExclusive(IN PEPROCESS Process)
134 {
135 /* Enter a Critical Region */
136 KeEnterCriticalRegion();
137
138 /* Lock the Process */
139 ExAcquirePushLockExclusive(&Process->ProcessLock);
140 }
141
142 FORCEINLINE
143 VOID
PspUnlockProcessSecurityExclusive(IN PEPROCESS Process)144 PspUnlockProcessSecurityExclusive(IN PEPROCESS Process)
145 {
146 /* Unlock the Process */
147 ExReleasePushLockExclusive(&Process->ProcessLock);
148
149 /* Leave Critical Region */
150 KeLeaveCriticalRegion();
151 }
152
153 FORCEINLINE
154 VOID
PspLockThreadSecurityShared(IN PETHREAD Thread)155 PspLockThreadSecurityShared(IN PETHREAD Thread)
156 {
157 /* Enter a Critical Region */
158 KeEnterCriticalRegion();
159
160 /* Lock the Thread */
161 ExAcquirePushLockShared(&Thread->ThreadLock);
162 }
163
164 FORCEINLINE
165 VOID
PspUnlockThreadSecurityShared(IN PETHREAD Thread)166 PspUnlockThreadSecurityShared(IN PETHREAD Thread)
167 {
168 /* Unlock the Thread */
169 ExReleasePushLockShared(&Thread->ThreadLock);
170
171 /* Leave Critical Region */
172 KeLeaveCriticalRegion();
173 }
174
175 FORCEINLINE
176 VOID
PspLockThreadSecurityExclusive(IN PETHREAD Thread)177 PspLockThreadSecurityExclusive(IN PETHREAD Thread)
178 {
179 /* Enter a Critical Region */
180 KeEnterCriticalRegion();
181
182 /* Lock the Thread */
183 ExAcquirePushLockExclusive(&Thread->ThreadLock);
184 }
185
186 FORCEINLINE
187 VOID
PspUnlockThreadSecurityExclusive(IN PETHREAD Thread)188 PspUnlockThreadSecurityExclusive(IN PETHREAD Thread)
189 {
190 /* Unlock the Process */
191 ExReleasePushLockExclusive(&Thread->ThreadLock);
192
193 /* Leave Critical Thread */
194 KeLeaveCriticalRegion();
195 }
196
197 FORCEINLINE
198 PEPROCESS
_PsGetCurrentProcess(VOID)199 _PsGetCurrentProcess(VOID)
200 {
201 /* Get the current process */
202 return (PEPROCESS)KeGetCurrentThread()->ApcState.Process;
203 }
204