ReactOS 0.4.15-dev-8207-gd73a838
ke_x.h File Reference
This graph shows which files directly or indirectly include this file:

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 KiTryThreadLock (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)
 

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:34
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1765

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:1161

Definition at line 824 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:75
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_In_ KPRIORITY _In_ BOOLEAN Abandoned
Definition: kefuncs.h:582

Definition at line 715 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:407
@ SemaphoreObject
Definition: ketypes.h:411
#define TIMER_OR_EVENT_TYPE
Definition: ke.h:161

Definition at line 749 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:408

Definition at line 767 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:803
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:453
DWORD Interval
Definition: netstat.c:30
NTKERNELAPI volatile KSYSTEM_TIME KeTickCount
Definition: clock.c:19
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG LowPart
Definition: ketypes.h:929
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
@ DelayExecution
Definition: ketypes.h:419

Definition at line 1076 of file ke_x.h.

◆ KxMultiThreadWait

#define KxMultiThreadWait ( )

Definition at line 1107 of file ke_x.h.

◆ KxQueueThreadWait

#define KxQueueThreadWait ( )

Definition at line 1208 of file ke_x.h.

◆ KxSingleThreadWait

#define KxSingleThreadWait ( )

Definition at line 1163 of file ke_x.h.

Function Documentation

◆ _KeAcquireGuardedMutex()

FORCEINLINE VOID _KeAcquireGuardedMutex ( IN PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1587 of file ke_x.h.

1588{
1590
1591 /* Sanity checks */
1593 ASSERT(GuardedMutex->Owner != Thread);
1594
1595 /* Disable Special APCs */
1597
1598 /* Remove the lock */
1599 if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
1600 {
1601 /* The Guarded Mutex was already locked, enter contented case */
1602 KiAcquireGuardedMutex(GuardedMutex);
1603 }
1604
1605 /* Set the Owner and Special APC Disable state */
1606 GuardedMutex->Owner = Thread;
1607 GuardedMutex->SpecialApcDisable = Thread->SpecialApcDisable;
1608}
#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 1522 of file ke_x.h.

1523{
1525
1526 /* Sanity checks */
1528 (Thread->SpecialApcDisable < 0) ||
1529 (Thread->Teb == NULL) ||
1530 (Thread->Teb >= (PTEB)MM_SYSTEM_RANGE_START));
1531 ASSERT(GuardedMutex->Owner != Thread);
1532
1533 /* Remove the lock */
1534 if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
1535 {
1536 /* The Guarded Mutex was already locked, enter contented case */
1537 KiAcquireGuardedMutex(GuardedMutex);
1538 }
1539
1540 /* Set the Owner */
1541 GuardedMutex->Owner = Thread;
1542}
#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 1509 of file ke_x.h.

1510{
1511 /* Setup the Initial Data */
1512 GuardedMutex->Count = GM_LOCK_BIT;
1513 GuardedMutex->Owner = NULL;
1514 GuardedMutex->Contention = 0;
1515
1516 /* Initialize the Wait Gate */
1517 KeInitializeGate(&GuardedMutex->Gate);
1518}
VOID FASTCALL KeInitializeGate(PKGATE Gate)
#define GM_LOCK_BIT

Referenced by KeInitializeGuardedMutex().

◆ _KeReleaseGuardedMutex()

FORCEINLINE VOID _KeReleaseGuardedMutex ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1612 of file ke_x.h.

