More work on USB related definitions
[reactos.git] / include / ddk / wdm.h
1 #pragma once
2
3 /* Dependencies */
4 #define NT_INCLUDED
5 #include <excpt.h>
6 #include <ntdef.h>
7 #include <ntstatus.h>
8
9 #ifndef GUID_DEFINED
10 #include <guiddef.h>
11 #endif /* GUID_DEFINED */
12
13 #include "intrin.h"
14
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #if !defined(_NTHALDLL_) && !defined(_BLDR_)
21 #define NTHALAPI DECLSPEC_IMPORT
22 #else
23 #define NTHALAPI
24 #endif
25
26 #define NTKERNELAPI DECLSPEC_IMPORT
27
28 #if defined(_WIN64)
29 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
30 #else
31 #define POINTER_ALIGNMENT
32 #endif
33
34 /* Helper macro to enable gcc's extension. */
35 #ifndef __GNU_EXTENSION
36 #ifdef __GNUC__
37 #define __GNU_EXTENSION __extension__
38 #else
39 #define __GNU_EXTENSION
40 #endif
41 #endif
42
43 #if defined(_MSC_VER)
44
45 /* Indicate if #pragma alloc_text() is supported */
46 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)
47 #define ALLOC_PRAGMA 1
48 #endif
49
50 /* Indicate if #pragma data_seg() is supported */
51 #if defined(_M_IX86) || defined(_M_AMD64)
52 #define ALLOC_DATA_PRAGMA 1
53 #endif
54
55 #endif
56
57 /* Forward declarations */
58 struct _IRP;
59 struct _MDL;
60 struct _KAPC;
61 struct _KDPC;
62 struct _FILE_OBJECT;
63 struct _DMA_ADAPTER;
64 struct _DEVICE_OBJECT;
65 struct _DRIVER_OBJECT;
66 struct _IO_STATUS_BLOCK;
67 struct _DEVICE_DESCRIPTION;
68 struct _SCATTER_GATHER_LIST;
69 struct _DRIVE_LAYOUT_INFORMATION;
70 struct _COMPRESSED_DATA_INFO;
71 struct _IO_RESOURCE_DESCRIPTOR;
72
73 /* Structures not exposed to drivers */
74 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
75 typedef struct _HAL_DISPATCH_TABLE *PHAL_DISPATCH_TABLE;
76 typedef struct _HAL_PRIVATE_DISPATCH_TABLE *PHAL_PRIVATE_DISPATCH_TABLE;
77 typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
78 typedef struct _BUS_HANDLER *PBUS_HANDLER;
79 typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
80 typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
81 typedef struct _ETHREAD *PETHREAD;
82 typedef struct _EPROCESS *PEPROCESS;
83 typedef struct _IO_TIMER *PIO_TIMER;
84 typedef struct _KINTERRUPT *PKINTERRUPT;
85 typedef struct _KPROCESS *PKPROCESS;
86 typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
87 typedef struct _CONTEXT *PCONTEXT;
88
89
90 /******************************************************************************
91 * INTERLOCKED Functions *
92 ******************************************************************************/
93 //
94 // Intrinsics (note: taken from our winnt.h)
95 // FIXME: 64-bit
96 //
97 #if defined(__GNUC__)
98
99 static __inline__ BOOLEAN
100 InterlockedBitTestAndSet(IN LONG volatile *Base,
101 IN LONG Bit)
102 {
103 #if defined(_M_IX86)
104 LONG OldBit;
105 __asm__ __volatile__("lock "
106 "btsl %2,%1\n\t"
107 "sbbl %0,%0\n\t"
108 :"=r" (OldBit),"+m" (*Base)
109 :"Ir" (Bit)
110 : "memory");
111 return OldBit;
112 #else
113 return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
114 #endif
115 }
116
117 static __inline__ BOOLEAN
118 InterlockedBitTestAndReset(IN LONG volatile *Base,
119 IN LONG Bit)
120 {
121 #if defined(_M_IX86)
122 LONG OldBit;
123 __asm__ __volatile__("lock "
124 "btrl %2,%1\n\t"
125 "sbbl %0,%0\n\t"
126 :"=r" (OldBit),"+m" (*Base)
127 :"Ir" (Bit)
128 : "memory");
129 return OldBit;
130 #else
131 return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
132 #endif
133 }
134
135 #endif
136
137 #define BitScanForward _BitScanForward
138 #define BitScanReverse _BitScanReverse
139 #define BitTest _bittest
140 #define BitTestAndComplement _bittestandcomplement
141 #define BitTestAndSet _bittestandset
142 #define BitTestAndReset _bittestandreset
143 #define InterlockedBitTestAndSet _interlockedbittestandset
144 #define InterlockedBitTestAndReset _interlockedbittestandreset
145
146 #ifdef _M_AMD64
147 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
148 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
149 #endif
150
151 #if !defined(__INTERLOCKED_DECLARED)
152 #define __INTERLOCKED_DECLARED
153
154 #if defined (_X86_)
155 #if defined(NO_INTERLOCKED_INTRINSICS)
156 NTKERNELAPI
157 LONG
158 FASTCALL
159 InterlockedIncrement(
160 IN OUT LONG volatile *Addend);
161
162 NTKERNELAPI
163 LONG
164 FASTCALL
165 InterlockedDecrement(
166 IN OUT LONG volatile *Addend);
167
168 NTKERNELAPI
169 LONG
170 FASTCALL
171 InterlockedCompareExchange(
172 IN OUT LONG volatile *Destination,
173 IN LONG Exchange,
174 IN LONG Comparand);
175
176 NTKERNELAPI
177 LONG
178 FASTCALL
179 InterlockedExchange(
180 IN OUT LONG volatile *Destination,
181 IN LONG Value);
182
183 NTKERNELAPI
184 LONG
185 FASTCALL
186 InterlockedExchangeAdd(
187 IN OUT LONG volatile *Addend,
188 IN LONG Value);
189
190 #else // !defined(NO_INTERLOCKED_INTRINSICS)
191
192 #define InterlockedExchange _InterlockedExchange
193 #define InterlockedIncrement _InterlockedIncrement
194 #define InterlockedDecrement _InterlockedDecrement
195 #define InterlockedExchangeAdd _InterlockedExchangeAdd
196 #define InterlockedCompareExchange _InterlockedCompareExchange
197 #define InterlockedOr _InterlockedOr
198 #define InterlockedAnd _InterlockedAnd
199 #define InterlockedXor _InterlockedXor
200
201 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
202
203 #endif // defined (_X86_)
204
205 #if !defined (_WIN64)
206 /*
207 * PVOID
208 * InterlockedExchangePointer(
209 * IN OUT PVOID volatile *Target,
210 * IN PVOID Value)
211 */
212 #define InterlockedExchangePointer(Target, Value) \
213 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
214
215 /*
216 * PVOID
217 * InterlockedCompareExchangePointer(
218 * IN OUT PVOID *Destination,
219 * IN PVOID Exchange,
220 * IN PVOID Comparand)
221 */
222 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
223 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
224
225 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
226 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
227 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
228
229 #endif // !defined (_WIN64)
230
231 #if defined (_M_AMD64)
232
233 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
234 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
235 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
236 #define InterlockedAnd _InterlockedAnd
237 #define InterlockedOr _InterlockedOr
238 #define InterlockedXor _InterlockedXor
239 #define InterlockedIncrement _InterlockedIncrement
240 #define InterlockedDecrement _InterlockedDecrement
241 #define InterlockedAdd _InterlockedAdd
242 #define InterlockedExchange _InterlockedExchange
243 #define InterlockedExchangeAdd _InterlockedExchangeAdd
244 #define InterlockedCompareExchange _InterlockedCompareExchange
245 #define InterlockedAnd64 _InterlockedAnd64
246 #define InterlockedOr64 _InterlockedOr64
247 #define InterlockedXor64 _InterlockedXor64
248 #define InterlockedIncrement64 _InterlockedIncrement64
249 #define InterlockedDecrement64 _InterlockedDecrement64
250 #define InterlockedAdd64 _InterlockedAdd64
251 #define InterlockedExchange64 _InterlockedExchange64
252 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
253 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
254 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
255 #define InterlockedExchangePointer _InterlockedExchangePointer
256 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
257 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
258
259 #endif // _M_AMD64
260
261 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
262 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
263 FORCEINLINE
264 LONG64
265 InterlockedAdd64(
266 IN OUT LONG64 volatile *Addend,
267 IN LONG64 Value)
268 {
269 return InterlockedExchangeAdd64(Addend, Value) + Value;
270 }
271 //#endif
272 #endif
273
274 #endif /* !__INTERLOCKED_DECLARED */
275
276
277 /******************************************************************************
278 * Kernel Types *
279 ******************************************************************************/
280
281 typedef UCHAR KIRQL, *PKIRQL;
282 typedef UCHAR KPROCESSOR_MODE;
283 typedef LONG KPRIORITY;
284
285 typedef enum _MODE {
286 KernelMode,
287 UserMode,
288 MaximumMode
289 } MODE;
290
291 /* Processor features */
292 #define PF_FLOATING_POINT_PRECISION_ERRATA 0
293 #define PF_FLOATING_POINT_EMULATED 1
294 #define PF_COMPARE_EXCHANGE_DOUBLE 2
295 #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
296 #define PF_PPC_MOVEMEM_64BIT_OK 4
297 #define PF_ALPHA_BYTE_INSTRUCTIONS 5
298 #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
299 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
300 #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
301 #define PF_PAE_ENABLED 9
302 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
303 #define PF_SSE_DAZ_MODE_AVAILABLE 11
304 #define PF_NX_ENABLED 12
305 #define PF_SSE3_INSTRUCTIONS_AVAILABLE 13
306 #define PF_COMPARE_EXCHANGE128 14
307 #define PF_COMPARE64_EXCHANGE128 15
308 #define PF_CHANNELS_ENABLED 16
309
310 #define MAXIMUM_SUPPORTED_EXTENSION 512
311 #define MAXIMUM_WAIT_OBJECTS 64
312
313 #define ASSERT_APC(Object) \
314 ASSERT((Object)->Type == ApcObject)
315
316 #define ASSERT_DPC(Object) \
317 ASSERT(((Object)->Type == 0) || \
318 ((Object)->Type == DpcObject) || \
319 ((Object)->Type == ThreadedDpcObject))
320
321 #define ASSERT_DEVICE_QUEUE(Object) \
322 ASSERT((Object)->Type == DeviceQueueObject)
323
324 #define DPC_NORMAL 0
325 #define DPC_THREADED 1
326
327 #define GM_LOCK_BIT 0x1
328 #define GM_LOCK_BIT_V 0x0
329 #define GM_LOCK_WAITER_WOKEN 0x2
330 #define GM_LOCK_WAITER_INC 0x4
331
332 #define LOCK_QUEUE_WAIT 1
333 #define LOCK_QUEUE_OWNER 2
334 #define LOCK_QUEUE_TIMER_LOCK_SHIFT 4
335 #define LOCK_QUEUE_TIMER_TABLE_LOCKS (1 << (8 - LOCK_QUEUE_TIMER_LOCK_SHIFT))
336
337 #define PROCESSOR_FEATURE_MAX 64
338
339 #define DBG_STATUS_CONTROL_C 1
340 #define DBG_STATUS_SYSRQ 2
341 #define DBG_STATUS_BUGCHECK_FIRST 3
342 #define DBG_STATUS_BUGCHECK_SECOND 4
343 #define DBG_STATUS_FATAL 5
344 #define DBG_STATUS_DEBUG_CONTROL 6
345 #define DBG_STATUS_WORKER 7
346
347 #define KI_USER_SHARED_DATA 0xffdf0000
348 #define SharedUserData ((KUSER_SHARED_DATA * CONST) KI_USER_SHARED_DATA)
349
350 #define EFLAG_SIGN 0x8000
351 #define EFLAG_ZERO 0x4000
352 #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
353
354 #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
355 #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
356 #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
357
358 #if defined(_WIN64)
359 #define MAXIMUM_PROC_PER_GROUP 64
360 #else
361 #define MAXIMUM_PROC_PER_GROUP 32
362 #endif
363 #define MAXIMUM_PROCESSORS MAXIMUM_PROC_PER_GROUP
364
365 #if (_M_IX86)
366 #define KIP0PCRADDRESS 0xffdff000
367 #endif
368
369 #if defined(_X86_)
370
371 #define PASSIVE_LEVEL 0
372 #define LOW_LEVEL 0
373 #define APC_LEVEL 1
374 #define DISPATCH_LEVEL 2
375 #define CMCI_LEVEL 5
376 #define PROFILE_LEVEL 27
377 #define CLOCK1_LEVEL 28
378 #define CLOCK2_LEVEL 28
379 #define IPI_LEVEL 29
380 #define POWER_LEVEL 30
381 #define HIGH_LEVEL 31
382 #define CLOCK_LEVEL (CLOCK2_LEVEL)
383
384 typedef struct _KFLOATING_SAVE {
385 ULONG ControlWord;
386 ULONG StatusWord;
387 ULONG ErrorOffset;
388 ULONG ErrorSelector;
389 ULONG DataOffset;
390 ULONG DataSelector;
391 ULONG Cr0NpxState;
392 ULONG Spare1;
393 } KFLOATING_SAVE, *PKFLOATING_SAVE;
394
395 #endif
396
397 #if defined(_AMD64_)
398
399 #define PASSIVE_LEVEL 0
400 #define LOW_LEVEL 0
401 #define APC_LEVEL 1
402 #define DISPATCH_LEVEL 2
403 #define CMCI_LEVEL 5
404 #define CLOCK_LEVEL 13
405 #define IPI_LEVEL 14
406 #define DRS_LEVEL 14
407 #define POWER_LEVEL 14
408 #define PROFILE_LEVEL 15
409 #define HIGH_LEVEL 15
410
411 #endif
412
413 #if defined(_IA64_)
414
415 #define PASSIVE_LEVEL 0
416 #define LOW_LEVEL 0
417 #define APC_LEVEL 1
418 #define DISPATCH_LEVEL 2
419 #define CMC_LEVEL 3
420 #define DEVICE_LEVEL_BASE 4
421 #define PC_LEVEL 12
422 #define IPI_LEVEL 14
423 #define DRS_LEVEL 14
424 #define CLOCK_LEVEL 13
425 #define POWER_LEVEL 15
426 #define PROFILE_LEVEL 15
427 #define HIGH_LEVEL 15
428
429 #endif
430
431 /* Exception Records */
432 #define EXCEPTION_NONCONTINUABLE 1
433 #define EXCEPTION_MAXIMUM_PARAMETERS 15
434
435 typedef struct _EXCEPTION_RECORD {
436 NTSTATUS ExceptionCode;
437 ULONG ExceptionFlags;
438 struct _EXCEPTION_RECORD *ExceptionRecord;
439 PVOID ExceptionAddress;
440 ULONG NumberParameters;
441 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
442 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
443
444 typedef struct _EXCEPTION_RECORD32 {
445 NTSTATUS ExceptionCode;
446 ULONG ExceptionFlags;
447 ULONG ExceptionRecord;
448 ULONG ExceptionAddress;
449 ULONG NumberParameters;
450 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
451 } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
452
453 typedef struct _EXCEPTION_RECORD64 {
454 NTSTATUS ExceptionCode;
455 ULONG ExceptionFlags;
456 ULONG64 ExceptionRecord;
457 ULONG64 ExceptionAddress;
458 ULONG NumberParameters;
459 ULONG __unusedAlignment;
460 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
461 } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
462
463 typedef struct _EXCEPTION_POINTERS {
464 PEXCEPTION_RECORD ExceptionRecord;
465 PCONTEXT ContextRecord;
466 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
467
468
469 typedef enum _KBUGCHECK_CALLBACK_REASON {
470 KbCallbackInvalid,
471 KbCallbackReserved1,
472 KbCallbackSecondaryDumpData,
473 KbCallbackDumpIo,
474 KbCallbackAddPages
475 } KBUGCHECK_CALLBACK_REASON;
476
477 struct _KBUGCHECK_REASON_CALLBACK_RECORD;
478
479 typedef VOID
480 (DDKAPI *PKBUGCHECK_REASON_CALLBACK_ROUTINE)(
481 IN KBUGCHECK_CALLBACK_REASON Reason,
482 IN struct _KBUGCHECK_REASON_CALLBACK_RECORD *Record,
483 IN OUT PVOID ReasonSpecificData,
484 IN ULONG ReasonSpecificDataLength);
485
486 typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
487 LIST_ENTRY Entry;
488 PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
489 PUCHAR Component;
490 ULONG_PTR Checksum;
491 KBUGCHECK_CALLBACK_REASON Reason;
492 UCHAR State;
493 } KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
494
495 typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
496 BufferEmpty,
497 BufferInserted,
498 BufferStarted,
499 BufferFinished,
500 BufferIncomplete
501 } KBUGCHECK_BUFFER_DUMP_STATE;
502
503 typedef VOID
504 (DDKAPI *PKBUGCHECK_CALLBACK_ROUTINE)(
505 IN PVOID Buffer,
506 IN ULONG Length);
507
508 typedef struct _KBUGCHECK_CALLBACK_RECORD {
509 LIST_ENTRY Entry;
510 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
511 PVOID Buffer;
512 ULONG Length;
513 PUCHAR Component;
514 ULONG_PTR Checksum;
515 UCHAR State;
516 } KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
517
518 typedef BOOLEAN
519 (DDKAPI *PNMI_CALLBACK)(
520 IN PVOID Context,
521 IN BOOLEAN Handled);
522
523 typedef enum _KDPC_IMPORTANCE {
524 LowImportance,
525 MediumImportance,
526 HighImportance,
527 MediumHighImportance
528 } KDPC_IMPORTANCE;
529
530 typedef enum _TRACE_INFORMATION_CLASS {
531 TraceIdClass,
532 TraceHandleClass,
533 TraceEnableFlagsClass,
534 TraceEnableLevelClass,
535 GlobalLoggerHandleClass,
536 EventLoggerHandleClass,
537 AllLoggerHandlesClass,
538 TraceHandleByNameClass,
539 LoggerEventsLostClass,
540 TraceSessionSettingsClass,
541 LoggerEventsLoggedClass,
542 MaxTraceInformationClass
543 } TRACE_INFORMATION_CLASS;
544
545 typedef enum _KINTERRUPT_POLARITY {
546 InterruptPolarityUnknown,
547 InterruptActiveHigh,
548 InterruptActiveLow
549 } KINTERRUPT_POLARITY, *PKINTERRUPT_POLARITY;
550
551 typedef enum _KPROFILE_SOURCE {
552 ProfileTime,
553 ProfileAlignmentFixup,
554 ProfileTotalIssues,
555 ProfilePipelineDry,
556 ProfileLoadInstructions,
557 ProfilePipelineFrozen,
558 ProfileBranchInstructions,
559 ProfileTotalNonissues,
560 ProfileDcacheMisses,
561 ProfileIcacheMisses,
562 ProfileCacheMisses,
563 ProfileBranchMispredictions,
564 ProfileStoreInstructions,
565 ProfileFpInstructions,
566 ProfileIntegerInstructions,
567 Profile2Issue,
568 Profile3Issue,
569 Profile4Issue,
570 ProfileSpecialInstructions,
571 ProfileTotalCycles,
572 ProfileIcacheIssues,
573 ProfileDcacheAccesses,
574 ProfileMemoryBarrierCycles,
575 ProfileLoadLinkedIssues,
576 ProfileMaximum
577 } KPROFILE_SOURCE;
578
579 typedef enum _KWAIT_REASON {
580 Executive,
581 FreePage,
582 PageIn,
583 PoolAllocation,
584 DelayExecution,
585 Suspended,
586 UserRequest,
587 WrExecutive,
588 WrFreePage,
589 WrPageIn,
590 WrPoolAllocation,
591 WrDelayExecution,
592 WrSuspended,
593 WrUserRequest,
594 WrEventPair,
595 WrQueue,
596 WrLpcReceive,
597 WrLpcReply,
598 WrVirtualMemory,
599 WrPageOut,
600 WrRendezvous,
601 WrKeyedEvent,
602 WrTerminated,
603 WrProcessInSwap,
604 WrCpuRateControl,
605 WrCalloutStack,
606 WrKernel,
607 WrResource,
608 WrPushLock,
609 WrMutex,
610 WrQuantumEnd,
611 WrDispatchInt,
612 WrPreempted,
613 WrYieldExecution,
614 WrFastMutex,
615 WrGuardedMutex,
616 WrRundown,
617 MaximumWaitReason
618 } KWAIT_REASON;
619
620 typedef struct _KWAIT_BLOCK {
621 LIST_ENTRY WaitListEntry;
622 struct _KTHREAD *Thread;
623 PVOID Object;
624 struct _KWAIT_BLOCK *NextWaitBlock;
625 USHORT WaitKey;
626 UCHAR WaitType;
627 volatile UCHAR BlockState;
628 #if defined(_WIN64)
629 LONG SpareLong;
630 #endif
631 } KWAIT_BLOCK, *PKWAIT_BLOCK, *PRKWAIT_BLOCK;
632
633 typedef enum _KINTERRUPT_MODE {
634 LevelSensitive,
635 Latched
636 } KINTERRUPT_MODE;
637
638 #define THREAD_WAIT_OBJECTS 3
639
640 typedef VOID
641 (DDKAPI *PKINTERRUPT_ROUTINE)(
642 VOID);
643
644 typedef enum _KD_OPTION {
645 KD_OPTION_SET_BLOCK_ENABLE,
646 } KD_OPTION;
647
648 typedef enum _INTERFACE_TYPE {
649 InterfaceTypeUndefined = -1,
650 Internal,
651 Isa,
652 Eisa,
653 MicroChannel,
654 TurboChannel,
655 PCIBus,
656 VMEBus,
657 NuBus,
658 PCMCIABus,
659 CBus,
660 MPIBus,
661 MPSABus,
662 ProcessorInternal,
663 InternalPowerBus,
664 PNPISABus,
665 PNPBus,
666 MaximumInterfaceType
667 } INTERFACE_TYPE, *PINTERFACE_TYPE;
668
669 typedef VOID
670 (DDKAPI *PKNORMAL_ROUTINE)(
671 IN PVOID NormalContext,
672 IN PVOID SystemArgument1,
673 IN PVOID SystemArgument2);
674
675 typedef VOID
676 (DDKAPI *PKRUNDOWN_ROUTINE)(
677 IN struct _KAPC *Apc);
678
679 typedef VOID
680 (DDKAPI *PKKERNEL_ROUTINE)(
681 IN struct _KAPC *Apc,
682 IN OUT PKNORMAL_ROUTINE *NormalRoutine,
683 IN OUT PVOID *NormalContext,
684 IN OUT PVOID *SystemArgument1,
685 IN OUT PVOID *SystemArgument2);
686
687 typedef struct _KAPC
688 {
689 UCHAR Type;
690 UCHAR SpareByte0;
691 UCHAR Size;
692 UCHAR SpareByte1;
693 ULONG SpareLong0;
694 struct _KTHREAD *Thread;
695 LIST_ENTRY ApcListEntry;
696 PKKERNEL_ROUTINE KernelRoutine;
697 PKRUNDOWN_ROUTINE RundownRoutine;
698 PKNORMAL_ROUTINE NormalRoutine;
699 PVOID NormalContext;
700 PVOID SystemArgument1;
701 PVOID SystemArgument2;
702 CCHAR ApcStateIndex;
703 KPROCESSOR_MODE ApcMode;
704 BOOLEAN Inserted;
705 } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
706
707 typedef struct _KDEVICE_QUEUE_ENTRY {
708 LIST_ENTRY DeviceListEntry;
709 ULONG SortKey;
710 BOOLEAN Inserted;
711 } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY,
712 *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
713
714 typedef PVOID PKIPI_CONTEXT;
715
716 typedef
717 VOID
718 (NTAPI *PKIPI_WORKER)(
719 IN PKIPI_CONTEXT PacketContext,
720 IN PVOID Parameter1,
721 IN PVOID Parameter2,
722 IN PVOID Parameter3
723 );
724
725 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
726
727 typedef struct _KSPIN_LOCK_QUEUE {
728 struct _KSPIN_LOCK_QUEUE *volatile Next;
729 PKSPIN_LOCK volatile Lock;
730 } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
731
732 typedef struct _KLOCK_QUEUE_HANDLE {
733 KSPIN_LOCK_QUEUE LockQueue;
734 KIRQL OldIrql;
735 } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
736
737 #if defined(_AMD64_)
738
739 typedef ULONG64 KSPIN_LOCK_QUEUE_NUMBER;
740
741 #define LockQueueDispatcherLock 0
742 #define LockQueueExpansionLock 1
743 #define LockQueuePfnLock 2
744 #define LockQueueSystemSpaceLock 3
745 #define LockQueueVacbLock 4
746 #define LockQueueMasterLock 5
747 #define LockQueueNonPagedPoolLock 6
748 #define LockQueueIoCancelLock 7
749 #define LockQueueWorkQueueLock 8
750 #define LockQueueIoVpbLock 9
751 #define LockQueueIoDatabaseLock 10
752 #define LockQueueIoCompletionLock 11
753 #define LockQueueNtfsStructLock 12
754 #define LockQueueAfdWorkQueueLock 13
755 #define LockQueueBcbLock 14
756 #define LockQueueMmNonPagedPoolLock 15
757 #define LockQueueUnusedSpare16 16
758 #define LockQueueTimerTableLock 17
759 #define LockQueueMaximumLock (LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS)
760
761 #else
762
763 typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
764 LockQueueDispatcherLock,
765 LockQueueExpansionLock,
766 LockQueuePfnLock,
767 LockQueueSystemSpaceLock,
768 LockQueueVacbLock,
769 LockQueueMasterLock,
770 LockQueueNonPagedPoolLock,
771 LockQueueIoCancelLock,
772 LockQueueWorkQueueLock,
773 LockQueueIoVpbLock,
774 LockQueueIoDatabaseLock,
775 LockQueueIoCompletionLock,
776 LockQueueNtfsStructLock,
777 LockQueueAfdWorkQueueLock,
778 LockQueueBcbLock,
779 LockQueueMmNonPagedPoolLock,
780 LockQueueUnusedSpare16,
781 LockQueueTimerTableLock,
782 LockQueueMaximumLock = LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS
783 } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
784
785 #endif
786
787 typedef VOID
788 (DDKAPI *PKDEFERRED_ROUTINE)(
789 IN struct _KDPC *Dpc,
790 IN PVOID DeferredContext,
791 IN PVOID SystemArgument1,
792 IN PVOID SystemArgument2);
793
794 typedef struct _KDPC
795 {
796 UCHAR Type;
797 UCHAR Importance;
798 volatile USHORT Number;
799 LIST_ENTRY DpcListEntry;
800 PKDEFERRED_ROUTINE DeferredRoutine;
801 PVOID DeferredContext;
802 PVOID SystemArgument1;
803 PVOID SystemArgument2;
804 volatile PVOID DpcData;
805 } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
806
807 typedef struct _KDEVICE_QUEUE {
808 CSHORT Type;
809 CSHORT Size;
810 LIST_ENTRY DeviceListHead;
811 KSPIN_LOCK Lock;
812 #if defined(_AMD64_)
813 union {
814 BOOLEAN Busy;
815 struct {
816 LONG64 Reserved : 8;
817 LONG64 Hint : 56;
818 };
819 };
820 #else
821 BOOLEAN Busy;
822 #endif
823
824 } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
825
826 typedef struct _DISPATCHER_HEADER
827 {
828 __GNU_EXTENSION union
829 {
830 __GNU_EXTENSION struct
831 {
832 UCHAR Type;
833 __GNU_EXTENSION union
834 {
835 UCHAR Absolute;
836 UCHAR NpxIrql;
837 };
838 __GNU_EXTENSION union
839 {
840 UCHAR Size;
841 UCHAR Hand;
842 };
843 __GNU_EXTENSION union
844 {
845 UCHAR Inserted;
846 BOOLEAN DebugActive;
847 };
848 };
849 volatile LONG Lock;
850 };
851 LONG SignalState;
852 LIST_ENTRY WaitListHead;
853 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
854
855 typedef struct _KGATE
856 {
857 DISPATCHER_HEADER Header;
858 } KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
859
860 typedef struct _KGUARDED_MUTEX
861 {
862 volatile LONG Count;
863 PKTHREAD Owner;
864 ULONG Contention;
865 KGATE Gate;
866 __GNU_EXTENSION union
867 {
868 __GNU_EXTENSION struct
869 {
870 SHORT KernelApcDisable;
871 SHORT SpecialApcDisable;
872 };
873 ULONG CombinedApcDisable;
874 };
875 } KGUARDED_MUTEX, *PKGUARDED_MUTEX;
876
877 typedef struct _KMUTANT {
878 DISPATCHER_HEADER Header;
879 LIST_ENTRY MutantListEntry;
880 struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
881 BOOLEAN Abandoned;
882 UCHAR ApcDisable;
883 } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
884
885 typedef struct _KTIMER {
886 DISPATCHER_HEADER Header;
887 ULARGE_INTEGER DueTime;
888 LIST_ENTRY TimerListEntry;
889 struct _KDPC *Dpc;
890 #if !defined(_X86_)
891 ULONG Processor;
892 #endif
893 ULONG Period;
894 } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
895
896 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
897 {
898 StandardDesign,
899 NEC98x86,
900 EndAlternatives
901 } ALTERNATIVE_ARCHITECTURE_TYPE;
902
903 typedef struct _KSYSTEM_TIME
904 {
905 ULONG LowPart;
906 LONG High1Time;
907 LONG High2Time;
908 } KSYSTEM_TIME, *PKSYSTEM_TIME;
909
910 typedef struct _KEVENT {
911 DISPATCHER_HEADER Header;
912 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
913
914 typedef struct _KSEMAPHORE {
915 DISPATCHER_HEADER Header;
916 LONG Limit;
917 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
918
919 typedef struct _PNP_BUS_INFORMATION {
920 GUID BusTypeGuid;
921 INTERFACE_TYPE LegacyBusType;
922 ULONG BusNumber;
923 } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
924
925 typedef struct DECLSPEC_ALIGN(16) _M128A {
926 ULONGLONG Low;
927 LONGLONG High;
928 } M128A, *PM128A;
929
930 typedef struct DECLSPEC_ALIGN(16) _XSAVE_FORMAT {
931 USHORT ControlWord;
932 USHORT StatusWord;
933 UCHAR TagWord;
934 UCHAR Reserved1;
935 USHORT ErrorOpcode;
936 ULONG ErrorOffset;
937 USHORT ErrorSelector;
938 USHORT Reserved2;
939 ULONG DataOffset;
940 USHORT DataSelector;
941 USHORT Reserved3;
942 ULONG MxCsr;
943 ULONG MxCsr_Mask;
944 M128A FloatRegisters[8];
945
946 #if defined(_WIN64)
947
948 M128A XmmRegisters[16];
949 UCHAR Reserved4[96];
950
951 #else
952
953 M128A XmmRegisters[8];
954 UCHAR Reserved4[192];
955
956 ULONG StackControl[7];
957 ULONG Cr0NpxState;
958
959 #endif
960
961 } XSAVE_FORMAT, *PXSAVE_FORMAT;
962
963 #ifdef _AMD64_
964
965 typedef XSAVE_FORMAT XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
966
967 #endif // _AMD64_
968
969
970 /******************************************************************************
971 * Kernel Functions *
972 ******************************************************************************/
973
974 #if (NTDDI_VERSION >= NTDDI_WIN2K)
975
976 NTKERNELAPI
977 DECLSPEC_NORETURN
978 VOID
979 NTAPI
980 KeBugCheckEx(
981 IN ULONG BugCheckCode,
982 IN ULONG_PTR BugCheckParameter1,
983 IN ULONG_PTR BugCheckParameter2,
984 IN ULONG_PTR BugCheckParameter3,
985 IN ULONG_PTR BugCheckParameter4);
986
987 NTKERNELAPI
988 BOOLEAN
989 NTAPI
990 KeCancelTimer(
991 IN OUT PKTIMER);
992
993 NTKERNELAPI
994 NTSTATUS
995 NTAPI
996 KeDelayExecutionThread(
997 IN KPROCESSOR_MODE WaitMode,
998 IN BOOLEAN Alertable,
999 IN PLARGE_INTEGER Interval);
1000
1001 NTKERNELAPI
1002 BOOLEAN
1003 NTAPI
1004 KeDeregisterBugCheckCallback(
1005 IN OUT PKBUGCHECK_CALLBACK_RECORD CallbackRecord);
1006
1007 NTKERNELAPI
1008 VOID
1009 NTAPI
1010 KeEnterCriticalRegion(VOID);
1011
1012 NTKERNELAPI
1013 VOID
1014 NTAPI
1015 KeInitializeDeviceQueue(
1016 OUT PKDEVICE_QUEUE DeviceQueue);
1017
1018 NTKERNELAPI
1019 VOID
1020 NTAPI
1021 KeInitializeMutex(
1022 OUT PRKMUTEX Mutex,
1023 IN ULONG Level);
1024
1025 NTKERNELAPI
1026 VOID
1027 NTAPI
1028 KeInitializeSemaphore(
1029 OUT PRKSEMAPHORE Semaphore,
1030 IN LONG Count,
1031 IN LONG Limit);
1032
1033 NTKERNELAPI
1034 VOID
1035 NTAPI
1036 KeInitializeTimer(
1037 OUT PKTIMER Timer);
1038
1039 NTKERNELAPI
1040 VOID
1041 NTAPI
1042 KeInitializeTimerEx(
1043 OUT PKTIMER Timer,
1044 IN TIMER_TYPE Type);
1045
1046 NTKERNELAPI
1047 BOOLEAN
1048 NTAPI
1049 KeInsertByKeyDeviceQueue(
1050 IN OUT PKDEVICE_QUEUE DeviceQueue,
1051 IN OUT PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
1052 IN ULONG SortKey);
1053
1054 NTKERNELAPI
1055 BOOLEAN
1056 NTAPI
1057 KeInsertDeviceQueue(
1058 IN OUT PKDEVICE_QUEUE DeviceQueue,
1059 IN OUT PKDEVICE_QUEUE_ENTRY DeviceQueueEntry);
1060
1061 NTKERNELAPI
1062 BOOLEAN
1063 NTAPI
1064 KeInsertQueueDpc(
1065 IN OUT PRKDPC Dpc,
1066 IN PVOID SystemArgument1 OPTIONAL,
1067 IN PVOID SystemArgument2 OPTIONAL);
1068
1069 NTKERNELAPI
1070 VOID
1071 NTAPI
1072 KeLeaveCriticalRegion(VOID);
1073
1074 #endif
1075
1076 #if (NTDDI_VERSION >= NTDDI_WINXP)
1077
1078 VOID
1079 FASTCALL
1080 KeAcquireInStackQueuedSpinLock (
1081 IN OUT PKSPIN_LOCK SpinLock,
1082 OUT PKLOCK_QUEUE_HANDLE LockHandle);
1083
1084 NTKERNELAPI
1085 VOID
1086 FASTCALL
1087 KeAcquireInStackQueuedSpinLockAtDpcLevel(
1088 IN OUT PKSPIN_LOCK SpinLock,
1089 OUT PKLOCK_QUEUE_HANDLE LockHandle);
1090
1091 NTKERNELAPI
1092 KIRQL
1093 NTAPI
1094 KeAcquireInterruptSpinLock(
1095 IN OUT PKINTERRUPT Interrupt);
1096
1097 NTKERNELAPI
1098 BOOLEAN
1099 NTAPI
1100 KeAreApcsDisabled(VOID);
1101
1102 NTKERNELAPI
1103 ULONG
1104 NTAPI
1105 KeGetRecommendedSharedDataAlignment(VOID);
1106
1107 #endif
1108
1109 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
1110
1111 NTKERNELAPI
1112 VOID
1113 NTAPI
1114 KeFlushQueuedDpcs(
1115 VOID);
1116
1117 #endif
1118
1119 #if defined(_IA64_)
1120 FORCEINLINE
1121 VOID
1122 KeFlushWriteBuffer(VOID)
1123 {
1124 __mf ();
1125 return;
1126 }
1127 #else
1128 NTHALAPI
1129 VOID
1130 NTAPI
1131 KeFlushWriteBuffer(VOID);
1132 #endif
1133
1134 NTKERNELAPI
1135 VOID
1136 NTAPI
1137 KeClearEvent(
1138 IN OUT PRKEVENT Event);
1139
1140 /*
1141 * VOID
1142 * KeFlushIoBuffers(
1143 * IN PMDL Mdl,
1144 * IN BOOLEAN ReadOperation,
1145 * IN BOOLEAN DmaOperation)
1146 */
1147 #define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
1148
1149 #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
1150 #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
1151 #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
1152 #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
1153
1154
1155 /* SPINLOCK FUNCTIONS */
1156
1157 #if (NTDDI_VERSION >= NTDDI_WINXP)
1158 //_DECL_HAL_KE_IMPORT
1159 VOID
1160 FASTCALL
1161 KeAcquireInStackQueuedSpinLock(
1162 IN OUT PKSPIN_LOCK SpinLock,
1163 OUT PKLOCK_QUEUE_HANDLE LockHandle);
1164
1165 //_DECL_HAL_KE_IMPORT
1166 VOID
1167 FASTCALL
1168 KeReleaseInStackQueuedSpinLock(
1169 IN PKLOCK_QUEUE_HANDLE LockHandle);
1170
1171 #endif
1172
1173 /* FIXME : #if (NTDDI_VERSION >= NTDDI_WS03SP1) */
1174 NTKERNELAPI
1175 BOOLEAN
1176 FASTCALL
1177 KeTryToAcquireSpinLockAtDpcLevel(
1178 IN OUT PKSPIN_LOCK SpinLock
1179 );
1180 /* #endif (NTDDI_VERSION >= NTDDI_WS03SP1) */
1181
1182 #if (NTDDI_VERSION >= NTDDI_WS03)
1183 NTKERNELAPI
1184 BOOLEAN
1185 FASTCALL
1186 KeTestSpinLock(
1187 IN PKSPIN_LOCK SpinLock
1188 );
1189 #endif
1190
1191 /* FIXME : #if (NTDDI_VERSION >= NTDDI_WS03SP1) */
1192 NTKERNELAPI
1193 BOOLEAN
1194 NTAPI
1195 KeAreAllApcsDisabled(
1196 VOID);
1197 /* #endif (NTDDI_VERSION >= NTDDI_WS03SP1) */
1198
1199 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
1200
1201 /* Guarded Mutex routines */
1202
1203 NTKERNELAPI
1204 VOID
1205 FASTCALL
1206 KeAcquireGuardedMutex(
1207 IN OUT PKGUARDED_MUTEX GuardedMutex
1208 );
1209
1210 NTKERNELAPI
1211 VOID
1212 FASTCALL
1213 KeAcquireGuardedMutexUnsafe(
1214 IN OUT PKGUARDED_MUTEX GuardedMutex
1215 );
1216
1217 NTKERNELAPI
1218 VOID
1219 KeEnterGuardedRegion(
1220 VOID
1221 );
1222
1223 NTKERNELAPI
1224 VOID
1225 NTAPI
1226 KeLeaveGuardedRegion(
1227 VOID
1228 );
1229
1230 NTKERNELAPI
1231 VOID
1232 FASTCALL
1233 KeInitializeGuardedMutex(
1234 OUT PKGUARDED_MUTEX GuardedMutex
1235 );
1236
1237 NTKERNELAPI
1238 VOID
1239 FASTCALL
1240 KeReleaseGuardedMutexUnsafe(
1241 IN OUT PKGUARDED_MUTEX GuardedMutex
1242 );
1243
1244 NTKERNELAPI
1245 VOID
1246 FASTCALL
1247 KeReleaseGuardedMutex(
1248 IN OUT PKGUARDED_MUTEX GuardedMutex
1249 );
1250
1251 NTKERNELAPI
1252 BOOLEAN
1253 FASTCALL
1254 KeTryToAcquireGuardedMutex(
1255 IN OUT PKGUARDED_MUTEX GuardedMutex
1256 );
1257
1258 #endif
1259
1260 NTHALAPI
1261 KIRQL
1262 NTAPI
1263 KeGetCurrentIrql(
1264 VOID);
1265
1266 #if defined(_M_AMD64)
1267
1268 ULONG64
1269 __readgsqword (
1270 IN ULONG Offset);
1271
1272 #pragma intrinsic(__readgsqword)
1273
1274 FORCEINLINE
1275 PKTHREAD
1276 KeGetCurrentThread (
1277 VOID)
1278 {
1279 return (struct _KTHREAD *)__readgsqword(0x188);
1280 }
1281
1282 #endif
1283
1284 #if defined(_M_IX86) || defined(_M_IA64)
1285 NTSYSAPI
1286 PKTHREAD
1287 NTAPI
1288 KeGetCurrentThread(
1289 VOID);
1290 #endif
1291
1292 NTKERNELAPI
1293 VOID
1294 NTAPI
1295 KeInitializeEvent(
1296 OUT PRKEVENT Event,
1297 IN EVENT_TYPE Type,
1298 IN BOOLEAN State);
1299
1300 /*
1301 * VOID
1302 * KeInitializeCallbackRecord(
1303 * IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
1304 */
1305 #define KeInitializeCallbackRecord(CallbackRecord) \
1306 CallbackRecord->State = BufferEmpty;
1307
1308 #if DBG
1309
1310 #if (NTDDI_VERSION >= NTDDI_VISTA)
1311 #define PAGED_ASSERT( exp ) NT_ASSERT( exp )
1312 #else
1313 #define PAGED_ASSERT( exp ) ASSERT( exp )
1314 #endif
1315
1316 #define PAGED_CODE() { \
1317 if (KeGetCurrentIrql() > APC_LEVEL) { \
1318 KdPrint( ("NTDDK: Pageable code called at IRQL > APC_LEVEL (%d)\n", KeGetCurrentIrql() )); \
1319 PAGED_ASSERT(FALSE); \
1320 } \
1321 }
1322
1323 #else
1324
1325 #define PAGED_CODE()
1326
1327 #endif
1328
1329 #if defined(_NTDDK_) || defined(_NTIFS_)
1330
1331 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1332
1333 NTKERNELAPI
1334 VOID
1335 NTAPI
1336 ProbeForRead(
1337 IN CONST VOID *Address,
1338 IN SIZE_T Length,
1339 IN ULONG Alignment);
1340
1341 #endif
1342
1343 #endif
1344
1345 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1346
1347 NTKERNELAPI
1348 VOID
1349 NTAPI
1350 ProbeForWrite(
1351 IN PVOID Address,
1352 IN SIZE_T Length,
1353 IN ULONG Alignment);
1354
1355 #endif
1356
1357 #if defined(_X86_) || defined(_AMD64_)
1358
1359 /* x86 and x64 performs a 0x2C interrupt */
1360 #define DbgRaiseAssertionFailure __int2c
1361
1362 #elif defined(_ARM_)
1363
1364 //
1365 // TODO
1366 //
1367
1368 #else
1369 #error Unsupported Architecture
1370 #endif
1371
1372
1373 /******************************************************************************
1374 * Memory manager Types *
1375 ******************************************************************************/
1376
1377 #define PAGE_SIZE 0x1000
1378 #define PAGE_SHIFT 12L
1379
1380 #define MM_DONT_ZERO_ALLOCATION 0x00000001
1381 #define MM_ALLOCATE_FROM_LOCAL_NODE_ONLY 0x00000002
1382 #define MM_ALLOCATE_FULLY_REQUIRED 0x00000004
1383 #define MM_ALLOCATE_NO_WAIT 0x00000008
1384 #define MM_ALLOCATE_PREFER_CONTIGUOUS 0x00000010
1385 #define MM_ALLOCATE_REQUIRE_CONTIGUOUS_CHUNKS 0x00000020
1386
1387 #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
1388 #define MDL_PAGES_LOCKED 0x0002
1389 #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
1390 #define MDL_ALLOCATED_FIXED_SIZE 0x0008
1391 #define MDL_PARTIAL 0x0010
1392 #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
1393 #define MDL_IO_PAGE_READ 0x0040
1394 #define MDL_WRITE_OPERATION 0x0080
1395 #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
1396 #define MDL_FREE_EXTRA_PTES 0x0200
1397 #define MDL_DESCRIBES_AWE 0x0400
1398 #define MDL_IO_SPACE 0x0800
1399 #define MDL_NETWORK_HEADER 0x1000
1400 #define MDL_MAPPING_CAN_FAIL 0x2000
1401 #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
1402 #define MDL_INTERNAL 0x8000
1403
1404 #define MDL_MAPPING_FLAGS ( \
1405 MDL_MAPPED_TO_SYSTEM_VA | \
1406 MDL_PAGES_LOCKED | \
1407 MDL_SOURCE_IS_NONPAGED_POOL | \
1408 MDL_PARTIAL_HAS_BEEN_MAPPED | \
1409 MDL_PARENT_MAPPED_SYSTEM_VA | \
1410 MDL_SYSTEM_VA | \
1411 MDL_IO_SPACE)
1412
1413 #define FLUSH_MULTIPLE_MAXIMUM 32
1414
1415 /* Section access rights */
1416 #define SECTION_QUERY 0x0001
1417 #define SECTION_MAP_WRITE 0x0002
1418 #define SECTION_MAP_READ 0x0004
1419 #define SECTION_MAP_EXECUTE 0x0008
1420 #define SECTION_EXTEND_SIZE 0x0010
1421 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
1422
1423 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
1424 SECTION_MAP_WRITE | \
1425 SECTION_MAP_READ | \
1426 SECTION_MAP_EXECUTE | \
1427 SECTION_EXTEND_SIZE)
1428
1429 #define SESSION_QUERY_ACCESS 0x0001
1430 #define SESSION_MODIFY_ACCESS 0x0002
1431
1432 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
1433 SESSION_QUERY_ACCESS | \
1434 SESSION_MODIFY_ACCESS)
1435
1436 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
1437
1438 #define PAGE_NOACCESS 0x01
1439 #define PAGE_READONLY 0x02
1440 #define PAGE_READWRITE 0x04
1441 #define PAGE_WRITECOPY 0x08
1442 #define PAGE_EXECUTE 0x10
1443 #define PAGE_EXECUTE_READ 0x20
1444 #define PAGE_EXECUTE_READWRITE 0x40
1445 #define PAGE_EXECUTE_WRITECOPY 0x80
1446 #define PAGE_GUARD 0x100
1447 #define PAGE_NOCACHE 0x200
1448 #define PAGE_WRITECOMBINE 0x400
1449
1450 #define MEM_COMMIT 0x1000
1451 #define MEM_RESERVE 0x2000
1452 #define MEM_DECOMMIT 0x4000
1453 #define MEM_RELEASE 0x8000
1454 #define MEM_FREE 0x10000
1455 #define MEM_PRIVATE 0x20000
1456 #define MEM_MAPPED 0x40000
1457 #define MEM_RESET 0x80000
1458 #define MEM_TOP_DOWN 0x100000
1459 #define MEM_LARGE_PAGES 0x20000000
1460 #define MEM_4MB_PAGES 0x80000000
1461
1462 #define SEC_RESERVE 0x4000000
1463 #define SEC_LARGE_PAGES 0x80000000
1464
1465 /* Section map options */
1466 typedef enum _SECTION_INHERIT {
1467 ViewShare = 1,
1468 ViewUnmap = 2
1469 } SECTION_INHERIT;
1470
1471 typedef ULONG PFN_COUNT;
1472 typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
1473 typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
1474
1475 typedef struct _MDL {
1476 struct _MDL *Next;
1477 CSHORT Size;
1478 CSHORT MdlFlags;
1479 struct _EPROCESS *Process;
1480 PVOID MappedSystemVa;
1481 PVOID StartVa;
1482 ULONG ByteCount;
1483 ULONG ByteOffset;
1484 } MDL, *PMDL;
1485
1486 typedef enum _MEMORY_CACHING_TYPE_ORIG {
1487 MmFrameBufferCached = 2
1488 } MEMORY_CACHING_TYPE_ORIG;
1489
1490 typedef enum _MEMORY_CACHING_TYPE {
1491 MmNonCached = FALSE,
1492 MmCached = TRUE,
1493 MmWriteCombined = MmFrameBufferCached,
1494 MmHardwareCoherentCached,
1495 MmNonCachedUnordered,
1496 MmUSWCCached,
1497 MmMaximumCacheType
1498 } MEMORY_CACHING_TYPE;
1499
1500 typedef enum _MM_PAGE_PRIORITY {
1501 LowPagePriority,
1502 NormalPagePriority = 16,
1503 HighPagePriority = 32
1504 } MM_PAGE_PRIORITY;
1505
1506 typedef enum _LOCK_OPERATION {
1507 IoReadAccess,
1508 IoWriteAccess,
1509 IoModifyAccess
1510 } LOCK_OPERATION;
1511
1512 typedef enum _MM_SYSTEM_SIZE {
1513 MmSmallSystem,
1514 MmMediumSystem,
1515 MmLargeSystem
1516 } MM_SYSTEMSIZE;
1517
1518
1519 /******************************************************************************
1520 * Memory manager Functions *
1521 ******************************************************************************/
1522
1523 /*
1524 * Alignment Macros
1525 */
1526 #define ALIGN_DOWN(s, t) \
1527 ((ULONG)(s) & ~(sizeof(t) - 1))
1528
1529 #define ALIGN_UP(s, t) \
1530 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
1531
1532 #define ALIGN_DOWN_POINTER(p, t) \
1533 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
1534
1535 #define ALIGN_UP_POINTER(p, t) \
1536 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
1537
1538 /* ULONG
1539 * BYTE_OFFSET(
1540 * IN PVOID Va)
1541 */
1542 #define BYTE_OFFSET(Va) \
1543 ((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
1544
1545 /* ULONG
1546 * BYTES_TO_PAGES(
1547 * IN ULONG Size)
1548 */
1549 #define BYTES_TO_PAGES(Size) \
1550 (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
1551
1552 /* PVOID
1553 * PAGE_ALIGN(
1554 * IN PVOID Va)
1555 */
1556 #define PAGE_ALIGN(Va) \
1557 ((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
1558
1559 /* ULONG_PTR
1560 * ROUND_TO_PAGES(
1561 * IN ULONG_PTR Size)
1562 */
1563 #define ROUND_TO_PAGES(Size) \
1564 (((ULONG_PTR) (Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
1565
1566 /* PVOID MmGetSystemAddressForMdl(
1567 * IN PMDL Mdl);
1568 */
1569 #define MmGetSystemAddressForMdl(Mdl) \
1570 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
1571 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1572 ((Mdl)->MappedSystemVa) : \
1573 (MmMapLockedPages((Mdl), KernelMode)))
1574
1575 /* PVOID
1576 * MmGetSystemAddressForMdlSafe(
1577 * IN PMDL Mdl,
1578 * IN MM_PAGE_PRIORITY Priority)
1579 */
1580 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
1581 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
1582 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1583 (_Mdl)->MappedSystemVa : \
1584 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
1585 KernelMode, MmCached, NULL, FALSE, (_Priority)))
1586
1587 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1588 NTKERNELAPI
1589 PMDL
1590 NTAPI
1591 MmCreateMdl(
1592 IN PMDL MemoryDescriptorList OPTIONAL,
1593 IN PVOID Base,
1594 IN SIZE_T Length);
1595
1596 #endif
1597
1598 /******************************************************************************
1599 * Security Manager Types *
1600 ******************************************************************************/
1601
1602 /* Simple types */
1603 typedef PVOID PSECURITY_DESCRIPTOR;
1604 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
1605 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
1606 typedef PVOID PACCESS_TOKEN;
1607 typedef PVOID PSID;
1608
1609 #define DELETE 0x00010000L
1610 #define READ_CONTROL 0x00020000L
1611 #define WRITE_DAC 0x00040000L
1612 #define WRITE_OWNER 0x00080000L
1613 #define SYNCHRONIZE 0x00100000L
1614 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
1615 #define STANDARD_RIGHTS_READ READ_CONTROL
1616 #define STANDARD_RIGHTS_WRITE READ_CONTROL
1617 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
1618 #define STANDARD_RIGHTS_ALL 0x001F0000L
1619 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
1620 #define ACCESS_SYSTEM_SECURITY 0x01000000L
1621 #define MAXIMUM_ALLOWED 0x02000000L
1622 #define GENERIC_READ 0x80000000L
1623 #define GENERIC_WRITE 0x40000000L
1624 #define GENERIC_EXECUTE 0x20000000L
1625 #define GENERIC_ALL 0x10000000L
1626
1627 typedef struct _GENERIC_MAPPING {
1628 ACCESS_MASK GenericRead;
1629 ACCESS_MASK GenericWrite;
1630 ACCESS_MASK GenericExecute;
1631 ACCESS_MASK GenericAll;
1632 } GENERIC_MAPPING, *PGENERIC_MAPPING;
1633
1634 #define ACL_REVISION 2
1635 #define ACL_REVISION_DS 4
1636
1637 #define ACL_REVISION1 1
1638 #define ACL_REVISION2 2
1639 #define ACL_REVISION3 3
1640 #define ACL_REVISION4 4
1641 #define MIN_ACL_REVISION ACL_REVISION2
1642 #define MAX_ACL_REVISION ACL_REVISION4
1643
1644 typedef struct _ACL {
1645 UCHAR AclRevision;
1646 UCHAR Sbz1;
1647 USHORT AclSize;
1648 USHORT AceCount;
1649 USHORT Sbz2;
1650 } ACL, *PACL;
1651
1652 /* Current security descriptor revision value */
1653 #define SECURITY_DESCRIPTOR_REVISION (1)
1654 #define SECURITY_DESCRIPTOR_REVISION1 (1)
1655
1656 /* Privilege attributes */
1657 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
1658 #define SE_PRIVILEGE_ENABLED (0x00000002L)
1659 #define SE_PRIVILEGE_REMOVED (0X00000004L)
1660 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
1661
1662 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
1663 SE_PRIVILEGE_ENABLED | \
1664 SE_PRIVILEGE_REMOVED | \
1665 SE_PRIVILEGE_USED_FOR_ACCESS)
1666
1667 #include <pshpack4.h>
1668 typedef struct _LUID_AND_ATTRIBUTES {
1669 LUID Luid;
1670 ULONG Attributes;
1671 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
1672 #include <poppack.h>
1673
1674 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
1675 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
1676
1677 /* Privilege sets */
1678 #define PRIVILEGE_SET_ALL_NECESSARY (1)
1679
1680 typedef struct _PRIVILEGE_SET {
1681 ULONG PrivilegeCount;
1682 ULONG Control;
1683 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
1684 } PRIVILEGE_SET,*PPRIVILEGE_SET;
1685
1686 typedef enum _SECURITY_IMPERSONATION_LEVEL {
1687 SecurityAnonymous,
1688 SecurityIdentification,
1689 SecurityImpersonation,
1690 SecurityDelegation
1691 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
1692
1693 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
1694 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
1695 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
1696 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
1697
1698 #define SECURITY_DYNAMIC_TRACKING (TRUE)
1699 #define SECURITY_STATIC_TRACKING (FALSE)
1700
1701 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
1702
1703 typedef struct _SECURITY_QUALITY_OF_SERVICE {
1704 ULONG Length;
1705 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1706 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
1707 BOOLEAN EffectiveOnly;
1708 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
1709
1710 typedef struct _SE_IMPERSONATION_STATE {
1711 PACCESS_TOKEN Token;
1712 BOOLEAN CopyOnOpen;
1713 BOOLEAN EffectiveOnly;
1714 SECURITY_IMPERSONATION_LEVEL Level;
1715 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
1716
1717 #define OWNER_SECURITY_INFORMATION (0x00000001L)
1718 #define GROUP_SECURITY_INFORMATION (0x00000002L)
1719 #define DACL_SECURITY_INFORMATION (0x00000004L)
1720 #define SACL_SECURITY_INFORMATION (0x00000008L)
1721 #define LABEL_SECURITY_INFORMATION (0x00000010L)
1722
1723 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
1724 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
1725 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
1726 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
1727
1728 typedef enum _SECURITY_OPERATION_CODE {
1729 SetSecurityDescriptor,
1730 QuerySecurityDescriptor,
1731 DeleteSecurityDescriptor,
1732 AssignSecurityDescriptor
1733 } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
1734
1735 #define INITIAL_PRIVILEGE_COUNT 3
1736
1737 typedef struct _INITIAL_PRIVILEGE_SET {
1738 ULONG PrivilegeCount;
1739 ULONG Control;
1740 LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
1741 } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
1742
1743 #define SE_MIN_WELL_KNOWN_PRIVILEGE 2
1744 #define SE_CREATE_TOKEN_PRIVILEGE 2
1745 #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3
1746 #define SE_LOCK_MEMORY_PRIVILEGE 4
1747 #define SE_INCREASE_QUOTA_PRIVILEGE 5
1748 #define SE_MACHINE_ACCOUNT_PRIVILEGE 6
1749 #define SE_TCB_PRIVILEGE 7
1750 #define SE_SECURITY_PRIVILEGE 8
1751 #define SE_TAKE_OWNERSHIP_PRIVILEGE 9
1752 #define SE_LOAD_DRIVER_PRIVILEGE 10
1753 #define SE_SYSTEM_PROFILE_PRIVILEGE 11
1754 #define SE_SYSTEMTIME_PRIVILEGE 12
1755 #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13
1756 #define SE_INC_BASE_PRIORITY_PRIVILEGE 14
1757 #define SE_CREATE_PAGEFILE_PRIVILEGE 15
1758 #define SE_CREATE_PERMANENT_PRIVILEGE 16
1759 #define SE_BACKUP_PRIVILEGE 17
1760 #define SE_RESTORE_PRIVILEGE 18
1761 #define SE_SHUTDOWN_PRIVILEGE 19
1762 #define SE_DEBUG_PRIVILEGE 20
1763 #define SE_AUDIT_PRIVILEGE 21
1764 #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22
1765 #define SE_CHANGE_NOTIFY_PRIVILEGE 23
1766 #define SE_REMOTE_SHUTDOWN_PRIVILEGE 24
1767 #define SE_UNDOCK_PRIVILEGE 25
1768 #define SE_SYNC_AGENT_PRIVILEGE 26
1769 #define SE_ENABLE_DELEGATION_PRIVILEGE 27
1770 #define SE_MANAGE_VOLUME_PRIVILEGE 28
1771 #define SE_IMPERSONATE_PRIVILEGE 29
1772 #define SE_CREATE_GLOBAL_PRIVILEGE 30
1773 #define SE_TRUSTED_CREDMAN_ACCESS_PRIVILEGE 31
1774 #define SE_RELABEL_PRIVILEGE 32
1775 #define SE_INC_WORKING_SET_PRIVILEGE 33
1776 #define SE_TIME_ZONE_PRIVILEGE 34
1777 #define SE_CREATE_SYMBOLIC_LINK_PRIVILEGE 35
1778 #define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_SYMBOLIC_LINK_PRIVILEGE
1779
1780 typedef struct _SECURITY_SUBJECT_CONTEXT {
1781 PACCESS_TOKEN ClientToken;
1782 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1783 PACCESS_TOKEN PrimaryToken;
1784 PVOID ProcessAuditId;
1785 } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
1786
1787 typedef struct _ACCESS_STATE {
1788 LUID OperationID;
1789 BOOLEAN SecurityEvaluated;
1790 BOOLEAN GenerateAudit;
1791 BOOLEAN GenerateOnClose;
1792 BOOLEAN PrivilegesAllocated;
1793 ULONG Flags;
1794 ACCESS_MASK RemainingDesiredAccess;
1795 ACCESS_MASK PreviouslyGrantedAccess;
1796 ACCESS_MASK OriginalDesiredAccess;
1797 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
1798 PSECURITY_DESCRIPTOR SecurityDescriptor;
1799 PVOID AuxData;
1800 union {
1801 INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
1802 PRIVILEGE_SET PrivilegeSet;
1803 } Privileges;
1804
1805 BOOLEAN AuditPrivileges;
1806 UNICODE_STRING ObjectName;
1807 UNICODE_STRING ObjectTypeName;
1808 } ACCESS_STATE, *PACCESS_STATE;
1809
1810
1811 /******************************************************************************
1812 * Power Types *
1813 ******************************************************************************/
1814
1815
1816 /* Power States/Levels */
1817 typedef enum _SYSTEM_POWER_STATE {
1818 PowerSystemUnspecified,
1819 PowerSystemWorking,
1820 PowerSystemSleeping1,
1821 PowerSystemSleeping2,
1822 PowerSystemSleeping3,
1823 PowerSystemHibernate,
1824 PowerSystemShutdown,
1825 PowerSystemMaximum
1826 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
1827
1828 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
1829
1830 typedef enum _POWER_INFORMATION_LEVEL {
1831 SystemPowerPolicyAc,
1832 SystemPowerPolicyDc,
1833 VerifySystemPolicyAc,
1834 VerifySystemPolicyDc,
1835 SystemPowerCapabilities,
1836 SystemBatteryState,
1837 SystemPowerStateHandler,
1838 ProcessorStateHandler,
1839 SystemPowerPolicyCurrent,
1840 AdministratorPowerPolicy,
1841 SystemReserveHiberFile,
1842 ProcessorInformation,
1843 SystemPowerInformation,
1844 ProcessorStateHandler2,
1845 LastWakeTime,
1846 LastSleepTime,
1847 SystemExecutionState,
1848 SystemPowerStateNotifyHandler,
1849 ProcessorPowerPolicyAc,
1850 ProcessorPowerPolicyDc,
1851 VerifyProcessorPowerPolicyAc,
1852 VerifyProcessorPowerPolicyDc,
1853 ProcessorPowerPolicyCurrent
1854 } POWER_INFORMATION_LEVEL;
1855
1856 typedef enum {
1857 PowerActionNone,
1858 PowerActionReserved,
1859 PowerActionSleep,
1860 PowerActionHibernate,
1861 PowerActionShutdown,
1862 PowerActionShutdownReset,
1863 PowerActionShutdownOff,
1864 PowerActionWarmEject
1865 } POWER_ACTION, *PPOWER_ACTION;
1866
1867 typedef enum _DEVICE_POWER_STATE {
1868 PowerDeviceUnspecified,
1869 PowerDeviceD0,
1870 PowerDeviceD1,
1871 PowerDeviceD2,
1872 PowerDeviceD3,
1873 PowerDeviceMaximum
1874 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
1875
1876
1877 /******************************************************************************
1878 * Configuration Manager Types *
1879 ******************************************************************************/
1880
1881 /* Resource list definitions */
1882 typedef int CM_RESOURCE_TYPE;
1883
1884 #define CmResourceTypeNull 0
1885 #define CmResourceTypePort 1
1886 #define CmResourceTypeInterrupt 2
1887 #define CmResourceTypeMemory 3
1888 #define CmResourceTypeDma 4
1889 #define CmResourceTypeDeviceSpecific 5
1890 #define CmResourceTypeBusNumber 6
1891 #define CmResourceTypeNonArbitrated 128
1892 #define CmResourceTypeConfigData 128
1893 #define CmResourceTypeDevicePrivate 129
1894 #define CmResourceTypePcCardConfig 130
1895 #define CmResourceTypeMfCardConfig 131
1896
1897
1898 /* KEY_VALUE_Xxx.Type */
1899 #define REG_NONE 0
1900 #define REG_SZ 1
1901 #define REG_EXPAND_SZ 2
1902 #define REG_BINARY 3
1903 #define REG_DWORD 4
1904 #define REG_DWORD_LITTLE_ENDIAN 4
1905 #define REG_DWORD_BIG_ENDIAN 5
1906 #define REG_LINK 6
1907 #define REG_MULTI_SZ 7
1908 #define REG_RESOURCE_LIST 8
1909 #define REG_FULL_RESOURCE_DESCRIPTOR 9
1910 #define REG_RESOURCE_REQUIREMENTS_LIST 10
1911 #define REG_QWORD 11
1912 #define REG_QWORD_LITTLE_ENDIAN 11
1913
1914 /* Registry Access Rights */
1915 #define KEY_QUERY_VALUE (0x0001)
1916 #define KEY_SET_VALUE (0x0002)
1917 #define KEY_CREATE_SUB_KEY (0x0004)
1918 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
1919 #define KEY_NOTIFY (0x0010)
1920 #define KEY_CREATE_LINK (0x0020)
1921 #define KEY_WOW64_32KEY (0x0200)
1922 #define KEY_WOW64_64KEY (0x0100)
1923 #define KEY_WOW64_RES (0x0300)
1924
1925 #define KEY_READ ((STANDARD_RIGHTS_READ |\
1926 KEY_QUERY_VALUE |\
1927 KEY_ENUMERATE_SUB_KEYS |\
1928 KEY_NOTIFY) \
1929 & \
1930 (~SYNCHRONIZE))
1931
1932 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
1933 KEY_SET_VALUE |\
1934 KEY_CREATE_SUB_KEY) \
1935 & \
1936 (~SYNCHRONIZE))
1937
1938 #define KEY_EXECUTE ((KEY_READ) \
1939 & \
1940 (~SYNCHRONIZE))
1941
1942 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
1943 KEY_QUERY_VALUE |\
1944 KEY_SET_VALUE |\
1945 KEY_CREATE_SUB_KEY |\
1946 KEY_ENUMERATE_SUB_KEYS |\
1947 KEY_NOTIFY |\
1948 KEY_CREATE_LINK) \
1949 & \
1950 (~SYNCHRONIZE))
1951
1952 /* Registry Open/Create Options */
1953 #define REG_OPTION_RESERVED (0x00000000L)
1954 #define REG_OPTION_NON_VOLATILE (0x00000000L)
1955 #define REG_OPTION_VOLATILE (0x00000001L)
1956 #define REG_OPTION_CREATE_LINK (0x00000002L)
1957 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
1958 #define REG_OPTION_OPEN_LINK (0x00000008L)
1959
1960 #define REG_LEGAL_OPTION \
1961 (REG_OPTION_RESERVED |\
1962 REG_OPTION_NON_VOLATILE |\
1963 REG_OPTION_VOLATILE |\
1964 REG_OPTION_CREATE_LINK |\
1965 REG_OPTION_BACKUP_RESTORE |\
1966 REG_OPTION_OPEN_LINK)
1967
1968 /* Key creation/open disposition */
1969 #define REG_CREATED_NEW_KEY (0x00000001L)
1970 #define REG_OPENED_EXISTING_KEY (0x00000002L)
1971
1972 /* Key restore & hive load flags */
1973 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
1974 #define REG_REFRESH_HIVE (0x00000002L)
1975 #define REG_NO_LAZY_FLUSH (0x00000004L)
1976 #define REG_FORCE_RESTORE (0x00000008L)
1977 #define REG_APP_HIVE (0x00000010L)
1978 #define REG_PROCESS_PRIVATE (0x00000020L)
1979 #define REG_START_JOURNAL (0x00000040L)
1980 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
1981 #define REG_HIVE_NO_RM (0x00000100L)
1982 #define REG_HIVE_SINGLE_LOG (0x00000200L)
1983
1984 /* Unload Flags */
1985 #define REG_FORCE_UNLOAD 1
1986
1987 /* Notify Filter Values */
1988 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
1989 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
1990 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
1991 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
1992
1993 #define REG_LEGAL_CHANGE_FILTER \
1994 (REG_NOTIFY_CHANGE_NAME |\
1995 REG_NOTIFY_CHANGE_ATTRIBUTES |\
1996 REG_NOTIFY_CHANGE_LAST_SET |\
1997 REG_NOTIFY_CHANGE_SECURITY)
1998
1999 typedef struct _CM_FLOPPY_DEVICE_DATA {
2000 USHORT Version;
2001 USHORT Revision;
2002 CHAR Size[8];
2003 ULONG MaxDensity;
2004 ULONG MountDensity;
2005 UCHAR StepRateHeadUnloadTime;
2006 UCHAR HeadLoadTime;
2007 UCHAR MotorOffTime;
2008 UCHAR SectorLengthCode;
2009 UCHAR SectorPerTrack;
2010 UCHAR ReadWriteGapLength;
2011 UCHAR DataTransferLength;
2012 UCHAR FormatGapLength;
2013 UCHAR FormatFillCharacter;
2014 UCHAR HeadSettleTime;
2015 UCHAR MotorSettleTime;
2016 UCHAR MaximumTrackValue;
2017 UCHAR DataTransferRate;
2018 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
2019
2020 #include <pshpack4.h>
2021 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
2022 UCHAR Type;
2023 UCHAR ShareDisposition;
2024 USHORT Flags;
2025 union {
2026 struct {
2027 PHYSICAL_ADDRESS Start;
2028 ULONG Length;
2029 } Generic;
2030 struct {
2031 PHYSICAL_ADDRESS Start;
2032 ULONG Length;
2033 } Port;
2034 struct {
2035 ULONG Level;
2036 ULONG Vector;
2037 KAFFINITY Affinity;
2038 } Interrupt;
2039 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
2040 struct {
2041 __GNU_EXTENSION union {
2042 struct {
2043 USHORT Reserved;
2044 USHORT MessageCount;
2045 ULONG Vector;
2046 KAFFINITY Affinity;
2047 } Raw;
2048 struct {
2049 ULONG Level;
2050 ULONG Vector;
2051 KAFFINITY Affinity;
2052 } Translated;
2053 };
2054 } MessageInterrupt;
2055 #endif
2056 struct {
2057 PHYSICAL_ADDRESS Start;
2058 ULONG Length;
2059 } Memory;
2060 struct {
2061 ULONG Channel;
2062 ULONG Port;
2063 ULONG Reserved1;
2064 } Dma;
2065 struct {
2066 ULONG Data[3];
2067 } DevicePrivate;
2068 struct {
2069 ULONG Start;
2070 ULONG Length;
2071 ULONG Reserved;
2072 } BusNumber;
2073 struct {
2074 ULONG DataSize;
2075 ULONG Reserved1;
2076 ULONG Reserved2;
2077 } DeviceSpecificData;
2078 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
2079 struct {
2080 PHYSICAL_ADDRESS Start;
2081 ULONG Length40;
2082 } Memory40;
2083 struct {
2084 PHYSICAL_ADDRESS Start;
2085 ULONG Length48;
2086 } Memory48;
2087 struct {
2088 PHYSICAL_ADDRESS Start;
2089 ULONG Length64;
2090 } Memory64;
2091 #endif
2092 } u;
2093 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
2094 #include <poppack.h>
2095
2096 #include <pshpack1.h>
2097 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
2098
2099 #define CmResourceTypeNull 0
2100 #define CmResourceTypePort 1
2101 #define CmResourceTypeInterrupt 2
2102 #define CmResourceTypeMemory 3
2103 #define CmResourceTypeDma 4
2104 #define CmResourceTypeDeviceSpecific 5
2105 #define CmResourceTypeBusNumber 6
2106 #define CmResourceTypeMemoryLarge 7
2107 #define CmResourceTypeNonArbitrated 128
2108 #define CmResourceTypeConfigData 128
2109 #define CmResourceTypeDevicePrivate 129
2110 #define CmResourceTypePcCardConfig 130
2111 #define CmResourceTypeMfCardConfig 131
2112
2113 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
2114
2115 typedef enum _CM_SHARE_DISPOSITION {
2116 CmResourceShareUndetermined,
2117 CmResourceShareDeviceExclusive,
2118 CmResourceShareDriverExclusive,
2119 CmResourceShareShared
2120 } CM_SHARE_DISPOSITION;
2121
2122 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
2123
2124 #define CM_RESOURCE_PORT_MEMORY 0x0000
2125 #define CM_RESOURCE_PORT_IO 0x0001
2126 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
2127 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
2128 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
2129 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
2130 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
2131 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
2132 #define CM_RESOURCE_PORT_BAR 0x0100
2133
2134 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
2135
2136 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
2137 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
2138 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
2139 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
2140
2141 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
2142
2143 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
2144 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
2145 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
2146 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
2147 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
2148 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
2149 #define CM_RESOURCE_MEMORY_24 0x0010
2150 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
2151 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
2152 #define CM_RESOURCE_MEMORY_BAR 0x0080
2153 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
2154
2155 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
2156
2157 #define CM_RESOURCE_DMA_8 0x0000
2158 #define CM_RESOURCE_DMA_16 0x0001
2159 #define CM_RESOURCE_DMA_32 0x0002
2160 #define CM_RESOURCE_DMA_8_AND_16 0x0004
2161 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
2162 #define CM_RESOURCE_DMA_TYPE_A 0x0010
2163 #define CM_RESOURCE_DMA_TYPE_B 0x0020
2164 #define CM_RESOURCE_DMA_TYPE_F 0x0040
2165
2166 typedef struct _CM_PARTIAL_RESOURCE_LIST {
2167 USHORT Version;
2168 USHORT Revision;
2169 ULONG Count;
2170 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
2171 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
2172
2173 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
2174 INTERFACE_TYPE InterfaceType;
2175 ULONG BusNumber;
2176 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
2177 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
2178
2179 typedef struct _CM_RESOURCE_LIST {
2180 ULONG Count;
2181 CM_FULL_RESOURCE_DESCRIPTOR List[1];
2182 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
2183
2184 typedef struct _CM_INT13_DRIVE_PARAMETER {
2185 USHORT DriveSelect;
2186 ULONG MaxCylinders;
2187 USHORT SectorsPerTrack;
2188 USHORT MaxHeads;
2189 USHORT NumberDrives;
2190 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
2191
2192 typedef struct _CM_PNP_BIOS_DEVICE_NODE
2193 {
2194 USHORT Size;
2195 UCHAR Node;
2196 ULONG ProductId;
2197 UCHAR DeviceType[3];
2198 USHORT DeviceAttributes;
2199 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
2200
2201 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
2202 {
2203 UCHAR Signature[4];
2204 UCHAR Revision;
2205 UCHAR Length;
2206 USHORT ControlField;
2207 UCHAR Checksum;
2208 ULONG EventFlagAddress;
2209 USHORT RealModeEntryOffset;
2210 USHORT RealModeEntrySegment;
2211 USHORT ProtectedModeEntryOffset;
2212 ULONG ProtectedModeCodeBaseAddress;
2213 ULONG OemDeviceId;
2214 USHORT RealModeDataBaseAddress;
2215 ULONG ProtectedModeDataBaseAddress;
2216 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
2217
2218 #include <poppack.h>
2219
2220 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
2221 {
2222 ULONG BytesPerSector;
2223 ULONG NumberOfCylinders;
2224 ULONG SectorsPerTrack;
2225 ULONG NumberOfHeads;
2226 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
2227
2228 typedef struct _CM_KEYBOARD_DEVICE_DATA {
2229 USHORT Version;
2230 USHORT Revision;
2231 UCHAR Type;
2232 UCHAR Subtype;
2233 USHORT KeyboardFlags;
2234 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
2235
2236 typedef struct _CM_MCA_POS_DATA {
2237 USHORT AdapterId;
2238 UCHAR PosData1;
2239 UCHAR PosData2;
2240 UCHAR PosData3;
2241 UCHAR PosData4;
2242 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
2243
2244 #if (NTDDI_VERSION >= NTDDI_WINXP)
2245 typedef struct CM_Power_Data_s {
2246 ULONG PD_Size;
2247 DEVICE_POWER_STATE PD_MostRecentPowerState;
2248 ULONG PD_Capabilities;
2249 ULONG PD_D1Latency;
2250 ULONG PD_D2Latency;
2251 ULONG PD_D3Latency;
2252 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
2253 SYSTEM_POWER_STATE PD_DeepestSystemWake;
2254 } CM_POWER_DATA, *PCM_POWER_DATA;
2255
2256 #define PDCAP_D0_SUPPORTED 0x00000001
2257 #define PDCAP_D1_SUPPORTED 0x00000002
2258 #define PDCAP_D2_SUPPORTED 0x00000004
2259 #define PDCAP_D3_SUPPORTED 0x00000008
2260 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
2261 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
2262 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
2263 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
2264 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
2265
2266 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
2267
2268 typedef struct _CM_SCSI_DEVICE_DATA {
2269 USHORT Version;
2270 USHORT Revision;
2271 UCHAR HostIdentifier;
2272 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
2273
2274 typedef struct _CM_SERIAL_DEVICE_DATA {
2275 USHORT Version;
2276 USHORT Revision;
2277 ULONG BaudClock;
2278 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
2279
2280 typedef enum _KEY_INFORMATION_CLASS {
2281 KeyBasicInformation,
2282 KeyNodeInformation,
2283 KeyFullInformation,
2284 KeyNameInformation,
2285 KeyCachedInformation,
2286 KeyFlagsInformation
2287 } KEY_INFORMATION_CLASS;
2288
2289 typedef struct _KEY_BASIC_INFORMATION {
2290 LARGE_INTEGER LastWriteTime;
2291 ULONG TitleIndex;
2292 ULONG NameLength;
2293 WCHAR Name[1];
2294 } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
2295
2296 typedef struct _KEY_FULL_INFORMATION {
2297 LARGE_INTEGER LastWriteTime;
2298 ULONG TitleIndex;
2299 ULONG ClassOffset;
2300 ULONG ClassLength;
2301 ULONG SubKeys;
2302 ULONG MaxNameLen;
2303 ULONG MaxClassLen;
2304 ULONG Values;
2305 ULONG MaxValueNameLen;
2306 ULONG MaxValueDataLen;
2307 WCHAR Class[1];
2308 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
2309
2310 typedef struct _KEY_NODE_INFORMATION {
2311 LARGE_INTEGER LastWriteTime;
2312 ULONG TitleIndex;
2313 ULONG ClassOffset;
2314 ULONG ClassLength;
2315 ULONG NameLength;
2316 WCHAR Name[1];
2317 } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
2318
2319 typedef struct _KEY_VALUE_BASIC_INFORMATION {
2320 ULONG TitleIndex;
2321 ULONG Type;
2322 ULONG NameLength;
2323 WCHAR Name[1];
2324 } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
2325
2326 typedef struct _KEY_VALUE_FULL_INFORMATION {
2327 ULONG TitleIndex;
2328 ULONG Type;
2329 ULONG DataOffset;
2330 ULONG DataLength;
2331 ULONG NameLength;
2332 WCHAR Name[1];
2333 } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
2334
2335 typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
2336 ULONG TitleIndex;
2337 ULONG Type;
2338 ULONG DataLength;
2339 UCHAR Data[1];
2340 } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
2341
2342 typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
2343 ULONG Type;
2344 ULONG DataLength;
2345 UCHAR Data[1];
2346 } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
2347
2348 typedef struct _KEY_VALUE_ENTRY {
2349 PUNICODE_STRING ValueName;
2350 ULONG DataLength;
2351 ULONG DataOffset;
2352 ULONG Type;
2353 } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
2354
2355 typedef enum _KEY_VALUE_INFORMATION_CLASS {
2356 KeyValueBasicInformation,
2357 KeyValueFullInformation,
2358 KeyValuePartialInformation,
2359 KeyValueFullInformationAlign64,
2360 KeyValuePartialInformationAlign64
2361 } KEY_VALUE_INFORMATION_CLASS;
2362
2363 typedef struct _KEY_WRITE_TIME_INFORMATION {
2364 LARGE_INTEGER LastWriteTime;
2365 } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
2366
2367 typedef enum _KEY_SET_INFORMATION_CLASS {
2368 KeyWriteTimeInformation,
2369 KeyWow64FlagsInformation,
2370 KeyControlFlagsInformation,
2371 KeySetVirtualizationInformation,
2372 KeySetDebugInformation,
2373 KeySetHandleTagsInformation,
2374 MaxKeySetInfoClass
2375 } KEY_SET_INFORMATION_CLASS;
2376
2377 typedef enum _REG_NOTIFY_CLASS {
2378 RegNtDeleteKey,
2379 RegNtPreDeleteKey = RegNtDeleteKey,
2380 RegNtSetValueKey,
2381 RegNtPreSetValueKey = RegNtSetValueKey,
2382 RegNtDeleteValueKey,
2383 RegNtPreDeleteValueKey = RegNtDeleteValueKey,
2384 RegNtSetInformationKey,
2385 RegNtPreSetInformationKey = RegNtSetInformationKey,
2386 RegNtRenameKey,
2387 RegNtPreRenameKey = RegNtRenameKey,
2388 RegNtEnumerateKey,
2389 RegNtPreEnumerateKey = RegNtEnumerateKey,
2390 RegNtEnumerateValueKey,
2391 RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
2392 RegNtQueryKey,
2393 RegNtPreQueryKey = RegNtQueryKey,
2394 RegNtQueryValueKey,
2395 RegNtPreQueryValueKey = RegNtQueryValueKey,
2396 RegNtQueryMultipleValueKey,
2397 RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
2398 RegNtPreCreateKey,
2399 RegNtPostCreateKey,
2400 RegNtPreOpenKey,
2401 RegNtPostOpenKey,
2402 RegNtKeyHandleClose,
2403 RegNtPreKeyHandleClose = RegNtKeyHandleClose,
2404 RegNtPostDeleteKey,
2405 RegNtPostSetValueKey,
2406 RegNtPostDeleteValueKey,
2407 RegNtPostSetInformationKey,
2408 RegNtPostRenameKey,
2409 RegNtPostEnumerateKey,
2410 RegNtPostEnumerateValueKey,
2411 RegNtPostQueryKey,
2412 RegNtPostQueryValueKey,
2413 RegNtPostQueryMultipleValueKey,
2414 RegNtPostKeyHandleClose,
2415 RegNtPreCreateKeyEx,
2416 RegNtPostCreateKeyEx,
2417 RegNtPreOpenKeyEx,
2418 RegNtPostOpenKeyEx,
2419 RegNtPreFlushKey,
2420 RegNtPostFlushKey,
2421 RegNtPreLoadKey,
2422 RegNtPostLoadKey,
2423 RegNtPreUnLoadKey,
2424 RegNtPostUnLoadKey,
2425 RegNtPreQueryKeySecurity,
2426 RegNtPostQueryKeySecurity,
2427 RegNtPreSetKeySecurity,
2428 RegNtPostSetKeySecurity,
2429 RegNtCallbackObjectContextCleanup,
2430 RegNtPreRestoreKey,
2431 RegNtPostRestoreKey,
2432 RegNtPreSaveKey,
2433 RegNtPostSaveKey,
2434 RegNtPreReplaceKey,
2435 RegNtPostReplaceKey,
2436 MaxRegNtNotifyClass
2437 } REG_NOTIFY_CLASS, *PREG_NOTIFY_CLASS;
2438
2439 typedef NTSTATUS
2440 (NTAPI *PEX_CALLBACK_FUNCTION)(
2441 IN PVOID CallbackContext,
2442 IN PVOID Argument1,
2443 IN PVOID Argument2
2444 );
2445
2446 typedef struct _REG_DELETE_KEY_INFORMATION {
2447 PVOID Object;
2448 PVOID CallContext;
2449 PVOID ObjectContext;
2450 PVOID Reserved;
2451 } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION
2452 #if (NTDDI_VERSION >= NTDDI_VISTA)
2453 , REG_FLUSH_KEY_INFORMATION, *PREG_FLUSH_KEY_INFORMATION
2454 #endif
2455 ;
2456
2457 typedef struct _REG_SET_VALUE_KEY_INFORMATION {
2458 PVOID Object;
2459 PUNICODE_STRING ValueName;
2460 ULONG TitleIndex;
2461 ULONG Type;
2462 PVOID Data;
2463 ULONG DataSize;
2464 PVOID CallContext;
2465 PVOID ObjectContext;
2466 PVOID Reserved;
2467 } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
2468
2469 typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
2470 PVOID Object;
2471 PUNICODE_STRING ValueName;
2472 PVOID CallContext;
2473 PVOID ObjectContext;
2474 PVOID Reserved;
2475 } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
2476
2477 typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
2478 PVOID Object;
2479 KEY_SET_INFORMATION_CLASS KeySetInformationClass;
2480 PVOID KeySetInformation;
2481 ULONG KeySetInformationLength;
2482 PVOID CallContext;
2483 PVOID ObjectContext;
2484 PVOID Reserved;
2485 } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
2486
2487 typedef struct _REG_ENUMERATE_KEY_INFORMATION {
2488 PVOID Object;
2489 ULONG Index;
2490 KEY_INFORMATION_CLASS KeyInformationClass;
2491 PVOID KeyInformation;
2492 ULONG Length;
2493 PULONG ResultLength;
2494 PVOID CallContext;
2495 PVOID ObjectContext;
2496 PVOID Reserved;
2497 } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
2498
2499 typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
2500 PVOID Object;
2501 ULONG Index;
2502 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
2503 PVOID KeyValueInformation;
2504 ULONG Length;
2505 PULONG ResultLength;
2506 PVOID CallContext;
2507 PVOID ObjectContext;
2508 PVOID Reserved;
2509 } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
2510
2511 typedef struct _REG_QUERY_KEY_INFORMATION {
2512 PVOID Object;
2513 KEY_INFORMATION_CLASS KeyInformationClass;
2514 PVOID KeyInformation;
2515 ULONG Length;
2516 PULONG ResultLength;
2517 PVOID CallContext;
2518 PVOID ObjectContext;
2519 PVOID Reserved;
2520 } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
2521
2522 typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
2523 PVOID Object;
2524 PUNICODE_STRING ValueName;
2525 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
2526 PVOID KeyValueInformation;
2527 ULONG Length;
2528 PULONG ResultLength;
2529 PVOID CallContext;
2530 PVOID ObjectContext;
2531 PVOID Reserved;
2532 } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
2533
2534 typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
2535 PVOID Object;
2536 PKEY_VALUE_ENTRY ValueEntries;
2537 ULONG EntryCount;
2538 PVOID ValueBuffer;
2539 PULONG BufferLength;
2540 PULONG RequiredBufferLength;
2541 PVOID CallContext;
2542 PVOID ObjectContext;
2543 PVOID Reserved;
2544 } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
2545
2546 typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
2547 PUNICODE_STRING CompleteName;
2548 } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
2549
2550 typedef struct _REG_POST_CREATE_KEY_INFORMATION {
2551 PUNICODE_STRING CompleteName;
2552 PVOID Object;
2553 NTSTATUS Status;
2554 } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
2555
2556 typedef struct _REG_POST_OPERATION_INFORMATION {
2557 PVOID Object;
2558 NTSTATUS Status;
2559 PVOID PreInformation;
2560 NTSTATUS ReturnStatus;
2561 PVOID CallContext;
2562 PVOID ObjectContext;
2563 PVOID Reserved;
2564 } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
2565
2566 typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
2567 PVOID Object;
2568 PVOID CallContext;
2569 PVOID ObjectContext;
2570 PVOID Reserved;
2571 } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
2572
2573
2574 /******************************************************************************
2575 * Configuration Manager Functions *
2576 ******************************************************************************/
2577
2578 #if (NTDDI_VERSION >= NTDDI_WINXP)
2579 NTKERNELAPI
2580 NTSTATUS
2581 NTAPI
2582 CmRegisterCallback(
2583 IN PEX_CALLBACK_FUNCTION Function,
2584 IN PVOID Context OPTIONAL,
2585 OUT PLARGE_INTEGER Cookie);
2586
2587 NTKERNELAPI
2588 NTSTATUS
2589 NTAPI
2590 CmUnRegisterCallback(
2591 IN LARGE_INTEGER Cookie);
2592 #endif
2593
2594
2595 /******************************************************************************
2596 * RTL Types *
2597 ******************************************************************************/
2598
2599 #define RTL_REGISTRY_ABSOLUTE 0
2600 #define RTL_REGISTRY_SERVICES 1
2601 #define RTL_REGISTRY_CONTROL 2
2602 #define RTL_REGISTRY_WINDOWS_NT 3
2603 #define RTL_REGISTRY_DEVICEMAP 4
2604 #define RTL_REGISTRY_USER 5
2605 #define RTL_REGISTRY_MAXIMUM 6
2606 #define RTL_REGISTRY_HANDLE 0x40000000
2607 #define RTL_REGISTRY_OPTIONAL 0x80000000
2608
2609 /* RTL_QUERY_REGISTRY_TABLE.Flags */
2610 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
2611 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
2612 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
2613 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
2614 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
2615 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
2616 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
2617
2618 #define HASH_STRING_ALGORITHM_DEFAULT 0
2619 #define HASH_STRING_ALGORITHM_X65599 1
2620 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
2621
2622 typedef struct _RTL_BITMAP {
2623 ULONG SizeOfBitMap;
2624 PULONG Buffer;
2625 } RTL_BITMAP, *PRTL_BITMAP;
2626
2627 typedef struct _RTL_BITMAP_RUN {
2628 ULONG StartingIndex;
2629 ULONG NumberOfBits;
2630 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
2631
2632 typedef NTSTATUS
2633 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
2634 IN PWSTR ValueName,
2635 IN ULONG ValueType,
2636 IN PVOID ValueData,
2637 IN ULONG ValueLength,
2638 IN PVOID Context,
2639 IN PVOID EntryContext);
2640
2641 typedef struct _RTL_QUERY_REGISTRY_TABLE {
2642 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
2643 ULONG Flags;
2644 PCWSTR Name;
2645 PVOID EntryContext;
2646 ULONG DefaultType;
2647 PVOID DefaultData;
2648 ULONG DefaultLength;
2649 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
2650
2651 typedef struct _TIME_FIELDS {
2652 CSHORT Year;
2653 CSHORT Month;
2654 CSHORT Day;
2655 CSHORT Hour;
2656 CSHORT Minute;
2657 CSHORT Second;
2658 CSHORT Milliseconds;
2659 CSHORT Weekday;
2660 } TIME_FIELDS, *PTIME_FIELDS;
2661
2662 /* Slist Header */
2663 #ifndef _SLIST_HEADER_
2664 #define _SLIST_HEADER_
2665
2666 #if defined(_WIN64)
2667 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
2668 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
2669 PSLIST_ENTRY Next;
2670 } SLIST_ENTRY;
2671 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
2672 struct {
2673 ULONGLONG Alignment;
2674 ULONGLONG Region;
2675 } DUMMYSTRUCTNAME;
2676 struct {
2677 ULONGLONG Depth:16;
2678 ULONGLONG Sequence:9;
2679 ULONGLONG NextEntry:39;
2680 ULONGLONG HeaderType:1;
2681 ULONGLONG Init:1;
2682 ULONGLONG Reserved:59;
2683 ULONGLONG Region:3;
2684 } Header8;
2685 struct {
2686 ULONGLONG Depth:16;
2687 ULONGLONG Sequence:48;
2688 ULONGLONG HeaderType:1;
2689 ULONGLONG Init:1;
2690 ULONGLONG Reserved:2;
2691 ULONGLONG NextEntry:60;
2692 } Header16;
2693 } SLIST_HEADER, *PSLIST_HEADER;
2694 #else
2695 #define SLIST_ENTRY SINGLE_LIST_ENTRY
2696 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
2697 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
2698 typedef union _SLIST_HEADER {
2699 ULONGLONG Alignment;
2700 struct {
2701 SLIST_ENTRY Next;
2702 USHORT Depth;
2703 USHORT Sequence;
2704 } DUMMYSTRUCTNAME;
2705 } SLIST_HEADER, *PSLIST_HEADER;
2706 #endif
2707
2708 #endif /* _SLIST_HEADER_ */
2709
2710
2711 /******************************************************************************
2712 * RTL Functions *
2713 ******************************************************************************/
2714
2715 FORCEINLINE
2716 VOID
2717 InitializeListHead(
2718 OUT PLIST_ENTRY ListHead)
2719 {
2720 ListHead->Flink = ListHead->Blink = ListHead;
2721 }
2722
2723 FORCEINLINE
2724 VOID
2725 InsertHeadList(
2726 IN OUT PLIST_ENTRY ListHead,
2727 IN OUT PLIST_ENTRY Entry)
2728 {
2729 PLIST_ENTRY OldFlink;
2730 OldFlink = ListHead->Flink;
2731 Entry->Flink = OldFlink;
2732 Entry->Blink = ListHead;
2733 OldFlink->Blink = Entry;
2734 ListHead->Flink = Entry;
2735 }
2736
2737 FORCEINLINE
2738 VOID
2739 InsertTailList(
2740 IN OUT PLIST_ENTRY ListHead,
2741 IN OUT PLIST_ENTRY Entry)
2742 {
2743 PLIST_ENTRY OldBlink;
2744 OldBlink = ListHead->Blink;
2745 Entry->Flink = ListHead;
2746 Entry->Blink = OldBlink;
2747 OldBlink->Flink = Entry;
2748 ListHead->Blink = Entry;
2749 }
2750
2751 BOOLEAN
2752 FORCEINLINE
2753 IsListEmpty(
2754 IN CONST LIST_ENTRY * ListHead)
2755 {
2756 return (BOOLEAN)(ListHead->Flink == ListHead);
2757 }
2758
2759 FORCEINLINE
2760 PSINGLE_LIST_ENTRY
2761 PopEntryList(
2762 IN OUT PSINGLE_LIST_ENTRY ListHead)
2763 {
2764 PSINGLE_LIST_ENTRY FirstEntry;
2765 FirstEntry = ListHead->Next;
2766 if (FirstEntry != NULL) {
2767 ListHead->Next = FirstEntry->Next;
2768 }
2769 return FirstEntry;
2770 }
2771
2772 FORCEINLINE
2773 VOID
2774 PushEntryList(
2775 IN OUT PSINGLE_LIST_ENTRY ListHead,
2776 IN OUT PSINGLE_LIST_ENTRY Entry)
2777 {
2778 Entry->Next = ListHead->Next;
2779 ListHead->Next = Entry;
2780 }
2781
2782 FORCEINLINE
2783 BOOLEAN
2784 RemoveEntryList(
2785 IN PLIST_ENTRY Entry)
2786 {
2787 PLIST_ENTRY OldFlink;
2788 PLIST_ENTRY OldBlink;
2789
2790 OldFlink = Entry->Flink;
2791 OldBlink = Entry->Blink;
2792 OldFlink->Blink = OldBlink;
2793 OldBlink->Flink = OldFlink;
2794 return (BOOLEAN)(OldFlink == OldBlink);
2795 }
2796
2797 FORCEINLINE
2798 PLIST_ENTRY
2799 RemoveHeadList(
2800 IN OUT PLIST_ENTRY ListHead)
2801 {
2802 PLIST_ENTRY Flink;
2803 PLIST_ENTRY Entry;
2804
2805 Entry = ListHead->Flink;
2806 Flink = Entry->Flink;
2807 ListHead->Flink = Flink;
2808 Flink->Blink = ListHead;
2809 return Entry;
2810 }
2811
2812 FORCEINLINE
2813 PLIST_ENTRY
2814 RemoveTailList(
2815 IN OUT PLIST_ENTRY ListHead)
2816 {
2817 PLIST_ENTRY Blink;
2818 PLIST_ENTRY Entry;
2819
2820 Entry = ListHead->Blink;
2821 Blink = Entry->Blink;
2822 ListHead->Blink = Blink;
2823 Blink->Flink = ListHead;
2824 return Entry;
2825 }
2826
2827 NTSYSAPI
2828 VOID
2829 NTAPI
2830 RtlAssert(
2831 IN PVOID FailedAssertion,
2832 IN PVOID FileName,
2833 IN ULONG LineNumber,
2834 IN PCHAR Message);
2835
2836 /* VOID
2837 * RtlCopyMemory(
2838 * IN VOID UNALIGNED *Destination,
2839 * IN CONST VOID UNALIGNED *Source,
2840 * IN SIZE_T Length)
2841 */
2842 #define RtlCopyMemory(Destination, Source, Length) \
2843 memcpy(Destination, Source, Length)
2844
2845 #define RtlCopyBytes RtlCopyMemory
2846
2847 #if defined(_M_AMD64)
2848 NTSYSAPI
2849 VOID
2850 NTAPI
2851 RtlCopyMemoryNonTemporal(
2852 VOID UNALIGNED *Destination,
2853 CONST VOID UNALIGNED *Source,
2854 SIZE_T Length);
2855 #else
2856 #define RtlCopyMemoryNonTemporal RtlCopyMemory
2857 #endif
2858
2859 /* BOOLEAN
2860 * RtlEqualLuid(
2861 * IN PLUID Luid1,
2862 * IN PLUID Luid2)
2863 */
2864 #define RtlEqualLuid(Luid1, Luid2) \
2865 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
2866
2867 /* ULONG
2868 * RtlEqualMemory(
2869 * IN VOID UNALIGNED *Destination,
2870 * IN CONST VOID UNALIGNED *Source,
2871 * IN SIZE_T Length)
2872 */
2873 #define RtlEqualMemory(Destination, Source, Length) \
2874 (!memcmp(Destination, Source, Length))
2875
2876 /* VOID
2877 * RtlFillMemory(
2878 * IN VOID UNALIGNED *Destination,
2879 * IN SIZE_T Length,
2880 * IN UCHAR Fill)
2881 */
2882 #define RtlFillMemory(Destination, Length, Fill) \
2883 memset(Destination, Fill, Length)
2884
2885 #define RtlFillBytes RtlFillMemory
2886
2887 NTSYSAPI
2888 VOID
2889 NTAPI
2890 RtlFreeUnicodeString(
2891 IN PUNICODE_STRING UnicodeString);
2892
2893 NTSYSAPI
2894 NTSTATUS
2895 NTAPI
2896 RtlGUIDFromString(
2897 IN PUNICODE_STRING GuidString,
2898 OUT GUID *Guid);
2899
2900 NTSYSAPI
2901 VOID
2902 NTAPI
2903 RtlInitUnicodeString(
2904 IN OUT PUNICODE_STRING DestinationString,
2905 IN PCWSTR SourceString);
2906
2907 /* VOID
2908 * RtlMoveMemory(
2909 * IN VOID UNALIGNED *Destination,
2910 * IN CONST VOID UNALIGNED *Source,
2911 * IN SIZE_T Length)
2912 */
2913 #define RtlMoveMemory(Destination, Source, Length) \
2914 memmove(Destination, Source, Length)
2915
2916 NTSYSAPI
2917 NTSTATUS
2918 NTAPI
2919 RtlStringFromGUID(
2920 IN REFGUID Guid,
2921 OUT PUNICODE_STRING GuidString);
2922
2923 /* VOID
2924 * RtlZeroMemory(
2925 * IN VOID UNALIGNED *Destination,
2926 * IN SIZE_T Length)
2927 */
2928 #define RtlZeroMemory(Destination, Length) \
2929 memset(Destination, 0, Length)
2930
2931 #define RtlZeroBytes RtlZeroMemory
2932
2933
2934 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2935 NTSYSAPI
2936 BOOLEAN
2937 NTAPI
2938 RtlAreBitsClear(
2939 IN PRTL_BITMAP BitMapHeader,
2940 IN ULONG StartingIndex,
2941 IN ULONG Length);
2942
2943 NTSYSAPI
2944 BOOLEAN
2945 NTAPI
2946 RtlAreBitsSet(
2947 IN PRTL_BITMAP BitMapHeader,
2948 IN ULONG StartingIndex,
2949 IN ULONG Length);
2950
2951 NTSYSAPI
2952 NTSTATUS
2953 NTAPI
2954 RtlAnsiStringToUnicodeString(
2955 IN OUT PUNICODE_STRING DestinationString,
2956 IN PANSI_STRING SourceString,
2957 IN BOOLEAN AllocateDestinationString);
2958
2959 NTSYSAPI
2960 ULONG
2961 NTAPI
2962 RtlxAnsiStringToUnicodeSize(
2963 IN PCANSI_STRING AnsiString);
2964
2965 #define RtlAnsiStringToUnicodeSize(String) ( \
2966 NLS_MB_CODE_PAGE_TAG ? \
2967 RtlxAnsiStringToUnicodeSize(String) : \
2968 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
2969 )
2970
2971 NTSYSAPI
2972 NTSTATUS
2973 NTAPI
2974 RtlAppendUnicodeStringToString(
2975 IN OUT PUNICODE_STRING Destination,
2976 IN PCUNICODE_STRING Source);
2977
2978 NTSYSAPI
2979 NTSTATUS
2980 NTAPI
2981 RtlAppendUnicodeToString(
2982 IN OUT PUNICODE_STRING Destination,
2983 IN PCWSTR Source);
2984
2985 NTSYSAPI
2986 NTSTATUS
2987 NTAPI
2988 RtlCheckRegistryKey(
2989 IN ULONG RelativeTo,
2990 IN PWSTR Path);
2991
2992 NTSYSAPI
2993 VOID
2994 NTAPI
2995 RtlClearAllBits(
2996 IN PRTL_BITMAP BitMapHeader);
2997
2998 NTSYSAPI
2999 VOID
3000 NTAPI
3001 RtlClearBits(
3002 IN PRTL_BITMAP BitMapHeader,
3003 IN ULONG StartingIndex,
3004 IN ULONG NumberToClear);
3005
3006 NTSYSAPI
3007 SIZE_T
3008 NTAPI
3009 RtlCompareMemory(
3010 IN CONST VOID *Source1,
3011 IN CONST VOID *Source2,
3012 IN SIZE_T Length);
3013
3014 NTSYSAPI
3015 LONG
3016 NTAPI
3017 RtlCompareUnicodeString(
3018 IN PCUNICODE_STRING String1,
3019 IN PCUNICODE_STRING String2,
3020 IN BOOLEAN CaseInSensitive);
3021
3022 NTSYSAPI
3023 LONG
3024 NTAPI
3025 RtlCompareUnicodeStrings(
3026 IN PCWCH String1,
3027 IN SIZE_T String1Length,
3028 IN PCWCH String2,
3029 IN SIZE_T String2Length,
3030 IN BOOLEAN CaseInSensitive);
3031
3032 NTSYSAPI
3033 VOID
3034 NTAPI
3035 RtlCopyUnicodeString(
3036 IN OUT PUNICODE_STRING DestinationString,
3037 IN PCUNICODE_STRING SourceString);
3038
3039 NTSYSAPI
3040 NTSTATUS
3041 NTAPI
3042 RtlCreateRegistryKey(
3043 IN ULONG RelativeTo,
3044 IN PWSTR Path);
3045
3046 NTSYSAPI
3047 NTSTATUS
3048 NTAPI
3049 RtlCreateSecurityDescriptor(
3050 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3051 IN ULONG Revision);
3052
3053 NTSYSAPI
3054 NTSTATUS
3055 NTAPI
3056 RtlDeleteRegistryValue(
3057 IN ULONG RelativeTo,
3058 IN PCWSTR Path,
3059 IN PCWSTR ValueName);
3060
3061 NTSYSAPI
3062 BOOLEAN
3063 NTAPI
3064 RtlEqualUnicodeString(
3065 IN CONST UNICODE_STRING *String1,
3066 IN CONST UNICODE_STRING *String2,
3067 IN BOOLEAN CaseInSensitive);
3068
3069 #if !defined(_AMD64_) && !defined(_IA64_)
3070 NTSYSAPI
3071 LARGE_INTEGER
3072 NTAPI
3073 RtlExtendedIntegerMultiply(
3074 IN LARGE_INTEGER Multiplicand,
3075 IN LONG Multiplier);
3076
3077 NTSYSAPI
3078 LARGE_INTEGER
3079 NTAPI
3080 RtlExtendedLargeIntegerDivide(
3081 IN LARGE_INTEGER Dividend,
3082 IN ULONG Divisor,
3083 IN OUT PULONG Remainder);
3084 #endif
3085
3086 #if defined(_X86_) || defined(_IA64_)
3087 NTSYSAPI
3088 LARGE_INTEGER
3089 NTAPI
3090 RtlExtendedMagicDivide(
3091 IN LARGE_INTEGER Dividend,
3092 IN LARGE_INTEGER MagicDivisor,
3093 IN CCHAR ShiftCount);
3094 #endif
3095
3096 NTSYSAPI
3097 VOID
3098 NTAPI
3099 RtlFreeAnsiString(
3100 IN PANSI_STRING AnsiString);
3101
3102 NTSYSAPI
3103 ULONG
3104 NTAPI
3105 RtlFindClearBits(
3106 IN PRTL_BITMAP BitMapHeader,
3107 IN ULONG NumberToFind,
3108 IN ULONG HintIndex);
3109
3110 NTSYSAPI
3111 ULONG
3112 NTAPI
3113 RtlFindClearBitsAndSet(
3114 IN PRTL_BITMAP BitMapHeader,
3115 IN ULONG NumberToFind,
3116 IN ULONG HintIndex);
3117
3118 NTSYSAPI
3119 ULONG
3120 NTAPI
3121 RtlFindFirstRunClear(
3122 IN PRTL_BITMAP BitMapHeader,
3123 OUT PULONG StartingIndex);
3124
3125 NTSYSAPI
3126 ULONG
3127 NTAPI
3128 RtlFindClearRuns(
3129 IN PRTL_BITMAP BitMapHeader,
3130 OUT PRTL_BITMAP_RUN RunArray,
3131 IN ULONG SizeOfRunArray,
3132 IN BOOLEAN LocateLongestRuns);
3133
3134 NTSYSAPI
3135 ULONG
3136 NTAPI
3137 RtlFindLastBackwardRunClear(
3138 IN PRTL_BITMAP BitMapHeader,
3139 IN ULONG FromIndex,
3140 OUT PULONG StartingRunIndex);
3141
3142 NTSYSAPI
3143 CCHAR
3144 NTAPI
3145 RtlFindLeastSignificantBit(
3146 IN ULONGLONG Set);
3147
3148 NTSYSAPI
3149 ULONG
3150 NTAPI
3151 RtlFindLongestRunClear(
3152 IN PRTL_BITMAP BitMapHeader,
3153 OUT PULONG StartingIndex);
3154
3155 NTSYSAPI
3156 CCHAR
3157 NTAPI
3158 RtlFindMostSignificantBit(
3159 IN ULONGLONG Set);
3160
3161 NTSYSAPI
3162 ULONG
3163 NTAPI
3164 RtlFindNextForwardRunClear(
3165 IN PRTL_BITMAP BitMapHeader,
3166 IN ULONG FromIndex,
3167 OUT PULONG StartingRunIndex);
3168
3169 NTSYSAPI
3170 ULONG
3171 NTAPI
3172 RtlFindSetBits(
3173 IN PRTL_BITMAP BitMapHeader,
3174 IN ULONG NumberToFind,
3175 IN ULONG HintIndex);
3176
3177 NTSYSAPI
3178 ULONG
3179 NTAPI
3180 RtlFindSetBitsAndClear(
3181 IN PRTL_BITMAP BitMapHeader,
3182 IN ULONG NumberToFind,
3183 IN ULONG HintIndex);
3184
3185 NTSYSAPI
3186 NTSTATUS
3187 NTAPI
3188 RtlHashUnicodeString(
3189 IN CONST UNICODE_STRING *String,
3190 IN BOOLEAN CaseInSensitive,
3191 IN ULONG HashAlgorithm,
3192 OUT PULONG HashValue);
3193
3194 NTSYSAPI
3195 VOID
3196 NTAPI
3197 RtlInitAnsiString(
3198 IN OUT PANSI_STRING DestinationString,
3199 IN PCSZ SourceString);
3200
3201 NTSYSAPI
3202 VOID
3203 NTAPI
3204 RtlInitializeBitMap(
3205 IN PRTL_BITMAP BitMapHeader,
3206 IN PULONG BitMapBuffer,
3207 IN ULONG SizeOfBitMap);
3208
3209 NTSYSAPI
3210 VOID
3211 NTAPI
3212 RtlInitString(
3213 IN OUT PSTRING DestinationString,
3214 IN PCSZ SourceString);
3215
3216 NTSYSAPI
3217 NTSTATUS
3218 NTAPI
3219 RtlIntegerToUnicodeString(
3220 IN ULONG Value,
3221 IN ULONG Base OPTIONAL,
3222 IN OUT PUNICODE_STRING String);
3223
3224 NTSYSAPI
3225 NTSTATUS
3226 NTAPI
3227 RtlInt64ToUnicodeString(
3228 IN ULONGLONG Value,
3229 IN ULONG Base OPTIONAL,
3230 IN OUT PUNICODE_STRING String);
3231
3232 #ifdef _WIN64
3233 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3234 RtlInt64ToUnicodeString(Value, Base, String)
3235 #else
3236 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3237 RtlIntegerToUnicodeString(Value, Base, String)
3238 #endif
3239
3240 /* BOOLEAN
3241 * RtlIsZeroLuid(
3242 * IN PLUID L1);
3243 */
3244 #define RtlIsZeroLuid(_L1) \
3245 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
3246
3247 NTSYSAPI
3248 ULONG
3249 NTAPI
3250 RtlLengthSecurityDescriptor(
3251 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3252
3253 NTSYSAPI
3254 ULONG
3255 NTAPI
3256 RtlNumberOfClearBits(
3257 IN PRTL_BITMAP BitMapHeader);
3258
3259 NTSYSAPI
3260 ULONG
3261 NTAPI
3262 RtlNumberOfSetBits(
3263 IN PRTL_BITMAP BitMapHeader);
3264
3265 NTSYSAPI
3266 NTSTATUS
3267 NTAPI
3268 RtlQueryRegistryValues(
3269 IN ULONG RelativeTo,
3270 IN PCWSTR Path,
3271 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
3272 IN PVOID Context,
3273 IN PVOID Environment OPTIONAL);
3274
3275 #define LONG_SIZE (sizeof(LONG))
3276 #define LONG_MASK (LONG_SIZE - 1)
3277
3278 /* VOID
3279 * RtlRetrieveUlong(
3280 * PULONG DestinationAddress,
3281 * PULONG SourceAddress);
3282 */
3283 #if defined(_AMD64_)
3284 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3285 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
3286 #else
3287 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3288 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3289 { \
3290 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3291 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3292 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
3293 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
3294 } \
3295 else \
3296 { \
3297 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
3298 }
3299 #endif
3300
3301 /* VOID
3302 * RtlRetrieveUshort(
3303 * PUSHORT DestinationAddress,
3304 * PUSHORT SourceAddress);
3305 */
3306 #if defined(_AMD64_)
3307 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3308 *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
3309 #else
3310 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3311 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3312 { \
3313 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3314 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3315 } \
3316 else \
3317 { \
3318 *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
3319 }
3320 #endif
3321
3322 NTSYSAPI
3323 VOID
3324 NTAPI
3325 RtlSetAllBits(
3326 IN PRTL_BITMAP BitMapHeader);
3327
3328 NTSYSAPI
3329 VOID
3330 NTAPI
3331 RtlSetBits(
3332 IN PRTL_BITMAP BitMapHeader,
3333 IN ULONG StartingIndex,
3334 IN ULONG NumberToSet);
3335
3336 NTSYSAPI
3337 NTSTATUS
3338 NTAPI
3339 RtlSetDaclSecurityDescriptor(
3340 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3341 IN BOOLEAN DaclPresent,
3342 IN PACL Dacl OPTIONAL,
3343 IN BOOLEAN DaclDefaulted OPTIONAL);
3344
3345 /* VOID
3346 * RtlStoreUlong(
3347 * IN PULONG Address,
3348 * IN ULONG Value);
3349 */
3350 #if defined(_AMD64_)
3351 #define RtlStoreUlong(Address,Value) \
3352 *(ULONG UNALIGNED *)(Address) = (Value)
3353 #else
3354 #define RtlStoreUlong(Address,Value) \
3355 if ((ULONG_PTR)(Address) & LONG_MASK) { \
3356 ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3357 ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
3358 ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
3359 ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT] = (UCHAR)(FOURTHBYTE(Value)); \
3360 } \
3361 else { \
3362 *((PULONG)(Address)) = (ULONG) (Value); \
3363 }
3364 #endif
3365
3366 /* VOID
3367 * RtlStoreUlonglong(
3368 * IN OUT PULONGLONG Address,
3369 * ULONGLONG Value);
3370 */
3371 #if defined(_AMD64_)
3372 #define RtlStoreUlonglong(Address,Value) \
3373 *(ULONGLONG UNALIGNED *)(Address) = (Value)
3374 #else
3375 #define RtlStoreUlonglong(Address,Value) \
3376 if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
3377 RtlStoreUlong((ULONG_PTR)(Address), \
3378 (ULONGLONG)(Value) & 0xFFFFFFFF); \
3379 RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
3380 (ULONGLONG)(Value) >> 32); \
3381 } else { \
3382 *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
3383 }
3384 #endif
3385
3386 /* VOID
3387 * RtlStoreUlongPtr(
3388 * IN OUT PULONG_PTR Address,
3389 * IN ULONG_PTR Value);
3390 */
3391 #ifdef _WIN64
3392 #define RtlStoreUlongPtr(Address,Value) \
3393 RtlStoreUlonglong(Address,Value)
3394 #else
3395 #define RtlStoreUlongPtr(Address,Value) \
3396 RtlStoreUlong(Address,Value)
3397 #endif
3398
3399 /* VOID
3400 * RtlStoreUshort(
3401 * IN PUSHORT Address,
3402 * IN USHORT Value);
3403 */
3404 #if defined(_AMD64_)
3405 #define RtlStoreUshort(Address,Value) \
3406 *(USHORT UNALIGNED *)(Address) = (Value)
3407 #else
3408 #define RtlStoreUshort(Address,Value) \
3409 if ((ULONG_PTR)(Address) & SHORT_MASK) { \
3410 ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3411 ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
3412 } \
3413 else { \
3414 *((PUSHORT) (Address)) = (USHORT)Value; \
3415 }
3416 #endif
3417
3418 NTSYSAPI
3419 BOOLEAN
3420 NTAPI
3421 RtlTimeFieldsToTime(
3422 IN PTIME_FIELDS TimeFields,
3423 IN PLARGE_INTEGER Time);
3424
3425 NTSYSAPI
3426 VOID
3427 NTAPI
3428 RtlTimeToTimeFields(
3429 IN PLARGE_INTEGER Time,
3430 IN PTIME_FIELDS TimeFields);
3431
3432 NTSYSAPI
3433 ULONG
3434 FASTCALL
3435 RtlUlongByteSwap(
3436 IN ULONG Source);
3437
3438 NTSYSAPI
3439 ULONGLONG
3440 FASTCALL
3441 RtlUlonglongByteSwap(
3442 IN ULONGLONG Source);
3443
3444 NTSYSAPI
3445 NTSTATUS
3446 NTAPI
3447 RtlUnicodeStringToAnsiString(
3448 IN OUT PANSI_STRING DestinationString,
3449 IN PCUNICODE_STRING SourceString,
3450 IN BOOLEAN AllocateDestinationString);
3451
3452 NTSYSAPI
3453 ULONG
3454 NTAPI
3455 RtlxUnicodeStringToAnsiSize(
3456 IN PCUNICODE_STRING UnicodeString);
3457
3458 #define RtlUnicodeStringToAnsiSize(String) ( \
3459 NLS_MB_CODE_PAGE_TAG ? \
3460 RtlxUnicodeStringToAnsiSize(String) : \
3461 ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
3462 )
3463
3464 NTSYSAPI
3465 NTSTATUS
3466 NTAPI
3467 RtlUnicodeStringToInteger(
3468 IN PCUNICODE_STRING String,
3469 IN ULONG Base OPTIONAL,
3470 OUT PULONG Value);
3471
3472 NTSYSAPI
3473 WCHAR
3474 NTAPI
3475 RtlUpcaseUnicodeChar(
3476 IN WCHAR SourceCharacter);
3477
3478 NTSYSAPI
3479 USHORT
3480 FASTCALL
3481 RtlUshortByteSwap(
3482 IN USHORT Source);
3483
3484 NTSYSAPI
3485 BOOLEAN
3486 NTAPI
3487 RtlValidRelativeSecurityDescriptor(
3488 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
3489 IN ULONG SecurityDescriptorLength,
3490 IN SECURITY_INFORMATION RequiredInformation);
3491
3492 NTSYSAPI
3493 BOOLEAN
3494 NTAPI
3495 RtlValidSecurityDescriptor(
3496 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3497
3498 NTSYSAPI
3499 NTSTATUS
3500 NTAPI
3501 RtlWriteRegistryValue(
3502 IN ULONG RelativeTo,
3503 IN PCWSTR Path,
3504 IN PCWSTR ValueName,
3505 IN ULONG ValueType,
3506 IN PVOID ValueData,
3507 IN ULONG ValueLength);
3508
3509 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
3510
3511 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
3512 NTSYSAPI
3513 VOID
3514 FASTCALL
3515 RtlPrefetchMemoryNonTemporal(
3516 IN PVOID Source,
3517 IN SIZE_T Length);
3518 #endif
3519
3520 #if (NTDDI_VERSION >= NTDDI_WINXP)
3521 NTSYSAPI
3522 VOID
3523 NTAPI
3524 RtlClearBit(
3525 PRTL_BITMAP BitMapHeader,
3526 ULONG BitNumber);
3527
3528 NTSYSAPI
3529 WCHAR
3530 NTAPI
3531 RtlDowncaseUnicodeChar(
3532 IN WCHAR SourceCharacter);
3533
3534 NTSYSAPI
3535 VOID
3536 NTAPI
3537 RtlSetBit(
3538 PRTL_BITMAP BitMapHeader,
3539 ULONG BitNumber);
3540
3541 NTSYSAPI
3542 BOOLEAN
3543 NTAPI
3544 RtlTestBit(
3545 IN PRTL_BITMAP BitMapHeader,
3546 IN ULONG BitNumber);
3547
3548 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
3549
3550 #if (NTDDI_VERSION >= NTDDI_VISTA)
3551 NTSYSAPI
3552 ULONG
3553 NTAPI
3554 RtlNumberOfSetBitsUlongPtr(
3555 IN ULONG_PTR Target);
3556
3557 NTSYSAPI
3558 ULONGLONG
3559 NTAPI
3560 RtlIoDecodeMemIoResource (
3561 IN struct _IO_RESOURCE_DESCRIPTOR *Descriptor,
3562 OUT PULONGLONG Alignment OPTIONAL,
3563 OUT PULONGLONG MinimumAddress OPTIONAL,
3564 OUT PULONGLONG MaximumAddress OPTIONAL);
3565
3566 NTSYSAPI
3567 NTSTATUS
3568 NTAPI
3569 RtlIoEncodeMemIoResource(
3570 IN struct _IO_RESOURCE_DESCRIPTOR *Descriptor,
3571 IN UCHAR Type,
3572 IN ULONGLONG Length,
3573 IN ULONGLONG Alignment,
3574 IN ULONGLONG MinimumAddress,
3575 IN ULONGLONG MaximumAddress);
3576
3577 NTSYSAPI
3578 ULONGLONG
3579 NTAPI
3580 RtlCmDecodeMemIoResource(
3581 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
3582 OUT PULONGLONG Start OPTIONAL);
3583
3584 NTSYSAPI
3585 NTSTATUS
3586 NTAPI
3587 RtlFindClosestEncodableLength(
3588 IN ULONGLONG SourceLength,
3589 OUT PULONGLONG TargetLength);
3590
3591 #endif
3592
3593 #if !defined(MIDL_PASS)
3594 /* inline funftions */
3595 //DECLSPEC_DEPRECATED_DDK_WINXP
3596 static __inline
3597 LARGE_INTEGER
3598 NTAPI_INLINE
3599 RtlConvertLongToLargeInteger(LONG SignedInteger)
3600 {
3601 LARGE_INTEGER ret;
3602 ret.QuadPart = SignedInteger;
3603 return ret;
3604 }
3605
3606 //DECLSPEC_DEPRECATED_DDK_WINXP
3607 static __inline
3608 LARGE_INTEGER
3609 NTAPI_INLINE
3610 RtlConvertUlongToLargeInteger(
3611 ULONG UnsignedInteger)
3612 {
3613 LARGE_INTEGER ret;
3614 ret.QuadPart = UnsignedInteger;
3615 return ret;
3616 }
3617
3618 //DECLSPEC_DEPRECATED_DDK
3619 static __inline
3620 ULONG
3621 NTAPI_INLINE
3622 RtlEnlargedUnsignedDivide(
3623 IN ULARGE_INTEGER Dividend,
3624 IN ULONG Divisor,
3625 IN OUT PULONG Remainder)
3626 {
3627 if (Remainder)
3628 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3629 return (ULONG)(Dividend.QuadPart / Divisor);
3630 }
3631
3632 //DECLSPEC_DEPRECATED_DDK
3633 static __inline
3634 LARGE_INTEGER
3635 NTAPI_INLINE
3636 RtlEnlargedUnsignedMultiply(
3637 IN ULONG Multiplicand,
3638 IN ULONG Multiplier)
3639 {
3640 LARGE_INTEGER ret;
3641 ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3642 return ret;
3643 }
3644
3645 //DECLSPEC_DEPRECATED_DDK
3646 static __inline
3647 LARGE_INTEGER
3648 NTAPI_INLINE
3649 RtlEnlargedIntegerMultiply(
3650 IN LONG Multiplicand,
3651 IN LONG Multiplier)
3652 {
3653 LARGE_INTEGER ret;
3654 ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3655 return ret;
3656 }
3657
3658 FORCEINLINE
3659 VOID
3660 RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
3661 IN PCHAR Buffer,
3662 IN USHORT BufferSize)
3663 {
3664 AnsiString->Length = 0;
3665 AnsiString->MaximumLength = BufferSize;
3666 AnsiString->Buffer = Buffer;
3667 }
3668
3669 FORCEINLINE
3670 VOID
3671 RtlInitEmptyUnicodeString(
3672 OUT PUNICODE_STRING UnicodeString,
3673 IN PWSTR Buffer,
3674 IN USHORT BufferSize)
3675 {
3676 UnicodeString->Length = 0;
3677 UnicodeString->MaximumLength = BufferSize;
3678 UnicodeString->Buffer = Buffer;
3679 }
3680
3681 #if defined(_AMD64_) || defined(_IA64_)
3682 static __inline
3683 LARGE_INTEGER
3684 NTAPI_INLINE
3685 RtlExtendedIntegerMultiply(
3686 LARGE_INTEGER Multiplicand,
3687 LONG Multiplier)
3688 {
3689 LARGE_INTEGER ret;
3690 ret.QuadPart = Multiplicand.QuadPart * Multiplier;
3691 return ret;
3692 }
3693
3694 static __inline
3695 LARGE_INTEGER
3696 NTAPI_INLINE
3697 RtlExtendedLargeIntegerDivide(
3698 LARGE_INTEGER Dividend,
3699 ULONG Divisor,
3700 PULONG Remainder)
3701 {
3702 LARGE_INTEGER ret;
3703 ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
3704 if (Remainder)
3705 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3706 return ret;
3707 }
3708 #endif
3709
3710 #if defined(_AMD64_)
3711
3712 #define MultiplyHigh __mulh
3713 #define UnsignedMultiplyHigh __umulh
3714
3715 //DECLSPEC_DEPRECATED_DDK
3716 static __inline
3717 LARGE_INTEGER
3718 NTAPI_INLINE
3719 RtlExtendedMagicDivide(
3720 IN LARGE_INTEGER Dividend,
3721 IN LARGE_INTEGER MagicDivisor,
3722 IN CCHAR ShiftCount)
3723 {
3724 LARGE_INTEGER ret;
3725 ULONG64 ret64;
3726 BOOLEAN Pos;
3727 Pos = (Dividend.QuadPart >= 0);
3728 ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
3729 MagicDivisor.QuadPart);
3730 ret64 >>= ShiftCount;
3731 ret.QuadPart = Pos ? ret64 : -ret64;
3732 return ret;
3733 }
3734 #endif
3735
3736 //DECLSPEC_DEPRECATED_DDK
3737 static __inline
3738 LARGE_INTEGER
3739 NTAPI_INLINE
3740 RtlLargeIntegerAdd(
3741 IN LARGE_INTEGER Addend1,
3742 IN LARGE_INTEGER Addend2)
3743 {
3744 LARGE_INTEGER ret;
3745 ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
3746 return ret;
3747 }
3748
3749 /* VOID
3750 * RtlLargeIntegerAnd(
3751 * IN OUT LARGE_INTEGER Result,
3752 * IN LARGE_INTEGER Source,
3753 * IN LARGE_INTEGER Mask);
3754 */
3755 #define RtlLargeIntegerAnd(Result, Source, Mask) \
3756 Result.QuadPart = Source.QuadPart & Mask.QuadPart
3757
3758 //DECLSPEC_DEPRECATED_DDK
3759 static __inline
3760 LARGE_INTEGER
3761 NTAPI_INLINE
3762 RtlLargeIntegerArithmeticShift(
3763 IN LARGE_INTEGER LargeInteger,
3764 IN CCHAR ShiftCount)
3765 {
3766 LARGE_INTEGER ret;
3767 ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
3768 return ret;
3769 }
3770
3771 /* BOOLEAN
3772 * RtlLargeIntegerEqualTo(
3773 * IN LARGE_INTEGER Operand1,
3774 * IN LARGE_INTEGER Operand2);
3775 */
3776 #define RtlLargeIntegerEqualTo(X,Y) \
3777 (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
3778
3779 FORCEINLINE
3780 PVOID
3781 RtlSecureZeroMemory(
3782 OUT PVOID Pointer,
3783 IN SIZE_T Size)
3784 {
3785 volatile char* vptr = (volatile char*)Pointer;
3786 #if defined(_M_AMD64)
3787 __stosb((PUCHAR)vptr, 0, Size);
3788 #else
3789 char * endptr = (char *)vptr + Size;
3790 while (vptr < endptr)
3791 {
3792 *vptr = 0; vptr++;
3793 }
3794 #endif
3795 return Pointer;
3796 }
3797
3798 #if defined(_M_AMD64)
3799 FORCEINLINE
3800 ULONG
3801 RtlCheckBit(
3802 IN PRTL_BITMAP BitMapHeader,
3803 IN ULONG BitPosition)
3804 {
3805 return BitTest((LONG CONST*)BitMapHeader->Buffer, BitPosition);
3806 }
3807 #else
3808 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
3809 #endif // defined(_M_AMD64)
3810
3811 #endif // !defined(MIDL_PASS)
3812
3813 /* Byte Swap Functions */
3814 #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037 || defined(__GNUC__))) || \
3815 ((defined(_M_AMD64) || defined(_M_IA64)) \
3816 && (_MSC_FULL_VER > 13009175 || defined(__GNUC__)))
3817
3818 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
3819 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
3820 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
3821
3822 #endif
3823
3824 #if DBG
3825
3826 #define ASSERT(exp) \
3827 (VOID)((!(exp)) ? \
3828 RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, NULL ), FALSE : TRUE)
3829
3830 #define ASSERTMSG(msg, exp) \
3831 (VOID)((!(exp)) ? \
3832 RtlAssert( (PVOID)#exp, (PVOID)__FILE__, __LINE__, msg ), FALSE : TRUE)
3833
3834 #define RTL_SOFT_ASSERT(exp) \
3835 (VOID)((!(exp)) ? \
3836 DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #exp), FALSE : TRUE)
3837
3838 #define RTL_SOFT_ASSERTMSG(msg, exp) \
3839 (VOID)((!(exp)) ? \
3840 DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #exp, (msg)), FALSE : TRUE)
3841
3842 #define RTL_VERIFY(exp) ASSERT(exp)
3843 #define RTL_VERIFYMSG(msg, exp) ASSERTMSG(msg, exp)
3844
3845 #define RTL_SOFT_VERIFY(exp) RTL_SOFT_ASSERT(exp)
3846 #define RTL_SOFT_VERIFYMSG(msg, exp) RTL_SOFT_ASSERTMSG(msg, exp)
3847
3848 #if defined(_MSC_VER)
3849
3850 #define NT_ASSERT(exp) \
3851 ((!(exp)) ? \
3852 (__annotation(L"Debug", L"AssertFail", L#exp), \
3853 DbgRaiseAssertionFailure(), FALSE) : TRUE)
3854
3855 #define NT_ASSERTMSG(msg, exp) \
3856 ((!(exp)) ? \
3857 (__annotation(L"Debug", L"AssertFail", L##msg), \
3858 DbgRaiseAssertionFailure(), FALSE) : TRUE)
3859
3860 #define NT_ASSERTMSGW(msg, exp) \
3861 ((!(exp)) ? \
3862 (__annotation(L"Debug", L"AssertFail", msg), \
3863 DbgRaiseAssertionFailure(), FALSE) : TRUE)
3864
3865 #else
3866
3867 /* GCC doesn't support __annotation (nor PDB) */
3868 #define NT_ASSERT(exp) \
3869 (VOID)((!(exp)) ? (DbgRaiseAssertionFailure(), FALSE) : TRUE)
3870
3871 #define NT_ASSERTMSG NT_ASSERT
3872 #define NT_ASSERTMSGW NT_ASSERT
3873
3874 #endif
3875
3876 #else /* !DBG */
3877
3878 #define ASSERT(exp) ((VOID) 0)
3879 #define ASSERTMSG(msg, exp) ((VOID) 0)
3880
3881 #define RTL_SOFT_ASSERT(exp) ((VOID) 0)
3882 #define RTL_SOFT_ASSERTMSG(msg, exp) ((VOID) 0)
3883
3884 #define RTL_VERIFY(exp) ((exp) ? TRUE : FALSE)
3885 #define RTL_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE)
3886
3887 #define RTL_SOFT_VERIFY(exp) ((exp) ? TRUE : FALSE)
3888 #define RTL_SOFT_VERIFYMSG(msg, exp) ((exp) ? TRUE : FALSE)
3889
3890 #define NT_ASSERT(exp) ((VOID)0)
3891 #define NT_ASSERTMSG(exp) ((VOID)0)
3892 #define NT_ASSERTMSGW(exp) ((VOID)0)
3893
3894 #endif /* DBG */
3895
3896
3897
3898 /******************************************************************************
3899 * I/O Manager Types *
3900 ******************************************************************************/
3901
3902 /* PCI_COMMON_CONFIG.Command */
3903 #define PCI_ENABLE_IO_SPACE 0x0001
3904 #define PCI_ENABLE_MEMORY_SPACE 0x0002
3905 #define PCI_ENABLE_BUS_MASTER 0x0004
3906 #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
3907 #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
3908 #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
3909 #define PCI_ENABLE_PARITY 0x0040
3910 #define PCI_ENABLE_WAIT_CYCLE 0x0080
3911 #define PCI_ENABLE_SERR 0x0100
3912 #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200
3913 #define PCI_DISABLE_LEVEL_INTERRUPT 0x0400
3914
3915 /* PCI_COMMON_CONFIG.Status */
3916 #define PCI_STATUS_INTERRUPT_PENDING 0x0008
3917 #define PCI_STATUS_CAPABILITIES_LIST 0x0010
3918 #define PCI_STATUS_66MHZ_CAPABLE 0x0020
3919 #define PCI_STATUS_UDF_SUPPORTED 0x0040
3920 #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080
3921 #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
3922 #define PCI_STATUS_DEVSEL 0x0600
3923 #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
3924 #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
3925 #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
3926 #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
3927 #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
3928
3929 /* PCI_COMMON_CONFIG.HeaderType */
3930 #define PCI_MULTIFUNCTION 0x80
3931 #define PCI_DEVICE_TYPE 0x00
3932 #define PCI_BRIDGE_TYPE 0x01
3933 #define PCI_CARDBUS_BRIDGE_TYPE 0x02
3934
3935 #define PCI_CONFIGURATION_TYPE(PciData) \
3936 (((PPCI_COMMON_CONFIG) (PciData))->HeaderType & ~PCI_MULTIFUNCTION)
3937
3938 #define PCI_MULTIFUNCTION_DEVICE(PciData) \
3939 ((((PPCI_COMMON_CONFIG) (PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
3940
3941 /* PCI device classes */
3942 #define PCI_CLASS_PRE_20 0x00
3943 #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
3944 #define PCI_CLASS_NETWORK_CTLR 0x02
3945 #define PCI_CLASS_DISPLAY_CTLR 0x03
3946 #define PCI_CLASS_MULTIMEDIA_DEV 0x04
3947 #define PCI_CLASS_MEMORY_CTLR 0x05
3948 #define PCI_CLASS_BRIDGE_DEV 0x06
3949 #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
3950 #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
3951 #define PCI_CLASS_INPUT_DEV 0x09
3952 #define PCI_CLASS_DOCKING_STATION 0x0a
3953 #define PCI_CLASS_PROCESSOR 0x0b
3954 #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
3955 #define PCI_CLASS_WIRELESS_CTLR 0x0d
3956 #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
3957 #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
3958 #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
3959 #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
3960
3961 /* PCI device subclasses for class 0 */
3962 #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
3963 #define PCI_SUBCLASS_PRE_20_VGA 0x01
3964
3965 /* PCI device subclasses for class 1 (mass storage controllers)*/
3966 #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
3967 #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
3968 #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
3969 #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
3970 #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
3971 #define PCI_SUBCLASS_MSC_OTHER 0x80
3972
3973 /* PCI device subclasses for class 2 (network controllers)*/
3974 #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
3975 #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
3976 #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
3977 #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
3978 #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
3979 #define PCI_SUBCLASS_NET_OTHER 0x80
3980
3981 /* PCI device subclasses for class 3 (display controllers)*/
3982 #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
3983 #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
3984 #define PCI_SUBCLASS_VID_3D_CTLR 0x02
3985 #define PCI_SUBCLASS_VID_OTHER 0x80
3986
3987 /* PCI device subclasses for class 4 (multimedia device)*/
3988 #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
3989 #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
3990 #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
3991 #define PCI_SUBCLASS_MM_OTHER 0x80
3992
3993 /* PCI device subclasses for class 5 (memory controller)*/
3994 #define PCI_SUBCLASS_MEM_RAM 0x00
3995 #define PCI_SUBCLASS_MEM_FLASH 0x01
3996 #define PCI_SUBCLASS_MEM_OTHER 0x80
3997
3998 /* PCI device subclasses for class 6 (bridge device)*/
3999 #define PCI_SUBCLASS_BR_HOST 0x00
4000 #define PCI_SUBCLASS_BR_ISA 0x01
4001 #define PCI_SUBCLASS_BR_EISA 0x02
4002 #define PCI_SUBCLASS_BR_MCA 0x03
4003 #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
4004 #define PCI_SUBCLASS_BR_PCMCIA 0x05
4005 #define PCI_SUBCLASS_BR_NUBUS 0x06
4006 #define PCI_SUBCLASS_BR_CARDBUS 0x07
4007 #define PCI_SUBCLASS_BR_RACEWAY 0x08
4008 #define PCI_SUBCLASS_BR_OTHER 0x80
4009
4010 /* PCI device subclasses for class C (serial bus controller)*/
4011 #define PCI_SUBCLASS_SB_IEEE1394 0x00
4012 #define PCI_SUBCLASS_SB_ACCESS 0x01
4013 #define PCI_SUBCLASS_SB_SSA 0x02
4014 #define PCI_SUBCLASS_SB_USB 0x03
4015 #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
4016 #define PCI_SUBCLASS_SB_SMBUS 0x05
4017
4018 #define PCI_MAX_DEVICES 32
4019 #define PCI_MAX_FUNCTION 8
4020 #define PCI_MAX_BRIDGE_NUMBER 0xFF
4021 #define PCI_INVALID_VENDORID 0xFFFF
4022 #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET(PCI_COMMON_CONFIG, DeviceSpecific))
4023
4024 #define PCI_ADDRESS_IO_SPACE 0x00000001
4025 #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006
4026 #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008
4027 #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
4028 #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
4029 #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
4030
4031 #define PCI_TYPE_32BIT 0
4032 #define PCI_TYPE_20BIT 2
4033 #define PCI_TYPE_64BIT 4
4034
4035 #define POOL_COLD_ALLOCATION 256