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