ReactOS  0.4.14-dev-98-gb0d4763
ExResource.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite Executive Resource test
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 //#define NDEBUG
11 #include <debug.h>
12 
13 static
15 _Acquires_lock_(_Global_critical_region_)
16 PVOID
17 (NTAPI
18 *pExEnterCriticalRegionAndAcquireResourceShared)(
21 
22 static
24 _Acquires_lock_(_Global_critical_region_)
25 PVOID
26 (NTAPI
27 *pExEnterCriticalRegionAndAcquireResourceExclusive)(
30 
31 static
33 _Acquires_lock_(_Global_critical_region_)
34 PVOID
35 (NTAPI
36 *pExEnterCriticalRegionAndAcquireSharedWaitForExclusive)(
39 
40 static
42 _Releases_lock_(_Global_critical_region_)
43 VOID
44 (FASTCALL
45 *pExReleaseResourceAndLeaveCriticalRegion)(
48 
49 static
52 BOOLEAN
53 (NTAPI
54 *pKeAreAllApcsDisabled)(VOID);
55 
56 /* TODO: This is getting pretty long, make it somehow easier to read if possible */
57 
58 /* TODO: this is the Windows Server 2003 version! ROS should use this!
59  * This declaration can be removed once ROS headers are corrected */
60 typedef struct _ERESOURCE_2K3 {
61  LIST_ENTRY SystemResourcesList;
62  POWNER_ENTRY OwnerTable;
63  SHORT ActiveCount;
64  USHORT Flag;
65  volatile PKSEMAPHORE SharedWaiters;
66  volatile PKEVENT ExclusiveWaiters;
67  OWNER_ENTRY OwnerThreads[2];
68  ULONG ContentionCount;
69  USHORT NumberOfSharedWaiters;
70  USHORT NumberOfExclusiveWaiters;
71  _ANONYMOUS_UNION union {
72  PVOID Address;
73  ULONG_PTR CreatorBackTraceIndex;
77 
78 #define CheckResourceFields(Res, Reinit) do \
79 { \
80  ok_eq_pointer((Res)->SystemResourcesList.Flink->Blink, &(Res)->SystemResourcesList); \
81  ok_eq_pointer((Res)->SystemResourcesList.Blink->Flink, &(Res)->SystemResourcesList); \
82  if (!Reinit) ok_eq_pointer((Res)->OwnerTable, NULL); \
83  ok_eq_int((Res)->ActiveCount, 0); \
84  ok_eq_uint((Res)->Flag, 0); \
85  if (!Reinit) ok_eq_pointer((Res)->SharedWaiters, NULL); \
86  if (!Reinit) ok_eq_pointer((Res)->ExclusiveWaiters, NULL); \
87  ok_eq_ulongptr((Res)->OwnerThreads[0].OwnerThread, 0); \
88  ok_eq_ulong((Res)->OwnerThreads[0].TableSize, 0LU); \
89  ok_eq_ulongptr((Res)->OwnerThreads[1].OwnerThread, 0); \
90  ok_eq_ulong((Res)->OwnerThreads[1].TableSize, 0LU); \
91  ok_eq_ulong((Res)->ContentionCount, 0LU); \
92  ok_eq_uint((Res)->NumberOfSharedWaiters, 0); \
93  ok_eq_uint((Res)->NumberOfExclusiveWaiters, 0); \
94  ok_eq_pointer((Res)->Address, NULL); \
95  ok_eq_ulongptr((Res)->SpinLock, 0); \
96 } while (0)
97 
98 #define CheckResourceStatus(Res, Exclusive, Shared, ExclusiveWaiters, SharedWaiters) do \
99 { \
100  if (Exclusive) \
101  ok_bool_true(ExIsResourceAcquiredExclusiveLite(Res), "ExIsResourceAcquiredExclusiveLite returned"); \
102  else \
103  ok_bool_false(ExIsResourceAcquiredExclusiveLite(Res), "ExIsResourceAcquiredExclusiveLite returned"); \
104  ok_eq_ulong(ExIsResourceAcquiredSharedLite(Res), Shared); \
105  ok_eq_ulong(ExGetExclusiveWaiterCount(Res), ExclusiveWaiters); \
106  ok_eq_ulong(ExGetSharedWaiterCount(Res), SharedWaiters); \
107 } while (0)
108 
109 static
110 VOID
112  IN PERESOURCE Res)
113 {
114  LONG Count = 0;
115 
117  ok_bool_true(ExAcquireResourceSharedLite(Res, FALSE), "ExAcquireResourceSharedLite returned"); ++Count;
118  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
119 
120  ok_bool_true(ExAcquireResourceSharedLite(Res, FALSE), "ExAcquireResourceSharedLite returned"); ++Count;
121  ok_bool_true(ExAcquireResourceSharedLite(Res, TRUE), "ExAcquireResourceSharedLite returned"); ++Count;
122  ok_bool_true(ExAcquireSharedStarveExclusive(Res, FALSE), "ExAcquireSharedStarveExclusive returned"); ++Count;
123  ok_bool_true(ExAcquireSharedStarveExclusive(Res, TRUE), "ExAcquireSharedStarveExclusive returned"); ++Count;
124  ok_bool_true(ExAcquireSharedWaitForExclusive(Res, FALSE), "ExAcquireSharedWaitForExclusive returned"); ++Count;
125  ok_bool_true(ExAcquireSharedWaitForExclusive(Res, TRUE), "ExAcquireSharedWaitForExclusive returned"); ++Count;
126  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
127 
128  /* this one fails, TRUE would deadlock */
129  ok_bool_false(ExAcquireResourceExclusiveLite(Res, FALSE), "ExAcquireResourceExclusiveLite returned");
130  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
131 
132  /* this asserts */
133  if (!KmtIsCheckedBuild)
135  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
136 
137  while (Count--)
140 }
141 
142 static
143 VOID
145  IN PERESOURCE Res)
146 {
147  LONG Count = 0;
148 
150  ok_bool_true(ExAcquireResourceExclusiveLite(Res, FALSE), "ExAcquireResourceExclusiveLite returned"); ++Count;
151 
152  CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU);
153 
154  ok_bool_true(ExAcquireResourceExclusiveLite(Res, TRUE), "ExAcquireResourceExclusiveLite returned"); ++Count;
155  CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU);
156 
157  ok_bool_true(ExAcquireResourceSharedLite(Res, FALSE), "ExAcquireResourceSharedLite returned"); ++Count;
158  ok_bool_true(ExAcquireResourceSharedLite(Res, TRUE), "ExAcquireResourceSharedLite returned"); ++Count;
159  ok_bool_true(ExAcquireSharedStarveExclusive(Res, FALSE), "ExAcquireSharedStarveExclusive returned"); ++Count;
160  ok_bool_true(ExAcquireSharedStarveExclusive(Res, TRUE), "ExAcquireSharedStarveExclusive returned"); ++Count;
161  ok_bool_true(ExAcquireSharedWaitForExclusive(Res, FALSE), "ExAcquireSharedWaitForExclusive returned"); ++Count;
162  ok_bool_true(ExAcquireSharedWaitForExclusive(Res, TRUE), "ExAcquireSharedWaitForExclusive returned"); ++Count;
163  CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU);
164 
166  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
167 
168  while (Count--)
171 }
172 
173 static
174 VOID
176  IN PERESOURCE Res,
177  IN BOOLEAN AreApcsDisabled)
178 {
179  PVOID Ret;
180  LONG Count = 0;
181 
182  ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
183  if (pKeAreAllApcsDisabled)
184  ok_eq_uint(pKeAreAllApcsDisabled(), AreApcsDisabled);
185 
186  if (skip(pExEnterCriticalRegionAndAcquireResourceShared &&
187  pExEnterCriticalRegionAndAcquireSharedWaitForExclusive &&
188  pExEnterCriticalRegionAndAcquireResourceExclusive &&
189  pExReleaseResourceAndLeaveCriticalRegion, "No shortcuts\n"))
190  {
191  return;
192  }
193  /* ExEnterCriticalRegionAndAcquireResourceShared, ExEnterCriticalRegionAndAcquireSharedWaitForExclusive */
194  Count = 0;
195  Ret = pExEnterCriticalRegionAndAcquireResourceShared(Res); ++Count;
196  ok_eq_pointer(Ret, KeGetCurrentThread()->Win32Thread);
197  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
198  if (pKeAreAllApcsDisabled)
199  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
200  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
201 
202  Ret = pExEnterCriticalRegionAndAcquireResourceShared(Res); ++Count;
203  ok_eq_pointer(Ret, KeGetCurrentThread()->Win32Thread);
204  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
205  if (pKeAreAllApcsDisabled)
206  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
207  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
208 
209  pExEnterCriticalRegionAndAcquireSharedWaitForExclusive(Res); ++Count;
210  ok_eq_pointer(Ret, KeGetCurrentThread()->Win32Thread);
211  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
212  if (pKeAreAllApcsDisabled)
213  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
214  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
215 
216  while (Count-- > 1)
217  {
218  pExReleaseResourceAndLeaveCriticalRegion(Res);
219  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
220  if (pKeAreAllApcsDisabled)
221  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
222  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
223  }
224 
225  pExReleaseResourceAndLeaveCriticalRegion(Res);
226  ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
227  if (pKeAreAllApcsDisabled)
228  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
229  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
230 
231  /* ExEnterCriticalRegionAndAcquireResourceExclusive */
232  Count = 0;
233  ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
234  if (pKeAreAllApcsDisabled)
235  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
236  Ret = pExEnterCriticalRegionAndAcquireResourceExclusive(Res); ++Count;
237  ok_eq_pointer(Ret, KeGetCurrentThread()->Win32Thread);
238  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
239  if (pKeAreAllApcsDisabled)
240  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
241  CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU);
242 
243  Ret = pExEnterCriticalRegionAndAcquireResourceExclusive(Res); ++Count;
244  ok_eq_pointer(Ret, KeGetCurrentThread()->Win32Thread);
245  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
246  if (pKeAreAllApcsDisabled)
247  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
248  CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU);
249 
250  pExReleaseResourceAndLeaveCriticalRegion(Res); --Count;
251  ok_bool_true(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
252  if (pKeAreAllApcsDisabled)
253  ok_eq_bool(pKeAreAllApcsDisabled(), AreApcsDisabled);
254  CheckResourceStatus(Res, TRUE, Count, 0LU, 0LU);
255 
256  pExReleaseResourceAndLeaveCriticalRegion(Res); --Count;
257  ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
258  if (pKeAreAllApcsDisabled)
259  ok_eq_uint(pKeAreAllApcsDisabled(), AreApcsDisabled);
260  CheckResourceStatus(Res, FALSE, Count, 0LU, 0LU);
261 }
262 
264 
265 typedef struct
266 {
267  HANDLE Handle;
270  KEVENT InEvent;
271  KEVENT OutEvent;
274  BOOLEAN RetExpected;
277 
278 static
279 VOID
280 NTAPI
282  PVOID Context)
283 {
286  BOOLEAN Ret;
287 
289  Ret = ThreadData->AcquireResource(ThreadData->Res, ThreadData->Wait);
290  if (ThreadData->RetExpected)
291  ok_bool_true(Ret, "AcquireResource returned");
292  else
293  ok_bool_false(Ret, "AcquireResource returned");
294 
295  ok_bool_false(KeSetEvent(&ThreadData->OutEvent, 0, TRUE), "KeSetEvent returned");
298 
299  if (Ret)
302 }
303 
304 static
305 VOID
308  PERESOURCE Res,
309  PACQUIRE_FUNCTION AcquireFunction,
311 {
312  ThreadData->Res = Res;
315  ThreadData->AcquireResource = AcquireFunction;
316  ThreadData->StartRoutine = StartRoutine;
317 }
318 
319 static
320 VOID
323  PERESOURCE Res,
324  PACQUIRE_FUNCTION AcquireFunction)
325 {
326  InitThreadDataEx(ThreadData, Res, AcquireFunction, AcquireResourceThread);
327 }
328 
329 static
330 NTSTATUS
334  BOOLEAN Wait,
335  BOOLEAN RetExpected)
336 {
339 
340  ThreadData->Wait = Wait;
341  ThreadData->RetExpected = RetExpected;
347 
349 }
350 
351 static
352 VOID
355 {
357 
358  KeSetEvent(&ThreadData->InEvent, 0, TRUE);
361 
365  KeClearEvent(&ThreadData->InEvent);
366  KeClearEvent(&ThreadData->OutEvent);
367 }
368 
369 static
370 VOID
372  IN PERESOURCE Res)
373 {
375  THREAD_DATA ThreadDataShared;
376  THREAD_DATA ThreadDataShared2;
377  THREAD_DATA ThreadDataExclusive;
378  THREAD_DATA ThreadDataSharedStarve;
379  THREAD_DATA ThreadDataSharedWait;
381  Timeout.QuadPart = -10 * 1000 * 10; /* 10 ms */
382 
383  InitThreadData(&ThreadDataShared, Res, ExAcquireResourceSharedLite);
384  InitThreadData(&ThreadDataShared2, Res, ExAcquireResourceSharedLite);
385  InitThreadData(&ThreadDataExclusive, Res, ExAcquireResourceExclusiveLite);
386  InitThreadData(&ThreadDataSharedStarve, Res, ExAcquireSharedStarveExclusive);
387  InitThreadData(&ThreadDataSharedWait, Res, ExAcquireSharedWaitForExclusive);
388 
389  /* have a thread acquire the resource shared */
390  Status = StartThread(&ThreadDataShared, NULL, FALSE, TRUE);
392  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
393  ok_eq_int(Res->ActiveCount, 1);
394 
395  /* a second thread should be able to acquire the resource shared */
396  Status = StartThread(&ThreadDataShared2, NULL, FALSE, TRUE);
398  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
399  ok_eq_int(Res->ActiveCount, 2);
400  FinishThread(&ThreadDataShared2);
401  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
402  ok_eq_int(Res->ActiveCount, 1);
403 
404  /* now have a thread that tries to acquire the resource exclusive -- it should fail */
405  Status = StartThread(&ThreadDataExclusive, NULL, FALSE, FALSE);
407  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
408  ok_eq_int(Res->ActiveCount, 1);
409  FinishThread(&ThreadDataExclusive);
410  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
411  ok_eq_int(Res->ActiveCount, 1);
412 
413  /* as above, but this time it should block */
414  Status = StartThread(&ThreadDataExclusive, &Timeout, TRUE, TRUE);
416  CheckResourceStatus(Res, FALSE, 0LU, 1LU, 0LU);
417  ok_eq_int(Res->ActiveCount, 1);
418 
419  /* now try another shared one -- it should fail */
420  Status = StartThread(&ThreadDataShared2, NULL, FALSE, FALSE);
422  CheckResourceStatus(Res, FALSE, 0LU, 1LU, 0LU);
423  ok_eq_int(Res->ActiveCount, 1);
424  FinishThread(&ThreadDataShared2);
425 
426  /* same for ExAcquireSharedWaitForExclusive */
427  Status = StartThread(&ThreadDataSharedWait, NULL, FALSE, FALSE);
429  CheckResourceStatus(Res, FALSE, 0LU, 1LU, 0LU);
430  ok_eq_int(Res->ActiveCount, 1);
431  FinishThread(&ThreadDataSharedWait);
432 
433  /* ExAcquireSharedStarveExclusive must get access though! */
434  Status = StartThread(&ThreadDataSharedStarve, NULL, TRUE, TRUE);
436  CheckResourceStatus(Res, FALSE, 0LU, 1LU, 0LU);
437  ok_eq_int(Res->ActiveCount, 2);
438  FinishThread(&ThreadDataSharedStarve);
439  CheckResourceStatus(Res, FALSE, 0LU, 1LU, 0LU);
440  ok_eq_int(Res->ActiveCount, 1);
441 
442  /* block another shared one */
443  Status = StartThread(&ThreadDataShared2, &Timeout, TRUE, TRUE);
445  CheckResourceStatus(Res, FALSE, 0LU, 1LU, 1LU);
446  ok_eq_int(Res->ActiveCount, 1);
447 
448  /* finish the very first one */
449  FinishThread(&ThreadDataShared);
450 
451  /* now the blocked exclusive one should get the resource */
452  Status = KeWaitForSingleObject(&ThreadDataExclusive.OutEvent, Executive, KernelMode, FALSE, NULL);
454  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 1LU);
455  ok_eq_int(Res->ActiveCount, 1);
456  ok_eq_uint((Res->Flag & ResourceOwnedExclusive) != 0, 1);
457 
458  FinishThread(&ThreadDataExclusive);
459  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
460 
461  /* now the blocked shared one should resume */
464  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
465  ok_eq_int(Res->ActiveCount, 1);
466  FinishThread(&ThreadDataShared2);
467  CheckResourceStatus(Res, FALSE, 0LU, 0LU, 0LU);
468  ok_eq_int(Res->ActiveCount, 0);
469 }
470 
471 static
472 VOID
473 NTAPI
475  PVOID Context)
476 {
479  BOOLEAN Ret;
480 
482  Ret = ThreadData->AcquireResource(ThreadData->Res, ThreadData->Wait);
483  if (ThreadData->RetExpected)
484  ok_bool_true(Ret, "AcquireResource returned");
485  else
486  ok_bool_false(Ret, "AcquireResource returned");
488 
490 
491  ok_bool_false(KeSetEvent(&ThreadData->OutEvent, 0, TRUE), "KeSetEvent returned");
494 }
495 
496 static
497 VOID
499  IN PERESOURCE Res)
500 {
502  THREAD_DATA ThreadDataOwner;
503 
505 
507  ok_bool_true(ExAcquireResourceExclusiveLite(Res, FALSE), "ExAcquireResourceExclusiveLite returned");
510 
511  ok_bool_true(ExAcquireResourceExclusiveLite(Res, FALSE), "ExAcquireResourceExclusiveLite returned");
512  ExSetResourceOwnerPointer(Res, (PVOID)((ULONG_PTR)Res | 3));
514 
515  Status = StartThread(&ThreadDataOwner, NULL, FALSE, FALSE);
517 
518  FinishThread(&ThreadDataOwner);
519 }
520 
521 START_TEST(ExResource)
522 {
524  ERESOURCE Res;
525  KIRQL Irql;
526 
527  pExEnterCriticalRegionAndAcquireResourceShared = KmtGetSystemRoutineAddress(L"ExEnterCriticalRegionAndAcquireResourceShared");
528  pExEnterCriticalRegionAndAcquireSharedWaitForExclusive = KmtGetSystemRoutineAddress(L"ExEnterCriticalRegionAndAcquireSharedWaitForExclusive");
529  pExEnterCriticalRegionAndAcquireResourceExclusive = KmtGetSystemRoutineAddress(L"ExEnterCriticalRegionAndAcquireResourceExclusive");
530  pExReleaseResourceAndLeaveCriticalRegion = KmtGetSystemRoutineAddress(L"ExReleaseResourceAndLeaveCriticalRegion");
531  pKeAreAllApcsDisabled = KmtGetSystemRoutineAddress(L"KeAreAllApcsDisabled");
532 
533  if (skip(pKeAreAllApcsDisabled != NULL, "KeAreAllApcsDisabled unavailable\n"))
534  {
535  /* We can live without this function here */
536  }
537 
538  /* this must be true even with the different structure versions */
539  ASSERT(sizeof(ERESOURCE) == sizeof(ERESOURCE_2K3));
540 
541  /* functional tests & internals */
546 
549  KeLowerIrql(Irql);
550 
551  memset(&Res, 0x55, sizeof Res);
555 
556  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
557 
559  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
560 
562  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
563 
565  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
568  KeLowerIrql(Irql);
569  ok_bool_false(KeAreApcsDisabled(), "KeAreApcsDisabled returned");
570  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
571 
573 
574  /* ExReinitializeResourceLite cleans up after us */
578  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
579 
580  TestResourceWithOwner(&Res);
581  CheckResourceStatus(&Res, FALSE, 0LU, 0LU, 0LU);
582 
585 
586  /* parameter checks */
588  _SEH2_TRY {
592  } _SEH2_END;
594 
595  /* these bugcheck
596  ExDeleteResourceLite(NULL);
597  Status = ExDeleteResourceLite(&Res);*/
598 }
BOOLEAN NTAPI ExAcquireSharedWaitForExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1217
static NTSTATUS StartThread(PTHREAD_DATA ThreadData, PLARGE_INTEGER Timeout, BOOLEAN Wait, BOOLEAN RetExpected)
Definition: ExResource.c:331
static VOID TestResourceUndocumentedShortcuts(IN PERESOURCE Res, IN BOOLEAN AreApcsDisabled)
Definition: ExResource.c:175
Definition: extypes.h:210
#define IN
Definition: typedefs.h:38
#define GENERIC_ALL
Definition: nt_native.h:92
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
struct THREAD_DATA * PTHREAD_DATA
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment KeRaiseIrqlToDpcLevel
Definition: CrNtStubs.h:67
static VOID InitThreadDataEx(PTHREAD_DATA ThreadData, PERESOURCE Res, PACQUIRE_FUNCTION AcquireFunction, PKSTART_ROUTINE StartRoutine)
Definition: ExResource.c:306
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
NTSTATUS NTAPI ExReinitializeResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1756
#define CheckResourceStatus(Res, Exclusive, Shared, ExclusiveWaiters, SharedWaiters)
Definition: ExResource.c:98
PERESOURCE Res
Definition: ExResource.c:269
#define CheckResourceFields(Res, Reinit)
Definition: ExResource.c:78
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
#define ok_eq_int(value, expected)
Definition: kmt_test.h:238
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define _ANONYMOUS_UNION
Definition: ntbasedef.h:30
#define ok_eq_pointer(value, expected)
static VOID NTAPI AcquireResourceThread(PVOID Context)
Definition: ExResource.c:281
VOID NTAPI ExConvertExclusiveToSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1402
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
_Acquires_shared_lock_(Vcb->Resource)) FINISHED FatAcquireSharedVcb(IN PIRP_CONTEXT IrpContext
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_Requires_lock_not_held_(Vcb->fcb_lock) _Acquires_shared_lock_(Vcb -> fcb_lock) static __inline void acquire_fcb_lock_shared(device_extension *Vcb)
Definition: btrfs_drv.h:923
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_Acquires_exclusive_lock_(Vcb->Resource)) FINISHED FatAcquireExclusiveVcb_Real(IN PIRP_CONTEXT IrpContext
#define DUMMYUNIONNAME
Definition: ntbasedef.h:32
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FASTCALL
Definition: nt_native.h:50
_Out_ PKIRQL Irql
Definition: csq.h:179
_SEH2_TRY
Definition: create.c:4250
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID _In_opt_ PKSPIN_LOCK SpinLock
Definition: iofuncs.h:798
uint32_t ULONG_PTR
Definition: typedefs.h:63
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
UCHAR KIRQL
Definition: env_spec_w32.h:591
BOOLEAN KmtIsCheckedBuild
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
#define _IRQL_requires_min_(irql)
Definition: no_sal2.h:651
#define _Acquires_lock_(lock)
Definition: no_sal2.h:677
ERESOURCE * PERESOURCE
Definition: env_spec_w32.h:595
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:496
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:848
KSTART_ROUTINE * PKSTART_ROUTINE
Definition: ketypes.h:487
static VOID TestResourceSharedAccess(IN PERESOURCE Res)
Definition: ExResource.c:111
long LONG
Definition: pedump.c:60
short SHORT
Definition: pedump.c:59
#define _Releases_lock_(a)
Definition: btrfs_drv.h:186
static VOID TestResourceWithOwner(IN PERESOURCE Res)
Definition: ExResource.c:498
KEVENT OutEvent
Definition: ExFastMutex.c:152
static VOID TestResourceWithThreads(IN PERESOURCE Res)
Definition: ExResource.c:371
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
static VOID FinishThread(PTHREAD_DATA ThreadData)
Definition: ExResource.c:353
#define ok_eq_bool(value, expected)
Definition: kmt_test.h:258
void * PVOID
Definition: retypes.h:9
BOOLEAN Wait
Definition: ExResource.c:273
_In_ HANDLE Handle
Definition: extypes.h:390
HANDLE Handle
Definition: drwtsn32.h:25
static VOID NTAPI TestOwnerRes(PVOID Context)
Definition: ExResource.c:474
Definition: xml2sdb.h:79
#define ExReleaseResource(R)
Definition: exfuncs.h:257
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PVOID KmtGetSystemRoutineAddress(IN PCWSTR RoutineName)
#define _Inout_
Definition: no_sal2.h:244
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
static VOID InitThreadData(PTHREAD_DATA ThreadData, PERESOURCE Res, PACQUIRE_FUNCTION AcquireFunction)
Definition: ExResource.c:321
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN(NTAPI * PACQUIRE_FUNCTION)(PERESOURCE, BOOLEAN)
Definition: ExResource.c:263
POBJECT_TYPE PsThreadType
Definition: thread.c:20
static const WCHAR L[]
Definition: oid.c:1250
#define VOID
Definition: acefi.h:82
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
Definition: typedefs.h:117
VOID NTAPI ExSetResourceOwnerPointer(IN PERESOURCE Resource, IN PVOID OwnerPointer)
Definition: resource.c:2045
#define SYNCHRONIZE
Definition: nt_native.h:61
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI KeAreApcsDisabled(VOID)
Definition: apc.c:958
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
BOOLEAN NTAPI ExAcquireSharedStarveExclusive(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:1063
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
_SEH2_END
Definition: create.c:4424
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
static ULONG Timeout
Definition: ping.c:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned short USHORT
Definition: pedump.c:61
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
static VOID TestResourceExclusiveAccess(IN PERESOURCE Res)
Definition: ExResource.c:144
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define skip(...)
Definition: atltest.h:64
* PERESOURCE_2K3
Definition: ExResource.c:76
#define BOOLEAN
Definition: pedump.c:73
struct tagContext Context
Definition: acpixf.h:1024
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
VOID NTAPI ExReleaseResourceForThreadLite(IN PERESOURCE Resource, IN ERESOURCE_THREAD Thread)
Definition: resource.c:1844
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ok_eq_hex(value, expected)
PKSTART_ROUTINE StartRoutine
Definition: ExResource.c:275
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
ERESOURCE_2K3
Definition: ExResource.c:76
#define KeGetCurrentThread
Definition: hal.h:44
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define memset(x, y, z)
Definition: compat.h:39
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
PACQUIRE_FUNCTION AcquireResource
Definition: ExResource.c:272
#define APC_LEVEL
Definition: env_spec_w32.h:695
static _IRQL_requires_max_(APC_LEVEL)
Definition: ExResource.c:14
#define ResourceOwnedExclusive
Definition: dldetect.h:32
#define _Requires_lock_held_(a)
Definition: btrfs_drv.h:184
START_TEST(ExResource)
Definition: ExResource.c:521
IN BOOLEAN Wait
Definition: fatprocs.h:1529