ReactOS  0.4.15-dev-5097-g328cc41
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 #ifdef _MINIHAL_
32 VOID
36 {
37 #if DBG
38  /* To be on par with HAL/NTOSKRNL */
40 #endif
41 }
42 #endif /* defined(_MINIHAL_) */
43 
44 /*
45  * @implemented
46  */
47 KIRQL
50 {
51  KIRQL OldIrql;
52 
53  /* Raise to sync */
55 
56  /* Acquire the lock and return */
57  KxAcquireSpinLock(SpinLock);
58  return OldIrql;
59 }
60 
61 /*
62  * @implemented
63  */
64 KIRQL
67 {
68  KIRQL OldIrql;
69 
70  /* Raise to dispatch and acquire the lock */
72  KxAcquireSpinLock(SpinLock);
73  return OldIrql;
74 }
75 
76 /*
77  * @implemented
78  */
79 VOID
82  KIRQL OldIrql)
83 {
84  /* Release the lock and lower IRQL back */
85  KxReleaseSpinLock(SpinLock);
87 }
88 
89 /*
90  * @implemented
91  */
92 KIRQL
95 {
96  KIRQL OldIrql;
97 
98  /* Raise to dispatch */
100 
101  /* Acquire the lock */
102  KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
103  return OldIrql;
104 }
105 
106 /*
107  * @implemented
108  */
109 KIRQL
110 FASTCALL
112 {
113  KIRQL OldIrql;
114 
115  /* Raise to synch */
117 
118  /* Acquire the lock */
119  KxAcquireSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
120  return OldIrql;
121 }
122 
123 /*
124  * @implemented
125  */
126 VOID
127 FASTCALL
130 {
131  /* Set up the lock */
134 
135  /* Raise to dispatch */
137 
138  /* Acquire the lock */
139  KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
140 }
141 
142 /*
143  * @implemented
144  */
145 VOID
146 FASTCALL
149 {
150  /* Set up the lock */
153 
154  /* Raise to synch */
156 
157  /* Acquire the lock */
158  KxAcquireSpinLock(LockHandle->LockQueue.Lock); // HACK
159 }
160 
161 /*
162  * @implemented
163  */
164 VOID
165 FASTCALL
167  IN KIRQL OldIrql)
168 {
169  /* Release the lock */
170  KxReleaseSpinLock(KeGetCurrentPrcb()->LockQueue[LockNumber].Lock); // HACK
171 
172  /* Lower IRQL back */
174 }
175 
176 /*
177  * @implemented
178  */
179 VOID
180 FASTCALL
182 {
183  /* Simply lower IRQL back */
184  KxReleaseSpinLock(LockHandle->LockQueue.Lock); // HACK
186 }
187 
188 #ifndef _MINIHAL_
189 /*
190  * @implemented
191  */
192 BOOLEAN
193 FASTCALL
195  IN PKIRQL OldIrql)
196 {
197  PKSPIN_LOCK Lock = KeGetCurrentPrcb()->LockQueue[LockNumber].Lock;
198 
199  /* KM tests demonstrate that this raises IRQL even if locking fails */
201  /* HACK */
203 }
204 
205 /*
206  * @implemented
207  */
208 LOGICAL
209 FASTCALL
212 {
213  PKSPIN_LOCK Lock = KeGetCurrentPrcb()->LockQueue[LockNumber].Lock;
214 
215  /* KM tests demonstrate that this raises IRQL even if locking fails */
217  /* HACK */
219 }
220 #endif /* !defined(_MINIHAL_) */
221 
222 #endif /* defined(_M_IX86) */
223 
224 VOID
225 NTAPI
227 {
229 
230  /* Get flags and disable interrupts */
231  Flags = __readeflags();
232  _disable();
233 
234  /* Acquire the lock */
235  KxAcquireSpinLock(&HalpSystemHardwareLock);
236 
237  /* We have the lock, save the flags now */
239 }
240 
241 VOID
242 NTAPI
244 {
246 
247  /* Get the flags */
249 
250  /* Release the lock */
251  KxReleaseSpinLock(&HalpSystemHardwareLock);
252 
253  /* Restore the flags */
255 }
256 
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:1080
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:1666
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:243
_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
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:226
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1661
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
VOID FASTCALL KefAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:243
KSPIN_LOCK_QUEUE LockQueue
Definition: ketypes.h:615
*LockHandle LockHandle _Out_ PKLOCK_QUEUE_HANDLE LockHandle
Definition: kefuncs.h:731
#define KeGetCurrentThread
Definition: hal.h:55
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