Move more stuff to wdm.h
[reactos.git] / include / ddk / wdm.h
1 #ifndef _WDMDDK_
2 #define _WDMDDK_
3
4 /* Helper macro to enable gcc's extension. */
5 #ifndef __GNU_EXTENSION
6 #ifdef __GNUC__
7 #define __GNU_EXTENSION __extension__
8 #else
9 #define __GNU_EXTENSION
10 #endif
11 #endif
12
13 //
14 // Dependencies
15 //
16 #define NT_INCLUDED
17 #include <excpt.h>
18 #include <ntdef.h>
19 #include <ntstatus.h>
20
21 #ifndef GUID_DEFINED
22 #include <guiddef.h>
23 #endif /* GUID_DEFINED */
24
25 #include "intrin.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define NTKERNELAPI DECLSPEC_IMPORT
32
33 #ifdef _WIN64
34 #define PORT_MAXIMUM_MESSAGE_LENGTH 512
35 #else
36 #define PORT_MAXIMUM_MESSAGE_LENGTH 256
37 #endif
38
39
40 #if defined(_MSC_VER)
41
42 //
43 // Indicate if #pragma alloc_text() is supported
44 //
45 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)
46 #define ALLOC_PRAGMA 1
47 #endif
48
49 //
50 // Indicate if #pragma data_seg() is supported
51 //
52 #if defined(_M_IX86) || defined(_M_AMD64)
53 #define ALLOC_DATA_PRAGMA 1
54 #endif
55
56 #endif
57
58
59 /*
60 * Alignment Macros
61 */
62 #define ALIGN_DOWN(s, t) \
63 ((ULONG)(s) & ~(sizeof(t) - 1))
64
65 #define ALIGN_UP(s, t) \
66 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
67
68 #define ALIGN_DOWN_POINTER(p, t) \
69 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
70
71 #define ALIGN_UP_POINTER(p, t) \
72 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
73
74 /*
75 * GUID Comparison
76 */
77
78 #ifndef __IID_ALIGNED__
79 #define __IID_ALIGNED__
80 #ifdef __cplusplus
81 inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
82 {
83 return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
84 }
85 #else
86 #define IsEqualGUIDAligned(guid1, guid2) \
87 ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
88 #endif
89 #endif
90
91 /*
92 ** Forward declarations
93 */
94
95 struct _IRP;
96 struct _MDL;
97 struct _KAPC;
98 struct _KDPC;
99 struct _FILE_OBJECT;
100 struct _DMA_ADAPTER;
101 struct _DEVICE_OBJECT;
102 struct _DRIVER_OBJECT;
103 struct _IO_STATUS_BLOCK;
104 struct _DEVICE_DESCRIPTION;
105 struct _SCATTER_GATHER_LIST;
106 struct _DRIVE_LAYOUT_INFORMATION;
107
108 typedef PVOID PSID;
109
110 /*
111 ** Simple structures
112 */
113
114 typedef UCHAR KIRQL, *PKIRQL;
115
116 typedef enum _MODE {
117 KernelMode,
118 UserMode,
119 MaximumMode
120 } MODE;
121
122 /* Constants */
123 #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
124 #define ZwCurrentProcess() NtCurrentProcess()
125 #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
126 #define ZwCurrentThread() NtCurrentThread()
127
128 #if (_M_IX86)
129 #define KIP0PCRADDRESS 0xffdff000
130 #endif
131
132 #if defined(_WIN64)
133 #define MAXIMUM_PROCESSORS 64
134 #else
135 #define MAXIMUM_PROCESSORS 32
136 #endif
137
138 #define MAXIMUM_WAIT_OBJECTS 64
139
140 #define EX_RUNDOWN_ACTIVE 0x1
141 #define EX_RUNDOWN_COUNT_SHIFT 0x1
142 #define EX_RUNDOWN_COUNT_INC (1 << EX_RUNDOWN_COUNT_SHIFT)
143
144 #define METHOD_BUFFERED 0
145 #define METHOD_IN_DIRECT 1
146 #define METHOD_OUT_DIRECT 2
147 #define METHOD_NEITHER 3
148
149 #define LOW_PRIORITY 0
150 #define LOW_REALTIME_PRIORITY 16
151 #define HIGH_PRIORITY 31
152 #define MAXIMUM_PRIORITY 32
153
154 #define MAXIMUM_SUSPEND_COUNT MAXCHAR
155
156 #define MAXIMUM_FILENAME_LENGTH 256
157
158 #define FILE_SUPERSEDED 0x00000000
159 #define FILE_OPENED 0x00000001
160 #define FILE_CREATED 0x00000002
161 #define FILE_OVERWRITTEN 0x00000003
162 #define FILE_EXISTS 0x00000004
163 #define FILE_DOES_NOT_EXIST 0x00000005
164
165 #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
166 #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
167
168 /* Simple types */
169 typedef UCHAR KPROCESSOR_MODE;
170 typedef LONG KPRIORITY;
171 typedef PVOID PSECURITY_DESCRIPTOR;
172 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
173
174 /* Structures not exposed to drivers */
175 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
176 typedef struct _HAL_DISPATCH_TABLE *PHAL_DISPATCH_TABLE;
177 typedef struct _HAL_PRIVATE_DISPATCH_TABLE *PHAL_PRIVATE_DISPATCH_TABLE;
178 typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
179 typedef struct _BUS_HANDLER *PBUS_HANDLER;
180
181 typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
182 typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
183 typedef struct _ETHREAD *PETHREAD;
184 typedef struct _EPROCESS *PEPROCESS;
185 typedef struct _IO_TIMER *PIO_TIMER;
186 typedef struct _KINTERRUPT *PKINTERRUPT;
187 typedef struct _KPROCESS *PKPROCESS;
188 typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
189
190
191 typedef struct _CONTEXT *PCONTEXT;
192
193 //
194 // Resource list definitions
195 //
196 typedef int CM_RESOURCE_TYPE;
197
198 #define CmResourceTypeNull 0
199 #define CmResourceTypePort 1
200 #define CmResourceTypeInterrupt 2
201 #define CmResourceTypeMemory 3
202 #define CmResourceTypeDma 4
203 #define CmResourceTypeDeviceSpecific 5
204 #define CmResourceTypeBusNumber 6
205 #define CmResourceTypeNonArbitrated 128
206 #define CmResourceTypeConfigData 128
207 #define CmResourceTypeDevicePrivate 129
208 #define CmResourceTypePcCardConfig 130
209 #define CmResourceTypeMfCardConfig 131
210
211 typedef enum _INTERFACE_TYPE {
212 InterfaceTypeUndefined = -1,
213 Internal,
214 Isa,
215 Eisa,
216 MicroChannel,
217 TurboChannel,
218 PCIBus,
219 VMEBus,
220 NuBus,
221 PCMCIABus,
222 CBus,
223 MPIBus,
224 MPSABus,
225 ProcessorInternal,
226 InternalPowerBus,
227 PNPISABus,
228 PNPBus,
229 MaximumInterfaceType
230 } INTERFACE_TYPE, *PINTERFACE_TYPE;
231
232 /* IO_RESOURCE_DESCRIPTOR.Option */
233
234 #define IO_RESOURCE_PREFERRED 0x01
235 #define IO_RESOURCE_DEFAULT 0x02
236 #define IO_RESOURCE_ALTERNATIVE 0x08
237
238 typedef struct _IO_RESOURCE_DESCRIPTOR {
239 UCHAR Option;
240 UCHAR Type;
241 UCHAR ShareDisposition;
242 UCHAR Spare1;
243 USHORT Flags;
244 USHORT Spare2;
245 union {
246 struct {
247 ULONG Length;
248 ULONG Alignment;
249 PHYSICAL_ADDRESS MinimumAddress;
250 PHYSICAL_ADDRESS MaximumAddress;
251 } Port;
252 struct {
253 ULONG Length;
254 ULONG Alignment;
255 PHYSICAL_ADDRESS MinimumAddress;
256 PHYSICAL_ADDRESS MaximumAddress;
257 } Memory;
258 struct {
259 ULONG MinimumVector;
260 ULONG MaximumVector;
261 } Interrupt;
262 struct {
263 ULONG MinimumChannel;
264 ULONG MaximumChannel;
265 } Dma;
266 struct {
267 ULONG Length;
268 ULONG Alignment;
269 PHYSICAL_ADDRESS MinimumAddress;
270 PHYSICAL_ADDRESS MaximumAddress;
271 } Generic;
272 struct {
273 ULONG Data[3];
274 } DevicePrivate;
275 struct {
276 ULONG Length;
277 ULONG MinBusNumber;
278 ULONG MaxBusNumber;
279 ULONG Reserved;
280 } BusNumber;
281 struct {
282 ULONG Priority;
283 ULONG Reserved1;
284 ULONG Reserved2;
285 } ConfigData;
286 } u;
287 } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
288
289 typedef struct _IO_RESOURCE_LIST {
290 USHORT Version;
291 USHORT Revision;
292 ULONG Count;
293 IO_RESOURCE_DESCRIPTOR Descriptors[1];
294 } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
295
296 typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
297 ULONG ListSize;
298 INTERFACE_TYPE InterfaceType;
299 ULONG BusNumber;
300 ULONG SlotNumber;
301 ULONG Reserved[3];
302 ULONG AlternativeLists;
303 IO_RESOURCE_LIST List[1];
304 } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
305
306 //
307 // Global debug flag
308 //
309 extern ULONG NtGlobalFlag;
310
311
312 #include <pshpack4.h>
313 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
314 UCHAR Type;
315 UCHAR ShareDisposition;
316 USHORT Flags;
317 union {
318 struct {
319 PHYSICAL_ADDRESS Start;
320 ULONG Length;
321 } Generic;
322 struct {
323 PHYSICAL_ADDRESS Start;
324 ULONG Length;
325 } Port;
326 struct {
327 ULONG Level;
328 ULONG Vector;
329 KAFFINITY Affinity;
330 } Interrupt;
331 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
332 struct {
333 __GNU_EXTENSION union {
334 struct {
335 USHORT Reserved;
336 USHORT MessageCount;
337 ULONG Vector;
338 KAFFINITY Affinity;
339 } Raw;
340 struct {
341 ULONG Level;
342 ULONG Vector;
343 KAFFINITY Affinity;
344 } Translated;
345 };
346 } MessageInterrupt;
347 #endif
348 struct {
349 PHYSICAL_ADDRESS Start;
350 ULONG Length;
351 } Memory;
352 struct {
353 ULONG Channel;
354 ULONG Port;
355 ULONG Reserved1;
356 } Dma;
357 struct {
358 ULONG Data[3];
359 } DevicePrivate;
360 struct {
361 ULONG Start;
362 ULONG Length;
363 ULONG Reserved;
364 } BusNumber;
365 struct {
366 ULONG DataSize;
367 ULONG Reserved1;
368 ULONG Reserved2;
369 } DeviceSpecificData;
370 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
371 struct {
372 PHYSICAL_ADDRESS Start;
373 ULONG Length40;
374 } Memory40;
375 struct {
376 PHYSICAL_ADDRESS Start;
377 ULONG Length48;
378 } Memory48;
379 struct {
380 PHYSICAL_ADDRESS Start;
381 ULONG Length64;
382 } Memory64;
383 #endif
384 } u;
385 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
386 #include <poppack.h>
387
388 //
389 // Section map options
390 //
391 typedef enum _SECTION_INHERIT {
392 ViewShare = 1,
393 ViewUnmap = 2
394 } SECTION_INHERIT;
395
396 //
397 // Section access rights
398 //
399 #define SECTION_QUERY 0x0001
400 #define SECTION_MAP_WRITE 0x0002
401 #define SECTION_MAP_READ 0x0004
402 #define SECTION_MAP_EXECUTE 0x0008
403 #define SECTION_EXTEND_SIZE 0x0010
404 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
405
406 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
407 SECTION_MAP_WRITE | \
408 SECTION_MAP_READ | \
409 SECTION_MAP_EXECUTE | \
410 SECTION_EXTEND_SIZE)
411
412 #define SESSION_QUERY_ACCESS 0x0001
413 #define SESSION_MODIFY_ACCESS 0x0002
414
415 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
416 SESSION_QUERY_ACCESS | \
417 SESSION_MODIFY_ACCESS)
418
419
420
421 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
422
423 #define PAGE_NOACCESS 0x01
424 #define PAGE_READONLY 0x02
425 #define PAGE_READWRITE 0x04
426 #define PAGE_WRITECOPY 0x08
427 #define PAGE_EXECUTE 0x10
428 #define PAGE_EXECUTE_READ 0x20
429 #define PAGE_EXECUTE_READWRITE 0x40
430 #define PAGE_EXECUTE_WRITECOPY 0x80
431 #define PAGE_GUARD 0x100
432 #define PAGE_NOCACHE 0x200
433 #define PAGE_WRITECOMBINE 0x400
434
435 #define MEM_COMMIT 0x1000
436 #define MEM_RESERVE 0x2000
437 #define MEM_DECOMMIT 0x4000
438 #define MEM_RELEASE 0x8000
439 #define MEM_FREE 0x10000
440 #define MEM_PRIVATE 0x20000
441 #define MEM_MAPPED 0x40000
442 #define MEM_RESET 0x80000
443 #define MEM_TOP_DOWN 0x100000
444 #define MEM_LARGE_PAGES 0x20000000
445 #define MEM_4MB_PAGES 0x80000000
446
447 #define SEC_RESERVE 0x4000000
448 #define SEC_LARGE_PAGES 0x80000000
449
450 #define PROCESS_DUP_HANDLE (0x0040)
451
452 #if (NTDDI_VERSION >= NTDDI_VISTA)
453 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
454 0xFFFF)
455 #else
456 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
457 0xFFF)
458 #endif
459
460
461
462 //
463 // Processor features
464 //
465 #define PF_FLOATING_POINT_PRECISION_ERRATA 0
466 #define PF_FLOATING_POINT_EMULATED 1
467 #define PF_COMPARE_EXCHANGE_DOUBLE 2
468 #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
469 #define PF_PPC_MOVEMEM_64BIT_OK 4
470 #define PF_ALPHA_BYTE_INSTRUCTIONS 5
471 #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
472 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
473 #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
474 #define PF_PAE_ENABLED 9
475 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
476 #define PF_SSE_DAZ_MODE_AVAILABLE 11
477 #define PF_NX_ENABLED 12
478 #define PF_SSE3_INSTRUCTIONS_AVAILABLE 13
479 #define PF_COMPARE_EXCHANGE128 14
480 #define PF_COMPARE64_EXCHANGE128 15
481 #define PF_CHANNELS_ENABLED 16
482
483
484
485 //
486 // Intrinsics (note: taken from our winnt.h)
487 // FIXME: 64-bit
488 //
489 #if defined(__GNUC__)
490
491 static __inline__ BOOLEAN
492 InterlockedBitTestAndSet(IN LONG volatile *Base,
493 IN LONG Bit)
494 {
495 #if defined(_M_IX86)
496 LONG OldBit;
497 __asm__ __volatile__("lock "
498 "btsl %2,%1\n\t"
499 "sbbl %0,%0\n\t"
500 :"=r" (OldBit),"+m" (*Base)
501 :"Ir" (Bit)
502 : "memory");
503 return OldBit;
504 #else
505 return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
506 #endif
507 }
508
509 static __inline__ BOOLEAN
510 InterlockedBitTestAndReset(IN LONG volatile *Base,
511 IN LONG Bit)
512 {
513 #if defined(_M_IX86)
514 LONG OldBit;
515 __asm__ __volatile__("lock "
516 "btrl %2,%1\n\t"
517 "sbbl %0,%0\n\t"
518 :"=r" (OldBit),"+m" (*Base)
519 :"Ir" (Bit)
520 : "memory");
521 return OldBit;
522 #else
523 return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
524 #endif
525 }
526
527 #endif
528
529 #define BitScanForward _BitScanForward
530 #define BitScanReverse _BitScanReverse
531
532 #define BitTest _bittest
533 #define BitTestAndComplement _bittestandcomplement
534 #define BitTestAndSet _bittestandset
535 #define BitTestAndReset _bittestandreset
536 #define InterlockedBitTestAndSet _interlockedbittestandset
537 #define InterlockedBitTestAndReset _interlockedbittestandreset
538
539
540 /** INTERLOCKED FUNCTIONS *****************************************************/
541
542 #if !defined(__INTERLOCKED_DECLARED)
543 #define __INTERLOCKED_DECLARED
544
545 #if defined (_X86_)
546 #if defined(NO_INTERLOCKED_INTRINSICS)
547 NTKERNELAPI
548 LONG
549 FASTCALL
550 InterlockedIncrement(
551 IN OUT LONG volatile *Addend);
552
553 NTKERNELAPI
554 LONG
555 FASTCALL
556 InterlockedDecrement(
557 IN OUT LONG volatile *Addend);
558
559 NTKERNELAPI
560 LONG
561 FASTCALL
562 InterlockedCompareExchange(
563 IN OUT LONG volatile *Destination,
564 IN LONG Exchange,
565 IN LONG Comparand);
566
567 NTKERNELAPI
568 LONG
569 FASTCALL
570 InterlockedExchange(
571 IN OUT LONG volatile *Destination,
572 IN LONG Value);
573
574 NTKERNELAPI
575 LONG
576 FASTCALL
577 InterlockedExchangeAdd(
578 IN OUT LONG volatile *Addend,
579 IN LONG Value);
580
581 #else // !defined(NO_INTERLOCKED_INTRINSICS)
582
583 #define InterlockedExchange _InterlockedExchange
584 #define InterlockedIncrement _InterlockedIncrement
585 #define InterlockedDecrement _InterlockedDecrement
586 #define InterlockedExchangeAdd _InterlockedExchangeAdd
587 #define InterlockedCompareExchange _InterlockedCompareExchange
588 #define InterlockedOr _InterlockedOr
589 #define InterlockedAnd _InterlockedAnd
590 #define InterlockedXor _InterlockedXor
591
592 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
593
594 #endif // defined (_X86_)
595
596 #if !defined (_WIN64)
597 /*
598 * PVOID
599 * InterlockedExchangePointer(
600 * IN OUT PVOID volatile *Target,
601 * IN PVOID Value)
602 */
603 #define InterlockedExchangePointer(Target, Value) \
604 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
605
606 /*
607 * PVOID
608 * InterlockedCompareExchangePointer(
609 * IN OUT PVOID *Destination,
610 * IN PVOID Exchange,
611 * IN PVOID Comparand)
612 */
613 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
614 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
615
616 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
617 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
618 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
619
620 #endif // !defined (_WIN64)
621
622 #if defined (_M_AMD64)
623
624 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
625 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
626 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
627 #define InterlockedAnd _InterlockedAnd
628 #define InterlockedOr _InterlockedOr
629 #define InterlockedXor _InterlockedXor
630 #define InterlockedIncrement _InterlockedIncrement
631 #define InterlockedDecrement _InterlockedDecrement
632 #define InterlockedAdd _InterlockedAdd
633 #define InterlockedExchange _InterlockedExchange
634 #define InterlockedExchangeAdd _InterlockedExchangeAdd
635 #define InterlockedCompareExchange _InterlockedCompareExchange
636 #define InterlockedAnd64 _InterlockedAnd64
637 #define InterlockedOr64 _InterlockedOr64
638 #define InterlockedXor64 _InterlockedXor64
639 #define InterlockedIncrement64 _InterlockedIncrement64
640 #define InterlockedDecrement64 _InterlockedDecrement64
641 #define InterlockedAdd64 _InterlockedAdd64
642 #define InterlockedExchange64 _InterlockedExchange64
643 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
644 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
645 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
646 #define InterlockedExchangePointer _InterlockedExchangePointer
647 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
648 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
649
650 #endif // _M_AMD64
651
652 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
653 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
654 FORCEINLINE
655 LONG64
656 InterlockedAdd64(
657 IN OUT LONG64 volatile *Addend,
658 IN LONG64 Value)
659 {
660 return InterlockedExchangeAdd64(Addend, Value) + Value;
661 }
662 //#endif
663 #endif
664
665 #endif /* !__INTERLOCKED_DECLARED */
666
667 #if defined(_M_IX86)
668 #define YieldProcessor _mm_pause
669 #elif defined (_M_AMD64)
670 #define YieldProcessor _mm_pause
671 #elif defined(_M_PPC)
672 #define YieldProcessor() __asm__ __volatile__("nop");
673 #elif defined(_M_MIPS)
674 #define YieldProcessor() __asm__ __volatile__("nop");
675 #elif defined(_M_ARM)
676 #define YieldProcessor()
677 #else
678 #error Unknown architecture
679 #endif
680
681
682
683 //
684 // Slist Header
685 //
686 #ifndef _SLIST_HEADER_
687 #define _SLIST_HEADER_
688
689 #if defined(_WIN64)
690 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
691 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
692 PSLIST_ENTRY Next;
693 } SLIST_ENTRY;
694 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
695 struct {
696 ULONGLONG Alignment;
697 ULONGLONG Region;
698 } DUMMYSTRUCTNAME;
699 struct {
700 ULONGLONG Depth:16;
701 ULONGLONG Sequence:9;
702 ULONGLONG NextEntry:39;
703 ULONGLONG HeaderType:1;
704 ULONGLONG Init:1;
705 ULONGLONG Reserved:59;
706 ULONGLONG Region:3;
707 } Header8;
708 struct {
709 ULONGLONG Depth:16;
710 ULONGLONG Sequence:48;
711 ULONGLONG HeaderType:1;
712 ULONGLONG Init:1;
713 ULONGLONG Reserved:2;
714 ULONGLONG NextEntry:60;
715 } Header16;
716 } SLIST_HEADER, *PSLIST_HEADER;
717 #else
718 #define SLIST_ENTRY SINGLE_LIST_ENTRY
719 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
720 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
721 typedef union _SLIST_HEADER {
722 ULONGLONG Alignment;
723 struct {
724 SLIST_ENTRY Next;
725 USHORT Depth;
726 USHORT Sequence;
727 } DUMMYSTRUCTNAME;
728 } SLIST_HEADER, *PSLIST_HEADER;
729 #endif
730
731 #endif /* _SLIST_HEADER_ */
732
733
734
735 //
736 // Power States/Levels
737 //
738 typedef enum _SYSTEM_POWER_STATE {
739 PowerSystemUnspecified,
740 PowerSystemWorking,
741 PowerSystemSleeping1,
742 PowerSystemSleeping2,
743 PowerSystemSleeping3,
744 PowerSystemHibernate,
745 PowerSystemShutdown,
746 PowerSystemMaximum
747 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
748
749 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
750
751 typedef enum _POWER_INFORMATION_LEVEL {
752 SystemPowerPolicyAc,
753 SystemPowerPolicyDc,
754 VerifySystemPolicyAc,
755 VerifySystemPolicyDc,
756 SystemPowerCapabilities,
757 SystemBatteryState,
758 SystemPowerStateHandler,
759 ProcessorStateHandler,
760 SystemPowerPolicyCurrent,
761 AdministratorPowerPolicy,
762 SystemReserveHiberFile,
763 ProcessorInformation,
764 SystemPowerInformation,
765 ProcessorStateHandler2,
766 LastWakeTime,
767 LastSleepTime,
768 SystemExecutionState,
769 SystemPowerStateNotifyHandler,
770 ProcessorPowerPolicyAc,
771 ProcessorPowerPolicyDc,
772 VerifyProcessorPowerPolicyAc,
773 VerifyProcessorPowerPolicyDc,
774 ProcessorPowerPolicyCurrent
775 } POWER_INFORMATION_LEVEL;
776
777 typedef enum {
778 PowerActionNone,
779 PowerActionReserved,
780 PowerActionSleep,
781 PowerActionHibernate,
782 PowerActionShutdown,
783 PowerActionShutdownReset,
784 PowerActionShutdownOff,
785 PowerActionWarmEject
786 } POWER_ACTION, *PPOWER_ACTION;
787
788 typedef enum _DEVICE_POWER_STATE {
789 PowerDeviceUnspecified,
790 PowerDeviceD0,
791 PowerDeviceD1,
792 PowerDeviceD2,
793 PowerDeviceD3,
794 PowerDeviceMaximum
795 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
796
797 #define ES_SYSTEM_REQUIRED 0x00000001
798 #define ES_DISPLAY_REQUIRED 0x00000002
799 #define ES_USER_PRESENT 0x00000004
800 #define ES_CONTINUOUS 0x80000000
801
802 typedef ULONG EXECUTION_STATE;
803
804 typedef enum {
805 LT_DONT_CARE,
806 LT_LOWEST_LATENCY
807 } LATENCY_TIME;
808
809
810
811 //
812 // Access/Security Stuff
813 //
814 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
815 typedef PVOID PACCESS_TOKEN;
816
817 #define DELETE 0x00010000L
818 #define READ_CONTROL 0x00020000L
819 #define WRITE_DAC 0x00040000L
820 #define WRITE_OWNER 0x00080000L
821 #define SYNCHRONIZE 0x00100000L
822 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
823 #define STANDARD_RIGHTS_READ READ_CONTROL
824 #define STANDARD_RIGHTS_WRITE READ_CONTROL
825 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
826 #define STANDARD_RIGHTS_ALL 0x001F0000L
827 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
828 #define ACCESS_SYSTEM_SECURITY 0x01000000L
829 #define MAXIMUM_ALLOWED 0x02000000L
830 #define GENERIC_READ 0x80000000L
831 #define GENERIC_WRITE 0x40000000L
832 #define GENERIC_EXECUTE 0x20000000L
833 #define GENERIC_ALL 0x10000000L
834
835 typedef struct _GENERIC_MAPPING {
836 ACCESS_MASK GenericRead;
837 ACCESS_MASK GenericWrite;
838 ACCESS_MASK GenericExecute;
839 ACCESS_MASK GenericAll;
840 } GENERIC_MAPPING, *PGENERIC_MAPPING;
841
842 #define ACL_REVISION 2
843 #define ACL_REVISION_DS 4
844
845 #define ACL_REVISION1 1
846 #define ACL_REVISION2 2
847 #define ACL_REVISION3 3
848 #define ACL_REVISION4 4
849 #define MIN_ACL_REVISION ACL_REVISION2
850 #define MAX_ACL_REVISION ACL_REVISION4
851
852 typedef struct _ACL {
853 UCHAR AclRevision;
854 UCHAR Sbz1;
855 USHORT AclSize;
856 USHORT AceCount;
857 USHORT Sbz2;
858 } ACL, *PACL;
859
860
861
862 //
863 // Current security descriptor revision value
864 //
865 #define SECURITY_DESCRIPTOR_REVISION (1)
866 #define SECURITY_DESCRIPTOR_REVISION1 (1)
867
868 //
869 // Privilege attributes
870 //
871 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
872 #define SE_PRIVILEGE_ENABLED (0x00000002L)
873 #define SE_PRIVILEGE_REMOVED (0X00000004L)
874 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
875
876 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
877 SE_PRIVILEGE_ENABLED | \
878 SE_PRIVILEGE_REMOVED | \
879 SE_PRIVILEGE_USED_FOR_ACCESS)
880
881 #include <pshpack4.h>
882 typedef struct _LUID_AND_ATTRIBUTES {
883 LUID Luid;
884 ULONG Attributes;
885 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
886 #include <poppack.h>
887 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
888 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
889
890
891
892 //
893 // Privilege sets
894 //
895 #define PRIVILEGE_SET_ALL_NECESSARY (1)
896
897 typedef struct _PRIVILEGE_SET {
898 ULONG PrivilegeCount;
899 ULONG Control;
900 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
901 } PRIVILEGE_SET,*PPRIVILEGE_SET;
902
903 typedef enum _SECURITY_IMPERSONATION_LEVEL {
904 SecurityAnonymous,
905 SecurityIdentification,
906 SecurityImpersonation,
907 SecurityDelegation
908 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
909
910 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
911 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
912 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
913 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
914
915 #define SECURITY_DYNAMIC_TRACKING (TRUE)
916 #define SECURITY_STATIC_TRACKING (FALSE)
917
918 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
919
920 typedef struct _SECURITY_QUALITY_OF_SERVICE {
921 ULONG Length;
922 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
923 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
924 BOOLEAN EffectiveOnly;
925 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
926
927 typedef struct _SE_IMPERSONATION_STATE {
928 PACCESS_TOKEN Token;
929 BOOLEAN CopyOnOpen;
930 BOOLEAN EffectiveOnly;
931 SECURITY_IMPERSONATION_LEVEL Level;
932 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
933
934 #define OWNER_SECURITY_INFORMATION (0x00000001L)
935 #define GROUP_SECURITY_INFORMATION (0x00000002L)
936 #define DACL_SECURITY_INFORMATION (0x00000004L)
937 #define SACL_SECURITY_INFORMATION (0x00000008L)
938 #define LABEL_SECURITY_INFORMATION (0x00000010L)
939
940 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
941 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
942 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
943 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
944
945
946
947 //
948 // Registry Access Rights
949 //
950 #define KEY_QUERY_VALUE (0x0001)
951 #define KEY_SET_VALUE (0x0002)
952 #define KEY_CREATE_SUB_KEY (0x0004)
953 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
954 #define KEY_NOTIFY (0x0010)
955 #define KEY_CREATE_LINK (0x0020)
956 #define KEY_WOW64_32KEY (0x0200)
957 #define KEY_WOW64_64KEY (0x0100)
958 #define KEY_WOW64_RES (0x0300)
959
960 #define KEY_READ ((STANDARD_RIGHTS_READ |\
961 KEY_QUERY_VALUE |\
962 KEY_ENUMERATE_SUB_KEYS |\
963 KEY_NOTIFY) \
964 & \
965 (~SYNCHRONIZE))
966
967 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
968 KEY_SET_VALUE |\
969 KEY_CREATE_SUB_KEY) \
970 & \
971 (~SYNCHRONIZE))
972
973 #define KEY_EXECUTE ((KEY_READ) \
974 & \
975 (~SYNCHRONIZE))
976
977 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
978 KEY_QUERY_VALUE |\
979 KEY_SET_VALUE |\
980 KEY_CREATE_SUB_KEY |\
981 KEY_ENUMERATE_SUB_KEYS |\
982 KEY_NOTIFY |\
983 KEY_CREATE_LINK) \
984 & \
985 (~SYNCHRONIZE))
986
987 //
988 // Registry Open/Create Options
989 //
990 #define REG_OPTION_RESERVED (0x00000000L)
991 #define REG_OPTION_NON_VOLATILE (0x00000000L)
992 #define REG_OPTION_VOLATILE (0x00000001L)
993 #define REG_OPTION_CREATE_LINK (0x00000002L)
994 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
995 #define REG_OPTION_OPEN_LINK (0x00000008L)
996
997 #define REG_LEGAL_OPTION \
998 (REG_OPTION_RESERVED |\
999 REG_OPTION_NON_VOLATILE |\
1000 REG_OPTION_VOLATILE |\
1001 REG_OPTION_CREATE_LINK |\
1002 REG_OPTION_BACKUP_RESTORE |\
1003 REG_OPTION_OPEN_LINK)
1004
1005 //
1006 // Key creation/open disposition
1007 //
1008 #define REG_CREATED_NEW_KEY (0x00000001L)
1009 #define REG_OPENED_EXISTING_KEY (0x00000002L)
1010
1011 //
1012 // Key restore & hive load flags
1013 //
1014 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
1015 #define REG_REFRESH_HIVE (0x00000002L)
1016 #define REG_NO_LAZY_FLUSH (0x00000004L)
1017 #define REG_FORCE_RESTORE (0x00000008L)
1018 #define REG_APP_HIVE (0x00000010L)
1019 #define REG_PROCESS_PRIVATE (0x00000020L)
1020 #define REG_START_JOURNAL (0x00000040L)
1021 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
1022 #define REG_HIVE_NO_RM (0x00000100L)
1023 #define REG_HIVE_SINGLE_LOG (0x00000200L)
1024
1025 //
1026 // Unload Flags
1027 //
1028 #define REG_FORCE_UNLOAD 1
1029
1030 //
1031 // Notify Filter Values
1032 //
1033 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
1034 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
1035 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
1036 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
1037
1038 #define REG_LEGAL_CHANGE_FILTER \
1039 (REG_NOTIFY_CHANGE_NAME |\
1040 REG_NOTIFY_CHANGE_ATTRIBUTES |\
1041 REG_NOTIFY_CHANGE_LAST_SET |\
1042 REG_NOTIFY_CHANGE_SECURITY)
1043
1044
1045
1046 //
1047 // Thread Access Rights
1048 //
1049 #define THREAD_TERMINATE (0x0001)
1050 #define THREAD_SUSPEND_RESUME (0x0002)
1051 #define THREAD_ALERT (0x0004)
1052 #define THREAD_GET_CONTEXT (0x0008)
1053 #define THREAD_SET_CONTEXT (0x0010)
1054 #define THREAD_SET_INFORMATION (0x0020)
1055 #define THREAD_SET_LIMITED_INFORMATION (0x0400)
1056 #define THREAD_QUERY_LIMITED_INFORMATION (0x0800)
1057 #if (NTDDI_VERSION >= NTDDI_VISTA)
1058 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
1059 0xFFFF)
1060 #else
1061 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
1062 0x3FF)
1063 #endif
1064
1065 //
1066 // Service Start Types
1067 //
1068 #define SERVICE_BOOT_START 0x00000000
1069 #define SERVICE_SYSTEM_START 0x00000001
1070 #define SERVICE_AUTO_START 0x00000002
1071 #define SERVICE_DEMAND_START 0x00000003
1072 #define SERVICE_DISABLED 0x00000004
1073
1074 //
1075 // Exception Records
1076 //
1077 #define EXCEPTION_NONCONTINUABLE 1
1078 #define EXCEPTION_MAXIMUM_PARAMETERS 15
1079
1080 typedef struct _EXCEPTION_RECORD {
1081 NTSTATUS ExceptionCode;
1082 ULONG ExceptionFlags;
1083 struct _EXCEPTION_RECORD *ExceptionRecord;
1084 PVOID ExceptionAddress;
1085 ULONG NumberParameters;
1086 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1087 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
1088
1089 typedef struct _EXCEPTION_RECORD32 {
1090 NTSTATUS ExceptionCode;
1091 ULONG ExceptionFlags;
1092 ULONG ExceptionRecord;
1093 ULONG ExceptionAddress;
1094 ULONG NumberParameters;
1095 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1096 } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
1097
1098 typedef struct _EXCEPTION_RECORD64 {
1099 NTSTATUS ExceptionCode;
1100 ULONG ExceptionFlags;
1101 ULONG64 ExceptionRecord;
1102 ULONG64 ExceptionAddress;
1103 ULONG NumberParameters;
1104 ULONG __unusedAlignment;
1105 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
1106 } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
1107
1108 typedef struct _EXCEPTION_POINTERS {
1109 PEXCEPTION_RECORD ExceptionRecord;
1110 PCONTEXT ContextRecord;
1111 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
1112
1113
1114
1115 //
1116 // Process Qoutas
1117 //
1118 typedef struct _QUOTA_LIMITS {
1119 SIZE_T PagedPoolLimit;
1120 SIZE_T NonPagedPoolLimit;
1121 SIZE_T MinimumWorkingSetSize;
1122 SIZE_T MaximumWorkingSetSize;
1123 SIZE_T PagefileLimit;
1124 LARGE_INTEGER TimeLimit;
1125 } QUOTA_LIMITS, *PQUOTA_LIMITS;
1126
1127 #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
1128 #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
1129 #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
1130 #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
1131 #define QUOTA_LIMITS_USE_DEFAULT_LIMITS 0x00000010
1132
1133
1134 /******************************************************************************
1135 * WINBASE Functions *
1136 ******************************************************************************/
1137 #if !defined(_WINBASE_)
1138
1139 #if defined(_WIN64)
1140
1141 #define InterlockedPopEntrySList(Head) \
1142 ExpInterlockedPopEntrySList(Head)
1143
1144 #define InterlockedPushEntrySList(Head, Entry) \
1145 ExpInterlockedPushEntrySList(Head, Entry)
1146
1147 #define InterlockedFlushSList(Head) \
1148 ExpInterlockedFlushSList(Head)
1149
1150 #define QueryDepthSList(Head) \
1151 ExQueryDepthSList(Head)
1152
1153 #else // !defined(_WIN64)
1154
1155 NTKERNELAPI
1156 PSLIST_ENTRY
1157 FASTCALL
1158 InterlockedPopEntrySList(
1159 IN PSLIST_HEADER ListHead);
1160
1161 NTKERNELAPI
1162 PSLIST_ENTRY
1163 FASTCALL
1164 InterlockedPushEntrySList(
1165 IN PSLIST_HEADER ListHead,
1166 IN PSLIST_ENTRY ListEntry);
1167
1168 #define InterlockedFlushSList(ListHead) \
1169 ExInterlockedFlushSList(ListHead)
1170
1171 #define QueryDepthSList(Head) \
1172 ExQueryDepthSList(Head)
1173
1174 #endif // !defined(_WIN64)
1175
1176 #endif // !defined(_WINBASE_)
1177
1178
1179 /******************************************************************************
1180 * Kernel Types *
1181 ******************************************************************************/
1182
1183 typedef struct _DISPATCHER_HEADER
1184 {
1185 __GNU_EXTENSION union
1186 {
1187 __GNU_EXTENSION struct
1188 {
1189 UCHAR Type;
1190 __GNU_EXTENSION union
1191 {
1192 UCHAR Absolute;
1193 UCHAR NpxIrql;
1194 };
1195 __GNU_EXTENSION union
1196 {
1197 UCHAR Size;
1198 UCHAR Hand;
1199 };
1200 __GNU_EXTENSION union
1201 {
1202 UCHAR Inserted;
1203 BOOLEAN DebugActive;
1204 };
1205 };
1206 volatile LONG Lock;
1207 };
1208 LONG SignalState;
1209 LIST_ENTRY WaitListHead;
1210 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
1211
1212 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
1213
1214 typedef struct _KEVENT {
1215 DISPATCHER_HEADER Header;
1216 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
1217
1218 typedef struct _KSEMAPHORE {
1219 DISPATCHER_HEADER Header;
1220 LONG Limit;
1221 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
1222
1223 /******************************************************************************
1224 * RTL Types *
1225 ******************************************************************************/
1226
1227 #define RTL_REGISTRY_ABSOLUTE 0
1228 #define RTL_REGISTRY_SERVICES 1
1229 #define RTL_REGISTRY_CONTROL 2
1230 #define RTL_REGISTRY_WINDOWS_NT 3
1231 #define RTL_REGISTRY_DEVICEMAP 4
1232 #define RTL_REGISTRY_USER 5
1233 #define RTL_REGISTRY_MAXIMUM 6
1234 #define RTL_REGISTRY_HANDLE 0x40000000
1235 #define RTL_REGISTRY_OPTIONAL 0x80000000
1236
1237 /* RTL_QUERY_REGISTRY_TABLE.Flags */
1238 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
1239 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
1240 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
1241 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
1242 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
1243 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
1244 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
1245
1246 typedef struct _RTL_BITMAP {
1247 ULONG SizeOfBitMap;
1248 PULONG Buffer;
1249 } RTL_BITMAP, *PRTL_BITMAP;
1250
1251 typedef struct _RTL_BITMAP_RUN {
1252 ULONG StartingIndex;
1253 ULONG NumberOfBits;
1254 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
1255
1256 typedef NTSTATUS
1257 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
1258 IN PWSTR ValueName,
1259 IN ULONG ValueType,
1260 IN PVOID ValueData,
1261 IN ULONG ValueLength,
1262 IN PVOID Context,
1263 IN PVOID EntryContext);
1264
1265 typedef struct _RTL_QUERY_REGISTRY_TABLE {
1266 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
1267 ULONG Flags;
1268 PCWSTR Name;
1269 PVOID EntryContext;
1270 ULONG DefaultType;
1271 PVOID DefaultData;
1272 ULONG DefaultLength;
1273 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
1274
1275 typedef struct _TIME_FIELDS {
1276 CSHORT Year;
1277 CSHORT Month;
1278 CSHORT Day;
1279 CSHORT Hour;
1280 CSHORT Minute;
1281 CSHORT Second;
1282 CSHORT Milliseconds;
1283 CSHORT Weekday;
1284 } TIME_FIELDS, *PTIME_FIELDS;
1285
1286
1287 /******************************************************************************
1288 * RTL Functions *
1289 ******************************************************************************/
1290
1291 NTSYSAPI
1292 VOID
1293 NTAPI
1294 RtlAssert(
1295 IN PVOID FailedAssertion,
1296 IN PVOID FileName,
1297 IN ULONG LineNumber,
1298 IN PCHAR Message);
1299
1300 /* VOID
1301 * RtlCopyMemory(
1302 * IN VOID UNALIGNED *Destination,
1303 * IN CONST VOID UNALIGNED *Source,
1304 * IN SIZE_T Length)
1305 */
1306 #define RtlCopyMemory(Destination, Source, Length) \
1307 memcpy(Destination, Source, Length)
1308
1309 #define RtlCopyBytes RtlCopyMemory
1310
1311 #if defined(_M_AMD64)
1312 NTSYSAPI
1313 VOID
1314 NTAPI
1315 RtlCopyMemoryNonTemporal(
1316 VOID UNALIGNED *Destination,
1317 CONST VOID UNALIGNED *Source,
1318 SIZE_T Length);
1319 #else
1320 #define RtlCopyMemoryNonTemporal RtlCopyMemory
1321 #endif
1322
1323 /* BOOLEAN
1324 * RtlEqualLuid(
1325 * IN PLUID Luid1,
1326 * IN PLUID Luid2)
1327 */
1328 #define RtlEqualLuid(Luid1, Luid2) \
1329 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
1330
1331 /* ULONG
1332 * RtlEqualMemory(
1333 * IN VOID UNALIGNED *Destination,
1334 * IN CONST VOID UNALIGNED *Source,
1335 * IN SIZE_T Length)
1336 */
1337 #define RtlEqualMemory(Destination, Source, Length) \
1338 (!memcmp(Destination, Source, Length))
1339
1340 /* VOID
1341 * RtlFillMemory(
1342 * IN VOID UNALIGNED *Destination,
1343 * IN SIZE_T Length,
1344 * IN UCHAR Fill)
1345 */
1346 #define RtlFillMemory(Destination, Length, Fill) \
1347 memset(Destination, Fill, Length)
1348
1349 #define RtlFillBytes RtlFillMemory
1350
1351 NTSYSAPI
1352 VOID
1353 NTAPI
1354 RtlFreeUnicodeString(
1355 IN PUNICODE_STRING UnicodeString);
1356
1357 NTSYSAPI
1358 NTSTATUS
1359 NTAPI
1360 RtlGUIDFromString(
1361 IN PUNICODE_STRING GuidString,
1362 OUT GUID *Guid);
1363
1364 NTSYSAPI
1365 VOID
1366 NTAPI
1367 RtlInitUnicodeString(
1368 IN OUT PUNICODE_STRING DestinationString,
1369 IN PCWSTR SourceString);
1370
1371 /* VOID
1372 * RtlMoveMemory(
1373 * IN VOID UNALIGNED *Destination,
1374 * IN CONST VOID UNALIGNED *Source,
1375 * IN SIZE_T Length)
1376 */
1377 #define RtlMoveMemory(Destination, Source, Length) \
1378 memmove(Destination, Source, Length)
1379
1380 NTSYSAPI
1381 NTSTATUS
1382 NTAPI
1383 RtlStringFromGUID(
1384 IN REFGUID Guid,
1385 OUT PUNICODE_STRING GuidString);
1386
1387 /* VOID
1388 * RtlZeroMemory(
1389 * IN VOID UNALIGNED *Destination,
1390 * IN SIZE_T Length)
1391 */
1392 #define RtlZeroMemory(Destination, Length) \
1393 memset(Destination, 0, Length)
1394
1395 #define RtlZeroBytes RtlZeroMemory
1396
1397
1398 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1399 NTSYSAPI
1400 BOOLEAN
1401 NTAPI
1402 RtlAreBitsClear(
1403 IN PRTL_BITMAP BitMapHeader,
1404 IN ULONG StartingIndex,
1405 IN ULONG Length);
1406
1407 NTSYSAPI
1408 BOOLEAN
1409 NTAPI
1410 RtlAreBitsSet(
1411 IN PRTL_BITMAP BitMapHeader,
1412 IN ULONG StartingIndex,
1413 IN ULONG Length);
1414
1415 NTSYSAPI
1416 NTSTATUS
1417 NTAPI
1418 RtlAnsiStringToUnicodeString(
1419 IN OUT PUNICODE_STRING DestinationString,
1420 IN PANSI_STRING SourceString,
1421 IN BOOLEAN AllocateDestinationString);
1422
1423 NTSYSAPI
1424 ULONG
1425 NTAPI
1426 RtlxAnsiStringToUnicodeSize(
1427 IN PCANSI_STRING AnsiString);
1428
1429 #define RtlAnsiStringToUnicodeSize(String) ( \
1430 NLS_MB_CODE_PAGE_TAG ? \
1431 RtlxAnsiStringToUnicodeSize(String) : \
1432 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
1433 )
1434
1435 NTSYSAPI
1436 NTSTATUS
1437 NTAPI
1438 RtlAppendUnicodeStringToString(
1439 IN OUT PUNICODE_STRING Destination,
1440 IN PCUNICODE_STRING Source);
1441
1442 NTSYSAPI
1443 NTSTATUS
1444 NTAPI
1445 RtlAppendUnicodeToString(
1446 IN OUT PUNICODE_STRING Destination,
1447 IN PCWSTR Source);
1448
1449 NTSYSAPI
1450 NTSTATUS
1451 NTAPI
1452 RtlCheckRegistryKey(
1453 IN ULONG RelativeTo,
1454 IN PWSTR Path);
1455
1456 NTSYSAPI
1457 VOID
1458 NTAPI
1459 RtlClearAllBits(
1460 IN PRTL_BITMAP BitMapHeader);
1461
1462 NTSYSAPI
1463 VOID
1464 NTAPI
1465 RtlClearBits(
1466 IN PRTL_BITMAP BitMapHeader,
1467 IN ULONG StartingIndex,
1468 IN ULONG NumberToClear);
1469
1470 NTSYSAPI
1471 SIZE_T
1472 NTAPI
1473 RtlCompareMemory(
1474 IN CONST VOID *Source1,
1475 IN CONST VOID *Source2,
1476 IN SIZE_T Length);
1477
1478 NTSYSAPI
1479 LONG
1480 NTAPI
1481 RtlCompareUnicodeString(
1482 IN PCUNICODE_STRING String1,
1483 IN PCUNICODE_STRING String2,
1484 IN BOOLEAN CaseInSensitive);
1485
1486 NTSYSAPI
1487 LONG
1488 NTAPI
1489 RtlCompareUnicodeStrings(
1490 IN PCWCH String1,
1491 IN SIZE_T String1Length,
1492 IN PCWCH String2,
1493 IN SIZE_T String2Length,
1494 IN BOOLEAN CaseInSensitive);
1495
1496 NTSYSAPI
1497 VOID
1498 NTAPI
1499 RtlCopyUnicodeString(
1500 IN OUT PUNICODE_STRING DestinationString,
1501 IN PCUNICODE_STRING SourceString);
1502
1503 NTSYSAPI
1504 NTSTATUS
1505 NTAPI
1506 RtlCreateRegistryKey(
1507 IN ULONG RelativeTo,
1508 IN PWSTR Path);
1509
1510 NTSYSAPI
1511 NTSTATUS
1512 NTAPI
1513 RtlCreateSecurityDescriptor(
1514 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
1515 IN ULONG Revision);
1516
1517 NTSYSAPI
1518 NTSTATUS
1519 NTAPI
1520 RtlDeleteRegistryValue(
1521 IN ULONG RelativeTo,
1522 IN PCWSTR Path,
1523 IN PCWSTR ValueName);
1524
1525 NTSYSAPI
1526 BOOLEAN
1527 NTAPI
1528 RtlEqualUnicodeString(
1529 IN CONST UNICODE_STRING *String1,
1530 IN CONST UNICODE_STRING *String2,
1531 IN BOOLEAN CaseInSensitive);
1532
1533 #if !defined(_AMD64_) && !defined(_IA64_)
1534 NTSYSAPI
1535 LARGE_INTEGER
1536 NTAPI
1537 RtlExtendedIntegerMultiply(
1538 IN LARGE_INTEGER Multiplicand,
1539 IN LONG Multiplier);
1540
1541 NTSYSAPI
1542 LARGE_INTEGER
1543 NTAPI
1544 RtlExtendedLargeIntegerDivide(
1545 IN LARGE_INTEGER Dividend,
1546 IN ULONG Divisor,
1547 IN OUT PULONG Remainder);
1548 #endif
1549
1550 #if defined(_X86_) || defined(_IA64_)
1551 NTSYSAPI
1552 LARGE_INTEGER
1553 NTAPI
1554 RtlExtendedMagicDivide(
1555 IN LARGE_INTEGER Dividend,
1556 IN LARGE_INTEGER MagicDivisor,
1557 IN CCHAR ShiftCount);
1558 #endif
1559
1560 NTSYSAPI
1561 VOID
1562 NTAPI
1563 RtlFreeAnsiString(
1564 IN PANSI_STRING AnsiString);
1565
1566 NTSYSAPI
1567 ULONG
1568 NTAPI
1569 RtlFindClearBits(
1570 IN PRTL_BITMAP BitMapHeader,
1571 IN ULONG NumberToFind,
1572 IN ULONG HintIndex);
1573
1574 NTSYSAPI
1575 ULONG
1576 NTAPI
1577 RtlFindClearBitsAndSet(
1578 IN PRTL_BITMAP BitMapHeader,
1579 IN ULONG NumberToFind,
1580 IN ULONG HintIndex);
1581
1582 NTSYSAPI
1583 ULONG
1584 NTAPI
1585 RtlFindFirstRunClear(
1586 IN PRTL_BITMAP BitMapHeader,
1587 OUT PULONG StartingIndex);
1588
1589 NTSYSAPI
1590 ULONG
1591 NTAPI
1592 RtlFindClearRuns(
1593 IN PRTL_BITMAP BitMapHeader,
1594 OUT PRTL_BITMAP_RUN RunArray,
1595 IN ULONG SizeOfRunArray,
1596 IN BOOLEAN LocateLongestRuns);
1597
1598 NTSYSAPI
1599 ULONG
1600 NTAPI
1601 RtlFindLastBackwardRunClear(
1602 IN PRTL_BITMAP BitMapHeader,
1603 IN ULONG FromIndex,
1604 OUT PULONG StartingRunIndex);
1605
1606 NTSYSAPI
1607 CCHAR
1608 NTAPI
1609 RtlFindLeastSignificantBit(
1610 IN ULONGLONG Set);
1611
1612 NTSYSAPI
1613 ULONG
1614 NTAPI
1615 RtlFindLongestRunClear(
1616 IN PRTL_BITMAP BitMapHeader,
1617 OUT PULONG StartingIndex);
1618
1619 NTSYSAPI
1620 CCHAR
1621 NTAPI
1622 RtlFindMostSignificantBit(
1623 IN ULONGLONG Set);
1624
1625 NTSYSAPI
1626 ULONG
1627 NTAPI
1628 RtlFindNextForwardRunClear(
1629 IN PRTL_BITMAP BitMapHeader,
1630 IN ULONG FromIndex,
1631 OUT PULONG StartingRunIndex);
1632
1633 NTSYSAPI
1634 ULONG
1635 NTAPI
1636 RtlFindSetBits(
1637 IN PRTL_BITMAP BitMapHeader,
1638 IN ULONG NumberToFind,
1639 IN ULONG HintIndex);
1640
1641 NTSYSAPI
1642 ULONG
1643 NTAPI
1644 RtlFindSetBitsAndClear(
1645 IN PRTL_BITMAP BitMapHeader,
1646 IN ULONG NumberToFind,
1647 IN ULONG HintIndex);
1648
1649 NTSYSAPI
1650 NTSTATUS
1651 NTAPI
1652 RtlHashUnicodeString(
1653 IN CONST UNICODE_STRING *String,
1654 IN BOOLEAN CaseInSensitive,
1655 IN ULONG HashAlgorithm,
1656 OUT PULONG HashValue);
1657
1658 NTSYSAPI
1659 VOID
1660 NTAPI
1661 RtlInitAnsiString(
1662 IN OUT PANSI_STRING DestinationString,
1663 IN PCSZ SourceString);
1664
1665 NTSYSAPI
1666 VOID
1667 NTAPI
1668 RtlInitializeBitMap(
1669 IN PRTL_BITMAP BitMapHeader,
1670 IN PULONG BitMapBuffer,
1671 IN ULONG SizeOfBitMap);
1672
1673 NTSYSAPI
1674 VOID
1675 NTAPI
1676 RtlInitString(
1677 IN OUT PSTRING DestinationString,
1678 IN PCSZ SourceString);
1679
1680 NTSYSAPI
1681 NTSTATUS
1682 NTAPI
1683 RtlIntegerToUnicodeString(
1684 IN ULONG Value,
1685 IN ULONG Base OPTIONAL,
1686 IN OUT PUNICODE_STRING String);
1687
1688 NTSYSAPI
1689 NTSTATUS
1690 NTAPI
1691 RtlInt64ToUnicodeString(
1692 IN ULONGLONG Value,
1693 IN ULONG Base OPTIONAL,
1694 IN OUT PUNICODE_STRING String);
1695
1696 #ifdef _WIN64
1697 #define RtlIntPtrToUnicodeString(Value, Base, String) \
1698 RtlInt64ToUnicodeString(Value, Base, String)
1699 #else
1700 #define RtlIntPtrToUnicodeString(Value, Base, String) \
1701 RtlIntegerToUnicodeString(Value, Base, String)
1702 #endif
1703
1704 /* BOOLEAN
1705 * RtlIsZeroLuid(
1706 * IN PLUID L1);
1707 */
1708 #define RtlIsZeroLuid(_L1) \
1709 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
1710
1711 NTSYSAPI
1712 ULONG
1713 NTAPI
1714 RtlLengthSecurityDescriptor(
1715 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
1716
1717 NTSYSAPI
1718 ULONG
1719 NTAPI
1720 RtlNumberOfClearBits(
1721 IN PRTL_BITMAP BitMapHeader);
1722
1723 NTSYSAPI
1724 ULONG
1725 NTAPI
1726 RtlNumberOfSetBits(
1727 IN PRTL_BITMAP BitMapHeader);
1728
1729 NTSYSAPI
1730 NTSTATUS
1731 NTAPI
1732 RtlQueryRegistryValues(
1733 IN ULONG RelativeTo,
1734 IN PCWSTR Path,
1735 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
1736 IN PVOID Context,
1737 IN PVOID Environment OPTIONAL);
1738
1739 #define LONG_SIZE (sizeof(LONG))
1740 #define LONG_MASK (LONG_SIZE - 1)
1741
1742 /* VOID
1743 * RtlRetrieveUlong(
1744 * PULONG DestinationAddress,
1745 * PULONG SourceAddress);
1746 */
1747 #if defined(_AMD64_)
1748 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
1749 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
1750 #else
1751 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
1752 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
1753 { \
1754 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
1755 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
1756 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
1757 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
1758 } \
1759 else \
1760 { \
1761 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
1762 }
1763 #endif
1764
1765 /* VOID
1766 * RtlRetrieveUshort(
1767 * PUSHORT DestinationAddress,
1768 * PUSHORT SourceAddress);
1769 */
1770 #if defined(_AMD64_)
1771 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
1772 *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
1773 #else
1774 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
1775 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
1776 { \
1777 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
1778 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
1779 } \
1780 else \
1781 { \
1782 *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
1783 }
1784 #endif
1785
1786 NTSYSAPI
1787 VOID
1788 NTAPI
1789 RtlSetAllBits(
1790 IN PRTL_BITMAP BitMapHeader);
1791
1792 NTSYSAPI
1793 VOID
1794 NTAPI
1795 RtlSetBits(
1796 IN PRTL_BITMAP BitMapHeader,
1797 IN ULONG StartingIndex,
1798 IN ULONG NumberToSet);
1799
1800 NTSYSAPI
1801 NTSTATUS
1802 NTAPI
1803 RtlSetDaclSecurityDescriptor(
1804 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
1805 IN BOOLEAN DaclPresent,
1806 IN PACL Dacl OPTIONAL,
1807 IN BOOLEAN DaclDefaulted OPTIONAL);
1808
1809 /* VOID
1810 * RtlStoreUlong(
1811 * IN PULONG Address,
1812 * IN ULONG Value);
1813 */
1814 #if defined(_AMD64_)
1815 #define RtlStoreUlong(Address,Value) \
1816 *(ULONG UNALIGNED *)(Address) = (Value)
1817 #else
1818 #define RtlStoreUlong(Address,Value) \
1819 if ((ULONG_PTR)(Address) & LONG_MASK) { \
1820 ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
1821 ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
1822 ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
1823 ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT] = (UCHAR)(FOURTHBYTE(Value)); \
1824 } \
1825 else { \
1826 *((PULONG)(Address)) = (ULONG) (Value); \
1827 }
1828 #endif
1829
1830 /* VOID
1831 * RtlStoreUlonglong(
1832 * IN OUT PULONGLONG Address,
1833 * ULONGLONG Value);
1834 */
1835 #if defined(_AMD64_)
1836 #define RtlStoreUlonglong(Address,Value) \
1837 *(ULONGLONG UNALIGNED *)(Address) = (Value)
1838 #else
1839 #define RtlStoreUlonglong(Address,Value) \
1840 if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
1841 RtlStoreUlong((ULONG_PTR)(Address), \
1842 (ULONGLONG)(Value) & 0xFFFFFFFF); \
1843 RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
1844 (ULONGLONG)(Value) >> 32); \
1845 } else { \
1846 *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
1847 }
1848 #endif
1849
1850 /* VOID
1851 * RtlStoreUlongPtr(
1852 * IN OUT PULONG_PTR Address,
1853 * IN ULONG_PTR Value);
1854 */
1855 #ifdef _WIN64
1856 #define RtlStoreUlongPtr(Address,Value) \
1857 RtlStoreUlonglong(Address,Value)
1858 #else
1859 #define RtlStoreUlongPtr(Address,Value) \
1860 RtlStoreUlong(Address,Value)
1861 #endif
1862
1863 /* VOID
1864 * RtlStoreUshort(
1865 * IN PUSHORT Address,
1866 * IN USHORT Value);
1867 */
1868 #if defined(_AMD64_)
1869 #define RtlStoreUshort(Address,Value) \
1870 *(USHORT UNALIGNED *)(Address) = (Value)
1871 #else
1872 #define RtlStoreUshort(Address,Value) \
1873 if ((ULONG_PTR)(Address) & SHORT_MASK) { \
1874 ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
1875 ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
1876 } \
1877 else { \
1878 *((PUSHORT) (Address)) = (USHORT)Value; \
1879 }
1880 #endif
1881
1882 NTSYSAPI
1883 BOOLEAN
1884 NTAPI
1885 RtlTimeFieldsToTime(
1886 IN PTIME_FIELDS TimeFields,
1887 IN PLARGE_INTEGER Time);
1888
1889 NTSYSAPI
1890 VOID
1891 NTAPI
1892 RtlTimeToTimeFields(
1893 IN PLARGE_INTEGER Time,
1894 IN PTIME_FIELDS TimeFields);
1895
1896 NTSYSAPI
1897 ULONG
1898 FASTCALL
1899 RtlUlongByteSwap(
1900 IN ULONG Source);
1901
1902 NTSYSAPI
1903 ULONGLONG
1904 FASTCALL
1905 RtlUlonglongByteSwap(
1906 IN ULONGLONG Source);
1907
1908 NTSYSAPI
1909 NTSTATUS
1910 NTAPI
1911 RtlUnicodeStringToAnsiString(
1912 IN OUT PANSI_STRING DestinationString,
1913 IN PCUNICODE_STRING SourceString,
1914 IN BOOLEAN AllocateDestinationString);
1915
1916 NTSYSAPI
1917 ULONG
1918 NTAPI
1919 RtlxUnicodeStringToAnsiSize(
1920 IN PCUNICODE_STRING UnicodeString);
1921
1922 #define RtlUnicodeStringToAnsiSize(String) ( \
1923 NLS_MB_CODE_PAGE_TAG ? \
1924 RtlxUnicodeStringToAnsiSize(String) : \
1925 ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
1926 )
1927
1928 NTSYSAPI
1929 NTSTATUS
1930 NTAPI
1931 RtlUnicodeStringToInteger(
1932 IN PCUNICODE_STRING String,
1933 IN ULONG Base OPTIONAL,
1934 OUT PULONG Value);
1935
1936 NTSYSAPI
1937 WCHAR
1938 NTAPI
1939 RtlUpcaseUnicodeChar(
1940 IN WCHAR SourceCharacter);
1941
1942 NTSYSAPI
1943 USHORT
1944 FASTCALL
1945 RtlUshortByteSwap(
1946 IN USHORT Source);
1947
1948 NTSYSAPI
1949 BOOLEAN
1950 NTAPI
1951 RtlValidRelativeSecurityDescriptor(
1952 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
1953 IN ULONG SecurityDescriptorLength,
1954 IN SECURITY_INFORMATION RequiredInformation);
1955
1956 NTSYSAPI
1957 BOOLEAN
1958 NTAPI
1959 RtlValidSecurityDescriptor(
1960 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
1961
1962 NTSYSAPI
1963 NTSTATUS
1964 NTAPI
1965 RtlWriteRegistryValue(
1966 IN ULONG RelativeTo,
1967 IN PCWSTR Path,
1968 IN PCWSTR ValueName,
1969 IN ULONG ValueType,
1970 IN PVOID ValueData,
1971 IN ULONG ValueLength);
1972
1973 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
1974
1975 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
1976 NTSYSAPI
1977 VOID
1978 FASTCALL
1979 RtlPrefetchMemoryNonTemporal(
1980 IN PVOID Source,
1981 IN SIZE_T Length);
1982 #endif
1983
1984 #if (NTDDI_VERSION >= NTDDI_WINXP)
1985 NTSYSAPI
1986 VOID
1987 NTAPI
1988 RtlClearBit(
1989 PRTL_BITMAP BitMapHeader,
1990 ULONG BitNumber);
1991
1992 NTSYSAPI
1993 WCHAR
1994 NTAPI
1995 RtlDowncaseUnicodeChar(
1996 IN WCHAR SourceCharacter);
1997
1998 NTSYSAPI
1999 VOID
2000 NTAPI
2001 RtlSetBit(
2002 PRTL_BITMAP BitMapHeader,
2003 ULONG BitNumber);
2004
2005 NTSYSAPI
2006 BOOLEAN
2007 NTAPI
2008 RtlTestBit(
2009 IN PRTL_BITMAP BitMapHeader,
2010 IN ULONG BitNumber);
2011
2012 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
2013
2014 #if (NTDDI_VERSION >= NTDDI_VISTA)
2015 NTSYSAPI
2016 ULONG
2017 NTAPI
2018 RtlNumberOfSetBitsUlongPtr(
2019 IN ULONG_PTR Target);
2020
2021 NTSYSAPI
2022 ULONGLONG
2023 NTAPI
2024 RtlIoDecodeMemIoResource (
2025 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
2026 OUT PULONGLONG Alignment OPTIONAL,
2027 OUT PULONGLONG MinimumAddress OPTIONAL,
2028 OUT PULONGLONG MaximumAddress OPTIONAL);
2029
2030 NTSYSAPI
2031 NTSTATUS
2032 NTAPI
2033 RtlIoEncodeMemIoResource(
2034 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
2035 IN UCHAR Type,
2036 IN ULONGLONG Length,
2037 IN ULONGLONG Alignment,
2038 IN ULONGLONG MinimumAddress,
2039 IN ULONGLONG MaximumAddress);
2040
2041 NTSYSAPI
2042 ULONGLONG
2043 NTAPI
2044 RtlCmDecodeMemIoResource(
2045 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
2046 OUT PULONGLONG Start OPTIONAL);
2047
2048 NTSYSAPI
2049 NTSTATUS
2050 NTAPI
2051 RtlFindClosestEncodableLength(
2052 IN ULONGLONG SourceLength,
2053 OUT PULONGLONG TargetLength);
2054
2055 #endif
2056
2057 #if !defined(MIDL_PASS)
2058 /* inline funftions */
2059 //DECLSPEC_DEPRECATED_DDK_WINXP
2060 static __inline
2061 LARGE_INTEGER
2062 NTAPI_INLINE
2063 RtlConvertLongToLargeInteger(LONG SignedInteger)
2064 {
2065 LARGE_INTEGER ret;
2066 ret.QuadPart = SignedInteger;
2067 return ret;
2068 }
2069
2070 //DECLSPEC_DEPRECATED_DDK_WINXP
2071 static __inline
2072 LARGE_INTEGER
2073 NTAPI_INLINE
2074 RtlConvertUlongToLargeInteger(
2075 ULONG UnsignedInteger)
2076 {
2077 LARGE_INTEGER ret;
2078 ret.QuadPart = UnsignedInteger;
2079 return ret;
2080 }
2081
2082 //DECLSPEC_DEPRECATED_DDK
2083 static __inline
2084 ULONG
2085 NTAPI_INLINE
2086 RtlEnlargedUnsignedDivide(
2087 IN ULARGE_INTEGER Dividend,
2088 IN ULONG Divisor,
2089 IN OUT PULONG Remainder)
2090 {
2091 if (Remainder)
2092 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
2093 return (ULONG)(Dividend.QuadPart / Divisor);
2094 }
2095
2096 //DECLSPEC_DEPRECATED_DDK
2097 static __inline
2098 LARGE_INTEGER
2099 NTAPI_INLINE
2100 RtlEnlargedUnsignedMultiply(
2101 IN ULONG Multiplicand,
2102 IN ULONG Multiplier)
2103 {
2104 LARGE_INTEGER ret;
2105 ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
2106 return ret;
2107 }
2108
2109 //DECLSPEC_DEPRECATED_DDK
2110 static __inline
2111 LARGE_INTEGER
2112 NTAPI_INLINE
2113 RtlEnlargedIntegerMultiply(
2114 IN LONG Multiplicand,
2115 IN LONG Multiplier)
2116 {
2117 LARGE_INTEGER ret;
2118 ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
2119 return ret;
2120 }
2121
2122 FORCEINLINE
2123 VOID
2124 RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
2125 IN PCHAR Buffer,
2126 IN USHORT BufferSize)
2127 {
2128 AnsiString->Length = 0;
2129 AnsiString->MaximumLength = BufferSize;
2130 AnsiString->Buffer = Buffer;
2131 }
2132
2133 FORCEINLINE
2134 VOID
2135 RtlInitEmptyUnicodeString(
2136 OUT PUNICODE_STRING UnicodeString,
2137 IN PWSTR Buffer,
2138 IN USHORT BufferSize)
2139 {
2140 UnicodeString->Length = 0;
2141 UnicodeString->MaximumLength = BufferSize;
2142 UnicodeString->Buffer = Buffer;
2143 }
2144
2145 #if defined(_AMD64_) || defined(_IA64_)
2146 static __inline
2147 LARGE_INTEGER
2148 NTAPI_INLINE
2149 RtlExtendedIntegerMultiply(
2150 LARGE_INTEGER Multiplicand,
2151 LONG Multiplier)
2152 {
2153 LARGE_INTEGER ret;
2154 ret.QuadPart = Multiplicand.QuadPart * Multiplier;
2155 return ret;
2156 }
2157
2158 static __inline
2159 LARGE_INTEGER
2160 NTAPI_INLINE
2161 RtlExtendedLargeIntegerDivide(
2162 LARGE_INTEGER Dividend,
2163 ULONG Divisor,
2164 PULONG Remainder)
2165 {
2166 LARGE_INTEGER ret;
2167 ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
2168 if (Remainder)
2169 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
2170 return ret;
2171 }
2172 #endif
2173
2174 #if defined(_AMD64_)
2175
2176 #define MultiplyHigh __mulh
2177 #define UnsignedMultiplyHigh __umulh
2178
2179 //DECLSPEC_DEPRECATED_DDK
2180 static __inline
2181 LARGE_INTEGER
2182 NTAPI_INLINE
2183 RtlExtendedMagicDivide(
2184 IN LARGE_INTEGER Dividend,
2185 IN LARGE_INTEGER MagicDivisor,
2186 IN CCHAR ShiftCount)
2187 {
2188 LARGE_INTEGER ret;
2189 ULONG64 ret64;
2190 BOOLEAN Pos;
2191 Pos = (Dividend.QuadPart >= 0);
2192 ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
2193 MagicDivisor.QuadPart);
2194 ret64 >>= ShiftCount;
2195 ret.QuadPart = Pos ? ret64 : -ret64;
2196 return ret;
2197 }
2198 #endif
2199
2200 //DECLSPEC_DEPRECATED_DDK
2201 static __inline
2202 LARGE_INTEGER
2203 NTAPI_INLINE
2204 RtlLargeIntegerAdd(
2205 IN LARGE_INTEGER Addend1,
2206 IN LARGE_INTEGER Addend2)
2207 {
2208 LARGE_INTEGER ret;
2209 ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
2210 return ret;
2211 }
2212
2213 /* VOID
2214 * RtlLargeIntegerAnd(
2215 * IN OUT LARGE_INTEGER Result,
2216 * IN LARGE_INTEGER Source,
2217 * IN LARGE_INTEGER Mask);
2218 */
2219 #define RtlLargeIntegerAnd(Result, Source, Mask) \
2220 Result.QuadPart = Source.QuadPart & Mask.QuadPart
2221
2222 //DECLSPEC_DEPRECATED_DDK
2223 static __inline
2224 LARGE_INTEGER
2225 NTAPI_INLINE
2226 RtlLargeIntegerArithmeticShift(
2227 IN LARGE_INTEGER LargeInteger,
2228 IN CCHAR ShiftCount)
2229 {
2230 LARGE_INTEGER ret;
2231 ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
2232 return ret;
2233 }
2234
2235 /* BOOLEAN
2236 * RtlLargeIntegerEqualTo(
2237 * IN LARGE_INTEGER Operand1,
2238 * IN LARGE_INTEGER Operand2);
2239 */
2240 #define RtlLargeIntegerEqualTo(X,Y) \
2241 (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
2242
2243 FORCEINLINE
2244 PVOID
2245 RtlSecureZeroMemory(
2246 OUT PVOID Pointer,
2247 IN SIZE_T Size)
2248 {
2249 volatile char* vptr = (volatile char*)Pointer;
2250 #if defined(_M_AMD64)
2251 __stosb((PUCHAR)vptr, 0, Size);
2252 #else
2253 char * endptr = (char *)vptr + Size;
2254 while (vptr < endptr)
2255 {
2256 *vptr = 0; vptr++;
2257 }
2258 #endif
2259 return Pointer;
2260 }
2261
2262 #if defined(_M_AMD64)
2263 FORCEINLINE
2264 ULONG
2265 RtlCheckBit(
2266 IN PRTL_BITMAP BitMapHeader,
2267 IN ULONG BitPosition)
2268 {
2269 return BitTest((LONG CONST*)BitMapHeader->Buffer, BitPosition);
2270 }
2271 #else
2272 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
2273 #endif // defined(_M_AMD64)
2274
2275 #endif // !defined(MIDL_PASS)
2276
2277 //
2278 // Byte Swap Functions
2279 //
2280 #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037 || defined(__GNUC__))) || \
2281 ((defined(_M_AMD64) || defined(_M_IA64)) \
2282 && (_MSC_FULL_VER > 13009175 || defined(__GNUC__)))
2283
2284 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
2285 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
2286 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
2287
2288 #endif
2289
2290 /******************************************************************************
2291 * Memory manager Types *
2292 ******************************************************************************/
2293
2294 typedef struct _MDL {
2295 struct _MDL *Next;
2296 CSHORT Size;
2297 CSHORT MdlFlags;
2298 struct _EPROCESS *Process;
2299 PVOID MappedSystemVa;
2300 PVOID StartVa;
2301 ULONG ByteCount;
2302 ULONG ByteOffset;
2303 } MDL, *PMDL;
2304
2305
2306 /******************************************************************************
2307 * Memory manager Functions *
2308 ******************************************************************************/
2309
2310 /* PVOID MmGetSystemAddressForMdl(
2311 * IN PMDL Mdl);
2312 */
2313 #define MmGetSystemAddressForMdl(Mdl) \
2314 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
2315 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
2316 ((Mdl)->MappedSystemVa) : \
2317 (MmMapLockedPages((Mdl), KernelMode)))
2318
2319 /* PVOID
2320 * MmGetSystemAddressForMdlSafe(
2321 * IN PMDL Mdl,
2322 * IN MM_PAGE_PRIORITY Priority)
2323 */
2324 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
2325 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
2326 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
2327 (_Mdl)->MappedSystemVa : \
2328 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
2329 KernelMode, MmCached, NULL, FALSE, (_Priority)))
2330
2331 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2332 NTKERNELAPI
2333 PMDL
2334 NTAPI
2335 MmCreateMdl(
2336 IN PMDL MemoryDescriptorList OPTIONAL,
2337 IN PVOID Base,
2338 IN SIZE_T Length);
2339
2340 #endif
2341
2342
2343 /******************************************************************************
2344 * I/O Manager Functions *
2345 ******************************************************************************/
2346
2347 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
2348 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
2349
2350 #define DMA_MACROS_DEFINED
2351
2352 FORCEINLINE
2353 NTSTATUS
2354 IoAllocateAdapterChannel(
2355 IN PADAPTER_OBJECT AdapterObject,
2356 IN PDEVICE_OBJECT DeviceObject,
2357 IN ULONG NumberOfMapRegisters,
2358 IN PDRIVER_CONTROL ExecutionRoutine,
2359 IN PVOID Context)
2360 {
2361 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
2362 AllocateAdapterChannel =
2363 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
2364 ASSERT(AllocateAdapterChannel);
2365 return AllocateAdapterChannel(DmaAdapter,
2366 DeviceObject,
2367 NumberOfMapRegisters,
2368 ExecutionRoutine,
2369 Context );
2370 }
2371
2372 FORCEINLINE
2373 BOOLEAN
2374 IoFlushAdapterBuffers(
2375 IN PADAPTER_OBJECT AdapterObject,
2376 IN PMDL Mdl,
2377 IN PVOID MapRegisterBase,
2378 IN PVOID CurrentVa,
2379 IN ULONG Length,
2380 IN BOOLEAN WriteToDevice)
2381 {
2382 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
2383 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
2384 ASSERT(FlushAdapterBuffers);
2385 return FlushAdapterBuffers(DmaAdapter,
2386 Mdl,
2387 MapRegisterBase,
2388 CurrentVa,
2389 Length,
2390 WriteToDevice );
2391 }
2392
2393 FORCEINLINE
2394 VOID
2395 IoFreeAdapterChannel(
2396 IN PADAPTER_OBJECT AdapterObject)
2397 {
2398 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
2399 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
2400 ASSERT(FreeAdapterChannel);
2401 FreeAdapterChannel(DmaAdapter);
2402 }
2403
2404 FORCEINLINE
2405 VOID
2406 IoFreeMapRegisters(
2407 IN PADAPTER_OBJECT AdapterObject,
2408 IN PVOID MapRegisterBase,
2409 IN ULONG NumberOfMapRegisters)
2410 {
2411 PFREE_MAP_REGISTERS FreeMapRegisters;
2412 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
2413 ASSERT(FreeMapRegisters);
2414 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
2415 }
2416
2417 FORCEINLINE
2418 PHYSICAL_ADDRESS
2419 IoMapTransfer(
2420 IN PDMA_ADAPTER DmaAdapter,
2421 IN PMDL Mdl,
2422 IN PVOID MapRegisterBase,
2423 IN PVOID CurrentVa,
2424 IN OUT PULONG Length,
2425 IN BOOLEAN WriteToDevice)
2426 {
2427 PMAP_TRANSFER MapTransfer;
2428
2429 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
2430 ASSERT(MapTransfer);
2431 return MapTransfer(DmaAdapter,
2432 Mdl,
2433 MapRegisterBase,
2434 CurrentVa,
2435 Length,
2436 WriteToDevice);
2437 }
2438 #endif
2439
2440
2441 /******************************************************************************
2442 * Executive Types *
2443 ******************************************************************************/
2444
2445 typedef enum _POOL_TYPE {
2446 NonPagedPool,
2447 PagedPool,
2448 NonPagedPoolMustSucceed,
2449 DontUseThisType,
2450 NonPagedPoolCacheAligned,
2451 PagedPoolCacheAligned,
2452 NonPagedPoolCacheAlignedMustS,
2453 MaxPoolType,
2454 NonPagedPoolSession = 32,
2455 PagedPoolSession,
2456 NonPagedPoolMustSucceedSession,
2457 DontUseThisTypeSession,
2458 NonPagedPoolCacheAlignedSession,
2459 PagedPoolCacheAlignedSession,
2460 NonPagedPoolCacheAlignedMustSSession
2461 } POOL_TYPE;
2462
2463 typedef enum _SUITE_TYPE {
2464 SmallBusiness,
2465 Enterprise,
2466 BackOffice,
2467 CommunicationServer,
2468 TerminalServer,
2469 SmallBusinessRestricted,
2470 EmbeddedNT,
2471 DataCenter,
2472 SingleUserTS,
2473 Personal,
2474 Blade,
2475 MaxSuiteType
2476 } SUITE_TYPE;
2477
2478 typedef enum _EX_POOL_PRIORITY {
2479 LowPoolPriority,
2480 LowPoolPrioritySpecialPoolOverrun = 8,
2481 LowPoolPrioritySpecialPoolUnderrun = 9,
2482 NormalPoolPriority = 16,
2483 NormalPoolPrioritySpecialPoolOverrun = 24,
2484 NormalPoolPrioritySpecialPoolUnderrun = 25,
2485 HighPoolPriority = 32,
2486 HighPoolPrioritySpecialPoolOverrun = 40,
2487 HighPoolPrioritySpecialPoolUnderrun = 41
2488 } EX_POOL_PRIORITY;
2489
2490 typedef struct _FAST_MUTEX
2491 {
2492 LONG Count;
2493 PKTHREAD Owner;
2494 ULONG Contention;
2495 KEVENT Gate;
2496 ULONG OldIrql;
2497 } FAST_MUTEX, *PFAST_MUTEX;
2498
2499 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
2500
2501 typedef struct _OWNER_ENTRY {
2502 ERESOURCE_THREAD OwnerThread;
2503 _ANONYMOUS_UNION union {
2504 LONG OwnerCount;
2505 ULONG TableSize;
2506 } DUMMYUNIONNAME;
2507 } OWNER_ENTRY, *POWNER_ENTRY;
2508
2509 typedef struct _ERESOURCE
2510 {
2511 LIST_ENTRY SystemResourcesList;
2512 POWNER_ENTRY OwnerTable;
2513 SHORT ActiveCount;
2514 USHORT Flag;
2515 volatile PKSEMAPHORE SharedWaiters;
2516 volatile PKEVENT ExclusiveWaiters;
2517 OWNER_ENTRY OwnerEntry;
2518 ULONG ActiveEntries;
2519 ULONG ContentionCount;
2520 ULONG NumberOfSharedWaiters;
2521 ULONG NumberOfExclusiveWaiters;
2522 __GNU_EXTENSION union
2523 {
2524 PVOID Address;
2525 ULONG_PTR CreatorBackTraceIndex;
2526 };
2527 KSPIN_LOCK SpinLock;
2528 } ERESOURCE, *PERESOURCE;
2529
2530 #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
2531 #define LOOKASIDE_ALIGN
2532 #else
2533 #define LOOKASIDE_ALIGN /* FIXME: DECLSPEC_CACHEALIGN */
2534 #endif
2535
2536 typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
2537
2538 typedef PVOID
2539 (DDKAPI *PALLOCATE_FUNCTION)(
2540 IN POOL_TYPE PoolType,
2541 IN SIZE_T NumberOfBytes,
2542 IN ULONG Tag);
2543
2544 typedef PVOID
2545 (DDKAPI *PALLOCATE_FUNCTION_EX)(
2546 IN POOL_TYPE PoolType,
2547 IN SIZE_T NumberOfBytes,
2548 IN ULONG Tag,
2549 IN OUT PLOOKASIDE_LIST_EX Lookaside);
2550
2551 typedef VOID
2552 (DDKAPI *PFREE_FUNCTION)(
2553 IN PVOID Buffer);
2554
2555 typedef VOID
2556 (DDKAPI *PFREE_FUNCTION_EX)(
2557 IN PVOID Buffer,
2558 IN OUT PLOOKASIDE_LIST_EX Lookaside);
2559
2560 typedef VOID
2561 (DDKAPI *PCALLBACK_FUNCTION)(
2562 IN PVOID CallbackContext,
2563 IN PVOID Argument1,
2564 IN PVOID Argument2);
2565
2566 typedef struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE {
2567 union {
2568 SLIST_HEADER ListHead;
2569 SINGLE_LIST_ENTRY SingleListHead;
2570 } DUMMYUNIONNAME;
2571 USHORT Depth;
2572 USHORT MaximumDepth;
2573 ULONG TotalAllocates;
2574 union {
2575 ULONG AllocateMisses;
2576 ULONG AllocateHits;
2577 } DUMMYUNIONNAME2;
2578 ULONG TotalFrees;
2579 union {
2580 ULONG FreeMisses;
2581 ULONG FreeHits;
2582 } DUMMYUNIONNAME3;
2583 POOL_TYPE Type;
2584 ULONG Tag;
2585 ULONG Size;
2586 union {
2587 PALLOCATE_FUNCTION_EX AllocateEx;
2588 PALLOCATE_FUNCTION Allocate;
2589 } DUMMYUNIONNAME4;
2590 union {
2591 PFREE_FUNCTION_EX FreeEx;
2592 PFREE_FUNCTION Free;
2593 } DUMMYUNIONNAME5;
2594 LIST_ENTRY ListEntry;
2595 ULONG LastTotalAllocates;
2596 union {
2597 ULONG LastAllocateMisses;
2598 ULONG LastAllocateHits;
2599 } DUMMYUNIONNAME6;
2600 ULONG Future[2];
2601 } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
2602
2603 typedef struct _PAGED_LOOKASIDE_LIST {
2604 GENERAL_LOOKASIDE L;
2605 #if !defined(_AMD64_) && !defined(_IA64_)
2606 FAST_MUTEX Lock__ObsoleteButDoNotDelete;
2607 #endif
2608 } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
2609
2610 typedef struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST {
2611 GENERAL_LOOKASIDE L;
2612 #if !defined(_AMD64_) && !defined(_IA64_)
2613 KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
2614 #endif
2615 } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
2616
2617 //typedef struct _LOOKASIDE_LIST_EX {
2618 // GENERAL_LOOKASIDE_POOL L;
2619 //} LOOKASIDE_LIST_EX, *PLOOKASIDE_LIST_EX;
2620
2621 typedef struct _EX_RUNDOWN_REF {
2622 __GNU_EXTENSION union {
2623 volatile ULONG_PTR Count;
2624 volatile PVOID Ptr;
2625 };
2626 } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
2627
2628 typedef struct _EX_RUNDOWN_REF_CACHE_AWARE *PEX_RUNDOWN_REF_CACHE_AWARE;
2629
2630 typedef enum _WORK_QUEUE_TYPE {
2631 CriticalWorkQueue,
2632 DelayedWorkQueue,
2633 HyperCriticalWorkQueue,
2634 MaximumWorkQueue
2635 } WORK_QUEUE_TYPE;
2636
2637 typedef VOID
2638 (DDKAPI *PWORKER_THREAD_ROUTINE)(
2639 IN PVOID Parameter);
2640
2641 typedef struct _WORK_QUEUE_ITEM {
2642 LIST_ENTRY List;
2643 PWORKER_THREAD_ROUTINE WorkerRoutine;
2644 volatile PVOID Parameter;
2645 } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
2646
2647
2648 /******************************************************************************
2649 * Executive Functions *
2650 ******************************************************************************/
2651
2652 #if defined(_X86_)
2653 #if defined(_NTHAL_)
2654 #define ExAcquireFastMutex ExiAcquireFastMutex
2655 #define ExReleaseFastMutex ExiReleaseFastMutex
2656 #define ExTryToAcquireFastMutex ExiTryToAcquireFastMutex
2657 #endif
2658 #define ExInterlockedAddUlong ExfInterlockedAddUlong
2659 #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
2660 #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
2661 #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
2662 #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
2663 #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
2664 #endif
2665
2666 #if defined(_WIN64)
2667
2668 #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || \
2669 defined(_NTHAL_) || defined(_NTOSP_)
2670 NTKERNELAPI
2671 USHORT
2672 ExQueryDepthSList(IN PSLIST_HEADER ListHead);
2673 #else
2674 FORCEINLINE
2675 USHORT
2676 ExQueryDepthSList(IN PSLIST_HEADER ListHead)
2677 {
2678 return (USHORT)(ListHead->Alignment & 0xffff);
2679 }
2680 #endif
2681
2682 NTKERNELAPI
2683 PSLIST_ENTRY
2684 ExpInterlockedFlushSList(
2685 PSLIST_HEADER ListHead);
2686
2687 NTKERNELAPI
2688 PSLIST_ENTRY
2689 ExpInterlockedPopEntrySList(
2690 PSLIST_HEADER ListHead);
2691
2692 NTKERNELAPI
2693 PSLIST_ENTRY
2694 ExpInterlockedPushEntrySList(
2695 PSLIST_HEADER ListHead,
2696 PSLIST_ENTRY ListEntry);
2697
2698 #define ExInterlockedFlushSList(Head) \
2699 ExpInterlockedFlushSList(Head)
2700 #define ExInterlockedPopEntrySList(Head, Lock) \
2701 ExpInterlockedPopEntrySList(Head)
2702 #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
2703 ExpInterlockedPushEntrySList(Head, Entry)
2704
2705 #else // !defined(_WIN64)
2706
2707 #define ExQueryDepthSList(listhead) (listhead)->Depth
2708
2709 NTKERNELAPI
2710 PSINGLE_LIST_ENTRY
2711 FASTCALL
2712 ExInterlockedFlushSList(
2713 IN PSLIST_HEADER ListHead);
2714
2715 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
2716 NTKERNELAPI
2717 PSINGLE_LIST_ENTRY
2718 FASTCALL
2719 ExInterlockedPopEntrySList(
2720 IN PSLIST_HEADER ListHead,
2721 IN PKSPIN_LOCK Lock);
2722
2723 NTKERNELAPI
2724 PSINGLE_LIST_ENTRY
2725 FASTCALL
2726 ExInterlockedPushEntrySList(
2727 IN PSLIST_HEADER ListHead,
2728 IN PSINGLE_LIST_ENTRY ListEntry,
2729 IN PKSPIN_LOCK Lock);
2730 #else
2731 #define ExInterlockedPopEntrySList(_ListHead, _Lock) \
2732 InterlockedPopEntrySList(_ListHead)
2733 #define ExInterlockedPushEntrySList(_ListHead, _ListEntry, _Lock) \
2734 InterlockedPushEntrySList(_ListHead, _ListEntry)
2735 #endif // _WIN2K_COMPAT_SLIST_USAGE
2736
2737 #endif // !defined(_WIN64)
2738
2739 /* ERESOURCE_THREAD
2740 * ExGetCurrentResourceThread(
2741 * VOID);
2742 */
2743 #define ExGetCurrentResourceThread() ((ERESOURCE_THREAD)PsGetCurrentThread())
2744
2745 #define ExReleaseResource(R) (ExReleaseResourceLite(R))
2746
2747 /* VOID
2748 * ExInitializeWorkItem(
2749 * IN PWORK_QUEUE_ITEM Item,
2750 * IN PWORKER_THREAD_ROUTINE Routine,
2751 * IN PVOID Context)
2752 */
2753 #define ExInitializeWorkItem(Item, Routine, Context) \
2754 { \
2755 (Item)->WorkerRoutine = Routine; \
2756 (Item)->Parameter = Context; \
2757 (Item)->List.Flink = NULL; \
2758 }
2759
2760 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2761
2762 NTKERNELAPI
2763 VOID
2764 FASTCALL
2765 ExAcquireFastMutex(
2766 IN OUT PFAST_MUTEX FastMutex);
2767
2768 NTKERNELAPI
2769 VOID
2770 FASTCALL
2771 ExReleaseFastMutex(
2772 IN OUT PFAST_MUTEX FastMutex);
2773
2774 NTKERNELAPI
2775 BOOLEAN
2776 FASTCALL
2777 ExTryToAcquireFastMutex(
2778 IN OUT PFAST_MUTEX FastMutex);
2779
2780 NTKERNELAPI
2781 VOID
2782 FASTCALL
2783 ExAcquireFastMutexUnsafe(
2784 IN OUT PFAST_MUTEX FastMutex);
2785
2786 NTKERNELAPI
2787 VOID
2788 FASTCALL
2789 ExReleaseFastMutexUnsafe(
2790 IN OUT PFAST_MUTEX FastMutex);
2791
2792 NTKERNELAPI
2793 BOOLEAN
2794 NTAPI
2795 ExAcquireResourceExclusiveLite(
2796 IN PERESOURCE Resource,
2797 IN BOOLEAN Wait);
2798
2799 NTKERNELAPI
2800 BOOLEAN
2801 NTAPI
2802 ExAcquireResourceSharedLite(
2803 IN PERESOURCE Resource,
2804 IN BOOLEAN Wait);
2805
2806 NTKERNELAPI
2807 BOOLEAN
2808 NTAPI
2809 ExAcquireSharedStarveExclusive(
2810 IN PERESOURCE Resource,
2811 IN BOOLEAN Wait);
2812
2813 NTKERNELAPI
2814 BOOLEAN
2815 NTAPI
2816 ExAcquireSharedWaitForExclusive(
2817 IN PERESOURCE Resource,
2818 IN BOOLEAN Wait);
2819
2820 NTKERNELAPI
2821 PVOID
2822 NTAPI
2823 ExAllocatePool(
2824 IN POOL_TYPE PoolType,
2825 IN SIZE_T NumberOfBytes);
2826
2827 #ifdef POOL_TAGGING
2828 #define ExAllocatePool(p,n) ExAllocatePoolWithTag(p,n,' kdD')
2829 #endif /* POOL_TAGGING */
2830
2831 NTKERNELAPI
2832 PVOID
2833 NTAPI
2834 ExAllocatePoolWithQuota(
2835 IN POOL_TYPE PoolType,
2836 IN SIZE_T NumberOfBytes);
2837
2838 #ifdef POOL_TAGGING
2839 #define ExAllocatePoolWithQuota(p,n) ExAllocatePoolWithQuotaTag(p,n,' kdD')
2840 #endif /* POOL_TAGGING */
2841
2842 NTKERNELAPI
2843 PVOID
2844 NTAPI
2845 ExAllocatePoolWithQuotaTag(
2846 IN POOL_TYPE PoolType,
2847 IN SIZE_T NumberOfBytes,
2848 IN ULONG Tag);
2849
2850 #ifndef POOL_TAGGING
2851 #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
2852 #endif /* POOL_TAGGING */
2853
2854 NTKERNELAPI
2855 PVOID
2856 NTAPI
2857 ExAllocatePoolWithTag(
2858 IN POOL_TYPE PoolType,
2859 IN SIZE_T NumberOfBytes,
2860 IN ULONG Tag);
2861
2862 NTKERNELAPI
2863 PVOID
2864 NTAPI
2865 ExAllocatePoolWithTagPriority(
2866 IN POOL_TYPE PoolType,
2867 IN SIZE_T NumberOfBytes,
2868 IN ULONG Tag,
2869 IN EX_POOL_PRIORITY Priority);
2870
2871 NTKERNELAPI
2872 VOID
2873 NTAPI
2874 ExConvertExclusiveToSharedLite(
2875 IN PERESOURCE Resource);
2876
2877 NTKERNELAPI
2878 NTSTATUS
2879 NTAPI
2880 ExCreateCallback(
2881 OUT PCALLBACK_OBJECT *CallbackObject,
2882 IN POBJECT_ATTRIBUTES ObjectAttributes,
2883 IN BOOLEAN Create,
2884 IN BOOLEAN AllowMultipleCallbacks);
2885
2886 NTKERNELAPI
2887 VOID
2888 NTAPI
2889 ExDeleteNPagedLookasideList(
2890 IN PNPAGED_LOOKASIDE_LIST Lookaside);
2891
2892 NTKERNELAPI
2893 VOID
2894 NTAPI
2895 ExDeletePagedLookasideList(
2896 IN PPAGED_LOOKASIDE_LIST Lookaside);
2897
2898 NTKERNELAPI
2899 NTSTATUS
2900 NTAPI
2901 ExDeleteResourceLite(
2902 IN PERESOURCE Resource);
2903
2904 NTKERNELAPI
2905 VOID
2906 NTAPI
2907 ExFreePool(
2908 IN PVOID P);
2909
2910 #ifdef POOL_TAGGING
2911 #define ExFreePool(P) ExFreePoolWithTag(P, 0)
2912 #endif
2913
2914 NTKERNELAPI
2915 VOID
2916 NTAPI
2917 ExFreePoolWithTag(
2918 IN PVOID P,
2919 IN ULONG Tag);
2920
2921 NTKERNELAPI
2922 ULONG
2923 NTAPI
2924 ExGetExclusiveWaiterCount(
2925 IN PERESOURCE Resource);
2926
2927 NTKERNELAPI
2928 KPROCESSOR_MODE
2929 NTAPI
2930 ExGetPreviousMode(
2931 VOID);
2932
2933 NTKERNELAPI
2934 ULONG
2935 NTAPI
2936 ExGetSharedWaiterCount(
2937 IN PERESOURCE Resource);
2938
2939 NTKERNELAPI
2940 VOID
2941 NTAPI
2942 ExInitializeNPagedLookasideList(
2943 IN PNPAGED_LOOKASIDE_LIST Lookaside,
2944 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
2945 IN PFREE_FUNCTION Free OPTIONAL,
2946 IN ULONG Flags,
2947 IN SIZE_T Size,
2948 IN ULONG Tag,
2949 IN USHORT Depth);
2950
2951 NTKERNELAPI
2952 VOID
2953 NTAPI
2954 ExInitializePagedLookasideList(
2955 IN PPAGED_LOOKASIDE_LIST Lookaside,
2956 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
2957 IN PFREE_FUNCTION Free OPTIONAL,
2958 IN ULONG Flags,
2959 IN SIZE_T Size,
2960 IN ULONG Tag,
2961 IN USHORT Depth);
2962
2963 NTKERNELAPI
2964 NTSTATUS
2965 NTAPI
2966 ExInitializeResourceLite(
2967 IN PERESOURCE Resource);
2968
2969 NTKERNELAPI
2970 LARGE_INTEGER
2971 NTAPI
2972 ExInterlockedAddLargeInteger(
2973 IN PLARGE_INTEGER Addend,
2974 IN LARGE_INTEGER Increment,
2975 IN PKSPIN_LOCK Lock);
2976
2977 #if defined(_WIN64)
2978 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
2979 (VOID)InterlockedAdd64(&(Addend)->QuadPart, Increment)
2980 #else
2981 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
2982 _InterlockedAddLargeStatistic((PLONGLONG)&(Addend)->QuadPart, Increment)
2983 #endif
2984
2985 NTKERNELAPI
2986 ULONG
2987 FASTCALL
2988 ExInterlockedAddUlong(
2989 IN PULONG Addend,
2990 IN ULONG Increment,
2991 PKSPIN_LOCK Lock);
2992
2993 #if defined(_AMD64_) || defined(_IA64_)
2994 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
2995 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
2996 #elif defined(_X86_)
2997 NTKERNELAPI
2998 LONGLONG
2999 FASTCALL
3000 ExfInterlockedCompareExchange64(
3001 IN OUT LONGLONG volatile *Destination,
3002 IN PLONGLONG Exchange,
3003 IN PLONGLONG Comperand);
3004 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
3005 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
3006 #else
3007 NTKERNELAPI
3008 LONGLONG
3009 FASTCALL
3010 ExInterlockedCompareExchange64(
3011 IN OUT LONGLONG volatile *Destination,
3012 IN PLONGLONG Exchange,
3013 IN PLONGLONG Comparand,
3014 IN PKSPIN_LOCK Lock);
3015 #endif
3016
3017 NTKERNELAPI
3018 PLIST_ENTRY
3019 FASTCALL
3020 ExInterlockedInsertHeadList(
3021 IN PLIST_ENTRY ListHead,
3022 IN PLIST_ENTRY ListEntry,
3023 IN PKSPIN_LOCK Lock);
3024
3025 NTKERNELAPI
3026 PLIST_ENTRY
3027 FASTCALL
3028 ExInterlockedInsertTailList(
3029 IN PLIST_ENTRY ListHead,
3030 IN PLIST_ENTRY ListEntry,
3031 IN PKSPIN_LOCK Lock);
3032
3033 NTKERNELAPI
3034 PSINGLE_LIST_ENTRY
3035 FASTCALL
3036 ExInterlockedPopEntryList(
3037 IN PSINGLE_LIST_ENTRY ListHead,
3038 IN PKSPIN_LOCK Lock);
3039
3040 NTKERNELAPI
3041 PSINGLE_LIST_ENTRY
3042 FASTCALL
3043 ExInterlockedPushEntryList(
3044 IN PSINGLE_LIST_ENTRY ListHead,
3045 IN PSINGLE_LIST_ENTRY ListEntry,
3046 IN PKSPIN_LOCK Lock);
3047
3048 NTKERNELAPI
3049 PLIST_ENTRY
3050 FASTCALL
3051 ExInterlockedRemoveHeadList(
3052 IN PLIST_ENTRY ListHead,
3053 IN PKSPIN_LOCK Lock);
3054
3055 NTKERNELAPI
3056 BOOLEAN
3057 NTAPI
3058 ExIsProcessorFeaturePresent(
3059 IN ULONG ProcessorFeature);
3060
3061 NTKERNELAPI
3062 BOOLEAN
3063 NTAPI
3064 ExIsResourceAcquiredExclusiveLite(
3065 IN PERESOURCE Resource);
3066
3067 NTKERNELAPI
3068 ULONG
3069 NTAPI
3070 ExIsResourceAcquiredSharedLite(
3071 IN PERESOURCE Resource);
3072
3073 #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
3074
3075 NTKERNELAPI
3076 VOID
3077 NTAPI
3078 ExLocalTimeToSystemTime(
3079 IN PLARGE_INTEGER LocalTime,
3080 OUT PLARGE_INTEGER SystemTime);
3081
3082 NTKERNELAPI
3083 VOID
3084 NTAPI
3085 ExNotifyCallback(
3086 IN PCALLBACK_OBJECT CallbackObject,
3087 IN PVOID Argument1,
3088 IN PVOID Argument2);
3089
3090 NTKERNELAPI
3091 VOID
3092 NTAPI
3093 ExQueueWorkItem(
3094 IN PWORK_QUEUE_ITEM WorkItem,
3095 IN WORK_QUEUE_TYPE QueueType);
3096
3097 NTKERNELAPI
3098 DECLSPEC_NORETURN
3099 VOID
3100 NTAPI
3101 ExRaiseStatus(
3102 IN NTSTATUS Status);
3103
3104 NTKERNELAPI
3105 PVOID
3106 NTAPI
3107 ExRegisterCallback(
3108 IN PCALLBACK_OBJECT CallbackObject,
3109 IN PCALLBACK_FUNCTION CallbackFunction,
3110 IN PVOID CallbackContext);
3111
3112 NTKERNELAPI
3113 NTSTATUS
3114 NTAPI
3115 ExReinitializeResourceLite(
3116 IN PERESOURCE Resource);
3117
3118 NTKERNELAPI
3119 VOID
3120 NTAPI
3121 ExReleaseResourceForThreadLite(
3122 IN PERESOURCE Resource,
3123 IN ERESOURCE_THREAD ResourceThreadId);
3124
3125 NTKERNELAPI
3126 VOID
3127 FASTCALL
3128 ExReleaseResourceLite(
3129 IN PERESOURCE Resource);
3130
3131 NTKERNELAPI
3132 VOID
3133 NTAPI
3134 ExSetResourceOwnerPointer(
3135 IN PERESOURCE Resource,
3136 IN PVOID OwnerPointer);
3137
3138 NTKERNELAPI
3139 ULONG
3140 NTAPI
3141 ExSetTimerResolution(
3142 IN ULONG DesiredTime,
3143 IN BOOLEAN SetResolution);
3144
3145 NTKERNELAPI
3146 VOID
3147 NTAPI
3148 ExSystemTimeToLocalTime(
3149 IN PLARGE_INTEGER SystemTime,
3150 OUT PLARGE_INTEGER LocalTime);
3151
3152 NTKERNELAPI
3153 VOID
3154 NTAPI
3155 ExUnregisterCallback(
3156 IN PVOID CbRegistration);
3157
3158
3159 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
3160
3161 #if (NTDDI_VERSION >= NTDDI_WINXP)
3162 NTKERNELAPI
3163 BOOLEAN
3164 FASTCALL
3165 ExAcquireRundownProtection(
3166 IN OUT PEX_RUNDOWN_REF RunRef);
3167
3168 NTKERNELAPI
3169 VOID
3170 FASTCALL
3171 ExInitializeRundownProtection(
3172 OUT PEX_RUNDOWN_REF RunRef);
3173
3174 NTKERNELAPI
3175 VOID
3176 FASTCALL
3177 ExReInitializeRundownProtection(
3178 OUT PEX_RUNDOWN_REF RunRef);
3179
3180 NTKERNELAPI
3181 VOID
3182 FASTCALL
3183 ExReleaseRundownProtection(
3184 IN OUT PEX_RUNDOWN_REF RunRef);
3185
3186 NTKERNELAPI
3187 VOID
3188 FASTCALL
3189 ExRundownCompleted(
3190 OUT PEX_RUNDOWN_REF RunRef);
3191
3192 NTKERNELAPI
3193 BOOLEAN
3194 NTAPI
3195 ExVerifySuite(
3196 IN SUITE_TYPE SuiteType);
3197
3198 NTKERNELAPI
3199 VOID
3200 FASTCALL
3201 ExWaitForRundownProtectionRelease(
3202 IN OUT PEX_RUNDOWN_REF RunRef);
3203
3204 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
3205
3206 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
3207 NTKERNELAPI
3208 BOOLEAN
3209 FASTCALL
3210 ExAcquireRundownProtectionEx(
3211 IN OUT PEX_RUNDOWN_REF RunRef,
3212 IN ULONG Count);
3213
3214 NTKERNELAPI
3215 VOID
3216 FASTCALL
3217 ExReleaseRundownProtectionEx(
3218 IN OUT PEX_RUNDOWN_REF RunRef,
3219 IN ULONG Count);
3220 #endif // (NTDDI_VERSION >= NTDDI_WINXPSP2)
3221
3222 #if (NTDDI_VERSION >= NTDDI_WS03)
3223
3224 #endif // (NTDDI_VERSION >= NTDDI_WS03)
3225
3226 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
3227 NTKERNELAPI
3228 PEX_RUNDOWN_REF_CACHE_AWARE
3229 ExAllocateCacheAwareRundownProtection(
3230 IN POOL_TYPE PoolType,
3231 IN ULONG PoolTag);
3232
3233 NTKERNELAPI
3234 SIZE_T
3235 ExSizeOfRundownProtectionCacheAware(VOID);
3236
3237 #endif // (NTDDI_VERSION >= NTDDI_WS03SP1)
3238
3239 #if (NTDDI_VERSION >= NTDDI_VISTA)
3240 NTKERNELAPI
3241 NTSTATUS
3242 ExInitializeLookasideListEx(
3243 OUT PLOOKASIDE_LIST_EX Lookaside,
3244 IN PALLOCATE_FUNCTION_EX Allocate OPTIONAL,
3245 IN PFREE_FUNCTION_EX Free OPTIONAL,
3246 IN POOL_TYPE PoolType,
3247 IN ULONG Flags,
3248 IN SIZE_T Size,
3249 IN ULONG Tag,
3250 IN USHORT Depth);
3251 #endif
3252
3253
3254 #if !defined(MIDL_PASS)
3255
3256 static __inline PVOID
3257 ExAllocateFromNPagedLookasideList(
3258 IN PNPAGED_LOOKASIDE_LIST Lookaside)
3259 {
3260 PVOID Entry;
3261
3262 Lookaside->L.TotalAllocates++;
3263 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
3264 if (Entry == NULL) {
3265 Lookaside->L.AllocateMisses++;
3266 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
3267 Lookaside->L.Size,
3268 Lookaside->L.Tag);
3269 }
3270 return Entry;
3271 }
3272
3273 static __inline PVOID
3274 ExAllocateFromPagedLookasideList(
3275 IN PPAGED_LOOKASIDE_LIST Lookaside)
3276 {
3277 PVOID Entry;
3278
3279 Lookaside->L.TotalAllocates++;
3280 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
3281 if (Entry == NULL) {
3282 Lookaside->L.AllocateMisses++;
3283 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
3284 Lookaside->L.Size,
3285 Lookaside->L.Tag);
3286 }
3287 return Entry;
3288 }
3289
3290 static __inline VOID
3291 ExFreeToNPagedLookasideList(
3292 IN PNPAGED_LOOKASIDE_LIST Lookaside,
3293 IN PVOID Entry)
3294 {
3295 Lookaside->L.TotalFrees++;
3296 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
3297 Lookaside->L.FreeMisses++;
3298 (Lookaside->L.Free)(Entry);
3299 } else {
3300 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
3301 }
3302 }
3303
3304 static __inline VOID
3305 ExFreeToPagedLookasideList(
3306 IN PPAGED_LOOKASIDE_LIST Lookaside,
3307 IN PVOID Entry)
3308 {
3309 Lookaside->L.TotalFrees++;
3310 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
3311 Lookaside->L.FreeMisses++;
3312 (Lookaside->L.Free)(Entry);
3313 } else {
3314 InterlockedPushEntrySList(&Lookaside->L.ListHead, (PSLIST_ENTRY)Entry);
3315 }
3316 }
3317
3318
3319 #endif // !defined(MIDL_PASS)
3320
3321
3322 #ifdef __cplusplus
3323 }
3324 #endif
3325
3326 #endif // _WDMDDK_