1613{
1615 LONG OldValue, NewValue;
1616
1617 /* Sanity checks */
1619 ASSERT(GuardedMutex->Owner == Thread);
1620 ASSERT(Thread->SpecialApcDisable == GuardedMutex->SpecialApcDisable);
1621
1622 /* Destroy the Owner */
1623 GuardedMutex->Owner = NULL;
1624
1625 /* Add the Lock Bit */
1626 OldValue = InterlockedExchangeAdd(&GuardedMutex->Count, GM_LOCK_BIT);
1627 ASSERT((OldValue & GM_LOCK_BIT) == 0);
1628
1629 /* Check if it was already locked, but not woken */
1630 if ((OldValue) && !(OldValue & GM_LOCK_WAITER_WOKEN))
1631 {
1632 /* Update the Oldvalue to what it should be now */
1633 OldValue += GM_LOCK_BIT;
1634
1635 /* The mutex will be woken, minus one waiter */
1636 NewValue = OldValue + GM_LOCK_WAITER_WOKEN -
1638
1639 /* Remove the Woken bit */
1640 if (InterlockedCompareExchange(&GuardedMutex->Count,
1641 NewValue,
1642 OldValue) == OldValue)
1643 {
1644 /* Signal the Gate */
1645 KeSignalGateBoostPriority(&GuardedMutex->Gate);
1646 }
1647 }
1648
1649 /* Re-enable APCs */
1651}
#define InterlockedExchangeAdd
Definition: interlocked.h:181
#define InterlockedCompareExchange
Definition: interlocked.h:104
#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 1546 of file ke_x.h.

1547{
1548 LONG OldValue, NewValue;
1549
1550 /* Sanity checks */
1552 (KeGetCurrentThread()->SpecialApcDisable < 0) ||
1553 (KeGetCurrentThread()->Teb == NULL) ||
1555 ASSERT(GuardedMutex->Owner == KeGetCurrentThread());
1556
1557 /* Destroy the Owner */
1558 GuardedMutex->Owner = NULL;
1559
1560 /* Add the Lock Bit */
1561 OldValue = InterlockedExchangeAdd(&GuardedMutex->Count, GM_LOCK_BIT);
1562 ASSERT((OldValue & GM_LOCK_BIT) == 0);
1563
1564 /* Check if it was already locked, but not woken */
1565 if ((OldValue) && !(OldValue & GM_LOCK_WAITER_WOKEN))
1566 {
1567 /* Update the Oldvalue to what it should be now */
1568 OldValue += GM_LOCK_BIT;
1569
1570 /* The mutex will be woken, minus one waiter */
1571 NewValue = OldValue + GM_LOCK_WAITER_WOKEN -
1573
1574 /* Remove the Woken bit */
1575 if (InterlockedCompareExchange(&GuardedMutex->Count,
1576 NewValue,
1577 OldValue) == OldValue)
1578 {
1579 /* Signal the Gate */
1580 KeSignalGateBoostPriority(&GuardedMutex->Gate);
1581 }
1582 }
1583}

Referenced by KeReleaseGuardedMutexUnsafe().

◆ _KeTryToAcquireGuardedMutex()

FORCEINLINE BOOLEAN _KeTryToAcquireGuardedMutex ( IN OUT PKGUARDED_MUTEX  GuardedMutex)

Definition at line 1655 of file ke_x.h.

1656{
1658
1659 /* Block APCs */
1661
1662 /* Remove the lock */
1663 if (!InterlockedBitTestAndReset(&GuardedMutex->Count, GM_LOCK_BIT_V))
1664 {
1665 /* Re-enable APCs */
1668
1669 /* Return failure */
1670 return FALSE;
1671 }
1672
1673 /* Set the Owner and APC State */
1674 GuardedMutex->Owner = Thread;
1675 GuardedMutex->SpecialApcDisable = Thread->SpecialApcDisable;
1676 return TRUE;
1677}
#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 1350 of file ke_x.h.

