ReactOS  0.4.15-dev-3728-ga92304f
KeSpinLock.c File Reference
#include <kmt_test.h>
#include <limits.h>
#include <debug.h>
Include dependency graph for KeSpinLock.c:

Go to the source code of this file.

Macros

#define WIN9X_COMPAT_SPINLOCK
 
#define DEFINE_ACQUIRE(LocalName, SetIsAcquired, DoCall)
 
#define DEFINE_RELEASE(LocalName, SetIsAcquired, DoCall)
 
#define CheckSpinLockLock(SpinLock, CheckData, Value)
 
#define CheckSpinLockQueue(SpinLock, CheckData, Value)
 
#define CheckSpinLockQueueHandle(SpinLock, CheckData, Value)
 
#define CheckSpinLock(SpinLock, CheckData, Value)
 

Functions

 __declspec (__declspec() void __stdcall KeAcquireSpinLockAtDpcLevel(unsigned long *) dllimport)
 
 DEFINE_ACQUIRE (AcquireExpNoRaise, DEFINE_RELEASE(FALSE,(KeAcquireSpinLockAtDpcLevel)(SpinLock))
 
BOOLEAN TryQueuedSynch (PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData)
 
BOOLEAN TryNoRaise (PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData)
 
static VOID TestSpinLock (PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData)
 
 START_TEST (KeSpinLock)
 

Macro Definition Documentation

◆ CheckSpinLock

#define CheckSpinLock (   SpinLock,
  CheckData,
  Value 
)
Value:
do \
{ \
BOOLEAN Ret = SpinLock && pKeTestSpinLock ? pKeTestSpinLock(SpinLock) : TRUE; \
KIRQL ExpectedIrql = (CheckData)->OriginalIrql; \
switch ((CheckData)->Check) \
{ \
case CheckLock: \
CheckSpinLockLock(SpinLock, CheckData, Value); \
break; \
case CheckQueue: \
CheckSpinLockQueue(SpinLock, CheckData, Value); \
break; \
case CheckQueueHandle: \
CheckSpinLockQueueHandle(SpinLock, CheckData, Value); \
break; \
} \
if ((CheckData)->IsAcquired) \
ExpectedIrql = (CheckData)->IrqlWhenAcquired; \
ok_irql(ExpectedIrql); \
ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned"); \
ok_bool_true(KmtAreInterruptsEnabled(), "Interrupts enabled:"); \
} while (0)
#define TRUE
Definition: types.h:120
if(dx==0 &&dy==0)
Definition: linetemp.h:174
int Check()
Definition: movefile.cpp:196
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
switch(r->id)
Definition: btrfs.c:2980
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
BOOLEAN KmtAreInterruptsEnabled(VOID)
BOOLEAN NTAPI KeAreApcsDisabled(VOID)
Definition: apc.c:958

Definition at line 220 of file KeSpinLock.c.

◆ CheckSpinLockLock

#define CheckSpinLockLock (   SpinLock,
  CheckData,
  Value 
)
Value:
do \
{ \
PKTHREAD Thread = KeGetCurrentThread(); \
{ \
ok_eq_bool(Ret, (Value) == 0); \
if (SpinLock) \
{ \
ok_eq_ulongptr(*(SpinLock), (Value) ? (ULONG_PTR)Thread | 1 : 0); \
ok_eq_ulongptr(*(SpinLock), (Value) ? 1 : 0); \
} \
} \
else \
{ \
ok_bool_true(Ret, "KeTestSpinLock returned"); \
if (SpinLock) \
ok_eq_ulongptr(*(SpinLock), 0); \
} \
ok_eq_uint((CheckData)->Irql, (CheckData)->OriginalIrql); \
} while (0)
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
_Out_ PKIRQL Irql
Definition: csq.h:179
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN KmtIsCheckedBuild
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
BOOLEAN KmtIsMultiProcessorBuild
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
#define VOID
Definition: acefi.h:82
#define KeGetCurrentThread
Definition: hal.h:55

Definition at line 166 of file KeSpinLock.c.

◆ CheckSpinLockQueue

#define CheckSpinLockQueue (   SpinLock,
  CheckData,
  Value 
)
Value:
do \
{ \
ok_eq_pointer((CheckData)->Queue->Next, NULL); \
ok_eq_pointer((CheckData)->Queue->Lock, NULL); \
ok_eq_uint((CheckData)->Irql, (CheckData)->OriginalIrql); \
} while (0)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2221
_Out_ PKIRQL Irql
Definition: csq.h:179
#define NULL
Definition: types.h:112

