2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/include/ke_x.h
5 * PURPOSE: Internal Inlined Functions for the Kernel
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
12 KeGetPreviousMode(VOID
)
14 /* Return the current mode */
15 return KeGetCurrentThread()->PreviousMode
;
20 // Enters a Guarded Region
22 #define KeEnterGuardedRegion() \
24 PKTHREAD _Thread = KeGetCurrentThread(); \
27 ASSERT(KeGetCurrentIrql() <= APC_LEVEL); \
28 ASSERT(_Thread == KeGetCurrentThread()); \
29 ASSERT((_Thread->SpecialApcDisable <= 0) && \
30 (_Thread->SpecialApcDisable != -32768)); \
32 /* Disable Special APCs */ \
33 _Thread->SpecialApcDisable--; \
37 // Leaves a Guarded Region
39 #define KeLeaveGuardedRegion() \
41 PKTHREAD _Thread = KeGetCurrentThread(); \
44 ASSERT(KeGetCurrentIrql() <= APC_LEVEL); \
45 ASSERT(_Thread == KeGetCurrentThread()); \
46 ASSERT(_Thread->SpecialApcDisable < 0); \
48 /* Leave region and check if APCs are OK now */ \
49 if (!(++_Thread->SpecialApcDisable)) \
51 /* Check for Kernel APCs on the list */ \
52 if (!IsListEmpty(&_Thread->ApcState. \
53 ApcListHead[KernelMode])) \
55 /* Check for APC Delivery */ \
56 KiCheckForKernelApcDelivery(); \
62 // Enters a Critical Region
64 #define KeEnterCriticalRegion() \
66 PKTHREAD _Thread = KeGetCurrentThread(); \
69 ASSERT(_Thread == KeGetCurrentThread()); \
70 ASSERT((_Thread->KernelApcDisable <= 0) && \
71 (_Thread->KernelApcDisable != -32768)); \
73 /* Disable Kernel APCs */ \
74 _Thread->KernelApcDisable--; \
78 // Leaves a Critical Region
80 #define KeLeaveCriticalRegion() \
82 PKTHREAD _Thread = KeGetCurrentThread(); \
85 ASSERT(_Thread == KeGetCurrentThread()); \
86 ASSERT(_Thread->KernelApcDisable < 0); \
88 /* Enable Kernel APCs */ \
89 _Thread->KernelApcDisable++; \
91 /* Check if Kernel APCs are now enabled */ \
92 if (!(_Thread->KernelApcDisable)) \
94 /* Check if we need to request an APC Delivery */ \
95 if (!(IsListEmpty(&_Thread->ApcState.ApcListHead[KernelMode])) && \
96 !(_Thread->SpecialApcDisable)) \
98 /* Check for the right environment */ \
99 KiCheckForKernelApcDelivery(); \
107 // This routine protects against multiple CPU acquires, it's meaningless on UP.
111 KiAcquireDispatcherObject(IN DISPATCHER_HEADER
* Object
)
113 UNREFERENCED_PARAMETER(Object
);
117 // This routine protects against multiple CPU acquires, it's meaningless on UP.
121 KiReleaseDispatcherObject(IN DISPATCHER_HEADER
* Object
)
123 UNREFERENCED_PARAMETER(Object
);
128 KiAcquireDispatcherLock(VOID
)
130 /* Raise to synch level */
131 return KfRaiseIrql(SYNCH_LEVEL
);
136 KiReleaseDispatcherLock(IN KIRQL OldIrql
)
138 /* Just exit the dispatcher */
139 KiExitDispatcher(OldIrql
);
144 KiAcquireDispatcherLockAtDpcLevel(VOID
)
146 /* This is a no-op at DPC Level for UP systems */
152 KiReleaseDispatcherLockFromDpcLevel(VOID
)
154 /* This is a no-op at DPC Level for UP systems */
159 // This routine makes the thread deferred ready on the boot CPU.
163 KiInsertDeferredReadyList(IN PKTHREAD Thread
)
165 /* Set the thread to deferred state and boot CPU */
166 Thread
->State
= DeferredReady
;
167 Thread
->DeferredProcessor
= 0;
169 /* Make the thread ready immediately */
170 KiDeferredReadyThread(Thread
);
175 KiRescheduleThread(IN BOOLEAN NewThread
,
178 /* This is meaningless on UP systems */
179 UNREFERENCED_PARAMETER(NewThread
);
180 UNREFERENCED_PARAMETER(Cpu
);
184 // This routine protects against multiple CPU acquires, it's meaningless on UP.
188 KiSetThreadSwapBusy(IN PKTHREAD Thread
)
190 UNREFERENCED_PARAMETER(Thread
);
194 // This routine protects against multiple CPU acquires, it's meaningless on UP.
198 KiAcquirePrcbLock(IN PKPRCB Prcb
)
200 UNREFERENCED_PARAMETER(Prcb
);
204 // This routine protects against multiple CPU acquires, it's meaningless on UP.
208 KiReleasePrcbLock(IN PKPRCB Prcb
)
210 UNREFERENCED_PARAMETER(Prcb
);
214 // This routine protects against multiple CPU acquires, it's meaningless on UP.
218 KiAcquireThreadLock(IN PKTHREAD Thread
)
220 UNREFERENCED_PARAMETER(Thread
);
224 // This routine protects against multiple CPU acquires, it's meaningless on UP.
228 KiReleaseThreadLock(IN PKTHREAD Thread
)
230 UNREFERENCED_PARAMETER(Thread
);
234 // This routine protects against multiple CPU acquires, it's meaningless on UP.
238 KiTryThreadLock(IN PKTHREAD Thread
)
240 UNREFERENCED_PARAMETER(Thread
);
246 KiCheckDeferredReadyList(IN PKPRCB Prcb
)
248 /* There are no deferred ready lists on UP systems */
249 UNREFERENCED_PARAMETER(Prcb
);
254 KiRequestApcInterrupt(IN BOOLEAN NeedApc
,
257 /* We deliver instantly on UP */
258 UNREFERENCED_PARAMETER(NeedApc
);
259 UNREFERENCED_PARAMETER(Processor
);
264 KiAcquireTimerLock(IN ULONG Hand
)
266 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
268 /* Nothing to do on UP */
269 UNREFERENCED_PARAMETER(Hand
);
275 KiReleaseTimerLock(IN PKSPIN_LOCK_QUEUE LockQueue
)
277 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
279 /* Nothing to do on UP */
280 UNREFERENCED_PARAMETER(LockQueue
);
287 KiAcquireDispatcherObject(IN DISPATCHER_HEADER
* Object
)
291 /* Make sure we're at a safe level to touch the lock */
292 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
294 /* Start acquire loop */
297 /* Loop until the other CPU releases it */
300 /* Check if it got released */
301 OldValue
= Object
->Lock
;
302 if ((OldValue
& KOBJECT_LOCK_BIT
) == 0) break;
304 /* Let the CPU know that this is a loop */
308 /* Try acquiring the lock now */
309 } while (InterlockedCompareExchange(&Object
->Lock
,
310 OldValue
| KOBJECT_LOCK_BIT
,
311 OldValue
) != OldValue
);
316 KiReleaseDispatcherObject(IN DISPATCHER_HEADER
* Object
)
318 /* Make sure we're at a safe level to touch the lock */
319 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
322 InterlockedAnd(&Object
->Lock
, ~KOBJECT_LOCK_BIT
);
327 KiAcquireDispatcherLock(VOID
)
329 /* Raise to synchronization level and acquire the dispatcher lock */
330 return KeAcquireQueuedSpinLockRaiseToSynch(LockQueueDispatcherLock
);
335 KiReleaseDispatcherLock(IN KIRQL OldIrql
)
337 /* First release the lock */
338 KeReleaseQueuedSpinLockFromDpcLevel(&KeGetCurrentPrcb()->
339 LockQueue
[LockQueueDispatcherLock
]);
341 /* Then exit the dispatcher */
342 KiExitDispatcher(OldIrql
);
347 KiAcquireDispatcherLockAtDpcLevel(VOID
)
349 /* Acquire the dispatcher lock */
350 KeAcquireQueuedSpinLockAtDpcLevel(&KeGetCurrentPrcb()->
351 LockQueue
[LockQueueDispatcherLock
]);
356 KiReleaseDispatcherLockFromDpcLevel(VOID
)
358 /* Release the dispatcher lock */
359 KeReleaseQueuedSpinLockFromDpcLevel(&KeGetCurrentPrcb()->
360 LockQueue
[LockQueueDispatcherLock
]);
364 // This routine inserts a thread into the deferred ready list of the current CPU
368 KiInsertDeferredReadyList(IN PKTHREAD Thread
)
370 PKPRCB Prcb
= KeGetCurrentPrcb();
372 /* Set the thread to deferred state and CPU */
373 Thread
->State
= DeferredReady
;
374 Thread
->DeferredProcessor
= Prcb
->Number
;
376 /* Add it on the list */
377 PushEntryList(&Prcb
->DeferredReadyListHead
, &Thread
->SwapListEntry
);
382 KiRescheduleThread(IN BOOLEAN NewThread
,
385 /* Check if a new thread needs to be scheduled on a different CPU */
386 if ((NewThread
) && !(KeGetPcr()->Number
== Cpu
))
388 /* Send an IPI to request delivery */
389 KiIpiSend(AFFINITY_MASK(Cpu
), IPI_DPC
);
394 // This routine sets the current thread in a swap busy state, which ensure that
395 // nobody else tries to swap it concurrently.
399 KiSetThreadSwapBusy(IN PKTHREAD Thread
)
401 /* Make sure nobody already set it */
402 ASSERT(Thread
->SwapBusy
== FALSE
);
404 /* Set it ourselves */
405 Thread
->SwapBusy
= TRUE
;
409 // This routine acquires the PRCB lock so that only one caller can touch
410 // volatile PRCB data.
412 // Since this is a simple optimized spin-lock, it must only be acquired
413 // at dispatcher level or higher!
417 KiAcquirePrcbLock(IN PKPRCB Prcb
)
419 /* Make sure we're at a safe level to touch the PRCB lock */
420 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
422 /* Start acquire loop */
425 /* Acquire the lock and break out if we acquired it first */
426 if (!InterlockedExchange((PLONG
)&Prcb
->PrcbLock
, 1)) break;
428 /* Loop until the other CPU releases it */
431 /* Let the CPU know that this is a loop */
433 } while (Prcb
->PrcbLock
);
438 // This routine releases the PRCB lock so that other callers can touch
439 // volatile PRCB data.
441 // Since this is a simple optimized spin-lock, it must be be only acquired
442 // at dispatcher level or higher!
446 KiReleasePrcbLock(IN PKPRCB Prcb
)
448 /* Make sure we are above dispatch and the lock is acquired! */
449 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
450 ASSERT(Prcb
->PrcbLock
!= 0);
453 InterlockedAnd((PLONG
)&Prcb
->PrcbLock
, 0);
457 // This routine acquires the thread lock so that only one caller can touch
458 // volatile thread data.
460 // Since this is a simple optimized spin-lock, it must be be only acquired
461 // at dispatcher level or higher!
465 KiAcquireThreadLock(IN PKTHREAD Thread
)
467 /* Make sure we're at a safe level to touch the thread lock */
468 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
470 /* Start acquire loop */
473 /* Acquire the lock and break out if we acquired it first */
474 if (!InterlockedExchange((PLONG
)&Thread
->ThreadLock
, 1)) break;
476 /* Loop until the other CPU releases it */
479 /* Let the CPU know that this is a loop */
481 } while (Thread
->ThreadLock
);
486 // This routine releases the thread lock so that other callers can touch
487 // volatile thread data.
489 // Since this is a simple optimized spin-lock, it must be be only acquired
490 // at dispatcher level or higher!
494 KiReleaseThreadLock(IN PKTHREAD Thread
)
496 /* Make sure we are still above dispatch */
497 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
500 InterlockedAnd((PLONG
)&Thread
->ThreadLock
, 0);
505 KiTryThreadLock(IN PKTHREAD Thread
)
509 /* If the lock isn't acquired, return false */
510 if (!Thread
->ThreadLock
) return FALSE
;
512 /* Otherwise, try to acquire it and check the result */
514 Value
= InterlockedExchange((PLONG
)&Thread
->ThreadLock
, Value
);
516 /* Return the lock state */
522 KiCheckDeferredReadyList(IN PKPRCB Prcb
)
524 /* Scan the deferred ready lists if required */
525 if (Prcb
->DeferredReadyListHead
.Next
) KiProcessDeferredReadyList(Prcb
);
530 KiRequestApcInterrupt(IN BOOLEAN NeedApc
,
533 /* Check if we need to request APC delivery */
536 /* Check if it's on another CPU */
537 if (KeGetPcr()->Number
!= Processor
)
539 /* Send an IPI to request delivery */
540 KiIpiSend(AFFINITY_MASK(Processor
), IPI_APC
);
544 /* Request a software interrupt */
545 HalRequestSoftwareInterrupt(APC_LEVEL
);
552 KiAcquireTimerLock(IN ULONG Hand
)
554 PKSPIN_LOCK_QUEUE LockQueue
;
556 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
558 /* Get the lock index */
559 LockIndex
= Hand
>> LOCK_QUEUE_TIMER_LOCK_SHIFT
;
560 LockIndex
&= (LOCK_QUEUE_TIMER_TABLE_LOCKS
- 1);
562 /* Now get the lock */
563 LockQueue
= &KeGetCurrentPrcb()->LockQueue
[LockQueueTimerTableLock
+ LockIndex
];
565 /* Acquire it and return */
566 KeAcquireQueuedSpinLockAtDpcLevel(LockQueue
);
572 KiReleaseTimerLock(IN PKSPIN_LOCK_QUEUE LockQueue
)
574 ASSERT(KeGetCurrentIrql() >= DISPATCH_LEVEL
);
576 /* Release the lock */
577 KeReleaseQueuedSpinLockFromDpcLevel(LockQueue
);
584 KiAcquireApcLock(IN PKTHREAD Thread
,
585 IN PKLOCK_QUEUE_HANDLE Handle
)
587 /* Acquire the lock and raise to synchronization level */
588 KeAcquireInStackQueuedSpinLockRaiseToSynch(&Thread
->ApcQueueLock
, Handle
);
593 KiAcquireApcLockAtDpcLevel(IN PKTHREAD Thread
,
594 IN PKLOCK_QUEUE_HANDLE Handle
)
596 /* Acquire the lock */
597 KeAcquireInStackQueuedSpinLockAtDpcLevel(&Thread
->ApcQueueLock
, Handle
);
602 KiAcquireApcLockAtApcLevel(IN PKTHREAD Thread
,
603 IN PKLOCK_QUEUE_HANDLE Handle
)
605 /* Acquire the lock */
606 KeAcquireInStackQueuedSpinLock(&Thread
->ApcQueueLock
, Handle
);
611 KiReleaseApcLock(IN PKLOCK_QUEUE_HANDLE Handle
)
613 /* Release the lock */
614 KeReleaseInStackQueuedSpinLock(Handle
);
619 KiReleaseApcLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle
)
621 /* Release the lock */
622 KeReleaseInStackQueuedSpinLockFromDpcLevel(Handle
);
627 KiAcquireProcessLock(IN PKPROCESS Process
,
628 IN PKLOCK_QUEUE_HANDLE Handle
)
630 /* Acquire the lock and raise to synchronization level */
631 KeAcquireInStackQueuedSpinLockRaiseToSynch(&Process
->ProcessLock
, Handle
);
636 KiReleaseProcessLock(IN PKLOCK_QUEUE_HANDLE Handle
)
638 /* Release the lock */
639 KeReleaseInStackQueuedSpinLock(Handle
);
644 KiReleaseProcessLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE Handle
)
646 /* Release the lock */
647 KeReleaseInStackQueuedSpinLockFromDpcLevel(Handle
);
652 KiAcquireDeviceQueueLock(IN PKDEVICE_QUEUE DeviceQueue
,
653 IN PKLOCK_QUEUE_HANDLE DeviceLock
)
655 /* Check if we were called from a threaded DPC */
656 if (KeGetCurrentPrcb()->DpcThreadActive
)
658 /* Lock the Queue, we're not at DPC level */
659 KeAcquireInStackQueuedSpinLock(&DeviceQueue
->Lock
, DeviceLock
);
663 /* We must be at DPC level, acquire the lock safely */
664 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
665 KeAcquireInStackQueuedSpinLockAtDpcLevel(&DeviceQueue
->Lock
,
672 KiReleaseDeviceQueueLock(IN PKLOCK_QUEUE_HANDLE DeviceLock
)
674 /* Check if we were called from a threaded DPC */
675 if (KeGetCurrentPrcb()->DpcThreadActive
)
677 /* Unlock the Queue, we're not at DPC level */
678 KeReleaseInStackQueuedSpinLock(DeviceLock
);
682 /* We must be at DPC level, release the lock safely */
683 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
684 KeReleaseInStackQueuedSpinLockFromDpcLevel(DeviceLock
);
689 // Satisfies the wait of a mutant dispatcher object
691 #define KiSatisfyMutantWait(Object, Thread) \
693 /* Decrease the Signal State */ \
694 (Object)->Header.SignalState--; \
696 /* Check if it's now non-signaled */ \
697 if (!(Object)->Header.SignalState) \
699 /* Set the Owner Thread */ \
700 (Object)->OwnerThread = Thread; \
702 /* Disable APCs if needed */ \
703 Thread->KernelApcDisable = Thread->KernelApcDisable - \
704 (Object)->ApcDisable; \
706 /* Check if it's abandoned */ \
707 if ((Object)->Abandoned) \
710 (Object)->Abandoned = FALSE; \
712 /* Return Status */ \
713 Thread->WaitStatus = STATUS_ABANDONED; \
716 /* Insert it into the Mutant List */ \
717 InsertHeadList(Thread->MutantListHead.Blink, \
718 &(Object)->MutantListEntry); \
723 // Satisfies the wait of any nonmutant dispatcher object
725 #define KiSatisfyNonMutantWait(Object) \
727 if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) == \
728 EventSynchronizationObject) \
730 /* Synchronization Timers and Events just get un-signaled */ \
731 (Object)->Header.SignalState = 0; \
733 else if ((Object)->Header.Type == SemaphoreObject) \
735 /* These ones can have multiple states, so we only decrease it */ \
736 (Object)->Header.SignalState--; \
741 // Satisfies the wait of any dispatcher object
743 #define KiSatisfyObjectWait(Object, Thread) \
745 /* Special case for Mutants */ \
746 if ((Object)->Header.Type == MutantObject) \
748 KiSatisfyMutantWait((Object), (Thread)); \
752 KiSatisfyNonMutantWait(Object); \
757 // Recalculates the due time
761 KiRecalculateDueTime(IN PLARGE_INTEGER OriginalDueTime
,
762 IN PLARGE_INTEGER DueTime
,
763 IN OUT PLARGE_INTEGER NewDueTime
)
765 /* Don't do anything for absolute waits */
766 if (OriginalDueTime
->QuadPart
>= 0) return OriginalDueTime
;
768 /* Otherwise, query the interrupt time and recalculate */
769 NewDueTime
->QuadPart
= KeQueryInterruptTime();
770 NewDueTime
->QuadPart
-= DueTime
->QuadPart
;
775 // Determines whether a thread should be added to the wait list
779 KiCheckThreadStackSwap(IN PKTHREAD Thread
,
780 IN KPROCESSOR_MODE WaitMode
)
782 /* Check the required conditions */
783 if ((WaitMode
!= KernelMode
) &&
784 (Thread
->EnableStackSwap
) &&
785 (Thread
->Priority
>= (LOW_REALTIME_PRIORITY
+ 9)))
787 /* We are go for swap */
792 /* Don't swap the thread */
798 // Adds a thread to the wait list
800 #define KiAddThreadToWaitList(Thread, Swappable) \
802 /* Make sure it's swappable */ \
805 /* Insert it into the PRCB's List */ \
806 InsertTailList(&KeGetCurrentPrcb()->WaitListHead, \
807 &Thread->WaitListEntry); \
812 // Checks if a wait in progress should be interrupted by APCs or an alertable
817 KiCheckAlertability(IN PKTHREAD Thread
,
818 IN BOOLEAN Alertable
,
819 IN KPROCESSOR_MODE WaitMode
)
821 /* Check if the wait is alertable */
824 /* It is, first check if the thread is alerted in this mode */
825 if (Thread
->Alerted
[WaitMode
])
827 /* It is, so bail out of the wait */
828 Thread
->Alerted
[WaitMode
] = FALSE
;
829 return STATUS_ALERTED
;
831 else if ((WaitMode
!= KernelMode
) &&
832 (!IsListEmpty(&Thread
->ApcState
.ApcListHead
[UserMode
])))
834 /* It's isn't, but this is a user wait with queued user APCs */
835 Thread
->ApcState
.UserApcPending
= TRUE
;
836 return STATUS_USER_APC
;
838 else if (Thread
->Alerted
[KernelMode
])
840 /* It isn't that either, but we're alered in kernel mode */
841 Thread
->Alerted
[KernelMode
] = FALSE
;
842 return STATUS_ALERTED
;
845 else if ((WaitMode
!= KernelMode
) && (Thread
->ApcState
.UserApcPending
))
847 /* Not alertable, but this is a user wait with pending user APCs */
848 return STATUS_USER_APC
;
851 /* Otherwise, we're fine */
852 return STATUS_WAIT_0
;
857 KiComputeTimerTableIndex(IN ULONGLONG DueTime
)
859 return (DueTime
/ KeMaximumIncrement
) & (TIMER_TABLE_SIZE
- 1);
863 // Called from KiCompleteTimer, KiInsertTreeTimer, KeSetSystemTime
864 // to remove timer entries
865 // See Windows HPI blog for more information.
868 KiRemoveEntryTimer(IN PKTIMER Timer
)
871 PKTIMER_TABLE_ENTRY TableEntry
;
873 /* Remove the timer from the timer list and check if it's empty */
874 Hand
= Timer
->Header
.Hand
;
875 if (RemoveEntryList(&Timer
->TimerListEntry
))
877 /* Get the respective timer table entry */
878 TableEntry
= &KiTimerTableListHead
[Hand
];
879 if (&TableEntry
->Entry
== TableEntry
->Entry
.Flink
)
881 /* Set the entry to an infinite absolute time */
882 TableEntry
->Time
.HighPart
= 0xFFFFFFFF;
886 /* Clear the list entries on dbg builds so we can tell the timer is gone */
888 Timer
->TimerListEntry
.Flink
= NULL
;
889 Timer
->TimerListEntry
.Blink
= NULL
;
894 // Called by Wait and Queue code to insert a timer for dispatching.
895 // Also called by KeSetTimerEx to insert a timer from the caller.
899 KxInsertTimer(IN PKTIMER Timer
,
902 PKSPIN_LOCK_QUEUE LockQueue
;
904 /* Acquire the lock and release the dispatcher lock */
905 LockQueue
= KiAcquireTimerLock(Hand
);
906 KiReleaseDispatcherLockFromDpcLevel();
908 /* Try to insert the timer */
909 if (KiInsertTimerTable(Timer
, Hand
))
912 KiCompleteTimer(Timer
, LockQueue
);
916 /* Do nothing, just release the lock */
917 KiReleaseTimerLock(LockQueue
);
922 // Called by KeSetTimerEx and KiInsertTreeTimer to calculate Due Time
923 // See the Windows HPI Blog for more information
927 KiComputeDueTime(IN PKTIMER Timer
,
928 IN LARGE_INTEGER DueTime
,
931 LARGE_INTEGER InterruptTime
, SystemTime
, DifferenceTime
;
933 /* Convert to relative time if needed */
934 Timer
->Header
.Absolute
= FALSE
;
935 if (DueTime
.HighPart
>= 0)
937 /* Get System Time */
938 KeQuerySystemTime(&SystemTime
);
940 /* Do the conversion */
941 DifferenceTime
.QuadPart
= SystemTime
.QuadPart
- DueTime
.QuadPart
;
943 /* Make sure it hasn't already expired */
944 Timer
->Header
.Absolute
= TRUE
;
945 if (DifferenceTime
.HighPart
>= 0)
947 /* Cancel everything */
948 Timer
->Header
.SignalState
= TRUE
;
949 Timer
->Header
.Hand
= 0;
950 Timer
->DueTime
.QuadPart
= 0;
955 /* Set the time as Absolute */
956 DueTime
= DifferenceTime
;
959 /* Get the Interrupt Time */
960 InterruptTime
.QuadPart
= KeQueryInterruptTime();
962 /* Recalculate due time */
963 Timer
->DueTime
.QuadPart
= InterruptTime
.QuadPart
- DueTime
.QuadPart
;
966 *Hand
= KiComputeTimerTableIndex(Timer
->DueTime
.QuadPart
);
967 Timer
->Header
.Hand
= (UCHAR
)*Hand
;
968 Timer
->Header
.Inserted
= TRUE
;
973 // Called from Unlink and Queue Insert Code.
974 // Also called by timer code when canceling an inserted timer.
975 // Removes a timer from it's tree.
979 KxRemoveTreeTimer(IN PKTIMER Timer
)
981 ULONG Hand
= Timer
->Header
.Hand
;
982 PKSPIN_LOCK_QUEUE LockQueue
;
983 PKTIMER_TABLE_ENTRY TimerEntry
;
985 /* Acquire timer lock */
986 LockQueue
= KiAcquireTimerLock(Hand
);
988 /* Set the timer as non-inserted */
989 Timer
->Header
.Inserted
= FALSE
;
991 /* Remove it from the timer list */
992 if (RemoveEntryList(&Timer
->TimerListEntry
))
994 /* Get the entry and check if it's empty */
995 TimerEntry
= &KiTimerTableListHead
[Hand
];
996 if (IsListEmpty(&TimerEntry
->Entry
))
998 /* Clear the time then */
999 TimerEntry
->Time
.HighPart
= 0xFFFFFFFF;
1003 /* Release the timer lock */
1004 KiReleaseTimerLock(LockQueue
);
1009 KxSetTimerForThreadWait(IN PKTIMER Timer
,
1010 IN LARGE_INTEGER Interval
,
1014 LARGE_INTEGER InterruptTime
, SystemTime
, TimeDifference
;
1016 /* Check the timer's interval to see if it's absolute */
1017 Timer
->Header
.Absolute
= FALSE
;
1018 if (Interval
.HighPart
>= 0)
1020 /* Get the system time and calculate the relative time */
1021 KeQuerySystemTime(&SystemTime
);
1022 TimeDifference
.QuadPart
= SystemTime
.QuadPart
- Interval
.QuadPart
;
1023 Timer
->Header
.Absolute
= TRUE
;
1025 /* Check if we've already expired */
1026 if (TimeDifference
.HighPart
>= 0)
1028 /* Reset everything */
1029 Timer
->DueTime
.QuadPart
= 0;
1031 Timer
->Header
.Hand
= 0;
1036 /* Update the interval */
1037 Interval
= TimeDifference
;
1041 /* Calculate the due time */
1042 InterruptTime
.QuadPart
= KeQueryInterruptTime();
1043 DueTime
= InterruptTime
.QuadPart
- Interval
.QuadPart
;
1044 Timer
->DueTime
.QuadPart
= DueTime
;
1046 /* Calculate the timer handle */
1047 *Hand
= KiComputeTimerTableIndex(DueTime
);
1048 Timer
->Header
.Hand
= (UCHAR
)*Hand
;
1051 #define KxDelayThreadWait() \
1053 /* Setup the Wait Block */ \
1054 Thread->WaitBlockList = TimerBlock; \
1056 /* Setup the timer */ \
1057 KxSetTimerForThreadWait(Timer, *Interval, &Hand); \
1059 /* Save the due time for the caller */ \
1060 DueTime.QuadPart = Timer->DueTime.QuadPart; \
1062 /* Link the timer to this Wait Block */ \
1063 TimerBlock->NextWaitBlock = TimerBlock; \
1064 Timer->Header.WaitListHead.Flink = &TimerBlock->WaitListEntry; \
1065 Timer->Header.WaitListHead.Blink = &TimerBlock->WaitListEntry; \
1067 /* Clear wait status */ \
1068 Thread->WaitStatus = STATUS_SUCCESS; \
1070 /* Setup wait fields */ \
1071 Thread->Alertable = Alertable; \
1072 Thread->WaitReason = DelayExecution; \
1073 Thread->WaitMode = WaitMode; \
1075 /* Check if we can swap the thread's stack */ \
1076 Thread->WaitListEntry.Flink = NULL; \
1077 Swappable = KiCheckThreadStackSwap(Thread, WaitMode); \
1079 /* Set the wait time */ \
1080 Thread->WaitTime = KeTickCount.LowPart;
1082 #define KxMultiThreadWait() \
1083 /* Link wait block array to the thread */ \
1084 Thread->WaitBlockList = WaitBlockArray; \
1086 /* Reset the index */ \
1089 /* Loop wait blocks */ \
1092 /* Fill out the wait block */ \
1093 WaitBlock = &WaitBlockArray[Index]; \
1094 WaitBlock->Object = Object[Index]; \
1095 WaitBlock->WaitKey = (USHORT)Index; \
1096 WaitBlock->WaitType = WaitType; \
1097 WaitBlock->Thread = Thread; \
1099 /* Link to next block */ \
1100 WaitBlock->NextWaitBlock = &WaitBlockArray[Index + 1]; \
1102 } while (Index < Count); \
1104 /* Link the last block */ \
1105 WaitBlock->NextWaitBlock = WaitBlockArray; \
1107 /* Set default wait status */ \
1108 Thread->WaitStatus = STATUS_WAIT_0; \
1110 /* Check if we have a timer */ \
1113 /* Link to the block */ \
1114 TimerBlock->NextWaitBlock = WaitBlockArray; \
1116 /* Setup the timer */ \
1117 KxSetTimerForThreadWait(Timer, *Timeout, &Hand); \
1119 /* Save the due time for the caller */ \
1120 DueTime.QuadPart = Timer->DueTime.QuadPart; \
1122 /* Initialize the list */ \
1123 InitializeListHead(&Timer->Header.WaitListHead); \
1126 /* Set wait settings */ \
1127 Thread->Alertable = Alertable; \
1128 Thread->WaitMode = WaitMode; \
1129 Thread->WaitReason = WaitReason; \
1131 /* Check if we can swap the thread's stack */ \
1132 Thread->WaitListEntry.Flink = NULL; \
1133 Swappable = KiCheckThreadStackSwap(Thread, WaitMode); \
1135 /* Set the wait time */ \
1136 Thread->WaitTime = KeTickCount.LowPart;
1138 #define KxSingleThreadWait() \
1139 /* Setup the Wait Block */ \
1140 Thread->WaitBlockList = WaitBlock; \
1141 WaitBlock->WaitKey = STATUS_SUCCESS; \
1142 WaitBlock->Object = Object; \
1143 WaitBlock->WaitType = WaitAny; \
1145 /* Clear wait status */ \
1146 Thread->WaitStatus = STATUS_SUCCESS; \
1148 /* Check if we have a timer */ \
1151 /* Setup the timer */ \
1152 KxSetTimerForThreadWait(Timer, *Timeout, &Hand); \
1154 /* Save the due time for the caller */ \
1155 DueTime.QuadPart = Timer->DueTime.QuadPart; \
1157 /* Pointer to timer block */ \
1158 WaitBlock->NextWaitBlock = TimerBlock; \
1159 TimerBlock->NextWaitBlock = WaitBlock; \
1161 /* Link the timer to this Wait Block */ \
1162 Timer->Header.WaitListHead.Flink = &TimerBlock->WaitListEntry; \
1163 Timer->Header.WaitListHead.Blink = &TimerBlock->WaitListEntry; \
1167 /* No timer block, just ourselves */ \
1168 WaitBlock->NextWaitBlock = WaitBlock; \
1171 /* Set wait settings */ \
1172 Thread->Alertable = Alertable; \
1173 Thread->WaitMode = WaitMode; \
1174 Thread->WaitReason = WaitReason; \
1176 /* Check if we can swap the thread's stack */ \
1177 Thread->WaitListEntry.Flink = NULL; \
1178 Swappable = KiCheckThreadStackSwap(Thread, WaitMode); \
1180 /* Set the wait time */ \
1181 Thread->WaitTime = KeTickCount.LowPart;
1183 #define KxQueueThreadWait() \
1184 /* Setup the Wait Block */ \
1185 Thread->WaitBlockList = WaitBlock; \
1186 WaitBlock->WaitKey = STATUS_SUCCESS; \
1187 WaitBlock->Object = Queue; \
1188 WaitBlock->WaitType = WaitAny; \
1189 WaitBlock->Thread = Thread; \
1191 /* Clear wait status */ \
1192 Thread->WaitStatus = STATUS_SUCCESS; \
1194 /* Check if we have a timer */ \
1197 /* Setup the timer */ \
1198 KxSetTimerForThreadWait(Timer, *Timeout, &Hand); \
1200 /* Save the due time for the caller */ \
1201 DueTime.QuadPart = Timer->DueTime.QuadPart; \
1203 /* Pointer to timer block */ \
1204 WaitBlock->NextWaitBlock = TimerBlock; \
1205 TimerBlock->NextWaitBlock = WaitBlock; \
1207 /* Link the timer to this Wait Block */ \
1208 Timer->Header.WaitListHead.Flink = &TimerBlock->WaitListEntry; \
1209 Timer->Header.WaitListHead.Blink = &TimerBlock->WaitListEntry; \
1213 /* No timer block, just ourselves */ \
1214 WaitBlock->NextWaitBlock = WaitBlock; \
1217 /* Set wait settings */ \
1218 Thread->Alertable = FALSE; \
1219 Thread->WaitMode = WaitMode; \
1220 Thread->WaitReason = WrQueue; \
1222 /* Check if we can swap the thread's stack */ \
1223 Thread->WaitListEntry.Flink = NULL; \
1224 Swappable = KiCheckThreadStackSwap(Thread, WaitMode); \
1226 /* Set the wait time */ \
1227 Thread->WaitTime = KeTickCount.LowPart;
1234 KxUnwaitThread(IN DISPATCHER_HEADER
*Object
,
1235 IN KPRIORITY Increment
)
1237 PLIST_ENTRY WaitEntry
, WaitList
;
1238 PKWAIT_BLOCK WaitBlock
;
1239 PKTHREAD WaitThread
;
1242 /* Loop the Wait Entries */
1243 WaitList
= &Object
->WaitListHead
;
1244 ASSERT(IsListEmpty(&Object
->WaitListHead
) == FALSE
);
1245 WaitEntry
= WaitList
->Flink
;
1248 /* Get the current wait block */
1249 WaitBlock
= CONTAINING_RECORD(WaitEntry
, KWAIT_BLOCK
, WaitListEntry
);
1251 /* Get the waiting thread */
1252 WaitThread
= WaitBlock
->Thread
;
1254 /* Check the current Wait Mode */
1255 if (WaitBlock
->WaitType
== WaitAny
)
1257 /* Use the actual wait key */
1258 WaitKey
= WaitBlock
->WaitKey
;
1262 /* Otherwise, use STATUS_KERNEL_APC */
1263 WaitKey
= STATUS_KERNEL_APC
;
1266 /* Unwait the thread */
1267 KiUnwaitThread(WaitThread
, WaitKey
, Increment
);
1270 WaitEntry
= WaitList
->Flink
;
1271 } while (WaitEntry
!= WaitList
);
1275 // Unwaits a Thread waiting on an event
1279 KxUnwaitThreadForEvent(IN PKEVENT Event
,
1280 IN KPRIORITY Increment
)
1282 PLIST_ENTRY WaitEntry
, WaitList
;
1283 PKWAIT_BLOCK WaitBlock
;
1284 PKTHREAD WaitThread
;
1286 /* Loop the Wait Entries */
1287 WaitList
= &Event
->Header
.WaitListHead
;
1288 ASSERT(IsListEmpty(&Event
->Header
.WaitListHead
) == FALSE
);
1289 WaitEntry
= WaitList
->Flink
;
1292 /* Get the current wait block */
1293 WaitBlock
= CONTAINING_RECORD(WaitEntry
, KWAIT_BLOCK
, WaitListEntry
);
1295 /* Get the waiting thread */
1296 WaitThread
= WaitBlock
->Thread
;
1298 /* Check the current Wait Mode */
1299 if (WaitBlock
->WaitType
== WaitAny
)
1302 Event
->Header
.SignalState
= 0;
1304 /* Un-signal the event and unwait the thread */
1305 KiUnwaitThread(WaitThread
, WaitBlock
->WaitKey
, Increment
);
1309 /* Unwait the thread with STATUS_KERNEL_APC */
1310 KiUnwaitThread(WaitThread
, STATUS_KERNEL_APC
, Increment
);
1313 WaitEntry
= WaitList
->Flink
;
1314 } while (WaitEntry
!= WaitList
);
1318 // This routine queues a thread that is ready on the PRCB's ready lists.
1319 // If this thread cannot currently run on this CPU, then the thread is
1320 // added to the deferred ready list instead.
1322 // This routine must be entered with the PRCB lock held and it will exit
1323 // with the PRCB lock released!
1327 KxQueueReadyThread(IN PKTHREAD Thread
,
1334 ASSERT(Prcb
== KeGetCurrentPrcb());
1335 ASSERT(Thread
->State
== Running
);
1336 ASSERT(Thread
->NextProcessor
== Prcb
->Number
);
1338 /* Check if this thread is allowed to run in this CPU */
1340 if ((Thread
->Affinity
) & (Prcb
->SetMember
))
1345 /* Set thread ready for execution */
1346 Thread
->State
= Ready
;
1348 /* Save current priority and if someone had pre-empted it */
1349 Priority
= Thread
->Priority
;
1350 Preempted
= Thread
->Preempted
;
1352 /* We're not pre-empting now, and set the wait time */
1353 Thread
->Preempted
= FALSE
;
1354 Thread
->WaitTime
= KeTickCount
.LowPart
;
1357 ASSERT((Priority
>= 0) && (Priority
<= HIGH_PRIORITY
));
1359 /* Insert this thread in the appropriate order */
1360 Preempted
? InsertHeadList(&Prcb
->DispatcherReadyListHead
[Priority
],
1361 &Thread
->WaitListEntry
) :
1362 InsertTailList(&Prcb
->DispatcherReadyListHead
[Priority
],
1363 &Thread
->WaitListEntry
);
1365 /* Update the ready summary */
1366 Prcb
->ReadySummary
|= PRIORITY_MASK(Priority
);
1369 ASSERT(Priority
== Thread
->Priority
);
1371 /* Release the PRCB lock */
1372 KiReleasePrcbLock(Prcb
);
1376 /* Otherwise, prepare this thread to be deferred */
1377 Thread
->State
= DeferredReady
;
1378 Thread
->DeferredProcessor
= Prcb
->Number
;
1380 /* Release the lock and defer scheduling */
1381 KiReleasePrcbLock(Prcb
);
1382 KiDeferredReadyThread(Thread
);
1387 // This routine scans for an appropriate ready thread to select at the
1388 // given priority and for the given CPU.
1392 KiSelectReadyThread(IN KPRIORITY Priority
,
1397 PLIST_ENTRY ListEntry
;
1398 PKTHREAD Thread
= NULL
;
1400 /* Save the current mask and get the priority set for the CPU */
1401 PrioritySet
= Prcb
->ReadySummary
>> Priority
;
1402 if (!PrioritySet
) goto Quickie
;
1404 /* Get the highest priority possible */
1405 BitScanReverse((PULONG
)&HighPriority
, PrioritySet
);
1406 ASSERT((PrioritySet
& PRIORITY_MASK(HighPriority
)) != 0);
1407 HighPriority
+= Priority
;
1409 /* Make sure the list isn't empty at the highest priority */
1410 ASSERT(IsListEmpty(&Prcb
->DispatcherReadyListHead
[HighPriority
]) == FALSE
);
1412 /* Get the first thread on the list */
1413 ListEntry
= Prcb
->DispatcherReadyListHead
[HighPriority
].Flink
;
1414 Thread
= CONTAINING_RECORD(ListEntry
, KTHREAD
, WaitListEntry
);
1416 /* Make sure this thread is here for a reason */
1417 ASSERT(HighPriority
== Thread
->Priority
);
1418 ASSERT(Thread
->Affinity
& AFFINITY_MASK(Prcb
->Number
));
1419 ASSERT(Thread
->NextProcessor
== Prcb
->Number
);
1421 /* Remove it from the list */
1422 if (RemoveEntryList(&Thread
->WaitListEntry
))
1424 /* The list is empty now, reset the ready summary */
1425 Prcb
->ReadySummary
^= PRIORITY_MASK(HighPriority
);
1428 /* Sanity check and return the thread */
1430 ASSERT((Thread
== NULL
) ||
1431 (Thread
->BasePriority
== 0) ||
1432 (Thread
->Priority
!= 0));
1437 // This routine computes the new priority for a thread. It is only valid for
1438 // threads with priorities in the dynamic priority range.
1442 KiComputeNewPriority(IN PKTHREAD Thread
,
1443 IN SCHAR Adjustment
)
1447 /* Priority sanity checks */
1448 ASSERT((Thread
->PriorityDecrement
>= 0) &&
1449 (Thread
->PriorityDecrement
<= Thread
->Priority
));
1450 ASSERT((Thread
->Priority
< LOW_REALTIME_PRIORITY
) ?
1451 TRUE
: (Thread
->PriorityDecrement
== 0));
1453 /* Get the current priority */
1454 Priority
= Thread
->Priority
;
1455 if (Priority
< LOW_REALTIME_PRIORITY
)
1457 /* Decrease priority by the priority decrement */
1458 Priority
-= (Thread
->PriorityDecrement
+ Adjustment
);
1460 /* Don't go out of bounds */
1461 if (Priority
< Thread
->BasePriority
) Priority
= Thread
->BasePriority
;
1463 /* Reset the priority decrement */
1464 Thread
->PriorityDecrement
= 0;
1468 ASSERT((Thread
->BasePriority
== 0) || (Priority
!= 0));
1470 /* Return the new priority */
1475 // Guarded Mutex Routines
1479 _KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex
)
1481 /* Setup the Initial Data */
1482 GuardedMutex
->Count
= GM_LOCK_BIT
;
1483 GuardedMutex
->Owner
= NULL
;
1484 GuardedMutex
->Contention
= 0;
1486 /* Initialize the Wait Gate */
1487 KeInitializeGate(&GuardedMutex
->Gate
);
1492 _KeAcquireGuardedMutexUnsafe(IN OUT PKGUARDED_MUTEX GuardedMutex
)
1494 PKTHREAD Thread
= KeGetCurrentThread();
1497 ASSERT((KeGetCurrentIrql() == APC_LEVEL
) ||
1498 (Thread
->SpecialApcDisable
< 0) ||
1499 (Thread
->Teb
== NULL
) ||
1500 (Thread
->Teb
>= (PTEB
)MM_SYSTEM_RANGE_START
));
1501 ASSERT(GuardedMutex
->Owner
!= Thread
);
1503 /* Remove the lock */
1504 if (!InterlockedBitTestAndReset(&GuardedMutex
->Count
, GM_LOCK_BIT_V
))
1506 /* The Guarded Mutex was already locked, enter contented case */
1507 KiAcquireGuardedMutex(GuardedMutex
);
1511 GuardedMutex
->Owner
= Thread
;
1516 _KeReleaseGuardedMutexUnsafe(IN OUT PKGUARDED_MUTEX GuardedMutex
)
1518 LONG OldValue
, NewValue
;
1521 ASSERT((KeGetCurrentIrql() == APC_LEVEL
) ||
1522 (KeGetCurrentThread()->SpecialApcDisable
< 0) ||
1523 (KeGetCurrentThread()->Teb
== NULL
) ||
1524 (KeGetCurrentThread()->Teb
>= (PTEB
)MM_SYSTEM_RANGE_START
));
1525 ASSERT(GuardedMutex
->Owner
== KeGetCurrentThread());
1527 /* Destroy the Owner */
1528 GuardedMutex
->Owner
= NULL
;
1530 /* Add the Lock Bit */
1531 OldValue
= InterlockedExchangeAdd(&GuardedMutex
->Count
, GM_LOCK_BIT
);
1532 ASSERT((OldValue
& GM_LOCK_BIT
) == 0);
1534 /* Check if it was already locked, but not woken */
1535 if ((OldValue
) && !(OldValue
& GM_LOCK_WAITER_WOKEN
))
1537 /* Update the Oldvalue to what it should be now */
1538 OldValue
+= GM_LOCK_BIT
;
1540 /* The mutex will be woken, minus one waiter */
1541 NewValue
= OldValue
+ GM_LOCK_WAITER_WOKEN
-
1544 /* Remove the Woken bit */
1545 if (InterlockedCompareExchange(&GuardedMutex
->Count
,
1547 OldValue
) == OldValue
)
1549 /* Signal the Gate */
1550 KeSignalGateBoostPriority(&GuardedMutex
->Gate
);
1557 _KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex
)
1559 PKTHREAD Thread
= KeGetCurrentThread();
1562 ASSERT(KeGetCurrentIrql() <= APC_LEVEL
);
1563 ASSERT(GuardedMutex
->Owner
!= Thread
);
1565 /* Disable Special APCs */
1566 KeEnterGuardedRegion();
1568 /* Remove the lock */
1569 if (!InterlockedBitTestAndReset(&GuardedMutex
->Count
, GM_LOCK_BIT_V
))
1571 /* The Guarded Mutex was already locked, enter contented case */
1572 KiAcquireGuardedMutex(GuardedMutex
);
1575 /* Set the Owner and Special APC Disable state */
1576 GuardedMutex
->Owner
= Thread
;
1577 GuardedMutex
->SpecialApcDisable
= Thread
->SpecialApcDisable
;
1582 _KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex
)
1584 LONG OldValue
, NewValue
;
1587 ASSERT(KeGetCurrentIrql() <= APC_LEVEL
);
1588 ASSERT(GuardedMutex
->Owner
== KeGetCurrentThread());
1589 ASSERT(KeGetCurrentThread()->SpecialApcDisable
==
1590 GuardedMutex
->SpecialApcDisable
);
1592 /* Destroy the Owner */
1593 GuardedMutex
->Owner
= NULL
;
1595 /* Add the Lock Bit */
1596 OldValue
= InterlockedExchangeAdd(&GuardedMutex
->Count
, GM_LOCK_BIT
);
1597 ASSERT((OldValue
& GM_LOCK_BIT
) == 0);
1599 /* Check if it was already locked, but not woken */
1600 if ((OldValue
) && !(OldValue
& GM_LOCK_WAITER_WOKEN
))
1602 /* Update the Oldvalue to what it should be now */
1603 OldValue
+= GM_LOCK_BIT
;
1605 /* The mutex will be woken, minus one waiter */
1606 NewValue
= OldValue
+ GM_LOCK_WAITER_WOKEN
-
1609 /* Remove the Woken bit */
1610 if (InterlockedCompareExchange(&GuardedMutex
->Count
,
1612 OldValue
) == OldValue
)
1614 /* Signal the Gate */
1615 KeSignalGateBoostPriority(&GuardedMutex
->Gate
);
1619 /* Re-enable APCs */
1620 KeLeaveGuardedRegion();
1625 _KeTryToAcquireGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex
)
1627 PKTHREAD Thread
= KeGetCurrentThread();
1630 KeEnterGuardedRegion();
1632 /* Remove the lock */
1633 if (!InterlockedBitTestAndReset(&GuardedMutex
->Count
, GM_LOCK_BIT_V
))
1635 /* Re-enable APCs */
1636 KeLeaveGuardedRegion();
1639 /* Return failure */
1643 /* Set the Owner and APC State */
1644 GuardedMutex
->Owner
= Thread
;
1645 GuardedMutex
->SpecialApcDisable
= Thread
->SpecialApcDisable
;
1652 KiAcquireNmiListLock(OUT PKIRQL OldIrql
)
1654 KeAcquireSpinLock(&KiNmiCallbackListLock
, OldIrql
);
1659 KiReleaseNmiListLock(IN KIRQL OldIrql
)
1661 KeReleaseSpinLock(&KiNmiCallbackListLock
, OldIrql
);