1356{
1357 BOOLEAN Preempted;
1359
1360 /* Sanity checks */
1361 ASSERT(Prcb == KeGetCurrentPrcb());
1362#ifdef CONFIG_SMP
1363 ASSERT(Prcb->PrcbLock != 0);
1364#endif
1365 ASSERT(Thread->State == Running);
1366 ASSERT(Thread->NextProcessor == Prcb->Number);
1367
1368 /* Check if this thread is allowed to run in this CPU */
1369#ifdef CONFIG_SMP
1370 if ((Thread->Affinity) & (Prcb->SetMember))
1371#else
1372 if (TRUE)
1373#endif
1374 {
1375 /* Set thread ready for execution */
1376 Thread->State = Ready;
1377
1378 /* Save current priority and if someone had pre-empted it */
1379 Priority = Thread->Priority;
1380 Preempted = Thread->Preempted;
1381
1382 /* We're not pre-empting now, and set the wait time */
1383 Thread->Preempted = FALSE;
1384 Thread->WaitTime = KeTickCount.LowPart;
1385
1386 /* Sanity check */
1387 ASSERT((Priority >= 0) && (Priority <= HIGH_PRIORITY));
1388
1389 /* Insert this thread in the appropriate order */
1390 Preempted ? InsertHeadList(&Prcb->DispatcherReadyListHead[Priority],
1391 &Thread->WaitListEntry) :
1392 InsertTailList(&Prcb->DispatcherReadyListHead[Priority],
1393 &Thread->WaitListEntry);
1394
1395 /* Update the ready summary */
1396 Prcb->ReadySummary |= PRIORITY_MASK(Priority);
1397
1398 /* Sanity check */
1399 ASSERT(Priority == Thread->Priority);
1400
1401 /* Release the PRCB lock */
1402 KiReleasePrcbLock(Prcb);
1403 }
1404 else
1405 {
1406 /* Otherwise, prepare this thread to be deferred */
1407 Thread->State = DeferredReady;
1408 Thread->DeferredProcessor = Prcb->Number;
1409
1410 /* Release the lock and defer scheduling */
1411 KiReleasePrcbLock(Prcb);
1413 }
1414}
unsigned char BOOLEAN
LONG KPRIORITY
Definition: compat.h:803
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
#define HIGH_PRIORITY
FORCEINLINE VOID KiReleasePrcbLock(IN PKPRCB Prcb)
Definition: ke_x.h:230
@ Ready
Definition: ketypes.h:389
@ Running
Definition: ketypes.h:390
@ DeferredReady
Definition: ketypes.h:395
#define PRIORITY_MASK(Priority)
Definition: ke.h:158
VOID FASTCALL KiDeferredReadyThread(IN PKTHREAD Thread)
Definition: thrdschd.c:79
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:655

◆ 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 616 of file ke_x.h.

618{
619 /* Acquire the lock */
622}
#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 626 of file ke_x.h.

628{
629 /* Acquire the lock */
631}
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 607 of file ke_x.h.

609{
610 /* Acquire the lock and raise to synchronization level */
612}
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 676 of file ke_x.h.

678{
679 /* Check if we were called from a threaded DPC */
680 if (KeGetCurrentPrcb()->DpcThreadActive)
681 {
682 /* Lock the Queue, we're not at DPC level */
683 KeAcquireInStackQueuedSpinLock(&DeviceQueue->Lock, DeviceLock);
684 }
685 else
686 {
687 /* We must be at DPC level, acquire the lock safely */
690 DeviceLock);
691 }
692}
#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:317

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

◆ KiAcquireNmiListLock()

FORCEINLINE VOID KiAcquireNmiListLock ( OUT PKIRQL  OldIrql)

Definition at line 1682 of file ke_x.h.

1683{
1685}
#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 651 of file ke_x.h.

653{
654 /* Acquire the lock and raise to synchronization level */
656}
_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 841 of file ke_x.h.