Definition at line 190 of file KeSpinLock.c.

◆ CheckSpinLockQueueHandle

#define CheckSpinLockQueueHandle (   SpinLock,
  CheckData,
  Value 
)
Value:
do \
{ \
{ \
ok_eq_bool(Ret, (Value) == 0); \
if (SpinLock) \
ok_eq_ulongptr(*(SpinLock), \
(Value) ? &(CheckData)->QueueHandle : 0); \
ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Next, NULL); \
ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Lock, \
(PVOID)((ULONG_PTR)SpinLock | ((Value) ? 2 : 0))); \
} \
else \
{ \
ok_bool_true(Ret, "KeTestSpinLock returned"); \
if (SpinLock) \
ok_eq_ulongptr(*(SpinLock), 0); \
ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Next, (CheckData)->UntouchedValue); \
ok_eq_pointer((CheckData)->QueueHandle.LockQueue.Lock, (CheckData)->UntouchedValue); \
} \
ok_eq_uint((CheckData)->QueueHandle.OldIrql, (CheckData)->OriginalIrql); \
} while (0)
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN KmtIsCheckedBuild
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
BOOLEAN KmtIsMultiProcessorBuild
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
#define NULL
Definition: types.h:112

Definition at line 197 of file KeSpinLock.c.

◆ DEFINE_ACQUIRE

#define DEFINE_ACQUIRE (   LocalName,
  SetIsAcquired,
  DoCall 
)
Value:
static VOID LocalName(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData) \
{ \
ASSERT(!CheckData->IsAcquired); \
DoCall; \
if (SetIsAcquired) CheckData->IsAcquired = TRUE; \
}
#define TRUE
Definition: types.h:120
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225

Definition at line 91 of file KeSpinLock.c.

◆ DEFINE_RELEASE

#define DEFINE_RELEASE (   LocalName,
  SetIsAcquired,
  DoCall 
)
Value:
static VOID LocalName(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData) \
{ \
DoCall; \
if (SetIsAcquired) CheckData->IsAcquired = FALSE; \
}
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225

Definition at line 99 of file KeSpinLock.c.

◆ WIN9X_COMPAT_SPINLOCK

#define WIN9X_COMPAT_SPINLOCK

Function Documentation

◆ __declspec()

__declspec ( __declspec() void __stdcall KeAcquireSpinLockAtDpcLevel(unsigned long *)  dllimport)

Definition at line 9 of file KeSpinLock.c.

