ReactOS 0.4.17-dev-1196-gb6224c3
ke_x.h File Reference

Go to the source code of this file.

Macros

#define KeEnterGuardedRegionThread(_Thread)
 
#define KeEnterGuardedRegion()
 
#define KeLeaveGuardedRegionThread(_Thread)
 
#define KeLeaveGuardedRegion()
 
#define KeEnterCriticalRegionThread(_Thread)
 
#define KeEnterCriticalRegion()
 
#define KeLeaveCriticalRegionThread(_Thread)
 
#define KeLeaveCriticalRegion()
 
#define KiSatisfyMutantWait(Object, Thread)
 
#define KiSatisfyNonMutantWait(Object)
 
#define KiSatisfyObjectWait(Object, Thread)
 
#define KiAddThreadToWaitList(Thread, Swappable)
 
#define KxDelayThreadWait()
 
#define KxMultiThreadWait()
 
#define KxSingleThreadWait()
 
#define KxQueueThreadWait()
 

Functions

FORCEINLINE KPROCESSOR_MODE KeGetPreviousMode (VOID)
 
FORCEINLINE VOID KiAcquireDispatcherObject (IN DISPATCHER_HEADER *Object)
 
FORCEINLINE VOID KiReleaseDispatcherObject (IN DISPATCHER_HEADER *Object)
 
FORCEINLINE KIRQL KiAcquireDispatcherLock (VOID)
 
FORCEINLINE VOID KiReleaseDispatcherLock (IN KIRQL OldIrql)
 
FORCEINLINE VOID KiAcquireDispatcherLockAtSynchLevel (VOID)
 
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel (VOID)
 
FORCEINLINE VOID KiInsertDeferredReadyList (IN PKTHREAD Thread)
 
FORCEINLINE VOID KiRescheduleThread (IN BOOLEAN NewThread, IN ULONG Cpu)
 
FORCEINLINE VOID KiSetThreadSwapBusy (IN PKTHREAD Thread)
 
FORCEINLINE VOID KiAcquirePrcbLock (IN PKPRCB Prcb)
 
FORCEINLINE VOID KiReleasePrcbLock (IN PKPRCB Prcb)
 
FORCEINLINE VOID KiAcquireThreadLock (IN PKTHREAD Thread)
 
FORCEINLINE VOID KiReleaseThreadLock (IN PKTHREAD Thread)
 
FORCEINLINE BOOLEAN KiTryToAcquireThreadLock (IN PKTHREAD Thread)
 
FORCEINLINE VOID KiCheckDeferredReadyList (IN PKPRCB Prcb)
 
FORCEINLINE VOID KiRequestApcInterrupt (IN BOOLEAN NeedApc, IN UCHAR Processor)
 
FORCEINLINE PKSPIN_LOCK_QUEUE KiAcquireTimerLock (IN ULONG Hand)
 
FORCEINLINE VOID KiReleaseTimerLock (IN PKSPIN_LOCK_QUEUE LockQueue)
 