844{
845 /* Check if the wait is alertable */
846 if (Alertable)
847 {
848 /* It is, first check if the thread is alerted in this mode */
849 if (Thread->Alerted[WaitMode])
850 {
851 /* It is, so bail out of the wait */
852 Thread->Alerted[WaitMode] = FALSE;
853 return STATUS_ALERTED;
854 }
855 else if ((WaitMode != KernelMode) &&
856 (!IsListEmpty(&Thread->ApcState.ApcListHead[UserMode])))
857 {
858 /* It's isn't, but this is a user wait with queued user APCs */
859 Thread->ApcState.UserApcPending = TRUE;
860 return STATUS_USER_APC;
861 }
862 else if (Thread->Alerted[KernelMode])
863 {
864 /* It isn't that either, but we're alered in kernel mode */
865 Thread->Alerted[KernelMode] = FALSE;
866 return STATUS_ALERTED;
867 }
868 }
869 else if ((WaitMode != KernelMode) && (Thread->ApcState.UserApcPending))
870 {
871 /* Not alertable, but this is a user wait with pending user APCs */
872 return STATUS_USER_APC;
873 }
874
875 /* Otherwise, we're fine */
876 return STATUS_WAIT_0;
877}
#define UserMode
Definition: asm.h:35
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define STATUS_ALERTED
Definition: ntstatus.h:80
#define STATUS_USER_APC
Definition: ntstatus.h:78

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 803 of file ke_x.h.

805{
806 /* Check the required conditions */
807 if ((WaitMode != KernelMode) &&
808 (Thread->EnableStackSwap) &&
809 (Thread->Priority >= (LOW_REALTIME_PRIORITY + 9)))
810 {
811 /* We are go for swap */
812 return TRUE;
813 }
814 else
815 {
816 /* Don't swap the thread */
817 return FALSE;
818 }
819}
#define LOW_REALTIME_PRIORITY

◆ KiComputeDueTime()

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

Definition at line 952 of file ke_x.h.

955{
956 LARGE_INTEGER InterruptTime, SystemTime, DifferenceTime;
957
958 /* Convert to relative time if needed */
959 Timer->Header.Absolute = FALSE;
960 if (DueTime.HighPart >= 0)
961 {
962 /* Get System Time */
963 KeQuerySystemTime(&SystemTime);
964
965 /* Do the conversion */
966 DifferenceTime.QuadPart = SystemTime.QuadPart - DueTime.QuadPart;
967
968 /* Make sure it hasn't already expired */
969 Timer->Header.Absolute = TRUE;
970 if (DifferenceTime.HighPart >= 0)
971 {
972 /* Cancel everything */
973 Timer->Header.SignalState = TRUE;
974 Timer->Header.Hand = 0;
975 Timer->DueTime.QuadPart = 0;
976 *Hand = 0;
977 return FALSE;
978 }
979
980 /* Set the time as Absolute */
981 DueTime = DifferenceTime;
982 }
983
984 /* Get the Interrupt Time */
985 InterruptTime.QuadPart = KeQueryInterruptTime();
986
987 /* Recalculate due time */
988 Timer->DueTime.QuadPart = InterruptTime.QuadPart - DueTime.QuadPart;
989
990 /* Get the handle */
991 *Hand = KiComputeTimerTableIndex(Timer->DueTime.QuadPart);
992 Timer->Header.Hand = (UCHAR)*Hand;
993 Timer->Header.Inserted = TRUE;
994 return TRUE;
995}
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
FORCEINLINE ULONG KiComputeTimerTableIndex(IN ULONGLONG DueTime)
Definition: ke_x.h:881
#define KeQueryInterruptTime()
Definition: ke.h:37
LONGLONG QuadPart
Definition: typedefs.h:114
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by KeSetTimerEx(), and KiInsertTreeTimer().

◆ KiComputeNewPriority()

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

Definition at line 1472 of file ke_x.h.