64 {
65  enum
66  {
67  CheckQueueHandle,
68  CheckQueue,
69  CheckLock
70  } Check;
71  KIRQL IrqlWhenAcquired;
72  PACQUIRE_FUNCTION Acquire;
73  PRELEASE_FUNCTION Release;
74  PTRY_FUNCTION TryAcquire;
75  PACQUIRE_FUNCTION AcquireNoRaise;
76  PRELEASE_FUNCTION ReleaseNoLower;
77  PTRY_FUNCTION TryAcquireNoRaise;
78  KSPIN_LOCK_QUEUE_NUMBER QueueNumber;
79  BOOLEAN TryRetOnFailure;
80  KIRQL OriginalIrql;
81  BOOLEAN IsAcquired;
82  _ANONYMOUS_UNION union
83  {
84  KLOCK_QUEUE_HANDLE QueueHandle;
86  KIRQL Irql;
88  PVOID UntouchedValue;
89 };
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2221
#define _ANONYMOUS_UNION
Definition: ntbasedef.h:30
#define DUMMYUNIONNAME
Definition: ntbasedef.h:32
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
int Check()
Definition: movefile.cpp:196
unsigned char BOOLEAN
BOOLEAN(NTAPI * PACQUIRE_FUNCTION)(PERESOURCE, BOOLEAN)
Definition: ExResource.c:263
enum _KSPIN_LOCK_QUEUE_NUMBER KSPIN_LOCK_QUEUE_NUMBER
_In_ BOOLEAN Release
Definition: cdrom.h:920

◆ DEFINE_ACQUIRE()

DEFINE_ACQUIRE ( AcquireExpNoRaise  ,
DEFINE_RELEASE FALSE,
(KeAcquireSpinLockAtDpcLevel)(SpinLock  
)

Definition at line 127 of file KeSpinLock.c.

150  {
151  LOGICAL Ret = KeTryToAcquireQueuedSpinLock(CheckData->QueueNumber, &CheckData->Irql);
152  CheckData->IsAcquired = TRUE;
153  ASSERT(Ret == FALSE || Ret == TRUE);
154  return (BOOLEAN)Ret;
155 }
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LOGICAL FASTCALL KeTryToAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, OUT PKIRQL OldIrql)
Definition: spinlock.c:192
unsigned char BOOLEAN
#define ASSERT(a)
Definition: mode.c:44

◆ START_TEST()

START_TEST ( KeSpinLock  )

Definition at line 328 of file KeSpinLock.c.

329 {
330  KSPIN_LOCK SpinLock = (KSPIN_LOCK)0x5555555555555555LL;
331  PKSPIN_LOCK pSpinLock = &SpinLock;
333  KIRQL OriginalIrqls[] = { PASSIVE_LEVEL, APC_LEVEL, DISPATCH_LEVEL, HIGH_LEVEL };
334  CHECK_DATA TestData[] =
335  {
336  { CheckLock, DISPATCH_LEVEL, AcquireNormal, ReleaseNormal, NULL, AcquireNoRaise, ReleaseNoLower, TryNoRaise },
337  { CheckLock, DISPATCH_LEVEL, AcquireExp, ReleaseExp, NULL, AcquireExpNoRaise, ReleaseExpNoLower, NULL },
338  /* TODO: this one is just weird!
339  { CheckLock, DISPATCH_LEVEL, AcquireNormal, ReleaseNormal, NULL, AcquireForDpc, ReleaseForDpc, NULL },*/
340  { CheckLock, DISPATCH_LEVEL, AcquireNormal, ReleaseNormal, NULL, AcquireInt, ReleaseInt, NULL },
341  { CheckLock, SynchIrql, AcquireSynch, ReleaseNormal, NULL, NULL, NULL, NULL },
342  { CheckQueueHandle, DISPATCH_LEVEL, AcquireInStackQueued, ReleaseInStackQueued, NULL, AcquireInStackNoRaise, ReleaseInStackNoRaise, NULL },
343  { CheckQueueHandle, SynchIrql, AcquireInStackSynch, ReleaseInStackQueued, NULL, NULL, NULL, NULL },
344  { CheckQueueHandle, DISPATCH_LEVEL, AcquireInStackQueued, ReleaseInStackQueued, NULL, AcquireInStackForDpc, ReleaseInStackForDpc, NULL },
345  { CheckQueue, DISPATCH_LEVEL, AcquireQueued, ReleaseQueued, TryQueued, NULL, NULL, NULL, LockQueuePfnLock },
346  { CheckQueue, SynchIrql, AcquireQueuedSynch, ReleaseQueued, TryQueuedSynch, NULL, NULL, NULL, LockQueuePfnLock },
347  };
348  int i, iIrql;
349  PKPRCB Prcb;
350 
351  pKeTryToAcquireSpinLockAtDpcLevel = KmtGetSystemRoutineAddress(L"KeTryToAcquireSpinLockAtDpcLevel");
352  pKeAcquireInStackQueuedSpinLockForDpc = KmtGetSystemRoutineAddress(L"KeAcquireInStackQueuedSpinLockForDpc");
353  pKeReleaseInStackQueuedSpinLockForDpc = KmtGetSystemRoutineAddress(L"KeReleaseInStackQueuedSpinLockForDpc");
354  pKeTestSpinLock = KmtGetSystemRoutineAddress(L"KeTestSpinLock");
355 
356  Prcb = KeGetCurrentPrcb();
357 
358  /* KeInitializeSpinLock */
359  memset(&SpinLock, 0x55, sizeof SpinLock);
362 
363  /* KeTestSpinLock */
364  if (!skip(pKeTestSpinLock != NULL, "KeTestSpinLock unavailable\n"))
365  {
366  ok_bool_true(pKeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
367  SpinLock = 1;
368  ok_bool_false(pKeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
369  SpinLock = 2;
370  ok_bool_false(pKeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
371  SpinLock = (ULONG_PTR)-1;
372  ok_bool_false(pKeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
373  SpinLock = (ULONG_PTR)1 << (sizeof(ULONG_PTR) * CHAR_BIT - 1);
374  ok_bool_false(pKeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
375  SpinLock = 0;
376  ok_bool_true(pKeTestSpinLock(&SpinLock), "KeTestSpinLock returned");
377  }
378 
379  /* on UP none of the following functions actually looks at the spinlock! */
381  pSpinLock = NULL;
382 
383  for (i = 0; i < sizeof TestData / sizeof TestData[0]; ++i)
384  {
385  memset(&SpinLock, 0x55, sizeof SpinLock);
387  if (TestData[i].Check == CheckQueueHandle)
388  memset(&TestData[i].QueueHandle, 0x55, sizeof TestData[i].QueueHandle);
389  if (TestData[i].Check == CheckQueue)
390  {
391  TestData[i].Queue = &Prcb->LockQueue[TestData[i].QueueNumber];
392  TestData[i].UntouchedValue = NULL;
393  }
394  else
395  TestData[i].UntouchedValue = (PVOID)0x5555555555555555LL;
396 
397  for (iIrql = 0; iIrql < sizeof OriginalIrqls / sizeof OriginalIrqls[0]; ++iIrql)
398  {
399  if (KmtIsCheckedBuild && OriginalIrqls[iIrql] > DISPATCH_LEVEL)
400  continue;
401  KeRaiseIrql(OriginalIrqls[iIrql], &Irql);
402  TestData[i].OriginalIrql = OriginalIrqls[iIrql];
403  TestData[i].IsAcquired = FALSE;
404  TestSpinLock(pSpinLock, &TestData[i]);
405  KeLowerIrql(Irql);
406  }
407  }
408 
410 }
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1079
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
#define CHAR_BIT
Definition: urlcache.c:62
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
_Out_ PKIRQL Irql
Definition: csq.h:179
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
UCHAR KIRQL
Definition: env_spec_w32.h:591
BOOLEAN KmtIsCheckedBuild
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
int Check()
Definition: movefile.cpp:196
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
VOID KmtSetIrql(IN KIRQL NewIrql)
BOOLEAN KmtIsMultiProcessorBuild
void * PVOID
Definition: retypes.h:9
#define IPI_LEVEL
Definition: env_spec_w32.h:701
BOOLEAN TryNoRaise(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData)
Definition: KeSpinLock.c:161
PVOID KmtGetSystemRoutineAddress(IN PCWSTR RoutineName)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
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
#define skip(...)
Definition: atltest.h:64
#define ULONG_PTR
Definition: config.h:101
KSPIN_LOCK_QUEUE LockQueue[LockQueueMaximumLock]
Definition: ketypes.h:627
BOOLEAN TryQueuedSynch(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData)
Definition: KeSpinLock.c:156
static VOID TestSpinLock(PKSPIN_LOCK SpinLock, PCHECK_DATA CheckData)
Definition: KeSpinLock.c:247
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
#define memset(x, y, z)
Definition: compat.h:39
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ TestSpinLock()

static VOID TestSpinLock ( PKSPIN_LOCK  SpinLock,
PCHECK_DATA  CheckData 
)
static

Definition at line 247 of file KeSpinLock.c.

250 {
251  static INT Run = 0;
252  trace("Test SpinLock run %d\n", Run++);
253 
254  ok_irql(CheckData->OriginalIrql);
255 
256  if (SpinLock)
258  CheckData->Acquire(SpinLock, CheckData);
259  CheckSpinLock(SpinLock, CheckData, 1);
260  CheckData->Release(SpinLock, CheckData);
261  CheckSpinLock(SpinLock, CheckData, 0);
262 
263  if (CheckData->TryAcquire)
264  {
265  CheckSpinLock(SpinLock, CheckData, 0);
266  ok_bool_true(CheckData->TryAcquire(SpinLock, CheckData), "TryAcquire returned");
267  CheckSpinLock(SpinLock, CheckData, 1);
268  if (!KmtIsCheckedBuild)
269  {
270  /* SPINLOCK_ALREADY_OWNED on checked build */
271  ok_bool_true(CheckData->TryAcquire(SpinLock, CheckData), "TryAcquire returned");
272  /* even a failing acquire sets irql */
273  ok_eq_uint(CheckData->Irql, CheckData->IrqlWhenAcquired);
274  CheckData->Irql = CheckData->OriginalIrql;
275  CheckSpinLock(SpinLock, CheckData, 1);
276  }
277  CheckData->Release(SpinLock, CheckData);
278  CheckSpinLock(SpinLock, CheckData, 0);
279  }
280 
281  if (CheckData->AcquireNoRaise &&
282  (CheckData->OriginalIrql >= DISPATCH_LEVEL || !KmtIsCheckedBuild) &&
283  (CheckData->AcquireNoRaise != AcquireInStackForDpc ||
284  !skip(pKeAcquireInStackQueuedSpinLockForDpc &&
285  pKeReleaseInStackQueuedSpinLockForDpc, "No DPC spinlock functions\n")))
286  {
287  /* acquire/release without irql change */
288  CheckData->AcquireNoRaise(SpinLock, CheckData);
289  CheckSpinLock(SpinLock, CheckData, 1);
290  CheckData->ReleaseNoLower(SpinLock, CheckData);
291  CheckSpinLock(SpinLock, CheckData, 0);
292 
293  /* acquire without raise, but normal release */
294  CheckData->AcquireNoRaise(SpinLock, CheckData);
295  CheckSpinLock(SpinLock, CheckData, 1);
296  CheckData->Release(SpinLock, CheckData);
297  CheckSpinLock(SpinLock, CheckData, 0);
298 
299  /* acquire normally but release without lower */
300  CheckData->Acquire(SpinLock, CheckData);
301  CheckSpinLock(SpinLock, CheckData, 1);
302  CheckData->ReleaseNoLower(SpinLock, CheckData);
303  CheckSpinLock(SpinLock, CheckData, 0);
304  CheckData->IsAcquired = FALSE;
305  KmtSetIrql(CheckData->OriginalIrql);
306 
307  if (CheckData->TryAcquireNoRaise &&
308  !skip(pKeTryToAcquireSpinLockAtDpcLevel != NULL, "KeTryToAcquireSpinLockAtDpcLevel unavailable\n"))
309  {
310  CheckSpinLock(SpinLock, CheckData, 0);
311  ok_bool_true(CheckData->TryAcquireNoRaise(SpinLock, CheckData), "TryAcquireNoRaise returned");
312  CheckSpinLock(SpinLock, CheckData, 1);
313  if (!KmtIsCheckedBuild)
314  {
315  ok_bool_true(CheckData->TryAcquireNoRaise(SpinLock, CheckData), "TryAcquireNoRaise returned");
316  CheckSpinLock(SpinLock, CheckData, 1);
317  }
318  CheckData->ReleaseNoLower(SpinLock, CheckData);
319  CheckSpinLock(SpinLock, CheckData, 0);
320  }
321  }
322 
323  ok_irql(CheckData->OriginalIrql);
324  /* make sure we survive this in case of error */
325  KmtSetIrql(CheckData->OriginalIrql);
326 }
Definition: bidi.c:433
#define ok_eq_ulongptr(value, expected)
Definition: kmt_test.h:249
#define CheckSpinLock(SpinLock, CheckData, Value)
Definition: KeSpinLock.c:220
int32_t INT
Definition: typedefs.h:58
BOOLEAN KmtIsCheckedBuild
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
VOID KmtSetIrql(IN KIRQL NewIrql)
#define trace
Definition: atltest.h:70
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239

Referenced by START_TEST().

◆ TryNoRaise()

BOOLEAN TryNoRaise ( PKSPIN_LOCK  SpinLock,
PCHECK_DATA  CheckData 
)

Definition at line 161 of file KeSpinLock.c.

161  {
162  BOOLEAN Ret = pKeTryToAcquireSpinLockAtDpcLevel(SpinLock);
163  return Ret;
164 }
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:225
unsigned char BOOLEAN

Referenced by START_TEST().

◆ TryQueuedSynch()

BOOLEAN TryQueuedSynch ( PKSPIN_LOCK  SpinLock,
PCHECK_DATA  CheckData 
)

Definition at line 156 of file KeSpinLock.c.

156  {
157  BOOLEAN Ret = KeTryToAcquireQueuedSpinLockRaiseToSynch(CheckData->QueueNumber, &CheckData->Irql);
158  CheckData->IsAcquired = TRUE;
159  return Ret;
160 }
BOOLEAN FASTCALL KeTryToAcquireQueuedSpinLockRaiseToSynch(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN PKIRQL OldIrql)
Definition: spinlock.c:177
#define TRUE
Definition: types.h:120
unsigned char BOOLEAN

Referenced by START_TEST().