2005-12-29 19:54:42 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
2006-09-13 01:41:17 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2000-03-04 13:44:59 +00:00
|
|
|
* FILE: ntoskrnl/ke/spinlock.c
|
2006-09-13 01:41:17 +00:00
|
|
|
* PURPOSE: Spinlock and Queued Spinlock Support
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
2000-03-03 00:48:50 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
2000-03-03 00:48:50 +00:00
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2005-01-01 11:28:46 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2000-03-03 00:48:50 +00:00
|
|
|
|
2006-01-05 13:12:48 +00:00
|
|
|
#define LQ_WAIT 1
|
|
|
|
#define LQ_OWN 2
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
2000-03-03 00:48:50 +00:00
|
|
|
|
2009-09-30 20:30:57 +00:00
|
|
|
#if 0
|
|
|
|
//
|
|
|
|
// FIXME: The queued spinlock routines are broken.
|
|
|
|
//
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2007-09-24 14:01:54 +00:00
|
|
|
KeAcquireQueuedSpinLockAtDpcLevel(IN PKSPIN_LOCK_QUEUE LockHandle)
|
2000-03-03 00:48:50 +00:00
|
|
|
{
|
2006-09-13 01:41:17 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
PKSPIN_LOCK_QUEUE Prev;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Set the new lock */
|
|
|
|
Prev = (PKSPIN_LOCK_QUEUE)
|
2007-11-06 14:34:32 +00:00
|
|
|
InterlockedExchange((PLONG)LockHandle->Next,
|
2006-09-13 01:41:17 +00:00
|
|
|
(LONG)LockHandle);
|
|
|
|
if (!Prev)
|
|
|
|
{
|
|
|
|
/* There was nothing there before. We now own it */
|
2007-11-06 14:34:32 +00:00
|
|
|
*LockHandle->Lock |= LQ_OWN;
|
2006-09-13 01:41:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Set the wait flag */
|
2007-11-06 14:34:32 +00:00
|
|
|
*LockHandle->Lock |= LQ_WAIT;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Link us */
|
|
|
|
Prev->Next = (PKSPIN_LOCK_QUEUE)LockHandle;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Loop and wait */
|
2007-11-06 14:34:32 +00:00
|
|
|
while (*LockHandle->Lock & LQ_WAIT)
|
|
|
|
YieldProcessor();
|
2006-09-13 01:41:17 +00:00
|
|
|
#endif
|
2000-03-03 00:48:50 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2007-09-24 14:01:54 +00:00
|
|
|
KeReleaseQueuedSpinLockFromDpcLevel(IN PKSPIN_LOCK_QUEUE LockHandle)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2006-09-13 01:41:17 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
KSPIN_LOCK LockVal;
|
|
|
|
PKSPIN_LOCK_QUEUE Waiter;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Remove own and wait flags */
|
2007-11-06 14:34:32 +00:00
|
|
|
*LockHandle->Lock &= ~(LQ_OWN | LQ_WAIT);
|
|
|
|
LockVal = *LockHandle->Lock;
|
2005-12-29 19:54:42 +00:00
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Check if we already own it */
|
|
|
|
if (LockVal == (KSPIN_LOCK)LockHandle)
|
|
|
|
{
|
|
|
|
/* Disown it */
|
|
|
|
LockVal = (KSPIN_LOCK)
|
2007-11-06 14:34:32 +00:00
|
|
|
InterlockedCompareExchangePointer(LockHandle->Lock,
|
2006-09-13 01:41:17 +00:00
|
|
|
NULL,
|
|
|
|
LockHandle);
|
|
|
|
}
|
|
|
|
if (LockVal == (KSPIN_LOCK)LockHandle) return;
|
|
|
|
|
|
|
|
/* Need to wait for it */
|
2007-11-06 14:34:32 +00:00
|
|
|
Waiter = LockHandle->Next;
|
2006-09-13 01:41:17 +00:00
|
|
|
while (!Waiter)
|
|
|
|
{
|
|
|
|
YieldProcessor();
|
2007-11-06 14:34:32 +00:00
|
|
|
Waiter = LockHandle->Next;
|
2006-09-13 01:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* It's gone */
|
|
|
|
*(ULONG_PTR*)&Waiter->Lock ^= (LQ_OWN | LQ_WAIT);
|
2007-11-06 14:34:32 +00:00
|
|
|
LockHandle->Next = NULL;
|
2006-09-13 01:41:17 +00:00
|
|
|
#endif
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
2009-09-30 20:30:57 +00:00
|
|
|
#else
|
|
|
|
//
|
|
|
|
// HACK: Hacked to work like normal spinlocks
|
|
|
|
//
|
|
|
|
|
2021-05-21 07:44:32 +00:00
|
|
|
_IRQL_requires_min_(DISPATCH_LEVEL)
|
|
|
|
_Acquires_nonreentrant_lock_(*LockHandle->Lock)
|
|
|
|
_Acquires_exclusive_lock_(*LockHandle->Lock)
|
2009-09-30 20:30:57 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2021-05-21 07:44:32 +00:00
|
|
|
KeAcquireQueuedSpinLockAtDpcLevel(_Inout_ PKSPIN_LOCK_QUEUE LockHandle)
|
2009-09-30 20:30:57 +00:00
|
|
|
{
|
2021-05-21 07:44:32 +00:00
|
|
|
#if defined(CONFIG_SMP) || DBG
|
2009-09-30 20:30:57 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)LockHandle->Lock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
2021-05-20 08:13:40 +00:00
|
|
|
#endif
|
2009-09-30 20:30:57 +00:00
|
|
|
|
|
|
|
/* Do the inlined function */
|
|
|
|
KxAcquireSpinLock(LockHandle->Lock);
|
|
|
|
}
|
|
|
|
|
2021-05-21 07:44:32 +00:00
|
|
|
_IRQL_requires_min_(DISPATCH_LEVEL)
|
|
|
|
_Releases_nonreentrant_lock_(*LockHandle->Lock)
|
|
|
|
_Releases_exclusive_lock_(*LockHandle->Lock)
|
2009-09-30 20:30:57 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2021-05-21 07:44:32 +00:00
|
|
|
KeReleaseQueuedSpinLockFromDpcLevel(_Inout_ PKSPIN_LOCK_QUEUE LockHandle)
|
2009-09-30 20:30:57 +00:00
|
|
|
{
|
2021-05-21 07:44:32 +00:00
|
|
|
#if defined(CONFIG_SMP) || DBG
|
2009-09-30 20:30:57 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)LockHandle->Lock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
2021-05-20 08:13:40 +00:00
|
|
|
#endif
|
2009-09-30 20:30:57 +00:00
|
|
|
|
|
|
|
/* Do the inlined function */
|
|
|
|
KxReleaseSpinLock(LockHandle->Lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
2009-07-15 10:22:05 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
KIRQL
|
|
|
|
NTAPI
|
|
|
|
KeAcquireInterruptSpinLock(IN PKINTERRUPT Interrupt)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
|
|
|
|
/* Raise IRQL */
|
|
|
|
KeRaiseIrql(Interrupt->SynchronizeIrql, &OldIrql);
|
|
|
|
|
|
|
|
/* Acquire spinlock on MP */
|
|
|
|
KeAcquireSpinLockAtDpcLevel(Interrupt->ActualLock);
|
|
|
|
return OldIrql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KeReleaseInterruptSpinLock(IN PKINTERRUPT Interrupt,
|
|
|
|
IN KIRQL OldIrql)
|
|
|
|
{
|
|
|
|
/* Release lock on MP */
|
|
|
|
KeReleaseSpinLockFromDpcLevel(Interrupt->ActualLock);
|
|
|
|
|
|
|
|
/* Lower IRQL */
|
|
|
|
KeLowerIrql(OldIrql);
|
|
|
|
}
|
|
|
|
|
2003-07-10 17:44:06 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
2000-03-03 00:48:50 +00:00
|
|
|
*/
|
2005-12-29 19:54:42 +00:00
|
|
|
VOID
|
2006-09-13 01:41:17 +00:00
|
|
|
NTAPI
|
2009-07-16 11:42:09 +00:00
|
|
|
_KeInitializeSpinLock(IN PKSPIN_LOCK SpinLock)
|
2000-03-03 00:48:50 +00:00
|
|
|
{
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Clear it */
|
2005-12-29 19:54:42 +00:00
|
|
|
*SpinLock = 0;
|
2000-03-03 00:48:50 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 17:44:06 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-09-13 01:41:17 +00:00
|
|
|
#undef KeAcquireSpinLockAtDpcLevel
|
2005-12-29 19:54:42 +00:00
|
|
|
VOID
|
2006-09-13 01:41:17 +00:00
|
|
|
NTAPI
|
|
|
|
KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
|
2000-03-03 00:48:50 +00:00
|
|
|
{
|
2009-09-30 20:30:57 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)SpinLock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Do the inlined function */
|
|
|
|
KxAcquireSpinLock(SpinLock);
|
2000-03-03 00:48:50 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 17:44:06 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
Plug & Play manager improvments + few other things
ntoskrnl/ntoskrnl.edf:
Added exports for IoGetDmaAdapter, IoIsWdmVersionAvailable,
KefAcquireSpinLockAtDpcLevel, KefReleaseSpinLockFromDpcLevel,
ExFreePoolWithTag.
ntoskrnl/io/driver.c:
Implementation of NtUnloadDriver.
ntoskrnl/io/device.c:
Added prepending "\\SystemRoot\" and displaying "PnP Loading xxx..." message
in IopInitializeDeviceNodeService.
ntoskrnl/io/pnpmgr.c:
Split into ntoskrnl/io/pnpmgr.c, ntoskrnl/io/deviface.c,
ntoskrnl/io/pnpnotify.c, ntoskrnl/io/pnpmgr/pnpdma.c,
ntoskrnl/io/pnpmgr.c, ntoskrnl/io/pnpmgr/pnproot.c,
ntoskrnl/io/remlock.c, ntoskrnl/io/pnpmgr/pnpreport.c.
Fixed registry handling in IopActionInterrogateDeviceStack and
IopActionConfigureChildServices.
Partial implementation of IoGetDeviceProperty.
ntoskrnl/io/pnpdma.c:
Implementation of IoGetDmaAdapter.
ntoskrnl/io/wdm.c:
New file. Contains implementation of IoIsWdmVersionAvailable.
ntoskrnl/ke/spinlock.c:
Added KeAcquireSpinLockAtDpcLevel and KefReleaseSpinLockFromDpcLevel.
ntoskrnl/mm/pool.c:
Partial implementation of ExFreePoolWithTag.
svn path=/trunk/; revision=6136
2003-09-25 15:54:43 +00:00
|
|
|
*/
|
2006-09-13 01:41:17 +00:00
|
|
|
#undef KeReleaseSpinLockFromDpcLevel
|
2004-06-23 22:32:24 +00:00
|
|
|
VOID
|
2006-09-13 01:41:17 +00:00
|
|
|
NTAPI
|
|
|
|
KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2009-09-30 20:30:57 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)SpinLock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the inlined function */
|
2006-09-13 01:41:17 +00:00
|
|
|
KxReleaseSpinLock(SpinLock);
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
|
|
|
|
Plug & Play manager improvments + few other things
ntoskrnl/ntoskrnl.edf:
Added exports for IoGetDmaAdapter, IoIsWdmVersionAvailable,
KefAcquireSpinLockAtDpcLevel, KefReleaseSpinLockFromDpcLevel,
ExFreePoolWithTag.
ntoskrnl/io/driver.c:
Implementation of NtUnloadDriver.
ntoskrnl/io/device.c:
Added prepending "\\SystemRoot\" and displaying "PnP Loading xxx..." message
in IopInitializeDeviceNodeService.
ntoskrnl/io/pnpmgr.c:
Split into ntoskrnl/io/pnpmgr.c, ntoskrnl/io/deviface.c,
ntoskrnl/io/pnpnotify.c, ntoskrnl/io/pnpmgr/pnpdma.c,
ntoskrnl/io/pnpmgr.c, ntoskrnl/io/pnpmgr/pnproot.c,
ntoskrnl/io/remlock.c, ntoskrnl/io/pnpmgr/pnpreport.c.
Fixed registry handling in IopActionInterrogateDeviceStack and
IopActionConfigureChildServices.
Partial implementation of IoGetDeviceProperty.
ntoskrnl/io/pnpdma.c:
Implementation of IoGetDmaAdapter.
ntoskrnl/io/wdm.c:
New file. Contains implementation of IoIsWdmVersionAvailable.
ntoskrnl/ke/spinlock.c:
Added KeAcquireSpinLockAtDpcLevel and KefReleaseSpinLockFromDpcLevel.
ntoskrnl/mm/pool.c:
Partial implementation of ExFreePoolWithTag.
svn path=/trunk/; revision=6136
2003-09-25 15:54:43 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
2000-03-03 00:48:50 +00:00
|
|
|
*/
|
2005-12-29 19:54:42 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-09-13 01:41:17 +00:00
|
|
|
KefAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
|
2000-03-03 00:48:50 +00:00
|
|
|
{
|
2009-09-30 20:30:57 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)SpinLock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Do the inlined function */
|
|
|
|
KxAcquireSpinLock(SpinLock);
|
2000-03-03 00:48:50 +00:00
|
|
|
}
|
|
|
|
|
Plug & Play manager improvments + few other things
ntoskrnl/ntoskrnl.edf:
Added exports for IoGetDmaAdapter, IoIsWdmVersionAvailable,
KefAcquireSpinLockAtDpcLevel, KefReleaseSpinLockFromDpcLevel,
ExFreePoolWithTag.
ntoskrnl/io/driver.c:
Implementation of NtUnloadDriver.
ntoskrnl/io/device.c:
Added prepending "\\SystemRoot\" and displaying "PnP Loading xxx..." message
in IopInitializeDeviceNodeService.
ntoskrnl/io/pnpmgr.c:
Split into ntoskrnl/io/pnpmgr.c, ntoskrnl/io/deviface.c,
ntoskrnl/io/pnpnotify.c, ntoskrnl/io/pnpmgr/pnpdma.c,
ntoskrnl/io/pnpmgr.c, ntoskrnl/io/pnpmgr/pnproot.c,
ntoskrnl/io/remlock.c, ntoskrnl/io/pnpmgr/pnpreport.c.
Fixed registry handling in IopActionInterrogateDeviceStack and
IopActionConfigureChildServices.
Partial implementation of IoGetDeviceProperty.
ntoskrnl/io/pnpdma.c:
Implementation of IoGetDmaAdapter.
ntoskrnl/io/wdm.c:
New file. Contains implementation of IoIsWdmVersionAvailable.
ntoskrnl/ke/spinlock.c:
Added KeAcquireSpinLockAtDpcLevel and KefReleaseSpinLockFromDpcLevel.
ntoskrnl/mm/pool.c:
Partial implementation of ExFreePoolWithTag.
svn path=/trunk/; revision=6136
2003-09-25 15:54:43 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-12-29 19:54:42 +00:00
|
|
|
VOID
|
2006-09-13 01:41:17 +00:00
|
|
|
FASTCALL
|
|
|
|
KefReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
|
Plug & Play manager improvments + few other things
ntoskrnl/ntoskrnl.edf:
Added exports for IoGetDmaAdapter, IoIsWdmVersionAvailable,
KefAcquireSpinLockAtDpcLevel, KefReleaseSpinLockFromDpcLevel,
ExFreePoolWithTag.
ntoskrnl/io/driver.c:
Implementation of NtUnloadDriver.
ntoskrnl/io/device.c:
Added prepending "\\SystemRoot\" and displaying "PnP Loading xxx..." message
in IopInitializeDeviceNodeService.
ntoskrnl/io/pnpmgr.c:
Split into ntoskrnl/io/pnpmgr.c, ntoskrnl/io/deviface.c,
ntoskrnl/io/pnpnotify.c, ntoskrnl/io/pnpmgr/pnpdma.c,
ntoskrnl/io/pnpmgr.c, ntoskrnl/io/pnpmgr/pnproot.c,
ntoskrnl/io/remlock.c, ntoskrnl/io/pnpmgr/pnpreport.c.
Fixed registry handling in IopActionInterrogateDeviceStack and
IopActionConfigureChildServices.
Partial implementation of IoGetDeviceProperty.
ntoskrnl/io/pnpdma.c:
Implementation of IoGetDmaAdapter.
ntoskrnl/io/wdm.c:
New file. Contains implementation of IoIsWdmVersionAvailable.
ntoskrnl/ke/spinlock.c:
Added KeAcquireSpinLockAtDpcLevel and KefReleaseSpinLockFromDpcLevel.
ntoskrnl/mm/pool.c:
Partial implementation of ExFreePoolWithTag.
svn path=/trunk/; revision=6136
2003-09-25 15:54:43 +00:00
|
|
|
{
|
2009-09-30 20:30:57 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)SpinLock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the inlined function */
|
2006-09-13 01:41:17 +00:00
|
|
|
KxReleaseSpinLock(SpinLock);
|
2004-01-18 22:41:53 +00:00
|
|
|
}
|
|
|
|
|
2004-06-23 22:32:24 +00:00
|
|
|
/*
|
2005-12-29 19:54:42 +00:00
|
|
|
* @implemented
|
2004-06-23 22:32:24 +00:00
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-09-13 01:41:17 +00:00
|
|
|
KiAcquireSpinLock(IN PKSPIN_LOCK SpinLock)
|
2004-06-23 22:32:24 +00:00
|
|
|
{
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Do the inlined function */
|
|
|
|
KxAcquireSpinLock(SpinLock);
|
2004-06-23 22:32:24 +00:00
|
|
|
}
|
2004-01-18 22:41:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-12-29 19:54:42 +00:00
|
|
|
VOID
|
2006-09-13 01:41:17 +00:00
|
|
|
FASTCALL
|
|
|
|
KiReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
|
2004-01-18 22:41:53 +00:00
|
|
|
{
|
2011-09-11 11:47:28 +00:00
|
|
|
/* Do the inlined function */
|
2006-09-13 01:41:17 +00:00
|
|
|
KxReleaseSpinLock(SpinLock);
|
2005-12-29 19:54:42 +00:00
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2007-02-18 16:50:37 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
FASTCALL
|
|
|
|
KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
|
|
|
|
{
|
2021-05-20 08:13:40 +00:00
|
|
|
#if DBG
|
2021-05-21 07:44:32 +00:00
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)SpinLock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2021-05-20 08:13:40 +00:00
|
|
|
/* Make sure that we don't own the lock already */
|
|
|
|
if (((KSPIN_LOCK)KeGetCurrentThread() | 1) == *SpinLock)
|
|
|
|
{
|
|
|
|
/* We do, bugcheck! */
|
|
|
|
KeBugCheckEx(SPIN_LOCK_ALREADY_OWNED, (ULONG_PTR)SpinLock, 0, 0, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 16:50:37 +00:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Check if it's already acquired */
|
|
|
|
if (!(*SpinLock))
|
|
|
|
{
|
|
|
|
/* Try to acquire it */
|
|
|
|
if (InterlockedBitTestAndSet((PLONG)SpinLock, 0))
|
|
|
|
{
|
|
|
|
/* Someone else acquired it */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It was already acquired */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-05-20 08:13:40 +00:00
|
|
|
#endif
|
2007-02-18 16:50:37 +00:00
|
|
|
|
2009-06-17 12:44:05 +00:00
|
|
|
#if DBG
|
2007-02-18 16:50:37 +00:00
|
|
|
/* On debug builds, we OR in the KTHREAD */
|
|
|
|
*SpinLock = (ULONG_PTR)KeGetCurrentThread() | 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* All is well, return TRUE */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-12-29 19:54:42 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-09-13 01:41:17 +00:00
|
|
|
KeAcquireInStackQueuedSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN PKLOCK_QUEUE_HANDLE LockHandle)
|
2005-12-29 19:54:42 +00:00
|
|
|
{
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Set it up properly */
|
|
|
|
LockHandle->LockQueue.Next = NULL;
|
|
|
|
LockHandle->LockQueue.Lock = SpinLock;
|
2021-05-20 08:13:40 +00:00
|
|
|
#ifdef CONFIG_SMP
|
2009-09-30 20:30:57 +00:00
|
|
|
#if 0
|
2007-11-06 14:34:32 +00:00
|
|
|
KeAcquireQueuedSpinLockAtDpcLevel(LockHandle->LockQueue.Next);
|
2009-09-30 20:30:57 +00:00
|
|
|
#else
|
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)LockHandle->LockQueue.Lock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
2021-05-20 08:13:40 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2009-09-30 20:30:57 +00:00
|
|
|
|
|
|
|
/* Acquire the lock */
|
|
|
|
KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
|
2004-01-18 22:41:53 +00:00
|
|
|
}
|
|
|
|
|
2006-09-13 01:41:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-01-05 13:12:48 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2006-09-13 01:41:17 +00:00
|
|
|
KeReleaseInStackQueuedSpinLockFromDpcLevel(IN PKLOCK_QUEUE_HANDLE LockHandle)
|
2006-01-05 13:12:48 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
2009-09-30 20:30:57 +00:00
|
|
|
#if 0
|
2006-09-13 01:41:17 +00:00
|
|
|
/* Call the internal function */
|
2007-11-06 14:34:32 +00:00
|
|
|
KeReleaseQueuedSpinLockFromDpcLevel(LockHandle->LockQueue.Next);
|
2009-09-30 20:30:57 +00:00
|
|
|
#else
|
|
|
|
/* Make sure we are at DPC or above! */
|
|
|
|
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
|
|
|
|
{
|
|
|
|
/* We aren't -- bugcheck */
|
|
|
|
KeBugCheckEx(IRQL_NOT_GREATER_OR_EQUAL,
|
|
|
|
(ULONG_PTR)LockHandle->LockQueue.Lock,
|
|
|
|
KeGetCurrentIrql(),
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
}
|
2021-05-20 08:13:40 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2009-09-30 20:30:57 +00:00
|
|
|
|
|
|
|
/* Release the lock */
|
|
|
|
KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
|
2006-01-05 13:12:48 +00:00
|
|
|
}
|
|
|
|
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
KIRQL
|
|
|
|
FASTCALL
|
|
|
|
KeAcquireSpinLockForDpc(IN PKSPIN_LOCK SpinLock)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KeReleaseSpinLockForDpc(IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN KIRQL OldIrql)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-05-26 15:05:15 +00:00
|
|
|
* @implemented
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
*/
|
2018-08-26 13:19:26 +00:00
|
|
|
VOID
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
FASTCALL
|
|
|
|
KeAcquireInStackQueuedSpinLockForDpc(IN PKSPIN_LOCK SpinLock,
|
|
|
|
IN PKLOCK_QUEUE_HANDLE LockHandle)
|
|
|
|
{
|
2021-05-26 15:05:15 +00:00
|
|
|
LockHandle->OldIrql = KeGetCurrentIrql();
|
|
|
|
if (LockHandle->OldIrql >= DISPATCH_LEVEL)
|
|
|
|
KeAcquireInStackQueuedSpinLockAtDpcLevel(SpinLock, LockHandle);
|
|
|
|
else
|
|
|
|
KeAcquireInStackQueuedSpinLock(SpinLock, LockHandle);
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-05-26 15:05:15 +00:00
|
|
|
* @implemented
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
KeReleaseInStackQueuedSpinLockForDpc(IN PKLOCK_QUEUE_HANDLE LockHandle)
|
|
|
|
{
|
2021-05-26 15:05:15 +00:00
|
|
|
if (LockHandle->OldIrql >= DISPATCH_LEVEL)
|
|
|
|
KeReleaseInStackQueuedSpinLockFromDpcLevel(LockHandle);
|
|
|
|
else
|
|
|
|
KeReleaseInStackQueuedSpinLock(LockHandle);
|
|
|
|
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-03-29 12:57:58 +00:00
|
|
|
* @implemented
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
FASTCALL
|
|
|
|
KeTestSpinLock(IN PKSPIN_LOCK SpinLock)
|
|
|
|
{
|
2009-03-29 12:57:58 +00:00
|
|
|
/* Test this spinlock */
|
|
|
|
if (*SpinLock)
|
|
|
|
{
|
|
|
|
/* Spinlock is busy, yield execution */
|
|
|
|
YieldProcessor();
|
|
|
|
|
|
|
|
/* Return busy flag */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Spinlock appears to be free */
|
|
|
|
return TRUE;
|
- Export KeI386MachineType and KeInitializeThreadedDpc
- Stubplement and export IoEnumerateRegisteredFiltersList, IoGetPagingIoPriority, KdRefreshDebuggerNotPresent, KeAcquireInStackQueuedSpinLockForDpc, KeReleaseInStackQueuedSpinLockForDpc, KeAcquireSpinLockForDpc, KeReleaseSpinLockForDpc, KeRegisterNmiCallback, KeDeregisterNmiCallback, KeInitializeCrashDumpHeader, KeTestSpinLock and MmAllocatePagesForMdlEx
- Add IO_PAGING_PRIORITY enumeration and PNMI_CALLBACK prototype to headers
svn path=/trunk/; revision=35103
2008-08-04 15:48:46 +00:00
|
|
|
}
|
2010-01-02 16:22:43 +00:00
|
|
|
|
|
|
|
#ifdef _M_IX86
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
Kii386SpinOnSpinLock(PKSPIN_LOCK SpinLock, ULONG Flags)
|
|
|
|
{
|
|
|
|
// FIXME: Handle flags
|
|
|
|
UNREFERENCED_PARAMETER(Flags);
|
|
|
|
|
|
|
|
/* Spin until it's unlocked */
|
|
|
|
while (*(volatile KSPIN_LOCK *)SpinLock & 1)
|
|
|
|
{
|
|
|
|
// FIXME: Check for timeout
|
|
|
|
|
|
|
|
/* Yield and keep looping */
|
|
|
|
YieldProcessor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|