FORCEINLINE VOID KiAcquireApcLockRaiseToSynch (IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiAcquireApcLockAtSynchLevel (IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiAcquireApcLockRaiseToDpc (IN PKTHREAD Thread, IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiReleaseApcLock (IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiReleaseApcLockFromSynchLevel (IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch (IN PKPROCESS Process, IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiReleaseProcessLock (IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiReleaseProcessLockFromSynchLevel (IN PKLOCK_QUEUE_HANDLE Handle)
 
FORCEINLINE VOID KiAcquireDeviceQueueLock (IN PKDEVICE_QUEUE DeviceQueue, IN PKLOCK_QUEUE_HANDLE DeviceLock)
 
FORCEINLINE VOID KiReleaseDeviceQueueLock (IN PKLOCK_QUEUE_HANDLE DeviceLock)
 
FORCEINLINE PLARGE_INTEGER KiRecalculateDueTime (IN PLARGE_INTEGER OriginalDueTime, IN PLARGE_INTEGER DueTime, IN OUT PLARGE_INTEGER NewDueTime)
 
FORCEINLINE BOOLEAN KiCheckThreadStackSwap (IN PKTHREAD Thread, IN KPROCESSOR_MODE WaitMode)
 
FORCEINLINE NTSTATUS KiCheckAlertability (IN PKTHREAD Thread, IN BOOLEAN Alertable, IN KPROCESSOR_MODE WaitMode)
 
FORCEINLINE ULONG KiComputeTimerTableIndex (IN ULONGLONG DueTime)
 
FORCEINLINE VOID KiRemoveEntryTimer (IN PKTIMER Timer)
 
FORCEINLINE VOID KxInsertTimer (IN PKTIMER Timer, IN ULONG Hand)
 
FORCEINLINE BOOLEAN KiComputeDueTime (IN PKTIMER Timer, IN LARGE_INTEGER DueTime, OUT PULONG Hand)
 
FORCEINLINE VOID KxRemoveTreeTimer (IN PKTIMER Timer)
 
FORCEINLINE VOID KxSetTimerForThreadWait (IN PKTIMER Timer, IN LARGE_INTEGER Interval, OUT PULONG Hand)
 
FORCEINLINE VOID KxUnwaitThread (IN DISPATCHER_HEADER *Object, IN KPRIORITY Increment)
 
FORCEINLINE VOID KxUnwaitThreadForEvent (IN PKEVENT Event, IN KPRIORITY Increment)
 
 _Requires_lock_held_ (Prcb->PrcbLock) _Releases_lock_(Prcb -> PrcbLock) FORCEINLINE VOID KxQueueReadyThread(IN PKTHREAD Thread, IN PKPRCB Prcb)
 
FORCEINLINE PKTHREAD KiSelectReadyThread (IN KPRIORITY Priority, IN PKPRCB Prcb)
 
FORCEINLINE SCHAR KiComputeNewPriority (IN PKTHREAD Thread, IN SCHAR Adjustment)
 
FORCEINLINE VOID _KeInitializeGuardedMutex (OUT PKGUARDED_MUTEX GuardedMutex)
 
FORCEINLINE VOID _KeAcquireGuardedMutexUnsafe (IN OUT PKGUARDED_MUTEX GuardedMutex)
 
FORCEINLINE VOID _KeReleaseGuardedMutexUnsafe (IN OUT PKGUARDED_MUTEX GuardedMutex)
 
FORCEINLINE VOID _KeAcquireGuardedMutex (IN PKGUARDED_MUTEX GuardedMutex)
 
FORCEINLINE VOID _KeReleaseGuardedMutex (IN OUT PKGUARDED_MUTEX GuardedMutex)
 
FORCEINLINE BOOLEAN _KeTryToAcquireGuardedMutex (IN OUT PKGUARDED_MUTEX GuardedMutex)
 
FORCEINLINE VOID KiAcquireNmiListLock (OUT PKIRQL OldIrql)
 
FORCEINLINE VOID KiReleaseNmiListLock (IN KIRQL OldIrql)
 
FORCEINLINE ULONG64 KiReadThreadCycleTime (_In_ PKTHREAD Thread)
 
FORCEINLINE VOID KiWriteThreadCycleTime (_Inout_ PKTHREAD Thread, _In_ ULONG64 NewCycleTime)
 

Macro Definition Documentation

◆ KeEnterCriticalRegion

#define KeEnterCriticalRegion ( )
Value:
{ \
KeEnterCriticalRegionThread(_Thread); \
}
#define KeGetCurrentThread
Definition: hal.h:55

Definition at line 88 of file ke_x.h.

◆ KeEnterCriticalRegionThread

#define KeEnterCriticalRegionThread (   _Thread)
Value:
{ \
/* Sanity checks */ \
ASSERT((_Thread) == KeGetCurrentThread()); \
ASSERT(((_Thread)->KernelApcDisable <= 0) && \
((_Thread)->KernelApcDisable != -32768)); \
\
/* Disable Kernel APCs */ \
(_Thread)->KernelApcDisable--; \
}

Definition at line 77 of file ke_x.h.

◆ KeEnterGuardedRegion

#define KeEnterGuardedRegion ( )
Value:
{ \
KeEnterGuardedRegionThread(_Thread); \
}

Definition at line 39 of file ke_x.h.

◆ KeEnterGuardedRegionThread

#define KeEnterGuardedRegionThread (   _Thread)
Value:
{ \
/* Sanity checks */ \
ASSERT(KeGetCurrentIrql() <= APC_LEVEL); \
ASSERT((_Thread) == KeGetCurrentThread()); \
ASSERT(((_Thread)->SpecialApcDisable <= 0) && \
((_Thread)->SpecialApcDisable != -32768)); \
\
/* Disable Special APCs */ \
(_Thread)->SpecialApcDisable--; \
}
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706

Definition at line 27 of file ke_x.h.

◆ KeLeaveCriticalRegion

#define KeLeaveCriticalRegion ( )
Value:
{ \
KeLeaveCriticalRegionThread(_Thread); \
}

Definition at line 119 of file ke_x.h.

◆ KeLeaveCriticalRegionThread

#define KeLeaveCriticalRegionThread (   _Thread)
Value:
{ \
/* Sanity checks */ \
ASSERT((_Thread) == KeGetCurrentThread()); \
ASSERT((_Thread)->KernelApcDisable < 0); \
\
/* Enable Kernel APCs */ \
(_Thread)->KernelApcDisable++; \
\
/* Check if Kernel APCs are now enabled */ \
if (!((_Thread)->KernelApcDisable)) \
{ \
/* Check if we need to request an APC Delivery */ \
if (!(IsListEmpty(&(_Thread)->ApcState.ApcListHead[KernelMode])) && \
!((_Thread)->SpecialApcDisable)) \
{ \
/* Check for the right environment */ \
KiCheckForKernelApcDelivery(); \
} \
} \
}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define KernelMode
Definition: asm.h:38
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1751

Definition at line 97 of file ke_x.h.

◆ KeLeaveGuardedRegion

#define KeLeaveGuardedRegion ( )
Value:
{ \
KeLeaveGuardedRegionThread(_Thread); \
}

Definition at line 68 of file ke_x.h.

◆ KeLeaveGuardedRegionThread

#define KeLeaveGuardedRegionThread (   _Thread)
Value:
{ \
/* Sanity checks */ \
ASSERT(KeGetCurrentIrql() <= APC_LEVEL); \
ASSERT((_Thread) == KeGetCurrentThread()); \
ASSERT((_Thread)->SpecialApcDisable < 0); \
\
/* Leave region and check if APCs are OK now */ \
if (!(++(_Thread)->SpecialApcDisable)) \
{ \
/* Check for Kernel APCs on the list */ \
if (!IsListEmpty(&(_Thread)->ApcState. \
ApcListHead[KernelMode])) \
{ \
/* Check for APC Delivery */ \
KiCheckForKernelApcDelivery(); \
} \
} \
}

Definition at line 48 of file ke_x.h.

◆ KiAddThreadToWaitList

#define KiAddThreadToWaitList (   Thread,
  Swappable 
)
Value:
{ \
/* Make sure it's swappable */ \
if (Swappable) \
{ \
/* Insert it into the PRCB's List */ \
InsertTailList(&KeGetCurrentPrcb()->WaitListHead, \
&Thread->WaitListEntry); \
} \
}
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1197

Definition at line 803 of file ke_x.h.

◆ KiSatisfyMutantWait

#define KiSatisfyMutantWait (   Object,
  Thread 
)
Value:
{ \
/* Decrease the Signal State */ \
(Object)->Header.SignalState--; \
\
/* Check if it's now non-signaled */ \
if (!(Object)->Header.SignalState) \
{ \
/* Set the Owner Thread */ \
(Object)->OwnerThread = Thread; \
\
/* Disable APCs if needed */ \
Thread->KernelApcDisable = Thread->KernelApcDisable - \
(Object)->ApcDisable; \
\
/* Check if it's abandoned */ \
if ((Object)->Abandoned) \
{ \
/* Unabandon it */ \
\
/* Return Status */ \
Thread->WaitStatus = STATUS_ABANDONED; \
} \
\
/* Insert it into the Mutant List */ \
InsertHeadList(Thread->MutantListHead.Blink, \
&(Object)->MutantListEntry); \
} \
}
Definition: Header.h:9
#define FALSE
Definition: types.h:117
if(dx< 0)
Definition: linetemp.h:194
#define STATUS_ABANDONED
Definition: ntstatus.h:127
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ KPRIORITY _In_ BOOLEAN Abandoned
Definition: kefuncs.h:582

Definition at line 694 of file ke_x.h.

◆ KiSatisfyNonMutantWait

#define KiSatisfyNonMutantWait (   Object)
Value:
{ \
if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) == \
{ \
/* Synchronization Timers and Events just get un-signaled */ \
(Object)->Header.SignalState = 0; \
} \
else if ((Object)->Header.Type == SemaphoreObject) \
{ \
/* These ones can have multiple states, so we only decrease it */ \
(Object)->Header.SignalState--; \
} \
}
@ EventSynchronizationObject
Definition: ketypes.h:426
@ SemaphoreObject
Definition: ketypes.h:430
#define TIMER_OR_EVENT_TYPE
Definition: ke.h:166

Definition at line 728 of file ke_x.h.

◆ KiSatisfyObjectWait

#define KiSatisfyObjectWait (   Object,
  Thread 
)
Value:
{ \
/* Special case for Mutants */ \
if ((Object)->Header.Type == MutantObject) \
{ \
KiSatisfyMutantWait((Object), (Thread)); \
} \
else \
{ \
KiSatisfyNonMutantWait(Object); \
} \
}
@ MutantObject
Definition: ketypes.h:427

Definition at line 746 of file ke_x.h.

◆ KxDelayThreadWait

#define KxDelayThreadWait ( )
Value:
\
/* Setup the Wait Block */ \
Thread->WaitBlockList = TimerBlock; \
\
/* Setup the timer */ \
KxSetTimerForThreadWait(Timer, *Interval, &Hand); \
\
/* Save the due time for the caller */ \
DueTime.QuadPart = Timer->DueTime.QuadPart; \
\
/* Link the timer to this Wait Block */ \
TimerBlock->NextWaitBlock = TimerBlock; \
Timer->Header.WaitListHead.Flink = &TimerBlock->WaitListEntry; \
Timer->Header.WaitListHead.Blink = &TimerBlock->WaitListEntry; \
\
/* Clear wait status */ \
Thread->WaitStatus = STATUS_SUCCESS; \
\
/* Setup wait fields */ \
Thread->Alertable = Alertable; \
Thread->WaitReason = DelayExecution; \
Thread->WaitMode = WaitMode; \
\
/* Check if we can swap the thread's stack */ \
Thread->WaitListEntry.Flink = NULL; \
Swappable = KiCheckThreadStackSwap(Thread, WaitMode); \
\
/* Set the wait time */ \
Thread->WaitTime = KeTickCount.LowPart;
#define NULL
Definition: types.h:112
FORCEINLINE BOOLEAN KiCheckThreadStackSwap(IN PKTHREAD Thread, IN KPROCESSOR_MODE WaitMode)
Definition: ke_x.h:782
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:453
DWORD Interval
Definition: netstat.c:28
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG LowPart
Definition: wdm.h:5
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
@ DelayExecution
Definition: ketypes.h:471

Definition at line 1055 of file ke_x.h.

◆ KxMultiThreadWait

#define KxMultiThreadWait ( )

Definition at line 1086 of file ke_x.h.

◆ KxQueueThreadWait

#define KxQueueThreadWait ( )

Definition at line 1187 of file ke_x.h.

◆ KxSingleThreadWait

#define KxSingleThreadWait ( )

Definition at line 1142 of file ke_x.h.

Function Documentation

◆ _KeAcquireGuardedMutex()

FORCEINLINE VOID _KeAcquireGuardedMutex ( IN PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1566 of file ke_x.h.

1567{
1569
1570 /* Sanity checks */
1572 ASSERT(GuardedMutex->Owner != Thread);
1573
1574 /* Disable Special APCs */
1576
1577 /* Remove the lock */
1578 if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
1579 {
1580 /* The Guarded Mutex was already locked, enter contented case */
1581 KiAcquireGuardedMutex(GuardedMutex);
1582 }
1583
1584 /* Set the Owner and Special APC Disable state */
1585 GuardedMutex->Owner = Thread;
1586 GuardedMutex->SpecialApcDisable = Thread->SpecialApcDisable;
1587}
#define InterlockedBitTestAndReset
Definition: interlocked.h:35
#define KeEnterGuardedRegionThread(_Thread)
Definition: ke_x.h:27
#define ASSERT(a)
Definition: mode.c:44
VOID FASTCALL KiAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: wait.c:122
#define GM_LOCK_BIT_V

Referenced by KeAcquireGuardedMutex().

◆ _KeAcquireGuardedMutexUnsafe()

FORCEINLINE VOID _KeAcquireGuardedMutexUnsafe ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1501 of file ke_x.h.

1502{
1504
1505 /* Sanity checks */
1507 (Thread->SpecialApcDisable < 0) ||
1508 (Thread->Teb == NULL) ||
1509 (Thread->Teb >= (PTEB)MM_SYSTEM_RANGE_START));
1510 ASSERT(GuardedMutex->Owner != Thread);
1511
1512 /* Remove the lock */
1513 if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
1514 {
1515 /* The Guarded Mutex was already locked, enter contented case */
1516 KiAcquireGuardedMutex(GuardedMutex);
1517 }
1518
1519 /* Set the Owner */
1520 GuardedMutex->Owner = Thread;
1521}
#define MM_SYSTEM_RANGE_START
Definition: armddk.h:18
Definition: compat.h:836

Referenced by KeAcquireGuardedMutexUnsafe().

◆ _KeInitializeGuardedMutex()

FORCEINLINE VOID _KeInitializeGuardedMutex ( OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1488 of file ke_x.h.

1489{
1490 /* Setup the Initial Data */
1491 GuardedMutex->Count = GM_LOCK_BIT;
1492 GuardedMutex->Owner = NULL;
1493 GuardedMutex->Contention = 0;
1494
1495 /* Initialize the Wait Gate */
1496 KeInitializeGate(&GuardedMutex->Gate);
1497}
VOID FASTCALL KeInitializeGate(PKGATE Gate)
#define GM_LOCK_BIT

Referenced by KeInitializeGuardedMutex().

◆ _KeReleaseGuardedMutex()

FORCEINLINE VOID _KeReleaseGuardedMutex ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1591 of file ke_x.h.

1592{
1594 LONG OldValue, NewValue;
1595
1596 /* Sanity checks */
1598 ASSERT(GuardedMutex->Owner == Thread);
1599 ASSERT(Thread->SpecialApcDisable == GuardedMutex->SpecialApcDisable);
1600
1601 /* Destroy the Owner */
1602 GuardedMutex->Owner = NULL;
1603
1604 /* Add the Lock Bit */
1605 OldValue = InterlockedExchangeAdd(&GuardedMutex->Count, GM_LOCK_BIT);
1606 ASSERT((OldValue & GM_LOCK_BIT) == 0);
1607
1608 /* Check if it was already locked, but not woken */
1609 if ((OldValue) && !(OldValue & GM_LOCK_WAITER_WOKEN))
1610 {
1611 /* Update the Oldvalue to what it should be now */
1612 OldValue += GM_LOCK_BIT;
1613
1614 /* The mutex will be woken, minus one waiter */
1615 NewValue = OldValue + GM_LOCK_WAITER_WOKEN -
1617
1618 /* Remove the Woken bit */
1619 if (InterlockedCompareExchange(&GuardedMutex->Count,
1620 NewValue,
1621 OldValue) == OldValue)
1622 {
1623 /* Signal the Gate */
1624 KeSignalGateBoostPriority(&GuardedMutex->Gate);
1625 }
1626 }
1627
1628 /* Re-enable APCs */
1630}
#define InterlockedExchangeAdd
Definition: interlocked.h:196
#define InterlockedCompareExchange
Definition: interlocked.h:119
#define KeLeaveGuardedRegionThread(_Thread)
Definition: ke_x.h:48
VOID FASTCALL KeSignalGateBoostPriority(PKGATE Gate)
long LONG
Definition: pedump.c:60
#define GM_LOCK_WAITER_WOKEN
#define GM_LOCK_WAITER_INC

Referenced by KeReleaseGuardedMutex().

◆ _KeReleaseGuardedMutexUnsafe()

FORCEINLINE VOID _KeReleaseGuardedMutexUnsafe ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1525 of file ke_x.h.

1526{
1527 LONG OldValue, NewValue;
1528
1529 /* Sanity checks */
1531 (KeGetCurrentThread()->SpecialApcDisable < 0) ||
1532 (KeGetCurrentThread()->Teb == NULL) ||
1534 ASSERT(GuardedMutex->Owner == KeGetCurrentThread());
1535
1536 /* Destroy the Owner */
1537 GuardedMutex->Owner = NULL;
1538
1539 /* Add the Lock Bit */
1540 OldValue = InterlockedExchangeAdd(&GuardedMutex->Count, GM_LOCK_BIT);
1541 ASSERT((OldValue & GM_LOCK_BIT) == 0);
1542
1543 /* Check if it was already locked, but not woken */
1544 if ((OldValue) && !(OldValue & GM_LOCK_WAITER_WOKEN))
1545 {
1546 /* Update the Oldvalue to what it should be now */
1547 OldValue += GM_LOCK_BIT;
1548
1549 /* The mutex will be woken, minus one waiter */
1550 NewValue = OldValue + GM_LOCK_WAITER_WOKEN -
1552
1553 /* Remove the Woken bit */
1554 if (InterlockedCompareExchange(&GuardedMutex->Count,
1555 NewValue,
1556 OldValue) == OldValue)
1557 {
1558 /* Signal the Gate */
1559 KeSignalGateBoostPriority(&GuardedMutex->Gate);
1560 }
1561 }
1562}

Referenced by KeReleaseGuardedMutexUnsafe().

◆ _KeTryToAcquireGuardedMutex()

FORCEINLINE BOOLEAN _KeTryToAcquireGuardedMutex ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1634 of file ke_x.h.

1635{
1637
1638 /* Block APCs */
1640
1641 /* Remove the lock */
1642 if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
1643 {
1644 /* Re-enable APCs */
1647
1648 /* Return failure */
1649 return FALSE;
1650 }
1651
1652 /* Set the Owner and APC State */
1653 GuardedMutex->Owner = Thread;
1654 GuardedMutex->SpecialApcDisable = Thread->SpecialApcDisable;
1655 return TRUE;
1656}
#define TRUE
Definition: types.h:120
#define YieldProcessor
Definition: ke.h:48

Referenced by KeTryToAcquireGuardedMutex().

◆ _Requires_lock_held_()

_Requires_lock_held_ ( Prcb->  PrcbLock) -> PrcbLock) FORCEINLINE VOID KxQueueReadyThread(IN PKTHREAD Thread, IN PKPRCB Prcb)

Definition at line 1329 of file ke_x.h.

1335{
1336 BOOLEAN Preempted;
1338
1339 /* Sanity checks */
1340 ASSERT(Prcb == KeGetCurrentPrcb());
1341#ifdef CONFIG_SMP
1342 ASSERT(Prcb->PrcbLock != 0);
1343#endif
1344 ASSERT(Thread->State == Running);
1345 ASSERT(Thread->NextProcessor == Prcb->Number);
1346
1347 /* Check if this thread is allowed to run in this CPU */
1348#ifdef CONFIG_SMP
1349 if ((Thread->Affinity) & (Prcb->SetMember))
1350#else
1351 if (TRUE)
1352#endif
1353 {
1354 /* Set thread ready for execution */
1355 Thread->State = Ready;
1356
1357 /* Save current priority and if someone had pre-empted it */
1358 Priority = Thread->Priority;
1359 Preempted = Thread->Preempted;
1360
1361 /* We're not pre-empting now, and set the wait time */
1362 Thread->Preempted = FALSE;
1363 Thread->WaitTime = KeTickCount.LowPart;
1364
1365 /* Sanity check */
1366 ASSERT((Priority >= 0) && (Priority <= HIGH_PRIORITY));
1367
1368 /* Insert this thread in the appropriate order */
1369 Preempted ? InsertHeadList(&Prcb->DispatcherReadyListHead[Priority],
1370 &Thread->WaitListEntry) :
1371 InsertTailList(&Prcb->DispatcherReadyListHead[Priority],
1372 &Thread->WaitListEntry);
1373
1374 /* Update the ready summary */
1375 Prcb->ReadySummary |= PRIORITY_MASK(Priority);
1376
1377 /* Sanity check */
1378 ASSERT(Priority == Thread->Priority);
1379
1380 /* Release the PRCB lock */
1381 KiReleasePrcbLock(Prcb);
1382 }
1383 else
1384 {
1385 /* Otherwise, prepare this thread to be deferred */
1386 Thread->State = DeferredReady;
1387 Thread->DeferredProcessor = Prcb->Number;
1388
1389 /* Release the lock and defer scheduling */
1390 KiReleasePrcbLock(Prcb);
1392 }
1393}
unsigned char BOOLEAN
Definition: actypes.h:127
LONG KPRIORITY
Definition: compat.h:803
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
_In_ UCXUSBDEVICE _In_ UCXENDPOINT _In_ ULONG Priority
Definition: hubucx.h:414
#define HIGH_PRIORITY
FORCEINLINE VOID KiReleasePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:230
@ Ready
Definition: ketypes.h:408
@ Running
Definition: ketypes.h:409
@ DeferredReady
Definition: ketypes.h:414
#define PRIORITY_MASK(Priority)
Definition: ke.h:163
VOID FASTCALL KiDeferredReadyThread(IN PKTHREAD Thread)
Definition: thrdschd.c:150

◆ KeGetPreviousMode()

FORCEINLINE KPROCESSOR_MODE KeGetPreviousMode ( VOID  )

Definition at line 17 of file ke_x.h.

18{
19 /* Return the current mode */
20 return KeGetCurrentThread()->PreviousMode;
21}

◆ KiAcquireApcLockAtSynchLevel()

FORCEINLINE VOID KiAcquireApcLockAtSynchLevel ( IN PKTHREAD  Thread,
IN PKLOCK_QUEUE_HANDLE  Handle 
)

Definition at line 595 of file ke_x.h.

597{
598 /* Acquire the lock */
601}
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
ULONG Handle
Definition: gdb_input.c:15
VOID FASTCALL KeAcquireInStackQueuedSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:363

Referenced by KeFreezeAllThreads(), and KeThawAllThreads().

◆ KiAcquireApcLockRaiseToDpc()

FORCEINLINE VOID KiAcquireApcLockRaiseToDpc ( IN PKTHREAD  Thread,
IN PKLOCK_QUEUE_HANDLE  Handle 
)

Definition at line 605 of file ke_x.h.

607{
608 /* Acquire the lock */
610}
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130

Referenced by KiDeliverApc().

◆ KiAcquireApcLockRaiseToSynch()

FORCEINLINE VOID KiAcquireApcLockRaiseToSynch ( IN PKTHREAD  Thread,
IN PKLOCK_QUEUE_HANDLE  Handle 
)

Definition at line 586 of file ke_x.h.

588{
589 /* Acquire the lock and raise to synchronization level */
591}
VOID FASTCALL KeAcquireInStackQueuedSpinLockRaiseToSynch(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:142

Referenced by KeAlertResumeThread(), KeAlertThread(), KeAttachProcess(), KeDetachProcess(), KeFlushQueueApc(), KeForceResumeThread(), KeInsertQueueApc(), KeRemoveQueueApc(), KeResumeThread(), KeStackAttachProcess(), KeSuspendThread(), KeTestAlertThread(), KeUnstackDetachProcess(), and KeWaitForGate().

◆ KiAcquireDeviceQueueLock()

FORCEINLINE VOID KiAcquireDeviceQueueLock ( IN PKDEVICE_QUEUE  DeviceQueue,
IN PKLOCK_QUEUE_HANDLE  DeviceLock 
)

Definition at line 655 of file ke_x.h.

657{
658 /* Check if we were called from a threaded DPC */
659 if (KeGetCurrentPrcb()->DpcThreadActive)
660 {
661 /* Lock the Queue, we're not at DPC level */
662 KeAcquireInStackQueuedSpinLock(&DeviceQueue->Lock, DeviceLock);
663 }
664 else
665 {
666 /* We must be at DPC level, acquire the lock safely */
669 DeviceLock);
670 }
671}
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696

Referenced by KeInsertByKeyDeviceQueue(), KeInsertDeviceQueue(), KeRemoveByKeyDeviceQueue(), KeRemoveByKeyDeviceQueueIfBusy(), KeRemoveDeviceQueue(), and KeRemoveEntryDeviceQueue().

◆ KiAcquireDispatcherLock()

◆ KiAcquireDispatcherLockAtSynchLevel()

◆ KiAcquireDispatcherObject()

FORCEINLINE VOID KiAcquireDispatcherObject ( IN DISPATCHER_HEADER *  Object)

Definition at line 132 of file ke_x.h.

133{
135}
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329

Referenced by KeSignalGateBoostPriority(), KeWaitForGate(), and KiInsertQueueApc().

◆ KiAcquireNmiListLock()

FORCEINLINE VOID KiAcquireNmiListLock ( OUT PKIRQL  OldIrql)

Definition at line 1661 of file ke_x.h.

1662{
1664}
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KSPIN_LOCK KiNmiCallbackListLock
Definition: bug.c:34
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by KeDeregisterNmiCallback(), and KeRegisterNmiCallback().

◆ KiAcquirePrcbLock()

◆ KiAcquireProcessLockRaiseToSynch()

FORCEINLINE VOID KiAcquireProcessLockRaiseToSynch ( IN PKPROCESS  Process,
IN PKLOCK_QUEUE_HANDLE  Handle 
)

Definition at line 630 of file ke_x.h.

632{
633 /* Acquire the lock and raise to synchronization level */
635}
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223

Referenced by KeFreezeAllThreads(), KeQueryRuntimeProcess(), KeQueryValuesProcess(), KeSetAffinityProcess(), KeSetPriorityAndQuantumProcess(), KeSetQuantumProcess(), KeStartThread(), KeTerminateThread(), KeThawAllThreads(), and MmSetExecuteOptions().

◆ KiAcquireThreadLock()

◆ KiAcquireTimerLock()

FORCEINLINE PKSPIN_LOCK_QUEUE KiAcquireTimerLock ( IN ULONG  Hand)

Definition at line 286 of file ke_x.h.

287{
289
290 /* Nothing to do on UP */
292 return NULL;
293}

Referenced by KeSetSystemTime(), KiInsertTreeTimer(), KiTimerExpiration(), KxInsertTimer(), and KxRemoveTreeTimer().

◆ KiCheckAlertability()

FORCEINLINE NTSTATUS KiCheckAlertability ( IN PKTHREAD  Thread,
IN BOOLEAN  Alertable,
IN KPROCESSOR_MODE  WaitMode 
)

Definition at line 820 of file ke_x.h.

823{
824 /* Check if the wait is alertable */
825 if (Alertable)
826 {
827 /* It is, first check if the thread is alerted in this mode */
828 if (Thread->Alerted[WaitMode])
829 {
830 /* It is, so bail out of the wait */
831 Thread->Alerted[WaitMode] = FALSE;
832 return STATUS_ALERTED;
833 }
834 else if ((WaitMode != KernelMode) &&
835 (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
836 {
837 /* It's isn't, but this is a user wait with queued user APCs */
838 Thread->ApcState.UserApcPending = TRUE;
839 return STATUS_USER_APC;
840 }
841 else if (Thread->Alerted[KernelMode])
842 {
843 /* It isn't that either, but we're alered in kernel mode */
844 Thread->Alerted[KernelMode] = FALSE;
845 return STATUS_ALERTED;
846 }
847 }
848 else if ((WaitMode != KernelMode) && (Thread->ApcState.UserApcPending))
849 {
850 /* Not alertable, but this is a user wait with pending user APCs */
851 return STATUS_USER_APC;
852 }
853
854 /* Otherwise, we're fine */
855 return STATUS_WAIT_0;
856}
#define UserMode
Definition: asm.h:39
#define STATUS_WAIT_0
Definition: ntstatus.h:330
#define STATUS_ALERTED
Definition: ntstatus.h:133
#define STATUS_USER_APC
Definition: ntstatus.h:130

Referenced by KeDelayExecutionThread(), KeWaitForMultipleObjects(), and KeWaitForSingleObject().

◆ KiCheckDeferredReadyList()

FORCEINLINE VOID KiCheckDeferredReadyList ( IN PKPRCB  Prcb)

Definition at line 268 of file ke_x.h.

269{
270 /* There are no deferred ready lists on UP systems */
272}

Referenced by KiExitDispatcher().

◆ KiCheckThreadStackSwap()

FORCEINLINE BOOLEAN KiCheckThreadStackSwap ( IN PKTHREAD  Thread,
IN KPROCESSOR_MODE  WaitMode 
)

Definition at line 782 of file ke_x.h.

784{
785 /* Check the required conditions */
786 if ((WaitMode != KernelMode) &&
787 (Thread->EnableStackSwap) &&
788 (Thread->Priority >= (LOW_REALTIME_PRIORITY + 9)))
789 {
790 /* We are go for swap */
791 return TRUE;
792 }
793 else
794 {
795 /* Don't swap the thread */
796 return FALSE;
797 }
798}
#define LOW_REALTIME_PRIORITY

◆ KiComputeDueTime()

FORCEINLINE BOOLEAN KiComputeDueTime ( IN PKTIMER  Timer,
IN LARGE_INTEGER  DueTime,
OUT PULONG  Hand 
)

Definition at line 931 of file ke_x.h.

934{
935 LARGE_INTEGER InterruptTime, SystemTime, DifferenceTime;
936
937 /* Convert to relative time if needed */
938 Timer->Header.Absolute = FALSE;
939 if (DueTime.HighPart >= 0)
940 {
941 /* Get System Time */
942 KeQuerySystemTime(&SystemTime);
943
944 /* Do the conversion */
945 DifferenceTime.QuadPart = SystemTime.QuadPart - DueTime.QuadPart;
946
947 /* Make sure it hasn't already expired */
948 Timer->Header.Absolute = TRUE;
949 if (DifferenceTime.HighPart >= 0)
950 {
951 /* Cancel everything */
952 Timer->Header.SignalState = TRUE;
953 Timer->Header.Hand = 0;
954 Timer->DueTime.QuadPart = 0;
955 *Hand = 0;
956 return FALSE;
957 }
958
959 /* Set the time as Absolute */
960 DueTime = DifferenceTime;
961 }
962
963 /* Get the Interrupt Time */
964 InterruptTime.QuadPart = KeQueryInterruptTime();
965
966 /* Recalculate due time */
967 Timer->DueTime.QuadPart = InterruptTime.QuadPart - DueTime.QuadPart;
968
969 /* Get the handle */
970 *Hand = KiComputeTimerTableIndex(Timer->DueTime.QuadPart);
971 Timer->Header.Hand = (UCHAR)*Hand;
972 Timer->Header.Inserted = TRUE;
973 return TRUE;
974}
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
FORCEINLINE ULONG KiComputeTimerTableIndex(IN ULONGLONG DueTime)
Definition: ke_x.h:860
#define KeQueryInterruptTime()
Definition: ke.h:37
unsigned char UCHAR
Definition: typedefs.h:53
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by KeSetTimerEx(), and KiInsertTreeTimer().

◆ KiComputeNewPriority()

FORCEINLINE SCHAR KiComputeNewPriority ( IN PKTHREAD  Thread,
IN SCHAR  Adjustment 
)

Definition at line 1451 of file ke_x.h.

1453{
1455
1456 /* Priority sanity checks */
1457 ASSERT((Thread->PriorityDecrement >= 0) &&
1458 (Thread->PriorityDecrement <= Thread->Priority));
1459 ASSERT((Thread->Priority < LOW_REALTIME_PRIORITY) ?
1460 TRUE : (Thread->PriorityDecrement == 0));
1461
1462 /* Get the current priority */
1463 Priority = Thread->Priority;
1465 {
1466 /* Decrease priority by the priority decrement */
1467 Priority -= (Thread->PriorityDecrement + Adjustment);
1468
1469 /* Don't go out of bounds */
1470 if (Priority < Thread->BasePriority) Priority = Thread->BasePriority;
1471
1472 /* Reset the priority decrement */
1473 Thread->PriorityDecrement = 0;
1474 }
1475
1476 /* Sanity check */
1477 ASSERT((Thread->BasePriority == 0) || (Priority != 0));
1478
1479 /* Return the new priority */
1480 return Priority;
1481}
signed char SCHAR
Definition: sqltypes.h:14
_In_ KPRIORITY _In_ LONG Adjustment
Definition: kefuncs.h:427

Referenced by _Requires_lock_not_held_(), KeSetBasePriorityThread(), KeSetEventBoostPriority(), KiAdjustQuantumThread(), KiDeferredReadyThread(), and NtYieldExecution().

◆ KiComputeTimerTableIndex()

FORCEINLINE ULONG KiComputeTimerTableIndex ( IN ULONGLONG  DueTime)

Definition at line 860 of file ke_x.h.

861{
863}
ULONG KeMaximumIncrement
Definition: clock.c:20
#define TIMER_TABLE_SIZE
Definition: ketypes.h:916

Referenced by KeSetSystemTime(), KiComputeDueTime(), KiInsertTimerTable(), and KxSetTimerForThreadWait().

◆ KiInsertDeferredReadyList()

FORCEINLINE VOID KiInsertDeferredReadyList ( IN PKTHREAD  Thread)

Definition at line 185 of file ke_x.h.

186{
187 /* Set the thread to deferred state and boot CPU */
188 Thread->State = DeferredReady;
189 Thread->DeferredProcessor = 0;
190
191 /* Make the thread ready immediately */
193}

Referenced by KiInsertQueueApc(), KiReadyThread(), KiScanReadyQueues(), and KiSetPriorityThread().

◆ KiReadThreadCycleTime()

FORCEINLINE ULONG64 KiReadThreadCycleTime ( _In_ PKTHREAD  Thread)

Definition at line 1696 of file ke_x.h.

1698{
1699 /* Hack until we switched to NTDDI_VISTA, where CycleTime is in KTHREAD */
1700 PETHREAD EThread = (PETHREAD)Thread;
1701
1702#ifdef _WIN64
1703 return EThread->CycleTime;
1704#else
1705 /* Read in a loop until we get a match */
1706 ULARGE_INTEGER CycleTimeAsULI;
1707 for (;;)
1708 {
1709 volatile ULARGE_INTEGER* CycleTimePtr = (volatile ULARGE_INTEGER*)&EThread->CycleTime;
1710 CycleTimeAsULI.HighPart = CycleTimePtr->HighPart;
1711 CycleTimeAsULI.LowPart = CycleTimePtr->LowPart;
1712 if (CycleTimeAsULI.HighPart == EThread->CycleTimeHigh)
1713 break;
1715 }
1716 return CycleTimeAsULI.QuadPart;
1717#endif
1718}
struct _ETHREAD * PETHREAD
Definition: nt_native.h:29
$ULONG LowPart
Definition: ntbasedef.h:581
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
$ULONG HighPart
Definition: ntbasedef.h:582

Referenced by _IRQL_requires_max_().

◆ KiRecalculateDueTime()

FORCEINLINE PLARGE_INTEGER KiRecalculateDueTime ( IN PLARGE_INTEGER  OriginalDueTime,
IN PLARGE_INTEGER  DueTime,
IN OUT PLARGE_INTEGER  NewDueTime 
)

Definition at line 764 of file ke_x.h.

767{
768 /* Don't do anything for absolute waits */
769 if (OriginalDueTime->QuadPart >= 0) return OriginalDueTime;
770
771 /* Otherwise, query the interrupt time and recalculate */
772 NewDueTime->QuadPart = KeQueryInterruptTime();
773 NewDueTime->QuadPart -= DueTime->QuadPart;
774 return NewDueTime;
775}

Referenced by KeDelayExecutionThread(), KeRemoveQueue(), KeWaitForMultipleObjects(), and KeWaitForSingleObject().

◆ KiReleaseApcLock()

FORCEINLINE VOID KiReleaseApcLock ( IN PKLOCK_QUEUE_HANDLE  Handle)

Definition at line 614 of file ke_x.h.

615{
616 /* Release the lock */
618}
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166

Referenced by KeFlushQueueApc(), KeRemoveQueueApc(), KeSuspendThread(), KeTestAlertThread(), KeUnstackDetachProcess(), KeWaitForGate(), and KiDeliverApc().

◆ KiReleaseApcLockFromSynchLevel()

FORCEINLINE VOID KiReleaseApcLockFromSynchLevel ( IN PKLOCK_QUEUE_HANDLE  Handle)

Definition at line 622 of file ke_x.h.

623{
624 /* Release the lock */
626}
VOID FASTCALL KeReleaseInStackQueuedSpinLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:395

Referenced by KeAlertResumeThread(), KeAlertThread(), KeDetachProcess(), KeForceResumeThread(), KeFreezeAllThreads(), KeInsertQueueApc(), KeResumeThread(), KeSuspendThread(), KeThawAllThreads(), KeUnstackDetachProcess(), KeWaitForGate(), and KiAttachProcess().

◆ KiReleaseDeviceQueueLock()

FORCEINLINE VOID KiReleaseDeviceQueueLock ( IN PKLOCK_QUEUE_HANDLE  DeviceLock)

Definition at line 675 of file ke_x.h.

676{
677 /* Check if we were called from a threaded DPC */
678 if (KeGetCurrentPrcb()->DpcThreadActive)
679 {
680 /* Unlock the Queue, we're not at DPC level */
682 }
683 else
684 {
685 /* We must be at DPC level, release the lock safely */
688 }
689}

Referenced by KeInsertByKeyDeviceQueue(), KeInsertDeviceQueue(), KeRemoveByKeyDeviceQueue(), KeRemoveByKeyDeviceQueueIfBusy(), KeRemoveDeviceQueue(), and KeRemoveEntryDeviceQueue().

◆ KiReleaseDispatcherLock()

◆ KiReleaseDispatcherLockFromSynchLevel()

◆ KiReleaseDispatcherObject()

FORCEINLINE VOID KiReleaseDispatcherObject ( IN DISPATCHER_HEADER *  Object)

Definition at line 142 of file ke_x.h.

143{
145}

Referenced by KeSignalGateBoostPriority(), KeWaitForGate(), and KiInsertQueueApc().

◆ KiReleaseNmiListLock()

FORCEINLINE VOID KiReleaseNmiListLock ( IN KIRQL  OldIrql)

Definition at line 1668 of file ke_x.h.

1669{
1671}
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by KeDeregisterNmiCallback(), and KeRegisterNmiCallback().

◆ KiReleasePrcbLock()

◆ KiReleaseProcessLock()

FORCEINLINE VOID KiReleaseProcessLock ( IN PKLOCK_QUEUE_HANDLE  Handle)

Definition at line 639 of file ke_x.h.

640{
641 /* Release the lock and restore previous IRQL */
643}

Referenced by KeFreezeAllThreads(), KeQueryRuntimeProcess(), KeQueryValuesProcess(), KeSetQuantumProcess(), KeStartThread(), and MmSetExecuteOptions().

◆ KiReleaseProcessLockFromSynchLevel()

FORCEINLINE VOID KiReleaseProcessLockFromSynchLevel ( IN PKLOCK_QUEUE_HANDLE  Handle)

Definition at line 647 of file ke_x.h.

648{
649 /* Release the lock without lowering IRQL */
651}

Referenced by KeFreezeAllThreads(), KeSetAffinityProcess(), KeSetPriorityAndQuantumProcess(), KeTerminateThread(), and KeThawAllThreads().

◆ KiReleaseThreadLock()

◆ KiReleaseTimerLock()

FORCEINLINE VOID KiReleaseTimerLock ( IN PKSPIN_LOCK_QUEUE  LockQueue)

Definition at line 297 of file ke_x.h.

298{
300
301 /* Nothing to do on UP */
302 UNREFERENCED_PARAMETER(LockQueue);
303}

Referenced by KeSetSystemTime(), KiCompleteTimer(), KiInsertTreeTimer(), KiTimerExpiration(), KxInsertTimer(), and KxRemoveTreeTimer().

◆ KiRemoveEntryTimer()

FORCEINLINE VOID KiRemoveEntryTimer ( IN PKTIMER  Timer)

Definition at line 871 of file ke_x.h.

872{
873 ULONG Hand;
875
876 /* Remove the timer from the timer list and check if it's empty */
877 Hand = Timer->Header.Hand;
878 if (RemoveEntryList(&Timer->TimerListEntry))
879 {
880 /* Get the respective timer table entry */
882 if (&TableEntry->Entry == TableEntry->Entry.Flink)
883 {
884 /* Set the entry to an infinite absolute time */
885 TableEntry->Time.HighPart = 0xFFFFFFFF;
886 }
887 }
888
889 /* Clear the list entries on dbg builds so we can tell the timer is gone */
890#if DBG
891 Timer->TimerListEntry.Flink = NULL;
892 Timer->TimerListEntry.Blink = NULL;
893#endif
894}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
Definition: ketypes.h:918
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ typedef _In_ ULONG TableEntry
Definition: iotypes.h:4319

Referenced by KeSetSystemTime(), KiCompleteTimer(), KiInsertTreeTimer(), and KiTimerExpiration().

◆ KiRequestApcInterrupt()

FORCEINLINE VOID KiRequestApcInterrupt ( IN BOOLEAN  NeedApc,
IN UCHAR  Processor 
)

Definition at line 276 of file ke_x.h.

278{
279 /* We deliver instantly on UP */
280 UNREFERENCED_PARAMETER(NeedApc);
282}
_In_ UCHAR Processor
Definition: kefuncs.h:670

Referenced by KiInsertQueueApc().

◆ KiRescheduleThread()

FORCEINLINE VOID KiRescheduleThread ( IN BOOLEAN  NewThread,
IN ULONG  Cpu 
)

Definition at line 197 of file ke_x.h.

199{
200 /* This is meaningless on UP systems */
201 UNREFERENCED_PARAMETER(NewThread);
203}

◆ KiSelectReadyThread()

FORCEINLINE PKTHREAD KiSelectReadyThread ( IN KPRIORITY  Priority,
IN PKPRCB  Prcb 
)

Definition at line 1401 of file ke_x.h.

1403{
1404 ULONG PrioritySet;
1405 LONG HighPriority;
1406 PLIST_ENTRY ListEntry;
1408
1409 /* Save the current mask and get the priority set for the CPU */
1410 PrioritySet = Prcb->ReadySummary >> Priority;
1411 if (!PrioritySet) goto Quickie;
1412
1413 /* Get the highest priority possible */
1414 BitScanReverse((PULONG)&HighPriority, PrioritySet);
1415 ASSERT((PrioritySet & PRIORITY_MASK(HighPriority)) != 0);
1416 HighPriority += Priority;
1417
1418 /* Make sure the list isn't empty at the highest priority */
1419 ASSERT(IsListEmpty(&Prcb->DispatcherReadyListHead[HighPriority]) == FALSE);
1420
1421 /* Get the first thread on the list */
1422 ListEntry = Prcb->DispatcherReadyListHead[HighPriority].Flink;
1423 Thread = CONTAINING_RECORD(ListEntry, KTHREAD, WaitListEntry);
1424
1425 /* Make sure this thread is here for a reason */
1426 ASSERT(HighPriority == Thread->Priority);
1427 ASSERT(Thread->Affinity & AFFINITY_MASK(Prcb->Number));
1428 ASSERT(Thread->NextProcessor == Prcb->Number);
1429
1430 /* Remove it from the list */
1431 if (RemoveEntryList(&Thread->WaitListEntry))
1432 {
1433 /* The list is empty now, reset the ready summary */
1434 Prcb->ReadySummary ^= PRIORITY_MASK(HighPriority);
1435 }
1436
1437 /* Sanity check and return the thread */
1438Quickie:
1439 ASSERT((Thread == NULL) ||
1440 (Thread->BasePriority == 0) ||
1441 (Thread->Priority != 0));
1442 return Thread;
1443}
#define BitScanReverse
Definition: interlocked.h:6
FORCEINLINE KAFFINITY AFFINITY_MASK(ULONG Index)
Definition: kefuncs.h:39
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint32_t * PULONG
Definition: typedefs.h:59
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by _Requires_lock_not_held_(), KiAdjustQuantumThread(), KiSelectNextThread(), KiSetPriorityThread(), KiSwapThread(), and NtYieldExecution().

◆ KiSetThreadSwapBusy()

◆ KiTryToAcquireThreadLock()

FORCEINLINE BOOLEAN KiTryToAcquireThreadLock ( IN PKTHREAD  Thread)

Definition at line 260 of file ke_x.h.

261{
263 return TRUE;
264}

Referenced by KeSignalGateBoostPriority().

◆ KiWriteThreadCycleTime()

FORCEINLINE VOID KiWriteThreadCycleTime ( _Inout_ PKTHREAD  Thread,
_In_ ULONG64  NewCycleTime 
)

Definition at line 1723 of file ke_x.h.

1726{
1727 /* Hack until we switched to NTDDI_VISTA, where CycleTime is in KTHREAD */
1728 PETHREAD EThread = (PETHREAD)Thread;
1729
1730#ifdef _WIN64
1731 EThread->CycleTime = NewCycleTime;
1732#else
1733 /* On 32 bit systems we need to use the same trick as for writing a KSYSTEM_TIME */
1734 ULARGE_INTEGER NewCycleTimeAsULI;
1735 NewCycleTimeAsULI.QuadPart = NewCycleTime;
1736 volatile ULARGE_INTEGER* CycleTimePtr = (volatile ULARGE_INTEGER*)&EThread->CycleTime;
1737 EThread->CycleTimeHigh = NewCycleTimeAsULI.HighPart;
1738 CycleTimePtr->LowPart = NewCycleTimeAsULI.LowPart;
1739 CycleTimePtr->HighPart = NewCycleTimeAsULI.HighPart;
1740#endif
1741}

Referenced by KiSwapContextExit().

◆ KxInsertTimer()

FORCEINLINE VOID KxInsertTimer ( IN PKTIMER  Timer,
IN ULONG  Hand 
)

Definition at line 902 of file ke_x.h.

904{
905 PKSPIN_LOCK_QUEUE LockQueue;
907
908 /* Acquire the lock and release the dispatcher lock */
909 LockQueue = KiAcquireTimerLock(Hand);
911
912 /* Try to insert the timer */
913 if (KiInsertTimerTable(Timer, Hand))
914 {
915 /* Complete it */
916 KiCompleteTimer(Timer, LockQueue);
917 }
918 else
919 {
920 /* Do nothing, just release the lock */
921 KiReleaseTimerLock(LockQueue);
922 }
923}
FORCEINLINE VOID KiReleaseTimerLock(IN PKSPIN_LOCK_QUEUE LockQueue)
Definition: ke_x.h:297
FORCEINLINE PKSPIN_LOCK_QUEUE KiAcquireTimerLock(IN ULONG Hand)
Definition: ke_x.h:286
FORCEINLINE VOID KiReleaseDispatcherLockFromSynchLevel(VOID)
Definition: ke_x.h:174
VOID FASTCALL KiCompleteTimer(IN PKTIMER Timer, IN PKSPIN_LOCK_QUEUE LockQueue)
Definition: timerobj.c:167
BOOLEAN FASTCALL KiInsertTimerTable(IN PKTIMER Timer, IN ULONG Hand)
Definition: timerobj.c:63

Referenced by KeDelayExecutionThread(), KeRemoveQueue(), KeSetTimerEx(), KeWaitForMultipleObjects(), and KeWaitForSingleObject().

◆ KxRemoveTreeTimer()

FORCEINLINE VOID KxRemoveTreeTimer ( IN PKTIMER  Timer)

Definition at line 983 of file ke_x.h.

984{
985 ULONG Hand = Timer->Header.Hand;
986 PKSPIN_LOCK_QUEUE LockQueue;
987 PKTIMER_TABLE_ENTRY TimerEntry;
988
989 /* Acquire timer lock */
990 LockQueue = KiAcquireTimerLock(Hand);
991
992 /* Set the timer as non-inserted */
993 Timer->Header.Inserted = FALSE;
994
995 /* Remove it from the timer list */
996 if (RemoveEntryList(&Timer->TimerListEntry))
997 {
998 /* Get the entry and check if it's empty */
999 TimerEntry = &KiTimerTableListHead[Hand];
1000 if (IsListEmpty(&TimerEntry->Entry))
1001 {
1002 /* Clear the time then */
1003 TimerEntry->Time.HighPart = 0xFFFFFFFF;
1004 }
1005 }
1006
1007 /* Release the timer lock */
1008 KiReleaseTimerLock(LockQueue);
1009}
ULARGE_INTEGER Time
Definition: ketypes.h:923
LIST_ENTRY Entry
Definition: ketypes.h:922

Referenced by KeCancelTimer(), KeSetTimerEx(), KiInsertQueue(), and KiUnlinkThread().

◆ KxSetTimerForThreadWait()

FORCEINLINE VOID KxSetTimerForThreadWait ( IN PKTIMER  Timer,
IN LARGE_INTEGER  Interval,
OUT PULONG  Hand 
)

Definition at line 1013 of file ke_x.h.

1016{
1018 LARGE_INTEGER InterruptTime, SystemTime, TimeDifference;
1019
1020 /* Check the timer's interval to see if it's absolute */
1021 Timer->Header.Absolute = FALSE;
1022 if (Interval.HighPart >= 0)
1023 {
1024 /* Get the system time and calculate the relative time */
1025 KeQuerySystemTime(&SystemTime);
1026 TimeDifference.QuadPart = SystemTime.QuadPart - Interval.QuadPart;
1027 Timer->Header.Absolute = TRUE;
1028
1029 /* Check if we've already expired */
1030 if (TimeDifference.HighPart >= 0)
1031 {
1032 /* Reset everything */
1033 Timer->DueTime.QuadPart = 0;
1034 *Hand = 0;
1035 Timer->Header.Hand = 0;
1036 return;
1037 }
1038 else
1039 {
1040 /* Update the interval */
1041 Interval = TimeDifference;
1042 }
1043 }
1044
1045 /* Calculate the due time */
1046 InterruptTime.QuadPart = KeQueryInterruptTime();
1047 DueTime = InterruptTime.QuadPart - Interval.QuadPart;
1048 Timer->DueTime.QuadPart = DueTime;
1049
1050 /* Calculate the timer handle */
1052 Timer->Header.Hand = (UCHAR)*Hand;
1053}
uint64_t ULONGLONG
Definition: typedefs.h:67

◆ KxUnwaitThread()

FORCEINLINE VOID KxUnwaitThread ( IN DISPATCHER_HEADER *  Object,
IN KPRIORITY  Increment 
)

Definition at line 1238 of file ke_x.h.

1240{
1241 PLIST_ENTRY WaitEntry, WaitList;
1242 PKWAIT_BLOCK WaitBlock;
1243 PKTHREAD WaitThread;
1244 ULONG WaitKey;
1245
1246 /* Loop the Wait Entries */
1247 WaitList = &Object->WaitListHead;
1248 ASSERT(IsListEmpty(&Object->WaitListHead) == FALSE);
1249 WaitEntry = WaitList->Flink;
1250 do
1251 {
1252 /* Get the current wait block */
1253 WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
1254
1255 /* Get the waiting thread */
1256 WaitThread = WaitBlock->Thread;
1257
1258 /* Check the current Wait Mode */
1259 if (WaitBlock->WaitType == WaitAny)
1260 {
1261 /* Use the actual wait key */
1262 WaitKey = WaitBlock->WaitKey;
1263 }
1264 else
1265 {
1266 /* Otherwise, use STATUS_KERNEL_APC */
1267 WaitKey = STATUS_KERNEL_APC;
1268 }
1269
1270 /* Unwait the thread */
1271 KiUnwaitThread(WaitThread, WaitKey, Increment);
1272
1273 /* Next entry */
1274 WaitEntry = WaitList->Flink;
1275 } while (WaitEntry != WaitList);
1276}
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46
@ WaitAny
VOID FASTCALL KiUnwaitThread(IN PKTHREAD Thread, IN LONG_PTR WaitStatus, IN KPRIORITY Increment)
Definition: wait.c:89
#define STATUS_KERNEL_APC
Definition: ntstatus.h:132
struct _KTHREAD * Thread
Definition: ketypes.h:533
UCHAR WaitType
Definition: ketypes.h:526
USHORT WaitKey
Definition: ketypes.h:528

Referenced by KeSetEvent(), KeSetProcess(), KeTerminateThread(), KiSignalTimer(), KiTimerExpiration(), and KiTimerListExpire().

◆ KxUnwaitThreadForEvent()

FORCEINLINE VOID KxUnwaitThreadForEvent ( IN PKEVENT  Event,
IN KPRIORITY  Increment 
)

Definition at line 1283 of file ke_x.h.

1285{
1286 PLIST_ENTRY WaitEntry, WaitList;
1287 PKWAIT_BLOCK WaitBlock;
1288 PKTHREAD WaitThread;
1289
1290 /* Loop the Wait Entries */
1291 WaitList = &Event->Header.WaitListHead;
1292 ASSERT(IsListEmpty(&Event->Header.WaitListHead) == FALSE);
1293 WaitEntry = WaitList->Flink;
1294 do
1295 {
1296 /* Get the current wait block */
1297 WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
1298
1299 /* Get the waiting thread */
1300 WaitThread = WaitBlock->Thread;
1301
1302 /* Check the current Wait Mode */
1303 if (WaitBlock->WaitType == WaitAny)
1304 {
1305 /* Un-signal it */
1306 Event->Header.SignalState = 0;
1307
1308 /* Un-signal the event and unwait the thread */
1309 KiUnwaitThread(WaitThread, WaitBlock->WaitKey, Increment);
1310 break;
1311 }
1312
1313 /* Unwait the thread with STATUS_KERNEL_APC */
1315
1316 /* Next entry */
1317 WaitEntry = WaitList->Flink;
1318 } while (WaitEntry != WaitList);
1319}
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287

Referenced by KeSetEvent(), KeSetEventBoostPriority(), KiSignalTimer(), KiTimerExpiration(), and KiTimerListExpire().