- globally disable warnings for char array subscripts
[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 NTAPI
1044 KeQueryActiveProcessors(
1045 VOID);
1046 #endif
1047
1048 #if !defined(_M_AMD64)
1049 NTKERNELAPI
1050 ULONGLONG
1051 NTAPI
1052 KeQueryInterruptTime(
1053 VOID);
1054
1055 NTKERNELAPI
1056 VOID
1057 NTAPI
1058 KeQuerySystemTime(
1059 OUT PLARGE_INTEGER CurrentTime);
1060 #endif /* !_M_AMD64 */
1061
1062 NTKERNELAPI
1063 DECLSPEC_NORETURN
1064 VOID
1065 NTAPI
1066 KeBugCheckEx(
1067 IN ULONG BugCheckCode,
1068 IN ULONG_PTR BugCheckParameter1,
1069 IN ULONG_PTR BugCheckParameter2,
1070 IN ULONG_PTR BugCheckParameter3,
1071 IN ULONG_PTR BugCheckParameter4);
1072
1073 NTKERNELAPI
1074 BOOLEAN
1075 NTAPI
1076 KeCancelTimer(
1077 IN OUT PKTIMER);
1078
1079 NTKERNELAPI
1080 NTSTATUS
1081 NTAPI
1082 KeDelayExecutionThread(
1083 IN KPROCESSOR_MODE WaitMode,
1084 IN BOOLEAN Alertable,
1085 IN PLARGE_INTEGER Interval);
1086
1087 NTKERNELAPI
1088 BOOLEAN
1089 NTAPI
1090 KeDeregisterBugCheckCallback(
1091 IN OUT PKBUGCHECK_CALLBACK_RECORD CallbackRecord);
1092
1093 NTKERNELAPI
1094 VOID
1095 NTAPI
1096 KeEnterCriticalRegion(VOID);
1097
1098 NTKERNELAPI
1099 VOID
1100 NTAPI
1101 KeInitializeDeviceQueue(
1102 OUT PKDEVICE_QUEUE DeviceQueue);
1103
1104 NTKERNELAPI
1105 VOID
1106 NTAPI
1107 KeInitializeMutex(
1108 OUT PRKMUTEX Mutex,
1109 IN ULONG Level);
1110
1111 NTKERNELAPI
1112 VOID
1113 NTAPI
1114 KeInitializeSemaphore(
1115 OUT PRKSEMAPHORE Semaphore,
1116 IN LONG Count,
1117 IN LONG Limit);
1118
1119 NTKERNELAPI
1120 VOID
1121 NTAPI
1122 KeInitializeTimer(
1123 OUT PKTIMER Timer);
1124
1125 NTKERNELAPI
1126 VOID
1127 NTAPI
1128 KeInitializeTimerEx(
1129 OUT PKTIMER Timer,
1130 IN TIMER_TYPE Type);
1131
1132 NTKERNELAPI
1133 BOOLEAN
1134 NTAPI
1135 KeInsertByKeyDeviceQueue(
1136 IN OUT PKDEVICE_QUEUE DeviceQueue,
1137 IN OUT PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
1138 IN ULONG SortKey);
1139
1140 NTKERNELAPI
1141 BOOLEAN
1142 NTAPI
1143 KeInsertDeviceQueue(
1144 IN OUT PKDEVICE_QUEUE DeviceQueue,
1145 IN OUT PKDEVICE_QUEUE_ENTRY DeviceQueueEntry);
1146
1147 NTKERNELAPI
1148 BOOLEAN
1149 NTAPI
1150 KeInsertQueueDpc(
1151 IN OUT PRKDPC Dpc,
1152 IN PVOID SystemArgument1 OPTIONAL,
1153 IN PVOID SystemArgument2 OPTIONAL);
1154
1155 NTKERNELAPI
1156 VOID
1157 NTAPI
1158 KeLeaveCriticalRegion(VOID);
1159
1160 NTHALAPI
1161 LARGE_INTEGER
1162 NTAPI
1163 KeQueryPerformanceCounter(
1164 OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL);
1165
1166 NTKERNELAPI
1167 KPRIORITY
1168 NTAPI
1169 KeQueryPriorityThread(
1170 IN PRKTHREAD Thread);
1171
1172 NTKERNELAPI
1173 ULONG
1174 NTAPI
1175 KeQueryTimeIncrement(
1176 VOID);
1177
1178 NTKERNELAPI
1179 LONG
1180 NTAPI
1181 KeReadStateEvent(
1182 IN PRKEVENT Event);
1183
1184 NTKERNELAPI
1185 LONG
1186 NTAPI
1187 KeReadStateMutex(
1188 IN PRKMUTEX Mutex);
1189
1190
1191 NTKERNELAPI
1192 LONG
1193 NTAPI
1194 KeReadStateSemaphore(
1195 IN PRKSEMAPHORE Semaphore);
1196
1197 NTKERNELAPI
1198 BOOLEAN
1199 NTAPI
1200 KeReadStateTimer(
1201 IN PKTIMER Timer);
1202
1203 NTKERNELAPI
1204 BOOLEAN
1205 NTAPI
1206 KeRegisterBugCheckCallback(
1207 OUT PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
1208 IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
1209 IN PVOID Buffer,
1210 IN ULONG Length,
1211 IN PUCHAR Component);
1212
1213 NTKERNELAPI
1214 LONG
1215 NTAPI
1216 KeReleaseMutex(
1217 IN OUT PRKMUTEX Mutex,
1218 IN BOOLEAN Wait);
1219
1220 NTKERNELAPI
1221 LONG
1222 NTAPI
1223 KeReleaseSemaphore(
1224 IN OUT PRKSEMAPHORE Semaphore,
1225 IN KPRIORITY Increment,
1226 IN LONG Adjustment,
1227 IN BOOLEAN Wait);
1228
1229 NTKERNELAPI
1230 PKDEVICE_QUEUE_ENTRY
1231 NTAPI
1232 KeRemoveByKeyDeviceQueue(
1233 IN OUT PKDEVICE_QUEUE DeviceQueue,
1234 IN ULONG SortKey);
1235
1236 NTKERNELAPI
1237 PKDEVICE_QUEUE_ENTRY
1238 NTAPI
1239 KeRemoveDeviceQueue(
1240 IN OUT PKDEVICE_QUEUE DeviceQueue);
1241
1242 NTKERNELAPI
1243 BOOLEAN
1244 NTAPI
1245 KeRemoveEntryDeviceQueue(
1246 IN OUT PKDEVICE_QUEUE DeviceQueue,
1247 IN OUT PKDEVICE_QUEUE_ENTRY DeviceQueueEntry);
1248
1249 NTKERNELAPI
1250 BOOLEAN
1251 NTAPI
1252 KeRemoveQueueDpc(
1253 IN OUT PRKDPC Dpc);
1254
1255 NTKERNELAPI
1256 LONG
1257 NTAPI
1258 KeResetEvent(
1259 IN OUT PRKEVENT Event);
1260
1261 NTKERNELAPI
1262 LONG
1263 NTAPI
1264 KeSetEvent(
1265 IN OUT PRKEVENT Event,
1266 IN KPRIORITY Increment,
1267 IN BOOLEAN Wait);
1268
1269 NTKERNELAPI
1270 VOID
1271 NTAPI
1272 KeSetImportanceDpc(
1273 IN OUT PRKDPC Dpc,
1274 IN KDPC_IMPORTANCE Importance);
1275
1276 NTKERNELAPI
1277 KPRIORITY
1278 NTAPI
1279 KeSetPriorityThread(
1280 IN OUT PKTHREAD Thread,
1281 IN KPRIORITY Priority);
1282
1283 NTKERNELAPI
1284 BOOLEAN
1285 NTAPI
1286 KeSetTimer(
1287 IN OUT PKTIMER Timer,
1288 IN LARGE_INTEGER DueTime,
1289 IN PKDPC Dpc OPTIONAL);
1290
1291 NTKERNELAPI
1292 BOOLEAN
1293 NTAPI
1294 KeSetTimerEx(
1295 IN OUT PKTIMER Timer,
1296 IN LARGE_INTEGER DueTime,
1297 IN LONG Period OPTIONAL,
1298 IN PKDPC Dpc OPTIONAL);
1299
1300 NTHALAPI
1301 VOID
1302 NTAPI
1303 KeStallExecutionProcessor(
1304 IN ULONG MicroSeconds);
1305
1306 NTKERNELAPI
1307 BOOLEAN
1308 NTAPI
1309 KeSynchronizeExecution(
1310 IN OUT PKINTERRUPT Interrupt,
1311 IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
1312 IN PVOID SynchronizeContext OPTIONAL);
1313
1314 NTKERNELAPI
1315 NTSTATUS
1316 NTAPI
1317 KeWaitForMultipleObjects(
1318 IN ULONG Count,
1319 IN PVOID Object[],
1320 IN WAIT_TYPE WaitType,
1321 IN KWAIT_REASON WaitReason,
1322 IN KPROCESSOR_MODE WaitMode,
1323 IN BOOLEAN Alertable,
1324 IN PLARGE_INTEGER Timeout OPTIONAL,
1325 OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL);
1326
1327 #define KeWaitForMutexObject KeWaitForSingleObject
1328
1329 NTKERNELAPI
1330 NTSTATUS
1331 NTAPI
1332 KeWaitForSingleObject(
1333 IN PVOID Object,
1334 IN KWAIT_REASON WaitReason,
1335 IN KPROCESSOR_MODE WaitMode,
1336 IN BOOLEAN Alertable,
1337 IN PLARGE_INTEGER Timeout OPTIONAL);
1338
1339 #endif
1340
1341 #if (NTDDI_VERSION >= NTDDI_WINXP)
1342
1343 // _DECL_HAL_KE_IMPORT
1344 VOID
1345 FASTCALL
1346 KeAcquireInStackQueuedSpinLock (
1347 IN OUT PKSPIN_LOCK SpinLock,
1348 OUT PKLOCK_QUEUE_HANDLE LockHandle);
1349
1350 NTKERNELAPI
1351 VOID
1352 FASTCALL
1353 KeAcquireInStackQueuedSpinLockAtDpcLevel(
1354 IN OUT PKSPIN_LOCK SpinLock,
1355 OUT PKLOCK_QUEUE_HANDLE LockHandle);
1356
1357 NTKERNELAPI
1358 KIRQL
1359 NTAPI
1360 KeAcquireInterruptSpinLock(
1361 IN OUT PKINTERRUPT Interrupt);
1362
1363 NTKERNELAPI
1364 BOOLEAN
1365 NTAPI
1366 KeAreApcsDisabled(VOID);
1367
1368 NTKERNELAPI
1369 ULONG
1370 NTAPI
1371 KeGetRecommendedSharedDataAlignment(VOID);
1372
1373 NTKERNELAPI
1374 ULONG
1375 NTAPI
1376 KeQueryRuntimeThread(
1377 IN PKTHREAD Thread,
1378 OUT PULONG UserTime);
1379
1380 NTKERNELAPI
1381 VOID
1382 FASTCALL
1383 KeReleaseInStackQueuedSpinLockFromDpcLevel(
1384 IN PKLOCK_QUEUE_HANDLE LockHandle);
1385
1386 NTKERNELAPI
1387 VOID
1388 NTAPI
1389 KeReleaseInterruptSpinLock(
1390 IN OUT PKINTERRUPT Interrupt,
1391 IN KIRQL OldIrql);
1392
1393 #endif
1394
1395 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
1396
1397 NTKERNELAPI
1398 VOID
1399 NTAPI
1400 KeFlushQueuedDpcs(
1401 VOID);
1402
1403 #endif
1404
1405 #if (NTDDI_VERSION >= NTDDI_WS03)
1406
1407 NTKERNELAPI
1408 PVOID
1409 NTAPI
1410 KeRegisterNmiCallback(
1411 IN PNMI_CALLBACK CallbackRoutine,
1412 IN PVOID Context OPTIONAL);
1413
1414 NTKERNELAPI
1415 NTSTATUS
1416 NTAPI
1417 KeDeregisterNmiCallback(
1418 IN PVOID Handle
1419 );
1420
1421 NTKERNELAPI
1422 ULONG_PTR
1423 NTAPI
1424 KeIpiGenericCall(
1425 IN PKIPI_BROADCAST_WORKER BroadcastFunction,
1426 IN ULONG_PTR Context
1427 );
1428
1429 #endif
1430
1431 #if defined(_X86_)
1432 NTKERNELAPI
1433 NTSTATUS
1434 NTAPI
1435 KeSaveFloatingPointState(
1436 OUT PKFLOATING_SAVE FloatSave);
1437
1438 NTKERNELAPI
1439 NTSTATUS
1440 NTAPI
1441 KeRestoreFloatingPointState(
1442 IN PKFLOATING_SAVE FloatSave);
1443 #endif
1444
1445 #if defined(_IA64_)
1446 FORCEINLINE
1447 VOID
1448 KeFlushWriteBuffer(VOID)
1449 {
1450 __mf ();
1451 return;
1452 }
1453 #else
1454 NTHALAPI
1455 VOID
1456 NTAPI
1457 KeFlushWriteBuffer(VOID);
1458 #endif
1459
1460 /*
1461 * VOID
1462 * KeFlushIoBuffers(
1463 * IN PMDL Mdl,
1464 * IN BOOLEAN ReadOperation,
1465 * IN BOOLEAN DmaOperation)
1466 */
1467 #define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
1468
1469 #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
1470 #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
1471 #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
1472 #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
1473
1474
1475 /* SPINLOCK FUNCTIONS */
1476
1477 #if (NTDDI_VERSION >= NTDDI_WINXP)
1478 //_DECL_HAL_KE_IMPORT
1479 VOID
1480 FASTCALL
1481 KeAcquireInStackQueuedSpinLock(
1482 IN OUT PKSPIN_LOCK SpinLock,
1483 OUT PKLOCK_QUEUE_HANDLE LockHandle);
1484
1485 //_DECL_HAL_KE_IMPORT
1486 VOID
1487 FASTCALL
1488 KeReleaseInStackQueuedSpinLock(
1489 IN PKLOCK_QUEUE_HANDLE LockHandle);
1490
1491 #endif
1492
1493 /* FIXME : #if (NTDDI_VERSION >= NTDDI_WS03SP1) */
1494 NTKERNELAPI
1495 BOOLEAN
1496 FASTCALL
1497 KeTryToAcquireSpinLockAtDpcLevel(
1498 IN OUT PKSPIN_LOCK SpinLock
1499 );
1500 /* #endif (NTDDI_VERSION >= NTDDI_WS03SP1) */
1501
1502 #if (NTDDI_VERSION >= NTDDI_WS03)
1503 NTKERNELAPI
1504 BOOLEAN
1505 FASTCALL
1506 KeTestSpinLock(
1507 IN PKSPIN_LOCK SpinLock
1508 );
1509 #endif
1510
1511 /* FIXME : #if (NTDDI_VERSION >= NTDDI_WS03SP1) */
1512 NTKERNELAPI
1513 BOOLEAN
1514 NTAPI
1515 KeAreAllApcsDisabled(
1516 VOID);
1517 /* #endif (NTDDI_VERSION >= NTDDI_WS03SP1) */
1518
1519 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
1520
1521 /* Guarded Mutex routines */
1522
1523 NTKERNELAPI
1524 VOID
1525 FASTCALL
1526 KeAcquireGuardedMutex(
1527 IN OUT PKGUARDED_MUTEX GuardedMutex
1528 );
1529
1530 NTKERNELAPI
1531 VOID
1532 FASTCALL
1533 KeAcquireGuardedMutexUnsafe(
1534 IN OUT PKGUARDED_MUTEX GuardedMutex
1535 );
1536
1537 NTKERNELAPI
1538 VOID
1539 KeEnterGuardedRegion(
1540 VOID
1541 );
1542
1543 NTKERNELAPI
1544 VOID
1545 NTAPI
1546 KeLeaveGuardedRegion(
1547 VOID
1548 );
1549
1550 NTKERNELAPI
1551 VOID
1552 FASTCALL
1553 KeInitializeGuardedMutex(
1554 OUT PKGUARDED_MUTEX GuardedMutex
1555 );
1556
1557 NTKERNELAPI
1558 VOID
1559 FASTCALL
1560 KeReleaseGuardedMutexUnsafe(
1561 IN OUT PKGUARDED_MUTEX GuardedMutex
1562 );
1563
1564 NTKERNELAPI
1565 VOID
1566 FASTCALL
1567 KeReleaseGuardedMutex(
1568 IN OUT PKGUARDED_MUTEX GuardedMutex
1569 );
1570
1571 NTKERNELAPI
1572 BOOLEAN
1573 FASTCALL
1574 KeTryToAcquireGuardedMutex(
1575 IN OUT PKGUARDED_MUTEX GuardedMutex
1576 );
1577
1578 #endif
1579
1580 NTHALAPI
1581 KIRQL
1582 NTAPI
1583 KeGetCurrentIrql(
1584 VOID);
1585
1586 #if defined(_M_AMD64)
1587
1588 ULONG64
1589 __readgsqword (
1590 IN ULONG Offset);
1591
1592 #pragma intrinsic(__readgsqword)
1593
1594 FORCEINLINE
1595 PKTHREAD
1596 KeGetCurrentThread (
1597 VOID)
1598 {
1599 return (struct _KTHREAD *)__readgsqword(0x188);
1600 }
1601
1602 #endif
1603
1604 #if defined(_M_IX86) || defined(_M_IA64)
1605 NTSYSAPI
1606 PKTHREAD
1607 NTAPI
1608 KeGetCurrentThread(
1609 VOID);
1610 #endif
1611
1612 /*
1613 * VOID
1614 * KeInitializeCallbackRecord(
1615 * IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord)
1616 */
1617 #define KeInitializeCallbackRecord(CallbackRecord) \
1618 CallbackRecord->State = BufferEmpty;
1619
1620 #if DBG
1621
1622 #if (NTDDI_VERSION >= NTDDI_VISTA)
1623 #define PAGED_ASSERT( exp ) NT_ASSERT( exp )
1624 #else
1625 #define PAGED_ASSERT( exp ) ASSERT( exp )
1626 #endif
1627
1628 #define PAGED_CODE() { \
1629 if (KeGetCurrentIrql() > APC_LEVEL) { \
1630 KdPrint( ("NTDDK: Pageable code called at IRQL > APC_LEVEL (%d)\n", KeGetCurrentIrql() )); \
1631 PAGED_ASSERT(FALSE); \
1632 } \
1633 }
1634
1635 #else
1636
1637 #define PAGED_CODE()
1638
1639 #endif
1640
1641 #if defined(_NTDDK_) || defined(_NTIFS_)
1642
1643 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1644
1645 NTKERNELAPI
1646 VOID
1647 NTAPI
1648 ProbeForRead(
1649 IN CONST VOID *Address,
1650 IN SIZE_T Length,
1651 IN ULONG Alignment);
1652
1653 #endif
1654
1655 #endif
1656
1657 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1658
1659 NTKERNELAPI
1660 VOID
1661 NTAPI
1662 ProbeForWrite(
1663 IN PVOID Address,
1664 IN SIZE_T Length,
1665 IN ULONG Alignment);
1666
1667 #endif
1668
1669 #if defined(_X86_) || defined(_AMD64_)
1670
1671 /* x86 and x64 performs a 0x2C interrupt */
1672 #define DbgRaiseAssertionFailure __int2c
1673
1674 #elif defined(_ARM_)
1675
1676 //
1677 // TODO
1678 //
1679
1680 #else
1681 #error Unsupported Architecture
1682 #endif
1683
1684
1685 /******************************************************************************
1686 * Memory manager Types *
1687 ******************************************************************************/
1688
1689 #define PAGE_SIZE 0x1000
1690 #define PAGE_SHIFT 12L
1691
1692 #define MM_DONT_ZERO_ALLOCATION 0x00000001
1693 #define MM_ALLOCATE_FROM_LOCAL_NODE_ONLY 0x00000002
1694 #define MM_ALLOCATE_FULLY_REQUIRED 0x00000004
1695 #define MM_ALLOCATE_NO_WAIT 0x00000008
1696 #define MM_ALLOCATE_PREFER_CONTIGUOUS 0x00000010
1697 #define MM_ALLOCATE_REQUIRE_CONTIGUOUS_CHUNKS 0x00000020
1698
1699 #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
1700 #define MDL_PAGES_LOCKED 0x0002
1701 #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
1702 #define MDL_ALLOCATED_FIXED_SIZE 0x0008
1703 #define MDL_PARTIAL 0x0010
1704 #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
1705 #define MDL_IO_PAGE_READ 0x0040
1706 #define MDL_WRITE_OPERATION 0x0080
1707 #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
1708 #define MDL_FREE_EXTRA_PTES 0x0200
1709 #define MDL_DESCRIBES_AWE 0x0400
1710 #define MDL_IO_SPACE 0x0800
1711 #define MDL_NETWORK_HEADER 0x1000
1712 #define MDL_MAPPING_CAN_FAIL 0x2000
1713 #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
1714 #define MDL_INTERNAL 0x8000
1715
1716 #define MDL_MAPPING_FLAGS ( \
1717 MDL_MAPPED_TO_SYSTEM_VA | \
1718 MDL_PAGES_LOCKED | \
1719 MDL_SOURCE_IS_NONPAGED_POOL | \
1720 MDL_PARTIAL_HAS_BEEN_MAPPED | \
1721 MDL_PARENT_MAPPED_SYSTEM_VA | \
1722 MDL_SYSTEM_VA | \
1723 MDL_IO_SPACE)
1724
1725 #define FLUSH_MULTIPLE_MAXIMUM 32
1726
1727 /* Section access rights */
1728 #define SECTION_QUERY 0x0001
1729 #define SECTION_MAP_WRITE 0x0002
1730 #define SECTION_MAP_READ 0x0004
1731 #define SECTION_MAP_EXECUTE 0x0008
1732 #define SECTION_EXTEND_SIZE 0x0010
1733 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
1734
1735 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
1736 SECTION_MAP_WRITE | \
1737 SECTION_MAP_READ | \
1738 SECTION_MAP_EXECUTE | \
1739 SECTION_EXTEND_SIZE)
1740
1741 #define SESSION_QUERY_ACCESS 0x0001
1742 #define SESSION_MODIFY_ACCESS 0x0002
1743
1744 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
1745 SESSION_QUERY_ACCESS | \
1746 SESSION_MODIFY_ACCESS)
1747
1748 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
1749
1750 #define PAGE_NOACCESS 0x01
1751 #define PAGE_READONLY 0x02
1752 #define PAGE_READWRITE 0x04
1753 #define PAGE_WRITECOPY 0x08
1754 #define PAGE_EXECUTE 0x10
1755 #define PAGE_EXECUTE_READ 0x20
1756 #define PAGE_EXECUTE_READWRITE 0x40
1757 #define PAGE_EXECUTE_WRITECOPY 0x80
1758 #define PAGE_GUARD 0x100
1759 #define PAGE_NOCACHE 0x200
1760 #define PAGE_WRITECOMBINE 0x400
1761
1762 #define MEM_COMMIT 0x1000
1763 #define MEM_RESERVE 0x2000
1764 #define MEM_DECOMMIT 0x4000
1765 #define MEM_RELEASE 0x8000
1766 #define MEM_FREE 0x10000
1767 #define MEM_PRIVATE 0x20000
1768 #define MEM_MAPPED 0x40000
1769 #define MEM_RESET 0x80000
1770 #define MEM_TOP_DOWN 0x100000
1771 #define MEM_LARGE_PAGES 0x20000000
1772 #define MEM_4MB_PAGES 0x80000000
1773
1774 #define SEC_RESERVE 0x4000000
1775 #define SEC_COMMIT 0x8000000
1776 #define SEC_LARGE_PAGES 0x80000000
1777
1778 /* Section map options */
1779 typedef enum _SECTION_INHERIT {
1780 ViewShare = 1,
1781 ViewUnmap = 2
1782 } SECTION_INHERIT;
1783
1784 typedef ULONG PFN_COUNT;
1785 typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
1786 typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
1787
1788 typedef struct _MDL {
1789 struct _MDL *Next;
1790 CSHORT Size;
1791 CSHORT MdlFlags;
1792 struct _EPROCESS *Process;
1793 PVOID MappedSystemVa;
1794 PVOID StartVa;
1795 ULONG ByteCount;
1796 ULONG ByteOffset;
1797 } MDL, *PMDL;
1798 typedef MDL *PMDLX;
1799
1800 typedef enum _MEMORY_CACHING_TYPE_ORIG {
1801 MmFrameBufferCached = 2
1802 } MEMORY_CACHING_TYPE_ORIG;
1803
1804 typedef enum _MEMORY_CACHING_TYPE {
1805 MmNonCached = FALSE,
1806 MmCached = TRUE,
1807 MmWriteCombined = MmFrameBufferCached,
1808 MmHardwareCoherentCached,
1809 MmNonCachedUnordered,
1810 MmUSWCCached,
1811 MmMaximumCacheType
1812 } MEMORY_CACHING_TYPE;
1813
1814 typedef enum _MM_PAGE_PRIORITY {
1815 LowPagePriority,
1816 NormalPagePriority = 16,
1817 HighPagePriority = 32
1818 } MM_PAGE_PRIORITY;
1819
1820 typedef enum _LOCK_OPERATION {
1821 IoReadAccess,
1822 IoWriteAccess,
1823 IoModifyAccess
1824 } LOCK_OPERATION;
1825
1826 typedef enum _MM_SYSTEM_SIZE {
1827 MmSmallSystem,
1828 MmMediumSystem,
1829 MmLargeSystem
1830 } MM_SYSTEMSIZE;
1831
1832
1833 /******************************************************************************
1834 * Memory manager Functions *
1835 ******************************************************************************/
1836
1837 /*
1838 * Alignment Macros
1839 */
1840 #define ALIGN_DOWN(s, t) \
1841 ((ULONG)(s) & ~(sizeof(t) - 1))
1842
1843 #define ALIGN_UP(s, t) \
1844 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
1845
1846 #define ALIGN_DOWN_POINTER(p, t) \
1847 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
1848
1849 #define ALIGN_UP_POINTER(p, t) \
1850 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
1851
1852 /* ULONG
1853 * BYTE_OFFSET(
1854 * IN PVOID Va)
1855 */
1856 #define BYTE_OFFSET(Va) \
1857 ((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
1858
1859 /* ULONG
1860 * BYTES_TO_PAGES(
1861 * IN ULONG Size)
1862 */
1863 #define BYTES_TO_PAGES(Size) \
1864 (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
1865
1866 /* PVOID
1867 * PAGE_ALIGN(
1868 * IN PVOID Va)
1869 */
1870 #define PAGE_ALIGN(Va) \
1871 ((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
1872
1873 /* ULONG_PTR
1874 * ROUND_TO_PAGES(
1875 * IN ULONG_PTR Size)
1876 */
1877 #define ROUND_TO_PAGES(Size) \
1878 (((ULONG_PTR) (Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
1879
1880 /*
1881 * ULONG
1882 * MmGetMdlByteCount(
1883 * IN PMDL Mdl)
1884 */
1885 #define MmGetMdlByteCount(_Mdl) \
1886 ((_Mdl)->ByteCount)
1887
1888 /*
1889 * ULONG
1890 * MmGetMdlByteOffset(
1891 * IN PMDL Mdl)
1892 */
1893 #define MmGetMdlByteOffset(_Mdl) \
1894 ((_Mdl)->ByteOffset)
1895
1896 /*
1897 * PPFN_NUMBER
1898 * MmGetMdlPfnArray(
1899 * IN PMDL Mdl)
1900 */
1901 #define MmGetMdlPfnArray(_Mdl) \
1902 ((PPFN_NUMBER) ((_Mdl) + 1))
1903
1904 /*
1905 * PVOID
1906 * MmGetMdlVirtualAddress(
1907 * IN PMDL Mdl)
1908 */
1909 #define MmGetMdlVirtualAddress(_Mdl) \
1910 ((PVOID) ((PCHAR) ((_Mdl)->StartVa) + (_Mdl)->ByteOffset))
1911
1912 #define MmGetProcedureAddress(Address) (Address)
1913
1914 /* PVOID MmGetSystemAddressForMdl(
1915 * IN PMDL Mdl);
1916 */
1917 #define MmGetSystemAddressForMdl(Mdl) \
1918 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
1919 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1920 ((Mdl)->MappedSystemVa) : \
1921 (MmMapLockedPages((Mdl), KernelMode)))
1922
1923 /* PVOID
1924 * MmGetSystemAddressForMdlSafe(
1925 * IN PMDL Mdl,
1926 * IN MM_PAGE_PRIORITY Priority)
1927 */
1928 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
1929 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
1930 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1931 (_Mdl)->MappedSystemVa : \
1932 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
1933 KernelMode, MmCached, NULL, FALSE, (_Priority)))
1934
1935 /*
1936 * VOID
1937 * MmInitializeMdl(
1938 * IN PMDL MemoryDescriptorList,
1939 * IN PVOID BaseVa,
1940 * IN SIZE_T Length)
1941 */
1942 #define MmInitializeMdl(_MemoryDescriptorList, \
1943 _BaseVa, \
1944 _Length) \
1945 { \
1946 (_MemoryDescriptorList)->Next = (PMDL) NULL; \
1947 (_MemoryDescriptorList)->Size = (CSHORT) (sizeof(MDL) + \
1948 (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES(_BaseVa, _Length))); \
1949 (_MemoryDescriptorList)->MdlFlags = 0; \
1950 (_MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN(_BaseVa); \
1951 (_MemoryDescriptorList)->ByteOffset = BYTE_OFFSET(_BaseVa); \
1952 (_MemoryDescriptorList)->ByteCount = (ULONG) _Length; \
1953 }
1954
1955 /*
1956 * VOID
1957 * MmPrepareMdlForReuse(
1958 * IN PMDL Mdl)
1959 */
1960 #define MmPrepareMdlForReuse(_Mdl) \
1961 { \
1962 if (((_Mdl)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
1963 ASSERT(((_Mdl)->MdlFlags & MDL_PARTIAL) != 0); \
1964 MmUnmapLockedPages((_Mdl)->MappedSystemVa, (_Mdl)); \
1965 } else if (((_Mdl)->MdlFlags & MDL_PARTIAL) == 0) { \
1966 ASSERT(((_Mdl)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
1967 } \
1968 }
1969
1970 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1971
1972 NTKERNELAPI
1973 PVOID
1974 NTAPI
1975 MmAllocateContiguousMemory(
1976 IN SIZE_T NumberOfBytes,
1977 IN PHYSICAL_ADDRESS HighestAcceptableAddress);
1978
1979 NTKERNELAPI
1980 PVOID
1981 NTAPI
1982 MmAllocateContiguousMemorySpecifyCache(
1983 IN SIZE_T NumberOfBytes,
1984 IN PHYSICAL_ADDRESS LowestAcceptableAddress,
1985 IN PHYSICAL_ADDRESS HighestAcceptableAddress,
1986 IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
1987 IN MEMORY_CACHING_TYPE CacheType);
1988
1989 NTKERNELAPI
1990 PMDL
1991 NTAPI
1992 MmAllocatePagesForMdl(
1993 IN PHYSICAL_ADDRESS LowAddress,
1994 IN PHYSICAL_ADDRESS HighAddress,
1995 IN PHYSICAL_ADDRESS SkipBytes,
1996 IN SIZE_T TotalBytes);
1997
1998 NTKERNELAPI
1999 VOID
2000 NTAPI
2001 MmBuildMdlForNonPagedPool(
2002 IN OUT PMDLX MemoryDescriptorList);
2003
2004 //DECLSPEC_DEPRECATED_DDK
2005 NTKERNELAPI
2006 PMDL
2007 NTAPI
2008 MmCreateMdl(
2009 IN PMDL MemoryDescriptorList OPTIONAL,
2010 IN PVOID Base,
2011 IN SIZE_T Length);
2012
2013 NTKERNELAPI
2014 VOID
2015 NTAPI
2016 MmFreeContiguousMemory(
2017 IN PVOID BaseAddress);
2018
2019 NTKERNELAPI
2020 VOID
2021 NTAPI
2022 MmFreeContiguousMemorySpecifyCache(
2023 IN PVOID BaseAddress,
2024 IN SIZE_T NumberOfBytes,
2025 IN MEMORY_CACHING_TYPE CacheType);
2026
2027 NTKERNELAPI
2028 VOID
2029 NTAPI
2030 MmFreePagesFromMdl(
2031 IN PMDL MemoryDescriptorList);
2032
2033 NTKERNELAPI
2034 PVOID
2035 NTAPI
2036 MmGetSystemRoutineAddress(
2037 IN PUNICODE_STRING SystemRoutineName);
2038
2039 NTKERNELAPI
2040 LOGICAL
2041 NTAPI
2042 MmIsDriverVerifying(
2043 IN struct _DRIVER_OBJECT *DriverObject);
2044
2045 NTKERNELAPI
2046 PVOID
2047 NTAPI
2048 MmLockPagableDataSection(
2049 IN PVOID AddressWithinSection);
2050
2051 NTKERNELAPI
2052 PVOID
2053 NTAPI
2054 MmMapIoSpace(
2055 IN PHYSICAL_ADDRESS PhysicalAddress,
2056 IN SIZE_T NumberOfBytes,
2057 IN MEMORY_CACHING_TYPE CacheEnable);
2058
2059 NTKERNELAPI
2060 PVOID
2061 NTAPI
2062 MmMapLockedPages(
2063 IN PMDL MemoryDescriptorList,
2064 IN KPROCESSOR_MODE AccessMode);
2065
2066 NTKERNELAPI
2067 PVOID
2068 NTAPI
2069 MmMapLockedPagesSpecifyCache(
2070 IN PMDL MemoryDescriptorList,
2071 IN KPROCESSOR_MODE AccessMode,
2072 IN MEMORY_CACHING_TYPE CacheType,
2073 IN PVOID BaseAddress OPTIONAL,
2074 IN ULONG BugCheckOnFailure,
2075 IN MM_PAGE_PRIORITY Priority);
2076
2077 NTKERNELAPI
2078 PVOID
2079 NTAPI
2080 MmPageEntireDriver(
2081 IN PVOID AddressWithinSection);
2082
2083 NTKERNELAPI
2084 VOID
2085 NTAPI
2086 MmProbeAndLockPages(
2087 IN OUT PMDL MemoryDescriptorList,
2088 IN KPROCESSOR_MODE AccessMode,
2089 IN LOCK_OPERATION Operation);
2090
2091 NTKERNELAPI
2092 MM_SYSTEMSIZE
2093 NTAPI
2094 MmQuerySystemSize(
2095 VOID);
2096
2097 NTKERNELAPI
2098 VOID
2099 NTAPI
2100 MmResetDriverPaging(
2101 IN PVOID AddressWithinSection);
2102
2103 NTKERNELAPI
2104 SIZE_T
2105 NTAPI
2106 MmSizeOfMdl(
2107 IN PVOID Base,
2108 IN SIZE_T Length);
2109
2110 NTKERNELAPI
2111 VOID
2112 NTAPI
2113 MmUnlockPagableImageSection(
2114 IN PVOID ImageSectionHandle);
2115
2116 NTKERNELAPI
2117 VOID
2118 NTAPI
2119 MmUnlockPages(
2120 IN OUT PMDL MemoryDescriptorList);
2121
2122 NTKERNELAPI
2123 VOID
2124 NTAPI
2125 MmUnmapIoSpace(
2126 IN PVOID BaseAddress,
2127 IN SIZE_T NumberOfBytes);
2128
2129 NTKERNELAPI
2130 VOID
2131 NTAPI
2132 MmProbeAndLockProcessPages(
2133 IN OUT PMDL MemoryDescriptorList,
2134 IN PEPROCESS Process,
2135 IN KPROCESSOR_MODE AccessMode,
2136 IN LOCK_OPERATION Operation);
2137
2138 NTKERNELAPI
2139 VOID
2140 NTAPI
2141 MmUnmapLockedPages(
2142 IN PVOID BaseAddress,
2143 IN PMDL MemoryDescriptorList);
2144
2145 #endif
2146
2147 #if (NTDDI_VERSION >= NTDDI_WINXP)
2148
2149 NTKERNELAPI
2150 NTSTATUS
2151 NTAPI
2152 MmAdvanceMdl(
2153 IN OUT PMDL Mdl,
2154 IN ULONG NumberOfBytes);
2155
2156 NTKERNELAPI
2157 PVOID
2158 NTAPI
2159 MmAllocateMappingAddress(
2160 IN SIZE_T NumberOfBytes,
2161 IN ULONG PoolTag);
2162
2163 NTKERNELAPI
2164 VOID
2165 NTAPI
2166 MmFreeMappingAddress(
2167 IN PVOID BaseAddress,
2168 IN ULONG PoolTag);
2169
2170 NTKERNELAPI
2171 NTSTATUS
2172 NTAPI
2173 MmIsVerifierEnabled(
2174 OUT PULONG VerifierFlags);
2175
2176 NTKERNELAPI
2177 PVOID
2178 NTAPI
2179 MmMapLockedPagesWithReservedMapping(
2180 IN PVOID MappingAddress,
2181 IN ULONG PoolTag,
2182 IN PMDL MemoryDescriptorList,
2183 IN MEMORY_CACHING_TYPE CacheType);
2184
2185 NTKERNELAPI
2186 NTSTATUS
2187 NTAPI
2188 MmProtectMdlSystemAddress(
2189 IN PMDL MemoryDescriptorList,
2190 IN ULONG NewProtect);
2191
2192 NTKERNELAPI
2193 VOID
2194 NTAPI
2195 MmUnmapReservedMapping(
2196 IN PVOID BaseAddress,
2197 IN ULONG PoolTag,
2198 IN PMDL MemoryDescriptorList);
2199
2200 #endif
2201
2202 #if (NTDDI_VERSION >= NTDDI_WS03SP1)
2203 NTKERNELAPI
2204 PMDL
2205 NTAPI
2206 MmAllocatePagesForMdlEx(
2207 IN PHYSICAL_ADDRESS LowAddress,
2208 IN PHYSICAL_ADDRESS HighAddress,
2209 IN PHYSICAL_ADDRESS SkipBytes,
2210 IN SIZE_T TotalBytes,
2211 IN MEMORY_CACHING_TYPE CacheType,
2212 IN ULONG Flags);
2213 #endif
2214
2215 /******************************************************************************
2216 * Security Manager Types *
2217 ******************************************************************************/
2218
2219 /* Simple types */
2220 typedef PVOID PSECURITY_DESCRIPTOR;
2221 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
2222 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
2223 typedef PVOID PACCESS_TOKEN;
2224 typedef PVOID PSID;
2225
2226 #define DELETE 0x00010000L
2227 #define READ_CONTROL 0x00020000L
2228 #define WRITE_DAC 0x00040000L
2229 #define WRITE_OWNER 0x00080000L
2230 #define SYNCHRONIZE 0x00100000L
2231 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
2232 #define STANDARD_RIGHTS_READ READ_CONTROL
2233 #define STANDARD_RIGHTS_WRITE READ_CONTROL
2234 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
2235 #define STANDARD_RIGHTS_ALL 0x001F0000L
2236 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
2237 #define ACCESS_SYSTEM_SECURITY 0x01000000L
2238 #define MAXIMUM_ALLOWED 0x02000000L
2239 #define GENERIC_READ 0x80000000L
2240 #define GENERIC_WRITE 0x40000000L
2241 #define GENERIC_EXECUTE 0x20000000L
2242 #define GENERIC_ALL 0x10000000L
2243
2244 typedef struct _GENERIC_MAPPING {
2245 ACCESS_MASK GenericRead;
2246 ACCESS_MASK GenericWrite;
2247 ACCESS_MASK GenericExecute;
2248 ACCESS_MASK GenericAll;
2249 } GENERIC_MAPPING, *PGENERIC_MAPPING;
2250
2251 #define ACL_REVISION 2
2252 #define ACL_REVISION_DS 4
2253
2254 #define ACL_REVISION1 1
2255 #define ACL_REVISION2 2
2256 #define ACL_REVISION3 3
2257 #define ACL_REVISION4 4
2258 #define MIN_ACL_REVISION ACL_REVISION2
2259 #define MAX_ACL_REVISION ACL_REVISION4
2260
2261 typedef struct _ACL {
2262 UCHAR AclRevision;
2263 UCHAR Sbz1;
2264 USHORT AclSize;
2265 USHORT AceCount;
2266 USHORT Sbz2;
2267 } ACL, *PACL;
2268
2269 /* Current security descriptor revision value */
2270 #define SECURITY_DESCRIPTOR_REVISION (1)
2271 #define SECURITY_DESCRIPTOR_REVISION1 (1)
2272
2273 /* Privilege attributes */
2274 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
2275 #define SE_PRIVILEGE_ENABLED (0x00000002L)
2276 #define SE_PRIVILEGE_REMOVED (0X00000004L)
2277 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
2278
2279 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
2280 SE_PRIVILEGE_ENABLED | \
2281 SE_PRIVILEGE_REMOVED | \
2282 SE_PRIVILEGE_USED_FOR_ACCESS)
2283
2284 #include <pshpack4.h>
2285 typedef struct _LUID_AND_ATTRIBUTES {
2286 LUID Luid;
2287 ULONG Attributes;
2288 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
2289 #include <poppack.h>
2290
2291 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
2292 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
2293
2294 /* Privilege sets */
2295 #define PRIVILEGE_SET_ALL_NECESSARY (1)
2296
2297 typedef struct _PRIVILEGE_SET {
2298 ULONG PrivilegeCount;
2299 ULONG Control;
2300 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
2301 } PRIVILEGE_SET,*PPRIVILEGE_SET;
2302
2303 typedef enum _SECURITY_IMPERSONATION_LEVEL {
2304 SecurityAnonymous,
2305 SecurityIdentification,
2306 SecurityImpersonation,
2307 SecurityDelegation
2308 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
2309
2310 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
2311 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
2312 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
2313 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
2314
2315 #define SECURITY_DYNAMIC_TRACKING (TRUE)
2316 #define SECURITY_STATIC_TRACKING (FALSE)
2317
2318 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
2319
2320 typedef struct _SECURITY_QUALITY_OF_SERVICE {
2321 ULONG Length;
2322 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2323 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
2324 BOOLEAN EffectiveOnly;
2325 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
2326
2327 typedef struct _SE_IMPERSONATION_STATE {
2328 PACCESS_TOKEN Token;
2329 BOOLEAN CopyOnOpen;
2330 BOOLEAN EffectiveOnly;
2331 SECURITY_IMPERSONATION_LEVEL Level;
2332 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
2333
2334 #define OWNER_SECURITY_INFORMATION (0x00000001L)
2335 #define GROUP_SECURITY_INFORMATION (0x00000002L)
2336 #define DACL_SECURITY_INFORMATION (0x00000004L)
2337 #define SACL_SECURITY_INFORMATION (0x00000008L)
2338 #define LABEL_SECURITY_INFORMATION (0x00000010L)
2339
2340 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
2341 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
2342 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
2343 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
2344
2345 typedef enum _SECURITY_OPERATION_CODE {
2346 SetSecurityDescriptor,
2347 QuerySecurityDescriptor,
2348 DeleteSecurityDescriptor,
2349 AssignSecurityDescriptor
2350 } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
2351
2352 #define INITIAL_PRIVILEGE_COUNT 3
2353
2354 typedef struct _INITIAL_PRIVILEGE_SET {
2355 ULONG PrivilegeCount;
2356 ULONG Control;
2357 LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
2358 } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
2359
2360 #define SE_MIN_WELL_KNOWN_PRIVILEGE 2
2361 #define SE_CREATE_TOKEN_PRIVILEGE 2
2362 #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3
2363 #define SE_LOCK_MEMORY_PRIVILEGE 4
2364 #define SE_INCREASE_QUOTA_PRIVILEGE 5
2365 #define SE_MACHINE_ACCOUNT_PRIVILEGE 6
2366 #define SE_TCB_PRIVILEGE 7
2367 #define SE_SECURITY_PRIVILEGE 8
2368 #define SE_TAKE_OWNERSHIP_PRIVILEGE 9
2369 #define SE_LOAD_DRIVER_PRIVILEGE 10
2370 #define SE_SYSTEM_PROFILE_PRIVILEGE 11
2371 #define SE_SYSTEMTIME_PRIVILEGE 12
2372 #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13
2373 #define SE_INC_BASE_PRIORITY_PRIVILEGE 14
2374 #define SE_CREATE_PAGEFILE_PRIVILEGE 15
2375 #define SE_CREATE_PERMANENT_PRIVILEGE 16
2376 #define SE_BACKUP_PRIVILEGE 17
2377 #define SE_RESTORE_PRIVILEGE 18
2378 #define SE_SHUTDOWN_PRIVILEGE 19
2379 #define SE_DEBUG_PRIVILEGE 20
2380 #define SE_AUDIT_PRIVILEGE 21
2381 #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22
2382 #define SE_CHANGE_NOTIFY_PRIVILEGE 23
2383 #define SE_REMOTE_SHUTDOWN_PRIVILEGE 24
2384 #define SE_UNDOCK_PRIVILEGE 25
2385 #define SE_SYNC_AGENT_PRIVILEGE 26
2386 #define SE_ENABLE_DELEGATION_PRIVILEGE 27
2387 #define SE_MANAGE_VOLUME_PRIVILEGE 28
2388 #define SE_IMPERSONATE_PRIVILEGE 29
2389 #define SE_CREATE_GLOBAL_PRIVILEGE 30
2390 #define SE_TRUSTED_CREDMAN_ACCESS_PRIVILEGE 31
2391 #define SE_RELABEL_PRIVILEGE 32
2392 #define SE_INC_WORKING_SET_PRIVILEGE 33
2393 #define SE_TIME_ZONE_PRIVILEGE 34
2394 #define SE_CREATE_SYMBOLIC_LINK_PRIVILEGE 35
2395 #define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_SYMBOLIC_LINK_PRIVILEGE
2396
2397 typedef struct _SECURITY_SUBJECT_CONTEXT {
2398 PACCESS_TOKEN ClientToken;
2399 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2400 PACCESS_TOKEN PrimaryToken;
2401 PVOID ProcessAuditId;
2402 } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
2403
2404 typedef struct _ACCESS_STATE {
2405 LUID OperationID;
2406 BOOLEAN SecurityEvaluated;
2407 BOOLEAN GenerateAudit;
2408 BOOLEAN GenerateOnClose;
2409 BOOLEAN PrivilegesAllocated;
2410 ULONG Flags;
2411 ACCESS_MASK RemainingDesiredAccess;
2412 ACCESS_MASK PreviouslyGrantedAccess;
2413 ACCESS_MASK OriginalDesiredAccess;
2414 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
2415 PSECURITY_DESCRIPTOR SecurityDescriptor;
2416 PVOID AuxData;
2417 union {
2418 INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
2419 PRIVILEGE_SET PrivilegeSet;
2420 } Privileges;
2421
2422 BOOLEAN AuditPrivileges;
2423 UNICODE_STRING ObjectName;
2424 UNICODE_STRING ObjectTypeName;
2425 } ACCESS_STATE, *PACCESS_STATE;
2426
2427 /******************************************************************************
2428 * Security Manager Functions *
2429 ******************************************************************************/
2430
2431 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2432
2433 NTKERNELAPI
2434 BOOLEAN
2435 NTAPI
2436 SeAccessCheck(
2437 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
2438 IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
2439 IN BOOLEAN SubjectContextLocked,
2440 IN ACCESS_MASK DesiredAccess,
2441 IN ACCESS_MASK PreviouslyGrantedAccess,
2442 OUT PPRIVILEGE_SET *Privileges OPTIONAL,
2443 IN PGENERIC_MAPPING GenericMapping,
2444 IN KPROCESSOR_MODE AccessMode,
2445 OUT PACCESS_MASK GrantedAccess,
2446 OUT PNTSTATUS AccessStatus);
2447
2448 NTKERNELAPI
2449 NTSTATUS
2450 NTAPI
2451 SeAssignSecurity(
2452 IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
2453 IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
2454 OUT PSECURITY_DESCRIPTOR *NewDescriptor,
2455 IN BOOLEAN IsDirectoryObject,
2456 IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
2457 IN PGENERIC_MAPPING GenericMapping,
2458 IN POOL_TYPE PoolType);
2459
2460 NTKERNELAPI
2461 NTSTATUS
2462 NTAPI
2463 SeAssignSecurityEx(
2464 IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
2465 IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
2466 OUT PSECURITY_DESCRIPTOR *NewDescriptor,
2467 IN GUID *ObjectType OPTIONAL,
2468 IN BOOLEAN IsDirectoryObject,
2469 IN ULONG AutoInheritFlags,
2470 IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
2471 IN PGENERIC_MAPPING GenericMapping,
2472 IN POOL_TYPE PoolType);
2473
2474 NTKERNELAPI
2475 NTSTATUS
2476 NTAPI
2477 SeDeassignSecurity(
2478 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor);
2479
2480 NTKERNELAPI
2481 BOOLEAN
2482 NTAPI
2483 SeValidSecurityDescriptor(
2484 IN ULONG Length,
2485 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
2486
2487 #endif
2488
2489 /******************************************************************************
2490 * Power Management Support Types *
2491 ******************************************************************************/
2492
2493 /* Power States/Levels */
2494 typedef enum _SYSTEM_POWER_STATE {
2495 PowerSystemUnspecified,
2496 PowerSystemWorking,
2497 PowerSystemSleeping1,
2498 PowerSystemSleeping2,
2499 PowerSystemSleeping3,
2500 PowerSystemHibernate,
2501 PowerSystemShutdown,
2502 PowerSystemMaximum
2503 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
2504
2505 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
2506
2507 typedef enum _POWER_INFORMATION_LEVEL {
2508 SystemPowerPolicyAc,
2509 SystemPowerPolicyDc,
2510 VerifySystemPolicyAc,
2511 VerifySystemPolicyDc,
2512 SystemPowerCapabilities,
2513 SystemBatteryState,
2514 SystemPowerStateHandler,
2515 ProcessorStateHandler,
2516 SystemPowerPolicyCurrent,
2517 AdministratorPowerPolicy,
2518 SystemReserveHiberFile,
2519 ProcessorInformation,
2520 SystemPowerInformation,
2521 ProcessorStateHandler2,
2522 LastWakeTime,
2523 LastSleepTime,
2524 SystemExecutionState,
2525 SystemPowerStateNotifyHandler,
2526 ProcessorPowerPolicyAc,
2527 ProcessorPowerPolicyDc,
2528 VerifyProcessorPowerPolicyAc,
2529 VerifyProcessorPowerPolicyDc,
2530 ProcessorPowerPolicyCurrent
2531 } POWER_INFORMATION_LEVEL;
2532
2533 typedef enum {
2534 PowerActionNone,
2535 PowerActionReserved,
2536 PowerActionSleep,
2537 PowerActionHibernate,
2538 PowerActionShutdown,
2539 PowerActionShutdownReset,
2540 PowerActionShutdownOff,
2541 PowerActionWarmEject
2542 } POWER_ACTION, *PPOWER_ACTION;
2543
2544 typedef enum _DEVICE_POWER_STATE {
2545 PowerDeviceUnspecified,
2546 PowerDeviceD0,
2547 PowerDeviceD1,
2548 PowerDeviceD2,
2549 PowerDeviceD3,
2550 PowerDeviceMaximum
2551 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
2552
2553 typedef union _POWER_STATE {
2554 SYSTEM_POWER_STATE SystemState;
2555 DEVICE_POWER_STATE DeviceState;
2556 } POWER_STATE, *PPOWER_STATE;
2557
2558 typedef enum _POWER_STATE_TYPE {
2559 SystemPowerState = 0,
2560 DevicePowerState
2561 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
2562
2563 typedef VOID
2564 (DDKAPI *PREQUEST_POWER_COMPLETE)(
2565 IN struct _DEVICE_OBJECT *DeviceObject,
2566 IN UCHAR MinorFunction,
2567 IN POWER_STATE PowerState,
2568 IN PVOID Context,
2569 IN struct _IO_STATUS_BLOCK *IoStatus);
2570
2571 /******************************************************************************
2572 * Power Management Support Functions *
2573 ******************************************************************************/
2574
2575 #define PoSetDeviceBusy(IdlePointer) ((void)(*(IdlePointer) = 0))
2576
2577 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2578
2579 NTKERNELAPI
2580 NTSTATUS
2581 NTAPI
2582 PoCallDriver(
2583 IN struct _DEVICE_OBJECT *DeviceObject,
2584 IN OUT struct _IRP *Irp);
2585
2586 NTKERNELAPI
2587 PULONG
2588 NTAPI
2589 PoRegisterDeviceForIdleDetection(
2590 IN struct _DEVICE_OBJECT *DeviceObject,
2591 IN ULONG ConservationIdleTime,
2592 IN ULONG PerformanceIdleTime,
2593 IN DEVICE_POWER_STATE State);
2594
2595 NTKERNELAPI
2596 PVOID
2597 NTAPI
2598 PoRegisterSystemState(
2599 IN PVOID StateHandle OPTIONAL,
2600 IN EXECUTION_STATE Flags);
2601
2602 NTKERNELAPI
2603 NTSTATUS
2604 NTAPI
2605 PoRequestPowerIrp(
2606 IN struct _DEVICE_OBJECT *DeviceObject,
2607 IN UCHAR MinorFunction,
2608 IN POWER_STATE PowerState,
2609 IN PREQUEST_POWER_COMPLETE CompletionFunction OPTIONAL,
2610 IN PVOID Context OPTIONAL,
2611 OUT struct _IRP **Irp OPTIONAL);
2612
2613 NTKERNELAPI
2614 POWER_STATE
2615 NTAPI
2616 PoSetPowerState(
2617 IN struct _DEVICE_OBJECT *DeviceObject,
2618 IN POWER_STATE_TYPE Type,
2619 IN POWER_STATE State);
2620
2621 NTKERNELAPI
2622 VOID
2623 NTAPI
2624 PoSetSystemState(
2625 IN EXECUTION_STATE Flags);
2626
2627 NTKERNELAPI
2628 VOID
2629 NTAPI
2630 PoStartNextPowerIrp(
2631 IN OUT struct _IRP *Irp);
2632
2633 NTKERNELAPI
2634 VOID
2635 NTAPI
2636 PoUnregisterSystemState(
2637 IN OUT PVOID StateHandle);
2638
2639 #endif
2640
2641 /******************************************************************************
2642 * Configuration Manager Types *
2643 ******************************************************************************/
2644
2645 /* Resource list definitions */
2646 typedef int CM_RESOURCE_TYPE;
2647
2648 #define CmResourceTypeNull 0
2649 #define CmResourceTypePort 1
2650 #define CmResourceTypeInterrupt 2
2651 #define CmResourceTypeMemory 3
2652 #define CmResourceTypeDma 4
2653 #define CmResourceTypeDeviceSpecific 5
2654 #define CmResourceTypeBusNumber 6
2655 #define CmResourceTypeNonArbitrated 128
2656 #define CmResourceTypeConfigData 128
2657 #define CmResourceTypeDevicePrivate 129
2658 #define CmResourceTypePcCardConfig 130
2659 #define CmResourceTypeMfCardConfig 131
2660
2661
2662 /* KEY_VALUE_Xxx.Type */
2663 #define REG_NONE 0
2664 #define REG_SZ 1
2665 #define REG_EXPAND_SZ 2
2666 #define REG_BINARY 3
2667 #define REG_DWORD 4
2668 #define REG_DWORD_LITTLE_ENDIAN 4
2669 #define REG_DWORD_BIG_ENDIAN 5
2670 #define REG_LINK 6
2671 #define REG_MULTI_SZ 7
2672 #define REG_RESOURCE_LIST 8
2673 #define REG_FULL_RESOURCE_DESCRIPTOR 9
2674 #define REG_RESOURCE_REQUIREMENTS_LIST 10
2675 #define REG_QWORD 11
2676 #define REG_QWORD_LITTLE_ENDIAN 11
2677
2678 /* Registry Access Rights */
2679 #define KEY_QUERY_VALUE (0x0001)
2680 #define KEY_SET_VALUE (0x0002)
2681 #define KEY_CREATE_SUB_KEY (0x0004)
2682 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
2683 #define KEY_NOTIFY (0x0010)
2684 #define KEY_CREATE_LINK (0x0020)
2685 #define KEY_WOW64_32KEY (0x0200)
2686 #define KEY_WOW64_64KEY (0x0100)
2687 #define KEY_WOW64_RES (0x0300)
2688
2689 #define KEY_READ ((STANDARD_RIGHTS_READ |\
2690 KEY_QUERY_VALUE |\
2691 KEY_ENUMERATE_SUB_KEYS |\
2692 KEY_NOTIFY) \
2693 & \
2694 (~SYNCHRONIZE))
2695
2696 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
2697 KEY_SET_VALUE |\
2698 KEY_CREATE_SUB_KEY) \
2699 & \
2700 (~SYNCHRONIZE))
2701
2702 #define KEY_EXECUTE ((KEY_READ) \
2703 & \
2704 (~SYNCHRONIZE))
2705
2706 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
2707 KEY_QUERY_VALUE |\
2708 KEY_SET_VALUE |\
2709 KEY_CREATE_SUB_KEY |\
2710 KEY_ENUMERATE_SUB_KEYS |\
2711 KEY_NOTIFY |\
2712 KEY_CREATE_LINK) \
2713 & \
2714 (~SYNCHRONIZE))
2715
2716 /* Registry Open/Create Options */
2717 #define REG_OPTION_RESERVED (0x00000000L)
2718 #define REG_OPTION_NON_VOLATILE (0x00000000L)
2719 #define REG_OPTION_VOLATILE (0x00000001L)
2720 #define REG_OPTION_CREATE_LINK (0x00000002L)
2721 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
2722 #define REG_OPTION_OPEN_LINK (0x00000008L)
2723
2724 #define REG_LEGAL_OPTION \
2725 (REG_OPTION_RESERVED |\
2726 REG_OPTION_NON_VOLATILE |\
2727 REG_OPTION_VOLATILE |\
2728 REG_OPTION_CREATE_LINK |\
2729 REG_OPTION_BACKUP_RESTORE |\
2730 REG_OPTION_OPEN_LINK)
2731
2732 /* Key creation/open disposition */
2733 #define REG_CREATED_NEW_KEY (0x00000001L)
2734 #define REG_OPENED_EXISTING_KEY (0x00000002L)
2735
2736 /* Key restore & hive load flags */
2737 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
2738 #define REG_REFRESH_HIVE (0x00000002L)
2739 #define REG_NO_LAZY_FLUSH (0x00000004L)
2740 #define REG_FORCE_RESTORE (0x00000008L)
2741 #define REG_APP_HIVE (0x00000010L)
2742 #define REG_PROCESS_PRIVATE (0x00000020L)
2743 #define REG_START_JOURNAL (0x00000040L)
2744 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
2745 #define REG_HIVE_NO_RM (0x00000100L)
2746 #define REG_HIVE_SINGLE_LOG (0x00000200L)
2747
2748 /* Unload Flags */
2749 #define REG_FORCE_UNLOAD 1
2750
2751 /* Notify Filter Values */
2752 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
2753 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
2754 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
2755 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
2756
2757 #define REG_LEGAL_CHANGE_FILTER \
2758 (REG_NOTIFY_CHANGE_NAME |\
2759 REG_NOTIFY_CHANGE_ATTRIBUTES |\
2760 REG_NOTIFY_CHANGE_LAST_SET |\
2761 REG_NOTIFY_CHANGE_SECURITY)
2762
2763 typedef struct _CM_FLOPPY_DEVICE_DATA {
2764 USHORT Version;
2765 USHORT Revision;
2766 CHAR Size[8];
2767 ULONG MaxDensity;
2768 ULONG MountDensity;
2769 UCHAR StepRateHeadUnloadTime;
2770 UCHAR HeadLoadTime;
2771 UCHAR MotorOffTime;
2772 UCHAR SectorLengthCode;
2773 UCHAR SectorPerTrack;
2774 UCHAR ReadWriteGapLength;
2775 UCHAR DataTransferLength;
2776 UCHAR FormatGapLength;
2777 UCHAR FormatFillCharacter;
2778 UCHAR HeadSettleTime;
2779 UCHAR MotorSettleTime;
2780 UCHAR MaximumTrackValue;
2781 UCHAR DataTransferRate;
2782 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
2783
2784 #include <pshpack4.h>
2785 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
2786 UCHAR Type;
2787 UCHAR ShareDisposition;
2788 USHORT Flags;
2789 union {
2790 struct {
2791 PHYSICAL_ADDRESS Start;
2792 ULONG Length;
2793 } Generic;
2794 struct {
2795 PHYSICAL_ADDRESS Start;
2796 ULONG Length;
2797 } Port;
2798 struct {
2799 #if defined(NT_PROCESSOR_GROUPS)
2800 USHORT Level;
2801 USHORT Group;
2802 #else
2803 ULONG Level;
2804 #endif
2805 ULONG Vector;
2806 KAFFINITY Affinity;
2807 } Interrupt;
2808 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
2809 struct {
2810 __GNU_EXTENSION union {
2811 struct {
2812 #if defined(NT_PROCESSOR_GROUPS)
2813 USHORT Group;
2814 #else
2815 USHORT Reserved;
2816 #endif
2817 USHORT MessageCount;
2818 ULONG Vector;
2819 KAFFINITY Affinity;
2820 } Raw;
2821 struct {
2822 #if defined(NT_PROCESSOR_GROUPS)
2823 USHORT Level;
2824 USHORT Group;
2825 #else
2826 ULONG Level;
2827 #endif
2828 ULONG Vector;
2829 KAFFINITY Affinity;
2830 } Translated;
2831 } DUMMYUNIONNAME;
2832 } MessageInterrupt;
2833 #endif
2834 struct {
2835 PHYSICAL_ADDRESS Start;
2836 ULONG Length;
2837 } Memory;
2838 struct {
2839 ULONG Channel;
2840 ULONG Port;
2841 ULONG Reserved1;
2842 } Dma;
2843 struct {
2844 ULONG Data[3];
2845 } DevicePrivate;
2846 struct {
2847 ULONG Start;
2848 ULONG Length;
2849 ULONG Reserved;
2850 } BusNumber;
2851 struct {
2852 ULONG DataSize;
2853 ULONG Reserved1;
2854 ULONG Reserved2;
2855 } DeviceSpecificData;
2856 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
2857 struct {
2858 PHYSICAL_ADDRESS Start;
2859 ULONG Length40;
2860 } Memory40;
2861 struct {
2862 PHYSICAL_ADDRESS Start;
2863 ULONG Length48;
2864 } Memory48;
2865 struct {
2866 PHYSICAL_ADDRESS Start;
2867 ULONG Length64;
2868 } Memory64;
2869 #endif
2870 } u;
2871 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
2872 #include <poppack.h>
2873
2874 #include <pshpack1.h>
2875 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
2876
2877 #define CmResourceTypeNull 0
2878 #define CmResourceTypePort 1
2879 #define CmResourceTypeInterrupt 2
2880 #define CmResourceTypeMemory 3
2881 #define CmResourceTypeDma 4
2882 #define CmResourceTypeDeviceSpecific 5
2883 #define CmResourceTypeBusNumber 6
2884 #define CmResourceTypeMemoryLarge 7
2885 #define CmResourceTypeNonArbitrated 128
2886 #define CmResourceTypeConfigData 128
2887 #define CmResourceTypeDevicePrivate 129
2888 #define CmResourceTypePcCardConfig 130
2889 #define CmResourceTypeMfCardConfig 131
2890
2891 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
2892
2893 typedef enum _CM_SHARE_DISPOSITION {
2894 CmResourceShareUndetermined,
2895 CmResourceShareDeviceExclusive,
2896 CmResourceShareDriverExclusive,
2897 CmResourceShareShared
2898 } CM_SHARE_DISPOSITION;
2899
2900 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
2901
2902 #define CM_RESOURCE_PORT_MEMORY 0x0000
2903 #define CM_RESOURCE_PORT_IO 0x0001
2904 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
2905 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
2906 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
2907 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
2908 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
2909 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
2910 #define CM_RESOURCE_PORT_BAR 0x0100
2911
2912 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
2913
2914 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
2915 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
2916 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
2917 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
2918
2919 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
2920
2921 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
2922 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
2923 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
2924 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
2925 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
2926 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
2927 #define CM_RESOURCE_MEMORY_24 0x0010
2928 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
2929 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
2930 #define CM_RESOURCE_MEMORY_BAR 0x0080
2931 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
2932
2933 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
2934
2935 #define CM_RESOURCE_DMA_8 0x0000
2936 #define CM_RESOURCE_DMA_16 0x0001
2937 #define CM_RESOURCE_DMA_32 0x0002
2938 #define CM_RESOURCE_DMA_8_AND_16 0x0004
2939 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
2940 #define CM_RESOURCE_DMA_TYPE_A 0x0010
2941 #define CM_RESOURCE_DMA_TYPE_B 0x0020
2942 #define CM_RESOURCE_DMA_TYPE_F 0x0040
2943
2944 typedef struct _CM_PARTIAL_RESOURCE_LIST {
2945 USHORT Version;
2946 USHORT Revision;
2947 ULONG Count;
2948 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
2949 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
2950
2951 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
2952 INTERFACE_TYPE InterfaceType;
2953 ULONG BusNumber;
2954 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
2955 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
2956
2957 typedef struct _CM_RESOURCE_LIST {
2958 ULONG Count;
2959 CM_FULL_RESOURCE_DESCRIPTOR List[1];
2960 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
2961
2962 typedef struct _CM_INT13_DRIVE_PARAMETER {
2963 USHORT DriveSelect;
2964 ULONG MaxCylinders;
2965 USHORT SectorsPerTrack;
2966 USHORT MaxHeads;
2967 USHORT NumberDrives;
2968 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
2969
2970 typedef struct _CM_PNP_BIOS_DEVICE_NODE
2971 {
2972 USHORT Size;
2973 UCHAR Node;
2974 ULONG ProductId;
2975 UCHAR DeviceType[3];
2976 USHORT DeviceAttributes;
2977 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
2978
2979 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
2980 {
2981 UCHAR Signature[4];
2982 UCHAR Revision;
2983 UCHAR Length;
2984 USHORT ControlField;
2985 UCHAR Checksum;
2986 ULONG EventFlagAddress;
2987 USHORT RealModeEntryOffset;
2988 USHORT RealModeEntrySegment;
2989 USHORT ProtectedModeEntryOffset;
2990 ULONG ProtectedModeCodeBaseAddress;
2991 ULONG OemDeviceId;
2992 USHORT RealModeDataBaseAddress;
2993 ULONG ProtectedModeDataBaseAddress;
2994 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
2995
2996 #include <poppack.h>
2997
2998 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
2999 {
3000 ULONG BytesPerSector;
3001 ULONG NumberOfCylinders;
3002 ULONG SectorsPerTrack;
3003 ULONG NumberOfHeads;
3004 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
3005
3006 typedef struct _CM_KEYBOARD_DEVICE_DATA {
3007 USHORT Version;
3008 USHORT Revision;
3009 UCHAR Type;
3010 UCHAR Subtype;
3011 USHORT KeyboardFlags;
3012 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
3013
3014 typedef struct _CM_MCA_POS_DATA {
3015 USHORT AdapterId;
3016 UCHAR PosData1;
3017 UCHAR PosData2;
3018 UCHAR PosData3;
3019 UCHAR PosData4;
3020 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
3021
3022 #if (NTDDI_VERSION >= NTDDI_WINXP)
3023 typedef struct CM_Power_Data_s {
3024 ULONG PD_Size;
3025 DEVICE_POWER_STATE PD_MostRecentPowerState;
3026 ULONG PD_Capabilities;
3027 ULONG PD_D1Latency;
3028 ULONG PD_D2Latency;
3029 ULONG PD_D3Latency;
3030 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
3031 SYSTEM_POWER_STATE PD_DeepestSystemWake;
3032 } CM_POWER_DATA, *PCM_POWER_DATA;
3033
3034 #define PDCAP_D0_SUPPORTED 0x00000001
3035 #define PDCAP_D1_SUPPORTED 0x00000002
3036 #define PDCAP_D2_SUPPORTED 0x00000004
3037 #define PDCAP_D3_SUPPORTED 0x00000008
3038 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
3039 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
3040 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
3041 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
3042 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
3043
3044 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
3045
3046 typedef struct _CM_SCSI_DEVICE_DATA {
3047 USHORT Version;
3048 USHORT Revision;
3049 UCHAR HostIdentifier;
3050 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
3051
3052 typedef struct _CM_SERIAL_DEVICE_DATA {
3053 USHORT Version;
3054 USHORT Revision;
3055 ULONG BaudClock;
3056 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
3057
3058 typedef enum _KEY_INFORMATION_CLASS {
3059 KeyBasicInformation,
3060 KeyNodeInformation,
3061 KeyFullInformation,
3062 KeyNameInformation,
3063 KeyCachedInformation,
3064 KeyFlagsInformation
3065 } KEY_INFORMATION_CLASS;
3066
3067 typedef struct _KEY_BASIC_INFORMATION {
3068 LARGE_INTEGER LastWriteTime;
3069 ULONG TitleIndex;
3070 ULONG NameLength;
3071 WCHAR Name[1];
3072 } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
3073
3074 typedef struct _KEY_FULL_INFORMATION {
3075 LARGE_INTEGER LastWriteTime;
3076 ULONG TitleIndex;
3077 ULONG ClassOffset;
3078 ULONG ClassLength;
3079 ULONG SubKeys;
3080 ULONG MaxNameLen;
3081 ULONG MaxClassLen;
3082 ULONG Values;
3083 ULONG MaxValueNameLen;
3084 ULONG MaxValueDataLen;
3085 WCHAR Class[1];
3086 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
3087
3088 typedef struct _KEY_NODE_INFORMATION {
3089 LARGE_INTEGER LastWriteTime;
3090 ULONG TitleIndex;
3091 ULONG ClassOffset;
3092 ULONG ClassLength;
3093 ULONG NameLength;
3094 WCHAR Name[1];
3095 } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
3096
3097 typedef struct _KEY_VALUE_BASIC_INFORMATION {
3098 ULONG TitleIndex;
3099 ULONG Type;
3100 ULONG NameLength;
3101 WCHAR Name[1];
3102 } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
3103
3104 typedef struct _KEY_VALUE_FULL_INFORMATION {
3105 ULONG TitleIndex;
3106 ULONG Type;
3107 ULONG DataOffset;
3108 ULONG DataLength;
3109 ULONG NameLength;
3110 WCHAR Name[1];
3111 } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
3112
3113 typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
3114 ULONG TitleIndex;
3115 ULONG Type;
3116 ULONG DataLength;
3117 UCHAR Data[1];
3118 } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
3119
3120 typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
3121 ULONG Type;
3122 ULONG DataLength;
3123 UCHAR Data[1];
3124 } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
3125
3126 typedef struct _KEY_VALUE_ENTRY {
3127 PUNICODE_STRING ValueName;
3128 ULONG DataLength;
3129 ULONG DataOffset;
3130 ULONG Type;
3131 } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
3132
3133 typedef enum _KEY_VALUE_INFORMATION_CLASS {
3134 KeyValueBasicInformation,
3135 KeyValueFullInformation,
3136 KeyValuePartialInformation,
3137 KeyValueFullInformationAlign64,
3138 KeyValuePartialInformationAlign64
3139 } KEY_VALUE_INFORMATION_CLASS;
3140
3141 typedef struct _KEY_WRITE_TIME_INFORMATION {
3142 LARGE_INTEGER LastWriteTime;
3143 } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
3144
3145 typedef enum _KEY_SET_INFORMATION_CLASS {
3146 KeyWriteTimeInformation,
3147 KeyWow64FlagsInformation,
3148 KeyControlFlagsInformation,
3149 KeySetVirtualizationInformation,
3150 KeySetDebugInformation,
3151 KeySetHandleTagsInformation,
3152 MaxKeySetInfoClass
3153 } KEY_SET_INFORMATION_CLASS;
3154
3155 typedef enum _REG_NOTIFY_CLASS {
3156 RegNtDeleteKey,
3157 RegNtPreDeleteKey = RegNtDeleteKey,
3158 RegNtSetValueKey,
3159 RegNtPreSetValueKey = RegNtSetValueKey,
3160 RegNtDeleteValueKey,
3161 RegNtPreDeleteValueKey = RegNtDeleteValueKey,
3162 RegNtSetInformationKey,
3163 RegNtPreSetInformationKey = RegNtSetInformationKey,
3164 RegNtRenameKey,
3165 RegNtPreRenameKey = RegNtRenameKey,
3166 RegNtEnumerateKey,
3167 RegNtPreEnumerateKey = RegNtEnumerateKey,
3168 RegNtEnumerateValueKey,
3169 RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
3170 RegNtQueryKey,
3171 RegNtPreQueryKey = RegNtQueryKey,
3172 RegNtQueryValueKey,
3173 RegNtPreQueryValueKey = RegNtQueryValueKey,
3174 RegNtQueryMultipleValueKey,
3175 RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
3176 RegNtPreCreateKey,
3177 RegNtPostCreateKey,
3178 RegNtPreOpenKey,
3179 RegNtPostOpenKey,
3180 RegNtKeyHandleClose,
3181 RegNtPreKeyHandleClose = RegNtKeyHandleClose,
3182 RegNtPostDeleteKey,
3183 RegNtPostSetValueKey,
3184 RegNtPostDeleteValueKey,
3185 RegNtPostSetInformationKey,
3186 RegNtPostRenameKey,
3187 RegNtPostEnumerateKey,
3188 RegNtPostEnumerateValueKey,
3189 RegNtPostQueryKey,
3190 RegNtPostQueryValueKey,
3191 RegNtPostQueryMultipleValueKey,
3192 RegNtPostKeyHandleClose,
3193 RegNtPreCreateKeyEx,
3194 RegNtPostCreateKeyEx,
3195 RegNtPreOpenKeyEx,
3196 RegNtPostOpenKeyEx,
3197 RegNtPreFlushKey,
3198 RegNtPostFlushKey,
3199 RegNtPreLoadKey,
3200 RegNtPostLoadKey,
3201 RegNtPreUnLoadKey,
3202 RegNtPostUnLoadKey,
3203 RegNtPreQueryKeySecurity,
3204 RegNtPostQueryKeySecurity,
3205 RegNtPreSetKeySecurity,
3206 RegNtPostSetKeySecurity,
3207 RegNtCallbackObjectContextCleanup,
3208 RegNtPreRestoreKey,
3209 RegNtPostRestoreKey,
3210 RegNtPreSaveKey,
3211 RegNtPostSaveKey,
3212 RegNtPreReplaceKey,
3213 RegNtPostReplaceKey,
3214 MaxRegNtNotifyClass
3215 } REG_NOTIFY_CLASS, *PREG_NOTIFY_CLASS;
3216
3217 typedef NTSTATUS
3218 (NTAPI *PEX_CALLBACK_FUNCTION)(
3219 IN PVOID CallbackContext,
3220 IN PVOID Argument1,
3221 IN PVOID Argument2
3222 );
3223
3224 typedef struct _REG_DELETE_KEY_INFORMATION {
3225 PVOID Object;
3226 PVOID CallContext;
3227 PVOID ObjectContext;
3228 PVOID Reserved;
3229 } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION
3230 #if (NTDDI_VERSION >= NTDDI_VISTA)
3231 , REG_FLUSH_KEY_INFORMATION, *PREG_FLUSH_KEY_INFORMATION
3232 #endif
3233 ;
3234
3235 typedef struct _REG_SET_VALUE_KEY_INFORMATION {
3236 PVOID Object;
3237 PUNICODE_STRING ValueName;
3238 ULONG TitleIndex;
3239 ULONG Type;
3240 PVOID Data;
3241 ULONG DataSize;
3242 PVOID CallContext;
3243 PVOID ObjectContext;
3244 PVOID Reserved;
3245 } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
3246
3247 typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
3248 PVOID Object;
3249 PUNICODE_STRING ValueName;
3250 PVOID CallContext;
3251 PVOID ObjectContext;
3252 PVOID Reserved;
3253 } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
3254
3255 typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
3256 PVOID Object;
3257 KEY_SET_INFORMATION_CLASS KeySetInformationClass;
3258 PVOID KeySetInformation;
3259 ULONG KeySetInformationLength;
3260 PVOID CallContext;
3261 PVOID ObjectContext;
3262 PVOID Reserved;
3263 } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
3264
3265 typedef struct _REG_ENUMERATE_KEY_INFORMATION {
3266 PVOID Object;
3267 ULONG Index;
3268 KEY_INFORMATION_CLASS KeyInformationClass;
3269 PVOID KeyInformation;
3270 ULONG Length;
3271 PULONG ResultLength;
3272 PVOID CallContext;
3273 PVOID ObjectContext;
3274 PVOID Reserved;
3275 } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
3276
3277 typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
3278 PVOID Object;
3279 ULONG Index;
3280 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
3281 PVOID KeyValueInformation;
3282 ULONG Length;
3283 PULONG ResultLength;
3284 PVOID CallContext;
3285 PVOID ObjectContext;
3286 PVOID Reserved;
3287 } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
3288
3289 typedef struct _REG_QUERY_KEY_INFORMATION {
3290 PVOID Object;
3291 KEY_INFORMATION_CLASS KeyInformationClass;
3292 PVOID KeyInformation;
3293 ULONG Length;
3294 PULONG ResultLength;
3295 PVOID CallContext;
3296 PVOID ObjectContext;
3297 PVOID Reserved;
3298 } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
3299
3300 typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
3301 PVOID Object;
3302 PUNICODE_STRING ValueName;
3303 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
3304 PVOID KeyValueInformation;
3305 ULONG Length;
3306 PULONG ResultLength;
3307 PVOID CallContext;
3308 PVOID ObjectContext;
3309 PVOID Reserved;
3310 } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
3311
3312 typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
3313 PVOID Object;
3314 PKEY_VALUE_ENTRY ValueEntries;
3315 ULONG EntryCount;
3316 PVOID ValueBuffer;
3317 PULONG BufferLength;
3318 PULONG RequiredBufferLength;
3319 PVOID CallContext;
3320 PVOID ObjectContext;
3321 PVOID Reserved;
3322 } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
3323
3324 typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
3325 PUNICODE_STRING CompleteName;
3326 } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
3327
3328 typedef struct _REG_POST_CREATE_KEY_INFORMATION {
3329 PUNICODE_STRING CompleteName;
3330 PVOID Object;
3331 NTSTATUS Status;
3332 } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
3333
3334 typedef struct _REG_POST_OPERATION_INFORMATION {
3335 PVOID Object;
3336 NTSTATUS Status;
3337 PVOID PreInformation;
3338 NTSTATUS ReturnStatus;
3339 PVOID CallContext;
3340 PVOID ObjectContext;
3341 PVOID Reserved;
3342 } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
3343
3344 typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
3345 PVOID Object;
3346 PVOID CallContext;
3347 PVOID ObjectContext;
3348 PVOID Reserved;
3349 } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
3350
3351
3352 /******************************************************************************
3353 * Configuration Manager Functions *
3354 ******************************************************************************/
3355
3356 #if (NTDDI_VERSION >= NTDDI_WINXP)
3357 NTKERNELAPI
3358 NTSTATUS
3359 NTAPI
3360 CmRegisterCallback(
3361 IN PEX_CALLBACK_FUNCTION Function,
3362 IN PVOID Context OPTIONAL,
3363 OUT PLARGE_INTEGER Cookie);
3364
3365 NTKERNELAPI
3366 NTSTATUS
3367 NTAPI
3368 CmUnRegisterCallback(
3369 IN LARGE_INTEGER Cookie);
3370 #endif
3371
3372
3373 /******************************************************************************
3374 * RTL Types *
3375 ******************************************************************************/
3376
3377 #define RTL_REGISTRY_ABSOLUTE 0
3378 #define RTL_REGISTRY_SERVICES 1
3379 #define RTL_REGISTRY_CONTROL 2
3380 #define RTL_REGISTRY_WINDOWS_NT 3
3381 #define RTL_REGISTRY_DEVICEMAP 4
3382 #define RTL_REGISTRY_USER 5
3383 #define RTL_REGISTRY_MAXIMUM 6
3384 #define RTL_REGISTRY_HANDLE 0x40000000
3385 #define RTL_REGISTRY_OPTIONAL 0x80000000
3386
3387 /* RTL_QUERY_REGISTRY_TABLE.Flags */
3388 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
3389 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
3390 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
3391 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
3392 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
3393 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
3394 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
3395
3396 #define HASH_STRING_ALGORITHM_DEFAULT 0
3397 #define HASH_STRING_ALGORITHM_X65599 1
3398 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
3399
3400 typedef struct _RTL_BITMAP {
3401 ULONG SizeOfBitMap;
3402 PULONG Buffer;
3403 } RTL_BITMAP, *PRTL_BITMAP;
3404
3405 typedef struct _RTL_BITMAP_RUN {
3406 ULONG StartingIndex;
3407 ULONG NumberOfBits;
3408 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
3409
3410 typedef NTSTATUS
3411 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
3412 IN PWSTR ValueName,
3413 IN ULONG ValueType,
3414 IN PVOID ValueData,
3415 IN ULONG ValueLength,
3416 IN PVOID Context,
3417 IN PVOID EntryContext);
3418
3419 typedef struct _RTL_QUERY_REGISTRY_TABLE {
3420 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
3421 ULONG Flags;
3422 PCWSTR Name;
3423 PVOID EntryContext;
3424 ULONG DefaultType;
3425 PVOID DefaultData;
3426 ULONG DefaultLength;
3427 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
3428
3429 typedef struct _TIME_FIELDS {
3430 CSHORT Year;
3431 CSHORT Month;
3432 CSHORT Day;
3433 CSHORT Hour;
3434 CSHORT Minute;
3435 CSHORT Second;
3436 CSHORT Milliseconds;
3437 CSHORT Weekday;
3438 } TIME_FIELDS, *PTIME_FIELDS;
3439
3440 /* Slist Header */
3441 #ifndef _SLIST_HEADER_
3442 #define _SLIST_HEADER_
3443
3444 #if defined(_WIN64)
3445 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
3446 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
3447 PSLIST_ENTRY Next;
3448 } SLIST_ENTRY;
3449 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
3450 struct {
3451 ULONGLONG Alignment;
3452 ULONGLONG Region;
3453 } DUMMYSTRUCTNAME;
3454 struct {
3455 ULONGLONG Depth:16;
3456 ULONGLONG Sequence:9;
3457 ULONGLONG NextEntry:39;
3458 ULONGLONG HeaderType:1;
3459 ULONGLONG Init:1;
3460 ULONGLONG Reserved:59;
3461 ULONGLONG Region:3;
3462 } Header8;
3463 struct {
3464 ULONGLONG Depth:16;
3465 ULONGLONG Sequence:48;
3466 ULONGLONG HeaderType:1;
3467 ULONGLONG Init:1;
3468 ULONGLONG Reserved:2;
3469 ULONGLONG NextEntry:60;
3470 } Header16;
3471 } SLIST_HEADER, *PSLIST_HEADER;
3472 #else
3473 #define SLIST_ENTRY SINGLE_LIST_ENTRY
3474 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
3475 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
3476 typedef union _SLIST_HEADER {
3477 ULONGLONG Alignment;
3478 struct {
3479 SLIST_ENTRY Next;
3480 USHORT Depth;
3481 USHORT Sequence;
3482 } DUMMYSTRUCTNAME;
3483 } SLIST_HEADER, *PSLIST_HEADER;
3484 #endif
3485
3486 #endif /* _SLIST_HEADER_ */
3487
3488
3489 /******************************************************************************
3490 * RTL Functions *
3491 ******************************************************************************/
3492
3493 FORCEINLINE
3494 VOID
3495 InitializeListHead(
3496 OUT PLIST_ENTRY ListHead)
3497 {
3498 ListHead->Flink = ListHead->Blink = ListHead;
3499 }
3500
3501 FORCEINLINE
3502 VOID
3503 InsertHeadList(
3504 IN OUT PLIST_ENTRY ListHead,
3505 IN OUT PLIST_ENTRY Entry)
3506 {
3507 PLIST_ENTRY OldFlink;
3508 OldFlink = ListHead->Flink;
3509 Entry->Flink = OldFlink;
3510 Entry->Blink = ListHead;
3511 OldFlink->Blink = Entry;
3512 ListHead->Flink = Entry;
3513 }
3514
3515 FORCEINLINE
3516 VOID
3517 InsertTailList(
3518 IN OUT PLIST_ENTRY ListHead,
3519 IN OUT PLIST_ENTRY Entry)
3520 {
3521 PLIST_ENTRY OldBlink;
3522 OldBlink = ListHead->Blink;
3523 Entry->Flink = ListHead;
3524 Entry->Blink = OldBlink;
3525 OldBlink->Flink = Entry;
3526 ListHead->Blink = Entry;
3527 }
3528
3529 BOOLEAN
3530 FORCEINLINE
3531 IsListEmpty(
3532 IN CONST LIST_ENTRY * ListHead)
3533 {
3534 return (BOOLEAN)(ListHead->Flink == ListHead);
3535 }
3536
3537 FORCEINLINE
3538 PSINGLE_LIST_ENTRY
3539 PopEntryList(
3540 IN OUT PSINGLE_LIST_ENTRY ListHead)
3541 {
3542 PSINGLE_LIST_ENTRY FirstEntry;
3543 FirstEntry = ListHead->Next;
3544 if (FirstEntry != NULL) {
3545 ListHead->Next = FirstEntry->Next;
3546 }
3547 return FirstEntry;
3548 }
3549
3550 FORCEINLINE
3551 VOID
3552 PushEntryList(
3553 IN OUT PSINGLE_LIST_ENTRY ListHead,
3554 IN OUT PSINGLE_LIST_ENTRY Entry)
3555 {
3556 Entry->Next = ListHead->Next;
3557 ListHead->Next = Entry;
3558 }
3559
3560 FORCEINLINE
3561 BOOLEAN
3562 RemoveEntryList(
3563 IN PLIST_ENTRY Entry)
3564 {
3565 PLIST_ENTRY OldFlink;
3566 PLIST_ENTRY OldBlink;
3567
3568 OldFlink = Entry->Flink;
3569 OldBlink = Entry->Blink;
3570 OldFlink->Blink = OldBlink;
3571 OldBlink->Flink = OldFlink;
3572 return (BOOLEAN)(OldFlink == OldBlink);
3573 }
3574
3575 FORCEINLINE
3576 PLIST_ENTRY
3577 RemoveHeadList(
3578 IN OUT PLIST_ENTRY ListHead)
3579 {
3580 PLIST_ENTRY Flink;
3581 PLIST_ENTRY Entry;
3582
3583 Entry = ListHead->Flink;
3584 Flink = Entry->Flink;
3585 ListHead->Flink = Flink;
3586 Flink->Blink = ListHead;
3587 return Entry;
3588 }
3589
3590 FORCEINLINE
3591 PLIST_ENTRY
3592 RemoveTailList(
3593 IN OUT PLIST_ENTRY ListHead)
3594 {
3595 PLIST_ENTRY Blink;
3596 PLIST_ENTRY Entry;
3597
3598 Entry = ListHead->Blink;
3599 Blink = Entry->Blink;
3600 ListHead->Blink = Blink;
3601 Blink->Flink = ListHead;
3602 return Entry;
3603 }
3604
3605 NTSYSAPI
3606 VOID
3607 NTAPI
3608 RtlAssert(
3609 IN PVOID FailedAssertion,
3610 IN PVOID FileName,
3611 IN ULONG LineNumber,
3612 IN PCHAR Message);
3613
3614 /* VOID
3615 * RtlCopyMemory(
3616 * IN VOID UNALIGNED *Destination,
3617 * IN CONST VOID UNALIGNED *Source,
3618 * IN SIZE_T Length)
3619 */
3620 #define RtlCopyMemory(Destination, Source, Length) \
3621 memcpy(Destination, Source, Length)
3622
3623 #define RtlCopyBytes RtlCopyMemory
3624
3625 #if defined(_M_AMD64)
3626 NTSYSAPI
3627 VOID
3628 NTAPI
3629 RtlCopyMemoryNonTemporal(
3630 VOID UNALIGNED *Destination,
3631 CONST VOID UNALIGNED *Source,
3632 SIZE_T Length);
3633 #else
3634 #define RtlCopyMemoryNonTemporal RtlCopyMemory
3635 #endif
3636
3637 /* BOOLEAN
3638 * RtlEqualLuid(
3639 * IN PLUID Luid1,
3640 * IN PLUID Luid2)
3641 */
3642 #define RtlEqualLuid(Luid1, Luid2) \
3643 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
3644
3645 /* ULONG
3646 * RtlEqualMemory(
3647 * IN VOID UNALIGNED *Destination,
3648 * IN CONST VOID UNALIGNED *Source,
3649 * IN SIZE_T Length)
3650 */
3651 #define RtlEqualMemory(Destination, Source, Length) \
3652 (!memcmp(Destination, Source, Length))
3653
3654 /* VOID
3655 * RtlFillMemory(
3656 * IN VOID UNALIGNED *Destination,
3657 * IN SIZE_T Length,
3658 * IN UCHAR Fill)
3659 */
3660 #define RtlFillMemory(Destination, Length, Fill) \
3661 memset(Destination, Fill, Length)
3662
3663 #define RtlFillBytes RtlFillMemory
3664
3665 NTSYSAPI
3666 VOID
3667 NTAPI
3668 RtlFreeUnicodeString(
3669 IN PUNICODE_STRING UnicodeString);
3670
3671 NTSYSAPI
3672 NTSTATUS
3673 NTAPI
3674 RtlGUIDFromString(
3675 IN PUNICODE_STRING GuidString,
3676 OUT GUID *Guid);
3677
3678 NTSYSAPI
3679 VOID
3680 NTAPI
3681 RtlInitUnicodeString(
3682 IN OUT PUNICODE_STRING DestinationString,
3683 IN PCWSTR SourceString);
3684
3685 /* VOID
3686 * RtlMoveMemory(
3687 * IN VOID UNALIGNED *Destination,
3688 * IN CONST VOID UNALIGNED *Source,
3689 * IN SIZE_T Length)
3690 */
3691 #define RtlMoveMemory(Destination, Source, Length) \
3692 memmove(Destination, Source, Length)
3693
3694 NTSYSAPI
3695 NTSTATUS
3696 NTAPI
3697 RtlStringFromGUID(
3698 IN REFGUID Guid,
3699 OUT PUNICODE_STRING GuidString);
3700
3701 /* VOID
3702 * RtlZeroMemory(
3703 * IN VOID UNALIGNED *Destination,
3704 * IN SIZE_T Length)
3705 */
3706 #define RtlZeroMemory(Destination, Length) \
3707 memset(Destination, 0, Length)
3708
3709 #define RtlZeroBytes RtlZeroMemory
3710
3711
3712 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3713 NTSYSAPI
3714 BOOLEAN
3715 NTAPI
3716 RtlAreBitsClear(
3717 IN PRTL_BITMAP BitMapHeader,
3718 IN ULONG StartingIndex,
3719 IN ULONG Length);
3720
3721 NTSYSAPI
3722 BOOLEAN
3723 NTAPI
3724 RtlAreBitsSet(
3725 IN PRTL_BITMAP BitMapHeader,
3726 IN ULONG StartingIndex,
3727 IN ULONG Length);
3728
3729 NTSYSAPI
3730 NTSTATUS
3731 NTAPI
3732 RtlAnsiStringToUnicodeString(
3733 IN OUT PUNICODE_STRING DestinationString,
3734 IN PANSI_STRING SourceString,
3735 IN BOOLEAN AllocateDestinationString);
3736
3737 NTSYSAPI
3738 ULONG
3739 NTAPI
3740 RtlxAnsiStringToUnicodeSize(
3741 IN PCANSI_STRING AnsiString);
3742
3743 #define RtlAnsiStringToUnicodeSize(String) ( \
3744 NLS_MB_CODE_PAGE_TAG ? \
3745 RtlxAnsiStringToUnicodeSize(String) : \
3746 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
3747 )
3748
3749 NTSYSAPI
3750 NTSTATUS
3751 NTAPI
3752 RtlAppendUnicodeStringToString(
3753 IN OUT PUNICODE_STRING Destination,
3754 IN PCUNICODE_STRING Source);
3755
3756 NTSYSAPI
3757 NTSTATUS
3758 NTAPI
3759 RtlAppendUnicodeToString(
3760 IN OUT PUNICODE_STRING Destination,
3761 IN PCWSTR Source);
3762
3763 NTSYSAPI
3764 NTSTATUS
3765 NTAPI
3766 RtlCheckRegistryKey(
3767 IN ULONG RelativeTo,
3768 IN PWSTR Path);
3769
3770 NTSYSAPI
3771 VOID
3772 NTAPI
3773 RtlClearAllBits(
3774 IN PRTL_BITMAP BitMapHeader);
3775
3776 NTSYSAPI
3777 VOID
3778 NTAPI
3779 RtlClearBits(
3780 IN PRTL_BITMAP BitMapHeader,
3781 IN ULONG StartingIndex,
3782 IN ULONG NumberToClear);
3783
3784 NTSYSAPI
3785 SIZE_T
3786 NTAPI
3787 RtlCompareMemory(
3788 IN CONST VOID *Source1,
3789 IN CONST VOID *Source2,
3790 IN SIZE_T Length);
3791
3792 NTSYSAPI
3793 LONG
3794 NTAPI
3795 RtlCompareUnicodeString(
3796 IN PCUNICODE_STRING String1,
3797 IN PCUNICODE_STRING String2,
3798 IN BOOLEAN CaseInSensitive);
3799
3800 NTSYSAPI
3801 LONG
3802 NTAPI
3803 RtlCompareUnicodeStrings(
3804 IN PCWCH String1,
3805 IN SIZE_T String1Length,
3806 IN PCWCH String2,
3807 IN SIZE_T String2Length,
3808 IN BOOLEAN CaseInSensitive);
3809
3810 NTSYSAPI
3811 VOID
3812 NTAPI
3813 RtlCopyUnicodeString(
3814 IN OUT PUNICODE_STRING DestinationString,
3815 IN PCUNICODE_STRING SourceString);
3816
3817 NTSYSAPI
3818 NTSTATUS
3819 NTAPI
3820 RtlCreateRegistryKey(
3821 IN ULONG RelativeTo,
3822 IN PWSTR Path);
3823
3824 NTSYSAPI
3825 NTSTATUS
3826 NTAPI
3827 RtlCreateSecurityDescriptor(
3828 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3829 IN ULONG Revision);
3830
3831 NTSYSAPI
3832 NTSTATUS
3833 NTAPI
3834 RtlDeleteRegistryValue(
3835 IN ULONG RelativeTo,
3836 IN PCWSTR Path,
3837 IN PCWSTR ValueName);
3838
3839 NTSYSAPI
3840 BOOLEAN
3841 NTAPI
3842 RtlEqualUnicodeString(
3843 IN CONST UNICODE_STRING *String1,
3844 IN CONST UNICODE_STRING *String2,
3845 IN BOOLEAN CaseInSensitive);
3846
3847 #if !defined(_AMD64_) && !defined(_IA64_)
3848 NTSYSAPI
3849 LARGE_INTEGER
3850 NTAPI
3851 RtlExtendedIntegerMultiply(
3852 IN LARGE_INTEGER Multiplicand,
3853 IN LONG Multiplier);
3854
3855 NTSYSAPI
3856 LARGE_INTEGER
3857 NTAPI
3858 RtlExtendedLargeIntegerDivide(
3859 IN LARGE_INTEGER Dividend,
3860 IN ULONG Divisor,
3861 IN OUT PULONG Remainder);
3862 #endif
3863
3864 #if defined(_X86_) || defined(_IA64_)
3865 NTSYSAPI
3866 LARGE_INTEGER
3867 NTAPI
3868 RtlExtendedMagicDivide(
3869 IN LARGE_INTEGER Dividend,
3870 IN LARGE_INTEGER MagicDivisor,
3871 IN CCHAR ShiftCount);
3872 #endif
3873
3874 NTSYSAPI
3875 VOID
3876 NTAPI
3877 RtlFreeAnsiString(
3878 IN PANSI_STRING AnsiString);
3879
3880 NTSYSAPI
3881 ULONG
3882 NTAPI
3883 RtlFindClearBits(
3884 IN PRTL_BITMAP BitMapHeader,
3885 IN ULONG NumberToFind,
3886 IN ULONG HintIndex);
3887
3888 NTSYSAPI
3889 ULONG
3890 NTAPI
3891 RtlFindClearBitsAndSet(
3892 IN PRTL_BITMAP BitMapHeader,
3893 IN ULONG NumberToFind,
3894 IN ULONG HintIndex);
3895
3896 NTSYSAPI
3897 ULONG
3898 NTAPI
3899 RtlFindFirstRunClear(
3900 IN PRTL_BITMAP BitMapHeader,
3901 OUT PULONG StartingIndex);
3902
3903 NTSYSAPI
3904 ULONG
3905 NTAPI
3906 RtlFindClearRuns(
3907 IN PRTL_BITMAP BitMapHeader,
3908 OUT PRTL_BITMAP_RUN RunArray,
3909 IN ULONG SizeOfRunArray,
3910 IN BOOLEAN LocateLongestRuns);
3911
3912 NTSYSAPI
3913 ULONG
3914 NTAPI
3915 RtlFindLastBackwardRunClear(
3916 IN PRTL_BITMAP BitMapHeader,
3917 IN ULONG FromIndex,
3918 OUT PULONG StartingRunIndex);
3919
3920 NTSYSAPI
3921 CCHAR
3922 NTAPI
3923 RtlFindLeastSignificantBit(
3924 IN ULONGLONG Set);
3925
3926 NTSYSAPI
3927 ULONG
3928 NTAPI
3929 RtlFindLongestRunClear(
3930 IN PRTL_BITMAP BitMapHeader,
3931 OUT PULONG StartingIndex);
3932
3933 NTSYSAPI
3934 CCHAR
3935 NTAPI
3936 RtlFindMostSignificantBit(
3937 IN ULONGLONG Set);
3938
3939 NTSYSAPI
3940 ULONG
3941 NTAPI
3942 RtlFindNextForwardRunClear(
3943 IN PRTL_BITMAP BitMapHeader,
3944 IN ULONG FromIndex,
3945 OUT PULONG StartingRunIndex);
3946
3947 NTSYSAPI
3948 ULONG
3949 NTAPI
3950 RtlFindSetBits(
3951 IN PRTL_BITMAP BitMapHeader,
3952 IN ULONG NumberToFind,
3953 IN ULONG HintIndex);
3954
3955 NTSYSAPI
3956 ULONG
3957 NTAPI
3958 RtlFindSetBitsAndClear(
3959 IN PRTL_BITMAP BitMapHeader,
3960 IN ULONG NumberToFind,
3961 IN ULONG HintIndex);
3962
3963 NTSYSAPI
3964 NTSTATUS
3965 NTAPI
3966 RtlHashUnicodeString(
3967 IN CONST UNICODE_STRING *String,
3968 IN BOOLEAN CaseInSensitive,
3969 IN ULONG HashAlgorithm,
3970 OUT PULONG HashValue);
3971
3972 NTSYSAPI
3973 VOID
3974 NTAPI
3975 RtlInitAnsiString(
3976 IN OUT PANSI_STRING DestinationString,
3977 IN PCSZ SourceString);
3978
3979 NTSYSAPI
3980 VOID
3981 NTAPI
3982 RtlInitializeBitMap(
3983 IN PRTL_BITMAP BitMapHeader,
3984 IN PULONG BitMapBuffer,
3985 IN ULONG SizeOfBitMap);
3986
3987 NTSYSAPI
3988 VOID
3989 NTAPI
3990 RtlInitString(
3991 IN OUT PSTRING DestinationString,
3992 IN PCSZ SourceString);
3993
3994 NTSYSAPI
3995 NTSTATUS
3996 NTAPI
3997 RtlIntegerToUnicodeString(
3998 IN ULONG Value,
3999 IN ULONG Base OPTIONAL,
4000 IN OUT PUNICODE_STRING String);
4001
4002 NTSYSAPI
4003 NTSTATUS
4004 NTAPI
4005 RtlInt64ToUnicodeString(
4006 IN ULONGLONG Value,
4007 IN ULONG Base OPTIONAL,
4008 IN OUT PUNICODE_STRING String);
4009
4010 #ifdef _WIN64
4011 #define RtlIntPtrToUnicodeString(Value, Base, String) \
4012 RtlInt64ToUnicodeString(Value, Base, String)
4013 #else
4014 #define RtlIntPtrToUnicodeString(Value, Base, String) \
4015 RtlIntegerToUnicodeString(Value, Base, String)
4016 #endif
4017
4018 /* BOOLEAN
4019 * RtlIsZeroLuid(
4020 * IN PLUID L1);
4021 */
4022 #define RtlIsZeroLuid(_L1) \
4023 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
4024
4025 NTSYSAPI
4026 ULONG
4027 NTAPI
4028 RtlLengthSecurityDescriptor(
4029 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
4030
4031 NTSYSAPI
4032 ULONG
4033 NTAPI
4034 RtlNumberOfClearBits(
4035 IN PRTL_BITMAP BitMapHeader);
4036
4037 NTSYSAPI
4038 ULONG
4039 NTAPI
4040 RtlNumberOfSetBits(
4041 IN PRTL_BITMAP BitMapHeader);
4042
4043 NTSYSAPI
4044 NTSTATUS
4045 NTAPI
4046 RtlQueryRegistryValues(
4047 IN ULONG RelativeTo,
4048 IN PCWSTR Path,
4049 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
4050 IN PVOID Context,
4051 IN PVOID Environment OPTIONAL);
4052
4053 #define LONG_SIZE (sizeof(LONG))
4054 #define LONG_MASK (LONG_SIZE - 1)
4055
4056 /* VOID
4057 * RtlRetrieveUlong(
4058 * PULONG DestinationAddress,
4059 * PULONG SourceAddress);
4060 */
4061 #if defined(_AMD64_)
4062 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
4063 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
4064 #else
4065 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
4066 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
4067 { \
4068 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
4069 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
4070 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
4071 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
4072 } \
4073 else \
4074 { \
4075 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
4076 }
4077 #endif
4078
4079 /* VOID
4080 * RtlRetrieveUshort(
4081 * PUSHORT DestinationAddress,
4082 * PUSHORT SourceAddress);
4083 */
4084 #if defined(_AMD64_)