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