44084344a1247ff1dd35fe34fcaff3441d7d6d1d
[reactos.git] / reactos / include / ddk / exfuncs.h
1 #ifndef _NTOS_EXFUNCS_H
2 #define _NTOS_EXFUNCS_H
3
4 /* EXECUTIVE ROUTINES ******************************************************/
5
6 #ifdef __NTOSKRNL__
7 extern POBJECT_TYPE EXPORTED ExDesktopObjectType;
8 extern POBJECT_TYPE EXPORTED ExEventObjectType;
9 extern POBJECT_TYPE EXPORTED ExWindowStationObjectType;
10 extern POBJECT_TYPE EXPORTED ExIoCompletionType;
11 #else
12 extern POBJECT_TYPE IMPORTED ExDesktopObjectType;
13 extern POBJECT_TYPE IMPORTED ExEventObjectType;
14 extern POBJECT_TYPE IMPORTED ExWindowStationObjectType;
15 extern POBJECT_TYPE IMPORTED ExIoCompletionType;
16 #endif
17
18 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
19
20 VOID
21 FASTCALL
22 ExAcquireFastMutex (
23 PFAST_MUTEX FastMutex
24 );
25 VOID
26 FASTCALL
27 ExAcquireFastMutexUnsafe (
28 PFAST_MUTEX FastMutex
29 );
30 BOOLEAN
31 STDCALL
32 ExAcquireResourceExclusive (
33 PERESOURCE Resource,
34 BOOLEAN Wait
35 );
36 BOOLEAN
37 STDCALL
38 ExAcquireResourceExclusiveLite (
39 PERESOURCE Resource,
40 BOOLEAN Wait
41 );
42 BOOLEAN
43 STDCALL
44 ExAcquireResourceSharedLite (
45 PERESOURCE Resource,
46 BOOLEAN Wait
47 );
48 BOOLEAN
49 FASTCALL
50 ExAcquireRundownProtection (
51 IN PEX_RUNDOWN_REF RunRef
52 );
53 BOOLEAN
54 FASTCALL
55 ExAcquireRundownProtectionEx (
56 IN PEX_RUNDOWN_REF RunRef,
57 IN ULONG Count
58 );
59 PVOID
60 FASTCALL
61 ExfAcquirePushLockExclusive (
62 PVOID Lock
63 );
64 PVOID
65 FASTCALL
66 ExfAcquirePushLockShared (
67 PVOID Lock
68 );
69 PVOID
70 FASTCALL
71 ExfReleasePushLock (
72 PVOID Lock
73 );
74 BOOLEAN
75 STDCALL
76 ExAcquireSharedStarveExclusive (
77 PERESOURCE Resource,
78 BOOLEAN Wait
79 );
80 BOOLEAN
81 STDCALL
82 ExAcquireSharedWaitForExclusive (
83 PERESOURCE Resource,
84 BOOLEAN Wait
85 );
86
87 PVOID
88 STDCALL
89 ExAllocateFromZone (
90 PZONE_HEADER Zone
91 );
92
93 /*
94 * PVOID
95 * ExAllocateFromZone (
96 * PZONE_HEADER Zone
97 * );
98 *
99 * FUNCTION:
100 * Allocate a block from a zone
101 *
102 * ARGUMENTS:
103 * Zone = Zone to allocate from
104 *
105 * RETURNS:
106 * The base address of the block allocated
107 */
108 #define ExAllocateFromZone(Zone) \
109 (PVOID)((Zone)->FreeList.Next); \
110 if ((Zone)->FreeList.Next) \
111 (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
112
113 /*
114 * FUNCTION: Allocates memory from the nonpaged pool
115 * ARGUMENTS:
116 * NumberOfBytes = minimum size of the block to be allocated
117 * PoolType = the type of memory to use for the block (ignored)
118 * RETURNS:
119 * the address of the block if it succeeds
120 */
121 PVOID
122 STDCALL
123 ExAllocatePool (
124 IN POOL_TYPE PoolType,
125 IN ULONG NumberOfBytes
126 );
127
128 PVOID
129 STDCALL
130 ExAllocatePoolWithQuota (
131 IN POOL_TYPE PoolType,
132 IN ULONG NumberOfBytes
133 );
134 PVOID
135 STDCALL
136 ExAllocatePoolWithQuotaTag (
137 IN POOL_TYPE PoolType,
138 IN ULONG NumberOfBytes,
139 IN ULONG Tag
140 );
141 PVOID
142 STDCALL
143 ExAllocatePoolWithTag (
144 IN POOL_TYPE PoolType,
145 IN ULONG NumberOfBytes,
146 IN ULONG Tag
147 );
148
149 PVOID
150 NTAPI
151 ExAllocatePoolWithTagPriority(
152 IN POOL_TYPE PoolType,
153 IN SIZE_T NumberOfBytes,
154 IN ULONG Tag,
155 IN EX_POOL_PRIORITY Priority
156 );
157
158 VOID
159 STDCALL
160 ExConvertExclusiveToSharedLite (
161 PERESOURCE Resource
162 );
163
164 NTSTATUS
165 STDCALL
166 ExCreateCallback (
167 OUT PCALLBACK_OBJECT * CallbackObject,
168 IN POBJECT_ATTRIBUTES ObjectAttributes,
169 IN BOOLEAN Create,
170 IN BOOLEAN AllowMultipleCallbacks
171 );
172
173 NTSTATUS
174 STDCALL
175 ExDeleteResource (
176 PERESOURCE Resource
177 );
178 NTSTATUS
179 STDCALL
180 ExDeleteResourceLite (
181 PERESOURCE Resource
182 );
183
184 VOID
185 STDCALL
186 ExDisableResourceBoostLite (
187 PERESOURCE Resource
188 );
189
190 VOID
191 STDCALL
192 ExEnumHandleTable (
193 PULONG HandleTable,
194 PVOID Callback,
195 PVOID Param,
196 PHANDLE Handle OPTIONAL
197 );
198
199 NTSTATUS
200 STDCALL
201 ExExtendZone (
202 PZONE_HEADER Zone,
203 PVOID Segment,
204 ULONG SegmentSize
205 );
206
207 /*
208 * FUNCTION: Releases previously allocated memory
209 * ARGUMENTS:
210 * block = block to free
211 */
212 VOID
213 STDCALL
214 ExFreePool (
215 PVOID block
216 );
217
218 /*
219 * PVOID
220 * ExFreeToZone (
221 * PZONE_HEADER Zone,
222 * PVOID Block
223 * );
224 *
225 * FUNCTION:
226 * Frees a block from a zone
227 *
228 * ARGUMENTS:
229 * Zone = Zone the block was allocated from
230 * Block = Block to free
231 */
232 #define ExFreeToZone(Zone,Block) \
233 (((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
234 (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
235 ((PSINGLE_LIST_ENTRY)(Block))->Next)
236
237 /*
238 * ERESOURCE_THREAD
239 * ExGetCurrentResourceThread (
240 * VOID
241 * );
242 */
243 #define ExGetCurrentResourceThread() \
244 ((ERESOURCE_THREAD)KeGetCurrentThread())
245
246 LONGLONG
247 FASTCALL
248 ExfInterlockedCompareExchange64(
249 IN OUT LONGLONG volatile *Destination,
250 IN PLONGLONG ExChange,
251 IN PLONGLONG Comperand
252 );
253
254 VOID
255 STDCALL
256 ExGetCurrentProcessorCounts (
257 PULONG ThreadKernelTime,
258 PULONG TotalCpuTime,
259 PULONG ProcessorNumber
260 );
261
262 VOID
263 STDCALL
264 ExGetCurrentProcessorCpuUsage (
265 PULONG CpuUsage
266 );
267
268 ULONG
269 STDCALL
270 ExGetExclusiveWaiterCount (
271 PERESOURCE Resource
272 );
273
274 KPROCESSOR_MODE
275 STDCALL
276 ExGetPreviousMode (
277 VOID
278 );
279
280 ULONG
281 STDCALL
282 ExGetSharedWaiterCount (
283 PERESOURCE Resource
284 );
285
286 /*
287 * VOID
288 * ExInitializeFastMutex (
289 * PFAST_MUTEX FastMutex
290 * );
291 */
292 #define ExInitializeFastMutex(_FastMutex) \
293 ((PFAST_MUTEX)_FastMutex)->Count = 1; \
294 ((PFAST_MUTEX)_FastMutex)->Owner = NULL; \
295 ((PFAST_MUTEX)_FastMutex)->Contention = 0; \
296 KeInitializeEvent(&((PFAST_MUTEX)_FastMutex)->Event, \
297 SynchronizationEvent, \
298 FALSE);
299
300 NTSTATUS
301 STDCALL
302 ExInitializeResource (
303 PERESOURCE Resource
304 );
305 NTSTATUS
306 STDCALL
307 ExInitializeResourceLite (
308 PERESOURCE Resource
309 );
310
311 VOID
312 FASTCALL
313 ExInitializeRundownProtection (
314 IN PEX_RUNDOWN_REF RunRef
315 );
316
317 /*
318 * VOID
319 * ExInitializeSListHead (
320 * PSLIST_HEADER SListHead
321 * );
322 */
323 #define ExInitializeSListHead(ListHead) \
324 (ListHead)->Alignment = 0
325
326 /*
327 * VOID
328 * ExInitializeWorkItem (
329 * PWORK_QUEUE_ITEM Item,
330 * PWORKER_THREAD_ROUTINE Routine,
331 * PVOID Context
332 * );
333 *
334 * FUNCTION:
335 * Initializes a work item to be processed by one of the system
336 * worker threads
337 *
338 * ARGUMENTS:
339 * Item = Pointer to the item to be initialized
340 * Routine = Routine to be called by the worker thread
341 * Context = Parameter to be passed to the callback
342 */
343 #define ExInitializeWorkItem(Item, Routine, RoutineContext) \
344 ASSERT_IRQL(DISPATCH_LEVEL); \
345 (Item)->WorkerRoutine = (Routine); \
346 (Item)->Parameter = (RoutineContext); \
347 (Item)->List.Flink = NULL; \
348 (Item)->List.Blink = NULL;
349
350 NTSTATUS
351 STDCALL
352 ExInitializeZone (
353 PZONE_HEADER Zone,
354 ULONG BlockSize,
355 PVOID InitialSegment,
356 ULONG InitialSegmentSize
357 );
358
359 LARGE_INTEGER
360 STDCALL
361 ExInterlockedAddLargeInteger (
362 PLARGE_INTEGER Addend,
363 LARGE_INTEGER Increment,
364 PKSPIN_LOCK Lock
365 );
366
367 VOID
368 FASTCALL
369 ExInterlockedAddLargeStatistic (
370 IN PLARGE_INTEGER Addend,
371 IN ULONG Increment
372 );
373
374 ULONG
375 STDCALL
376 ExInterlockedAddUlong (
377 PULONG Addend,
378 ULONG Increment,
379 PKSPIN_LOCK Lock
380 );
381
382 /*
383 * PVOID
384 * STDCALL
385 * ExInterlockedAllocateFromZone (
386 * PZONE_HEADER Zone,
387 * PKSPIN_LOCK Lock
388 * );
389 */
390 #define ExInterlockedAllocateFromZone(Zone,Lock) \
391 (PVOID)ExInterlockedPopEntryList(&(Zone)->FreeList,Lock)
392
393 LONGLONG
394 FASTCALL
395 ExInterlockedCompareExchange64 (
396 IN OUT PLONGLONG Destination,
397 IN PLONGLONG Exchange,
398 IN PLONGLONG Comparand,
399 IN PKSPIN_LOCK Lock
400 );
401
402 INTERLOCKED_RESULT
403 STDCALL
404 ExInterlockedDecrementLong (
405 PLONG Addend,
406 PKSPIN_LOCK Lock
407 );
408
409 ULONG
410 STDCALL
411 ExInterlockedExchangeUlong (
412 PULONG Target,
413 ULONG Value,
414 PKSPIN_LOCK Lock
415 );
416
417 NTSTATUS
418 STDCALL
419 ExInterlockedExtendZone (
420 PZONE_HEADER Zone,
421 PVOID Segment,
422 ULONG SegmentSize,
423 PKSPIN_LOCK Lock
424 );
425
426 PSLIST_ENTRY
427 FASTCALL
428 ExInterlockedFlushSList (
429 IN PSLIST_HEADER ListHead
430 );
431
432 /*
433 * PVOID
434 * ExInterlockedFreeToZone (
435 * PZONE_HEADER Zone,
436 * PVOID Block,
437 * PKSPIN_LOCK Lock
438 * );
439 */
440 #define ExInterlockedFreeToZone(Zone,Block,Lock) \
441 ExInterlockedPushEntryList(&(Zone)->FreeList,((PSINGLE_LIST_ENTRY)(Block)),(Lock))
442
443 INTERLOCKED_RESULT
444 STDCALL
445 ExInterlockedIncrementLong (
446 PLONG Addend,
447 PKSPIN_LOCK Lock
448 );
449 PLIST_ENTRY
450 STDCALL
451 ExInterlockedInsertHeadList (
452 PLIST_ENTRY ListHead,
453 PLIST_ENTRY ListEntry,
454 PKSPIN_LOCK Lock
455 );
456 PLIST_ENTRY
457 STDCALL
458 ExInterlockedInsertTailList (
459 PLIST_ENTRY ListHead,
460 PLIST_ENTRY ListEntry,
461 PKSPIN_LOCK Lock
462 );
463 PSINGLE_LIST_ENTRY
464 STDCALL
465 ExInterlockedPopEntryList (
466 PSINGLE_LIST_ENTRY ListHead,
467 PKSPIN_LOCK Lock
468 );
469 PSINGLE_LIST_ENTRY
470 FASTCALL
471 ExInterlockedPopEntrySList (
472 PSLIST_HEADER ListHead,
473 PKSPIN_LOCK Lock
474 );
475 PSINGLE_LIST_ENTRY
476 STDCALL
477 ExInterlockedPushEntryList (
478 PSINGLE_LIST_ENTRY ListHead,
479 PSINGLE_LIST_ENTRY ListEntry,
480 PKSPIN_LOCK Lock
481 );
482 PSINGLE_LIST_ENTRY
483 FASTCALL
484 ExInterlockedPushEntrySList (
485 PSLIST_HEADER ListHead,
486 PSINGLE_LIST_ENTRY ListEntry,
487 PKSPIN_LOCK Lock
488 );
489 PLIST_ENTRY
490 STDCALL
491 ExInterlockedRemoveHeadList (
492 PLIST_ENTRY Head,
493 PKSPIN_LOCK Lock
494 );
495
496 /*
497 * BOOLEAN
498 * ExIsFullZone (
499 * PZONE_HEADER Zone
500 * );
501 */
502 #define ExIsFullZone(Zone) \
503 ((Zone)->FreeList.Next==(PSINGLE_LIST_ENTRY)NULL)
504
505 /*
506 * BOOLEAN
507 * ExIsObjectInFirstZoneSegment (
508 * PZONE_HEADER Zone,
509 * PVOID Object
510 * );
511 */
512 #define ExIsObjectInFirstZoneSegment(Zone,Object) \
513 (((PUCHAR)(Object)>=(PUCHAR)(Zone)->SegmentList.Next) && \
514 ((PUCHAR)(Object)<(PUCHAR)(Zone)->SegmentList.Next+(Zone)->TotalSegmentSize))
515
516 BOOLEAN
517 STDCALL
518 ExIsProcessorFeaturePresent (
519 IN ULONG ProcessorFeature
520 );
521
522 BOOLEAN
523 STDCALL
524 ExIsResourceAcquiredExclusiveLite (
525 PERESOURCE Resource
526 );
527
528 /* was ULONG */
529 USHORT
530 STDCALL
531 ExIsResourceAcquiredSharedLite (
532 PERESOURCE Resource
533 );
534
535 VOID
536 STDCALL
537 ExLocalTimeToSystemTime (
538 PLARGE_INTEGER LocalTime,
539 PLARGE_INTEGER SystemTime
540 );
541
542 VOID
543 STDCALL
544 ExNotifyCallback (
545 IN PCALLBACK_OBJECT CallbackObject,
546 IN PVOID Argument1,
547 IN PVOID Argument2
548 );
549
550 VOID
551 STDCALL
552 ExPostSystemEvent (
553 ULONG Unknown1,
554 ULONG Unknown2,
555 ULONG Unknown3
556 );
557
558 /*
559 * USHORT
560 * ExQueryDepthSList (
561 * PSLIST_HEADER SListHead
562 * );
563 */
564 #define ExQueryDepthSList(ListHead) \
565 (USHORT)(ListHead)->Depth
566
567 VOID
568 STDCALL
569 ExQueueWorkItem (
570 PWORK_QUEUE_ITEM WorkItem,
571 WORK_QUEUE_TYPE QueueType
572 );
573
574 SIZE_T
575 STDCALL
576 ExQueryPoolBlockSize (
577 IN PVOID PoolBlock,
578 OUT PBOOLEAN QuotaCharged
579 );
580
581 VOID
582 STDCALL
583 ExRaiseAccessViolation (
584 VOID
585 );
586 VOID
587 STDCALL
588 ExRaiseDatatypeMisalignment (
589 VOID
590 );
591 VOID
592 STDCALL
593 ExRaiseStatus (
594 NTSTATUS Status
595 );
596 VOID
597 STDCALL
598 ExRaiseException (
599 PEXCEPTION_RECORD pExcptRec
600 );
601 VOID
602 STDCALL
603 ExRaiseHardError (
604 IN NTSTATUS ErrorStatus,
605 IN ULONG NumberOfParameters,
606 IN PUNICODE_STRING UnicodeStringParameterMask OPTIONAL,
607 IN PVOID *Parameters,
608 IN HARDERROR_RESPONSE_OPTION ResponseOption,
609 OUT PHARDERROR_RESPONSE Response
610 );
611
612 PVOID
613 STDCALL
614 ExRegisterCallback (
615 IN PCALLBACK_OBJECT CallbackObject,
616 IN PCALLBACK_FUNCTION CallbackFunction,
617 IN PVOID CallbackContext
618 );
619
620 VOID
621 STDCALL
622 ExReinitializeResourceLite (
623 PERESOURCE Resource
624 );
625 VOID
626 FASTCALL
627 ExReInitializeRundownProtection (
628 IN PEX_RUNDOWN_REF RunRef
629 );
630
631 /* ReactOS Specific: begin */
632 VOID
633 FASTCALL
634 ExReleaseFastMutex (
635 PFAST_MUTEX Mutex
636 );
637 /* ReactOS Specific: end */
638 VOID
639 FASTCALL
640 ExReleaseFastMutexUnsafe (
641 PFAST_MUTEX Mutex
642 );
643 /*
644 VOID
645 STDCALL
646 ExReleaseResource (
647 PERESOURCE Resource
648 );
649 */
650 #define ExReleaseResource(Resource) \
651 (ExReleaseResourceLite (Resource))
652
653 VOID
654 FASTCALL
655 ExReleaseResourceLite (
656 PERESOURCE Resource
657 );
658 VOID
659 STDCALL
660 ExReleaseResourceForThread (
661 PERESOURCE Resource,
662 ERESOURCE_THREAD ResourceThreadId
663 );
664 VOID
665 STDCALL
666 ExReleaseResourceForThreadLite (
667 PERESOURCE Resource,
668 ERESOURCE_THREAD ResourceThreadId
669 );
670 VOID
671 FASTCALL
672 ExReleaseRundownProtection (
673 IN PEX_RUNDOWN_REF RunRef
674 );
675 VOID
676 FASTCALL
677 ExReleaseRundownProtectionEx (
678 IN PEX_RUNDOWN_REF RunRef,
679 IN ULONG Count
680 );
681 /* ReactOS Specific: begin */
682 VOID STDCALL
683 ExRosDumpPagedPoolByTag (
684 IN ULONG Tag
685 );
686 ULONG STDCALL
687 ExRosQueryPoolTag (
688 IN PVOID Block
689 );
690 /* ReactOS Specific: end */
691 VOID
692 FASTCALL
693 ExRundownCompleted (
694 IN PEX_RUNDOWN_REF RunRef
695 );
696 VOID
697 STDCALL
698 ExSetResourceOwnerPointer (
699 IN PERESOURCE Resource,
700 IN PVOID OwnerPointer
701 );
702
703 VOID
704 STDCALL
705 ExSetTimerResolution (
706 IN ULONG DesiredTime,
707 IN BOOLEAN SetResolution
708 );
709
710 BOOLEAN
711 STDCALL
712 ExVerifySuite(
713 SUITE_TYPE SuiteType
714 );
715
716 BOOLEAN
717 STDCALL
718 ExSystemExceptionFilter();
719
720 VOID
721 STDCALL
722 ExSystemTimeToLocalTime (
723 PLARGE_INTEGER SystemTime,
724 PLARGE_INTEGER LocalTime
725 );
726
727 BOOLEAN
728 FASTCALL
729 ExTryToAcquireFastMutex (
730 PFAST_MUTEX FastMutex
731 );
732
733 BOOLEAN
734 STDCALL
735 ExTryToAcquireResourceExclusiveLite (
736 PERESOURCE Resource
737 );
738
739 VOID
740 STDCALL
741 ExUnregisterCallback (
742 IN PVOID CallbackRegistration
743 );
744
745 typedef GUID UUID;
746
747 NTSTATUS
748 STDCALL
749 ExUuidCreate(
750 OUT UUID *Uuid
751 );
752
753 VOID
754 FASTCALL
755 ExWaitForRundownProtectionRelease (
756 IN PEX_RUNDOWN_REF RunRef
757 );
758
759 PSLIST_ENTRY
760 FASTCALL
761 InterlockedPopEntrySList (
762 IN PSLIST_HEADER ListHead
763 );
764
765 PSLIST_ENTRY
766 FASTCALL
767 InterlockedPushEntrySList(
768 IN PSLIST_HEADER ListHead,
769 IN PSLIST_ENTRY ListEntry
770 );
771
772 /*
773 * PVOID
774 * ExAllocateFromNPagedLookasideList (
775 * PNPAGED_LOOKASIDE_LIST LookSide
776 * );
777 *
778 * FUNCTION:
779 * Removes (pops) the first entry from the specified nonpaged
780 * lookaside list.
781 *
782 * ARGUMENTS:
783 * Lookaside = Pointer to a nonpaged lookaside list
784 *
785 * RETURNS:
786 * Address of the allocated list entry
787 */
788 static
789 inline
790 PVOID
791 ExAllocateFromNPagedLookasideList (
792 IN PNPAGED_LOOKASIDE_LIST Lookaside
793 )
794 {
795 PVOID Entry;
796
797 Lookaside->TotalAllocates++;
798 Entry = ExInterlockedPopEntrySList (&Lookaside->ListHead,
799 &Lookaside->Obsoleted);
800 if (Entry == NULL)
801 {
802 Lookaside->AllocateMisses++;
803 Entry = (Lookaside->Allocate)(Lookaside->Type,
804 Lookaside->Size,
805 Lookaside->Tag);
806 }
807
808 return Entry;
809 }
810
811 static inline PVOID
812 ExAllocateFromPagedLookasideList(
813 IN PPAGED_LOOKASIDE_LIST Lookaside)
814 {
815 PVOID Entry;
816
817 Lookaside->TotalAllocates++;
818 Entry = InterlockedPopEntrySList(&Lookaside->ListHead);
819 if (Entry == NULL) {
820 Lookaside->AllocateMisses++;
821 Entry = (Lookaside->Allocate)(Lookaside->Type,
822 Lookaside->Size, Lookaside->Tag);
823 }
824 return Entry;
825 }
826
827 VOID
828 STDCALL
829 ExDeleteNPagedLookasideList (
830 PNPAGED_LOOKASIDE_LIST Lookaside
831 );
832
833 VOID
834 STDCALL
835 ExDeletePagedLookasideList (
836 PPAGED_LOOKASIDE_LIST Lookaside
837 );
838
839
840 /*
841 * VOID
842 * ExFreeToNPagedLookasideList (
843 * PNPAGED_LOOKASIDE_LIST Lookaside,
844 * PVOID Entry
845 * );
846 *
847 * FUNCTION:
848 * Inserts (pushes) the specified entry into the specified
849 * nonpaged lookaside list.
850 *
851 * ARGUMENTS:
852 * Lookaside = Pointer to the nonpaged lookaside list
853 * Entry = Pointer to the entry that is inserted in the lookaside list
854 */
855 static
856 inline
857 VOID
858 ExFreeToNPagedLookasideList (
859 IN PNPAGED_LOOKASIDE_LIST Lookaside,
860 IN PVOID Entry
861 )
862 {
863 Lookaside->TotalFrees++;
864 if (ExQueryDepthSList (&Lookaside->ListHead) >= Lookaside->Depth)
865 {
866 Lookaside->FreeMisses++;
867 (Lookaside->Free)(Entry);
868 }
869 else
870 {
871 ExInterlockedPushEntrySList (&Lookaside->ListHead,
872 (PSINGLE_LIST_ENTRY)Entry,
873 &Lookaside->Obsoleted);
874 }
875 }
876
877 static inline VOID
878 ExFreeToPagedLookasideList(
879 IN PPAGED_LOOKASIDE_LIST Lookaside,
880 IN PVOID Entry)
881 {
882 Lookaside->TotalFrees++;
883 if (ExQueryDepthSList(&Lookaside->ListHead) >= Lookaside->Depth) {
884 Lookaside->FreeMisses++;
885 (Lookaside->Free)(Entry);
886 } else {
887 InterlockedPushEntrySList(&Lookaside->ListHead, (PSLIST_ENTRY)Entry);
888 }
889 }
890
891 VOID
892 STDCALL
893 ExInitializeNPagedLookasideList (
894 PNPAGED_LOOKASIDE_LIST Lookaside,
895 PALLOCATE_FUNCTION Allocate,
896 PFREE_FUNCTION Free,
897 ULONG Flags,
898 ULONG Size,
899 ULONG Tag,
900 USHORT Depth
901 );
902
903 VOID
904 STDCALL
905 ExInitializePagedLookasideList (
906 PPAGED_LOOKASIDE_LIST Lookaside,
907 PALLOCATE_FUNCTION Allocate,
908 PFREE_FUNCTION Free,
909 ULONG Flags,
910 ULONG Size,
911 ULONG Tag,
912 USHORT Depth
913 );
914
915 ULONG FASTCALL
916 ExfInterlockedAddUlong(IN PULONG Addend,
917 IN ULONG Increment,
918 IN PKSPIN_LOCK Lock);
919
920 PLIST_ENTRY FASTCALL
921 ExfInterlockedInsertHeadList(IN PLIST_ENTRY ListHead,
922 IN PLIST_ENTRY ListEntry,
923 IN PKSPIN_LOCK Lock);
924
925 PLIST_ENTRY FASTCALL
926 ExfInterlockedInsertTailList(IN PLIST_ENTRY ListHead,
927 IN PLIST_ENTRY ListEntry,
928 IN PKSPIN_LOCK Lock);
929
930 PSINGLE_LIST_ENTRY FASTCALL
931 ExfInterlockedPopEntryList(IN PSINGLE_LIST_ENTRY ListHead,
932 IN PKSPIN_LOCK Lock);
933
934 PSINGLE_LIST_ENTRY FASTCALL
935 ExfInterlockedPushEntryList(IN PSINGLE_LIST_ENTRY ListHead,
936 IN PSINGLE_LIST_ENTRY ListEntry,
937 IN PKSPIN_LOCK Lock);
938
939 PLIST_ENTRY FASTCALL
940 ExfInterlockedRemoveHeadList(IN PLIST_ENTRY Head,
941 IN PKSPIN_LOCK Lock);
942
943 INTERLOCKED_RESULT FASTCALL
944 Exfi386InterlockedIncrementLong(IN PLONG Addend);
945
946 INTERLOCKED_RESULT FASTCALL
947 Exfi386InterlockedDecrementLong(IN PLONG Addend);
948
949 ULONG FASTCALL
950 Exfi386InterlockedExchangeUlong(IN PULONG Target,
951 IN ULONG Value);
952
953 INTERLOCKED_RESULT STDCALL
954 Exi386InterlockedIncrementLong(IN PLONG Addend);
955
956 INTERLOCKED_RESULT STDCALL
957 Exi386InterlockedDecrementLong(IN PLONG Addend);
958
959 ULONG STDCALL
960 Exi386InterlockedExchangeUlong(IN PULONG Target,
961 IN ULONG Value);
962
963
964 LONG
965 FASTCALL
966 InterlockedCompareExchange (
967 PLONG Destination,
968 LONG Exchange,
969 LONG Comperand
970 );
971
972 #ifdef _GNU_H_WINDOWS_H
973 #ifdef InterlockedDecrement
974 #undef InterlockedDecrement
975 #undef InterlockedExchange
976 #undef InterlockedExchangeAdd
977 #undef InterlockedIncrement
978 #endif /* def InterlockedDecrement */
979 #endif /* def _GNU_H_WINDOWS_H */
980 LONG
981 FASTCALL
982 InterlockedDecrement (
983 PLONG Addend
984 );
985 LONG
986 FASTCALL
987 InterlockedExchange (
988 PLONG Target,
989 LONG Value
990 );
991 LONG
992 FASTCALL
993 InterlockedExchangeAdd (
994 PLONG Addend,
995 LONG Value
996 );
997 LONG
998 FASTCALL
999 InterlockedIncrement (
1000 PLONG Addend
1001 );
1002
1003 #ifndef InterlockedExchangePointer
1004 # ifdef _WIN64
1005 # define InterlockedExchangePointer(__T__, __V__) \
1006 (PVOID)InterlockedExchange64((PLONGLONG)(__T__), (LONGLONG)(__V__))
1007 # else
1008 # define InterlockedExchangePointer(__T__, __V__) \
1009 (PVOID)InterlockedExchange((PLONG)(__T__), (LONG)(__V__))
1010 # endif
1011 #endif
1012
1013 #ifndef InterlockedCompareExchangePointer
1014 # ifdef _WIN64
1015 # define InterlockedCompareExchangePointer(__T__, __V__, __C__) \
1016 (PVOID)InterlockedCompareExchange64((PLONGLONG)(__T__), (LONGLONG)(__V__), (LONGLONG)(__C__))
1017 # else
1018 # define InterlockedCompareExchangePointer(__T__, __V__, __C__) \
1019 (PVOID)InterlockedCompareExchange((PLONG)(__T__), (LONG)(__V__), (LONG)(__C__))
1020 # endif
1021 #endif
1022
1023 /*---*/
1024
1025 typedef
1026 unsigned int
1027 (*exception_hook) (
1028 CONTEXT * c,
1029 unsigned int exp
1030 );
1031 unsigned int
1032 ExHookException (
1033 exception_hook fn,
1034 unsigned int exp
1035 );
1036
1037 #endif /* ndef _NTOS_EXFUNCS_H */