1 #ifndef _NTOS_EXFUNCS_H
2 #define _NTOS_EXFUNCS_H
4 /* EXECUTIVE ROUTINES ******************************************************/
6 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
15 ExAcquireFastMutexUnsafe (
20 ExAcquireResourceExclusive (
26 ExAcquireResourceExclusiveLite (
32 ExAcquireResourceSharedLite (
38 ExAcquireSharedStarveExclusive (
44 ExAcquireSharedWaitForExclusive (
51 * ExAllocateFromNPagedLookasideList (
52 * PNPAGED_LOOKASIDE_LIST LookSide
56 * Removes (pops) the first entry from the specified nonpaged
60 * Lookaside = Pointer to a nonpaged lookaside list
63 * Address of the allocated list entry
68 ExAllocateFromNPagedLookasideList (
69 IN PNPAGED_LOOKASIDE_LIST Lookaside
75 Lookaside
->TotalAllocates
++;
76 Entry
= ExInterlockedPopEntrySList (&Lookaside
->ListHead
,
80 Lookaside
->AllocateMisses
++;
81 Entry
= (Lookaside
->Allocate
)(Lookaside
->Type
,
93 ExAllocateFromPagedLookasideList (
94 PPAGED_LOOKASIDE_LIST LookSide
104 * ExAllocateFromZone (
109 * Allocate a block from a zone
112 * Zone = Zone to allocate from
115 * The base address of the block allocated
117 #define ExAllocateFromZone(Zone) \
118 (PVOID)((Zone)->FreeList.Next); \
119 if ((Zone)->FreeList.Next) \
120 (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
123 * FUNCTION: Allocates memory from the nonpaged pool
125 * NumberOfBytes = minimum size of the block to be allocated
126 * PoolType = the type of memory to use for the block (ignored)
128 * the address of the block if it succeeds
133 IN POOL_TYPE PoolType
,
134 IN ULONG NumberOfBytes
139 ExAllocatePoolWithQuota (
140 IN POOL_TYPE PoolType
,
141 IN ULONG NumberOfBytes
145 ExAllocatePoolWithQuotaTag (
146 IN POOL_TYPE PoolType
,
147 IN ULONG NumberOfBytes
,
152 ExAllocatePoolWithTag (
153 IN POOL_TYPE PoolType
,
154 IN ULONG NumberOfBytes
,
160 ExConvertExclusiveToSharedLite (
167 OUT PCALLBACK_OBJECT
* CallbackObject
,
168 IN POBJECT_ATTRIBUTES ObjectAttributes
,
170 IN BOOLEAN AllowMultipleCallbacks
175 ExDeleteNPagedLookasideList (
176 PNPAGED_LOOKASIDE_LIST Lookaside
180 ExDeletePagedLookasideList (
181 PPAGED_LOOKASIDE_LIST Lookaside
190 ExDeleteResourceLite (
196 ExDisableResourceBoostLite (
209 * FUNCTION: Releases previously allocated memory
211 * block = block to free
221 * ExFreeToNPagedLookasideList (
222 * PNPAGED_LOOKASIDE_LIST Lookaside,
227 * Inserts (pushes) the specified entry into the specified
228 * nonpaged lookaside list.
231 * Lookaside = Pointer to the nonpaged lookaside list
232 * Entry = Pointer to the entry that is inserted in the lookaside list
237 ExFreeToNPagedLookasideList (
238 IN PNPAGED_LOOKASIDE_LIST Lookaside
,
243 Lookaside
->TotalFrees
++;
244 if (ExQueryDepthSList (&Lookaside
->ListHead
) >= Lookaside
->Depth
)
246 Lookaside
->FreeMisses
++;
247 (Lookaside
->Free
)(Entry
);
251 ExInterlockedPushEntrySList (&Lookaside
->ListHead
,
252 (PSINGLE_LIST_ENTRY
)Entry
,
260 ExFreeToPagedLookasideList (
261 PPAGED_LOOKASIDE_LIST Lookaside
,
273 * Frees a block from a zone
276 * Zone = Zone the block was allocated from
277 * Block = Block to free
279 #define ExFreeToZone(Zone,Block) \
280 (((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
281 (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
282 ((PSINGLE_LIST_ENTRY)(Block))->Next)
286 * ExGetCurrentResourceThread (
290 #define ExGetCurrentResourceThread() \
291 ((ERESOURCE_THREAD)PsGetCurrentThread())
295 ExGetExclusiveWaiterCount (
307 ExGetSharedWaiterCount (
313 * ExInitializeFastMutex (
314 * PFAST_MUTEX FastMutex
317 #define ExInitializeFastMutex(_FastMutex) \
318 (_FastMutex)->Count = 1; \
319 (_FastMutex)->Owner = NULL; \
320 (_FastMutex)->Contention = 0; \
321 KeInitializeEvent(&(_FastMutex)->Event, \
322 SynchronizationEvent, \
327 ExInitializeNPagedLookasideList (
328 PNPAGED_LOOKASIDE_LIST Lookaside
,
329 PALLOCATE_FUNCTION Allocate
,
338 ExInitializePagedLookasideList (
339 PPAGED_LOOKASIDE_LIST Lookaside
,
340 PALLOCATE_FUNCTION Allocate
,
349 ExInitializeResource (
354 ExInitializeResourceLite (
360 * ExInitializeSListHead (
361 * PSLIST_HEADER SListHead
364 #define ExInitializeSListHead(ListHead) \
365 (ListHead)->Alignment = 0
369 * ExInitializeWorkItem (
370 * PWORK_QUEUE_ITEM Item,
371 * PWORKER_THREAD_ROUTINE Routine,
376 * Initializes a work item to be processed by one of the system
380 * Item = Pointer to the item to be initialized
381 * Routine = Routine to be called by the worker thread
382 * Context = Parameter to be passed to the callback
384 #define ExInitializeWorkItem(Item, WorkerRoutine, RoutineContext) \
385 ASSERT_IRQL(DISPATCH_LEVEL); \
386 (Item)->Routine = (WorkerRoutine); \
387 (Item)->Context = (RoutineContext); \
388 (Item)->Entry.Flink = NULL; \
389 (Item)->Entry.Blink = NULL;
396 PVOID InitialSegment
,
397 ULONG InitialSegmentSize
402 ExInterlockedAddLargeInteger (
403 PLARGE_INTEGER Addend
,
404 LARGE_INTEGER Increment
,
410 ExInterlockedAddLargeStatistic (
411 IN PLARGE_INTEGER Addend
,
417 ExInterlockedAddUlong (
426 * ExInterlockedAllocateFromZone (
431 #define ExInterlockedAllocateFromZone(Zone,Lock) \
432 (PVOID)ExInterlockedPopEntryList(&(Zone)->FreeList,Lock)
436 ExInterlockedCompareExchange64 (
437 IN OUT PLONGLONG Destination
,
438 IN PLONGLONG Exchange
,
439 IN PLONGLONG Comparand
,
445 ExInterlockedDecrementLong (
451 ExInterlockedExchangeUlong (
458 ExInterlockedExtendZone (
467 * ExInterlockedFreeToZone (
473 #define ExInterlockedFreeToZone(Zone,Block,Lock) \
474 ExInterlockedPushEntryList(&(Zone)->FreeList,((PSINGLE_LIST_ENTRY)(Block)),(Lock))
478 ExInterlockedIncrementLong (
484 ExInterlockedInsertHeadList (
485 PLIST_ENTRY ListHead
,
486 PLIST_ENTRY ListEntry
,
491 ExInterlockedInsertTailList (
492 PLIST_ENTRY ListHead
,
493 PLIST_ENTRY ListEntry
,
498 ExInterlockedPopEntryList (
499 PSINGLE_LIST_ENTRY ListHead
,
504 ExInterlockedPopEntrySList (
505 PSLIST_HEADER ListHead
,
510 ExInterlockedPushEntryList (
511 PSINGLE_LIST_ENTRY ListHead
,
512 PSINGLE_LIST_ENTRY ListEntry
,
517 ExInterlockedPushEntrySList (
518 PSLIST_HEADER ListHead
,
519 PSINGLE_LIST_ENTRY ListEntry
,
524 ExInterlockedRemoveEntryList (
525 PLIST_ENTRY ListHead
,
532 ExInterlockedRemoveHeadList (
543 #define ExIsFullZone(Zone) \
544 ((Zone)->FreeList.Next==(PSINGLE_LIST_ENTRY)NULL)
548 * ExIsObjectInFirstZoneSegment (
553 #define ExIsObjectInFirstZoneSegment(Zone,Object) \
554 (((PUCHAR)(Object)>=(PUCHAR)(Zone)->SegmentList.Next) && \
555 ((PUCHAR)(Object)<(PUCHAR)(Zone)->SegmentList.Next+(Zone)->TotalSegmentSize))
559 ExIsProcessorFeaturePresent (
560 IN ULONG ProcessorFeature
565 ExIsResourceAcquiredExclusiveLite (
571 ExIsResourceAcquiredSharedLite (
577 ExLocalTimeToSystemTime (
578 PLARGE_INTEGER LocalTime
,
579 PLARGE_INTEGER SystemTime
585 IN PVOID CallbackObject
,
600 * ExQueryDepthSListHead (
601 * PSLIST_HEADER SListHead
604 #define ExQueryDepthSListHead(ListHead) \
605 (USHORT)(ListHead)->Depth
610 PWORK_QUEUE_ITEM WorkItem
,
611 WORK_QUEUE_TYPE QueueType
615 ExRaiseAccessViolation (
620 ExRaiseDatatypeMisalignment (
632 IN PCALLBACK_OBJECT CallbackObject
,
633 IN PCALLBACK_FUNCTION CallbackFunction
,
634 IN PVOID CallbackContext
639 ExReinitializeResourceLite (
642 /* ReactOS Specific: begin */
648 /* ReactOS Specific: end */
651 ExReleaseFastMutexUnsafe (
661 #define ExReleaseResource(Resource) \
662 (ExReleaseResourceLite (Resource))
666 ExReleaseResourceLite (
671 ExReleaseResourceForThread (
673 ERESOURCE_THREAD ResourceThreadId
677 ExReleaseResourceForThreadLite (
679 ERESOURCE_THREAD ResourceThreadId
684 ExSetResourceOwnerPointer (
685 IN PERESOURCE Resource
,
686 IN PVOID OwnerPointer
691 ExSystemTimeToLocalTime (
692 PLARGE_INTEGER SystemTime
,
693 PLARGE_INTEGER LocalTime
698 ExTryToAcquireFastMutex (
699 PFAST_MUTEX FastMutex
704 ExTryToAcquireResourceExclusiveLite (
710 ExUnregisterCallback (
711 IN PVOID CallbackRegistration
717 InterlockedCompareExchange (
725 InterlockedCompareExchange (
730 #ifdef _GNU_H_WINDOWS_H
731 #ifdef InterlockedDecrement
732 #undef InterlockedDecrement
733 #undef InterlockedExchange
734 #undef InterlockedExchangeAdd
735 #undef InterlockedIncrement
736 #endif /* def InterlockedDecrement */
737 #endif /* def _GNU_H_WINDOWS_H */
740 InterlockedDecrement (
745 InterlockedExchange (
751 InterlockedExchangeAdd (
757 InterlockedIncrement (
775 #endif /* ndef _NTOS_EXFUNCS_H */