[NTOSKRNL]
[reactos.git] / 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 NTKERNELAPI
46 VOID
47 FASTCALL
48 ExAcquireFastMutex(
49 IN OUT PFAST_MUTEX FastMutex);
50
51 NTKERNELAPI
52 VOID
53 FASTCALL
54 ExReleaseFastMutex(
55 IN OUT PFAST_MUTEX FastMutex);
56
57 NTKERNELAPI
58 BOOLEAN
59 FASTCALL
60 ExTryToAcquireFastMutex(
61 IN OUT PFAST_MUTEX FastMutex);
62
63 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
64
65 #endif /* defined(_NTHAL_) && defined(_X86_) */
66
67 #if defined(_X86_)
68 #define ExInterlockedAddUlong ExfInterlockedAddUlong
69 #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
70 #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
71 #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
72 #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
73 #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
74 #endif /* defined(_X86_) */
75
76 #if defined(_WIN64)
77
78 #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || \
79 defined(_NTHAL_) || defined(_NTOSP_)
80 NTKERNELAPI
81 USHORT
82 ExQueryDepthSList(IN PSLIST_HEADER ListHead);
83 #else
84 FORCEINLINE
85 USHORT
86 ExQueryDepthSList(IN PSLIST_HEADER ListHead)
87 {
88 return (USHORT)(ListHead->Alignment & 0xffff);
89 }
90 #endif
91
92 NTKERNELAPI
93 PSLIST_ENTRY
94 ExpInterlockedFlushSList(
95 PSLIST_HEADER ListHead);
96
97 NTKERNELAPI
98 PSLIST_ENTRY
99 ExpInterlockedPopEntrySList(
100 PSLIST_HEADER ListHead);
101
102 NTKERNELAPI
103 PSLIST_ENTRY
104 ExpInterlockedPushEntrySList(
105 PSLIST_HEADER ListHead,
106 PSLIST_ENTRY ListEntry);
107
108 #define ExInterlockedFlushSList(Head) \
109 ExpInterlockedFlushSList(Head)
110 #define ExInterlockedPopEntrySList(Head, Lock) \
111 ExpInterlockedPopEntrySList(Head)
112 #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
113 ExpInterlockedPushEntrySList(Head, Entry)
114
115 #else /* !defined(_WIN64) */
116
117 #define ExQueryDepthSList(listhead) (listhead)->Depth
118
119 NTKERNELAPI
120 PSINGLE_LIST_ENTRY
121 FASTCALL
122 ExInterlockedFlushSList(
123 IN OUT PSLIST_HEADER ListHead);
124
125 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
126
127 NTKERNELAPI
128 PSINGLE_LIST_ENTRY
129 FASTCALL
130 ExInterlockedPopEntrySList(
131 IN PSLIST_HEADER ListHead,
132 IN PKSPIN_LOCK Lock);
133
134 NTKERNELAPI
135 PSINGLE_LIST_ENTRY
136 FASTCALL
137 ExInterlockedPushEntrySList(
138 IN PSLIST_HEADER ListHead,
139 IN PSINGLE_LIST_ENTRY ListEntry,
140 IN PKSPIN_LOCK Lock);
141
142 NTKERNELAPI
143 PVOID
144 NTAPI
145 ExAllocateFromPagedLookasideList(
146 IN OUT PPAGED_LOOKASIDE_LIST Lookaside);
147
148 NTKERNELAPI
149 VOID
150 NTAPI
151 ExFreeToPagedLookasideList(
152 IN OUT PPAGED_LOOKASIDE_LIST Lookaside,
153 IN PVOID Entry);
154
155 #else
156
157 #define ExInterlockedPopEntrySList(_ListHead, _Lock) \
158 InterlockedPopEntrySList(_ListHead)
159 #define ExInterlockedPushEntrySList(_ListHead, _ListEntry, _Lock) \
160 InterlockedPushEntrySList(_ListHead, _ListEntry)
161
162 static __inline
163 PVOID
164 ExAllocateFromPagedLookasideList(
165 IN OUT PPAGED_LOOKASIDE_LIST Lookaside)
166 {
167 PVOID Entry;
168
169 Lookaside->L.TotalAllocates++;
170 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
171 if (Entry == NULL) {
172 Lookaside->L.AllocateMisses++;
173 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
174 Lookaside->L.Size,
175 Lookaside->L.Tag);
176 }
177 return Entry;
178 }
179
180 static __inline
181 VOID
182 ExFreeToPagedLookasideList(
183 IN OUT PPAGED_LOOKASIDE_LIST Lookaside,
184 IN PVOID Entry)
185 {
186 Lookaside->L.TotalFrees++;
187 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
188 Lookaside->L.FreeMisses++;
189 (Lookaside->L.Free)(Entry);
190 } else {
191 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
192 }
193 }
194
195 #endif /* _WIN2K_COMPAT_SLIST_USAGE */
196
197 #endif /* !defined(_WIN64) */
198
199 /* ERESOURCE_THREAD
200 * ExGetCurrentResourceThread(
201 * VOID);
202 */
203 #define ExGetCurrentResourceThread() ((ERESOURCE_THREAD)PsGetCurrentThread())
204
205 #define ExReleaseResource(R) (ExReleaseResourceLite(R))
206
207 /* VOID
208 * ExInitializeWorkItem(
209 * IN PWORK_QUEUE_ITEM Item,
210 * IN PWORKER_THREAD_ROUTINE Routine,
211 * IN PVOID Context)
212 */
213 #define ExInitializeWorkItem(Item, Routine, Context) \
214 { \
215 (Item)->WorkerRoutine = Routine; \
216 (Item)->Parameter = Context; \
217 (Item)->List.Flink = NULL; \
218 }
219
220 FORCEINLINE
221 VOID
222 ExInitializeFastMutex(
223 OUT PFAST_MUTEX FastMutex)
224 {
225 FastMutex->Count = FM_LOCK_BIT;
226 FastMutex->Owner = NULL;
227 FastMutex->Contention = 0;
228 KeInitializeEvent(&FastMutex->Event, SynchronizationEvent, FALSE);
229 return;
230 }
231
232 #if (NTDDI_VERSION >= NTDDI_WIN2K)
233
234 NTKERNELAPI
235 VOID
236 FASTCALL
237 ExAcquireFastMutexUnsafe(
238 IN OUT PFAST_MUTEX FastMutex);
239
240 NTKERNELAPI
241 VOID
242 FASTCALL
243 ExReleaseFastMutexUnsafe(
244 IN OUT PFAST_MUTEX FastMutex);
245
246 NTKERNELAPI
247 BOOLEAN
248 NTAPI
249 ExAcquireResourceExclusiveLite(
250 IN PERESOURCE Resource,
251 IN BOOLEAN Wait);
252
253 NTKERNELAPI
254 BOOLEAN
255 NTAPI
256 ExAcquireResourceSharedLite(
257 IN OUT PERESOURCE Resource,
258 IN BOOLEAN Wait);
259
260 NTKERNELAPI
261 BOOLEAN
262 NTAPI
263 ExAcquireSharedStarveExclusive(
264 IN PERESOURCE Resource,
265 IN BOOLEAN Wait);
266
267 NTKERNELAPI
268 BOOLEAN
269 NTAPI
270 ExAcquireSharedWaitForExclusive(
271 IN PERESOURCE Resource,
272 IN BOOLEAN Wait);
273
274 NTKERNELAPI
275 PVOID
276 NTAPI
277 ExAllocatePool(
278 IN POOL_TYPE PoolType,
279 IN SIZE_T NumberOfBytes);
280
281 NTKERNELAPI
282 PVOID
283 NTAPI
284 ExAllocatePoolWithQuota(
285 IN POOL_TYPE PoolType,
286 IN SIZE_T NumberOfBytes);
287
288 NTKERNELAPI
289 PVOID
290 NTAPI
291 ExAllocatePoolWithQuotaTag(
292 IN POOL_TYPE PoolType,
293 IN SIZE_T NumberOfBytes,
294 IN ULONG Tag);
295
296 #ifndef POOL_TAGGING
297 #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
298 #endif
299
300 NTKERNELAPI
301 PVOID
302 NTAPI
303 ExAllocatePoolWithTag(
304 IN POOL_TYPE PoolType,
305 IN SIZE_T NumberOfBytes,
306 IN ULONG Tag);
307
308 #ifndef POOL_TAGGING
309 #define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
310 #endif
311
312 NTKERNELAPI
313 PVOID
314 NTAPI
315 ExAllocatePoolWithTagPriority(
316 IN POOL_TYPE PoolType,
317 IN SIZE_T NumberOfBytes,
318 IN ULONG Tag,
319 IN EX_POOL_PRIORITY Priority);
320
321 NTKERNELAPI
322 VOID
323 NTAPI
324 ExConvertExclusiveToSharedLite(
325 IN PERESOURCE Resource);
326
327 NTKERNELAPI
328 NTSTATUS
329 NTAPI
330 ExCreateCallback(
331 OUT PCALLBACK_OBJECT *CallbackObject,
332 IN POBJECT_ATTRIBUTES ObjectAttributes,
333 IN BOOLEAN Create,
334 IN BOOLEAN AllowMultipleCallbacks);
335
336 NTKERNELAPI
337 VOID
338 NTAPI
339 ExDeleteNPagedLookasideList(
340 IN OUT PNPAGED_LOOKASIDE_LIST Lookaside);
341
342 NTKERNELAPI
343 VOID
344 NTAPI
345 ExDeletePagedLookasideList(
346 IN PPAGED_LOOKASIDE_LIST Lookaside);
347
348 NTKERNELAPI
349 NTSTATUS
350 NTAPI
351 ExDeleteResourceLite(
352 IN PERESOURCE Resource);
353
354 NTKERNELAPI
355 VOID
356 NTAPI
357 ExFreePool(
358 IN PVOID P);
359
360 NTKERNELAPI
361 VOID
362 NTAPI
363 ExFreePoolWithTag(
364 IN PVOID P,
365 IN ULONG Tag);
366
367 NTKERNELAPI
368 ULONG
369 NTAPI
370 ExGetExclusiveWaiterCount(
371 IN PERESOURCE Resource);
372
373 NTKERNELAPI
374 KPROCESSOR_MODE
375 NTAPI
376 ExGetPreviousMode(VOID);
377
378 NTKERNELAPI
379 ULONG
380 NTAPI
381 ExGetSharedWaiterCount(
382 IN PERESOURCE Resource);
383
384 NTKERNELAPI
385 VOID
386 NTAPI
387 ExInitializeNPagedLookasideList(
388 IN PNPAGED_LOOKASIDE_LIST Lookaside,
389 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
390 IN PFREE_FUNCTION Free OPTIONAL,
391 IN ULONG Flags,
392 IN SIZE_T Size,
393 IN ULONG Tag,
394 IN USHORT Depth);
395
396 NTKERNELAPI
397 VOID
398 NTAPI
399 ExInitializePagedLookasideList(
400 IN PPAGED_LOOKASIDE_LIST Lookaside,
401 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
402 IN PFREE_FUNCTION Free OPTIONAL,
403 IN ULONG Flags,
404 IN SIZE_T Size,
405 IN ULONG Tag,
406 IN USHORT Depth);
407
408 NTKERNELAPI
409 NTSTATUS
410 NTAPI
411 ExInitializeResourceLite(
412 OUT PERESOURCE Resource);
413
414 NTKERNELAPI
415 LARGE_INTEGER
416 NTAPI
417 ExInterlockedAddLargeInteger(
418 IN PLARGE_INTEGER Addend,
419 IN LARGE_INTEGER Increment,
420 IN PKSPIN_LOCK Lock);
421
422 #if defined(_WIN64)
423 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
424 (VOID)InterlockedAdd64(&(Addend)->QuadPart, Increment)
425 #else
426 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
427 _InterlockedAddLargeStatistic((PLONGLONG)&(Addend)->QuadPart, Increment)
428 #endif
429
430 NTKERNELAPI
431 ULONG
432 FASTCALL
433 ExInterlockedAddUlong(
434 IN PULONG Addend,
435 IN ULONG Increment,
436 IN OUT PKSPIN_LOCK Lock);
437
438 #if defined(_AMD64_) || defined(_IA64_)
439
440 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
441 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
442
443 #elif defined(_X86_)
444
445 NTKERNELAPI
446 LONGLONG
447 FASTCALL
448 ExfInterlockedCompareExchange64(
449 IN OUT LONGLONG volatile *Destination,
450 IN PLONGLONG Exchange,
451 IN PLONGLONG Comperand);
452
453 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
454 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
455
456 #else
457
458 NTKERNELAPI
459 LONGLONG
460 FASTCALL
461 ExInterlockedCompareExchange64(
462 IN OUT LONGLONG volatile *Destination,
463 IN PLONGLONG Exchange,
464 IN PLONGLONG Comparand,
465 IN PKSPIN_LOCK Lock);
466
467 #endif /* defined(_AMD64_) || defined(_IA64_) */
468
469 NTKERNELAPI
470 PLIST_ENTRY
471 FASTCALL
472 ExInterlockedInsertHeadList(
473 IN OUT PLIST_ENTRY ListHead,
474 IN OUT PLIST_ENTRY ListEntry,
475 IN OUT PKSPIN_LOCK Lock);
476
477 NTKERNELAPI
478 PLIST_ENTRY
479 FASTCALL
480 ExInterlockedInsertTailList(
481 IN OUT PLIST_ENTRY ListHead,
482 IN OUT PLIST_ENTRY ListEntry,
483 IN OUT PKSPIN_LOCK Lock);
484
485 NTKERNELAPI
486 PSINGLE_LIST_ENTRY
487 FASTCALL
488 ExInterlockedPopEntryList(
489 IN OUT PSINGLE_LIST_ENTRY ListHead,
490 IN OUT PKSPIN_LOCK Lock);
491
492 NTKERNELAPI
493 PSINGLE_LIST_ENTRY
494 FASTCALL
495 ExInterlockedPushEntryList(
496 IN OUT PSINGLE_LIST_ENTRY ListHead,
497 IN OUT PSINGLE_LIST_ENTRY ListEntry,
498 IN OUT PKSPIN_LOCK Lock);
499
500 NTKERNELAPI
501 PLIST_ENTRY
502 FASTCALL
503 ExInterlockedRemoveHeadList(
504 IN OUT PLIST_ENTRY ListHead,
505 IN OUT PKSPIN_LOCK Lock);
506
507 NTKERNELAPI
508 BOOLEAN
509 NTAPI
510 ExIsProcessorFeaturePresent(
511 IN ULONG ProcessorFeature);
512
513 NTKERNELAPI
514 BOOLEAN
515 NTAPI
516 ExIsResourceAcquiredExclusiveLite(
517 IN PERESOURCE Resource);
518
519 NTKERNELAPI
520 ULONG
521 NTAPI
522 ExIsResourceAcquiredSharedLite(
523 IN PERESOURCE Resource);
524
525 #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
526
527 NTKERNELAPI
528 VOID
529 NTAPI
530 ExLocalTimeToSystemTime(
531 IN PLARGE_INTEGER LocalTime,
532 OUT PLARGE_INTEGER SystemTime);
533
534 NTKERNELAPI
535 VOID
536 NTAPI
537 ExNotifyCallback(
538 IN PCALLBACK_OBJECT CallbackObject,
539 IN PVOID Argument1,
540 IN PVOID Argument2);
541
542 NTKERNELAPI
543 VOID
544 NTAPI
545 ExQueueWorkItem(
546 IN OUT PWORK_QUEUE_ITEM WorkItem,
547 IN WORK_QUEUE_TYPE QueueType);
548
549 NTKERNELAPI
550 DECLSPEC_NORETURN
551 VOID
552 NTAPI
553 ExRaiseStatus(
554 IN NTSTATUS Status);
555
556 NTKERNELAPI
557 PVOID
558 NTAPI
559 ExRegisterCallback(
560 IN PCALLBACK_OBJECT CallbackObject,
561 IN PCALLBACK_FUNCTION CallbackFunction,
562 IN PVOID CallbackContext);
563
564 NTKERNELAPI
565 NTSTATUS
566 NTAPI
567 ExReinitializeResourceLite(
568 IN OUT PERESOURCE Resource);
569
570 NTKERNELAPI
571 VOID
572 NTAPI
573 ExReleaseResourceForThreadLite(
574 IN PERESOURCE Resource,
575 IN ERESOURCE_THREAD ResourceThreadId);
576
577 NTKERNELAPI
578 VOID
579 FASTCALL
580 ExReleaseResourceLite(
581 IN PERESOURCE Resource);
582
583 NTKERNELAPI
584 VOID
585 NTAPI
586 ExSetResourceOwnerPointer(
587 IN PERESOURCE Resource,
588 IN PVOID OwnerPointer);
589
590 NTKERNELAPI
591 ULONG
592 NTAPI
593 ExSetTimerResolution(
594 IN ULONG DesiredTime,
595 IN BOOLEAN SetResolution);
596
597 NTKERNELAPI
598 VOID
599 NTAPI
600 ExSystemTimeToLocalTime(
601 IN PLARGE_INTEGER SystemTime,
602 OUT PLARGE_INTEGER LocalTime);
603
604 NTKERNELAPI
605 VOID
606 NTAPI
607 ExUnregisterCallback(
608 IN PVOID CbRegistration);
609
610 #endif /* (NTDDI_VERSION >= NTDDI_WIN2K) */
611
612 #if (NTDDI_VERSION >= NTDDI_WINXP)
613
614 NTKERNELAPI
615 BOOLEAN
616 FASTCALL
617 ExAcquireRundownProtection(
618 IN OUT PEX_RUNDOWN_REF RunRef);
619
620 NTKERNELAPI
621 VOID
622 FASTCALL
623 ExInitializeRundownProtection(
624 OUT PEX_RUNDOWN_REF RunRef);
625
626 NTKERNELAPI
627 VOID
628 FASTCALL
629 ExReInitializeRundownProtection(
630 OUT PEX_RUNDOWN_REF RunRef);
631
632 NTKERNELAPI
633 VOID
634 FASTCALL
635 ExReleaseRundownProtection(
636 IN OUT PEX_RUNDOWN_REF RunRef);
637
638 NTKERNELAPI
639 VOID
640 FASTCALL
641 ExRundownCompleted(
642 OUT PEX_RUNDOWN_REF RunRef);
643
644 NTKERNELAPI
645 BOOLEAN
646 NTAPI
647 ExVerifySuite(
648 IN SUITE_TYPE SuiteType);
649
650 NTKERNELAPI
651 VOID
652 FASTCALL
653 ExWaitForRundownProtectionRelease(
654 IN OUT PEX_RUNDOWN_REF RunRef);
655
656 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
657
658 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
659
660 NTKERNELAPI
661 BOOLEAN
662 FASTCALL
663 ExAcquireRundownProtectionEx(
664 IN OUT PEX_RUNDOWN_REF RunRef,
665 IN ULONG Count);
666
667 NTKERNELAPI
668 VOID
669 FASTCALL
670 ExReleaseRundownProtectionEx(
671 IN OUT PEX_RUNDOWN_REF RunRef,
672 IN ULONG Count);
673
674 #endif /* (NTDDI_VERSION >= NTDDI_WINXPSP2) */
675
676 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
677
678 NTKERNELAPI
679 PEX_RUNDOWN_REF_CACHE_AWARE
680 NTAPI
681 ExAllocateCacheAwareRundownProtection(
682 IN POOL_TYPE PoolType,
683 IN ULONG PoolTag);
684
685 NTKERNELAPI
686 SIZE_T
687 NTAPI
688 ExSizeOfRundownProtectionCacheAware(VOID);
689
690 #endif /* (NTDDI_VERSION >= NTDDI_WS03SP1) */
691
692 #if (NTDDI_VERSION >= NTDDI_VISTA)
693
694 NTKERNELAPI
695 NTSTATUS
696 NTAPI
697 ExInitializeLookasideListEx(
698 OUT PLOOKASIDE_LIST_EX Lookaside,
699 IN PALLOCATE_FUNCTION_EX Allocate OPTIONAL,
700 IN PFREE_FUNCTION_EX Free OPTIONAL,
701 IN POOL_TYPE PoolType,
702 IN ULONG Flags,
703 IN SIZE_T Size,
704 IN ULONG Tag,
705 IN USHORT Depth);
706
707 NTKERNELAPI
708 VOID
709 NTAPI
710 ExDeleteLookasideListEx(
711 IN OUT PLOOKASIDE_LIST_EX Lookaside);
712
713 NTKERNELAPI
714 VOID
715 NTAPI
716 ExFlushLookasideListEx(
717 IN OUT PLOOKASIDE_LIST_EX Lookaside);
718
719 FORCEINLINE
720 PVOID
721 ExAllocateFromLookasideListEx(
722 IN OUT PLOOKASIDE_LIST_EX Lookaside)
723 {
724 PVOID Entry;
725
726 Lookaside->L.TotalAllocates += 1;
727 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
728 if (Entry == NULL) {
729 Lookaside->L.AllocateMisses += 1;
730 Entry = (Lookaside->L.AllocateEx)(Lookaside->L.Type,
731 Lookaside->L.Size,
732 Lookaside->L.Tag,
733 Lookaside);
734 }
735 return Entry;
736 }
737
738 FORCEINLINE
739 VOID
740 ExFreeToLookasideListEx(
741 IN OUT PLOOKASIDE_LIST_EX Lookaside,
742 IN PVOID Entry)
743 {
744 Lookaside->L.TotalFrees += 1;
745 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
746 Lookaside->L.FreeMisses += 1;
747 (Lookaside->L.FreeEx)(Entry, Lookaside);
748 } else {
749 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
750 }
751 return;
752 }
753
754 #endif /* (NTDDI_VERSION >= NTDDI_VISTA) */
755
756 static __inline PVOID
757 ExAllocateFromNPagedLookasideList(
758 IN OUT PNPAGED_LOOKASIDE_LIST Lookaside)
759 {
760 PVOID Entry;
761
762 Lookaside->L.TotalAllocates++;
763 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
764 Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
765 &Lookaside->Lock__ObsoleteButDoNotDelete);
766 #else
767 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
768 #endif
769 if (Entry == NULL) {
770 Lookaside->L.AllocateMisses++;
771 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
772 Lookaside->L.Size,
773 Lookaside->L.Tag);
774 }
775 return Entry;
776 }
777
778 static __inline VOID
779 ExFreeToNPagedLookasideList(
780 IN OUT PNPAGED_LOOKASIDE_LIST Lookaside,
781 IN PVOID Entry)
782 {
783 Lookaside->L.TotalFrees++;
784 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
785 Lookaside->L.FreeMisses++;
786 (Lookaside->L.Free)(Entry);
787 } else {
788 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
789 ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
790 (PSLIST_ENTRY)Entry,
791 &Lookaside->Lock__ObsoleteButDoNotDelete);
792 #else
793 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
794 #endif
795 }
796 }
797
798 $endif
799