1474{
1476
1477 /* Priority sanity checks */
1478 ASSERT((Thread->PriorityDecrement >= 0) &&
1479 (Thread->PriorityDecrement <= Thread->Priority));
1480 ASSERT((Thread->Priority < LOW_REALTIME_PRIORITY) ?
1481 TRUE : (Thread->PriorityDecrement == 0));
1482
1483 /* Get the current priority */
1484 Priority = Thread->Priority;
1486 {
1487 /* Decrease priority by the priority decrement */
1488 Priority -= (Thread->PriorityDecrement + Adjustment);
1489
1490 /* Don't go out of bounds */
1491 if (Priority < Thread->BasePriority) Priority = Thread->BasePriority;
1492
1493 /* Reset the priority decrement */
1494 Thread->PriorityDecrement = 0;
1495 }
1496
1497 /* Sanity check */
1498 ASSERT((Thread->BasePriority == 0) || (Priority != 0));
1499
1500 /* Return the new priority */
1501 return Priority;
1502}
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 881 of file ke_x.h.

882{
884}
ULONG KeMaximumIncrement
Definition: clock.c:20
#define TIMER_TABLE_SIZE
Definition: ketypes.h:848

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().

◆ KiRecalculateDueTime()

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

Definition at line 785 of file ke_x.h.

788{
789 /* Don't do anything for absolute waits */
790 if (OriginalDueTime->QuadPart >= 0) return OriginalDueTime;
791
792 /* Otherwise, query the interrupt time and recalculate */
793 NewDueTime->QuadPart = KeQueryInterruptTime();
794 NewDueTime->QuadPart -= DueTime->QuadPart;
795 return NewDueTime;
796}

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

◆ KiReleaseApcLock()

FORCEINLINE VOID KiReleaseApcLock ( IN PKLOCK_QUEUE_HANDLE  Handle)

Definition at line 635 of file ke_x.h.

636{
637 /* Release the lock */
639}
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 643 of file ke_x.h.

644{
645 /* Release the lock */
647}
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 696 of file ke_x.h.

697{
698 /* Check if we were called from a threaded DPC */
699 if (KeGetCurrentPrcb()->DpcThreadActive)
700 {
701 /* Unlock the Queue, we're not at DPC level */
703 }
704 else
705 {
706 /* We must be at DPC level, release the lock safely */
709 }
710}

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 1689 of file ke_x.h.

1690{
1692}
#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 660 of file ke_x.h.

661{
662 /* Release the lock and restore previous IRQL */
664}

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

◆ KiReleaseProcessLockFromSynchLevel()

FORCEINLINE VOID KiReleaseProcessLockFromSynchLevel ( IN PKLOCK_QUEUE_HANDLE  Handle)

Definition at line 668 of file ke_x.h.

669{
670 /* Release the lock without lowering IRQL */
672}

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 892 of file ke_x.h.

893{
894 ULONG Hand;
896
897 /* Remove the timer from the timer list and check if it's empty */
898 Hand = Timer->Header.Hand;
899 if (RemoveEntryList(&Timer->TimerListEntry))
900 {
901 /* Get the respective timer table entry */
903 if (&TableEntry->Entry == TableEntry->Entry.Flink)
904 {
905 /* Set the entry to an infinite absolute time */
906 TableEntry->Time.HighPart = 0xFFFFFFFF;
907 }
908 }
909
910 /* Clear the list entries on dbg builds so we can tell the timer is gone */
911#if DBG
912 Timer->TimerListEntry.Flink = NULL;
913 Timer->TimerListEntry.Blink = NULL;
914#endif
915}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
Definition: ketypes.h:774
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ typedef _In_ ULONG TableEntry
Definition: iotypes.h:4303

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 1422 of file ke_x.h.

