2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/ps_x.h
5 * PURPOSE: Intenral Inlined Functions for the Process Manager
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Thomas Weidenmueller (w3seek@reactos.org)
11 // Extract Quantum Settings from the Priority Separation Mask
13 #define PspPrioritySeparationFromMask(Mask) \
16 #define PspQuantumTypeFromMask(Mask) \
19 #define PspQuantumLengthFromMask(Mask) \
23 // Cross Thread Flag routines
25 #define PspSetCrossThreadFlag(Thread, Flag) \
26 InterlockedOr((PLONG)&Thread->CrossThreadFlags, Flag)
27 #define PspClearCrossThreadFlag(Thread, Flag) \
28 InterlockedAnd((PLONG)&Thread->CrossThreadFlags, ~Flag)
31 // Process flag routines
33 #define PspSetProcessFlag(Process, Flag) \
34 InterlockedOr((PLONG)&Process->Flags, Flag)
35 #define PspClearProcessFlag(Process, Flag) \
36 InterlockedAnd((PLONG)&Process->Flags, ~Flag)
40 PspRunCreateThreadNotifyRoutines(IN PETHREAD CurrentThread
,
45 /* Check if we have registered routines */
46 if (PspThreadNotifyRoutineCount
)
49 for (i
= 0; i
< PSP_MAX_CREATE_THREAD_NOTIFY
; i
++)
52 ExDoCallBack(&PspThreadNotifyRoutine
[i
],
53 CurrentThread
->Cid
.UniqueProcess
,
54 CurrentThread
->Cid
.UniqueThread
,
55 (PVOID
)(ULONG_PTR
)Create
);
62 PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess
,
67 /* Check if we have registered routines */
68 if (PspProcessNotifyRoutineCount
)
71 for (i
= 0; i
< PSP_MAX_CREATE_PROCESS_NOTIFY
; i
++)
74 ExDoCallBack(&PspProcessNotifyRoutine
[i
],
75 CurrentProcess
->InheritedFromUniqueProcessId
,
76 CurrentProcess
->UniqueProcessId
,
77 (PVOID
)(ULONG_PTR
)Create
);
84 PspRunLoadImageNotifyRoutines(PUNICODE_STRING FullImageName
,
86 PIMAGE_INFO ImageInfo
)
90 /* Loop the notify routines */
91 for (i
= 0; i
< PSP_MAX_LOAD_IMAGE_NOTIFY
; ++ i
)
94 ExDoCallBack(&PspLoadImageNotifyRoutine
[i
],
103 PspRunLegoRoutine(IN PKTHREAD Thread
)
106 if (PspLegoNotifyRoutine
) PspLegoNotifyRoutine(Thread
);
111 PspLockProcessSecurityShared(IN PEPROCESS Process
)
113 /* Enter a Critical Region */
114 KeEnterCriticalRegion();
116 /* Lock the Process */
117 ExAcquirePushLockShared(&Process
->ProcessLock
);
122 PspUnlockProcessSecurityShared(IN PEPROCESS Process
)
124 /* Unlock the Process */
125 ExReleasePushLockShared(&Process
->ProcessLock
);
127 /* Leave Critical Region */
128 KeLeaveCriticalRegion();
133 PspLockProcessSecurityExclusive(IN PEPROCESS Process
)
135 /* Enter a Critical Region */
136 KeEnterCriticalRegion();
138 /* Lock the Process */
139 ExAcquirePushLockExclusive(&Process
->ProcessLock
);
144 PspUnlockProcessSecurityExclusive(IN PEPROCESS Process
)
146 /* Unlock the Process */
147 ExReleasePushLockExclusive(&Process
->ProcessLock
);
149 /* Leave Critical Region */
150 KeLeaveCriticalRegion();
155 PspLockThreadSecurityShared(IN PETHREAD Thread
)
157 /* Enter a Critical Region */
158 KeEnterCriticalRegion();
160 /* Lock the Thread */
161 ExAcquirePushLockShared(&Thread
->ThreadLock
);
166 PspUnlockThreadSecurityShared(IN PETHREAD Thread
)
168 /* Unlock the Thread */
169 ExReleasePushLockShared(&Thread
->ThreadLock
);
171 /* Leave Critical Region */
172 KeLeaveCriticalRegion();
177 PspLockThreadSecurityExclusive(IN PETHREAD Thread
)
179 /* Enter a Critical Region */
180 KeEnterCriticalRegion();
182 /* Lock the Thread */
183 ExAcquirePushLockExclusive(&Thread
->ThreadLock
);
188 PspUnlockThreadSecurityExclusive(IN PETHREAD Thread
)
190 /* Unlock the Process */
191 ExReleasePushLockExclusive(&Thread
->ThreadLock
);
193 /* Leave Critical Thread */
194 KeLeaveCriticalRegion();
199 _PsGetCurrentProcess(VOID
)
201 /* Get the current process */
202 return (PEPROCESS
)KeGetCurrentThread()->ApcState
.Process
;