2006-11-08 11:47:44 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-10-04 11:54:25 +00:00
|
|
|
* FILE: ntoskrnl/include/internal/ps_x.h
|
2017-06-19 15:26:08 +00:00
|
|
|
* PURPOSE: Internal Inlined Functions for the Process Manager
|
2006-11-08 11:47:44 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Thomas Weidenmueller (w3seek@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// Extract Quantum Settings from the Priority Separation Mask
|
|
|
|
//
|
|
|
|
#define PspPrioritySeparationFromMask(Mask) \
|
|
|
|
((Mask) & 3)
|
|
|
|
|
|
|
|
#define PspQuantumTypeFromMask(Mask) \
|
|
|
|
((Mask) & 12)
|
|
|
|
|
|
|
|
#define PspQuantumLengthFromMask(Mask) \
|
|
|
|
((Mask) & 48)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Cross Thread Flag routines
|
|
|
|
//
|
|
|
|
#define PspSetCrossThreadFlag(Thread, Flag) \
|
|
|
|
InterlockedOr((PLONG)&Thread->CrossThreadFlags, Flag)
|
|
|
|
#define PspClearCrossThreadFlag(Thread, Flag) \
|
|
|
|
InterlockedAnd((PLONG)&Thread->CrossThreadFlags, ~Flag)
|
|
|
|
|
2007-09-26 16:41:35 +00:00
|
|
|
//
|
|
|
|
// Process flag routines
|
|
|
|
//
|
|
|
|
#define PspSetProcessFlag(Process, Flag) \
|
|
|
|
InterlockedOr((PLONG)&Process->Flags, Flag)
|
|
|
|
#define PspClearProcessFlag(Process, Flag) \
|
|
|
|
InterlockedAnd((PLONG)&Process->Flags, ~Flag)
|
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspRunCreateThreadNotifyRoutines(IN PETHREAD CurrentThread,
|
|
|
|
IN BOOLEAN Create)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
2007-01-16 15:09:53 +00:00
|
|
|
/* Check if we have registered routines */
|
|
|
|
if (PspThreadNotifyRoutineCount)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-01-16 15:09:53 +00:00
|
|
|
/* Loop callbacks */
|
|
|
|
for (i = 0; i < PSP_MAX_CREATE_THREAD_NOTIFY; i++)
|
|
|
|
{
|
|
|
|
/* Do the callback */
|
|
|
|
ExDoCallBack(&PspThreadNotifyRoutine[i],
|
|
|
|
CurrentThread->Cid.UniqueProcess,
|
|
|
|
CurrentThread->Cid.UniqueThread,
|
|
|
|
(PVOID)(ULONG_PTR)Create);
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspRunCreateProcessNotifyRoutines(IN PEPROCESS CurrentProcess,
|
|
|
|
IN BOOLEAN Create)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
2007-01-16 15:09:53 +00:00
|
|
|
/* Check if we have registered routines */
|
|
|
|
if (PspProcessNotifyRoutineCount)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-01-16 15:09:53 +00:00
|
|
|
/* Loop callbacks */
|
|
|
|
for (i = 0; i < PSP_MAX_CREATE_PROCESS_NOTIFY; i++)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-01-16 15:09:53 +00:00
|
|
|
/* Do the callback */
|
|
|
|
ExDoCallBack(&PspProcessNotifyRoutine[i],
|
|
|
|
CurrentProcess->InheritedFromUniqueProcessId,
|
2008-12-21 05:08:18 +00:00
|
|
|
CurrentProcess->UniqueProcessId,
|
|
|
|
(PVOID)(ULONG_PTR)Create);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspRunLoadImageNotifyRoutines(PUNICODE_STRING FullImageName,
|
|
|
|
HANDLE ProcessId,
|
|
|
|
PIMAGE_INFO ImageInfo)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
/* Loop the notify routines */
|
|
|
|
for (i = 0; i < PSP_MAX_LOAD_IMAGE_NOTIFY; ++ i)
|
|
|
|
{
|
2007-01-16 15:09:53 +00:00
|
|
|
/* Do the callback */
|
|
|
|
ExDoCallBack(&PspLoadImageNotifyRoutine[i],
|
|
|
|
FullImageName,
|
|
|
|
ProcessId,
|
|
|
|
ImageInfo);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspRunLegoRoutine(IN PKTHREAD Thread)
|
|
|
|
{
|
|
|
|
/* Call it */
|
|
|
|
if (PspLegoNotifyRoutine) PspLegoNotifyRoutine(Thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspLockProcessSecurityShared(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
/* Enter a Critical Region */
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
|
|
|
|
/* Lock the Process */
|
|
|
|
ExAcquirePushLockShared(&Process->ProcessLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspUnlockProcessSecurityShared(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
/* Unlock the Process */
|
|
|
|
ExReleasePushLockShared(&Process->ProcessLock);
|
|
|
|
|
|
|
|
/* Leave Critical Region */
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspLockProcessSecurityExclusive(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
/* Enter a Critical Region */
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
|
|
|
|
/* Lock the Process */
|
|
|
|
ExAcquirePushLockExclusive(&Process->ProcessLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspUnlockProcessSecurityExclusive(IN PEPROCESS Process)
|
|
|
|
{
|
|
|
|
/* Unlock the Process */
|
|
|
|
ExReleasePushLockExclusive(&Process->ProcessLock);
|
|
|
|
|
|
|
|
/* Leave Critical Region */
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspLockThreadSecurityShared(IN PETHREAD Thread)
|
|
|
|
{
|
|
|
|
/* Enter a Critical Region */
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
|
|
|
|
/* Lock the Thread */
|
|
|
|
ExAcquirePushLockShared(&Thread->ThreadLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspUnlockThreadSecurityShared(IN PETHREAD Thread)
|
|
|
|
{
|
|
|
|
/* Unlock the Thread */
|
|
|
|
ExReleasePushLockShared(&Thread->ThreadLock);
|
|
|
|
|
|
|
|
/* Leave Critical Region */
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspLockThreadSecurityExclusive(IN PETHREAD Thread)
|
|
|
|
{
|
|
|
|
/* Enter a Critical Region */
|
|
|
|
KeEnterCriticalRegion();
|
|
|
|
|
|
|
|
/* Lock the Thread */
|
|
|
|
ExAcquirePushLockExclusive(&Thread->ThreadLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
PspUnlockThreadSecurityExclusive(IN PETHREAD Thread)
|
|
|
|
{
|
|
|
|
/* Unlock the Process */
|
|
|
|
ExReleasePushLockExclusive(&Thread->ThreadLock);
|
|
|
|
|
|
|
|
/* Leave Critical Thread */
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
2008-12-03 17:28:33 +00:00
|
|
|
PEPROCESS
|
2006-11-08 11:47:44 +00:00
|
|
|
_PsGetCurrentProcess(VOID)
|
|
|
|
{
|
|
|
|
/* Get the current process */
|
|
|
|
return (PEPROCESS)KeGetCurrentThread()->ApcState.Process;
|
|
|
|
}
|