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