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