ExInitializeWorkItem: synch with Windows (only NULL the Flink)
[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
349 NTSTATUS
350 STDCALL
351 ExInitializeZone (
352 PZONE_HEADER Zone,
353 ULONG BlockSize,
354 PVOID InitialSegment,
355 ULONG InitialSegmentSize
356 );
357
358 LARGE_INTEGER
359 STDCALL
360 ExInterlockedAddLargeInteger (
361 PLARGE_INTEGER Addend,
362 LARGE_INTEGER Increment,
363 PKSPIN_LOCK Lock
364 );
365
366 VOID
367 FASTCALL
368 ExInterlockedAddLargeStatistic (
369 IN PLARGE_INTEGER Addend,
370 IN ULONG Increment
371 );
372
373 ULONG
374 STDCALL
375 ExInterlockedAddUlong (
376 PULONG Addend,
377 ULONG Increment,
378 PKSPIN_LOCK Lock
379 );
380
381 /*
382 * PVOID
383 * STDCALL
384 * ExInterlockedAllocateFromZone (
385 * PZONE_HEADER Zone,
386 * PKSPIN_LOCK Lock
387 * );
388 */
389 #define ExInterlockedAllocateFromZone(Zone,Lock) \
390 (PVOID)ExInterlockedPopEntryList(&(Zone)->FreeList,Lock)
391
392 LONGLONG
393 FASTCALL
394 ExInterlockedCompareExchange64 (
395 IN OUT PLONGLONG Destination,
396 IN PLONGLONG Exchange,
397 IN PLONGLONG Comparand,
398 IN PKSPIN_LOCK Lock
399 );
400
401 INTERLOCKED_RESULT
402 STDCALL
403 ExInterlockedDecrementLong (
404 PLONG Addend,
405 PKSPIN_LOCK Lock
406 );
407
408 ULONG
409 STDCALL
410 ExInterlockedExchangeUlong (
411 PULONG Target,
412 ULONG Value,
413 PKSPIN_LOCK Lock
414 );
415
416 NTSTATUS
417 STDCALL
418 ExInterlockedExtendZone (
419 PZONE_HEADER Zone,
420 PVOID Segment,
421 ULONG SegmentSize,
422 PKSPIN_LOCK Lock
423 );
424
425 PSLIST_ENTRY
426 FASTCALL
427 ExInterlockedFlushSList (
428 IN PSLIST_HEADER ListHead
429 );
430
431 /*
432 * PVOID
433 * ExInterlockedFreeToZone (
434 * PZONE_HEADER Zone,
435 * PVOID Block,
436 * PKSPIN_LOCK Lock
437 * );
438 */
439 #define ExInterlockedFreeToZone(Zone,Block,Lock) \
440 ExInterlockedPushEntryList(&(Zone)->FreeList,((PSINGLE_LIST_ENTRY)(Block)),(Lock))
441
442 INTERLOCKED_RESULT
443 STDCALL
444 ExInterlockedIncrementLong (
445 PLONG Addend,
446 PKSPIN_LOCK Lock
447 );
448 PLIST_ENTRY
449 STDCALL
450 ExInterlockedInsertHeadList (
451 PLIST_ENTRY ListHead,
452 PLIST_ENTRY ListEntry,
453 PKSPIN_LOCK Lock
454 );
455 PLIST_ENTRY
456 STDCALL
457 ExInterlockedInsertTailList (
458 PLIST_ENTRY ListHead,
459 PLIST_ENTRY ListEntry,
460 PKSPIN_LOCK Lock
461 );
462 PSINGLE_LIST_ENTRY
463 STDCALL
464 ExInterlockedPopEntryList (
465 PSINGLE_LIST_ENTRY ListHead,
466 PKSPIN_LOCK Lock
467 );
468 PSINGLE_LIST_ENTRY
469 FASTCALL
470 ExInterlockedPopEntrySList (
471 PSLIST_HEADER ListHead,
472 PKSPIN_LOCK Lock
473 );
474 PSINGLE_LIST_ENTRY
475 STDCALL
476 ExInterlockedPushEntryList (
477 PSINGLE_LIST_ENTRY ListHead,
478 PSINGLE_LIST_ENTRY ListEntry,
479 PKSPIN_LOCK Lock
480 );
481 PSINGLE_LIST_ENTRY
482 FASTCALL
483 ExInterlockedPushEntrySList (
484 PSLIST_HEADER ListHead,
485 PSINGLE_LIST_ENTRY ListEntry,
486 PKSPIN_LOCK Lock
487 );
488 PLIST_ENTRY
489 STDCALL
490 ExInterlockedRemoveHeadList (
491 PLIST_ENTRY Head,
492 PKSPIN_LOCK Lock
493 );
494
495 /*
496 * BOOLEAN
497 * ExIsFullZone (
498 * PZONE_HEADER Zone
499 * );
500 */
501 #define ExIsFullZone(Zone) \
502 ((Zone)->FreeList.Next==(PSINGLE_LIST_ENTRY)NULL)
503
504 /*
505 * BOOLEAN
506 * ExIsObjectInFirstZoneSegment (
507 * PZONE_HEADER Zone,
508 * PVOID Object
509 * );
510 */
511 #define ExIsObjectInFirstZoneSegment(Zone,Object) \
512 (((PUCHAR)(Object)>=(PUCHAR)(Zone)->SegmentList.Next) && \
513 ((PUCHAR)(Object)<(PUCHAR)(Zone)->SegmentList.Next+(Zone)->TotalSegmentSize))
514
515 BOOLEAN
516 STDCALL
517 ExIsProcessorFeaturePresent (
518 IN ULONG ProcessorFeature
519 );
520
521 BOOLEAN
522 STDCALL
523 ExIsResourceAcquiredExclusiveLite (
524 PERESOURCE Resource
525 );
526
527 /* was ULONG */
528 USHORT
529 STDCALL
530 ExIsResourceAcquiredSharedLite (
531 PERESOURCE Resource
532 );
533
534 VOID
535 STDCALL
536 ExLocalTimeToSystemTime (
537 PLARGE_INTEGER LocalTime,
538 PLARGE_INTEGER SystemTime
539 );
540
541 VOID
542 STDCALL
543 ExNotifyCallback (
544 IN PCALLBACK_OBJECT CallbackObject,
545 IN PVOID Argument1,
546 IN PVOID Argument2
547 );
548
549 VOID
550 STDCALL
551 ExPostSystemEvent (
552 ULONG Unknown1,
553 ULONG Unknown2,
554 ULONG Unknown3
555 );
556
557 /*
558 * USHORT
559 * ExQueryDepthSList (
560 * PSLIST_HEADER SListHead
561 * );
562 */
563 #define ExQueryDepthSList(ListHead) \
564 (USHORT)(ListHead)->Depth
565
566 VOID
567 STDCALL
568 ExQueueWorkItem (
569 PWORK_QUEUE_ITEM WorkItem,
570 WORK_QUEUE_TYPE QueueType
571 );
572
573 SIZE_T
574 STDCALL
575 ExQueryPoolBlockSize (
576 IN PVOID PoolBlock,
577 OUT PBOOLEAN QuotaCharged
578 );
579
580 VOID
581 STDCALL
582 ExRaiseAccessViolation (
583 VOID
584 );
585 VOID
586 STDCALL
587 ExRaiseDatatypeMisalignment (
588 VOID
589 );
590 VOID
591 STDCALL
592 ExRaiseStatus (
593 NTSTATUS Status
594 );
595 VOID
596 STDCALL
597 ExRaiseException (
598 PEXCEPTION_RECORD pExcptRec
599 );
600 VOID
601 STDCALL
602 ExRaiseHardError (
603 IN NTSTATUS ErrorStatus,
604 IN ULONG NumberOfParameters,
605 IN PUNICODE_STRING UnicodeStringParameterMask OPTIONAL,
606 IN PVOID *Parameters,
607 IN HARDERROR_RESPONSE_OPTION ResponseOption,
608 OUT PHARDERROR_RESPONSE Response
609 );
610
611 PVOID
612 STDCALL
613 ExRegisterCallback (
614 IN PCALLBACK_OBJECT CallbackObject,
615 IN PCALLBACK_FUNCTION CallbackFunction,
616 IN PVOID CallbackContext
617 );
618
619 VOID
620 STDCALL
621 ExReinitializeResourceLite (
622 PERESOURCE Resource
623 );
624 VOID
625 FASTCALL
626 ExReInitializeRundownProtection (
627 IN PEX_RUNDOWN_REF RunRef
628 );
629
630 /* ReactOS Specific: begin */
631 VOID
632 FASTCALL
633 ExReleaseFastMutex (
634 PFAST_MUTEX Mutex
635 );
636 /* ReactOS Specific: end */
637 VOID
638 FASTCALL
639 ExReleaseFastMutexUnsafe (
640 PFAST_MUTEX Mutex
641 );
642 /*
643 VOID
644 STDCALL
645 ExReleaseResource (
646 PERESOURCE Resource
647 );
648 */
649 #define ExReleaseResource(Resource) \
650 (ExReleaseResourceLite (Resource))
651
652 VOID
653 FASTCALL
654 ExReleaseResourceLite (
655 PERESOURCE Resource
656 );
657 VOID
658 STDCALL
659 ExReleaseResourceForThread (
660 PERESOURCE Resource,
661 ERESOURCE_THREAD ResourceThreadId
662 );
663 VOID
664 STDCALL
665 ExReleaseResourceForThreadLite (
666 PERESOURCE Resource,
667 ERESOURCE_THREAD ResourceThreadId
668 );
669 VOID
670 FASTCALL
671 ExReleaseRundownProtection (
672 IN PEX_RUNDOWN_REF RunRef
673 );
674 VOID
675 FASTCALL
676 ExReleaseRundownProtectionEx (
677 IN PEX_RUNDOWN_REF RunRef,
678 IN ULONG Count
679 );
680 /* ReactOS Specific: begin */
681 VOID STDCALL
682 ExRosDumpPagedPoolByTag (
683 IN ULONG Tag
684 );
685 ULONG STDCALL
686 ExRosQueryPoolTag (
687 IN PVOID Block
688 );
689 /* ReactOS Specific: end */
690 VOID
691 FASTCALL
692 ExRundownCompleted (
693 IN PEX_RUNDOWN_REF RunRef
694 );
695 VOID
696 STDCALL
697 ExSetResourceOwnerPointer (
698 IN PERESOURCE Resource,
699 IN PVOID OwnerPointer
700 );
701
702 VOID
703 STDCALL
704 ExSetTimerResolution (
705 IN ULONG DesiredTime,
706 IN BOOLEAN SetResolution
707 );
708
709 BOOLEAN
710 STDCALL
711 ExVerifySuite(
712 SUITE_TYPE SuiteType
713 );
714
715 BOOLEAN
716 STDCALL
717 ExSystemExceptionFilter();
718
719 VOID
720 STDCALL
721 ExSystemTimeToLocalTime (
722 PLARGE_INTEGER SystemTime,
723 PLARGE_INTEGER LocalTime
724 );
725
726 BOOLEAN
727 FASTCALL
728 ExTryToAcquireFastMutex (
729 PFAST_MUTEX FastMutex
730 );
731
732 BOOLEAN
733 STDCALL
734 ExTryToAcquireResourceExclusiveLite (
735 PERESOURCE Resource
736 );
737
738 VOID
739 STDCALL
740 ExUnregisterCallback (
741 IN PVOID CallbackRegistration
742 );
743
744 typedef GUID UUID;
745
746 NTSTATUS
747 STDCALL
748 ExUuidCreate(
749 OUT UUID *Uuid
750 );
751
752 VOID
753 FASTCALL
754 ExWaitForRundownProtectionRelease (
755 IN PEX_RUNDOWN_REF RunRef
756 );
757
758 PSLIST_ENTRY
759 FASTCALL
760 InterlockedPopEntrySList (
761 IN PSLIST_HEADER ListHead
762 );
763
764 PSLIST_ENTRY
765 FASTCALL
766 InterlockedPushEntrySList(
767 IN PSLIST_HEADER ListHead,
768 IN PSLIST_ENTRY ListEntry
769 );
770
771 /*
772 * PVOID
773 * ExAllocateFromNPagedLookasideList (
774 * PNPAGED_LOOKASIDE_LIST LookSide
775 * );
776 *
777 * FUNCTION:
778 * Removes (pops) the first entry from the specified nonpaged
779 * lookaside list.
780 *
781 * ARGUMENTS:
782 * Lookaside = Pointer to a nonpaged lookaside list
783 *
784 * RETURNS:
785 * Address of the allocated list entry
786 */
787 static
788 inline
789 PVOID
790 ExAllocateFromNPagedLookasideList (
791 IN PNPAGED_LOOKASIDE_LIST Lookaside
792 )
793 {
794 PVOID Entry;
795
796 Lookaside->TotalAllocates++;
797 Entry = ExInterlockedPopEntrySList (&Lookaside->ListHead,
798 &Lookaside->Obsoleted);
799 if (Entry == NULL)
800 {
801 Lookaside->AllocateMisses++;
802 Entry = (Lookaside->Allocate)(Lookaside->Type,
803 Lookaside->Size,
804 Lookaside->Tag);
805 }
806
807 return Entry;
808 }
809
810 static inline PVOID
811 ExAllocateFromPagedLookasideList(
812 IN PPAGED_LOOKASIDE_LIST Lookaside)
813 {
814 PVOID Entry;
815
816 Lookaside->TotalAllocates++;
817 Entry = InterlockedPopEntrySList(&Lookaside->ListHead);
818 if (Entry == NULL) {
819 Lookaside->AllocateMisses++;
820 Entry = (Lookaside->Allocate)(Lookaside->Type,
821 Lookaside->Size, Lookaside->Tag);
822 }
823 return Entry;
824 }
825
826 VOID
827 STDCALL
828 ExDeleteNPagedLookasideList (
829 PNPAGED_LOOKASIDE_LIST Lookaside
830 );
831
832 VOID
833 STDCALL
834 ExDeletePagedLookasideList (
835 PPAGED_LOOKASIDE_LIST Lookaside
836 );
837
838
839 /*
840 * VOID
841 * ExFreeToNPagedLookasideList (
842 * PNPAGED_LOOKASIDE_LIST Lookaside,
843 * PVOID Entry
844 * );
845 *
846 * FUNCTION:
847 * Inserts (pushes) the specified entry into the specified
848 * nonpaged lookaside list.
849 *
850 * ARGUMENTS:
851 * Lookaside = Pointer to the nonpaged lookaside list
852 * Entry = Pointer to the entry that is inserted in the lookaside list
853 */
854 static
855 inline
856 VOID
857 ExFreeToNPagedLookasideList (
858 IN PNPAGED_LOOKASIDE_LIST Lookaside,
859 IN PVOID Entry
860 )
861 {
862 Lookaside->TotalFrees++;
863 if (ExQueryDepthSList (&Lookaside->ListHead) >= Lookaside->Depth)
864 {
865 Lookaside->FreeMisses++;
866 (Lookaside->Free)(Entry);
867 }
868 else
869 {
870 ExInterlockedPushEntrySList (&Lookaside->ListHead,
871 (PSINGLE_LIST_ENTRY)Entry,
872 &Lookaside->Obsoleted);
873 }
874 }
875
876 static inline VOID
877 ExFreeToPagedLookasideList(
878 IN PPAGED_LOOKASIDE_LIST Lookaside,
879 IN PVOID Entry)
880 {
881 Lookaside->TotalFrees++;
882 if (ExQueryDepthSList(&Lookaside->ListHead) >= Lookaside->Depth) {
883 Lookaside->FreeMisses++;
884 (Lookaside->Free)(Entry);
885 } else {
886 InterlockedPushEntrySList(&Lookaside->ListHead, (PSLIST_ENTRY)Entry);
887 }
888 }
889
890 VOID
891 STDCALL
892 ExInitializeNPagedLookasideList (
893 PNPAGED_LOOKASIDE_LIST Lookaside,
894 PALLOCATE_FUNCTION Allocate,
895 PFREE_FUNCTION Free,
896 ULONG Flags,
897 ULONG Size,
898 ULONG Tag,
899 USHORT Depth
900 );
901
902 VOID
903 STDCALL
904 ExInitializePagedLookasideList (
905 PPAGED_LOOKASIDE_LIST Lookaside,
906 PALLOCATE_FUNCTION Allocate,
907 PFREE_FUNCTION Free,
908 ULONG Flags,
909 ULONG Size,
910 ULONG Tag,
911 USHORT Depth
912 );
913
914 ULONG FASTCALL
915 ExfInterlockedAddUlong(IN PULONG Addend,
916 IN ULONG Increment,
917 IN PKSPIN_LOCK Lock);
918
919 PLIST_ENTRY FASTCALL
920 ExfInterlockedInsertHeadList(IN PLIST_ENTRY ListHead,
921 IN PLIST_ENTRY ListEntry,
922 IN PKSPIN_LOCK Lock);
923
924 PLIST_ENTRY FASTCALL
925 ExfInterlockedInsertTailList(IN PLIST_ENTRY ListHead,
926 IN PLIST_ENTRY ListEntry,
927 IN PKSPIN_LOCK Lock);
928
929 PSINGLE_LIST_ENTRY FASTCALL
930 ExfInterlockedPopEntryList(IN PSINGLE_LIST_ENTRY ListHead,
931 IN PKSPIN_LOCK Lock);
932
933 PSINGLE_LIST_ENTRY FASTCALL
934 ExfInterlockedPushEntryList(IN PSINGLE_LIST_ENTRY ListHead,
935 IN PSINGLE_LIST_ENTRY ListEntry,
936 IN PKSPIN_LOCK Lock);
937
938 PLIST_ENTRY FASTCALL
939 ExfInterlockedRemoveHeadList(IN PLIST_ENTRY Head,
940 IN PKSPIN_LOCK Lock);
941
942 INTERLOCKED_RESULT FASTCALL
943 Exfi386InterlockedIncrementLong(IN PLONG Addend);
944
945 INTERLOCKED_RESULT FASTCALL
946 Exfi386InterlockedDecrementLong(IN PLONG Addend);
947
948 ULONG FASTCALL
949 Exfi386InterlockedExchangeUlong(IN PULONG Target,
950 IN ULONG Value);
951
952 INTERLOCKED_RESULT STDCALL
953 Exi386InterlockedIncrementLong(IN PLONG Addend);
954
955 INTERLOCKED_RESULT STDCALL
956 Exi386InterlockedDecrementLong(IN PLONG Addend);
957
958 ULONG STDCALL
959 Exi386InterlockedExchangeUlong(IN PULONG Target,
960 IN ULONG Value);
961
962
963 LONG
964 FASTCALL
965 InterlockedCompareExchange (
966 PLONG Destination,
967 LONG Exchange,
968 LONG Comperand
969 );
970
971 #ifdef _GNU_H_WINDOWS_H
972 #ifdef InterlockedDecrement
973 #undef InterlockedDecrement
974 #undef InterlockedExchange
975 #undef InterlockedExchangeAdd
976 #undef InterlockedIncrement
977 #endif /* def InterlockedDecrement */
978 #endif /* def _GNU_H_WINDOWS_H */
979 LONG
980 FASTCALL
981 InterlockedDecrement (
982 PLONG Addend
983 );
984 LONG
985 FASTCALL
986 InterlockedExchange (
987 PLONG Target,
988 LONG Value
989 );
990 LONG
991 FASTCALL
992 InterlockedExchangeAdd (
993 PLONG Addend,
994 LONG Value
995 );
996 LONG
997 FASTCALL
998 InterlockedIncrement (
999 PLONG Addend
1000 );
1001
1002 #ifndef InterlockedExchangePointer
1003 # ifdef _WIN64
1004 # define InterlockedExchangePointer(__T__, __V__) \
1005 (PVOID)InterlockedExchange64((PLONGLONG)(__T__), (LONGLONG)(__V__))
1006 # else
1007 # define InterlockedExchangePointer(__T__, __V__) \
1008 (PVOID)InterlockedExchange((PLONG)(__T__), (LONG)(__V__))
1009 # endif
1010 #endif
1011
1012 #ifndef InterlockedCompareExchangePointer
1013 # ifdef _WIN64
1014 # define InterlockedCompareExchangePointer(__T__, __V__, __C__) \
1015 (PVOID)InterlockedCompareExchange64((PLONGLONG)(__T__), (LONGLONG)(__V__), (LONGLONG)(__C__))
1016 # else
1017 # define InterlockedCompareExchangePointer(__T__, __V__, __C__) \
1018 (PVOID)InterlockedCompareExchange((PLONG)(__T__), (LONG)(__V__), (LONG)(__C__))
1019 # endif
1020 #endif
1021
1022 /*---*/
1023
1024 typedef
1025 unsigned int
1026 (*exception_hook) (
1027 CONTEXT * c,
1028 unsigned int exp
1029 );
1030 unsigned int
1031 ExHookException (
1032 exception_hook fn,
1033 unsigned int exp
1034 );
1035
1036 #endif /* ndef _NTOS_EXFUNCS_H */