- Move more stuff to wdm.h
[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 /* PVOID MmGetSystemAddressForMdl(
1858 * IN PMDL Mdl);
1859 */
1860 #define MmGetSystemAddressForMdl(Mdl) \
1861 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
1862 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1863 ((Mdl)->MappedSystemVa) : \
1864 (MmMapLockedPages((Mdl), KernelMode)))
1865
1866 /* PVOID
1867 * MmGetSystemAddressForMdlSafe(
1868 * IN PMDL Mdl,
1869 * IN MM_PAGE_PRIORITY Priority)
1870 */
1871 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
1872 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
1873 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1874 (_Mdl)->MappedSystemVa : \
1875 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
1876 KernelMode, MmCached, NULL, FALSE, (_Priority)))
1877
1878 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1879 NTKERNELAPI
1880 PMDL
1881 NTAPI
1882 MmCreateMdl(
1883 IN PMDL MemoryDescriptorList OPTIONAL,
1884 IN PVOID Base,
1885 IN SIZE_T Length);
1886
1887 #endif
1888
1889 /******************************************************************************
1890 * Security Manager Types *
1891 ******************************************************************************/
1892
1893 /* Simple types */
1894 typedef PVOID PSECURITY_DESCRIPTOR;
1895 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
1896 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
1897 typedef PVOID PACCESS_TOKEN;
1898 typedef PVOID PSID;
1899
1900 #define DELETE 0x00010000L
1901 #define READ_CONTROL 0x00020000L
1902 #define WRITE_DAC 0x00040000L
1903 #define WRITE_OWNER 0x00080000L
1904 #define SYNCHRONIZE 0x00100000L
1905 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
1906 #define STANDARD_RIGHTS_READ READ_CONTROL
1907 #define STANDARD_RIGHTS_WRITE READ_CONTROL
1908 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
1909 #define STANDARD_RIGHTS_ALL 0x001F0000L
1910 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
1911 #define ACCESS_SYSTEM_SECURITY 0x01000000L
1912 #define MAXIMUM_ALLOWED 0x02000000L
1913 #define GENERIC_READ 0x80000000L
1914 #define GENERIC_WRITE 0x40000000L
1915 #define GENERIC_EXECUTE 0x20000000L
1916 #define GENERIC_ALL 0x10000000L
1917
1918 typedef struct _GENERIC_MAPPING {
1919 ACCESS_MASK GenericRead;
1920 ACCESS_MASK GenericWrite;
1921 ACCESS_MASK GenericExecute;
1922 ACCESS_MASK GenericAll;
1923 } GENERIC_MAPPING, *PGENERIC_MAPPING;
1924
1925 #define ACL_REVISION 2
1926 #define ACL_REVISION_DS 4
1927
1928 #define ACL_REVISION1 1
1929 #define ACL_REVISION2 2
1930 #define ACL_REVISION3 3
1931 #define ACL_REVISION4 4
1932 #define MIN_ACL_REVISION ACL_REVISION2
1933 #define MAX_ACL_REVISION ACL_REVISION4
1934
1935 typedef struct _ACL {
1936 UCHAR AclRevision;
1937 UCHAR Sbz1;
1938 USHORT AclSize;
1939 USHORT AceCount;
1940 USHORT Sbz2;
1941 } ACL, *PACL;
1942
1943 /* Current security descriptor revision value */
1944 #define SECURITY_DESCRIPTOR_REVISION (1)
1945 #define SECURITY_DESCRIPTOR_REVISION1 (1)
1946
1947 /* Privilege attributes */
1948 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
1949 #define SE_PRIVILEGE_ENABLED (0x00000002L)
1950 #define SE_PRIVILEGE_REMOVED (0X00000004L)
1951 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
1952
1953 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
1954 SE_PRIVILEGE_ENABLED | \
1955 SE_PRIVILEGE_REMOVED | \
1956 SE_PRIVILEGE_USED_FOR_ACCESS)
1957
1958 #include <pshpack4.h>
1959 typedef struct _LUID_AND_ATTRIBUTES {
1960 LUID Luid;
1961 ULONG Attributes;
1962 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
1963 #include <poppack.h>
1964
1965 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
1966 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
1967
1968 /* Privilege sets */
1969 #define PRIVILEGE_SET_ALL_NECESSARY (1)
1970
1971 typedef struct _PRIVILEGE_SET {
1972 ULONG PrivilegeCount;
1973 ULONG Control;
1974 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
1975 } PRIVILEGE_SET,*PPRIVILEGE_SET;
1976
1977 typedef enum _SECURITY_IMPERSONATION_LEVEL {
1978 SecurityAnonymous,
1979 SecurityIdentification,
1980 SecurityImpersonation,
1981 SecurityDelegation
1982 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
1983
1984 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
1985 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
1986 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
1987 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
1988
1989 #define SECURITY_DYNAMIC_TRACKING (TRUE)
1990 #define SECURITY_STATIC_TRACKING (FALSE)
1991
1992 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
1993
1994 typedef struct _SECURITY_QUALITY_OF_SERVICE {
1995 ULONG Length;
1996 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1997 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
1998 BOOLEAN EffectiveOnly;
1999 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
2000
2001 typedef struct _SE_IMPERSONATION_STATE {
2002 PACCESS_TOKEN Token;
2003 BOOLEAN CopyOnOpen;
2004 BOOLEAN EffectiveOnly;
2005 SECURITY_IMPERSONATION_LEVEL Level;
2006 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
2007
2008 #define OWNER_SECURITY_INFORMATION (0x00000001L)
2009 #define GROUP_SECURITY_INFORMATION (0x00000002L)
2010 #define DACL_SECURITY_INFORMATION (0x00000004L)
2011 #define SACL_SECURITY_INFORMATION (0x00000008L)
2012 #define LABEL_SECURITY_INFORMATION (0x00000010L)
2013
2014 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
2015 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
2016 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
2017 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
2018
2019 typedef enum _SECURITY_OPERATION_CODE {
2020 SetSecurityDescriptor,
2021 QuerySecurityDescriptor,
2022 DeleteSecurityDescriptor,
2023 AssignSecurityDescriptor
2024 } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
2025
2026 #define INITIAL_PRIVILEGE_COUNT 3
2027
2028 typedef struct _INITIAL_PRIVILEGE_SET {
2029 ULONG PrivilegeCount;
2030 ULONG Control;
2031 LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
2032 } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
2033
2034 #define SE_MIN_WELL_KNOWN_PRIVILEGE 2
2035 #define SE_CREATE_TOKEN_PRIVILEGE 2
2036 #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3
2037 #define SE_LOCK_MEMORY_PRIVILEGE 4
2038 #define SE_INCREASE_QUOTA_PRIVILEGE 5
2039 #define SE_MACHINE_ACCOUNT_PRIVILEGE 6
2040 #define SE_TCB_PRIVILEGE 7
2041 #define SE_SECURITY_PRIVILEGE 8
2042 #define SE_TAKE_OWNERSHIP_PRIVILEGE 9
2043 #define SE_LOAD_DRIVER_PRIVILEGE 10
2044 #define SE_SYSTEM_PROFILE_PRIVILEGE 11
2045 #define SE_SYSTEMTIME_PRIVILEGE 12
2046 #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13
2047 #define SE_INC_BASE_PRIORITY_PRIVILEGE 14
2048 #define SE_CREATE_PAGEFILE_PRIVILEGE 15
2049 #define SE_CREATE_PERMANENT_PRIVILEGE 16
2050 #define SE_BACKUP_PRIVILEGE 17
2051 #define SE_RESTORE_PRIVILEGE 18
2052 #define SE_SHUTDOWN_PRIVILEGE 19
2053 #define SE_DEBUG_PRIVILEGE 20
2054 #define SE_AUDIT_PRIVILEGE 21
2055 #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22
2056 #define SE_CHANGE_NOTIFY_PRIVILEGE 23
2057 #define SE_REMOTE_SHUTDOWN_PRIVILEGE 24
2058 #define SE_UNDOCK_PRIVILEGE 25
2059 #define SE_SYNC_AGENT_PRIVILEGE 26
2060 #define SE_ENABLE_DELEGATION_PRIVILEGE 27
2061 #define SE_MANAGE_VOLUME_PRIVILEGE 28
2062 #define SE_IMPERSONATE_PRIVILEGE 29
2063 #define SE_CREATE_GLOBAL_PRIVILEGE 30
2064 #define SE_TRUSTED_CREDMAN_ACCESS_PRIVILEGE 31
2065 #define SE_RELABEL_PRIVILEGE 32
2066 #define SE_INC_WORKING_SET_PRIVILEGE 33
2067 #define SE_TIME_ZONE_PRIVILEGE 34
2068 #define SE_CREATE_SYMBOLIC_LINK_PRIVILEGE 35
2069 #define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_SYMBOLIC_LINK_PRIVILEGE
2070
2071 typedef struct _SECURITY_SUBJECT_CONTEXT {
2072 PACCESS_TOKEN ClientToken;
2073 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2074 PACCESS_TOKEN PrimaryToken;
2075 PVOID ProcessAuditId;
2076 } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
2077
2078 typedef struct _ACCESS_STATE {
2079 LUID OperationID;
2080 BOOLEAN SecurityEvaluated;
2081 BOOLEAN GenerateAudit;
2082 BOOLEAN GenerateOnClose;
2083 BOOLEAN PrivilegesAllocated;
2084 ULONG Flags;
2085 ACCESS_MASK RemainingDesiredAccess;
2086 ACCESS_MASK PreviouslyGrantedAccess;
2087 ACCESS_MASK OriginalDesiredAccess;
2088 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
2089 PSECURITY_DESCRIPTOR SecurityDescriptor;
2090 PVOID AuxData;
2091 union {
2092 INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
2093 PRIVILEGE_SET PrivilegeSet;
2094 } Privileges;
2095
2096 BOOLEAN AuditPrivileges;
2097 UNICODE_STRING ObjectName;
2098 UNICODE_STRING ObjectTypeName;
2099 } ACCESS_STATE, *PACCESS_STATE;
2100
2101
2102 /******************************************************************************
2103 * Power Types *
2104 ******************************************************************************/
2105
2106
2107 /* Power States/Levels */
2108 typedef enum _SYSTEM_POWER_STATE {
2109 PowerSystemUnspecified,
2110 PowerSystemWorking,
2111 PowerSystemSleeping1,
2112 PowerSystemSleeping2,
2113 PowerSystemSleeping3,
2114 PowerSystemHibernate,
2115 PowerSystemShutdown,
2116 PowerSystemMaximum
2117 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
2118
2119 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
2120
2121 typedef enum _POWER_INFORMATION_LEVEL {
2122 SystemPowerPolicyAc,
2123 SystemPowerPolicyDc,
2124 VerifySystemPolicyAc,
2125 VerifySystemPolicyDc,
2126 SystemPowerCapabilities,
2127 SystemBatteryState,
2128 SystemPowerStateHandler,
2129 ProcessorStateHandler,
2130 SystemPowerPolicyCurrent,
2131 AdministratorPowerPolicy,
2132 SystemReserveHiberFile,
2133 ProcessorInformation,
2134 SystemPowerInformation,
2135 ProcessorStateHandler2,
2136 LastWakeTime,
2137 LastSleepTime,
2138 SystemExecutionState,
2139 SystemPowerStateNotifyHandler,
2140 ProcessorPowerPolicyAc,
2141 ProcessorPowerPolicyDc,
2142 VerifyProcessorPowerPolicyAc,
2143 VerifyProcessorPowerPolicyDc,
2144 ProcessorPowerPolicyCurrent
2145 } POWER_INFORMATION_LEVEL;
2146
2147 typedef enum {
2148 PowerActionNone,
2149 PowerActionReserved,
2150 PowerActionSleep,
2151 PowerActionHibernate,
2152 PowerActionShutdown,
2153 PowerActionShutdownReset,
2154 PowerActionShutdownOff,
2155 PowerActionWarmEject
2156 } POWER_ACTION, *PPOWER_ACTION;
2157
2158 typedef enum _DEVICE_POWER_STATE {
2159 PowerDeviceUnspecified,
2160 PowerDeviceD0,
2161 PowerDeviceD1,
2162 PowerDeviceD2,
2163 PowerDeviceD3,
2164 PowerDeviceMaximum
2165 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
2166
2167
2168 /******************************************************************************
2169 * Configuration Manager Types *
2170 ******************************************************************************/
2171
2172 /* Resource list definitions */
2173 typedef int CM_RESOURCE_TYPE;
2174
2175 #define CmResourceTypeNull 0
2176 #define CmResourceTypePort 1
2177 #define CmResourceTypeInterrupt 2
2178 #define CmResourceTypeMemory 3
2179 #define CmResourceTypeDma 4
2180 #define CmResourceTypeDeviceSpecific 5
2181 #define CmResourceTypeBusNumber 6
2182 #define CmResourceTypeNonArbitrated 128
2183 #define CmResourceTypeConfigData 128
2184 #define CmResourceTypeDevicePrivate 129
2185 #define CmResourceTypePcCardConfig 130
2186 #define CmResourceTypeMfCardConfig 131
2187
2188
2189 /* KEY_VALUE_Xxx.Type */
2190 #define REG_NONE 0
2191 #define REG_SZ 1
2192 #define REG_EXPAND_SZ 2
2193 #define REG_BINARY 3
2194 #define REG_DWORD 4
2195 #define REG_DWORD_LITTLE_ENDIAN 4
2196 #define REG_DWORD_BIG_ENDIAN 5
2197 #define REG_LINK 6
2198 #define REG_MULTI_SZ 7
2199 #define REG_RESOURCE_LIST 8
2200 #define REG_FULL_RESOURCE_DESCRIPTOR 9
2201 #define REG_RESOURCE_REQUIREMENTS_LIST 10
2202 #define REG_QWORD 11
2203 #define REG_QWORD_LITTLE_ENDIAN 11
2204
2205 /* Registry Access Rights */
2206 #define KEY_QUERY_VALUE (0x0001)
2207 #define KEY_SET_VALUE (0x0002)
2208 #define KEY_CREATE_SUB_KEY (0x0004)
2209 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
2210 #define KEY_NOTIFY (0x0010)
2211 #define KEY_CREATE_LINK (0x0020)
2212 #define KEY_WOW64_32KEY (0x0200)
2213 #define KEY_WOW64_64KEY (0x0100)
2214 #define KEY_WOW64_RES (0x0300)
2215
2216 #define KEY_READ ((STANDARD_RIGHTS_READ |\
2217 KEY_QUERY_VALUE |\
2218 KEY_ENUMERATE_SUB_KEYS |\
2219 KEY_NOTIFY) \
2220 & \
2221 (~SYNCHRONIZE))
2222
2223 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
2224 KEY_SET_VALUE |\
2225 KEY_CREATE_SUB_KEY) \
2226 & \
2227 (~SYNCHRONIZE))
2228
2229 #define KEY_EXECUTE ((KEY_READ) \
2230 & \
2231 (~SYNCHRONIZE))
2232
2233 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
2234 KEY_QUERY_VALUE |\
2235 KEY_SET_VALUE |\
2236 KEY_CREATE_SUB_KEY |\
2237 KEY_ENUMERATE_SUB_KEYS |\
2238 KEY_NOTIFY |\
2239 KEY_CREATE_LINK) \
2240 & \
2241 (~SYNCHRONIZE))
2242
2243 /* Registry Open/Create Options */
2244 #define REG_OPTION_RESERVED (0x00000000L)
2245 #define REG_OPTION_NON_VOLATILE (0x00000000L)
2246 #define REG_OPTION_VOLATILE (0x00000001L)
2247 #define REG_OPTION_CREATE_LINK (0x00000002L)
2248 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
2249 #define REG_OPTION_OPEN_LINK (0x00000008L)
2250
2251 #define REG_LEGAL_OPTION \
2252 (REG_OPTION_RESERVED |\
2253 REG_OPTION_NON_VOLATILE |\
2254 REG_OPTION_VOLATILE |\
2255 REG_OPTION_CREATE_LINK |\
2256 REG_OPTION_BACKUP_RESTORE |\
2257 REG_OPTION_OPEN_LINK)
2258
2259 /* Key creation/open disposition */
2260 #define REG_CREATED_NEW_KEY (0x00000001L)
2261 #define REG_OPENED_EXISTING_KEY (0x00000002L)
2262
2263 /* Key restore & hive load flags */
2264 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
2265 #define REG_REFRESH_HIVE (0x00000002L)
2266 #define REG_NO_LAZY_FLUSH (0x00000004L)
2267 #define REG_FORCE_RESTORE (0x00000008L)
2268 #define REG_APP_HIVE (0x00000010L)
2269 #define REG_PROCESS_PRIVATE (0x00000020L)
2270 #define REG_START_JOURNAL (0x00000040L)
2271 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
2272 #define REG_HIVE_NO_RM (0x00000100L)
2273 #define REG_HIVE_SINGLE_LOG (0x00000200L)
2274
2275 /* Unload Flags */
2276 #define REG_FORCE_UNLOAD 1
2277
2278 /* Notify Filter Values */
2279 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
2280 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
2281 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
2282 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
2283
2284 #define REG_LEGAL_CHANGE_FILTER \
2285 (REG_NOTIFY_CHANGE_NAME |\
2286 REG_NOTIFY_CHANGE_ATTRIBUTES |\
2287 REG_NOTIFY_CHANGE_LAST_SET |\
2288 REG_NOTIFY_CHANGE_SECURITY)
2289
2290 typedef struct _CM_FLOPPY_DEVICE_DATA {
2291 USHORT Version;
2292 USHORT Revision;
2293 CHAR Size[8];
2294 ULONG MaxDensity;
2295 ULONG MountDensity;
2296 UCHAR StepRateHeadUnloadTime;
2297 UCHAR HeadLoadTime;
2298 UCHAR MotorOffTime;
2299 UCHAR SectorLengthCode;
2300 UCHAR SectorPerTrack;
2301 UCHAR ReadWriteGapLength;
2302 UCHAR DataTransferLength;
2303 UCHAR FormatGapLength;
2304 UCHAR FormatFillCharacter;
2305 UCHAR HeadSettleTime;
2306 UCHAR MotorSettleTime;
2307 UCHAR MaximumTrackValue;
2308 UCHAR DataTransferRate;
2309 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
2310
2311 #include <pshpack4.h>
2312 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
2313 UCHAR Type;
2314 UCHAR ShareDisposition;
2315 USHORT Flags;
2316 union {
2317 struct {
2318 PHYSICAL_ADDRESS Start;
2319 ULONG Length;
2320 } Generic;
2321 struct {
2322 PHYSICAL_ADDRESS Start;
2323 ULONG Length;
2324 } Port;
2325 struct {
2326 ULONG Level;
2327 ULONG Vector;
2328 KAFFINITY Affinity;
2329 } Interrupt;
2330 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
2331 struct {
2332 __GNU_EXTENSION union {
2333 struct {
2334 USHORT Reserved;
2335 USHORT MessageCount;
2336 ULONG Vector;
2337 KAFFINITY Affinity;
2338 } Raw;
2339 struct {
2340 ULONG Level;
2341 ULONG Vector;
2342 KAFFINITY Affinity;
2343 } Translated;
2344 };
2345 } MessageInterrupt;
2346 #endif
2347 struct {
2348 PHYSICAL_ADDRESS Start;
2349 ULONG Length;
2350 } Memory;
2351 struct {
2352 ULONG Channel;
2353 ULONG Port;
2354 ULONG Reserved1;
2355 } Dma;
2356 struct {
2357 ULONG Data[3];
2358 } DevicePrivate;
2359 struct {
2360 ULONG Start;
2361 ULONG Length;
2362 ULONG Reserved;
2363 } BusNumber;
2364 struct {
2365 ULONG DataSize;
2366 ULONG Reserved1;
2367 ULONG Reserved2;
2368 } DeviceSpecificData;
2369 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
2370 struct {
2371 PHYSICAL_ADDRESS Start;
2372 ULONG Length40;
2373 } Memory40;
2374 struct {
2375 PHYSICAL_ADDRESS Start;
2376 ULONG Length48;
2377 } Memory48;
2378 struct {
2379 PHYSICAL_ADDRESS Start;
2380 ULONG Length64;
2381 } Memory64;
2382 #endif
2383 } u;
2384 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
2385 #include <poppack.h>
2386
2387 #include <pshpack1.h>
2388 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
2389
2390 #define CmResourceTypeNull 0
2391 #define CmResourceTypePort 1
2392 #define CmResourceTypeInterrupt 2
2393 #define CmResourceTypeMemory 3
2394 #define CmResourceTypeDma 4
2395 #define CmResourceTypeDeviceSpecific 5
2396 #define CmResourceTypeBusNumber 6
2397 #define CmResourceTypeMemoryLarge 7
2398 #define CmResourceTypeNonArbitrated 128
2399 #define CmResourceTypeConfigData 128
2400 #define CmResourceTypeDevicePrivate 129
2401 #define CmResourceTypePcCardConfig 130
2402 #define CmResourceTypeMfCardConfig 131
2403
2404 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
2405
2406 typedef enum _CM_SHARE_DISPOSITION {
2407 CmResourceShareUndetermined,
2408 CmResourceShareDeviceExclusive,
2409 CmResourceShareDriverExclusive,
2410 CmResourceShareShared
2411 } CM_SHARE_DISPOSITION;
2412
2413 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
2414
2415 #define CM_RESOURCE_PORT_MEMORY 0x0000
2416 #define CM_RESOURCE_PORT_IO 0x0001
2417 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
2418 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
2419 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
2420 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
2421 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
2422 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
2423 #define CM_RESOURCE_PORT_BAR 0x0100
2424
2425 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
2426
2427 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
2428 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
2429 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
2430 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
2431
2432 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
2433
2434 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
2435 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
2436 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
2437 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
2438 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
2439 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
2440 #define CM_RESOURCE_MEMORY_24 0x0010
2441 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
2442 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
2443 #define CM_RESOURCE_MEMORY_BAR 0x0080
2444 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
2445
2446 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
2447
2448 #define CM_RESOURCE_DMA_8 0x0000
2449 #define CM_RESOURCE_DMA_16 0x0001
2450 #define CM_RESOURCE_DMA_32 0x0002
2451 #define CM_RESOURCE_DMA_8_AND_16 0x0004
2452 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
2453 #define CM_RESOURCE_DMA_TYPE_A 0x0010
2454 #define CM_RESOURCE_DMA_TYPE_B 0x0020
2455 #define CM_RESOURCE_DMA_TYPE_F 0x0040
2456
2457 typedef struct _CM_PARTIAL_RESOURCE_LIST {
2458 USHORT Version;
2459 USHORT Revision;
2460 ULONG Count;
2461 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
2462 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
2463
2464 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
2465 INTERFACE_TYPE InterfaceType;
2466 ULONG BusNumber;
2467 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
2468 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
2469
2470 typedef struct _CM_RESOURCE_LIST {
2471 ULONG Count;
2472 CM_FULL_RESOURCE_DESCRIPTOR List[1];
2473 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
2474
2475 typedef struct _CM_INT13_DRIVE_PARAMETER {
2476 USHORT DriveSelect;
2477 ULONG MaxCylinders;
2478 USHORT SectorsPerTrack;
2479 USHORT MaxHeads;
2480 USHORT NumberDrives;
2481 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
2482
2483 typedef struct _CM_PNP_BIOS_DEVICE_NODE
2484 {
2485 USHORT Size;
2486 UCHAR Node;
2487 ULONG ProductId;
2488 UCHAR DeviceType[3];
2489 USHORT DeviceAttributes;
2490 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
2491
2492 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
2493 {
2494 UCHAR Signature[4];
2495 UCHAR Revision;
2496 UCHAR Length;
2497 USHORT ControlField;
2498 UCHAR Checksum;
2499 ULONG EventFlagAddress;
2500 USHORT RealModeEntryOffset;
2501 USHORT RealModeEntrySegment;
2502 USHORT ProtectedModeEntryOffset;
2503 ULONG ProtectedModeCodeBaseAddress;
2504 ULONG OemDeviceId;
2505 USHORT RealModeDataBaseAddress;
2506 ULONG ProtectedModeDataBaseAddress;
2507 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
2508
2509 #include <poppack.h>
2510
2511 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
2512 {
2513 ULONG BytesPerSector;
2514 ULONG NumberOfCylinders;
2515 ULONG SectorsPerTrack;
2516 ULONG NumberOfHeads;
2517 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
2518
2519 typedef struct _CM_KEYBOARD_DEVICE_DATA {
2520 USHORT Version;
2521 USHORT Revision;
2522 UCHAR Type;
2523 UCHAR Subtype;
2524 USHORT KeyboardFlags;
2525 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
2526
2527 typedef struct _CM_MCA_POS_DATA {
2528 USHORT AdapterId;
2529 UCHAR PosData1;
2530 UCHAR PosData2;
2531 UCHAR PosData3;
2532 UCHAR PosData4;
2533 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
2534
2535 #if (NTDDI_VERSION >= NTDDI_WINXP)
2536 typedef struct CM_Power_Data_s {
2537 ULONG PD_Size;
2538 DEVICE_POWER_STATE PD_MostRecentPowerState;
2539 ULONG PD_Capabilities;
2540 ULONG PD_D1Latency;
2541 ULONG PD_D2Latency;
2542 ULONG PD_D3Latency;
2543 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
2544 SYSTEM_POWER_STATE PD_DeepestSystemWake;
2545 } CM_POWER_DATA, *PCM_POWER_DATA;
2546
2547 #define PDCAP_D0_SUPPORTED 0x00000001
2548 #define PDCAP_D1_SUPPORTED 0x00000002
2549 #define PDCAP_D2_SUPPORTED 0x00000004
2550 #define PDCAP_D3_SUPPORTED 0x00000008
2551 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
2552 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
2553 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
2554 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
2555 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
2556
2557 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
2558
2559 typedef struct _CM_SCSI_DEVICE_DATA {
2560 USHORT Version;
2561 USHORT Revision;
2562 UCHAR HostIdentifier;
2563 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
2564
2565 typedef struct _CM_SERIAL_DEVICE_DATA {
2566 USHORT Version;
2567 USHORT Revision;
2568 ULONG BaudClock;
2569 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
2570
2571 typedef enum _KEY_INFORMATION_CLASS {
2572 KeyBasicInformation,
2573 KeyNodeInformation,
2574 KeyFullInformation,
2575 KeyNameInformation,
2576 KeyCachedInformation,
2577 KeyFlagsInformation
2578 } KEY_INFORMATION_CLASS;
2579
2580 typedef struct _KEY_BASIC_INFORMATION {
2581 LARGE_INTEGER LastWriteTime;
2582 ULONG TitleIndex;
2583 ULONG NameLength;
2584 WCHAR Name[1];
2585 } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
2586
2587 typedef struct _KEY_FULL_INFORMATION {
2588 LARGE_INTEGER LastWriteTime;
2589 ULONG TitleIndex;
2590 ULONG ClassOffset;
2591 ULONG ClassLength;
2592 ULONG SubKeys;
2593 ULONG MaxNameLen;
2594 ULONG MaxClassLen;
2595 ULONG Values;
2596 ULONG MaxValueNameLen;
2597 ULONG MaxValueDataLen;
2598 WCHAR Class[1];
2599 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
2600
2601 typedef struct _KEY_NODE_INFORMATION {
2602 LARGE_INTEGER LastWriteTime;
2603 ULONG TitleIndex;
2604 ULONG ClassOffset;
2605 ULONG ClassLength;
2606 ULONG NameLength;
2607 WCHAR Name[1];
2608 } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
2609
2610 typedef struct _KEY_VALUE_BASIC_INFORMATION {
2611 ULONG TitleIndex;
2612 ULONG Type;
2613 ULONG NameLength;
2614 WCHAR Name[1];
2615 } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
2616
2617 typedef struct _KEY_VALUE_FULL_INFORMATION {
2618 ULONG TitleIndex;
2619 ULONG Type;
2620 ULONG DataOffset;
2621 ULONG DataLength;
2622 ULONG NameLength;
2623 WCHAR Name[1];
2624 } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
2625
2626 typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
2627 ULONG TitleIndex;
2628 ULONG Type;
2629 ULONG DataLength;
2630 UCHAR Data[1];
2631 } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
2632
2633 typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
2634 ULONG Type;
2635 ULONG DataLength;
2636 UCHAR Data[1];
2637 } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
2638
2639 typedef struct _KEY_VALUE_ENTRY {
2640 PUNICODE_STRING ValueName;
2641 ULONG DataLength;
2642 ULONG DataOffset;
2643 ULONG Type;
2644 } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
2645
2646 typedef enum _KEY_VALUE_INFORMATION_CLASS {
2647 KeyValueBasicInformation,
2648 KeyValueFullInformation,
2649 KeyValuePartialInformation,
2650 KeyValueFullInformationAlign64,
2651 KeyValuePartialInformationAlign64
2652 } KEY_VALUE_INFORMATION_CLASS;
2653
2654 typedef struct _KEY_WRITE_TIME_INFORMATION {
2655 LARGE_INTEGER LastWriteTime;
2656 } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
2657
2658 typedef enum _KEY_SET_INFORMATION_CLASS {
2659 KeyWriteTimeInformation,
2660 KeyWow64FlagsInformation,
2661 KeyControlFlagsInformation,
2662 KeySetVirtualizationInformation,
2663 KeySetDebugInformation,
2664 KeySetHandleTagsInformation,
2665 MaxKeySetInfoClass
2666 } KEY_SET_INFORMATION_CLASS;
2667
2668 typedef enum _REG_NOTIFY_CLASS {
2669 RegNtDeleteKey,
2670 RegNtPreDeleteKey = RegNtDeleteKey,
2671 RegNtSetValueKey,
2672 RegNtPreSetValueKey = RegNtSetValueKey,
2673 RegNtDeleteValueKey,
2674 RegNtPreDeleteValueKey = RegNtDeleteValueKey,
2675 RegNtSetInformationKey,
2676 RegNtPreSetInformationKey = RegNtSetInformationKey,
2677 RegNtRenameKey,
2678 RegNtPreRenameKey = RegNtRenameKey,
2679 RegNtEnumerateKey,
2680 RegNtPreEnumerateKey = RegNtEnumerateKey,
2681 RegNtEnumerateValueKey,
2682 RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
2683 RegNtQueryKey,
2684 RegNtPreQueryKey = RegNtQueryKey,
2685 RegNtQueryValueKey,
2686 RegNtPreQueryValueKey = RegNtQueryValueKey,
2687 RegNtQueryMultipleValueKey,
2688 RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
2689 RegNtPreCreateKey,
2690 RegNtPostCreateKey,
2691 RegNtPreOpenKey,
2692 RegNtPostOpenKey,
2693 RegNtKeyHandleClose,
2694 RegNtPreKeyHandleClose = RegNtKeyHandleClose,
2695 RegNtPostDeleteKey,
2696 RegNtPostSetValueKey,
2697 RegNtPostDeleteValueKey,
2698 RegNtPostSetInformationKey,
2699 RegNtPostRenameKey,
2700 RegNtPostEnumerateKey,
2701 RegNtPostEnumerateValueKey,
2702 RegNtPostQueryKey,
2703 RegNtPostQueryValueKey,
2704 RegNtPostQueryMultipleValueKey,
2705 RegNtPostKeyHandleClose,
2706 RegNtPreCreateKeyEx,
2707 RegNtPostCreateKeyEx,
2708 RegNtPreOpenKeyEx,
2709 RegNtPostOpenKeyEx,
2710 RegNtPreFlushKey,
2711 RegNtPostFlushKey,
2712 RegNtPreLoadKey,
2713 RegNtPostLoadKey,
2714 RegNtPreUnLoadKey,
2715 RegNtPostUnLoadKey,
2716 RegNtPreQueryKeySecurity,
2717 RegNtPostQueryKeySecurity,
2718 RegNtPreSetKeySecurity,
2719 RegNtPostSetKeySecurity,
2720 RegNtCallbackObjectContextCleanup,
2721 RegNtPreRestoreKey,
2722 RegNtPostRestoreKey,
2723 RegNtPreSaveKey,
2724 RegNtPostSaveKey,
2725 RegNtPreReplaceKey,
2726 RegNtPostReplaceKey,
2727 MaxRegNtNotifyClass
2728 } REG_NOTIFY_CLASS, *PREG_NOTIFY_CLASS;
2729
2730 typedef NTSTATUS
2731 (NTAPI *PEX_CALLBACK_FUNCTION)(
2732 IN PVOID CallbackContext,
2733 IN PVOID Argument1,
2734 IN PVOID Argument2
2735 );
2736
2737 typedef struct _REG_DELETE_KEY_INFORMATION {
2738 PVOID Object;
2739 PVOID CallContext;
2740 PVOID ObjectContext;
2741 PVOID Reserved;
2742 } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION
2743 #if (NTDDI_VERSION >= NTDDI_VISTA)
2744 , REG_FLUSH_KEY_INFORMATION, *PREG_FLUSH_KEY_INFORMATION
2745 #endif
2746 ;
2747
2748 typedef struct _REG_SET_VALUE_KEY_INFORMATION {
2749 PVOID Object;
2750 PUNICODE_STRING ValueName;
2751 ULONG TitleIndex;
2752 ULONG Type;
2753 PVOID Data;
2754 ULONG DataSize;
2755 PVOID CallContext;
2756 PVOID ObjectContext;
2757 PVOID Reserved;
2758 } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
2759
2760 typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
2761 PVOID Object;
2762 PUNICODE_STRING ValueName;
2763 PVOID CallContext;
2764 PVOID ObjectContext;
2765 PVOID Reserved;
2766 } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
2767
2768 typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
2769 PVOID Object;
2770 KEY_SET_INFORMATION_CLASS KeySetInformationClass;
2771 PVOID KeySetInformation;
2772 ULONG KeySetInformationLength;
2773 PVOID CallContext;
2774 PVOID ObjectContext;
2775 PVOID Reserved;
2776 } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
2777
2778 typedef struct _REG_ENUMERATE_KEY_INFORMATION {
2779 PVOID Object;
2780 ULONG Index;
2781 KEY_INFORMATION_CLASS KeyInformationClass;
2782 PVOID KeyInformation;
2783 ULONG Length;
2784 PULONG ResultLength;
2785 PVOID CallContext;
2786 PVOID ObjectContext;
2787 PVOID Reserved;
2788 } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
2789
2790 typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
2791 PVOID Object;
2792 ULONG Index;
2793 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
2794 PVOID KeyValueInformation;
2795 ULONG Length;
2796 PULONG ResultLength;
2797 PVOID CallContext;
2798 PVOID ObjectContext;
2799 PVOID Reserved;
2800 } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
2801
2802 typedef struct _REG_QUERY_KEY_INFORMATION {
2803 PVOID Object;
2804 KEY_INFORMATION_CLASS KeyInformationClass;
2805 PVOID KeyInformation;
2806 ULONG Length;
2807 PULONG ResultLength;
2808 PVOID CallContext;
2809 PVOID ObjectContext;
2810 PVOID Reserved;
2811 } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
2812
2813 typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
2814 PVOID Object;
2815 PUNICODE_STRING ValueName;
2816 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
2817 PVOID KeyValueInformation;
2818 ULONG Length;
2819 PULONG ResultLength;
2820 PVOID CallContext;
2821 PVOID ObjectContext;
2822 PVOID Reserved;
2823 } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
2824
2825 typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
2826 PVOID Object;
2827 PKEY_VALUE_ENTRY ValueEntries;
2828 ULONG EntryCount;
2829 PVOID ValueBuffer;
2830 PULONG BufferLength;
2831 PULONG RequiredBufferLength;
2832 PVOID CallContext;
2833 PVOID ObjectContext;
2834 PVOID Reserved;
2835 } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
2836
2837 typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
2838 PUNICODE_STRING CompleteName;
2839 } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
2840
2841 typedef struct _REG_POST_CREATE_KEY_INFORMATION {
2842 PUNICODE_STRING CompleteName;
2843 PVOID Object;
2844 NTSTATUS Status;
2845 } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
2846
2847 typedef struct _REG_POST_OPERATION_INFORMATION {
2848 PVOID Object;
2849 NTSTATUS Status;
2850 PVOID PreInformation;
2851 NTSTATUS ReturnStatus;
2852 PVOID CallContext;
2853 PVOID ObjectContext;
2854 PVOID Reserved;
2855 } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
2856
2857 typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
2858 PVOID Object;
2859 PVOID CallContext;
2860 PVOID ObjectContext;
2861 PVOID Reserved;
2862 } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
2863
2864
2865 /******************************************************************************
2866 * Configuration Manager Functions *
2867 ******************************************************************************/
2868
2869 #if (NTDDI_VERSION >= NTDDI_WINXP)
2870 NTKERNELAPI
2871 NTSTATUS
2872 NTAPI
2873 CmRegisterCallback(
2874 IN PEX_CALLBACK_FUNCTION Function,
2875 IN PVOID Context OPTIONAL,
2876 OUT PLARGE_INTEGER Cookie);
2877
2878 NTKERNELAPI
2879 NTSTATUS
2880 NTAPI
2881 CmUnRegisterCallback(
2882 IN LARGE_INTEGER Cookie);
2883 #endif
2884
2885
2886 /******************************************************************************
2887 * RTL Types *
2888 ******************************************************************************/
2889
2890 #define RTL_REGISTRY_ABSOLUTE 0
2891 #define RTL_REGISTRY_SERVICES 1
2892 #define RTL_REGISTRY_CONTROL 2
2893 #define RTL_REGISTRY_WINDOWS_NT 3
2894 #define RTL_REGISTRY_DEVICEMAP 4
2895 #define RTL_REGISTRY_USER 5
2896 #define RTL_REGISTRY_MAXIMUM 6
2897 #define RTL_REGISTRY_HANDLE 0x40000000
2898 #define RTL_REGISTRY_OPTIONAL 0x80000000
2899
2900 /* RTL_QUERY_REGISTRY_TABLE.Flags */
2901 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
2902 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
2903 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
2904 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
2905 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
2906 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
2907 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
2908
2909 #define HASH_STRING_ALGORITHM_DEFAULT 0
2910 #define HASH_STRING_ALGORITHM_X65599 1
2911 #define HASH_STRING_ALGORITHM_INVALID 0xffffffff
2912
2913 typedef struct _RTL_BITMAP {
2914 ULONG SizeOfBitMap;
2915 PULONG Buffer;
2916 } RTL_BITMAP, *PRTL_BITMAP;
2917
2918 typedef struct _RTL_BITMAP_RUN {
2919 ULONG StartingIndex;
2920 ULONG NumberOfBits;
2921 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
2922
2923 typedef NTSTATUS
2924 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
2925 IN PWSTR ValueName,
2926 IN ULONG ValueType,
2927 IN PVOID ValueData,
2928 IN ULONG ValueLength,
2929 IN PVOID Context,
2930 IN PVOID EntryContext);
2931
2932 typedef struct _RTL_QUERY_REGISTRY_TABLE {
2933 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
2934 ULONG Flags;
2935 PCWSTR Name;
2936 PVOID EntryContext;
2937 ULONG DefaultType;
2938 PVOID DefaultData;
2939 ULONG DefaultLength;
2940 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
2941
2942 typedef struct _TIME_FIELDS {
2943 CSHORT Year;
2944 CSHORT Month;
2945 CSHORT Day;
2946 CSHORT Hour;
2947 CSHORT Minute;
2948 CSHORT Second;
2949 CSHORT Milliseconds;
2950 CSHORT Weekday;
2951 } TIME_FIELDS, *PTIME_FIELDS;
2952
2953 /* Slist Header */
2954 #ifndef _SLIST_HEADER_
2955 #define _SLIST_HEADER_
2956
2957 #if defined(_WIN64)
2958 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
2959 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
2960 PSLIST_ENTRY Next;
2961 } SLIST_ENTRY;
2962 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
2963 struct {
2964 ULONGLONG Alignment;
2965 ULONGLONG Region;
2966 } DUMMYSTRUCTNAME;
2967 struct {
2968 ULONGLONG Depth:16;
2969 ULONGLONG Sequence:9;
2970 ULONGLONG NextEntry:39;
2971 ULONGLONG HeaderType:1;
2972 ULONGLONG Init:1;
2973 ULONGLONG Reserved:59;
2974 ULONGLONG Region:3;
2975 } Header8;
2976 struct {
2977 ULONGLONG Depth:16;
2978 ULONGLONG Sequence:48;
2979 ULONGLONG HeaderType:1;
2980 ULONGLONG Init:1;
2981 ULONGLONG Reserved:2;
2982 ULONGLONG NextEntry:60;
2983 } Header16;
2984 } SLIST_HEADER, *PSLIST_HEADER;
2985 #else
2986 #define SLIST_ENTRY SINGLE_LIST_ENTRY
2987 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
2988 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
2989 typedef union _SLIST_HEADER {
2990 ULONGLONG Alignment;
2991 struct {
2992 SLIST_ENTRY Next;
2993 USHORT Depth;
2994 USHORT Sequence;
2995 } DUMMYSTRUCTNAME;
2996 } SLIST_HEADER, *PSLIST_HEADER;
2997 #endif
2998
2999 #endif /* _SLIST_HEADER_ */
3000
3001
3002 /******************************************************************************
3003 * RTL Functions *
3004 ******************************************************************************/
3005
3006 FORCEINLINE
3007 VOID
3008 InitializeListHead(
3009 OUT PLIST_ENTRY ListHead)
3010 {
3011 ListHead->Flink = ListHead->Blink = ListHead;
3012 }
3013
3014 FORCEINLINE
3015 VOID
3016 InsertHeadList(
3017 IN OUT PLIST_ENTRY ListHead,
3018 IN OUT PLIST_ENTRY Entry)
3019 {
3020 PLIST_ENTRY OldFlink;
3021 OldFlink = ListHead->Flink;
3022 Entry->Flink = OldFlink;
3023 Entry->Blink = ListHead;
3024 OldFlink->Blink = Entry;
3025 ListHead->Flink = Entry;
3026 }
3027
3028 FORCEINLINE
3029 VOID
3030 InsertTailList(
3031 IN OUT PLIST_ENTRY ListHead,
3032 IN OUT PLIST_ENTRY Entry)
3033 {
3034 PLIST_ENTRY OldBlink;
3035 OldBlink = ListHead->Blink;
3036 Entry->Flink = ListHead;
3037 Entry->Blink = OldBlink;
3038 OldBlink->Flink = Entry;
3039 ListHead->Blink = Entry;
3040 }
3041
3042 BOOLEAN
3043 FORCEINLINE
3044 IsListEmpty(
3045 IN CONST LIST_ENTRY * ListHead)
3046 {
3047 return (BOOLEAN)(ListHead->Flink == ListHead);
3048 }
3049
3050 FORCEINLINE
3051 PSINGLE_LIST_ENTRY
3052 PopEntryList(
3053 IN OUT PSINGLE_LIST_ENTRY ListHead)
3054 {
3055 PSINGLE_LIST_ENTRY FirstEntry;
3056 FirstEntry = ListHead->Next;
3057 if (FirstEntry != NULL) {
3058 ListHead->Next = FirstEntry->Next;
3059 }
3060 return FirstEntry;
3061 }
3062
3063 FORCEINLINE
3064 VOID
3065 PushEntryList(
3066 IN OUT PSINGLE_LIST_ENTRY ListHead,
3067 IN OUT PSINGLE_LIST_ENTRY Entry)
3068 {
3069 Entry->Next = ListHead->Next;
3070 ListHead->Next = Entry;
3071 }
3072
3073 FORCEINLINE
3074 BOOLEAN
3075 RemoveEntryList(
3076 IN PLIST_ENTRY Entry)
3077 {
3078 PLIST_ENTRY OldFlink;
3079 PLIST_ENTRY OldBlink;
3080
3081 OldFlink = Entry->Flink;
3082 OldBlink = Entry->Blink;
3083 OldFlink->Blink = OldBlink;
3084 OldBlink->Flink = OldFlink;
3085 return (BOOLEAN)(OldFlink == OldBlink);
3086 }
3087
3088 FORCEINLINE
3089 PLIST_ENTRY
3090 RemoveHeadList(
3091 IN OUT PLIST_ENTRY ListHead)
3092 {
3093 PLIST_ENTRY Flink;
3094 PLIST_ENTRY Entry;
3095
3096 Entry = ListHead->Flink;
3097 Flink = Entry->Flink;
3098 ListHead->Flink = Flink;
3099 Flink->Blink = ListHead;
3100 return Entry;
3101 }
3102
3103 FORCEINLINE
3104 PLIST_ENTRY
3105 RemoveTailList(
3106 IN OUT PLIST_ENTRY ListHead)
3107 {
3108 PLIST_ENTRY Blink;
3109 PLIST_ENTRY Entry;
3110
3111 Entry = ListHead->Blink;
3112 Blink = Entry->Blink;
3113 ListHead->Blink = Blink;
3114 Blink->Flink = ListHead;
3115 return Entry;
3116 }
3117
3118 NTSYSAPI
3119 VOID
3120 NTAPI
3121 RtlAssert(
3122 IN PVOID FailedAssertion,
3123 IN PVOID FileName,
3124 IN ULONG LineNumber,
3125 IN PCHAR Message);
3126
3127 /* VOID
3128 * RtlCopyMemory(
3129 * IN VOID UNALIGNED *Destination,
3130 * IN CONST VOID UNALIGNED *Source,
3131 * IN SIZE_T Length)
3132 */
3133 #define RtlCopyMemory(Destination, Source, Length) \
3134 memcpy(Destination, Source, Length)
3135
3136 #define RtlCopyBytes RtlCopyMemory
3137
3138 #if defined(_M_AMD64)
3139 NTSYSAPI
3140 VOID
3141 NTAPI
3142 RtlCopyMemoryNonTemporal(
3143 VOID UNALIGNED *Destination,
3144 CONST VOID UNALIGNED *Source,
3145 SIZE_T Length);
3146 #else
3147 #define RtlCopyMemoryNonTemporal RtlCopyMemory
3148 #endif
3149
3150 /* BOOLEAN
3151 * RtlEqualLuid(
3152 * IN PLUID Luid1,
3153 * IN PLUID Luid2)
3154 */
3155 #define RtlEqualLuid(Luid1, Luid2) \
3156 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
3157
3158 /* ULONG
3159 * RtlEqualMemory(
3160 * IN VOID UNALIGNED *Destination,
3161 * IN CONST VOID UNALIGNED *Source,
3162 * IN SIZE_T Length)
3163 */
3164 #define RtlEqualMemory(Destination, Source, Length) \
3165 (!memcmp(Destination, Source, Length))
3166
3167 /* VOID
3168 * RtlFillMemory(
3169 * IN VOID UNALIGNED *Destination,
3170 * IN SIZE_T Length,
3171 * IN UCHAR Fill)
3172 */
3173 #define RtlFillMemory(Destination, Length, Fill) \
3174 memset(Destination, Fill, Length)
3175
3176 #define RtlFillBytes RtlFillMemory
3177
3178 NTSYSAPI
3179 VOID
3180 NTAPI
3181 RtlFreeUnicodeString(
3182 IN PUNICODE_STRING UnicodeString);
3183
3184 NTSYSAPI
3185 NTSTATUS
3186 NTAPI
3187 RtlGUIDFromString(
3188 IN PUNICODE_STRING GuidString,
3189 OUT GUID *Guid);
3190
3191 NTSYSAPI
3192 VOID
3193 NTAPI
3194 RtlInitUnicodeString(
3195 IN OUT PUNICODE_STRING DestinationString,
3196 IN PCWSTR SourceString);
3197
3198 /* VOID
3199 * RtlMoveMemory(
3200 * IN VOID UNALIGNED *Destination,
3201 * IN CONST VOID UNALIGNED *Source,
3202 * IN SIZE_T Length)
3203 */
3204 #define RtlMoveMemory(Destination, Source, Length) \
3205 memmove(Destination, Source, Length)
3206
3207 NTSYSAPI
3208 NTSTATUS
3209 NTAPI
3210 RtlStringFromGUID(
3211 IN REFGUID Guid,
3212 OUT PUNICODE_STRING GuidString);
3213
3214 /* VOID
3215 * RtlZeroMemory(
3216 * IN VOID UNALIGNED *Destination,
3217 * IN SIZE_T Length)
3218 */
3219 #define RtlZeroMemory(Destination, Length) \
3220 memset(Destination, 0, Length)
3221
3222 #define RtlZeroBytes RtlZeroMemory
3223
3224
3225 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3226 NTSYSAPI
3227 BOOLEAN
3228 NTAPI
3229 RtlAreBitsClear(
3230 IN PRTL_BITMAP BitMapHeader,
3231 IN ULONG StartingIndex,
3232 IN ULONG Length);
3233
3234 NTSYSAPI
3235 BOOLEAN
3236 NTAPI
3237 RtlAreBitsSet(
3238 IN PRTL_BITMAP BitMapHeader,
3239 IN ULONG StartingIndex,
3240 IN ULONG Length);
3241
3242 NTSYSAPI
3243 NTSTATUS
3244 NTAPI
3245 RtlAnsiStringToUnicodeString(
3246 IN OUT PUNICODE_STRING DestinationString,
3247 IN PANSI_STRING SourceString,
3248 IN BOOLEAN AllocateDestinationString);
3249
3250 NTSYSAPI
3251 ULONG
3252 NTAPI
3253 RtlxAnsiStringToUnicodeSize(
3254 IN PCANSI_STRING AnsiString);
3255
3256 #define RtlAnsiStringToUnicodeSize(String) ( \
3257 NLS_MB_CODE_PAGE_TAG ? \
3258 RtlxAnsiStringToUnicodeSize(String) : \
3259 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
3260 )
3261
3262 NTSYSAPI
3263 NTSTATUS
3264 NTAPI
3265 RtlAppendUnicodeStringToString(
3266 IN OUT PUNICODE_STRING Destination,
3267 IN PCUNICODE_STRING Source);
3268
3269 NTSYSAPI
3270 NTSTATUS
3271 NTAPI
3272 RtlAppendUnicodeToString(
3273 IN OUT PUNICODE_STRING Destination,
3274 IN PCWSTR Source);
3275
3276 NTSYSAPI
3277 NTSTATUS
3278 NTAPI
3279 RtlCheckRegistryKey(
3280 IN ULONG RelativeTo,
3281 IN PWSTR Path);
3282
3283 NTSYSAPI
3284 VOID
3285 NTAPI
3286 RtlClearAllBits(
3287 IN PRTL_BITMAP BitMapHeader);
3288
3289 NTSYSAPI
3290 VOID
3291 NTAPI
3292 RtlClearBits(
3293 IN PRTL_BITMAP BitMapHeader,
3294 IN ULONG StartingIndex,
3295 IN ULONG NumberToClear);
3296
3297 NTSYSAPI
3298 SIZE_T
3299 NTAPI
3300 RtlCompareMemory(
3301 IN CONST VOID *Source1,
3302 IN CONST VOID *Source2,
3303 IN SIZE_T Length);
3304
3305 NTSYSAPI
3306 LONG
3307 NTAPI
3308 RtlCompareUnicodeString(
3309 IN PCUNICODE_STRING String1,
3310 IN PCUNICODE_STRING String2,
3311 IN BOOLEAN CaseInSensitive);
3312
3313 NTSYSAPI
3314 LONG
3315 NTAPI
3316 RtlCompareUnicodeStrings(
3317 IN PCWCH String1,
3318 IN SIZE_T String1Length,
3319 IN PCWCH String2,
3320 IN SIZE_T String2Length,
3321 IN BOOLEAN CaseInSensitive);
3322
3323 NTSYSAPI
3324 VOID
3325 NTAPI
3326 RtlCopyUnicodeString(
3327 IN OUT PUNICODE_STRING DestinationString,
3328 IN PCUNICODE_STRING SourceString);
3329
3330 NTSYSAPI
3331 NTSTATUS
3332 NTAPI
3333 RtlCreateRegistryKey(
3334 IN ULONG RelativeTo,
3335 IN PWSTR Path);
3336
3337 NTSYSAPI
3338 NTSTATUS
3339 NTAPI
3340 RtlCreateSecurityDescriptor(
3341 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3342 IN ULONG Revision);
3343
3344 NTSYSAPI
3345 NTSTATUS
3346 NTAPI
3347 RtlDeleteRegistryValue(
3348 IN ULONG RelativeTo,
3349 IN PCWSTR Path,
3350 IN PCWSTR ValueName);
3351
3352 NTSYSAPI
3353 BOOLEAN
3354 NTAPI
3355 RtlEqualUnicodeString(
3356 IN CONST UNICODE_STRING *String1,
3357 IN CONST UNICODE_STRING *String2,
3358 IN BOOLEAN CaseInSensitive);
3359
3360 #if !defined(_AMD64_) && !defined(_IA64_)
3361 NTSYSAPI
3362 LARGE_INTEGER
3363 NTAPI
3364 RtlExtendedIntegerMultiply(
3365 IN LARGE_INTEGER Multiplicand,
3366 IN LONG Multiplier);
3367
3368 NTSYSAPI
3369 LARGE_INTEGER
3370 NTAPI
3371 RtlExtendedLargeIntegerDivide(
3372 IN LARGE_INTEGER Dividend,
3373 IN ULONG Divisor,
3374 IN OUT PULONG Remainder);
3375 #endif
3376
3377 #if defined(_X86_) || defined(_IA64_)
3378 NTSYSAPI
3379 LARGE_INTEGER
3380 NTAPI
3381 RtlExtendedMagicDivide(
3382 IN LARGE_INTEGER Dividend,
3383 IN LARGE_INTEGER MagicDivisor,
3384 IN CCHAR ShiftCount);
3385 #endif
3386
3387 NTSYSAPI
3388 VOID
3389 NTAPI
3390 RtlFreeAnsiString(
3391 IN PANSI_STRING AnsiString);
3392
3393 NTSYSAPI
3394 ULONG
3395 NTAPI
3396 RtlFindClearBits(
3397 IN PRTL_BITMAP BitMapHeader,
3398 IN ULONG NumberToFind,
3399 IN ULONG HintIndex);
3400
3401 NTSYSAPI
3402 ULONG
3403 NTAPI
3404 RtlFindClearBitsAndSet(
3405 IN PRTL_BITMAP BitMapHeader,
3406 IN ULONG NumberToFind,
3407 IN ULONG HintIndex);
3408
3409 NTSYSAPI
3410 ULONG
3411 NTAPI
3412 RtlFindFirstRunClear(
3413 IN PRTL_BITMAP BitMapHeader,
3414 OUT PULONG StartingIndex);
3415
3416 NTSYSAPI
3417 ULONG
3418 NTAPI
3419 RtlFindClearRuns(
3420 IN PRTL_BITMAP BitMapHeader,
3421 OUT PRTL_BITMAP_RUN RunArray,
3422 IN ULONG SizeOfRunArray,
3423 IN BOOLEAN LocateLongestRuns);
3424
3425 NTSYSAPI
3426 ULONG
3427 NTAPI
3428 RtlFindLastBackwardRunClear(
3429 IN PRTL_BITMAP BitMapHeader,
3430 IN ULONG FromIndex,
3431 OUT PULONG StartingRunIndex);
3432
3433 NTSYSAPI
3434 CCHAR
3435 NTAPI
3436 RtlFindLeastSignificantBit(
3437 IN ULONGLONG Set);
3438
3439 NTSYSAPI
3440 ULONG
3441 NTAPI
3442 RtlFindLongestRunClear(
3443 IN PRTL_BITMAP BitMapHeader,
3444 OUT PULONG StartingIndex);
3445
3446 NTSYSAPI
3447 CCHAR
3448 NTAPI
3449 RtlFindMostSignificantBit(
3450 IN ULONGLONG Set);
3451
3452 NTSYSAPI
3453 ULONG
3454 NTAPI
3455 RtlFindNextForwardRunClear(
3456 IN PRTL_BITMAP BitMapHeader,
3457 IN ULONG FromIndex,
3458 OUT PULONG StartingRunIndex);
3459
3460 NTSYSAPI
3461 ULONG
3462 NTAPI
3463 RtlFindSetBits(
3464 IN PRTL_BITMAP BitMapHeader,
3465 IN ULONG NumberToFind,
3466 IN ULONG HintIndex);
3467
3468 NTSYSAPI
3469 ULONG
3470 NTAPI
3471 RtlFindSetBitsAndClear(
3472 IN PRTL_BITMAP BitMapHeader,
3473 IN ULONG NumberToFind,
3474 IN ULONG HintIndex);
3475
3476 NTSYSAPI
3477 NTSTATUS
3478 NTAPI
3479 RtlHashUnicodeString(
3480 IN CONST UNICODE_STRING *String,
3481 IN BOOLEAN CaseInSensitive,
3482 IN ULONG HashAlgorithm,
3483 OUT PULONG HashValue);
3484
3485 NTSYSAPI
3486 VOID
3487 NTAPI
3488 RtlInitAnsiString(
3489 IN OUT PANSI_STRING DestinationString,
3490 IN PCSZ SourceString);
3491
3492 NTSYSAPI
3493 VOID
3494 NTAPI
3495 RtlInitializeBitMap(
3496 IN PRTL_BITMAP BitMapHeader,
3497 IN PULONG BitMapBuffer,
3498 IN ULONG SizeOfBitMap);
3499
3500 NTSYSAPI
3501 VOID
3502 NTAPI
3503 RtlInitString(
3504 IN OUT PSTRING DestinationString,
3505 IN PCSZ SourceString);
3506
3507 NTSYSAPI
3508 NTSTATUS
3509 NTAPI
3510 RtlIntegerToUnicodeString(
3511 IN ULONG Value,
3512 IN ULONG Base OPTIONAL,
3513 IN OUT PUNICODE_STRING String);
3514
3515 NTSYSAPI
3516 NTSTATUS
3517 NTAPI
3518 RtlInt64ToUnicodeString(
3519 IN ULONGLONG Value,
3520 IN ULONG Base OPTIONAL,
3521 IN OUT PUNICODE_STRING String);
3522
3523 #ifdef _WIN64
3524 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3525 RtlInt64ToUnicodeString(Value, Base, String)
3526 #else
3527 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3528 RtlIntegerToUnicodeString(Value, Base, String)
3529 #endif
3530
3531 /* BOOLEAN
3532 * RtlIsZeroLuid(
3533 * IN PLUID L1);
3534 */
3535 #define RtlIsZeroLuid(_L1) \
3536 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
3537
3538 NTSYSAPI
3539 ULONG
3540 NTAPI
3541 RtlLengthSecurityDescriptor(
3542 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3543
3544 NTSYSAPI
3545 ULONG
3546 NTAPI
3547 RtlNumberOfClearBits(
3548 IN PRTL_BITMAP BitMapHeader);
3549
3550 NTSYSAPI
3551 ULONG
3552 NTAPI
3553 RtlNumberOfSetBits(
3554 IN PRTL_BITMAP BitMapHeader);
3555
3556 NTSYSAPI
3557 NTSTATUS
3558 NTAPI
3559 RtlQueryRegistryValues(
3560 IN ULONG RelativeTo,
3561 IN PCWSTR Path,
3562 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
3563 IN PVOID Context,
3564 IN PVOID Environment OPTIONAL);
3565
3566 #define LONG_SIZE (sizeof(LONG))
3567 #define LONG_MASK (LONG_SIZE - 1)
3568
3569 /* VOID
3570 * RtlRetrieveUlong(
3571 * PULONG DestinationAddress,
3572 * PULONG SourceAddress);
3573 */
3574 #if defined(_AMD64_)
3575 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3576 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
3577 #else
3578 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3579 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3580 { \
3581 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3582 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3583 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
3584 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
3585 } \
3586 else \
3587 { \
3588 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
3589 }
3590 #endif
3591
3592 /* VOID
3593 * RtlRetrieveUshort(
3594 * PUSHORT DestinationAddress,
3595 * PUSHORT SourceAddress);
3596 */
3597 #if defined(_AMD64_)
3598 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3599 *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
3600 #else
3601 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3602 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3603 { \
3604 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3605 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3606 } \
3607 else \
3608 { \
3609 *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
3610 }
3611 #endif
3612
3613 NTSYSAPI
3614 VOID
3615 NTAPI
3616 RtlSetAllBits(
3617 IN PRTL_BITMAP BitMapHeader);
3618
3619 NTSYSAPI
3620 VOID
3621 NTAPI
3622 RtlSetBits(
3623 IN PRTL_BITMAP BitMapHeader,
3624 IN ULONG StartingIndex,
3625 IN ULONG NumberToSet);
3626
3627 NTSYSAPI
3628 NTSTATUS
3629 NTAPI
3630 RtlSetDaclSecurityDescriptor(
3631 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3632 IN BOOLEAN DaclPresent,
3633 IN PACL Dacl OPTIONAL,
3634 IN BOOLEAN DaclDefaulted OPTIONAL);
3635
3636 /* VOID
3637 * RtlStoreUlong(
3638 * IN PULONG Address,
3639 * IN ULONG Value);
3640 */
3641 #if defined(_AMD64_)
3642 #define RtlStoreUlong(Address,Value) \
3643 *(ULONG UNALIGNED *)(Address) = (Value)
3644 #else
3645 #define RtlStoreUlong(Address,Value) \
3646 if ((ULONG_PTR)(Address) & LONG_MASK) { \
3647 ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3648 ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
3649 ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
3650 ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT] = (UCHAR)(FOURTHBYTE(Value)); \
3651 } \
3652 else { \
3653 *((PULONG)(Address)) = (ULONG) (Value); \
3654 }
3655 #endif
3656
3657 /* VOID
3658 * RtlStoreUlonglong(
3659 * IN OUT PULONGLONG Address,
3660 * ULONGLONG Value);
3661 */
3662 #if defined(_AMD64_)
3663 #define RtlStoreUlonglong(Address,Value) \
3664 *(ULONGLONG UNALIGNED *)(Address) = (Value)
3665 #else
3666 #define RtlStoreUlonglong(Address,Value) \
3667 if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
3668 RtlStoreUlong((ULONG_PTR)(Address), \
3669 (ULONGLONG)(Value) & 0xFFFFFFFF); \
3670 RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
3671 (ULONGLONG)(Value) >> 32); \
3672 } else { \
3673 *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
3674 }
3675 #endif
3676
3677 /* VOID
3678 * RtlStoreUlongPtr(
3679 * IN OUT PULONG_PTR Address,
3680 * IN ULONG_PTR Value);
3681 */
3682 #ifdef _WIN64
3683 #define RtlStoreUlongPtr(Address,Value) \
3684 RtlStoreUlonglong(Address,Value)
3685 #else
3686 #define RtlStoreUlongPtr(Address,Value) \
3687 RtlStoreUlong(Address,Value)
3688 #endif
3689
3690 /* VOID
3691 * RtlStoreUshort(
3692 * IN PUSHORT Address,
3693 * IN USHORT Value);
3694 */
3695 #if defined(_AMD64_)
3696 #define RtlStoreUshort(Address,Value) \
3697 *(USHORT UNALIGNED *)(Address) = (Value)
3698 #else
3699 #define RtlStoreUshort(Address,Value) \
3700 if ((ULONG_PTR)(Address) & SHORT_MASK) { \
3701 ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3702 ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
3703 } \
3704 else { \
3705 *((PUSHORT) (Address)) = (USHORT)Value; \
3706 }
3707 #endif
3708
3709 NTSYSAPI
3710 BOOLEAN
3711 NTAPI
3712 RtlTimeFieldsToTime(
3713 IN PTIME_FIELDS TimeFields,
3714 IN PLARGE_INTEGER Time);
3715
3716 NTSYSAPI
3717 VOID
3718 NTAPI
3719 RtlTimeToTimeFields(
3720 IN PLARGE_INTEGER Time,
3721 IN PTIME_FIELDS TimeFields);
3722
3723 NTSYSAPI
3724 ULONG
3725 FASTCALL
3726 RtlUlongByteSwap(
3727 IN ULONG Source);
3728
3729 NTSYSAPI
3730 ULONGLONG
3731 FASTCALL
3732 RtlUlonglongByteSwap(
3733 IN ULONGLONG Source);
3734
3735 NTSYSAPI
3736 NTSTATUS
3737 NTAPI
3738 RtlUnicodeStringToAnsiString(
3739 IN OUT PANSI_STRING DestinationString,
3740 IN PCUNICODE_STRING SourceString,
3741 IN BOOLEAN AllocateDestinationString);
3742
3743 NTSYSAPI
3744 ULONG
3745 NTAPI
3746 RtlxUnicodeStringToAnsiSize(
3747 IN PCUNICODE_STRING UnicodeString);
3748
3749 #define RtlUnicodeStringToAnsiSize(String) ( \
3750 NLS_MB_CODE_PAGE_TAG ? \
3751 RtlxUnicodeStringToAnsiSize(String) : \
3752 ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
3753 )
3754
3755 NTSYSAPI
3756 NTSTATUS
3757 NTAPI
3758 RtlUnicodeStringToInteger(
3759 IN PCUNICODE_STRING String,
3760 IN ULONG Base OPTIONAL,
3761 OUT PULONG Value);
3762
3763 NTSYSAPI
3764 WCHAR
3765 NTAPI
3766 RtlUpcaseUnicodeChar(
3767 IN WCHAR SourceCharacter);
3768
3769 NTSYSAPI
3770 USHORT
3771 FASTCALL
3772 RtlUshortByteSwap(
3773 IN USHORT Source);
3774
3775 NTSYSAPI
3776 BOOLEAN
3777 NTAPI
3778 RtlValidRelativeSecurityDescriptor(
3779 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
3780 IN ULONG SecurityDescriptorLength,
3781 IN SECURITY_INFORMATION RequiredInformation);
3782
3783 NTSYSAPI
3784 BOOLEAN
3785 NTAPI
3786 RtlValidSecurityDescriptor(
3787 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3788
3789 NTSYSAPI
3790 NTSTATUS
3791 NTAPI
3792 RtlWriteRegistryValue(
3793 IN ULONG RelativeTo,
3794 IN PCWSTR Path,
3795 IN PCWSTR ValueName,
3796 IN ULONG ValueType,
3797 IN PVOID ValueData,
3798 IN ULONG ValueLength);
3799
3800 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
3801
3802 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
3803 NTSYSAPI
3804 VOID
3805 FASTCALL
3806 RtlPrefetchMemoryNonTemporal(
3807 IN PVOID Source,
3808 IN SIZE_T Length);
3809 #endif
3810
3811 #if (NTDDI_VERSION >= NTDDI_WINXP)
3812 NTSYSAPI
3813 VOID
3814 NTAPI
3815 RtlClearBit(
3816 PRTL_BITMAP BitMapHeader,
3817 ULONG BitNumber);
3818
3819 NTSYSAPI
3820 WCHAR
3821 NTAPI
3822 RtlDowncaseUnicodeChar(
3823 IN WCHAR SourceCharacter);
3824
3825 NTSYSAPI
3826 VOID
3827 NTAPI
3828 RtlSetBit(
3829 PRTL_BITMAP BitMapHeader,
3830 ULONG BitNumber);
3831
3832 NTSYSAPI
3833 BOOLEAN
3834 NTAPI
3835 RtlTestBit(
3836 IN PRTL_BITMAP BitMapHeader,
3837 IN ULONG BitNumber);
3838
3839 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
3840
3841 #if (NTDDI_VERSION >= NTDDI_VISTA)
3842 NTSYSAPI
3843 ULONG
3844 NTAPI
3845 RtlNumberOfSetBitsUlongPtr(
3846 IN ULONG_PTR Target);
3847
3848 NTSYSAPI
3849 ULONGLONG
3850 NTAPI
3851 RtlIoDecodeMemIoResource (
3852 IN struct _IO_RESOURCE_DESCRIPTOR *Descriptor,
3853 OUT PULONGLONG Alignment OPTIONAL,
3854 OUT PULONGLONG MinimumAddress OPTIONAL,
3855 OUT PULONGLONG MaximumAddress OPTIONAL);
3856
3857 NTSYSAPI
3858 NTSTATUS
3859 NTAPI
3860 RtlIoEncodeMemIoResource(
3861 IN struct _IO_RESOURCE_DESCRIPTOR *Descriptor,
3862 IN UCHAR Type,
3863 IN ULONGLONG Length,
3864 IN ULONGLONG Alignment,
3865 IN ULONGLONG MinimumAddress,
3866 IN ULONGLONG MaximumAddress);
3867
3868 NTSYSAPI
3869 ULONGLONG
3870 NTAPI
3871 RtlCmDecodeMemIoResource(
3872 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
3873 OUT PULONGLONG Start OPTIONAL);
3874
3875 NTSYSAPI
3876 NTSTATUS
3877 NTAPI
3878 RtlFindClosestEncodableLength(
3879 IN ULONGLONG SourceLength,
3880 OUT PULONGLONG TargetLength);
3881
3882 #endif
3883
3884 #if !defined(MIDL_PASS)
3885 /* inline funftions */
3886 //DECLSPEC_DEPRECATED_DDK_WINXP
3887 static __inline
3888 LARGE_INTEGER
3889 NTAPI_INLINE
3890 RtlConvertLongToLargeInteger(LONG SignedInteger)
3891 {
3892 LARGE_INTEGER ret;
3893 ret.QuadPart = SignedInteger;
3894 return ret;
3895 }
3896
3897 //DECLSPEC_DEPRECATED_DDK_WINXP
3898 static __inline
3899 LARGE_INTEGER
3900 NTAPI_INLINE
3901 RtlConvertUlongToLargeInteger(
3902 ULONG UnsignedInteger)
3903 {
3904 LARGE_INTEGER ret;
3905 ret.QuadPart = UnsignedInteger;
3906 return ret;
3907 }
3908
3909 //DECLSPEC_DEPRECATED_DDK
3910 static __inline
3911 ULONG
3912 NTAPI_INLINE
3913 RtlEnlargedUnsignedDivide(
3914 IN ULARGE_INTEGER Dividend,
3915 IN ULONG Divisor,
3916 IN OUT PULONG Remainder)
3917 {
3918 if (Remainder)
3919 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3920 return (ULONG)(Dividend.QuadPart / Divisor);
3921 }
3922
3923 //DECLSPEC_DEPRECATED_DDK
3924 static __inline
3925 LARGE_INTEGER
3926 NTAPI_INLINE
3927 RtlEnlargedUnsignedMultiply(
3928 IN ULONG Multiplicand,
3929 IN ULONG Multiplier)
3930 {
3931 LARGE_INTEGER ret;
3932 ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3933 return ret;
3934 }
3935
3936 //DECLSPEC_DEPRECATED_DDK
3937 static __inline
3938 LARGE_INTEGER
3939 NTAPI_INLINE
3940 RtlEnlargedIntegerMultiply(
3941 IN LONG Multiplicand,
3942 IN LONG Multiplier)
3943 {
3944 LARGE_INTEGER ret;
3945 ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3946 return ret;
3947 }
3948
3949 FORCEINLINE
3950 VOID
3951 RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
3952 IN PCHAR Buffer,
3953 IN USHORT BufferSize)
3954 {
3955 AnsiString->Length = 0;
3956 AnsiString->MaximumLength = BufferSize;
3957 AnsiString->Buffer = Buffer;
3958 }
3959
3960 FORCEINLINE
3961 VOID
3962 RtlInitEmptyUnicodeString(
3963 OUT PUNICODE_STRING UnicodeString,
3964 IN PWSTR Buffer,
3965 IN USHORT BufferSize)
3966 {
3967 UnicodeString->Length = 0;
3968 UnicodeString->MaximumLength = BufferSize;
3969 UnicodeString->Buffer = Buffer;
3970 }
3971
3972 #if defined(_AMD64_) || defined(_IA64_)
3973 static __inline
3974 LARGE_INTEGER
3975 NTAPI_INLINE
3976 RtlExtendedIntegerMultiply(
3977 LARGE_INTEGER Multiplicand,
3978 LONG Multiplier)
3979 {
3980 LARGE_INTEGER ret;
3981 ret.QuadPart = Multiplicand.QuadPart * Multiplier;
3982 return ret;
3983 }
3984
3985 static __inline
3986 LARGE_INTEGER
3987 NTAPI_INLINE
3988 RtlExtendedLargeIntegerDivide(
3989 LARGE_INTEGER Dividend,
3990 ULONG Divisor,
3991 PULONG Remainder)
3992 {
3993 LARGE_INTEGER ret;
3994 ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
3995 if (Remainder)
3996 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3997 return ret;
3998 }
3999 #endif
4000
4001 #if defined(_AMD64_)
4002
4003 #define MultiplyHigh __mulh
4004 #define UnsignedMultiplyHigh __umulh
4005
4006 //DECLSPEC_DEPRECATED_DDK
4007 static __inline
4008 LARGE_INTEGER
4009 NTAPI_INLINE
4010 RtlExtendedMagicDivide(
4011 IN LARGE_INTEGER Dividend,
4012 IN LARGE_INTEGER MagicDivisor,
4013 IN CCHAR ShiftCount)
4014 {
4015 LARGE_INTEGER ret;
4016 ULONG64 ret64;
4017 BOOLEAN Pos;
4018 Pos = (Dividend.QuadPart >= 0);
4019 ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
4020 MagicDivisor.QuadPart);
4021 ret64 >>= ShiftCount;
4022 ret.QuadPart = Pos ? ret64 : -ret64;
4023 return ret;
4024 }
4025 #endif
4026
4027 //DECLSPEC_DEPRECATED_DDK
4028 static __inline
4029 LARGE_INTEGER
4030 NTAPI_INLINE
4031 RtlLargeIntegerAdd(
4032 IN LARGE_INTEGER Addend1,
4033 IN LARGE_INTEGER Addend2)
4034 {
4035 LARGE_INTEGER ret;
4036 ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
4037 return ret;
4038 }
4039
4040 /* VOID
4041 * RtlLargeIntegerAnd(
4042 * IN OUT LARGE_INTEGER Result,
4043 * IN LARGE_INTEGER Source,
4044 * IN LARGE_INTEGER Mask);
4045 */
4046 #define RtlLargeIntegerAnd(Result, Source, Mask) \
4047 Result.QuadPart = Source.QuadPart & Mask.QuadPart
4048
4049 //DECLSPEC_DEPRECATED_DDK
4050 static __inline
4051 LARGE_INTEGER
4052 NTAPI_INLINE
4053 RtlLargeIntegerArithmeticShift(
4054 IN LARGE_INTEGER LargeInteger,
4055 IN CCHAR ShiftCount)
4056 {
4057 LARGE_INTEGER ret;
4058 ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
4059 return ret;
4060 }
4061
4062 /* BOOLEAN
4063 * RtlLargeIntegerEqualTo(
4064 * IN LARGE_INTEGER Operand1,
4065 * IN LARGE_INTEGER Operand2);
4066 */
4067 #define RtlLargeIntegerEqualTo(X,Y) \
4068 (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
4069
4070 FORCEINLINE
4071 PVOID
4072 RtlSecureZeroMemory(