1424{
1425 ULONG PrioritySet;
1426 LONG HighPriority;
1427 PLIST_ENTRY ListEntry;
1429
1430 /* Save the current mask and get the priority set for the CPU */
1431 PrioritySet = Prcb->ReadySummary >> Priority;
1432 if (!PrioritySet) goto Quickie;
1433
1434 /* Get the highest priority possible */
1435 BitScanReverse((PULONG)&HighPriority, PrioritySet);
1436 ASSERT((PrioritySet & PRIORITY_MASK(HighPriority)) != 0);
1437 HighPriority += Priority;
1438
1439 /* Make sure the list isn't empty at the highest priority */
1440 ASSERT(IsListEmpty(&Prcb->DispatcherReadyListHead[HighPriority]) == FALSE);
1441
1442 /* Get the first thread on the list */
1443 ListEntry = Prcb->DispatcherReadyListHead[HighPriority].Flink;
1444 Thread = CONTAINING_RECORD(ListEntry, KTHREAD, WaitListEntry);
1445
1446 /* Make sure this thread is here for a reason */
1447 ASSERT(HighPriority == Thread->Priority);
1448 ASSERT(Thread->Affinity & AFFINITY_MASK(Prcb->Number));
1449 ASSERT(Thread->NextProcessor == Prcb->Number);
1450
1451 /* Remove it from the list */
1452 if (RemoveEntryList(&Thread->WaitListEntry))
1453 {
1454 /* The list is empty now, reset the ready summary */
1455 Prcb->ReadySummary ^= PRIORITY_MASK(HighPriority);
1456 }
1457
1458 /* Sanity check and return the thread */
1459Quickie:
1460 ASSERT((Thread == NULL) ||
1461 (Thread->BasePriority == 0) ||
1462 (Thread->Priority != 0));
1463 return Thread;
1464}
#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()

◆ KiTryThreadLock()

FORCEINLINE BOOLEAN KiTryThreadLock ( IN PKTHREAD  Thread)

Definition at line 260 of file ke_x.h.

261{
263 return FALSE;
264}

Referenced by KeSignalGateBoostPriority().

◆ KxInsertTimer()

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

Definition at line 923 of file ke_x.h.

925{
926 PKSPIN_LOCK_QUEUE LockQueue;
928
929 /* Acquire the lock and release the dispatcher lock */
930 LockQueue = KiAcquireTimerLock(Hand);
932
933 /* Try to insert the timer */
934 if (KiInsertTimerTable(Timer, Hand))
935 {
936 /* Complete it */
937 KiCompleteTimer(Timer, LockQueue);
938 }
939 else
940 {
941 /* Do nothing, just release the lock */
942 KiReleaseTimerLock(LockQueue);
943 }
944}
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 1004 of file ke_x.h.

1005{
1006 ULONG Hand = Timer->Header.Hand;
1007 PKSPIN_LOCK_QUEUE LockQueue;
1008 PKTIMER_TABLE_ENTRY TimerEntry;
1009
1010 /* Acquire timer lock */
1011 LockQueue = KiAcquireTimerLock(Hand);
1012
1013 /* Set the timer as non-inserted */
1014 Timer->Header.Inserted = FALSE;
1015
1016 /* Remove it from the timer list */
1017 if (RemoveEntryList(&Timer->TimerListEntry))
1018 {
1019 /* Get the entry and check if it's empty */
1020 TimerEntry = &KiTimerTableListHead[Hand];
1021 if (IsListEmpty(&TimerEntry->Entry))
1022 {
1023 /* Clear the time then */
1024 TimerEntry->Time.HighPart = 0xFFFFFFFF;
1025 }
1026 }
1027
1028 /* Release the timer lock */
1029 KiReleaseTimerLock(LockQueue);
1030}
ULARGE_INTEGER Time
Definition: ketypes.h:779
LIST_ENTRY Entry
Definition: ketypes.h:778
$ULONG HighPart
Definition: ntbasedef.h:570

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

◆ KxSetTimerForThreadWait()

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

Definition at line 1034 of file ke_x.h.

