ReactOS  0.4.15-dev-3173-g40ee59d
spinlock.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS HAL
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: hal/halx86/generic/spinlock.c
5  * PURPOSE: Spinlock and Queued Spinlock Support
6  * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 /* This file is compiled twice. Once for UP and once for MP */
12 
13 #include <hal.h>
14 #define NDEBUG
15 #include <debug.h>
16 
17 #include <internal/spinlock.h>
18 
19 #undef KeAcquireSpinLock
20 #undef KeReleaseSpinLock
21 
22 /* GLOBALS *******************************************************************/
23 
26 
27 /* FUNCTIONS *****************************************************************/
28 
29 #ifdef _M_IX86
30 
31 /*
32  * @implemented
33  */
34 KIRQL
37 {
38  KIRQL OldIrql;
39 
40  /* Raise to sync */
42 
43  /* Acquire the lock and return */
44  KxAcquireSpinLock(SpinLock);
45  return OldIrql;
46 }
47 
48 /*
49  * @implemented
50  */
51 KIRQL
54 {
55  KIRQL OldIrql;
56 
57  /* Raise to dispatch and acquire the lock */
59  KxAcquireSpinLock(SpinLock);
60  return OldIrql;
61 }
62 
63 /*
64  * @implemented
65  */
66 VOID
69  KIRQL OldIrql)
70 {
71  /* Release the lock and lower IRQL back */
72  KxReleaseSpinLock(SpinLock);
74 }
75 
76 /*
77  * @implemented
78  */
79 KIRQL
82 {
83  KIRQL OldIrql;
84 
85  /* Raise to dispatch */
87 
88  /* Acquire the lock */
89  KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
90  return OldIrql;
91 }
92 
93 /*
94  * @implemented
95  */
96 KIRQL
99 {
100  KIRQL OldIrql;
101 
102  /* Raise to synch */
104 
105  /* Acquire the lock */
106  KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
107  return OldIrql;
108 }
109 
110 /*
111  * @implemented
112  */
113 VOID
114 FASTCALL
117 {
118  /* Set up the lock */
121 
122  /* Raise to dispatch */
124 
125  /* Acquire the lock */
126  KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
127 }
128 
129 /*
130  * @implemented
131  */
132 VOID
133 FASTCALL
136 {
137  /* Set up the lock */
140 
141  /* Raise to synch */
143 
144  /* Acquire the lock */
145  KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
146 }
147 
148 /*
149  * @implemented
150  */
151 VOID
152 FASTCALL
154  IN KIRQL OldIrql)
155 {
156  /* Release the lock */
157  KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
158 
159  /* Lower IRQL back */
161 }
162 
163 /*
164  * @implemented
165  */
166 VOID
167 FASTCALL
169 {
170  /* Simply lower IRQL back */
171  KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
173 }
174 
175 #ifndef _MINIHAL_
176 /*
177  * @implemented
178  */
179 BOOLEAN
180 FASTCALL
182  IN PKIRQL OldIrql)
183 {
184  PKSPIN_LOCK Lock = KeGetCurrentPrcb()->LockQueue[LockNumber].Lock;
185 
186  /* KM tests demonstrate that this raises IRQL even if locking fails */
188  /* HACK */
190 }
191 
192 /*
193  * @implemented
194  */
195 LOGICAL
196 FASTCALL
199 {
200  PKSPIN_LOCK Lock = KeGetCurrentPrcb()->LockQueue[LockNumber].Lock;
201 
202  /* KM tests demonstrate that this raises IRQL even if locking fails */
204  /* HACK */
206 }
207 #endif /* !defined(_MINIHAL_) */
208 #endif /* defined(_M_IX86) */
209 
210 VOID
211 NTAPI
213 {
215 
216  /* Get flags and disable interrupts */
217  Flags = __readeflags();
218  _disable();
219 
220  /* Acquire the lock */
221  KxAcquireSpinLock(&HalpSystemHardwareLock);
222 
223  /* We have the lock, save the flags now */
225 }
226 
227 VOID
228 NTAPI
230 {
232 
233  /* Get the flags */
235 
236  /* Release the lock */
237  KxReleaseSpinLock(&HalpSystemHardwareLock);
238 
239  /* Restore the flags */
241 }
242 
BOOLEAN FASTCALL KeTryToAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN PKIRQL OldIrql)
Definition: spinlock.c:177
VOID FASTCALL KeAcquireInStackQueuedSpinLockRaiseToSynch(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:142
#define IN
Definition: typedefs.h:39
PKSPIN_LOCK volatile Lock
Definition: ketypes.h:611
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
struct _KSPIN_LOCK_QUEUE *volatile Next
Definition: ketypes.h:610
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
VOID FASTCALL KeAcquireInStackQueuedSpinLock(IN PKSPIN_LOCK SpinLock, IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:130
#define FASTCALL
Definition: nt_native.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
UCHAR KIRQL
Definition: env_spec_w32.h:591
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1675
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VOID NTAPI HalpReleaseCmosSpinLock(VOID)
Definition: spinlock.c:229
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
LOGICAL FASTCALL KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, OUT PKIRQL OldIrql)
Definition: spinlock.c:192
unsigned char BOOLEAN
ULONG_PTR HalpSystemHardwareFlags
Definition: spinlock.c:24
KSPIN_LOCK HalpSystemHardwareLock
Definition: spinlock.c:25
KIRQL OldIrql
Definition: mm.h:1502
VOID FASTCALL KeReleaseInStackQueuedSpinLock(IN PKLOCK_QUEUE_HANDLE LockHandle)
Definition: spinlock.c:166
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
VOID NTAPI HalpAcquireCmosSpinLock(VOID)
Definition: spinlock.c:212
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1670
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
enum _KSPIN_LOCK_QUEUE_NUMBER KSPIN_LOCK_QUEUE_NUMBER
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
#define NULL
Definition: types.h:112
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
KIRQL FASTCALL KeAcquireSpinLockRaiseToSynch(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:62
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:124
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
void __cdecl _disable(void)
Definition: intrin_arm.h:365
KSPIN_LOCK_QUEUE LockQueue
Definition: ketypes.h:615
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:729
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
Definition: spinlock.c:309
KIRQL FASTCALL KeAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:119