Sync with trunk head (part 1 of 2)
[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(
308 VOID);
309
310 NTKERNELAPI
311 ULONG
312 NTAPI
313 ExGetSharedWaiterCount(
314 IN PERESOURCE Resource);
315
316 NTKERNELAPI
317 VOID
318 NTAPI
319 ExInitializeNPagedLookasideList(
320 IN PNPAGED_LOOKASIDE_LIST Lookaside,
321 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
322 IN PFREE_FUNCTION Free OPTIONAL,
323 IN ULONG Flags,
324 IN SIZE_T Size,
325 IN ULONG Tag,
326 IN USHORT Depth);
327
328 NTKERNELAPI
329 VOID
330 NTAPI
331 ExInitializePagedLookasideList(
332 IN PPAGED_LOOKASIDE_LIST Lookaside,
333 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
334 IN PFREE_FUNCTION Free OPTIONAL,
335 IN ULONG Flags,
336 IN SIZE_T Size,
337 IN ULONG Tag,
338 IN USHORT Depth);
339
340 NTKERNELAPI
341 NTSTATUS
342 NTAPI
343 ExInitializeResourceLite(
344 IN PERESOURCE Resource);
345
346 NTKERNELAPI
347 LARGE_INTEGER
348 NTAPI
349 ExInterlockedAddLargeInteger(
350 IN PLARGE_INTEGER Addend,
351 IN LARGE_INTEGER Increment,
352 IN PKSPIN_LOCK Lock);
353
354 #if defined(_WIN64)
355 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
356 (VOID)InterlockedAdd64(&(Addend)->QuadPart, Increment)
357 #else
358 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
359 _InterlockedAddLargeStatistic((PLONGLONG)&(Addend)->QuadPart, Increment)
360 #endif
361
362 NTKERNELAPI
363 ULONG
364 FASTCALL
365 ExInterlockedAddUlong(
366 IN PULONG Addend,
367 IN ULONG Increment,
368 PKSPIN_LOCK Lock);
369
370 #if defined(_AMD64_) || defined(_IA64_)
371 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
372 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
373 #elif defined(_X86_)
374 NTKERNELAPI
375 LONGLONG
376 FASTCALL
377 ExfInterlockedCompareExchange64(
378 IN OUT LONGLONG volatile *Destination,
379 IN PLONGLONG Exchange,
380 IN PLONGLONG Comperand);
381 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
382 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
383 #else
384 NTKERNELAPI
385 LONGLONG
386 FASTCALL
387 ExInterlockedCompareExchange64(
388 IN OUT LONGLONG volatile *Destination,
389 IN PLONGLONG Exchange,
390 IN PLONGLONG Comparand,
391 IN PKSPIN_LOCK Lock);
392 #endif
393
394 NTKERNELAPI
395 PLIST_ENTRY
396 FASTCALL
397 ExInterlockedInsertHeadList(
398 IN PLIST_ENTRY ListHead,
399 IN PLIST_ENTRY ListEntry,
400 IN PKSPIN_LOCK Lock);
401
402 NTKERNELAPI
403 PLIST_ENTRY
404 FASTCALL
405 ExInterlockedInsertTailList(
406 IN PLIST_ENTRY ListHead,
407 IN PLIST_ENTRY ListEntry,
408 IN PKSPIN_LOCK Lock);
409
410 NTKERNELAPI
411 PSINGLE_LIST_ENTRY
412 FASTCALL
413 ExInterlockedPopEntryList(
414 IN PSINGLE_LIST_ENTRY ListHead,
415 IN PKSPIN_LOCK Lock);
416
417 NTKERNELAPI
418 PSINGLE_LIST_ENTRY
419 FASTCALL
420 ExInterlockedPushEntryList(
421 IN PSINGLE_LIST_ENTRY ListHead,
422 IN PSINGLE_LIST_ENTRY ListEntry,
423 IN PKSPIN_LOCK Lock);
424
425 NTKERNELAPI
426 PLIST_ENTRY
427 FASTCALL
428 ExInterlockedRemoveHeadList(
429 IN PLIST_ENTRY ListHead,
430 IN PKSPIN_LOCK Lock);
431
432 NTKERNELAPI
433 BOOLEAN
434 NTAPI
435 ExIsProcessorFeaturePresent(
436 IN ULONG ProcessorFeature);
437
438 NTKERNELAPI
439 BOOLEAN
440 NTAPI
441 ExIsResourceAcquiredExclusiveLite(
442 IN PERESOURCE Resource);
443
444 NTKERNELAPI
445 ULONG
446 NTAPI
447 ExIsResourceAcquiredSharedLite(
448 IN PERESOURCE Resource);
449
450 #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
451
452 NTKERNELAPI
453 VOID
454 NTAPI
455 ExLocalTimeToSystemTime(
456 IN PLARGE_INTEGER LocalTime,
457 OUT PLARGE_INTEGER SystemTime);
458
459 NTKERNELAPI
460 VOID
461 NTAPI
462 ExNotifyCallback(
463 IN PCALLBACK_OBJECT CallbackObject,
464 IN PVOID Argument1,
465 IN PVOID Argument2);
466
467 NTKERNELAPI
468 VOID
469 NTAPI
470 ExQueueWorkItem(
471 IN PWORK_QUEUE_ITEM WorkItem,
472 IN WORK_QUEUE_TYPE QueueType);
473
474 NTKERNELAPI
475 DECLSPEC_NORETURN
476 VOID
477 NTAPI
478 ExRaiseStatus(
479 IN NTSTATUS Status);
480
481 NTKERNELAPI
482 PVOID
483 NTAPI
484 ExRegisterCallback(
485 IN PCALLBACK_OBJECT CallbackObject,
486 IN PCALLBACK_FUNCTION CallbackFunction,
487 IN PVOID CallbackContext);
488
489 NTKERNELAPI
490 NTSTATUS
491 NTAPI
492 ExReinitializeResourceLite(
493 IN PERESOURCE Resource);
494
495 NTKERNELAPI
496 VOID
497 NTAPI
498 ExReleaseResourceForThreadLite(
499 IN PERESOURCE Resource,
500 IN ERESOURCE_THREAD ResourceThreadId);
501
502 NTKERNELAPI
503 VOID
504 FASTCALL
505 ExReleaseResourceLite(
506 IN PERESOURCE Resource);
507
508 NTKERNELAPI
509 VOID
510 NTAPI
511 ExSetResourceOwnerPointer(
512 IN PERESOURCE Resource,
513 IN PVOID OwnerPointer);
514
515 NTKERNELAPI
516 ULONG
517 NTAPI
518 ExSetTimerResolution(
519 IN ULONG DesiredTime,
520 IN BOOLEAN SetResolution);
521
522 NTKERNELAPI
523 VOID
524 NTAPI
525 ExSystemTimeToLocalTime(
526 IN PLARGE_INTEGER SystemTime,
527 OUT PLARGE_INTEGER LocalTime);
528
529 NTKERNELAPI
530 VOID
531 NTAPI
532 ExUnregisterCallback(
533 IN PVOID CbRegistration);
534
535
536 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
537
538 #if (NTDDI_VERSION >= NTDDI_WINXP)
539 NTKERNELAPI
540 BOOLEAN
541 FASTCALL
542 ExAcquireRundownProtection(
543 IN OUT PEX_RUNDOWN_REF RunRef);
544
545 NTKERNELAPI
546 VOID
547 FASTCALL
548 ExInitializeRundownProtection(
549 OUT PEX_RUNDOWN_REF RunRef);
550
551 NTKERNELAPI
552 VOID
553 FASTCALL
554 ExReInitializeRundownProtection(
555 OUT PEX_RUNDOWN_REF RunRef);
556
557 NTKERNELAPI
558 VOID
559 FASTCALL
560 ExReleaseRundownProtection(
561 IN OUT PEX_RUNDOWN_REF RunRef);
562
563 NTKERNELAPI
564 VOID
565 FASTCALL
566 ExRundownCompleted(
567 OUT PEX_RUNDOWN_REF RunRef);
568
569 NTKERNELAPI
570 BOOLEAN
571 NTAPI
572 ExVerifySuite(
573 IN SUITE_TYPE SuiteType);
574
575 NTKERNELAPI
576 VOID
577 FASTCALL
578 ExWaitForRundownProtectionRelease(
579 IN OUT PEX_RUNDOWN_REF RunRef);
580
581 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
582
583 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
584 NTKERNELAPI
585 BOOLEAN
586 FASTCALL
587 ExAcquireRundownProtectionEx(
588 IN OUT PEX_RUNDOWN_REF RunRef,
589 IN ULONG Count);
590
591 NTKERNELAPI
592 VOID
593 FASTCALL
594 ExReleaseRundownProtectionEx(
595 IN OUT PEX_RUNDOWN_REF RunRef,
596 IN ULONG Count);
597 #endif // (NTDDI_VERSION >= NTDDI_WINXPSP2)
598
599 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
600 NTKERNELAPI
601 PEX_RUNDOWN_REF_CACHE_AWARE
602 NTAPI
603 ExAllocateCacheAwareRundownProtection(
604 IN POOL_TYPE PoolType,
605 IN ULONG PoolTag);
606
607 NTKERNELAPI
608 SIZE_T
609 NTAPI
610 ExSizeOfRundownProtectionCacheAware(VOID);
611 #endif // (NTDDI_VERSION >= NTDDI_WS03SP1)
612
613 #if (NTDDI_VERSION >= NTDDI_VISTA)
614 NTKERNELAPI
615 NTSTATUS
616 NTAPI
617 ExInitializeLookasideListEx(
618 OUT PLOOKASIDE_LIST_EX Lookaside,
619 IN PALLOCATE_FUNCTION_EX Allocate OPTIONAL,
620 IN PFREE_FUNCTION_EX Free OPTIONAL,
621 IN POOL_TYPE PoolType,
622 IN ULONG Flags,
623 IN SIZE_T Size,
624 IN ULONG Tag,
625 IN USHORT Depth);
626 #endif
627
628 #if !defined(MIDL_PASS)
629
630 static __inline PVOID
631 ExAllocateFromNPagedLookasideList(
632 IN PNPAGED_LOOKASIDE_LIST Lookaside)
633 {
634 PVOID Entry;
635
636 Lookaside->L.TotalAllocates++;
637 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
638 if (Entry == NULL) {
639 Lookaside->L.AllocateMisses++;
640 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
641 Lookaside->L.Size,
642 Lookaside->L.Tag);
643 }
644 return Entry;
645 }
646
647 static __inline PVOID
648 ExAllocateFromPagedLookasideList(
649 IN PPAGED_LOOKASIDE_LIST Lookaside)
650 {
651 PVOID Entry;
652
653 Lookaside->L.TotalAllocates++;
654 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
655 if (Entry == NULL) {
656 Lookaside->L.AllocateMisses++;
657 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
658 Lookaside->L.Size,
659 Lookaside->L.Tag);
660 }
661 return Entry;
662 }
663
664 static __inline VOID
665 ExFreeToNPagedLookasideList(
666 IN PNPAGED_LOOKASIDE_LIST Lookaside,
667 IN PVOID Entry)
668 {
669 Lookaside->L.TotalFrees++;
670 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
671 Lookaside->L.FreeMisses++;
672 (Lookaside->L.Free)(Entry);
673 } else {
674 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
675 }
676 }
677
678 static __inline VOID
679 ExFreeToPagedLookasideList(
680 IN PPAGED_LOOKASIDE_LIST Lookaside,
681 IN PVOID Entry)
682 {
683 Lookaside->L.TotalFrees++;
684 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
685 Lookaside->L.FreeMisses++;
686 (Lookaside->L.Free)(Entry);
687 } else {
688 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
689 }
690 }
691
692 #endif // !defined(MIDL_PASS)
693
694 $endif
695