[XDK] Introduce ExAllocate*Zero and ExAllocate*Uninitialized functions
[reactos.git] / sdk / include / xdk / exfuncs.h
1 /******************************************************************************
2 * Executive Functions *
3 ******************************************************************************/
4
5 $if (_WDMDDK_)
6 #define ExInterlockedIncrementLong(Addend,Lock) Exfi386InterlockedIncrementLong(Addend)
7 #define ExInterlockedDecrementLong(Addend,Lock) Exfi386InterlockedDecrementLong(Addend)
8 #define ExInterlockedExchangeUlong(Target, Value, Lock) Exfi386InterlockedExchangeUlong(Target, Value)
9
10 #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
11 #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
12 #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
13 #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
14
15 #define ExInitializeSListHead InitializeSListHead
16
17 #if defined(_NTHAL_) && defined(_X86_)
18
19 NTKERNELAPI
20 VOID
21 FASTCALL
22 ExiAcquireFastMutex(
23 IN OUT PFAST_MUTEX FastMutex);
24
25 NTKERNELAPI
26 VOID
27 FASTCALL
28 ExiReleaseFastMutex(
29 IN OUT PFAST_MUTEX FastMutex);
30
31 NTKERNELAPI
32 BOOLEAN
33 FASTCALL
34 ExiTryToAcquireFastMutex(
35 IN OUT PFAST_MUTEX FastMutex);
36
37 #define ExAcquireFastMutex ExiAcquireFastMutex
38 #define ExReleaseFastMutex ExiReleaseFastMutex
39 #define ExTryToAcquireFastMutex ExiTryToAcquireFastMutex
40
41 #else
42
43 #if (NTDDI_VERSION >= NTDDI_WIN2K)
44
45 _IRQL_raises_(APC_LEVEL)
46 _IRQL_saves_global_(OldIrql, FastMutex)
47 NTKERNELAPI
48 VOID
49 FASTCALL
50 ExAcquireFastMutex(
51 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_)
52 PFAST_MUTEX FastMutex);
53
54 _IRQL_requires_(APC_LEVEL)
55 _IRQL_restores_global_(OldIrql, FastMutex)
56 NTKERNELAPI
57 VOID
58 FASTCALL
59 ExReleaseFastMutex(
60 _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_)
61 PFAST_MUTEX FastMutex);
62
63 _Must_inspect_result_
64 _Success_(return!=FALSE)
65 _IRQL_raises_(APC_LEVEL)
66 _IRQL_saves_global_(OldIrql, FastMutex)
67 NTKERNELAPI
68 BOOLEAN
69 FASTCALL
70 ExTryToAcquireFastMutex(
71 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_)
72 PFAST_MUTEX FastMutex);
73
74 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
75
76 #endif /* defined(_NTHAL_) && defined(_X86_) */
77
78 #if defined(_X86_)
79 #define ExInterlockedAddUlong ExfInterlockedAddUlong
80 #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
81 #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
82 #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
83 #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
84 #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
85 #endif /* defined(_X86_) */
86
87 #ifdef _X86_
88
89 #ifdef _WIN2K_COMPAT_SLIST_USAGE
90
91 NTKERNELAPI
92 PSLIST_ENTRY
93 FASTCALL
94 ExInterlockedPushEntrySList(
95 _Inout_ PSLIST_HEADER SListHead,
96 _Inout_ __drv_aliasesMem PSLIST_ENTRY SListEntry,
97 _Inout_opt_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
98
99 NTKERNELAPI
100 PSLIST_ENTRY
101 FASTCALL
102 ExInterlockedPopEntrySList(
103 _Inout_ PSLIST_HEADER SListHead,
104 _Inout_opt_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
105
106 #else /* !_WIN2K_COMPAT_SLIST_USAGE */
107
108 #define ExInterlockedPushEntrySList(SListHead, SListEntry, Lock) \
109 InterlockedPushEntrySList(SListHead, SListEntry)
110
111 #define ExInterlockedPopEntrySList(SListHead, Lock) \
112 InterlockedPopEntrySList(SListHead)
113
114 #endif /* _WIN2K_COMPAT_SLIST_USAGE */
115
116 NTKERNELAPI
117 PSLIST_ENTRY
118 FASTCALL
119 ExInterlockedFlushSList(
120 _Inout_ PSLIST_HEADER SListHead);
121
122 #ifdef NONAMELESSUNION
123 #define ExQueryDepthSList(SListHead) (SListHead)->s.Depth
124 #else
125 #define ExQueryDepthSList(SListHead) (SListHead)->Depth
126 #endif
127
128 #else /* !_X86_ */
129
130 NTKERNELAPI
131 PSLIST_ENTRY
132 ExpInterlockedPushEntrySList(
133 _Inout_ PSLIST_HEADER SListHead,
134 _Inout_ __drv_aliasesMem PSLIST_ENTRY SListEntry);
135
136 NTKERNELAPI
137 PSLIST_ENTRY
138 ExpInterlockedPopEntrySList(
139 _Inout_ PSLIST_HEADER SListHead);
140
141 NTKERNELAPI
142 PSLIST_ENTRY
143 ExpInterlockedFlushSList(
144 _Inout_ PSLIST_HEADER SListHead);
145
146 #if !defined(_NTSYSTEM_) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
147 NTKERNELAPI
148 USHORT
149 ExQueryDepthSList(_In_ PSLIST_HEADER SListHead);
150 #else
151 FORCEINLINE
152 USHORT
153 ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)
154 {
155 #ifdef _WIN64
156 return (USHORT)(SListHead->Alignment & 0xffff);
157 #else /* !_WIN64 */
158 return (USHORT)SListHead->Depth;
159 #endif /* _WIN64 */
160 }
161 #endif
162
163 #define ExInterlockedPushEntrySList(SListHead, SListEntry, Lock) \
164 ExpInterlockedPushEntrySList(SListHead, SListEntry)
165
166 #define ExInterlockedPopEntrySList(SListHead, Lock) \
167 ExpInterlockedPopEntrySList(SListHead)
168
169 #define ExInterlockedFlushSList(SListHead) \
170 ExpInterlockedFlushSList(SListHead)
171
172 #endif /* _X86_ */
173
174
175 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
176
177 _IRQL_requires_max_(APC_LEVEL)
178 NTKERNELAPI
179 PVOID
180 NTAPI
181 ExAllocateFromPagedLookasideList(
182 _Inout_ PPAGED_LOOKASIDE_LIST Lookaside);
183
184 _IRQL_requires_max_(APC_LEVEL)
185 NTKERNELAPI
186 VOID
187 NTAPI
188 ExFreeToPagedLookasideList(
189 _Inout_ PPAGED_LOOKASIDE_LIST Lookaside,
190 _In_ PVOID Entry);
191
192 #else /* !_WIN2K_COMPAT_SLIST_USAGE */
193
194 _IRQL_requires_max_(APC_LEVEL)
195 static __inline
196 PVOID
197 ExAllocateFromPagedLookasideList(
198 _Inout_ PPAGED_LOOKASIDE_LIST Lookaside)
199 {
200 PVOID Entry;
201
202 Lookaside->L.TotalAllocates++;
203 #ifdef NONAMELESSUNION
204 Entry = InterlockedPopEntrySList(&Lookaside->L.u.ListHead);
205 if (Entry == NULL) {
206 Lookaside->L.u2.AllocateMisses++;
207 Entry = (Lookaside->L.u4.Allocate)(Lookaside->L.Type,
208 Lookaside->L.Size,
209 Lookaside->L.Tag);
210 }
211 #else /* NONAMELESSUNION */
212 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
213 if (Entry == NULL) {
214 Lookaside->L.AllocateMisses++;
215 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
216 Lookaside->L.Size,
217 Lookaside->L.Tag);
218 }
219 #endif /* NONAMELESSUNION */
220 return Entry;
221 }
222
223 _IRQL_requires_max_(APC_LEVEL)
224 static __inline
225 VOID
226 ExFreeToPagedLookasideList(
227 _Inout_ PPAGED_LOOKASIDE_LIST Lookaside,
228 _In_ PVOID Entry)
229 {
230 Lookaside->L.TotalFrees++;
231 #ifdef NONAMELESSUNION
232 if (ExQueryDepthSList(&Lookaside->L.u.ListHead) >= Lookaside->L.Depth) {
233 Lookaside->L.u3.FreeMisses++;
234 (Lookaside->L.u5.Free)(Entry);
235 } else {
236 InterlockedPushEntrySList(&Lookaside->L.u.ListHead, (PSLIST_ENTRY)Entry);
237 }
238 #else /* NONAMELESSUNION */
239 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
240 Lookaside->L.FreeMisses++;
241 (Lookaside->L.Free)(Entry);
242 } else {
243 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
244 }
245 #endif /* NONAMELESSUNION */
246 }
247
248 #endif /* _WIN2K_COMPAT_SLIST_USAGE */
249
250
251 /* ERESOURCE_THREAD
252 * ExGetCurrentResourceThread(
253 * VOID);
254 */
255 #define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
256
257 #define ExReleaseResource(R) (ExReleaseResourceLite(R))
258
259 /* VOID
260 * ExInitializeWorkItem(
261 * IN PWORK_QUEUE_ITEM Item,
262 * IN PWORKER_THREAD_ROUTINE Routine,
263 * IN PVOID Context)
264 */
265 #define ExInitializeWorkItem(Item, Routine, Context) \
266 { \
267 (Item)->WorkerRoutine = Routine; \
268 (Item)->Parameter = Context; \
269 (Item)->List.Flink = NULL; \
270 }
271
272 FORCEINLINE
273 VOID
274 ExInitializeFastMutex(
275 _Out_ PFAST_MUTEX FastMutex)
276 {
277 FastMutex->Count = FM_LOCK_BIT;
278 FastMutex->Owner = NULL;
279 FastMutex->Contention = 0;
280 KeInitializeEvent(&FastMutex->Event, SynchronizationEvent, FALSE);
281 return;
282 }
283
284 $endif (_WDMDDK_)
285 $if (_NTDDK_)
286 static __inline PVOID
287 ExAllocateFromZone(
288 IN PZONE_HEADER Zone)
289 {
290 PVOID Result = (PVOID)Zone->FreeList.Next;
291 if (Zone->FreeList.Next)
292 Zone->FreeList.Next = Zone->FreeList.Next->Next;
293 return Result;
294 }
295
296 static __inline PVOID
297 ExFreeToZone(
298 IN PZONE_HEADER Zone,
299 IN PVOID Block)
300 {
301 ((PSINGLE_LIST_ENTRY) Block)->Next = Zone->FreeList.Next;
302 Zone->FreeList.Next = ((PSINGLE_LIST_ENTRY) Block);
303 return ((PSINGLE_LIST_ENTRY) Block)->Next;
304 }
305
306 /*
307 * PVOID
308 * ExInterlockedAllocateFromZone(
309 * IN PZONE_HEADER Zone,
310 * IN PKSPIN_LOCK Lock)
311 */
312 #define ExInterlockedAllocateFromZone(Zone, Lock) \
313 ((PVOID) ExInterlockedPopEntryList(&Zone->FreeList, Lock))
314
315 /* PVOID
316 * ExInterlockedFreeToZone(
317 * IN PZONE_HEADER Zone,
318 * IN PVOID Block,
319 * IN PKSPIN_LOCK Lock);
320 */
321 #define ExInterlockedFreeToZone(Zone, Block, Lock) \
322 ExInterlockedPushEntryList(&(Zone)->FreeList, (PSINGLE_LIST_ENTRY)(Block), Lock)
323
324 /*
325 * BOOLEAN
326 * ExIsFullZone(
327 * IN PZONE_HEADER Zone)
328 */
329 #define ExIsFullZone(Zone) \
330 ((Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY) NULL)
331
332 /* BOOLEAN
333 * ExIsObjectInFirstZoneSegment(
334 * IN PZONE_HEADER Zone,
335 * IN PVOID Object);
336 */
337 #define ExIsObjectInFirstZoneSegment(Zone,Object) \
338 ((BOOLEAN)( ((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
339 ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
340 (Zone)->TotalSegmentSize)) )
341
342 #define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
343 #define ExAcquireResourceShared ExAcquireResourceSharedLite
344 #define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
345 #define ExDeleteResource ExDeleteResourceLite
346 #define ExInitializeResource ExInitializeResourceLite
347 #define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
348 #define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
349 #define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
350 #define ExReleaseResourceForThread ExReleaseResourceForThreadLite
351
352 #ifndef _M_IX86
353 #define RESULT_ZERO 0
354 #define RESULT_NEGATIVE 1
355 #define RESULT_POSITIVE 2
356 #endif
357
358 typedef enum _INTERLOCKED_RESULT {
359 ResultNegative = RESULT_NEGATIVE,
360 ResultZero = RESULT_ZERO,
361 ResultPositive = RESULT_POSITIVE
362 } INTERLOCKED_RESULT;
363
364 #ifdef _X86_
365
366 NTKERNELAPI
367 INTERLOCKED_RESULT
368 FASTCALL
369 Exfi386InterlockedIncrementLong(
370 _Inout_ _Interlocked_operand_ LONG volatile *Addend);
371
372 NTKERNELAPI
373 INTERLOCKED_RESULT
374 FASTCALL
375 Exfi386InterlockedDecrementLong(
376 _Inout_ _Interlocked_operand_ PLONG Addend);
377
378 NTKERNELAPI
379 ULONG
380 FASTCALL
381 Exfi386InterlockedExchangeUlong(
382 _Inout_ _Interlocked_operand_ PULONG Target,
383 _In_ ULONG Value);
384
385 #endif
386
387 $endif (_NTDDK_)
388 $if (_NTIFS_)
389
390 #define ExDisableResourceBoost ExDisableResourceBoostLite
391
392 VOID
393 NTAPI
394 ExInitializePushLock(
395 _Out_ PEX_PUSH_LOCK PushLock);
396 $endif (_NTIFS_)
397
398 #if (NTDDI_VERSION >= NTDDI_WIN2K)
399 $if (_WDMDDK_)
400 _IRQL_requires_max_(APC_LEVEL)
401 _Requires_lock_held_(_Global_critical_region_)
402 NTKERNELAPI
403 VOID
404 FASTCALL
405 ExAcquireFastMutexUnsafe(
406 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_)
407 PFAST_MUTEX FastMutex);
408
409 _IRQL_requires_max_(APC_LEVEL)
410 _Requires_lock_held_(_Global_critical_region_)
411 NTKERNELAPI
412 VOID
413 FASTCALL
414 ExReleaseFastMutexUnsafe(
415 _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_)
416 PFAST_MUTEX FastMutex);
417
418 _Requires_lock_held_(_Global_critical_region_)
419 _Requires_lock_not_held_(*Resource)
420 _When_(Wait!=0, _Acquires_exclusive_lock_(*Resource))
421 _IRQL_requires_max_(APC_LEVEL)
422 _When_(Wait!=0, _Post_satisfies_(return == 1))
423 _When_(Wait==0, _Post_satisfies_(return == 0 || return == 1) _Must_inspect_result_)
424 NTKERNELAPI
425 BOOLEAN
426 NTAPI
427 ExAcquireResourceExclusiveLite(
428 _Inout_ PERESOURCE Resource,
429 _In_ _Literal_ BOOLEAN Wait);
430
431 _IRQL_requires_max_(APC_LEVEL)
432 _Requires_lock_held_(_Global_critical_region_)
433 _When_(Wait!=0, _Post_satisfies_(return == 1))
434 _When_(Wait==0, _Post_satisfies_(return == 0 || return == 1) _Must_inspect_result_)
435 NTKERNELAPI
436 BOOLEAN
437 NTAPI
438 ExAcquireResourceSharedLite(
439 _Inout_ _Requires_lock_not_held_(*_Curr_)
440 _When_(return!=0, _Acquires_shared_lock_(*_Curr_))
441 PERESOURCE Resource,
442 _In_ BOOLEAN Wait);
443
444 _IRQL_requires_max_(APC_LEVEL)
445 _Requires_lock_held_(_Global_critical_region_)
446 _When_(Wait!=0, _Post_satisfies_(return == 1))
447 _When_(Wait==0, _Post_satisfies_(return == 0 || return == 1) _Must_inspect_result_)
448 NTKERNELAPI
449 BOOLEAN
450 NTAPI
451 ExAcquireSharedStarveExclusive(
452 _Inout_ _Requires_lock_not_held_(*_Curr_)
453 _When_(return!=0, _Acquires_shared_lock_(*_Curr_))
454 PERESOURCE Resource,
455 _In_ BOOLEAN Wait);
456
457 _IRQL_requires_max_(APC_LEVEL)
458 _Requires_lock_held_(_Global_critical_region_)
459 _When_(Wait!=0, _Post_satisfies_(return == 1))
460 _When_(Wait==0, _Post_satisfies_(return == 0 || return == 1) _Must_inspect_result_)
461 NTKERNELAPI
462 BOOLEAN
463 NTAPI
464 ExAcquireSharedWaitForExclusive(
465 _Inout_ _Requires_lock_not_held_(*_Curr_)
466 _When_(return!=0, _Acquires_lock_(*_Curr_))
467 PERESOURCE Resource,
468 _In_ BOOLEAN Wait);
469
470 __drv_preferredFunction("ExAllocatePoolWithTag",
471 "No tag interferes with debugging.")
472 __drv_allocatesMem(Mem)
473 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
474 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
475 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
476 __drv_reportError("Must succeed pool allocations are forbidden. "
477 "Allocation failures cause a system crash"))
478 _When_((PoolType & (NonPagedPoolMustSucceed |
479 POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
480 _Post_maybenull_ _Must_inspect_result_)
481 _When_((PoolType & (NonPagedPoolMustSucceed |
482 POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
483 _Post_notnull_)
484 _Post_writable_byte_size_(NumberOfBytes)
485 NTKERNELAPI
486 PVOID
487 NTAPI
488 ExAllocatePool(
489 __drv_strictTypeMatch(__drv_typeExpr) _In_ POOL_TYPE PoolType,
490 _In_ SIZE_T NumberOfBytes);
491
492 __drv_preferredFunction("ExAllocatePoolWithQuotaTag",
493 "No tag interferes with debugging.")
494 __drv_allocatesMem(Mem)
495 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
496 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
497 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
498 __drv_reportError("Must succeed pool allocations are forbidden. "
499 "Allocation failures cause a system crash"))
500 _When_((PoolType & POOL_QUOTA_FAIL_INSTEAD_OF_RAISE) != 0,
501 _Post_maybenull_ _Must_inspect_result_)
502 _When_((PoolType & POOL_QUOTA_FAIL_INSTEAD_OF_RAISE) == 0, _Post_notnull_)
503 _Post_writable_byte_size_(NumberOfBytes)
504 NTKERNELAPI
505 PVOID
506 NTAPI
507 ExAllocatePoolWithQuota(
508 __drv_strictTypeMatch(__drv_typeExpr) _In_ POOL_TYPE PoolType,
509 _In_ SIZE_T NumberOfBytes);
510
511 __drv_allocatesMem(Mem)
512 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
513 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
514 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
515 __drv_reportError("Must succeed pool allocations are forbidden. "
516 "Allocation failures cause a system crash"))
517 _When_((PoolType & POOL_QUOTA_FAIL_INSTEAD_OF_RAISE) != 0,
518 _Post_maybenull_ _Must_inspect_result_)
519 _When_((PoolType & POOL_QUOTA_FAIL_INSTEAD_OF_RAISE) == 0, _Post_notnull_)
520 _Post_writable_byte_size_(NumberOfBytes)
521 NTKERNELAPI
522 PVOID
523 NTAPI
524 ExAllocatePoolWithQuotaTag(
525 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
526 _In_ SIZE_T NumberOfBytes,
527 _In_ ULONG Tag);
528
529 #ifndef POOL_TAGGING
530 #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
531 #endif
532
533 __drv_allocatesMem(Mem)
534 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
535 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
536 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
537 __drv_reportError("Must succeed pool allocations are forbidden. "
538 "Allocation failures cause a system crash"))
539 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
540 _Post_maybenull_ _Must_inspect_result_)
541 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
542 _Post_notnull_)
543 _Post_writable_byte_size_(NumberOfBytes)
544 _Function_class_(ALLOCATE_FUNCTION)
545 NTKERNELAPI
546 PVOID
547 NTAPI
548 ExAllocatePoolWithTag(
549 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
550 _In_ SIZE_T NumberOfBytes,
551 _In_ ULONG Tag);
552
553 #ifndef POOL_TAGGING
554 #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
555 #endif
556
557 __drv_allocatesMem(Mem)
558 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
559 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
560 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
561 __drv_reportError("Must succeed pool allocations are forbidden. "
562 "Allocation failures cause a system crash"))
563 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
564 _Post_maybenull_ _Must_inspect_result_)
565 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
566 _Post_notnull_)
567 _Post_writable_byte_size_(NumberOfBytes)
568 NTKERNELAPI
569 PVOID
570 NTAPI
571 ExAllocatePoolWithTagPriority(
572 _In_ __drv_strictTypeMatch(__drv_typeCond) POOL_TYPE PoolType,
573 _In_ SIZE_T NumberOfBytes,
574 _In_ ULONG Tag,
575 _In_ __drv_strictTypeMatch(__drv_typeExpr) EX_POOL_PRIORITY Priority);
576
577 FORCEINLINE
578 __drv_allocatesMem(Mem)
579 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
580 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
581 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
582 __drv_reportError("Must succeed pool allocations are forbidden. "
583 "Allocation failures cause a system crash"))
584 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
585 _Post_maybenull_ _Must_inspect_result_)
586 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
587 _Post_notnull_)
588 _Post_writable_byte_size_(NumberOfBytes)
589 PVOID
590 NTAPI
591 ExAllocatePoolZero(
592 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
593 _In_ SIZE_T NumberOfBytes,
594 _In_ ULONG Tag)
595 {
596 PVOID Allocation;
597
598 Allocation = ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
599
600 if (Allocation != NULL) {
601 RtlZeroMemory(Allocation, NumberOfBytes);
602 }
603
604 return Allocation;
605 }
606
607 FORCEINLINE
608 __drv_allocatesMem(Mem)
609 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
610 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
611 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
612 __drv_reportError("Must succeed pool allocations are forbidden. "
613 "Allocation failures cause a system crash"))
614 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
615 _Post_maybenull_ _Must_inspect_result_)
616 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
617 _Post_notnull_)
618 _Post_writable_byte_size_(NumberOfBytes)
619 PVOID
620 NTAPI
621 ExAllocatePoolUninitialized(
622 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
623 _In_ SIZE_T NumberOfBytes,
624 _In_ ULONG Tag)
625 {
626 return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
627 }
628
629 FORCEINLINE
630 __drv_allocatesMem(Mem)
631 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
632 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
633 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
634 __drv_reportError("Must succeed pool allocations are forbidden. "
635 "Allocation failures cause a system crash"))
636 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
637 _Post_maybenull_ _Must_inspect_result_)
638 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
639 _Post_notnull_)
640 _Post_writable_byte_size_(NumberOfBytes)
641 PVOID
642 NTAPI
643 ExAllocatePoolQuotaZero (
644 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
645 _In_ SIZE_T NumberOfBytes,
646 _In_ ULONG Tag)
647 {
648 PVOID Allocation;
649
650 Allocation = ExAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag);
651
652 if (Allocation != NULL) {
653 RtlZeroMemory(Allocation, NumberOfBytes);
654 }
655
656 return Allocation;
657 }
658
659 FORCEINLINE
660 __drv_allocatesMem(Mem)
661 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
662 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
663 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
664 __drv_reportError("Must succeed pool allocations are forbidden. "
665 "Allocation failures cause a system crash"))
666 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
667 _Post_maybenull_ _Must_inspect_result_)
668 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
669 _Post_notnull_)
670 _Post_writable_byte_size_(NumberOfBytes)
671 PVOID
672 NTAPI
673 ExAllocatePoolQuotaUninitialized(
674 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
675 _In_ SIZE_T NumberOfBytes,
676 _In_ ULONG Tag)
677 {
678 return ExAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag);
679 }
680
681 FORCEINLINE
682 __drv_allocatesMem(Mem)
683 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
684 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
685 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
686 __drv_reportError("Must succeed pool allocations are forbidden. "
687 "Allocation failures cause a system crash"))
688 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
689 _Post_maybenull_ _Must_inspect_result_)
690 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
691 _Post_notnull_)
692 _Post_writable_byte_size_(NumberOfBytes)
693 PVOID
694 NTAPI
695 ExAllocatePoolPriorityZero(
696 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
697 _In_ SIZE_T NumberOfBytes,
698 _In_ ULONG Tag,
699 _In_ EX_POOL_PRIORITY Priority)
700 {
701 PVOID Allocation;
702
703 Allocation = ExAllocatePoolWithTagPriority(PoolType, NumberOfBytes, Tag, Priority);
704
705 if (Allocation != NULL) {
706 RtlZeroMemory(Allocation, NumberOfBytes);
707 }
708
709 return Allocation;
710 }
711
712 FORCEINLINE
713 __drv_allocatesMem(Mem)
714 _When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
715 _When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
716 _When_((PoolType & NonPagedPoolMustSucceed) != 0,
717 __drv_reportError("Must succeed pool allocations are forbidden. "
718 "Allocation failures cause a system crash"))
719 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
720 _Post_maybenull_ _Must_inspect_result_)
721 _When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
722 _Post_notnull_)
723 _Post_writable_byte_size_(NumberOfBytes)
724 PVOID
725 NTAPI
726 ExAllocatePoolPriorityUninitialized(
727 _In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
728 _In_ SIZE_T NumberOfBytes,
729 _In_ ULONG Tag,
730 _In_ EX_POOL_PRIORITY Priority)
731 {
732 return ExAllocatePoolWithTagPriority(PoolType, NumberOfBytes, Tag, Priority);
733 }
734
735 _IRQL_requires_max_(DISPATCH_LEVEL)
736 NTKERNELAPI
737 VOID
738 NTAPI
739 ExConvertExclusiveToSharedLite(
740 _Inout_ _Requires_lock_held_(*_Curr_) PERESOURCE Resource);
741
742 _IRQL_requires_max_(APC_LEVEL)
743 NTKERNELAPI
744 NTSTATUS
745 NTAPI
746 ExCreateCallback(
747 _Outptr_ PCALLBACK_OBJECT *CallbackObject,
748 _In_ POBJECT_ATTRIBUTES ObjectAttributes,
749 _In_ BOOLEAN Create,
750 _In_ BOOLEAN AllowMultipleCallbacks);
751
752 NTKERNELAPI
753 VOID
754 NTAPI
755 ExDeleteNPagedLookasideList(
756 _Inout_ PNPAGED_LOOKASIDE_LIST Lookaside);
757
758 _IRQL_requires_max_(APC_LEVEL)
759 NTKERNELAPI
760 VOID
761 NTAPI
762 ExDeletePagedLookasideList(
763 _Inout_ PPAGED_LOOKASIDE_LIST Lookaside);
764
765 _IRQL_requires_max_(DISPATCH_LEVEL)
766 NTKERNELAPI
767 NTSTATUS
768 NTAPI
769 ExDeleteResourceLite(
770 _Inout_ PERESOURCE Resource);
771
772 _IRQL_requires_max_(DISPATCH_LEVEL)
773 _Function_class_(FREE_FUNCTION)
774 NTKERNELAPI
775 VOID
776 NTAPI
777 ExFreePool(
778 _Pre_notnull_ __drv_freesMem(Mem) PVOID P);
779
780 _IRQL_requires_max_(DISPATCH_LEVEL)
781 NTKERNELAPI
782 VOID
783 NTAPI
784 ExFreePoolWithTag(
785 _Pre_notnull_ __drv_freesMem(Mem) PVOID P,
786 _In_ ULONG Tag);
787
788 _IRQL_requires_max_(DISPATCH_LEVEL)
789 NTKERNELAPI
790 ULONG
791 NTAPI
792 ExGetExclusiveWaiterCount(
793 _In_ PERESOURCE Resource);
794
795 _IRQL_requires_max_(DISPATCH_LEVEL)
796 NTKERNELAPI
797 KPROCESSOR_MODE
798 NTAPI
799 ExGetPreviousMode(VOID);
800
801 _IRQL_requires_max_(DISPATCH_LEVEL)
802 NTKERNELAPI
803 ULONG
804 NTAPI
805 ExGetSharedWaiterCount(
806 _In_ PERESOURCE Resource);
807
808 _IRQL_requires_max_(DISPATCH_LEVEL)
809 NTKERNELAPI
810 VOID
811 NTAPI
812 ExInitializeNPagedLookasideList(
813 _Out_ PNPAGED_LOOKASIDE_LIST Lookaside,
814 _In_opt_ PALLOCATE_FUNCTION Allocate,
815 _In_opt_ PFREE_FUNCTION Free,
816 _In_ ULONG Flags,
817 _In_ SIZE_T Size,
818 _In_ ULONG Tag,
819 _In_ USHORT Depth);
820
821 _IRQL_requires_max_(APC_LEVEL)
822 NTKERNELAPI
823 VOID
824 NTAPI
825 ExInitializePagedLookasideList(
826 _Out_ PPAGED_LOOKASIDE_LIST Lookaside,
827 _In_opt_ PALLOCATE_FUNCTION Allocate,
828 _In_opt_ PFREE_FUNCTION Free,
829 _In_ ULONG Flags,
830 _In_ SIZE_T Size,
831 _In_ ULONG Tag,
832 _In_ USHORT Depth);
833
834 _IRQL_requires_max_(DISPATCH_LEVEL)
835 NTKERNELAPI
836 NTSTATUS
837 NTAPI
838 ExInitializeResourceLite(
839 _Out_ PERESOURCE Resource);
840
841 NTKERNELAPI
842 LARGE_INTEGER
843 NTAPI
844 ExInterlockedAddLargeInteger(
845 _Inout_ PLARGE_INTEGER Addend,
846 _In_ LARGE_INTEGER Increment,
847 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
848
849 #if !defined(_M_IX86)
850 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
851 (VOID)InterlockedAdd64(&(Addend)->QuadPart, Increment)
852 #else
853 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
854 (VOID)_InterlockedAddLargeStatistic((PLONGLONG)&(Addend)->QuadPart, Increment)
855 #endif
856
857 NTKERNELAPI
858 ULONG
859 FASTCALL
860 ExInterlockedAddUlong(
861 _Inout_ PULONG Addend,
862 _In_ ULONG Increment,
863 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
864
865 #if defined(_M_IX86)
866
867 NTKERNELAPI
868 LONGLONG
869 FASTCALL
870 ExfInterlockedCompareExchange64(
871 _Inout_ _Interlocked_operand_ LONGLONG volatile *Destination,
872 _In_ PLONGLONG Exchange,
873 _In_ PLONGLONG Comperand);
874
875 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
876 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
877
878 #else
879
880 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
881 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
882
883 #endif /* defined(_M_IX86) */
884
885 NTKERNELAPI
886 PLIST_ENTRY
887 FASTCALL
888 ExInterlockedInsertHeadList(
889 _Inout_ PLIST_ENTRY ListHead,
890 _Inout_ __drv_aliasesMem PLIST_ENTRY ListEntry,
891 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
892
893 NTKERNELAPI
894 PLIST_ENTRY
895 FASTCALL
896 ExInterlockedInsertTailList(
897 _Inout_ PLIST_ENTRY ListHead,
898 _Inout_ __drv_aliasesMem PLIST_ENTRY ListEntry,
899 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
900
901 NTKERNELAPI
902 PSINGLE_LIST_ENTRY
903 FASTCALL
904 ExInterlockedPopEntryList(
905 _Inout_ PSINGLE_LIST_ENTRY ListHead,
906 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
907
908 NTKERNELAPI
909 PSINGLE_LIST_ENTRY
910 FASTCALL
911 ExInterlockedPushEntryList(
912 _Inout_ PSINGLE_LIST_ENTRY ListHead,
913 _Inout_ __drv_aliasesMem PSINGLE_LIST_ENTRY ListEntry,
914 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
915
916 NTKERNELAPI
917 PLIST_ENTRY
918 FASTCALL
919 ExInterlockedRemoveHeadList(
920 _Inout_ PLIST_ENTRY ListHead,
921 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
922
923 _IRQL_requires_max_(PASSIVE_LEVEL)
924 NTKERNELAPI
925 BOOLEAN
926 NTAPI
927 ExIsProcessorFeaturePresent(
928 _In_ ULONG ProcessorFeature);
929
930 _IRQL_requires_max_(DISPATCH_LEVEL)
931 NTKERNELAPI
932 BOOLEAN
933 NTAPI
934 ExIsResourceAcquiredExclusiveLite(
935 _In_ PERESOURCE Resource);
936
937 _IRQL_requires_max_(DISPATCH_LEVEL)
938 NTKERNELAPI
939 ULONG
940 NTAPI
941 ExIsResourceAcquiredSharedLite(
942 _In_ PERESOURCE Resource);
943
944 #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
945
946 NTKERNELAPI
947 VOID
948 NTAPI
949 ExLocalTimeToSystemTime(
950 _In_ PLARGE_INTEGER LocalTime,
951 _Out_ PLARGE_INTEGER SystemTime);
952
953 _IRQL_requires_max_(DISPATCH_LEVEL)
954 NTKERNELAPI
955 VOID
956 NTAPI
957 ExNotifyCallback(
958 _In_ PCALLBACK_OBJECT CallbackObject,
959 _In_opt_ PVOID Argument1,
960 _In_opt_ PVOID Argument2);
961
962 _IRQL_requires_max_(DISPATCH_LEVEL)
963 NTKERNELAPI
964 VOID
965 NTAPI
966 ExQueueWorkItem(
967 _Inout_ __drv_aliasesMem PWORK_QUEUE_ITEM WorkItem,
968 __drv_strictTypeMatch(__drv_typeExpr) _In_ WORK_QUEUE_TYPE QueueType);
969
970 _IRQL_requires_max_(APC_LEVEL)
971 NTKERNELAPI
972 DECLSPEC_NORETURN
973 VOID
974 NTAPI
975 ExRaiseStatus(
976 _In_ NTSTATUS Status);
977
978 _IRQL_requires_max_(APC_LEVEL)
979 NTKERNELAPI
980 PVOID
981 NTAPI
982 ExRegisterCallback(
983 _Inout_ PCALLBACK_OBJECT CallbackObject,
984 _In_ PCALLBACK_FUNCTION CallbackFunction,
985 _In_opt_ PVOID CallbackContext);
986
987 _IRQL_requires_max_(DISPATCH_LEVEL)
988 NTKERNELAPI
989 NTSTATUS
990 NTAPI
991 ExReinitializeResourceLite(
992 _Inout_ PERESOURCE Resource);
993
994 _IRQL_requires_max_(DISPATCH_LEVEL)
995 _Requires_lock_held_(_Global_critical_region_)
996 NTKERNELAPI
997 VOID
998 NTAPI
999 ExReleaseResourceForThreadLite(
1000 _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_)
1001 PERESOURCE Resource,
1002 _In_ ERESOURCE_THREAD ResourceThreadId);
1003
1004 _Requires_lock_held_(_Global_critical_region_)
1005 _Requires_lock_held_(*Resource)
1006 _Releases_lock_(*Resource)
1007 _IRQL_requires_max_(DISPATCH_LEVEL)
1008 NTKERNELAPI
1009 VOID
1010 FASTCALL
1011 ExReleaseResourceLite(
1012 _Inout_ PERESOURCE Resource);
1013
1014 _IRQL_requires_max_(DISPATCH_LEVEL)
1015 NTKERNELAPI
1016 VOID
1017 NTAPI
1018 ExSetResourceOwnerPointer(
1019 _Inout_ PERESOURCE Resource,
1020 _In_ PVOID OwnerPointer);
1021
1022 _IRQL_requires_max_(APC_LEVEL)
1023 NTKERNELAPI
1024 ULONG
1025 NTAPI
1026 ExSetTimerResolution(
1027 _In_ ULONG DesiredTime,
1028 _In_ BOOLEAN SetResolution);
1029
1030 NTKERNELAPI
1031 VOID
1032 NTAPI
1033 ExSystemTimeToLocalTime(
1034 _In_ PLARGE_INTEGER SystemTime,
1035 _Out_ PLARGE_INTEGER LocalTime);
1036
1037 _IRQL_requires_max_(APC_LEVEL)
1038 NTKERNELAPI
1039 VOID
1040 NTAPI
1041 ExUnregisterCallback(
1042 _Inout_ PVOID CbRegistration);
1043
1044 $endif (_WDMDDK_)
1045 $if (_NTDDK_)
1046 NTKERNELAPI
1047 NTSTATUS
1048 NTAPI
1049 ExExtendZone(
1050 _Inout_ PZONE_HEADER Zone,
1051 _Inout_ PVOID Segment,
1052 _In_ ULONG SegmentSize);
1053
1054 NTKERNELAPI
1055 NTSTATUS
1056 NTAPI
1057 ExInitializeZone(
1058 _Out_ PZONE_HEADER Zone,
1059 _In_ ULONG BlockSize,
1060 _Inout_ PVOID InitialSegment,
1061 _In_ ULONG InitialSegmentSize);
1062
1063 _IRQL_requires_max_(DISPATCH_LEVEL)
1064 NTKERNELAPI
1065 NTSTATUS
1066 NTAPI
1067 ExInterlockedExtendZone(
1068 _Inout_ PZONE_HEADER Zone,
1069 _Inout_ PVOID Segment,
1070 _In_ ULONG SegmentSize,
1071 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
1072
1073 _IRQL_requires_max_(PASSIVE_LEVEL)
1074 NTKERNELAPI
1075 NTSTATUS
1076 NTAPI
1077 ExUuidCreate(
1078 _Out_ UUID *Uuid);
1079
1080 _IRQL_requires_max_(PASSIVE_LEVEL)
1081 NTKERNELAPI
1082 DECLSPEC_NORETURN
1083 VOID
1084 NTAPI
1085 ExRaiseAccessViolation(VOID);
1086
1087 _IRQL_requires_max_(PASSIVE_LEVEL)
1088 NTKERNELAPI
1089 DECLSPEC_NORETURN
1090 VOID
1091 NTAPI
1092 ExRaiseDatatypeMisalignment(VOID);
1093
1094 $endif (_NTDDK_)
1095 $if (_NTIFS_)
1096
1097 _IRQL_requires_max_(DISPATCH_LEVEL)
1098 NTKERNELAPI
1099 SIZE_T
1100 NTAPI
1101 ExQueryPoolBlockSize(
1102 _In_ PVOID PoolBlock,
1103 _Out_ PBOOLEAN QuotaCharged);
1104
1105 _IRQL_requires_max_(DISPATCH_LEVEL)
1106 VOID
1107 ExAdjustLookasideDepth(VOID);
1108
1109 _IRQL_requires_max_(DISPATCH_LEVEL)
1110 NTKERNELAPI
1111 VOID
1112 NTAPI
1113 ExDisableResourceBoostLite(
1114 _In_ PERESOURCE Resource);
1115 $endif (_NTIFS_)
1116 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
1117
1118 $if (_WDMDDK_ || _NTIFS_)
1119 #if (NTDDI_VERSION >= NTDDI_WINXP)
1120 $endif (_WDMDDK_ || _NTIFS_)
1121 $if (_WDMDDK_)
1122
1123 _Must_inspect_result_
1124 _Post_satisfies_(return == 0 || return == 1)
1125 NTKERNELAPI
1126 BOOLEAN
1127 FASTCALL
1128 ExAcquireRundownProtection(
1129 _Inout_ PEX_RUNDOWN_REF RunRef);
1130
1131 NTKERNELAPI
1132 VOID
1133 FASTCALL
1134 ExInitializeRundownProtection(
1135 _Out_ PEX_RUNDOWN_REF RunRef);
1136
1137 NTKERNELAPI
1138 VOID
1139 FASTCALL
1140 ExReInitializeRundownProtection(
1141 _Inout_ PEX_RUNDOWN_REF RunRef);
1142
1143 NTKERNELAPI
1144 VOID
1145 FASTCALL
1146 ExReleaseRundownProtection(
1147 _Inout_ PEX_RUNDOWN_REF RunRef);
1148
1149 NTKERNELAPI
1150 VOID
1151 FASTCALL
1152 ExRundownCompleted(
1153 _Out_ PEX_RUNDOWN_REF RunRef);
1154
1155 NTKERNELAPI
1156 BOOLEAN
1157 NTAPI
1158 ExVerifySuite(
1159 __drv_strictTypeMatch(__drv_typeExpr) _In_ SUITE_TYPE SuiteType);
1160
1161 NTKERNELAPI
1162 VOID
1163 FASTCALL
1164 ExWaitForRundownProtectionRelease(
1165 _Inout_ PEX_RUNDOWN_REF RunRef);
1166 $endif (_WDMDDK_)
1167 $if (_NTIFS_)
1168
1169 PSLIST_ENTRY
1170 FASTCALL
1171 InterlockedPushListSList(
1172 _Inout_ PSLIST_HEADER ListHead,
1173 _Inout_ __drv_aliasesMem PSLIST_ENTRY List,
1174 _Inout_ PSLIST_ENTRY ListEnd,
1175 _In_ ULONG Count);
1176 $endif (_NTIFS_)
1177 $if (_WDMDDK_ || _NTIFS_)
1178 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
1179 $endif (_WDMDDK_ || _NTIFS_)
1180
1181 $if (_WDMDDK_)
1182 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
1183
1184 _Must_inspect_result_
1185 _Post_satisfies_(return == 0 || return == 1)
1186 NTKERNELAPI
1187 BOOLEAN
1188 FASTCALL
1189 ExAcquireRundownProtectionEx(
1190 _Inout_ PEX_RUNDOWN_REF RunRef,
1191 _In_ ULONG Count);
1192
1193 NTKERNELAPI
1194 VOID
1195 FASTCALL
1196 ExReleaseRundownProtectionEx(
1197 _Inout_ PEX_RUNDOWN_REF RunRef,
1198 _In_ ULONG Count);
1199
1200 #endif /* (NTDDI_VERSION >= NTDDI_WINXPSP2) */
1201
1202 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
1203
1204 _Must_inspect_result_
1205 _IRQL_requires_max_(APC_LEVEL)
1206 NTKERNELAPI
1207 PEX_RUNDOWN_REF_CACHE_AWARE
1208 NTAPI
1209 ExAllocateCacheAwareRundownProtection(
1210 __drv_strictTypeMatch(__drv_typeExpr) _In_ POOL_TYPE PoolType,
1211 _In_ ULONG PoolTag);
1212
1213 _IRQL_requires_max_(APC_LEVEL)
1214 NTKERNELAPI
1215 SIZE_T
1216 NTAPI
1217 ExSizeOfRundownProtectionCacheAware(VOID);
1218
1219 _IRQL_requires_max_(APC_LEVEL)
1220 _Acquires_lock_(_Global_critical_region_)
1221 NTKERNELAPI
1222 PVOID
1223 NTAPI
1224 ExEnterCriticalRegionAndAcquireResourceShared(
1225 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_shared_lock_(*_Curr_)
1226 PERESOURCE Resource);
1227
1228 _IRQL_requires_max_(APC_LEVEL)
1229 _Acquires_lock_(_Global_critical_region_)
1230 NTKERNELAPI
1231 PVOID
1232 NTAPI
1233 ExEnterCriticalRegionAndAcquireResourceExclusive(
1234 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_exclusive_lock_(*_Curr_)
1235 PERESOURCE Resource);
1236
1237 _IRQL_requires_max_(APC_LEVEL)
1238 _Acquires_lock_(_Global_critical_region_)
1239 NTKERNELAPI
1240 PVOID
1241 NTAPI
1242 ExEnterCriticalRegionAndAcquireSharedWaitForExclusive(
1243 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_)
1244 PERESOURCE Resource);
1245
1246 _IRQL_requires_max_(DISPATCH_LEVEL)
1247 _Releases_lock_(_Global_critical_region_)
1248 NTKERNELAPI
1249 VOID
1250 FASTCALL
1251 ExReleaseResourceAndLeaveCriticalRegion(
1252 _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_)
1253 PERESOURCE Resource);
1254
1255 _IRQL_requires_max_(APC_LEVEL)
1256 NTKERNELAPI
1257 VOID
1258 NTAPI
1259 ExInitializeRundownProtectionCacheAware(
1260 _Out_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware,
1261 _In_ SIZE_T RunRefSize);
1262
1263 _IRQL_requires_max_(APC_LEVEL)
1264 NTKERNELAPI
1265 VOID
1266 NTAPI
1267 ExFreeCacheAwareRundownProtection(
1268 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1269
1270 _Must_inspect_result_
1271 _Post_satisfies_(return == 0 || return == 1)
1272 NTKERNELAPI
1273 BOOLEAN
1274 FASTCALL
1275 ExAcquireRundownProtectionCacheAware(
1276 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1277
1278 NTKERNELAPI
1279 VOID
1280 FASTCALL
1281 ExReleaseRundownProtectionCacheAware(
1282 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1283
1284 _Must_inspect_result_
1285 _Post_satisfies_(return == 0 || return == 1)
1286 NTKERNELAPI
1287 BOOLEAN
1288 FASTCALL
1289 ExAcquireRundownProtectionCacheAwareEx(
1290 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware,
1291 _In_ ULONG Count);
1292
1293 NTKERNELAPI
1294 VOID
1295 FASTCALL
1296 ExReleaseRundownProtectionCacheAwareEx(
1297 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRef,
1298 _In_ ULONG Count);
1299
1300 NTKERNELAPI
1301 VOID
1302 FASTCALL
1303 ExWaitForRundownProtectionReleaseCacheAware(
1304 IN OUT PEX_RUNDOWN_REF_CACHE_AWARE RunRef);
1305
1306 NTKERNELAPI
1307 VOID
1308 FASTCALL
1309 ExReInitializeRundownProtectionCacheAware(
1310 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1311
1312 NTKERNELAPI
1313 VOID
1314 FASTCALL
1315 ExRundownCompletedCacheAware(
1316 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1317
1318 #endif /* (NTDDI_VERSION >= NTDDI_WS03SP1) */
1319
1320 #if (NTDDI_VERSION >= NTDDI_VISTA)
1321
1322 _IRQL_requires_max_(DISPATCH_LEVEL)
1323 NTKERNELAPI
1324 NTSTATUS
1325 NTAPI
1326 ExInitializeLookasideListEx(
1327 _Out_ PLOOKASIDE_LIST_EX Lookaside,
1328 _In_opt_ PALLOCATE_FUNCTION_EX Allocate,
1329 _In_opt_ PFREE_FUNCTION_EX Free,
1330 _In_ POOL_TYPE PoolType,
1331 _In_ ULONG Flags,
1332 _In_ SIZE_T Size,
1333 _In_ ULONG Tag,
1334 _In_ USHORT Depth);
1335
1336 _IRQL_requires_max_(DISPATCH_LEVEL)
1337 NTKERNELAPI
1338 VOID
1339 NTAPI
1340 ExDeleteLookasideListEx(
1341 _Inout_ PLOOKASIDE_LIST_EX Lookaside);
1342
1343 _IRQL_requires_max_(DISPATCH_LEVEL)
1344 NTKERNELAPI
1345 VOID
1346 NTAPI
1347 ExFlushLookasideListEx(
1348 _Inout_ PLOOKASIDE_LIST_EX Lookaside);
1349
1350 #ifdef _MSC_VER
1351 #pragma warning(push)
1352 #pragma warning(disable:__WARNING_MEMORY_NOT_ACQUIRED)
1353 #endif
1354
1355 __drv_allocatesMem(Mem)
1356 _Must_inspect_result_
1357 _IRQL_requires_max_(DISPATCH_LEVEL)
1358 FORCEINLINE
1359 PVOID
1360 ExAllocateFromLookasideListEx(
1361 _Inout_ PLOOKASIDE_LIST_EX Lookaside)
1362 {
1363 PVOID Entry;
1364
1365 Lookaside->L.TotalAllocates += 1;
1366 #ifdef NONAMELESSUNION
1367 Entry = InterlockedPopEntrySList(&Lookaside->L.u.ListHead);
1368 if (Entry == NULL) {
1369 Lookaside->L.u2.AllocateMisses += 1;
1370 Entry = (Lookaside->L.u4.AllocateEx)(Lookaside->L.Type,
1371 Lookaside->L.Size,
1372 Lookaside->L.Tag,
1373 Lookaside);
1374 }
1375 #else /* NONAMELESSUNION */
1376 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
1377 if (Entry == NULL) {
1378 Lookaside->L.AllocateMisses += 1;
1379 Entry = (Lookaside->L.AllocateEx)(Lookaside->L.Type,
1380 Lookaside->L.Size,
1381 Lookaside->L.Tag,
1382 Lookaside);
1383 }
1384 #endif /* NONAMELESSUNION */
1385 return Entry;
1386 }
1387
1388 #ifdef _MSC_VER
1389 #pragma warning(pop)
1390 #endif
1391
1392 _IRQL_requires_max_(DISPATCH_LEVEL)
1393 FORCEINLINE
1394 VOID
1395 ExFreeToLookasideListEx(
1396 _Inout_ PLOOKASIDE_LIST_EX Lookaside,
1397 _In_ __drv_freesMem(Entry) PVOID Entry)
1398 {
1399 Lookaside->L.TotalFrees += 1;
1400 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
1401 Lookaside->L.FreeMisses += 1;
1402 (Lookaside->L.FreeEx)(Entry, Lookaside);
1403 } else {
1404 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
1405 }
1406 return;
1407 }
1408
1409 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
1410
1411 #if (NTDDI_VERSION >= NTDDI_WIN7)
1412
1413 _IRQL_requires_max_(DISPATCH_LEVEL)
1414 NTKERNELAPI
1415 VOID
1416 NTAPI
1417 ExSetResourceOwnerPointerEx(
1418 _Inout_ PERESOURCE Resource,
1419 _In_ PVOID OwnerPointer,
1420 _In_ ULONG Flags);
1421
1422 #define FLAG_OWNER_POINTER_IS_THREAD 0x1
1423
1424 #endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
1425
1426 __drv_allocatesMem(Mem)
1427 _IRQL_requires_max_(DISPATCH_LEVEL)
1428 _Ret_maybenull_
1429 _Post_writable_byte_size_(Lookaside->L.Size)
1430 static __inline
1431 PVOID
1432 ExAllocateFromNPagedLookasideList(
1433 _Inout_ PNPAGED_LOOKASIDE_LIST Lookaside)
1434 {
1435 PVOID Entry;
1436
1437 Lookaside->L.TotalAllocates++;
1438 #ifdef NONAMELESSUNION
1439 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1440 Entry = ExInterlockedPopEntrySList(&Lookaside->L.u.ListHead,
1441 &Lookaside->Lock__ObsoleteButDoNotDelete);
1442 #else
1443 Entry = InterlockedPopEntrySList(&Lookaside->L.u.ListHead);
1444 #endif
1445 if (Entry == NULL) {
1446 Lookaside->L.u2.AllocateMisses++;
1447 Entry = (Lookaside->L.u4.Allocate)(Lookaside->L.Type,
1448 Lookaside->L.Size,
1449 Lookaside->L.Tag);
1450 }
1451 #else /* NONAMELESSUNION */
1452 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1453 Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
1454 &Lookaside->Lock__ObsoleteButDoNotDelete);
1455 #else
1456 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
1457 #endif
1458 if (Entry == NULL) {
1459 Lookaside->L.AllocateMisses++;
1460 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
1461 Lookaside->L.Size,
1462 Lookaside->L.Tag);
1463 }
1464 #endif /* NONAMELESSUNION */
1465 return Entry;
1466 }
1467
1468 _IRQL_requires_max_(DISPATCH_LEVEL)
1469 static __inline
1470 VOID
1471 ExFreeToNPagedLookasideList(
1472 _Inout_ PNPAGED_LOOKASIDE_LIST Lookaside,
1473 _In_ __drv_freesMem(Mem) PVOID Entry)
1474 {
1475 Lookaside->L.TotalFrees++;
1476 #ifdef NONAMELESSUNION
1477 if (ExQueryDepthSList(&Lookaside->L.u.ListHead) >= Lookaside->L.Depth) {
1478 Lookaside->L.u3.FreeMisses++;
1479 (Lookaside->L.u5.Free)(Entry);
1480 } else {
1481 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1482 ExInterlockedPushEntrySList(&Lookaside->L.u.ListHead,
1483 (PSLIST_ENTRY)Entry,
1484 &Lookaside->Lock__ObsoleteButDoNotDelete);
1485 #else
1486 InterlockedPushEntrySList(&Lookaside->L.u.ListHead, (PSLIST_ENTRY)Entry);
1487 #endif
1488 }
1489 #else /* NONAMELESSUNION */
1490 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
1491 Lookaside->L.FreeMisses++;
1492 (Lookaside->L.Free)(Entry);
1493 } else {
1494 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1495 ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
1496 (PSLIST_ENTRY)Entry,
1497 &Lookaside->Lock__ObsoleteButDoNotDelete);
1498 #else
1499 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
1500 #endif
1501 }
1502 #endif /* NONAMELESSUNION */
1503 }
1504
1505 $endif (_WDMDDK_)