Reactos
at master 203 lines 4.9 kB view raw
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 38FORCEINLINE 39VOID 40PspRunCreateThreadNotifyRoutines(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 60FORCEINLINE 61VOID 62PspRunCreateProcessNotifyRoutines(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 82FORCEINLINE 83VOID 84PspRunLoadImageNotifyRoutines(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 101FORCEINLINE 102VOID 103PspRunLegoRoutine(IN PKTHREAD Thread) 104{ 105 /* Call it */ 106 if (PspLegoNotifyRoutine) PspLegoNotifyRoutine(Thread); 107} 108 109FORCEINLINE 110VOID 111PspLockProcessSecurityShared(IN PEPROCESS Process) 112{ 113 /* Enter a Critical Region */ 114 KeEnterCriticalRegion(); 115 116 /* Lock the Process */ 117 ExAcquirePushLockShared(&Process->ProcessLock); 118} 119 120FORCEINLINE 121VOID 122PspUnlockProcessSecurityShared(IN PEPROCESS Process) 123{ 124 /* Unlock the Process */ 125 ExReleasePushLockShared(&Process->ProcessLock); 126 127 /* Leave Critical Region */ 128 KeLeaveCriticalRegion(); 129} 130 131FORCEINLINE 132VOID 133PspLockProcessSecurityExclusive(IN PEPROCESS Process) 134{ 135 /* Enter a Critical Region */ 136 KeEnterCriticalRegion(); 137 138 /* Lock the Process */ 139 ExAcquirePushLockExclusive(&Process->ProcessLock); 140} 141 142FORCEINLINE 143VOID 144PspUnlockProcessSecurityExclusive(IN PEPROCESS Process) 145{ 146 /* Unlock the Process */ 147 ExReleasePushLockExclusive(&Process->ProcessLock); 148 149 /* Leave Critical Region */ 150 KeLeaveCriticalRegion(); 151} 152 153FORCEINLINE 154VOID 155PspLockThreadSecurityShared(IN PETHREAD Thread) 156{ 157 /* Enter a Critical Region */ 158 KeEnterCriticalRegion(); 159 160 /* Lock the Thread */ 161 ExAcquirePushLockShared(&Thread->ThreadLock); 162} 163 164FORCEINLINE 165VOID 166PspUnlockThreadSecurityShared(IN PETHREAD Thread) 167{ 168 /* Unlock the Thread */ 169 ExReleasePushLockShared(&Thread->ThreadLock); 170 171 /* Leave Critical Region */ 172 KeLeaveCriticalRegion(); 173} 174 175FORCEINLINE 176VOID 177PspLockThreadSecurityExclusive(IN PETHREAD Thread) 178{ 179 /* Enter a Critical Region */ 180 KeEnterCriticalRegion(); 181 182 /* Lock the Thread */ 183 ExAcquirePushLockExclusive(&Thread->ThreadLock); 184} 185 186FORCEINLINE 187VOID 188PspUnlockThreadSecurityExclusive(IN PETHREAD Thread) 189{ 190 /* Unlock the Process */ 191 ExReleasePushLockExclusive(&Thread->ThreadLock); 192 193 /* Leave Critical Thread */ 194 KeLeaveCriticalRegion(); 195} 196 197FORCEINLINE 198PEPROCESS 199_PsGetCurrentProcess(VOID) 200{ 201 /* Get the current process */ 202 return (PEPROCESS)KeGetCurrentThread()->ApcState.Process; 203}