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
ExQueryDepthSList(_In_ PSLIST_HEADER SListHead)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
_IRQL_requires_max_(APC_LEVEL)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
_IRQL_requires_max_(APC_LEVEL)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
ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)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_)
$if(_NTDDK_)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
ExFreeToZone(IN PZONE_HEADER Zone,IN PVOID Block)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
__drv_allocatesMem(Mem)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
__drv_allocatesMem(Mem)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
__drv_allocatesMem(Mem)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
__drv_allocatesMem(Mem)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
__drv_allocatesMem(Mem)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
__drv_allocatesMem(Mem)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 #if (NTDDI_VERSION >= NTDDI_WINBLUE)
954
955 #define EX_TIMER_HIGH_RESOLUTION 0x4
956 #define EX_TIMER_NO_WAKE 0x8
957 #define EX_TIMER_UNLIMITED_TOLERANCE ((LONGLONG)-1)
958 #define EX_TIMER_NOTIFICATION (1UL << 31)
959
960 NTKERNELAPI
961 PEX_TIMER
962 NTAPI
963 ExAllocateTimer(
964 _In_opt_ PEXT_CALLBACK Callback,
965 _In_opt_ PVOID CallbackContext,
966 _In_ ULONG Attributes);
967
968 NTKERNELAPI
969 BOOLEAN
970 NTAPI
971 ExSetTimer(
972 _In_ PEX_TIMER Timer,
973 _In_ LONGLONG DueTime,
974 _In_ LONGLONG Period,
975 _In_opt_ PEXT_SET_PARAMETERS Parameters);
976
977 NTKERNELAPI
978 BOOLEAN
979 NTAPI
980 ExCancelTimer(
981 _Inout_ PEX_TIMER Timer,
982 _In_opt_ PEXT_CANCEL_PARAMETERS Parameters);
983
984 NTKERNELAPI
985 BOOLEAN
986 NTAPI
987 ExDeleteTimer(
988 _In_ PEX_TIMER Timer,
989 _In_ BOOLEAN Cancel,
990 _In_ BOOLEAN Wait,
991 _In_opt_ PEXT_DELETE_PARAMETERS Parameters);
992
993 FORCEINLINE
994 VOID
ExInitializeSetTimerParameters(_Out_ PEXT_SET_PARAMETERS Parameters)995 ExInitializeSetTimerParameters(
996 _Out_ PEXT_SET_PARAMETERS Parameters)
997 {
998 ASSERT(FALSE);
999 }
1000
1001 #endif // NTDDI_WINBLUE
1002
1003 _IRQL_requires_max_(DISPATCH_LEVEL)
1004 NTKERNELAPI
1005 VOID
1006 NTAPI
1007 ExNotifyCallback(
1008 _In_ PCALLBACK_OBJECT CallbackObject,
1009 _In_opt_ PVOID Argument1,
1010 _In_opt_ PVOID Argument2);
1011
1012 _IRQL_requires_max_(DISPATCH_LEVEL)
1013 NTKERNELAPI
1014 VOID
1015 NTAPI
1016 ExQueueWorkItem(
1017 _Inout_ __drv_aliasesMem PWORK_QUEUE_ITEM WorkItem,
1018 __drv_strictTypeMatch(__drv_typeExpr) _In_ WORK_QUEUE_TYPE QueueType);
1019
1020 _IRQL_requires_max_(APC_LEVEL)
1021 NTKERNELAPI
1022 DECLSPEC_NORETURN
1023 VOID
1024 NTAPI
1025 ExRaiseStatus(
1026 _In_ NTSTATUS Status);
1027
1028 _IRQL_requires_max_(APC_LEVEL)
1029 NTKERNELAPI
1030 PVOID
1031 NTAPI
1032 ExRegisterCallback(
1033 _Inout_ PCALLBACK_OBJECT CallbackObject,
1034 _In_ PCALLBACK_FUNCTION CallbackFunction,
1035 _In_opt_ PVOID CallbackContext);
1036
1037 _IRQL_requires_max_(DISPATCH_LEVEL)
1038 NTKERNELAPI
1039 NTSTATUS
1040 NTAPI
1041 ExReinitializeResourceLite(
1042 _Inout_ PERESOURCE Resource);
1043
1044 _IRQL_requires_max_(DISPATCH_LEVEL)
1045 _Requires_lock_held_(_Global_critical_region_)
1046 NTKERNELAPI
1047 VOID
1048 NTAPI
1049 ExReleaseResourceForThreadLite(
1050 _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_)
1051 PERESOURCE Resource,
1052 _In_ ERESOURCE_THREAD ResourceThreadId);
1053
1054 _Requires_lock_held_(_Global_critical_region_)
1055 _Requires_lock_held_(*Resource)
1056 _Releases_lock_(*Resource)
1057 _IRQL_requires_max_(DISPATCH_LEVEL)
1058 NTKERNELAPI
1059 VOID
1060 FASTCALL
1061 ExReleaseResourceLite(
1062 _Inout_ PERESOURCE Resource);
1063
1064 _IRQL_requires_max_(DISPATCH_LEVEL)
1065 NTKERNELAPI
1066 VOID
1067 NTAPI
1068 ExSetResourceOwnerPointer(
1069 _Inout_ PERESOURCE Resource,
1070 _In_ PVOID OwnerPointer);
1071
1072 _IRQL_requires_max_(APC_LEVEL)
1073 NTKERNELAPI
1074 ULONG
1075 NTAPI
1076 ExSetTimerResolution(
1077 _In_ ULONG DesiredTime,
1078 _In_ BOOLEAN SetResolution);
1079
1080 NTKERNELAPI
1081 VOID
1082 NTAPI
1083 ExSystemTimeToLocalTime(
1084 _In_ PLARGE_INTEGER SystemTime,
1085 _Out_ PLARGE_INTEGER LocalTime);
1086
1087 _IRQL_requires_max_(APC_LEVEL)
1088 NTKERNELAPI
1089 VOID
1090 NTAPI
1091 ExUnregisterCallback(
1092 _Inout_ PVOID CbRegistration);
1093
1094 $endif (_WDMDDK_)
1095 $if (_NTDDK_)
1096 NTKERNELAPI
1097 NTSTATUS
1098 NTAPI
1099 ExExtendZone(
1100 _Inout_ PZONE_HEADER Zone,
1101 _Inout_ PVOID Segment,
1102 _In_ ULONG SegmentSize);
1103
1104 NTKERNELAPI
1105 NTSTATUS
1106 NTAPI
1107 ExInitializeZone(
1108 _Out_ PZONE_HEADER Zone,
1109 _In_ ULONG BlockSize,
1110 _Inout_ PVOID InitialSegment,
1111 _In_ ULONG InitialSegmentSize);
1112
1113 _IRQL_requires_max_(DISPATCH_LEVEL)
1114 NTKERNELAPI
1115 NTSTATUS
1116 NTAPI
1117 ExInterlockedExtendZone(
1118 _Inout_ PZONE_HEADER Zone,
1119 _Inout_ PVOID Segment,
1120 _In_ ULONG SegmentSize,
1121 _Inout_ _Requires_lock_not_held_(*_Curr_) PKSPIN_LOCK Lock);
1122
1123 _IRQL_requires_max_(PASSIVE_LEVEL)
1124 NTKERNELAPI
1125 NTSTATUS
1126 NTAPI
1127 ExUuidCreate(
1128 _Out_ UUID *Uuid);
1129
1130 _IRQL_requires_max_(PASSIVE_LEVEL)
1131 NTKERNELAPI
1132 DECLSPEC_NORETURN
1133 VOID
1134 NTAPI
1135 ExRaiseAccessViolation(VOID);
1136
1137 _IRQL_requires_max_(PASSIVE_LEVEL)
1138 NTKERNELAPI
1139 DECLSPEC_NORETURN
1140 VOID
1141 NTAPI
1142 ExRaiseDatatypeMisalignment(VOID);
1143
1144 $endif (_NTDDK_)
1145 $if (_NTIFS_)
1146
1147 _IRQL_requires_max_(DISPATCH_LEVEL)
1148 NTKERNELAPI
1149 SIZE_T
1150 NTAPI
1151 ExQueryPoolBlockSize(
1152 _In_ PVOID PoolBlock,
1153 _Out_ PBOOLEAN QuotaCharged);
1154
1155 _IRQL_requires_max_(DISPATCH_LEVEL)
1156 VOID
1157 ExAdjustLookasideDepth(VOID);
1158
1159 _IRQL_requires_max_(DISPATCH_LEVEL)
1160 NTKERNELAPI
1161 VOID
1162 NTAPI
1163 ExDisableResourceBoostLite(
1164 _In_ PERESOURCE Resource);
1165 $endif (_NTIFS_)
1166 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
1167
1168 $if (_WDMDDK_ || _NTIFS_)
1169 #if (NTDDI_VERSION >= NTDDI_WINXP)
1170 $endif (_WDMDDK_ || _NTIFS_)
1171 $if (_WDMDDK_)
1172
1173 _Must_inspect_result_
1174 _Post_satisfies_(return == 0 || return == 1)
1175 NTKERNELAPI
1176 BOOLEAN
1177 FASTCALL
1178 ExAcquireRundownProtection(
1179 _Inout_ PEX_RUNDOWN_REF RunRef);
1180
1181 NTKERNELAPI
1182 VOID
1183 FASTCALL
1184 ExInitializeRundownProtection(
1185 _Out_ PEX_RUNDOWN_REF RunRef);
1186
1187 NTKERNELAPI
1188 VOID
1189 FASTCALL
1190 ExReInitializeRundownProtection(
1191 _Inout_ PEX_RUNDOWN_REF RunRef);
1192
1193 NTKERNELAPI
1194 VOID
1195 FASTCALL
1196 ExReleaseRundownProtection(
1197 _Inout_ PEX_RUNDOWN_REF RunRef);
1198
1199 NTKERNELAPI
1200 VOID
1201 FASTCALL
1202 ExRundownCompleted(
1203 _Out_ PEX_RUNDOWN_REF RunRef);
1204
1205 NTKERNELAPI
1206 BOOLEAN
1207 NTAPI
1208 ExVerifySuite(
1209 __drv_strictTypeMatch(__drv_typeExpr) _In_ SUITE_TYPE SuiteType);
1210
1211 NTKERNELAPI
1212 VOID
1213 FASTCALL
1214 ExWaitForRundownProtectionRelease(
1215 _Inout_ PEX_RUNDOWN_REF RunRef);
1216 $endif (_WDMDDK_)
1217 $if (_NTIFS_)
1218
1219 PSLIST_ENTRY
1220 FASTCALL
1221 InterlockedPushListSList(
1222 _Inout_ PSLIST_HEADER ListHead,
1223 _Inout_ __drv_aliasesMem PSLIST_ENTRY List,
1224 _Inout_ PSLIST_ENTRY ListEnd,
1225 _In_ ULONG Count);
1226 $endif (_NTIFS_)
1227 $if (_WDMDDK_ || _NTIFS_)
1228 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
1229 $endif (_WDMDDK_ || _NTIFS_)
1230
1231 $if (_WDMDDK_)
1232 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
1233
1234 _Must_inspect_result_
1235 _Post_satisfies_(return == 0 || return == 1)
1236 NTKERNELAPI
1237 BOOLEAN
1238 FASTCALL
1239 ExAcquireRundownProtectionEx(
1240 _Inout_ PEX_RUNDOWN_REF RunRef,
1241 _In_ ULONG Count);
1242
1243 NTKERNELAPI
1244 VOID
1245 FASTCALL
1246 ExReleaseRundownProtectionEx(
1247 _Inout_ PEX_RUNDOWN_REF RunRef,
1248 _In_ ULONG Count);
1249
1250 #endif /* (NTDDI_VERSION >= NTDDI_WINXPSP2) */
1251
1252 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
1253
1254 _Must_inspect_result_
1255 _IRQL_requires_max_(APC_LEVEL)
1256 NTKERNELAPI
1257 PEX_RUNDOWN_REF_CACHE_AWARE
1258 NTAPI
1259 ExAllocateCacheAwareRundownProtection(
1260 __drv_strictTypeMatch(__drv_typeExpr) _In_ POOL_TYPE PoolType,
1261 _In_ ULONG PoolTag);
1262
1263 _IRQL_requires_max_(APC_LEVEL)
1264 NTKERNELAPI
1265 SIZE_T
1266 NTAPI
1267 ExSizeOfRundownProtectionCacheAware(VOID);
1268
1269 _IRQL_requires_max_(APC_LEVEL)
1270 _Acquires_lock_(_Global_critical_region_)
1271 NTKERNELAPI
1272 PVOID
1273 NTAPI
1274 ExEnterCriticalRegionAndAcquireResourceShared(
1275 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_shared_lock_(*_Curr_)
1276 PERESOURCE Resource);
1277
1278 _IRQL_requires_max_(APC_LEVEL)
1279 _Acquires_lock_(_Global_critical_region_)
1280 NTKERNELAPI
1281 PVOID
1282 NTAPI
1283 ExEnterCriticalRegionAndAcquireResourceExclusive(
1284 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_exclusive_lock_(*_Curr_)
1285 PERESOURCE Resource);
1286
1287 _IRQL_requires_max_(APC_LEVEL)
1288 _Acquires_lock_(_Global_critical_region_)
1289 NTKERNELAPI
1290 PVOID
1291 NTAPI
1292 ExEnterCriticalRegionAndAcquireSharedWaitForExclusive(
1293 _Inout_ _Requires_lock_not_held_(*_Curr_) _Acquires_lock_(*_Curr_)
1294 PERESOURCE Resource);
1295
1296 _IRQL_requires_max_(DISPATCH_LEVEL)
1297 _Releases_lock_(_Global_critical_region_)
1298 NTKERNELAPI
1299 VOID
1300 FASTCALL
1301 ExReleaseResourceAndLeaveCriticalRegion(
1302 _Inout_ _Requires_lock_held_(*_Curr_) _Releases_lock_(*_Curr_)
1303 PERESOURCE Resource);
1304
1305 _IRQL_requires_max_(APC_LEVEL)
1306 NTKERNELAPI
1307 VOID
1308 NTAPI
1309 ExInitializeRundownProtectionCacheAware(
1310 _Out_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware,
1311 _In_ SIZE_T RunRefSize);
1312
1313 _IRQL_requires_max_(APC_LEVEL)
1314 NTKERNELAPI
1315 VOID
1316 NTAPI
1317 ExFreeCacheAwareRundownProtection(
1318 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1319
1320 _Must_inspect_result_
1321 _Post_satisfies_(return == 0 || return == 1)
1322 NTKERNELAPI
1323 BOOLEAN
1324 FASTCALL
1325 ExAcquireRundownProtectionCacheAware(
1326 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1327
1328 NTKERNELAPI
1329 VOID
1330 FASTCALL
1331 ExReleaseRundownProtectionCacheAware(
1332 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1333
1334 _Must_inspect_result_
1335 _Post_satisfies_(return == 0 || return == 1)
1336 NTKERNELAPI
1337 BOOLEAN
1338 FASTCALL
1339 ExAcquireRundownProtectionCacheAwareEx(
1340 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware,
1341 _In_ ULONG Count);
1342
1343 NTKERNELAPI
1344 VOID
1345 FASTCALL
1346 ExReleaseRundownProtectionCacheAwareEx(
1347 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRef,
1348 _In_ ULONG Count);
1349
1350 NTKERNELAPI
1351 VOID
1352 FASTCALL
1353 ExWaitForRundownProtectionReleaseCacheAware(
1354 IN OUT PEX_RUNDOWN_REF_CACHE_AWARE RunRef);
1355
1356 NTKERNELAPI
1357 VOID
1358 FASTCALL
1359 ExReInitializeRundownProtectionCacheAware(
1360 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1361
1362 NTKERNELAPI
1363 VOID
1364 FASTCALL
1365 ExRundownCompletedCacheAware(
1366 _Inout_ PEX_RUNDOWN_REF_CACHE_AWARE RunRefCacheAware);
1367
1368 #endif /* (NTDDI_VERSION >= NTDDI_WS03SP1) */
1369
1370 #if (NTDDI_VERSION >= NTDDI_VISTA)
1371
1372 _IRQL_requires_max_(DISPATCH_LEVEL)
1373 NTKERNELAPI
1374 NTSTATUS
1375 NTAPI
1376 ExInitializeLookasideListEx(
1377 _Out_ PLOOKASIDE_LIST_EX Lookaside,
1378 _In_opt_ PALLOCATE_FUNCTION_EX Allocate,
1379 _In_opt_ PFREE_FUNCTION_EX Free,
1380 _In_ POOL_TYPE PoolType,
1381 _In_ ULONG Flags,
1382 _In_ SIZE_T Size,
1383 _In_ ULONG Tag,
1384 _In_ USHORT Depth);
1385
1386 _IRQL_requires_max_(DISPATCH_LEVEL)
1387 NTKERNELAPI
1388 VOID
1389 NTAPI
1390 ExDeleteLookasideListEx(
1391 _Inout_ PLOOKASIDE_LIST_EX Lookaside);
1392
1393 _IRQL_requires_max_(DISPATCH_LEVEL)
1394 NTKERNELAPI
1395 VOID
1396 NTAPI
1397 ExFlushLookasideListEx(
1398 _Inout_ PLOOKASIDE_LIST_EX Lookaside);
1399
1400 #ifdef _MSC_VER
1401 #pragma warning(push)
1402 #pragma warning(disable:__WARNING_MEMORY_NOT_ACQUIRED)
1403 #endif
1404
__drv_allocatesMem(Mem)1405 __drv_allocatesMem(Mem)
1406 _Must_inspect_result_
1407 _IRQL_requires_max_(DISPATCH_LEVEL)
1408 FORCEINLINE
1409 PVOID
1410 ExAllocateFromLookasideListEx(
1411 _Inout_ PLOOKASIDE_LIST_EX Lookaside)
1412 {
1413 PVOID Entry;
1414
1415 Lookaside->L.TotalAllocates += 1;
1416 #ifdef NONAMELESSUNION
1417 Entry = InterlockedPopEntrySList(&Lookaside->L.u.ListHead);
1418 if (Entry == NULL) {
1419 Lookaside->L.u2.AllocateMisses += 1;
1420 Entry = (Lookaside->L.u4.AllocateEx)(Lookaside->L.Type,
1421 Lookaside->L.Size,
1422 Lookaside->L.Tag,
1423 Lookaside);
1424 }
1425 #else /* NONAMELESSUNION */
1426 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
1427 if (Entry == NULL) {
1428 Lookaside->L.AllocateMisses += 1;
1429 Entry = (Lookaside->L.AllocateEx)(Lookaside->L.Type,
1430 Lookaside->L.Size,
1431 Lookaside->L.Tag,
1432 Lookaside);
1433 }
1434 #endif /* NONAMELESSUNION */
1435 return Entry;
1436 }
1437
1438 #ifdef _MSC_VER
1439 #pragma warning(pop)
1440 #endif
1441
_IRQL_requires_max_(DISPATCH_LEVEL)1442 _IRQL_requires_max_(DISPATCH_LEVEL)
1443 FORCEINLINE
1444 VOID
1445 ExFreeToLookasideListEx(
1446 _Inout_ PLOOKASIDE_LIST_EX Lookaside,
1447 _In_ __drv_freesMem(Entry) PVOID Entry)
1448 {
1449 Lookaside->L.TotalFrees += 1;
1450 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
1451 Lookaside->L.FreeMisses += 1;
1452 (Lookaside->L.FreeEx)(Entry, Lookaside);
1453 } else {
1454 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
1455 }
1456 return;
1457 }
1458
1459 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
1460
1461 #if (NTDDI_VERSION >= NTDDI_WIN7)
1462
1463 _IRQL_requires_max_(DISPATCH_LEVEL)
1464 NTKERNELAPI
1465 VOID
1466 NTAPI
1467 ExSetResourceOwnerPointerEx(
1468 _Inout_ PERESOURCE Resource,
1469 _In_ PVOID OwnerPointer,
1470 _In_ ULONG Flags);
1471
1472 #define FLAG_OWNER_POINTER_IS_THREAD 0x1
1473
1474 #endif /* (NTDDI_VERSION >= NTDDI_WIN7) */
1475
1476 __drv_allocatesMem(Mem)
_IRQL_requires_max_(DISPATCH_LEVEL)1477 _IRQL_requires_max_(DISPATCH_LEVEL)
1478 _Ret_maybenull_
1479 _Post_writable_byte_size_(Lookaside->L.Size)
1480 static __inline
1481 PVOID
1482 ExAllocateFromNPagedLookasideList(
1483 _Inout_ PNPAGED_LOOKASIDE_LIST Lookaside)
1484 {
1485 PVOID Entry;
1486
1487 Lookaside->L.TotalAllocates++;
1488 #ifdef NONAMELESSUNION
1489 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1490 Entry = ExInterlockedPopEntrySList(&Lookaside->L.u.ListHead,
1491 &Lookaside->Lock__ObsoleteButDoNotDelete);
1492 #else
1493 Entry = InterlockedPopEntrySList(&Lookaside->L.u.ListHead);
1494 #endif
1495 if (Entry == NULL) {
1496 Lookaside->L.u2.AllocateMisses++;
1497 Entry = (Lookaside->L.u4.Allocate)(Lookaside->L.Type,
1498 Lookaside->L.Size,
1499 Lookaside->L.Tag);
1500 }
1501 #else /* NONAMELESSUNION */
1502 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1503 Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
1504 &Lookaside->Lock__ObsoleteButDoNotDelete);
1505 #else
1506 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
1507 #endif
1508 if (Entry == NULL) {
1509 Lookaside->L.AllocateMisses++;
1510 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
1511 Lookaside->L.Size,
1512 Lookaside->L.Tag);
1513 }
1514 #endif /* NONAMELESSUNION */
1515 return Entry;
1516 }
1517
_IRQL_requires_max_(DISPATCH_LEVEL)1518 _IRQL_requires_max_(DISPATCH_LEVEL)
1519 static __inline
1520 VOID
1521 ExFreeToNPagedLookasideList(
1522 _Inout_ PNPAGED_LOOKASIDE_LIST Lookaside,
1523 _In_ __drv_freesMem(Mem) PVOID Entry)
1524 {
1525 Lookaside->L.TotalFrees++;
1526 #ifdef NONAMELESSUNION
1527 if (ExQueryDepthSList(&Lookaside->L.u.ListHead) >= Lookaside->L.Depth) {
1528 Lookaside->L.u3.FreeMisses++;
1529 (Lookaside->L.u5.Free)(Entry);
1530 } else {
1531 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1532 ExInterlockedPushEntrySList(&Lookaside->L.u.ListHead,
1533 (PSLIST_ENTRY)Entry,
1534 &Lookaside->Lock__ObsoleteButDoNotDelete);
1535 #else
1536 InterlockedPushEntrySList(&Lookaside->L.u.ListHead, (PSLIST_ENTRY)Entry);
1537 #endif
1538 }
1539 #else /* NONAMELESSUNION */
1540 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
1541 Lookaside->L.FreeMisses++;
1542 (Lookaside->L.Free)(Entry);
1543 } else {
1544 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
1545 ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
1546 (PSLIST_ENTRY)Entry,
1547 &Lookaside->Lock__ObsoleteButDoNotDelete);
1548 #else
1549 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
1550 #endif
1551 }
1552 #endif /* NONAMELESSUNION */
1553 }
1554
1555 $endif (_WDMDDK_)
1556