1037{
1039 LARGE_INTEGER InterruptTime, SystemTime, TimeDifference;
1040
1041 /* Check the timer's interval to see if it's absolute */
1042 Timer->Header.Absolute = FALSE;
1043 if (Interval.HighPart >= 0)
1044 {
1045 /* Get the system time and calculate the relative time */
1046 KeQuerySystemTime(&SystemTime);
1047 TimeDifference.QuadPart = SystemTime.QuadPart - Interval.QuadPart;
1048 Timer->Header.Absolute = TRUE;
1049
1050 /* Check if we've already expired */
1051 if (TimeDifference.HighPart >= 0)
1052 {
1053 /* Reset everything */
1054 Timer->DueTime.QuadPart = 0;
1055 *Hand = 0;
1056 Timer->Header.Hand = 0;
1057 return;
1058 }
1059 else
1060 {
1061 /* Update the interval */
1062 Interval = TimeDifference;
1063 }
1064 }
1065
1066 /* Calculate the due time */
1067 InterruptTime.QuadPart = KeQueryInterruptTime();
1068 DueTime = InterruptTime.QuadPart - Interval.QuadPart;
1069 Timer->DueTime.QuadPart = DueTime;
1070
1071 /* Calculate the timer handle */
1073 Timer->Header.Hand = (UCHAR)*Hand;
1074}
uint64_t ULONGLONG
Definition: typedefs.h:67

◆ KxUnwaitThread()

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

Definition at line 1259 of file ke_x.h.

1261{
1262 PLIST_ENTRY WaitEntry, WaitList;
1263 PKWAIT_BLOCK WaitBlock;
1264 PKTHREAD WaitThread;
1265 ULONG WaitKey;
1266
1267 /* Loop the Wait Entries */
1268 WaitList = &Object->WaitListHead;
1269 ASSERT(IsListEmpty(&Object->WaitListHead) == FALSE);
1270 WaitEntry = WaitList->Flink;
1271 do
1272 {
1273 /* Get the current wait block */
1274 WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
1275
1276 /* Get the waiting thread */
1277 WaitThread = WaitBlock->Thread;
1278
1279 /* Check the current Wait Mode */
1280 if (WaitBlock->WaitType == WaitAny)
1281 {
1282 /* Use the actual wait key */
1283 WaitKey = WaitBlock->WaitKey;
1284 }
1285 else
1286 {
1287 /* Otherwise, use STATUS_KERNEL_APC */
1288 WaitKey = STATUS_KERNEL_APC;
1289 }
1290
1291 /* Unwait the thread */
1292 KiUnwaitThread(WaitThread, WaitKey, Increment);
1293
1294 /* Next entry */
1295 WaitEntry = WaitList->Flink;
1296 } while (WaitEntry != WaitList);
1297}
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:79
struct _KTHREAD * Thread
Definition: ketypes.h:465
UCHAR WaitType
Definition: ketypes.h:458
USHORT WaitKey
Definition: ketypes.h:460

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

◆ KxUnwaitThreadForEvent()

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

Definition at line 1304 of file ke_x.h.

1306{
1307 PLIST_ENTRY WaitEntry, WaitList;
1308 PKWAIT_BLOCK WaitBlock;
1309 PKTHREAD WaitThread;
1310
1311 /* Loop the Wait Entries */
1312 WaitList = &Event->Header.WaitListHead;
1313 ASSERT(IsListEmpty(&Event->Header.WaitListHead) == FALSE);
1314 WaitEntry = WaitList->Flink;
1315 do
1316 {
1317 /* Get the current wait block */
1318 WaitBlock = CONTAINING_RECORD(WaitEntry, KWAIT_BLOCK, WaitListEntry);
1319
1320 /* Get the waiting thread */
1321 WaitThread = WaitBlock->Thread;
1322
1323 /* Check the current Wait Mode */
1324 if (WaitBlock->WaitType == WaitAny)
1325 {
1326 /* Un-signal it */
1327 Event->Header.SignalState = 0;
1328
1329 /* Un-signal the event and unwait the thread */
1330 KiUnwaitThread(WaitThread, WaitBlock->WaitKey, Increment);
1331 break;
1332 }
1333
1334 /* Unwait the thread with STATUS_KERNEL_APC */
1336
1337 /* Next entry */
1338 WaitEntry = WaitList->Flink;
1339 } while (WaitEntry != WaitList);
1340}

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