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