VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/i8042prt/include/ntddk.h@ 2981

Last change on this file since 2981 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 536.0 KB
Line 
1/*++ BUILD Version: 0121 // Increment this if a change has global effects
2
3Copyright (c) Microsoft Corporation. All rights reserved.
4
5Module Name:
6
7 ntddk.h
8
9Abstract:
10
11 This module defines the NT types, constants, and functions that are
12 exposed to device drivers.
13
14Revision History:
15
16--*/
17
18#ifndef _NTDDK_
19#define _NTDDK_
20
21#ifndef RC_INVOKED
22#if _MSC_VER < 1300
23#error Compiler version not supported by Windows DDK
24#endif
25#endif // RC_INVOKED
26
27#define NT_INCLUDED
28#define _CTYPE_DISABLE_MACROS
29
30#include <excpt.h>
31#include <ntdef.h>
32#include <ntstatus.h>
33#include <bugcodes.h>
34#include <ntiologc.h>
35//
36// Kernel Mutex Level Numbers (must be globallly assigned within executive)
37// The third token in the name is the sub-component name that defines and
38// uses the level number.
39//
40
41//
42// Used by Vdm for protecting io simulation structures
43//
44
45#define MUTEX_LEVEL_VDM_IO (ULONG)0x00000001
46
47#define MUTEX_LEVEL_EX_PROFILE (ULONG)0x00000040
48
49//
50// The LANMAN Redirector uses the file system major function, but defines
51// it's own mutex levels. We can do this safely because we know that the
52// local filesystem will never call the remote filesystem and vice versa.
53//
54
55#define MUTEX_LEVEL_RDR_FILESYS_DATABASE (ULONG)0x10100000
56#define MUTEX_LEVEL_RDR_FILESYS_SECURITY (ULONG)0x10100001
57
58//
59// File System levels.
60//
61
62#define MUTEX_LEVEL_FILESYSTEM_RAW_VCB (ULONG)0x11000006
63
64//
65// In the NT STREAMS environment, a mutex is used to serialize open, close
66// and Scheduler threads executing in a subsystem-parallelized stack.
67//
68
69#define MUTEX_LEVEL_STREAMS_SUBSYS (ULONG)0x11001001
70
71//
72// Mutex level used by LDT support on x86
73//
74
75#define MUTEX_LEVEL_PS_LDT (ULONG)0x1F000000
76
77//
78// Define types that are not exported.
79//
80
81typedef struct _BUS_HANDLER *PBUS_HANDLER;
82typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
83typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
84typedef struct _EPROCESS *PEPROCESS;
85typedef struct _ETHREAD *PETHREAD;
86typedef struct _IO_TIMER *PIO_TIMER;
87typedef struct _KINTERRUPT *PKINTERRUPT;
88typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
89typedef struct _OBJECT_TYPE *POBJECT_TYPE;
90typedef struct _PEB *PPEB;
91
92#if defined(_M_AMD64)
93
94PKTHREAD
95NTAPI
96KeGetCurrentThread(
97 VOID
98 );
99
100#endif // defined(_M_AMD64)
101
102#if defined(_M_IX86)
103PKTHREAD NTAPI KeGetCurrentThread();
104#endif // defined(_M_IX86)
105
106#if defined(_M_IA64)
107
108//
109// Define Address of Processor Control Registers.
110//
111
112#define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xffff0000)) // kernel address of first PCR
113
114//
115// Define Pointer to Processor Control Registers.
116//
117
118#define PCR ((volatile KPCR * const)KIPCR)
119
120PKTHREAD NTAPI KeGetCurrentThread();
121
122#endif // defined(_M_IA64)
123
124#define PsGetCurrentProcess() IoGetCurrentProcess()
125#define PsGetCurrentThread() ((PETHREAD) (KeGetCurrentThread()))
126extern NTSYSAPI CCHAR KeNumberProcessors;
127
128#include <mce.h>
129
130#ifndef FAR
131#define FAR
132#endif
133
134//
135// Define alignment macros to align structure sizes and pointers up and down.
136//
137
138#define ALIGN_DOWN(length, type) \
139 ((ULONG)(length) & ~(sizeof(type) - 1))
140
141#define ALIGN_UP(length, type) \
142 (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
143
144#define ALIGN_DOWN_POINTER(address, type) \
145 ((PVOID)((ULONG_PTR)(address) & ~((ULONG_PTR)sizeof(type) - 1)))
146
147#define ALIGN_UP_POINTER(address, type) \
148 (ALIGN_DOWN_POINTER(((ULONG_PTR)(address) + sizeof(type) - 1), type))
149
150//@@@AH 20041106 not available in NT4SP0
151//#define POOL_TAGGING 1
152
153#ifndef DBG
154#define DBG 0
155#endif
156
157#if DBG
158#define IF_DEBUG if (TRUE)
159#else
160#define IF_DEBUG if (FALSE)
161#endif
162
163#if DEVL
164
165
166extern ULONG NtGlobalFlag;
167
168#define IF_NTOS_DEBUG( FlagName ) \
169 if (NtGlobalFlag & (FLG_ ## FlagName))
170
171#else
172#define IF_NTOS_DEBUG( FlagName ) if (FALSE)
173#endif
174
175//
176// Kernel definitions that need to be here for forward reference purposes
177//
178
179
180//
181// Processor modes.
182//
183
184typedef CCHAR KPROCESSOR_MODE;
185
186typedef enum _MODE {
187 KernelMode,
188 UserMode,
189 MaximumMode
190} MODE;
191
192
193//
194// APC function types
195//
196
197//
198// Put in an empty definition for the KAPC so that the
199// routines can reference it before it is declared.
200//
201
202struct _KAPC;
203
204typedef
205VOID
206(*PKNORMAL_ROUTINE) (
207 IN PVOID NormalContext,
208 IN PVOID SystemArgument1,
209 IN PVOID SystemArgument2
210 );
211
212typedef
213VOID
214(*PKKERNEL_ROUTINE) (
215 IN struct _KAPC *Apc,
216 IN OUT PKNORMAL_ROUTINE *NormalRoutine,
217 IN OUT PVOID *NormalContext,
218 IN OUT PVOID *SystemArgument1,
219 IN OUT PVOID *SystemArgument2
220 );
221
222typedef
223VOID
224(*PKRUNDOWN_ROUTINE) (
225 IN struct _KAPC *Apc
226 );
227
228typedef
229BOOLEAN
230(*PKSYNCHRONIZE_ROUTINE) (
231 IN PVOID SynchronizeContext
232 );
233
234typedef
235BOOLEAN
236(*PKTRANSFER_ROUTINE) (
237 VOID
238 );
239
240//
241//
242// Asynchronous Procedure Call (APC) object
243//
244//
245
246typedef struct _KAPC {
247 CSHORT Type;
248 CSHORT Size;
249 ULONG Spare0;
250 struct _KTHREAD *Thread;
251 LIST_ENTRY ApcListEntry;
252 PKKERNEL_ROUTINE KernelRoutine;
253 PKRUNDOWN_ROUTINE RundownRoutine;
254 PKNORMAL_ROUTINE NormalRoutine;
255 PVOID NormalContext;
256
257 //
258 // N.B. The following two members MUST be together.
259 //
260
261 PVOID SystemArgument1;
262 PVOID SystemArgument2;
263 CCHAR ApcStateIndex;
264 KPROCESSOR_MODE ApcMode;
265 BOOLEAN Inserted;
266} KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
267
268
269//
270// DPC routine
271//
272
273struct _KDPC;
274
275typedef
276VOID
277(*PKDEFERRED_ROUTINE) (
278 IN struct _KDPC *Dpc,
279 IN PVOID DeferredContext,
280 IN PVOID SystemArgument1,
281 IN PVOID SystemArgument2
282 );
283
284//
285// Define DPC importance.
286//
287// LowImportance - Queue DPC at end of target DPC queue.
288// MediumImportance - Queue DPC at end of target DPC queue.
289// HighImportance - Queue DPC at front of target DPC DPC queue.
290//
291// If there is currently a DPC active on the target processor, or a DPC
292// interrupt has already been requested on the target processor when a
293// DPC is queued, then no further action is necessary. The DPC will be
294// executed on the target processor when its queue entry is processed.
295//
296// If there is not a DPC active on the target processor and a DPC interrupt
297// has not been requested on the target processor, then the exact treatment
298// of the DPC is dependent on whether the host system is a UP system or an
299// MP system.
300//
301// UP system.
302//
303// If the DPC is of medium or high importance, the current DPC queue depth
304// is greater than the maximum target depth, or current DPC request rate is
305// less the minimum target rate, then a DPC interrupt is requested on the
306// host processor and the DPC will be processed when the interrupt occurs.
307// Otherwise, no DPC interupt is requested and the DPC execution will be
308// delayed until the DPC queue depth is greater that the target depth or the
309// minimum DPC rate is less than the target rate.
310//
311// MP system.
312//
313// If the DPC is being queued to another processor and the depth of the DPC
314// queue on the target processor is greater than the maximum target depth or
315// the DPC is of high importance, then a DPC interrupt is requested on the
316// target processor and the DPC will be processed when the interrupt occurs.
317// Otherwise, the DPC execution will be delayed on the target processor until
318// the DPC queue depth on the target processor is greater that the maximum
319// target depth or the minimum DPC rate on the target processor is less than
320// the target mimimum rate.
321//
322// If the DPC is being queued to the current processor and the DPC is not of
323// low importance, the current DPC queue depth is greater than the maximum
324// target depth, or the minimum DPC rate is less than the minimum target rate,
325// then a DPC interrupt is request on the current processor and the DPV will
326// be processed whne the interrupt occurs. Otherwise, no DPC interupt is
327// requested and the DPC execution will be delayed until the DPC queue depth
328// is greater that the target depth or the minimum DPC rate is less than the
329// target rate.
330//
331
332typedef enum _KDPC_IMPORTANCE {
333 LowImportance,
334 MediumImportance,
335 HighImportance
336} KDPC_IMPORTANCE;
337
338//
339// Define DPC type indicies.
340//
341
342#define DPC_NORMAL 0
343#define DPC_THREADED 1
344
345//
346// Deferred Procedure Call (DPC) object
347//
348
349typedef struct _KDPC {
350 CSHORT Type;
351 UCHAR Number;
352 UCHAR Importance;
353 LIST_ENTRY DpcListEntry;
354 PKDEFERRED_ROUTINE DeferredRoutine;
355 PVOID DeferredContext;
356 PVOID SystemArgument1;
357 PVOID SystemArgument2;
358 PVOID DpcData;
359} KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
360
361//
362// Interprocessor interrupt worker routine function prototype.
363//
364
365typedef PVOID PKIPI_CONTEXT;
366
367typedef
368VOID
369(*PKIPI_WORKER)(
370 IN PKIPI_CONTEXT PacketContext,
371 IN PVOID Parameter1,
372 IN PVOID Parameter2,
373 IN PVOID Parameter3
374 );
375
376//
377// Define interprocessor interrupt performance counters.
378//
379
380typedef struct _KIPI_COUNTS {
381 ULONG Freeze;
382 ULONG Packet;
383 ULONG DPC;
384 ULONG APC;
385 ULONG FlushSingleTb;
386 ULONG FlushMultipleTb;
387 ULONG FlushEntireTb;
388 ULONG GenericCall;
389 ULONG ChangeColor;
390 ULONG SweepDcache;
391 ULONG SweepIcache;
392 ULONG SweepIcacheRange;
393 ULONG FlushIoBuffers;
394 ULONG GratuitousDPC;
395} KIPI_COUNTS, *PKIPI_COUNTS;
396
397
398//
399// I/O system definitions.
400//
401// Define a Memory Descriptor List (MDL)
402//
403// An MDL describes pages in a virtual buffer in terms of physical pages. The
404// pages associated with the buffer are described in an array that is allocated
405// just after the MDL header structure itself.
406//
407// One simply calculates the base of the array by adding one to the base
408// MDL pointer:
409//
410// Pages = (PPFN_NUMBER) (Mdl + 1);
411//
412// Notice that while in the context of the subject thread, the base virtual
413// address of a buffer mapped by an MDL may be referenced using the following:
414//
415// Mdl->StartVa | Mdl->ByteOffset
416//
417
418
419typedef struct _MDL {
420 struct _MDL *Next;
421 CSHORT Size;
422 CSHORT MdlFlags;
423 struct _EPROCESS *Process;
424 PVOID MappedSystemVa;
425 PVOID StartVa;
426 ULONG ByteCount;
427 ULONG ByteOffset;
428} MDL, *PMDL;
429
430#define MDL_MAPPED_TO_SYSTEM_VA 0x0001
431#define MDL_PAGES_LOCKED 0x0002
432#define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
433#define MDL_ALLOCATED_FIXED_SIZE 0x0008
434#define MDL_PARTIAL 0x0010
435#define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
436#define MDL_IO_PAGE_READ 0x0040
437#define MDL_WRITE_OPERATION 0x0080
438#define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
439#define MDL_FREE_EXTRA_PTES 0x0200
440#define MDL_DESCRIBES_AWE 0x0400
441#define MDL_IO_SPACE 0x0800
442#define MDL_NETWORK_HEADER 0x1000
443#define MDL_MAPPING_CAN_FAIL 0x2000
444#define MDL_ALLOCATED_MUST_SUCCEED 0x4000
445
446
447#define MDL_MAPPING_FLAGS (MDL_MAPPED_TO_SYSTEM_VA | \
448 MDL_PAGES_LOCKED | \
449 MDL_SOURCE_IS_NONPAGED_POOL | \
450 MDL_PARTIAL_HAS_BEEN_MAPPED | \
451 MDL_PARENT_MAPPED_SYSTEM_VA | \
452 MDL_SYSTEM_VA | \
453 MDL_IO_SPACE )
454
455
456//
457// switch to DBG when appropriate
458//
459
460#if DBG
461#define PAGED_CODE() \
462 { if (KeGetCurrentIrql() > APC_LEVEL) { \
463 KdPrint(( "EX: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
464 ASSERT(FALSE); \
465 } \
466 }
467#else
468#define PAGED_CODE() NOP_FUNCTION;
469#endif
470
471#define NTKERNELAPI DECLSPEC_IMPORT
472#if !defined(_NTHAL_) && !defined(_BLDR_)
473
474#define NTHALAPI DECLSPEC_IMPORT // wdm ntndis ntifs ntosp
475
476#else
477
478#define NTHALAPI // nthal
479
480#endif
481//
482// Common dispatcher object header
483//
484// N.B. The size field contains the number of dwords in the structure.
485//
486
487typedef struct _DISPATCHER_HEADER {
488 union {
489 struct {
490 UCHAR Type;
491 UCHAR Absolute;
492 UCHAR Size;
493 union {
494 UCHAR Inserted;
495 BOOLEAN DebugActive;
496 };
497 };
498
499 volatile LONG Lock;
500 };
501
502 LONG SignalState;
503 LIST_ENTRY WaitListHead;
504} DISPATCHER_HEADER;
505
506//
507// Event object
508//
509
510typedef struct _KEVENT {
511 DISPATCHER_HEADER Header;
512} KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
513
514//
515// Timer object
516//
517
518typedef struct _KTIMER {
519 DISPATCHER_HEADER Header;
520 ULARGE_INTEGER DueTime;
521 LIST_ENTRY TimerListEntry;
522 struct _KDPC *Dpc;
523 LONG Period;
524} KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
525
526typedef enum _LOCK_OPERATION {
527 IoReadAccess,
528 IoWriteAccess,
529 IoModifyAccess
530} LOCK_OPERATION;
531
532
533#ifdef _X86_
534
535//
536// Disable these two pragmas that evaluate to "sti" "cli" on x86 so that driver
537// writers to not leave them inadvertantly in their code.
538//
539
540#if !defined(MIDL_PASS)
541#if !defined(RC_INVOKED)
542
543#if _MSC_VER >= 1200
544#pragma warning(push)
545#endif
546#pragma warning(disable:4164) // disable C4164 warning so that apps that
547 // build with /Od don't get weird errors !
548#ifdef _M_IX86
549#pragma function(_enable)
550#pragma function(_disable)
551#endif
552
553#if _MSC_VER >= 1200
554#pragma warning(pop)
555#else
556#pragma warning(default:4164) // reenable C4164 warning
557#endif
558
559#endif
560#endif
561
562
563#if !defined(MIDL_PASS) || defined(_M_IX86)
564
565#if (_MSC_FULL_VER >= 13012035)
566
567//
568// Define bit scan intrinsics.
569//
570
571//#define BitScanForward _BitScanForward
572//#define BitScanReverse _BitScanReverse
573
574//BOOLEAN
575//_BitScanForward (
576// OUT ULONG *Index,
577// IN ULONG Mask
578// );
579
580//BOOLEAN
581//_BitScanReverse (
582// OUT ULONG *Index,
583// IN ULONG Mask
584// );
585
586
587//#pragma intrinsic(_BitScanForward)
588//#pragma intrinsic(_BitScanReverse)
589
590//
591// Define FS referencing intrinsics
592//
593#ifdef __cplusplus
594extern "C" {
595#endif
596
597UCHAR
598__readfsbyte (
599 IN ULONG Offset
600 );
601
602USHORT
603__readfsword (
604 IN ULONG Offset
605 );
606
607ULONG
608__readfsdword (
609 IN ULONG Offset
610 );
611
612VOID
613__writefsbyte (
614 IN ULONG Offset,
615 IN UCHAR Data
616 );
617
618VOID
619__writefsword (
620 IN ULONG Offset,
621 IN USHORT Data
622 );
623
624VOID
625__writefsdword (
626 IN ULONG Offset,
627 IN ULONG Data
628 );
629
630#ifdef __cplusplus
631}
632#endif
633
634#pragma intrinsic(__readfsbyte)
635#pragma intrinsic(__readfsword)
636#pragma intrinsic(__readfsdword)
637#pragma intrinsic(__writefsbyte)
638#pragma intrinsic(__writefsword)
639#pragma intrinsic(__writefsdword)
640
641#endif
642
643#endif
644
645//
646// Size of kernel mode stack.
647//
648
649#define KERNEL_STACK_SIZE 12288
650
651//
652// Define size of large kernel mode stack for callbacks.
653//
654
655#define KERNEL_LARGE_STACK_SIZE 61440
656
657//
658// Define number of pages to initialize in a large kernel stack.
659//
660
661#define KERNEL_LARGE_STACK_COMMIT 12288
662
663#ifdef _X86_
664
665#if !defined(MIDL_PASS) && defined(_M_IX86)
666
667FORCEINLINE
668VOID
669MemoryBarrier (
670 VOID
671 )
672{
673 LONG Barrier;
674 __asm {
675 xchg Barrier, eax
676 }
677}
678
679#define YieldProcessor() __asm { rep nop }
680
681//
682// Prefetch is not supported on all x86 procssors.
683//
684
685#define PreFetchCacheLine(l, a)
686
687//
688// PreFetchCacheLine level defines.
689//
690
691#define PF_TEMPORAL_LEVEL_1
692#define PF_NON_TEMPORAL_LEVEL_ALL
693#endif
694
695
696
697//
698// Define the size of the 80387 save area, which is in the context frame.
699//
700
701#define SIZE_OF_80387_REGISTERS 80
702
703//
704// The following flags control the contents of the CONTEXT structure.
705//
706
707#if !defined(RC_INVOKED)
708
709#define CONTEXT_i386 0x00010000 // this assumes that i386 and
710#define CONTEXT_i486 0x00010000 // i486 have identical context records
711
712
713
714#define CONTEXT_CONTROL (CONTEXT_i386 | 0x00000001L) // SS:SP, CS:IP, FLAGS, BP
715#define CONTEXT_INTEGER (CONTEXT_i386 | 0x00000002L) // AX, BX, CX, DX, SI, DI
716#define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS
717#define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 0x00000008L) // 387 state
718#define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x00000010L) // DB 0-3,6,7
719#define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386 | 0x00000020L) // cpu specific extensions
720
721#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER |\
722 CONTEXT_SEGMENTS)
723
724#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | CONTEXT_EXTENDED_REGISTERS)
725
726
727
728#endif
729
730#define MAXIMUM_SUPPORTED_EXTENSION 512
731
732typedef struct _FLOATING_SAVE_AREA {
733 ULONG ControlWord;
734 ULONG StatusWord;
735 ULONG TagWord;
736 ULONG ErrorOffset;
737 ULONG ErrorSelector;
738 ULONG DataOffset;
739 ULONG DataSelector;
740 UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
741 ULONG Cr0NpxState;
742} FLOATING_SAVE_AREA;
743
744typedef FLOATING_SAVE_AREA *PFLOATING_SAVE_AREA;
745
746//
747// Context Frame
748//
749// This frame has a several purposes: 1) it is used as an argument to
750// NtContinue, 2) is is used to constuct a call frame for APC delivery,
751// and 3) it is used in the user level thread creation routines.
752//
753// The layout of the record conforms to a standard call frame.
754//
755
756typedef struct _CONTEXT {
757
758 //
759 // The flags values within this flag control the contents of
760 // a CONTEXT record.
761 //
762 // If the context record is used as an input parameter, then
763 // for each portion of the context record controlled by a flag
764 // whose value is set, it is assumed that that portion of the
765 // context record contains valid context. If the context record
766 // is being used to modify a threads context, then only that
767 // portion of the threads context will be modified.
768 //
769 // If the context record is used as an IN OUT parameter to capture
770 // the context of a thread, then only those portions of the thread's
771 // context corresponding to set flags will be returned.
772 //
773 // The context record is never used as an OUT only parameter.
774 //
775
776 ULONG ContextFlags;
777
778 //
779 // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
780 // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
781 // included in CONTEXT_FULL.
782 //
783
784 ULONG Dr0;
785 ULONG Dr1;
786 ULONG Dr2;
787 ULONG Dr3;
788 ULONG Dr6;
789 ULONG Dr7;
790
791 //
792 // This section is specified/returned if the
793 // ContextFlags word contians the flag CONTEXT_FLOATING_POINT.
794 //
795
796 FLOATING_SAVE_AREA FloatSave;
797
798 //
799 // This section is specified/returned if the
800 // ContextFlags word contians the flag CONTEXT_SEGMENTS.
801 //
802
803 ULONG SegGs;
804 ULONG SegFs;
805 ULONG SegEs;
806 ULONG SegDs;
807
808 //
809 // This section is specified/returned if the
810 // ContextFlags word contians the flag CONTEXT_INTEGER.
811 //
812
813 ULONG Edi;
814 ULONG Esi;
815 ULONG Ebx;
816 ULONG Edx;
817 ULONG Ecx;
818 ULONG Eax;
819
820 //
821 // This section is specified/returned if the
822 // ContextFlags word contians the flag CONTEXT_CONTROL.
823 //
824
825 ULONG Ebp;
826 ULONG Eip;
827 ULONG SegCs; // MUST BE SANITIZED
828 ULONG EFlags; // MUST BE SANITIZED
829 ULONG Esp;
830 ULONG SegSs;
831
832 //
833 // This section is specified/returned if the ContextFlags word
834 // contains the flag CONTEXT_EXTENDED_REGISTERS.
835 // The format and contexts are processor specific
836 //
837
838 UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
839
840} CONTEXT;
841
842
843
844typedef CONTEXT *PCONTEXT;
845
846
847
848#endif //_X86_
849
850#endif // _X86_
851
852#if defined(_AMD64_)
853
854
855#if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
856
857//
858// Define bit test intrinsics.
859//
860
861#ifdef __cplusplus
862extern "C" {
863#endif
864
865#define BitTest _bittest
866#define BitTestAndComplement _bittestandcomplement
867#define BitTestAndSet _bittestandset
868#define BitTestAndReset _bittestandreset
869#define InterlockedBitTestAndSet _interlockedbittestandset
870#define InterlockedBitTestAndReset _interlockedbittestandreset
871
872#define BitTest64 _bittest64
873#define BitTestAndComplement64 _bittestandcomplement64
874#define BitTestAndSet64 _bittestandset64
875#define BitTestAndReset64 _bittestandreset64
876#define InterlockedBitTestAndSet64 _interlockedbittestandset64
877#define InterlockedBitTestAndReset64 _interlockedbittestandreset64
878
879BOOLEAN
880_bittest (
881 IN LONG *Base,
882 IN LONG Offset
883 );
884
885BOOLEAN
886_bittestandcomplement (
887 IN LONG *Base,
888 IN LONG Offset
889 );
890
891BOOLEAN
892_bittestandset (
893 IN LONG *Base,
894 IN LONG Offset
895 );
896
897BOOLEAN
898_bittestandreset (
899 IN LONG *Base,
900 IN LONG Offset
901 );
902
903BOOLEAN
904_interlockedbittestandset (
905 IN LONG *Base,
906 IN LONG Offset
907 );
908
909BOOLEAN
910_interlockedbittestandreset (
911 IN LONG *Base,
912 IN LONG Offset
913 );
914
915BOOLEAN
916_bittest64 (
917 IN LONG64 *Base,
918 IN LONG64 Offset
919 );
920
921BOOLEAN
922_bittestandcomplement64 (
923 IN LONG64 *Base,
924 IN LONG64 Offset
925 );
926
927BOOLEAN
928_bittestandset64 (
929 IN LONG64 *Base,
930 IN LONG64 Offset
931 );
932
933BOOLEAN
934_bittestandreset64 (
935 IN LONG64 *Base,
936 IN LONG64 Offset
937 );
938
939BOOLEAN
940_interlockedbittestandset64 (
941 IN LONG64 *Base,
942 IN LONG64 Offset
943 );
944
945BOOLEAN
946_interlockedbittestandreset64 (
947 IN LONG64 *Base,
948 IN LONG64 Offset
949 );
950
951#pragma intrinsic(_bittest)
952#pragma intrinsic(_bittestandcomplement)
953#pragma intrinsic(_bittestandset)
954#pragma intrinsic(_bittestandreset)
955#pragma intrinsic(_interlockedbittestandset)
956#pragma intrinsic(_interlockedbittestandreset)
957
958#pragma intrinsic(_bittest64)
959#pragma intrinsic(_bittestandcomplement64)
960#pragma intrinsic(_bittestandset64)
961#pragma intrinsic(_bittestandreset64)
962#pragma intrinsic(_interlockedbittestandset64)
963#pragma intrinsic(_interlockedbittestandreset64)
964
965//
966// Define bit scan intrinsics.
967//
968
969#define BitScanForward _BitScanForward
970#define BitScanReverse _BitScanReverse
971#define BitScanForward64 _BitScanForward64
972#define BitScanReverse64 _BitScanReverse64
973
974BOOLEAN
975_BitScanForward (
976 OUT ULONG *Index,
977 IN ULONG Mask
978 );
979
980BOOLEAN
981_BitScanReverse (
982 OUT ULONG *Index,
983 IN ULONG Mask
984 );
985
986BOOLEAN
987_BitScanForward64 (
988 OUT ULONG *Index,
989 IN ULONG64 Mask
990 );
991
992BOOLEAN
993_BitScanReverse64 (
994 OUT ULONG *Index,
995 IN ULONG64 Mask
996 );
997
998#pragma intrinsic(_BitScanForward)
999#pragma intrinsic(_BitScanReverse)
1000#pragma intrinsic(_BitScanForward64)
1001#pragma intrinsic(_BitScanReverse64)
1002
1003//
1004// Define function to flush a cache line.
1005//
1006
1007#define CacheLineFlush(Address) _mm_clflush(Address)
1008
1009VOID
1010_mm_clflush (
1011 PVOID Address
1012 );
1013
1014#pragma intrinsic(_mm_clflush)
1015
1016//
1017// Define memory fence intrinsics
1018//
1019
1020#define LoadFence _mm_lfence
1021#define MemoryFence _mm_mfence
1022#define StoreFence _mm_sfence
1023
1024VOID
1025_mm_lfence (
1026 VOID
1027 );
1028
1029VOID
1030_mm_mfence (
1031 VOID
1032 );
1033
1034VOID
1035_mm_sfence (
1036 VOID
1037 );
1038
1039void
1040_mm_prefetch(
1041 CHAR CONST *a,
1042 int sel
1043 );
1044
1045/* constants for use with _mm_prefetch */
1046#define _MM_HINT_T0 1
1047#define _MM_HINT_T1 2
1048#define _MM_HINT_T2 3
1049#define _MM_HINT_NTA 0
1050
1051#pragma intrinsic(_mm_prefetch)
1052#pragma intrinsic(_mm_lfence)
1053#pragma intrinsic(_mm_mfence)
1054#pragma intrinsic(_mm_sfence)
1055
1056#define YieldProcessor()
1057#define MemoryBarrier _mm_mfence
1058#define PreFetchCacheLine(l, a) _mm_prefetch((CHAR CONST *) a, l)
1059
1060//
1061// PreFetchCacheLine level defines.
1062//
1063
1064#define PF_TEMPORAL_LEVEL_1 _MM_HINT_T0
1065#define PF_NON_TEMPORAL_LEVEL_ALL _MM_HINT_NTA
1066
1067//
1068// Define function to get the caller's EFLAGs value.
1069//
1070
1071#define GetCallersEflags() __getcallerseflags()
1072
1073unsigned __int32
1074__getcallerseflags (
1075 VOID
1076 );
1077
1078#pragma intrinsic(__getcallerseflags)
1079
1080//
1081// Define function to read the value of the time stamp counter
1082//
1083
1084#define ReadTimeStampCounter() __rdtsc()
1085
1086ULONG64
1087__rdtsc (
1088 VOID
1089 );
1090
1091#pragma intrinsic(__rdtsc)
1092
1093//
1094// Define functions to move strings as bytes, words, dwords, and qwords.
1095//
1096
1097VOID
1098__movsb (
1099 IN PUCHAR Destination,
1100 IN PUCHAR Source,
1101 IN SIZE_T Count
1102 );
1103
1104VOID
1105__movsw (
1106 IN PUSHORT Destination,
1107 IN PUSHORT Source,
1108 IN SIZE_T Count
1109 );
1110
1111VOID
1112__movsd (
1113 IN PULONG Destination,
1114 IN PULONG Source,
1115 IN SIZE_T Count
1116 );
1117
1118VOID
1119__movsq (
1120 IN PULONGLONG Destination,
1121 IN PULONGLONG Source,
1122 IN SIZE_T Count
1123 );
1124
1125#pragma intrinsic(__movsb)
1126#pragma intrinsic(__movsw)
1127#pragma intrinsic(__movsd)
1128#pragma intrinsic(__movsq)
1129
1130//
1131// Define functions to store strings as bytes, words, dwords, and qwords.
1132//
1133
1134VOID
1135__stosb (
1136 IN PUCHAR Destination,
1137 IN UCHAR Value,
1138 IN SIZE_T Count
1139 );
1140
1141VOID
1142__stosw (
1143 IN PUSHORT Destination,
1144 IN USHORT Value,
1145 IN SIZE_T Count
1146 );
1147
1148VOID
1149__stosd (
1150 IN PULONG Destination,
1151 IN ULONG Value,
1152 IN SIZE_T Count
1153 );
1154
1155VOID
1156__stosq (
1157 IN PULONG64 Destination,
1158 IN ULONG64 Value,
1159 IN SIZE_T Count
1160 );
1161
1162#pragma intrinsic(__stosb)
1163#pragma intrinsic(__stosw)
1164#pragma intrinsic(__stosd)
1165#pragma intrinsic(__stosq)
1166
1167//
1168// Define functions to capture the high 64-bits of a 128-bit multiply.
1169//
1170
1171#define MultiplyHigh __mulh
1172#define UnsignedMultiplyHigh __umulh
1173
1174LONGLONG
1175MultiplyHigh (
1176 IN LONGLONG Multiplier,
1177 IN LONGLONG Multiplicand
1178 );
1179
1180ULONGLONG
1181UnsignedMultiplyHigh (
1182 IN ULONGLONG Multiplier,
1183 IN ULONGLONG Multiplicand
1184 );
1185
1186#pragma intrinsic(__mulh)
1187#pragma intrinsic(__umulh)
1188
1189//
1190// Define functions to read and write the uer TEB and the system PCR/PRCB.
1191//
1192
1193UCHAR
1194__readgsbyte (
1195 IN ULONG Offset
1196 );
1197
1198USHORT
1199__readgsword (
1200 IN ULONG Offset
1201 );
1202
1203ULONG
1204__readgsdword (
1205 IN ULONG Offset
1206 );
1207
1208ULONG64
1209__readgsqword (
1210 IN ULONG Offset
1211 );
1212
1213VOID
1214__writegsbyte (
1215 IN ULONG Offset,
1216 IN UCHAR Data
1217 );
1218
1219VOID
1220__writegsword (
1221 IN ULONG Offset,
1222 IN USHORT Data
1223 );
1224
1225VOID
1226__writegsdword (
1227 IN ULONG Offset,
1228 IN ULONG Data
1229 );
1230
1231VOID
1232__writegsqword (
1233 IN ULONG Offset,
1234 IN ULONG64 Data
1235 );
1236
1237#pragma intrinsic(__readgsbyte)
1238#pragma intrinsic(__readgsword)
1239#pragma intrinsic(__readgsdword)
1240#pragma intrinsic(__readgsqword)
1241#pragma intrinsic(__writegsbyte)
1242#pragma intrinsic(__writegsword)
1243#pragma intrinsic(__writegsdword)
1244#pragma intrinsic(__writegsqword)
1245
1246#ifdef __cplusplus
1247}
1248#endif
1249
1250#endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
1251
1252//
1253// Size of kernel mode stack.
1254//
1255
1256#define KERNEL_STACK_SIZE 0x6000
1257
1258//
1259// Define size of large kernel mode stack for callbacks.
1260//
1261
1262#define KERNEL_LARGE_STACK_SIZE 0xf000
1263
1264//
1265// Define number of pages to initialize in a large kernel stack.
1266//
1267
1268#define KERNEL_LARGE_STACK_COMMIT 0x5000
1269
1270//
1271// Define the size of the stack used for processing an MCA exception.
1272//
1273
1274#define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
1275
1276//
1277// The following flags control the contents of the CONTEXT structure.
1278//
1279
1280#if !defined(RC_INVOKED)
1281
1282#define CONTEXT_AMD64 0x100000
1283
1284
1285
1286#define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
1287#define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
1288#define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
1289#define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
1290#define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
1291
1292#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
1293
1294#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
1295
1296
1297
1298#endif // !defined(RC_INVOKED)
1299
1300//
1301// Define initial MxCsr control.
1302//
1303
1304#define INITIAL_MXCSR 0x1f80 // initial MXCSR value
1305
1306//
1307// Define 128-bit 16-byte aligned xmm register type.
1308//
1309
1310typedef struct DECLSPEC_ALIGN(16) _M128 {
1311 ULONGLONG Low;
1312 LONGLONG High;
1313} M128, *PM128;
1314
1315//
1316// Format of data for fnsave/frstor instructions.
1317//
1318// This structure is used to store the legacy floating point state.
1319//
1320
1321typedef struct _LEGACY_SAVE_AREA {
1322 USHORT ControlWord;
1323 USHORT Reserved0;
1324 USHORT StatusWord;
1325 USHORT Reserved1;
1326 USHORT TagWord;
1327 USHORT Reserved2;
1328 ULONG ErrorOffset;
1329 USHORT ErrorSelector;
1330 USHORT ErrorOpcode;
1331 ULONG DataOffset;
1332 USHORT DataSelector;
1333 USHORT Reserved3;
1334 UCHAR FloatRegisters[8 * 10];
1335} LEGACY_SAVE_AREA, *PLEGACY_SAVE_AREA;
1336
1337#define LEGACY_SAVE_AREA_LENGTH ((sizeof(LEGACY_SAVE_AREA) + 15) & ~15)
1338
1339//
1340// Context Frame
1341//
1342// This frame has a several purposes: 1) it is used as an argument to
1343// NtContinue, 2) is is used to constuct a call frame for APC delivery,
1344// and 3) it is used in the user level thread creation routines.
1345//
1346//
1347// The flags field within this record controls the contents of a CONTEXT
1348// record.
1349//
1350// If the context record is used as an input parameter, then for each
1351// portion of the context record controlled by a flag whose value is
1352// set, it is assumed that that portion of the context record contains
1353// valid context. If the context record is being used to modify a threads
1354// context, then only that portion of the threads context is modified.
1355//
1356// If the context record is used as an output parameter to capture the
1357// context of a thread, then only those portions of the thread's context
1358// corresponding to set flags will be returned.
1359//
1360// CONTEXT_CONTROL specifies SegSs, Rsp, SegCs, Rip, and EFlags.
1361//
1362// CONTEXT_INTEGER specifies Rax, Rcx, Rdx, Rbx, Rbp, Rsi, Rdi, and R8-R15.
1363//
1364// CONTEXT_SEGMENTS specifies SegDs, SegEs, SegFs, and SegGs.
1365//
1366// CONTEXT_DEBUG_REGISTERS specifies Dr0-Dr3 and Dr6-Dr7.
1367//
1368// CONTEXT_MMX_REGISTERS specifies the floating point and extended registers
1369// Mm0/St0-Mm7/St7 and Xmm0-Xmm15).
1370//
1371
1372typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
1373
1374 //
1375 // Register parameter home addresses.
1376 //
1377
1378 ULONG64 P1Home;
1379 ULONG64 P2Home;
1380 ULONG64 P3Home;
1381 ULONG64 P4Home;
1382 ULONG64 P5Home;
1383 ULONG64 P6Home;
1384
1385 //
1386 // Control flags.
1387 //
1388
1389 ULONG ContextFlags;
1390 ULONG MxCsr;
1391
1392 //
1393 // Segment Registers and processor flags.
1394 //
1395
1396 USHORT SegCs;
1397 USHORT SegDs;
1398 USHORT SegEs;
1399 USHORT SegFs;
1400 USHORT SegGs;
1401 USHORT SegSs;
1402 ULONG EFlags;
1403
1404 //
1405 // Debug registers
1406 //
1407
1408 ULONG64 Dr0;
1409 ULONG64 Dr1;
1410 ULONG64 Dr2;
1411 ULONG64 Dr3;
1412 ULONG64 Dr6;
1413 ULONG64 Dr7;
1414
1415 //
1416 // Integer registers.
1417 //
1418
1419 ULONG64 Rax;
1420 ULONG64 Rcx;
1421 ULONG64 Rdx;
1422 ULONG64 Rbx;
1423 ULONG64 Rsp;
1424 ULONG64 Rbp;
1425 ULONG64 Rsi;
1426 ULONG64 Rdi;
1427 ULONG64 R8;
1428 ULONG64 R9;
1429 ULONG64 R10;
1430 ULONG64 R11;
1431 ULONG64 R12;
1432 ULONG64 R13;
1433 ULONG64 R14;
1434 ULONG64 R15;
1435
1436 //
1437 // Program counter.
1438 //
1439
1440 ULONG64 Rip;
1441
1442 //
1443 // MMX/floating point state.
1444 //
1445
1446 M128 Xmm0;
1447 M128 Xmm1;
1448 M128 Xmm2;
1449 M128 Xmm3;
1450 M128 Xmm4;
1451 M128 Xmm5;
1452 M128 Xmm6;
1453 M128 Xmm7;
1454 M128 Xmm8;
1455 M128 Xmm9;
1456 M128 Xmm10;
1457 M128 Xmm11;
1458 M128 Xmm12;
1459 M128 Xmm13;
1460 M128 Xmm14;
1461 M128 Xmm15;
1462
1463 //
1464 // Legacy floating point state.
1465 //
1466
1467 LEGACY_SAVE_AREA FltSave;
1468 ULONG Fill;
1469
1470 //
1471 // Special debug control registers.
1472 //
1473
1474 ULONG64 DebugControl;
1475 ULONG64 LastBranchToRip;
1476 ULONG64 LastBranchFromRip;
1477 ULONG64 LastExceptionToRip;
1478 ULONG64 LastExceptionFromRip;
1479 ULONG64 Fill1;
1480} CONTEXT, *PCONTEXT;
1481
1482
1483#endif // _AMD64_
1484
1485
1486#ifdef _IA64_
1487
1488//
1489// Define size of kernel mode stack.
1490//
1491
1492#define KERNEL_STACK_SIZE 0x8000
1493
1494//
1495// Define size of large kernel mode stack for callbacks.
1496//
1497
1498#define KERNEL_LARGE_STACK_SIZE 0x1A000
1499
1500//
1501// Define number of pages to initialize in a large kernel stack.
1502//
1503
1504#define KERNEL_LARGE_STACK_COMMIT 0x8000
1505
1506//
1507// Define size of kernel mode backing store stack.
1508//
1509
1510#define KERNEL_BSTORE_SIZE 0x8000
1511
1512//
1513// Define size of large kernel mode backing store for callbacks.
1514//
1515
1516#define KERNEL_LARGE_BSTORE_SIZE 0x10000
1517
1518//
1519// Define number of pages to initialize in a large kernel backing store.
1520//
1521
1522#define KERNEL_LARGE_BSTORE_COMMIT 0x8000
1523
1524//
1525// Define base address for kernel and user space.
1526//
1527
1528#define UREGION_INDEX 0
1529
1530#define KREGION_INDEX 7
1531
1532#define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
1533
1534
1535#define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
1536
1537
1538void
1539__yield(
1540 void
1541 );
1542
1543void
1544__mf(
1545 void
1546 );
1547
1548void
1549__lfetch(
1550 int Level,
1551 VOID CONST *Address
1552 );
1553
1554void
1555__lfetchfault(
1556 int Level,
1557 VOID CONST *Address
1558 );
1559
1560//
1561// __lfetch control defines.
1562//
1563
1564#define MD_LFHINT_NONE 0x00
1565#define MD_LFHINT_NT1 0x01
1566#define MD_LFHINT_NT2 0x02
1567#define MD_LFHINT_NTA 0x03
1568
1569#pragma intrinsic (__yield)
1570#pragma intrinsic (__lfetch)
1571#pragma intrinsic (__lfetchfault)
1572#pragma intrinsic (__mf)
1573
1574
1575#define YieldProcessor __yield
1576#define MemoryBarrier __mf
1577#define PreFetchCacheLine __lfetch
1578
1579//
1580// PreFetchCacheLine level defines.
1581//
1582
1583#define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE
1584#define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA
1585
1586
1587//
1588// The following flags control the contents of the CONTEXT structure.
1589//
1590
1591#if !defined(RC_INVOKED)
1592
1593#define CONTEXT_IA64 0x00080000
1594
1595#define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
1596#define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
1597#define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
1598#define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
1599#define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
1600#define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
1601
1602
1603#define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
1604#define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
1605#define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
1606
1607#define CONTEXT_EXCEPTION_ACTIVE 0x8000000
1608#define CONTEXT_SERVICE_ACTIVE 0x10000000
1609#define CONTEXT_EXCEPTION_REQUEST 0x40000000
1610#define CONTEXT_EXCEPTION_REPORTING 0x80000000
1611
1612#endif // !defined(RC_INVOKED)
1613
1614//
1615// Context Frame
1616//
1617// This frame has a several purposes: 1) it is used as an argument to
1618// NtContinue, 2) it is used to construct a call frame for APC delivery,
1619// 3) it is used to construct a call frame for exception dispatching
1620// in user mode, 4) it is used in the user level thread creation
1621// routines, and 5) it is used to to pass thread state to debuggers.
1622//
1623// N.B. Because this record is used as a call frame, it must be EXACTLY
1624// a multiple of 16 bytes in length and aligned on a 16-byte boundary.
1625//
1626
1627typedef struct _CONTEXT {
1628
1629 //
1630 // The flags values within this flag control the contents of
1631 // a CONTEXT record.
1632 //
1633 // If the context record is used as an input parameter, then
1634 // for each portion of the context record controlled by a flag
1635 // whose value is set, it is assumed that that portion of the
1636 // context record contains valid context. If the context record
1637 // is being used to modify a thread's context, then only that
1638 // portion of the threads context will be modified.
1639 //
1640 // If the context record is used as an IN OUT parameter to capture
1641 // the context of a thread, then only those portions of the thread's
1642 // context corresponding to set flags will be returned.
1643 //
1644 // The context record is never used as an OUT only parameter.
1645 //
1646
1647 ULONG ContextFlags;
1648 ULONG Fill1[3]; // for alignment of following on 16-byte boundary
1649
1650 //
1651 // This section is specified/returned if the ContextFlags word contains
1652 // the flag CONTEXT_DEBUG.
1653 //
1654 // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
1655 //
1656
1657 ULONGLONG DbI0;
1658 ULONGLONG DbI1;
1659 ULONGLONG DbI2;
1660 ULONGLONG DbI3;
1661 ULONGLONG DbI4;
1662 ULONGLONG DbI5;
1663 ULONGLONG DbI6;
1664 ULONGLONG DbI7;
1665
1666 ULONGLONG DbD0;
1667 ULONGLONG DbD1;
1668 ULONGLONG DbD2;
1669 ULONGLONG DbD3;
1670 ULONGLONG DbD4;
1671 ULONGLONG DbD5;
1672 ULONGLONG DbD6;
1673 ULONGLONG DbD7;
1674
1675 //
1676 // This section is specified/returned if the ContextFlags word contains
1677 // the flag CONTEXT_LOWER_FLOATING_POINT.
1678 //
1679
1680 FLOAT128 FltS0;
1681 FLOAT128 FltS1;
1682 FLOAT128 FltS2;
1683 FLOAT128 FltS3;
1684 FLOAT128 FltT0;
1685 FLOAT128 FltT1;
1686 FLOAT128 FltT2;
1687 FLOAT128 FltT3;
1688 FLOAT128 FltT4;
1689 FLOAT128 FltT5;
1690 FLOAT128 FltT6;
1691 FLOAT128 FltT7;
1692 FLOAT128 FltT8;
1693 FLOAT128 FltT9;
1694
1695 //
1696 // This section is specified/returned if the ContextFlags word contains
1697 // the flag CONTEXT_HIGHER_FLOATING_POINT.
1698 //
1699
1700 FLOAT128 FltS4;
1701 FLOAT128 FltS5;
1702 FLOAT128 FltS6;
1703 FLOAT128 FltS7;
1704 FLOAT128 FltS8;
1705 FLOAT128 FltS9;
1706 FLOAT128 FltS10;
1707 FLOAT128 FltS11;
1708 FLOAT128 FltS12;
1709 FLOAT128 FltS13;
1710 FLOAT128 FltS14;
1711 FLOAT128 FltS15;
1712 FLOAT128 FltS16;
1713 FLOAT128 FltS17;
1714 FLOAT128 FltS18;
1715 FLOAT128 FltS19;
1716
1717 FLOAT128 FltF32;
1718 FLOAT128 FltF33;
1719 FLOAT128 FltF34;
1720 FLOAT128 FltF35;
1721 FLOAT128 FltF36;
1722 FLOAT128 FltF37;
1723 FLOAT128 FltF38;
1724 FLOAT128 FltF39;
1725
1726 FLOAT128 FltF40;
1727 FLOAT128 FltF41;
1728 FLOAT128 FltF42;
1729 FLOAT128 FltF43;
1730 FLOAT128 FltF44;
1731 FLOAT128 FltF45;
1732 FLOAT128 FltF46;
1733 FLOAT128 FltF47;
1734 FLOAT128 FltF48;
1735 FLOAT128 FltF49;
1736
1737 FLOAT128 FltF50;
1738 FLOAT128 FltF51;
1739 FLOAT128 FltF52;
1740 FLOAT128 FltF53;
1741 FLOAT128 FltF54;
1742 FLOAT128 FltF55;
1743 FLOAT128 FltF56;
1744 FLOAT128 FltF57;
1745 FLOAT128 FltF58;
1746 FLOAT128 FltF59;
1747
1748 FLOAT128 FltF60;
1749 FLOAT128 FltF61;
1750 FLOAT128 FltF62;
1751 FLOAT128 FltF63;
1752 FLOAT128 FltF64;
1753 FLOAT128 FltF65;
1754 FLOAT128 FltF66;
1755 FLOAT128 FltF67;
1756 FLOAT128 FltF68;
1757 FLOAT128 FltF69;
1758
1759 FLOAT128 FltF70;
1760 FLOAT128 FltF71;
1761 FLOAT128 FltF72;
1762 FLOAT128 FltF73;
1763 FLOAT128 FltF74;
1764 FLOAT128 FltF75;
1765 FLOAT128 FltF76;
1766 FLOAT128 FltF77;
1767 FLOAT128 FltF78;
1768 FLOAT128 FltF79;
1769
1770 FLOAT128 FltF80;
1771 FLOAT128 FltF81;
1772 FLOAT128 FltF82;
1773 FLOAT128 FltF83;
1774 FLOAT128 FltF84;
1775 FLOAT128 FltF85;
1776 FLOAT128 FltF86;
1777 FLOAT128 FltF87;
1778 FLOAT128 FltF88;
1779 FLOAT128 FltF89;
1780
1781 FLOAT128 FltF90;
1782 FLOAT128 FltF91;
1783 FLOAT128 FltF92;
1784 FLOAT128 FltF93;
1785 FLOAT128 FltF94;
1786 FLOAT128 FltF95;
1787 FLOAT128 FltF96;
1788 FLOAT128 FltF97;
1789 FLOAT128 FltF98;
1790 FLOAT128 FltF99;
1791
1792 FLOAT128 FltF100;
1793 FLOAT128 FltF101;
1794 FLOAT128 FltF102;
1795 FLOAT128 FltF103;
1796 FLOAT128 FltF104;
1797 FLOAT128 FltF105;
1798 FLOAT128 FltF106;
1799 FLOAT128 FltF107;
1800 FLOAT128 FltF108;
1801 FLOAT128 FltF109;
1802
1803 FLOAT128 FltF110;
1804 FLOAT128 FltF111;
1805 FLOAT128 FltF112;
1806 FLOAT128 FltF113;
1807 FLOAT128 FltF114;
1808 FLOAT128 FltF115;
1809 FLOAT128 FltF116;
1810 FLOAT128 FltF117;
1811 FLOAT128 FltF118;
1812 FLOAT128 FltF119;
1813
1814 FLOAT128 FltF120;
1815 FLOAT128 FltF121;
1816 FLOAT128 FltF122;
1817 FLOAT128 FltF123;
1818 FLOAT128 FltF124;
1819 FLOAT128 FltF125;
1820 FLOAT128 FltF126;
1821 FLOAT128 FltF127;
1822
1823 //
1824 // This section is specified/returned if the ContextFlags word contains
1825 // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
1826 //
1827
1828 ULONGLONG StFPSR; // FP status
1829
1830 //
1831 // This section is specified/returned if the ContextFlags word contains
1832 // the flag CONTEXT_INTEGER.
1833 //
1834 // N.B. The registers gp, sp, rp are part of the control context
1835 //
1836
1837 ULONGLONG IntGp; // r1, volatile
1838 ULONGLONG IntT0; // r2-r3, volatile
1839 ULONGLONG IntT1; //
1840 ULONGLONG IntS0; // r4-r7, preserved
1841 ULONGLONG IntS1;
1842 ULONGLONG IntS2;
1843 ULONGLONG IntS3;
1844 ULONGLONG IntV0; // r8, volatile
1845 ULONGLONG IntT2; // r9-r11, volatile
1846 ULONGLONG IntT3;
1847 ULONGLONG IntT4;
1848 ULONGLONG IntSp; // stack pointer (r12), special
1849 ULONGLONG IntTeb; // teb (r13), special
1850 ULONGLONG IntT5; // r14-r31, volatile
1851 ULONGLONG IntT6;
1852 ULONGLONG IntT7;
1853 ULONGLONG IntT8;
1854 ULONGLONG IntT9;
1855 ULONGLONG IntT10;
1856 ULONGLONG IntT11;
1857 ULONGLONG IntT12;
1858 ULONGLONG IntT13;
1859 ULONGLONG IntT14;
1860 ULONGLONG IntT15;
1861 ULONGLONG IntT16;
1862 ULONGLONG IntT17;
1863 ULONGLONG IntT18;
1864 ULONGLONG IntT19;
1865 ULONGLONG IntT20;
1866 ULONGLONG IntT21;
1867 ULONGLONG IntT22;
1868
1869 ULONGLONG IntNats; // Nat bits for r1-r31
1870 // r1-r31 in bits 1 thru 31.
1871 ULONGLONG Preds; // predicates, preserved
1872
1873 ULONGLONG BrRp; // return pointer, b0, preserved
1874 ULONGLONG BrS0; // b1-b5, preserved
1875 ULONGLONG BrS1;
1876 ULONGLONG BrS2;
1877 ULONGLONG BrS3;
1878 ULONGLONG BrS4;
1879 ULONGLONG BrT0; // b6-b7, volatile
1880 ULONGLONG BrT1;
1881
1882 //
1883 // This section is specified/returned if the ContextFlags word contains
1884 // the flag CONTEXT_CONTROL.
1885 //
1886
1887 // Other application registers
1888 ULONGLONG ApUNAT; // User Nat collection register, preserved
1889 ULONGLONG ApLC; // Loop counter register, preserved
1890 ULONGLONG ApEC; // Epilog counter register, preserved
1891 ULONGLONG ApCCV; // CMPXCHG value register, volatile
1892 ULONGLONG ApDCR; // Default control register (TBD)
1893
1894 // Register stack info
1895 ULONGLONG RsPFS; // Previous function state, preserved
1896 ULONGLONG RsBSP; // Backing store pointer, preserved
1897 ULONGLONG RsBSPSTORE;
1898 ULONGLONG RsRSC; // RSE configuration, volatile
1899 ULONGLONG RsRNAT; // RSE Nat collection register, preserved
1900
1901 // Trap Status Information
1902 ULONGLONG StIPSR; // Interruption Processor Status
1903 ULONGLONG StIIP; // Interruption IP
1904 ULONGLONG StIFS; // Interruption Function State
1905
1906 // iA32 related control registers
1907 ULONGLONG StFCR; // copy of Ar21
1908 ULONGLONG Eflag; // Eflag copy of Ar24
1909 ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
1910 ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
1911 ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
1912 ULONGLONG StFSR; // x86 FP status (copy of AR28)
1913 ULONGLONG StFIR; // x86 FP status (copy of AR29)
1914 ULONGLONG StFDR; // x86 FP status (copy of AR30)
1915
1916 ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
1917
1918} CONTEXT, *PCONTEXT;
1919
1920//
1921// Plabel descriptor structure definition
1922//
1923
1924typedef struct _PLABEL_DESCRIPTOR {
1925 ULONGLONG EntryPoint;
1926 ULONGLONG GlobalPointer;
1927} PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
1928
1929
1930
1931#endif // _IA64_
1932//
1933// Define an access token from a programmer's viewpoint. The structure is
1934// completely opaque and the programer is only allowed to have pointers
1935// to tokens.
1936//
1937
1938typedef PVOID PACCESS_TOKEN;
1939
1940//
1941// Pointer to a SECURITY_DESCRIPTOR opaque data type.
1942//
1943
1944typedef PVOID PSECURITY_DESCRIPTOR;
1945
1946//
1947// Define a pointer to the Security ID data type (an opaque data type)
1948//
1949
1950typedef PVOID PSID;
1951
1952typedef ULONG ACCESS_MASK;
1953typedef ACCESS_MASK *PACCESS_MASK;
1954
1955
1956//
1957// The following are masks for the predefined standard access types
1958//
1959
1960#define DELETE (0x00010000L)
1961#define READ_CONTROL (0x00020000L)
1962#define WRITE_DAC (0x00040000L)
1963#define WRITE_OWNER (0x00080000L)
1964#define SYNCHRONIZE (0x00100000L)
1965
1966#define STANDARD_RIGHTS_REQUIRED (0x000F0000L)
1967
1968#define STANDARD_RIGHTS_READ (READ_CONTROL)
1969#define STANDARD_RIGHTS_WRITE (READ_CONTROL)
1970#define STANDARD_RIGHTS_EXECUTE (READ_CONTROL)
1971
1972#define STANDARD_RIGHTS_ALL (0x001F0000L)
1973
1974#define SPECIFIC_RIGHTS_ALL (0x0000FFFFL)
1975
1976//
1977// AccessSystemAcl access type
1978//
1979
1980#define ACCESS_SYSTEM_SECURITY (0x01000000L)
1981
1982//
1983// MaximumAllowed access type
1984//
1985
1986#define MAXIMUM_ALLOWED (0x02000000L)
1987
1988//
1989// These are the generic rights.
1990//
1991
1992#define GENERIC_READ (0x80000000L)
1993#define GENERIC_WRITE (0x40000000L)
1994#define GENERIC_EXECUTE (0x20000000L)
1995#define GENERIC_ALL (0x10000000L)
1996
1997
1998//
1999// Define the generic mapping array. This is used to denote the
2000// mapping of each generic access right to a specific access mask.
2001//
2002
2003typedef struct _GENERIC_MAPPING {
2004 ACCESS_MASK GenericRead;
2005 ACCESS_MASK GenericWrite;
2006 ACCESS_MASK GenericExecute;
2007 ACCESS_MASK GenericAll;
2008} GENERIC_MAPPING;
2009typedef GENERIC_MAPPING *PGENERIC_MAPPING;
2010
2011
2012
2013////////////////////////////////////////////////////////////////////////
2014// //
2015// LUID_AND_ATTRIBUTES //
2016// //
2017////////////////////////////////////////////////////////////////////////
2018//
2019//
2020
2021
2022#include <pshpack4.h>
2023
2024typedef struct _LUID_AND_ATTRIBUTES {
2025 LUID Luid;
2026 ULONG Attributes;
2027 } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
2028typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
2029typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
2030
2031#include <poppack.h>
2032
2033
2034typedef enum {
2035
2036 WinNullSid = 0,
2037 WinWorldSid = 1,
2038 WinLocalSid = 2,
2039 WinCreatorOwnerSid = 3,
2040 WinCreatorGroupSid = 4,
2041 WinCreatorOwnerServerSid = 5,
2042 WinCreatorGroupServerSid = 6,
2043 WinNtAuthoritySid = 7,
2044 WinDialupSid = 8,
2045 WinNetworkSid = 9,
2046 WinBatchSid = 10,
2047 WinInteractiveSid = 11,
2048 WinServiceSid = 12,
2049 WinAnonymousSid = 13,
2050 WinProxySid = 14,
2051 WinEnterpriseControllersSid = 15,
2052 WinSelfSid = 16,
2053 WinAuthenticatedUserSid = 17,
2054 WinRestrictedCodeSid = 18,
2055 WinTerminalServerSid = 19,
2056 WinRemoteLogonIdSid = 20,
2057 WinLogonIdsSid = 21,
2058 WinLocalSystemSid = 22,
2059 WinLocalServiceSid = 23,
2060 WinNetworkServiceSid = 24,
2061 WinBuiltinDomainSid = 25,
2062 WinBuiltinAdministratorsSid = 26,
2063 WinBuiltinUsersSid = 27,
2064 WinBuiltinGuestsSid = 28,
2065 WinBuiltinPowerUsersSid = 29,
2066 WinBuiltinAccountOperatorsSid = 30,
2067 WinBuiltinSystemOperatorsSid = 31,
2068 WinBuiltinPrintOperatorsSid = 32,
2069 WinBuiltinBackupOperatorsSid = 33,
2070 WinBuiltinReplicatorSid = 34,
2071 WinBuiltinPreWindows2000CompatibleAccessSid = 35,
2072 WinBuiltinRemoteDesktopUsersSid = 36,
2073 WinBuiltinNetworkConfigurationOperatorsSid = 37,
2074 WinAccountAdministratorSid = 38,
2075 WinAccountGuestSid = 39,
2076 WinAccountKrbtgtSid = 40,
2077 WinAccountDomainAdminsSid = 41,
2078 WinAccountDomainUsersSid = 42,
2079 WinAccountDomainGuestsSid = 43,
2080 WinAccountComputersSid = 44,
2081 WinAccountControllersSid = 45,
2082 WinAccountCertAdminsSid = 46,
2083 WinAccountSchemaAdminsSid = 47,
2084 WinAccountEnterpriseAdminsSid = 48,
2085 WinAccountPolicyAdminsSid = 49,
2086 WinAccountRasAndIasServersSid = 50,
2087 WinNTLMAuthenticationSid = 51,
2088 WinDigestAuthenticationSid = 52,
2089 WinSChannelAuthenticationSid = 53,
2090 WinThisOrganizationSid = 54,
2091 WinOtherOrganizationSid = 55,
2092 WinBuiltinIncomingForestTrustBuildersSid = 56,
2093 WinBuiltinPerfMonitoringUsersSid = 57,
2094 WinBuiltinPerfLoggingUsersSid = 58,
2095 WinBuiltinAuthorizationAccessSid = 59,
2096 WinBuiltinTerminalServerLicenseServersSid = 60,
2097
2098} WELL_KNOWN_SID_TYPE;
2099
2100// This is the *current* ACL revision
2101
2102#define ACL_REVISION (2)
2103#define ACL_REVISION_DS (4)
2104
2105// This is the history of ACL revisions. Add a new one whenever
2106// ACL_REVISION is updated
2107
2108#define ACL_REVISION1 (1)
2109#define MIN_ACL_REVISION ACL_REVISION2
2110#define ACL_REVISION2 (2)
2111#define ACL_REVISION3 (3)
2112#define ACL_REVISION4 (4)
2113#define MAX_ACL_REVISION ACL_REVISION4
2114
2115typedef struct _ACL {
2116 UCHAR AclRevision;
2117 UCHAR Sbz1;
2118 USHORT AclSize;
2119 USHORT AceCount;
2120 USHORT Sbz2;
2121} ACL;
2122typedef ACL *PACL;
2123
2124//
2125// Current security descriptor revision value
2126//
2127
2128#define SECURITY_DESCRIPTOR_REVISION (1)
2129#define SECURITY_DESCRIPTOR_REVISION1 (1)
2130
2131//
2132// Privilege attributes
2133//
2134
2135#define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
2136#define SE_PRIVILEGE_ENABLED (0x00000002L)
2137#define SE_PRIVILEGE_REMOVED (0X00000004L)
2138#define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
2139
2140//
2141// Privilege Set Control flags
2142//
2143
2144#define PRIVILEGE_SET_ALL_NECESSARY (1)
2145
2146//
2147// Privilege Set - This is defined for a privilege set of one.
2148// If more than one privilege is needed, then this structure
2149// will need to be allocated with more space.
2150//
2151// Note: don't change this structure without fixing the INITIAL_PRIVILEGE_SET
2152// structure (defined in se.h)
2153//
2154
2155typedef struct _PRIVILEGE_SET {
2156 ULONG PrivilegeCount;
2157 ULONG Control;
2158 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
2159 } PRIVILEGE_SET, * PPRIVILEGE_SET;
2160
2161//
2162// These must be converted to LUIDs before use.
2163//
2164
2165#define SE_MIN_WELL_KNOWN_PRIVILEGE (2L)
2166#define SE_CREATE_TOKEN_PRIVILEGE (2L)
2167#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
2168#define SE_LOCK_MEMORY_PRIVILEGE (4L)
2169#define SE_INCREASE_QUOTA_PRIVILEGE (5L)
2170
2171
2172//
2173// Unsolicited Input is obsolete and unused.
2174//
2175
2176#define SE_UNSOLICITED_INPUT_PRIVILEGE (6L)
2177
2178
2179#define SE_MACHINE_ACCOUNT_PRIVILEGE (6L)
2180#define SE_TCB_PRIVILEGE (7L)
2181#define SE_SECURITY_PRIVILEGE (8L)
2182#define SE_TAKE_OWNERSHIP_PRIVILEGE (9L)
2183#define SE_LOAD_DRIVER_PRIVILEGE (10L)
2184#define SE_SYSTEM_PROFILE_PRIVILEGE (11L)
2185#define SE_SYSTEMTIME_PRIVILEGE (12L)
2186#define SE_PROF_SINGLE_PROCESS_PRIVILEGE (13L)
2187#define SE_INC_BASE_PRIORITY_PRIVILEGE (14L)
2188#define SE_CREATE_PAGEFILE_PRIVILEGE (15L)
2189#define SE_CREATE_PERMANENT_PRIVILEGE (16L)
2190#define SE_BACKUP_PRIVILEGE (17L)
2191#define SE_RESTORE_PRIVILEGE (18L)
2192#define SE_SHUTDOWN_PRIVILEGE (19L)
2193#define SE_DEBUG_PRIVILEGE (20L)
2194#define SE_AUDIT_PRIVILEGE (21L)
2195#define SE_SYSTEM_ENVIRONMENT_PRIVILEGE (22L)
2196#define SE_CHANGE_NOTIFY_PRIVILEGE (23L)
2197#define SE_REMOTE_SHUTDOWN_PRIVILEGE (24L)
2198#define SE_UNDOCK_PRIVILEGE (25L)
2199#define SE_SYNC_AGENT_PRIVILEGE (26L)
2200#define SE_ENABLE_DELEGATION_PRIVILEGE (27L)
2201#define SE_MANAGE_VOLUME_PRIVILEGE (28L)
2202#define SE_IMPERSONATE_PRIVILEGE (29L)
2203#define SE_CREATE_GLOBAL_PRIVILEGE (30L)
2204#define SE_MAX_WELL_KNOWN_PRIVILEGE (SE_CREATE_GLOBAL_PRIVILEGE)
2205
2206//
2207// Impersonation Level
2208//
2209// Impersonation level is represented by a pair of bits in Windows.
2210// If a new impersonation level is added or lowest value is changed from
2211// 0 to something else, fix the Windows CreateFile call.
2212//
2213
2214typedef enum _SECURITY_IMPERSONATION_LEVEL {
2215 SecurityAnonymous,
2216 SecurityIdentification,
2217 SecurityImpersonation,
2218 SecurityDelegation
2219 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
2220
2221#define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
2222#define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
2223#define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
2224#define VALID_IMPERSONATION_LEVEL(L) (((L) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((L) <= SECURITY_MAX_IMPERSONATION_LEVEL))
2225//
2226// Security Tracking Mode
2227//
2228
2229#define SECURITY_DYNAMIC_TRACKING (TRUE)
2230#define SECURITY_STATIC_TRACKING (FALSE)
2231
2232typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE,
2233 * PSECURITY_CONTEXT_TRACKING_MODE;
2234
2235
2236
2237//
2238// Quality Of Service
2239//
2240
2241typedef struct _SECURITY_QUALITY_OF_SERVICE {
2242 ULONG Length;
2243 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2244 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
2245 BOOLEAN EffectiveOnly;
2246 } SECURITY_QUALITY_OF_SERVICE, * PSECURITY_QUALITY_OF_SERVICE;
2247
2248
2249//
2250// Used to represent information related to a thread impersonation
2251//
2252
2253typedef struct _SE_IMPERSONATION_STATE {
2254 PACCESS_TOKEN Token;
2255 BOOLEAN CopyOnOpen;
2256 BOOLEAN EffectiveOnly;
2257 SECURITY_IMPERSONATION_LEVEL Level;
2258} SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
2259
2260
2261typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
2262
2263#define OWNER_SECURITY_INFORMATION (0x00000001L)
2264#define GROUP_SECURITY_INFORMATION (0x00000002L)
2265#define DACL_SECURITY_INFORMATION (0x00000004L)
2266#define SACL_SECURITY_INFORMATION (0x00000008L)
2267
2268#define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
2269#define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
2270#define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
2271#define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
2272
2273
2274#define LOW_PRIORITY 0 // Lowest thread priority level
2275#define LOW_REALTIME_PRIORITY 16 // Lowest realtime priority level
2276#define HIGH_PRIORITY 31 // Highest thread priority level
2277#define MAXIMUM_PRIORITY 32 // Number of thread priority levels
2278
2279#define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
2280
2281#define MAXIMUM_SUSPEND_COUNT MAXCHAR // Maximum times thread can be suspended
2282
2283
2284//
2285// Define system time structure.
2286//
2287
2288typedef struct _KSYSTEM_TIME {
2289 ULONG LowPart;
2290 LONG High1Time;
2291 LONG High2Time;
2292} KSYSTEM_TIME, *PKSYSTEM_TIME;
2293
2294//
2295// Thread priority
2296//
2297
2298typedef LONG KPRIORITY;
2299
2300//
2301// Spin Lock
2302//
2303
2304
2305
2306typedef ULONG_PTR KSPIN_LOCK;
2307typedef KSPIN_LOCK *PKSPIN_LOCK;
2308
2309
2310
2311//
2312// Define per processor lock queue structure.
2313//
2314// N.B. The lock field of the spin lock queue structure contains the address
2315// of the associated kernel spin lock, an owner bit, and a lock bit. Bit
2316// 0 of the spin lock address is the wait bit and bit 1 is the owner bit.
2317// The use of this field is such that the bits can be set and cleared
2318// noninterlocked, however, the back pointer must be preserved.
2319//
2320// The lock wait bit is set when a processor enqueues itself on the lock
2321// queue and it is not the only entry in the queue. The processor will
2322// spin on this bit waiting for the lock to be granted.
2323//
2324// The owner bit is set when the processor owns the respective lock.
2325//
2326// The next field of the spin lock queue structure is used to line the
2327// queued lock structures together in fifo order. It also can set set and
2328// cleared noninterlocked.
2329//
2330
2331#define LOCK_QUEUE_WAIT 1
2332#define LOCK_QUEUE_OWNER 2
2333
2334typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
2335 LockQueueDispatcherLock,
2336 LockQueueUnusedSpare1,
2337 LockQueuePfnLock,
2338 LockQueueSystemSpaceLock,
2339 LockQueueVacbLock,
2340 LockQueueMasterLock,
2341 LockQueueNonPagedPoolLock,
2342 LockQueueIoCancelLock,
2343 LockQueueWorkQueueLock,
2344 LockQueueIoVpbLock,
2345 LockQueueIoDatabaseLock,
2346 LockQueueIoCompletionLock,
2347 LockQueueNtfsStructLock,
2348 LockQueueAfdWorkQueueLock,
2349 LockQueueBcbLock,
2350 LockQueueMmNonPagedPoolLock,
2351 LockQueueMaximumLock
2352} KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
2353
2354typedef struct _KSPIN_LOCK_QUEUE {
2355 struct _KSPIN_LOCK_QUEUE * volatile Next;
2356 PKSPIN_LOCK volatile Lock;
2357} KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
2358
2359typedef struct _KLOCK_QUEUE_HANDLE {
2360 KSPIN_LOCK_QUEUE LockQueue;
2361 KIRQL OldIrql;
2362} KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
2363
2364
2365//
2366// Interrupt routine (first level dispatch)
2367//
2368
2369typedef
2370VOID
2371(*PKINTERRUPT_ROUTINE) (
2372 VOID
2373 );
2374
2375//
2376// Profile source types
2377//
2378typedef enum _KPROFILE_SOURCE {
2379 ProfileTime,
2380 ProfileAlignmentFixup,
2381 ProfileTotalIssues,
2382 ProfilePipelineDry,
2383 ProfileLoadInstructions,
2384 ProfilePipelineFrozen,
2385 ProfileBranchInstructions,
2386 ProfileTotalNonissues,
2387 ProfileDcacheMisses,
2388 ProfileIcacheMisses,
2389 ProfileCacheMisses,
2390 ProfileBranchMispredictions,
2391 ProfileStoreInstructions,
2392 ProfileFpInstructions,
2393 ProfileIntegerInstructions,
2394 Profile2Issue,
2395 Profile3Issue,
2396 Profile4Issue,
2397 ProfileSpecialInstructions,
2398 ProfileTotalCycles,
2399 ProfileIcacheIssues,
2400 ProfileDcacheAccesses,
2401 ProfileMemoryBarrierCycles,
2402 ProfileLoadLinkedIssues,
2403 ProfileMaximum
2404} KPROFILE_SOURCE;
2405
2406//
2407// for move macros
2408//
2409#ifdef _MAC
2410#ifndef _INC_STRING
2411#include <string.h>
2412#endif /* _INC_STRING */
2413#else
2414#include <string.h>
2415#endif // _MAC
2416
2417
2418#ifndef _SLIST_HEADER_
2419#define _SLIST_HEADER_
2420
2421#if defined(_WIN64)
2422
2423//
2424// The type SINGLE_LIST_ENTRY is not suitable for use with SLISTs. For
2425// WIN64, an entry on an SLIST is required to be 16-byte aligned, while a
2426// SINGLE_LIST_ENTRY structure has only 8 byte alignment.
2427//
2428// Therefore, all SLIST code should use the SLIST_ENTRY type instead of the
2429// SINGLE_LIST_ENTRY type.
2430//
2431
2432#pragma warning(push)
2433#pragma warning(disable:4324) // structure padded due to align()
2434typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
2435typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
2436 PSLIST_ENTRY Next;
2437} SLIST_ENTRY;
2438#pragma warning(pop)
2439
2440#else
2441
2442#define SLIST_ENTRY SINGLE_LIST_ENTRY
2443#define _SLIST_ENTRY _SINGLE_LIST_ENTRY
2444#define PSLIST_ENTRY PSINGLE_LIST_ENTRY
2445
2446#endif
2447
2448#if defined(_WIN64)
2449
2450typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
2451 ULONGLONG Alignment;
2452 ULONGLONG Region;
2453} SLIST_HEADER;
2454
2455typedef struct _SLIST_HEADER *PSLIST_HEADER;
2456
2457#else
2458
2459typedef union _SLIST_HEADER {
2460 ULONGLONG Alignment;
2461 struct {
2462 SLIST_ENTRY Next;
2463 USHORT Depth;
2464 USHORT Sequence;
2465 };
2466} SLIST_HEADER, *PSLIST_HEADER;
2467
2468#endif
2469
2470#endif
2471
2472//
2473// If debugging support enabled, define an ASSERT macro that works. Otherwise
2474// define the ASSERT macro to expand to an empty expression.
2475//
2476// The ASSERT macro has been updated to be an expression instead of a statement.
2477//
2478
2479NTSYSAPI
2480VOID
2481NTAPI
2482RtlAssert(
2483 PVOID FailedAssertion,
2484 PVOID FileName,
2485 ULONG LineNumber,
2486 PCHAR Message
2487 );
2488
2489#if DBG
2490
2491#define ASSERT( exp ) \
2492 ((!(exp)) ? \
2493 (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \
2494 TRUE)
2495
2496#define ASSERTMSG( msg, exp ) \
2497 ((!(exp)) ? \
2498 (RtlAssert( #exp, __FILE__, __LINE__, msg ),FALSE) : \
2499 TRUE)
2500
2501#define RTL_SOFT_ASSERT(_exp) \
2502 ((!(_exp)) ? \
2503 (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n", __FILE__, __LINE__, #_exp),FALSE) : \
2504 TRUE)
2505
2506#define RTL_SOFT_ASSERTMSG(_msg, _exp) \
2507 ((!(_exp)) ? \
2508 (DbgPrint("%s(%d): Soft assertion failed\n Expression: %s\n Message: %s\n", __FILE__, __LINE__, #_exp, (_msg)),FALSE) : \
2509 TRUE)
2510
2511#define RTL_VERIFY ASSERT
2512#define RTL_VERIFYMSG ASSERTMSG
2513
2514#define RTL_SOFT_VERIFY RTL_SOFT_ASSERT
2515#define RTL_SOFT_VERIFYMSG RTL_SOFT_ASSERTMSG
2516
2517#else
2518#define ASSERT( exp ) ((void) 0)
2519#define ASSERTMSG( msg, exp ) ((void) 0)
2520
2521#define RTL_SOFT_ASSERT(_exp) ((void) 0)
2522#define RTL_SOFT_ASSERTMSG(_msg, _exp) ((void) 0)
2523
2524#define RTL_VERIFY( exp ) ((exp) ? TRUE : FALSE)
2525#define RTL_VERIFYMSG( msg, exp ) ((exp) ? TRUE : FALSE)
2526
2527#define RTL_SOFT_VERIFY(_exp) ((_exp) ? TRUE : FALSE)
2528#define RTL_SOFT_VERIFYMSG(msg, _exp) ((_exp) ? TRUE : FALSE)
2529
2530#endif // DBG
2531
2532//
2533// Doubly-linked list manipulation routines.
2534//
2535
2536
2537//
2538// VOID
2539// InitializeListHead32(
2540// PLIST_ENTRY32 ListHead
2541// );
2542//
2543
2544#define InitializeListHead32(ListHead) (\
2545 (ListHead)->Flink = (ListHead)->Blink = PtrToUlong((ListHead)))
2546
2547#if !defined(MIDL_PASS) && !defined(SORTPP_PASS)
2548
2549
2550VOID
2551FORCEINLINE
2552InitializeListHead(
2553 IN PLIST_ENTRY ListHead
2554 )
2555{
2556 ListHead->Flink = ListHead->Blink = ListHead;
2557}
2558
2559//
2560// BOOLEAN
2561// IsListEmpty(
2562// PLIST_ENTRY ListHead
2563// );
2564//
2565
2566#define IsListEmpty(ListHead) \
2567 ((ListHead)->Flink == (ListHead))
2568
2569
2570
2571BOOLEAN
2572FORCEINLINE
2573RemoveEntryList(
2574 IN PLIST_ENTRY Entry
2575 )
2576{
2577 PLIST_ENTRY Blink;
2578 PLIST_ENTRY Flink;
2579
2580 Flink = Entry->Flink;
2581 Blink = Entry->Blink;
2582 Blink->Flink = Flink;
2583 Flink->Blink = Blink;
2584 return (BOOLEAN)(Flink == Blink);
2585}
2586
2587PLIST_ENTRY
2588FORCEINLINE
2589RemoveHeadList(
2590 IN PLIST_ENTRY ListHead
2591 )
2592{
2593 PLIST_ENTRY Flink;
2594 PLIST_ENTRY Entry;
2595
2596 Entry = ListHead->Flink;
2597 Flink = Entry->Flink;
2598 ListHead->Flink = Flink;
2599 Flink->Blink = ListHead;
2600 return Entry;
2601}
2602
2603
2604
2605PLIST_ENTRY
2606FORCEINLINE
2607RemoveTailList(
2608 IN PLIST_ENTRY ListHead
2609 )
2610{
2611 PLIST_ENTRY Blink;
2612 PLIST_ENTRY Entry;
2613
2614 Entry = ListHead->Blink;
2615 Blink = Entry->Blink;
2616 ListHead->Blink = Blink;
2617 Blink->Flink = ListHead;
2618 return Entry;
2619}
2620
2621
2622VOID
2623FORCEINLINE
2624InsertTailList(
2625 IN PLIST_ENTRY ListHead,
2626 IN PLIST_ENTRY Entry
2627 )
2628{
2629 PLIST_ENTRY Blink;
2630
2631 Blink = ListHead->Blink;
2632 Entry->Flink = ListHead;
2633 Entry->Blink = Blink;
2634 Blink->Flink = Entry;
2635 ListHead->Blink = Entry;
2636}
2637
2638
2639VOID
2640FORCEINLINE
2641InsertHeadList(
2642 IN PLIST_ENTRY ListHead,
2643 IN PLIST_ENTRY Entry
2644 )
2645{
2646 PLIST_ENTRY Flink;
2647
2648 Flink = ListHead->Flink;
2649 Entry->Flink = Flink;
2650 Entry->Blink = ListHead;
2651 Flink->Blink = Entry;
2652 ListHead->Flink = Entry;
2653}
2654
2655
2656//
2657//
2658// PSINGLE_LIST_ENTRY
2659// PopEntryList(
2660// PSINGLE_LIST_ENTRY ListHead
2661// );
2662//
2663
2664#define PopEntryList(ListHead) \
2665 (ListHead)->Next;\
2666 {\
2667 PSINGLE_LIST_ENTRY FirstEntry;\
2668 FirstEntry = (ListHead)->Next;\
2669 if (FirstEntry != NULL) { \
2670 (ListHead)->Next = FirstEntry->Next;\
2671 } \
2672 }
2673
2674
2675//
2676// VOID
2677// PushEntryList(
2678// PSINGLE_LIST_ENTRY ListHead,
2679// PSINGLE_LIST_ENTRY Entry
2680// );
2681//
2682
2683#define PushEntryList(ListHead,Entry) \
2684 (Entry)->Next = (ListHead)->Next; \
2685 (ListHead)->Next = (Entry)
2686
2687#endif // !MIDL_PASS
2688
2689
2690
2691
2692
2693#if defined (_MSC_VER) && ( _MSC_VER >= 900 )
2694
2695PVOID
2696_ReturnAddress (
2697 VOID
2698 );
2699
2700#pragma intrinsic(_ReturnAddress)
2701
2702#endif
2703
2704#if (defined(_M_AMD64) || defined(_M_IA64)) && !defined(_REALLY_GET_CALLERS_CALLER_)
2705
2706#define RtlGetCallersAddress(CallersAddress, CallersCaller) \
2707 *CallersAddress = (PVOID)_ReturnAddress(); \
2708 *CallersCaller = NULL;
2709
2710#else
2711
2712NTSYSAPI
2713VOID
2714NTAPI
2715RtlGetCallersAddress(
2716 OUT PVOID *CallersAddress,
2717 OUT PVOID *CallersCaller
2718 );
2719
2720#endif
2721
2722NTSYSAPI
2723ULONG
2724NTAPI
2725RtlWalkFrameChain (
2726 OUT PVOID *Callers,
2727 IN ULONG Count,
2728 IN ULONG Flags
2729 );
2730
2731//
2732// Subroutines for dealing with the Registry
2733//
2734
2735typedef NTSTATUS (NTAPI * PRTL_QUERY_REGISTRY_ROUTINE)(
2736 IN PWSTR ValueName,
2737 IN ULONG ValueType,
2738 IN PVOID ValueData,
2739 IN ULONG ValueLength,
2740 IN PVOID Context,
2741 IN PVOID EntryContext
2742 );
2743
2744typedef struct _RTL_QUERY_REGISTRY_TABLE {
2745 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
2746 ULONG Flags;
2747 PWSTR Name;
2748 PVOID EntryContext;
2749 ULONG DefaultType;
2750 PVOID DefaultData;
2751 ULONG DefaultLength;
2752
2753} RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
2754
2755
2756//
2757// The following flags specify how the Name field of a RTL_QUERY_REGISTRY_TABLE
2758// entry is interpreted. A NULL name indicates the end of the table.
2759//
2760
2761#define RTL_QUERY_REGISTRY_SUBKEY 0x00000001 // Name is a subkey and remainder of
2762 // table or until next subkey are value
2763 // names for that subkey to look at.
2764
2765#define RTL_QUERY_REGISTRY_TOPKEY 0x00000002 // Reset current key to original key for
2766 // this and all following table entries.
2767
2768#define RTL_QUERY_REGISTRY_REQUIRED 0x00000004 // Fail if no match found for this table
2769 // entry.
2770
2771#define RTL_QUERY_REGISTRY_NOVALUE 0x00000008 // Used to mark a table entry that has no
2772 // value name, just wants a call out, not
2773 // an enumeration of all values.
2774
2775#define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010 // Used to suppress the expansion of
2776 // REG_MULTI_SZ into multiple callouts or
2777 // to prevent the expansion of environment
2778 // variable values in REG_EXPAND_SZ
2779
2780#define RTL_QUERY_REGISTRY_DIRECT 0x00000020 // QueryRoutine field ignored. EntryContext
2781 // field points to location to store value.
2782 // For null terminated strings, EntryContext
2783 // points to UNICODE_STRING structure that
2784 // that describes maximum size of buffer.
2785 // If .Buffer field is NULL then a buffer is
2786 // allocated.
2787 //
2788
2789#define RTL_QUERY_REGISTRY_DELETE 0x00000040 // Used to delete value keys after they
2790 // are queried.
2791
2792NTSYSAPI
2793NTSTATUS
2794NTAPI
2795RtlQueryRegistryValues(
2796 IN ULONG RelativeTo,
2797 IN PCWSTR Path,
2798 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
2799 IN PVOID Context,
2800 IN PVOID Environment OPTIONAL
2801 );
2802
2803NTSYSAPI
2804NTSTATUS
2805NTAPI
2806RtlWriteRegistryValue(
2807 IN ULONG RelativeTo,
2808 IN PCWSTR Path,
2809 IN PCWSTR ValueName,
2810 IN ULONG ValueType,
2811 IN PVOID ValueData,
2812 IN ULONG ValueLength
2813 );
2814
2815NTSYSAPI
2816NTSTATUS
2817NTAPI
2818RtlDeleteRegistryValue(
2819 IN ULONG RelativeTo,
2820 IN PCWSTR Path,
2821 IN PCWSTR ValueName
2822 );
2823
2824
2825
2826NTSYSAPI
2827NTSTATUS
2828NTAPI
2829RtlCreateRegistryKey(
2830 IN ULONG RelativeTo,
2831 IN PWSTR Path
2832 );
2833
2834NTSYSAPI
2835NTSTATUS
2836NTAPI
2837RtlCheckRegistryKey(
2838 IN ULONG RelativeTo,
2839 IN PWSTR Path
2840 );
2841
2842
2843//
2844// The following values for the RelativeTo parameter determine what the
2845// Path parameter to RtlQueryRegistryValues is relative to.
2846//
2847
2848#define RTL_REGISTRY_ABSOLUTE 0 // Path is a full path
2849#define RTL_REGISTRY_SERVICES 1 // \Registry\Machine\System\CurrentControlSet\Services
2850#define RTL_REGISTRY_CONTROL 2 // \Registry\Machine\System\CurrentControlSet\Control
2851#define RTL_REGISTRY_WINDOWS_NT 3 // \Registry\Machine\Software\Microsoft\Windows NT\CurrentVersion
2852#define RTL_REGISTRY_DEVICEMAP 4 // \Registry\Machine\Hardware\DeviceMap
2853#define RTL_REGISTRY_USER 5 // \Registry\User\CurrentUser
2854#define RTL_REGISTRY_MAXIMUM 6
2855#define RTL_REGISTRY_HANDLE 0x40000000 // Low order bits are registry handle
2856#define RTL_REGISTRY_OPTIONAL 0x80000000 // Indicates the key node is optional
2857
2858NTSYSAPI
2859NTSTATUS
2860NTAPI
2861RtlCharToInteger (
2862 PCSZ String,
2863 ULONG Base,
2864 PULONG Value
2865 );
2866
2867NTSYSAPI
2868NTSTATUS
2869NTAPI
2870RtlIntegerToUnicodeString (
2871 ULONG Value,
2872 ULONG Base,
2873 PUNICODE_STRING String
2874 );
2875
2876NTSYSAPI
2877NTSTATUS
2878NTAPI
2879RtlInt64ToUnicodeString (
2880 IN ULONGLONG Value,
2881 IN ULONG Base OPTIONAL,
2882 IN OUT PUNICODE_STRING String
2883 );
2884
2885#ifdef _WIN64
2886#define RtlIntPtrToUnicodeString(Value, Base, String) RtlInt64ToUnicodeString(Value, Base, String)
2887#else
2888#define RtlIntPtrToUnicodeString(Value, Base, String) RtlIntegerToUnicodeString(Value, Base, String)
2889#endif
2890
2891NTSYSAPI
2892NTSTATUS
2893NTAPI
2894RtlUnicodeStringToInteger (
2895 PCUNICODE_STRING String,
2896 ULONG Base,
2897 PULONG Value
2898 );
2899
2900
2901
2902//
2903// String manipulation routines
2904//
2905
2906#ifdef _NTSYSTEM_
2907
2908#define NLS_MB_CODE_PAGE_TAG NlsMbCodePageTag
2909#define NLS_MB_OEM_CODE_PAGE_TAG NlsMbOemCodePageTag
2910
2911#else
2912
2913#define NLS_MB_CODE_PAGE_TAG (*NlsMbCodePageTag)
2914#define NLS_MB_OEM_CODE_PAGE_TAG (*NlsMbOemCodePageTag)
2915
2916#endif // _NTSYSTEM_
2917
2918extern BOOLEAN NLS_MB_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
2919extern BOOLEAN NLS_MB_OEM_CODE_PAGE_TAG; // TRUE -> Multibyte CP, FALSE -> Singlebyte
2920
2921NTSYSAPI
2922VOID
2923NTAPI
2924RtlInitString(
2925 PSTRING DestinationString,
2926 PCSZ SourceString
2927 );
2928
2929NTSYSAPI
2930VOID
2931NTAPI
2932RtlInitAnsiString(
2933 PANSI_STRING DestinationString,
2934 PCSZ SourceString
2935 );
2936
2937NTSYSAPI
2938VOID
2939NTAPI
2940RtlInitUnicodeString(
2941 PUNICODE_STRING DestinationString,
2942 PCWSTR SourceString
2943 );
2944
2945#define RtlInitEmptyUnicodeString(_ucStr,_buf,_bufSize) \
2946 ((_ucStr)->Buffer = (_buf), \
2947 (_ucStr)->Length = 0, \
2948 (_ucStr)->MaximumLength = (USHORT)(_bufSize))
2949
2950
2951NTSYSAPI
2952VOID
2953NTAPI
2954RtlCopyString(
2955 PSTRING DestinationString,
2956 const STRING * SourceString
2957 );
2958
2959NTSYSAPI
2960CHAR
2961NTAPI
2962RtlUpperChar (
2963 CHAR Character
2964 );
2965
2966NTSYSAPI
2967LONG
2968NTAPI
2969RtlCompareString(
2970 const STRING * String1,
2971 const STRING * String2,
2972 BOOLEAN CaseInSensitive
2973 );
2974
2975NTSYSAPI
2976BOOLEAN
2977NTAPI
2978RtlEqualString(
2979 const STRING * String1,
2980 const STRING * String2,
2981 BOOLEAN CaseInSensitive
2982 );
2983
2984
2985NTSYSAPI
2986VOID
2987NTAPI
2988RtlUpperString(
2989 PSTRING DestinationString,
2990 const STRING * SourceString
2991 );
2992
2993//
2994// NLS String functions
2995//
2996
2997NTSYSAPI
2998NTSTATUS
2999NTAPI
3000RtlAnsiStringToUnicodeString(
3001 PUNICODE_STRING DestinationString,
3002 PCANSI_STRING SourceString,
3003 BOOLEAN AllocateDestinationString
3004 );
3005
3006
3007NTSYSAPI
3008NTSTATUS
3009NTAPI
3010RtlUnicodeStringToAnsiString(
3011 PANSI_STRING DestinationString,
3012 PCUNICODE_STRING SourceString,
3013 BOOLEAN AllocateDestinationString
3014 );
3015
3016
3017NTSYSAPI
3018LONG
3019NTAPI
3020RtlCompareUnicodeString(
3021 PCUNICODE_STRING String1,
3022 PCUNICODE_STRING String2,
3023 BOOLEAN CaseInSensitive
3024 );
3025
3026NTSYSAPI
3027BOOLEAN
3028NTAPI
3029RtlEqualUnicodeString(
3030 PCUNICODE_STRING String1,
3031 PCUNICODE_STRING String2,
3032 BOOLEAN CaseInSensitive
3033 );
3034
3035#define HASH_STRING_ALGORITHM_DEFAULT (0)
3036#define HASH_STRING_ALGORITHM_X65599 (1)
3037#define HASH_STRING_ALGORITHM_INVALID (0xffffffff)
3038
3039NTSYSAPI
3040NTSTATUS
3041NTAPI
3042RtlHashUnicodeString(
3043 IN const UNICODE_STRING *String,
3044 IN BOOLEAN CaseInSensitive,
3045 IN ULONG HashAlgorithm,
3046 OUT PULONG HashValue
3047 );
3048
3049
3050NTSYSAPI
3051BOOLEAN
3052NTAPI
3053RtlPrefixUnicodeString(
3054 IN PCUNICODE_STRING String1,
3055 IN PCUNICODE_STRING String2,
3056 IN BOOLEAN CaseInSensitive
3057 );
3058
3059NTSYSAPI
3060NTSTATUS
3061NTAPI
3062RtlUpcaseUnicodeString(
3063 PUNICODE_STRING DestinationString,
3064 PCUNICODE_STRING SourceString,
3065 BOOLEAN AllocateDestinationString
3066 );
3067
3068
3069NTSYSAPI
3070VOID
3071NTAPI
3072RtlCopyUnicodeString(
3073 PUNICODE_STRING DestinationString,
3074 PCUNICODE_STRING SourceString
3075 );
3076
3077NTSYSAPI
3078NTSTATUS
3079NTAPI
3080RtlAppendUnicodeStringToString (
3081 PUNICODE_STRING Destination,
3082 PCUNICODE_STRING Source
3083 );
3084
3085NTSYSAPI
3086NTSTATUS
3087NTAPI
3088RtlAppendUnicodeToString (
3089 PUNICODE_STRING Destination,
3090 PCWSTR Source
3091 );
3092
3093
3094
3095NTSYSAPI
3096WCHAR
3097NTAPI
3098RtlUpcaseUnicodeChar(
3099 WCHAR SourceCharacter
3100 );
3101
3102NTSYSAPI
3103WCHAR
3104NTAPI
3105RtlDowncaseUnicodeChar(
3106 WCHAR SourceCharacter
3107 );
3108
3109
3110
3111NTSYSAPI
3112VOID
3113NTAPI
3114RtlFreeUnicodeString(
3115 PUNICODE_STRING UnicodeString
3116 );
3117
3118NTSYSAPI
3119VOID
3120NTAPI
3121RtlFreeAnsiString(
3122 PANSI_STRING AnsiString
3123 );
3124
3125
3126NTSYSAPI
3127ULONG
3128NTAPI
3129RtlxAnsiStringToUnicodeSize(
3130 PCANSI_STRING AnsiString
3131 );
3132
3133//
3134// NTSYSAPI
3135// ULONG
3136// NTAPI
3137// RtlAnsiStringToUnicodeSize(
3138// PANSI_STRING AnsiString
3139// );
3140//
3141
3142#define RtlAnsiStringToUnicodeSize(STRING) ( \
3143 NLS_MB_CODE_PAGE_TAG ? \
3144 RtlxAnsiStringToUnicodeSize(STRING) : \
3145 ((STRING)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
3146)
3147
3148
3149
3150
3151#include <guiddef.h>
3152
3153
3154
3155#ifndef DEFINE_GUIDEX
3156 #define DEFINE_GUIDEX(name) EXTERN_C const CDECL GUID name
3157#endif // !defined(DEFINE_GUIDEX)
3158
3159#ifndef STATICGUIDOF
3160 #define STATICGUIDOF(guid) STATIC_##guid
3161#endif // !defined(STATICGUIDOF)
3162
3163#ifndef __IID_ALIGNED__
3164 #define __IID_ALIGNED__
3165 #ifdef __cplusplus
3166 inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
3167 {
3168 return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
3169 }
3170 #else // !__cplusplus
3171 #define IsEqualGUIDAligned(guid1, guid2) \
3172 ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
3173 #endif // !__cplusplus
3174#endif // !__IID_ALIGNED__
3175
3176NTSYSAPI
3177NTSTATUS
3178NTAPI
3179RtlStringFromGUID(
3180 IN REFGUID Guid,
3181 OUT PUNICODE_STRING GuidString
3182 );
3183
3184NTSYSAPI
3185NTSTATUS
3186NTAPI
3187RtlGUIDFromString(
3188 IN PUNICODE_STRING GuidString,
3189 OUT GUID* Guid
3190 );
3191
3192//
3193// Fast primitives to compare, move, and zero memory
3194//
3195
3196
3197
3198NTSYSAPI
3199SIZE_T
3200NTAPI
3201RtlCompareMemory (
3202 const VOID *Source1,
3203 const VOID *Source2,
3204 SIZE_T Length
3205 );
3206
3207#define RtlEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
3208
3209#if defined(_M_AMD64)
3210
3211NTSYSAPI
3212VOID
3213NTAPI
3214RtlCopyMemory (
3215 VOID UNALIGNED *Destination,
3216 CONST VOID UNALIGNED *Source,
3217 SIZE_T Length
3218 );
3219
3220NTSYSAPI
3221VOID
3222NTAPI
3223RtlMoveMemory (
3224 VOID UNALIGNED *Destination,
3225 CONST VOID UNALIGNED *Source,
3226 SIZE_T Length
3227 );
3228
3229NTSYSAPI
3230VOID
3231NTAPI
3232RtlFillMemory (
3233 VOID UNALIGNED *Destination,
3234 SIZE_T Length,
3235 IN UCHAR Fill
3236 );
3237
3238NTSYSAPI
3239VOID
3240NTAPI
3241RtlZeroMemory (
3242 VOID UNALIGNED *Destination,
3243 SIZE_T Length
3244 );
3245
3246#else
3247
3248#define RtlMoveMemory(Destination,Source,Length) memmove((Destination),(Source),(Length))
3249#define RtlCopyMemory(Destination,Source,Length) memcpy((Destination),(Source),(Length))
3250#define RtlFillMemory(Destination,Length,Fill) memset((Destination),(Fill),(Length))
3251#define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length))
3252
3253#endif
3254
3255#if !defined(MIDL_PASS)
3256FORCEINLINE
3257PVOID
3258RtlSecureZeroMemory(
3259 IN PVOID ptr,
3260 IN SIZE_T cnt
3261 )
3262{
3263 volatile char *vptr = (volatile char *)ptr;
3264 while (cnt) {
3265 *vptr = 0;
3266 vptr++;
3267 cnt--;
3268 }
3269 return ptr;
3270}
3271#endif
3272
3273
3274
3275#define RtlCopyBytes RtlCopyMemory
3276#define RtlZeroBytes RtlZeroMemory
3277#define RtlFillBytes RtlFillMemory
3278
3279#if defined(_M_AMD64)
3280
3281NTSYSAPI
3282VOID
3283NTAPI
3284RtlCopyMemoryNonTemporal (
3285 VOID UNALIGNED *Destination,
3286 CONST VOID UNALIGNED *Source,
3287 SIZE_T Length
3288 );
3289
3290#else
3291
3292#define RtlCopyMemoryNonTemporal RtlCopyMemory
3293
3294#endif
3295
3296NTSYSAPI
3297VOID
3298FASTCALL
3299RtlPrefetchMemoryNonTemporal(
3300 IN PVOID Source,
3301 IN SIZE_T Length
3302 );
3303
3304//
3305// Define kernel debugger print prototypes and macros.
3306//
3307// N.B. The following function cannot be directly imported because there are
3308// a few places in the source tree where this function is redefined.
3309//
3310
3311VOID
3312NTAPI
3313DbgBreakPoint(
3314 VOID
3315 );
3316
3317
3318
3319NTSYSAPI
3320VOID
3321NTAPI
3322DbgBreakPointWithStatus(
3323 IN ULONG Status
3324 );
3325
3326
3327
3328#define DBG_STATUS_CONTROL_C 1
3329#define DBG_STATUS_SYSRQ 2
3330#define DBG_STATUS_BUGCHECK_FIRST 3
3331#define DBG_STATUS_BUGCHECK_SECOND 4
3332#define DBG_STATUS_FATAL 5
3333#define DBG_STATUS_DEBUG_CONTROL 6
3334#define DBG_STATUS_WORKER 7
3335
3336#if DBG
3337
3338#define KdPrint(_x_) DbgPrint _x_
3339
3340#define KdPrintEx(_x_) DbgPrintEx _x_
3341#define vKdPrintEx(_x_) vDbgPrintEx _x_
3342#define vKdPrintExWithPrefix(_x_) vDbgPrintExWithPrefix _x_
3343
3344#define KdBreakPoint() DbgBreakPoint()
3345
3346
3347
3348#define KdBreakPointWithStatus(s) DbgBreakPointWithStatus(s)
3349
3350
3351
3352#else
3353
3354#define KdPrint(_x_)
3355
3356#define KdPrintEx(_x_)
3357#define vKdPrintEx(_x_)
3358#define vKdPrintExWithPrefix(_x_)
3359
3360#define KdBreakPoint()
3361
3362
3363
3364#define KdBreakPointWithStatus(s)
3365
3366
3367
3368#endif
3369
3370#ifndef _DBGNT_
3371
3372ULONG
3373__cdecl
3374DbgPrint(
3375 PCH Format,
3376 ...
3377 );
3378
3379
3380
3381ULONG
3382__cdecl
3383DbgPrintEx(
3384 IN ULONG ComponentId,
3385 IN ULONG Level,
3386 IN PCH Format,
3387 ...
3388 );
3389
3390#ifdef _VA_LIST_DEFINED
3391
3392ULONG
3393vDbgPrintEx(
3394 IN ULONG ComponentId,
3395 IN ULONG Level,
3396 IN PCH Format,
3397 va_list arglist
3398 );
3399
3400ULONG
3401vDbgPrintExWithPrefix(
3402 IN PCH Prefix,
3403 IN ULONG ComponentId,
3404 IN ULONG Level,
3405 IN PCH Format,
3406 va_list arglist
3407 );
3408
3409#endif
3410
3411ULONG
3412__cdecl
3413DbgPrintReturnControlC(
3414 PCH Format,
3415 ...
3416 );
3417
3418NTSYSAPI
3419NTSTATUS
3420DbgQueryDebugFilterState(
3421 IN ULONG ComponentId,
3422 IN ULONG Level
3423 );
3424
3425NTSYSAPI
3426NTSTATUS
3427DbgSetDebugFilterState(
3428 IN ULONG ComponentId,
3429 IN ULONG Level,
3430 IN BOOLEAN State
3431 );
3432
3433
3434
3435#endif // _DBGNT_
3436
3437//
3438// Large integer arithmetic routines.
3439//
3440
3441//
3442// Large integer add - 64-bits + 64-bits -> 64-bits
3443//
3444
3445#if !defined(MIDL_PASS)
3446
3447DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3448__inline
3449LARGE_INTEGER
3450NTAPI
3451RtlLargeIntegerAdd (
3452 LARGE_INTEGER Addend1,
3453 LARGE_INTEGER Addend2
3454 )
3455{
3456 LARGE_INTEGER Sum;
3457
3458 Sum.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
3459 return Sum;
3460}
3461
3462//
3463// Enlarged integer multiply - 32-bits * 32-bits -> 64-bits
3464//
3465
3466DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3467__inline
3468LARGE_INTEGER
3469NTAPI
3470RtlEnlargedIntegerMultiply (
3471 LONG Multiplicand,
3472 LONG Multiplier
3473 )
3474{
3475 LARGE_INTEGER Product;
3476
3477 Product.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3478 return Product;
3479}
3480
3481//
3482// Unsigned enlarged integer multiply - 32-bits * 32-bits -> 64-bits
3483//
3484
3485DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3486__inline
3487LARGE_INTEGER
3488NTAPI
3489RtlEnlargedUnsignedMultiply (
3490 ULONG Multiplicand,
3491 ULONG Multiplier
3492 )
3493{
3494 LARGE_INTEGER Product;
3495
3496 Product.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3497 return Product;
3498}
3499
3500//
3501// Enlarged integer divide - 64-bits / 32-bits > 32-bits
3502//
3503
3504DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3505__inline
3506ULONG
3507NTAPI
3508RtlEnlargedUnsignedDivide (
3509 IN ULARGE_INTEGER Dividend,
3510 IN ULONG Divisor,
3511 IN PULONG Remainder OPTIONAL
3512 )
3513{
3514 ULONG Quotient;
3515
3516 Quotient = (ULONG)(Dividend.QuadPart / Divisor);
3517 if (ARGUMENT_PRESENT(Remainder)) {
3518 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3519 }
3520
3521 return Quotient;
3522}
3523
3524//
3525// Large integer negation - -(64-bits)
3526//
3527
3528DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3529__inline
3530LARGE_INTEGER
3531NTAPI
3532RtlLargeIntegerNegate (
3533 LARGE_INTEGER Subtrahend
3534 )
3535{
3536 LARGE_INTEGER Difference;
3537
3538 Difference.QuadPart = -Subtrahend.QuadPart;
3539 return Difference;
3540}
3541
3542//
3543// Large integer subtract - 64-bits - 64-bits -> 64-bits.
3544//
3545
3546DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3547__inline
3548LARGE_INTEGER
3549NTAPI
3550RtlLargeIntegerSubtract (
3551 LARGE_INTEGER Minuend,
3552 LARGE_INTEGER Subtrahend
3553 )
3554{
3555 LARGE_INTEGER Difference;
3556
3557 Difference.QuadPart = Minuend.QuadPart - Subtrahend.QuadPart;
3558 return Difference;
3559}
3560
3561//
3562// Extended large integer magic divide - 64-bits / 32-bits -> 64-bits
3563//
3564
3565#if defined(_AMD64_)
3566
3567DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3568__inline
3569LARGE_INTEGER
3570NTAPI
3571RtlExtendedMagicDivide (
3572 LARGE_INTEGER Dividend,
3573 LARGE_INTEGER MagicDivisor,
3574 CCHAR ShiftCount
3575 )
3576
3577{
3578
3579 LARGE_INTEGER Quotient;
3580
3581 if (Dividend.QuadPart >= 0) {
3582 Quotient.QuadPart = UnsignedMultiplyHigh(Dividend.QuadPart,
3583 (ULONG64)MagicDivisor.QuadPart);
3584
3585 } else {
3586 Quotient.QuadPart = UnsignedMultiplyHigh(-Dividend.QuadPart,
3587 (ULONG64)MagicDivisor.QuadPart);
3588 }
3589
3590 Quotient.QuadPart = (ULONG64)Quotient.QuadPart >> ShiftCount;
3591 if (Dividend.QuadPart < 0) {
3592 Quotient.QuadPart = - Quotient.QuadPart;
3593 }
3594
3595 return Quotient;
3596}
3597
3598#endif // defined(_AMD64_)
3599
3600#if defined(_X86_) || defined(_IA64_)
3601
3602DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3603NTSYSAPI
3604LARGE_INTEGER
3605NTAPI
3606RtlExtendedMagicDivide (
3607 LARGE_INTEGER Dividend,
3608 LARGE_INTEGER MagicDivisor,
3609 CCHAR ShiftCount
3610 );
3611
3612#endif // defined(_X86_) || defined(_IA64_)
3613
3614#if defined(_AMD64_) || defined(_IA64_)
3615
3616//
3617// Large Integer divide - 64-bits / 32-bits -> 64-bits
3618//
3619
3620DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3621__inline
3622LARGE_INTEGER
3623NTAPI
3624RtlExtendedLargeIntegerDivide (
3625 LARGE_INTEGER Dividend,
3626 ULONG Divisor,
3627 PULONG Remainder OPTIONAL
3628 )
3629{
3630 LARGE_INTEGER Quotient;
3631
3632 Quotient.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
3633 if (ARGUMENT_PRESENT(Remainder)) {
3634 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3635 }
3636
3637 return Quotient;
3638}
3639
3640
3641//
3642// Large Integer divide - 64-bits / 64-bits -> 64-bits
3643//
3644
3645DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3646__inline
3647LARGE_INTEGER
3648NTAPI
3649RtlLargeIntegerDivide (
3650 LARGE_INTEGER Dividend,
3651 LARGE_INTEGER Divisor,
3652 PLARGE_INTEGER Remainder OPTIONAL
3653 )
3654{
3655 LARGE_INTEGER Quotient;
3656
3657 Quotient.QuadPart = Dividend.QuadPart / Divisor.QuadPart;
3658 if (ARGUMENT_PRESENT(Remainder)) {
3659 Remainder->QuadPart = Dividend.QuadPart % Divisor.QuadPart;
3660 }
3661
3662 return Quotient;
3663}
3664
3665
3666//
3667// Extended integer multiply - 32-bits * 64-bits -> 64-bits
3668//
3669
3670DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3671__inline
3672LARGE_INTEGER
3673NTAPI
3674RtlExtendedIntegerMultiply (
3675 LARGE_INTEGER Multiplicand,
3676 LONG Multiplier
3677 )
3678{
3679 LARGE_INTEGER Product;
3680
3681 Product.QuadPart = Multiplicand.QuadPart * Multiplier;
3682 return Product;
3683}
3684
3685#else
3686
3687//
3688// Large Integer divide - 64-bits / 32-bits -> 64-bits
3689//
3690
3691DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3692NTSYSAPI
3693LARGE_INTEGER
3694NTAPI
3695RtlExtendedLargeIntegerDivide (
3696 LARGE_INTEGER Dividend,
3697 ULONG Divisor,
3698 PULONG Remainder
3699 );
3700
3701
3702//
3703// Large Integer divide - 64-bits / 64-bits -> 64-bits
3704//
3705
3706DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3707NTSYSAPI
3708LARGE_INTEGER
3709NTAPI
3710RtlLargeIntegerDivide (
3711 LARGE_INTEGER Dividend,
3712 LARGE_INTEGER Divisor,
3713 PLARGE_INTEGER Remainder
3714 );
3715
3716
3717//
3718// Extended integer multiply - 32-bits * 64-bits -> 64-bits
3719//
3720
3721DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3722NTSYSAPI
3723LARGE_INTEGER
3724NTAPI
3725RtlExtendedIntegerMultiply (
3726 LARGE_INTEGER Multiplicand,
3727 LONG Multiplier
3728 );
3729
3730#endif // defined(_AMD64_) || defined(_IA64_)
3731
3732//
3733// Large integer and - 64-bite & 64-bits -> 64-bits.
3734//
3735
3736#if PRAGMA_DEPRECATED_DDK
3737#pragma deprecated(RtlLargeIntegerAnd) // Use native __int64 math
3738#endif
3739#define RtlLargeIntegerAnd(Result, Source, Mask) \
3740 Result.QuadPart = Source.QuadPart & Mask.QuadPart
3741
3742//
3743// Convert signed integer to large integer.
3744//
3745
3746DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3747__inline
3748LARGE_INTEGER
3749NTAPI
3750RtlConvertLongToLargeInteger (
3751 LONG SignedInteger
3752 )
3753{
3754 LARGE_INTEGER Result;
3755
3756 Result.QuadPart = SignedInteger;
3757 return Result;
3758}
3759
3760//
3761// Convert unsigned integer to large integer.
3762//
3763
3764DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3765__inline
3766LARGE_INTEGER
3767NTAPI
3768RtlConvertUlongToLargeInteger (
3769 ULONG UnsignedInteger
3770 )
3771{
3772 LARGE_INTEGER Result;
3773
3774 Result.QuadPart = UnsignedInteger;
3775 return Result;
3776}
3777
3778//
3779// Large integer shift routines.
3780//
3781
3782DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3783__inline
3784LARGE_INTEGER
3785NTAPI
3786RtlLargeIntegerShiftLeft (
3787 LARGE_INTEGER LargeInteger,
3788 CCHAR ShiftCount
3789 )
3790{
3791 LARGE_INTEGER Result;
3792
3793 Result.QuadPart = LargeInteger.QuadPart << ShiftCount;
3794 return Result;
3795}
3796
3797DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3798__inline
3799LARGE_INTEGER
3800NTAPI
3801RtlLargeIntegerShiftRight (
3802 LARGE_INTEGER LargeInteger,
3803 CCHAR ShiftCount
3804 )
3805{
3806 LARGE_INTEGER Result;
3807
3808 Result.QuadPart = (ULONG64)LargeInteger.QuadPart >> ShiftCount;
3809 return Result;
3810}
3811
3812DECLSPEC_DEPRECATED_DDK // Use native __int64 math
3813__inline
3814LARGE_INTEGER
3815NTAPI
3816RtlLargeIntegerArithmeticShift (
3817 LARGE_INTEGER LargeInteger,
3818 CCHAR ShiftCount
3819 )
3820{
3821 LARGE_INTEGER Result;
3822
3823 Result.QuadPart = LargeInteger.QuadPart >> ShiftCount;
3824 return Result;
3825}
3826
3827
3828//
3829// Large integer comparison routines.
3830//
3831
3832#if PRAGMA_DEPRECATED_DDK
3833#pragma deprecated(RtlLargeIntegerGreaterThan) // Use native __int64 math
3834#pragma deprecated(RtlLargeIntegerGreaterThanOrEqualTo) // Use native __int64 math
3835#pragma deprecated(RtlLargeIntegerEqualTo) // Use native __int64 math
3836#pragma deprecated(RtlLargeIntegerNotEqualTo) // Use native __int64 math
3837#pragma deprecated(RtlLargeIntegerLessThan) // Use native __int64 math
3838#pragma deprecated(RtlLargeIntegerLessThanOrEqualTo) // Use native __int64 math
3839#pragma deprecated(RtlLargeIntegerGreaterThanZero) // Use native __int64 math
3840#pragma deprecated(RtlLargeIntegerGreaterOrEqualToZero) // Use native __int64 math
3841#pragma deprecated(RtlLargeIntegerEqualToZero) // Use native __int64 math
3842#pragma deprecated(RtlLargeIntegerNotEqualToZero) // Use native __int64 math
3843#pragma deprecated(RtlLargeIntegerLessThanZero) // Use native __int64 math
3844#pragma deprecated(RtlLargeIntegerLessOrEqualToZero) // Use native __int64 math
3845#endif
3846
3847#define RtlLargeIntegerGreaterThan(X,Y) ( \
3848 (((X).HighPart == (Y).HighPart) && ((X).LowPart > (Y).LowPart)) || \
3849 ((X).HighPart > (Y).HighPart) \
3850)
3851
3852#define RtlLargeIntegerGreaterThanOrEqualTo(X,Y) ( \
3853 (((X).HighPart == (Y).HighPart) && ((X).LowPart >= (Y).LowPart)) || \
3854 ((X).HighPart > (Y).HighPart) \
3855)
3856
3857#define RtlLargeIntegerEqualTo(X,Y) ( \
3858 !(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
3859)
3860
3861#define RtlLargeIntegerNotEqualTo(X,Y) ( \
3862 (((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)) \
3863)
3864
3865#define RtlLargeIntegerLessThan(X,Y) ( \
3866 (((X).HighPart == (Y).HighPart) && ((X).LowPart < (Y).LowPart)) || \
3867 ((X).HighPart < (Y).HighPart) \
3868)
3869
3870#define RtlLargeIntegerLessThanOrEqualTo(X,Y) ( \
3871 (((X).HighPart == (Y).HighPart) && ((X).LowPart <= (Y).LowPart)) || \
3872 ((X).HighPart < (Y).HighPart) \
3873)
3874
3875#define RtlLargeIntegerGreaterThanZero(X) ( \
3876 (((X).HighPart == 0) && ((X).LowPart > 0)) || \
3877 ((X).HighPart > 0 ) \
3878)
3879
3880#define RtlLargeIntegerGreaterOrEqualToZero(X) ( \
3881 (X).HighPart >= 0 \
3882)
3883
3884#define RtlLargeIntegerEqualToZero(X) ( \
3885 !((X).LowPart | (X).HighPart) \
3886)
3887
3888#define RtlLargeIntegerNotEqualToZero(X) ( \
3889 ((X).LowPart | (X).HighPart) \
3890)
3891
3892#define RtlLargeIntegerLessThanZero(X) ( \
3893 ((X).HighPart < 0) \
3894)
3895
3896#define RtlLargeIntegerLessOrEqualToZero(X) ( \
3897 ((X).HighPart < 0) || !((X).LowPart | (X).HighPart) \
3898)
3899
3900#endif // !defined(MIDL_PASS)
3901
3902
3903//
3904// Time conversion routines
3905//
3906
3907typedef struct _TIME_FIELDS {
3908 CSHORT Year; // range [1601...]
3909 CSHORT Month; // range [1..12]
3910 CSHORT Day; // range [1..31]
3911 CSHORT Hour; // range [0..23]
3912 CSHORT Minute; // range [0..59]
3913 CSHORT Second; // range [0..59]
3914 CSHORT Milliseconds;// range [0..999]
3915 CSHORT Weekday; // range [0..6] == [Sunday..Saturday]
3916} TIME_FIELDS;
3917typedef TIME_FIELDS *PTIME_FIELDS;
3918
3919
3920NTSYSAPI
3921VOID
3922NTAPI
3923RtlTimeToTimeFields (
3924 PLARGE_INTEGER Time,
3925 PTIME_FIELDS TimeFields
3926 );
3927
3928//
3929// A time field record (Weekday ignored) -> 64 bit Time value
3930//
3931
3932NTSYSAPI
3933BOOLEAN
3934NTAPI
3935RtlTimeFieldsToTime (
3936 PTIME_FIELDS TimeFields,
3937 PLARGE_INTEGER Time
3938 );
3939
3940//
3941// The following macros store and retrieve USHORTS and ULONGS from potentially
3942// unaligned addresses, avoiding alignment faults. they should probably be
3943// rewritten in assembler
3944//
3945
3946#define SHORT_SIZE (sizeof(USHORT))
3947#define SHORT_MASK (SHORT_SIZE - 1)
3948#define LONG_SIZE (sizeof(LONG))
3949#define LONGLONG_SIZE (sizeof(LONGLONG))
3950#define LONG_MASK (LONG_SIZE - 1)
3951#define LONGLONG_MASK (LONGLONG_SIZE - 1)
3952#define LOWBYTE_MASK 0x00FF
3953
3954#define FIRSTBYTE(VALUE) ((VALUE) & LOWBYTE_MASK)
3955#define SECONDBYTE(VALUE) (((VALUE) >> 8) & LOWBYTE_MASK)
3956#define THIRDBYTE(VALUE) (((VALUE) >> 16) & LOWBYTE_MASK)
3957#define FOURTHBYTE(VALUE) (((VALUE) >> 24) & LOWBYTE_MASK)
3958
3959//
3960// if MIPS Big Endian, order of bytes is reversed.
3961//
3962
3963#define SHORT_LEAST_SIGNIFICANT_BIT 0
3964#define SHORT_MOST_SIGNIFICANT_BIT 1
3965
3966#define LONG_LEAST_SIGNIFICANT_BIT 0
3967#define LONG_3RD_MOST_SIGNIFICANT_BIT 1
3968#define LONG_2ND_MOST_SIGNIFICANT_BIT 2
3969#define LONG_MOST_SIGNIFICANT_BIT 3
3970
3971//++
3972//
3973// VOID
3974// RtlStoreUshort (
3975// PUSHORT ADDRESS
3976// USHORT VALUE
3977// )
3978//
3979// Routine Description:
3980//
3981// This macro stores a USHORT value in at a particular address, avoiding
3982// alignment faults.
3983//
3984// Arguments:
3985//
3986// ADDRESS - where to store USHORT value
3987// VALUE - USHORT to store
3988//
3989// Return Value:
3990//
3991// none.
3992//
3993//--
3994
3995#define RtlStoreUshort(ADDRESS,VALUE) \
3996 if ((ULONG_PTR)(ADDRESS) & SHORT_MASK) { \
3997 ((PUCHAR) (ADDRESS))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(VALUE)); \
3998 ((PUCHAR) (ADDRESS))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
3999 } \
4000 else { \
4001 *((PUSHORT) (ADDRESS)) = (USHORT) VALUE; \
4002 }
4003
4004
4005//++
4006//
4007// VOID
4008// RtlStoreUlong (
4009// PULONG ADDRESS
4010// ULONG VALUE
4011// )
4012//
4013// Routine Description:
4014//
4015// This macro stores a ULONG value in at a particular address, avoiding
4016// alignment faults.
4017//
4018// Arguments:
4019//
4020// ADDRESS - where to store ULONG value
4021// VALUE - ULONG to store
4022//
4023// Return Value:
4024//
4025// none.
4026//
4027// Note:
4028// Depending on the machine, we might want to call storeushort in the
4029// unaligned case.
4030//
4031//--
4032
4033#define RtlStoreUlong(ADDRESS,VALUE) \
4034 if ((ULONG_PTR)(ADDRESS) & LONG_MASK) { \
4035 ((PUCHAR) (ADDRESS))[LONG_LEAST_SIGNIFICANT_BIT ] = (UCHAR)(FIRSTBYTE(VALUE)); \
4036 ((PUCHAR) (ADDRESS))[LONG_3RD_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(VALUE)); \
4037 ((PUCHAR) (ADDRESS))[LONG_2ND_MOST_SIGNIFICANT_BIT ] = (UCHAR)(THIRDBYTE(VALUE)); \
4038 ((PUCHAR) (ADDRESS))[LONG_MOST_SIGNIFICANT_BIT ] = (UCHAR)(FOURTHBYTE(VALUE)); \
4039 } \
4040 else { \
4041 *((PULONG) (ADDRESS)) = (ULONG) (VALUE); \
4042 }
4043
4044//++
4045//
4046// VOID
4047// RtlStoreUlonglong (
4048// PULONGLONG ADDRESS
4049// ULONG VALUE
4050// )
4051//
4052// Routine Description:
4053//
4054// This macro stores a ULONGLONG value in at a particular address, avoiding
4055// alignment faults.
4056//
4057// Arguments:
4058//
4059// ADDRESS - where to store ULONGLONG value
4060// VALUE - ULONGLONG to store
4061//
4062// Return Value:
4063//
4064// none.
4065//
4066//--
4067
4068#define RtlStoreUlonglong(ADDRESS,VALUE) \
4069 if ((ULONG_PTR)(ADDRESS) & LONGLONG_MASK) { \
4070 RtlStoreUlong((ULONG_PTR)(ADDRESS), \
4071 (ULONGLONG)(VALUE) & 0xFFFFFFFF); \
4072 RtlStoreUlong((ULONG_PTR)(ADDRESS)+sizeof(ULONG), \
4073 (ULONGLONG)(VALUE) >> 32); \
4074 } else { \
4075 *((PULONGLONG)(ADDRESS)) = (ULONGLONG)(VALUE); \
4076 }
4077
4078//++
4079//
4080// VOID
4081// RtlStoreUlongPtr (
4082// PULONG_PTR ADDRESS
4083// ULONG_PTR VALUE
4084// )
4085//
4086// Routine Description:
4087//
4088// This macro stores a ULONG_PTR value in at a particular address, avoiding
4089// alignment faults.
4090//
4091// Arguments:
4092//
4093// ADDRESS - where to store ULONG_PTR value
4094// VALUE - ULONG_PTR to store
4095//
4096// Return Value:
4097//
4098// none.
4099//
4100//--
4101
4102#ifdef _WIN64
4103
4104#define RtlStoreUlongPtr(ADDRESS,VALUE) \
4105 RtlStoreUlonglong(ADDRESS,VALUE)
4106
4107#else
4108
4109#define RtlStoreUlongPtr(ADDRESS,VALUE) \
4110 RtlStoreUlong(ADDRESS,VALUE)
4111
4112#endif
4113
4114//++
4115//
4116// VOID
4117// RtlRetrieveUshort (
4118// PUSHORT DESTINATION_ADDRESS
4119// PUSHORT SOURCE_ADDRESS
4120// )
4121//
4122// Routine Description:
4123//
4124// This macro retrieves a USHORT value from the SOURCE address, avoiding
4125// alignment faults. The DESTINATION address is assumed to be aligned.
4126//
4127// Arguments:
4128//
4129// DESTINATION_ADDRESS - where to store USHORT value
4130// SOURCE_ADDRESS - where to retrieve USHORT value from
4131//
4132// Return Value:
4133//
4134// none.
4135//
4136//--
4137
4138#define RtlRetrieveUshort(DEST_ADDRESS,SRC_ADDRESS) \
4139 if ((ULONG_PTR)SRC_ADDRESS & SHORT_MASK) { \
4140 ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
4141 ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
4142 } \
4143 else { \
4144 *((PUSHORT) DEST_ADDRESS) = *((PUSHORT) SRC_ADDRESS); \
4145 } \
4146
4147//++
4148//
4149// VOID
4150// RtlRetrieveUlong (
4151// PULONG DESTINATION_ADDRESS
4152// PULONG SOURCE_ADDRESS
4153// )
4154//
4155// Routine Description:
4156//
4157// This macro retrieves a ULONG value from the SOURCE address, avoiding
4158// alignment faults. The DESTINATION address is assumed to be aligned.
4159//
4160// Arguments:
4161//
4162// DESTINATION_ADDRESS - where to store ULONG value
4163// SOURCE_ADDRESS - where to retrieve ULONG value from
4164//
4165// Return Value:
4166//
4167// none.
4168//
4169// Note:
4170// Depending on the machine, we might want to call retrieveushort in the
4171// unaligned case.
4172//
4173//--
4174
4175#define RtlRetrieveUlong(DEST_ADDRESS,SRC_ADDRESS) \
4176 if ((ULONG_PTR)SRC_ADDRESS & LONG_MASK) { \
4177 ((PUCHAR) DEST_ADDRESS)[0] = ((PUCHAR) SRC_ADDRESS)[0]; \
4178 ((PUCHAR) DEST_ADDRESS)[1] = ((PUCHAR) SRC_ADDRESS)[1]; \
4179 ((PUCHAR) DEST_ADDRESS)[2] = ((PUCHAR) SRC_ADDRESS)[2]; \
4180 ((PUCHAR) DEST_ADDRESS)[3] = ((PUCHAR) SRC_ADDRESS)[3]; \
4181 } \
4182 else { \
4183 *((PULONG) DEST_ADDRESS) = *((PULONG) SRC_ADDRESS); \
4184 }
4185//
4186// BitMap routines. The following structure, routines, and macros are
4187// for manipulating bitmaps. The user is responsible for allocating a bitmap
4188// structure (which is really a header) and a buffer (which must be longword
4189// aligned and multiple longwords in size).
4190//
4191
4192typedef struct _RTL_BITMAP {
4193 ULONG SizeOfBitMap; // Number of bits in bit map
4194 PULONG Buffer; // Pointer to the bit map itself
4195} RTL_BITMAP;
4196typedef RTL_BITMAP *PRTL_BITMAP;
4197
4198//
4199// The following routine initializes a new bitmap. It does not alter the
4200// data currently in the bitmap. This routine must be called before
4201// any other bitmap routine/macro.
4202//
4203
4204NTSYSAPI
4205VOID
4206NTAPI
4207RtlInitializeBitMap (
4208 PRTL_BITMAP BitMapHeader,
4209 PULONG BitMapBuffer,
4210 ULONG SizeOfBitMap
4211 );
4212
4213//
4214// The following three routines clear, set, and test the state of a
4215// single bit in a bitmap.
4216//
4217
4218NTSYSAPI
4219VOID
4220NTAPI
4221RtlClearBit (
4222 PRTL_BITMAP BitMapHeader,
4223 ULONG BitNumber
4224 );
4225
4226NTSYSAPI
4227VOID
4228NTAPI
4229RtlSetBit (
4230 PRTL_BITMAP BitMapHeader,
4231 ULONG BitNumber
4232 );
4233
4234NTSYSAPI
4235BOOLEAN
4236NTAPI
4237RtlTestBit (
4238 PRTL_BITMAP BitMapHeader,
4239 ULONG BitNumber
4240 );
4241
4242//
4243// The following two routines either clear or set all of the bits
4244// in a bitmap.
4245//
4246
4247NTSYSAPI
4248VOID
4249NTAPI
4250RtlClearAllBits (
4251 PRTL_BITMAP BitMapHeader
4252 );
4253
4254NTSYSAPI
4255VOID
4256NTAPI
4257RtlSetAllBits (
4258 PRTL_BITMAP BitMapHeader
4259 );
4260
4261//
4262// The following two routines locate a contiguous region of either
4263// clear or set bits within the bitmap. The region will be at least
4264// as large as the number specified, and the search of the bitmap will
4265// begin at the specified hint index (which is a bit index within the
4266// bitmap, zero based). The return value is the bit index of the located
4267// region (zero based) or -1 (i.e., 0xffffffff) if such a region cannot
4268// be located
4269//
4270
4271NTSYSAPI
4272ULONG
4273NTAPI
4274RtlFindClearBits (
4275 PRTL_BITMAP BitMapHeader,
4276 ULONG NumberToFind,
4277 ULONG HintIndex
4278 );
4279
4280NTSYSAPI
4281ULONG
4282NTAPI
4283RtlFindSetBits (
4284 PRTL_BITMAP BitMapHeader,
4285 ULONG NumberToFind,
4286 ULONG HintIndex
4287 );
4288
4289//
4290// The following two routines locate a contiguous region of either
4291// clear or set bits within the bitmap and either set or clear the bits
4292// within the located region. The region will be as large as the number
4293// specified, and the search for the region will begin at the specified
4294// hint index (which is a bit index within the bitmap, zero based). The
4295// return value is the bit index of the located region (zero based) or
4296// -1 (i.e., 0xffffffff) if such a region cannot be located. If a region
4297// cannot be located then the setting/clearing of the bitmap is not performed.
4298//
4299
4300NTSYSAPI
4301ULONG
4302NTAPI
4303RtlFindClearBitsAndSet (
4304 PRTL_BITMAP BitMapHeader,
4305 ULONG NumberToFind,
4306 ULONG HintIndex
4307 );
4308
4309NTSYSAPI
4310ULONG
4311NTAPI
4312RtlFindSetBitsAndClear (
4313 PRTL_BITMAP BitMapHeader,
4314 ULONG NumberToFind,
4315 ULONG HintIndex
4316 );
4317
4318//
4319// The following two routines clear or set bits within a specified region
4320// of the bitmap. The starting index is zero based.
4321//
4322
4323NTSYSAPI
4324VOID
4325NTAPI
4326RtlClearBits (
4327 PRTL_BITMAP BitMapHeader,
4328 ULONG StartingIndex,
4329 ULONG NumberToClear
4330 );
4331
4332NTSYSAPI
4333VOID
4334NTAPI
4335RtlSetBits (
4336 PRTL_BITMAP BitMapHeader,
4337 ULONG StartingIndex,
4338 ULONG NumberToSet
4339 );
4340
4341//
4342// The following routine locates a set of contiguous regions of clear
4343// bits within the bitmap. The caller specifies whether to return the
4344// longest runs or just the first found lcoated. The following structure is
4345// used to denote a contiguous run of bits. The two routines return an array
4346// of this structure, one for each run located.
4347//
4348
4349typedef struct _RTL_BITMAP_RUN {
4350
4351 ULONG StartingIndex;
4352 ULONG NumberOfBits;
4353
4354} RTL_BITMAP_RUN;
4355typedef RTL_BITMAP_RUN *PRTL_BITMAP_RUN;
4356
4357NTSYSAPI
4358ULONG
4359NTAPI
4360RtlFindClearRuns (
4361 PRTL_BITMAP BitMapHeader,
4362 PRTL_BITMAP_RUN RunArray,
4363 ULONG SizeOfRunArray,
4364 BOOLEAN LocateLongestRuns
4365 );
4366
4367//
4368// The following routine locates the longest contiguous region of
4369// clear bits within the bitmap. The returned starting index value
4370// denotes the first contiguous region located satisfying our requirements
4371// The return value is the length (in bits) of the longest region found.
4372//
4373
4374NTSYSAPI
4375ULONG
4376NTAPI
4377RtlFindLongestRunClear (
4378 PRTL_BITMAP BitMapHeader,
4379 PULONG StartingIndex
4380 );
4381
4382//
4383// The following routine locates the first contiguous region of
4384// clear bits within the bitmap. The returned starting index value
4385// denotes the first contiguous region located satisfying our requirements
4386// The return value is the length (in bits) of the region found.
4387//
4388
4389NTSYSAPI
4390ULONG
4391NTAPI
4392RtlFindFirstRunClear (
4393 PRTL_BITMAP BitMapHeader,
4394 PULONG StartingIndex
4395 );
4396
4397//
4398// The following macro returns the value of the bit stored within the
4399// bitmap at the specified location. If the bit is set a value of 1 is
4400// returned otherwise a value of 0 is returned.
4401//
4402// ULONG
4403// RtlCheckBit (
4404// PRTL_BITMAP BitMapHeader,
4405// ULONG BitPosition
4406// );
4407//
4408//
4409// To implement CheckBit the macro retrieves the longword containing the
4410// bit in question, shifts the longword to get the bit in question into the
4411// low order bit position and masks out all other bits.
4412//
4413
4414#define RtlCheckBit(BMH,BP) ((((BMH)->Buffer[(BP) / 32]) >> ((BP) % 32)) & 0x1)
4415
4416//
4417// The following two procedures return to the caller the total number of
4418// clear or set bits within the specified bitmap.
4419//
4420
4421NTSYSAPI
4422ULONG
4423NTAPI
4424RtlNumberOfClearBits (
4425 PRTL_BITMAP BitMapHeader
4426 );
4427
4428NTSYSAPI
4429ULONG
4430NTAPI
4431RtlNumberOfSetBits (
4432 PRTL_BITMAP BitMapHeader
4433 );
4434
4435//
4436// The following two procedures return to the caller a boolean value
4437// indicating if the specified range of bits are all clear or set.
4438//
4439
4440NTSYSAPI
4441BOOLEAN
4442NTAPI
4443RtlAreBitsClear (
4444 PRTL_BITMAP BitMapHeader,
4445 ULONG StartingIndex,
4446 ULONG Length
4447 );
4448
4449NTSYSAPI
4450BOOLEAN
4451NTAPI
4452RtlAreBitsSet (
4453 PRTL_BITMAP BitMapHeader,
4454 ULONG StartingIndex,
4455 ULONG Length
4456 );
4457
4458NTSYSAPI
4459ULONG
4460NTAPI
4461RtlFindNextForwardRunClear (
4462 IN PRTL_BITMAP BitMapHeader,
4463 IN ULONG FromIndex,
4464 IN PULONG StartingRunIndex
4465 );
4466
4467NTSYSAPI
4468ULONG
4469NTAPI
4470RtlFindLastBackwardRunClear (
4471 IN PRTL_BITMAP BitMapHeader,
4472 IN ULONG FromIndex,
4473 IN PULONG StartingRunIndex
4474 );
4475
4476//
4477// The following two procedures return to the caller a value indicating
4478// the position within a ULONGLONG of the most or least significant non-zero
4479// bit. A value of zero results in a return value of -1.
4480//
4481
4482NTSYSAPI
4483CCHAR
4484NTAPI
4485RtlFindLeastSignificantBit (
4486 IN ULONGLONG Set
4487 );
4488
4489NTSYSAPI
4490CCHAR
4491NTAPI
4492RtlFindMostSignificantBit (
4493 IN ULONGLONG Set
4494 );
4495
4496
4497//
4498// BOOLEAN
4499// RtlEqualLuid(
4500// PLUID L1,
4501// PLUID L2
4502// );
4503
4504#define RtlEqualLuid(L1, L2) (((L1)->LowPart == (L2)->LowPart) && \
4505 ((L1)->HighPart == (L2)->HighPart))
4506
4507//
4508// BOOLEAN
4509// RtlIsZeroLuid(
4510// PLUID L1
4511// );
4512//
4513#define RtlIsZeroLuid(L1) ((BOOLEAN) (((L1)->LowPart | (L1)->HighPart) == 0))
4514
4515
4516#if !defined(MIDL_PASS)
4517
4518FORCEINLINE LUID
4519NTAPI
4520RtlConvertLongToLuid(
4521 LONG Long
4522 )
4523{
4524 LUID TempLuid;
4525 LARGE_INTEGER TempLi;
4526
4527 TempLi.QuadPart = Long;
4528 TempLuid.LowPart = TempLi.LowPart;
4529 TempLuid.HighPart = TempLi.HighPart;
4530 return(TempLuid);
4531}
4532
4533FORCEINLINE
4534LUID
4535NTAPI
4536RtlConvertUlongToLuid(
4537 ULONG Ulong
4538 )
4539{
4540 LUID TempLuid;
4541
4542 TempLuid.LowPart = Ulong;
4543 TempLuid.HighPart = 0;
4544 return(TempLuid);
4545}
4546#endif
4547
4548
4549NTSYSAPI
4550VOID
4551NTAPI
4552RtlMapGenericMask(
4553 PACCESS_MASK AccessMask,
4554 PGENERIC_MAPPING GenericMapping
4555 );
4556//
4557// SecurityDescriptor RTL routine definitions
4558//
4559
4560NTSYSAPI
4561NTSTATUS
4562NTAPI
4563RtlCreateSecurityDescriptor (
4564 PSECURITY_DESCRIPTOR SecurityDescriptor,
4565 ULONG Revision
4566 );
4567
4568
4569NTSYSAPI
4570BOOLEAN
4571NTAPI
4572RtlValidSecurityDescriptor (
4573 PSECURITY_DESCRIPTOR SecurityDescriptor
4574 );
4575
4576
4577NTSYSAPI
4578ULONG
4579NTAPI
4580RtlLengthSecurityDescriptor (
4581 PSECURITY_DESCRIPTOR SecurityDescriptor
4582 );
4583
4584NTSYSAPI
4585BOOLEAN
4586NTAPI
4587RtlValidRelativeSecurityDescriptor (
4588 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
4589 IN ULONG SecurityDescriptorLength,
4590 IN SECURITY_INFORMATION RequiredInformation
4591 );
4592
4593
4594NTSYSAPI
4595NTSTATUS
4596NTAPI
4597RtlSetDaclSecurityDescriptor (
4598 PSECURITY_DESCRIPTOR SecurityDescriptor,
4599 BOOLEAN DaclPresent,
4600 PACL Dacl,
4601 BOOLEAN DaclDefaulted
4602 );
4603
4604
4605//
4606// Range list package
4607//
4608
4609typedef struct _RTL_RANGE {
4610
4611 //
4612 // The start of the range
4613 //
4614 ULONGLONG Start; // Read only
4615
4616 //
4617 // The end of the range
4618 //
4619 ULONGLONG End; // Read only
4620
4621 //
4622 // Data the user passed in when they created the range
4623 //
4624 PVOID UserData; // Read/Write
4625
4626 //
4627 // The owner of the range
4628 //
4629 PVOID Owner; // Read/Write
4630
4631 //
4632 // User defined flags the user specified when they created the range
4633 //
4634 UCHAR Attributes; // Read/Write
4635
4636 //
4637 // Flags (RTL_RANGE_*)
4638 //
4639 UCHAR Flags; // Read only
4640
4641} RTL_RANGE, *PRTL_RANGE;
4642
4643
4644#define RTL_RANGE_SHARED 0x01
4645#define RTL_RANGE_CONFLICT 0x02
4646
4647typedef struct _RTL_RANGE_LIST {
4648
4649 //
4650 // The list of ranges
4651 //
4652 LIST_ENTRY ListHead;
4653
4654 //
4655 // These always come in useful
4656 //
4657 ULONG Flags; // use RANGE_LIST_FLAG_*
4658
4659 //
4660 // The number of entries in the list
4661 //
4662 ULONG Count;
4663
4664 //
4665 // Every time an add/delete operation is performed on the list this is
4666 // incremented. It is checked during iteration to ensure that the list
4667 // hasn't changed between GetFirst/GetNext or GetNext/GetNext calls
4668 //
4669 ULONG Stamp;
4670
4671} RTL_RANGE_LIST, *PRTL_RANGE_LIST;
4672
4673typedef struct _RANGE_LIST_ITERATOR {
4674
4675 PLIST_ENTRY RangeListHead;
4676 PLIST_ENTRY MergedHead;
4677 PVOID Current;
4678 ULONG Stamp;
4679
4680} RTL_RANGE_LIST_ITERATOR, *PRTL_RANGE_LIST_ITERATOR;
4681
4682
4683NTSYSAPI
4684VOID
4685NTAPI
4686RtlInitializeRangeList(
4687 IN OUT PRTL_RANGE_LIST RangeList
4688 );
4689
4690NTSYSAPI
4691VOID
4692NTAPI
4693RtlFreeRangeList(
4694 IN PRTL_RANGE_LIST RangeList
4695 );
4696
4697NTSYSAPI
4698NTSTATUS
4699NTAPI
4700RtlCopyRangeList(
4701 OUT PRTL_RANGE_LIST CopyRangeList,
4702 IN PRTL_RANGE_LIST RangeList
4703 );
4704
4705#define RTL_RANGE_LIST_ADD_IF_CONFLICT 0x00000001
4706#define RTL_RANGE_LIST_ADD_SHARED 0x00000002
4707
4708NTSYSAPI
4709NTSTATUS
4710NTAPI
4711RtlAddRange(
4712 IN OUT PRTL_RANGE_LIST RangeList,
4713 IN ULONGLONG Start,
4714 IN ULONGLONG End,
4715 IN UCHAR Attributes,
4716 IN ULONG Flags,
4717 IN PVOID UserData, OPTIONAL
4718 IN PVOID Owner OPTIONAL
4719 );
4720
4721NTSYSAPI
4722NTSTATUS
4723NTAPI
4724RtlDeleteRange(
4725 IN OUT PRTL_RANGE_LIST RangeList,
4726 IN ULONGLONG Start,
4727 IN ULONGLONG End,
4728 IN PVOID Owner
4729 );
4730
4731NTSYSAPI
4732NTSTATUS
4733NTAPI
4734RtlDeleteOwnersRanges(
4735 IN OUT PRTL_RANGE_LIST RangeList,
4736 IN PVOID Owner
4737 );
4738
4739#define RTL_RANGE_LIST_SHARED_OK 0x00000001
4740#define RTL_RANGE_LIST_NULL_CONFLICT_OK 0x00000002
4741
4742typedef
4743BOOLEAN
4744(*PRTL_CONFLICT_RANGE_CALLBACK) (
4745 IN PVOID Context,
4746 IN PRTL_RANGE Range
4747 );
4748
4749NTSYSAPI
4750NTSTATUS
4751NTAPI
4752RtlFindRange(
4753 IN PRTL_RANGE_LIST RangeList,
4754 IN ULONGLONG Minimum,
4755 IN ULONGLONG Maximum,
4756 IN ULONG Length,
4757 IN ULONG Alignment,
4758 IN ULONG Flags,
4759 IN UCHAR AttributeAvailableMask,
4760 IN PVOID Context OPTIONAL,
4761 IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
4762 OUT PULONGLONG Start
4763 );
4764
4765NTSYSAPI
4766NTSTATUS
4767NTAPI
4768RtlIsRangeAvailable(
4769 IN PRTL_RANGE_LIST RangeList,
4770 IN ULONGLONG Start,
4771 IN ULONGLONG End,
4772 IN ULONG Flags,
4773 IN UCHAR AttributeAvailableMask,
4774 IN PVOID Context OPTIONAL,
4775 IN PRTL_CONFLICT_RANGE_CALLBACK Callback OPTIONAL,
4776 OUT PBOOLEAN Available
4777 );
4778
4779#define FOR_ALL_RANGES(RangeList, Iterator, Current) \
4780 for (RtlGetFirstRange((RangeList), (Iterator), &(Current)); \
4781 (Current) != NULL; \
4782 RtlGetNextRange((Iterator), &(Current), TRUE) \
4783 )
4784
4785#define FOR_ALL_RANGES_BACKWARDS(RangeList, Iterator, Current) \
4786 for (RtlGetLastRange((RangeList), (Iterator), &(Current)); \
4787 (Current) != NULL; \
4788 RtlGetNextRange((Iterator), &(Current), FALSE) \
4789 )
4790
4791NTSYSAPI
4792NTSTATUS
4793NTAPI
4794RtlGetFirstRange(
4795 IN PRTL_RANGE_LIST RangeList,
4796 OUT PRTL_RANGE_LIST_ITERATOR Iterator,
4797 OUT PRTL_RANGE *Range
4798 );
4799
4800NTSYSAPI
4801NTSTATUS
4802NTAPI
4803RtlGetLastRange(
4804 IN PRTL_RANGE_LIST RangeList,
4805 OUT PRTL_RANGE_LIST_ITERATOR Iterator,
4806 OUT PRTL_RANGE *Range
4807 );
4808
4809NTSYSAPI
4810NTSTATUS
4811NTAPI
4812RtlGetNextRange(
4813 IN OUT PRTL_RANGE_LIST_ITERATOR Iterator,
4814 OUT PRTL_RANGE *Range,
4815 IN BOOLEAN MoveForwards
4816 );
4817
4818#define RTL_RANGE_LIST_MERGE_IF_CONFLICT RTL_RANGE_LIST_ADD_IF_CONFLICT
4819
4820NTSYSAPI
4821NTSTATUS
4822NTAPI
4823RtlMergeRangeLists(
4824 OUT PRTL_RANGE_LIST MergedRangeList,
4825 IN PRTL_RANGE_LIST RangeList1,
4826 IN PRTL_RANGE_LIST RangeList2,
4827 IN ULONG Flags
4828 );
4829
4830NTSYSAPI
4831NTSTATUS
4832NTAPI
4833RtlInvertRangeList(
4834 OUT PRTL_RANGE_LIST InvertedRangeList,
4835 IN PRTL_RANGE_LIST RangeList
4836 );
4837
4838
4839
4840
4841
4842//
4843// Byte swap routines. These are used to convert from little-endian to
4844// big-endian and vice-versa.
4845//
4846
4847#if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
4848#ifdef __cplusplus
4849extern "C" {
4850#endif
4851unsigned short __cdecl _byteswap_ushort(unsigned short);
4852unsigned long __cdecl _byteswap_ulong (unsigned long);
4853unsigned __int64 __cdecl _byteswap_uint64(unsigned __int64);
4854#ifdef __cplusplus
4855}
4856#endif
4857#pragma intrinsic(_byteswap_ushort)
4858#pragma intrinsic(_byteswap_ulong)
4859#pragma intrinsic(_byteswap_uint64)
4860
4861#define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
4862#define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
4863#define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
4864#else
4865USHORT
4866FASTCALL
4867RtlUshortByteSwap(
4868 IN USHORT Source
4869 );
4870
4871ULONG
4872FASTCALL
4873RtlUlongByteSwap(
4874 IN ULONG Source
4875 );
4876
4877ULONGLONG
4878FASTCALL
4879RtlUlonglongByteSwap(
4880 IN ULONGLONG Source
4881 );
4882#endif
4883
4884
4885
4886
4887
4888//
4889// Routine for converting from a volume device object to a DOS name.
4890//
4891
4892NTSYSAPI
4893NTSTATUS
4894NTAPI
4895RtlVolumeDeviceToDosName(
4896 IN PVOID VolumeDeviceObject,
4897 OUT PUNICODE_STRING DosName
4898 );
4899
4900typedef struct _OSVERSIONINFOA {
4901 ULONG dwOSVersionInfoSize;
4902 ULONG dwMajorVersion;
4903 ULONG dwMinorVersion;
4904 ULONG dwBuildNumber;
4905 ULONG dwPlatformId;
4906 CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
4907} OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA;
4908
4909typedef struct _OSVERSIONINFOW {
4910 ULONG dwOSVersionInfoSize;
4911 ULONG dwMajorVersion;
4912 ULONG dwMinorVersion;
4913 ULONG dwBuildNumber;
4914 ULONG dwPlatformId;
4915 WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
4916} OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW, RTL_OSVERSIONINFOW, *PRTL_OSVERSIONINFOW;
4917#ifdef UNICODE
4918typedef OSVERSIONINFOW OSVERSIONINFO;
4919typedef POSVERSIONINFOW POSVERSIONINFO;
4920typedef LPOSVERSIONINFOW LPOSVERSIONINFO;
4921#else
4922typedef OSVERSIONINFOA OSVERSIONINFO;
4923typedef POSVERSIONINFOA POSVERSIONINFO;
4924typedef LPOSVERSIONINFOA LPOSVERSIONINFO;
4925#endif // UNICODE
4926
4927typedef struct _OSVERSIONINFOEXA {
4928 ULONG dwOSVersionInfoSize;
4929 ULONG dwMajorVersion;
4930 ULONG dwMinorVersion;
4931 ULONG dwBuildNumber;
4932 ULONG dwPlatformId;
4933 CHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
4934 USHORT wServicePackMajor;
4935 USHORT wServicePackMinor;
4936 USHORT wSuiteMask;
4937 UCHAR wProductType;
4938 UCHAR wReserved;
4939} OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA;
4940typedef struct _OSVERSIONINFOEXW {
4941 ULONG dwOSVersionInfoSize;
4942 ULONG dwMajorVersion;
4943 ULONG dwMinorVersion;
4944 ULONG dwBuildNumber;
4945 ULONG dwPlatformId;
4946 WCHAR szCSDVersion[ 128 ]; // Maintenance string for PSS usage
4947 USHORT wServicePackMajor;
4948 USHORT wServicePackMinor;
4949 USHORT wSuiteMask;
4950 UCHAR wProductType;
4951 UCHAR wReserved;
4952} OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW, RTL_OSVERSIONINFOEXW, *PRTL_OSVERSIONINFOEXW;
4953#ifdef UNICODE
4954typedef OSVERSIONINFOEXW OSVERSIONINFOEX;
4955typedef POSVERSIONINFOEXW POSVERSIONINFOEX;
4956typedef LPOSVERSIONINFOEXW LPOSVERSIONINFOEX;
4957#else
4958typedef OSVERSIONINFOEXA OSVERSIONINFOEX;
4959typedef POSVERSIONINFOEXA POSVERSIONINFOEX;
4960typedef LPOSVERSIONINFOEXA LPOSVERSIONINFOEX;
4961#endif // UNICODE
4962
4963//
4964// RtlVerifyVersionInfo() conditions
4965//
4966
4967#define VER_EQUAL 1
4968#define VER_GREATER 2
4969#define VER_GREATER_EQUAL 3
4970#define VER_LESS 4
4971#define VER_LESS_EQUAL 5
4972#define VER_AND 6
4973#define VER_OR 7
4974
4975#define VER_CONDITION_MASK 7
4976#define VER_NUM_BITS_PER_CONDITION_MASK 3
4977
4978//
4979// RtlVerifyVersionInfo() type mask bits
4980//
4981
4982#define VER_MINORVERSION 0x0000001
4983#define VER_MAJORVERSION 0x0000002
4984#define VER_BUILDNUMBER 0x0000004
4985#define VER_PLATFORMID 0x0000008
4986#define VER_SERVICEPACKMINOR 0x0000010
4987#define VER_SERVICEPACKMAJOR 0x0000020
4988#define VER_SUITENAME 0x0000040
4989#define VER_PRODUCT_TYPE 0x0000080
4990
4991//
4992// RtlVerifyVersionInfo() os product type values
4993//
4994
4995#define VER_NT_WORKSTATION 0x0000001
4996#define VER_NT_DOMAIN_CONTROLLER 0x0000002
4997#define VER_NT_SERVER 0x0000003
4998
4999//
5000// dwPlatformId defines:
5001//
5002
5003#define VER_PLATFORM_WIN32s 0
5004#define VER_PLATFORM_WIN32_WINDOWS 1
5005#define VER_PLATFORM_WIN32_NT 2
5006
5007
5008//
5009//
5010// VerifyVersionInfo() macro to set the condition mask
5011//
5012// For documentation sakes here's the old version of the macro that got
5013// changed to call an API
5014// #define VER_SET_CONDITION(_m_,_t_,_c_) _m_=(_m_|(_c_<<(1<<_t_)))
5015//
5016
5017#define VER_SET_CONDITION(_m_,_t_,_c_) \
5018 ((_m_)=VerSetConditionMask((_m_),(_t_),(_c_)))
5019
5020ULONGLONG
5021NTAPI
5022VerSetConditionMask(
5023 IN ULONGLONG ConditionMask,
5024 IN ULONG TypeMask,
5025 IN UCHAR Condition
5026 );
5027//
5028
5029//
5030
5031NTSYSAPI
5032NTSTATUS
5033RtlGetVersion(
5034 OUT PRTL_OSVERSIONINFOW lpVersionInformation
5035 );
5036
5037NTSYSAPI
5038NTSTATUS
5039RtlVerifyVersionInfo(
5040 IN PRTL_OSVERSIONINFOEXW VersionInfo,
5041 IN ULONG TypeMask,
5042 IN ULONGLONG ConditionMask
5043 );
5044
5045//
5046//
5047// Interlocked bit manipulation interfaces
5048//
5049
5050#define RtlInterlockedSetBits(Flags, Flag) \
5051 InterlockedOr((PLONG)(Flags), Flag)
5052
5053#define RtlInterlockedAndBits(Flags, Flag) \
5054 InterlockedAnd((PLONG)(Flags), Flag)
5055
5056#define RtlInterlockedClearBits(Flags, Flag) \
5057 RtlInterlockedAndBits(Flags, ~(Flag))
5058
5059#define RtlInterlockedXorBits(Flags, Flag) \
5060 InterlockedXor(Flags, Flag)
5061
5062#define RtlInterlockedSetBitsDiscardReturn(Flags, Flag) \
5063 (VOID) RtlInterlockedSetBits(Flags, Flag)
5064
5065#define RtlInterlockedAndBitsDiscardReturn(Flags, Flag) \
5066 (VOID) RtlInterlockedAndBits(Flags, Flag)
5067
5068#define RtlInterlockedClearBitsDiscardReturn(Flags, Flag) \
5069 RtlInterlockedAndBitsDiscardReturn(Flags, ~(Flag))
5070
5071//
5072// Component name filter id enumeration and levels.
5073//
5074
5075#define DPFLTR_ERROR_LEVEL 0
5076#define DPFLTR_WARNING_LEVEL 1
5077#define DPFLTR_TRACE_LEVEL 2
5078#define DPFLTR_INFO_LEVEL 3
5079#define DPFLTR_MASK 0x80000000
5080
5081typedef enum _DPFLTR_TYPE {
5082 DPFLTR_SYSTEM_ID = 0,
5083 DPFLTR_SMSS_ID = 1,
5084 DPFLTR_SETUP_ID = 2,
5085 DPFLTR_NTFS_ID = 3,
5086 DPFLTR_FSTUB_ID = 4,
5087 DPFLTR_CRASHDUMP_ID = 5,
5088 DPFLTR_CDAUDIO_ID = 6,
5089 DPFLTR_CDROM_ID = 7,
5090 DPFLTR_CLASSPNP_ID = 8,
5091 DPFLTR_DISK_ID = 9,
5092 DPFLTR_REDBOOK_ID = 10,
5093 DPFLTR_STORPROP_ID = 11,
5094 DPFLTR_SCSIPORT_ID = 12,
5095 DPFLTR_SCSIMINIPORT_ID = 13,
5096 DPFLTR_CONFIG_ID = 14,
5097 DPFLTR_I8042PRT_ID = 15,
5098 DPFLTR_SERMOUSE_ID = 16,
5099 DPFLTR_LSERMOUS_ID = 17,
5100 DPFLTR_KBDHID_ID = 18,
5101 DPFLTR_MOUHID_ID = 19,
5102 DPFLTR_KBDCLASS_ID = 20,
5103 DPFLTR_MOUCLASS_ID = 21,
5104 DPFLTR_TWOTRACK_ID = 22,
5105 DPFLTR_WMILIB_ID = 23,
5106 DPFLTR_ACPI_ID = 24,
5107 DPFLTR_AMLI_ID = 25,
5108 DPFLTR_HALIA64_ID = 26,
5109 DPFLTR_VIDEO_ID = 27,
5110 DPFLTR_SVCHOST_ID = 28,
5111 DPFLTR_VIDEOPRT_ID = 29,
5112 DPFLTR_TCPIP_ID = 30,
5113 DPFLTR_DMSYNTH_ID = 31,
5114 DPFLTR_NTOSPNP_ID = 32,
5115 DPFLTR_FASTFAT_ID = 33,
5116 DPFLTR_SAMSS_ID = 34,
5117 DPFLTR_PNPMGR_ID = 35,
5118 DPFLTR_NETAPI_ID = 36,
5119 DPFLTR_SCSERVER_ID = 37,
5120 DPFLTR_SCCLIENT_ID = 38,
5121 DPFLTR_SERIAL_ID = 39,
5122 DPFLTR_SERENUM_ID = 40,
5123 DPFLTR_UHCD_ID = 41,
5124 DPFLTR_RPCPROXY_ID = 42,
5125 DPFLTR_AUTOCHK_ID = 43,
5126 DPFLTR_DCOMSS_ID = 44,
5127 DPFLTR_UNIMODEM_ID = 45,
5128 DPFLTR_SIS_ID = 46,
5129 DPFLTR_FLTMGR_ID = 47,
5130 DPFLTR_WMICORE_ID = 48,
5131 DPFLTR_BURNENG_ID = 49,
5132 DPFLTR_IMAPI_ID = 50,
5133 DPFLTR_SXS_ID = 51,
5134 DPFLTR_FUSION_ID = 52,
5135 DPFLTR_IDLETASK_ID = 53,
5136 DPFLTR_SOFTPCI_ID = 54,
5137 DPFLTR_TAPE_ID = 55,
5138 DPFLTR_MCHGR_ID = 56,
5139 DPFLTR_IDEP_ID = 57,
5140 DPFLTR_PCIIDE_ID = 58,
5141 DPFLTR_FLOPPY_ID = 59,
5142 DPFLTR_FDC_ID = 60,
5143 DPFLTR_TERMSRV_ID = 61,
5144 DPFLTR_W32TIME_ID = 62,
5145 DPFLTR_PREFETCHER_ID = 63,
5146 DPFLTR_RSFILTER_ID = 64,
5147 DPFLTR_FCPORT_ID = 65,
5148 DPFLTR_PCI_ID = 66,
5149 DPFLTR_DMIO_ID = 67,
5150 DPFLTR_DMCONFIG_ID = 68,
5151 DPFLTR_DMADMIN_ID = 69,
5152 DPFLTR_WSOCKTRANSPORT_ID = 70,
5153 DPFLTR_VSS_ID = 71,
5154 DPFLTR_PNPMEM_ID = 72,
5155 DPFLTR_PROCESSOR_ID = 73,
5156 DPFLTR_DMSERVER_ID = 74,
5157 DPFLTR_SR_ID = 75,
5158 DPFLTR_INFINIBAND_ID = 76,
5159 DPFLTR_IHVDRIVER_ID = 77,
5160 DPFLTR_IHVVIDEO_ID = 78,
5161 DPFLTR_IHVAUDIO_ID = 79,
5162 DPFLTR_IHVNETWORK_ID = 80,
5163 DPFLTR_IHVSTREAMING_ID = 81,
5164 DPFLTR_IHVBUS_ID = 82,
5165 DPFLTR_HPS_ID = 83,
5166 DPFLTR_RTLTHREADPOOL_ID = 84,
5167 DPFLTR_LDR_ID = 85,
5168 DPFLTR_TCPIP6_ID = 86,
5169 DPFLTR_ISAPNP_ID = 87,
5170 DPFLTR_SHPC_ID = 88,
5171 DPFLTR_STORPORT_ID = 89,
5172 DPFLTR_STORMINIPORT_ID = 90,
5173 DPFLTR_PRINTSPOOLER_ID = 91,
5174 DPFLTR_VSSDYNDISK_ID = 92,
5175 DPFLTR_VERIFIER_ID = 93,
5176 DPFLTR_VDS_ID = 94,
5177 DPFLTR_VDSBAS_ID = 95,
5178 DPFLTR_VDSDYNDR_ID = 96,
5179 DPFLTR_VDSUTIL_ID = 97,
5180 DPFLTR_DFRGIFC_ID = 98,
5181 DPFLTR_ENDOFTABLE_ID
5182} DPFLTR_TYPE;
5183
5184//
5185// Define the various device type values. Note that values used by Microsoft
5186// Corporation are in the range 0-32767, and 32768-65535 are reserved for use
5187// by customers.
5188//
5189
5190#define DEVICE_TYPE ULONG
5191
5192#define FILE_DEVICE_BEEP 0x00000001
5193#define FILE_DEVICE_CD_ROM 0x00000002
5194#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
5195#define FILE_DEVICE_CONTROLLER 0x00000004
5196#define FILE_DEVICE_DATALINK 0x00000005
5197#define FILE_DEVICE_DFS 0x00000006
5198#define FILE_DEVICE_DISK 0x00000007
5199#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
5200#define FILE_DEVICE_FILE_SYSTEM 0x00000009
5201#define FILE_DEVICE_INPORT_PORT 0x0000000a
5202#define FILE_DEVICE_KEYBOARD 0x0000000b
5203#define FILE_DEVICE_MAILSLOT 0x0000000c
5204#define FILE_DEVICE_MIDI_IN 0x0000000d
5205#define FILE_DEVICE_MIDI_OUT 0x0000000e
5206#define FILE_DEVICE_MOUSE 0x0000000f
5207#define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
5208#define FILE_DEVICE_NAMED_PIPE 0x00000011
5209#define FILE_DEVICE_NETWORK 0x00000012
5210#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
5211#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
5212#define FILE_DEVICE_NULL 0x00000015
5213#define FILE_DEVICE_PARALLEL_PORT 0x00000016
5214#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
5215#define FILE_DEVICE_PRINTER 0x00000018
5216#define FILE_DEVICE_SCANNER 0x00000019
5217#define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
5218#define FILE_DEVICE_SERIAL_PORT 0x0000001b
5219#define FILE_DEVICE_SCREEN 0x0000001c
5220#define FILE_DEVICE_SOUND 0x0000001d
5221#define FILE_DEVICE_STREAMS 0x0000001e
5222#define FILE_DEVICE_TAPE 0x0000001f
5223#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
5224#define FILE_DEVICE_TRANSPORT 0x00000021
5225#define FILE_DEVICE_UNKNOWN 0x00000022
5226#define FILE_DEVICE_VIDEO 0x00000023
5227#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
5228#define FILE_DEVICE_WAVE_IN 0x00000025
5229#define FILE_DEVICE_WAVE_OUT 0x00000026
5230#define FILE_DEVICE_8042_PORT 0x00000027
5231#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
5232#define FILE_DEVICE_BATTERY 0x00000029
5233#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
5234#define FILE_DEVICE_MODEM 0x0000002b
5235#define FILE_DEVICE_VDM 0x0000002c
5236#define FILE_DEVICE_MASS_STORAGE 0x0000002d
5237#define FILE_DEVICE_SMB 0x0000002e
5238#define FILE_DEVICE_KS 0x0000002f
5239#define FILE_DEVICE_CHANGER 0x00000030
5240#define FILE_DEVICE_SMARTCARD 0x00000031
5241#define FILE_DEVICE_ACPI 0x00000032
5242#define FILE_DEVICE_DVD 0x00000033
5243#define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
5244#define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
5245#define FILE_DEVICE_DFS_VOLUME 0x00000036
5246#define FILE_DEVICE_SERENUM 0x00000037
5247#define FILE_DEVICE_TERMSRV 0x00000038
5248#define FILE_DEVICE_KSEC 0x00000039
5249#define FILE_DEVICE_FIPS 0x0000003A
5250#define FILE_DEVICE_INFINIBAND 0x0000003B
5251
5252//
5253// Macro definition for defining IOCTL and FSCTL function control codes. Note
5254// that function codes 0-2047 are reserved for Microsoft Corporation, and
5255// 2048-4095 are reserved for customers.
5256//
5257
5258#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
5259 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
5260)
5261
5262//
5263// Macro to extract device type out of the device io control code
5264//
5265#define DEVICE_TYPE_FROM_CTL_CODE(ctrlCode) (((ULONG)(ctrlCode & 0xffff0000)) >> 16)
5266
5267//
5268// Define the method codes for how buffers are passed for I/O and FS controls
5269//
5270
5271#define METHOD_BUFFERED 0
5272#define METHOD_IN_DIRECT 1
5273#define METHOD_OUT_DIRECT 2
5274#define METHOD_NEITHER 3
5275
5276//
5277// Define some easier to comprehend aliases:
5278// METHOD_DIRECT_TO_HARDWARE (writes, aka METHOD_IN_DIRECT)
5279// METHOD_DIRECT_FROM_HARDWARE (reads, aka METHOD_OUT_DIRECT)
5280//
5281
5282#define METHOD_DIRECT_TO_HARDWARE METHOD_IN_DIRECT
5283#define METHOD_DIRECT_FROM_HARDWARE METHOD_OUT_DIRECT
5284
5285//
5286// Define the access check value for any access
5287//
5288//
5289// The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
5290// ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
5291// constants *MUST* always be in sync.
5292//
5293//
5294// FILE_SPECIAL_ACCESS is checked by the NT I/O system the same as FILE_ANY_ACCESS.
5295// The file systems, however, may add additional access checks for I/O and FS controls
5296// that use this value.
5297//
5298
5299
5300#define FILE_ANY_ACCESS 0
5301#define FILE_SPECIAL_ACCESS (FILE_ANY_ACCESS)
5302#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
5303#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
5304
5305
5306
5307//
5308// Define access rights to files and directories
5309//
5310
5311//
5312// The FILE_READ_DATA and FILE_WRITE_DATA constants are also defined in
5313// devioctl.h as FILE_READ_ACCESS and FILE_WRITE_ACCESS. The values for these
5314// constants *MUST* always be in sync.
5315// The values are redefined in devioctl.h because they must be available to
5316// both DOS and NT.
5317//
5318
5319#define FILE_READ_DATA ( 0x0001 ) // file & pipe
5320#define FILE_LIST_DIRECTORY ( 0x0001 ) // directory
5321
5322#define FILE_WRITE_DATA ( 0x0002 ) // file & pipe
5323#define FILE_ADD_FILE ( 0x0002 ) // directory
5324
5325#define FILE_APPEND_DATA ( 0x0004 ) // file
5326#define FILE_ADD_SUBDIRECTORY ( 0x0004 ) // directory
5327#define FILE_CREATE_PIPE_INSTANCE ( 0x0004 ) // named pipe
5328
5329
5330#define FILE_READ_EA ( 0x0008 ) // file & directory
5331
5332#define FILE_WRITE_EA ( 0x0010 ) // file & directory
5333
5334#define FILE_EXECUTE ( 0x0020 ) // file
5335#define FILE_TRAVERSE ( 0x0020 ) // directory
5336
5337#define FILE_DELETE_CHILD ( 0x0040 ) // directory
5338
5339#define FILE_READ_ATTRIBUTES ( 0x0080 ) // all
5340
5341#define FILE_WRITE_ATTRIBUTES ( 0x0100 ) // all
5342
5343#define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x1FF)
5344
5345#define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\
5346 FILE_READ_DATA |\
5347 FILE_READ_ATTRIBUTES |\
5348 FILE_READ_EA |\
5349 SYNCHRONIZE)
5350
5351
5352#define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE |\
5353 FILE_WRITE_DATA |\
5354 FILE_WRITE_ATTRIBUTES |\
5355 FILE_WRITE_EA |\
5356 FILE_APPEND_DATA |\
5357 SYNCHRONIZE)
5358
5359
5360#define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE |\
5361 FILE_READ_ATTRIBUTES |\
5362 FILE_EXECUTE |\
5363 SYNCHRONIZE)
5364
5365
5366
5367
5368//
5369// Define share access rights to files and directories
5370//
5371
5372#define FILE_SHARE_READ 0x00000001
5373#define FILE_SHARE_WRITE 0x00000002
5374#define FILE_SHARE_DELETE 0x00000004
5375#define FILE_SHARE_VALID_FLAGS 0x00000007
5376
5377//
5378// Define the file attributes values
5379//
5380// Note: 0x00000008 is reserved for use for the old DOS VOLID (volume ID)
5381// and is therefore not considered valid in NT.
5382//
5383// Note: 0x00000010 is reserved for use for the old DOS SUBDIRECTORY flag
5384// and is therefore not considered valid in NT. This flag has
5385// been disassociated with file attributes since the other flags are
5386// protected with READ_ and WRITE_ATTRIBUTES access to the file.
5387//
5388// Note: Note also that the order of these flags is set to allow both the
5389// FAT and the Pinball File Systems to directly set the attributes
5390// flags in attributes words without having to pick each flag out
5391// individually. The order of these flags should not be changed!
5392//
5393
5394#define FILE_ATTRIBUTE_READONLY 0x00000001
5395#define FILE_ATTRIBUTE_HIDDEN 0x00000002
5396#define FILE_ATTRIBUTE_SYSTEM 0x00000004
5397//OLD DOS VOLID 0x00000008
5398
5399#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
5400#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
5401#define FILE_ATTRIBUTE_DEVICE 0x00000040
5402#define FILE_ATTRIBUTE_NORMAL 0x00000080
5403
5404#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
5405#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
5406#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
5407#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
5408
5409#define FILE_ATTRIBUTE_OFFLINE 0x00001000
5410#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
5411#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
5412
5413#define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
5414#define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
5415
5416//
5417// Define the create disposition values
5418//
5419
5420#define FILE_SUPERSEDE 0x00000000
5421#define FILE_OPEN 0x00000001
5422#define FILE_CREATE 0x00000002
5423#define FILE_OPEN_IF 0x00000003
5424#define FILE_OVERWRITE 0x00000004
5425#define FILE_OVERWRITE_IF 0x00000005
5426#define FILE_MAXIMUM_DISPOSITION 0x00000005
5427
5428//
5429// Define the create/open option flags
5430//
5431
5432#define FILE_DIRECTORY_FILE 0x00000001
5433#define FILE_WRITE_THROUGH 0x00000002
5434#define FILE_SEQUENTIAL_ONLY 0x00000004
5435#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
5436
5437#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
5438#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
5439#define FILE_NON_DIRECTORY_FILE 0x00000040
5440#define FILE_CREATE_TREE_CONNECTION 0x00000080
5441
5442#define FILE_COMPLETE_IF_OPLOCKED 0x00000100
5443#define FILE_NO_EA_KNOWLEDGE 0x00000200
5444#define FILE_OPEN_FOR_RECOVERY 0x00000400
5445#define FILE_RANDOM_ACCESS 0x00000800
5446
5447#define FILE_DELETE_ON_CLOSE 0x00001000
5448#define FILE_OPEN_BY_FILE_ID 0x00002000
5449#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
5450#define FILE_NO_COMPRESSION 0x00008000
5451
5452#define FILE_RESERVE_OPFILTER 0x00100000
5453#define FILE_OPEN_REPARSE_POINT 0x00200000
5454#define FILE_OPEN_NO_RECALL 0x00400000
5455#define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
5456
5457#define FILE_COPY_STRUCTURED_STORAGE 0x00000041
5458#define FILE_STRUCTURED_STORAGE 0x00000441
5459
5460#define FILE_VALID_OPTION_FLAGS 0x00ffffff
5461#define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
5462#define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
5463#define FILE_VALID_SET_FLAGS 0x00000036
5464
5465//
5466// Define the I/O status information return values for NtCreateFile/NtOpenFile
5467//
5468
5469#define FILE_SUPERSEDED 0x00000000
5470#define FILE_OPENED 0x00000001
5471#define FILE_CREATED 0x00000002
5472#define FILE_OVERWRITTEN 0x00000003
5473#define FILE_EXISTS 0x00000004
5474#define FILE_DOES_NOT_EXIST 0x00000005
5475
5476//
5477// Define special ByteOffset parameters for read and write operations
5478//
5479
5480#define FILE_WRITE_TO_END_OF_FILE 0xffffffff
5481#define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
5482
5483//
5484// Define alignment requirement values
5485//
5486
5487#define FILE_BYTE_ALIGNMENT 0x00000000
5488#define FILE_WORD_ALIGNMENT 0x00000001
5489#define FILE_LONG_ALIGNMENT 0x00000003
5490#define FILE_QUAD_ALIGNMENT 0x00000007
5491#define FILE_OCTA_ALIGNMENT 0x0000000f
5492#define FILE_32_BYTE_ALIGNMENT 0x0000001f
5493#define FILE_64_BYTE_ALIGNMENT 0x0000003f
5494#define FILE_128_BYTE_ALIGNMENT 0x0000007f
5495#define FILE_256_BYTE_ALIGNMENT 0x000000ff
5496#define FILE_512_BYTE_ALIGNMENT 0x000001ff
5497
5498//
5499// Define the maximum length of a filename string
5500//
5501
5502#define MAXIMUM_FILENAME_LENGTH 256
5503
5504//
5505// Define the various device characteristics flags
5506//
5507
5508#define FILE_REMOVABLE_MEDIA 0x00000001
5509#define FILE_READ_ONLY_DEVICE 0x00000002
5510#define FILE_FLOPPY_DISKETTE 0x00000004
5511#define FILE_WRITE_ONCE_MEDIA 0x00000008
5512#define FILE_REMOTE_DEVICE 0x00000010
5513#define FILE_DEVICE_IS_MOUNTED 0x00000020
5514#define FILE_VIRTUAL_VOLUME 0x00000040
5515#define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
5516#define FILE_DEVICE_SECURE_OPEN 0x00000100
5517#define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
5518
5519
5520
5521//
5522// The FILE_EXPECT flags will only exist for WinXP. After that they will be
5523// ignored and an IRP will be sent in their place.
5524//
5525#define FILE_CHARACTERISTICS_EXPECT_ORDERLY_REMOVAL 0x00000200
5526#define FILE_CHARACTERISTICS_EXPECT_SURPRISE_REMOVAL 0x00000300
5527#define FILE_CHARACTERISTICS_REMOVAL_POLICY_MASK 0x00000300
5528
5529//
5530// flags specified here will be propagated up and down a device stack
5531// after FDO and all filter devices are added, but before the device
5532// stack is started
5533//
5534
5535#define FILE_CHARACTERISTICS_PROPAGATED ( FILE_REMOVABLE_MEDIA | \
5536 FILE_READ_ONLY_DEVICE | \
5537 FILE_FLOPPY_DISKETTE | \
5538 FILE_WRITE_ONCE_MEDIA | \
5539 FILE_DEVICE_SECURE_OPEN )
5540
5541//
5542// Define the base asynchronous I/O argument types
5543//
5544
5545typedef struct _IO_STATUS_BLOCK {
5546 union {
5547 NTSTATUS Status;
5548 PVOID Pointer;
5549 };
5550
5551 ULONG_PTR Information;
5552} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
5553
5554#if defined(_WIN64)
5555typedef struct _IO_STATUS_BLOCK32 {
5556 NTSTATUS Status;
5557 ULONG Information;
5558} IO_STATUS_BLOCK32, *PIO_STATUS_BLOCK32;
5559#endif
5560
5561
5562//
5563// Define an Asynchronous Procedure Call from I/O viewpoint
5564//
5565
5566typedef
5567VOID
5568(NTAPI *PIO_APC_ROUTINE) (
5569 IN PVOID ApcContext,
5570 IN PIO_STATUS_BLOCK IoStatusBlock,
5571 IN ULONG Reserved
5572 );
5573#define PIO_APC_ROUTINE_DEFINED
5574
5575//
5576// Define the file information class values
5577//
5578// WARNING: The order of the following values are assumed by the I/O system.
5579// Any changes made here should be reflected there as well.
5580//
5581
5582typedef enum _FILE_INFORMATION_CLASS {
5583
5584 FileDirectoryInformation = 1,
5585 FileFullDirectoryInformation, // 2
5586 FileBothDirectoryInformation, // 3
5587 FileBasicInformation, // 4 wdm
5588 FileStandardInformation, // 5 wdm
5589 FileInternalInformation, // 6
5590 FileEaInformation, // 7
5591 FileAccessInformation, // 8
5592 FileNameInformation, // 9
5593 FileRenameInformation, // 10
5594 FileLinkInformation, // 11
5595 FileNamesInformation, // 12
5596 FileDispositionInformation, // 13
5597 FilePositionInformation, // 14 wdm
5598 FileFullEaInformation, // 15
5599 FileModeInformation, // 16
5600 FileAlignmentInformation, // 17
5601 FileAllInformation, // 18
5602 FileAllocationInformation, // 19
5603 FileEndOfFileInformation, // 20 wdm
5604 FileAlternateNameInformation, // 21
5605 FileStreamInformation, // 22
5606 FilePipeInformation, // 23
5607 FilePipeLocalInformation, // 24
5608 FilePipeRemoteInformation, // 25
5609 FileMailslotQueryInformation, // 26
5610 FileMailslotSetInformation, // 27
5611 FileCompressionInformation, // 28
5612 FileObjectIdInformation, // 29
5613 FileCompletionInformation, // 30
5614 FileMoveClusterInformation, // 31
5615 FileQuotaInformation, // 32
5616 FileReparsePointInformation, // 33
5617 FileNetworkOpenInformation, // 34
5618 FileAttributeTagInformation, // 35
5619 FileTrackingInformation, // 36
5620 FileIdBothDirectoryInformation, // 37
5621 FileIdFullDirectoryInformation, // 38
5622 FileValidDataLengthInformation, // 39
5623 FileShortNameInformation, // 40
5624 FileMaximumInformation
5625
5626} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
5627
5628//
5629// Define the various structures which are returned on query operations
5630//
5631
5632typedef struct _FILE_BASIC_INFORMATION {
5633 LARGE_INTEGER CreationTime;
5634 LARGE_INTEGER LastAccessTime;
5635 LARGE_INTEGER LastWriteTime;
5636 LARGE_INTEGER ChangeTime;
5637 ULONG FileAttributes;
5638} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
5639
5640typedef struct _FILE_STANDARD_INFORMATION {
5641 LARGE_INTEGER AllocationSize;
5642 LARGE_INTEGER EndOfFile;
5643 ULONG NumberOfLinks;
5644 BOOLEAN DeletePending;
5645 BOOLEAN Directory;
5646} FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
5647
5648typedef struct _FILE_POSITION_INFORMATION {
5649 LARGE_INTEGER CurrentByteOffset;
5650} FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
5651
5652typedef struct _FILE_ALIGNMENT_INFORMATION {
5653 ULONG AlignmentRequirement;
5654} FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION;
5655
5656typedef struct _FILE_NAME_INFORMATION {
5657 ULONG FileNameLength;
5658 WCHAR FileName[1];
5659} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
5660
5661typedef struct _FILE_NETWORK_OPEN_INFORMATION {
5662 LARGE_INTEGER CreationTime;
5663 LARGE_INTEGER LastAccessTime;
5664 LARGE_INTEGER LastWriteTime;
5665 LARGE_INTEGER ChangeTime;
5666 LARGE_INTEGER AllocationSize;
5667 LARGE_INTEGER EndOfFile;
5668 ULONG FileAttributes;
5669} FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
5670
5671typedef struct _FILE_ATTRIBUTE_TAG_INFORMATION {
5672 ULONG FileAttributes;
5673 ULONG ReparseTag;
5674} FILE_ATTRIBUTE_TAG_INFORMATION, *PFILE_ATTRIBUTE_TAG_INFORMATION;
5675
5676typedef struct _FILE_DISPOSITION_INFORMATION {
5677 BOOLEAN DeleteFile;
5678} FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION;
5679
5680typedef struct _FILE_END_OF_FILE_INFORMATION {
5681 LARGE_INTEGER EndOfFile;
5682} FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION;
5683
5684typedef struct _FILE_VALID_DATA_LENGTH_INFORMATION {
5685 LARGE_INTEGER ValidDataLength;
5686} FILE_VALID_DATA_LENGTH_INFORMATION, *PFILE_VALID_DATA_LENGTH_INFORMATION;
5687
5688typedef struct _FILE_FULL_EA_INFORMATION {
5689 ULONG NextEntryOffset;
5690 UCHAR Flags;
5691 UCHAR EaNameLength;
5692 USHORT EaValueLength;
5693 CHAR EaName[1];
5694} FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
5695
5696//
5697// Define the file system information class values
5698//
5699// WARNING: The order of the following values are assumed by the I/O system.
5700// Any changes made here should be reflected there as well.
5701
5702typedef enum _FSINFOCLASS {
5703 FileFsVolumeInformation = 1,
5704 FileFsLabelInformation, // 2
5705 FileFsSizeInformation, // 3
5706 FileFsDeviceInformation, // 4
5707 FileFsAttributeInformation, // 5
5708 FileFsControlInformation, // 6
5709 FileFsFullSizeInformation, // 7
5710 FileFsObjectIdInformation, // 8
5711 FileFsDriverPathInformation, // 9
5712 FileFsMaximumInformation
5713} FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
5714
5715typedef struct _FILE_FS_DEVICE_INFORMATION {
5716 DEVICE_TYPE DeviceType;
5717 ULONG Characteristics;
5718} FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
5719
5720
5721//
5722// Define segement buffer structure for scatter/gather read/write.
5723//
5724
5725typedef union _FILE_SEGMENT_ELEMENT {
5726 PVOID64 Buffer;
5727 ULONGLONG Alignment;
5728}FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT;
5729
5730//
5731// Define the I/O bus interface types.
5732//
5733
5734typedef enum _INTERFACE_TYPE {
5735 InterfaceTypeUndefined = -1,
5736 Internal,
5737 Isa,
5738 Eisa,
5739 MicroChannel,
5740 TurboChannel,
5741 PCIBus,
5742 VMEBus,
5743 NuBus,
5744 PCMCIABus,
5745 CBus,
5746 MPIBus,
5747 MPSABus,
5748 ProcessorInternal,
5749 InternalPowerBus,
5750 PNPISABus,
5751 PNPBus,
5752 MaximumInterfaceType
5753}INTERFACE_TYPE, *PINTERFACE_TYPE;
5754
5755//
5756// Define the DMA transfer widths.
5757//
5758
5759typedef enum _DMA_WIDTH {
5760 Width8Bits,
5761 Width16Bits,
5762 Width32Bits,
5763 MaximumDmaWidth
5764}DMA_WIDTH, *PDMA_WIDTH;
5765
5766//
5767// Define DMA transfer speeds.
5768//
5769
5770typedef enum _DMA_SPEED {
5771 Compatible,
5772 TypeA,
5773 TypeB,
5774 TypeC,
5775 TypeF,
5776 MaximumDmaSpeed
5777}DMA_SPEED, *PDMA_SPEED;
5778
5779//
5780// Define Interface reference/dereference routines for
5781// Interfaces exported by IRP_MN_QUERY_INTERFACE
5782//
5783
5784typedef VOID (*PINTERFACE_REFERENCE)(PVOID Context);
5785typedef VOID (*PINTERFACE_DEREFERENCE)(PVOID Context);
5786
5787
5788
5789//
5790// Define types of bus information.
5791//
5792
5793typedef enum _BUS_DATA_TYPE {
5794 ConfigurationSpaceUndefined = -1,
5795 Cmos,
5796 EisaConfiguration,
5797 Pos,
5798 CbusConfiguration,
5799 PCIConfiguration,
5800 VMEConfiguration,
5801 NuBusConfiguration,
5802 PCMCIAConfiguration,
5803 MPIConfiguration,
5804 MPSAConfiguration,
5805 PNPISAConfiguration,
5806 SgiInternalConfiguration,
5807 MaximumBusDataType
5808} BUS_DATA_TYPE, *PBUS_DATA_TYPE;
5809
5810//
5811// Define I/O Driver error log packet structure. This structure is filled in
5812// by the driver.
5813//
5814
5815typedef struct _IO_ERROR_LOG_PACKET {
5816 UCHAR MajorFunctionCode;
5817 UCHAR RetryCount;
5818 USHORT DumpDataSize;
5819 USHORT NumberOfStrings;
5820 USHORT StringOffset;
5821 USHORT EventCategory;
5822 NTSTATUS ErrorCode;
5823 ULONG UniqueErrorValue;
5824 NTSTATUS FinalStatus;
5825 ULONG SequenceNumber;
5826 ULONG IoControlCode;
5827 LARGE_INTEGER DeviceOffset;
5828 ULONG DumpData[1];
5829}IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
5830
5831//
5832// Define the I/O error log message. This message is sent by the error log
5833// thread over the lpc port.
5834//
5835
5836typedef struct _IO_ERROR_LOG_MESSAGE {
5837 USHORT Type;
5838 USHORT Size;
5839 USHORT DriverNameLength;
5840 LARGE_INTEGER TimeStamp;
5841 ULONG DriverNameOffset;
5842 IO_ERROR_LOG_PACKET EntryData;
5843}IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
5844
5845//
5846// Define the maximum message size that will be sent over the LPC to the
5847// application reading the error log entries.
5848//
5849
5850//
5851// Regardless of LPC size restrictions, ERROR_LOG_MAXIMUM_SIZE must remain
5852// a value that can fit in a UCHAR.
5853//
5854
5855#define ERROR_LOG_LIMIT_SIZE (256-16)
5856
5857//
5858// This limit, exclusive of IO_ERROR_LOG_MESSAGE_HEADER_LENGTH, also applies
5859// to IO_ERROR_LOG_MESSAGE_LENGTH
5860//
5861
5862#define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
5863 sizeof(IO_ERROR_LOG_PACKET) + \
5864 (sizeof(WCHAR) * 40))
5865
5866#define ERROR_LOG_MESSAGE_LIMIT_SIZE \
5867 (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
5868
5869//
5870// IO_ERROR_LOG_MESSAGE_LENGTH is
5871// min(PORT_MAXIMUM_MESSAGE_LENGTH, ERROR_LOG_MESSAGE_LIMIT_SIZE)
5872//
5873
5874#define IO_ERROR_LOG_MESSAGE_LENGTH \
5875 ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
5876 ERROR_LOG_MESSAGE_LIMIT_SIZE : \
5877 PORT_MAXIMUM_MESSAGE_LENGTH)
5878
5879//
5880// Define the maximum packet size a driver can allocate.
5881//
5882
5883#define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
5884 IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
5885
5886#ifdef _WIN64
5887#define PORT_MAXIMUM_MESSAGE_LENGTH 512
5888#else
5889#define PORT_MAXIMUM_MESSAGE_LENGTH 256
5890#endif
5891//
5892// Registry Specific Access Rights.
5893//
5894
5895#define KEY_QUERY_VALUE (0x0001)
5896#define KEY_SET_VALUE (0x0002)
5897#define KEY_CREATE_SUB_KEY (0x0004)
5898#define KEY_ENUMERATE_SUB_KEYS (0x0008)
5899#define KEY_NOTIFY (0x0010)
5900#define KEY_CREATE_LINK (0x0020)
5901#define KEY_WOW64_32KEY (0x0200)
5902#define KEY_WOW64_64KEY (0x0100)
5903#define KEY_WOW64_RES (0x0300)
5904
5905#define KEY_READ ((STANDARD_RIGHTS_READ |\
5906 KEY_QUERY_VALUE |\
5907 KEY_ENUMERATE_SUB_KEYS |\
5908 KEY_NOTIFY) \
5909 & \
5910 (~SYNCHRONIZE))
5911
5912
5913#define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
5914 KEY_SET_VALUE |\
5915 KEY_CREATE_SUB_KEY) \
5916 & \
5917 (~SYNCHRONIZE))
5918
5919#define KEY_EXECUTE ((KEY_READ) \
5920 & \
5921 (~SYNCHRONIZE))
5922
5923#define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
5924 KEY_QUERY_VALUE |\
5925 KEY_SET_VALUE |\
5926 KEY_CREATE_SUB_KEY |\
5927 KEY_ENUMERATE_SUB_KEYS |\
5928 KEY_NOTIFY |\
5929 KEY_CREATE_LINK) \
5930 & \
5931 (~SYNCHRONIZE))
5932
5933//
5934// Open/Create Options
5935//
5936
5937#define REG_OPTION_RESERVED (0x00000000L) // Parameter is reserved
5938
5939#define REG_OPTION_NON_VOLATILE (0x00000000L) // Key is preserved
5940 // when system is rebooted
5941
5942#define REG_OPTION_VOLATILE (0x00000001L) // Key is not preserved
5943 // when system is rebooted
5944
5945#define REG_OPTION_CREATE_LINK (0x00000002L) // Created key is a
5946 // symbolic link
5947
5948#define REG_OPTION_BACKUP_RESTORE (0x00000004L) // open for backup or restore
5949 // special access rules
5950 // privilege required
5951
5952#define REG_OPTION_OPEN_LINK (0x00000008L) // Open symbolic link
5953
5954#define REG_LEGAL_OPTION \
5955 (REG_OPTION_RESERVED |\
5956 REG_OPTION_NON_VOLATILE |\
5957 REG_OPTION_VOLATILE |\
5958 REG_OPTION_CREATE_LINK |\
5959 REG_OPTION_BACKUP_RESTORE |\
5960 REG_OPTION_OPEN_LINK)
5961
5962//
5963// Key creation/open disposition
5964//
5965
5966#define REG_CREATED_NEW_KEY (0x00000001L) // New Registry Key created
5967#define REG_OPENED_EXISTING_KEY (0x00000002L) // Existing Key opened
5968
5969//
5970// hive format to be used by Reg(Nt)SaveKeyEx
5971//
5972#define REG_STANDARD_FORMAT 1
5973#define REG_LATEST_FORMAT 2
5974#define REG_NO_COMPRESSION 4
5975
5976//
5977// Key restore flags
5978//
5979
5980#define REG_WHOLE_HIVE_VOLATILE (0x00000001L) // Restore whole hive volatile
5981#define REG_REFRESH_HIVE (0x00000002L) // Unwind changes to last flush
5982#define REG_NO_LAZY_FLUSH (0x00000004L) // Never lazy flush this hive
5983#define REG_FORCE_RESTORE (0x00000008L) // Force the restore process even when we have open handles on subkeys
5984
5985//
5986// Unload Flags
5987//
5988#define REG_FORCE_UNLOAD 1
5989
5990//
5991// Key query structures
5992//
5993
5994typedef struct _KEY_BASIC_INFORMATION {
5995 LARGE_INTEGER LastWriteTime;
5996 ULONG TitleIndex;
5997 ULONG NameLength;
5998 WCHAR Name[1]; // Variable length string
5999} KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
6000
6001typedef struct _KEY_NODE_INFORMATION {
6002 LARGE_INTEGER LastWriteTime;
6003 ULONG TitleIndex;
6004 ULONG ClassOffset;
6005 ULONG ClassLength;
6006 ULONG NameLength;
6007 WCHAR Name[1]; // Variable length string
6008// Class[1]; // Variable length string not declared
6009} KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
6010
6011typedef struct _KEY_FULL_INFORMATION {
6012 LARGE_INTEGER LastWriteTime;
6013 ULONG TitleIndex;
6014 ULONG ClassOffset;
6015 ULONG ClassLength;
6016 ULONG SubKeys;
6017 ULONG MaxNameLen;
6018 ULONG MaxClassLen;
6019 ULONG Values;
6020 ULONG MaxValueNameLen;
6021 ULONG MaxValueDataLen;
6022 WCHAR Class[1]; // Variable length
6023} KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
6024
6025
6026typedef struct _KEY_NAME_INFORMATION {
6027 ULONG NameLength;
6028 WCHAR Name[1]; // Variable length string
6029} KEY_NAME_INFORMATION, *PKEY_NAME_INFORMATION;
6030
6031typedef struct _KEY_CACHED_INFORMATION {
6032 LARGE_INTEGER LastWriteTime;
6033 ULONG TitleIndex;
6034 ULONG SubKeys;
6035 ULONG MaxNameLen;
6036 ULONG Values;
6037 ULONG MaxValueNameLen;
6038 ULONG MaxValueDataLen;
6039 ULONG NameLength;
6040 WCHAR Name[1]; // Variable length string
6041} KEY_CACHED_INFORMATION, *PKEY_CACHED_INFORMATION;
6042
6043typedef struct _KEY_FLAGS_INFORMATION {
6044 ULONG UserFlags;
6045} KEY_FLAGS_INFORMATION, *PKEY_FLAGS_INFORMATION;
6046
6047
6048typedef enum _KEY_INFORMATION_CLASS {
6049 KeyBasicInformation,
6050 KeyNodeInformation,
6051 KeyFullInformation
6052
6053 ,
6054 KeyNameInformation,
6055 KeyCachedInformation,
6056 KeyFlagsInformation,
6057 MaxKeyInfoClass // MaxKeyInfoClass should always be the last enum
6058
6059} KEY_INFORMATION_CLASS;
6060
6061typedef struct _KEY_WRITE_TIME_INFORMATION {
6062 LARGE_INTEGER LastWriteTime;
6063} KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
6064
6065typedef struct _KEY_USER_FLAGS_INFORMATION {
6066 ULONG UserFlags;
6067} KEY_USER_FLAGS_INFORMATION, *PKEY_USER_FLAGS_INFORMATION;
6068
6069typedef enum _KEY_SET_INFORMATION_CLASS {
6070 KeyWriteTimeInformation,
6071 KeyUserFlagsInformation,
6072 MaxKeySetInfoClass // MaxKeySetInfoClass should always be the last enum
6073} KEY_SET_INFORMATION_CLASS;
6074
6075//
6076// Value entry query structures
6077//
6078
6079typedef struct _KEY_VALUE_BASIC_INFORMATION {
6080 ULONG TitleIndex;
6081 ULONG Type;
6082 ULONG NameLength;
6083 WCHAR Name[1]; // Variable size
6084} KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
6085
6086typedef struct _KEY_VALUE_FULL_INFORMATION {
6087 ULONG TitleIndex;
6088 ULONG Type;
6089 ULONG DataOffset;
6090 ULONG DataLength;
6091 ULONG NameLength;
6092 WCHAR Name[1]; // Variable size
6093// Data[1]; // Variable size data not declared
6094} KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
6095
6096typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
6097 ULONG TitleIndex;
6098 ULONG Type;
6099 ULONG DataLength;
6100 UCHAR Data[1]; // Variable size
6101} KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
6102
6103typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
6104 ULONG Type;
6105 ULONG DataLength;
6106 UCHAR Data[1]; // Variable size
6107} KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
6108
6109typedef struct _KEY_VALUE_ENTRY {
6110 PUNICODE_STRING ValueName;
6111 ULONG DataLength;
6112 ULONG DataOffset;
6113 ULONG Type;
6114} KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
6115
6116typedef enum _KEY_VALUE_INFORMATION_CLASS {
6117 KeyValueBasicInformation,
6118 KeyValueFullInformation,
6119 KeyValuePartialInformation,
6120 KeyValueFullInformationAlign64,
6121 KeyValuePartialInformationAlign64,
6122 MaxKeyValueInfoClass // MaxKeyValueInfoClass should always be the last enum
6123} KEY_VALUE_INFORMATION_CLASS;
6124
6125
6126
6127#define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
6128
6129//
6130// Object Manager Object Type Specific Access Rights.
6131//
6132
6133#define OBJECT_TYPE_CREATE (0x0001)
6134
6135#define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
6136
6137//
6138// Object Manager Directory Specific Access Rights.
6139//
6140
6141#define DIRECTORY_QUERY (0x0001)
6142#define DIRECTORY_TRAVERSE (0x0002)
6143#define DIRECTORY_CREATE_OBJECT (0x0004)
6144#define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
6145
6146#define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
6147
6148//
6149// Object Manager Symbolic Link Specific Access Rights.
6150//
6151
6152#define SYMBOLIC_LINK_QUERY (0x0001)
6153
6154#define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
6155
6156typedef struct _OBJECT_NAME_INFORMATION {
6157 UNICODE_STRING Name;
6158} OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
6159#define DUPLICATE_CLOSE_SOURCE 0x00000001
6160#define DUPLICATE_SAME_ACCESS 0x00000002
6161#define DUPLICATE_SAME_ATTRIBUTES 0x00000004
6162
6163//
6164// Section Information Structures.
6165//
6166
6167typedef enum _SECTION_INHERIT {
6168 ViewShare = 1,
6169 ViewUnmap = 2
6170} SECTION_INHERIT;
6171
6172//
6173// Section Access Rights.
6174//
6175
6176
6177#define SECTION_QUERY 0x0001
6178#define SECTION_MAP_WRITE 0x0002
6179#define SECTION_MAP_READ 0x0004
6180#define SECTION_MAP_EXECUTE 0x0008
6181#define SECTION_EXTEND_SIZE 0x0010
6182
6183#define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
6184 SECTION_MAP_WRITE | \
6185 SECTION_MAP_READ | \
6186 SECTION_MAP_EXECUTE | \
6187 SECTION_EXTEND_SIZE)
6188
6189
6190#define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
6191
6192#define PAGE_NOACCESS 0x01
6193#define PAGE_READONLY 0x02
6194#define PAGE_READWRITE 0x04
6195#define PAGE_WRITECOPY 0x08
6196#define PAGE_EXECUTE 0x10
6197#define PAGE_EXECUTE_READ 0x20
6198#define PAGE_EXECUTE_READWRITE 0x40
6199#define PAGE_EXECUTE_WRITECOPY 0x80
6200#define PAGE_GUARD 0x100
6201#define PAGE_NOCACHE 0x200
6202#define PAGE_WRITECOMBINE 0x400
6203
6204#define MEM_COMMIT 0x1000
6205#define MEM_RESERVE 0x2000
6206#define MEM_DECOMMIT 0x4000
6207#define MEM_RELEASE 0x8000
6208#define MEM_FREE 0x10000
6209#define MEM_PRIVATE 0x20000
6210#define MEM_MAPPED 0x40000
6211#define MEM_RESET 0x80000
6212#define MEM_TOP_DOWN 0x100000
6213#define MEM_LARGE_PAGES 0x20000000
6214#define MEM_4MB_PAGES 0x80000000
6215#define SEC_RESERVE 0x4000000
6216#define PROCESS_DUP_HANDLE (0x0040)
6217#define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
6218 0xFFF)
6219
6220
6221#if defined(_WIN64)
6222
6223#define MAXIMUM_PROCESSORS 64
6224
6225#else
6226
6227#define MAXIMUM_PROCESSORS 32
6228
6229#endif
6230
6231
6232
6233
6234
6235//
6236// Thread Specific Access Rights
6237//
6238
6239#define THREAD_TERMINATE (0x0001)
6240#define THREAD_SET_INFORMATION (0x0020)
6241
6242#define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
6243 0x3FF)
6244
6245//
6246// ClientId
6247//
6248
6249typedef struct _CLIENT_ID {
6250 HANDLE UniqueProcess;
6251 HANDLE UniqueThread;
6252} CLIENT_ID;
6253typedef CLIENT_ID *PCLIENT_ID;
6254
6255//
6256// Thread Environment Block (and portable part of Thread Information Block)
6257//
6258
6259//
6260// NT_TIB - Thread Information Block - Portable part.
6261//
6262// This is the subsystem portable part of the Thread Information Block.
6263// It appears as the first part of the TEB for all threads which have
6264// a user mode component.
6265//
6266//
6267
6268
6269
6270typedef struct _NT_TIB {
6271 struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
6272 PVOID StackBase;
6273 PVOID StackLimit;
6274 PVOID SubSystemTib;
6275 union {
6276 PVOID FiberData;
6277 ULONG Version;
6278 };
6279 PVOID ArbitraryUserPointer;
6280 struct _NT_TIB *Self;
6281} NT_TIB;
6282typedef NT_TIB *PNT_TIB;
6283
6284//
6285// 32 and 64 bit specific version for wow64 and the debugger
6286//
6287typedef struct _NT_TIB32 {
6288 ULONG ExceptionList;
6289 ULONG StackBase;
6290 ULONG StackLimit;
6291 ULONG SubSystemTib;
6292 union {
6293 ULONG FiberData;
6294 ULONG Version;
6295 };
6296 ULONG ArbitraryUserPointer;
6297 ULONG Self;
6298} NT_TIB32, *PNT_TIB32;
6299
6300typedef struct _NT_TIB64 {
6301 ULONG64 ExceptionList;
6302 ULONG64 StackBase;
6303 ULONG64 StackLimit;
6304 ULONG64 SubSystemTib;
6305 union {
6306 ULONG64 FiberData;
6307 ULONG Version;
6308 };
6309 ULONG64 ArbitraryUserPointer;
6310 ULONG64 Self;
6311} NT_TIB64, *PNT_TIB64;
6312
6313//
6314// Process Information Classes
6315//
6316
6317typedef enum _PROCESSINFOCLASS {
6318 ProcessBasicInformation,
6319 ProcessQuotaLimits,
6320 ProcessIoCounters,
6321 ProcessVmCounters,
6322 ProcessTimes,
6323 ProcessBasePriority,
6324 ProcessRaisePriority,
6325 ProcessDebugPort,
6326 ProcessExceptionPort,
6327 ProcessAccessToken,
6328 ProcessLdtInformation,
6329 ProcessLdtSize,
6330 ProcessDefaultHardErrorMode,
6331 ProcessIoPortHandlers, // Note: this is kernel mode only
6332 ProcessPooledUsageAndLimits,
6333 ProcessWorkingSetWatch,
6334 ProcessUserModeIOPL,
6335 ProcessEnableAlignmentFaultFixup,
6336 ProcessPriorityClass,
6337 ProcessWx86Information,
6338 ProcessHandleCount,
6339 ProcessAffinityMask,
6340 ProcessPriorityBoost,
6341 ProcessDeviceMap,
6342 ProcessSessionInformation,
6343 ProcessForegroundInformation,
6344 ProcessWow64Information,
6345 ProcessImageFileName,
6346 ProcessLUIDDeviceMapsEnabled,
6347 ProcessBreakOnTermination,
6348 ProcessDebugObjectHandle,
6349 ProcessDebugFlags,
6350 ProcessHandleTracing,
6351 MaxProcessInfoClass // MaxProcessInfoClass should always be the last enum
6352 } PROCESSINFOCLASS;
6353
6354//
6355// Thread Information Classes
6356//
6357
6358typedef enum _THREADINFOCLASS {
6359 ThreadBasicInformation,
6360 ThreadTimes,
6361 ThreadPriority,
6362 ThreadBasePriority,
6363 ThreadAffinityMask,
6364 ThreadImpersonationToken,
6365 ThreadDescriptorTableEntry,
6366 ThreadEnableAlignmentFaultFixup,
6367 ThreadEventPair_Reusable,
6368 ThreadQuerySetWin32StartAddress,
6369 ThreadZeroTlsCell,
6370 ThreadPerformanceCount,
6371 ThreadAmILastThread,
6372 ThreadIdealProcessor,
6373 ThreadPriorityBoost,
6374 ThreadSetTlsArrayAddress,
6375 ThreadIsIoPending,
6376 ThreadHideFromDebugger,
6377 ThreadBreakOnTermination,
6378 MaxThreadInfoClass
6379 } THREADINFOCLASS;
6380//
6381// Process Information Structures
6382//
6383
6384//
6385// PageFaultHistory Information
6386// NtQueryInformationProcess using ProcessWorkingSetWatch
6387//
6388typedef struct _PROCESS_WS_WATCH_INFORMATION {
6389 PVOID FaultingPc;
6390 PVOID FaultingVa;
6391} PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION;
6392
6393//
6394// Basic Process Information
6395// NtQueryInformationProcess using ProcessBasicInfo
6396//
6397
6398typedef struct _PROCESS_BASIC_INFORMATION {
6399 NTSTATUS ExitStatus;
6400 PPEB PebBaseAddress;
6401 ULONG_PTR AffinityMask;
6402 KPRIORITY BasePriority;
6403 ULONG_PTR UniqueProcessId;
6404 ULONG_PTR InheritedFromUniqueProcessId;
6405} PROCESS_BASIC_INFORMATION;
6406typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
6407
6408
6409
6410//
6411// Process Device Map information
6412// NtQueryInformationProcess using ProcessDeviceMap
6413// NtSetInformationProcess using ProcessDeviceMap
6414//
6415
6416typedef struct _PROCESS_DEVICEMAP_INFORMATION {
6417 union {
6418 struct {
6419 HANDLE DirectoryHandle;
6420 } Set;
6421 struct {
6422 ULONG DriveMap;
6423 UCHAR DriveType[ 32 ];
6424 } Query;
6425 };
6426} PROCESS_DEVICEMAP_INFORMATION, *PPROCESS_DEVICEMAP_INFORMATION;
6427
6428typedef struct _PROCESS_DEVICEMAP_INFORMATION_EX {
6429 union {
6430 struct {
6431 HANDLE DirectoryHandle;
6432 } Set;
6433 struct {
6434 ULONG DriveMap;
6435 UCHAR DriveType[ 32 ];
6436 } Query;
6437 };
6438 ULONG Flags; // specifies that the query type
6439} PROCESS_DEVICEMAP_INFORMATION_EX, *PPROCESS_DEVICEMAP_INFORMATION_EX;
6440
6441//
6442// PROCESS_DEVICEMAP_INFORMATION_EX flags
6443//
6444#define PROCESS_LUID_DOSDEVICES_ONLY 0x00000001
6445
6446//
6447// Multi-User Session specific Process Information
6448// NtQueryInformationProcess using ProcessSessionInformation
6449//
6450
6451typedef struct _PROCESS_SESSION_INFORMATION {
6452 ULONG SessionId;
6453} PROCESS_SESSION_INFORMATION, *PPROCESS_SESSION_INFORMATION;
6454
6455
6456typedef struct _PROCESS_HANDLE_TRACING_ENABLE {
6457 ULONG Flags;
6458} PROCESS_HANDLE_TRACING_ENABLE, *PPROCESS_HANDLE_TRACING_ENABLE;
6459
6460typedef struct _PROCESS_HANDLE_TRACING_ENABLE_EX {
6461 ULONG Flags;
6462 ULONG TotalSlots;
6463} PROCESS_HANDLE_TRACING_ENABLE_EX, *PPROCESS_HANDLE_TRACING_ENABLE_EX;
6464
6465
6466#define PROCESS_HANDLE_TRACING_MAX_STACKS 16
6467
6468typedef struct _PROCESS_HANDLE_TRACING_ENTRY {
6469 HANDLE Handle;
6470 CLIENT_ID ClientId;
6471 ULONG Type;
6472 PVOID Stacks[PROCESS_HANDLE_TRACING_MAX_STACKS];
6473} PROCESS_HANDLE_TRACING_ENTRY, *PPROCESS_HANDLE_TRACING_ENTRY;
6474
6475typedef struct _PROCESS_HANDLE_TRACING_QUERY {
6476 HANDLE Handle;
6477 ULONG TotalTraces;
6478 PROCESS_HANDLE_TRACING_ENTRY HandleTrace[1];
6479} PROCESS_HANDLE_TRACING_QUERY, *PPROCESS_HANDLE_TRACING_QUERY;
6480
6481//
6482// Process Quotas
6483// NtQueryInformationProcess using ProcessQuotaLimits
6484// NtQueryInformationProcess using ProcessPooledQuotaLimits
6485// NtSetInformationProcess using ProcessQuotaLimits
6486//
6487
6488
6489
6490typedef struct _QUOTA_LIMITS {
6491 SIZE_T PagedPoolLimit;
6492 SIZE_T NonPagedPoolLimit;
6493 SIZE_T MinimumWorkingSetSize;
6494 SIZE_T MaximumWorkingSetSize;
6495 SIZE_T PagefileLimit;
6496 LARGE_INTEGER TimeLimit;
6497} QUOTA_LIMITS, *PQUOTA_LIMITS;
6498
6499#define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
6500#define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
6501#define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
6502#define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
6503
6504typedef struct _QUOTA_LIMITS_EX {
6505 SIZE_T PagedPoolLimit;
6506 SIZE_T NonPagedPoolLimit;
6507 SIZE_T MinimumWorkingSetSize;
6508 SIZE_T MaximumWorkingSetSize;
6509 SIZE_T PagefileLimit;
6510 LARGE_INTEGER TimeLimit;
6511 SIZE_T Reserved1;
6512 SIZE_T Reserved2;
6513 SIZE_T Reserved3;
6514 SIZE_T Reserved4;
6515 ULONG Flags;
6516 ULONG Reserved5;
6517} QUOTA_LIMITS_EX, *PQUOTA_LIMITS_EX;
6518
6519
6520
6521//
6522// Process I/O Counters
6523// NtQueryInformationProcess using ProcessIoCounters
6524//
6525
6526
6527typedef struct _IO_COUNTERS {
6528 ULONGLONG ReadOperationCount;
6529 ULONGLONG WriteOperationCount;
6530 ULONGLONG OtherOperationCount;
6531 ULONGLONG ReadTransferCount;
6532 ULONGLONG WriteTransferCount;
6533 ULONGLONG OtherTransferCount;
6534} IO_COUNTERS;
6535typedef IO_COUNTERS *PIO_COUNTERS;
6536
6537
6538
6539//
6540// Process Virtual Memory Counters
6541// NtQueryInformationProcess using ProcessVmCounters
6542//
6543
6544typedef struct _VM_COUNTERS {
6545 SIZE_T PeakVirtualSize;
6546 SIZE_T VirtualSize;
6547 ULONG PageFaultCount;
6548 SIZE_T PeakWorkingSetSize;
6549 SIZE_T WorkingSetSize;
6550 SIZE_T QuotaPeakPagedPoolUsage;
6551 SIZE_T QuotaPagedPoolUsage;
6552 SIZE_T QuotaPeakNonPagedPoolUsage;
6553 SIZE_T QuotaNonPagedPoolUsage;
6554 SIZE_T PagefileUsage;
6555 SIZE_T PeakPagefileUsage;
6556} VM_COUNTERS;
6557typedef VM_COUNTERS *PVM_COUNTERS;
6558
6559typedef struct _VM_COUNTERS_EX {
6560 SIZE_T PeakVirtualSize;
6561 SIZE_T VirtualSize;
6562 ULONG PageFaultCount;
6563 SIZE_T PeakWorkingSetSize;
6564 SIZE_T WorkingSetSize;
6565 SIZE_T QuotaPeakPagedPoolUsage;
6566 SIZE_T QuotaPagedPoolUsage;
6567 SIZE_T QuotaPeakNonPagedPoolUsage;
6568 SIZE_T QuotaNonPagedPoolUsage;
6569 SIZE_T PagefileUsage;
6570 SIZE_T PeakPagefileUsage;
6571 SIZE_T PrivateUsage;
6572} VM_COUNTERS_EX;
6573typedef VM_COUNTERS_EX *PVM_COUNTERS_EX;
6574
6575//
6576// Process Pooled Quota Usage and Limits
6577// NtQueryInformationProcess using ProcessPooledUsageAndLimits
6578//
6579
6580typedef struct _POOLED_USAGE_AND_LIMITS {
6581 SIZE_T PeakPagedPoolUsage;
6582 SIZE_T PagedPoolUsage;
6583 SIZE_T PagedPoolLimit;
6584 SIZE_T PeakNonPagedPoolUsage;
6585 SIZE_T NonPagedPoolUsage;
6586 SIZE_T NonPagedPoolLimit;
6587 SIZE_T PeakPagefileUsage;
6588 SIZE_T PagefileUsage;
6589 SIZE_T PagefileLimit;
6590} POOLED_USAGE_AND_LIMITS;
6591typedef POOLED_USAGE_AND_LIMITS *PPOOLED_USAGE_AND_LIMITS;
6592
6593//
6594// Process Security Context Information
6595// NtSetInformationProcess using ProcessAccessToken
6596// PROCESS_SET_ACCESS_TOKEN access to the process is needed
6597// to use this info level.
6598//
6599
6600typedef struct _PROCESS_ACCESS_TOKEN {
6601
6602 //
6603 // Handle to Primary token to assign to the process.
6604 // TOKEN_ASSIGN_PRIMARY access to this token is needed.
6605 //
6606
6607 HANDLE Token;
6608
6609 //
6610 // Handle to the initial thread of the process.
6611 // A process's access token can only be changed if the process has
6612 // no threads or one thread. If the process has no threads, this
6613 // field must be set to NULL. Otherwise, it must contain a handle
6614 // open to the process's only thread. THREAD_QUERY_INFORMATION access
6615 // is needed via this handle.
6616
6617 HANDLE Thread;
6618
6619} PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN;
6620
6621//
6622// Process/Thread System and User Time
6623// NtQueryInformationProcess using ProcessTimes
6624// NtQueryInformationThread using ThreadTimes
6625//
6626
6627typedef struct _KERNEL_USER_TIMES {
6628 LARGE_INTEGER CreateTime;
6629 LARGE_INTEGER ExitTime;
6630 LARGE_INTEGER KernelTime;
6631 LARGE_INTEGER UserTime;
6632} KERNEL_USER_TIMES;
6633typedef KERNEL_USER_TIMES *PKERNEL_USER_TIMES;
6634NTSYSCALLAPI
6635NTSTATUS
6636NTAPI
6637NtOpenProcess (
6638 OUT PHANDLE ProcessHandle,
6639 IN ACCESS_MASK DesiredAccess,
6640 IN POBJECT_ATTRIBUTES ObjectAttributes,
6641 IN PCLIENT_ID ClientId OPTIONAL
6642 );
6643#define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
6644#define ZwCurrentProcess() NtCurrentProcess()
6645NTSYSCALLAPI
6646NTSTATUS
6647NTAPI
6648NtQueryInformationProcess(
6649 IN HANDLE ProcessHandle,
6650 IN PROCESSINFOCLASS ProcessInformationClass,
6651 OUT PVOID ProcessInformation,
6652 IN ULONG ProcessInformationLength,
6653 OUT PULONG ReturnLength OPTIONAL
6654 );
6655#define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
6656#define ZwCurrentThread() NtCurrentThread()
6657
6658#ifndef _PO_DDK_
6659#define _PO_DDK_
6660
6661
6662
6663typedef enum _SYSTEM_POWER_STATE {
6664 PowerSystemUnspecified = 0,
6665 PowerSystemWorking = 1,
6666 PowerSystemSleeping1 = 2,
6667 PowerSystemSleeping2 = 3,
6668 PowerSystemSleeping3 = 4,
6669 PowerSystemHibernate = 5,
6670 PowerSystemShutdown = 6,
6671 PowerSystemMaximum = 7
6672} SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
6673
6674#define POWER_SYSTEM_MAXIMUM 7
6675
6676typedef enum {
6677 PowerActionNone = 0,
6678 PowerActionReserved,
6679 PowerActionSleep,
6680 PowerActionHibernate,
6681 PowerActionShutdown,
6682 PowerActionShutdownReset,
6683 PowerActionShutdownOff,
6684 PowerActionWarmEject
6685} POWER_ACTION, *PPOWER_ACTION;
6686
6687typedef enum _DEVICE_POWER_STATE {
6688 PowerDeviceUnspecified = 0,
6689 PowerDeviceD0,
6690 PowerDeviceD1,
6691 PowerDeviceD2,
6692 PowerDeviceD3,
6693 PowerDeviceMaximum
6694} DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
6695
6696
6697
6698typedef union _POWER_STATE {
6699 SYSTEM_POWER_STATE SystemState;
6700 DEVICE_POWER_STATE DeviceState;
6701} POWER_STATE, *PPOWER_STATE;
6702
6703typedef enum _POWER_STATE_TYPE {
6704 SystemPowerState = 0,
6705 DevicePowerState
6706} POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
6707
6708//
6709// Generic power related IOCTLs
6710//
6711
6712#define IOCTL_QUERY_DEVICE_POWER_STATE \
6713 CTL_CODE(FILE_DEVICE_BATTERY, 0x0, METHOD_BUFFERED, FILE_READ_ACCESS)
6714
6715#define IOCTL_SET_DEVICE_WAKE \
6716 CTL_CODE(FILE_DEVICE_BATTERY, 0x1, METHOD_BUFFERED, FILE_WRITE_ACCESS)
6717
6718#define IOCTL_CANCEL_DEVICE_WAKE \
6719 CTL_CODE(FILE_DEVICE_BATTERY, 0x2, METHOD_BUFFERED, FILE_WRITE_ACCESS)
6720
6721
6722//
6723// Defines for W32 interfaces
6724//
6725
6726
6727
6728#define ES_SYSTEM_REQUIRED ((ULONG)0x00000001)
6729#define ES_DISPLAY_REQUIRED ((ULONG)0x00000002)
6730#define ES_USER_PRESENT ((ULONG)0x00000004)
6731#define ES_CONTINUOUS ((ULONG)0x80000000)
6732
6733typedef ULONG EXECUTION_STATE;
6734
6735typedef enum {
6736 LT_DONT_CARE,
6737 LT_LOWEST_LATENCY
6738} LATENCY_TIME;
6739
6740
6741typedef enum {
6742 SystemPowerPolicyAc,
6743 SystemPowerPolicyDc,
6744 VerifySystemPolicyAc,
6745 VerifySystemPolicyDc,
6746 SystemPowerCapabilities,
6747 SystemBatteryState,
6748 SystemPowerStateHandler,
6749 ProcessorStateHandler,
6750 SystemPowerPolicyCurrent,
6751 AdministratorPowerPolicy,
6752 SystemReserveHiberFile,
6753 ProcessorInformation,
6754 SystemPowerInformation,
6755 ProcessorStateHandler2,
6756 LastWakeTime, // Compare with KeQueryInterruptTime()
6757 LastSleepTime, // Compare with KeQueryInterruptTime()
6758 SystemExecutionState,
6759 SystemPowerStateNotifyHandler,
6760 ProcessorPowerPolicyAc,
6761 ProcessorPowerPolicyDc,
6762 VerifyProcessorPowerPolicyAc,
6763 VerifyProcessorPowerPolicyDc,
6764 ProcessorPowerPolicyCurrent,
6765 SystemPowerStateLogging,
6766 SystemPowerLoggingEntry
6767} POWER_INFORMATION_LEVEL;
6768
6769
6770
6771//
6772// System power manager capabilities
6773//
6774
6775typedef struct {
6776 ULONG Granularity;
6777 ULONG Capacity;
6778} BATTERY_REPORTING_SCALE, *PBATTERY_REPORTING_SCALE;
6779
6780
6781
6782
6783#endif // !_PO_DDK_
6784
6785
6786#if defined(_X86_)
6787
6788//
6789// Types to use to contain PFNs and their counts.
6790//
6791
6792typedef ULONG PFN_COUNT;
6793
6794typedef LONG SPFN_NUMBER, *PSPFN_NUMBER;
6795typedef ULONG PFN_NUMBER, *PPFN_NUMBER;
6796
6797//
6798// Define maximum size of flush multiple TB request.
6799//
6800
6801#define FLUSH_MULTIPLE_MAXIMUM 32
6802
6803//
6804// Indicate that the i386 compiler supports the pragma textout construct.
6805//
6806
6807#define ALLOC_PRAGMA 1
6808//
6809// Indicate that the i386 compiler supports the DATA_SEG("INIT") and
6810// DATA_SEG("PAGE") pragmas
6811//
6812
6813#define ALLOC_DATA_PRAGMA 1
6814
6815#define NORMAL_DISPATCH_LENGTH 106
6816#define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
6817//
6818// Interrupt Request Level definitions
6819//
6820
6821#define PASSIVE_LEVEL 0 // Passive release level
6822#define LOW_LEVEL 0 // Lowest interrupt level
6823#define APC_LEVEL 1 // APC interrupt level
6824#define DISPATCH_LEVEL 2 // Dispatcher level
6825
6826#define PROFILE_LEVEL 27 // timer used for profiling.
6827#define CLOCK1_LEVEL 28 // Interval clock 1 level - Not used on x86
6828#define CLOCK2_LEVEL 28 // Interval clock 2 level
6829#define IPI_LEVEL 29 // Interprocessor interrupt level
6830#define POWER_LEVEL 30 // Power failure level
6831#define HIGH_LEVEL 31 // Highest interrupt level
6832
6833#define SYNCH_LEVEL (IPI_LEVEL-2)
6834
6835//
6836// I/O space read and write macros.
6837//
6838// These have to be actual functions on the 386, because we need
6839// to use assembler, but cannot return a value if we inline it.
6840//
6841// The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
6842// (Use x86 move instructions, with LOCK prefix to force correct behavior
6843// w.r.t. caches and write buffers.)
6844//
6845// The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
6846// (Use x86 in/out instructions.)
6847//
6848
6849NTKERNELAPI
6850UCHAR
6851NTAPI
6852READ_REGISTER_UCHAR(
6853 PUCHAR Register
6854 );
6855
6856NTKERNELAPI
6857USHORT
6858NTAPI
6859READ_REGISTER_USHORT(
6860 PUSHORT Register
6861 );
6862
6863NTKERNELAPI
6864ULONG
6865NTAPI
6866READ_REGISTER_ULONG(
6867 PULONG Register
6868 );
6869
6870NTKERNELAPI
6871VOID
6872NTAPI
6873READ_REGISTER_BUFFER_UCHAR(
6874 PUCHAR Register,
6875 PUCHAR Buffer,
6876 ULONG Count
6877 );
6878
6879NTKERNELAPI
6880VOID
6881NTAPI
6882READ_REGISTER_BUFFER_USHORT(
6883 PUSHORT Register,
6884 PUSHORT Buffer,
6885 ULONG Count
6886 );
6887
6888NTKERNELAPI
6889VOID
6890NTAPI
6891READ_REGISTER_BUFFER_ULONG(
6892 PULONG Register,
6893 PULONG Buffer,
6894 ULONG Count
6895 );
6896
6897
6898NTKERNELAPI
6899VOID
6900NTAPI
6901WRITE_REGISTER_UCHAR(
6902 PUCHAR Register,
6903 UCHAR Value
6904 );
6905
6906NTKERNELAPI
6907VOID
6908NTAPI
6909WRITE_REGISTER_USHORT(
6910 PUSHORT Register,
6911 USHORT Value
6912 );
6913
6914NTKERNELAPI
6915VOID
6916NTAPI
6917WRITE_REGISTER_ULONG(
6918 PULONG Register,
6919 ULONG Value
6920 );
6921
6922NTKERNELAPI
6923VOID
6924NTAPI
6925WRITE_REGISTER_BUFFER_UCHAR(
6926 PUCHAR Register,
6927 PUCHAR Buffer,
6928 ULONG Count
6929 );
6930
6931NTKERNELAPI
6932VOID
6933NTAPI
6934WRITE_REGISTER_BUFFER_USHORT(
6935 PUSHORT Register,
6936 PUSHORT Buffer,
6937 ULONG Count
6938 );
6939
6940NTKERNELAPI
6941VOID
6942NTAPI
6943WRITE_REGISTER_BUFFER_ULONG(
6944 PULONG Register,
6945 PULONG Buffer,
6946 ULONG Count
6947 );
6948
6949NTHALAPI
6950UCHAR
6951NTAPI
6952READ_PORT_UCHAR(
6953 PUCHAR Port
6954 );
6955
6956NTHALAPI
6957USHORT
6958NTAPI
6959READ_PORT_USHORT(
6960 PUSHORT Port
6961 );
6962
6963NTHALAPI
6964ULONG
6965NTAPI
6966READ_PORT_ULONG(
6967 PULONG Port
6968 );
6969
6970NTHALAPI
6971VOID
6972NTAPI
6973READ_PORT_BUFFER_UCHAR(
6974 PUCHAR Port,
6975 PUCHAR Buffer,
6976 ULONG Count
6977 );
6978
6979NTHALAPI
6980VOID
6981NTAPI
6982READ_PORT_BUFFER_USHORT(
6983 PUSHORT Port,
6984 PUSHORT Buffer,
6985 ULONG Count
6986 );
6987
6988NTHALAPI
6989VOID
6990NTAPI
6991READ_PORT_BUFFER_ULONG(
6992 PULONG Port,
6993 PULONG Buffer,
6994 ULONG Count
6995 );
6996
6997NTHALAPI
6998VOID
6999NTAPI
7000WRITE_PORT_UCHAR(
7001 PUCHAR Port,
7002 UCHAR Value
7003 );
7004
7005NTHALAPI
7006VOID
7007NTAPI
7008WRITE_PORT_USHORT(
7009 PUSHORT Port,
7010 USHORT Value
7011 );
7012
7013NTHALAPI
7014VOID
7015NTAPI
7016WRITE_PORT_ULONG(
7017 PULONG Port,
7018 ULONG Value
7019 );
7020
7021NTHALAPI
7022VOID
7023NTAPI
7024WRITE_PORT_BUFFER_UCHAR(
7025 PUCHAR Port,
7026 PUCHAR Buffer,
7027 ULONG Count
7028 );
7029
7030NTHALAPI
7031VOID
7032NTAPI
7033WRITE_PORT_BUFFER_USHORT(
7034 PUSHORT Port,
7035 PUSHORT Buffer,
7036 ULONG Count
7037 );
7038
7039NTHALAPI
7040VOID
7041NTAPI
7042WRITE_PORT_BUFFER_ULONG(
7043 PULONG Port,
7044 PULONG Buffer,
7045 ULONG Count
7046 );
7047
7048
7049//
7050// Get data cache fill size.
7051//
7052
7053#if PRAGMA_DEPRECATED_DDK
7054#pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
7055#endif
7056
7057#define KeGetDcacheFillSize() 1L
7058
7059
7060#define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
7061
7062
7063#define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
7064#define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
7065#define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
7066#define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
7067
7068
7069#if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
7070
7071
7072
7073#define KeQueryTickCount(CurrentCount ) { \
7074 volatile PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
7075 while (TRUE) { \
7076 (CurrentCount)->HighPart = _TickCount->High1Time; \
7077 (CurrentCount)->LowPart = _TickCount->LowPart; \
7078 if ((CurrentCount)->HighPart == _TickCount->High2Time) break; \
7079 _asm { rep nop } \
7080 } \
7081}
7082
7083
7084
7085#else
7086
7087
7088VOID
7089NTAPI
7090KeQueryTickCount (
7091 OUT PLARGE_INTEGER CurrentCount
7092 );
7093
7094#endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
7095
7096
7097//
7098// Processor Control Region Structure Definition
7099//
7100
7101#define PCR_MINOR_VERSION 1
7102#define PCR_MAJOR_VERSION 1
7103
7104typedef struct _KPCR {
7105
7106//
7107// Start of the architecturally defined section of the PCR. This section
7108// may be directly addressed by vendor/platform specific HAL code and will
7109// not change from version to version of NT.
7110//
7111// Certain fields in the TIB are not used in kernel mode. These include the
7112// stack limit, subsystem TIB, fiber data, arbitrary user pointer, and the
7113// self address of then PCR itself (another field has been added for that
7114// purpose). Therefore, these fields are overlaid with other data to get
7115// better cache locality.
7116//
7117
7118 union {
7119 NT_TIB NtTib;
7120 struct {
7121 struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
7122 PVOID Used_StackBase;
7123 PVOID PerfGlobalGroupMask;
7124 PVOID TssCopy;
7125 ULONG ContextSwitches;
7126 KAFFINITY SetMemberCopy;
7127 PVOID Used_Self;
7128 };
7129 };
7130
7131 struct _KPCR *SelfPcr; // flat address of this PCR
7132 struct _KPRCB *Prcb; // pointer to Prcb
7133 KIRQL Irql; // do not use 3 bytes after this as
7134 // HALs assume they are zero.
7135 ULONG IRR;
7136 ULONG IrrActive;
7137 ULONG IDR;
7138 PVOID KdVersionBlock;
7139
7140 struct _KIDTENTRY *IDT;
7141 struct _KGDTENTRY *GDT;
7142 struct _KTSS *TSS;
7143 USHORT MajorVersion;
7144 USHORT MinorVersion;
7145 KAFFINITY SetMember;
7146 ULONG StallScaleFactor;
7147 UCHAR SpareUnused;
7148 UCHAR Number;
7149
7150
7151} KPCR, *PKPCR;
7152
7153//
7154// The non-volatile 387 state
7155//
7156
7157typedef struct _KFLOATING_SAVE {
7158 ULONG ControlWord;
7159 ULONG StatusWord;
7160 ULONG ErrorOffset;
7161 ULONG ErrorSelector;
7162 ULONG DataOffset; // Not used in wdm
7163 ULONG DataSelector;
7164 ULONG Cr0NpxState;
7165 ULONG Spare1; // Not used in wdm
7166} KFLOATING_SAVE, *PKFLOATING_SAVE;
7167
7168//
7169// i386 Specific portions of mm component
7170//
7171
7172//
7173// Define the page size for the Intel 386 as 4096 (0x1000).
7174//
7175
7176#define PAGE_SIZE 0x1000
7177
7178//
7179// Define the number of trailing zeroes in a page aligned virtual address.
7180// This is used as the shift count when shifting virtual addresses to
7181// virtual page numbers.
7182//
7183
7184#define PAGE_SHIFT 12L
7185
7186
7187//
7188// Define the number of bits to shift to right justify the Page Directory Index
7189// field of a PTE.
7190//
7191
7192#define PDI_SHIFT_X86 22
7193#define PDI_SHIFT_X86PAE 21
7194
7195#if !defined (_X86PAE_)
7196#define PDI_SHIFT PDI_SHIFT_X86
7197#else
7198#define PDI_SHIFT PDI_SHIFT_X86PAE
7199#define PPI_SHIFT 30
7200#endif
7201
7202//
7203// Define the number of bits to shift to right justify the Page Table Index
7204// field of a PTE.
7205//
7206
7207#define PTI_SHIFT 12
7208
7209//
7210// Define the highest user address and user probe address.
7211//
7212
7213
7214extern PVOID *MmHighestUserAddress;
7215extern PVOID *MmSystemRangeStart;
7216extern ULONG *MmUserProbeAddress;
7217
7218#define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
7219#define MM_SYSTEM_RANGE_START *MmSystemRangeStart
7220#define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
7221
7222//
7223// The lowest user address reserves the low 64k.
7224//
7225
7226#define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
7227
7228//
7229// The lowest address for system space.
7230//
7231
7232#if !defined (_X86PAE_)
7233#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
7234#else
7235#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0C00000
7236#endif
7237
7238
7239
7240#define MmGetProcedureAddress(Address) (Address)
7241#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
7242
7243#define KIP0PCRADDRESS 0xffdff000
7244
7245#define KI_USER_SHARED_DATA 0xffdf0000
7246#define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
7247
7248//
7249// Result type definition for i386. (Machine specific enumerate type
7250// which is return type for portable exinterlockedincrement/decrement
7251// procedures.) In general, you should use the enumerated type defined
7252// in ex.h instead of directly referencing these constants.
7253//
7254
7255// Flags loaded into AH by LAHF instruction
7256
7257#define EFLAG_SIGN 0x8000
7258#define EFLAG_ZERO 0x4000
7259#define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
7260
7261#define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
7262#define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
7263#define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
7264
7265//
7266// Convert various portable ExInterlock APIs into their architectural
7267// equivalents.
7268//
7269
7270#if PRAGMA_DEPRECATED_DDK
7271#pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
7272#pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
7273#pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
7274#endif
7275
7276#define ExInterlockedIncrementLong(Addend,Lock) \
7277 Exfi386InterlockedIncrementLong(Addend)
7278
7279#define ExInterlockedDecrementLong(Addend,Lock) \
7280 Exfi386InterlockedDecrementLong(Addend)
7281
7282#define ExInterlockedExchangeUlong(Target,Value,Lock) \
7283 Exfi386InterlockedExchangeUlong(Target,Value)
7284
7285
7286
7287#define ExInterlockedAddUlong ExfInterlockedAddUlong
7288#define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
7289#define ExInterlockedInsertTailList ExfInterlockedInsertTailList
7290#define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
7291#define ExInterlockedPopEntryList ExfInterlockedPopEntryList
7292#define ExInterlockedPushEntryList ExfInterlockedPushEntryList
7293
7294
7295
7296//
7297// Prototypes for architectural specific versions of Exi386 Api
7298//
7299
7300//
7301// Interlocked result type is portable, but its values are machine specific.
7302// Constants for value are in i386.h, mips.h, etc.
7303//
7304
7305typedef enum _INTERLOCKED_RESULT {
7306 ResultNegative = RESULT_NEGATIVE,
7307 ResultZero = RESULT_ZERO,
7308 ResultPositive = RESULT_POSITIVE
7309} INTERLOCKED_RESULT;
7310
7311NTKERNELAPI
7312INTERLOCKED_RESULT
7313FASTCALL
7314Exfi386InterlockedIncrementLong (
7315 IN PLONG Addend
7316 );
7317
7318NTKERNELAPI
7319INTERLOCKED_RESULT
7320FASTCALL
7321Exfi386InterlockedDecrementLong (
7322 IN PLONG Addend
7323 );
7324
7325NTKERNELAPI
7326ULONG
7327FASTCALL
7328Exfi386InterlockedExchangeUlong (
7329 IN PULONG Target,
7330 IN ULONG Value
7331 );
7332
7333#if !defined(_WINBASE_) && !defined(NONTOSPINTERLOCK)
7334#if !defined(MIDL_PASS) // wdm
7335#if defined(NO_INTERLOCKED_INTRINSICS) || defined(_CROSS_PLATFORM_)
7336
7337
7338NTKERNELAPI
7339LONG
7340FASTCALL
7341InterlockedIncrement(
7342 IN LONG volatile *Addend
7343 );
7344
7345NTKERNELAPI
7346LONG
7347FASTCALL
7348InterlockedDecrement(
7349 IN LONG volatile *Addend
7350 );
7351
7352NTKERNELAPI
7353LONG
7354FASTCALL
7355InterlockedExchange(
7356 IN OUT LONG volatile *Target,
7357 IN LONG Value
7358 );
7359
7360#define InterlockedExchangePointer(Target, Value) \
7361 (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
7362
7363LONG
7364FASTCALL
7365InterlockedExchangeAdd(
7366 IN OUT LONG volatile *Addend,
7367 IN LONG Increment
7368 );
7369
7370NTKERNELAPI
7371LONG
7372FASTCALL
7373InterlockedCompareExchange(
7374 IN OUT LONG volatile *Destination,
7375 IN LONG ExChange,
7376 IN LONG Comperand
7377 );
7378
7379#define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
7380 (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
7381
7382#define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
7383 ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
7384
7385NTKERNELAPI
7386LONGLONG
7387FASTCALL
7388ExfInterlockedCompareExchange64(
7389 IN OUT LONGLONG volatile *Destination,
7390 IN PLONGLONG ExChange,
7391 IN PLONGLONG Comperand
7392 );
7393
7394
7395
7396#else // NO_INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
7397
7398#define InterlockedExchangePointer(Target, Value) \
7399 (PVOID)InterlockedExchange((PLONG)Target, (LONG)Value)
7400
7401
7402#if (_MSC_FULL_VER > 13009037)
7403LONG
7404__cdecl
7405_InterlockedExchange(
7406 IN OUT LONG volatile *Target,
7407 IN LONG Value
7408 );
7409
7410#pragma intrinsic (_InterlockedExchange)
7411#define InterlockedExchange _InterlockedExchange
7412#else
7413FORCEINLINE
7414LONG
7415FASTCALL
7416InterlockedExchange(
7417 IN OUT LONG volatile *Target,
7418 IN LONG Value
7419 )
7420{
7421 __asm {
7422 mov eax, Value
7423 mov ecx, Target
7424 xchg [ecx], eax
7425 }
7426}
7427#endif
7428
7429#if (_MSC_FULL_VER > 13009037)
7430LONG
7431__cdecl
7432_InterlockedIncrement(
7433 IN LONG volatile *Addend
7434 );
7435
7436#pragma intrinsic (_InterlockedIncrement)
7437#define InterlockedIncrement _InterlockedIncrement
7438#else
7439#define InterlockedIncrement(Addend) (InterlockedExchangeAdd (Addend, 1)+1)
7440#endif
7441
7442#if (_MSC_FULL_VER > 13009037)
7443LONG
7444__cdecl
7445_InterlockedDecrement(
7446 IN LONG volatile *Addend
7447 );
7448
7449#pragma intrinsic (_InterlockedDecrement)
7450#define InterlockedDecrement _InterlockedDecrement
7451#else
7452#define InterlockedDecrement(Addend) (InterlockedExchangeAdd (Addend, -1)-1)
7453#endif
7454
7455#if (_MSC_FULL_VER > 13009037)
7456LONG
7457__cdecl
7458_InterlockedExchangeAdd(
7459 IN OUT LONG volatile *Addend,
7460 IN LONG Increment
7461 );
7462
7463#pragma intrinsic (_InterlockedExchangeAdd)
7464#define InterlockedExchangeAdd _InterlockedExchangeAdd
7465#else
7466
7467FORCEINLINE
7468LONG
7469FASTCALL
7470InterlockedExchangeAdd(
7471 IN OUT LONG volatile *Addend,
7472 IN LONG Increment
7473 )
7474{
7475 __asm {
7476 mov eax, Increment
7477 mov ecx, Addend
7478 lock xadd [ecx], eax
7479 }
7480}
7481
7482#endif
7483
7484#if (_MSC_FULL_VER > 13009037)
7485LONG
7486__cdecl
7487_InterlockedCompareExchange (
7488 IN OUT LONG volatile *Destination,
7489 IN LONG ExChange,
7490 IN LONG Comperand
7491 );
7492
7493#pragma intrinsic (_InterlockedCompareExchange)
7494#define InterlockedCompareExchange (LONG)_InterlockedCompareExchange
7495#else
7496FORCEINLINE
7497LONG
7498FASTCALL
7499InterlockedCompareExchange(
7500 IN OUT LONG volatile *Destination,
7501 IN LONG Exchange,
7502 IN LONG Comperand
7503 )
7504{
7505 __asm {
7506 mov eax, Comperand
7507 mov ecx, Destination
7508 mov edx, Exchange
7509 lock cmpxchg [ecx], edx
7510 }
7511}
7512#endif
7513
7514#define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
7515 (PVOID)InterlockedCompareExchange((PLONG)Destination, (LONG)ExChange, (LONG)Comperand)
7516
7517#define InterlockedCompareExchange64(Destination, ExChange, Comperand) \
7518 ExfInterlockedCompareExchange64(Destination, &(ExChange), &(Comperand))
7519
7520NTKERNELAPI
7521LONGLONG
7522FASTCALL
7523ExfInterlockedCompareExchange64(
7524 IN OUT LONGLONG volatile *Destination,
7525 IN PLONGLONG ExChange,
7526 IN PLONGLONG Comperand
7527 );
7528
7529#endif // INTERLOCKED_INTRINSICS || _CROSS_PLATFORM_
7530
7531#endif // MIDL_PASS
7532
7533#define InterlockedIncrementAcquire InterlockedIncrement
7534#define InterlockedIncrementRelease InterlockedIncrement
7535#define InterlockedDecrementAcquire InterlockedDecrement
7536#define InterlockedDecrementRelease InterlockedDecrement
7537#define InterlockedExchangeAcquire64 InterlockedExchange64
7538#define InterlockedCompareExchangeAcquire InterlockedCompareExchange
7539#define InterlockedCompareExchangeRelease InterlockedCompareExchange
7540#define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
7541#define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
7542
7543#endif // __WINBASE__ && !NONTOSPINTERLOCK
7544
7545//
7546// Turn these instrinsics off until the compiler can handle them
7547//
7548#if (_MSC_FULL_VER > 13009037)
7549
7550LONG
7551_InterlockedOr (
7552 IN OUT LONG volatile *Target,
7553 IN LONG Set
7554 );
7555
7556#pragma intrinsic (_InterlockedOr)
7557
7558#define InterlockedOr _InterlockedOr
7559
7560LONG
7561_InterlockedAnd (
7562 IN OUT LONG volatile *Target,
7563 IN LONG Set
7564 );
7565
7566#pragma intrinsic (_InterlockedAnd)
7567
7568#define InterlockedAnd _InterlockedAnd
7569
7570LONG
7571_InterlockedXor (
7572 IN OUT LONG volatile *Target,
7573 IN LONG Set
7574 );
7575
7576#pragma intrinsic (_InterlockedXor)
7577
7578#define InterlockedXor _InterlockedXor
7579
7580#else // compiler version
7581
7582FORCEINLINE
7583LONG
7584InterlockedAnd (
7585 IN OUT LONG volatile *Target,
7586 LONG Set
7587 )
7588{
7589 LONG i;
7590 LONG j;
7591
7592 j = *Target;
7593 do {
7594 i = j;
7595 j = InterlockedCompareExchange(Target,
7596 i & Set,
7597 i);
7598
7599 } while (i != j);
7600
7601 return j;
7602}
7603
7604FORCEINLINE
7605LONG
7606InterlockedOr (
7607 IN OUT LONG volatile *Target,
7608 IN LONG Set
7609 )
7610{
7611 LONG i;
7612 LONG j;
7613
7614 j = *Target;
7615 do {
7616 i = j;
7617 j = InterlockedCompareExchange(Target,
7618 i | Set,
7619 i);
7620
7621 } while (i != j);
7622
7623 return j;
7624}
7625
7626#endif // compiler version
7627
7628
7629
7630#if !defined(MIDL_PASS) && defined(_M_IX86)
7631
7632//
7633// i386 function definitions
7634//
7635
7636
7637
7638#if _MSC_VER >= 1200
7639#pragma warning(push)
7640#endif
7641#pragma warning(disable:4035) // re-enable below
7642
7643 #define _PCR fs:[0]
7644
7645//
7646// Get current IRQL.
7647//
7648// On x86 this function resides in the HAL
7649//
7650
7651
7652NTHALAPI
7653KIRQL
7654NTAPI
7655KeGetCurrentIrql();
7656
7657
7658
7659//
7660// Get the current processor number
7661//
7662
7663FORCEINLINE
7664ULONG
7665NTAPI
7666KeGetCurrentProcessorNumber(VOID)
7667{
7668#if (_MSC_FULL_VER >= 13012035)
7669 return (ULONG) __readfsbyte (FIELD_OFFSET (KPCR, Number));
7670#else
7671 __asm { movzx eax, _PCR KPCR.Number }
7672#endif
7673}
7674
7675
7676#if _MSC_VER >= 1200
7677#pragma warning(pop)
7678#else
7679#pragma warning(default:4035)
7680#endif
7681
7682
7683#endif // !defined(MIDL_PASS) && defined(_M_IX86)
7684
7685
7686//++
7687//
7688// VOID
7689// KeMemoryBarrier (
7690// VOID
7691// )
7692//
7693// VOID
7694// KeMemoryBarrierWithoutFence (
7695// VOID
7696// )
7697//
7698//
7699// Routine Description:
7700//
7701// These functions order memory accesses as seen by other processors.
7702//
7703// Arguments:
7704//
7705// None.
7706//
7707// Return Value:
7708//
7709// None.
7710//
7711//--
7712
7713#ifdef __cplusplus
7714extern "C" {
7715#endif
7716
7717VOID
7718_ReadWriteBarrier(
7719 VOID
7720 );
7721
7722#ifdef __cplusplus
7723}
7724#endif
7725
7726#pragma intrinsic (_ReadWriteBarrier)
7727
7728
7729FORCEINLINE
7730VOID
7731KeMemoryBarrier (
7732 VOID
7733 )
7734{
7735 LONG Barrier;
7736 __asm {
7737 xchg Barrier, eax
7738 }
7739}
7740
7741#define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
7742
7743
7744NTKERNELAPI
7745NTSTATUS
7746NTAPI
7747KeSaveFloatingPointState (
7748 OUT PKFLOATING_SAVE FloatSave
7749 );
7750
7751NTKERNELAPI
7752NTSTATUS
7753NTAPI
7754KeRestoreFloatingPointState (
7755 IN PKFLOATING_SAVE FloatSave
7756 );
7757
7758
7759#endif // defined(_X86_)
7760
7761
7762// Use the following for kernel mode runtime checks of X86 system architecture
7763
7764#ifdef _X86_
7765
7766#ifdef IsNEC_98
7767#undef IsNEC_98
7768#endif
7769
7770#ifdef IsNotNEC_98
7771#undef IsNotNEC_98
7772#endif
7773
7774#ifdef SetNEC_98
7775#undef SetNEC_98
7776#endif
7777
7778#ifdef SetNotNEC_98
7779#undef SetNotNEC_98
7780#endif
7781
7782#define IsNEC_98 (SharedUserData->AlternativeArchitecture == NEC98x86)
7783#define IsNotNEC_98 (SharedUserData->AlternativeArchitecture != NEC98x86)
7784#define SetNEC_98 SharedUserData->AlternativeArchitecture = NEC98x86
7785#define SetNotNEC_98 SharedUserData->AlternativeArchitecture = StandardDesign
7786
7787#endif
7788
7789
7790#if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
7791
7792//
7793// Define intrinsic function to do in's and out's.
7794//
7795
7796#ifdef __cplusplus
7797extern "C" {
7798#endif
7799
7800UCHAR
7801__inbyte (
7802 IN USHORT Port
7803 );
7804
7805USHORT
7806__inword (
7807 IN USHORT Port
7808 );
7809
7810ULONG
7811__indword (
7812 IN USHORT Port
7813 );
7814
7815VOID
7816__outbyte (
7817 IN USHORT Port,
7818 IN UCHAR Data
7819 );
7820
7821VOID
7822__outword (
7823 IN USHORT Port,
7824 IN USHORT Data
7825 );
7826
7827VOID
7828__outdword (
7829 IN USHORT Port,
7830 IN ULONG Data
7831 );
7832
7833VOID
7834__inbytestring (
7835 IN USHORT Port,
7836 IN PUCHAR Buffer,
7837 IN ULONG Count
7838 );
7839
7840VOID
7841__inwordstring (
7842 IN USHORT Port,
7843 IN PUSHORT Buffer,
7844 IN ULONG Count
7845 );
7846
7847VOID
7848__indwordstring (
7849 IN USHORT Port,
7850 IN PULONG Buffer,
7851 IN ULONG Count
7852 );
7853
7854VOID
7855__outbytestring (
7856 IN USHORT Port,
7857 IN PUCHAR Buffer,
7858 IN ULONG Count
7859 );
7860
7861VOID
7862__outwordstring (
7863 IN USHORT Port,
7864 IN PUSHORT Buffer,
7865 IN ULONG Count
7866 );
7867
7868VOID
7869__outdwordstring (
7870 IN USHORT Port,
7871 IN PULONG Buffer,
7872 IN ULONG Count
7873 );
7874
7875#ifdef __cplusplus
7876}
7877#endif
7878
7879#pragma intrinsic(__inbyte)
7880#pragma intrinsic(__inword)
7881#pragma intrinsic(__indword)
7882#pragma intrinsic(__outbyte)
7883#pragma intrinsic(__outword)
7884#pragma intrinsic(__outdword)
7885#pragma intrinsic(__inbytestring)
7886#pragma intrinsic(__inwordstring)
7887#pragma intrinsic(__indwordstring)
7888#pragma intrinsic(__outbytestring)
7889#pragma intrinsic(__outwordstring)
7890#pragma intrinsic(__outdwordstring)
7891
7892//
7893// Interlocked intrinsic functions.
7894//
7895
7896#define InterlockedAnd _InterlockedAnd
7897#define InterlockedOr _InterlockedOr
7898#define InterlockedXor _InterlockedXor
7899#define InterlockedIncrement _InterlockedIncrement
7900#define InterlockedIncrementAcquire InterlockedIncrement
7901#define InterlockedIncrementRelease InterlockedIncrement
7902#define InterlockedDecrement _InterlockedDecrement
7903#define InterlockedDecrementAcquire InterlockedDecrement
7904#define InterlockedDecrementRelease InterlockedDecrement
7905#define InterlockedAdd _InterlockedAdd
7906#define InterlockedExchange _InterlockedExchange
7907#define InterlockedExchangeAdd _InterlockedExchangeAdd
7908#define InterlockedCompareExchange _InterlockedCompareExchange
7909#define InterlockedCompareExchangeAcquire InterlockedCompareExchange
7910#define InterlockedCompareExchangeRelease InterlockedCompareExchange
7911
7912#define InterlockedAnd64 _InterlockedAnd64
7913#define InterlockedOr64 _InterlockedOr64
7914#define InterlockedXor64 _InterlockedXor64
7915#define InterlockedIncrement64 _InterlockedIncrement64
7916#define InterlockedDecrement64 _InterlockedDecrement64
7917#define InterlockedAdd64 _InterlockedAdd64
7918#define InterlockedExchange64 _InterlockedExchange64
7919#define InterlockedExchangeAcquire64 InterlockedExchange64
7920#define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
7921#define InterlockedCompareExchange64 _InterlockedCompareExchange64
7922#define InterlockedCompareExchangeAcquire64 InterlockedCompareExchange64
7923#define InterlockedCompareExchangeRelease64 InterlockedCompareExchange64
7924
7925#define InterlockedExchangePointer _InterlockedExchangePointer
7926#define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
7927
7928#ifdef __cplusplus
7929extern "C" {
7930#endif
7931
7932LONG
7933InterlockedAnd (
7934 IN OUT LONG volatile *Destination,
7935 IN LONG Value
7936 );
7937
7938LONG
7939InterlockedOr (
7940 IN OUT LONG volatile *Destination,
7941 IN LONG Value
7942 );
7943
7944LONG
7945InterlockedXor (
7946 IN OUT LONG volatile *Destination,
7947 IN LONG Value
7948 );
7949
7950LONG64
7951InterlockedAnd64 (
7952 IN OUT LONG64 volatile *Destination,
7953 IN LONG64 Value
7954 );
7955
7956LONG64
7957InterlockedOr64 (
7958 IN OUT LONG64 volatile *Destination,
7959 IN LONG64 Value
7960 );
7961
7962LONG64
7963InterlockedXor64 (
7964 IN OUT LONG64 volatile *Destination,
7965 IN LONG64 Value
7966 );
7967
7968LONG
7969InterlockedIncrement(
7970 IN OUT LONG volatile *Addend
7971 );
7972
7973LONG
7974InterlockedDecrement(
7975 IN OUT LONG volatile *Addend
7976 );
7977
7978LONG
7979InterlockedExchange(
7980 IN OUT LONG volatile *Target,
7981 IN LONG Value
7982 );
7983
7984LONG
7985InterlockedExchangeAdd(
7986 IN OUT LONG volatile *Addend,
7987 IN LONG Value
7988 );
7989
7990#if !defined(_X86AMD64_)
7991
7992__forceinline
7993LONG
7994InterlockedAdd(
7995 IN OUT LONG volatile *Addend,
7996 IN LONG Value
7997 )
7998
7999{
8000 return InterlockedExchangeAdd(Addend, Value) + Value;
8001}
8002
8003#endif
8004
8005LONG
8006InterlockedCompareExchange (
8007 IN OUT LONG volatile *Destination,
8008 IN LONG ExChange,
8009 IN LONG Comperand
8010 );
8011
8012LONG64
8013InterlockedIncrement64(
8014 IN OUT LONG64 volatile *Addend
8015 );
8016
8017LONG64
8018InterlockedDecrement64(
8019 IN OUT LONG64 volatile *Addend
8020 );
8021
8022LONG64
8023InterlockedExchange64(
8024 IN OUT LONG64 volatile *Target,
8025 IN LONG64 Value
8026 );
8027
8028LONG64
8029InterlockedExchangeAdd64(
8030 IN OUT LONG64 volatile *Addend,
8031 IN LONG64 Value
8032 );
8033
8034#if !defined(_X86AMD64_)
8035
8036__forceinline
8037LONG64
8038InterlockedAdd64(
8039 IN OUT LONG64 volatile *Addend,
8040 IN LONG64 Value
8041 )
8042
8043{
8044 return InterlockedExchangeAdd64(Addend, Value) + Value;
8045}
8046
8047#endif
8048
8049LONG64
8050InterlockedCompareExchange64 (
8051 IN OUT LONG64 volatile *Destination,
8052 IN LONG64 ExChange,
8053 IN LONG64 Comperand
8054 );
8055
8056PVOID
8057InterlockedCompareExchangePointer (
8058 IN OUT PVOID volatile *Destination,
8059 IN PVOID Exchange,
8060 IN PVOID Comperand
8061 );
8062
8063PVOID
8064InterlockedExchangePointer(
8065 IN OUT PVOID volatile *Target,
8066 IN PVOID Value
8067 );
8068
8069#pragma intrinsic(_InterlockedAnd)
8070#pragma intrinsic(_InterlockedOr)
8071#pragma intrinsic(_InterlockedXor)
8072#pragma intrinsic(_InterlockedIncrement)
8073#pragma intrinsic(_InterlockedDecrement)
8074#pragma intrinsic(_InterlockedExchange)
8075#pragma intrinsic(_InterlockedExchangeAdd)
8076#pragma intrinsic(_InterlockedCompareExchange)
8077#pragma intrinsic(_InterlockedAnd64)
8078#pragma intrinsic(_InterlockedOr64)
8079#pragma intrinsic(_InterlockedXor64)
8080#pragma intrinsic(_InterlockedIncrement64)
8081#pragma intrinsic(_InterlockedDecrement64)
8082#pragma intrinsic(_InterlockedExchange64)
8083#pragma intrinsic(_InterlockedExchangeAdd64)
8084#pragma intrinsic(_InterlockedCompareExchange64)
8085#pragma intrinsic(_InterlockedExchangePointer)
8086#pragma intrinsic(_InterlockedCompareExchangePointer)
8087
8088#ifdef __cplusplus
8089}
8090#endif
8091
8092#endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
8093
8094#if defined(_AMD64_)
8095
8096//
8097// Types to use to contain PFNs and their counts.
8098//
8099
8100typedef ULONG PFN_COUNT;
8101
8102typedef LONG64 SPFN_NUMBER, *PSPFN_NUMBER;
8103typedef ULONG64 PFN_NUMBER, *PPFN_NUMBER;
8104
8105//
8106// Define maximum size of flush multiple TB request.
8107//
8108
8109#define FLUSH_MULTIPLE_MAXIMUM 32
8110
8111//
8112// Indicate that the AMD64 compiler supports the allocate pragmas.
8113//
8114
8115#define ALLOC_PRAGMA 1
8116#define ALLOC_DATA_PRAGMA 1
8117
8118#define NORMAL_DISPATCH_LENGTH 106
8119#define DISPATCH_LENGTH NORMAL_DISPATCH_LENGTH
8120
8121//
8122// Interrupt Request Level definitions
8123//
8124
8125#define PASSIVE_LEVEL 0 // Passive release level
8126#define LOW_LEVEL 0 // Lowest interrupt level
8127#define APC_LEVEL 1 // APC interrupt level
8128#define DISPATCH_LEVEL 2 // Dispatcher level
8129
8130#define CLOCK_LEVEL 13 // Interval clock level
8131#define IPI_LEVEL 14 // Interprocessor interrupt level
8132#define POWER_LEVEL 14 // Power failure level
8133#define PROFILE_LEVEL 15 // timer used for profiling.
8134#define HIGH_LEVEL 15 // Highest interrupt level
8135
8136#define SYNCH_LEVEL (IPI_LEVEL-2)
8137
8138//
8139// I/O space read and write macros.
8140//
8141// The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space.
8142//
8143// The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space.
8144//
8145
8146__forceinline
8147UCHAR
8148READ_REGISTER_UCHAR (
8149 volatile UCHAR *Register
8150 )
8151{
8152 return *Register;
8153}
8154
8155__forceinline
8156USHORT
8157READ_REGISTER_USHORT (
8158 volatile USHORT *Register
8159 )
8160{
8161 return *Register;
8162}
8163
8164__forceinline
8165ULONG
8166READ_REGISTER_ULONG (
8167 volatile ULONG *Register
8168 )
8169{
8170 return *Register;
8171}
8172
8173__forceinline
8174VOID
8175READ_REGISTER_BUFFER_UCHAR (
8176 PUCHAR Register,
8177 PUCHAR Buffer,
8178 ULONG Count
8179 )
8180{
8181 __movsb(Buffer, Register, Count);
8182 return;
8183}
8184
8185__forceinline
8186VOID
8187READ_REGISTER_BUFFER_USHORT (
8188 PUSHORT Register,
8189 PUSHORT Buffer,
8190 ULONG Count
8191 )
8192{
8193 __movsw(Buffer, Register, Count);
8194 return;
8195}
8196
8197__forceinline
8198VOID
8199READ_REGISTER_BUFFER_ULONG (
8200 PULONG Register,
8201 PULONG Buffer,
8202 ULONG Count
8203 )
8204{
8205 __movsd(Buffer, Register, Count);
8206 return;
8207}
8208
8209__forceinline
8210VOID
8211WRITE_REGISTER_UCHAR (
8212 PUCHAR Register,
8213 UCHAR Value
8214 )
8215{
8216
8217 *Register = Value;
8218 StoreFence();
8219 return;
8220}
8221
8222__forceinline
8223VOID
8224WRITE_REGISTER_USHORT (
8225 PUSHORT Register,
8226 USHORT Value
8227 )
8228{
8229
8230 *Register = Value;
8231 StoreFence();
8232 return;
8233}
8234
8235__forceinline
8236VOID
8237WRITE_REGISTER_ULONG (
8238 PULONG Register,
8239 ULONG Value
8240 )
8241{
8242
8243 *Register = Value;
8244 StoreFence();
8245 return;
8246}
8247
8248__forceinline
8249VOID
8250WRITE_REGISTER_BUFFER_UCHAR (
8251 PUCHAR Register,
8252 PUCHAR Buffer,
8253 ULONG Count
8254 )
8255{
8256
8257 __movsb(Register, Buffer, Count);
8258 StoreFence();
8259 return;
8260}
8261
8262__forceinline
8263VOID
8264WRITE_REGISTER_BUFFER_USHORT (
8265 PUSHORT Register,
8266 PUSHORT Buffer,
8267 ULONG Count
8268 )
8269{
8270
8271 __movsw(Register, Buffer, Count);
8272 StoreFence();
8273 return;
8274}
8275
8276__forceinline
8277VOID
8278WRITE_REGISTER_BUFFER_ULONG (
8279 PULONG Register,
8280 PULONG Buffer,
8281 ULONG Count
8282 )
8283{
8284
8285 __movsd(Register, Buffer, Count);
8286 StoreFence();
8287 return;
8288}
8289
8290__forceinline
8291UCHAR
8292READ_PORT_UCHAR (
8293 PUCHAR Port
8294 )
8295
8296{
8297 return __inbyte((USHORT)((ULONG64)Port));
8298}
8299
8300__forceinline
8301USHORT
8302READ_PORT_USHORT (
8303 PUSHORT Port
8304 )
8305
8306{
8307 return __inword((USHORT)((ULONG64)Port));
8308}
8309
8310__forceinline
8311ULONG
8312READ_PORT_ULONG (
8313 PULONG Port
8314 )
8315
8316{
8317 return __indword((USHORT)((ULONG64)Port));
8318}
8319
8320
8321__forceinline
8322VOID
8323READ_PORT_BUFFER_UCHAR (
8324 PUCHAR Port,
8325 PUCHAR Buffer,
8326 ULONG Count
8327 )
8328
8329{
8330 __inbytestring((USHORT)((ULONG64)Port), Buffer, Count);
8331 return;
8332}
8333
8334__forceinline
8335VOID
8336READ_PORT_BUFFER_USHORT (
8337 PUSHORT Port,
8338 PUSHORT Buffer,
8339 ULONG Count
8340 )
8341
8342{
8343 __inwordstring((USHORT)((ULONG64)Port), Buffer, Count);
8344 return;
8345}
8346
8347__forceinline
8348VOID
8349READ_PORT_BUFFER_ULONG (
8350 PULONG Port,
8351 PULONG Buffer,
8352 ULONG Count
8353 )
8354
8355{
8356 __indwordstring((USHORT)((ULONG64)Port), Buffer, Count);
8357 return;
8358}
8359
8360__forceinline
8361VOID
8362WRITE_PORT_UCHAR (
8363 PUCHAR Port,
8364 UCHAR Value
8365 )
8366
8367{
8368 __outbyte((USHORT)((ULONG64)Port), Value);
8369 return;
8370}
8371
8372__forceinline
8373VOID
8374WRITE_PORT_USHORT (
8375 PUSHORT Port,
8376 USHORT Value
8377 )
8378
8379{
8380 __outword((USHORT)((ULONG64)Port), Value);
8381 return;
8382}
8383
8384__forceinline
8385VOID
8386WRITE_PORT_ULONG (
8387 PULONG Port,
8388 ULONG Value
8389 )
8390
8391{
8392 __outdword((USHORT)((ULONG64)Port), Value);
8393 return;
8394}
8395
8396__forceinline
8397VOID
8398WRITE_PORT_BUFFER_UCHAR (
8399 PUCHAR Port,
8400 PUCHAR Buffer,
8401 ULONG Count
8402 )
8403
8404{
8405 __outbytestring((USHORT)((ULONG64)Port), Buffer, Count);
8406 return;
8407}
8408
8409__forceinline
8410VOID
8411WRITE_PORT_BUFFER_USHORT (
8412 PUSHORT Port,
8413 PUSHORT Buffer,
8414 ULONG Count
8415 )
8416
8417{
8418 __outwordstring((USHORT)((ULONG64)Port), Buffer, Count);
8419 return;
8420}
8421
8422__forceinline
8423VOID
8424WRITE_PORT_BUFFER_ULONG (
8425 PULONG Port,
8426 PULONG Buffer,
8427 ULONG Count
8428 )
8429
8430{
8431 __outdwordstring((USHORT)((ULONG64)Port), Buffer, Count);
8432 return;
8433}
8434
8435
8436//
8437// Get data cache fill size.
8438//
8439
8440#if PRAGMA_DEPRECATED_DDK
8441#pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
8442#endif
8443
8444#define KeGetDcacheFillSize() 1L
8445
8446
8447#define KeFlushIoBuffers(Mdl, ReadOperation, DmaOperation)
8448
8449
8450#define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
8451#define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
8452#define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
8453#define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
8454
8455
8456#define KI_USER_SHARED_DATA 0xFFFFF78000000000UI64
8457
8458#define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
8459
8460#define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
8461#define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
8462#define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
8463
8464#define KeQueryInterruptTime() *((volatile ULONG64 *)(SharedInterruptTime))
8465
8466#define KeQuerySystemTime(CurrentCount) \
8467 *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedSystemTime))
8468
8469#define KeQueryTickCount(CurrentCount) \
8470 *((PULONG64)(CurrentCount)) = *((volatile ULONG64 *)(SharedTickCount))
8471
8472
8473//
8474// Processor Control Region Structure Definition
8475//
8476
8477#define PCR_MINOR_VERSION 1
8478#define PCR_MAJOR_VERSION 1
8479
8480typedef struct _KPCR {
8481
8482//
8483// Start of the architecturally defined section of the PCR. This section
8484// may be directly addressed by vendor/platform specific HAL code and will
8485// not change from version to version of NT.
8486//
8487// Certain fields in the TIB are not used in kernel mode. These include the
8488// exception list, stack base, stack limit, subsystem TIB, fiber data, and
8489// the arbitrary user pointer. Therefore, these fields are overlaid with
8490// other data to get better cache locality.
8491
8492 union {
8493 NT_TIB NtTib;
8494 struct {
8495 union _KGDTENTRY64 *GdtBase;
8496 struct _KTSS64 *TssBase;
8497 PVOID PerfGlobalGroupMask;
8498 struct _KPCR *Self;
8499 ULONG ContextSwitches;
8500 ULONG NotUsed;
8501 KAFFINITY SetMember;
8502 PVOID Used_Self;
8503 };
8504 };
8505
8506 struct _KPRCB *CurrentPrcb;
8507 ULONG64 SavedRcx;
8508 ULONG64 SavedR11;
8509 KIRQL Irql;
8510 UCHAR SecondLevelCacheAssociativity;
8511 UCHAR Number;
8512 UCHAR Fill0;
8513 ULONG Irr;
8514 ULONG IrrActive;
8515 ULONG Idr;
8516 USHORT MajorVersion;
8517 USHORT MinorVersion;
8518 ULONG StallScaleFactor;
8519 union _KIDTENTRY64 *IdtBase;
8520 PVOID Unused1;
8521 PVOID Unused2;
8522
8523
8524} KPCR, *PKPCR;
8525
8526//
8527// Exception frame
8528//
8529// This frame is established when handling an exception. It provides a place
8530// to save all nonvolatile registers. The volatile registers will already
8531// have been saved in a trap frame.
8532//
8533// N.B. The exception frame has a built in exception record capable of
8534// storing information for four parameter values. This exception
8535// record is used exclusively within the trap handling code.
8536//
8537
8538#define EXCEPTION_AREA_SIZE 64
8539
8540typedef struct _KEXCEPTION_FRAME {
8541
8542//
8543// Home address for the parameter registers.
8544//
8545
8546 ULONG64 P1Home;
8547 ULONG64 P2Home;
8548 ULONG64 P3Home;
8549 ULONG64 P4Home;
8550 ULONG64 P5;
8551
8552//
8553// Kernel callout initial stack value.
8554//
8555
8556 ULONG64 InitialStack;
8557
8558//
8559// Saved nonvolatile floating registers.
8560//
8561
8562 M128 Xmm6;
8563 M128 Xmm7;
8564 M128 Xmm8;
8565 M128 Xmm9;
8566 M128 Xmm10;
8567 M128 Xmm11;
8568 M128 Xmm12;
8569 M128 Xmm13;
8570 M128 Xmm14;
8571 M128 Xmm15;
8572
8573//
8574// Kernel callout frame variables.
8575//
8576
8577 ULONG64 TrapFrame;
8578 ULONG64 CallbackStack;
8579 ULONG64 OutputBuffer;
8580 ULONG64 OutputLength;
8581
8582//
8583// Exception record for exceptions.
8584//
8585
8586 UCHAR ExceptionRecord[EXCEPTION_AREA_SIZE];
8587
8588//
8589// Saved nonvolatile register - not always saved.
8590//
8591
8592 ULONG64 Fill1;
8593 ULONG64 Rbp;
8594
8595//
8596// Saved nonvolatile registers.
8597//
8598
8599 ULONG64 Rbx;
8600 ULONG64 Rdi;
8601 ULONG64 Rsi;
8602 ULONG64 R12;
8603 ULONG64 R13;
8604 ULONG64 R14;
8605 ULONG64 R15;
8606
8607//
8608// EFLAGS and return address.
8609//
8610
8611 ULONG64 Return;
8612} KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
8613
8614//
8615// Trap frame
8616//
8617// This frame is established when handling a trap. It provides a place to
8618// save all volatile registers. The nonvolatile registers are saved in an
8619// exception frame or through the normal C calling conventions for saved
8620// registers.
8621//
8622
8623typedef struct _KTRAP_FRAME {
8624
8625//
8626// Home address for the parameter registers.
8627//
8628
8629 ULONG64 P1Home;
8630 ULONG64 P2Home;
8631 ULONG64 P3Home;
8632 ULONG64 P4Home;
8633 ULONG64 P5;
8634
8635//
8636// Previous processor mode (system services only) and previous IRQL
8637// (interrupts only).
8638//
8639
8640 KPROCESSOR_MODE PreviousMode;
8641 KIRQL PreviousIrql;
8642
8643//
8644// Page fault load/store indicator.
8645//
8646
8647 UCHAR FaultIndicator;
8648 UCHAR Fill0;
8649
8650//
8651// Floating point state.
8652//
8653
8654 ULONG MxCsr;
8655
8656//
8657// Volatile registers.
8658//
8659// N.B. These registers are only saved on exceptions and interrupts. They
8660// are not saved for system calls.
8661//
8662
8663 ULONG64 Rax;
8664 ULONG64 Rcx;
8665 ULONG64 Rdx;
8666 ULONG64 R8;
8667 ULONG64 R9;
8668 ULONG64 R10;
8669 ULONG64 R11;
8670 ULONG64 Spare0;
8671
8672//
8673// Volatile floating registers.
8674//
8675// N.B. These registers are only saved on exceptions and interrupts. They
8676// are not saved for system calls.
8677//
8678
8679 M128 Xmm0;
8680 M128 Xmm1;
8681 M128 Xmm2;
8682 M128 Xmm3;
8683 M128 Xmm4;
8684 M128 Xmm5;
8685
8686//
8687// Page fault address.
8688//
8689
8690 ULONG64 FaultAddress;
8691
8692//
8693// Debug registers.
8694//
8695
8696 ULONG64 Dr0;
8697 ULONG64 Dr1;
8698 ULONG64 Dr2;
8699 ULONG64 Dr3;
8700 ULONG64 Dr6;
8701 ULONG64 Dr7;
8702
8703//
8704// Special debug registers.
8705//
8706
8707 ULONG64 DebugControl;
8708 ULONG64 LastBranchToRip;
8709 ULONG64 LastBranchFromRip;
8710 ULONG64 LastExceptionToRip;
8711 ULONG64 LastExceptionFromRip;
8712
8713//
8714// Segment registers
8715//
8716
8717 USHORT SegDs;
8718 USHORT SegEs;
8719 USHORT SegFs;
8720 USHORT SegGs;
8721
8722//
8723// Previous trap frame address.
8724//
8725
8726 ULONG64 TrapFrame;
8727
8728//
8729// Saved nonvolatile registers RBX, RDI and RSI. These registers are only
8730// saved in system service trap frames.
8731//
8732
8733 ULONG64 Rbx;
8734 ULONG64 Rdi;
8735 ULONG64 Rsi;
8736
8737//
8738// Saved nonvolatile register RBP. This register is used as a frame
8739// pointer during trap processing and is saved in all trap frames.
8740//
8741
8742 ULONG64 Rbp;
8743
8744//
8745// Information pushed by hardware.
8746//
8747// N.B. The error code is not always pushed by hardware. For those cases
8748// where it is not pushed by hardware a dummy error code is allocated
8749// on the stack.
8750//
8751
8752 ULONG64 ErrorCode;
8753 ULONG64 Rip;
8754 USHORT SegCs;
8755 USHORT Fill1[3];
8756 ULONG EFlags;
8757 ULONG Fill2;
8758 ULONG64 Rsp;
8759 USHORT SegSs;
8760 USHORT Fill3[3];
8761} KTRAP_FRAME, *PKTRAP_FRAME;
8762
8763//
8764// The nonvolatile floating state
8765//
8766
8767typedef struct _KFLOATING_SAVE {
8768 ULONG MxCsr;
8769} KFLOATING_SAVE, *PKFLOATING_SAVE;
8770
8771//
8772// AMD64 Specific portions of mm component.
8773//
8774// Define the page size for the AMD64 as 4096 (0x1000).
8775//
8776
8777#define PAGE_SIZE 0x1000
8778
8779//
8780// Define the number of trailing zeroes in a page aligned virtual address.
8781// This is used as the shift count when shifting virtual addresses to
8782// virtual page numbers.
8783//
8784
8785#define PAGE_SHIFT 12L
8786
8787
8788
8789#define PXE_BASE 0xFFFFF6FB7DBED000UI64
8790#define PXE_SELFMAP 0xFFFFF6FB7DBEDF68UI64
8791#define PPE_BASE 0xFFFFF6FB7DA00000UI64
8792#define PDE_BASE 0xFFFFF6FB40000000UI64
8793#define PTE_BASE 0xFFFFF68000000000UI64
8794
8795#define PXE_TOP 0xFFFFF6FB7DBEDFFFUI64
8796#define PPE_TOP 0xFFFFF6FB7DBFFFFFUI64
8797#define PDE_TOP 0xFFFFF6FB7FFFFFFFUI64
8798#define PTE_TOP 0xFFFFF6FFFFFFFFFFUI64
8799
8800#define PDE_KTBASE_AMD64 PPE_BASE
8801
8802#define PTI_SHIFT 12
8803#define PDI_SHIFT 21
8804#define PPI_SHIFT 30
8805#define PXI_SHIFT 39
8806
8807#define PTE_PER_PAGE 512
8808#define PDE_PER_PAGE 512
8809#define PPE_PER_PAGE 512
8810#define PXE_PER_PAGE 512
8811
8812#define PTI_MASK_AMD64 (PTE_PER_PAGE - 1)
8813#define PDI_MASK_AMD64 (PDE_PER_PAGE - 1)
8814#define PPI_MASK (PPE_PER_PAGE - 1)
8815#define PXI_MASK (PXE_PER_PAGE - 1)
8816
8817//
8818// Define the highest user address and user probe address.
8819//
8820
8821
8822extern PVOID *MmHighestUserAddress;
8823extern PVOID *MmSystemRangeStart;
8824extern ULONG64 *MmUserProbeAddress;
8825
8826#define MM_HIGHEST_USER_ADDRESS *MmHighestUserAddress
8827#define MM_SYSTEM_RANGE_START *MmSystemRangeStart
8828#define MM_USER_PROBE_ADDRESS *MmUserProbeAddress
8829
8830//
8831// The lowest user address reserves the low 64k.
8832//
8833
8834#define MM_LOWEST_USER_ADDRESS (PVOID)0x10000
8835
8836//
8837// The lowest address for system space.
8838//
8839
8840#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFF080000000000
8841
8842
8843
8844#define MmGetProcedureAddress(Address) (Address)
8845#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
8846
8847
8848//
8849// Intrinsic functions
8850//
8851
8852
8853
8854#if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
8855
8856
8857
8858//
8859// The following routines are provided for backward compatibility with old
8860// code. They are no longer the preferred way to accomplish these functions.
8861//
8862
8863#if PRAGMA_DEPRECATED_DDK
8864#pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
8865#pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
8866#pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
8867#endif
8868
8869#define RESULT_ZERO 0
8870#define RESULT_NEGATIVE 1
8871#define RESULT_POSITIVE 2
8872
8873typedef enum _INTERLOCKED_RESULT {
8874 ResultNegative = RESULT_NEGATIVE,
8875 ResultZero = RESULT_ZERO,
8876 ResultPositive = RESULT_POSITIVE
8877} INTERLOCKED_RESULT;
8878
8879#define ExInterlockedDecrementLong(Addend, Lock) \
8880 _ExInterlockedDecrementLong(Addend)
8881
8882__forceinline
8883LONG
8884_ExInterlockedDecrementLong (
8885 IN OUT PLONG Addend
8886 )
8887
8888{
8889
8890 LONG Result;
8891
8892 Result = InterlockedDecrement(Addend);
8893 if (Result < 0) {
8894 return ResultNegative;
8895
8896 } else if (Result > 0) {
8897 return ResultPositive;
8898
8899 } else {
8900 return ResultZero;
8901 }
8902}
8903
8904#define ExInterlockedIncrementLong(Addend, Lock) \
8905 _ExInterlockedIncrementLong(Addend)
8906
8907__forceinline
8908LONG
8909_ExInterlockedIncrementLong (
8910 IN OUT PLONG Addend
8911 )
8912
8913{
8914
8915 LONG Result;
8916
8917 Result = InterlockedIncrement(Addend);
8918 if (Result < 0) {
8919 return ResultNegative;
8920
8921 } else if (Result > 0) {
8922 return ResultPositive;
8923
8924 } else {
8925 return ResultZero;
8926 }
8927}
8928
8929#define ExInterlockedExchangeUlong(Target, Value, Lock) \
8930 _ExInterlockedExchangeUlong(Target, Value)
8931
8932__forceinline
8933_ExInterlockedExchangeUlong (
8934 IN OUT PULONG Target,
8935 IN ULONG Value
8936 )
8937
8938{
8939
8940 return (ULONG)InterlockedExchange((PLONG)Target, (LONG)Value);
8941}
8942
8943
8944
8945#endif // defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
8946
8947
8948#if !defined(MIDL_PASS) && defined(_M_AMD64)
8949
8950//
8951// AMD646 function prototype definitions
8952//
8953
8954
8955
8956
8957//
8958// Get the current processor number
8959//
8960
8961__forceinline
8962ULONG
8963KeGetCurrentProcessorNumber (
8964 VOID
8965 )
8966
8967{
8968
8969 return (ULONG)__readgsbyte(FIELD_OFFSET(KPCR, Number));
8970}
8971
8972
8973
8974
8975#endif // !defined(MIDL_PASS) && defined(_M_AMD64)
8976
8977
8978//++
8979//
8980//
8981// VOID
8982// KeMemoryBarrier (
8983// VOID
8984// )
8985//
8986// VOID
8987// KeMemoryBarrierWithoutFence (
8988// VOID
8989// )
8990//
8991//
8992// Routine Description:
8993//
8994// These functions order memory accesses as seen by other processors.
8995//
8996// Arguments:
8997//
8998// None.
8999//
9000// Return Value:
9001//
9002// None.
9003//
9004//--
9005
9006#if !defined(_CROSS_PLATFORM_)
9007
9008#ifdef __cplusplus
9009extern "C" {
9010#endif
9011
9012VOID
9013_ReadWriteBarrier (
9014 VOID
9015 );
9016
9017#pragma intrinsic(_ReadWriteBarrier)
9018
9019#ifdef __cplusplus
9020}
9021#endif
9022
9023#define KeMemoryBarrier() _ReadWriteBarrier()
9024#define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
9025
9026#else
9027
9028#define KeMemoryBarrier()
9029#define KeMemoryBarrierWithoutFence()
9030
9031#endif
9032
9033
9034NTKERNELAPI
9035NTSTATUS
9036KeSaveFloatingPointState (
9037 OUT PKFLOATING_SAVE SaveArea
9038 );
9039
9040NTKERNELAPI
9041NTSTATUS
9042KeRestoreFloatingPointState (
9043 IN PKFLOATING_SAVE SaveArea
9044 );
9045
9046
9047#endif // defined(_AMD64_)
9048
9049
9050
9051#if defined(_AMD64_)
9052
9053NTKERNELAPI
9054KIRQL
9055KeGetCurrentIrql (
9056 VOID
9057 );
9058
9059NTKERNELAPI
9060VOID
9061KeLowerIrql (
9062 IN KIRQL NewIrql
9063 );
9064
9065#define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
9066
9067NTKERNELAPI
9068KIRQL
9069KfRaiseIrql (
9070 IN KIRQL NewIrql
9071 );
9072
9073
9074
9075NTKERNELAPI
9076KIRQL
9077KeRaiseIrqlToDpcLevel (
9078 VOID
9079 );
9080
9081NTKERNELAPI
9082KIRQL
9083KeRaiseIrqlToSynchLevel (
9084 VOID
9085 );
9086
9087
9088
9089#endif // defined(_AMD64_)
9090
9091
9092#if defined(_IA64_)
9093
9094//
9095// Types to use to contain PFNs and their counts.
9096//
9097
9098typedef ULONG PFN_COUNT;
9099
9100typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
9101typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
9102
9103//
9104// Indicate that the IA64 compiler supports the pragma textout construct.
9105//
9106
9107#define ALLOC_PRAGMA 1
9108
9109//
9110// Define intrinsic calls and their prototypes
9111//
9112
9113#include "ia64reg.h"
9114
9115
9116#ifdef __cplusplus
9117extern "C" {
9118#endif
9119
9120unsigned __int64 __getReg (int);
9121void __setReg (int, unsigned __int64);
9122void __isrlz (void);
9123void __dsrlz (void);
9124void __fwb (void);
9125void __mf (void);
9126void __mfa (void);
9127void __synci (void);
9128__int64 __thash (__int64);
9129__int64 __ttag (__int64);
9130void __ptcl (__int64, __int64);
9131void __ptcg (__int64, __int64);
9132void __ptcga (__int64, __int64);
9133void __ptri (__int64, __int64);
9134void __ptrd (__int64, __int64);
9135void __invalat (void);
9136void __break (int);
9137void __fc (__int64);
9138void __fci (__int64);
9139void __sum (int);
9140void __rsm (int);
9141void _ReleaseSpinLock( unsigned __int64 *);
9142void __yield();
9143void __lfetch(int, void const *);
9144void __lfetchfault(int, void const *);
9145
9146#ifdef _M_IA64
9147#pragma intrinsic (__getReg)
9148#pragma intrinsic (__setReg)
9149#pragma intrinsic (__isrlz)
9150#pragma intrinsic (__dsrlz)
9151#pragma intrinsic (__fwb)
9152#pragma intrinsic (__mf)
9153#pragma intrinsic (__mfa)
9154#pragma intrinsic (__synci)
9155#pragma intrinsic (__thash)
9156#pragma intrinsic (__ttag)
9157#pragma intrinsic (__ptcl)
9158#pragma intrinsic (__ptcg)
9159#pragma intrinsic (__ptcga)
9160#pragma intrinsic (__ptri)
9161#pragma intrinsic (__ptrd)
9162#pragma intrinsic (__invalat)
9163#pragma intrinsic (__break)
9164#pragma intrinsic (__fc)
9165#pragma intrinsic (__fci)
9166#pragma intrinsic (__sum)
9167#pragma intrinsic (__rsm)
9168#pragma intrinsic (_ReleaseSpinLock)
9169#pragma intrinsic (__yield)
9170#pragma intrinsic (__lfetch)
9171#pragma intrinsic (__lfetchfault)
9172#endif // _M_IA64
9173
9174#ifdef __cplusplus
9175}
9176#endif
9177
9178
9179
9180
9181//
9182// Define length of interrupt vector table.
9183//
9184
9185#define MAXIMUM_VECTOR 256
9186
9187
9188
9189
9190//
9191// IA64 specific interlocked operation result values.
9192//
9193
9194#define RESULT_ZERO 0
9195#define RESULT_NEGATIVE 1
9196#define RESULT_POSITIVE 2
9197
9198//
9199// Interlocked result type is portable, but its values are machine specific.
9200// Constants for values are in i386.h, mips.h, etc.
9201//
9202
9203typedef enum _INTERLOCKED_RESULT {
9204 ResultNegative = RESULT_NEGATIVE,
9205 ResultZero = RESULT_ZERO,
9206 ResultPositive = RESULT_POSITIVE
9207} INTERLOCKED_RESULT;
9208
9209//
9210// Convert portable interlock interfaces to architecture specific interfaces.
9211//
9212
9213#if PRAGMA_DEPRECATED_DDK
9214#pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
9215#pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
9216#pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
9217#endif
9218
9219#define ExInterlockedIncrementLong(Addend, Lock) \
9220 ExIa64InterlockedIncrementLong(Addend)
9221
9222#define ExInterlockedDecrementLong(Addend, Lock) \
9223 ExIa64InterlockedDecrementLong(Addend)
9224
9225#define ExInterlockedExchangeUlong(Target, Value, Lock) \
9226 ExIa64InterlockedExchangeUlong(Target, Value)
9227
9228NTKERNELAPI
9229INTERLOCKED_RESULT
9230ExIa64InterlockedIncrementLong (
9231 IN PLONG Addend
9232 );
9233
9234NTKERNELAPI
9235INTERLOCKED_RESULT
9236ExIa64InterlockedDecrementLong (
9237 IN PLONG Addend
9238 );
9239
9240NTKERNELAPI
9241ULONG
9242ExIa64InterlockedExchangeUlong (
9243 IN PULONG Target,
9244 IN ULONG Value
9245 );
9246
9247
9248
9249
9250//
9251// IA64 Interrupt Definitions.
9252//
9253//
9254// Define length of interrupt object dispatch code in longwords.
9255//
9256
9257#define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
9258
9259// Begin of a block of definitions that must be synchronized with kxia64.h.
9260//
9261
9262//
9263// Define Interrupt Request Levels.
9264//
9265
9266#define PASSIVE_LEVEL 0 // Passive release level
9267#define LOW_LEVEL 0 // Lowest interrupt level
9268#define APC_LEVEL 1 // APC interrupt level
9269#define DISPATCH_LEVEL 2 // Dispatcher level
9270#define CMC_LEVEL 3 // Correctable machine check level
9271#define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
9272#define PC_LEVEL 12 // Performance Counter IRQL
9273#define IPI_LEVEL 14 // IPI IRQL
9274#define CLOCK_LEVEL 13 // Clock Timer IRQL
9275#define POWER_LEVEL 15 // Power failure level
9276#define PROFILE_LEVEL 15 // Profiling level
9277#define HIGH_LEVEL 15 // Highest interrupt level
9278
9279
9280#if defined(_M_IA64) && !defined(RC_INVOKED)
9281
9282#define InterlockedAdd _InterlockedAdd
9283#define InterlockedIncrement _InterlockedIncrement
9284#define InterlockedIncrementAcquire _InterlockedIncrement_acq
9285#define InterlockedIncrementRelease _InterlockedIncrement_rel
9286#define InterlockedDecrement _InterlockedDecrement
9287#define InterlockedDecrementAcquire _InterlockedDecrement_acq
9288#define InterlockedDecrementRelease _InterlockedDecrement_rel
9289#define InterlockedExchange _InterlockedExchange
9290#define InterlockedExchangeAdd _InterlockedExchangeAdd
9291
9292#define InterlockedAdd64 _InterlockedAdd64
9293#define InterlockedIncrement64 _InterlockedIncrement64
9294#define InterlockedDecrement64 _InterlockedDecrement64
9295#define InterlockedExchange64 _InterlockedExchange64
9296#define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
9297#define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
9298#define InterlockedCompareExchange64 _InterlockedCompareExchange64
9299#define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
9300#define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
9301
9302#define InterlockedCompareExchange _InterlockedCompareExchange
9303#define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
9304#define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
9305#define InterlockedExchangePointer _InterlockedExchangePointer
9306#define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
9307
9308#ifdef __cplusplus
9309extern "C" {
9310#endif
9311
9312LONG
9313__cdecl
9314InterlockedAdd (
9315 LONG volatile *Addend,
9316 LONG Value
9317 );
9318
9319LONGLONG
9320__cdecl
9321InterlockedAdd64 (
9322 LONGLONG volatile *Addend,
9323 LONGLONG Value
9324 );
9325
9326LONG
9327__cdecl
9328InterlockedIncrement(
9329 IN OUT LONG volatile *Addend
9330 );
9331
9332LONG
9333__cdecl
9334InterlockedDecrement(
9335 IN OUT LONG volatile *Addend
9336 );
9337
9338LONG
9339__cdecl
9340InterlockedIncrementAcquire(
9341 IN OUT LONG volatile *Addend
9342 );
9343
9344LONG
9345__cdecl
9346InterlockedDecrementAcquire(
9347 IN OUT LONG volatile *Addend
9348 );
9349
9350LONG
9351__cdecl
9352InterlockedIncrementRelease(
9353 IN OUT LONG volatile *Addend
9354 );
9355
9356LONG
9357__cdecl
9358InterlockedDecrementRelease(
9359 IN OUT LONG volatile *Addend
9360 );
9361
9362LONG
9363__cdecl
9364InterlockedExchange(
9365 IN OUT LONG volatile *Target,
9366 IN LONG Value
9367 );
9368
9369LONG
9370__cdecl
9371InterlockedExchangeAdd(
9372 IN OUT LONG volatile *Addend,
9373 IN LONG Value
9374 );
9375
9376LONG
9377__cdecl
9378InterlockedCompareExchange (
9379 IN OUT LONG volatile *Destination,
9380 IN LONG ExChange,
9381 IN LONG Comperand
9382 );
9383
9384
9385LONG
9386__cdecl
9387InterlockedCompareExchangeRelease (
9388 IN OUT LONG volatile *Destination,
9389 IN LONG ExChange,
9390 IN LONG Comperand
9391 );
9392
9393
9394LONG
9395__cdecl
9396InterlockedCompareExchangeAcquire (
9397 IN OUT LONG volatile *Destination,
9398 IN LONG ExChange,
9399 IN LONG Comperand
9400 );
9401
9402
9403LONGLONG
9404__cdecl
9405InterlockedIncrement64(
9406 IN OUT LONGLONG volatile *Addend
9407 );
9408
9409LONGLONG
9410__cdecl
9411InterlockedDecrement64(
9412 IN OUT LONGLONG volatile *Addend
9413 );
9414
9415LONGLONG
9416__cdecl
9417InterlockedExchange64(
9418 IN OUT LONGLONG volatile *Target,
9419 IN LONGLONG Value
9420 );
9421
9422LONGLONG
9423__cdecl
9424InterlockedExchangeAcquire64(
9425 IN OUT LONGLONG volatile *Target,
9426 IN LONGLONG Value
9427 );
9428
9429LONGLONG
9430__cdecl
9431InterlockedExchangeAdd64(
9432 IN OUT LONGLONG volatile *Addend,
9433 IN LONGLONG Value
9434 );
9435
9436LONGLONG
9437__cdecl
9438InterlockedCompareExchange64 (
9439 IN OUT LONGLONG volatile *Destination,
9440 IN LONGLONG ExChange,
9441 IN LONGLONG Comperand
9442 );
9443
9444LONGLONG
9445__cdecl
9446InterlockedCompareExchangeAcquire64 (
9447 IN OUT LONGLONG volatile *Destination,
9448 IN LONGLONG ExChange,
9449 IN LONGLONG Comperand
9450 );
9451
9452LONGLONG
9453__cdecl
9454InterlockedCompareExchangeRelease64 (
9455 IN OUT LONGLONG volatile *Destination,
9456 IN LONGLONG ExChange,
9457 IN LONGLONG Comperand
9458 );
9459
9460PVOID
9461__cdecl
9462InterlockedCompareExchangePointer (
9463 IN OUT PVOID volatile *Destination,
9464 IN PVOID Exchange,
9465 IN PVOID Comperand
9466 );
9467
9468PVOID
9469__cdecl
9470InterlockedExchangePointer(
9471 IN OUT PVOID volatile *Target,
9472 IN PVOID Value
9473 );
9474
9475#if !defined (InterlockedAnd64)
9476
9477#define InterlockedAnd64 InterlockedAnd64_Inline
9478
9479LONGLONG
9480FORCEINLINE
9481InterlockedAnd64_Inline (
9482 IN OUT LONGLONG volatile *Destination,
9483 IN LONGLONG Value
9484 )
9485{
9486 LONGLONG Old;
9487
9488 do {
9489 Old = *Destination;
9490 } while (InterlockedCompareExchange64(Destination,
9491 Old & Value,
9492 Old) != Old);
9493
9494 return Old;
9495}
9496
9497#endif
9498
9499#if !defined (InterlockedOr64)
9500
9501#define InterlockedOr64 InterlockedOr64_Inline
9502
9503LONGLONG
9504FORCEINLINE
9505InterlockedOr64_Inline (
9506 IN OUT LONGLONG volatile *Destination,
9507 IN LONGLONG Value
9508 )
9509{
9510 LONGLONG Old;
9511
9512 do {
9513 Old = *Destination;
9514 } while (InterlockedCompareExchange64(Destination,
9515 Old | Value,
9516 Old) != Old);
9517
9518 return Old;
9519}
9520
9521#endif
9522
9523
9524#if !defined (InterlockedXor64)
9525
9526#define InterlockedXor64 InterlockedXor64_Inline
9527
9528LONGLONG
9529FORCEINLINE
9530InterlockedXor64_Inline (
9531 IN OUT LONGLONG volatile *Destination,
9532 IN LONGLONG Value
9533 )
9534{
9535 LONGLONG Old;
9536
9537 do {
9538 Old = *Destination;
9539 } while (InterlockedCompareExchange64(Destination,
9540 Old ^ Value,
9541 Old) != Old);
9542
9543 return Old;
9544}
9545
9546#endif
9547
9548
9549#pragma intrinsic(_InterlockedAdd)
9550#pragma intrinsic(_InterlockedIncrement)
9551#pragma intrinsic(_InterlockedIncrement_acq)
9552#pragma intrinsic(_InterlockedIncrement_rel)
9553#pragma intrinsic(_InterlockedDecrement)
9554#pragma intrinsic(_InterlockedDecrement_acq)
9555#pragma intrinsic(_InterlockedDecrement_rel)
9556#pragma intrinsic(_InterlockedExchange)
9557#pragma intrinsic(_InterlockedCompareExchange)
9558#pragma intrinsic(_InterlockedCompareExchange_acq)
9559#pragma intrinsic(_InterlockedCompareExchange_rel)
9560#pragma intrinsic(_InterlockedExchangeAdd)
9561#pragma intrinsic(_InterlockedAdd64)
9562#pragma intrinsic(_InterlockedIncrement64)
9563#pragma intrinsic(_InterlockedDecrement64)
9564#pragma intrinsic(_InterlockedExchange64)
9565#pragma intrinsic(_InterlockedExchange64_acq)
9566#pragma intrinsic(_InterlockedCompareExchange64)
9567#pragma intrinsic(_InterlockedCompareExchange64_acq)
9568#pragma intrinsic(_InterlockedCompareExchange64_rel)
9569#pragma intrinsic(_InterlockedExchangeAdd64)
9570#pragma intrinsic(_InterlockedExchangePointer)
9571#pragma intrinsic(_InterlockedCompareExchangePointer)
9572
9573#ifdef __cplusplus
9574}
9575#endif
9576
9577#endif // defined(_M_IA64) && !defined(RC_INVOKED)
9578
9579
9580
9581__forceinline
9582LONG
9583InterlockedAnd (
9584 IN OUT LONG volatile *Target,
9585 LONG Set
9586 )
9587{
9588 LONG i;
9589 LONG j;
9590
9591 j = *Target;
9592 do {
9593 i = j;
9594 j = InterlockedCompareExchange(Target,
9595 i & Set,
9596 i);
9597
9598 } while (i != j);
9599
9600 return j;
9601}
9602
9603__forceinline
9604LONG
9605InterlockedOr (
9606 IN OUT LONG volatile *Target,
9607 IN LONG Set
9608 )
9609{
9610 LONG i;
9611 LONG j;
9612
9613 j = *Target;
9614 do {
9615 i = j;
9616 j = InterlockedCompareExchange(Target,
9617 i | Set,
9618 i);
9619
9620 } while (i != j);
9621
9622 return j;
9623}
9624
9625__forceinline
9626LONG
9627InterlockedXor (
9628 IN OUT LONG volatile *Target,
9629 IN LONG Set
9630 )
9631{
9632 LONG i;
9633 LONG j;
9634
9635 j = *Target;
9636 do {
9637 i = j;
9638 j = InterlockedCompareExchange(Target,
9639 i ^ Set,
9640 i);
9641
9642 } while (i != j);
9643
9644 return j;
9645}
9646
9647
9648
9649#define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
9650#define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
9651
9652
9653
9654//
9655// Get address of processor control region.
9656//
9657
9658#define KeGetPcr() PCR
9659
9660//
9661// Get address of current kernel thread object.
9662//
9663
9664#if defined(_M_IA64)
9665#define KeGetCurrentThread() PCR->CurrentThread
9666#endif
9667
9668//
9669// Get current processor number.
9670//
9671
9672#define KeGetCurrentProcessorNumber() ((ULONG)(PCR->Number))
9673
9674//
9675// Get data cache fill size.
9676//
9677
9678#if PRAGMA_DEPRECATED_DDK
9679#pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
9680#endif
9681
9682#define KeGetDcacheFillSize() PCR->DcacheFillSize
9683
9684
9685#define KeSaveFloatingPointState(a) STATUS_SUCCESS
9686#define KeRestoreFloatingPointState(a) STATUS_SUCCESS
9687
9688
9689
9690//
9691//
9692// VOID
9693// KeMemoryBarrierWithoutFence (
9694// VOID
9695// )
9696//
9697//
9698// Routine Description:
9699//
9700// This function cases ordering of memory acceses generated by the compiler.
9701//
9702//
9703// Arguments:
9704//
9705// None.
9706//
9707// Return Value:
9708//
9709// None.
9710//--
9711
9712#ifdef __cplusplus
9713extern "C" {
9714#endif
9715
9716VOID
9717_ReadWriteBarrier (
9718 VOID
9719 );
9720
9721#ifdef __cplusplus
9722}
9723#endif
9724
9725#pragma intrinsic(_ReadWriteBarrier)
9726
9727#define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
9728
9729//++
9730//
9731//
9732// VOID
9733// KeMemoryBarrier (
9734// VOID
9735// )
9736//
9737//
9738// Routine Description:
9739//
9740// This function cases ordering of memory acceses as generated by the compiler and
9741// as seen by other processors.
9742//
9743//
9744// Arguments:
9745//
9746// None.
9747//
9748// Return Value:
9749//
9750// None.
9751//--
9752
9753#define KE_MEMORY_BARRIER_REQUIRED
9754
9755#define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
9756
9757//
9758// Define the page size
9759//
9760
9761#define PAGE_SIZE 0x2000
9762
9763//
9764// Define the number of trailing zeroes in a page aligned virtual address.
9765// This is used as the shift count when shifting virtual addresses to
9766// virtual page numbers.
9767//
9768
9769#define PAGE_SHIFT 13L
9770
9771//
9772// Cache and write buffer flush functions.
9773//
9774
9775NTKERNELAPI
9776VOID
9777KeFlushIoBuffers (
9778 IN PMDL Mdl,
9779 IN BOOLEAN ReadOperation,
9780 IN BOOLEAN DmaOperation
9781 );
9782
9783
9784//
9785// Kernel breakin breakpoint
9786//
9787
9788VOID
9789KeBreakinBreakpoint (
9790 VOID
9791 );
9792
9793
9794#define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
9795#define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
9796#define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
9797#define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
9798
9799
9800#if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
9801
9802
9803
9804#define KeQueryTickCount(CurrentCount ) \
9805 *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
9806
9807
9808
9809#else
9810
9811
9812NTKERNELAPI
9813VOID
9814KeQueryTickCount (
9815 OUT PLARGE_INTEGER CurrentCount
9816 );
9817
9818#endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
9819
9820//
9821// I/O space read and write macros.
9822//
9823
9824NTHALAPI
9825UCHAR
9826READ_PORT_UCHAR (
9827 PUCHAR RegisterAddress
9828 );
9829
9830NTHALAPI
9831USHORT
9832READ_PORT_USHORT (
9833 PUSHORT RegisterAddress
9834 );
9835
9836NTHALAPI
9837ULONG
9838READ_PORT_ULONG (
9839 PULONG RegisterAddress
9840 );
9841
9842NTHALAPI
9843VOID
9844READ_PORT_BUFFER_UCHAR (
9845 PUCHAR portAddress,
9846 PUCHAR readBuffer,
9847 ULONG readCount
9848 );
9849
9850NTHALAPI
9851VOID
9852READ_PORT_BUFFER_USHORT (
9853 PUSHORT portAddress,
9854 PUSHORT readBuffer,
9855 ULONG readCount
9856 );
9857
9858NTHALAPI
9859VOID
9860READ_PORT_BUFFER_ULONG (
9861 PULONG portAddress,
9862 PULONG readBuffer,
9863 ULONG readCount
9864 );
9865
9866NTHALAPI
9867VOID
9868WRITE_PORT_UCHAR (
9869 PUCHAR portAddress,
9870 UCHAR Data
9871 );
9872
9873NTHALAPI
9874VOID
9875WRITE_PORT_USHORT (
9876 PUSHORT portAddress,
9877 USHORT Data
9878 );
9879
9880NTHALAPI
9881VOID
9882WRITE_PORT_ULONG (
9883 PULONG portAddress,
9884 ULONG Data
9885 );
9886
9887NTHALAPI
9888VOID
9889WRITE_PORT_BUFFER_UCHAR (
9890 PUCHAR portAddress,
9891 PUCHAR writeBuffer,
9892 ULONG writeCount
9893 );
9894
9895NTHALAPI
9896VOID
9897WRITE_PORT_BUFFER_USHORT (
9898 PUSHORT portAddress,
9899 PUSHORT writeBuffer,
9900 ULONG writeCount
9901 );
9902
9903NTHALAPI
9904VOID
9905WRITE_PORT_BUFFER_ULONG (
9906 PULONG portAddress,
9907 PULONG writeBuffer,
9908 ULONG writeCount
9909 );
9910
9911
9912#define READ_REGISTER_UCHAR(x) \
9913 (__mf(), *(volatile UCHAR * const)(x))
9914
9915#define READ_REGISTER_USHORT(x) \
9916 (__mf(), *(volatile USHORT * const)(x))
9917
9918#define READ_REGISTER_ULONG(x) \
9919 (__mf(), *(volatile ULONG * const)(x))
9920
9921#define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
9922 PUCHAR registerBuffer = x; \
9923 PUCHAR readBuffer = y; \
9924 ULONG readCount; \
9925 __mf(); \
9926 for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
9927 *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
9928 } \
9929}
9930
9931#define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
9932 PUSHORT registerBuffer = x; \
9933 PUSHORT readBuffer = y; \
9934 ULONG readCount; \
9935 __mf(); \
9936 for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
9937 *readBuffer = *(volatile USHORT * const)(registerBuffer); \
9938 } \
9939}
9940
9941#define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
9942 PULONG registerBuffer = x; \
9943 PULONG readBuffer = y; \
9944 ULONG readCount; \
9945 __mf(); \
9946 for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
9947 *readBuffer = *(volatile ULONG * const)(registerBuffer); \
9948 } \
9949}
9950
9951#define WRITE_REGISTER_UCHAR(x, y) { \
9952 *(volatile UCHAR * const)(x) = y; \
9953 KeFlushWriteBuffer(); \
9954}
9955
9956#define WRITE_REGISTER_USHORT(x, y) { \
9957 *(volatile USHORT * const)(x) = y; \
9958 KeFlushWriteBuffer(); \
9959}
9960
9961#define WRITE_REGISTER_ULONG(x, y) { \
9962 *(volatile ULONG * const)(x) = y; \
9963 KeFlushWriteBuffer(); \
9964}
9965
9966#define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
9967 PUCHAR registerBuffer = x; \
9968 PUCHAR writeBuffer = y; \
9969 ULONG writeCount; \
9970 for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
9971 *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
9972 } \
9973 KeFlushWriteBuffer(); \
9974}
9975
9976#define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
9977 PUSHORT registerBuffer = x; \
9978 PUSHORT writeBuffer = y; \
9979 ULONG writeCount; \
9980 for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
9981 *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
9982 } \
9983 KeFlushWriteBuffer(); \
9984}
9985
9986#define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
9987 PULONG registerBuffer = x; \
9988 PULONG writeBuffer = y; \
9989 ULONG writeCount; \
9990 for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
9991 *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
9992 } \
9993 KeFlushWriteBuffer(); \
9994}
9995
9996//
9997// Non-volatile floating point state
9998//
9999
10000typedef struct _KFLOATING_SAVE {
10001 ULONG Reserved;
10002} KFLOATING_SAVE, *PKFLOATING_SAVE;
10003
10004
10005//
10006// Define Processor Control Region Structure.
10007//
10008
10009#define PCR_MINOR_VERSION 1
10010#define PCR_MAJOR_VERSION 1
10011
10012typedef struct _KPCR {
10013
10014//
10015// Major and minor version numbers of the PCR.
10016//
10017 ULONG MinorVersion;
10018 ULONG MajorVersion;
10019
10020//
10021// Start of the architecturally defined section of the PCR. This section
10022// may be directly addressed by vendor/platform specific HAL code and will
10023// not change from version to version of NT.
10024//
10025
10026//
10027// First and second level cache parameters.
10028//
10029
10030 ULONG FirstLevelDcacheSize;
10031 ULONG FirstLevelDcacheFillSize;
10032 ULONG FirstLevelIcacheSize;
10033 ULONG FirstLevelIcacheFillSize;
10034 ULONG SecondLevelDcacheSize;
10035 ULONG SecondLevelDcacheFillSize;
10036 ULONG SecondLevelIcacheSize;
10037 ULONG SecondLevelIcacheFillSize;
10038
10039//
10040// Data cache alignment and fill size used for cache flushing and alignment.
10041// These fields are set to the larger of the first and second level data
10042// cache fill sizes.
10043//
10044
10045 ULONG DcacheAlignment;
10046 ULONG DcacheFillSize;
10047
10048//
10049// Instruction cache alignment and fill size used for cache flushing and
10050// alignment. These fields are set to the larger of the first and second
10051// level data cache fill sizes.
10052//
10053
10054 ULONG IcacheAlignment;
10055 ULONG IcacheFillSize;
10056
10057//
10058// Processor identification from PrId register.
10059//
10060
10061 ULONG ProcessorId;
10062
10063//
10064// Profiling data.
10065//
10066
10067 ULONG ProfileInterval;
10068 ULONG ProfileCount;
10069
10070//
10071// Stall execution count and scale factor.
10072//
10073
10074 ULONG StallExecutionCount;
10075 ULONG StallScaleFactor;
10076
10077 ULONG InterruptionCount;
10078
10079//
10080// Space reserved for the system.
10081//
10082
10083 ULONGLONG SystemReserved[6];
10084
10085//
10086// Space reserved for the HAL
10087//
10088
10089 ULONGLONG HalReserved[64];
10090
10091//
10092// IRQL mapping tables.
10093//
10094
10095 UCHAR IrqlMask[64];
10096 UCHAR IrqlTable[64];
10097
10098//
10099// External Interrupt vectors.
10100//
10101
10102 PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
10103
10104//
10105// Reserved interrupt vector mask.
10106//
10107
10108 ULONG ReservedVectors;
10109
10110//
10111// Processor affinity mask.
10112//
10113
10114 KAFFINITY SetMember;
10115
10116//
10117// Complement of the processor affinity mask.
10118//
10119
10120 KAFFINITY NotMember;
10121
10122//
10123// Pointer to processor control block.
10124//
10125
10126 struct _KPRCB *Prcb;
10127
10128//
10129// Shadow copy of Prcb->CurrentThread for fast access
10130//
10131
10132 struct _KTHREAD *CurrentThread;
10133
10134//
10135// Processor number.
10136//
10137
10138 CCHAR Number; // Processor Number
10139
10140
10141} KPCR, *PKPCR;
10142
10143
10144
10145NTKERNELAPI
10146KIRQL
10147KeGetCurrentIrql();
10148
10149NTKERNELAPI
10150VOID
10151KeLowerIrql (
10152 IN KIRQL NewIrql
10153 );
10154
10155NTKERNELAPI
10156VOID
10157KeRaiseIrql (
10158 IN KIRQL NewIrql,
10159 OUT PKIRQL OldIrql
10160 );
10161
10162
10163
10164NTKERNELAPI
10165KIRQL
10166KeRaiseIrqlToDpcLevel (
10167 VOID
10168 );
10169
10170NTKERNELAPI
10171KIRQL
10172KeRaiseIrqlToSynchLevel (
10173 VOID
10174 );
10175
10176
10177//
10178// The highest user address reserves 64K bytes for a guard page. This
10179// the probing of address from kernel mode to only have to check the
10180// starting address for structures of 64k bytes or less.
10181//
10182
10183extern NTKERNELAPI PVOID MmHighestUserAddress;
10184extern NTKERNELAPI PVOID MmSystemRangeStart;
10185extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
10186
10187
10188#define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
10189#define MM_USER_PROBE_ADDRESS MmUserProbeAddress
10190#define MM_SYSTEM_RANGE_START MmSystemRangeStart
10191
10192//
10193// The lowest user address reserves the low 64k.
10194//
10195
10196#define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
10197
10198
10199
10200#define MmGetProcedureAddress(Address) (Address)
10201#define MmLockPagableCodeSection(PLabelAddress) \
10202 MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
10203
10204#define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
10205
10206//
10207// The lowest address for system space.
10208//
10209
10210#define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
10211#endif // defined(_IA64_)
10212//
10213// Event Specific Access Rights.
10214//
10215
10216#define EVENT_QUERY_STATE 0x0001
10217#define EVENT_MODIFY_STATE 0x0002
10218#define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
10219
10220//
10221// Semaphore Specific Access Rights.
10222//
10223
10224#define SEMAPHORE_QUERY_STATE 0x0001
10225#define SEMAPHORE_MODIFY_STATE 0x0002
10226
10227#define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|0x3)
10228
10229//
10230// Timer APC routine definition.
10231//
10232
10233typedef
10234VOID
10235(*PTIMER_APC_ROUTINE) (
10236 IN PVOID TimerContext,
10237 IN ULONG TimerLowValue,
10238 IN LONG TimerHighValue
10239 );
10240
10241
10242//
10243// Driver Verifier Definitions
10244//
10245
10246typedef ULONG_PTR (*PDRIVER_VERIFIER_THUNK_ROUTINE) (
10247 IN PVOID Context
10248 );
10249
10250//
10251// This structure is passed in by drivers that want to thunk callers of
10252// their exports.
10253//
10254
10255typedef struct _DRIVER_VERIFIER_THUNK_PAIRS {
10256 PDRIVER_VERIFIER_THUNK_ROUTINE PristineRoutine;
10257 PDRIVER_VERIFIER_THUNK_ROUTINE NewRoutine;
10258} DRIVER_VERIFIER_THUNK_PAIRS, *PDRIVER_VERIFIER_THUNK_PAIRS;
10259
10260//
10261// Driver Verifier flags.
10262//
10263
10264#define DRIVER_VERIFIER_SPECIAL_POOLING 0x0001
10265#define DRIVER_VERIFIER_FORCE_IRQL_CHECKING 0x0002
10266#define DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES 0x0004
10267#define DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS 0x0008
10268#define DRIVER_VERIFIER_IO_CHECKING 0x0010
10269
10270
10271//
10272// Defined processor features
10273//
10274
10275#define PF_FLOATING_POINT_PRECISION_ERRATA 0
10276#define PF_FLOATING_POINT_EMULATED 1
10277#define PF_COMPARE_EXCHANGE_DOUBLE 2
10278#define PF_MMX_INSTRUCTIONS_AVAILABLE 3
10279#define PF_PPC_MOVEMEM_64BIT_OK 4
10280#define PF_ALPHA_BYTE_INSTRUCTIONS 5
10281#define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
10282#define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
10283#define PF_RDTSC_INSTRUCTION_AVAILABLE 8
10284#define PF_PAE_ENABLED 9
10285#define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
10286
10287typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE {
10288 StandardDesign, // None == 0 == standard design
10289 NEC98x86, // NEC PC98xx series on X86
10290 EndAlternatives // past end of known alternatives
10291} ALTERNATIVE_ARCHITECTURE_TYPE;
10292
10293// correctly define these run-time definitions for non X86 machines
10294
10295#ifndef _X86_
10296
10297#ifndef IsNEC_98
10298#define IsNEC_98 (FALSE)
10299#endif
10300
10301#ifndef IsNotNEC_98
10302#define IsNotNEC_98 (TRUE)
10303#endif
10304
10305#ifndef SetNEC_98
10306#define SetNEC_98
10307#endif
10308
10309#ifndef SetNotNEC_98
10310#define SetNotNEC_98
10311#endif
10312
10313#endif
10314
10315#define PROCESSOR_FEATURE_MAX 64
10316
10317
10318
10319#if defined(REMOTE_BOOT)
10320//
10321// Defined system flags.
10322//
10323
10324/* the following two lines should be tagged with "winnt" when REMOTE_BOOT is on. */
10325#define SYSTEM_FLAG_REMOTE_BOOT_CLIENT 0x00000001
10326#define SYSTEM_FLAG_DISKLESS_CLIENT 0x00000002
10327#endif // defined(REMOTE_BOOT)
10328
10329//
10330// Define data shared between kernel and user mode.
10331//
10332// N.B. User mode has read only access to this data
10333//
10334#ifdef _MAC
10335#pragma warning( disable : 4121)
10336#endif
10337
10338//
10339// WARNING: This structure must have exactly the same layout for 32- and
10340// 64-bit systems. The layout of this structure cannot change and new
10341// fields can only be added to the end of the structure. Deprecated
10342// fields cannot be deleted. Platform specific fields are included on
10343// all systems.
10344//
10345// Layout exactness is required for Wow64 support of 32bit applications
10346// on Win64 systems.
10347//
10348// The layout itself cannot change since this sturcture has been exported
10349// in ntddk, ntifs.h, and nthal.h for some time.
10350//
10351
10352typedef struct _KUSER_SHARED_DATA {
10353
10354 //
10355 // Current low 32-bit of tick count and tick count multiplier.
10356 //
10357 // N.B. The tick count is updated each time the clock ticks.
10358 //
10359
10360 ULONG TickCountLowDeprecated;
10361 ULONG TickCountMultiplier;
10362
10363 //
10364 // Current 64-bit interrupt time in 100ns units.
10365 //
10366
10367 volatile KSYSTEM_TIME InterruptTime;
10368
10369 //
10370 // Current 64-bit system time in 100ns units.
10371 //
10372
10373 volatile KSYSTEM_TIME SystemTime;
10374
10375 //
10376 // Current 64-bit time zone bias.
10377 //
10378
10379 volatile KSYSTEM_TIME TimeZoneBias;
10380
10381 //
10382 // Support image magic number range for the host system.
10383 //
10384 // N.B. This is an inclusive range.
10385 //
10386
10387 USHORT ImageNumberLow;
10388 USHORT ImageNumberHigh;
10389
10390 //
10391 // Copy of system root in Unicode
10392 //
10393
10394 WCHAR NtSystemRoot[ 260 ];
10395
10396 //
10397 // Maximum stack trace depth if tracing enabled.
10398 //
10399
10400 ULONG MaxStackTraceDepth;
10401
10402 //
10403 // Crypto Exponent
10404 //
10405
10406 ULONG CryptoExponent;
10407
10408 //
10409 // TimeZoneId
10410 //
10411
10412 ULONG TimeZoneId;
10413
10414 ULONG LargePageMinimum;
10415 ULONG Reserved2[ 7 ];
10416
10417 //
10418 // product type
10419 //
10420
10421 NT_PRODUCT_TYPE NtProductType;
10422 BOOLEAN ProductTypeIsValid;
10423
10424 //
10425 // NT Version. Note that each process sees a version from its PEB, but
10426 // if the process is running with an altered view of the system version,
10427 // the following two fields are used to correctly identify the version
10428 //
10429
10430 ULONG NtMajorVersion;
10431 ULONG NtMinorVersion;
10432
10433 //
10434 // Processor Feature Bits
10435 //
10436
10437 BOOLEAN ProcessorFeatures[PROCESSOR_FEATURE_MAX];
10438
10439 //
10440 // Reserved fields - do not use
10441 //
10442 ULONG Reserved1;
10443 ULONG Reserved3;
10444
10445 //
10446 // Time slippage while in debugger
10447 //
10448
10449 volatile ULONG TimeSlip;
10450
10451 //
10452 // Alternative system architecture. Example: NEC PC98xx on x86
10453 //
10454
10455 ALTERNATIVE_ARCHITECTURE_TYPE AlternativeArchitecture;
10456
10457 //
10458 // If the system is an evaluation unit, the following field contains the
10459 // date and time that the evaluation unit expires. A value of 0 indicates
10460 // that there is no expiration. A non-zero value is the UTC absolute time
10461 // that the system expires.
10462 //
10463
10464 LARGE_INTEGER SystemExpirationDate;
10465
10466 //
10467 // Suite Support
10468 //
10469
10470 ULONG SuiteMask;
10471
10472 //
10473 // TRUE if a kernel debugger is connected/enabled
10474 //
10475
10476 BOOLEAN KdDebuggerEnabled;
10477
10478
10479 //
10480 // Current console session Id. Always zero on non-TS systems
10481 //
10482 volatile ULONG ActiveConsoleId;
10483
10484 //
10485 // Force-dismounts cause handles to become invalid. Rather than
10486 // always probe handles, we maintain a serial number of
10487 // dismounts that clients can use to see if they need to probe
10488 // handles.
10489 //
10490
10491 volatile ULONG DismountCount;
10492
10493 //
10494 // This field indicates the status of the 64-bit COM+ package on the system.
10495 // It indicates whether the Itermediate Language (IL) COM+ images need to
10496 // use the 64-bit COM+ runtime or the 32-bit COM+ runtime.
10497 //
10498
10499 ULONG ComPlusPackage;
10500
10501 //
10502 // Time in tick count for system-wide last user input across all
10503 // terminal sessions. For MP performance, it is not updated all
10504 // the time (e.g. once a minute per session). It is used for idle
10505 // detection.
10506 //
10507
10508 ULONG LastSystemRITEventTickCount;
10509
10510 //
10511 // Number of physical pages in the system. This can dynamically
10512 // change as physical memory can be added or removed from a running
10513 // system.
10514 //
10515
10516 ULONG NumberOfPhysicalPages;
10517
10518 //
10519 // True if the system was booted in safe boot mode.
10520 //
10521
10522 BOOLEAN SafeBootMode;
10523
10524 //
10525 // The following field is used for Heap and CritSec Tracing
10526 // The last bit is set for Critical Sec Collision tracing and
10527 // second Last bit is for Heap Tracing
10528 // Also the first 16 bits are used as counter.
10529 //
10530
10531 ULONG TraceLogging;
10532
10533 //
10534 // Depending on the processor, the code for fast system call
10535 // will differ, the following buffer is filled with the appropriate
10536 // code sequence and user mode code will branch through it.
10537 //
10538 // (32 bytes, using ULONGLONG for alignment).
10539 //
10540 // N.B. The following two fields are only used on 32-bit systems.
10541 //
10542
10543 ULONGLONG Fill0; // alignment
10544 ULONGLONG SystemCall[4];
10545
10546 //
10547 // The 64-bit tick count.
10548 //
10549
10550 union {
10551 volatile KSYSTEM_TIME TickCount;
10552 volatile ULONG64 TickCountQuad;
10553 };
10554
10555} KUSER_SHARED_DATA, *PKUSER_SHARED_DATA;
10556
10557#ifdef _MAC
10558#pragma warning( default : 4121 )
10559#endif
10560
10561
10562//
10563// Predefined Value Types.
10564//
10565
10566#define REG_NONE ( 0 ) // No value type
10567#define REG_SZ ( 1 ) // Unicode nul terminated string
10568#define REG_EXPAND_SZ ( 2 ) // Unicode nul terminated string
10569 // (with environment variable references)
10570#define REG_BINARY ( 3 ) // Free form binary
10571#define REG_DWORD ( 4 ) // 32-bit number
10572#define REG_DWORD_LITTLE_ENDIAN ( 4 ) // 32-bit number (same as REG_DWORD)
10573#define REG_DWORD_BIG_ENDIAN ( 5 ) // 32-bit number
10574#define REG_LINK ( 6 ) // Symbolic Link (unicode)
10575#define REG_MULTI_SZ ( 7 ) // Multiple Unicode strings
10576#define REG_RESOURCE_LIST ( 8 ) // Resource list in the resource map
10577#define REG_FULL_RESOURCE_DESCRIPTOR ( 9 ) // Resource list in the hardware description
10578#define REG_RESOURCE_REQUIREMENTS_LIST ( 10 )
10579#define REG_QWORD ( 11 ) // 64-bit number
10580#define REG_QWORD_LITTLE_ENDIAN ( 11 ) // 64-bit number (same as REG_QWORD)
10581
10582//
10583// Service Types (Bit Mask)
10584//
10585#define SERVICE_KERNEL_DRIVER 0x00000001
10586#define SERVICE_FILE_SYSTEM_DRIVER 0x00000002
10587#define SERVICE_ADAPTER 0x00000004
10588#define SERVICE_RECOGNIZER_DRIVER 0x00000008
10589
10590#define SERVICE_DRIVER (SERVICE_KERNEL_DRIVER | \
10591 SERVICE_FILE_SYSTEM_DRIVER | \
10592 SERVICE_RECOGNIZER_DRIVER)
10593
10594#define SERVICE_WIN32_OWN_PROCESS 0x00000010
10595#define SERVICE_WIN32_SHARE_PROCESS 0x00000020
10596#define SERVICE_WIN32 (SERVICE_WIN32_OWN_PROCESS | \
10597 SERVICE_WIN32_SHARE_PROCESS)
10598
10599#define SERVICE_INTERACTIVE_PROCESS 0x00000100
10600
10601#define SERVICE_TYPE_ALL (SERVICE_WIN32 | \
10602 SERVICE_ADAPTER | \
10603 SERVICE_DRIVER | \
10604 SERVICE_INTERACTIVE_PROCESS)
10605
10606//
10607// Start Type
10608//
10609
10610#define SERVICE_BOOT_START 0x00000000
10611#define SERVICE_SYSTEM_START 0x00000001
10612#define SERVICE_AUTO_START 0x00000002
10613#define SERVICE_DEMAND_START 0x00000003
10614#define SERVICE_DISABLED 0x00000004
10615
10616//
10617// Error control type
10618//
10619#define SERVICE_ERROR_IGNORE 0x00000000
10620#define SERVICE_ERROR_NORMAL 0x00000001
10621#define SERVICE_ERROR_SEVERE 0x00000002
10622#define SERVICE_ERROR_CRITICAL 0x00000003
10623
10624//
10625//
10626// Define the registry driver node enumerations
10627//
10628
10629typedef enum _CM_SERVICE_NODE_TYPE {
10630 DriverType = SERVICE_KERNEL_DRIVER,
10631 FileSystemType = SERVICE_FILE_SYSTEM_DRIVER,
10632 Win32ServiceOwnProcess = SERVICE_WIN32_OWN_PROCESS,
10633 Win32ServiceShareProcess = SERVICE_WIN32_SHARE_PROCESS,
10634 AdapterType = SERVICE_ADAPTER,
10635 RecognizerType = SERVICE_RECOGNIZER_DRIVER
10636} SERVICE_NODE_TYPE;
10637
10638typedef enum _CM_SERVICE_LOAD_TYPE {
10639 BootLoad = SERVICE_BOOT_START,
10640 SystemLoad = SERVICE_SYSTEM_START,
10641 AutoLoad = SERVICE_AUTO_START,
10642 DemandLoad = SERVICE_DEMAND_START,
10643 DisableLoad = SERVICE_DISABLED
10644} SERVICE_LOAD_TYPE;
10645
10646typedef enum _CM_ERROR_CONTROL_TYPE {
10647 IgnoreError = SERVICE_ERROR_IGNORE,
10648 NormalError = SERVICE_ERROR_NORMAL,
10649 SevereError = SERVICE_ERROR_SEVERE,
10650 CriticalError = SERVICE_ERROR_CRITICAL
10651} SERVICE_ERROR_TYPE;
10652
10653
10654
10655//
10656// Resource List definitions
10657//
10658
10659
10660
10661//
10662// Defines the Type in the RESOURCE_DESCRIPTOR
10663//
10664// NOTE: For all CM_RESOURCE_TYPE values, there must be a
10665// corresponding ResType value in the 32-bit ConfigMgr headerfile
10666// (cfgmgr32.h). Values in the range [0x6,0x80) use the same values
10667// as their ConfigMgr counterparts. CM_RESOURCE_TYPE values with
10668// the high bit set (i.e., in the range [0x80,0xFF]), are
10669// non-arbitrated resources. These correspond to the same values
10670// in cfgmgr32.h that have their high bit set (however, since
10671// cfgmgr32.h uses 16 bits for ResType values, these values are in
10672// the range [0x8000,0x807F). Note that ConfigMgr ResType values
10673// cannot be in the range [0x8080,0xFFFF), because they would not
10674// be able to map into CM_RESOURCE_TYPE values. (0xFFFF itself is
10675// a special value, because it maps to CmResourceTypeDeviceSpecific.)
10676//
10677
10678typedef int CM_RESOURCE_TYPE;
10679
10680// CmResourceTypeNull is reserved
10681
10682#define CmResourceTypeNull 0 // ResType_All or ResType_None (0x0000)
10683#define CmResourceTypePort 1 // ResType_IO (0x0002)
10684#define CmResourceTypeInterrupt 2 // ResType_IRQ (0x0004)
10685#define CmResourceTypeMemory 3 // ResType_Mem (0x0001)
10686#define CmResourceTypeDma 4 // ResType_DMA (0x0003)
10687#define CmResourceTypeDeviceSpecific 5 // ResType_ClassSpecific (0xFFFF)
10688#define CmResourceTypeBusNumber 6 // ResType_BusNumber (0x0006)
10689
10690#define CmResourceTypeMaximum 7
10691
10692#define CmResourceTypeNonArbitrated 128 // Not arbitrated if 0x80 bit set
10693#define CmResourceTypeConfigData 128 // ResType_Reserved (0x8000)
10694#define CmResourceTypeDevicePrivate 129 // ResType_DevicePrivate (0x8001)
10695#define CmResourceTypePcCardConfig 130 // ResType_PcCardConfig (0x8002)
10696#define CmResourceTypeMfCardConfig 131 // ResType_MfCardConfig (0x8003)
10697
10698//
10699// Defines the ShareDisposition in the RESOURCE_DESCRIPTOR
10700//
10701
10702typedef enum _CM_SHARE_DISPOSITION {
10703 CmResourceShareUndetermined = 0, // Reserved
10704 CmResourceShareDeviceExclusive,
10705 CmResourceShareDriverExclusive,
10706 CmResourceShareShared
10707} CM_SHARE_DISPOSITION;
10708
10709//
10710// Define the bit masks for Flags when type is CmResourceTypeInterrupt
10711//
10712
10713#define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
10714#define CM_RESOURCE_INTERRUPT_LATCHED 1
10715
10716//
10717// Define the bit masks for Flags when type is CmResourceTypeMemory
10718//
10719
10720#define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
10721#define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
10722#define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
10723#define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
10724
10725#define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
10726#define CM_RESOURCE_MEMORY_24 0x0010
10727#define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
10728
10729//
10730// Define the bit masks for Flags when type is CmResourceTypePort
10731//
10732
10733#define CM_RESOURCE_PORT_MEMORY 0x0000
10734#define CM_RESOURCE_PORT_IO 0x0001
10735#define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
10736#define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
10737#define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
10738#define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
10739#define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
10740#define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
10741
10742//
10743// Define the bit masks for Flags when type is CmResourceTypeDma
10744//
10745
10746#define CM_RESOURCE_DMA_8 0x0000
10747#define CM_RESOURCE_DMA_16 0x0001
10748#define CM_RESOURCE_DMA_32 0x0002
10749#define CM_RESOURCE_DMA_8_AND_16 0x0004
10750#define CM_RESOURCE_DMA_BUS_MASTER 0x0008
10751#define CM_RESOURCE_DMA_TYPE_A 0x0010
10752#define CM_RESOURCE_DMA_TYPE_B 0x0020
10753#define CM_RESOURCE_DMA_TYPE_F 0x0040
10754
10755
10756
10757//
10758// This structure defines one type of resource used by a driver.
10759//
10760// There can only be *1* DeviceSpecificData block. It must be located at
10761// the end of all resource descriptors in a full descriptor block.
10762//
10763
10764//
10765// Make sure alignment is made properly by compiler; otherwise move
10766// flags back to the top of the structure (common to all members of the
10767// union).
10768//
10769
10770
10771#include "pshpack4.h"
10772typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
10773 UCHAR Type;
10774 UCHAR ShareDisposition;
10775 USHORT Flags;
10776 union {
10777
10778 //
10779 // Range of resources, inclusive. These are physical, bus relative.
10780 // It is known that Port and Memory below have the exact same layout
10781 // as Generic.
10782 //
10783
10784 struct {
10785 PHYSICAL_ADDRESS Start;
10786 ULONG Length;
10787 } Generic;
10788
10789 //
10790
10791 // Range of port numbers, inclusive. These are physical, bus
10792 // relative. The value should be the same as the one passed to
10793 // HalTranslateBusAddress().
10794
10795 //
10796
10797 struct {
10798 PHYSICAL_ADDRESS Start;
10799 ULONG Length;
10800 } Port;
10801
10802 //
10803
10804 // IRQL and vector. Should be same values as were passed to
10805 // HalGetInterruptVector().
10806
10807 //
10808
10809 struct {
10810 ULONG Level;
10811 ULONG Vector;
10812 KAFFINITY Affinity;
10813 } Interrupt;
10814
10815 //
10816 // Range of memory addresses, inclusive. These are physical, bus
10817 // relative. The value should be the same as the one passed to
10818 // HalTranslateBusAddress().
10819 //
10820
10821 struct {
10822 PHYSICAL_ADDRESS Start; // 64 bit physical addresses.
10823 ULONG Length;
10824 } Memory;
10825
10826 //
10827 // Physical DMA channel.
10828 //
10829
10830 struct {
10831 ULONG Channel;
10832 ULONG Port;
10833 ULONG Reserved1;
10834 } Dma;
10835
10836 //
10837 // Device driver private data, usually used to help it figure
10838 // what the resource assignments decisions that were made.
10839 //
10840
10841 struct {
10842 ULONG Data[3];
10843 } DevicePrivate;
10844
10845 //
10846 // Bus Number information.
10847 //
10848
10849 struct {
10850 ULONG Start;
10851 ULONG Length;
10852 ULONG Reserved;
10853 } BusNumber;
10854
10855 //
10856 // Device Specific information defined by the driver.
10857 // The DataSize field indicates the size of the data in bytes. The
10858 // data is located immediately after the DeviceSpecificData field in
10859 // the structure.
10860 //
10861
10862 struct {
10863 ULONG DataSize;
10864 ULONG Reserved1;
10865 ULONG Reserved2;
10866 } DeviceSpecificData;
10867 } u;
10868} CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
10869#include "poppack.h"
10870
10871//
10872// A Partial Resource List is what can be found in the ARC firmware
10873// or will be generated by ntdetect.com.
10874// The configuration manager will transform this structure into a Full
10875// resource descriptor when it is about to store it in the regsitry.
10876//
10877// Note: There must a be a convention to the order of fields of same type,
10878// (defined on a device by device basis) so that the fields can make sense
10879// to a driver (i.e. when multiple memory ranges are necessary).
10880//
10881
10882typedef struct _CM_PARTIAL_RESOURCE_LIST {
10883 USHORT Version;
10884 USHORT Revision;
10885 ULONG Count;
10886 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
10887} CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
10888
10889//
10890// A Full Resource Descriptor is what can be found in the registry.
10891// This is what will be returned to a driver when it queries the registry
10892// to get device information; it will be stored under a key in the hardware
10893// description tree.
10894//
10895
10896// Note: The BusNumber and Type are redundant information, but we will keep
10897// it since it allows the driver _not_ to append it when it is creating
10898// a resource list which could possibly span multiple buses.
10899//
10900
10901// Note: There must a be a convention to the order of fields of same type,
10902// (defined on a device by device basis) so that the fields can make sense
10903// to a driver (i.e. when multiple memory ranges are necessary).
10904//
10905
10906typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
10907 INTERFACE_TYPE InterfaceType; // unused for WDM
10908 ULONG BusNumber; // unused for WDM
10909 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
10910} CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
10911
10912//
10913// The Resource list is what will be stored by the drivers into the
10914// resource map via the IO API.
10915//
10916
10917typedef struct _CM_RESOURCE_LIST {
10918 ULONG Count;
10919 CM_FULL_RESOURCE_DESCRIPTOR List[1];
10920} CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
10921
10922
10923//
10924// Define the structures used to interpret configuration data of
10925// \\Registry\machine\hardware\description tree.
10926// Basically, these structures are used to interpret component
10927// sepcific data.
10928//
10929
10930//
10931// Define DEVICE_FLAGS
10932//
10933
10934typedef struct _DEVICE_FLAGS {
10935 ULONG Failed : 1;
10936 ULONG ReadOnly : 1;
10937 ULONG Removable : 1;
10938 ULONG ConsoleIn : 1;
10939 ULONG ConsoleOut : 1;
10940 ULONG Input : 1;
10941 ULONG Output : 1;
10942} DEVICE_FLAGS, *PDEVICE_FLAGS;
10943
10944//
10945// Define Component Information structure
10946//
10947
10948typedef struct _CM_COMPONENT_INFORMATION {
10949 DEVICE_FLAGS Flags;
10950 ULONG Version;
10951 ULONG Key;
10952 KAFFINITY AffinityMask;
10953} CM_COMPONENT_INFORMATION, *PCM_COMPONENT_INFORMATION;
10954
10955//
10956// The following structures are used to interpret x86
10957// DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
10958// (Most of the structures are defined by BIOS. They are
10959// not aligned on word (or dword) boundary.
10960//
10961
10962//
10963// Define the Rom Block structure
10964//
10965
10966typedef struct _CM_ROM_BLOCK {
10967 ULONG Address;
10968 ULONG Size;
10969} CM_ROM_BLOCK, *PCM_ROM_BLOCK;
10970
10971
10972
10973#include "pshpack1.h"
10974
10975
10976
10977//
10978// Define INT13 driver parameter block
10979//
10980
10981typedef struct _CM_INT13_DRIVE_PARAMETER {
10982 USHORT DriveSelect;
10983 ULONG MaxCylinders;
10984 USHORT SectorsPerTrack;
10985 USHORT MaxHeads;
10986 USHORT NumberDrives;
10987} CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
10988
10989
10990
10991//
10992// Define Mca POS data block for slot
10993//
10994
10995typedef struct _CM_MCA_POS_DATA {
10996 USHORT AdapterId;
10997 UCHAR PosData1;
10998 UCHAR PosData2;
10999 UCHAR PosData3;
11000 UCHAR PosData4;
11001} CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
11002
11003//
11004// Memory configuration of eisa data block structure
11005//
11006
11007typedef struct _EISA_MEMORY_TYPE {
11008 UCHAR ReadWrite: 1;
11009 UCHAR Cached : 1;
11010 UCHAR Reserved0 :1;
11011 UCHAR Type:2;
11012 UCHAR Shared:1;
11013 UCHAR Reserved1 :1;
11014 UCHAR MoreEntries : 1;
11015} EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
11016
11017typedef struct _EISA_MEMORY_CONFIGURATION {
11018 EISA_MEMORY_TYPE ConfigurationByte;
11019 UCHAR DataSize;
11020 USHORT AddressLowWord;
11021 UCHAR AddressHighByte;
11022 USHORT MemorySize;
11023} EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
11024
11025
11026//
11027// Interrupt configurationn of eisa data block structure
11028//
11029
11030typedef struct _EISA_IRQ_DESCRIPTOR {
11031 UCHAR Interrupt : 4;
11032 UCHAR Reserved :1;
11033 UCHAR LevelTriggered :1;
11034 UCHAR Shared : 1;
11035 UCHAR MoreEntries : 1;
11036} EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
11037
11038typedef struct _EISA_IRQ_CONFIGURATION {
11039 EISA_IRQ_DESCRIPTOR ConfigurationByte;
11040 UCHAR Reserved;
11041} EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
11042
11043
11044//
11045// DMA description of eisa data block structure
11046//
11047
11048typedef struct _DMA_CONFIGURATION_BYTE0 {
11049 UCHAR Channel : 3;
11050 UCHAR Reserved : 3;
11051 UCHAR Shared :1;
11052 UCHAR MoreEntries :1;
11053} DMA_CONFIGURATION_BYTE0;
11054
11055typedef struct _DMA_CONFIGURATION_BYTE1 {
11056 UCHAR Reserved0 : 2;
11057 UCHAR TransferSize : 2;
11058 UCHAR Timing : 2;
11059 UCHAR Reserved1 : 2;
11060} DMA_CONFIGURATION_BYTE1;
11061
11062typedef struct _EISA_DMA_CONFIGURATION {
11063 DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
11064 DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
11065} EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
11066
11067
11068//
11069// Port description of eisa data block structure
11070//
11071
11072typedef struct _EISA_PORT_DESCRIPTOR {
11073 UCHAR NumberPorts : 5;
11074 UCHAR Reserved :1;
11075 UCHAR Shared :1;
11076 UCHAR MoreEntries : 1;
11077} EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
11078
11079typedef struct _EISA_PORT_CONFIGURATION {
11080 EISA_PORT_DESCRIPTOR Configuration;
11081 USHORT PortAddress;
11082} EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
11083
11084
11085//
11086// Eisa slot information definition
11087// N.B. This structure is different from the one defined
11088// in ARC eisa addendum.
11089//
11090
11091typedef struct _CM_EISA_SLOT_INFORMATION {
11092 UCHAR ReturnCode;
11093 UCHAR ReturnFlags;
11094 UCHAR MajorRevision;
11095 UCHAR MinorRevision;
11096 USHORT Checksum;
11097 UCHAR NumberFunctions;
11098 UCHAR FunctionInformation;
11099 ULONG CompressedId;
11100} CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
11101
11102
11103//
11104// Eisa function information definition
11105//
11106
11107typedef struct _CM_EISA_FUNCTION_INFORMATION {
11108 ULONG CompressedId;
11109 UCHAR IdSlotFlags1;
11110 UCHAR IdSlotFlags2;
11111 UCHAR MinorRevision;
11112 UCHAR MajorRevision;
11113 UCHAR Selections[26];
11114 UCHAR FunctionFlags;
11115 UCHAR TypeString[80];
11116 EISA_MEMORY_CONFIGURATION EisaMemory[9];
11117 EISA_IRQ_CONFIGURATION EisaIrq[7];
11118 EISA_DMA_CONFIGURATION EisaDma[4];
11119 EISA_PORT_CONFIGURATION EisaPort[20];
11120 UCHAR InitializationData[60];
11121} CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
11122
11123//
11124// The following defines the way pnp bios information is stored in
11125// the registry \\HKEY_LOCAL_MACHINE\HARDWARE\Description\System\MultifunctionAdapter\x
11126// key, where x is an integer number indicating adapter instance. The
11127// "Identifier" of the key must equal to "PNP BIOS" and the
11128// "ConfigurationData" is organized as follow:
11129//
11130// CM_PNP_BIOS_INSTALLATION_CHECK +
11131// CM_PNP_BIOS_DEVICE_NODE for device 1 +
11132// CM_PNP_BIOS_DEVICE_NODE for device 2 +
11133// ...
11134// CM_PNP_BIOS_DEVICE_NODE for device n
11135//
11136
11137//
11138// Pnp BIOS device node structure
11139//
11140
11141typedef struct _CM_PNP_BIOS_DEVICE_NODE {
11142 USHORT Size;
11143 UCHAR Node;
11144 ULONG ProductId;
11145 UCHAR DeviceType[3];
11146 USHORT DeviceAttributes;
11147 // followed by AllocatedResourceBlock, PossibleResourceBlock
11148 // and CompatibleDeviceId
11149} CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
11150
11151//
11152// Pnp BIOS Installation check
11153//
11154
11155typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK {
11156 UCHAR Signature[4]; // $PnP (ascii)
11157 UCHAR Revision;
11158 UCHAR Length;
11159 USHORT ControlField;
11160 UCHAR Checksum;
11161 ULONG EventFlagAddress; // Physical address
11162 USHORT RealModeEntryOffset;
11163 USHORT RealModeEntrySegment;
11164 USHORT ProtectedModeEntryOffset;
11165 ULONG ProtectedModeCodeBaseAddress;
11166 ULONG OemDeviceId;
11167 USHORT RealModeDataBaseAddress;
11168 ULONG ProtectedModeDataBaseAddress;
11169} CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
11170
11171#include "poppack.h"
11172
11173//
11174// Masks for EISA function information
11175//
11176
11177#define EISA_FUNCTION_ENABLED 0x80
11178#define EISA_FREE_FORM_DATA 0x40
11179#define EISA_HAS_PORT_INIT_ENTRY 0x20
11180#define EISA_HAS_PORT_RANGE 0x10
11181#define EISA_HAS_DMA_ENTRY 0x08
11182#define EISA_HAS_IRQ_ENTRY 0x04
11183#define EISA_HAS_MEMORY_ENTRY 0x02
11184#define EISA_HAS_TYPE_ENTRY 0x01
11185#define EISA_HAS_INFORMATION EISA_HAS_PORT_RANGE + \
11186 EISA_HAS_DMA_ENTRY + \
11187 EISA_HAS_IRQ_ENTRY + \
11188 EISA_HAS_MEMORY_ENTRY + \
11189 EISA_HAS_TYPE_ENTRY
11190
11191//
11192// Masks for EISA memory configuration
11193//
11194
11195#define EISA_MORE_ENTRIES 0x80
11196#define EISA_SYSTEM_MEMORY 0x00
11197#define EISA_MEMORY_TYPE_RAM 0x01
11198
11199//
11200// Returned error code for EISA bios call
11201//
11202
11203#define EISA_INVALID_SLOT 0x80
11204#define EISA_INVALID_FUNCTION 0x81
11205#define EISA_INVALID_CONFIGURATION 0x82
11206#define EISA_EMPTY_SLOT 0x83
11207#define EISA_INVALID_BIOS_CALL 0x86
11208
11209
11210
11211//
11212// The following structures are used to interpret mips
11213// DeviceSpecificData of CM_PARTIAL_RESOURCE_DESCRIPTOR.
11214//
11215
11216//
11217// Device data records for adapters.
11218//
11219
11220//
11221// The device data record for the Emulex SCSI controller.
11222//
11223
11224typedef struct _CM_SCSI_DEVICE_DATA {
11225 USHORT Version;
11226 USHORT Revision;
11227 UCHAR HostIdentifier;
11228} CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
11229
11230//
11231// Device data records for controllers.
11232//
11233
11234//
11235// The device data record for the Video controller.
11236//
11237
11238typedef struct _CM_VIDEO_DEVICE_DATA {
11239 USHORT Version;
11240 USHORT Revision;
11241 ULONG VideoClock;
11242} CM_VIDEO_DEVICE_DATA, *PCM_VIDEO_DEVICE_DATA;
11243
11244//
11245// The device data record for the SONIC network controller.
11246//
11247
11248typedef struct _CM_SONIC_DEVICE_DATA {
11249 USHORT Version;
11250 USHORT Revision;
11251 USHORT DataConfigurationRegister;
11252 UCHAR EthernetAddress[8];
11253} CM_SONIC_DEVICE_DATA, *PCM_SONIC_DEVICE_DATA;
11254
11255//
11256// The device data record for the serial controller.
11257//
11258
11259typedef struct _CM_SERIAL_DEVICE_DATA {
11260 USHORT Version;
11261 USHORT Revision;
11262 ULONG BaudClock;
11263} CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
11264
11265//
11266// Device data records for peripherals.
11267//
11268
11269//
11270// The device data record for the Monitor peripheral.
11271//
11272
11273typedef struct _CM_MONITOR_DEVICE_DATA {
11274 USHORT Version;
11275 USHORT Revision;
11276 USHORT HorizontalScreenSize;
11277 USHORT VerticalScreenSize;
11278 USHORT HorizontalResolution;
11279 USHORT VerticalResolution;
11280 USHORT HorizontalDisplayTimeLow;
11281 USHORT HorizontalDisplayTime;
11282 USHORT HorizontalDisplayTimeHigh;
11283 USHORT HorizontalBackPorchLow;
11284 USHORT HorizontalBackPorch;
11285 USHORT HorizontalBackPorchHigh;
11286 USHORT HorizontalFrontPorchLow;
11287 USHORT HorizontalFrontPorch;
11288 USHORT HorizontalFrontPorchHigh;
11289 USHORT HorizontalSyncLow;
11290 USHORT HorizontalSync;
11291 USHORT HorizontalSyncHigh;
11292 USHORT VerticalBackPorchLow;
11293 USHORT VerticalBackPorch;
11294 USHORT VerticalBackPorchHigh;
11295 USHORT VerticalFrontPorchLow;
11296 USHORT VerticalFrontPorch;
11297 USHORT VerticalFrontPorchHigh;
11298 USHORT VerticalSyncLow;
11299 USHORT VerticalSync;
11300 USHORT VerticalSyncHigh;
11301} CM_MONITOR_DEVICE_DATA, *PCM_MONITOR_DEVICE_DATA;
11302
11303//
11304// The device data record for the Floppy peripheral.
11305//
11306
11307typedef struct _CM_FLOPPY_DEVICE_DATA {
11308 USHORT Version;
11309 USHORT Revision;
11310 CHAR Size[8];
11311 ULONG MaxDensity;
11312 ULONG MountDensity;
11313 //
11314 // New data fields for version >= 2.0
11315 //
11316 UCHAR StepRateHeadUnloadTime;
11317 UCHAR HeadLoadTime;
11318 UCHAR MotorOffTime;
11319 UCHAR SectorLengthCode;
11320 UCHAR SectorPerTrack;
11321 UCHAR ReadWriteGapLength;
11322 UCHAR DataTransferLength;
11323 UCHAR FormatGapLength;
11324 UCHAR FormatFillCharacter;
11325 UCHAR HeadSettleTime;
11326 UCHAR MotorSettleTime;
11327 UCHAR MaximumTrackValue;
11328 UCHAR DataTransferRate;
11329} CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
11330
11331//
11332// The device data record for the Keyboard peripheral.
11333// The KeyboardFlags is defined (by x86 BIOS INT 16h, function 02) as:
11334// bit 7 : Insert on
11335// bit 6 : Caps Lock on
11336// bit 5 : Num Lock on
11337// bit 4 : Scroll Lock on
11338// bit 3 : Alt Key is down
11339// bit 2 : Ctrl Key is down
11340// bit 1 : Left shift key is down
11341// bit 0 : Right shift key is down
11342//
11343
11344typedef struct _CM_KEYBOARD_DEVICE_DATA {
11345 USHORT Version;
11346 USHORT Revision;
11347 UCHAR Type;
11348 UCHAR Subtype;
11349 USHORT KeyboardFlags;
11350} CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
11351
11352//
11353// Declaration of the structure for disk geometries
11354//
11355
11356typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA {
11357 ULONG BytesPerSector;
11358 ULONG NumberOfCylinders;
11359 ULONG SectorsPerTrack;
11360 ULONG NumberOfHeads;
11361} CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
11362
11363
11364//
11365// Declaration of the structure for the PcCard ISA IRQ map
11366//
11367
11368typedef struct _CM_PCCARD_DEVICE_DATA {
11369 UCHAR Flags;
11370 UCHAR ErrorCode;
11371 USHORT Reserved;
11372 ULONG BusData;
11373 ULONG DeviceId;
11374 ULONG LegacyBaseAddress;
11375 UCHAR IRQMap[16];
11376} CM_PCCARD_DEVICE_DATA, *PCM_PCCARD_DEVICE_DATA;
11377
11378// Definitions for Flags
11379
11380#define PCCARD_MAP_ERROR 0x01
11381#define PCCARD_DEVICE_PCI 0x10
11382
11383#define PCCARD_SCAN_DISABLED 0x01
11384#define PCCARD_MAP_ZERO 0x02
11385#define PCCARD_NO_TIMER 0x03
11386#define PCCARD_NO_PIC 0x04
11387#define PCCARD_NO_LEGACY_BASE 0x05
11388#define PCCARD_DUP_LEGACY_BASE 0x06
11389#define PCCARD_NO_CONTROLLERS 0x07
11390
11391
11392
11393
11394//
11395// Defines Resource Options
11396//
11397
11398#define IO_RESOURCE_PREFERRED 0x01
11399#define IO_RESOURCE_DEFAULT 0x02
11400#define IO_RESOURCE_ALTERNATIVE 0x08
11401
11402
11403//
11404// This structure defines one type of resource requested by the driver
11405//
11406
11407typedef struct _IO_RESOURCE_DESCRIPTOR {
11408 UCHAR Option;
11409 UCHAR Type; // use CM_RESOURCE_TYPE
11410 UCHAR ShareDisposition; // use CM_SHARE_DISPOSITION
11411 UCHAR Spare1;
11412 USHORT Flags; // use CM resource flag defines
11413 USHORT Spare2; // align
11414
11415 union {
11416 struct {
11417 ULONG Length;
11418 ULONG Alignment;
11419 PHYSICAL_ADDRESS MinimumAddress;
11420 PHYSICAL_ADDRESS MaximumAddress;
11421 } Port;
11422
11423 struct {
11424 ULONG Length;
11425 ULONG Alignment;
11426 PHYSICAL_ADDRESS MinimumAddress;
11427 PHYSICAL_ADDRESS MaximumAddress;
11428 } Memory;
11429
11430 struct {
11431 ULONG MinimumVector;
11432 ULONG MaximumVector;
11433 } Interrupt;
11434
11435 struct {
11436 ULONG MinimumChannel;
11437 ULONG MaximumChannel;
11438 } Dma;
11439
11440 struct {
11441 ULONG Length;
11442 ULONG Alignment;
11443 PHYSICAL_ADDRESS MinimumAddress;
11444 PHYSICAL_ADDRESS MaximumAddress;
11445 } Generic;
11446
11447 struct {
11448 ULONG Data[3];
11449 } DevicePrivate;
11450
11451 //
11452 // Bus Number information.
11453 //
11454
11455 struct {
11456 ULONG Length;
11457 ULONG MinBusNumber;
11458 ULONG MaxBusNumber;
11459 ULONG Reserved;
11460 } BusNumber;
11461
11462 struct {
11463 ULONG Priority; // use LCPRI_Xxx values in cfg.h
11464 ULONG Reserved1;
11465 ULONG Reserved2;
11466 } ConfigData;
11467
11468 } u;
11469
11470} IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
11471
11472
11473
11474
11475typedef struct _IO_RESOURCE_LIST {
11476 USHORT Version;
11477 USHORT Revision;
11478
11479 ULONG Count;
11480 IO_RESOURCE_DESCRIPTOR Descriptors[1];
11481} IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
11482
11483
11484typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
11485 ULONG ListSize;
11486 INTERFACE_TYPE InterfaceType; // unused for WDM
11487 ULONG BusNumber; // unused for WDM
11488 ULONG SlotNumber;
11489 ULONG Reserved[3];
11490 ULONG AlternativeLists;
11491 IO_RESOURCE_LIST List[1];
11492} IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
11493
11494//
11495// Exception flag definitions.
11496//
11497
11498
11499#define EXCEPTION_NONCONTINUABLE 0x1 // Noncontinuable exception
11500
11501
11502//
11503// Define maximum number of exception parameters.
11504//
11505
11506
11507#define EXCEPTION_MAXIMUM_PARAMETERS 15 // maximum number of exception parameters
11508
11509//
11510// Exception record definition.
11511//
11512
11513typedef struct _EXCEPTION_RECORD {
11514 NTSTATUS ExceptionCode;
11515 ULONG ExceptionFlags;
11516 struct _EXCEPTION_RECORD *ExceptionRecord;
11517 PVOID ExceptionAddress;
11518 ULONG NumberParameters;
11519 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
11520 } EXCEPTION_RECORD;
11521
11522typedef EXCEPTION_RECORD *PEXCEPTION_RECORD;
11523
11524typedef struct _EXCEPTION_RECORD32 {
11525 NTSTATUS ExceptionCode;
11526 ULONG ExceptionFlags;
11527 ULONG ExceptionRecord;
11528 ULONG ExceptionAddress;
11529 ULONG NumberParameters;
11530 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
11531} EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
11532
11533typedef struct _EXCEPTION_RECORD64 {
11534 NTSTATUS ExceptionCode;
11535 ULONG ExceptionFlags;
11536 ULONG64 ExceptionRecord;
11537 ULONG64 ExceptionAddress;
11538 ULONG NumberParameters;
11539 ULONG __unusedAlignment;
11540 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
11541} EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
11542
11543//
11544// Typedef for pointer returned by exception_info()
11545//
11546
11547typedef struct _EXCEPTION_POINTERS {
11548 PEXCEPTION_RECORD ExceptionRecord;
11549 PCONTEXT ContextRecord;
11550} EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
11551
11552
11553//
11554// Define configuration routine types.
11555//
11556// Configuration information.
11557//
11558
11559typedef enum _CONFIGURATION_TYPE {
11560 ArcSystem,
11561 CentralProcessor,
11562 FloatingPointProcessor,
11563 PrimaryIcache,
11564 PrimaryDcache,
11565 SecondaryIcache,
11566 SecondaryDcache,
11567 SecondaryCache,
11568 EisaAdapter,
11569 TcAdapter,
11570 ScsiAdapter,
11571 DtiAdapter,
11572 MultiFunctionAdapter,
11573 DiskController,
11574 TapeController,
11575 CdromController,
11576 WormController,
11577 SerialController,
11578 NetworkController,
11579 DisplayController,
11580 ParallelController,
11581 PointerController,
11582 KeyboardController,
11583 AudioController,
11584 OtherController,
11585 DiskPeripheral,
11586 FloppyDiskPeripheral,
11587 TapePeripheral,
11588 ModemPeripheral,
11589 MonitorPeripheral,
11590 PrinterPeripheral,
11591 PointerPeripheral,
11592 KeyboardPeripheral,
11593 TerminalPeripheral,
11594 OtherPeripheral,
11595 LinePeripheral,
11596 NetworkPeripheral,
11597 SystemMemory,
11598 DockingInformation,
11599 RealModeIrqRoutingTable,
11600 RealModePCIEnumeration,
11601 MaximumType
11602} CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
11603
11604
11605#define THREAD_WAIT_OBJECTS 3 // Builtin usable wait blocks
11606
11607//
11608
11609#if defined(_X86_)
11610
11611#define PAUSE_PROCESSOR _asm { rep nop }
11612
11613#else
11614
11615#define PAUSE_PROCESSOR
11616
11617#endif
11618
11619
11620//
11621// Interrupt modes.
11622//
11623
11624typedef enum _KINTERRUPT_MODE {
11625 LevelSensitive,
11626 Latched
11627 } KINTERRUPT_MODE;
11628
11629//
11630// Wait reasons
11631//
11632
11633typedef enum _KWAIT_REASON {
11634 Executive,
11635 FreePage,
11636 PageIn,
11637 PoolAllocation,
11638 DelayExecution,
11639 Suspended,
11640 UserRequest,
11641 WrExecutive,
11642 WrFreePage,
11643 WrPageIn,
11644 WrPoolAllocation,
11645 WrDelayExecution,
11646 WrSuspended,
11647 WrUserRequest,
11648 WrEventPair,
11649 WrQueue,
11650 WrLpcReceive,
11651 WrLpcReply,
11652 WrVirtualMemory,
11653 WrPageOut,
11654 WrRendezvous,
11655 Spare2,
11656 Spare3,
11657 Spare4,
11658 Spare5,
11659 Spare6,
11660 WrKernel,
11661 WrResource,
11662 WrPushLock,
11663 WrMutex,
11664 WrQuantumEnd,
11665 WrDispatchInt,
11666 WrPreempted,
11667 WrYieldExecution,
11668 MaximumWaitReason
11669 } KWAIT_REASON;
11670
11671
11672typedef struct _KWAIT_BLOCK {
11673 LIST_ENTRY WaitListEntry;
11674 struct _KTHREAD *RESTRICTED_POINTER Thread;
11675 PVOID Object;
11676 struct _KWAIT_BLOCK *RESTRICTED_POINTER NextWaitBlock;
11677 USHORT WaitKey;
11678 USHORT WaitType;
11679} KWAIT_BLOCK, *PKWAIT_BLOCK, *RESTRICTED_POINTER PRKWAIT_BLOCK;
11680
11681//
11682// Thread start function
11683//
11684
11685typedef
11686VOID
11687(*PKSTART_ROUTINE) (
11688 IN PVOID StartContext
11689 );
11690
11691//
11692// Kernel object structure definitions
11693//
11694
11695//
11696// Device Queue object and entry
11697//
11698
11699typedef struct _KDEVICE_QUEUE {
11700 CSHORT Type;
11701 CSHORT Size;
11702 LIST_ENTRY DeviceListHead;
11703 KSPIN_LOCK Lock;
11704 BOOLEAN Busy;
11705} KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
11706
11707typedef struct _KDEVICE_QUEUE_ENTRY {
11708 LIST_ENTRY DeviceListEntry;
11709 ULONG SortKey;
11710 BOOLEAN Inserted;
11711} KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY, *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
11712
11713//
11714// Define the interrupt service function type and the empty struct
11715// type.
11716//
11717
11718typedef
11719BOOLEAN
11720(*PKSERVICE_ROUTINE) (
11721 IN struct _KINTERRUPT *Interrupt,
11722 IN PVOID ServiceContext
11723 );
11724
11725//
11726// Mutant object
11727//
11728
11729typedef struct _KMUTANT {
11730 DISPATCHER_HEADER Header;
11731 LIST_ENTRY MutantListEntry;
11732 struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
11733 BOOLEAN Abandoned;
11734 UCHAR ApcDisable;
11735} KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
11736
11737//
11738//
11739// Semaphore object
11740//
11741
11742typedef struct _KSEMAPHORE {
11743 DISPATCHER_HEADER Header;
11744 LONG Limit;
11745} KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
11746
11747//
11748// DPC object
11749//
11750
11751NTKERNELAPI
11752VOID
11753KeInitializeDpc (
11754 IN PRKDPC Dpc,
11755 IN PKDEFERRED_ROUTINE DeferredRoutine,
11756 IN PVOID DeferredContext
11757 );
11758
11759
11760NTKERNELAPI
11761BOOLEAN
11762KeInsertQueueDpc (
11763 IN PRKDPC Dpc,
11764 IN PVOID SystemArgument1,
11765 IN PVOID SystemArgument2
11766 );
11767
11768NTKERNELAPI
11769BOOLEAN
11770KeRemoveQueueDpc (
11771 IN PRKDPC Dpc
11772 );
11773
11774
11775
11776NTKERNELAPI
11777VOID
11778KeSetImportanceDpc (
11779 IN PRKDPC Dpc,
11780 IN KDPC_IMPORTANCE Importance
11781 );
11782
11783NTKERNELAPI
11784VOID
11785KeSetTargetProcessorDpc (
11786 IN PRKDPC Dpc,
11787 IN CCHAR Number
11788 );
11789
11790
11791
11792NTKERNELAPI
11793VOID
11794KeFlushQueuedDpcs (
11795 VOID
11796 );
11797
11798//
11799// Device queue object
11800//
11801
11802NTKERNELAPI
11803VOID
11804KeInitializeDeviceQueue (
11805 IN PKDEVICE_QUEUE DeviceQueue
11806 );
11807
11808NTKERNELAPI
11809BOOLEAN
11810KeInsertDeviceQueue (
11811 IN PKDEVICE_QUEUE DeviceQueue,
11812 IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
11813 );
11814
11815NTKERNELAPI
11816BOOLEAN
11817KeInsertByKeyDeviceQueue (
11818 IN PKDEVICE_QUEUE DeviceQueue,
11819 IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
11820 IN ULONG SortKey
11821 );
11822
11823NTKERNELAPI
11824PKDEVICE_QUEUE_ENTRY
11825KeRemoveDeviceQueue (
11826 IN PKDEVICE_QUEUE DeviceQueue
11827 );
11828
11829NTKERNELAPI
11830PKDEVICE_QUEUE_ENTRY
11831KeRemoveByKeyDeviceQueue (
11832 IN PKDEVICE_QUEUE DeviceQueue,
11833 IN ULONG SortKey
11834 );
11835
11836NTKERNELAPI
11837PKDEVICE_QUEUE_ENTRY
11838KeRemoveByKeyDeviceQueueIfBusy (
11839 IN PKDEVICE_QUEUE DeviceQueue,
11840 IN ULONG SortKey
11841 );
11842
11843NTKERNELAPI
11844BOOLEAN
11845KeRemoveEntryDeviceQueue (
11846 IN PKDEVICE_QUEUE DeviceQueue,
11847 IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
11848 );
11849
11850
11851NTKERNELAPI
11852BOOLEAN
11853KeSynchronizeExecution (
11854 IN PKINTERRUPT Interrupt,
11855 IN PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
11856 IN PVOID SynchronizeContext
11857 );
11858
11859NTKERNELAPI
11860KIRQL
11861KeAcquireInterruptSpinLock (
11862 IN PKINTERRUPT Interrupt
11863 );
11864
11865NTKERNELAPI
11866VOID
11867KeReleaseInterruptSpinLock (
11868 IN PKINTERRUPT Interrupt,
11869 IN KIRQL OldIrql
11870 );
11871
11872//
11873// Kernel dispatcher object functions
11874//
11875// Event Object
11876//
11877
11878
11879NTKERNELAPI
11880VOID
11881KeInitializeEvent (
11882 IN PRKEVENT Event,
11883 IN EVENT_TYPE Type,
11884 IN BOOLEAN State
11885 );
11886
11887NTKERNELAPI
11888VOID
11889KeClearEvent (
11890 IN PRKEVENT Event
11891 );
11892
11893
11894NTKERNELAPI
11895LONG
11896KePulseEvent (
11897 IN PRKEVENT Event,
11898 IN KPRIORITY Increment,
11899 IN BOOLEAN Wait
11900 );
11901
11902
11903NTKERNELAPI
11904LONG
11905KeReadStateEvent (
11906 IN PRKEVENT Event
11907 );
11908
11909NTKERNELAPI
11910LONG
11911KeResetEvent (
11912 IN PRKEVENT Event
11913 );
11914
11915NTKERNELAPI
11916LONG
11917KeSetEvent (
11918 IN PRKEVENT Event,
11919 IN KPRIORITY Increment,
11920 IN BOOLEAN Wait
11921 );
11922
11923//
11924// Mutex object
11925//
11926
11927NTKERNELAPI
11928VOID
11929KeInitializeMutex (
11930 IN PRKMUTEX Mutex,
11931 IN ULONG Level
11932 );
11933
11934NTKERNELAPI
11935LONG
11936KeReadStateMutex (
11937 IN PRKMUTEX Mutex
11938 );
11939
11940NTKERNELAPI
11941LONG
11942KeReleaseMutex (
11943 IN PRKMUTEX Mutex,
11944 IN BOOLEAN Wait
11945 );
11946
11947//
11948// Semaphore object
11949//
11950
11951NTKERNELAPI
11952VOID
11953KeInitializeSemaphore (
11954 IN PRKSEMAPHORE Semaphore,
11955 IN LONG Count,
11956 IN LONG Limit
11957 );
11958
11959NTKERNELAPI
11960LONG
11961KeReadStateSemaphore (
11962 IN PRKSEMAPHORE Semaphore
11963 );
11964
11965NTKERNELAPI
11966LONG
11967KeReleaseSemaphore (
11968 IN PRKSEMAPHORE Semaphore,
11969 IN KPRIORITY Increment,
11970 IN LONG Adjustment,
11971 IN BOOLEAN Wait
11972 );
11973
11974NTKERNELAPI
11975NTSTATUS
11976KeDelayExecutionThread (
11977 IN KPROCESSOR_MODE WaitMode,
11978 IN BOOLEAN Alertable,
11979 IN PLARGE_INTEGER Interval
11980 );
11981
11982NTKERNELAPI
11983KPRIORITY
11984KeQueryPriorityThread (
11985 IN PKTHREAD Thread
11986 );
11987
11988NTKERNELAPI
11989ULONG
11990KeQueryRuntimeThread (
11991 IN PKTHREAD Thread,
11992 OUT PULONG UserTime
11993 );
11994
11995NTKERNELAPI
11996LONG
11997KeSetBasePriorityThread (
11998 IN PKTHREAD Thread,
11999 IN LONG Increment
12000 );
12001
12002NTKERNELAPI
12003KPRIORITY
12004KeSetPriorityThread (
12005 IN PKTHREAD Thread,
12006 IN KPRIORITY Priority
12007 );
12008
12009
12010#if ((defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) ||defined(_NTHAL_)) && !defined(_NTSYSTEM_DRIVER_) || defined(_NTOSP_))
12011
12012
12013
12014NTKERNELAPI
12015VOID
12016KeEnterCriticalRegion (
12017 VOID
12018 );
12019
12020NTKERNELAPI
12021VOID
12022KeLeaveCriticalRegion (
12023 VOID
12024 );
12025
12026NTKERNELAPI
12027BOOLEAN
12028KeAreApcsDisabled (
12029 VOID
12030 );
12031
12032
12033
12034#endif
12035
12036
12037
12038//
12039// Timer object
12040//
12041
12042NTKERNELAPI
12043VOID
12044KeInitializeTimer (
12045 IN PKTIMER Timer
12046 );
12047
12048NTKERNELAPI
12049VOID
12050KeInitializeTimerEx (
12051 IN PKTIMER Timer,
12052 IN TIMER_TYPE Type
12053 );
12054
12055NTKERNELAPI
12056BOOLEAN
12057KeCancelTimer (
12058 IN PKTIMER
12059 );
12060
12061NTKERNELAPI
12062BOOLEAN
12063KeReadStateTimer (
12064 PKTIMER Timer
12065 );
12066
12067NTKERNELAPI
12068BOOLEAN
12069KeSetTimer (
12070 IN PKTIMER Timer,
12071 IN LARGE_INTEGER DueTime,
12072 IN PKDPC Dpc OPTIONAL
12073 );
12074
12075NTKERNELAPI
12076BOOLEAN
12077KeSetTimerEx (
12078 IN PKTIMER Timer,
12079 IN LARGE_INTEGER DueTime,
12080 IN LONG Period OPTIONAL,
12081 IN PKDPC Dpc OPTIONAL
12082 );
12083
12084
12085#define KeWaitForMutexObject KeWaitForSingleObject
12086
12087NTKERNELAPI
12088NTSTATUS
12089KeWaitForMultipleObjects (
12090 IN ULONG Count,
12091 IN PVOID Object[],
12092 IN WAIT_TYPE WaitType,
12093 IN KWAIT_REASON WaitReason,
12094 IN KPROCESSOR_MODE WaitMode,
12095 IN BOOLEAN Alertable,
12096 IN PLARGE_INTEGER Timeout OPTIONAL,
12097 IN PKWAIT_BLOCK WaitBlockArray OPTIONAL
12098 );
12099
12100NTKERNELAPI
12101NTSTATUS
12102KeWaitForSingleObject (
12103 IN PVOID Object,
12104 IN KWAIT_REASON WaitReason,
12105 IN KPROCESSOR_MODE WaitMode,
12106 IN BOOLEAN Alertable,
12107 IN PLARGE_INTEGER Timeout OPTIONAL
12108 );
12109
12110//
12111// Define interprocess interrupt generic call types.
12112//
12113
12114typedef
12115ULONG_PTR
12116(*PKIPI_BROADCAST_WORKER)(
12117 IN ULONG_PTR Argument
12118 );
12119
12120ULONG_PTR
12121KeIpiGenericCall (
12122 IN PKIPI_BROADCAST_WORKER BroadcastFunction,
12123 IN ULONG_PTR Context
12124 );
12125
12126
12127//
12128// On X86 the following routines are defined in the HAL and imported by
12129// all other modules.
12130//
12131
12132#if defined(_X86_) && !defined(_NTHAL_)
12133
12134#define _DECL_HAL_KE_IMPORT __declspec(dllimport)
12135
12136#else
12137
12138#define _DECL_HAL_KE_IMPORT
12139
12140#endif
12141
12142//
12143// spin lock functions
12144//
12145
12146#if defined(_X86_) && (defined(_WDMDDK_) || defined(WIN9X_COMPAT_SPINLOCK))
12147
12148NTKERNELAPI
12149VOID
12150NTAPI
12151KeInitializeSpinLock (
12152 IN PKSPIN_LOCK SpinLock
12153 );
12154
12155#else
12156
12157__inline
12158VOID
12159NTAPI
12160KeInitializeSpinLock (
12161 IN PKSPIN_LOCK SpinLock
12162 )
12163{
12164 *SpinLock = 0;
12165}
12166
12167#endif
12168
12169#if defined(_X86_)
12170
12171NTKERNELAPI
12172VOID
12173FASTCALL
12174KefAcquireSpinLockAtDpcLevel (
12175 IN PKSPIN_LOCK SpinLock
12176 );
12177
12178NTKERNELAPI
12179VOID
12180FASTCALL
12181KefReleaseSpinLockFromDpcLevel (
12182 IN PKSPIN_LOCK SpinLock
12183 );
12184
12185#define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
12186#define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
12187
12188_DECL_HAL_KE_IMPORT
12189KIRQL
12190FASTCALL
12191KfAcquireSpinLock (
12192 IN PKSPIN_LOCK SpinLock
12193 );
12194
12195_DECL_HAL_KE_IMPORT
12196VOID
12197FASTCALL
12198KfReleaseSpinLock (
12199 IN PKSPIN_LOCK SpinLock,
12200 IN KIRQL NewIrql
12201 );
12202
12203
12204#define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
12205#define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
12206
12207NTKERNELAPI
12208BOOLEAN
12209FASTCALL
12210KeTestSpinLock (
12211 IN PKSPIN_LOCK SpinLock
12212 );
12213
12214NTKERNELAPI
12215BOOLEAN
12216FASTCALL
12217KeTryToAcquireSpinLockAtDpcLevel (
12218 IN PKSPIN_LOCK SpinLock
12219 );
12220
12221#else
12222
12223//
12224// These functions are imported for IA64, ntddk, ntifs, nthal, ntosp, and wdm.
12225// They can be inlined for the system on AMD64.
12226//
12227
12228#define KeAcquireSpinLock(SpinLock, OldIrql) \
12229 *(OldIrql) = KeAcquireSpinLockRaiseToDpc(SpinLock)
12230
12231#if defined(_IA64_) || defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_) || defined(_WDMDDK_)
12232
12233
12234NTKERNELAPI
12235VOID
12236KeAcquireSpinLockAtDpcLevel (
12237 IN PKSPIN_LOCK SpinLock
12238 );
12239
12240NTKERNELAPI
12241KIRQL
12242KeAcquireSpinLockRaiseToDpc (
12243 IN PKSPIN_LOCK SpinLock
12244 );
12245
12246NTKERNELAPI
12247VOID
12248KeReleaseSpinLock (
12249 IN PKSPIN_LOCK SpinLock,
12250 IN KIRQL NewIrql
12251 );
12252
12253NTKERNELAPI
12254VOID
12255KeReleaseSpinLockFromDpcLevel (
12256 IN PKSPIN_LOCK SpinLock
12257 );
12258
12259NTKERNELAPI
12260BOOLEAN
12261FASTCALL
12262KeTestSpinLock (
12263 IN PKSPIN_LOCK SpinLock
12264 );
12265
12266NTKERNELAPI
12267BOOLEAN
12268FASTCALL
12269KeTryToAcquireSpinLockAtDpcLevel (
12270 IN PKSPIN_LOCK SpinLock
12271 );
12272
12273#else
12274
12275#if defined(_AMD64_)
12276
12277//
12278// The system version of these functions are defined in amd64.h for AMD64.
12279//
12280
12281#endif
12282
12283#endif
12284
12285#endif
12286
12287
12288#if defined(_X86_)
12289
12290_DECL_HAL_KE_IMPORT
12291VOID
12292FASTCALL
12293KfLowerIrql (
12294 IN KIRQL NewIrql
12295 );
12296
12297_DECL_HAL_KE_IMPORT
12298KIRQL
12299FASTCALL
12300KfRaiseIrql (
12301 IN KIRQL NewIrql
12302 );
12303
12304
12305
12306_DECL_HAL_KE_IMPORT
12307KIRQL
12308KeRaiseIrqlToDpcLevel(
12309 VOID
12310 );
12311
12312
12313#define KeLowerIrql(a) KfLowerIrql(a)
12314#define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
12315
12316
12317
12318
12319
12320#elif defined(_IA64_)
12321
12322//
12323// These function are defined in IA64.h for the IA64 platform.
12324//
12325
12326
12327#elif defined(_AMD64_)
12328
12329//
12330// These function are defined in amd64.h for the AMD64 platform.
12331//
12332
12333#else
12334
12335#error "no target architecture"
12336
12337#endif
12338
12339//
12340// Queued spin lock functions for "in stack" lock handles.
12341//
12342// The following three functions RAISE and LOWER IRQL when a queued
12343// in stack spin lock is acquired or released using these routines.
12344//
12345
12346_DECL_HAL_KE_IMPORT
12347VOID
12348FASTCALL
12349KeAcquireInStackQueuedSpinLock (
12350 IN PKSPIN_LOCK SpinLock,
12351 IN PKLOCK_QUEUE_HANDLE LockHandle
12352 );
12353
12354
12355_DECL_HAL_KE_IMPORT
12356VOID
12357FASTCALL
12358KeReleaseInStackQueuedSpinLock (
12359 IN PKLOCK_QUEUE_HANDLE LockHandle
12360 );
12361
12362//
12363// The following two functions do NOT raise or lower IRQL when a queued
12364// in stack spin lock is acquired or released using these functions.
12365//
12366
12367NTKERNELAPI
12368VOID
12369FASTCALL
12370KeAcquireInStackQueuedSpinLockAtDpcLevel (
12371 IN PKSPIN_LOCK SpinLock,
12372 IN PKLOCK_QUEUE_HANDLE LockHandle
12373 );
12374
12375NTKERNELAPI
12376VOID
12377FASTCALL
12378KeReleaseInStackQueuedSpinLockFromDpcLevel (
12379 IN PKLOCK_QUEUE_HANDLE LockHandle
12380 );
12381
12382//
12383// Miscellaneous kernel functions
12384//
12385
12386typedef enum _KBUGCHECK_BUFFER_DUMP_STATE {
12387 BufferEmpty,
12388 BufferInserted,
12389 BufferStarted,
12390 BufferFinished,
12391 BufferIncomplete
12392} KBUGCHECK_BUFFER_DUMP_STATE;
12393
12394typedef
12395VOID
12396(*PKBUGCHECK_CALLBACK_ROUTINE) (
12397 IN PVOID Buffer,
12398 IN ULONG Length
12399 );
12400
12401typedef struct _KBUGCHECK_CALLBACK_RECORD {
12402 LIST_ENTRY Entry;
12403 PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine;
12404 PVOID Buffer;
12405 ULONG Length;
12406 PUCHAR Component;
12407 ULONG_PTR Checksum;
12408 UCHAR State;
12409} KBUGCHECK_CALLBACK_RECORD, *PKBUGCHECK_CALLBACK_RECORD;
12410
12411#define KeInitializeCallbackRecord(CallbackRecord) \
12412 (CallbackRecord)->State = BufferEmpty
12413
12414NTKERNELAPI
12415BOOLEAN
12416KeDeregisterBugCheckCallback (
12417 IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
12418 );
12419
12420NTKERNELAPI
12421BOOLEAN
12422KeRegisterBugCheckCallback (
12423 IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord,
12424 IN PKBUGCHECK_CALLBACK_ROUTINE CallbackRoutine,
12425 IN PVOID Buffer,
12426 IN ULONG Length,
12427 IN PUCHAR Component
12428 );
12429
12430typedef enum _KBUGCHECK_CALLBACK_REASON {
12431 KbCallbackInvalid,
12432 KbCallbackReserved1,
12433 KbCallbackSecondaryDumpData,
12434 KbCallbackDumpIo,
12435} KBUGCHECK_CALLBACK_REASON;
12436
12437typedef
12438VOID
12439(*PKBUGCHECK_REASON_CALLBACK_ROUTINE) (
12440 IN KBUGCHECK_CALLBACK_REASON Reason,
12441 IN struct _KBUGCHECK_REASON_CALLBACK_RECORD* Record,
12442 IN OUT PVOID ReasonSpecificData,
12443 IN ULONG ReasonSpecificDataLength
12444 );
12445
12446typedef struct _KBUGCHECK_REASON_CALLBACK_RECORD {
12447 LIST_ENTRY Entry;
12448 PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine;
12449 PUCHAR Component;
12450 ULONG_PTR Checksum;
12451 KBUGCHECK_CALLBACK_REASON Reason;
12452 UCHAR State;
12453} KBUGCHECK_REASON_CALLBACK_RECORD, *PKBUGCHECK_REASON_CALLBACK_RECORD;
12454
12455typedef struct _KBUGCHECK_SECONDARY_DUMP_DATA {
12456 IN PVOID InBuffer;
12457 IN ULONG InBufferLength;
12458 IN ULONG MaximumAllowed;
12459 OUT GUID Guid;
12460 OUT PVOID OutBuffer;
12461 OUT ULONG OutBufferLength;
12462} KBUGCHECK_SECONDARY_DUMP_DATA, *PKBUGCHECK_SECONDARY_DUMP_DATA;
12463
12464typedef enum _KBUGCHECK_DUMP_IO_TYPE
12465{
12466 KbDumpIoInvalid,
12467 KbDumpIoHeader,
12468 KbDumpIoBody,
12469 KbDumpIoSecondaryData,
12470 KbDumpIoComplete
12471} KBUGCHECK_DUMP_IO_TYPE;
12472
12473typedef struct _KBUGCHECK_DUMP_IO {
12474 IN ULONG64 Offset;
12475 IN PVOID Buffer;
12476 IN ULONG BufferLength;
12477 IN KBUGCHECK_DUMP_IO_TYPE Type;
12478} KBUGCHECK_DUMP_IO, *PKBUGCHECK_DUMP_IO;
12479
12480NTKERNELAPI
12481BOOLEAN
12482KeDeregisterBugCheckReasonCallback (
12483 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
12484 );
12485
12486NTKERNELAPI
12487BOOLEAN
12488KeRegisterBugCheckReasonCallback (
12489 IN PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord,
12490 IN PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine,
12491 IN KBUGCHECK_CALLBACK_REASON Reason,
12492 IN PUCHAR Component
12493 );
12494
12495typedef
12496BOOLEAN
12497(*PNMI_CALLBACK)(
12498 IN PVOID Context,
12499 IN BOOLEAN Handled
12500 );
12501
12502NTKERNELAPI
12503PVOID
12504KeRegisterNmiCallback(
12505 PNMI_CALLBACK CallbackRoutine,
12506 PVOID Context
12507 );
12508
12509NTSTATUS
12510KeDeregisterNmiCallback(
12511 PVOID Handle
12512 );
12513
12514
12515
12516NTKERNELAPI
12517DECLSPEC_NORETURN
12518VOID
12519NTAPI
12520KeBugCheck (
12521 IN ULONG BugCheckCode
12522 );
12523
12524
12525NTKERNELAPI
12526DECLSPEC_NORETURN
12527VOID
12528KeBugCheckEx(
12529 IN ULONG BugCheckCode,
12530 IN ULONG_PTR BugCheckParameter1,
12531 IN ULONG_PTR BugCheckParameter2,
12532 IN ULONG_PTR BugCheckParameter3,
12533 IN ULONG_PTR BugCheckParameter4
12534 );
12535
12536
12537#if defined(_AMD64_) || defined(_X86_)
12538
12539NTKERNELAPI
12540BOOLEAN
12541KeInvalidateAllCaches (
12542 VOID
12543 );
12544
12545#endif
12546
12547
12548#if !defined(_AMD64_)
12549
12550NTKERNELAPI
12551ULONGLONG
12552KeQueryInterruptTime (
12553 VOID
12554 );
12555
12556NTKERNELAPI
12557VOID
12558KeQuerySystemTime (
12559 OUT PLARGE_INTEGER CurrentTime
12560 );
12561
12562#endif
12563
12564NTKERNELAPI
12565ULONG
12566KeQueryTimeIncrement (
12567 VOID
12568 );
12569
12570NTKERNELAPI
12571ULONG
12572KeGetRecommendedSharedDataAlignment (
12573 VOID
12574 );
12575
12576
12577
12578NTKERNELAPI
12579KAFFINITY
12580KeQueryActiveProcessors (
12581 VOID
12582 );
12583
12584
12585#if defined(_IA64_)
12586
12587extern volatile LARGE_INTEGER KeTickCount;
12588
12589#elif defined(_X86_)
12590
12591extern volatile KSYSTEM_TIME KeTickCount;
12592
12593#endif
12594
12595
12596typedef enum _MEMORY_CACHING_TYPE_ORIG {
12597 MmFrameBufferCached = 2
12598} MEMORY_CACHING_TYPE_ORIG;
12599
12600typedef enum _MEMORY_CACHING_TYPE {
12601 MmNonCached = FALSE,
12602 MmCached = TRUE,
12603 MmWriteCombined = MmFrameBufferCached,
12604 MmHardwareCoherentCached,
12605 MmNonCachedUnordered, // IA64
12606 MmUSWCCached,
12607 MmMaximumCacheType
12608} MEMORY_CACHING_TYPE;
12609
12610//
12611// Define external data.
12612// because of indirection for all drivers external to ntoskrnl these are actually ptrs
12613//
12614
12615#if defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_WDMDDK_) || defined(_NTOSP_)
12616
12617extern PBOOLEAN KdDebuggerNotPresent;
12618extern PBOOLEAN KdDebuggerEnabled;
12619#define KD_DEBUGGER_ENABLED *KdDebuggerEnabled
12620#define KD_DEBUGGER_NOT_PRESENT *KdDebuggerNotPresent
12621
12622#else
12623
12624extern BOOLEAN KdDebuggerNotPresent;
12625extern BOOLEAN KdDebuggerEnabled;
12626#define KD_DEBUGGER_ENABLED KdDebuggerEnabled
12627#define KD_DEBUGGER_NOT_PRESENT KdDebuggerNotPresent
12628
12629#endif
12630
12631
12632
12633
12634NTSTATUS
12635KdDisableDebugger(
12636 VOID
12637 );
12638
12639NTSTATUS
12640KdEnableDebugger(
12641 VOID
12642 );
12643
12644//
12645// KdRefreshDebuggerPresent attempts to communicate with
12646// the debugger host machine to refresh the state of
12647// KdDebuggerNotPresent. It returns the state of
12648// KdDebuggerNotPresent while the kd locks are held.
12649// KdDebuggerNotPresent may immediately change state
12650// after the kd locks are released so it may not
12651// match the return value.
12652//
12653
12654BOOLEAN
12655KdRefreshDebuggerNotPresent(
12656 VOID
12657 );
12658
12659//
12660// Pool Allocation routines (in pool.c)
12661//
12662
12663typedef enum _POOL_TYPE {
12664 NonPagedPool,
12665 PagedPool,
12666 NonPagedPoolMustSucceed,
12667 DontUseThisType,
12668 NonPagedPoolCacheAligned,
12669 PagedPoolCacheAligned,
12670 NonPagedPoolCacheAlignedMustS,
12671 MaxPoolType
12672
12673
12674 ,
12675 //
12676 // Note these per session types are carefully chosen so that the appropriate
12677 // masking still applies as well as MaxPoolType above.
12678 //
12679
12680 NonPagedPoolSession = 32,
12681 PagedPoolSession = NonPagedPoolSession + 1,
12682 NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
12683 DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
12684 NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
12685 PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
12686 NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1,
12687
12688
12689
12690 } POOL_TYPE;
12691
12692#define POOL_COLD_ALLOCATION 256 // Note this cannot encode into the header.
12693
12694
12695DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithTag
12696NTKERNELAPI
12697PVOID
12698ExAllocatePool(
12699 IN POOL_TYPE PoolType,
12700 IN SIZE_T NumberOfBytes
12701 );
12702
12703DECLSPEC_DEPRECATED_DDK // Use ExAllocatePoolWithQuotaTag
12704NTKERNELAPI
12705PVOID
12706ExAllocatePoolWithQuota(
12707 IN POOL_TYPE PoolType,
12708 IN SIZE_T NumberOfBytes
12709 );
12710
12711NTKERNELAPI
12712PVOID
12713NTAPI
12714ExAllocatePoolWithTag(
12715 IN POOL_TYPE PoolType,
12716 IN SIZE_T NumberOfBytes,
12717 IN ULONG Tag
12718 );
12719
12720//
12721// _EX_POOL_PRIORITY_ provides a method for the system to handle requests
12722// intelligently in low resource conditions.
12723//
12724// LowPoolPriority should be used when it is acceptable to the driver for the
12725// mapping request to fail if the system is low on resources. An example of
12726// this could be for a non-critical network connection where the driver can
12727// handle the failure case when system resources are close to being depleted.
12728//
12729// NormalPoolPriority should be used when it is acceptable to the driver for the
12730// mapping request to fail if the system is very low on resources. An example
12731// of this could be for a non-critical local filesystem request.
12732//
12733// HighPoolPriority should be used when it is unacceptable to the driver for the
12734// mapping request to fail unless the system is completely out of resources.
12735// An example of this would be the paging file path in a driver.
12736//
12737// SpecialPool can be specified to bound the allocation at a page end (or
12738// beginning). This should only be done on systems being debugged as the
12739// memory cost is expensive.
12740//
12741// N.B. These values are very carefully chosen so that the pool allocation
12742// code can quickly crack the priority request.
12743//
12744
12745typedef enum _EX_POOL_PRIORITY {
12746 LowPoolPriority,
12747 LowPoolPrioritySpecialPoolOverrun = 8,
12748 LowPoolPrioritySpecialPoolUnderrun = 9,
12749 NormalPoolPriority = 16,
12750 NormalPoolPrioritySpecialPoolOverrun = 24,
12751 NormalPoolPrioritySpecialPoolUnderrun = 25,
12752 HighPoolPriority = 32,
12753 HighPoolPrioritySpecialPoolOverrun = 40,
12754 HighPoolPrioritySpecialPoolUnderrun = 41
12755
12756 } EX_POOL_PRIORITY;
12757
12758NTKERNELAPI
12759PVOID
12760NTAPI
12761ExAllocatePoolWithTagPriority(
12762 IN POOL_TYPE PoolType,
12763 IN SIZE_T NumberOfBytes,
12764 IN ULONG Tag,
12765 IN EX_POOL_PRIORITY Priority
12766 );
12767
12768#ifndef POOL_TAGGING
12769#define ExAllocatePoolWithTag(a,b,c) ExAllocatePool(a,b)
12770#endif //POOL_TAGGING
12771
12772NTKERNELAPI
12773PVOID
12774ExAllocatePoolWithQuotaTag(
12775 IN POOL_TYPE PoolType,
12776 IN SIZE_T NumberOfBytes,
12777 IN ULONG Tag
12778 );
12779
12780#ifndef POOL_TAGGING
12781#define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
12782#endif //POOL_TAGGING
12783
12784NTKERNELAPI
12785VOID
12786NTAPI
12787ExFreePool(
12788 IN PVOID P
12789 );
12790
12791
12792#if defined(POOL_TAGGING)
12793#define ExFreePool(a) ExFreePoolWithTag(a,0)
12794#endif
12795
12796//
12797// If high order bit in Pool tag is set, then must use ExFreePoolWithTag to free
12798//
12799
12800#define PROTECTED_POOL 0x80000000
12801
12802
12803NTKERNELAPI
12804VOID
12805ExFreePoolWithTag(
12806 IN PVOID P,
12807 IN ULONG Tag
12808 );
12809
12810//
12811// Routines to support fast mutexes.
12812//
12813
12814typedef struct _FAST_MUTEX {
12815 LONG Count;
12816 PKTHREAD Owner;
12817 ULONG Contention;
12818 KEVENT Event;
12819 ULONG OldIrql;
12820} FAST_MUTEX, *PFAST_MUTEX;
12821
12822#define ExInitializeFastMutex(_FastMutex) \
12823 (_FastMutex)->Count = 1; \
12824 (_FastMutex)->Owner = NULL; \
12825 (_FastMutex)->Contention = 0; \
12826 KeInitializeEvent(&(_FastMutex)->Event, \
12827 SynchronizationEvent, \
12828 FALSE);
12829
12830
12831NTKERNELAPI
12832VOID
12833FASTCALL
12834ExAcquireFastMutexUnsafe (
12835 IN PFAST_MUTEX FastMutex
12836 );
12837
12838NTKERNELAPI
12839VOID
12840FASTCALL
12841ExReleaseFastMutexUnsafe (
12842 IN PFAST_MUTEX FastMutex
12843 );
12844
12845
12846#if defined(_IA64_) || defined(_AMD64_)
12847
12848NTKERNELAPI
12849VOID
12850FASTCALL
12851ExAcquireFastMutex (
12852 IN PFAST_MUTEX FastMutex
12853 );
12854
12855NTKERNELAPI
12856VOID
12857FASTCALL
12858ExReleaseFastMutex (
12859 IN PFAST_MUTEX FastMutex
12860 );
12861
12862NTKERNELAPI
12863BOOLEAN
12864FASTCALL
12865ExTryToAcquireFastMutex (
12866 IN PFAST_MUTEX FastMutex
12867 );
12868
12869#elif defined(_X86_)
12870
12871NTHALAPI
12872VOID
12873FASTCALL
12874ExAcquireFastMutex (
12875 IN PFAST_MUTEX FastMutex
12876 );
12877
12878NTHALAPI
12879VOID
12880FASTCALL
12881ExReleaseFastMutex (
12882 IN PFAST_MUTEX FastMutex
12883 );
12884
12885NTHALAPI
12886BOOLEAN
12887FASTCALL
12888ExTryToAcquireFastMutex (
12889 IN PFAST_MUTEX FastMutex
12890 );
12891
12892#else
12893
12894#error "Target architecture not defined"
12895
12896#endif
12897
12898//
12899
12900#if defined(_WIN64)
12901
12902#define ExInterlockedAddLargeStatistic(Addend, Increment) \
12903 (VOID) InterlockedAdd64(&(Addend)->QuadPart, Increment)
12904
12905#else
12906
12907#ifdef __cplusplus
12908extern "C" {
12909#endif
12910
12911LONG
12912_InterlockedAddLargeStatistic (
12913 IN PLONGLONG Addend,
12914 IN ULONG Increment
12915 );
12916
12917#ifdef __cplusplus
12918}
12919#endif
12920
12921#pragma intrinsic (_InterlockedAddLargeStatistic)
12922
12923#define ExInterlockedAddLargeStatistic(Addend,Increment) \
12924 (VOID) _InterlockedAddLargeStatistic ((PLONGLONG)&(Addend)->QuadPart, Increment)
12925
12926#endif
12927
12928
12929
12930NTKERNELAPI
12931LARGE_INTEGER
12932ExInterlockedAddLargeInteger (
12933 IN PLARGE_INTEGER Addend,
12934 IN LARGE_INTEGER Increment,
12935 IN PKSPIN_LOCK Lock
12936 );
12937
12938
12939NTKERNELAPI
12940ULONG
12941FASTCALL
12942ExInterlockedAddUlong (
12943 IN PULONG Addend,
12944 IN ULONG Increment,
12945 IN PKSPIN_LOCK Lock
12946 );
12947
12948
12949#if defined(_AMD64_) || defined(_AXP64_) || defined(_IA64_)
12950
12951#define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
12952 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
12953
12954#elif defined(_ALPHA_)
12955
12956#define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
12957 ExpInterlockedCompareExchange64(Destination, Exchange, Comperand)
12958
12959#else
12960
12961#define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
12962 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
12963
12964#endif
12965
12966NTKERNELAPI
12967PLIST_ENTRY
12968FASTCALL
12969ExInterlockedInsertHeadList (
12970 IN PLIST_ENTRY ListHead,
12971 IN PLIST_ENTRY ListEntry,
12972 IN PKSPIN_LOCK Lock
12973 );
12974
12975NTKERNELAPI
12976PLIST_ENTRY
12977FASTCALL
12978ExInterlockedInsertTailList (
12979 IN PLIST_ENTRY ListHead,
12980 IN PLIST_ENTRY ListEntry,
12981 IN PKSPIN_LOCK Lock
12982 );
12983
12984NTKERNELAPI
12985PLIST_ENTRY
12986FASTCALL
12987ExInterlockedRemoveHeadList (
12988 IN PLIST_ENTRY ListHead,
12989 IN PKSPIN_LOCK Lock
12990 );
12991
12992NTKERNELAPI
12993PSINGLE_LIST_ENTRY
12994FASTCALL
12995ExInterlockedPopEntryList (
12996 IN PSINGLE_LIST_ENTRY ListHead,
12997 IN PKSPIN_LOCK Lock
12998 );
12999
13000NTKERNELAPI
13001PSINGLE_LIST_ENTRY
13002FASTCALL
13003ExInterlockedPushEntryList (
13004 IN PSINGLE_LIST_ENTRY ListHead,
13005 IN PSINGLE_LIST_ENTRY ListEntry,
13006 IN PKSPIN_LOCK Lock
13007 );
13008
13009//
13010// Define interlocked sequenced listhead functions.
13011//
13012// A sequenced interlocked list is a singly linked list with a header that
13013// contains the current depth and a sequence number. Each time an entry is
13014// inserted or removed from the list the depth is updated and the sequence
13015// number is incremented. This enables AMD64, IA64, and Pentium and later
13016// machines to insert and remove from the list without the use of spinlocks.
13017//
13018
13019#if !defined(_WINBASE_)
13020
13021/*++
13022
13023Routine Description:
13024
13025 This function initializes a sequenced singly linked listhead.
13026
13027Arguments:
13028
13029 SListHead - Supplies a pointer to a sequenced singly linked listhead.
13030
13031Return Value:
13032
13033 None.
13034
13035--*/
13036
13037#if defined(_WIN64) && (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
13038
13039NTKERNELAPI
13040VOID
13041InitializeSListHead (
13042 IN PSLIST_HEADER SListHead
13043 );
13044
13045#else
13046
13047__inline
13048VOID
13049InitializeSListHead (
13050 IN PSLIST_HEADER SListHead
13051 )
13052
13053{
13054
13055#ifdef _WIN64
13056
13057 //
13058 // Slist headers must be 16 byte aligned.
13059 //
13060
13061 if ((ULONG_PTR) SListHead & 0x0f) {
13062
13063 DbgPrint( "InitializeSListHead unaligned Slist header. Address = %p, Caller = %p\n", SListHead, _ReturnAddress());
13064 RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
13065 }
13066
13067#endif
13068
13069 SListHead->Alignment = 0;
13070
13071 //
13072 // For IA-64 we save the region number of the elements of the list in a
13073 // separate field. This imposes the requirement that all elements stored
13074 // in the list are from the same region.
13075
13076#if defined(_IA64_)
13077
13078 SListHead->Region = (ULONG_PTR)SListHead & VRN_MASK;
13079
13080#elif defined(_AMD64_)
13081
13082 SListHead->Region = 0;
13083
13084#endif
13085
13086 return;
13087}
13088
13089#endif
13090
13091#endif // !defined(_WINBASE_)
13092
13093#define ExInitializeSListHead InitializeSListHead
13094
13095PSLIST_ENTRY
13096FirstEntrySList (
13097 IN const SLIST_HEADER *SListHead
13098 );
13099
13100/*++
13101
13102Routine Description:
13103
13104 This function queries the current number of entries contained in a
13105 sequenced single linked list.
13106
13107Arguments:
13108
13109 SListHead - Supplies a pointer to the sequenced listhead which is
13110 be queried.
13111
13112Return Value:
13113
13114 The current number of entries in the sequenced singly linked list is
13115 returned as the function value.
13116
13117--*/
13118
13119#if defined(_WIN64)
13120
13121#if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_))
13122
13123NTKERNELAPI
13124USHORT
13125ExQueryDepthSList (
13126 IN PSLIST_HEADER SListHead
13127 );
13128
13129#else
13130
13131__inline
13132USHORT
13133ExQueryDepthSList (
13134 IN PSLIST_HEADER SListHead
13135 )
13136
13137{
13138
13139 return (USHORT)(SListHead->Alignment & 0xffff);
13140}
13141
13142#endif
13143
13144#else
13145
13146#define ExQueryDepthSList(_listhead_) (_listhead_)->Depth
13147
13148#endif
13149
13150#if defined(_WIN64)
13151
13152#define ExInterlockedPopEntrySList(Head, Lock) \
13153 ExpInterlockedPopEntrySList(Head)
13154
13155#define ExInterlockedPushEntrySList(Head, Entry, Lock) \
13156 ExpInterlockedPushEntrySList(Head, Entry)
13157
13158#define ExInterlockedFlushSList(Head) \
13159 ExpInterlockedFlushSList(Head)
13160
13161#if !defined(_WINBASE_)
13162
13163#define InterlockedPopEntrySList(Head) \
13164 ExpInterlockedPopEntrySList(Head)
13165
13166#define InterlockedPushEntrySList(Head, Entry) \
13167 ExpInterlockedPushEntrySList(Head, Entry)
13168
13169#define InterlockedFlushSList(Head) \
13170 ExpInterlockedFlushSList(Head)
13171
13172#define QueryDepthSList(Head) \
13173 ExQueryDepthSList(Head)
13174
13175#endif // !defined(_WINBASE_)
13176
13177NTKERNELAPI
13178PSLIST_ENTRY
13179ExpInterlockedPopEntrySList (
13180 IN PSLIST_HEADER ListHead
13181 );
13182
13183NTKERNELAPI
13184PSLIST_ENTRY
13185ExpInterlockedPushEntrySList (
13186 IN PSLIST_HEADER ListHead,
13187 IN PSLIST_ENTRY ListEntry
13188 );
13189
13190NTKERNELAPI
13191PSLIST_ENTRY
13192ExpInterlockedFlushSList (
13193 IN PSLIST_HEADER ListHead
13194 );
13195
13196#else
13197
13198#if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
13199
13200NTKERNELAPI
13201PSLIST_ENTRY
13202FASTCALL
13203ExInterlockedPopEntrySList (
13204 IN PSLIST_HEADER ListHead,
13205 IN PKSPIN_LOCK Lock
13206 );
13207
13208NTKERNELAPI
13209PSLIST_ENTRY
13210FASTCALL
13211ExInterlockedPushEntrySList (
13212 IN PSLIST_HEADER ListHead,
13213 IN PSLIST_ENTRY ListEntry,
13214 IN PKSPIN_LOCK Lock
13215 );
13216
13217#else
13218
13219#define ExInterlockedPopEntrySList(ListHead, Lock) \
13220 InterlockedPopEntrySList(ListHead)
13221
13222#define ExInterlockedPushEntrySList(ListHead, ListEntry, Lock) \
13223 InterlockedPushEntrySList(ListHead, ListEntry)
13224
13225#endif
13226
13227NTKERNELAPI
13228PSLIST_ENTRY
13229FASTCALL
13230ExInterlockedFlushSList (
13231 IN PSLIST_HEADER ListHead
13232 );
13233
13234#if !defined(_WINBASE_)
13235
13236NTKERNELAPI
13237PSLIST_ENTRY
13238FASTCALL
13239InterlockedPopEntrySList (
13240 IN PSLIST_HEADER ListHead
13241 );
13242
13243NTKERNELAPI
13244PSLIST_ENTRY
13245FASTCALL
13246InterlockedPushEntrySList (
13247 IN PSLIST_HEADER ListHead,
13248 IN PSLIST_ENTRY ListEntry
13249 );
13250
13251#define InterlockedFlushSList(Head) \
13252 ExInterlockedFlushSList(Head)
13253
13254#define QueryDepthSList(Head) \
13255 ExQueryDepthSList(Head)
13256
13257#endif // !defined(_WINBASE_)
13258
13259#endif // defined(_WIN64)
13260
13261
13262typedef
13263PVOID
13264(*PALLOCATE_FUNCTION) (
13265 IN POOL_TYPE PoolType,
13266 IN SIZE_T NumberOfBytes,
13267 IN ULONG Tag
13268 );
13269
13270typedef
13271VOID
13272(*PFREE_FUNCTION) (
13273 IN PVOID Buffer
13274 );
13275
13276#if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
13277
13278typedef struct _GENERAL_LOOKASIDE {
13279
13280#else
13281
13282typedef struct DECLSPEC_CACHEALIGN _GENERAL_LOOKASIDE {
13283
13284#endif
13285
13286 SLIST_HEADER ListHead;
13287 USHORT Depth;
13288 USHORT MaximumDepth;
13289 ULONG TotalAllocates;
13290 union {
13291 ULONG AllocateMisses;
13292 ULONG AllocateHits;
13293 };
13294
13295 ULONG TotalFrees;
13296 union {
13297 ULONG FreeMisses;
13298 ULONG FreeHits;
13299 };
13300
13301 POOL_TYPE Type;
13302 ULONG Tag;
13303 ULONG Size;
13304 PALLOCATE_FUNCTION Allocate;
13305 PFREE_FUNCTION Free;
13306 LIST_ENTRY ListEntry;
13307 ULONG LastTotalAllocates;
13308 union {
13309 ULONG LastAllocateMisses;
13310 ULONG LastAllocateHits;
13311 };
13312
13313 ULONG Future[2];
13314} GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
13315
13316#if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
13317
13318typedef struct _NPAGED_LOOKASIDE_LIST {
13319
13320#else
13321
13322typedef struct DECLSPEC_CACHEALIGN _NPAGED_LOOKASIDE_LIST {
13323
13324#endif
13325
13326 GENERAL_LOOKASIDE L;
13327
13328#if !defined(_AMD64_) && !defined(_IA64_)
13329
13330 KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
13331
13332#endif
13333
13334} NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
13335
13336NTKERNELAPI
13337VOID
13338ExInitializeNPagedLookasideList (
13339 IN PNPAGED_LOOKASIDE_LIST Lookaside,
13340 IN PALLOCATE_FUNCTION Allocate,
13341 IN PFREE_FUNCTION Free,
13342 IN ULONG Flags,
13343 IN SIZE_T Size,
13344 IN ULONG Tag,
13345 IN USHORT Depth
13346 );
13347
13348NTKERNELAPI
13349VOID
13350ExDeleteNPagedLookasideList (
13351 IN PNPAGED_LOOKASIDE_LIST Lookaside
13352 );
13353
13354__inline
13355PVOID
13356ExAllocateFromNPagedLookasideList(
13357 IN PNPAGED_LOOKASIDE_LIST Lookaside
13358 )
13359
13360/*++
13361
13362Routine Description:
13363
13364 This function removes (pops) the first entry from the specified
13365 nonpaged lookaside list.
13366
13367Arguments:
13368
13369 Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
13370
13371Return Value:
13372
13373 If an entry is removed from the specified lookaside list, then the
13374 address of the entry is returned as the function value. Otherwise,
13375 NULL is returned.
13376
13377--*/
13378
13379{
13380
13381 PVOID Entry;
13382
13383 Lookaside->L.TotalAllocates += 1;
13384
13385#if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
13386
13387 Entry = ExInterlockedPopEntrySList(&Lookaside->L.ListHead,
13388 &Lookaside->Lock__ObsoleteButDoNotDelete);
13389
13390
13391#else
13392
13393 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
13394
13395#endif
13396
13397 if (Entry == NULL) {
13398 Lookaside->L.AllocateMisses += 1;
13399 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
13400 Lookaside->L.Size,
13401 Lookaside->L.Tag);
13402 }
13403
13404 return Entry;
13405}
13406
13407__inline
13408VOID
13409ExFreeToNPagedLookasideList(
13410 IN PNPAGED_LOOKASIDE_LIST Lookaside,
13411 IN PVOID Entry
13412 )
13413
13414/*++
13415
13416Routine Description:
13417
13418 This function inserts (pushes) the specified entry into the specified
13419 nonpaged lookaside list.
13420
13421Arguments:
13422
13423 Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
13424
13425 Entry - Supples a pointer to the entry that is inserted in the
13426 lookaside list.
13427
13428Return Value:
13429
13430 None.
13431
13432--*/
13433
13434{
13435
13436 Lookaside->L.TotalFrees += 1;
13437 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
13438 Lookaside->L.FreeMisses += 1;
13439 (Lookaside->L.Free)(Entry);
13440
13441 } else {
13442
13443#if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
13444
13445 ExInterlockedPushEntrySList(&Lookaside->L.ListHead,
13446 (PSLIST_ENTRY)Entry,
13447 &Lookaside->Lock__ObsoleteButDoNotDelete);
13448
13449#else
13450
13451 InterlockedPushEntrySList(&Lookaside->L.ListHead,
13452 (PSLIST_ENTRY)Entry);
13453
13454#endif
13455
13456 }
13457 return;
13458}
13459
13460
13461
13462#if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
13463
13464typedef struct _PAGED_LOOKASIDE_LIST {
13465
13466#else
13467
13468typedef struct DECLSPEC_CACHEALIGN _PAGED_LOOKASIDE_LIST {
13469
13470#endif
13471
13472 GENERAL_LOOKASIDE L;
13473
13474#if !defined(_AMD64_) && !defined(_IA64_)
13475
13476 FAST_MUTEX Lock__ObsoleteButDoNotDelete;
13477
13478#endif
13479
13480} PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
13481
13482
13483NTKERNELAPI
13484VOID
13485ExInitializePagedLookasideList (
13486 IN PPAGED_LOOKASIDE_LIST Lookaside,
13487 IN PALLOCATE_FUNCTION Allocate,
13488 IN PFREE_FUNCTION Free,
13489 IN ULONG Flags,
13490 IN SIZE_T Size,
13491 IN ULONG Tag,
13492 IN USHORT Depth
13493 );
13494
13495NTKERNELAPI
13496VOID
13497ExDeletePagedLookasideList (
13498 IN PPAGED_LOOKASIDE_LIST Lookaside
13499 );
13500
13501#if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
13502
13503NTKERNELAPI
13504PVOID
13505ExAllocateFromPagedLookasideList(
13506 IN PPAGED_LOOKASIDE_LIST Lookaside
13507 );
13508
13509#else
13510
13511__inline
13512PVOID
13513ExAllocateFromPagedLookasideList(
13514 IN PPAGED_LOOKASIDE_LIST Lookaside
13515 )
13516
13517/*++
13518
13519Routine Description:
13520
13521 This function removes (pops) the first entry from the specified
13522 paged lookaside list.
13523
13524Arguments:
13525
13526 Lookaside - Supplies a pointer to a paged lookaside list structure.
13527
13528Return Value:
13529
13530 If an entry is removed from the specified lookaside list, then the
13531 address of the entry is returned as the function value. Otherwise,
13532 NULL is returned.
13533
13534--*/
13535
13536{
13537
13538 PVOID Entry;
13539
13540 Lookaside->L.TotalAllocates += 1;
13541 Entry = InterlockedPopEntrySList(&Lookaside->L.ListHead);
13542 if (Entry == NULL) {
13543 Lookaside->L.AllocateMisses += 1;
13544 Entry = (Lookaside->L.Allocate)(Lookaside->L.Type,
13545 Lookaside->L.Size,
13546 Lookaside->L.Tag);
13547 }
13548
13549 return Entry;
13550}
13551
13552#endif
13553
13554#if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
13555
13556NTKERNELAPI
13557VOID
13558ExFreeToPagedLookasideList(
13559 IN PPAGED_LOOKASIDE_LIST Lookaside,
13560 IN PVOID Entry
13561 );
13562
13563#else
13564
13565__inline
13566VOID
13567ExFreeToPagedLookasideList(
13568 IN PPAGED_LOOKASIDE_LIST Lookaside,
13569 IN PVOID Entry
13570 )
13571
13572/*++
13573
13574Routine Description:
13575
13576 This function inserts (pushes) the specified entry into the specified
13577 paged lookaside list.
13578
13579Arguments:
13580
13581 Lookaside - Supplies a pointer to a nonpaged lookaside list structure.
13582
13583 Entry - Supples a pointer to the entry that is inserted in the
13584 lookaside list.
13585
13586Return Value:
13587
13588 None.
13589
13590--*/
13591
13592{
13593
13594 Lookaside->L.TotalFrees += 1;
13595 if (ExQueryDepthSList(&Lookaside->L.ListHead) >= Lookaside->L.Depth) {
13596 Lookaside->L.FreeMisses += 1;
13597 (Lookaside->L.Free)(Entry);
13598
13599 } else {
13600 InterlockedPushEntrySList(&Lookaside->L.ListHead,
13601 (PSLIST_ENTRY)Entry);
13602 }
13603
13604 return;
13605}
13606
13607#endif
13608
13609
13610NTKERNELAPI
13611VOID
13612NTAPI
13613ProbeForRead(
13614 IN CONST VOID *Address,
13615 IN SIZE_T Length,
13616 IN ULONG Alignment
13617 );
13618
13619//
13620// Common probe for write functions.
13621//
13622
13623NTKERNELAPI
13624VOID
13625NTAPI
13626ProbeForWrite (
13627 IN PVOID Address,
13628 IN SIZE_T Length,
13629 IN ULONG Alignment
13630 );
13631
13632//
13633// Worker Thread
13634//
13635
13636typedef enum _WORK_QUEUE_TYPE {
13637 CriticalWorkQueue,
13638 DelayedWorkQueue,
13639 HyperCriticalWorkQueue,
13640 MaximumWorkQueue
13641} WORK_QUEUE_TYPE;
13642
13643typedef
13644VOID
13645(*PWORKER_THREAD_ROUTINE)(
13646 IN PVOID Parameter
13647 );
13648
13649typedef struct _WORK_QUEUE_ITEM {
13650 LIST_ENTRY List;
13651 PWORKER_THREAD_ROUTINE WorkerRoutine;
13652 PVOID Parameter;
13653} WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
13654
13655#if PRAGMA_DEPRECATED_DDK
13656#pragma deprecated(ExInitializeWorkItem) // Use IoAllocateWorkItem
13657#endif
13658#define ExInitializeWorkItem(Item, Routine, Context) \
13659 (Item)->WorkerRoutine = (Routine); \
13660 (Item)->Parameter = (Context); \
13661 (Item)->List.Flink = NULL;
13662
13663DECLSPEC_DEPRECATED_DDK // Use IoQueueWorkItem
13664NTKERNELAPI
13665VOID
13666ExQueueWorkItem(
13667 IN PWORK_QUEUE_ITEM WorkItem,
13668 IN WORK_QUEUE_TYPE QueueType
13669 );
13670
13671
13672NTKERNELAPI
13673BOOLEAN
13674ExIsProcessorFeaturePresent(
13675 ULONG ProcessorFeature
13676 );
13677
13678//
13679// Zone Allocation
13680//
13681
13682typedef struct _ZONE_SEGMENT_HEADER {
13683 SINGLE_LIST_ENTRY SegmentList;
13684 PVOID Reserved;
13685} ZONE_SEGMENT_HEADER, *PZONE_SEGMENT_HEADER;
13686
13687typedef struct _ZONE_HEADER {
13688 SINGLE_LIST_ENTRY FreeList;
13689 SINGLE_LIST_ENTRY SegmentList;
13690 ULONG BlockSize;
13691 ULONG TotalSegmentSize;
13692} ZONE_HEADER, *PZONE_HEADER;
13693
13694
13695DECLSPEC_DEPRECATED_DDK
13696NTKERNELAPI
13697NTSTATUS
13698ExInitializeZone(
13699 IN PZONE_HEADER Zone,
13700 IN ULONG BlockSize,
13701 IN PVOID InitialSegment,
13702 IN ULONG InitialSegmentSize
13703 );
13704
13705DECLSPEC_DEPRECATED_DDK
13706NTKERNELAPI
13707NTSTATUS
13708ExExtendZone(
13709 IN PZONE_HEADER Zone,
13710 IN PVOID Segment,
13711 IN ULONG SegmentSize
13712 );
13713
13714DECLSPEC_DEPRECATED_DDK
13715NTKERNELAPI
13716NTSTATUS
13717ExInterlockedExtendZone(
13718 IN PZONE_HEADER Zone,
13719 IN PVOID Segment,
13720 IN ULONG SegmentSize,
13721 IN PKSPIN_LOCK Lock
13722 );
13723
13724//++
13725//
13726// PVOID
13727// ExAllocateFromZone(
13728// IN PZONE_HEADER Zone
13729// )
13730//
13731// Routine Description:
13732//
13733// This routine removes an entry from the zone and returns a pointer to it.
13734//
13735// Arguments:
13736//
13737// Zone - Pointer to the zone header controlling the storage from which the
13738// entry is to be allocated.
13739//
13740// Return Value:
13741//
13742// The function value is a pointer to the storage allocated from the zone.
13743//
13744//--
13745#if PRAGMA_DEPRECATED_DDK
13746#pragma deprecated(ExAllocateFromZone)
13747#endif
13748#define ExAllocateFromZone(Zone) \
13749 (PVOID)((Zone)->FreeList.Next); \
13750 if ( (Zone)->FreeList.Next ) (Zone)->FreeList.Next = (Zone)->FreeList.Next->Next
13751
13752
13753//++
13754//
13755// PVOID
13756// ExFreeToZone(
13757// IN PZONE_HEADER Zone,
13758// IN PVOID Block
13759// )
13760//
13761// Routine Description:
13762//
13763// This routine places the specified block of storage back onto the free
13764// list in the specified zone.
13765//
13766// Arguments:
13767//
13768// Zone - Pointer to the zone header controlling the storage to which the
13769// entry is to be inserted.
13770//
13771// Block - Pointer to the block of storage to be freed back to the zone.
13772//
13773// Return Value:
13774//
13775// Pointer to previous block of storage that was at the head of the free
13776// list. NULL implies the zone went from no available free blocks to
13777// at least one free block.
13778//
13779//--
13780
13781#if PRAGMA_DEPRECATED_DDK
13782#pragma deprecated(ExFreeToZone)
13783#endif
13784#define ExFreeToZone(Zone,Block) \
13785 ( ((PSINGLE_LIST_ENTRY)(Block))->Next = (Zone)->FreeList.Next, \
13786 (Zone)->FreeList.Next = ((PSINGLE_LIST_ENTRY)(Block)), \
13787 ((PSINGLE_LIST_ENTRY)(Block))->Next \
13788 )
13789
13790//++
13791//
13792// BOOLEAN
13793// ExIsFullZone(
13794// IN PZONE_HEADER Zone
13795// )
13796//
13797// Routine Description:
13798//
13799// This routine determines if the specified zone is full or not. A zone
13800// is considered full if the free list is empty.
13801//
13802// Arguments:
13803//
13804// Zone - Pointer to the zone header to be tested.
13805//
13806// Return Value:
13807//
13808// TRUE if the zone is full and FALSE otherwise.
13809//
13810//--
13811
13812#if PRAGMA_DEPRECATED_DDK
13813#pragma deprecated(ExIsFullZone)
13814#endif
13815#define ExIsFullZone(Zone) \
13816 ( (Zone)->FreeList.Next == (PSINGLE_LIST_ENTRY)NULL )
13817
13818//++
13819//
13820// PVOID
13821// ExInterlockedAllocateFromZone(
13822// IN PZONE_HEADER Zone,
13823// IN PKSPIN_LOCK Lock
13824// )
13825//
13826// Routine Description:
13827//
13828// This routine removes an entry from the zone and returns a pointer to it.
13829// The removal is performed with the specified lock owned for the sequence
13830// to make it MP-safe.
13831//
13832// Arguments:
13833//
13834// Zone - Pointer to the zone header controlling the storage from which the
13835// entry is to be allocated.
13836//
13837// Lock - Pointer to the spin lock which should be obtained before removing
13838// the entry from the allocation list. The lock is released before
13839// returning to the caller.
13840//
13841// Return Value:
13842//
13843// The function value is a pointer to the storage allocated from the zone.
13844//
13845//--
13846
13847#if PRAGMA_DEPRECATED_DDK
13848#pragma deprecated(ExInterlockedAllocateFromZone)
13849#endif
13850#define ExInterlockedAllocateFromZone(Zone,Lock) \
13851 (PVOID) ExInterlockedPopEntryList( &(Zone)->FreeList, Lock )
13852
13853//++
13854//
13855// PVOID
13856// ExInterlockedFreeToZone(
13857// IN PZONE_HEADER Zone,
13858// IN PVOID Block,
13859// IN PKSPIN_LOCK Lock
13860// )
13861//
13862// Routine Description:
13863//
13864// This routine places the specified block of storage back onto the free
13865// list in the specified zone. The insertion is performed with the lock
13866// owned for the sequence to make it MP-safe.
13867//
13868// Arguments:
13869//
13870// Zone - Pointer to the zone header controlling the storage to which the
13871// entry is to be inserted.
13872//
13873// Block - Pointer to the block of storage to be freed back to the zone.
13874//
13875// Lock - Pointer to the spin lock which should be obtained before inserting
13876// the entry onto the free list. The lock is released before returning
13877// to the caller.
13878//
13879// Return Value:
13880//
13881// Pointer to previous block of storage that was at the head of the free
13882// list. NULL implies the zone went from no available free blocks to
13883// at least one free block.
13884//
13885//--
13886
13887#if PRAGMA_DEPRECATED_DDK
13888#pragma deprecated(ExInterlockedFreeToZone)
13889#endif
13890#define ExInterlockedFreeToZone(Zone,Block,Lock) \
13891 ExInterlockedPushEntryList( &(Zone)->FreeList, ((PSINGLE_LIST_ENTRY) (Block)), Lock )
13892
13893
13894//++
13895//
13896// BOOLEAN
13897// ExIsObjectInFirstZoneSegment(
13898// IN PZONE_HEADER Zone,
13899// IN PVOID Object
13900// )
13901//
13902// Routine Description:
13903//
13904// This routine determines if the specified pointer lives in the zone.
13905//
13906// Arguments:
13907//
13908// Zone - Pointer to the zone header controlling the storage to which the
13909// object may belong.
13910//
13911// Object - Pointer to the object in question.
13912//
13913// Return Value:
13914//
13915// TRUE if the Object came from the first segment of zone.
13916//
13917//--
13918
13919#if PRAGMA_DEPRECATED_DDK
13920#pragma deprecated(ExIsObjectInFirstZoneSegment)
13921#endif
13922#define ExIsObjectInFirstZoneSegment(Zone,Object) ((BOOLEAN) \
13923 (((PUCHAR)(Object) >= (PUCHAR)(Zone)->SegmentList.Next) && \
13924 ((PUCHAR)(Object) < (PUCHAR)(Zone)->SegmentList.Next + \
13925 (Zone)->TotalSegmentSize)) \
13926)
13927
13928//
13929// Define executive resource data structures.
13930//
13931
13932typedef ULONG_PTR ERESOURCE_THREAD;
13933typedef ERESOURCE_THREAD *PERESOURCE_THREAD;
13934
13935typedef struct _OWNER_ENTRY {
13936 ERESOURCE_THREAD OwnerThread;
13937 union {
13938 LONG OwnerCount;
13939 ULONG TableSize;
13940 };
13941
13942} OWNER_ENTRY, *POWNER_ENTRY;
13943
13944typedef struct _ERESOURCE {
13945 LIST_ENTRY SystemResourcesList;
13946 POWNER_ENTRY OwnerTable;
13947 SHORT ActiveCount;
13948 USHORT Flag;
13949 PKSEMAPHORE SharedWaiters;
13950 PKEVENT ExclusiveWaiters;
13951 OWNER_ENTRY OwnerThreads[2];
13952 ULONG ContentionCount;
13953 USHORT NumberOfSharedWaiters;
13954 USHORT NumberOfExclusiveWaiters;
13955 union {
13956 PVOID Address;
13957 ULONG_PTR CreatorBackTraceIndex;
13958 };
13959
13960 KSPIN_LOCK SpinLock;
13961} ERESOURCE, *PERESOURCE;
13962//
13963// Values for ERESOURCE.Flag
13964//
13965
13966#define ResourceNeverExclusive 0x10
13967#define ResourceReleaseByOtherThread 0x20
13968#define ResourceOwnedExclusive 0x80
13969
13970#define RESOURCE_HASH_TABLE_SIZE 64
13971
13972typedef struct _RESOURCE_HASH_ENTRY {
13973 LIST_ENTRY ListEntry;
13974 PVOID Address;
13975 ULONG ContentionCount;
13976 ULONG Number;
13977} RESOURCE_HASH_ENTRY, *PRESOURCE_HASH_ENTRY;
13978
13979typedef struct _RESOURCE_PERFORMANCE_DATA {
13980 ULONG ActiveResourceCount;
13981 ULONG TotalResourceCount;
13982 ULONG ExclusiveAcquire;
13983 ULONG SharedFirstLevel;
13984 ULONG SharedSecondLevel;
13985 ULONG StarveFirstLevel;
13986 ULONG StarveSecondLevel;
13987 ULONG WaitForExclusive;
13988 ULONG OwnerTableExpands;
13989 ULONG MaximumTableExpand;
13990 LIST_ENTRY HashTable[RESOURCE_HASH_TABLE_SIZE];
13991} RESOURCE_PERFORMANCE_DATA, *PRESOURCE_PERFORMANCE_DATA;
13992
13993//
13994// Define executive resource function prototypes.
13995//
13996NTKERNELAPI
13997NTSTATUS
13998ExInitializeResourceLite(
13999 IN PERESOURCE Resource
14000 );
14001
14002NTKERNELAPI
14003NTSTATUS
14004ExReinitializeResourceLite(
14005 IN PERESOURCE Resource
14006 );
14007
14008NTKERNELAPI
14009BOOLEAN
14010ExAcquireResourceSharedLite(
14011 IN PERESOURCE Resource,
14012 IN BOOLEAN Wait
14013 );
14014
14015NTKERNELAPI
14016BOOLEAN
14017ExAcquireResourceExclusiveLite(
14018 IN PERESOURCE Resource,
14019 IN BOOLEAN Wait
14020 );
14021
14022NTKERNELAPI
14023BOOLEAN
14024ExAcquireSharedStarveExclusive(
14025 IN PERESOURCE Resource,
14026 IN BOOLEAN Wait
14027 );
14028
14029NTKERNELAPI
14030BOOLEAN
14031ExAcquireSharedWaitForExclusive(
14032 IN PERESOURCE Resource,
14033 IN BOOLEAN Wait
14034 );
14035
14036NTKERNELAPI
14037BOOLEAN
14038ExTryToAcquireResourceExclusiveLite(
14039 IN PERESOURCE Resource
14040 );
14041
14042//
14043// VOID
14044// ExReleaseResource(
14045// IN PERESOURCE Resource
14046// );
14047//
14048
14049#if PRAGMA_DEPRECATED_DDK
14050#pragma deprecated(ExReleaseResource) // Use ExReleaseResourceLite
14051#endif
14052#define ExReleaseResource(R) (ExReleaseResourceLite(R))
14053
14054NTKERNELAPI
14055VOID
14056FASTCALL
14057ExReleaseResourceLite(
14058 IN PERESOURCE Resource
14059 );
14060
14061NTKERNELAPI
14062VOID
14063ExReleaseResourceForThreadLite(
14064 IN PERESOURCE Resource,
14065 IN ERESOURCE_THREAD ResourceThreadId
14066 );
14067
14068NTKERNELAPI
14069VOID
14070ExSetResourceOwnerPointer(
14071 IN PERESOURCE Resource,
14072 IN PVOID OwnerPointer
14073 );
14074
14075NTKERNELAPI
14076VOID
14077ExConvertExclusiveToSharedLite(
14078 IN PERESOURCE Resource
14079 );
14080
14081NTKERNELAPI
14082NTSTATUS
14083ExDeleteResourceLite (
14084 IN PERESOURCE Resource
14085 );
14086
14087NTKERNELAPI
14088ULONG
14089ExGetExclusiveWaiterCount (
14090 IN PERESOURCE Resource
14091 );
14092
14093NTKERNELAPI
14094ULONG
14095ExGetSharedWaiterCount (
14096 IN PERESOURCE Resource
14097 );
14098
14099//
14100// ERESOURCE_THREAD
14101// ExGetCurrentResourceThread(
14102// );
14103//
14104
14105#define ExGetCurrentResourceThread() ((ULONG_PTR)PsGetCurrentThread())
14106
14107NTKERNELAPI
14108BOOLEAN
14109ExIsResourceAcquiredExclusiveLite (
14110 IN PERESOURCE Resource
14111 );
14112
14113NTKERNELAPI
14114ULONG
14115ExIsResourceAcquiredSharedLite (
14116 IN PERESOURCE Resource
14117 );
14118
14119//
14120// An acquired resource is always owned shared, as shared ownership is a subset
14121// of exclusive ownership.
14122//
14123#define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
14124
14125
14126//
14127// ntddk.h stole the entrypoints we wanted so fix them up here.
14128//
14129
14130#if PRAGMA_DEPRECATED_DDK
14131#pragma deprecated(ExInitializeResource) // use ExInitializeResourceLite
14132#pragma deprecated(ExAcquireResourceShared) // use ExAcquireResourceSharedLite
14133#pragma deprecated(ExAcquireResourceExclusive) // use ExAcquireResourceExclusiveLite
14134#pragma deprecated(ExReleaseResourceForThread) // use ExReleaseResourceForThreadLite
14135#pragma deprecated(ExConvertExclusiveToShared) // use ExConvertExclusiveToSharedLite
14136#pragma deprecated(ExDeleteResource) // use ExDeleteResourceLite
14137#pragma deprecated(ExIsResourceAcquiredExclusive) // use ExIsResourceAcquiredExclusiveLite
14138#pragma deprecated(ExIsResourceAcquiredShared) // use ExIsResourceAcquiredSharedLite
14139#pragma deprecated(ExIsResourceAcquired) // use ExIsResourceAcquiredSharedLite
14140#endif
14141#define ExInitializeResource ExInitializeResourceLite
14142#define ExAcquireResourceShared ExAcquireResourceSharedLite
14143#define ExAcquireResourceExclusive ExAcquireResourceExclusiveLite
14144#define ExReleaseResourceForThread ExReleaseResourceForThreadLite
14145#define ExConvertExclusiveToShared ExConvertExclusiveToSharedLite
14146#define ExDeleteResource ExDeleteResourceLite
14147#define ExIsResourceAcquiredExclusive ExIsResourceAcquiredExclusiveLite
14148#define ExIsResourceAcquiredShared ExIsResourceAcquiredSharedLite
14149#define ExIsResourceAcquired ExIsResourceAcquiredSharedLite
14150
14151//
14152// Get previous mode
14153//
14154
14155NTKERNELAPI
14156KPROCESSOR_MODE
14157ExGetPreviousMode(
14158 VOID
14159 );
14160//
14161// Raise status from kernel mode.
14162//
14163
14164NTKERNELAPI
14165VOID
14166NTAPI
14167ExRaiseStatus (
14168 IN NTSTATUS Status
14169 );
14170
14171
14172
14173NTKERNELAPI
14174VOID
14175ExRaiseDatatypeMisalignment (
14176 VOID
14177 );
14178
14179NTKERNELAPI
14180VOID
14181ExRaiseAccessViolation (
14182 VOID
14183 );
14184
14185//
14186// Set timer resolution.
14187//
14188
14189NTKERNELAPI
14190ULONG
14191ExSetTimerResolution (
14192 IN ULONG DesiredTime,
14193 IN BOOLEAN SetResolution
14194 );
14195
14196//
14197// Subtract time zone bias from system time to get local time.
14198//
14199
14200NTKERNELAPI
14201VOID
14202ExSystemTimeToLocalTime (
14203 IN PLARGE_INTEGER SystemTime,
14204 OUT PLARGE_INTEGER LocalTime
14205 );
14206
14207//
14208// Add time zone bias to local time to get system time.
14209//
14210
14211NTKERNELAPI
14212VOID
14213ExLocalTimeToSystemTime (
14214 IN PLARGE_INTEGER LocalTime,
14215 OUT PLARGE_INTEGER SystemTime
14216 );
14217
14218
14219//
14220// Define the type for Callback function.
14221//
14222
14223typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
14224
14225typedef VOID (*PCALLBACK_FUNCTION ) (
14226 IN PVOID CallbackContext,
14227 IN PVOID Argument1,
14228 IN PVOID Argument2
14229 );
14230
14231
14232NTKERNELAPI
14233NTSTATUS
14234ExCreateCallback (
14235 OUT PCALLBACK_OBJECT *CallbackObject,
14236 IN POBJECT_ATTRIBUTES ObjectAttributes,
14237 IN BOOLEAN Create,
14238 IN BOOLEAN AllowMultipleCallbacks
14239 );
14240
14241NTKERNELAPI
14242PVOID
14243ExRegisterCallback (
14244 IN PCALLBACK_OBJECT CallbackObject,
14245 IN PCALLBACK_FUNCTION CallbackFunction,
14246 IN PVOID CallbackContext
14247 );
14248
14249NTKERNELAPI
14250VOID
14251ExUnregisterCallback (
14252 IN PVOID CallbackRegistration
14253 );
14254
14255NTKERNELAPI
14256VOID
14257ExNotifyCallback (
14258 IN PVOID CallbackObject,
14259 IN PVOID Argument1,
14260 IN PVOID Argument2
14261 );
14262
14263
14264
14265//
14266// UUID Generation
14267//
14268
14269typedef GUID UUID;
14270
14271NTKERNELAPI
14272NTSTATUS
14273ExUuidCreate(
14274 OUT UUID *Uuid
14275 );
14276
14277//
14278// suite support
14279//
14280
14281NTKERNELAPI
14282BOOLEAN
14283ExVerifySuite(
14284 SUITE_TYPE SuiteType
14285 );
14286
14287
14288//
14289// Define a block to hold the actual routine registration.
14290//
14291typedef NTSTATUS (*PEX_CALLBACK_FUNCTION ) (
14292 IN PVOID CallbackContext,
14293 IN PVOID Argument1,
14294 IN PVOID Argument2
14295 );
14296
14297
14298//
14299// Registry kernel mode callbacks
14300//
14301
14302//
14303// Hook selector
14304//
14305typedef enum _REG_NOTIFY_CLASS {
14306 RegNtDeleteKey,
14307 RegNtPreDeleteKey = RegNtDeleteKey,
14308 RegNtSetValueKey,
14309 RegNtPreSetValueKey = RegNtSetValueKey,
14310 RegNtDeleteValueKey,
14311 RegNtPreDeleteValueKey = RegNtDeleteValueKey,
14312 RegNtSetInformationKey,
14313 RegNtPreSetInformationKey = RegNtSetInformationKey,
14314 RegNtRenameKey,
14315 RegNtPreRenameKey = RegNtRenameKey,
14316 RegNtEnumerateKey,
14317 RegNtPreEnumerateKey = RegNtEnumerateKey,
14318 RegNtEnumerateValueKey,
14319 RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
14320 RegNtQueryKey,
14321 RegNtPreQueryKey = RegNtQueryKey,
14322 RegNtQueryValueKey,
14323 RegNtPreQueryValueKey = RegNtQueryValueKey,
14324 RegNtQueryMultipleValueKey,
14325 RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
14326 RegNtPreCreateKey,
14327 RegNtPostCreateKey,
14328 RegNtPreOpenKey,
14329 RegNtPostOpenKey,
14330 RegNtKeyHandleClose,
14331 RegNtPreKeyHandleClose = RegNtKeyHandleClose,
14332 //
14333 // .Net only
14334 //
14335 RegNtPostDeleteKey,
14336 RegNtPostSetValueKey,
14337 RegNtPostDeleteValueKey,
14338 RegNtPostSetInformationKey,
14339 RegNtPostRenameKey,
14340 RegNtPostEnumerateKey,
14341 RegNtPostEnumerateValueKey,
14342 RegNtPostQueryKey,
14343 RegNtPostQueryValueKey,
14344 RegNtPostQueryMultipleValueKey,
14345 RegNtPostKeyHandleClose,
14346 RegNtPreCreateKeyEx,
14347 RegNtPostCreateKeyEx,
14348 RegNtPreOpenKeyEx,
14349 RegNtPostOpenKeyEx
14350} REG_NOTIFY_CLASS;
14351
14352//
14353// Parameter description for each notify class
14354//
14355typedef struct _REG_DELETE_KEY_INFORMATION {
14356 PVOID Object; // IN
14357} REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION;
14358
14359typedef struct _REG_SET_VALUE_KEY_INFORMATION {
14360 PVOID Object; // IN
14361 PUNICODE_STRING ValueName; // IN
14362 ULONG TitleIndex; // IN
14363 ULONG Type; // IN
14364 PVOID Data; // IN
14365 ULONG DataSize; // IN
14366} REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
14367
14368typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
14369 PVOID Object; // IN
14370 PUNICODE_STRING ValueName; // IN
14371} REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
14372
14373typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
14374 PVOID Object; // IN
14375 KEY_SET_INFORMATION_CLASS KeySetInformationClass; // IN
14376 PVOID KeySetInformation; // IN
14377 ULONG KeySetInformationLength;// IN
14378} REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
14379
14380typedef struct _REG_ENUMERATE_KEY_INFORMATION {
14381 PVOID Object; // IN
14382 ULONG Index; // IN
14383 KEY_INFORMATION_CLASS KeyInformationClass; // IN
14384 PVOID KeyInformation; // IN
14385 ULONG Length; // IN
14386 PULONG ResultLength; // OUT
14387} REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
14388
14389typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
14390 PVOID Object; // IN
14391 ULONG Index; // IN
14392 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
14393 PVOID KeyValueInformation; // IN
14394 ULONG Length; // IN
14395 PULONG ResultLength; // OUT
14396} REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
14397
14398typedef struct _REG_QUERY_KEY_INFORMATION {
14399 PVOID Object; // IN
14400 KEY_INFORMATION_CLASS KeyInformationClass; // IN
14401 PVOID KeyInformation; // IN
14402 ULONG Length; // IN
14403 PULONG ResultLength; // OUT
14404} REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
14405
14406typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
14407 PVOID Object; // IN
14408 PUNICODE_STRING ValueName; // IN
14409 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass; // IN
14410 PVOID KeyValueInformation; // IN
14411 ULONG Length; // IN
14412 PULONG ResultLength; // OUT
14413} REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
14414
14415typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
14416 PVOID Object; // IN
14417 PKEY_VALUE_ENTRY ValueEntries; // IN
14418 ULONG EntryCount; // IN
14419 PVOID ValueBuffer; // IN
14420 PULONG BufferLength; // IN OUT
14421 PULONG RequiredBufferLength; // OUT
14422} REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
14423
14424typedef struct _REG_RENAME_KEY_INFORMATION {
14425 PVOID Object; // IN
14426 PUNICODE_STRING NewName; // IN
14427} REG_RENAME_KEY_INFORMATION, *PREG_RENAME_KEY_INFORMATION;
14428
14429
14430typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
14431 PVOID Object; // IN
14432} REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
14433
14434/* .Net Only */
14435typedef struct _REG_CREATE_KEY_INFORMATION {
14436 PUNICODE_STRING CompleteName; // IN
14437 PVOID RootObject; // IN
14438} REG_CREATE_KEY_INFORMATION, REG_OPEN_KEY_INFORMATION,*PREG_CREATE_KEY_INFORMATION, *PREG_OPEN_KEY_INFORMATION;
14439
14440typedef struct _REG_POST_OPERATION_INFORMATION {
14441 PVOID Object; // IN
14442 NTSTATUS Status; // IN
14443} REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
14444/* end .Net Only */
14445
14446/* XP only */
14447typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
14448 PUNICODE_STRING CompleteName; // IN
14449} REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
14450
14451typedef struct _REG_POST_CREATE_KEY_INFORMATION {
14452 PUNICODE_STRING CompleteName; // IN
14453 PVOID Object; // IN
14454 NTSTATUS Status; // IN
14455} REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
14456/* end XP only */
14457
14458
14459NTSTATUS
14460CmRegisterCallback(IN PEX_CALLBACK_FUNCTION Function,
14461 IN PVOID Context,
14462 IN OUT PLARGE_INTEGER Cookie
14463 );
14464NTSTATUS
14465CmUnRegisterCallback(IN LARGE_INTEGER Cookie);
14466
14467//
14468// Priority increment definitions. The comment for each definition gives
14469// the names of the system services that use the definition when satisfying
14470// a wait.
14471//
14472
14473//
14474// Priority increment used when satisfying a wait on an executive event
14475// (NtPulseEvent and NtSetEvent)
14476//
14477
14478#define EVENT_INCREMENT 1
14479
14480//
14481// Priority increment when no I/O has been done. This is used by device
14482// and file system drivers when completing an IRP (IoCompleteRequest).
14483//
14484
14485#define IO_NO_INCREMENT 0
14486
14487
14488//
14489// Priority increment for completing CD-ROM I/O. This is used by CD-ROM device
14490// and file system drivers when completing an IRP (IoCompleteRequest)
14491//
14492
14493#define IO_CD_ROM_INCREMENT 1
14494
14495//
14496// Priority increment for completing disk I/O. This is used by disk device
14497// and file system drivers when completing an IRP (IoCompleteRequest)
14498//
14499
14500#define IO_DISK_INCREMENT 1
14501
14502
14503
14504//
14505// Priority increment for completing keyboard I/O. This is used by keyboard
14506// device drivers when completing an IRP (IoCompleteRequest)
14507//
14508
14509#define IO_KEYBOARD_INCREMENT 6
14510
14511
14512//
14513// Priority increment for completing mailslot I/O. This is used by the mail-
14514// slot file system driver when completing an IRP (IoCompleteRequest).
14515//
14516
14517#define IO_MAILSLOT_INCREMENT 2
14518
14519
14520//
14521// Priority increment for completing mouse I/O. This is used by mouse device
14522// drivers when completing an IRP (IoCompleteRequest)
14523//
14524
14525#define IO_MOUSE_INCREMENT 6
14526
14527
14528//
14529// Priority increment for completing named pipe I/O. This is used by the
14530// named pipe file system driver when completing an IRP (IoCompleteRequest).
14531//
14532
14533#define IO_NAMED_PIPE_INCREMENT 2
14534
14535//
14536// Priority increment for completing network I/O. This is used by network
14537// device and network file system drivers when completing an IRP
14538// (IoCompleteRequest).
14539//
14540
14541#define IO_NETWORK_INCREMENT 2
14542
14543
14544//
14545// Priority increment for completing parallel I/O. This is used by parallel
14546// device drivers when completing an IRP (IoCompleteRequest)
14547//
14548
14549#define IO_PARALLEL_INCREMENT 1
14550
14551//
14552// Priority increment for completing serial I/O. This is used by serial device
14553// drivers when completing an IRP (IoCompleteRequest)
14554//
14555
14556#define IO_SERIAL_INCREMENT 2
14557
14558//
14559// Priority increment for completing sound I/O. This is used by sound device
14560// drivers when completing an IRP (IoCompleteRequest)
14561//
14562
14563#define IO_SOUND_INCREMENT 8
14564
14565//
14566// Priority increment for completing video I/O. This is used by video device
14567// drivers when completing an IRP (IoCompleteRequest)
14568//
14569
14570#define IO_VIDEO_INCREMENT 1
14571
14572//
14573// Priority increment used when satisfying a wait on an executive semaphore
14574// (NtReleaseSemaphore)
14575//
14576
14577#define SEMAPHORE_INCREMENT 1
14578
14579//
14580// Indicates the system may do I/O to physical addresses above 4 GB.
14581//
14582
14583extern PBOOLEAN Mm64BitPhysicalAddress;
14584
14585
14586//
14587// Define maximum disk transfer size to be used by MM and Cache Manager,
14588// so that packet-oriented disk drivers can optimize their packet allocation
14589// to this size.
14590//
14591
14592#define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
14593
14594//++
14595//
14596// ULONG_PTR
14597// ROUND_TO_PAGES (
14598// IN ULONG_PTR Size
14599// )
14600//
14601// Routine Description:
14602//
14603// The ROUND_TO_PAGES macro takes a size in bytes and rounds it up to a
14604// multiple of the page size.
14605//
14606// NOTE: This macro fails for values 0xFFFFFFFF - (PAGE_SIZE - 1).
14607//
14608// Arguments:
14609//
14610// Size - Size in bytes to round up to a page multiple.
14611//
14612// Return Value:
14613//
14614// Returns the size rounded up to a multiple of the page size.
14615//
14616//--
14617
14618#define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
14619
14620//++
14621//
14622// ULONG
14623// BYTES_TO_PAGES (
14624// IN ULONG Size
14625// )
14626//
14627// Routine Description:
14628//
14629// The BYTES_TO_PAGES macro takes the size in bytes and calculates the
14630// number of pages required to contain the bytes.
14631//
14632// Arguments:
14633//
14634// Size - Size in bytes.
14635//
14636// Return Value:
14637//
14638// Returns the number of pages required to contain the specified size.
14639//
14640//--
14641
14642#define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + \
14643 (((Size) & (PAGE_SIZE - 1)) != 0))
14644
14645//++
14646//
14647// ULONG
14648// BYTE_OFFSET (
14649// IN PVOID Va
14650// )
14651//
14652// Routine Description:
14653//
14654// The BYTE_OFFSET macro takes a virtual address and returns the byte offset
14655// of that address within the page.
14656//
14657// Arguments:
14658//
14659// Va - Virtual address.
14660//
14661// Return Value:
14662//
14663// Returns the byte offset portion of the virtual address.
14664//
14665//--
14666
14667#define BYTE_OFFSET(Va) ((ULONG)((LONG_PTR)(Va) & (PAGE_SIZE - 1)))
14668
14669//++
14670//
14671// PVOID
14672// PAGE_ALIGN (
14673// IN PVOID Va
14674// )
14675//
14676// Routine Description:
14677//
14678// The PAGE_ALIGN macro takes a virtual address and returns a page-aligned
14679// virtual address for that page.
14680//
14681// Arguments:
14682//
14683// Va - Virtual address.
14684//
14685// Return Value:
14686//
14687// Returns the page aligned virtual address.
14688//
14689//--
14690
14691#define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
14692
14693//++
14694//
14695// ULONG
14696// ADDRESS_AND_SIZE_TO_SPAN_PAGES (
14697// IN PVOID Va,
14698// IN ULONG Size
14699// )
14700//
14701// Routine Description:
14702//
14703// The ADDRESS_AND_SIZE_TO_SPAN_PAGES macro takes a virtual address and
14704// size and returns the number of pages spanned by the size.
14705//
14706// Arguments:
14707//
14708// Va - Virtual address.
14709//
14710// Size - Size in bytes.
14711//
14712// Return Value:
14713//
14714// Returns the number of pages spanned by the size.
14715//
14716//--
14717
14718#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size) \
14719 ((ULONG)((((ULONG_PTR)(Va) & (PAGE_SIZE -1)) + (Size) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
14720
14721#if PRAGMA_DEPRECATED_DDK
14722#pragma deprecated(COMPUTE_PAGES_SPANNED) // Use ADDRESS_AND_SIZE_TO_SPAN_PAGES
14723#endif
14724
14725#define COMPUTE_PAGES_SPANNED(Va, Size) ADDRESS_AND_SIZE_TO_SPAN_PAGES(Va,Size)
14726
14727
14728//++
14729// PPFN_NUMBER
14730// MmGetMdlPfnArray (
14731// IN PMDL Mdl
14732// )
14733//
14734// Routine Description:
14735//
14736// The MmGetMdlPfnArray routine returns the virtual address of the
14737// first element of the array of physical page numbers associated with
14738// the MDL.
14739//
14740// Arguments:
14741//
14742// Mdl - Pointer to an MDL.
14743//
14744// Return Value:
14745//
14746// Returns the virtual address of the first element of the array of
14747// physical page numbers associated with the MDL.
14748//
14749//--
14750
14751#define MmGetMdlPfnArray(Mdl) ((PPFN_NUMBER)(Mdl + 1))
14752
14753//++
14754//
14755// PVOID
14756// MmGetMdlVirtualAddress (
14757// IN PMDL Mdl
14758// )
14759//
14760// Routine Description:
14761//
14762// The MmGetMdlVirtualAddress returns the virtual address of the buffer
14763// described by the Mdl.
14764//
14765// Arguments:
14766//
14767// Mdl - Pointer to an MDL.
14768//
14769// Return Value:
14770//
14771// Returns the virtual address of the buffer described by the Mdl
14772//
14773//--
14774
14775#define MmGetMdlVirtualAddress(Mdl) \
14776 ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset))
14777
14778//++
14779//
14780// ULONG
14781// MmGetMdlByteCount (
14782// IN PMDL Mdl
14783// )
14784//
14785// Routine Description:
14786//
14787// The MmGetMdlByteCount returns the length in bytes of the buffer
14788// described by the Mdl.
14789//
14790// Arguments:
14791//
14792// Mdl - Pointer to an MDL.
14793//
14794// Return Value:
14795//
14796// Returns the byte count of the buffer described by the Mdl
14797//
14798//--
14799
14800#define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount)
14801
14802//++
14803//
14804// ULONG
14805// MmGetMdlByteOffset (
14806// IN PMDL Mdl
14807// )
14808//
14809// Routine Description:
14810//
14811// The MmGetMdlByteOffset returns the byte offset within the page
14812// of the buffer described by the Mdl.
14813//
14814// Arguments:
14815//
14816// Mdl - Pointer to an MDL.
14817//
14818// Return Value:
14819//
14820// Returns the byte offset within the page of the buffer described by the Mdl
14821//
14822//--
14823
14824#define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset)
14825
14826//++
14827//
14828// PVOID
14829// MmGetMdlStartVa (
14830// IN PMDL Mdl
14831// )
14832//
14833// Routine Description:
14834//
14835// The MmGetMdlBaseVa returns the virtual address of the buffer
14836// described by the Mdl rounded down to the nearest page.
14837//
14838// Arguments:
14839//
14840// Mdl - Pointer to an MDL.
14841//
14842// Return Value:
14843//
14844// Returns the returns the starting virtual address of the MDL.
14845//
14846//
14847//--
14848
14849#define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
14850
14851typedef enum _MM_SYSTEM_SIZE {
14852 MmSmallSystem,
14853 MmMediumSystem,
14854 MmLargeSystem
14855} MM_SYSTEMSIZE;
14856
14857NTKERNELAPI
14858MM_SYSTEMSIZE
14859MmQuerySystemSize (
14860 VOID
14861 );
14862
14863
14864
14865NTKERNELAPI
14866BOOLEAN
14867MmIsThisAnNtAsSystem (
14868 VOID
14869 );
14870
14871
14872NTSTATUS
14873MmIsVerifierEnabled (
14874 OUT PULONG VerifierFlags
14875 );
14876
14877NTSTATUS
14878MmAddVerifierThunks (
14879 IN PVOID ThunkBuffer,
14880 IN ULONG ThunkBufferSize
14881 );
14882
14883
14884NTKERNELAPI
14885VOID
14886MmProbeAndLockProcessPages (
14887 IN OUT PMDL MemoryDescriptorList,
14888 IN PEPROCESS Process,
14889 IN KPROCESSOR_MODE AccessMode,
14890 IN LOCK_OPERATION Operation
14891 );
14892
14893
14894
14895//
14896// I/O support routines.
14897//
14898
14899NTKERNELAPI
14900VOID
14901MmProbeAndLockPages (
14902 IN OUT PMDL MemoryDescriptorList,
14903 IN KPROCESSOR_MODE AccessMode,
14904 IN LOCK_OPERATION Operation
14905 );
14906
14907
14908NTKERNELAPI
14909VOID
14910MmUnlockPages (
14911 IN PMDL MemoryDescriptorList
14912 );
14913
14914
14915NTKERNELAPI
14916VOID
14917MmBuildMdlForNonPagedPool (
14918 IN OUT PMDL MemoryDescriptorList
14919 );
14920
14921NTKERNELAPI
14922PVOID
14923MmMapLockedPages (
14924 IN PMDL MemoryDescriptorList,
14925 IN KPROCESSOR_MODE AccessMode
14926 );
14927
14928LOGICAL
14929MmIsIoSpaceActive (
14930 IN PHYSICAL_ADDRESS StartAddress,
14931 IN SIZE_T NumberOfBytes
14932 );
14933
14934NTKERNELAPI
14935PVOID
14936MmGetSystemRoutineAddress (
14937 IN PUNICODE_STRING SystemRoutineName
14938 );
14939
14940NTKERNELAPI
14941NTSTATUS
14942MmAdvanceMdl (
14943 IN PMDL Mdl,
14944 IN ULONG NumberOfBytes
14945 );
14946
14947
14948
14949NTKERNELAPI
14950NTSTATUS
14951MmMapUserAddressesToPage (
14952 IN PVOID BaseAddress,
14953 IN SIZE_T NumberOfBytes,
14954 IN PVOID PageAddress
14955 );
14956
14957
14958NTKERNELAPI
14959NTSTATUS
14960MmProtectMdlSystemAddress (
14961 IN PMDL MemoryDescriptorList,
14962 IN ULONG NewProtect
14963 );
14964
14965//
14966// _MM_PAGE_PRIORITY_ provides a method for the system to handle requests
14967// intelligently in low resource conditions.
14968//
14969// LowPagePriority should be used when it is acceptable to the driver for the
14970// mapping request to fail if the system is low on resources. An example of
14971// this could be for a non-critical network connection where the driver can
14972// handle the failure case when system resources are close to being depleted.
14973//
14974// NormalPagePriority should be used when it is acceptable to the driver for the
14975// mapping request to fail if the system is very low on resources. An example
14976// of this could be for a non-critical local filesystem request.
14977//
14978// HighPagePriority should be used when it is unacceptable to the driver for the
14979// mapping request to fail unless the system is completely out of resources.
14980// An example of this would be the paging file path in a driver.
14981//
14982
14983
14984
14985typedef enum _MM_PAGE_PRIORITY {
14986 LowPagePriority,
14987 NormalPagePriority = 16,
14988 HighPagePriority = 32
14989} MM_PAGE_PRIORITY;
14990
14991
14992
14993//
14994// Note: This function is not available in WDM 1.0
14995//
14996NTKERNELAPI
14997PVOID
14998MmMapLockedPagesSpecifyCache (
14999 IN PMDL MemoryDescriptorList,
15000 IN KPROCESSOR_MODE AccessMode,
15001 IN MEMORY_CACHING_TYPE CacheType,
15002 IN PVOID BaseAddress,
15003 IN ULONG BugCheckOnFailure,
15004 IN MM_PAGE_PRIORITY Priority
15005 );
15006
15007NTKERNELAPI
15008VOID
15009MmUnmapLockedPages (
15010 IN PVOID BaseAddress,
15011 IN PMDL MemoryDescriptorList
15012 );
15013
15014PVOID
15015MmAllocateMappingAddress (
15016 IN SIZE_T NumberOfBytes,
15017 IN ULONG PoolTag
15018 );
15019
15020VOID
15021MmFreeMappingAddress (
15022 IN PVOID BaseAddress,
15023 IN ULONG PoolTag
15024 );
15025
15026PVOID
15027MmMapLockedPagesWithReservedMapping (
15028 IN PVOID MappingAddress,
15029 IN ULONG PoolTag,
15030 IN PMDL MemoryDescriptorList,
15031 IN MEMORY_CACHING_TYPE CacheType
15032 );
15033
15034VOID
15035MmUnmapReservedMapping (
15036 IN PVOID BaseAddress,
15037 IN ULONG PoolTag,
15038 IN PMDL MemoryDescriptorList
15039 );
15040
15041
15042
15043typedef struct _PHYSICAL_MEMORY_RANGE {
15044 PHYSICAL_ADDRESS BaseAddress;
15045 LARGE_INTEGER NumberOfBytes;
15046} PHYSICAL_MEMORY_RANGE, *PPHYSICAL_MEMORY_RANGE;
15047
15048NTKERNELAPI
15049NTSTATUS
15050MmAddPhysicalMemory (
15051 IN PPHYSICAL_ADDRESS StartAddress,
15052 IN OUT PLARGE_INTEGER NumberOfBytes
15053 );
15054
15055
15056NTKERNELAPI
15057NTSTATUS
15058MmRemovePhysicalMemory (
15059 IN PPHYSICAL_ADDRESS StartAddress,
15060 IN OUT PLARGE_INTEGER NumberOfBytes
15061 );
15062
15063
15064NTKERNELAPI
15065PPHYSICAL_MEMORY_RANGE
15066MmGetPhysicalMemoryRanges (
15067 VOID
15068 );
15069
15070
15071NTKERNELAPI
15072PMDL
15073MmAllocatePagesForMdl (
15074 IN PHYSICAL_ADDRESS LowAddress,
15075 IN PHYSICAL_ADDRESS HighAddress,
15076 IN PHYSICAL_ADDRESS SkipBytes,
15077 IN SIZE_T TotalBytes
15078 );
15079
15080NTKERNELAPI
15081VOID
15082MmFreePagesFromMdl (
15083 IN PMDL MemoryDescriptorList
15084 );
15085
15086NTKERNELAPI
15087PVOID
15088MmMapIoSpace (
15089 IN PHYSICAL_ADDRESS PhysicalAddress,
15090 IN SIZE_T NumberOfBytes,
15091 IN MEMORY_CACHING_TYPE CacheType
15092 );
15093
15094NTKERNELAPI
15095VOID
15096MmUnmapIoSpace (
15097 IN PVOID BaseAddress,
15098 IN SIZE_T NumberOfBytes
15099 );
15100
15101
15102NTKERNELAPI
15103PVOID
15104MmMapVideoDisplay (
15105 IN PHYSICAL_ADDRESS PhysicalAddress,
15106 IN SIZE_T NumberOfBytes,
15107 IN MEMORY_CACHING_TYPE CacheType
15108 );
15109
15110NTKERNELAPI
15111VOID
15112MmUnmapVideoDisplay (
15113 IN PVOID BaseAddress,
15114 IN SIZE_T NumberOfBytes
15115 );
15116
15117NTKERNELAPI
15118PHYSICAL_ADDRESS
15119MmGetPhysicalAddress (
15120 IN PVOID BaseAddress
15121 );
15122
15123NTKERNELAPI
15124PVOID
15125MmGetVirtualForPhysical (
15126 IN PHYSICAL_ADDRESS PhysicalAddress
15127 );
15128
15129NTKERNELAPI
15130PVOID
15131MmAllocateContiguousMemory (
15132 IN SIZE_T NumberOfBytes,
15133 IN PHYSICAL_ADDRESS HighestAcceptableAddress
15134 );
15135
15136NTKERNELAPI
15137PVOID
15138MmAllocateContiguousMemorySpecifyCache (
15139 IN SIZE_T NumberOfBytes,
15140 IN PHYSICAL_ADDRESS LowestAcceptableAddress,
15141 IN PHYSICAL_ADDRESS HighestAcceptableAddress,
15142 IN PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL,
15143 IN MEMORY_CACHING_TYPE CacheType
15144 );
15145
15146NTKERNELAPI
15147VOID
15148MmFreeContiguousMemory (
15149 IN PVOID BaseAddress
15150 );
15151
15152NTKERNELAPI
15153VOID
15154MmFreeContiguousMemorySpecifyCache (
15155 IN PVOID BaseAddress,
15156 IN SIZE_T NumberOfBytes,
15157 IN MEMORY_CACHING_TYPE CacheType
15158 );
15159
15160
15161NTKERNELAPI
15162PVOID
15163MmAllocateNonCachedMemory (
15164 IN SIZE_T NumberOfBytes
15165 );
15166
15167NTKERNELAPI
15168VOID
15169MmFreeNonCachedMemory (
15170 IN PVOID BaseAddress,
15171 IN SIZE_T NumberOfBytes
15172 );
15173
15174NTKERNELAPI
15175BOOLEAN
15176MmIsAddressValid (
15177 IN PVOID VirtualAddress
15178 );
15179
15180DECLSPEC_DEPRECATED_DDK
15181NTKERNELAPI
15182BOOLEAN
15183MmIsNonPagedSystemAddressValid (
15184 IN PVOID VirtualAddress
15185 );
15186
15187
15188
15189NTKERNELAPI
15190SIZE_T
15191MmSizeOfMdl (
15192 IN PVOID Base,
15193 IN SIZE_T Length
15194 );
15195
15196DECLSPEC_DEPRECATED_DDK // Use IoAllocateMdl
15197NTKERNELAPI
15198PMDL
15199MmCreateMdl (
15200 IN PMDL MemoryDescriptorList OPTIONAL,
15201 IN PVOID Base,
15202 IN SIZE_T Length
15203 );
15204
15205NTKERNELAPI
15206PVOID
15207MmLockPagableDataSection (
15208 IN PVOID AddressWithinSection
15209 );
15210
15211
15212
15213NTKERNELAPI
15214VOID
15215MmLockPagableSectionByHandle (
15216 IN PVOID ImageSectionHandle
15217 );
15218
15219NTKERNELAPI
15220VOID
15221MmResetDriverPaging (
15222 IN PVOID AddressWithinSection
15223 );
15224
15225
15226NTKERNELAPI
15227PVOID
15228MmPageEntireDriver (
15229 IN PVOID AddressWithinSection
15230 );
15231
15232NTKERNELAPI
15233VOID
15234MmUnlockPagableImageSection(
15235 IN PVOID ImageSectionHandle
15236 );
15237
15238
15239
15240
15241
15242//
15243// Note that even though this function prototype
15244// says "HANDLE", MmSecureVirtualMemory does NOT return
15245// anything resembling a Win32-style handle. The return
15246// value from this function can ONLY be used with MmUnsecureVirtualMemory.
15247//
15248NTKERNELAPI
15249HANDLE
15250MmSecureVirtualMemory (
15251 IN PVOID Address,
15252 IN SIZE_T Size,
15253 IN ULONG ProbeMode
15254 );
15255
15256NTKERNELAPI
15257VOID
15258MmUnsecureVirtualMemory (
15259 IN HANDLE SecureHandle
15260 );
15261
15262
15263
15264NTKERNELAPI
15265NTSTATUS
15266MmMapViewInSystemSpace (
15267 IN PVOID Section,
15268 OUT PVOID *MappedBase,
15269 IN PSIZE_T ViewSize
15270 );
15271
15272NTKERNELAPI
15273NTSTATUS
15274MmUnmapViewInSystemSpace (
15275 IN PVOID MappedBase
15276 );
15277
15278
15279NTKERNELAPI
15280NTSTATUS
15281MmMapViewInSessionSpace (
15282 IN PVOID Section,
15283 OUT PVOID *MappedBase,
15284 IN OUT PSIZE_T ViewSize
15285 );
15286
15287
15288NTKERNELAPI
15289NTSTATUS
15290MmUnmapViewInSessionSpace (
15291 IN PVOID MappedBase
15292 );
15293
15294
15295
15296
15297//++
15298//
15299// VOID
15300// MmInitializeMdl (
15301// IN PMDL MemoryDescriptorList,
15302// IN PVOID BaseVa,
15303// IN SIZE_T Length
15304// )
15305//
15306// Routine Description:
15307//
15308// This routine initializes the header of a Memory Descriptor List (MDL).
15309//
15310// Arguments:
15311//
15312// MemoryDescriptorList - Pointer to the MDL to initialize.
15313//
15314// BaseVa - Base virtual address mapped by the MDL.
15315//
15316// Length - Length, in bytes, of the buffer mapped by the MDL.
15317//
15318// Return Value:
15319//
15320// None.
15321//
15322//--
15323
15324#define MmInitializeMdl(MemoryDescriptorList, BaseVa, Length) { \
15325 (MemoryDescriptorList)->Next = (PMDL) NULL; \
15326 (MemoryDescriptorList)->Size = (CSHORT)(sizeof(MDL) + \
15327 (sizeof(PFN_NUMBER) * ADDRESS_AND_SIZE_TO_SPAN_PAGES((BaseVa), (Length)))); \
15328 (MemoryDescriptorList)->MdlFlags = 0; \
15329 (MemoryDescriptorList)->StartVa = (PVOID) PAGE_ALIGN((BaseVa)); \
15330 (MemoryDescriptorList)->ByteOffset = BYTE_OFFSET((BaseVa)); \
15331 (MemoryDescriptorList)->ByteCount = (ULONG)(Length); \
15332 }
15333
15334//++
15335//
15336// PVOID
15337// MmGetSystemAddressForMdlSafe (
15338// IN PMDL MDL,
15339// IN MM_PAGE_PRIORITY PRIORITY
15340// )
15341//
15342// Routine Description:
15343//
15344// This routine returns the mapped address of an MDL. If the
15345// Mdl is not already mapped or a system address, it is mapped.
15346//
15347// Arguments:
15348//
15349// MemoryDescriptorList - Pointer to the MDL to map.
15350//
15351// Priority - Supplies an indication as to how important it is that this
15352// request succeed under low available PTE conditions.
15353//
15354// Return Value:
15355//
15356// Returns the base address where the pages are mapped. The base address
15357// has the same offset as the virtual address in the MDL.
15358//
15359// Unlike MmGetSystemAddressForMdl, Safe guarantees that it will always
15360// return NULL on failure instead of bugchecking the system.
15361//
15362// This macro is not usable by WDM 1.0 drivers as 1.0 did not include
15363// MmMapLockedPagesSpecifyCache. The solution for WDM 1.0 drivers is to
15364// provide synchronization and set/reset the MDL_MAPPING_CAN_FAIL bit.
15365//
15366//--
15367
15368#define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \
15369 (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
15370 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
15371 ((MDL)->MappedSystemVa) : \
15372 (MmMapLockedPagesSpecifyCache((MDL), \
15373 KernelMode, \
15374 MmCached, \
15375 NULL, \
15376 FALSE, \
15377 (PRIORITY))))
15378
15379//++
15380//
15381// PVOID
15382// MmGetSystemAddressForMdl (
15383// IN PMDL MDL
15384// )
15385//
15386// Routine Description:
15387//
15388// This routine returns the mapped address of an MDL, if the
15389// Mdl is not already mapped or a system address, it is mapped.
15390//
15391// Arguments:
15392//
15393// MemoryDescriptorList - Pointer to the MDL to map.
15394//
15395// Return Value:
15396//
15397// Returns the base address where the pages are mapped. The base address
15398// has the same offset as the virtual address in the MDL.
15399//
15400//--
15401
15402//#define MmGetSystemAddressForMdl(MDL)
15403// (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA)) ?
15404// ((MDL)->MappedSystemVa) :
15405// ((((MDL)->MdlFlags & (MDL_SOURCE_IS_NONPAGED_POOL)) ?
15406// ((PVOID)((ULONG)(MDL)->StartVa | (MDL)->ByteOffset)) :
15407// (MmMapLockedPages((MDL),KernelMode)))))
15408
15409#if PRAGMA_DEPRECATED_DDK
15410#pragma deprecated(MmGetSystemAddressForMdl) // Use MmGetSystemAddressForMdlSafe
15411#endif
15412
15413#define MmGetSystemAddressForMdl(MDL) \
15414 (((MDL)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
15415 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
15416 ((MDL)->MappedSystemVa) : \
15417 (MmMapLockedPages((MDL),KernelMode)))
15418
15419//++
15420//
15421// VOID
15422// MmPrepareMdlForReuse (
15423// IN PMDL MDL
15424// )
15425//
15426// Routine Description:
15427//
15428// This routine will take all of the steps necessary to allow an MDL to be
15429// re-used.
15430//
15431// Arguments:
15432//
15433// MemoryDescriptorList - Pointer to the MDL that will be re-used.
15434//
15435// Return Value:
15436//
15437// None.
15438//
15439//--
15440
15441#define MmPrepareMdlForReuse(MDL) \
15442 if (((MDL)->MdlFlags & MDL_PARTIAL_HAS_BEEN_MAPPED) != 0) { \
15443 ASSERT(((MDL)->MdlFlags & MDL_PARTIAL) != 0); \
15444 MmUnmapLockedPages( (MDL)->MappedSystemVa, (MDL) ); \
15445 } else if (((MDL)->MdlFlags & MDL_PARTIAL) == 0) { \
15446 ASSERT(((MDL)->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA) == 0); \
15447 }
15448
15449typedef NTSTATUS (*PMM_DLL_INITIALIZE)(
15450 IN PUNICODE_STRING RegistryPath
15451 );
15452
15453typedef NTSTATUS (*PMM_DLL_UNLOAD)(
15454 VOID
15455 );
15456
15457
15458
15459NTKERNELAPI
15460NTSTATUS
15461MmCreateMirror (
15462 VOID
15463 );
15464
15465
15466//
15467// Define an empty typedef for the _DRIVER_OBJECT structure so it may be
15468// referenced by function types before it is actually defined.
15469//
15470struct _DRIVER_OBJECT;
15471
15472NTKERNELAPI
15473LOGICAL
15474MmIsDriverVerifying (
15475 IN struct _DRIVER_OBJECT *DriverObject
15476 );
15477
15478//
15479// Security operation codes
15480//
15481
15482typedef enum _SECURITY_OPERATION_CODE {
15483 SetSecurityDescriptor,
15484 QuerySecurityDescriptor,
15485 DeleteSecurityDescriptor,
15486 AssignSecurityDescriptor
15487 } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
15488
15489//
15490// Data structure used to capture subject security context
15491// for access validations and auditing.
15492//
15493// THE FIELDS OF THIS DATA STRUCTURE SHOULD BE CONSIDERED OPAQUE
15494// BY ALL EXCEPT THE SECURITY ROUTINES.
15495//
15496
15497typedef struct _SECURITY_SUBJECT_CONTEXT {
15498 PACCESS_TOKEN ClientToken;
15499 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
15500 PACCESS_TOKEN PrimaryToken;
15501 PVOID ProcessAuditId;
15502 } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
15503
15504///////////////////////////////////////////////////////////////////////////////
15505// //
15506// ACCESS_STATE and related structures //
15507// //
15508///////////////////////////////////////////////////////////////////////////////
15509
15510//
15511// Initial Privilege Set - Room for three privileges, which should
15512// be enough for most applications. This structure exists so that
15513// it can be imbedded in an ACCESS_STATE structure. Use PRIVILEGE_SET
15514// for all other references to Privilege sets.
15515//
15516
15517#define INITIAL_PRIVILEGE_COUNT 3
15518
15519typedef struct _INITIAL_PRIVILEGE_SET {
15520 ULONG PrivilegeCount;
15521 ULONG Control;
15522 LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
15523 } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
15524
15525
15526
15527//
15528// Combine the information that describes the state
15529// of an access-in-progress into a single structure
15530//
15531
15532
15533typedef struct _ACCESS_STATE {
15534 LUID OperationID;
15535 BOOLEAN SecurityEvaluated;
15536 BOOLEAN GenerateAudit;
15537 BOOLEAN GenerateOnClose;
15538 BOOLEAN PrivilegesAllocated;
15539 ULONG Flags;
15540 ACCESS_MASK RemainingDesiredAccess;
15541 ACCESS_MASK PreviouslyGrantedAccess;
15542 ACCESS_MASK OriginalDesiredAccess;
15543 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
15544 PSECURITY_DESCRIPTOR SecurityDescriptor;
15545 PVOID AuxData;
15546 union {
15547 INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
15548 PRIVILEGE_SET PrivilegeSet;
15549 } Privileges;
15550
15551 BOOLEAN AuditPrivileges;
15552 UNICODE_STRING ObjectName;
15553 UNICODE_STRING ObjectTypeName;
15554
15555 } ACCESS_STATE, *PACCESS_STATE;
15556
15557
15558NTKERNELAPI
15559NTSTATUS
15560SeAssignSecurity (
15561 IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
15562 IN PSECURITY_DESCRIPTOR ExplicitDescriptor,
15563 OUT PSECURITY_DESCRIPTOR *NewDescriptor,
15564 IN BOOLEAN IsDirectoryObject,
15565 IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
15566 IN PGENERIC_MAPPING GenericMapping,
15567 IN POOL_TYPE PoolType
15568 );
15569
15570NTKERNELAPI
15571NTSTATUS
15572SeAssignSecurityEx (
15573 IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL,
15574 IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL,
15575 OUT PSECURITY_DESCRIPTOR *NewDescriptor,
15576 IN GUID *ObjectType OPTIONAL,
15577 IN BOOLEAN IsDirectoryObject,
15578 IN ULONG AutoInheritFlags,
15579 IN PSECURITY_SUBJECT_CONTEXT SubjectContext,
15580 IN PGENERIC_MAPPING GenericMapping,
15581 IN POOL_TYPE PoolType
15582 );
15583
15584NTKERNELAPI
15585NTSTATUS
15586SeDeassignSecurity (
15587 IN OUT PSECURITY_DESCRIPTOR *SecurityDescriptor
15588 );
15589
15590NTKERNELAPI
15591BOOLEAN
15592SeAccessCheck (
15593 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
15594 IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext,
15595 IN BOOLEAN SubjectContextLocked,
15596 IN ACCESS_MASK DesiredAccess,
15597 IN ACCESS_MASK PreviouslyGrantedAccess,
15598 OUT PPRIVILEGE_SET *Privileges OPTIONAL,
15599 IN PGENERIC_MAPPING GenericMapping,
15600 IN KPROCESSOR_MODE AccessMode,
15601 OUT PACCESS_MASK GrantedAccess,
15602 OUT PNTSTATUS AccessStatus
15603 );
15604
15605
15606#ifdef SE_NTFS_WORLD_CACHE
15607
15608VOID
15609SeGetWorldRights (
15610 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
15611 IN PGENERIC_MAPPING GenericMapping,
15612 OUT PACCESS_MASK GrantedAccess
15613 );
15614
15615#endif
15616
15617
15618NTKERNELAPI
15619BOOLEAN
15620SeValidSecurityDescriptor(
15621 IN ULONG Length,
15622 IN PSECURITY_DESCRIPTOR SecurityDescriptor
15623 );
15624
15625NTKERNELAPI
15626BOOLEAN
15627SeSinglePrivilegeCheck(
15628 LUID PrivilegeValue,
15629 KPROCESSOR_MODE PreviousMode
15630 );
15631//
15632// System Thread and Process Creation and Termination
15633//
15634
15635NTKERNELAPI
15636NTSTATUS
15637PsCreateSystemThread(
15638 OUT PHANDLE ThreadHandle,
15639 IN ULONG DesiredAccess,
15640 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
15641 IN HANDLE ProcessHandle OPTIONAL,
15642 OUT PCLIENT_ID ClientId OPTIONAL,
15643 IN PKSTART_ROUTINE StartRoutine,
15644 IN PVOID StartContext
15645 );
15646
15647NTKERNELAPI
15648NTSTATUS
15649PsTerminateSystemThread(
15650 IN NTSTATUS ExitStatus
15651 );
15652
15653
15654typedef
15655VOID
15656(*PCREATE_PROCESS_NOTIFY_ROUTINE)(
15657 IN HANDLE ParentId,
15658 IN HANDLE ProcessId,
15659 IN BOOLEAN Create
15660 );
15661
15662NTSTATUS
15663PsSetCreateProcessNotifyRoutine(
15664 IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
15665 IN BOOLEAN Remove
15666 );
15667
15668typedef
15669VOID
15670(*PCREATE_THREAD_NOTIFY_ROUTINE)(
15671 IN HANDLE ProcessId,
15672 IN HANDLE ThreadId,
15673 IN BOOLEAN Create
15674 );
15675
15676NTSTATUS
15677PsSetCreateThreadNotifyRoutine(
15678 IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
15679 );
15680
15681NTSTATUS
15682PsRemoveCreateThreadNotifyRoutine (
15683 IN PCREATE_THREAD_NOTIFY_ROUTINE NotifyRoutine
15684 );
15685
15686//
15687// Structures for Load Image Notify
15688//
15689
15690typedef struct _IMAGE_INFO {
15691 union {
15692 ULONG Properties;
15693 struct {
15694 ULONG ImageAddressingMode : 8; // code addressing mode
15695 ULONG SystemModeImage : 1; // system mode image
15696 ULONG ImageMappedToAllPids : 1; // image mapped into all processes
15697 ULONG Reserved : 22;
15698 };
15699 };
15700 PVOID ImageBase;
15701 ULONG ImageSelector;
15702 SIZE_T ImageSize;
15703 ULONG ImageSectionNumber;
15704} IMAGE_INFO, *PIMAGE_INFO;
15705
15706#define IMAGE_ADDRESSING_MODE_32BIT 3
15707
15708typedef
15709VOID
15710(*PLOAD_IMAGE_NOTIFY_ROUTINE)(
15711 IN PUNICODE_STRING FullImageName,
15712 IN HANDLE ProcessId, // pid into which image is being mapped
15713 IN PIMAGE_INFO ImageInfo
15714 );
15715
15716NTSTATUS
15717PsSetLoadImageNotifyRoutine(
15718 IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
15719 );
15720
15721NTSTATUS
15722PsRemoveLoadImageNotifyRoutine(
15723 IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine
15724 );
15725
15726
15727
15728HANDLE
15729PsGetCurrentProcessId( VOID );
15730
15731HANDLE
15732PsGetCurrentThreadId( VOID );
15733
15734
15735
15736
15737BOOLEAN
15738PsGetVersion(
15739 PULONG MajorVersion OPTIONAL,
15740 PULONG MinorVersion OPTIONAL,
15741 PULONG BuildNumber OPTIONAL,
15742 PUNICODE_STRING CSDVersion OPTIONAL
15743 );
15744
15745//
15746// Define I/O system data structure type codes. Each major data structure in
15747// the I/O system has a type code The type field in each structure is at the
15748// same offset. The following values can be used to determine which type of
15749// data structure a pointer refers to.
15750//
15751
15752#define IO_TYPE_ADAPTER 0x00000001
15753#define IO_TYPE_CONTROLLER 0x00000002
15754#define IO_TYPE_DEVICE 0x00000003
15755#define IO_TYPE_DRIVER 0x00000004
15756#define IO_TYPE_FILE 0x00000005
15757#define IO_TYPE_IRP 0x00000006
15758#define IO_TYPE_MASTER_ADAPTER 0x00000007
15759#define IO_TYPE_OPEN_PACKET 0x00000008
15760#define IO_TYPE_TIMER 0x00000009
15761#define IO_TYPE_VPB 0x0000000a
15762#define IO_TYPE_ERROR_LOG 0x0000000b
15763#define IO_TYPE_ERROR_MESSAGE 0x0000000c
15764#define IO_TYPE_DEVICE_OBJECT_EXTENSION 0x0000000d
15765
15766
15767//
15768// Define the major function codes for IRPs.
15769//
15770
15771
15772#define IRP_MJ_CREATE 0x00
15773#define IRP_MJ_CREATE_NAMED_PIPE 0x01
15774#define IRP_MJ_CLOSE 0x02
15775#define IRP_MJ_READ 0x03
15776#define IRP_MJ_WRITE 0x04
15777#define IRP_MJ_QUERY_INFORMATION 0x05
15778#define IRP_MJ_SET_INFORMATION 0x06
15779#define IRP_MJ_QUERY_EA 0x07
15780#define IRP_MJ_SET_EA 0x08
15781#define IRP_MJ_FLUSH_BUFFERS 0x09
15782#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
15783#define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
15784#define IRP_MJ_DIRECTORY_CONTROL 0x0c
15785#define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
15786#define IRP_MJ_DEVICE_CONTROL 0x0e
15787#define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
15788#define IRP_MJ_SHUTDOWN 0x10
15789#define IRP_MJ_LOCK_CONTROL 0x11
15790#define IRP_MJ_CLEANUP 0x12
15791#define IRP_MJ_CREATE_MAILSLOT 0x13
15792#define IRP_MJ_QUERY_SECURITY 0x14
15793#define IRP_MJ_SET_SECURITY 0x15
15794#define IRP_MJ_POWER 0x16
15795#define IRP_MJ_SYSTEM_CONTROL 0x17
15796#define IRP_MJ_DEVICE_CHANGE 0x18
15797#define IRP_MJ_QUERY_QUOTA 0x19
15798#define IRP_MJ_SET_QUOTA 0x1a
15799#define IRP_MJ_PNP 0x1b
15800#define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
15801#define IRP_MJ_MAXIMUM_FUNCTION 0x1b
15802
15803//
15804// Make the Scsi major code the same as internal device control.
15805//
15806
15807#define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
15808
15809//
15810// Define the minor function codes for IRPs. The lower 128 codes, from 0x00 to
15811// 0x7f are reserved to Microsoft. The upper 128 codes, from 0x80 to 0xff, are
15812// reserved to customers of Microsoft.
15813//
15814
15815
15816//
15817// Directory control minor function codes
15818//
15819
15820#define IRP_MN_QUERY_DIRECTORY 0x01
15821#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
15822
15823//
15824// File system control minor function codes. Note that "user request" is
15825// assumed to be zero by both the I/O system and file systems. Do not change
15826// this value.
15827//
15828
15829#define IRP_MN_USER_FS_REQUEST 0x00
15830#define IRP_MN_MOUNT_VOLUME 0x01
15831#define IRP_MN_VERIFY_VOLUME 0x02
15832#define IRP_MN_LOAD_FILE_SYSTEM 0x03
15833#define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon
15834#define IRP_MN_KERNEL_CALL 0x04
15835
15836//
15837// Lock control minor function codes
15838//
15839
15840#define IRP_MN_LOCK 0x01
15841#define IRP_MN_UNLOCK_SINGLE 0x02
15842#define IRP_MN_UNLOCK_ALL 0x03
15843#define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
15844
15845//
15846// Read and Write minor function codes for file systems supporting Lan Manager
15847// software. All of these subfunction codes are invalid if the file has been
15848// opened with FO_NO_INTERMEDIATE_BUFFERING. They are also invalid in combi-
15849// nation with synchronous calls (Irp Flag or file open option).
15850//
15851// Note that "normal" is assumed to be zero by both the I/O system and file
15852// systems. Do not change this value.
15853//
15854
15855#define IRP_MN_NORMAL 0x00
15856#define IRP_MN_DPC 0x01
15857#define IRP_MN_MDL 0x02
15858#define IRP_MN_COMPLETE 0x04
15859#define IRP_MN_COMPRESSED 0x08
15860
15861#define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
15862#define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
15863#define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
15864
15865
15866//
15867// Device Control Request minor function codes for SCSI support. Note that
15868// user requests are assumed to be zero.
15869//
15870
15871#define IRP_MN_SCSI_CLASS 0x01
15872
15873//
15874// PNP minor function codes.
15875//
15876
15877#define IRP_MN_START_DEVICE 0x00
15878#define IRP_MN_QUERY_REMOVE_DEVICE 0x01
15879#define IRP_MN_REMOVE_DEVICE 0x02
15880#define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
15881#define IRP_MN_STOP_DEVICE 0x04
15882#define IRP_MN_QUERY_STOP_DEVICE 0x05
15883#define IRP_MN_CANCEL_STOP_DEVICE 0x06
15884
15885#define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
15886#define IRP_MN_QUERY_INTERFACE 0x08
15887#define IRP_MN_QUERY_CAPABILITIES 0x09
15888#define IRP_MN_QUERY_RESOURCES 0x0A
15889#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
15890#define IRP_MN_QUERY_DEVICE_TEXT 0x0C
15891#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
15892
15893#define IRP_MN_READ_CONFIG 0x0F
15894#define IRP_MN_WRITE_CONFIG 0x10
15895#define IRP_MN_EJECT 0x11
15896#define IRP_MN_SET_LOCK 0x12
15897#define IRP_MN_QUERY_ID 0x13
15898#define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
15899#define IRP_MN_QUERY_BUS_INFORMATION 0x15
15900#define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
15901#define IRP_MN_SURPRISE_REMOVAL 0x17
15902
15903#define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
15904
15905
15906//
15907// POWER minor function codes
15908//
15909#define IRP_MN_WAIT_WAKE 0x00
15910#define IRP_MN_POWER_SEQUENCE 0x01
15911#define IRP_MN_SET_POWER 0x02
15912#define IRP_MN_QUERY_POWER 0x03
15913
15914
15915//
15916// WMI minor function codes under IRP_MJ_SYSTEM_CONTROL
15917//
15918
15919#define IRP_MN_QUERY_ALL_DATA 0x00
15920#define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
15921#define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
15922#define IRP_MN_CHANGE_SINGLE_ITEM 0x03
15923#define IRP_MN_ENABLE_EVENTS 0x04
15924#define IRP_MN_DISABLE_EVENTS 0x05
15925#define IRP_MN_ENABLE_COLLECTION 0x06
15926#define IRP_MN_DISABLE_COLLECTION 0x07
15927#define IRP_MN_REGINFO 0x08
15928#define IRP_MN_EXECUTE_METHOD 0x09
15929// Minor code 0x0a is reserved
15930#define IRP_MN_REGINFO_EX 0x0b
15931
15932
15933
15934//
15935// Define option flags for IoCreateFile. Note that these values must be
15936// exactly the same as the SL_... flags for a create function. Note also
15937// that there are flags that may be passed to IoCreateFile that are not
15938// placed in the stack location for the create IRP. These flags start in
15939// the next byte.
15940//
15941
15942#define IO_FORCE_ACCESS_CHECK 0x0001
15943#define IO_NO_PARAMETER_CHECKING 0x0100
15944
15945//
15946// Define Information fields for whether or not a REPARSE or a REMOUNT has
15947// occurred in the file system.
15948//
15949
15950#define IO_REPARSE 0x0
15951#define IO_REMOUNT 0x1
15952
15953//
15954// Define callout routine type for use in IoQueryDeviceDescription().
15955//
15956
15957typedef NTSTATUS (*PIO_QUERY_DEVICE_ROUTINE)(
15958 IN PVOID Context,
15959 IN PUNICODE_STRING PathName,
15960 IN INTERFACE_TYPE BusType,
15961 IN ULONG BusNumber,
15962 IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
15963 IN CONFIGURATION_TYPE ControllerType,
15964 IN ULONG ControllerNumber,
15965 IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
15966 IN CONFIGURATION_TYPE PeripheralType,
15967 IN ULONG PeripheralNumber,
15968 IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
15969 );
15970
15971
15972// Defines the order of the information in the array of
15973// PKEY_VALUE_FULL_INFORMATION.
15974//
15975
15976typedef enum _IO_QUERY_DEVICE_DATA_FORMAT {
15977 IoQueryDeviceIdentifier = 0,
15978 IoQueryDeviceConfigurationData,
15979 IoQueryDeviceComponentInformation,
15980 IoQueryDeviceMaxData
15981} IO_QUERY_DEVICE_DATA_FORMAT, *PIO_QUERY_DEVICE_DATA_FORMAT;
15982
15983
15984//
15985// Define the objects that can be created by IoCreateFile.
15986//
15987
15988typedef enum _CREATE_FILE_TYPE {
15989 CreateFileTypeNone,
15990 CreateFileTypeNamedPipe,
15991 CreateFileTypeMailslot
15992} CREATE_FILE_TYPE;
15993
15994//
15995// Define the structures used by the I/O system
15996//
15997
15998//
15999// Define empty typedefs for the _IRP, _DEVICE_OBJECT, and _DRIVER_OBJECT
16000// structures so they may be referenced by function types before they are
16001// actually defined.
16002//
16003struct _DEVICE_DESCRIPTION;
16004struct _DEVICE_OBJECT;
16005struct _DMA_ADAPTER;
16006struct _DRIVER_OBJECT;
16007struct _DRIVE_LAYOUT_INFORMATION;
16008struct _DISK_PARTITION;
16009struct _FILE_OBJECT;
16010struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
16011struct _SCSI_REQUEST_BLOCK;
16012struct _SCATTER_GATHER_LIST;
16013
16014//
16015// Define the I/O version of a DPC routine.
16016//
16017
16018typedef
16019VOID
16020(*PIO_DPC_ROUTINE) (
16021 IN PKDPC Dpc,
16022 IN struct _DEVICE_OBJECT *DeviceObject,
16023 IN struct _IRP *Irp,
16024 IN PVOID Context
16025 );
16026
16027//
16028// Define driver timer routine type.
16029//
16030
16031typedef
16032VOID
16033(*PIO_TIMER_ROUTINE) (
16034 IN struct _DEVICE_OBJECT *DeviceObject,
16035 IN PVOID Context
16036 );
16037
16038//
16039// Define driver initialization routine type.
16040//
16041typedef
16042NTSTATUS
16043(*PDRIVER_INITIALIZE) (
16044 IN struct _DRIVER_OBJECT *DriverObject,
16045 IN PUNICODE_STRING RegistryPath
16046 );
16047
16048
16049//
16050// Define driver reinitialization routine type.
16051//
16052
16053typedef
16054VOID
16055(*PDRIVER_REINITIALIZE) (
16056 IN struct _DRIVER_OBJECT *DriverObject,
16057 IN PVOID Context,
16058 IN ULONG Count
16059 );
16060
16061
16062//
16063// Define driver cancel routine type.
16064//
16065
16066typedef
16067VOID
16068(*PDRIVER_CANCEL) (
16069 IN struct _DEVICE_OBJECT *DeviceObject,
16070 IN struct _IRP *Irp
16071 );
16072
16073//
16074// Define driver dispatch routine type.
16075//
16076
16077typedef
16078NTSTATUS
16079(*PDRIVER_DISPATCH) (
16080 IN struct _DEVICE_OBJECT *DeviceObject,
16081 IN struct _IRP *Irp
16082 );
16083
16084//
16085// Define driver start I/O routine type.
16086//
16087
16088typedef
16089VOID
16090(*PDRIVER_STARTIO) (
16091 IN struct _DEVICE_OBJECT *DeviceObject,
16092 IN struct _IRP *Irp
16093 );
16094
16095//
16096// Define driver unload routine type.
16097//
16098typedef
16099VOID
16100(*PDRIVER_UNLOAD) (
16101 IN struct _DRIVER_OBJECT *DriverObject
16102 );
16103//
16104// Define driver AddDevice routine type.
16105//
16106
16107typedef
16108NTSTATUS
16109(*PDRIVER_ADD_DEVICE) (
16110 IN struct _DRIVER_OBJECT *DriverObject,
16111 IN struct _DEVICE_OBJECT *PhysicalDeviceObject
16112 );
16113
16114
16115//
16116// Define fast I/O procedure prototypes.
16117//
16118// Fast I/O read and write procedures.
16119//
16120
16121typedef
16122BOOLEAN
16123(*PFAST_IO_CHECK_IF_POSSIBLE) (
16124 IN struct _FILE_OBJECT *FileObject,
16125 IN PLARGE_INTEGER FileOffset,
16126 IN ULONG Length,
16127 IN BOOLEAN Wait,
16128 IN ULONG LockKey,
16129 IN BOOLEAN CheckForReadOperation,
16130 OUT PIO_STATUS_BLOCK IoStatus,
16131 IN struct _DEVICE_OBJECT *DeviceObject
16132 );
16133
16134typedef
16135BOOLEAN
16136(*PFAST_IO_READ) (
16137 IN struct _FILE_OBJECT *FileObject,
16138 IN PLARGE_INTEGER FileOffset,
16139 IN ULONG Length,
16140 IN BOOLEAN Wait,
16141 IN ULONG LockKey,
16142 OUT PVOID Buffer,
16143 OUT PIO_STATUS_BLOCK IoStatus,
16144 IN struct _DEVICE_OBJECT *DeviceObject
16145 );
16146
16147typedef
16148BOOLEAN
16149(*PFAST_IO_WRITE) (
16150 IN struct _FILE_OBJECT *FileObject,
16151 IN PLARGE_INTEGER FileOffset,
16152 IN ULONG Length,
16153 IN BOOLEAN Wait,
16154 IN ULONG LockKey,
16155 IN PVOID Buffer,
16156 OUT PIO_STATUS_BLOCK IoStatus,
16157 IN struct _DEVICE_OBJECT *DeviceObject
16158 );
16159
16160//
16161// Fast I/O query basic and standard information procedures.
16162//
16163
16164typedef
16165BOOLEAN
16166(*PFAST_IO_QUERY_BASIC_INFO) (
16167 IN struct _FILE_OBJECT *FileObject,
16168 IN BOOLEAN Wait,
16169 OUT PFILE_BASIC_INFORMATION Buffer,
16170 OUT PIO_STATUS_BLOCK IoStatus,
16171 IN struct _DEVICE_OBJECT *DeviceObject
16172 );
16173
16174typedef
16175BOOLEAN
16176(*PFAST_IO_QUERY_STANDARD_INFO) (
16177 IN struct _FILE_OBJECT *FileObject,
16178 IN BOOLEAN Wait,
16179 OUT PFILE_STANDARD_INFORMATION Buffer,
16180 OUT PIO_STATUS_BLOCK IoStatus,
16181 IN struct _DEVICE_OBJECT *DeviceObject
16182 );
16183
16184//
16185// Fast I/O lock and unlock procedures.
16186//
16187
16188typedef
16189BOOLEAN
16190(*PFAST_IO_LOCK) (
16191 IN struct _FILE_OBJECT *FileObject,
16192 IN PLARGE_INTEGER FileOffset,
16193 IN PLARGE_INTEGER Length,
16194 PEPROCESS ProcessId,
16195 ULONG Key,
16196 BOOLEAN FailImmediately,
16197 BOOLEAN ExclusiveLock,
16198 OUT PIO_STATUS_BLOCK IoStatus,
16199 IN struct _DEVICE_OBJECT *DeviceObject
16200 );
16201
16202typedef
16203BOOLEAN
16204(*PFAST_IO_UNLOCK_SINGLE) (
16205 IN struct _FILE_OBJECT *FileObject,
16206 IN PLARGE_INTEGER FileOffset,
16207 IN PLARGE_INTEGER Length,
16208 PEPROCESS ProcessId,
16209 ULONG Key,
16210 OUT PIO_STATUS_BLOCK IoStatus,
16211 IN struct _DEVICE_OBJECT *DeviceObject
16212 );
16213
16214typedef
16215BOOLEAN
16216(*PFAST_IO_UNLOCK_ALL) (
16217 IN struct _FILE_OBJECT *FileObject,
16218 PEPROCESS ProcessId,
16219 OUT PIO_STATUS_BLOCK IoStatus,
16220 IN struct _DEVICE_OBJECT *DeviceObject
16221 );
16222
16223typedef
16224BOOLEAN
16225(*PFAST_IO_UNLOCK_ALL_BY_KEY) (
16226 IN struct _FILE_OBJECT *FileObject,
16227 PVOID ProcessId,
16228 ULONG Key,
16229 OUT PIO_STATUS_BLOCK IoStatus,
16230 IN struct _DEVICE_OBJECT *DeviceObject
16231 );
16232
16233//
16234// Fast I/O device control procedure.
16235//
16236
16237typedef
16238BOOLEAN
16239(*PFAST_IO_DEVICE_CONTROL) (
16240 IN struct _FILE_OBJECT *FileObject,
16241 IN BOOLEAN Wait,
16242 IN PVOID InputBuffer OPTIONAL,
16243 IN ULONG InputBufferLength,
16244 OUT PVOID OutputBuffer OPTIONAL,
16245 IN ULONG OutputBufferLength,
16246 IN ULONG IoControlCode,
16247 OUT PIO_STATUS_BLOCK IoStatus,
16248 IN struct _DEVICE_OBJECT *DeviceObject
16249 );
16250
16251//
16252// Define callbacks for NtCreateSection to synchronize correctly with
16253// the file system. It pre-acquires the resources that will be needed
16254// when calling to query and set file/allocation size in the file system.
16255//
16256
16257typedef
16258VOID
16259(*PFAST_IO_ACQUIRE_FILE) (
16260 IN struct _FILE_OBJECT *FileObject
16261 );
16262
16263typedef
16264VOID
16265(*PFAST_IO_RELEASE_FILE) (
16266 IN struct _FILE_OBJECT *FileObject
16267 );
16268
16269//
16270// Define callback for drivers that have device objects attached to lower-
16271// level drivers' device objects. This callback is made when the lower-level
16272// driver is deleting its device object.
16273//
16274
16275typedef
16276VOID
16277(*PFAST_IO_DETACH_DEVICE) (
16278 IN struct _DEVICE_OBJECT *SourceDevice,
16279 IN struct _DEVICE_OBJECT *TargetDevice
16280 );
16281
16282//
16283// This structure is used by the server to quickly get the information needed
16284// to service a server open call. It is takes what would be two fast io calls
16285// one for basic information and the other for standard information and makes
16286// it into one call.
16287//
16288
16289typedef
16290BOOLEAN
16291(*PFAST_IO_QUERY_NETWORK_OPEN_INFO) (
16292 IN struct _FILE_OBJECT *FileObject,
16293 IN BOOLEAN Wait,
16294 OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
16295 OUT struct _IO_STATUS_BLOCK *IoStatus,
16296 IN struct _DEVICE_OBJECT *DeviceObject
16297 );
16298
16299//
16300// Define Mdl-based routines for the server to call
16301//
16302
16303typedef
16304BOOLEAN
16305(*PFAST_IO_MDL_READ) (
16306 IN struct _FILE_OBJECT *FileObject,
16307 IN PLARGE_INTEGER FileOffset,
16308 IN ULONG Length,
16309 IN ULONG LockKey,
16310 OUT PMDL *MdlChain,
16311 OUT PIO_STATUS_BLOCK IoStatus,
16312 IN struct _DEVICE_OBJECT *DeviceObject
16313 );
16314
16315typedef
16316BOOLEAN
16317(*PFAST_IO_MDL_READ_COMPLETE) (
16318 IN struct _FILE_OBJECT *FileObject,
16319 IN PMDL MdlChain,
16320 IN struct _DEVICE_OBJECT *DeviceObject
16321 );
16322
16323typedef
16324BOOLEAN
16325(*PFAST_IO_PREPARE_MDL_WRITE) (
16326 IN struct _FILE_OBJECT *FileObject,
16327 IN PLARGE_INTEGER FileOffset,
16328 IN ULONG Length,
16329 IN ULONG LockKey,
16330 OUT PMDL *MdlChain,
16331 OUT PIO_STATUS_BLOCK IoStatus,
16332 IN struct _DEVICE_OBJECT *DeviceObject
16333 );
16334
16335typedef
16336BOOLEAN
16337(*PFAST_IO_MDL_WRITE_COMPLETE) (
16338 IN struct _FILE_OBJECT *FileObject,
16339 IN PLARGE_INTEGER FileOffset,
16340 IN PMDL MdlChain,
16341 IN struct _DEVICE_OBJECT *DeviceObject
16342 );
16343
16344//
16345// If this routine is present, it will be called by FsRtl
16346// to acquire the file for the mapped page writer.
16347//
16348
16349typedef
16350NTSTATUS
16351(*PFAST_IO_ACQUIRE_FOR_MOD_WRITE) (
16352 IN struct _FILE_OBJECT *FileObject,
16353 IN PLARGE_INTEGER EndingOffset,
16354 OUT struct _ERESOURCE **ResourceToRelease,
16355 IN struct _DEVICE_OBJECT *DeviceObject
16356 );
16357
16358typedef
16359NTSTATUS
16360(*PFAST_IO_RELEASE_FOR_MOD_WRITE) (
16361 IN struct _FILE_OBJECT *FileObject,
16362 IN struct _ERESOURCE *ResourceToRelease,
16363 IN struct _DEVICE_OBJECT *DeviceObject
16364 );
16365
16366//
16367// If this routine is present, it will be called by FsRtl
16368// to acquire the file for the mapped page writer.
16369//
16370
16371typedef
16372NTSTATUS
16373(*PFAST_IO_ACQUIRE_FOR_CCFLUSH) (
16374 IN struct _FILE_OBJECT *FileObject,
16375 IN struct _DEVICE_OBJECT *DeviceObject
16376 );
16377
16378typedef
16379NTSTATUS
16380(*PFAST_IO_RELEASE_FOR_CCFLUSH) (
16381 IN struct _FILE_OBJECT *FileObject,
16382 IN struct _DEVICE_OBJECT *DeviceObject
16383 );
16384
16385typedef
16386BOOLEAN
16387(*PFAST_IO_READ_COMPRESSED) (
16388 IN struct _FILE_OBJECT *FileObject,
16389 IN PLARGE_INTEGER FileOffset,
16390 IN ULONG Length,
16391 IN ULONG LockKey,
16392 OUT PVOID Buffer,
16393 OUT PMDL *MdlChain,
16394 OUT PIO_STATUS_BLOCK IoStatus,
16395 OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
16396 IN ULONG CompressedDataInfoLength,
16397 IN struct _DEVICE_OBJECT *DeviceObject
16398 );
16399
16400typedef
16401BOOLEAN
16402(*PFAST_IO_WRITE_COMPRESSED) (
16403 IN struct _FILE_OBJECT *FileObject,
16404 IN PLARGE_INTEGER FileOffset,
16405 IN ULONG Length,
16406 IN ULONG LockKey,
16407 IN PVOID Buffer,
16408 OUT PMDL *MdlChain,
16409 OUT PIO_STATUS_BLOCK IoStatus,
16410 IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
16411 IN ULONG CompressedDataInfoLength,
16412 IN struct _DEVICE_OBJECT *DeviceObject
16413 );
16414
16415typedef
16416BOOLEAN
16417(*PFAST_IO_MDL_READ_COMPLETE_COMPRESSED) (
16418 IN struct _FILE_OBJECT *FileObject,
16419 IN PMDL MdlChain,
16420 IN struct _DEVICE_OBJECT *DeviceObject
16421 );
16422
16423typedef
16424BOOLEAN
16425(*PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED) (
16426 IN struct _FILE_OBJECT *FileObject,
16427 IN PLARGE_INTEGER FileOffset,
16428 IN PMDL MdlChain,
16429 IN struct _DEVICE_OBJECT *DeviceObject
16430 );
16431
16432typedef
16433BOOLEAN
16434(*PFAST_IO_QUERY_OPEN) (
16435 IN struct _IRP *Irp,
16436 OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
16437 IN struct _DEVICE_OBJECT *DeviceObject
16438 );
16439
16440//
16441// Define the structure to describe the Fast I/O dispatch routines. Any
16442// additions made to this structure MUST be added monotonically to the end
16443// of the structure, and fields CANNOT be removed from the middle.
16444//
16445
16446typedef struct _FAST_IO_DISPATCH {
16447 ULONG SizeOfFastIoDispatch;
16448 PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
16449 PFAST_IO_READ FastIoRead;
16450 PFAST_IO_WRITE FastIoWrite;
16451 PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
16452 PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
16453 PFAST_IO_LOCK FastIoLock;
16454 PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
16455 PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
16456 PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
16457 PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
16458 PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
16459 PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
16460 PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
16461 PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
16462 PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
16463 PFAST_IO_MDL_READ MdlRead;
16464 PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
16465 PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
16466 PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
16467 PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
16468 PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
16469 PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
16470 PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
16471 PFAST_IO_QUERY_OPEN FastIoQueryOpen;
16472 PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
16473 PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
16474 PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
16475} FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
16476
16477//
16478// Define the actions that a driver execution routine may request of the
16479// adapter/controller allocation routines upon return.
16480//
16481
16482typedef enum _IO_ALLOCATION_ACTION {
16483 KeepObject = 1,
16484 DeallocateObject,
16485 DeallocateObjectKeepRegisters
16486} IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
16487
16488//
16489// Define device driver adapter/controller execution routine.
16490//
16491
16492typedef
16493IO_ALLOCATION_ACTION
16494(*PDRIVER_CONTROL) (
16495 IN struct _DEVICE_OBJECT *DeviceObject,
16496 IN struct _IRP *Irp,
16497 IN PVOID MapRegisterBase,
16498 IN PVOID Context
16499 );
16500
16501//
16502// Define the I/O system's security context type for use by file system's
16503// when checking access to volumes, files, and directories.
16504//
16505
16506typedef struct _IO_SECURITY_CONTEXT {
16507 PSECURITY_QUALITY_OF_SERVICE SecurityQos;
16508 PACCESS_STATE AccessState;
16509 ACCESS_MASK DesiredAccess;
16510 ULONG FullCreateOptions;
16511} IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
16512
16513//
16514// Define Volume Parameter Block (VPB) flags.
16515//
16516
16517#define VPB_MOUNTED 0x00000001
16518#define VPB_LOCKED 0x00000002
16519#define VPB_PERSISTENT 0x00000004
16520#define VPB_REMOVE_PENDING 0x00000008
16521#define VPB_RAW_MOUNT 0x00000010
16522
16523
16524//
16525// Volume Parameter Block (VPB)
16526//
16527
16528#define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR)) // 32 characters
16529
16530typedef struct _VPB {
16531 CSHORT Type;
16532 CSHORT Size;
16533 USHORT Flags;
16534 USHORT VolumeLabelLength; // in bytes
16535 struct _DEVICE_OBJECT *DeviceObject;
16536 struct _DEVICE_OBJECT *RealDevice;
16537 ULONG SerialNumber;
16538 ULONG ReferenceCount;
16539 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
16540} VPB, *PVPB;
16541
16542
16543#if defined(_WIN64)
16544
16545//
16546// Use __inline DMA macros (hal.h)
16547//
16548#ifndef USE_DMA_MACROS
16549#define USE_DMA_MACROS
16550#endif
16551
16552//
16553// Only PnP drivers!
16554//
16555#ifndef NO_LEGACY_DRIVERS
16556#define NO_LEGACY_DRIVERS
16557#endif
16558
16559#endif // _WIN64
16560
16561
16562#if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_) || defined(_NTOSP_))
16563
16564
16565//
16566// Define object type specific fields of various objects used by the I/O system
16567//
16568
16569typedef struct _DMA_ADAPTER *PADAPTER_OBJECT;
16570
16571
16572#else
16573
16574//
16575// Define object type specific fields of various objects used by the I/O system
16576//
16577
16578typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
16579
16580#endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_ || _NTOSP_)
16581
16582
16583//
16584// Define Wait Context Block (WCB)
16585//
16586
16587typedef struct _WAIT_CONTEXT_BLOCK {
16588 KDEVICE_QUEUE_ENTRY WaitQueueEntry;
16589 PDRIVER_CONTROL DeviceRoutine;
16590 PVOID DeviceContext;
16591 ULONG NumberOfMapRegisters;
16592 PVOID DeviceObject;
16593 PVOID CurrentIrp;
16594 PKDPC BufferChainingDpc;
16595} WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
16596
16597
16598
16599typedef struct _CONTROLLER_OBJECT {
16600 CSHORT Type;
16601 CSHORT Size;
16602 PVOID ControllerExtension;
16603 KDEVICE_QUEUE DeviceWaitQueue;
16604
16605 ULONG Spare1;
16606 LARGE_INTEGER Spare2;
16607
16608} CONTROLLER_OBJECT, *PCONTROLLER_OBJECT;
16609
16610
16611//
16612// Define Device Object (DO) flags
16613//
16614#define DO_VERIFY_VOLUME 0x00000002
16615#define DO_BUFFERED_IO 0x00000004
16616#define DO_EXCLUSIVE 0x00000008
16617#define DO_DIRECT_IO 0x00000010
16618#define DO_MAP_IO_BUFFER 0x00000020
16619#define DO_DEVICE_HAS_NAME 0x00000040
16620#define DO_DEVICE_INITIALIZING 0x00000080
16621#define DO_SYSTEM_BOOT_PARTITION 0x00000100
16622#define DO_LONG_TERM_REQUESTS 0x00000200
16623#define DO_NEVER_LAST_DEVICE 0x00000400
16624#define DO_SHUTDOWN_REGISTERED 0x00000800
16625#define DO_BUS_ENUMERATED_DEVICE 0x00001000
16626#define DO_POWER_PAGABLE 0x00002000
16627#define DO_POWER_INRUSH 0x00004000
16628#define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
16629//
16630// Device Object structure definition
16631//
16632
16633typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
16634 CSHORT Type;
16635 USHORT Size;
16636 LONG ReferenceCount;
16637 struct _DRIVER_OBJECT *DriverObject;
16638 struct _DEVICE_OBJECT *NextDevice;
16639 struct _DEVICE_OBJECT *AttachedDevice;
16640 struct _IRP *CurrentIrp;
16641 PIO_TIMER Timer;
16642 ULONG Flags; // See above: DO_...
16643 ULONG Characteristics; // See ntioapi: FILE_...
16644 PVPB Vpb;
16645 PVOID DeviceExtension;
16646 DEVICE_TYPE DeviceType;
16647 CCHAR StackSize;
16648 union {
16649 LIST_ENTRY ListEntry;
16650 WAIT_CONTEXT_BLOCK Wcb;
16651 } Queue;
16652 ULONG AlignmentRequirement;
16653 KDEVICE_QUEUE DeviceQueue;
16654 KDPC Dpc;
16655
16656 //
16657 // The following field is for exclusive use by the filesystem to keep
16658 // track of the number of Fsp threads currently using the device
16659 //
16660
16661 ULONG ActiveThreadCount;
16662 PSECURITY_DESCRIPTOR SecurityDescriptor;
16663 KEVENT DeviceLock;
16664
16665 USHORT SectorSize;
16666 USHORT Spare1;
16667
16668 struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
16669 PVOID Reserved;
16670} DEVICE_OBJECT;
16671
16672typedef struct _DEVICE_OBJECT *PDEVICE_OBJECT;
16673
16674
16675struct _DEVICE_OBJECT_POWER_EXTENSION;
16676
16677typedef struct _DEVOBJ_EXTENSION {
16678
16679 CSHORT Type;
16680 USHORT Size;
16681
16682 //
16683 // Public part of the DeviceObjectExtension structure
16684 //
16685
16686 PDEVICE_OBJECT DeviceObject; // owning device object
16687
16688
16689} DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
16690
16691//
16692// Define Driver Object (DRVO) flags
16693//
16694
16695#define DRVO_UNLOAD_INVOKED 0x00000001
16696#define DRVO_LEGACY_DRIVER 0x00000002
16697#define DRVO_BUILTIN_DRIVER 0x00000004 // Driver objects for Hal, PnP Mgr
16698
16699#define DRVO_REINIT_REGISTERED 0x00000008
16700#define DRVO_INITIALIZED 0x00000010
16701#define DRVO_BOOTREINIT_REGISTERED 0x00000020
16702#define DRVO_LEGACY_RESOURCES 0x00000040
16703
16704
16705
16706typedef struct _DRIVER_EXTENSION {
16707
16708 //
16709 // Back pointer to Driver Object
16710 //
16711
16712 struct _DRIVER_OBJECT *DriverObject;
16713
16714 //
16715 // The AddDevice entry point is called by the Plug & Play manager
16716 // to inform the driver when a new device instance arrives that this
16717 // driver must control.
16718 //
16719
16720 PDRIVER_ADD_DEVICE AddDevice;
16721
16722 //
16723 // The count field is used to count the number of times the driver has
16724 // had its registered reinitialization routine invoked.
16725 //
16726
16727 ULONG Count;
16728
16729 //
16730 // The service name field is used by the pnp manager to determine
16731 // where the driver related info is stored in the registry.
16732 //
16733
16734 UNICODE_STRING ServiceKeyName;
16735
16736 //
16737 // Note: any new shared fields get added here.
16738 //
16739
16740
16741} DRIVER_EXTENSION, *PDRIVER_EXTENSION;
16742
16743
16744typedef struct _DRIVER_OBJECT {
16745 CSHORT Type;
16746 CSHORT Size;
16747
16748 //
16749 // The following links all of the devices created by a single driver
16750 // together on a list, and the Flags word provides an extensible flag
16751 // location for driver objects.
16752 //
16753
16754 PDEVICE_OBJECT DeviceObject;
16755 ULONG Flags;
16756
16757 //
16758 // The following section describes where the driver is loaded. The count
16759 // field is used to count the number of times the driver has had its
16760 // registered reinitialization routine invoked.
16761 //
16762
16763 PVOID DriverStart;
16764 ULONG DriverSize;
16765 PVOID DriverSection;
16766 PDRIVER_EXTENSION DriverExtension;
16767
16768 //
16769 // The driver name field is used by the error log thread
16770 // determine the name of the driver that an I/O request is/was bound.
16771 //
16772
16773 UNICODE_STRING DriverName;
16774
16775 //
16776 // The following section is for registry support. Thise is a pointer
16777 // to the path to the hardware information in the registry
16778 //
16779
16780 PUNICODE_STRING HardwareDatabase;
16781
16782 //
16783 // The following section contains the optional pointer to an array of
16784 // alternate entry points to a driver for "fast I/O" support. Fast I/O
16785 // is performed by invoking the driver routine directly with separate
16786 // parameters, rather than using the standard IRP call mechanism. Note
16787 // that these functions may only be used for synchronous I/O, and when
16788 // the file is cached.
16789 //
16790
16791 PFAST_IO_DISPATCH FastIoDispatch;
16792
16793 //
16794 // The following section describes the entry points to this particular
16795 // driver. Note that the major function dispatch table must be the last
16796 // field in the object so that it remains extensible.
16797 //
16798
16799 PDRIVER_INITIALIZE DriverInit;
16800 PDRIVER_STARTIO DriverStartIo;
16801 PDRIVER_UNLOAD DriverUnload;
16802 PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
16803
16804} DRIVER_OBJECT;
16805typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
16806
16807
16808
16809//
16810// The following structure is pointed to by the SectionObject pointer field
16811// of a file object, and is allocated by the various NT file systems.
16812//
16813
16814typedef struct _SECTION_OBJECT_POINTERS {
16815 PVOID DataSectionObject;
16816 PVOID SharedCacheMap;
16817 PVOID ImageSectionObject;
16818} SECTION_OBJECT_POINTERS;
16819typedef SECTION_OBJECT_POINTERS *PSECTION_OBJECT_POINTERS;
16820
16821//
16822// Define the format of a completion message.
16823//
16824
16825typedef struct _IO_COMPLETION_CONTEXT {
16826 PVOID Port;
16827 PVOID Key;
16828} IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
16829
16830//
16831// Define File Object (FO) flags
16832//
16833
16834#define FO_FILE_OPEN 0x00000001
16835#define FO_SYNCHRONOUS_IO 0x00000002
16836#define FO_ALERTABLE_IO 0x00000004
16837#define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
16838#define FO_WRITE_THROUGH 0x00000010
16839#define FO_SEQUENTIAL_ONLY 0x00000020
16840#define FO_CACHE_SUPPORTED 0x00000040
16841#define FO_NAMED_PIPE 0x00000080
16842#define FO_STREAM_FILE 0x00000100
16843#define FO_MAILSLOT 0x00000200
16844#define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
16845#define FO_DIRECT_DEVICE_OPEN 0x00000800
16846#define FO_FILE_MODIFIED 0x00001000
16847#define FO_FILE_SIZE_CHANGED 0x00002000
16848#define FO_CLEANUP_COMPLETE 0x00004000
16849#define FO_TEMPORARY_FILE 0x00008000
16850#define FO_DELETE_ON_CLOSE 0x00010000
16851#define FO_OPENED_CASE_SENSITIVE 0x00020000
16852#define FO_HANDLE_CREATED 0x00040000
16853#define FO_FILE_FAST_IO_READ 0x00080000
16854#define FO_RANDOM_ACCESS 0x00100000
16855#define FO_FILE_OPEN_CANCELLED 0x00200000
16856#define FO_VOLUME_OPEN 0x00400000
16857#define FO_FILE_OBJECT_HAS_EXTENSION 0x00800000
16858#define FO_REMOTE_ORIGIN 0x01000000
16859
16860typedef struct _FILE_OBJECT {
16861 CSHORT Type;
16862 CSHORT Size;
16863 PDEVICE_OBJECT DeviceObject;
16864 PVPB Vpb;
16865 PVOID FsContext;
16866 PVOID FsContext2;
16867 PSECTION_OBJECT_POINTERS SectionObjectPointer;
16868 PVOID PrivateCacheMap;
16869 NTSTATUS FinalStatus;
16870 struct _FILE_OBJECT *RelatedFileObject;
16871 BOOLEAN LockOperation;
16872 BOOLEAN DeletePending;
16873 BOOLEAN ReadAccess;
16874 BOOLEAN WriteAccess;
16875 BOOLEAN DeleteAccess;
16876 BOOLEAN SharedRead;
16877 BOOLEAN SharedWrite;
16878 BOOLEAN SharedDelete;
16879 ULONG Flags;
16880 UNICODE_STRING FileName;
16881 LARGE_INTEGER CurrentByteOffset;
16882 ULONG Waiters;
16883 ULONG Busy;
16884 PVOID LastLock;
16885 KEVENT Lock;
16886 KEVENT Event;
16887 PIO_COMPLETION_CONTEXT CompletionContext;
16888} FILE_OBJECT;
16889typedef struct _FILE_OBJECT *PFILE_OBJECT;
16890
16891//
16892// Define I/O Request Packet (IRP) flags
16893//
16894
16895#define IRP_NOCACHE 0x00000001
16896#define IRP_PAGING_IO 0x00000002
16897#define IRP_MOUNT_COMPLETION 0x00000002
16898#define IRP_SYNCHRONOUS_API 0x00000004
16899#define IRP_ASSOCIATED_IRP 0x00000008
16900#define IRP_BUFFERED_IO 0x00000010
16901#define IRP_DEALLOCATE_BUFFER 0x00000020
16902#define IRP_INPUT_OPERATION 0x00000040
16903#define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
16904#define IRP_CREATE_OPERATION 0x00000080
16905#define IRP_READ_OPERATION 0x00000100
16906#define IRP_WRITE_OPERATION 0x00000200
16907#define IRP_CLOSE_OPERATION 0x00000400
16908
16909
16910#define IRP_DEFER_IO_COMPLETION 0x00000800
16911#define IRP_OB_QUERY_NAME 0x00001000
16912#define IRP_HOLD_DEVICE_QUEUE 0x00002000
16913
16914
16915
16916//
16917// Define I/O request packet (IRP) alternate flags for allocation control.
16918//
16919
16920#define IRP_QUOTA_CHARGED 0x01
16921#define IRP_ALLOCATED_MUST_SUCCEED 0x02
16922#define IRP_ALLOCATED_FIXED_SIZE 0x04
16923#define IRP_LOOKASIDE_ALLOCATION 0x08
16924
16925//
16926// I/O Request Packet (IRP) definition
16927//
16928
16929typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP {
16930 CSHORT Type;
16931 USHORT Size;
16932
16933 //
16934 // Define the common fields used to control the IRP.
16935 //
16936
16937 //
16938 // Define a pointer to the Memory Descriptor List (MDL) for this I/O
16939 // request. This field is only used if the I/O is "direct I/O".
16940 //
16941
16942 PMDL MdlAddress;
16943
16944 //
16945 // Flags word - used to remember various flags.
16946 //
16947
16948 ULONG Flags;
16949
16950 //
16951 // The following union is used for one of three purposes:
16952 //
16953 // 1. This IRP is an associated IRP. The field is a pointer to a master
16954 // IRP.
16955 //
16956 // 2. This is the master IRP. The field is the count of the number of
16957 // IRPs which must complete (associated IRPs) before the master can
16958 // complete.
16959 //
16960 // 3. This operation is being buffered and the field is the address of
16961 // the system space buffer.
16962 //
16963
16964 union {
16965 struct _IRP *MasterIrp;
16966 LONG IrpCount;
16967 PVOID SystemBuffer;
16968 } AssociatedIrp;
16969
16970 //
16971 // Thread list entry - allows queueing the IRP to the thread pending I/O
16972 // request packet list.
16973 //
16974
16975 LIST_ENTRY ThreadListEntry;
16976
16977 //
16978 // I/O status - final status of operation.
16979 //
16980
16981 IO_STATUS_BLOCK IoStatus;
16982
16983 //
16984 // Requestor mode - mode of the original requestor of this operation.
16985 //
16986
16987 KPROCESSOR_MODE RequestorMode;
16988
16989 //
16990 // Pending returned - TRUE if pending was initially returned as the
16991 // status for this packet.
16992 //
16993
16994 BOOLEAN PendingReturned;
16995
16996 //
16997 // Stack state information.
16998 //
16999
17000 CHAR StackCount;
17001 CHAR CurrentLocation;
17002
17003 //
17004 // Cancel - packet has been canceled.
17005 //
17006
17007 BOOLEAN Cancel;
17008
17009 //
17010 // Cancel Irql - Irql at which the cancel spinlock was acquired.
17011 //
17012
17013 KIRQL CancelIrql;
17014
17015 //
17016 // ApcEnvironment - Used to save the APC environment at the time that the
17017 // packet was initialized.
17018 //
17019
17020 CCHAR ApcEnvironment;
17021
17022 //
17023 // Allocation control flags.
17024 //
17025
17026 UCHAR AllocationFlags;
17027
17028 //
17029 // User parameters.
17030 //
17031
17032 PIO_STATUS_BLOCK UserIosb;
17033 PKEVENT UserEvent;
17034 union {
17035 struct {
17036 PIO_APC_ROUTINE UserApcRoutine;
17037 PVOID UserApcContext;
17038 } AsynchronousParameters;
17039 LARGE_INTEGER AllocationSize;
17040 } Overlay;
17041
17042 //
17043 // CancelRoutine - Used to contain the address of a cancel routine supplied
17044 // by a device driver when the IRP is in a cancelable state.
17045 //
17046
17047 PDRIVER_CANCEL CancelRoutine;
17048
17049 //
17050 // Note that the UserBuffer parameter is outside of the stack so that I/O
17051 // completion can copy data back into the user's address space without
17052 // having to know exactly which service was being invoked. The length
17053 // of the copy is stored in the second half of the I/O status block. If
17054 // the UserBuffer field is NULL, then no copy is performed.
17055 //
17056
17057 PVOID UserBuffer;
17058
17059 //
17060 // Kernel structures
17061 //
17062 // The following section contains kernel structures which the IRP needs
17063 // in order to place various work information in kernel controller system
17064 // queues. Because the size and alignment cannot be controlled, they are
17065 // placed here at the end so they just hang off and do not affect the
17066 // alignment of other fields in the IRP.
17067 //
17068
17069 union {
17070
17071 struct {
17072
17073 union {
17074
17075 //
17076 // DeviceQueueEntry - The device queue entry field is used to
17077 // queue the IRP to the device driver device queue.
17078 //
17079
17080 KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
17081
17082 struct {
17083
17084 //
17085 // The following are available to the driver to use in
17086 // whatever manner is desired, while the driver owns the
17087 // packet.
17088 //
17089
17090 PVOID DriverContext[4];
17091
17092 } ;
17093
17094 } ;
17095
17096 //
17097 // Thread - pointer to caller's Thread Control Block.
17098 //
17099
17100 PETHREAD Thread;
17101
17102 //
17103 // Auxiliary buffer - pointer to any auxiliary buffer that is
17104 // required to pass information to a driver that is not contained
17105 // in a normal buffer.
17106 //
17107
17108 PCHAR AuxiliaryBuffer;
17109
17110 //
17111 // The following unnamed structure must be exactly identical
17112 // to the unnamed structure used in the minipacket header used
17113 // for completion queue entries.
17114 //
17115
17116 struct {
17117
17118 //
17119 // List entry - used to queue the packet to completion queue, among
17120 // others.
17121 //
17122
17123 LIST_ENTRY ListEntry;
17124
17125 union {
17126
17127 //
17128 // Current stack location - contains a pointer to the current
17129 // IO_STACK_LOCATION structure in the IRP stack. This field
17130 // should never be directly accessed by drivers. They should
17131 // use the standard functions.
17132 //
17133
17134 struct _IO_STACK_LOCATION *CurrentStackLocation;
17135
17136 //
17137 // Minipacket type.
17138 //
17139
17140 ULONG PacketType;
17141 };
17142 };
17143
17144 //
17145 // Original file object - pointer to the original file object
17146 // that was used to open the file. This field is owned by the
17147 // I/O system and should not be used by any other drivers.
17148 //
17149
17150 PFILE_OBJECT OriginalFileObject;
17151
17152 } Overlay;
17153
17154 //
17155 // APC - This APC control block is used for the special kernel APC as
17156 // well as for the caller's APC, if one was specified in the original
17157 // argument list. If so, then the APC is reused for the normal APC for
17158 // whatever mode the caller was in and the "special" routine that is
17159 // invoked before the APC gets control simply deallocates the IRP.
17160 //
17161
17162 KAPC Apc;
17163
17164 //
17165 // CompletionKey - This is the key that is used to distinguish
17166 // individual I/O operations initiated on a single file handle.
17167 //
17168
17169 PVOID CompletionKey;
17170
17171 } Tail;
17172
17173} IRP, *PIRP;
17174
17175//
17176// Define completion routine types for use in stack locations in an IRP
17177//
17178
17179typedef
17180NTSTATUS
17181(*PIO_COMPLETION_ROUTINE) (
17182 IN PDEVICE_OBJECT DeviceObject,
17183 IN PIRP Irp,
17184 IN PVOID Context
17185 );
17186
17187//
17188// Define stack location control flags
17189//
17190
17191#define SL_PENDING_RETURNED 0x01
17192#define SL_INVOKE_ON_CANCEL 0x20
17193#define SL_INVOKE_ON_SUCCESS 0x40
17194#define SL_INVOKE_ON_ERROR 0x80
17195
17196//
17197// Define flags for various functions
17198//
17199
17200//
17201// Create / Create Named Pipe
17202//
17203// The following flags must exactly match those in the IoCreateFile call's
17204// options. The case sensitive flag is added in later, by the parse routine,
17205// and is not an actual option to open. Rather, it is part of the object
17206// manager's attributes structure.
17207//
17208
17209#define SL_FORCE_ACCESS_CHECK 0x01
17210#define SL_OPEN_PAGING_FILE 0x02
17211#define SL_OPEN_TARGET_DIRECTORY 0x04
17212
17213#define SL_CASE_SENSITIVE 0x80
17214
17215//
17216// Read / Write
17217//
17218
17219#define SL_KEY_SPECIFIED 0x01
17220#define SL_OVERRIDE_VERIFY_VOLUME 0x02
17221#define SL_WRITE_THROUGH 0x04
17222#define SL_FT_SEQUENTIAL_WRITE 0x08
17223
17224//
17225// Device I/O Control
17226//
17227//
17228// Same SL_OVERRIDE_VERIFY_VOLUME as for read/write above.
17229//
17230
17231#define SL_READ_ACCESS_GRANTED 0x01
17232#define SL_WRITE_ACCESS_GRANTED 0x04 // Gap for SL_OVERRIDE_VERIFY_VOLUME
17233
17234//
17235// Lock
17236//
17237
17238#define SL_FAIL_IMMEDIATELY 0x01
17239#define SL_EXCLUSIVE_LOCK 0x02
17240
17241//
17242// QueryDirectory / QueryEa / QueryQuota
17243//
17244
17245#define SL_RESTART_SCAN 0x01
17246#define SL_RETURN_SINGLE_ENTRY 0x02
17247#define SL_INDEX_SPECIFIED 0x04
17248
17249//
17250// NotifyDirectory
17251//
17252
17253#define SL_WATCH_TREE 0x01
17254
17255//
17256// FileSystemControl
17257//
17258// minor: mount/verify volume
17259//
17260
17261#define SL_ALLOW_RAW_MOUNT 0x01
17262
17263//
17264// Define PNP/POWER types required by IRP_MJ_PNP/IRP_MJ_POWER.
17265//
17266
17267typedef enum _DEVICE_RELATION_TYPE {
17268 BusRelations,
17269 EjectionRelations,
17270 PowerRelations,
17271 RemovalRelations,
17272 TargetDeviceRelation,
17273 SingleBusRelations
17274} DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
17275
17276typedef struct _DEVICE_RELATIONS {
17277 ULONG Count;
17278 PDEVICE_OBJECT Objects[1]; // variable length
17279} DEVICE_RELATIONS, *PDEVICE_RELATIONS;
17280
17281typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
17282 DeviceUsageTypeUndefined,
17283 DeviceUsageTypePaging,
17284 DeviceUsageTypeHibernation,
17285 DeviceUsageTypeDumpFile
17286} DEVICE_USAGE_NOTIFICATION_TYPE;
17287
17288
17289
17290// workaround overloaded definition (rpc generated headers all define INTERFACE
17291// to match the class name).
17292#undef INTERFACE
17293
17294typedef struct _INTERFACE {
17295 USHORT Size;
17296 USHORT Version;
17297 PVOID Context;
17298 PINTERFACE_REFERENCE InterfaceReference;
17299 PINTERFACE_DEREFERENCE InterfaceDereference;
17300 // interface specific entries go here
17301} INTERFACE, *PINTERFACE;
17302
17303
17304
17305typedef struct _DEVICE_CAPABILITIES {
17306 USHORT Size;
17307 USHORT Version; // the version documented here is version 1
17308 ULONG DeviceD1:1;
17309 ULONG DeviceD2:1;
17310 ULONG LockSupported:1;
17311 ULONG EjectSupported:1; // Ejectable in S0
17312 ULONG Removable:1;
17313 ULONG DockDevice:1;
17314 ULONG UniqueID:1;
17315 ULONG SilentInstall:1;
17316 ULONG RawDeviceOK:1;
17317 ULONG SurpriseRemovalOK:1;
17318 ULONG WakeFromD0:1;
17319 ULONG WakeFromD1:1;
17320 ULONG WakeFromD2:1;
17321 ULONG WakeFromD3:1;
17322 ULONG HardwareDisabled:1;
17323 ULONG NonDynamic:1;
17324 ULONG WarmEjectSupported:1;
17325 ULONG NoDisplayInUI:1;
17326 ULONG Reserved:14;
17327
17328 ULONG Address;
17329 ULONG UINumber;
17330
17331 DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM];
17332 SYSTEM_POWER_STATE SystemWake;
17333 DEVICE_POWER_STATE DeviceWake;
17334 ULONG D1Latency;
17335 ULONG D2Latency;
17336 ULONG D3Latency;
17337} DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
17338
17339typedef struct _POWER_SEQUENCE {
17340 ULONG SequenceD1;
17341 ULONG SequenceD2;
17342 ULONG SequenceD3;
17343} POWER_SEQUENCE, *PPOWER_SEQUENCE;
17344
17345typedef enum {
17346 BusQueryDeviceID = 0, // <Enumerator>\<Enumerator-specific device id>
17347 BusQueryHardwareIDs = 1, // Hardware ids
17348 BusQueryCompatibleIDs = 2, // compatible device ids
17349 BusQueryInstanceID = 3, // persistent id for this instance of the device
17350 BusQueryDeviceSerialNumber = 4 // serial number for this device
17351} BUS_QUERY_ID_TYPE, *PBUS_QUERY_ID_TYPE;
17352
17353typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
17354
17355#define PNP_DEVICE_DISABLED 0x00000001
17356#define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
17357#define PNP_DEVICE_FAILED 0x00000004
17358#define PNP_DEVICE_REMOVED 0x00000008
17359#define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
17360#define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
17361
17362typedef enum {
17363 DeviceTextDescription = 0, // DeviceDesc property
17364 DeviceTextLocationInformation = 1 // DeviceLocation property
17365} DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE;
17366
17367//
17368// Define I/O Request Packet (IRP) stack locations
17369//
17370
17371#if !defined(_AMD64_) && !defined(_IA64_)
17372#include "pshpack4.h"
17373#endif
17374
17375
17376
17377#if defined(_WIN64)
17378#define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
17379#else
17380#define POINTER_ALIGNMENT
17381#endif
17382
17383
17384
17385typedef struct _IO_STACK_LOCATION {
17386 UCHAR MajorFunction;
17387 UCHAR MinorFunction;
17388 UCHAR Flags;
17389 UCHAR Control;
17390
17391 //
17392 // The following user parameters are based on the service that is being
17393 // invoked. Drivers and file systems can determine which set to use based
17394 // on the above major and minor function codes.
17395 //
17396
17397 union {
17398
17399 //
17400 // System service parameters for: NtCreateFile
17401 //
17402
17403 struct {
17404 PIO_SECURITY_CONTEXT SecurityContext;
17405 ULONG Options;
17406 USHORT POINTER_ALIGNMENT FileAttributes;
17407 USHORT ShareAccess;
17408 ULONG POINTER_ALIGNMENT EaLength;
17409 } Create;
17410
17411
17412 //
17413 // System service parameters for: NtReadFile
17414 //
17415
17416 struct {
17417 ULONG Length;
17418 ULONG POINTER_ALIGNMENT Key;
17419 LARGE_INTEGER ByteOffset;
17420 } Read;
17421
17422 //
17423 // System service parameters for: NtWriteFile
17424 //
17425
17426 struct {
17427 ULONG Length;
17428 ULONG POINTER_ALIGNMENT Key;
17429 LARGE_INTEGER ByteOffset;
17430 } Write;
17431
17432
17433 //
17434 // System service parameters for: NtQueryInformationFile
17435 //
17436
17437 struct {
17438 ULONG Length;
17439 FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
17440 } QueryFile;
17441
17442 //
17443 // System service parameters for: NtSetInformationFile
17444 //
17445
17446 struct {
17447 ULONG Length;
17448 FILE_INFORMATION_CLASS POINTER_ALIGNMENT FileInformationClass;
17449 PFILE_OBJECT FileObject;
17450 union {
17451 struct {
17452 BOOLEAN ReplaceIfExists;
17453 BOOLEAN AdvanceOnly;
17454 };
17455 ULONG ClusterCount;
17456 HANDLE DeleteHandle;
17457 };
17458 } SetFile;
17459
17460
17461 //
17462 // System service parameters for: NtQueryVolumeInformationFile
17463 //
17464
17465 struct {
17466 ULONG Length;
17467 FS_INFORMATION_CLASS POINTER_ALIGNMENT FsInformationClass;
17468 } QueryVolume;
17469
17470
17471 //
17472 // System service parameters for: NtFlushBuffersFile
17473 //
17474 // No extra user-supplied parameters.
17475 //
17476
17477
17478 //
17479 // System service parameters for: NtDeviceIoControlFile
17480 //
17481 // Note that the user's output buffer is stored in the UserBuffer field
17482 // and the user's input buffer is stored in the SystemBuffer field.
17483 //
17484
17485 struct {
17486 ULONG OutputBufferLength;
17487 ULONG POINTER_ALIGNMENT InputBufferLength;
17488 ULONG POINTER_ALIGNMENT IoControlCode;
17489 PVOID Type3InputBuffer;
17490 } DeviceIoControl;
17491
17492
17493 //
17494 // System service parameters for: NtQuerySecurityObject
17495 //
17496
17497 struct {
17498 SECURITY_INFORMATION SecurityInformation;
17499 ULONG POINTER_ALIGNMENT Length;
17500 } QuerySecurity;
17501
17502 //
17503 // System service parameters for: NtSetSecurityObject
17504 //
17505
17506 struct {
17507 SECURITY_INFORMATION SecurityInformation;
17508 PSECURITY_DESCRIPTOR SecurityDescriptor;
17509 } SetSecurity;
17510
17511
17512 //
17513 // Non-system service parameters.
17514 //
17515 // Parameters for MountVolume
17516 //
17517
17518 struct {
17519 PVPB Vpb;
17520 PDEVICE_OBJECT DeviceObject;
17521 } MountVolume;
17522
17523 //
17524 // Parameters for VerifyVolume
17525 //
17526
17527 struct {
17528 PVPB Vpb;
17529 PDEVICE_OBJECT DeviceObject;
17530 } VerifyVolume;
17531
17532 //
17533 // Parameters for Scsi with internal device contorl.
17534 //
17535
17536 struct {
17537 struct _SCSI_REQUEST_BLOCK *Srb;
17538 } Scsi;
17539
17540
17541 //
17542 // Parameters for IRP_MN_QUERY_DEVICE_RELATIONS
17543 //
17544
17545 struct {
17546 DEVICE_RELATION_TYPE Type;
17547 } QueryDeviceRelations;
17548
17549 //
17550 // Parameters for IRP_MN_QUERY_INTERFACE
17551 //
17552
17553 struct {
17554 CONST GUID *InterfaceType;
17555 USHORT Size;
17556 USHORT Version;
17557 PINTERFACE Interface;
17558 PVOID InterfaceSpecificData;
17559 } QueryInterface;
17560
17561
17562
17563 //
17564 // Parameters for IRP_MN_QUERY_CAPABILITIES
17565 //
17566
17567 struct {
17568 PDEVICE_CAPABILITIES Capabilities;
17569 } DeviceCapabilities;
17570
17571 //
17572 // Parameters for IRP_MN_FILTER_RESOURCE_REQUIREMENTS
17573 //
17574
17575 struct {
17576 PIO_RESOURCE_REQUIREMENTS_LIST IoResourceRequirementList;
17577 } FilterResourceRequirements;
17578
17579 //
17580 // Parameters for IRP_MN_READ_CONFIG and IRP_MN_WRITE_CONFIG
17581 //
17582
17583 struct {
17584 ULONG WhichSpace;
17585 PVOID Buffer;
17586 ULONG Offset;
17587 ULONG POINTER_ALIGNMENT Length;
17588 } ReadWriteConfig;
17589
17590 //
17591 // Parameters for IRP_MN_SET_LOCK
17592 //
17593
17594 struct {
17595 BOOLEAN Lock;
17596 } SetLock;
17597
17598 //
17599 // Parameters for IRP_MN_QUERY_ID
17600 //
17601
17602 struct {
17603 BUS_QUERY_ID_TYPE IdType;
17604 } QueryId;
17605
17606 //
17607 // Parameters for IRP_MN_QUERY_DEVICE_TEXT
17608 //
17609
17610 struct {
17611 DEVICE_TEXT_TYPE DeviceTextType;
17612 LCID POINTER_ALIGNMENT LocaleId;
17613 } QueryDeviceText;
17614
17615 //
17616 // Parameters for IRP_MN_DEVICE_USAGE_NOTIFICATION
17617 //
17618
17619 struct {
17620 BOOLEAN InPath;
17621 BOOLEAN Reserved[3];
17622 DEVICE_USAGE_NOTIFICATION_TYPE POINTER_ALIGNMENT Type;
17623 } UsageNotification;
17624
17625 //
17626 // Parameters for IRP_MN_WAIT_WAKE
17627 //
17628
17629 struct {
17630 SYSTEM_POWER_STATE PowerState;
17631 } WaitWake;
17632
17633 //
17634 // Parameter for IRP_MN_POWER_SEQUENCE
17635 //
17636
17637 struct {
17638 PPOWER_SEQUENCE PowerSequence;
17639 } PowerSequence;
17640
17641 //
17642 // Parameters for IRP_MN_SET_POWER and IRP_MN_QUERY_POWER
17643 //
17644
17645 struct {
17646 ULONG SystemContext;
17647 POWER_STATE_TYPE POINTER_ALIGNMENT Type;
17648 POWER_STATE POINTER_ALIGNMENT State;
17649 POWER_ACTION POINTER_ALIGNMENT ShutdownType;
17650 } Power;
17651
17652 //
17653 // Parameters for StartDevice
17654 //
17655
17656 struct {
17657 PCM_RESOURCE_LIST AllocatedResources;
17658 PCM_RESOURCE_LIST AllocatedResourcesTranslated;
17659 } StartDevice;
17660
17661
17662 //
17663 // Parameters for Cleanup
17664 //
17665 // No extra parameters supplied
17666 //
17667
17668 //
17669 // WMI Irps
17670 //
17671
17672 struct {
17673 ULONG_PTR ProviderId;
17674 PVOID DataPath;
17675 ULONG BufferSize;
17676 PVOID Buffer;
17677 } WMI;
17678
17679 //
17680 // Others - driver-specific
17681 //
17682
17683 struct {
17684 PVOID Argument1;
17685 PVOID Argument2;
17686 PVOID Argument3;
17687 PVOID Argument4;
17688 } Others;
17689
17690 } Parameters;
17691
17692 //
17693 // Save a pointer to this device driver's device object for this request
17694 // so it can be passed to the completion routine if needed.
17695 //
17696
17697 PDEVICE_OBJECT DeviceObject;
17698
17699 //
17700 // The following location contains a pointer to the file object for this
17701 //
17702
17703 PFILE_OBJECT FileObject;
17704
17705 //
17706 // The following routine is invoked depending on the flags in the above
17707 // flags field.
17708 //
17709
17710 PIO_COMPLETION_ROUTINE CompletionRoutine;
17711
17712 //
17713 // The following is used to store the address of the context parameter
17714 // that should be passed to the CompletionRoutine.
17715 //
17716
17717 PVOID Context;
17718
17719} IO_STACK_LOCATION, *PIO_STACK_LOCATION;
17720#if !defined(_AMD64_) && !defined(_IA64_)
17721#include "poppack.h"
17722#endif
17723
17724//
17725// Define the share access structure used by file systems to determine
17726// whether or not another accessor may open the file.
17727//
17728
17729typedef struct _SHARE_ACCESS {
17730 ULONG OpenCount;
17731 ULONG Readers;
17732 ULONG Writers;
17733 ULONG Deleters;
17734 ULONG SharedRead;
17735 ULONG SharedWrite;
17736 ULONG SharedDelete;
17737} SHARE_ACCESS, *PSHARE_ACCESS;
17738
17739
17740
17741//
17742// The following structure is used by drivers that are initializing to
17743// determine the number of devices of a particular type that have already
17744// been initialized. It is also used to track whether or not the AtDisk
17745// address range has already been claimed. Finally, it is used by the
17746// NtQuerySystemInformation system service to return device type counts.
17747//
17748
17749typedef struct _CONFIGURATION_INFORMATION {
17750
17751 //
17752 // This field indicates the total number of disks in the system. This
17753 // number should be used by the driver to determine the name of new
17754 // disks. This field should be updated by the driver as it finds new
17755 // disks.
17756 //
17757
17758 ULONG DiskCount; // Count of hard disks thus far
17759 ULONG FloppyCount; // Count of floppy disks thus far
17760 ULONG CdRomCount; // Count of CD-ROM drives thus far
17761 ULONG TapeCount; // Count of tape drives thus far
17762 ULONG ScsiPortCount; // Count of SCSI port adapters thus far
17763 ULONG SerialCount; // Count of serial devices thus far
17764 ULONG ParallelCount; // Count of parallel devices thus far
17765
17766 //
17767 // These next two fields indicate ownership of one of the two IO address
17768 // spaces that are used by WD1003-compatable disk controllers.
17769 //
17770
17771 BOOLEAN AtDiskPrimaryAddressClaimed; // 0x1F0 - 0x1FF
17772 BOOLEAN AtDiskSecondaryAddressClaimed; // 0x170 - 0x17F
17773
17774 //
17775 // Indicates the structure version, as anything value belong this will have been added.
17776 // Use the structure size as the version.
17777 //
17778
17779 ULONG Version;
17780
17781 //
17782 // Indicates the total number of medium changer devices in the system.
17783 // This field will be updated by the drivers as it determines that
17784 // new devices have been found and will be supported.
17785 //
17786
17787 ULONG MediumChangerCount;
17788
17789} CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
17790
17791//
17792// Public I/O routine definitions
17793//
17794
17795NTKERNELAPI
17796VOID
17797IoAcquireCancelSpinLock(
17798 OUT PKIRQL Irql
17799 );
17800
17801
17802DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
17803NTKERNELAPI
17804NTSTATUS
17805IoAllocateAdapterChannel(
17806 IN PADAPTER_OBJECT AdapterObject,
17807 IN PDEVICE_OBJECT DeviceObject,
17808 IN ULONG NumberOfMapRegisters,
17809 IN PDRIVER_CONTROL ExecutionRoutine,
17810 IN PVOID Context
17811 );
17812
17813NTKERNELAPI
17814VOID
17815IoAllocateController(
17816 IN PCONTROLLER_OBJECT ControllerObject,
17817 IN PDEVICE_OBJECT DeviceObject,
17818 IN PDRIVER_CONTROL ExecutionRoutine,
17819 IN PVOID Context
17820 );
17821
17822
17823
17824NTKERNELAPI
17825NTSTATUS
17826IoAllocateDriverObjectExtension(
17827 IN PDRIVER_OBJECT DriverObject,
17828 IN PVOID ClientIdentificationAddress,
17829 IN ULONG DriverObjectExtensionSize,
17830 OUT PVOID *DriverObjectExtension
17831 );
17832
17833
17834
17835NTKERNELAPI
17836PVOID
17837IoAllocateErrorLogEntry(
17838 IN PVOID IoObject,
17839 IN UCHAR EntrySize
17840 );
17841
17842NTKERNELAPI
17843PIRP
17844IoAllocateIrp(
17845 IN CCHAR StackSize,
17846 IN BOOLEAN ChargeQuota
17847 );
17848
17849NTKERNELAPI
17850PMDL
17851IoAllocateMdl(
17852 IN PVOID VirtualAddress,
17853 IN ULONG Length,
17854 IN BOOLEAN SecondaryBuffer,
17855 IN BOOLEAN ChargeQuota,
17856 IN OUT PIRP Irp OPTIONAL
17857 );
17858
17859
17860//++
17861//
17862// VOID
17863// IoAssignArcName(
17864// IN PUNICODE_STRING ArcName,
17865// IN PUNICODE_STRING DeviceName
17866// )
17867//
17868// Routine Description:
17869//
17870// This routine is invoked by drivers of bootable media to create a symbolic
17871// link between the ARC name of their device and its NT name. This allows
17872// the system to determine which device in the system was actually booted
17873// from since the ARC firmware only deals in ARC names, and NT only deals
17874// in NT names.
17875//
17876// Arguments:
17877//
17878// ArcName - Supplies the Unicode string representing the ARC name.
17879//
17880// DeviceName - Supplies the name to which the ARCname refers.
17881//
17882// Return Value:
17883//
17884// None.
17885//
17886//--
17887
17888#define IoAssignArcName( ArcName, DeviceName ) ( \
17889 IoCreateSymbolicLink( (ArcName), (DeviceName) ) )
17890
17891DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReprtDetectedDevice
17892NTKERNELAPI
17893NTSTATUS
17894IoAssignResources (
17895 IN PUNICODE_STRING RegistryPath,
17896 IN PUNICODE_STRING DriverClassName OPTIONAL,
17897 IN PDRIVER_OBJECT DriverObject,
17898 IN PDEVICE_OBJECT DeviceObject OPTIONAL,
17899 IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources,
17900 IN OUT PCM_RESOURCE_LIST *AllocatedResources
17901 );
17902
17903typedef enum _IO_PAGING_PRIORITY {
17904 IoPagingPriorityInvalid, // Returned if a non-paging IO IRP is passed.
17905 IoPagingPriorityNormal, // For regular paging IO
17906 IoPagingPriorityHigh, // For high priority paging IO
17907 IoPagingPriorityReserved1, // Reserved for future use.
17908 IoPagingPriorityReserved2 // Reserved for future use.
17909} IO_PAGING_PRIORITY;
17910
17911NTKERNELAPI
17912NTSTATUS
17913IoAttachDevice(
17914 IN PDEVICE_OBJECT SourceDevice,
17915 IN PUNICODE_STRING TargetDevice,
17916 OUT PDEVICE_OBJECT *AttachedDevice
17917 );
17918
17919
17920
17921DECLSPEC_DEPRECATED_DDK // Use IoAttachDeviceToDeviceStack
17922NTKERNELAPI
17923NTSTATUS
17924IoAttachDeviceByPointer(
17925 IN PDEVICE_OBJECT SourceDevice,
17926 IN PDEVICE_OBJECT TargetDevice
17927 );
17928
17929
17930
17931NTKERNELAPI
17932PDEVICE_OBJECT
17933IoAttachDeviceToDeviceStack(
17934 IN PDEVICE_OBJECT SourceDevice,
17935 IN PDEVICE_OBJECT TargetDevice
17936 );
17937
17938NTKERNELAPI
17939PIRP
17940IoBuildAsynchronousFsdRequest(
17941 IN ULONG MajorFunction,
17942 IN PDEVICE_OBJECT DeviceObject,
17943 IN OUT PVOID Buffer OPTIONAL,
17944 IN ULONG Length OPTIONAL,
17945 IN PLARGE_INTEGER StartingOffset OPTIONAL,
17946 IN PIO_STATUS_BLOCK IoStatusBlock OPTIONAL
17947 );
17948
17949NTKERNELAPI
17950PIRP
17951IoBuildDeviceIoControlRequest(
17952 IN ULONG IoControlCode,
17953 IN PDEVICE_OBJECT DeviceObject,
17954 IN PVOID InputBuffer OPTIONAL,
17955 IN ULONG InputBufferLength,
17956 OUT PVOID OutputBuffer OPTIONAL,
17957 IN ULONG OutputBufferLength,
17958 IN BOOLEAN InternalDeviceIoControl,
17959 IN PKEVENT Event,
17960 OUT PIO_STATUS_BLOCK IoStatusBlock
17961 );
17962
17963NTKERNELAPI
17964VOID
17965IoBuildPartialMdl(
17966 IN PMDL SourceMdl,
17967 IN OUT PMDL TargetMdl,
17968 IN PVOID VirtualAddress,
17969 IN ULONG Length
17970 );
17971
17972typedef struct _BOOTDISK_INFORMATION {
17973 LONGLONG BootPartitionOffset;
17974 LONGLONG SystemPartitionOffset;
17975 ULONG BootDeviceSignature;
17976 ULONG SystemDeviceSignature;
17977} BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
17978
17979//
17980// This structure should follow the previous structure field for field.
17981//
17982typedef struct _BOOTDISK_INFORMATION_EX {
17983 LONGLONG BootPartitionOffset;
17984 LONGLONG SystemPartitionOffset;
17985 ULONG BootDeviceSignature;
17986 ULONG SystemDeviceSignature;
17987 GUID BootDeviceGuid;
17988 GUID SystemDeviceGuid;
17989 BOOLEAN BootDeviceIsGpt;
17990 BOOLEAN SystemDeviceIsGpt;
17991} BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
17992
17993NTKERNELAPI
17994NTSTATUS
17995IoGetBootDiskInformation(
17996 IN OUT PBOOTDISK_INFORMATION BootDiskInformation,
17997 IN ULONG Size
17998 );
17999
18000
18001NTKERNELAPI
18002PIRP
18003IoBuildSynchronousFsdRequest(
18004 IN ULONG MajorFunction,
18005 IN PDEVICE_OBJECT DeviceObject,
18006 IN OUT PVOID Buffer OPTIONAL,
18007 IN ULONG Length OPTIONAL,
18008 IN PLARGE_INTEGER StartingOffset OPTIONAL,
18009 IN PKEVENT Event,
18010 OUT PIO_STATUS_BLOCK IoStatusBlock
18011 );
18012
18013NTKERNELAPI
18014NTSTATUS
18015FASTCALL
18016IofCallDriver(
18017 IN PDEVICE_OBJECT DeviceObject,
18018 IN OUT PIRP Irp
18019 );
18020
18021#define IoCallDriver(a,b) \
18022 IofCallDriver(a,b)
18023
18024
18025NTKERNELAPI
18026BOOLEAN
18027IoCancelIrp(
18028 IN PIRP Irp
18029 );
18030
18031
18032NTKERNELAPI
18033NTSTATUS
18034IoCheckShareAccess(
18035 IN ACCESS_MASK DesiredAccess,
18036 IN ULONG DesiredShareAccess,
18037 IN OUT PFILE_OBJECT FileObject,
18038 IN OUT PSHARE_ACCESS ShareAccess,
18039 IN BOOLEAN Update
18040 );
18041
18042//
18043// This value should be returned from completion routines to continue
18044// completing the IRP upwards. Otherwise, STATUS_MORE_PROCESSING_REQUIRED
18045// should be returned.
18046//
18047#define STATUS_CONTINUE_COMPLETION STATUS_SUCCESS
18048
18049//
18050// Completion routines can also use this enumeration in place of status codes.
18051//
18052typedef enum _IO_COMPLETION_ROUTINE_RESULT {
18053
18054 ContinueCompletion = STATUS_CONTINUE_COMPLETION,
18055 StopCompletion = STATUS_MORE_PROCESSING_REQUIRED
18056
18057} IO_COMPLETION_ROUTINE_RESULT, *PIO_COMPLETION_ROUTINE_RESULT;
18058
18059NTKERNELAPI
18060VOID
18061FASTCALL
18062IofCompleteRequest(
18063 IN PIRP Irp,
18064 IN CCHAR PriorityBoost
18065 );
18066
18067#define IoCompleteRequest(a,b) \
18068 IofCompleteRequest(a,b)
18069
18070
18071
18072NTKERNELAPI
18073NTSTATUS
18074IoConnectInterrupt(
18075 OUT PKINTERRUPT *InterruptObject,
18076 IN PKSERVICE_ROUTINE ServiceRoutine,
18077 IN PVOID ServiceContext,
18078 IN PKSPIN_LOCK SpinLock OPTIONAL,
18079 IN ULONG Vector,
18080 IN KIRQL Irql,
18081 IN KIRQL SynchronizeIrql,
18082 IN KINTERRUPT_MODE InterruptMode,
18083 IN BOOLEAN ShareVector,
18084 IN KAFFINITY ProcessorEnableMask,
18085 IN BOOLEAN FloatingSave
18086 );
18087
18088
18089
18090NTKERNELAPI
18091PCONTROLLER_OBJECT
18092IoCreateController(
18093 IN ULONG Size
18094 );
18095
18096
18097
18098NTKERNELAPI
18099NTSTATUS
18100IoCreateDevice(
18101 IN PDRIVER_OBJECT DriverObject,
18102 IN ULONG DeviceExtensionSize,
18103 IN PUNICODE_STRING DeviceName OPTIONAL,
18104 IN DEVICE_TYPE DeviceType,
18105 IN ULONG DeviceCharacteristics,
18106 IN BOOLEAN Exclusive,
18107 OUT PDEVICE_OBJECT *DeviceObject
18108 );
18109
18110
18111#define WDM_MAJORVERSION 0x01
18112#define WDM_MINORVERSION 0x30
18113
18114NTKERNELAPI
18115BOOLEAN
18116IoIsWdmVersionAvailable(
18117 IN UCHAR MajorVersion,
18118 IN UCHAR MinorVersion
18119 );
18120
18121
18122
18123NTKERNELAPI
18124NTSTATUS
18125IoCreateFile(
18126 OUT PHANDLE FileHandle,
18127 IN ACCESS_MASK DesiredAccess,
18128 IN POBJECT_ATTRIBUTES ObjectAttributes,
18129 OUT PIO_STATUS_BLOCK IoStatusBlock,
18130 IN PLARGE_INTEGER AllocationSize OPTIONAL,
18131 IN ULONG FileAttributes,
18132 IN ULONG ShareAccess,
18133 IN ULONG Disposition,
18134 IN ULONG CreateOptions,
18135 IN PVOID EaBuffer OPTIONAL,
18136 IN ULONG EaLength,
18137 IN CREATE_FILE_TYPE CreateFileType,
18138 IN PVOID ExtraCreateParameters OPTIONAL,
18139 IN ULONG Options
18140 );
18141
18142
18143NTKERNELAPI
18144PKEVENT
18145IoCreateNotificationEvent(
18146 IN PUNICODE_STRING EventName,
18147 OUT PHANDLE EventHandle
18148 );
18149
18150NTKERNELAPI
18151NTSTATUS
18152IoCreateSymbolicLink(
18153 IN PUNICODE_STRING SymbolicLinkName,
18154 IN PUNICODE_STRING DeviceName
18155 );
18156
18157NTKERNELAPI
18158PKEVENT
18159IoCreateSynchronizationEvent(
18160 IN PUNICODE_STRING EventName,
18161 OUT PHANDLE EventHandle
18162 );
18163
18164NTKERNELAPI
18165NTSTATUS
18166IoCreateUnprotectedSymbolicLink(
18167 IN PUNICODE_STRING SymbolicLinkName,
18168 IN PUNICODE_STRING DeviceName
18169 );
18170
18171
18172
18173//++
18174//
18175// VOID
18176// IoDeassignArcName(
18177// IN PUNICODE_STRING ArcName
18178// )
18179//
18180// Routine Description:
18181//
18182// This routine is invoked by drivers to deassign an ARC name that they
18183// created to a device. This is generally only called if the driver is
18184// deleting the device object, which means that the driver is probably
18185// unloading.
18186//
18187// Arguments:
18188//
18189// ArcName - Supplies the ARC name to be removed.
18190//
18191// Return Value:
18192//
18193// None.
18194//
18195//--
18196
18197#define IoDeassignArcName( ArcName ) ( \
18198 IoDeleteSymbolicLink( (ArcName) ) )
18199
18200
18201
18202NTKERNELAPI
18203VOID
18204IoDeleteController(
18205 IN PCONTROLLER_OBJECT ControllerObject
18206 );
18207
18208
18209
18210NTKERNELAPI
18211VOID
18212IoDeleteDevice(
18213 IN PDEVICE_OBJECT DeviceObject
18214 );
18215
18216NTKERNELAPI
18217NTSTATUS
18218IoDeleteSymbolicLink(
18219 IN PUNICODE_STRING SymbolicLinkName
18220 );
18221
18222NTKERNELAPI
18223VOID
18224IoDetachDevice(
18225 IN OUT PDEVICE_OBJECT TargetDevice
18226 );
18227
18228
18229
18230NTKERNELAPI
18231VOID
18232IoDisconnectInterrupt(
18233 IN PKINTERRUPT InterruptObject
18234 );
18235
18236
18237NTKERNELAPI
18238VOID
18239IoFreeController(
18240 IN PCONTROLLER_OBJECT ControllerObject
18241 );
18242
18243
18244
18245NTKERNELAPI
18246VOID
18247IoFreeIrp(
18248 IN PIRP Irp
18249 );
18250
18251NTKERNELAPI
18252VOID
18253IoFreeMdl(
18254 IN PMDL Mdl
18255 );
18256
18257NTKERNELAPI
18258PDEVICE_OBJECT
18259IoGetAttachedDeviceReference(
18260 IN PDEVICE_OBJECT DeviceObject
18261 );
18262
18263NTKERNELAPI
18264PCONFIGURATION_INFORMATION
18265IoGetConfigurationInformation( VOID );
18266
18267//++
18268//
18269// PIO_STACK_LOCATION
18270// IoGetCurrentIrpStackLocation(
18271// IN PIRP Irp
18272// )
18273//
18274// Routine Description:
18275//
18276// This routine is invoked to return a pointer to the current stack location
18277// in an I/O Request Packet (IRP).
18278//
18279// Arguments:
18280//
18281// Irp - Pointer to the I/O Request Packet.
18282//
18283// Return Value:
18284//
18285// The function value is a pointer to the current stack location in the
18286// packet.
18287//
18288//--
18289
18290#define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
18291
18292
18293
18294NTKERNELAPI
18295PDEVICE_OBJECT
18296IoGetDeviceToVerify(
18297 IN PETHREAD Thread
18298 );
18299
18300
18301
18302NTKERNELAPI
18303PVOID
18304IoGetDriverObjectExtension(
18305 IN PDRIVER_OBJECT DriverObject,
18306 IN PVOID ClientIdentificationAddress
18307 );
18308
18309NTKERNELAPI
18310PEPROCESS
18311IoGetCurrentProcess(
18312 VOID
18313 );
18314
18315
18316
18317NTKERNELAPI
18318NTSTATUS
18319IoGetDeviceObjectPointer(
18320 IN PUNICODE_STRING ObjectName,
18321 IN ACCESS_MASK DesiredAccess,
18322 OUT PFILE_OBJECT *FileObject,
18323 OUT PDEVICE_OBJECT *DeviceObject
18324 );
18325
18326NTKERNELAPI
18327struct _DMA_ADAPTER *
18328IoGetDmaAdapter(
18329 IN PDEVICE_OBJECT PhysicalDeviceObject, OPTIONAL // required for PnP drivers
18330 IN struct _DEVICE_DESCRIPTION *DeviceDescription,
18331 IN OUT PULONG NumberOfMapRegisters
18332 );
18333
18334NTKERNELAPI
18335BOOLEAN
18336IoForwardIrpSynchronously(
18337 IN PDEVICE_OBJECT DeviceObject,
18338 IN PIRP Irp
18339 );
18340
18341#define IoForwardAndCatchIrp IoForwardIrpSynchronously
18342
18343
18344
18345NTKERNELAPI
18346PGENERIC_MAPPING
18347IoGetFileObjectGenericMapping(
18348 VOID
18349 );
18350
18351
18352
18353
18354
18355
18356//++
18357//
18358// ULONG
18359// IoGetFunctionCodeFromCtlCode(
18360// IN ULONG ControlCode
18361// )
18362//
18363// Routine Description:
18364//
18365// This routine extracts the function code from IOCTL and FSCTL function
18366// control codes.
18367// This routine should only be used by kernel mode code.
18368//
18369// Arguments:
18370//
18371// ControlCode - A function control code (IOCTL or FSCTL) from which the
18372// function code must be extracted.
18373//
18374// Return Value:
18375//
18376// The extracted function code.
18377//
18378// Note:
18379//
18380// The CTL_CODE macro, used to create IOCTL and FSCTL function control
18381// codes, is defined in ntioapi.h
18382//
18383//--
18384
18385#define IoGetFunctionCodeFromCtlCode( ControlCode ) (\
18386 ( ControlCode >> 2) & 0x00000FFF )
18387
18388
18389
18390NTKERNELAPI
18391PVOID
18392IoGetInitialStack(
18393 VOID
18394 );
18395
18396NTKERNELAPI
18397VOID
18398IoGetStackLimits (
18399 OUT PULONG_PTR LowLimit,
18400 OUT PULONG_PTR HighLimit
18401 );
18402
18403//
18404// The following function is used to tell the caller how much stack is available
18405//
18406
18407FORCEINLINE
18408ULONG_PTR
18409IoGetRemainingStackSize (
18410 VOID
18411 )
18412{
18413 ULONG_PTR Top;
18414 ULONG_PTR Bottom;
18415
18416 IoGetStackLimits( &Bottom, &Top );
18417 return((ULONG_PTR)(&Top) - Bottom );
18418}
18419
18420//++
18421//
18422// PIO_STACK_LOCATION
18423// IoGetNextIrpStackLocation(
18424// IN PIRP Irp
18425// )
18426//
18427// Routine Description:
18428//
18429// This routine is invoked to return a pointer to the next stack location
18430// in an I/O Request Packet (IRP).
18431//
18432// Arguments:
18433//
18434// Irp - Pointer to the I/O Request Packet.
18435//
18436// Return Value:
18437//
18438// The function value is a pointer to the next stack location in the packet.
18439//
18440//--
18441
18442#define IoGetNextIrpStackLocation( Irp ) (\
18443 (Irp)->Tail.Overlay.CurrentStackLocation - 1 )
18444
18445NTKERNELAPI
18446PDEVICE_OBJECT
18447IoGetRelatedDeviceObject(
18448 IN PFILE_OBJECT FileObject
18449 );
18450
18451
18452//++
18453//
18454// VOID
18455// IoInitializeDpcRequest(
18456// IN PDEVICE_OBJECT DeviceObject,
18457// IN PIO_DPC_ROUTINE DpcRoutine
18458// )
18459//
18460// Routine Description:
18461//
18462// This routine is invoked to initialize the DPC in a device object for a
18463// device driver during its initialization routine. The DPC is used later
18464// when the driver interrupt service routine requests that a DPC routine
18465// be queued for later execution.
18466//
18467// Arguments:
18468//
18469// DeviceObject - Pointer to the device object that the request is for.
18470//
18471// DpcRoutine - Address of the driver's DPC routine to be executed when
18472// the DPC is dequeued for processing.
18473//
18474// Return Value:
18475//
18476// None.
18477//
18478//--
18479
18480#define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\
18481 KeInitializeDpc( &(DeviceObject)->Dpc, \
18482 (PKDEFERRED_ROUTINE) (DpcRoutine), \
18483 (DeviceObject) ) )
18484
18485
18486NTKERNELAPI
18487VOID
18488IoInitializeIrp(
18489 IN OUT PIRP Irp,
18490 IN USHORT PacketSize,
18491 IN CCHAR StackSize
18492 );
18493
18494NTKERNELAPI
18495NTSTATUS
18496IoInitializeTimer(
18497 IN PDEVICE_OBJECT DeviceObject,
18498 IN PIO_TIMER_ROUTINE TimerRoutine,
18499 IN PVOID Context
18500 );
18501
18502
18503NTKERNELAPI
18504VOID
18505IoReuseIrp(
18506 IN OUT PIRP Irp,
18507 IN NTSTATUS Iostatus
18508 );
18509
18510
18511
18512NTKERNELAPI
18513VOID
18514IoCancelFileOpen(
18515 IN PDEVICE_OBJECT DeviceObject,
18516 IN PFILE_OBJECT FileObject
18517 );
18518
18519//++
18520//
18521// BOOLEAN
18522// IoIsErrorUserInduced(
18523// IN NTSTATUS Status
18524// )
18525//
18526// Routine Description:
18527//
18528// This routine is invoked to determine if an error was as a
18529// result of user actions. Typically these error are related
18530// to removable media and will result in a pop-up.
18531//
18532// Arguments:
18533//
18534// Status - The status value to check.
18535//
18536// Return Value:
18537// The function value is TRUE if the user induced the error,
18538// otherwise FALSE is returned.
18539//
18540//--
18541#define IoIsErrorUserInduced( Status ) ((BOOLEAN) \
18542 (((Status) == STATUS_DEVICE_NOT_READY) || \
18543 ((Status) == STATUS_IO_TIMEOUT) || \
18544 ((Status) == STATUS_MEDIA_WRITE_PROTECTED) || \
18545 ((Status) == STATUS_NO_MEDIA_IN_DEVICE) || \
18546 ((Status) == STATUS_VERIFY_REQUIRED) || \
18547 ((Status) == STATUS_UNRECOGNIZED_MEDIA) || \
18548 ((Status) == STATUS_WRONG_VOLUME)))
18549
18550
18551NTKERNELAPI
18552PIRP
18553IoMakeAssociatedIrp(
18554 IN PIRP Irp,
18555 IN CCHAR StackSize
18556 );
18557
18558
18559
18560//++
18561//
18562// VOID
18563// IoMarkIrpPending(
18564// IN OUT PIRP Irp
18565// )
18566//
18567// Routine Description:
18568//
18569// This routine marks the specified I/O Request Packet (IRP) to indicate
18570// that an initial status of STATUS_PENDING was returned to the caller.
18571// This is used so that I/O completion can determine whether or not to
18572// fully complete the I/O operation requested by the packet.
18573//
18574// Arguments:
18575//
18576// Irp - Pointer to the I/O Request Packet to be marked pending.
18577//
18578// Return Value:
18579//
18580// None.
18581//
18582//--
18583
18584#define IoMarkIrpPending( Irp ) ( \
18585 IoGetCurrentIrpStackLocation( (Irp) )->Control |= SL_PENDING_RETURNED )
18586
18587DECLSPEC_DEPRECATED_DDK // Use IoGetDeviceProperty
18588NTKERNELAPI
18589NTSTATUS
18590IoQueryDeviceDescription(
18591 IN PINTERFACE_TYPE BusType OPTIONAL,
18592 IN PULONG BusNumber OPTIONAL,
18593 IN PCONFIGURATION_TYPE ControllerType OPTIONAL,
18594 IN PULONG ControllerNumber OPTIONAL,
18595 IN PCONFIGURATION_TYPE PeripheralType OPTIONAL,
18596 IN PULONG PeripheralNumber OPTIONAL,
18597 IN PIO_QUERY_DEVICE_ROUTINE CalloutRoutine,
18598 IN PVOID Context
18599 );
18600
18601
18602NTKERNELAPI
18603VOID
18604IoRaiseHardError(
18605 IN PIRP Irp,
18606 IN PVPB Vpb OPTIONAL,
18607 IN PDEVICE_OBJECT RealDeviceObject
18608 );
18609
18610NTKERNELAPI
18611BOOLEAN
18612IoRaiseInformationalHardError(
18613 IN NTSTATUS ErrorStatus,
18614 IN PUNICODE_STRING String OPTIONAL,
18615 IN PKTHREAD Thread OPTIONAL
18616 );
18617
18618NTKERNELAPI
18619BOOLEAN
18620IoSetThreadHardErrorMode(
18621 IN BOOLEAN EnableHardErrors
18622 );
18623
18624NTKERNELAPI
18625VOID
18626IoRegisterBootDriverReinitialization(
18627 IN PDRIVER_OBJECT DriverObject,
18628 IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
18629 IN PVOID Context
18630 );
18631
18632NTKERNELAPI
18633VOID
18634IoRegisterDriverReinitialization(
18635 IN PDRIVER_OBJECT DriverObject,
18636 IN PDRIVER_REINITIALIZE DriverReinitializationRoutine,
18637 IN PVOID Context
18638 );
18639
18640
18641NTKERNELAPI
18642NTSTATUS
18643IoRegisterShutdownNotification(
18644 IN PDEVICE_OBJECT DeviceObject
18645 );
18646
18647NTKERNELAPI
18648NTSTATUS
18649IoRegisterLastChanceShutdownNotification(
18650 IN PDEVICE_OBJECT DeviceObject
18651 );
18652
18653
18654
18655NTKERNELAPI
18656VOID
18657IoReleaseCancelSpinLock(
18658 IN KIRQL Irql
18659 );
18660
18661
18662NTKERNELAPI
18663VOID
18664IoRemoveShareAccess(
18665 IN PFILE_OBJECT FileObject,
18666 IN OUT PSHARE_ACCESS ShareAccess
18667 );
18668
18669
18670DECLSPEC_DEPRECATED_DDK // Use IoReportResourceForDetection
18671NTKERNELAPI
18672NTSTATUS
18673IoReportResourceUsage(
18674 IN PUNICODE_STRING DriverClassName OPTIONAL,
18675 IN PDRIVER_OBJECT DriverObject,
18676 IN PCM_RESOURCE_LIST DriverList OPTIONAL,
18677 IN ULONG DriverListSize OPTIONAL,
18678 IN PDEVICE_OBJECT DeviceObject,
18679 IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
18680 IN ULONG DeviceListSize OPTIONAL,
18681 IN BOOLEAN OverrideConflict,
18682 OUT PBOOLEAN ConflictDetected
18683 );
18684
18685
18686
18687//++
18688//
18689// VOID
18690// IoRequestDpc(
18691// IN PDEVICE_OBJECT DeviceObject,
18692// IN PIRP Irp,
18693// IN PVOID Context
18694// )
18695//
18696// Routine Description:
18697//
18698// This routine is invoked by the device driver's interrupt service routine
18699// to request that a DPC routine be queued for later execution at a lower
18700// IRQL.
18701//
18702// Arguments:
18703//
18704// DeviceObject - Device object for which the request is being processed.
18705//
18706// Irp - Pointer to the current I/O Request Packet (IRP) for the specified
18707// device.
18708//
18709// Context - Provides a general context parameter to be passed to the
18710// DPC routine.
18711//
18712// Return Value:
18713//
18714// None.
18715//
18716//--
18717
18718#define IoRequestDpc( DeviceObject, Irp, Context ) ( \
18719 KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )
18720
18721//++
18722//
18723// PDRIVER_CANCEL
18724// IoSetCancelRoutine(
18725// IN PIRP Irp,
18726// IN PDRIVER_CANCEL CancelRoutine
18727// )
18728//
18729// Routine Description:
18730//
18731// This routine is invoked to set the address of a cancel routine which
18732// is to be invoked when an I/O packet has been canceled.
18733//
18734// Arguments:
18735//
18736// Irp - Pointer to the I/O Request Packet itself.
18737//
18738// CancelRoutine - Address of the cancel routine that is to be invoked
18739// if the IRP is cancelled.
18740//
18741// Return Value:
18742//
18743// Previous value of CancelRoutine field in the IRP.
18744//
18745//--
18746
18747#define IoSetCancelRoutine( Irp, NewCancelRoutine ) ( \
18748 (PDRIVER_CANCEL) (ULONG_PTR) InterlockedExchangePointer( (PVOID *) &(Irp)->CancelRoutine, (PVOID) (ULONG_PTR)(NewCancelRoutine) ) )
18749
18750//++
18751//
18752// VOID
18753// IoSetCompletionRoutine(
18754// IN PIRP Irp,
18755// IN PIO_COMPLETION_ROUTINE CompletionRoutine,
18756// IN PVOID Context,
18757// IN BOOLEAN InvokeOnSuccess,
18758// IN BOOLEAN InvokeOnError,
18759// IN BOOLEAN InvokeOnCancel
18760// )
18761//
18762// Routine Description:
18763//
18764// This routine is invoked to set the address of a completion routine which
18765// is to be invoked when an I/O packet has been completed by a lower-level
18766// driver.
18767//
18768// Arguments:
18769//
18770// Irp - Pointer to the I/O Request Packet itself.
18771//
18772// CompletionRoutine - Address of the completion routine that is to be
18773// invoked once the next level driver completes the packet.
18774//
18775// Context - Specifies a context parameter to be passed to the completion
18776// routine.
18777//
18778// InvokeOnSuccess - Specifies that the completion routine is invoked when the
18779// operation is successfully completed.
18780//
18781// InvokeOnError - Specifies that the completion routine is invoked when the
18782// operation completes with an error status.
18783//
18784// InvokeOnCancel - Specifies that the completion routine is invoked when the
18785// operation is being canceled.
18786//
18787// Return Value:
18788//
18789// None.
18790//
18791//--
18792
18793#define IoSetCompletionRoutine( Irp, Routine, CompletionContext, Success, Error, Cancel ) { \
18794 PIO_STACK_LOCATION __irpSp; \
18795 ASSERT( (Success) | (Error) | (Cancel) ? (Routine) != NULL : TRUE ); \
18796 __irpSp = IoGetNextIrpStackLocation( (Irp) ); \
18797 __irpSp->CompletionRoutine = (Routine); \
18798 __irpSp->Context = (CompletionContext); \
18799 __irpSp->Control = 0; \
18800 if ((Success)) { __irpSp->Control = SL_INVOKE_ON_SUCCESS; } \
18801 if ((Error)) { __irpSp->Control |= SL_INVOKE_ON_ERROR; } \
18802 if ((Cancel)) { __irpSp->Control |= SL_INVOKE_ON_CANCEL; } }
18803
18804NTSTATUS
18805IoSetCompletionRoutineEx(
18806 IN PDEVICE_OBJECT DeviceObject,
18807 IN PIRP Irp,
18808 IN PIO_COMPLETION_ROUTINE CompletionRoutine,
18809 IN PVOID Context,
18810 IN BOOLEAN InvokeOnSuccess,
18811 IN BOOLEAN InvokeOnError,
18812 IN BOOLEAN InvokeOnCancel
18813 );
18814
18815
18816
18817NTKERNELAPI
18818VOID
18819IoSetHardErrorOrVerifyDevice(
18820 IN PIRP Irp,
18821 IN PDEVICE_OBJECT DeviceObject
18822 );
18823
18824
18825//++
18826//
18827// VOID
18828// IoSetNextIrpStackLocation (
18829// IN OUT PIRP Irp
18830// )
18831//
18832// Routine Description:
18833//
18834// This routine is invoked to set the current IRP stack location to
18835// the next stack location, i.e. it "pushes" the stack.
18836//
18837// Arguments:
18838//
18839// Irp - Pointer to the I/O Request Packet (IRP).
18840//
18841// Return Value:
18842//
18843// None.
18844//
18845//--
18846
18847#define IoSetNextIrpStackLocation( Irp ) { \
18848 (Irp)->CurrentLocation--; \
18849 (Irp)->Tail.Overlay.CurrentStackLocation--; }
18850
18851//++
18852//
18853// VOID
18854// IoCopyCurrentIrpStackLocationToNext(
18855// IN PIRP Irp
18856// )
18857//
18858// Routine Description:
18859//
18860// This routine is invoked to copy the IRP stack arguments and file
18861// pointer from the current IrpStackLocation to the next
18862// in an I/O Request Packet (IRP).
18863//
18864// If the caller wants to call IoCallDriver with a completion routine
18865// but does not wish to change the arguments otherwise,
18866// the caller first calls IoCopyCurrentIrpStackLocationToNext,
18867// then IoSetCompletionRoutine, then IoCallDriver.
18868//
18869// Arguments:
18870//
18871// Irp - Pointer to the I/O Request Packet.
18872//
18873// Return Value:
18874//
18875// None.
18876//
18877//--
18878
18879#define IoCopyCurrentIrpStackLocationToNext( Irp ) { \
18880 PIO_STACK_LOCATION __irpSp; \
18881 PIO_STACK_LOCATION __nextIrpSp; \
18882 __irpSp = IoGetCurrentIrpStackLocation( (Irp) ); \
18883 __nextIrpSp = IoGetNextIrpStackLocation( (Irp) ); \
18884 RtlCopyMemory( __nextIrpSp, __irpSp, FIELD_OFFSET(IO_STACK_LOCATION, CompletionRoutine)); \
18885 __nextIrpSp->Control = 0; }
18886
18887//++
18888//
18889// VOID
18890// IoSkipCurrentIrpStackLocation (
18891// IN PIRP Irp
18892// )
18893//
18894// Routine Description:
18895//
18896// This routine is invoked to increment the current stack location of
18897// a given IRP.
18898//
18899// If the caller wishes to call the next driver in a stack, and does not
18900// wish to change the arguments, nor does he wish to set a completion
18901// routine, then the caller first calls IoSkipCurrentIrpStackLocation
18902// and the calls IoCallDriver.
18903//
18904// Arguments:
18905//
18906// Irp - Pointer to the I/O Request Packet.
18907//
18908// Return Value:
18909//
18910// None
18911//
18912//--
18913
18914#define IoSkipCurrentIrpStackLocation( Irp ) { \
18915 (Irp)->CurrentLocation++; \
18916 (Irp)->Tail.Overlay.CurrentStackLocation++; }
18917
18918
18919NTKERNELAPI
18920VOID
18921IoSetShareAccess(
18922 IN ACCESS_MASK DesiredAccess,
18923 IN ULONG DesiredShareAccess,
18924 IN OUT PFILE_OBJECT FileObject,
18925 OUT PSHARE_ACCESS ShareAccess
18926 );
18927
18928
18929
18930typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
18931
18932typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
18933 BOOLEAN Removed;
18934 BOOLEAN Reserved [3];
18935 LONG IoCount;
18936 KEVENT RemoveEvent;
18937
18938} IO_REMOVE_LOCK_COMMON_BLOCK;
18939
18940typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
18941 LONG Signature;
18942 ULONG HighWatermark;
18943 LONGLONG MaxLockedTicks;
18944 LONG AllocateTag;
18945 LIST_ENTRY LockList;
18946 KSPIN_LOCK Spin;
18947 LONG LowMemoryCount;
18948 ULONG Reserved1[4];
18949 PVOID Reserved2;
18950 PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
18951} IO_REMOVE_LOCK_DBG_BLOCK;
18952
18953typedef struct _IO_REMOVE_LOCK {
18954 IO_REMOVE_LOCK_COMMON_BLOCK Common;
18955#if DBG
18956 IO_REMOVE_LOCK_DBG_BLOCK Dbg;
18957#endif
18958} IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
18959
18960#define IoInitializeRemoveLock(Lock, Tag, Maxmin, HighWater) \
18961 IoInitializeRemoveLockEx (Lock, Tag, Maxmin, HighWater, sizeof (IO_REMOVE_LOCK))
18962
18963NTSYSAPI
18964VOID
18965NTAPI
18966IoInitializeRemoveLockEx(
18967 IN PIO_REMOVE_LOCK Lock,
18968 IN ULONG AllocateTag, // Used only on checked kernels
18969 IN ULONG MaxLockedMinutes, // Used only on checked kernels
18970 IN ULONG HighWatermark, // Used only on checked kernels
18971 IN ULONG RemlockSize // are we checked or free
18972 );
18973//
18974// Initialize a remove lock.
18975//
18976// Note: Allocation for remove locks needs to be within the device extension,
18977// so that the memory for this structure stays allocated until such time as the
18978// device object itself is deallocated.
18979//
18980
18981#define IoAcquireRemoveLock(RemoveLock, Tag) \
18982 IoAcquireRemoveLockEx(RemoveLock, Tag, __FILE__, __LINE__, sizeof (IO_REMOVE_LOCK))
18983
18984NTSYSAPI
18985NTSTATUS
18986NTAPI
18987IoAcquireRemoveLockEx (
18988 IN PIO_REMOVE_LOCK RemoveLock,
18989 IN OPTIONAL PVOID Tag, // Optional
18990 IN PCSTR File,
18991 IN ULONG Line,
18992 IN ULONG RemlockSize // are we checked or free
18993 );
18994
18995//
18996// Routine Description:
18997//
18998// This routine is called to acquire the remove lock for a device object.
18999// While the lock is held, the caller can assume that no pending pnp REMOVE
19000// requests will be completed.
19001//
19002// The lock should be acquired immediately upon entering a dispatch routine.
19003// It should also be acquired before creating any new reference to the
19004// device object if there's a chance of releasing the reference before the
19005// new one is done, in addition to references to the driver code itself,
19006// which is removed from memory when the last device object goes.
19007//
19008// Arguments:
19009//
19010// RemoveLock - A pointer to an initialized REMOVE_LOCK structure.
19011//
19012// Tag - Used for tracking lock allocation and release. The same tag
19013// specified when acquiring the lock must be used to release the lock.
19014// Tags are only checked in checked versions of the driver.
19015//
19016// File - set to __FILE__ as the location in the code where the lock was taken.
19017//
19018// Line - set to __LINE__.
19019//
19020// Return Value:
19021//
19022// Returns whether or not the remove lock was obtained.
19023// If successful the caller should continue with work calling
19024// IoReleaseRemoveLock when finished.
19025//
19026// If not successful the lock was not obtained. The caller should abort the
19027// work but not call IoReleaseRemoveLock.
19028//
19029
19030#define IoReleaseRemoveLock(RemoveLock, Tag) \
19031 IoReleaseRemoveLockEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
19032
19033NTSYSAPI
19034VOID
19035NTAPI
19036IoReleaseRemoveLockEx(
19037 IN PIO_REMOVE_LOCK RemoveLock,
19038 IN PVOID Tag, // Optional
19039 IN ULONG RemlockSize // are we checked or free
19040 );
19041//
19042//
19043// Routine Description:
19044//
19045// This routine is called to release the remove lock on the device object. It
19046// must be called when finished using a previously locked reference to the
19047// device object. If an Tag was specified when acquiring the lock then the
19048// same Tag must be specified when releasing the lock.
19049//
19050// When the lock count reduces to zero, this routine will signal the waiting
19051// event to release the waiting thread deleting the device object protected
19052// by this lock.
19053//
19054// Arguments:
19055//
19056// DeviceObject - the device object to lock
19057//
19058// Tag - The TAG (if any) specified when acquiring the lock. This is used
19059// for lock tracking purposes
19060//
19061// Return Value:
19062//
19063// none
19064//
19065
19066#define IoReleaseRemoveLockAndWait(RemoveLock, Tag) \
19067 IoReleaseRemoveLockAndWaitEx(RemoveLock, Tag, sizeof (IO_REMOVE_LOCK))
19068
19069NTSYSAPI
19070VOID
19071NTAPI
19072IoReleaseRemoveLockAndWaitEx(
19073 IN PIO_REMOVE_LOCK RemoveLock,
19074 IN PVOID Tag,
19075 IN ULONG RemlockSize // are we checked or free
19076 );
19077//
19078//
19079// Routine Description:
19080//
19081// This routine is called when the client would like to delete the
19082// remove-locked resource. This routine will block until all the remove
19083// locks have released.
19084//
19085// This routine MUST be called after acquiring the lock.
19086//
19087// Arguments:
19088//
19089// RemoveLock
19090//
19091// Return Value:
19092//
19093// none
19094//
19095
19096
19097//++
19098//
19099// USHORT
19100// IoSizeOfIrp(
19101// IN CCHAR StackSize
19102// )
19103//
19104// Routine Description:
19105//
19106// Determines the size of an IRP given the number of stack locations
19107// the IRP will have.
19108//
19109// Arguments:
19110//
19111// StackSize - Number of stack locations for the IRP.
19112//
19113// Return Value:
19114//
19115// Size in bytes of the IRP.
19116//
19117//--
19118
19119#define IoSizeOfIrp( StackSize ) \
19120 ((USHORT) (sizeof( IRP ) + ((StackSize) * (sizeof( IO_STACK_LOCATION )))))
19121
19122
19123
19124
19125NTKERNELAPI
19126VOID
19127IoStartNextPacket(
19128 IN PDEVICE_OBJECT DeviceObject,
19129 IN BOOLEAN Cancelable
19130 );
19131
19132NTKERNELAPI
19133VOID
19134IoStartNextPacketByKey(
19135 IN PDEVICE_OBJECT DeviceObject,
19136 IN BOOLEAN Cancelable,
19137 IN ULONG Key
19138 );
19139
19140NTKERNELAPI
19141VOID
19142IoStartPacket(
19143 IN PDEVICE_OBJECT DeviceObject,
19144 IN PIRP Irp,
19145 IN PULONG Key OPTIONAL,
19146 IN PDRIVER_CANCEL CancelFunction OPTIONAL
19147 );
19148
19149VOID
19150IoSetStartIoAttributes(
19151 IN PDEVICE_OBJECT DeviceObject,
19152 IN BOOLEAN DeferredStartIo,
19153 IN BOOLEAN NonCancelable
19154 );
19155
19156
19157
19158NTKERNELAPI
19159VOID
19160IoStartTimer(
19161 IN PDEVICE_OBJECT DeviceObject
19162 );
19163
19164NTKERNELAPI
19165VOID
19166IoStopTimer(
19167 IN PDEVICE_OBJECT DeviceObject
19168 );
19169
19170
19171NTKERNELAPI
19172VOID
19173IoUnregisterShutdownNotification(
19174 IN PDEVICE_OBJECT DeviceObject
19175 );
19176
19177
19178
19179NTKERNELAPI
19180VOID
19181IoUpdateShareAccess(
19182 IN PFILE_OBJECT FileObject,
19183 IN OUT PSHARE_ACCESS ShareAccess
19184 );
19185
19186NTKERNELAPI
19187VOID
19188IoWriteErrorLogEntry(
19189 IN PVOID ElEntry
19190 );
19191
19192typedef struct _IO_WORKITEM *PIO_WORKITEM;
19193
19194typedef
19195VOID
19196(*PIO_WORKITEM_ROUTINE) (
19197 IN PDEVICE_OBJECT DeviceObject,
19198 IN PVOID Context
19199 );
19200
19201PIO_WORKITEM
19202IoAllocateWorkItem(
19203 PDEVICE_OBJECT DeviceObject
19204 );
19205
19206VOID
19207IoFreeWorkItem(
19208 PIO_WORKITEM IoWorkItem
19209 );
19210
19211VOID
19212IoQueueWorkItem(
19213 IN PIO_WORKITEM IoWorkItem,
19214 IN PIO_WORKITEM_ROUTINE WorkerRoutine,
19215 IN WORK_QUEUE_TYPE QueueType,
19216 IN PVOID Context
19217 );
19218
19219
19220NTKERNELAPI
19221NTSTATUS
19222IoWMIRegistrationControl(
19223 IN PDEVICE_OBJECT DeviceObject,
19224 IN ULONG Action
19225);
19226
19227//
19228// Action code for IoWMIRegistrationControl api
19229//
19230
19231#define WMIREG_ACTION_REGISTER 1
19232#define WMIREG_ACTION_DEREGISTER 2
19233#define WMIREG_ACTION_REREGISTER 3
19234#define WMIREG_ACTION_UPDATE_GUIDS 4
19235#define WMIREG_ACTION_BLOCK_IRPS 5
19236
19237//
19238// Code passed in IRP_MN_REGINFO WMI irp
19239//
19240
19241#define WMIREGISTER 0
19242#define WMIUPDATE 1
19243
19244NTKERNELAPI
19245NTSTATUS
19246IoWMIAllocateInstanceIds(
19247 IN GUID *Guid,
19248 IN ULONG InstanceCount,
19249 OUT ULONG *FirstInstanceId
19250 );
19251
19252NTKERNELAPI
19253NTSTATUS
19254IoWMISuggestInstanceName(
19255 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
19256 IN PUNICODE_STRING SymbolicLinkName OPTIONAL,
19257 IN BOOLEAN CombineNames,
19258 OUT PUNICODE_STRING SuggestedInstanceName
19259 );
19260
19261NTKERNELAPI
19262NTSTATUS
19263IoWMIWriteEvent(
19264 IN PVOID WnodeEventItem
19265 );
19266
19267#if defined(_WIN64)
19268NTKERNELAPI
19269ULONG IoWMIDeviceObjectToProviderId(
19270 PDEVICE_OBJECT DeviceObject
19271 );
19272#else
19273#define IoWMIDeviceObjectToProviderId(DeviceObject) ((ULONG)(DeviceObject))
19274#endif
19275
19276NTKERNELAPI
19277NTSTATUS IoWMIOpenBlock(
19278 IN GUID *DataBlockGuid,
19279 IN ULONG DesiredAccess,
19280 OUT PVOID *DataBlockObject
19281 );
19282
19283
19284NTKERNELAPI
19285NTSTATUS IoWMIQueryAllData(
19286 IN PVOID DataBlockObject,
19287 IN OUT ULONG *InOutBufferSize,
19288 OUT /* non paged */ PVOID OutBuffer
19289);
19290
19291
19292NTKERNELAPI
19293NTSTATUS
19294IoWMIQueryAllDataMultiple(
19295 IN PVOID *DataBlockObjectList,
19296 IN ULONG ObjectCount,
19297 IN OUT ULONG *InOutBufferSize,
19298 OUT /* non paged */ PVOID OutBuffer
19299);
19300
19301
19302NTKERNELAPI
19303NTSTATUS
19304IoWMIQuerySingleInstance(
19305 IN PVOID DataBlockObject,
19306 IN PUNICODE_STRING InstanceName,
19307 IN OUT ULONG *InOutBufferSize,
19308 OUT /* non paged */ PVOID OutBuffer
19309);
19310
19311NTKERNELAPI
19312NTSTATUS
19313IoWMIQuerySingleInstanceMultiple(
19314 IN PVOID *DataBlockObjectList,
19315 IN PUNICODE_STRING InstanceNames,
19316 IN ULONG ObjectCount,
19317 IN OUT ULONG *InOutBufferSize,
19318 OUT /* non paged */ PVOID OutBuffer
19319);
19320
19321NTKERNELAPI
19322NTSTATUS
19323IoWMISetSingleInstance(
19324 IN PVOID DataBlockObject,
19325 IN PUNICODE_STRING InstanceName,
19326 IN ULONG Version,
19327 IN ULONG ValueBufferSize,
19328 IN PVOID ValueBuffer
19329 );
19330
19331NTKERNELAPI
19332NTSTATUS
19333IoWMISetSingleItem(
19334 IN PVOID DataBlockObject,
19335 IN PUNICODE_STRING InstanceName,
19336 IN ULONG DataItemId,
19337 IN ULONG Version,
19338 IN ULONG ValueBufferSize,
19339 IN PVOID ValueBuffer
19340 );
19341
19342NTKERNELAPI
19343NTSTATUS
19344IoWMIExecuteMethod(
19345 IN PVOID DataBlockObject,
19346 IN PUNICODE_STRING InstanceName,
19347 IN ULONG MethodId,
19348 IN ULONG InBufferSize,
19349 IN OUT PULONG OutBufferSize,
19350 IN OUT PUCHAR InOutBuffer
19351 );
19352
19353
19354
19355typedef VOID (*WMI_NOTIFICATION_CALLBACK)(
19356 PVOID Wnode,
19357 PVOID Context
19358 );
19359
19360NTKERNELAPI
19361NTSTATUS
19362IoWMISetNotificationCallback(
19363 IN PVOID Object,
19364 IN WMI_NOTIFICATION_CALLBACK Callback,
19365 IN PVOID Context
19366 );
19367
19368NTKERNELAPI
19369NTSTATUS
19370IoWMIHandleToInstanceName(
19371 IN PVOID DataBlockObject,
19372 IN HANDLE FileHandle,
19373 OUT PUNICODE_STRING InstanceName
19374 );
19375
19376NTKERNELAPI
19377NTSTATUS
19378IoWMIDeviceObjectToInstanceName(
19379 IN PVOID DataBlockObject,
19380 IN PDEVICE_OBJECT DeviceObject,
19381 OUT PUNICODE_STRING InstanceName
19382 );
19383
19384#if defined(_WIN64)
19385BOOLEAN
19386IoIs32bitProcess(
19387 IN PIRP Irp
19388 );
19389#endif
19390NTKERNELAPI
19391VOID
19392FASTCALL
19393HalExamineMBR(
19394 IN PDEVICE_OBJECT DeviceObject,
19395 IN ULONG SectorSize,
19396 IN ULONG MBRTypeIdentifier,
19397 OUT PVOID *Buffer
19398 );
19399
19400DECLSPEC_DEPRECATED_DDK // Use IoReadPartitionTableEx
19401NTKERNELAPI
19402NTSTATUS
19403FASTCALL
19404IoReadPartitionTable(
19405 IN PDEVICE_OBJECT DeviceObject,
19406 IN ULONG SectorSize,
19407 IN BOOLEAN ReturnRecognizedPartitions,
19408 OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
19409 );
19410
19411DECLSPEC_DEPRECATED_DDK // Use IoSetPartitionInformationEx
19412NTKERNELAPI
19413NTSTATUS
19414FASTCALL
19415IoSetPartitionInformation(
19416 IN PDEVICE_OBJECT DeviceObject,
19417 IN ULONG SectorSize,
19418 IN ULONG PartitionNumber,
19419 IN ULONG PartitionType
19420 );
19421
19422
19423DECLSPEC_DEPRECATED_DDK // Use IoWritePartitionTableEx
19424NTKERNELAPI
19425NTSTATUS
19426FASTCALL
19427IoWritePartitionTable(
19428 IN PDEVICE_OBJECT DeviceObject,
19429 IN ULONG SectorSize,
19430 IN ULONG SectorsPerTrack,
19431 IN ULONG NumberOfHeads,
19432 IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
19433 );
19434
19435NTKERNELAPI
19436NTSTATUS
19437IoCreateDisk(
19438 IN PDEVICE_OBJECT DeviceObject,
19439 IN struct _CREATE_DISK* Disk
19440 );
19441
19442NTKERNELAPI
19443NTSTATUS
19444IoReadPartitionTableEx(
19445 IN PDEVICE_OBJECT DeviceObject,
19446 IN struct _DRIVE_LAYOUT_INFORMATION_EX** DriveLayout
19447 );
19448
19449NTKERNELAPI
19450NTSTATUS
19451IoWritePartitionTableEx(
19452 IN PDEVICE_OBJECT DeviceObject,
19453 IN struct _DRIVE_LAYOUT_INFORMATION_EX* DriveLayout
19454 );
19455
19456NTKERNELAPI
19457NTSTATUS
19458IoSetPartitionInformationEx(
19459 IN PDEVICE_OBJECT DeviceObject,
19460 IN ULONG PartitionNumber,
19461 IN struct _SET_PARTITION_INFORMATION_EX* PartitionInfo
19462 );
19463
19464NTKERNELAPI
19465NTSTATUS
19466IoUpdateDiskGeometry(
19467 IN PDEVICE_OBJECT DeviceObject,
19468 IN struct _DISK_GEOMETRY_EX* OldDiskGeometry,
19469 IN struct _DISK_GEOMETRY_EX* NewDiskGeometry
19470 );
19471
19472NTKERNELAPI
19473NTSTATUS
19474IoVerifyPartitionTable(
19475 IN PDEVICE_OBJECT DeviceObject,
19476 IN BOOLEAN FixErrors
19477 );
19478
19479typedef struct _DISK_SIGNATURE {
19480 ULONG PartitionStyle;
19481 union {
19482 struct {
19483 ULONG Signature;
19484 ULONG CheckSum;
19485 } Mbr;
19486
19487 struct {
19488 GUID DiskId;
19489 } Gpt;
19490 };
19491} DISK_SIGNATURE, *PDISK_SIGNATURE;
19492
19493NTKERNELAPI
19494NTSTATUS
19495IoReadDiskSignature(
19496 IN PDEVICE_OBJECT DeviceObject,
19497 IN ULONG BytesPerSector,
19498 OUT PDISK_SIGNATURE Signature
19499 );
19500
19501
19502
19503NTSTATUS
19504IoVolumeDeviceToDosName(
19505 IN PVOID VolumeDeviceObject,
19506 OUT PUNICODE_STRING DosName
19507 );
19508
19509NTSTATUS
19510IoSetSystemPartition(
19511 PUNICODE_STRING VolumeNameString
19512 );
19513
19514
19515VOID
19516IoFreeErrorLogEntry(
19517 PVOID ElEntry
19518 );
19519
19520// Cancel SAFE API set start
19521//
19522// The following APIs are to help ease the pain of writing queue packages that
19523// handle the cancellation race well. The idea of this set of APIs is to not
19524// force a single queue data structure but allow the cancel logic to be hidden
19525// from the drivers. A driver implements a queue and as part of its header
19526// includes the IO_CSQ structure. In its initialization routine it calls
19527// IoInitializeCsq. Then in the dispatch routine when the driver wants to
19528// insert an IRP into the queue it calls IoCsqInsertIrp. When the driver wants
19529// to remove something from the queue it calls IoCsqRemoveIrp. Note that Insert
19530// can fail if the IRP was cancelled in the meantime. Remove can also fail if
19531// the IRP was already cancelled.
19532//
19533// There are typically two modes where drivers queue IRPs. These two modes are
19534// covered by the cancel safe queue API set.
19535//
19536// Mode 1:
19537// One is where the driver queues the IRP and at some later
19538// point in time dequeues an IRP and issues the IO request.
19539// For this mode the driver should use IoCsqInsertIrp and IoCsqRemoveNextIrp.
19540// The driver in this case is expected to pass NULL to the irp context
19541// parameter in IoInsertIrp.
19542//
19543// Mode 2:
19544// In this the driver queues theIRP, issues the IO request (like issuing a DMA
19545// request or writing to a register) and when the IO request completes (either
19546// using a DPC or timer) the driver dequeues the IRP and completes it. For this
19547// mode the driver should use IoCsqInsertIrp and IoCsqRemoveIrp. In this case
19548// the driver should allocate an IRP context and pass it in to IoCsqInsertIrp.
19549// The cancel API code creates an association between the IRP and the context
19550// and thus ensures that when the time comes to remove the IRP it can ascertain
19551// correctly.
19552//
19553// Note that the cancel API set assumes that the field DriverContext[3] is
19554// always available for use and that the driver does not use it.
19555//
19556
19557
19558//
19559// Bookkeeping structure. This should be opaque to drivers.
19560// Drivers typically include this as part of their queue headers.
19561// Given a CSQ pointer the driver should be able to get its
19562// queue header using CONTAINING_RECORD macro
19563//
19564
19565typedef struct _IO_CSQ IO_CSQ, *PIO_CSQ;
19566
19567#define IO_TYPE_CSQ_IRP_CONTEXT 1
19568#define IO_TYPE_CSQ 2
19569#define IO_TYPE_CSQ_EX 3
19570
19571//
19572// IRP context structure. This structure is necessary if the driver is using
19573// the second mode.
19574//
19575
19576
19577typedef struct _IO_CSQ_IRP_CONTEXT {
19578 ULONG Type;
19579 PIRP Irp;
19580 PIO_CSQ Csq;
19581} IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
19582
19583//
19584// Routines that insert/remove IRP
19585//
19586
19587typedef VOID
19588(*PIO_CSQ_INSERT_IRP)(
19589 IN struct _IO_CSQ *Csq,
19590 IN PIRP Irp
19591 );
19592
19593typedef NTSTATUS
19594(*PIO_CSQ_INSERT_IRP_EX)(
19595 IN struct _IO_CSQ *Csq,
19596 IN PIRP Irp,
19597 IN OUT PVOID InsertContext
19598 );
19599
19600typedef VOID
19601(*PIO_CSQ_REMOVE_IRP)(
19602 IN PIO_CSQ Csq,
19603 IN PIRP Irp
19604 );
19605
19606//
19607// Retrieves next entry after Irp from the queue.
19608// Returns NULL if there are no entries in the queue.
19609// If Irp is NUL, returns the entry in the head of the queue.
19610// This routine does not remove the IRP from the queue.
19611//
19612
19613
19614typedef PIRP
19615(*PIO_CSQ_PEEK_NEXT_IRP)(
19616 IN PIO_CSQ Csq,
19617 IN PIRP Irp,
19618 IN PVOID PeekContext
19619 );
19620
19621//
19622// Lock routine that protects the cancel safe queue.
19623//
19624
19625typedef VOID
19626(*PIO_CSQ_ACQUIRE_LOCK)(
19627 IN PIO_CSQ Csq,
19628 OUT PKIRQL Irql
19629 );
19630
19631typedef VOID
19632(*PIO_CSQ_RELEASE_LOCK)(
19633 IN PIO_CSQ Csq,
19634 IN KIRQL Irql
19635 );
19636
19637
19638//
19639// Completes the IRP with STATUS_CANCELLED. IRP is guaranteed to be valid
19640// In most cases this routine just calls IoCompleteRequest(Irp, STATUS_CANCELLED);
19641//
19642
19643typedef VOID
19644(*PIO_CSQ_COMPLETE_CANCELED_IRP)(
19645 IN PIO_CSQ Csq,
19646 IN PIRP Irp
19647 );
19648
19649//
19650// Bookkeeping structure. This should be opaque to drivers.
19651// Drivers typically include this as part of their queue headers.
19652// Given a CSQ pointer the driver should be able to get its
19653// queue header using CONTAINING_RECORD macro
19654//
19655
19656typedef struct _IO_CSQ {
19657 ULONG Type;
19658 PIO_CSQ_INSERT_IRP CsqInsertIrp;
19659 PIO_CSQ_REMOVE_IRP CsqRemoveIrp;
19660 PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp;
19661 PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock;
19662 PIO_CSQ_RELEASE_LOCK CsqReleaseLock;
19663 PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp;
19664 PVOID ReservePointer; // Future expansion
19665} IO_CSQ, *PIO_CSQ;
19666
19667//
19668// Initializes the cancel queue structure.
19669//
19670
19671NTSTATUS
19672IoCsqInitialize(
19673 IN PIO_CSQ Csq,
19674 IN PIO_CSQ_INSERT_IRP CsqInsertIrp,
19675 IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
19676 IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
19677 IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
19678 IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
19679 IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
19680 );
19681
19682NTSTATUS
19683IoCsqInitializeEx(
19684 IN PIO_CSQ Csq,
19685 IN PIO_CSQ_INSERT_IRP_EX CsqInsertIrp,
19686 IN PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
19687 IN PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
19688 IN PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
19689 IN PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
19690 IN PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
19691 );
19692
19693//
19694// The caller calls this routine to insert the IRP and return STATUS_PENDING.
19695//
19696
19697VOID
19698IoCsqInsertIrp(
19699 IN PIO_CSQ Csq,
19700 IN PIRP Irp,
19701 IN PIO_CSQ_IRP_CONTEXT Context
19702 );
19703
19704
19705NTSTATUS
19706IoCsqInsertIrpEx(
19707 IN PIO_CSQ Csq,
19708 IN PIRP Irp,
19709 IN PIO_CSQ_IRP_CONTEXT Context,
19710 IN PVOID InsertContext
19711 );
19712
19713//
19714// Returns an IRP if one can be found. NULL otherwise.
19715//
19716
19717PIRP
19718IoCsqRemoveNextIrp(
19719 IN PIO_CSQ Csq,
19720 IN PVOID PeekContext
19721 );
19722
19723//
19724// This routine is called from timeout or DPCs.
19725// The context is presumably part of the DPC or timer context.
19726// If succesfull returns the IRP associated with context.
19727//
19728
19729PIRP
19730IoCsqRemoveIrp(
19731 IN PIO_CSQ Csq,
19732 IN PIO_CSQ_IRP_CONTEXT Context
19733 );
19734
19735// Cancel SAFE API set end
19736
19737
19738NTSTATUS
19739IoValidateDeviceIoControlAccess(
19740 IN PIRP Irp,
19741 IN ULONG RequiredAccess
19742 );
19743
19744
19745
19746IO_PAGING_PRIORITY
19747FASTCALL
19748IoGetPagingIoPriority(
19749 IN PIRP IRP
19750 );
19751
19752
19753#ifdef RUN_WPP
19754#include <evntrace.h>
19755#include <stdarg.h>
19756#endif // #ifdef RUN_WPP
19757
19758#ifdef RUN_WPP
19759
19760NTKERNELAPI
19761NTSTATUS
19762WmiTraceMessage(
19763 IN TRACEHANDLE LoggerHandle,
19764 IN ULONG MessageFlags,
19765 IN LPGUID MessageGuid,
19766 IN USHORT MessageNumber,
19767 IN ...
19768 );
19769
19770NTKERNELAPI
19771NTSTATUS
19772WmiTraceMessageVa(
19773 IN TRACEHANDLE LoggerHandle,
19774 IN ULONG MessageFlags,
19775 IN LPGUID MessageGuid,
19776 IN USHORT MessageNumber,
19777 IN va_list MessageArgList
19778 );
19779
19780
19781#endif // #ifdef RUN_WPP
19782
19783#ifndef TRACE_INFORMATION_CLASS_DEFINE
19784typedef enum _TRACE_INFORMATION_CLASS {
19785 TraceIdClass,
19786 TraceHandleClass,
19787 TraceEnableFlagsClass,
19788 TraceEnableLevelClass,
19789 GlobalLoggerHandleClass,
19790 EventLoggerHandleClass,
19791 AllLoggerHandlesClass,
19792 TraceHandleByNameClass
19793} TRACE_INFORMATION_CLASS;
19794
19795NTKERNELAPI
19796NTSTATUS
19797WmiQueryTraceInformation(
19798 IN TRACE_INFORMATION_CLASS TraceInformationClass,
19799 OUT PVOID TraceInformation,
19800 IN ULONG TraceInformationLength,
19801 OUT PULONG RequiredLength OPTIONAL,
19802 IN PVOID Buffer OPTIONAL
19803 );
19804#define TRACE_INFORMATION_CLASS_DEFINE
19805#endif // TRACE_INFOPRMATION_CLASS_DEFINE
19806
19807
19808//
19809// Define PnP Device Property for IoGetDeviceProperty
19810//
19811
19812typedef enum {
19813 DevicePropertyDeviceDescription,
19814 DevicePropertyHardwareID,
19815 DevicePropertyCompatibleIDs,
19816 DevicePropertyBootConfiguration,
19817 DevicePropertyBootConfigurationTranslated,
19818 DevicePropertyClassName,
19819 DevicePropertyClassGuid,
19820 DevicePropertyDriverKeyName,
19821 DevicePropertyManufacturer,
19822 DevicePropertyFriendlyName,
19823 DevicePropertyLocationInformation,
19824 DevicePropertyPhysicalDeviceObjectName,
19825 DevicePropertyBusTypeGuid,
19826 DevicePropertyLegacyBusType,
19827 DevicePropertyBusNumber,
19828 DevicePropertyEnumeratorName,
19829 DevicePropertyAddress,
19830 DevicePropertyUINumber,
19831 DevicePropertyInstallState,
19832 DevicePropertyRemovalPolicy
19833} DEVICE_REGISTRY_PROPERTY;
19834
19835typedef BOOLEAN (*PTRANSLATE_BUS_ADDRESS)(
19836 IN PVOID Context,
19837 IN PHYSICAL_ADDRESS BusAddress,
19838 IN ULONG Length,
19839 IN OUT PULONG AddressSpace,
19840 OUT PPHYSICAL_ADDRESS TranslatedAddress
19841 );
19842
19843typedef struct _DMA_ADAPTER *(*PGET_DMA_ADAPTER)(
19844 IN PVOID Context,
19845 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
19846 OUT PULONG NumberOfMapRegisters
19847 );
19848
19849typedef ULONG (*PGET_SET_DEVICE_DATA)(
19850 IN PVOID Context,
19851 IN ULONG DataType,
19852 IN PVOID Buffer,
19853 IN ULONG Offset,
19854 IN ULONG Length
19855 );
19856
19857typedef enum _DEVICE_INSTALL_STATE {
19858 InstallStateInstalled,
19859 InstallStateNeedsReinstall,
19860 InstallStateFailedInstall,
19861 InstallStateFinishInstall
19862} DEVICE_INSTALL_STATE, *PDEVICE_INSTALL_STATE;
19863
19864//
19865// Define structure returned in response to IRP_MN_QUERY_BUS_INFORMATION by a
19866// PDO indicating the type of bus the device exists on.
19867//
19868
19869typedef struct _PNP_BUS_INFORMATION {
19870 GUID BusTypeGuid;
19871 INTERFACE_TYPE LegacyBusType;
19872 ULONG BusNumber;
19873} PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
19874
19875//
19876// Define structure returned in response to IRP_MN_QUERY_LEGACY_BUS_INFORMATION
19877// by an FDO indicating the type of bus it is. This is normally the same bus
19878// type as the device's children (i.e., as retrieved from the child PDO's via
19879// IRP_MN_QUERY_BUS_INFORMATION) except for cases like CardBus, which can
19880// support both 16-bit (PCMCIABus) and 32-bit (PCIBus) cards.
19881//
19882
19883typedef struct _LEGACY_BUS_INFORMATION {
19884 GUID BusTypeGuid;
19885 INTERFACE_TYPE LegacyBusType;
19886 ULONG BusNumber;
19887} LEGACY_BUS_INFORMATION, *PLEGACY_BUS_INFORMATION;
19888
19889//
19890// Defines for IoGetDeviceProperty(DevicePropertyRemovalPolicy).
19891//
19892typedef enum _DEVICE_REMOVAL_POLICY {
19893
19894 RemovalPolicyExpectNoRemoval = 1,
19895 RemovalPolicyExpectOrderlyRemoval = 2,
19896 RemovalPolicyExpectSurpriseRemoval = 3
19897
19898} DEVICE_REMOVAL_POLICY, *PDEVICE_REMOVAL_POLICY;
19899
19900
19901
19902typedef struct _BUS_INTERFACE_STANDARD {
19903 //
19904 // generic interface header
19905 //
19906 USHORT Size;
19907 USHORT Version;
19908 PVOID Context;
19909 PINTERFACE_REFERENCE InterfaceReference;
19910 PINTERFACE_DEREFERENCE InterfaceDereference;
19911 //
19912 // standard bus interfaces
19913 //
19914 PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
19915 PGET_DMA_ADAPTER GetDmaAdapter;
19916 PGET_SET_DEVICE_DATA SetBusData;
19917 PGET_SET_DEVICE_DATA GetBusData;
19918
19919} BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
19920
19921
19922typedef struct _AGP_TARGET_BUS_INTERFACE_STANDARD {
19923 //
19924 // generic interface header
19925 //
19926 USHORT Size;
19927 USHORT Version;
19928 PVOID Context;
19929 PINTERFACE_REFERENCE InterfaceReference;
19930 PINTERFACE_DEREFERENCE InterfaceDereference;
19931
19932 //
19933 // config munging routines
19934 //
19935 PGET_SET_DEVICE_DATA SetBusData;
19936 PGET_SET_DEVICE_DATA GetBusData;
19937 UCHAR CapabilityID; // 2 (AGPv2 host) or new 0xE (AGPv3 bridge)
19938
19939} AGP_TARGET_BUS_INTERFACE_STANDARD, *PAGP_TARGET_BUS_INTERFACE_STANDARD;
19940
19941
19942//
19943// The following definitions are used in ACPI QueryInterface
19944//
19945typedef BOOLEAN (* PGPE_SERVICE_ROUTINE) (
19946 PVOID,
19947 PVOID);
19948
19949typedef NTSTATUS (* PGPE_CONNECT_VECTOR) (
19950 PDEVICE_OBJECT,
19951 ULONG,
19952 KINTERRUPT_MODE,
19953 BOOLEAN,
19954 PGPE_SERVICE_ROUTINE,
19955 PVOID,
19956 PVOID);
19957
19958typedef NTSTATUS (* PGPE_DISCONNECT_VECTOR) (
19959 PVOID);
19960
19961typedef NTSTATUS (* PGPE_ENABLE_EVENT) (
19962 PDEVICE_OBJECT,
19963 PVOID);
19964
19965typedef NTSTATUS (* PGPE_DISABLE_EVENT) (
19966 PDEVICE_OBJECT,
19967 PVOID);
19968
19969typedef NTSTATUS (* PGPE_CLEAR_STATUS) (
19970 PDEVICE_OBJECT,
19971 PVOID);
19972
19973typedef VOID (* PDEVICE_NOTIFY_CALLBACK) (
19974 PVOID,
19975 ULONG);
19976
19977typedef NTSTATUS (* PREGISTER_FOR_DEVICE_NOTIFICATIONS) (
19978 PDEVICE_OBJECT,
19979 PDEVICE_NOTIFY_CALLBACK,
19980 PVOID);
19981
19982typedef void (* PUNREGISTER_FOR_DEVICE_NOTIFICATIONS) (
19983 PDEVICE_OBJECT,
19984 PDEVICE_NOTIFY_CALLBACK);
19985
19986typedef struct _ACPI_INTERFACE_STANDARD {
19987 //
19988 // Generic interface header
19989 //
19990 USHORT Size;
19991 USHORT Version;
19992 PVOID Context;
19993 PINTERFACE_REFERENCE InterfaceReference;
19994 PINTERFACE_DEREFERENCE InterfaceDereference;
19995 //
19996 // ACPI interfaces
19997 //
19998 PGPE_CONNECT_VECTOR GpeConnectVector;
19999 PGPE_DISCONNECT_VECTOR GpeDisconnectVector;
20000 PGPE_ENABLE_EVENT GpeEnableEvent;
20001 PGPE_DISABLE_EVENT GpeDisableEvent;
20002 PGPE_CLEAR_STATUS GpeClearStatus;
20003 PREGISTER_FOR_DEVICE_NOTIFICATIONS RegisterForDeviceNotifications;
20004 PUNREGISTER_FOR_DEVICE_NOTIFICATIONS UnregisterForDeviceNotifications;
20005
20006} ACPI_INTERFACE_STANDARD, *PACPI_INTERFACE_STANDARD;
20007
20008
20009NTKERNELAPI
20010NTSTATUS
20011IoReportDetectedDevice(
20012 IN PDRIVER_OBJECT DriverObject,
20013 IN INTERFACE_TYPE LegacyBusType,
20014 IN ULONG BusNumber,
20015 IN ULONG SlotNumber,
20016 IN PCM_RESOURCE_LIST ResourceList,
20017 IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL,
20018 IN BOOLEAN ResourceAssigned,
20019 IN OUT PDEVICE_OBJECT *DeviceObject
20020 );
20021
20022
20023
20024NTKERNELAPI
20025VOID
20026IoInvalidateDeviceRelations(
20027 IN PDEVICE_OBJECT DeviceObject,
20028 IN DEVICE_RELATION_TYPE Type
20029 );
20030
20031NTKERNELAPI
20032VOID
20033IoRequestDeviceEject(
20034 IN PDEVICE_OBJECT PhysicalDeviceObject
20035 );
20036
20037NTKERNELAPI
20038NTSTATUS
20039IoGetDeviceProperty(
20040 IN PDEVICE_OBJECT DeviceObject,
20041 IN DEVICE_REGISTRY_PROPERTY DeviceProperty,
20042 IN ULONG BufferLength,
20043 OUT PVOID PropertyBuffer,
20044 OUT PULONG ResultLength
20045 );
20046
20047//
20048// The following definitions are used in IoOpenDeviceRegistryKey
20049//
20050
20051#define PLUGPLAY_REGKEY_DEVICE 1
20052#define PLUGPLAY_REGKEY_DRIVER 2
20053#define PLUGPLAY_REGKEY_CURRENT_HWPROFILE 4
20054
20055NTKERNELAPI
20056NTSTATUS
20057IoOpenDeviceRegistryKey(
20058 IN PDEVICE_OBJECT DeviceObject,
20059 IN ULONG DevInstKeyType,
20060 IN ACCESS_MASK DesiredAccess,
20061 OUT PHANDLE DevInstRegKey
20062 );
20063
20064NTKERNELAPI
20065NTSTATUS
20066NTAPI
20067IoRegisterDeviceInterface(
20068 IN PDEVICE_OBJECT PhysicalDeviceObject,
20069 IN CONST GUID *InterfaceClassGuid,
20070 IN PUNICODE_STRING ReferenceString, OPTIONAL
20071 OUT PUNICODE_STRING SymbolicLinkName
20072 );
20073
20074NTKERNELAPI
20075NTSTATUS
20076IoOpenDeviceInterfaceRegistryKey(
20077 IN PUNICODE_STRING SymbolicLinkName,
20078 IN ACCESS_MASK DesiredAccess,
20079 OUT PHANDLE DeviceInterfaceKey
20080 );
20081
20082NTKERNELAPI
20083NTSTATUS
20084IoSetDeviceInterfaceState(
20085 IN PUNICODE_STRING SymbolicLinkName,
20086 IN BOOLEAN Enable
20087 );
20088
20089NTKERNELAPI
20090NTSTATUS
20091NTAPI
20092IoGetDeviceInterfaces(
20093 IN CONST GUID *InterfaceClassGuid,
20094 IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL,
20095 IN ULONG Flags,
20096 OUT PWSTR *SymbolicLinkList
20097 );
20098
20099#define DEVICE_INTERFACE_INCLUDE_NONACTIVE 0x00000001
20100
20101NTKERNELAPI
20102NTSTATUS
20103NTAPI
20104IoGetDeviceInterfaceAlias(
20105 IN PUNICODE_STRING SymbolicLinkName,
20106 IN CONST GUID *AliasInterfaceClassGuid,
20107 OUT PUNICODE_STRING AliasSymbolicLinkName
20108 );
20109
20110//
20111// Define PnP notification event categories
20112//
20113
20114typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
20115 EventCategoryReserved,
20116 EventCategoryHardwareProfileChange,
20117 EventCategoryDeviceInterfaceChange,
20118 EventCategoryTargetDeviceChange
20119} IO_NOTIFICATION_EVENT_CATEGORY;
20120
20121//
20122// Define flags that modify the behavior of IoRegisterPlugPlayNotification
20123// for the various event categories...
20124//
20125
20126#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
20127
20128typedef
20129NTSTATUS
20130(*PDRIVER_NOTIFICATION_CALLBACK_ROUTINE) (
20131 IN PVOID NotificationStructure,
20132 IN PVOID Context
20133);
20134
20135
20136NTKERNELAPI
20137NTSTATUS
20138IoRegisterPlugPlayNotification(
20139 IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory,
20140 IN ULONG EventCategoryFlags,
20141 IN PVOID EventCategoryData OPTIONAL,
20142 IN PDRIVER_OBJECT DriverObject,
20143 IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine,
20144 IN PVOID Context,
20145 OUT PVOID *NotificationEntry
20146 );
20147
20148NTKERNELAPI
20149NTSTATUS
20150IoUnregisterPlugPlayNotification(
20151 IN PVOID NotificationEntry
20152 );
20153
20154NTKERNELAPI
20155NTSTATUS
20156IoReportTargetDeviceChange(
20157 IN PDEVICE_OBJECT PhysicalDeviceObject,
20158 IN PVOID NotificationStructure // always begins with a PLUGPLAY_NOTIFICATION_HEADER
20159 );
20160
20161typedef
20162VOID
20163(*PDEVICE_CHANGE_COMPLETE_CALLBACK)(
20164 IN PVOID Context
20165 );
20166
20167NTKERNELAPI
20168VOID
20169IoInvalidateDeviceState(
20170 IN PDEVICE_OBJECT PhysicalDeviceObject
20171 );
20172
20173#define IoAdjustPagingPathCount(_count_,_paging_) { \
20174 if (_paging_) { \
20175 InterlockedIncrement(_count_); \
20176 } else { \
20177 InterlockedDecrement(_count_); \
20178 } \
20179}
20180
20181NTKERNELAPI
20182NTSTATUS
20183IoReportTargetDeviceChangeAsynchronous(
20184 IN PDEVICE_OBJECT PhysicalDeviceObject,
20185 IN PVOID NotificationStructure, // always begins with a PLUGPLAY_NOTIFICATION_HEADER
20186 IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback, OPTIONAL
20187 IN PVOID Context OPTIONAL
20188 );
20189
20190//
20191// Device location interface declarations
20192//
20193typedef
20194NTSTATUS
20195(*PGET_LOCATION_STRING) (
20196 IN PVOID Context,
20197 OUT PWCHAR *LocationStrings
20198 );
20199
20200typedef struct _PNP_LOCATION_INTERFACE {
20201 //
20202 // generic interface header
20203 //
20204 USHORT Size;
20205 USHORT Version;
20206 PVOID Context;
20207 PINTERFACE_REFERENCE InterfaceReference;
20208 PINTERFACE_DEREFERENCE InterfaceDereference;
20209
20210 //
20211 // interface specific entry
20212 //
20213 PGET_LOCATION_STRING GetLocationString;
20214
20215} PNP_LOCATION_INTERFACE, *PPNP_LOCATION_INTERFACE;
20216
20217//
20218// Resource arbiter declarations
20219//
20220
20221typedef enum _ARBITER_ACTION {
20222 ArbiterActionTestAllocation,
20223 ArbiterActionRetestAllocation,
20224 ArbiterActionCommitAllocation,
20225 ArbiterActionRollbackAllocation,
20226 ArbiterActionQueryAllocatedResources,
20227 ArbiterActionWriteReservedResources,
20228 ArbiterActionQueryConflict,
20229 ArbiterActionQueryArbitrate,
20230 ArbiterActionAddReserved,
20231 ArbiterActionBootAllocation
20232} ARBITER_ACTION, *PARBITER_ACTION;
20233
20234typedef struct _ARBITER_CONFLICT_INFO {
20235 //
20236 // The device object owning the device that is causing the conflict
20237 //
20238 PDEVICE_OBJECT OwningObject;
20239
20240 //
20241 // The start of the conflicting range
20242 //
20243 ULONGLONG Start;
20244
20245 //
20246 // The end of the conflicting range
20247 //
20248 ULONGLONG End;
20249
20250} ARBITER_CONFLICT_INFO, *PARBITER_CONFLICT_INFO;
20251
20252//
20253// The parameters for those actions
20254//
20255
20256typedef struct _ARBITER_PARAMETERS {
20257
20258 union {
20259
20260 struct {
20261
20262 //
20263 // Doubly linked list of ARBITER_LIST_ENTRY's
20264 //
20265 IN OUT PLIST_ENTRY ArbitrationList;
20266
20267 //
20268 // The size of the AllocateFrom array
20269 //
20270 IN ULONG AllocateFromCount;
20271
20272 //
20273 // Array of resource descriptors describing the resources available
20274 // to the arbiter for it to arbitrate
20275 //
20276 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
20277
20278 } TestAllocation;
20279
20280 struct {
20281
20282 //
20283 // Doubly linked list of ARBITER_LIST_ENTRY's
20284 //
20285 IN OUT PLIST_ENTRY ArbitrationList;
20286
20287 //
20288 // The size of the AllocateFrom array
20289 //
20290 IN ULONG AllocateFromCount;
20291
20292 //
20293 // Array of resource descriptors describing the resources available
20294 // to the arbiter for it to arbitrate
20295 //
20296 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR AllocateFrom;
20297
20298 } RetestAllocation;
20299
20300 struct {
20301
20302 //
20303 // Doubly linked list of ARBITER_LIST_ENTRY's
20304 //
20305 IN OUT PLIST_ENTRY ArbitrationList;
20306
20307 } BootAllocation;
20308
20309 struct {
20310
20311 //
20312 // The resources that are currently allocated
20313 //
20314 OUT PCM_PARTIAL_RESOURCE_LIST *AllocatedResources;
20315
20316 } QueryAllocatedResources;
20317
20318 struct {
20319
20320 //
20321 // This is the device we are trying to find a conflict for
20322 //
20323 IN PDEVICE_OBJECT PhysicalDeviceObject;
20324
20325 //
20326 // This is the resource to find the conflict for
20327 //
20328 IN PIO_RESOURCE_DESCRIPTOR ConflictingResource;
20329
20330 //
20331 // Number of devices conflicting on the resource
20332 //
20333 OUT PULONG ConflictCount;
20334
20335 //
20336 // Pointer to array describing the conflicting device objects and ranges
20337 //
20338 OUT PARBITER_CONFLICT_INFO *Conflicts;
20339
20340 } QueryConflict;
20341
20342 struct {
20343
20344 //
20345 // Doubly linked list of ARBITER_LIST_ENTRY's - should have
20346 // only one entry
20347 //
20348 IN PLIST_ENTRY ArbitrationList;
20349
20350 } QueryArbitrate;
20351
20352 struct {
20353
20354 //
20355 // Indicates the device whose resources are to be marked as reserved
20356 //
20357 PDEVICE_OBJECT ReserveDevice;
20358
20359 } AddReserved;
20360
20361 } Parameters;
20362
20363} ARBITER_PARAMETERS, *PARBITER_PARAMETERS;
20364
20365
20366
20367typedef enum _ARBITER_REQUEST_SOURCE {
20368
20369 ArbiterRequestUndefined = -1,
20370 ArbiterRequestLegacyReported, // IoReportResourceUsage
20371 ArbiterRequestHalReported, // IoReportHalResourceUsage
20372 ArbiterRequestLegacyAssigned, // IoAssignResources
20373 ArbiterRequestPnpDetected, // IoReportResourceForDetection
20374 ArbiterRequestPnpEnumerated // IRP_MN_QUERY_RESOURCE_REQUIREMENTS
20375
20376} ARBITER_REQUEST_SOURCE;
20377
20378
20379typedef enum _ARBITER_RESULT {
20380
20381 ArbiterResultUndefined = -1,
20382 ArbiterResultSuccess,
20383 ArbiterResultExternalConflict, // This indicates that the request can never be solved for devices in this list
20384 ArbiterResultNullRequest // The request was for length zero and thus no translation should be attempted
20385
20386} ARBITER_RESULT;
20387
20388//
20389// ARBITER_FLAG_BOOT_CONFIG - this indicates that the request is for the
20390// resources assigned by the firmware/BIOS. It should be succeeded even if
20391// it conflicts with another devices boot config.
20392//
20393
20394#define ARBITER_FLAG_BOOT_CONFIG 0x00000001
20395
20396
20397
20398NTKERNELAPI
20399NTSTATUS
20400IoReportResourceForDetection(
20401 IN PDRIVER_OBJECT DriverObject,
20402 IN PCM_RESOURCE_LIST DriverList OPTIONAL,
20403 IN ULONG DriverListSize OPTIONAL,
20404 IN PDEVICE_OBJECT DeviceObject OPTIONAL,
20405 IN PCM_RESOURCE_LIST DeviceList OPTIONAL,
20406 IN ULONG DeviceListSize OPTIONAL,
20407 OUT PBOOLEAN ConflictDetected
20408 );
20409
20410
20411
20412typedef struct _ARBITER_LIST_ENTRY {
20413
20414 //
20415 // This is a doubly linked list of entries for easy sorting
20416 //
20417 LIST_ENTRY ListEntry;
20418
20419 //
20420 // The number of alternative allocation
20421 //
20422 ULONG AlternativeCount;
20423
20424 //
20425 // Pointer to an array of resource descriptors for the possible allocations
20426 //
20427 PIO_RESOURCE_DESCRIPTOR Alternatives;
20428
20429 //
20430 // The device object of the device requesting these resources.
20431 //
20432 PDEVICE_OBJECT PhysicalDeviceObject;
20433
20434 //
20435 // Indicates where the request came from
20436 //
20437 ARBITER_REQUEST_SOURCE RequestSource;
20438
20439 //
20440 // Flags these indicate a variety of things (use ARBITER_FLAG_*)
20441 //
20442 ULONG Flags;
20443
20444 //
20445 // Space to aid the arbiter in processing the list it is initialized to 0 when
20446 // the entry is created. The system will not attempt to interpret it.
20447 //
20448 LONG_PTR WorkSpace;
20449
20450 //
20451 // Interface Type, Slot Number and Bus Number from Resource Requirements list,
20452 // used only for reverse identification.
20453 //
20454 INTERFACE_TYPE InterfaceType;
20455 ULONG SlotNumber;
20456 ULONG BusNumber;
20457
20458 //
20459 // A pointer to a descriptor to indicate the resource that was allocated.
20460 // This is allocated by the system and filled in by the arbiter in response to an
20461 // ArbiterActionTestAllocation.
20462 //
20463 PCM_PARTIAL_RESOURCE_DESCRIPTOR Assignment;
20464
20465 //
20466 // Pointer to the alternative that was chosen from to provide the assignment.
20467 // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
20468 //
20469 PIO_RESOURCE_DESCRIPTOR SelectedAlternative;
20470
20471 //
20472 // The result of the operation
20473 // This is filled in by the arbiter in response to an ArbiterActionTestAllocation.
20474 //
20475 ARBITER_RESULT Result;
20476
20477} ARBITER_LIST_ENTRY, *PARBITER_LIST_ENTRY;
20478
20479//
20480// The arbiter's entry point
20481//
20482
20483typedef
20484NTSTATUS
20485(*PARBITER_HANDLER) (
20486 IN PVOID Context,
20487 IN ARBITER_ACTION Action,
20488 IN OUT PARBITER_PARAMETERS Parameters
20489 );
20490
20491//
20492// Arbiter interface
20493//
20494
20495#define ARBITER_PARTIAL 0x00000001
20496
20497
20498typedef struct _ARBITER_INTERFACE {
20499
20500 //
20501 // Generic interface header
20502 //
20503 USHORT Size;
20504 USHORT Version;
20505 PVOID Context;
20506 PINTERFACE_REFERENCE InterfaceReference;
20507 PINTERFACE_DEREFERENCE InterfaceDereference;
20508
20509 //
20510 // Entry point to the arbiter
20511 //
20512 PARBITER_HANDLER ArbiterHandler;
20513
20514 //
20515 // Other information about the arbiter, use ARBITER_* flags
20516 //
20517 ULONG Flags;
20518
20519} ARBITER_INTERFACE, *PARBITER_INTERFACE;
20520
20521//
20522// The directions translation can take place in
20523//
20524
20525typedef enum _RESOURCE_TRANSLATION_DIRECTION { // ntosp
20526 TranslateChildToParent, // ntosp
20527 TranslateParentToChild // ntosp
20528} RESOURCE_TRANSLATION_DIRECTION; // ntosp
20529
20530//
20531// Translation functions
20532//
20533
20534
20535typedef
20536NTSTATUS
20537(*PTRANSLATE_RESOURCE_HANDLER)(
20538 IN PVOID Context,
20539 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Source,
20540 IN RESOURCE_TRANSLATION_DIRECTION Direction,
20541 IN ULONG AlternativesCount, OPTIONAL
20542 IN IO_RESOURCE_DESCRIPTOR Alternatives[], OPTIONAL
20543 IN PDEVICE_OBJECT PhysicalDeviceObject,
20544 OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Target
20545);
20546
20547typedef
20548NTSTATUS
20549(*PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER)(
20550 IN PVOID Context,
20551 IN PIO_RESOURCE_DESCRIPTOR Source,
20552 IN PDEVICE_OBJECT PhysicalDeviceObject,
20553 OUT PULONG TargetCount,
20554 OUT PIO_RESOURCE_DESCRIPTOR *Target
20555);
20556
20557//
20558// Translator Interface
20559//
20560
20561typedef struct _TRANSLATOR_INTERFACE {
20562 USHORT Size;
20563 USHORT Version;
20564 PVOID Context;
20565 PINTERFACE_REFERENCE InterfaceReference;
20566 PINTERFACE_DEREFERENCE InterfaceDereference;
20567 PTRANSLATE_RESOURCE_HANDLER TranslateResources;
20568 PTRANSLATE_RESOURCE_REQUIREMENTS_HANDLER TranslateResourceRequirements;
20569} TRANSLATOR_INTERFACE, *PTRANSLATOR_INTERFACE;
20570
20571
20572//
20573// Header structure for all Plug&Play notification events...
20574//
20575
20576typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
20577 USHORT Version; // presently at version 1.
20578 USHORT Size; // size (in bytes) of header + event-specific data.
20579 GUID Event;
20580 //
20581 // Event-specific stuff starts here.
20582 //
20583} PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
20584
20585//
20586// Notification structure for all EventCategoryHardwareProfileChange events...
20587//
20588
20589typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
20590 USHORT Version;
20591 USHORT Size;
20592 GUID Event;
20593 //
20594 // (No event-specific data)
20595 //
20596} HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
20597
20598
20599//
20600// Notification structure for all EventCategoryDeviceInterfaceChange events...
20601//
20602
20603typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
20604 USHORT Version;
20605 USHORT Size;
20606 GUID Event;
20607 //
20608 // Event-specific data
20609 //
20610 GUID InterfaceClassGuid;
20611 PUNICODE_STRING SymbolicLinkName;
20612} DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
20613
20614
20615//
20616// Notification structures for EventCategoryTargetDeviceChange...
20617//
20618
20619//
20620// The following structure is used for TargetDeviceQueryRemove,
20621// TargetDeviceRemoveCancelled, and TargetDeviceRemoveComplete:
20622//
20623typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
20624 USHORT Version;
20625 USHORT Size;
20626 GUID Event;
20627 //
20628 // Event-specific data
20629 //
20630 PFILE_OBJECT FileObject;
20631} TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
20632
20633//
20634// The following structure header is used for all other (i.e., 3rd-party)
20635// target device change events. The structure accommodates both a
20636// variable-length binary data buffer, and a variable-length unicode text
20637// buffer. The header must indicate where the text buffer begins, so that
20638// the data can be delivered in the appropriate format (ANSI or Unicode)
20639// to user-mode recipients (i.e., that have registered for handle-based
20640// notification via RegisterDeviceNotification).
20641//
20642
20643typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
20644 USHORT Version;
20645 USHORT Size;
20646 GUID Event;
20647 //
20648 // Event-specific data
20649 //
20650 PFILE_OBJECT FileObject; // This field must be set to NULL by callers of
20651 // IoReportTargetDeviceChange. Clients that
20652 // have registered for target device change
20653 // notification on the affected PDO will be
20654 // called with this field set to the file object
20655 // they specified during registration.
20656 //
20657 LONG NameBufferOffset; // offset (in bytes) from beginning of
20658 // CustomDataBuffer where text begins (-1 if none)
20659 //
20660 UCHAR CustomDataBuffer[1]; // variable-length buffer, containing (optionally)
20661 // a binary data at the start of the buffer,
20662 // followed by an optional unicode text buffer
20663 // (word-aligned).
20664 //
20665} TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
20666
20667//
20668// Define the device description structure.
20669//
20670
20671typedef struct _DEVICE_DESCRIPTION {
20672 ULONG Version;
20673 BOOLEAN Master;
20674 BOOLEAN ScatterGather;
20675 BOOLEAN DemandMode;
20676 BOOLEAN AutoInitialize;
20677 BOOLEAN Dma32BitAddresses;
20678 BOOLEAN IgnoreCount;
20679 BOOLEAN Reserved1; // must be false
20680 BOOLEAN Dma64BitAddresses;
20681 ULONG BusNumber; // unused for WDM
20682 ULONG DmaChannel;
20683 INTERFACE_TYPE InterfaceType;
20684 DMA_WIDTH DmaWidth;
20685 DMA_SPEED DmaSpeed;
20686 ULONG MaximumLength;
20687 ULONG DmaPort;
20688} DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
20689
20690//
20691// Define the supported version numbers for the device description structure.
20692//
20693
20694#define DEVICE_DESCRIPTION_VERSION 0
20695#define DEVICE_DESCRIPTION_VERSION1 1
20696#define DEVICE_DESCRIPTION_VERSION2 2
20697
20698//
20699// The following function prototypes are for HAL routines with a prefix of Hal.
20700//
20701// General functions.
20702//
20703
20704typedef
20705BOOLEAN
20706(*PHAL_RESET_DISPLAY_PARAMETERS) (
20707 IN ULONG Columns,
20708 IN ULONG Rows
20709 );
20710
20711DECLSPEC_DEPRECATED_DDK
20712NTHALAPI
20713VOID
20714HalAcquireDisplayOwnership (
20715 IN PHAL_RESET_DISPLAY_PARAMETERS ResetDisplayParameters
20716 );
20717
20718#if defined(_IA64_)
20719
20720DECLSPEC_DEPRECATED_DDK // Use GetDmaRequirement
20721NTHALAPI
20722ULONG
20723HalGetDmaAlignmentRequirement (
20724 VOID
20725 );
20726
20727#endif
20728
20729#if defined(_M_IX86) || defined(_M_AMD64)
20730
20731#define HalGetDmaAlignmentRequirement() 1L
20732#endif
20733
20734NTHALAPI
20735VOID
20736KeFlushWriteBuffer (
20737 VOID
20738 );
20739
20740//
20741// I/O driver configuration functions.
20742//
20743#if !defined(NO_LEGACY_DRIVERS)
20744DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
20745NTHALAPI
20746NTSTATUS
20747HalAssignSlotResources (
20748 IN PUNICODE_STRING RegistryPath,
20749 IN PUNICODE_STRING DriverClassName OPTIONAL,
20750 IN PDRIVER_OBJECT DriverObject,
20751 IN PDEVICE_OBJECT DeviceObject,
20752 IN INTERFACE_TYPE BusType,
20753 IN ULONG BusNumber,
20754 IN ULONG SlotNumber,
20755 IN OUT PCM_RESOURCE_LIST *AllocatedResources
20756 );
20757
20758DECLSPEC_DEPRECATED_DDK // Use Pnp or IoReportDetectedDevice
20759NTHALAPI
20760ULONG
20761HalGetInterruptVector(
20762 IN INTERFACE_TYPE InterfaceType,
20763 IN ULONG BusNumber,
20764 IN ULONG BusInterruptLevel,
20765 IN ULONG BusInterruptVector,
20766 OUT PKIRQL Irql,
20767 OUT PKAFFINITY Affinity
20768 );
20769
20770DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
20771NTHALAPI
20772ULONG
20773HalSetBusData(
20774 IN BUS_DATA_TYPE BusDataType,
20775 IN ULONG BusNumber,
20776 IN ULONG SlotNumber,
20777 IN PVOID Buffer,
20778 IN ULONG Length
20779 );
20780#endif // NO_LEGACY_DRIVERS
20781
20782DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
20783NTHALAPI
20784ULONG
20785HalSetBusDataByOffset(
20786 IN BUS_DATA_TYPE BusDataType,
20787 IN ULONG BusNumber,
20788 IN ULONG SlotNumber,
20789 IN PVOID Buffer,
20790 IN ULONG Offset,
20791 IN ULONG Length
20792 );
20793
20794DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
20795NTHALAPI
20796BOOLEAN
20797HalTranslateBusAddress(
20798 IN INTERFACE_TYPE InterfaceType,
20799 IN ULONG BusNumber,
20800 IN PHYSICAL_ADDRESS BusAddress,
20801 IN OUT PULONG AddressSpace,
20802 OUT PPHYSICAL_ADDRESS TranslatedAddress
20803 );
20804
20805//
20806// Values for AddressSpace parameter of HalTranslateBusAddress
20807//
20808// 0x0 - Memory space
20809// 0x1 - Port space
20810// 0x2 - 0x1F - Address spaces specific for Alpha
20811// 0x2 - UserMode view of memory space
20812// 0x3 - UserMode view of port space
20813// 0x4 - Dense memory space
20814// 0x5 - reserved
20815// 0x6 - UserMode view of dense memory space
20816// 0x7 - 0x1F - reserved
20817//
20818
20819NTHALAPI
20820PVOID
20821HalAllocateCrashDumpRegisters(
20822 IN PADAPTER_OBJECT AdapterObject,
20823 IN OUT PULONG NumberOfMapRegisters
20824 );
20825
20826#if !defined(NO_LEGACY_DRIVERS)
20827DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
20828NTHALAPI
20829ULONG
20830HalGetBusData(
20831 IN BUS_DATA_TYPE BusDataType,
20832 IN ULONG BusNumber,
20833 IN ULONG SlotNumber,
20834 IN PVOID Buffer,
20835 IN ULONG Length
20836 );
20837#endif // NO_LEGACY_DRIVERS
20838
20839DECLSPEC_DEPRECATED_DDK // Use IRP_MN_QUERY_INTERFACE and IRP_MN_READ_CONFIG
20840NTHALAPI
20841ULONG
20842HalGetBusDataByOffset(
20843 IN BUS_DATA_TYPE BusDataType,
20844 IN ULONG BusNumber,
20845 IN ULONG SlotNumber,
20846 IN PVOID Buffer,
20847 IN ULONG Offset,
20848 IN ULONG Length
20849 );
20850
20851DECLSPEC_DEPRECATED_DDK // Use IoGetDmaAdapter
20852NTHALAPI
20853PADAPTER_OBJECT
20854HalGetAdapter(
20855 IN PDEVICE_DESCRIPTION DeviceDescription,
20856 IN OUT PULONG NumberOfMapRegisters
20857 );
20858
20859//
20860// System beep functions.
20861//
20862#if !defined(NO_LEGACY_DRIVERS)
20863DECLSPEC_DEPRECATED_DDK
20864NTHALAPI
20865BOOLEAN
20866HalMakeBeep(
20867 IN ULONG Frequency
20868 );
20869#endif // NO_LEGACY_DRIVERS
20870
20871//
20872// The following function prototypes are for HAL routines with a prefix of Io.
20873//
20874// DMA adapter object functions.
20875//
20876
20877//
20878// Performance counter function.
20879//
20880
20881NTHALAPI
20882LARGE_INTEGER
20883KeQueryPerformanceCounter (
20884 OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL
20885 );
20886
20887
20888//
20889// Stall processor execution function.
20890//
20891
20892NTHALAPI
20893VOID
20894KeStallExecutionProcessor (
20895 IN ULONG MicroSeconds
20896 );
20897
20898
20899typedef
20900VOID
20901(*PDEVICE_CONTROL_COMPLETION)(
20902 IN struct _DEVICE_CONTROL_CONTEXT *ControlContext
20903 );
20904
20905typedef struct _DEVICE_CONTROL_CONTEXT {
20906 NTSTATUS Status;
20907 PDEVICE_HANDLER_OBJECT DeviceHandler;
20908 PDEVICE_OBJECT DeviceObject;
20909 ULONG ControlCode;
20910 PVOID Buffer;
20911 PULONG BufferLength;
20912 PVOID Context;
20913} DEVICE_CONTROL_CONTEXT, *PDEVICE_CONTROL_CONTEXT;
20914
20915typedef
20916PBUS_HANDLER
20917(FASTCALL *pHalHandlerForBus) (
20918 IN INTERFACE_TYPE InterfaceType,
20919 IN ULONG BusNumber
20920 );
20921typedef
20922VOID
20923(FASTCALL *pHalReferenceBusHandler) (
20924 IN PBUS_HANDLER BusHandler
20925 );
20926
20927//*****************************************************************************
20928// HAL Function dispatch
20929//
20930
20931typedef enum _HAL_QUERY_INFORMATION_CLASS {
20932 HalInstalledBusInformation,
20933 HalProfileSourceInformation,
20934 HalInformationClassUnused1,
20935 HalPowerInformation,
20936 HalProcessorSpeedInformation,
20937 HalCallbackInformation,
20938 HalMapRegisterInformation,
20939 HalMcaLogInformation, // Machine Check Abort Information
20940 HalFrameBufferCachingInformation,
20941 HalDisplayBiosInformation,
20942 HalProcessorFeatureInformation,
20943 HalNumaTopologyInterface,
20944 HalErrorInformation, // General MCA, CMC, CPE Error Information.
20945 HalCmcLogInformation, // Processor Corrected Machine Check Information
20946 HalCpeLogInformation, // Corrected Platform Error Information
20947 HalQueryMcaInterface,
20948 HalQueryAMLIIllegalIOPortAddresses,
20949 HalQueryMaxHotPlugMemoryAddress,
20950 HalPartitionIpiInterface,
20951 HalPlatformInformation,
20952 HalQueryProfileSourceList
20953 // information levels >= 0x8000000 reserved for OEM use
20954} HAL_QUERY_INFORMATION_CLASS, *PHAL_QUERY_INFORMATION_CLASS;
20955
20956
20957typedef enum _HAL_SET_INFORMATION_CLASS {
20958 HalProfileSourceInterval,
20959 HalProfileSourceInterruptHandler,
20960 HalMcaRegisterDriver, // Registring Machine Check Abort driver
20961 HalKernelErrorHandler,
20962 HalCmcRegisterDriver, // Registring Processor Corrected Machine Check driver
20963 HalCpeRegisterDriver, // Registring Corrected Platform Error driver
20964 HalMcaLog,
20965 HalCmcLog,
20966 HalCpeLog,
20967 HalGenerateCmcInterrupt // Used to test CMC
20968} HAL_SET_INFORMATION_CLASS, *PHAL_SET_INFORMATION_CLASS;
20969
20970
20971typedef
20972NTSTATUS
20973(*pHalQuerySystemInformation)(
20974 IN HAL_QUERY_INFORMATION_CLASS InformationClass,
20975 IN ULONG BufferSize,
20976 IN OUT PVOID Buffer,
20977 OUT PULONG ReturnedLength
20978 );
20979
20980
20981typedef
20982NTSTATUS
20983(*pHalSetSystemInformation)(
20984 IN HAL_SET_INFORMATION_CLASS InformationClass,
20985 IN ULONG BufferSize,
20986 IN PVOID Buffer
20987 );
20988
20989
20990typedef
20991VOID
20992(FASTCALL *pHalExamineMBR)(
20993 IN PDEVICE_OBJECT DeviceObject,
20994 IN ULONG SectorSize,
20995 IN ULONG MBRTypeIdentifier,
20996 OUT PVOID *Buffer
20997 );
20998
20999typedef
21000VOID
21001(FASTCALL *pHalIoAssignDriveLetters)(
21002 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
21003 IN PSTRING NtDeviceName,
21004 OUT PUCHAR NtSystemPath,
21005 OUT PSTRING NtSystemPathString
21006 );
21007
21008typedef
21009NTSTATUS
21010(FASTCALL *pHalIoReadPartitionTable)(
21011 IN PDEVICE_OBJECT DeviceObject,
21012 IN ULONG SectorSize,
21013 IN BOOLEAN ReturnRecognizedPartitions,
21014 OUT struct _DRIVE_LAYOUT_INFORMATION **PartitionBuffer
21015 );
21016
21017typedef
21018NTSTATUS
21019(FASTCALL *pHalIoSetPartitionInformation)(
21020 IN PDEVICE_OBJECT DeviceObject,
21021 IN ULONG SectorSize,
21022 IN ULONG PartitionNumber,
21023 IN ULONG PartitionType
21024 );
21025
21026typedef
21027NTSTATUS
21028(FASTCALL *pHalIoWritePartitionTable)(
21029 IN PDEVICE_OBJECT DeviceObject,
21030 IN ULONG SectorSize,
21031 IN ULONG SectorsPerTrack,
21032 IN ULONG NumberOfHeads,
21033 IN struct _DRIVE_LAYOUT_INFORMATION *PartitionBuffer
21034 );
21035
21036typedef
21037NTSTATUS
21038(*pHalQueryBusSlots)(
21039 IN PBUS_HANDLER BusHandler,
21040 IN ULONG BufferSize,
21041 OUT PULONG SlotNumbers,
21042 OUT PULONG ReturnedLength
21043 );
21044
21045typedef
21046NTSTATUS
21047(*pHalInitPnpDriver)(
21048 VOID
21049 );
21050
21051
21052typedef struct _PM_DISPATCH_TABLE {
21053 ULONG Signature;
21054 ULONG Version;
21055 PVOID Function[1];
21056} PM_DISPATCH_TABLE, *PPM_DISPATCH_TABLE;
21057
21058typedef
21059NTSTATUS
21060(*pHalInitPowerManagement)(
21061 IN PPM_DISPATCH_TABLE PmDriverDispatchTable,
21062 OUT PPM_DISPATCH_TABLE *PmHalDispatchTable
21063 );
21064
21065
21066typedef
21067struct _DMA_ADAPTER *
21068(*pHalGetDmaAdapter)(
21069 IN PVOID Context,
21070 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
21071 OUT PULONG NumberOfMapRegisters
21072 );
21073
21074
21075typedef
21076NTSTATUS
21077(*pHalGetInterruptTranslator)(
21078 IN INTERFACE_TYPE ParentInterfaceType,
21079 IN ULONG ParentBusNumber,
21080 IN INTERFACE_TYPE BridgeInterfaceType,
21081 IN USHORT Size,
21082 IN USHORT Version,
21083 OUT PTRANSLATOR_INTERFACE Translator,
21084 OUT PULONG BridgeBusNumber
21085 );
21086
21087
21088typedef
21089BOOLEAN
21090(*pHalTranslateBusAddress)(
21091 IN INTERFACE_TYPE InterfaceType,
21092 IN ULONG BusNumber,
21093 IN PHYSICAL_ADDRESS BusAddress,
21094 IN OUT PULONG AddressSpace,
21095 OUT PPHYSICAL_ADDRESS TranslatedAddress
21096 );
21097
21098typedef
21099NTSTATUS
21100(*pHalAssignSlotResources) (
21101 IN PUNICODE_STRING RegistryPath,
21102 IN PUNICODE_STRING DriverClassName OPTIONAL,
21103 IN PDRIVER_OBJECT DriverObject,
21104 IN PDEVICE_OBJECT DeviceObject,
21105 IN INTERFACE_TYPE BusType,
21106 IN ULONG BusNumber,
21107 IN ULONG SlotNumber,
21108 IN OUT PCM_RESOURCE_LIST *AllocatedResources
21109 );
21110
21111typedef
21112VOID
21113(*pHalHaltSystem) (
21114 VOID
21115 );
21116
21117typedef
21118BOOLEAN
21119(*pHalResetDisplay) (
21120 VOID
21121 );
21122
21123
21124typedef struct _MAP_REGISTER_ENTRY {
21125 PVOID MapRegister;
21126 BOOLEAN WriteToDevice;
21127} MAP_REGISTER_ENTRY, *PMAP_REGISTER_ENTRY;
21128
21129
21130
21131typedef
21132UCHAR
21133(*pHalVectorToIDTEntry) (
21134 ULONG Vector
21135);
21136
21137typedef
21138BOOLEAN
21139(*pHalFindBusAddressTranslation) (
21140 IN PHYSICAL_ADDRESS BusAddress,
21141 IN OUT PULONG AddressSpace,
21142 OUT PPHYSICAL_ADDRESS TranslatedAddress,
21143 IN OUT PULONG_PTR Context,
21144 IN BOOLEAN NextBus
21145 );
21146
21147typedef
21148NTSTATUS
21149(*pHalStartMirroring)(
21150 VOID
21151 );
21152
21153typedef
21154NTSTATUS
21155(*pHalEndMirroring)(
21156 IN ULONG PassNumber
21157 );
21158
21159typedef
21160NTSTATUS
21161(*pHalMirrorPhysicalMemory)(
21162 IN PHYSICAL_ADDRESS PhysicalAddress,
21163 IN LARGE_INTEGER NumberOfBytes
21164 );
21165
21166typedef
21167NTSTATUS
21168(*pHalMirrorVerify)(
21169 IN PHYSICAL_ADDRESS PhysicalAddress,
21170 IN LARGE_INTEGER NumberOfBytes
21171 );
21172
21173typedef struct {
21174 UCHAR Type; //CmResourceType
21175 BOOLEAN Valid;
21176 UCHAR Reserved[2];
21177 PUCHAR TranslatedAddress;
21178 ULONG Length;
21179} DEBUG_DEVICE_ADDRESS, *PDEBUG_DEVICE_ADDRESS;
21180
21181typedef struct {
21182 PHYSICAL_ADDRESS Start;
21183 PHYSICAL_ADDRESS MaxEnd;
21184 PVOID VirtualAddress;
21185 ULONG Length;
21186 BOOLEAN Cached;
21187 BOOLEAN Aligned;
21188} DEBUG_MEMORY_REQUIREMENTS, *PDEBUG_MEMORY_REQUIREMENTS;
21189
21190typedef struct {
21191 ULONG Bus;
21192 ULONG Slot;
21193 USHORT VendorID;
21194 USHORT DeviceID;
21195 UCHAR BaseClass;
21196 UCHAR SubClass;
21197 UCHAR ProgIf;
21198 BOOLEAN Initialized;
21199 DEBUG_DEVICE_ADDRESS BaseAddress[6];
21200 DEBUG_MEMORY_REQUIREMENTS Memory;
21201} DEBUG_DEVICE_DESCRIPTOR, *PDEBUG_DEVICE_DESCRIPTOR;
21202
21203typedef
21204NTSTATUS
21205(*pKdSetupPciDeviceForDebugging)(
21206 IN PVOID LoaderBlock, OPTIONAL
21207 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
21208);
21209
21210typedef
21211NTSTATUS
21212(*pKdReleasePciDeviceForDebugging)(
21213 IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
21214);
21215
21216typedef
21217PVOID
21218(*pKdGetAcpiTablePhase0)(
21219 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
21220 IN ULONG Signature
21221 );
21222
21223typedef
21224VOID
21225(*pKdCheckPowerButton)(
21226 VOID
21227 );
21228
21229typedef
21230VOID
21231(*pHalEndOfBoot)(
21232 VOID
21233 );
21234
21235typedef
21236PVOID
21237(*pKdMapPhysicalMemory64)(
21238 IN PHYSICAL_ADDRESS PhysicalAddress,
21239 IN ULONG NumberPages
21240 );
21241
21242typedef
21243VOID
21244(*pKdUnmapVirtualAddress)(
21245 IN PVOID VirtualAddress,
21246 IN ULONG NumberPages
21247 );
21248
21249
21250typedef struct {
21251 ULONG Version;
21252 pHalQuerySystemInformation HalQuerySystemInformation;
21253 pHalSetSystemInformation HalSetSystemInformation;
21254 pHalQueryBusSlots HalQueryBusSlots;
21255 ULONG Spare1;
21256 pHalExamineMBR HalExamineMBR;
21257 pHalIoAssignDriveLetters HalIoAssignDriveLetters;
21258 pHalIoReadPartitionTable HalIoReadPartitionTable;
21259 pHalIoSetPartitionInformation HalIoSetPartitionInformation;
21260 pHalIoWritePartitionTable HalIoWritePartitionTable;
21261
21262 pHalHandlerForBus HalReferenceHandlerForBus;
21263 pHalReferenceBusHandler HalReferenceBusHandler;
21264 pHalReferenceBusHandler HalDereferenceBusHandler;
21265
21266 pHalInitPnpDriver HalInitPnpDriver;
21267 pHalInitPowerManagement HalInitPowerManagement;
21268
21269 pHalGetDmaAdapter HalGetDmaAdapter;
21270 pHalGetInterruptTranslator HalGetInterruptTranslator;
21271
21272 pHalStartMirroring HalStartMirroring;
21273 pHalEndMirroring HalEndMirroring;
21274 pHalMirrorPhysicalMemory HalMirrorPhysicalMemory;
21275 pHalEndOfBoot HalEndOfBoot;
21276 pHalMirrorVerify HalMirrorVerify;
21277
21278} HAL_DISPATCH, *PHAL_DISPATCH;
21279
21280#if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)
21281
21282extern PHAL_DISPATCH HalDispatchTable;
21283#define HALDISPATCH HalDispatchTable
21284
21285#else
21286
21287extern HAL_DISPATCH HalDispatchTable;
21288#define HALDISPATCH (&HalDispatchTable)
21289
21290#endif
21291
21292#define HAL_DISPATCH_VERSION 3
21293
21294#define HalDispatchTableVersion HALDISPATCH->Version
21295#define HalQuerySystemInformation HALDISPATCH->HalQuerySystemInformation
21296#define HalSetSystemInformation HALDISPATCH->HalSetSystemInformation
21297#define HalQueryBusSlots HALDISPATCH->HalQueryBusSlots
21298
21299#define HalReferenceHandlerForBus HALDISPATCH->HalReferenceHandlerForBus
21300#define HalReferenceBusHandler HALDISPATCH->HalReferenceBusHandler
21301#define HalDereferenceBusHandler HALDISPATCH->HalDereferenceBusHandler
21302
21303#define HalInitPnpDriver HALDISPATCH->HalInitPnpDriver
21304#define HalInitPowerManagement HALDISPATCH->HalInitPowerManagement
21305
21306#define HalGetDmaAdapter HALDISPATCH->HalGetDmaAdapter
21307#define HalGetInterruptTranslator HALDISPATCH->HalGetInterruptTranslator
21308
21309#define HalStartMirroring HALDISPATCH->HalStartMirroring
21310#define HalEndMirroring HALDISPATCH->HalEndMirroring
21311#define HalMirrorPhysicalMemory HALDISPATCH->HalMirrorPhysicalMemory
21312#define HalEndOfBoot HALDISPATCH->HalEndOfBoot
21313#define HalMirrorVerify HALDISPATCH->HalMirrorVerify
21314
21315
21316//
21317// HAL System Information Structures.
21318//
21319
21320// for the information class "HalInstalledBusInformation"
21321typedef struct _HAL_BUS_INFORMATION{
21322 INTERFACE_TYPE BusType;
21323 BUS_DATA_TYPE ConfigurationType;
21324 ULONG BusNumber;
21325 ULONG Reserved;
21326} HAL_BUS_INFORMATION, *PHAL_BUS_INFORMATION;
21327
21328// for the information class "HalProfileSourceInformation"
21329typedef struct _HAL_PROFILE_SOURCE_INFORMATION {
21330 KPROFILE_SOURCE Source;
21331 BOOLEAN Supported;
21332 ULONG Interval;
21333} HAL_PROFILE_SOURCE_INFORMATION, *PHAL_PROFILE_SOURCE_INFORMATION;
21334
21335// for the information class "HalProfileSourceInformation"
21336typedef struct _HAL_PROFILE_SOURCE_INFORMATION_EX {
21337 KPROFILE_SOURCE Source;
21338 BOOLEAN Supported;
21339 ULONG_PTR Interval;
21340 ULONG_PTR DefInterval;
21341 ULONG_PTR MaxInterval;
21342 ULONG_PTR MinInterval;
21343} HAL_PROFILE_SOURCE_INFORMATION_EX, *PHAL_PROFILE_SOURCE_INFORMATION_EX;
21344
21345// for the information class "HalProfileSourceInterval"
21346typedef struct _HAL_PROFILE_SOURCE_INTERVAL {
21347 KPROFILE_SOURCE Source;
21348 ULONG_PTR Interval;
21349} HAL_PROFILE_SOURCE_INTERVAL, *PHAL_PROFILE_SOURCE_INTERVAL;
21350
21351// for the information class "HalQueryProfileSourceList"
21352typedef struct _HAL_PROFILE_SOURCE_LIST {
21353 KPROFILE_SOURCE Source;
21354 PWSTR Description;
21355} HAL_PROFILE_SOURCE_LIST, *PHAL_PROFILE_SOURCE_LIST;
21356
21357// for the information class "HalDispayBiosInformation"
21358typedef enum _HAL_DISPLAY_BIOS_INFORMATION {
21359 HalDisplayInt10Bios,
21360 HalDisplayEmulatedBios,
21361 HalDisplayNoBios
21362} HAL_DISPLAY_BIOS_INFORMATION, *PHAL_DISPLAY_BIOS_INFORMATION;
21363
21364// for the information class "HalPowerInformation"
21365typedef struct _HAL_POWER_INFORMATION {
21366 ULONG TBD;
21367} HAL_POWER_INFORMATION, *PHAL_POWER_INFORMATION;
21368
21369// for the information class "HalProcessorSpeedInformation"
21370typedef struct _HAL_PROCESSOR_SPEED_INFO {
21371 ULONG ProcessorSpeed;
21372} HAL_PROCESSOR_SPEED_INFORMATION, *PHAL_PROCESSOR_SPEED_INFORMATION;
21373
21374// for the information class "HalCallbackInformation"
21375typedef struct _HAL_CALLBACKS {
21376 PCALLBACK_OBJECT SetSystemInformation;
21377 PCALLBACK_OBJECT BusCheck;
21378} HAL_CALLBACKS, *PHAL_CALLBACKS;
21379
21380// for the information class "HalProcessorFeatureInformation"
21381typedef struct _HAL_PROCESSOR_FEATURE {
21382 ULONG UsableFeatureBits;
21383} HAL_PROCESSOR_FEATURE;
21384
21385// for the information class "HalNumaTopologyInterface"
21386
21387typedef ULONG HALNUMAPAGETONODE;
21388
21389typedef
21390HALNUMAPAGETONODE
21391(*PHALNUMAPAGETONODE)(
21392 IN ULONG_PTR PhysicalPageNumber
21393 );
21394
21395typedef
21396NTSTATUS
21397(*PHALNUMAQUERYPROCESSORNODE)(
21398 IN ULONG ProcessorNumber,
21399 OUT PUSHORT Identifier,
21400 OUT PUCHAR Node
21401 );
21402
21403typedef struct _HAL_NUMA_TOPOLOGY_INTERFACE {
21404 ULONG NumberOfNodes;
21405 PHALNUMAQUERYPROCESSORNODE QueryProcessorNode;
21406 PHALNUMAPAGETONODE PageToNode;
21407} HAL_NUMA_TOPOLOGY_INTERFACE;
21408
21409typedef
21410NTSTATUS
21411(*PHALIOREADWRITEHANDLER)(
21412 IN BOOLEAN fRead,
21413 IN ULONG dwAddr,
21414 IN ULONG dwSize,
21415 IN OUT PULONG pdwData
21416 );
21417
21418// for the information class "HalQueryIllegalIOPortAddresses"
21419typedef struct _HAL_AMLI_BAD_IO_ADDRESS_LIST
21420{
21421 ULONG BadAddrBegin;
21422 ULONG BadAddrSize;
21423 ULONG OSVersionTrigger;
21424 PHALIOREADWRITEHANDLER IOHandler;
21425} HAL_AMLI_BAD_IO_ADDRESS_LIST, *PHAL_AMLI_BAD_IO_ADDRESS_LIST;
21426
21427
21428
21429#if defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
21430
21431//
21432// HalQueryMcaInterface
21433//
21434
21435typedef
21436VOID
21437(*PHALMCAINTERFACELOCK)(
21438 VOID
21439 );
21440
21441typedef
21442VOID
21443(*PHALMCAINTERFACEUNLOCK)(
21444 VOID
21445 );
21446
21447typedef
21448NTSTATUS
21449(*PHALMCAINTERFACEREADREGISTER)(
21450 IN UCHAR BankNumber,
21451 IN OUT PVOID Exception
21452 );
21453
21454typedef struct _HAL_MCA_INTERFACE {
21455 PHALMCAINTERFACELOCK Lock;
21456 PHALMCAINTERFACEUNLOCK Unlock;
21457 PHALMCAINTERFACEREADREGISTER ReadRegister;
21458} HAL_MCA_INTERFACE;
21459
21460#if defined(_AMD64_)
21461
21462struct _KTRAP_FRAME;
21463struct _KEXCEPTION_FRAME;
21464
21465typedef
21466ERROR_SEVERITY
21467(*PDRIVER_EXCPTN_CALLBACK) (
21468 IN PVOID Context,
21469 IN struct _KTRAP_FRAME *TrapFrame,
21470 IN struct _KEXCEPTION_FRAME *ExceptionFrame,
21471 IN PMCA_EXCEPTION Exception
21472);
21473
21474#endif
21475
21476#if defined(_X86_) || defined(_IA64_)
21477
21478typedef
21479#if defined(_IA64_)
21480ERROR_SEVERITY
21481#else
21482VOID
21483#endif
21484(*PDRIVER_EXCPTN_CALLBACK) (
21485 IN PVOID Context,
21486 IN PMCA_EXCEPTION BankLog
21487);
21488
21489#endif
21490
21491typedef PDRIVER_EXCPTN_CALLBACK PDRIVER_MCA_EXCEPTION_CALLBACK;
21492
21493//
21494// Structure to record the callbacks from driver
21495//
21496
21497typedef struct _MCA_DRIVER_INFO {
21498 PDRIVER_MCA_EXCEPTION_CALLBACK ExceptionCallback;
21499 PKDEFERRED_ROUTINE DpcCallback;
21500 PVOID DeviceContext;
21501} MCA_DRIVER_INFO, *PMCA_DRIVER_INFO;
21502
21503
21504typedef struct _HAL_ERROR_INFO {
21505 ULONG Version; // Version of this structure
21506 ULONG Reserved; //
21507 ULONG McaMaxSize; // Maximum size of a Machine Check Abort record
21508 ULONG McaPreviousEventsCount; // Flag indicating previous or early-boot MCA event logs.
21509 ULONG McaCorrectedEventsCount; // Number of corrected MCA events since boot. approx.
21510 ULONG McaKernelDeliveryFails; // Number of Kernel callback failures. approx.
21511 ULONG McaDriverDpcQueueFails; // Number of OEM MCA Driver Dpc queueing failures. approx.
21512 ULONG McaReserved;
21513 ULONG CmcMaxSize; // Maximum size of a Corrected Machine Check record
21514 ULONG CmcPollingInterval; // In units of seconds
21515 ULONG CmcInterruptsCount; // Number of CMC interrupts. approx.
21516 ULONG CmcKernelDeliveryFails; // Number of Kernel callback failures. approx.
21517 ULONG CmcDriverDpcQueueFails; // Number of OEM CMC Driver Dpc queueing failures. approx.
21518 ULONG CmcGetStateFails; // Number of failures in getting the log from FW.
21519 ULONG CmcClearStateFails; // Number of failures in clearing the log from FW.
21520 ULONG CmcReserved;
21521 ULONGLONG CmcLogId; // Last seen record identifier.
21522 ULONG CpeMaxSize; // Maximum size of a Corrected Platform Event record
21523 ULONG CpePollingInterval; // In units of seconds
21524 ULONG CpeInterruptsCount; // Number of CPE interrupts. approx.
21525 ULONG CpeKernelDeliveryFails; // Number of Kernel callback failures. approx.
21526 ULONG CpeDriverDpcQueueFails; // Number of OEM CPE Driver Dpc queueing failures. approx.
21527 ULONG CpeGetStateFails; // Number of failures in getting the log from FW.
21528 ULONG CpeClearStateFails; // Number of failures in clearing the log from FW.
21529 ULONG CpeInterruptSources; // Number of SAPIC Platform Interrupt Sources
21530 ULONGLONG CpeLogId; // Last seen record identifier.
21531 ULONGLONG KernelReserved[4];
21532} HAL_ERROR_INFO, *PHAL_ERROR_INFO;
21533
21534
21535#define HAL_MCE_INTERRUPTS_BASED ((ULONG)-1)
21536#define HAL_MCE_DISABLED ((ULONG)0)
21537
21538//
21539// Known values for HAL_ERROR_INFO.CmcPollingInterval.
21540//
21541
21542#define HAL_CMC_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
21543#define HAL_CMC_DISABLED HAL_MCE_DISABLED
21544
21545//
21546// Known values for HAL_ERROR_INFO.CpePollingInterval.
21547//
21548
21549#define HAL_CPE_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
21550#define HAL_CPE_DISABLED HAL_MCE_DISABLED
21551
21552#define HAL_MCA_INTERRUPTS_BASED HAL_MCE_INTERRUPTS_BASED
21553#define HAL_MCA_DISABLED HAL_MCE_DISABLED
21554
21555
21556
21557//
21558// Driver Callback type for the information class "HalCmcRegisterDriver"
21559//
21560
21561typedef
21562VOID
21563(*PDRIVER_CMC_EXCEPTION_CALLBACK) (
21564 IN PVOID Context,
21565 IN PCMC_EXCEPTION CmcLog
21566);
21567
21568//
21569// Driver Callback type for the information class "HalCpeRegisterDriver"
21570//
21571
21572typedef
21573VOID
21574(*PDRIVER_CPE_EXCEPTION_CALLBACK) (
21575 IN PVOID Context,
21576 IN PCPE_EXCEPTION CmcLog
21577);
21578
21579//
21580//
21581// Structure to record the callbacks from driver
21582//
21583
21584typedef struct _CMC_DRIVER_INFO {
21585 PDRIVER_CMC_EXCEPTION_CALLBACK ExceptionCallback;
21586 PKDEFERRED_ROUTINE DpcCallback;
21587 PVOID DeviceContext;
21588} CMC_DRIVER_INFO, *PCMC_DRIVER_INFO;
21589
21590typedef struct _CPE_DRIVER_INFO {
21591 PDRIVER_CPE_EXCEPTION_CALLBACK ExceptionCallback;
21592 PKDEFERRED_ROUTINE DpcCallback;
21593 PVOID DeviceContext;
21594} CPE_DRIVER_INFO, *PCPE_DRIVER_INFO;
21595
21596#endif // defined(_X86_) || defined(_IA64_) || defined(_AMD64_)
21597
21598#if defined(_IA64_)
21599
21600typedef
21601NTSTATUS
21602(*HALSENDCROSSPARTITIONIPI)(
21603 IN USHORT ProcessorID,
21604 IN UCHAR HardwareVector
21605 );
21606
21607typedef
21608NTSTATUS
21609(*HALRESERVECROSSPARTITIONINTERRUPTVECTOR)(
21610 OUT PULONG Vector,
21611 OUT PKIRQL Irql,
21612 IN OUT PKAFFINITY Affinity,
21613 OUT PUCHAR HardwareVector
21614 );
21615
21616typedef struct _HAL_CROSS_PARTITION_IPI_INTERFACE {
21617 HALSENDCROSSPARTITIONIPI HalSendCrossPartitionIpi;
21618 HALRESERVECROSSPARTITIONINTERRUPTVECTOR HalReserveCrossPartitionInterruptVector;
21619} HAL_CROSS_PARTITION_IPI_INTERFACE;
21620
21621#endif
21622
21623typedef struct _HAL_PLATFORM_INFORMATION {
21624 ULONG PlatformFlags;
21625} HAL_PLATFORM_INFORMATION, *PHAL_PLATFORM_INFORMATION;
21626
21627//
21628// These platform flags are carried over from the IPPT table
21629// definition if appropriate.
21630//
21631
21632#define HAL_PLATFORM_DISABLE_WRITE_COMBINING 0x01L
21633#define HAL_PLATFORM_DISABLE_PTCG 0x04L
21634#define HAL_PLATFORM_DISABLE_UC_MAIN_MEMORY 0x08L
21635#define HAL_PLATFORM_ENABLE_WRITE_COMBINING_MMIO 0x10L
21636#define HAL_PLATFORM_ACPI_TABLES_CACHED 0x20L
21637
21638
21639
21640typedef struct _SCATTER_GATHER_ELEMENT {
21641 PHYSICAL_ADDRESS Address;
21642 ULONG Length;
21643 ULONG_PTR Reserved;
21644} SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
21645
21646#if _MSC_VER >= 1200
21647#pragma warning(push)
21648#endif
21649#pragma warning(disable:4200)
21650typedef struct _SCATTER_GATHER_LIST {
21651 ULONG NumberOfElements;
21652 ULONG_PTR Reserved;
21653 SCATTER_GATHER_ELEMENT Elements[];
21654} SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
21655#if _MSC_VER >= 1200
21656#pragma warning(pop)
21657#else
21658#pragma warning(default:4200)
21659#endif
21660
21661
21662
21663typedef struct _DMA_OPERATIONS *PDMA_OPERATIONS;
21664
21665typedef struct _DMA_ADAPTER {
21666 USHORT Version;
21667 USHORT Size;
21668 PDMA_OPERATIONS DmaOperations;
21669 // Private Bus Device Driver data follows,
21670} DMA_ADAPTER, *PDMA_ADAPTER;
21671
21672typedef VOID (*PPUT_DMA_ADAPTER)(
21673 PDMA_ADAPTER DmaAdapter
21674 );
21675
21676typedef PVOID (*PALLOCATE_COMMON_BUFFER)(
21677 IN PDMA_ADAPTER DmaAdapter,
21678 IN ULONG Length,
21679 OUT PPHYSICAL_ADDRESS LogicalAddress,
21680 IN BOOLEAN CacheEnabled
21681 );
21682
21683typedef VOID (*PFREE_COMMON_BUFFER)(
21684 IN PDMA_ADAPTER DmaAdapter,
21685 IN ULONG Length,
21686 IN PHYSICAL_ADDRESS LogicalAddress,
21687 IN PVOID VirtualAddress,
21688 IN BOOLEAN CacheEnabled
21689 );
21690
21691typedef NTSTATUS (*PALLOCATE_ADAPTER_CHANNEL)(
21692 IN PDMA_ADAPTER DmaAdapter,
21693 IN PDEVICE_OBJECT DeviceObject,
21694 IN ULONG NumberOfMapRegisters,
21695 IN PDRIVER_CONTROL ExecutionRoutine,
21696 IN PVOID Context
21697 );
21698
21699typedef BOOLEAN (*PFLUSH_ADAPTER_BUFFERS)(
21700 IN PDMA_ADAPTER DmaAdapter,
21701 IN PMDL Mdl,
21702 IN PVOID MapRegisterBase,
21703 IN PVOID CurrentVa,
21704 IN ULONG Length,
21705 IN BOOLEAN WriteToDevice
21706 );
21707
21708typedef VOID (*PFREE_ADAPTER_CHANNEL)(
21709 IN PDMA_ADAPTER DmaAdapter
21710 );
21711
21712typedef VOID (*PFREE_MAP_REGISTERS)(
21713 IN PDMA_ADAPTER DmaAdapter,
21714 PVOID MapRegisterBase,
21715 ULONG NumberOfMapRegisters
21716 );
21717
21718typedef PHYSICAL_ADDRESS (*PMAP_TRANSFER)(
21719 IN PDMA_ADAPTER DmaAdapter,
21720 IN PMDL Mdl,
21721 IN PVOID MapRegisterBase,
21722 IN PVOID CurrentVa,
21723 IN OUT PULONG Length,
21724 IN BOOLEAN WriteToDevice
21725 );
21726
21727typedef ULONG (*PGET_DMA_ALIGNMENT)(
21728 IN PDMA_ADAPTER DmaAdapter
21729 );
21730
21731typedef ULONG (*PREAD_DMA_COUNTER)(
21732 IN PDMA_ADAPTER DmaAdapter
21733 );
21734
21735typedef VOID
21736(*PDRIVER_LIST_CONTROL)(
21737 IN struct _DEVICE_OBJECT *DeviceObject,
21738 IN struct _IRP *Irp,
21739 IN PSCATTER_GATHER_LIST ScatterGather,
21740 IN PVOID Context
21741 );
21742
21743typedef NTSTATUS
21744(*PGET_SCATTER_GATHER_LIST)(
21745 IN PDMA_ADAPTER DmaAdapter,
21746 IN PDEVICE_OBJECT DeviceObject,
21747 IN PMDL Mdl,
21748 IN PVOID CurrentVa,
21749 IN ULONG Length,
21750 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
21751 IN PVOID Context,
21752 IN BOOLEAN WriteToDevice
21753 );
21754
21755typedef VOID
21756(*PPUT_SCATTER_GATHER_LIST)(
21757 IN PDMA_ADAPTER DmaAdapter,
21758 IN PSCATTER_GATHER_LIST ScatterGather,
21759 IN BOOLEAN WriteToDevice
21760 );
21761
21762typedef NTSTATUS
21763(*PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
21764 IN PDMA_ADAPTER DmaAdapter,
21765 IN OPTIONAL PMDL Mdl,
21766 IN PVOID CurrentVa,
21767 IN ULONG Length,
21768 OUT PULONG ScatterGatherListSize,
21769 OUT OPTIONAL PULONG pNumberOfMapRegisters
21770 );
21771
21772typedef NTSTATUS
21773(*PBUILD_SCATTER_GATHER_LIST)(
21774 IN PDMA_ADAPTER DmaAdapter,
21775 IN PDEVICE_OBJECT DeviceObject,
21776 IN PMDL Mdl,
21777 IN PVOID CurrentVa,
21778 IN ULONG Length,
21779 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
21780 IN PVOID Context,
21781 IN BOOLEAN WriteToDevice,
21782 IN PVOID ScatterGatherBuffer,
21783 IN ULONG ScatterGatherLength
21784 );
21785
21786typedef NTSTATUS
21787(*PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
21788 IN PDMA_ADAPTER DmaAdapter,
21789 IN PSCATTER_GATHER_LIST ScatterGather,
21790 IN PMDL OriginalMdl,
21791 OUT PMDL *TargetMdl
21792 );
21793
21794typedef struct _DMA_OPERATIONS {
21795 ULONG Size;
21796 PPUT_DMA_ADAPTER PutDmaAdapter;
21797 PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
21798 PFREE_COMMON_BUFFER FreeCommonBuffer;
21799 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
21800 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
21801 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
21802 PFREE_MAP_REGISTERS FreeMapRegisters;
21803 PMAP_TRANSFER MapTransfer;
21804 PGET_DMA_ALIGNMENT GetDmaAlignment;
21805 PREAD_DMA_COUNTER ReadDmaCounter;
21806 PGET_SCATTER_GATHER_LIST GetScatterGatherList;
21807 PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
21808 PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
21809 PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
21810 PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
21811} DMA_OPERATIONS;
21812
21813
21814
21815
21816#if defined(_WIN64)
21817
21818//
21819// Use __inline DMA macros (hal.h)
21820//
21821#ifndef USE_DMA_MACROS
21822#define USE_DMA_MACROS
21823#endif
21824
21825//
21826// Only PnP drivers!
21827//
21828#ifndef NO_LEGACY_DRIVERS
21829#define NO_LEGACY_DRIVERS
21830#endif
21831
21832#endif // _WIN64
21833
21834
21835#if defined(USE_DMA_MACROS) && (defined(_NTDDK_) || defined(_NTDRIVER_))
21836
21837
21838
21839DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
21840FORCEINLINE
21841PVOID
21842HalAllocateCommonBuffer(
21843 IN PDMA_ADAPTER DmaAdapter,
21844 IN ULONG Length,
21845 OUT PPHYSICAL_ADDRESS LogicalAddress,
21846 IN BOOLEAN CacheEnabled
21847 ){
21848
21849 PALLOCATE_COMMON_BUFFER allocateCommonBuffer;
21850 PVOID commonBuffer;
21851
21852 allocateCommonBuffer = *(DmaAdapter)->DmaOperations->AllocateCommonBuffer;
21853 ASSERT( allocateCommonBuffer != NULL );
21854
21855 commonBuffer = allocateCommonBuffer( DmaAdapter,
21856 Length,
21857 LogicalAddress,
21858 CacheEnabled );
21859
21860 return commonBuffer;
21861}
21862
21863DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
21864FORCEINLINE
21865VOID
21866HalFreeCommonBuffer(
21867 IN PDMA_ADAPTER DmaAdapter,
21868 IN ULONG Length,
21869 IN PHYSICAL_ADDRESS LogicalAddress,
21870 IN PVOID VirtualAddress,
21871 IN BOOLEAN CacheEnabled
21872 ){
21873
21874 PFREE_COMMON_BUFFER freeCommonBuffer;
21875
21876 freeCommonBuffer = *(DmaAdapter)->DmaOperations->FreeCommonBuffer;
21877 ASSERT( freeCommonBuffer != NULL );
21878
21879 freeCommonBuffer( DmaAdapter,
21880 Length,
21881 LogicalAddress,
21882 VirtualAddress,
21883 CacheEnabled );
21884}
21885
21886DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
21887FORCEINLINE
21888NTSTATUS
21889IoAllocateAdapterChannel(
21890 IN PDMA_ADAPTER DmaAdapter,
21891 IN PDEVICE_OBJECT DeviceObject,
21892 IN ULONG NumberOfMapRegisters,
21893 IN PDRIVER_CONTROL ExecutionRoutine,
21894 IN PVOID Context
21895 ){
21896
21897 PALLOCATE_ADAPTER_CHANNEL allocateAdapterChannel;
21898 NTSTATUS status;
21899
21900 allocateAdapterChannel =
21901 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
21902
21903 ASSERT( allocateAdapterChannel != NULL );
21904
21905 status = allocateAdapterChannel( DmaAdapter,
21906 DeviceObject,
21907 NumberOfMapRegisters,
21908 ExecutionRoutine,
21909 Context );
21910
21911 return status;
21912}
21913
21914DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
21915FORCEINLINE
21916BOOLEAN
21917IoFlushAdapterBuffers(
21918 IN PDMA_ADAPTER DmaAdapter,
21919 IN PMDL Mdl,
21920 IN PVOID MapRegisterBase,
21921 IN PVOID CurrentVa,
21922 IN ULONG Length,
21923 IN BOOLEAN WriteToDevice
21924 ){
21925
21926 PFLUSH_ADAPTER_BUFFERS flushAdapterBuffers;
21927 BOOLEAN result;
21928
21929 flushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
21930 ASSERT( flushAdapterBuffers != NULL );
21931
21932 result = flushAdapterBuffers( DmaAdapter,
21933 Mdl,
21934 MapRegisterBase,
21935 CurrentVa,
21936 Length,
21937 WriteToDevice );
21938 return result;
21939}
21940
21941DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
21942FORCEINLINE
21943VOID
21944IoFreeAdapterChannel(
21945 IN PDMA_ADAPTER DmaAdapter
21946 ){
21947
21948 PFREE_ADAPTER_CHANNEL freeAdapterChannel;
21949
21950 freeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
21951 ASSERT( freeAdapterChannel != NULL );
21952
21953 freeAdapterChannel( DmaAdapter );
21954}
21955
21956DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
21957FORCEINLINE
21958VOID
21959IoFreeMapRegisters(
21960 IN PDMA_ADAPTER DmaAdapter,
21961 IN PVOID MapRegisterBase,
21962 IN ULONG NumberOfMapRegisters
21963 ){
21964
21965 PFREE_MAP_REGISTERS freeMapRegisters;
21966
21967 freeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
21968 ASSERT( freeMapRegisters != NULL );
21969
21970 freeMapRegisters( DmaAdapter,
21971 MapRegisterBase,
21972 NumberOfMapRegisters );
21973}
21974
21975
21976DECLSPEC_DEPRECATED_DDK // Use MapTransfer
21977FORCEINLINE
21978PHYSICAL_ADDRESS
21979IoMapTransfer(
21980 IN PDMA_ADAPTER DmaAdapter,
21981 IN PMDL Mdl,
21982 IN PVOID MapRegisterBase,
21983 IN PVOID CurrentVa,
21984 IN OUT PULONG Length,
21985 IN BOOLEAN WriteToDevice
21986 ){
21987
21988 PHYSICAL_ADDRESS physicalAddress;
21989 PMAP_TRANSFER mapTransfer;
21990
21991 mapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
21992 ASSERT( mapTransfer != NULL );
21993
21994 physicalAddress = mapTransfer( DmaAdapter,
21995 Mdl,
21996 MapRegisterBase,
21997 CurrentVa,
21998 Length,
21999 WriteToDevice );
22000
22001 return physicalAddress;
22002}
22003
22004DECLSPEC_DEPRECATED_DDK // Use GetDmaAlignment
22005FORCEINLINE
22006ULONG
22007HalGetDmaAlignment(
22008 IN PDMA_ADAPTER DmaAdapter
22009 )
22010{
22011 PGET_DMA_ALIGNMENT getDmaAlignment;
22012 ULONG alignment;
22013
22014 getDmaAlignment = *(DmaAdapter)->DmaOperations->GetDmaAlignment;
22015 ASSERT( getDmaAlignment != NULL );
22016
22017 alignment = getDmaAlignment( DmaAdapter );
22018 return alignment;
22019}
22020
22021DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
22022FORCEINLINE
22023ULONG
22024HalReadDmaCounter(
22025 IN PDMA_ADAPTER DmaAdapter
22026 )
22027{
22028 PREAD_DMA_COUNTER readDmaCounter;
22029 ULONG counter;
22030
22031 readDmaCounter = *(DmaAdapter)->DmaOperations->ReadDmaCounter;
22032 ASSERT( readDmaCounter != NULL );
22033
22034 counter = readDmaCounter( DmaAdapter );
22035 return counter;
22036}
22037
22038
22039
22040#else
22041
22042//
22043// DMA adapter object functions.
22044//
22045DECLSPEC_DEPRECATED_DDK // Use AllocateAdapterChannel
22046NTHALAPI
22047NTSTATUS
22048HalAllocateAdapterChannel(
22049 IN PADAPTER_OBJECT AdapterObject,
22050 IN PWAIT_CONTEXT_BLOCK Wcb,
22051 IN ULONG NumberOfMapRegisters,
22052 IN PDRIVER_CONTROL ExecutionRoutine
22053 );
22054
22055DECLSPEC_DEPRECATED_DDK // Use AllocateCommonBuffer
22056NTHALAPI
22057PVOID
22058HalAllocateCommonBuffer(
22059 IN PADAPTER_OBJECT AdapterObject,
22060 IN ULONG Length,
22061 OUT PPHYSICAL_ADDRESS LogicalAddress,
22062 IN BOOLEAN CacheEnabled
22063 );
22064
22065DECLSPEC_DEPRECATED_DDK // Use FreeCommonBuffer
22066NTHALAPI
22067VOID
22068HalFreeCommonBuffer(
22069 IN PADAPTER_OBJECT AdapterObject,
22070 IN ULONG Length,
22071 IN PHYSICAL_ADDRESS LogicalAddress,
22072 IN PVOID VirtualAddress,
22073 IN BOOLEAN CacheEnabled
22074 );
22075
22076DECLSPEC_DEPRECATED_DDK // Use ReadDmaCounter
22077NTHALAPI
22078ULONG
22079HalReadDmaCounter(
22080 IN PADAPTER_OBJECT AdapterObject
22081 );
22082
22083DECLSPEC_DEPRECATED_DDK // Use FlushAdapterBuffers
22084NTHALAPI
22085BOOLEAN
22086IoFlushAdapterBuffers(
22087 IN PADAPTER_OBJECT AdapterObject,
22088 IN PMDL Mdl,
22089 IN PVOID MapRegisterBase,
22090 IN PVOID CurrentVa,
22091 IN ULONG Length,
22092 IN BOOLEAN WriteToDevice
22093 );
22094
22095DECLSPEC_DEPRECATED_DDK // Use FreeAdapterChannel
22096NTHALAPI
22097VOID
22098IoFreeAdapterChannel(
22099 IN PADAPTER_OBJECT AdapterObject
22100 );
22101
22102DECLSPEC_DEPRECATED_DDK // Use FreeMapRegisters
22103NTHALAPI
22104VOID
22105IoFreeMapRegisters(
22106 IN PADAPTER_OBJECT AdapterObject,
22107 IN PVOID MapRegisterBase,
22108 IN ULONG NumberOfMapRegisters
22109 );
22110
22111DECLSPEC_DEPRECATED_DDK // Use MapTransfer
22112NTHALAPI
22113PHYSICAL_ADDRESS
22114IoMapTransfer(
22115 IN PADAPTER_OBJECT AdapterObject,
22116 IN PMDL Mdl,
22117 IN PVOID MapRegisterBase,
22118 IN PVOID CurrentVa,
22119 IN OUT PULONG Length,
22120 IN BOOLEAN WriteToDevice
22121 );
22122#endif // USE_DMA_MACROS && (_NTDDK_ || _NTDRIVER_)
22123
22124DECLSPEC_DEPRECATED_DDK
22125NTSTATUS
22126HalGetScatterGatherList ( // Use GetScatterGatherList
22127 IN PADAPTER_OBJECT DmaAdapter,
22128 IN PDEVICE_OBJECT DeviceObject,
22129 IN PMDL Mdl,
22130 IN PVOID CurrentVa,
22131 IN ULONG Length,
22132 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
22133 IN PVOID Context,
22134 IN BOOLEAN WriteToDevice
22135 );
22136
22137DECLSPEC_DEPRECATED_DDK // Use PutScatterGatherList
22138VOID
22139HalPutScatterGatherList (
22140 IN PADAPTER_OBJECT DmaAdapter,
22141 IN PSCATTER_GATHER_LIST ScatterGather,
22142 IN BOOLEAN WriteToDevice
22143 );
22144
22145DECLSPEC_DEPRECATED_DDK // Use PutDmaAdapter
22146VOID
22147HalPutDmaAdapter(
22148 IN PADAPTER_OBJECT DmaAdapter
22149 );
22150
22151
22152NTKERNELAPI
22153VOID
22154PoSetSystemState (
22155 IN EXECUTION_STATE Flags
22156 );
22157
22158
22159
22160NTKERNELAPI
22161PVOID
22162PoRegisterSystemState (
22163 IN PVOID StateHandle,
22164 IN EXECUTION_STATE Flags
22165 );
22166
22167
22168
22169typedef
22170VOID
22171(*PREQUEST_POWER_COMPLETE) (
22172 IN PDEVICE_OBJECT DeviceObject,
22173 IN UCHAR MinorFunction,
22174 IN POWER_STATE PowerState,
22175 IN PVOID Context,
22176 IN PIO_STATUS_BLOCK IoStatus
22177 );
22178
22179NTKERNELAPI
22180NTSTATUS
22181PoRequestPowerIrp (
22182 IN PDEVICE_OBJECT DeviceObject,
22183 IN UCHAR MinorFunction,
22184 IN POWER_STATE PowerState,
22185 IN PREQUEST_POWER_COMPLETE CompletionFunction,
22186 IN PVOID Context,
22187 OUT PIRP *Irp OPTIONAL
22188 );
22189
22190NTKERNELAPI
22191NTSTATUS
22192PoRequestShutdownEvent (
22193 OUT PVOID *Event
22194 );
22195
22196NTKERNELAPI
22197NTSTATUS
22198PoRequestShutdownWait (
22199 IN PETHREAD Thread
22200 );
22201
22202
22203
22204NTKERNELAPI
22205VOID
22206PoUnregisterSystemState (
22207 IN PVOID StateHandle
22208 );
22209
22210
22211
22212NTKERNELAPI
22213POWER_STATE
22214PoSetPowerState (
22215 IN PDEVICE_OBJECT DeviceObject,
22216 IN POWER_STATE_TYPE Type,
22217 IN POWER_STATE State
22218 );
22219
22220NTKERNELAPI
22221NTSTATUS
22222PoCallDriver (
22223 IN PDEVICE_OBJECT DeviceObject,
22224 IN OUT PIRP Irp
22225 );
22226
22227NTKERNELAPI
22228VOID
22229PoStartNextPowerIrp(
22230 IN PIRP Irp
22231 );
22232
22233
22234NTKERNELAPI
22235PULONG
22236PoRegisterDeviceForIdleDetection (
22237 IN PDEVICE_OBJECT DeviceObject,
22238 IN ULONG ConservationIdleTime,
22239 IN ULONG PerformanceIdleTime,
22240 IN DEVICE_POWER_STATE State
22241 );
22242
22243#define PoSetDeviceBusy(IdlePointer) \
22244 *IdlePointer = 0
22245
22246//
22247// \Callback\PowerState values
22248//
22249
22250#define PO_CB_SYSTEM_POWER_POLICY 0
22251#define PO_CB_AC_STATUS 1
22252#define PO_CB_BUTTON_COLLISION 2
22253#define PO_CB_SYSTEM_STATE_LOCK 3
22254#define PO_CB_LID_SWITCH_STATE 4
22255#define PO_CB_PROCESSOR_POWER_POLICY 5
22256
22257//
22258// Determine if there is a complete device failure on an error.
22259//
22260
22261NTKERNELAPI
22262BOOLEAN
22263FsRtlIsTotalDeviceFailure(
22264 IN NTSTATUS Status
22265 );
22266
22267//
22268// Object Manager types
22269//
22270
22271typedef struct _OBJECT_HANDLE_INFORMATION {
22272 ULONG HandleAttributes;
22273 ACCESS_MASK GrantedAccess;
22274} OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
22275
22276NTKERNELAPI
22277NTSTATUS
22278ObReferenceObjectByHandle(
22279 IN HANDLE Handle,
22280 IN ACCESS_MASK DesiredAccess,
22281 IN POBJECT_TYPE ObjectType OPTIONAL,
22282 IN KPROCESSOR_MODE AccessMode,
22283 OUT PVOID *Object,
22284 OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL
22285 );
22286
22287#define ObDereferenceObject(a) \
22288 ObfDereferenceObject(a)
22289
22290#define ObReferenceObject(Object) ObfReferenceObject(Object)
22291
22292NTKERNELAPI
22293LONG_PTR
22294FASTCALL
22295ObfReferenceObject(
22296 IN PVOID Object
22297 );
22298
22299NTKERNELAPI
22300NTSTATUS
22301ObReferenceObjectByPointer(
22302 IN PVOID Object,
22303 IN ACCESS_MASK DesiredAccess,
22304 IN POBJECT_TYPE ObjectType,
22305 IN KPROCESSOR_MODE AccessMode
22306 );
22307
22308NTKERNELAPI
22309LONG_PTR
22310FASTCALL
22311ObfDereferenceObject(
22312 IN PVOID Object
22313 );
22314
22315NTSTATUS
22316ObGetObjectSecurity(
22317 IN PVOID Object,
22318 OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
22319 OUT PBOOLEAN MemoryAllocated
22320 );
22321
22322VOID
22323ObReleaseObjectSecurity(
22324 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
22325 IN BOOLEAN MemoryAllocated
22326 );
22327
22328//
22329// A PCI driver can read the complete 256 bytes of configuration
22330// information for any PCI device by calling:
22331//
22332// ULONG
22333// HalGetBusData (
22334// IN BUS_DATA_TYPE PCIConfiguration,
22335// IN ULONG PciBusNumber,
22336// IN PCI_SLOT_NUMBER VirtualSlotNumber,
22337// IN PPCI_COMMON_CONFIG &PCIDeviceConfig,
22338// IN ULONG sizeof (PCIDeviceConfig)
22339// );
22340//
22341// A return value of 0 means that the specified PCI bus does not exist.
22342//
22343// A return value of 2, with a VendorID of PCI_INVALID_VENDORID means
22344// that the PCI bus does exist, but there is no device at the specified
22345// VirtualSlotNumber (PCI Device/Function number).
22346//
22347//
22348
22349
22350
22351typedef struct _PCI_SLOT_NUMBER {
22352 union {
22353 struct {
22354 ULONG DeviceNumber:5;
22355 ULONG FunctionNumber:3;
22356 ULONG Reserved:24;
22357 } bits;
22358 ULONG AsULONG;
22359 } u;
22360} PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
22361
22362
22363#define PCI_TYPE0_ADDRESSES 6
22364#define PCI_TYPE1_ADDRESSES 2
22365#define PCI_TYPE2_ADDRESSES 5
22366
22367typedef struct _PCI_COMMON_CONFIG {
22368 USHORT VendorID; // (ro)
22369 USHORT DeviceID; // (ro)
22370 USHORT Command; // Device control
22371 USHORT Status;
22372 UCHAR RevisionID; // (ro)
22373 UCHAR ProgIf; // (ro)
22374 UCHAR SubClass; // (ro)
22375 UCHAR BaseClass; // (ro)
22376 UCHAR CacheLineSize; // (ro+)
22377 UCHAR LatencyTimer; // (ro+)
22378 UCHAR HeaderType; // (ro)
22379 UCHAR BIST; // Built in self test
22380
22381 union {
22382 struct _PCI_HEADER_TYPE_0 {
22383 ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
22384 ULONG CIS;
22385 USHORT SubVendorID;
22386 USHORT SubSystemID;
22387 ULONG ROMBaseAddress;
22388 UCHAR CapabilitiesPtr;
22389 UCHAR Reserved1[3];
22390 ULONG Reserved2;
22391 UCHAR InterruptLine; //
22392 UCHAR InterruptPin; // (ro)
22393 UCHAR MinimumGrant; // (ro)
22394 UCHAR MaximumLatency; // (ro)
22395 } type0;
22396
22397
22398
22399 //
22400 // PCI to PCI Bridge
22401 //
22402
22403 struct _PCI_HEADER_TYPE_1 {
22404 ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
22405 UCHAR PrimaryBus;
22406 UCHAR SecondaryBus;
22407 UCHAR SubordinateBus;
22408 UCHAR SecondaryLatency;
22409 UCHAR IOBase;
22410 UCHAR IOLimit;
22411 USHORT SecondaryStatus;
22412 USHORT MemoryBase;
22413 USHORT MemoryLimit;
22414 USHORT PrefetchBase;
22415 USHORT PrefetchLimit;
22416 ULONG PrefetchBaseUpper32;
22417 ULONG PrefetchLimitUpper32;
22418 USHORT IOBaseUpper16;
22419 USHORT IOLimitUpper16;
22420 UCHAR CapabilitiesPtr;
22421 UCHAR Reserved1[3];
22422 ULONG ROMBaseAddress;
22423 UCHAR InterruptLine;
22424 UCHAR InterruptPin;
22425 USHORT BridgeControl;
22426 } type1;
22427
22428 //
22429 // PCI to CARDBUS Bridge
22430 //
22431
22432 struct _PCI_HEADER_TYPE_2 {
22433 ULONG SocketRegistersBaseAddress;
22434 UCHAR CapabilitiesPtr;
22435 UCHAR Reserved;
22436 USHORT SecondaryStatus;
22437 UCHAR PrimaryBus;
22438 UCHAR SecondaryBus;
22439 UCHAR SubordinateBus;
22440 UCHAR SecondaryLatency;
22441 struct {
22442 ULONG Base;
22443 ULONG Limit;
22444 } Range[PCI_TYPE2_ADDRESSES-1];
22445 UCHAR InterruptLine;
22446 UCHAR InterruptPin;
22447 USHORT BridgeControl;
22448 } type2;
22449
22450
22451
22452 } u;
22453
22454 UCHAR DeviceSpecific[192];
22455
22456} PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
22457
22458
22459#define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET (PCI_COMMON_CONFIG, DeviceSpecific))
22460
22461#define PCI_MAX_DEVICES 32
22462#define PCI_MAX_FUNCTION 8
22463#define PCI_MAX_BRIDGE_NUMBER 0xFF
22464
22465#define PCI_INVALID_VENDORID 0xFFFF
22466
22467//
22468// Bit encodings for PCI_COMMON_CONFIG.HeaderType
22469//
22470
22471#define PCI_MULTIFUNCTION 0x80
22472#define PCI_DEVICE_TYPE 0x00
22473#define PCI_BRIDGE_TYPE 0x01
22474#define PCI_CARDBUS_BRIDGE_TYPE 0x02
22475
22476#define PCI_CONFIGURATION_TYPE(PciData) \
22477 (((PPCI_COMMON_CONFIG)(PciData))->HeaderType & ~PCI_MULTIFUNCTION)
22478
22479#define PCI_MULTIFUNCTION_DEVICE(PciData) \
22480 ((((PPCI_COMMON_CONFIG)(PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
22481
22482//
22483// Bit encodings for PCI_COMMON_CONFIG.Command
22484//
22485
22486#define PCI_ENABLE_IO_SPACE 0x0001
22487#define PCI_ENABLE_MEMORY_SPACE 0x0002
22488#define PCI_ENABLE_BUS_MASTER 0x0004
22489#define PCI_ENABLE_SPECIAL_CYCLES 0x0008
22490#define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
22491#define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
22492#define PCI_ENABLE_PARITY 0x0040 // (ro+)
22493#define PCI_ENABLE_WAIT_CYCLE 0x0080 // (ro+)
22494#define PCI_ENABLE_SERR 0x0100 // (ro+)
22495#define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200 // (ro)
22496
22497//
22498// Bit encodings for PCI_COMMON_CONFIG.Status
22499//
22500
22501#define PCI_STATUS_CAPABILITIES_LIST 0x0010 // (ro)
22502#define PCI_STATUS_66MHZ_CAPABLE 0x0020 // (ro)
22503#define PCI_STATUS_UDF_SUPPORTED 0x0040 // (ro)
22504#define PCI_STATUS_FAST_BACK_TO_BACK 0x0080 // (ro)
22505#define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
22506#define PCI_STATUS_DEVSEL 0x0600 // 2 bits wide
22507#define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
22508#define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
22509#define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
22510#define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
22511#define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
22512
22513//
22514// The NT PCI Driver uses a WhichSpace parameter on its CONFIG_READ/WRITE
22515// routines. The following values are defined-
22516//
22517
22518#define PCI_WHICHSPACE_CONFIG 0x0
22519#define PCI_WHICHSPACE_ROM 0x52696350
22520
22521
22522//
22523// PCI Capability IDs
22524//
22525
22526#define PCI_CAPABILITY_ID_POWER_MANAGEMENT 0x01
22527#define PCI_CAPABILITY_ID_AGP 0x02
22528#define PCI_CAPABILITY_ID_MSI 0x05
22529#define PCI_CAPABILITY_ID_AGP_TARGET 0x0E
22530
22531//
22532// All PCI Capability structures have the following header.
22533//
22534// CapabilityID is used to identify the type of the structure (is
22535// one of the PCI_CAPABILITY_ID values above.
22536//
22537// Next is the offset in PCI Configuration space (0x40 - 0xfc) of the
22538// next capability structure in the list, or 0x00 if there are no more
22539// entries.
22540//
22541typedef struct _PCI_CAPABILITIES_HEADER {
22542 UCHAR CapabilityID;
22543 UCHAR Next;
22544} PCI_CAPABILITIES_HEADER, *PPCI_CAPABILITIES_HEADER;
22545
22546//
22547// Power Management Capability
22548//
22549
22550typedef struct _PCI_PMC {
22551 UCHAR Version:3;
22552 UCHAR PMEClock:1;
22553 UCHAR Rsvd1:1;
22554 UCHAR DeviceSpecificInitialization:1;
22555 UCHAR Rsvd2:2;
22556 struct _PM_SUPPORT {
22557 UCHAR Rsvd2:1;
22558 UCHAR D1:1;
22559 UCHAR D2:1;
22560 UCHAR PMED0:1;
22561 UCHAR PMED1:1;
22562 UCHAR PMED2:1;
22563 UCHAR PMED3Hot:1;
22564 UCHAR PMED3Cold:1;
22565 } Support;
22566} PCI_PMC, *PPCI_PMC;
22567
22568typedef struct _PCI_PMCSR {
22569 USHORT PowerState:2;
22570 USHORT Rsvd1:6;
22571 USHORT PMEEnable:1;
22572 USHORT DataSelect:4;
22573 USHORT DataScale:2;
22574 USHORT PMEStatus:1;
22575} PCI_PMCSR, *PPCI_PMCSR;
22576
22577
22578typedef struct _PCI_PMCSR_BSE {
22579 UCHAR Rsvd1:6;
22580 UCHAR D3HotSupportsStopClock:1; // B2_B3#
22581 UCHAR BusPowerClockControlEnabled:1; // BPCC_EN
22582} PCI_PMCSR_BSE, *PPCI_PMCSR_BSE;
22583
22584
22585typedef struct _PCI_PM_CAPABILITY {
22586
22587 PCI_CAPABILITIES_HEADER Header;
22588
22589 //
22590 // Power Management Capabilities (Offset = 2)
22591 //
22592
22593 union {
22594 PCI_PMC Capabilities;
22595 USHORT AsUSHORT;
22596 } PMC;
22597
22598 //
22599 // Power Management Control/Status (Offset = 4)
22600 //
22601
22602 union {
22603 PCI_PMCSR ControlStatus;
22604 USHORT AsUSHORT;
22605 } PMCSR;
22606
22607 //
22608 // PMCSR PCI-PCI Bridge Support Extensions
22609 //
22610
22611 union {
22612 PCI_PMCSR_BSE BridgeSupport;
22613 UCHAR AsUCHAR;
22614 } PMCSR_BSE;
22615
22616 //
22617 // Optional read only 8 bit Data register. Contents controlled by
22618 // DataSelect and DataScale in ControlStatus.
22619 //
22620
22621 UCHAR Data;
22622
22623} PCI_PM_CAPABILITY, *PPCI_PM_CAPABILITY;
22624
22625//
22626// AGP Capability
22627//
22628typedef struct _PCI_AGP_CAPABILITY {
22629
22630 PCI_CAPABILITIES_HEADER Header;
22631
22632 USHORT Minor:4;
22633 USHORT Major:4;
22634 USHORT Rsvd1:8;
22635
22636 struct _PCI_AGP_STATUS {
22637 ULONG Rate:3;
22638 ULONG Agp3Mode:1;
22639 ULONG FastWrite:1;
22640 ULONG FourGB:1;
22641 ULONG HostTransDisable:1;
22642 ULONG Gart64:1;
22643 ULONG ITA_Coherent:1;
22644 ULONG SideBandAddressing:1; // SBA
22645 ULONG CalibrationCycle:3;
22646 ULONG AsyncRequestSize:3;
22647 ULONG Rsvd1:1;
22648 ULONG Isoch:1;
22649 ULONG Rsvd2:6;
22650 ULONG RequestQueueDepthMaximum:8; // RQ
22651 } AGPStatus;
22652
22653 struct _PCI_AGP_COMMAND {
22654 ULONG Rate:3;
22655 ULONG Rsvd1:1;
22656 ULONG FastWriteEnable:1;
22657 ULONG FourGBEnable:1;
22658 ULONG Rsvd2:1;
22659 ULONG Gart64:1;
22660 ULONG AGPEnable:1;
22661 ULONG SBAEnable:1;
22662 ULONG CalibrationCycle:3;
22663 ULONG AsyncReqSize:3;
22664 ULONG Rsvd3:8;
22665 ULONG RequestQueueDepth:8;
22666 } AGPCommand;
22667
22668} PCI_AGP_CAPABILITY, *PPCI_AGP_CAPABILITY;
22669
22670//
22671// An AGPv3 Target must have an extended capability,
22672// but it's only present for a Master when the Isoch
22673// bit is set in its status register
22674//
22675typedef enum _EXTENDED_AGP_REGISTER {
22676 IsochStatus,
22677 AgpControl,
22678 ApertureSize,
22679 AperturePageSize,
22680 GartLow,
22681 GartHigh,
22682 IsochCommand
22683} EXTENDED_AGP_REGISTER, *PEXTENDED_AGP_REGISTER;
22684
22685typedef struct _PCI_AGP_ISOCH_STATUS {
22686 ULONG ErrorCode: 2;
22687 ULONG Rsvd1: 1;
22688 ULONG Isoch_L: 3;
22689 ULONG Isoch_Y: 2;
22690 ULONG Isoch_N: 8;
22691 ULONG Rsvd2: 16;
22692} PCI_AGP_ISOCH_STATUS, *PPCI_AGP_ISOCH_STATUS;
22693
22694typedef struct _PCI_AGP_CONTROL {
22695 ULONG Rsvd1: 7;
22696 ULONG GTLB_Enable: 1;
22697 ULONG AP_Enable: 1;
22698 ULONG CAL_Disable: 1;
22699 ULONG Rsvd2: 22;
22700} PCI_AGP_CONTROL, *PPCI_AGP_CONTROL;
22701
22702typedef struct _PCI_AGP_APERTURE_PAGE_SIZE {
22703 USHORT PageSizeMask: 11;
22704 USHORT Rsvd1: 1;
22705 USHORT PageSizeSelect: 4;
22706} PCI_AGP_APERTURE_PAGE_SIZE, *PPCI_AGP_APERTURE_PAGE_SIZE;
22707
22708typedef struct _PCI_AGP_ISOCH_COMMAND {
22709 USHORT Rsvd1: 6;
22710 USHORT Isoch_Y: 2;
22711 USHORT Isoch_N: 8;
22712} PCI_AGP_ISOCH_COMMAND, *PPCI_AGP_ISOCH_COMMAND;
22713
22714typedef struct PCI_AGP_EXTENDED_CAPABILITY {
22715
22716 PCI_AGP_ISOCH_STATUS IsochStatus;
22717
22718//
22719// Target only ----------------<<-begin->>
22720//
22721 PCI_AGP_CONTROL AgpControl;
22722 USHORT ApertureSize;
22723 PCI_AGP_APERTURE_PAGE_SIZE AperturePageSize;
22724 ULONG GartLow;
22725 ULONG GartHigh;
22726//
22727// ------------------------------<<-end->>
22728//
22729
22730 PCI_AGP_ISOCH_COMMAND IsochCommand;
22731
22732} PCI_AGP_EXTENDED_CAPABILITY, *PPCI_AGP_EXTENDED_CAPABILITY;
22733
22734
22735#define PCI_AGP_RATE_1X 0x1
22736#define PCI_AGP_RATE_2X 0x2
22737#define PCI_AGP_RATE_4X 0x4
22738
22739//
22740// MSI (Message Signalled Interrupts) Capability
22741//
22742
22743typedef struct _PCI_MSI_CAPABILITY {
22744
22745 PCI_CAPABILITIES_HEADER Header;
22746
22747 struct _PCI_MSI_MESSAGE_CONTROL {
22748 USHORT MSIEnable:1;
22749 USHORT MultipleMessageCapable:3;
22750 USHORT MultipleMessageEnable:3;
22751 USHORT CapableOf64Bits:1;
22752 USHORT Reserved:8;
22753 } MessageControl;
22754
22755 union {
22756 struct _PCI_MSI_MESSAGE_ADDRESS {
22757 ULONG_PTR Reserved:2; // always zero, DWORD aligned address
22758 ULONG_PTR Address:30;
22759 } Register;
22760 ULONG_PTR Raw;
22761 } MessageAddress;
22762
22763 //
22764 // The rest of the Capability structure differs depending on whether
22765 // 32bit or 64bit addressing is being used.
22766 //
22767 // (The CapableOf64Bits bit above determines this)
22768 //
22769
22770 union {
22771
22772 // For 64 bit devices
22773
22774 struct _PCI_MSI_64BIT_DATA {
22775 ULONG MessageUpperAddress;
22776 USHORT MessageData;
22777 } Bit64;
22778
22779 // For 32 bit devices
22780
22781 struct _PCI_MSI_32BIT_DATA {
22782 USHORT MessageData;
22783 ULONG Unused;
22784 } Bit32;
22785 } Data;
22786
22787} PCI_MSI_CAPABILITY, *PPCI_PCI_CAPABILITY;
22788
22789
22790//
22791// Base Class Code encodings for Base Class (from PCI spec rev 2.1).
22792//
22793
22794#define PCI_CLASS_PRE_20 0x00
22795#define PCI_CLASS_MASS_STORAGE_CTLR 0x01
22796#define PCI_CLASS_NETWORK_CTLR 0x02
22797#define PCI_CLASS_DISPLAY_CTLR 0x03
22798#define PCI_CLASS_MULTIMEDIA_DEV 0x04
22799#define PCI_CLASS_MEMORY_CTLR 0x05
22800#define PCI_CLASS_BRIDGE_DEV 0x06
22801#define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
22802#define PCI_CLASS_BASE_SYSTEM_DEV 0x08
22803#define PCI_CLASS_INPUT_DEV 0x09
22804#define PCI_CLASS_DOCKING_STATION 0x0a
22805#define PCI_CLASS_PROCESSOR 0x0b
22806#define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
22807#define PCI_CLASS_WIRELESS_CTLR 0x0d
22808#define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
22809#define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
22810#define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
22811#define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
22812
22813// 0d thru fe reserved
22814
22815#define PCI_CLASS_NOT_DEFINED 0xff
22816
22817//
22818// Sub Class Code encodings (PCI rev 2.1).
22819//
22820
22821// Class 00 - PCI_CLASS_PRE_20
22822
22823#define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
22824#define PCI_SUBCLASS_PRE_20_VGA 0x01
22825
22826// Class 01 - PCI_CLASS_MASS_STORAGE_CTLR
22827
22828#define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
22829#define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
22830#define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
22831#define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
22832#define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
22833#define PCI_SUBCLASS_MSC_OTHER 0x80
22834
22835// Class 02 - PCI_CLASS_NETWORK_CTLR
22836
22837#define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
22838#define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
22839#define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
22840#define PCI_SUBCLASS_NET_ATM_CTLR 0x03
22841#define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
22842#define PCI_SUBCLASS_NET_OTHER 0x80
22843
22844// Class 03 - PCI_CLASS_DISPLAY_CTLR
22845
22846// N.B. Sub Class 00 could be VGA or 8514 depending on Interface byte
22847
22848#define PCI_SUBCLASS_VID_VGA_CTLR 0x00
22849#define PCI_SUBCLASS_VID_XGA_CTLR 0x01
22850#define PCI_SUBLCASS_VID_3D_CTLR 0x02
22851#define PCI_SUBCLASS_VID_OTHER 0x80
22852
22853// Class 04 - PCI_CLASS_MULTIMEDIA_DEV
22854
22855#define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
22856#define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
22857#define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
22858#define PCI_SUBCLASS_MM_OTHER 0x80
22859
22860// Class 05 - PCI_CLASS_MEMORY_CTLR
22861
22862#define PCI_SUBCLASS_MEM_RAM 0x00
22863#define PCI_SUBCLASS_MEM_FLASH 0x01
22864#define PCI_SUBCLASS_MEM_OTHER 0x80
22865
22866// Class 06 - PCI_CLASS_BRIDGE_DEV
22867
22868#define PCI_SUBCLASS_BR_HOST 0x00
22869#define PCI_SUBCLASS_BR_ISA 0x01
22870#define PCI_SUBCLASS_BR_EISA 0x02
22871#define PCI_SUBCLASS_BR_MCA 0x03
22872#define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
22873#define PCI_SUBCLASS_BR_PCMCIA 0x05
22874#define PCI_SUBCLASS_BR_NUBUS 0x06
22875#define PCI_SUBCLASS_BR_CARDBUS 0x07
22876#define PCI_SUBCLASS_BR_RACEWAY 0x08
22877#define PCI_SUBCLASS_BR_OTHER 0x80
22878
22879// Class 07 - PCI_CLASS_SIMPLE_COMMS_CTLR
22880
22881// N.B. Sub Class 00 and 01 additional info in Interface byte
22882
22883#define PCI_SUBCLASS_COM_SERIAL 0x00
22884#define PCI_SUBCLASS_COM_PARALLEL 0x01
22885#define PCI_SUBCLASS_COM_MULTIPORT 0x02
22886#define PCI_SUBCLASS_COM_MODEM 0x03
22887#define PCI_SUBCLASS_COM_OTHER 0x80
22888
22889// Class 08 - PCI_CLASS_BASE_SYSTEM_DEV
22890
22891// N.B. See Interface byte for additional info.
22892
22893#define PCI_SUBCLASS_SYS_INTERRUPT_CTLR 0x00
22894#define PCI_SUBCLASS_SYS_DMA_CTLR 0x01
22895#define PCI_SUBCLASS_SYS_SYSTEM_TIMER 0x02
22896#define PCI_SUBCLASS_SYS_REAL_TIME_CLOCK 0x03
22897#define PCI_SUBCLASS_SYS_GEN_HOTPLUG_CTLR 0x04
22898#define PCI_SUBCLASS_SYS_OTHER 0x80
22899
22900// Class 09 - PCI_CLASS_INPUT_DEV
22901
22902#define PCI_SUBCLASS_INP_KEYBOARD 0x00
22903#define PCI_SUBCLASS_INP_DIGITIZER 0x01
22904#define PCI_SUBCLASS_INP_MOUSE 0x02
22905#define PCI_SUBCLASS_INP_SCANNER 0x03
22906#define PCI_SUBCLASS_INP_GAMEPORT 0x04
22907#define PCI_SUBCLASS_INP_OTHER 0x80
22908
22909// Class 0a - PCI_CLASS_DOCKING_STATION
22910
22911#define PCI_SUBCLASS_DOC_GENERIC 0x00
22912#define PCI_SUBCLASS_DOC_OTHER 0x80
22913
22914// Class 0b - PCI_CLASS_PROCESSOR
22915
22916#define PCI_SUBCLASS_PROC_386 0x00
22917#define PCI_SUBCLASS_PROC_486 0x01
22918#define PCI_SUBCLASS_PROC_PENTIUM 0x02
22919#define PCI_SUBCLASS_PROC_ALPHA 0x10
22920#define PCI_SUBCLASS_PROC_POWERPC 0x20
22921#define PCI_SUBCLASS_PROC_COPROCESSOR 0x40
22922
22923// Class 0c - PCI_CLASS_SERIAL_BUS_CTLR
22924
22925#define PCI_SUBCLASS_SB_IEEE1394 0x00
22926#define PCI_SUBCLASS_SB_ACCESS 0x01
22927#define PCI_SUBCLASS_SB_SSA 0x02
22928#define PCI_SUBCLASS_SB_USB 0x03
22929#define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
22930#define PCI_SUBCLASS_SB_SMBUS 0x05
22931
22932// Class 0d - PCI_CLASS_WIRELESS_CTLR
22933
22934#define PCI_SUBCLASS_WIRELESS_IRDA 0x00
22935#define PCI_SUBCLASS_WIRELESS_CON_IR 0x01
22936#define PCI_SUBCLASS_WIRELESS_RF 0x10
22937#define PCI_SUBCLASS_WIRELESS_OTHER 0x80
22938
22939// Class 0e - PCI_CLASS_INTELLIGENT_IO_CTLR
22940
22941#define PCI_SUBCLASS_INTIO_I2O 0x00
22942
22943// Class 0f - PCI_CLASS_SATELLITE_CTLR
22944
22945#define PCI_SUBCLASS_SAT_TV 0x01
22946#define PCI_SUBCLASS_SAT_AUDIO 0x02
22947#define PCI_SUBCLASS_SAT_VOICE 0x03
22948#define PCI_SUBCLASS_SAT_DATA 0x04
22949
22950// Class 10 - PCI_CLASS_ENCRYPTION_DECRYPTION
22951
22952#define PCI_SUBCLASS_CRYPTO_NET_COMP 0x00
22953#define PCI_SUBCLASS_CRYPTO_ENTERTAINMENT 0x10
22954#define PCI_SUBCLASS_CRYPTO_OTHER 0x80
22955
22956// Class 11 - PCI_CLASS_DATA_ACQ_SIGNAL_PROC
22957
22958#define PCI_SUBCLASS_DASP_DPIO 0x00
22959#define PCI_SUBCLASS_DASP_OTHER 0x80
22960
22961
22962
22963
22964
22965//
22966// Bit encodes for PCI_COMMON_CONFIG.u.type0.BaseAddresses
22967//
22968
22969#define PCI_ADDRESS_IO_SPACE 0x00000001 // (ro)
22970#define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006 // (ro)
22971#define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008 // (ro)
22972
22973#define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
22974#define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
22975#define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
22976
22977#define PCI_TYPE_32BIT 0
22978#define PCI_TYPE_20BIT 2
22979#define PCI_TYPE_64BIT 4
22980
22981//
22982// Bit encodes for PCI_COMMON_CONFIG.u.type0.ROMBaseAddresses
22983//
22984
22985#define PCI_ROMADDRESS_ENABLED 0x00000001
22986
22987
22988//
22989// Reference notes for PCI configuration fields:
22990//
22991// ro these field are read only. changes to these fields are ignored
22992//
22993// ro+ these field are intended to be read only and should be initialized
22994// by the system to their proper values. However, driver may change
22995// these settings.
22996//
22997// ---
22998//
22999// All resources comsumed by a PCI device start as unitialized
23000// under NT. An uninitialized memory or I/O base address can be
23001// determined by checking it's corrisponding enabled bit in the
23002// PCI_COMMON_CONFIG.Command value. An InterruptLine is unitialized
23003// if it contains the value of -1.
23004//
23005
23006
23007
23008
23009//
23010// Portable portion of HAL & HAL bus extender definitions for BUSHANDLER
23011// BusData for installed PCI buses.
23012//
23013
23014typedef VOID
23015(*PciPin2Line) (
23016 IN struct _BUS_HANDLER *BusHandler,
23017 IN struct _BUS_HANDLER *RootHandler,
23018 IN PCI_SLOT_NUMBER SlotNumber,
23019 IN PPCI_COMMON_CONFIG PciData
23020 );
23021
23022typedef VOID
23023(*PciLine2Pin) (
23024 IN struct _BUS_HANDLER *BusHandler,
23025 IN struct _BUS_HANDLER *RootHandler,
23026 IN PCI_SLOT_NUMBER SlotNumber,
23027 IN PPCI_COMMON_CONFIG PciNewData,
23028 IN PPCI_COMMON_CONFIG PciOldData
23029 );
23030
23031typedef VOID
23032(*PciReadWriteConfig) (
23033 IN struct _BUS_HANDLER *BusHandler,
23034 IN PCI_SLOT_NUMBER Slot,
23035 IN PVOID Buffer,
23036 IN ULONG Offset,
23037 IN ULONG Length
23038 );
23039
23040#define PCI_DATA_TAG ' ICP'
23041#define PCI_DATA_VERSION 1
23042
23043typedef struct _PCIBUSDATA {
23044 ULONG Tag;
23045 ULONG Version;
23046 PciReadWriteConfig ReadConfig;
23047 PciReadWriteConfig WriteConfig;
23048 PciPin2Line Pin2Line;
23049 PciLine2Pin Line2Pin;
23050 PCI_SLOT_NUMBER ParentSlot;
23051 PVOID Reserved[4];
23052} PCIBUSDATA, *PPCIBUSDATA;
23053
23054typedef ULONG (*PCI_READ_WRITE_CONFIG)(
23055 IN PVOID Context,
23056 IN UCHAR BusOffset,
23057 IN ULONG Slot,
23058 IN PVOID Buffer,
23059 IN ULONG Offset,
23060 IN ULONG Length
23061 );
23062
23063typedef VOID (*PCI_PIN_TO_LINE)(
23064 IN PVOID Context,
23065 IN PPCI_COMMON_CONFIG PciData
23066 );
23067
23068typedef VOID (*PCI_LINE_TO_PIN)(
23069 IN PVOID Context,
23070 IN PPCI_COMMON_CONFIG PciNewData,
23071 IN PPCI_COMMON_CONFIG PciOldData
23072 );
23073
23074typedef struct _PCI_BUS_INTERFACE_STANDARD {
23075 //
23076 // generic interface header
23077 //
23078 USHORT Size;
23079 USHORT Version;
23080 PVOID Context;
23081 PINTERFACE_REFERENCE InterfaceReference;
23082 PINTERFACE_DEREFERENCE InterfaceDereference;
23083 //
23084 // standard PCI bus interfaces
23085 //
23086 PCI_READ_WRITE_CONFIG ReadConfig;
23087 PCI_READ_WRITE_CONFIG WriteConfig;
23088 PCI_PIN_TO_LINE PinToLine;
23089 PCI_LINE_TO_PIN LineToPin;
23090} PCI_BUS_INTERFACE_STANDARD, *PPCI_BUS_INTERFACE_STANDARD;
23091
23092#define PCI_BUS_INTERFACE_STANDARD_VERSION 1
23093
23094
23095
23096#define PCI_DEVICE_PRESENT_INTERFACE_VERSION 1
23097
23098//
23099// Flags for PCI_DEVICE_PRESENCE_PARAMETERS
23100//
23101#define PCI_USE_SUBSYSTEM_IDS 0x00000001
23102#define PCI_USE_REVISION 0x00000002
23103// The following flags are only valid for IsDevicePresentEx
23104#define PCI_USE_VENDEV_IDS 0x00000004
23105#define PCI_USE_CLASS_SUBCLASS 0x00000008
23106#define PCI_USE_PROGIF 0x00000010
23107#define PCI_USE_LOCAL_BUS 0x00000020
23108#define PCI_USE_LOCAL_DEVICE 0x00000040
23109
23110//
23111// Search parameters structure for IsDevicePresentEx
23112//
23113typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
23114
23115 ULONG Size;
23116 ULONG Flags;
23117
23118 USHORT VendorID;
23119 USHORT DeviceID;
23120 UCHAR RevisionID;
23121 USHORT SubVendorID;
23122 USHORT SubSystemID;
23123 UCHAR BaseClass;
23124 UCHAR SubClass;
23125 UCHAR ProgIf;
23126
23127} PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
23128
23129typedef
23130BOOLEAN
23131(*PPCI_IS_DEVICE_PRESENT) (
23132 IN USHORT VendorID,
23133 IN USHORT DeviceID,
23134 IN UCHAR RevisionID,
23135 IN USHORT SubVendorID,
23136 IN USHORT SubSystemID,
23137 IN ULONG Flags
23138);
23139
23140typedef
23141BOOLEAN
23142(*PPCI_IS_DEVICE_PRESENT_EX) (
23143 IN PVOID Context,
23144 IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
23145 );
23146
23147typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
23148 //
23149 // generic interface header
23150 //
23151 USHORT Size;
23152 USHORT Version;
23153 PVOID Context;
23154 PINTERFACE_REFERENCE InterfaceReference;
23155 PINTERFACE_DEREFERENCE InterfaceDereference;
23156 //
23157 // pci device info
23158 //
23159 PPCI_IS_DEVICE_PRESENT IsDevicePresent;
23160
23161 PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
23162
23163} PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
23164
23165
23166
23167
23168#ifdef POOL_TAGGING
23169#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,' kdD')
23170#define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,' kdD')
23171#endif
23172
23173extern POBJECT_TYPE *IoFileObjectType;
23174extern POBJECT_TYPE *ExEventObjectType;
23175extern POBJECT_TYPE *ExSemaphoreObjectType;
23176
23177//
23178// Define exported ZwXxx routines to device drivers.
23179//
23180
23181NTSYSAPI
23182NTSTATUS
23183NTAPI
23184ZwCreateFile(
23185 OUT PHANDLE FileHandle,
23186 IN ACCESS_MASK DesiredAccess,
23187 IN POBJECT_ATTRIBUTES ObjectAttributes,
23188 OUT PIO_STATUS_BLOCK IoStatusBlock,
23189 IN PLARGE_INTEGER AllocationSize OPTIONAL,
23190 IN ULONG FileAttributes,
23191 IN ULONG ShareAccess,
23192 IN ULONG CreateDisposition,
23193 IN ULONG CreateOptions,
23194 IN PVOID EaBuffer OPTIONAL,
23195 IN ULONG EaLength
23196 );
23197
23198NTSYSAPI
23199NTSTATUS
23200NTAPI
23201ZwOpenFile(
23202 OUT PHANDLE FileHandle,
23203 IN ACCESS_MASK DesiredAccess,
23204 IN POBJECT_ATTRIBUTES ObjectAttributes,
23205 OUT PIO_STATUS_BLOCK IoStatusBlock,
23206 IN ULONG ShareAccess,
23207 IN ULONG OpenOptions
23208 );
23209
23210NTSYSAPI
23211NTSTATUS
23212NTAPI
23213ZwQueryInformationFile(
23214 IN HANDLE FileHandle,
23215 OUT PIO_STATUS_BLOCK IoStatusBlock,
23216 OUT PVOID FileInformation,
23217 IN ULONG Length,
23218 IN FILE_INFORMATION_CLASS FileInformationClass
23219 );
23220
23221NTSYSAPI
23222NTSTATUS
23223NTAPI
23224ZwSetInformationFile(
23225 IN HANDLE FileHandle,
23226 OUT PIO_STATUS_BLOCK IoStatusBlock,
23227 IN PVOID FileInformation,
23228 IN ULONG Length,
23229 IN FILE_INFORMATION_CLASS FileInformationClass
23230 );
23231
23232NTSYSAPI
23233NTSTATUS
23234NTAPI
23235ZwReadFile(
23236 IN HANDLE FileHandle,
23237 IN HANDLE Event OPTIONAL,
23238 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
23239 IN PVOID ApcContext OPTIONAL,
23240 OUT PIO_STATUS_BLOCK IoStatusBlock,
23241 OUT PVOID Buffer,
23242 IN ULONG Length,
23243 IN PLARGE_INTEGER ByteOffset OPTIONAL,
23244 IN PULONG Key OPTIONAL
23245 );
23246
23247NTSYSAPI
23248NTSTATUS
23249NTAPI
23250ZwWriteFile(
23251 IN HANDLE FileHandle,
23252 IN HANDLE Event OPTIONAL,
23253 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
23254 IN PVOID ApcContext OPTIONAL,
23255 OUT PIO_STATUS_BLOCK IoStatusBlock,
23256 IN PVOID Buffer,
23257 IN ULONG Length,
23258 IN PLARGE_INTEGER ByteOffset OPTIONAL,
23259 IN PULONG Key OPTIONAL
23260 );
23261
23262NTSYSAPI
23263NTSTATUS
23264NTAPI
23265ZwClose(
23266 IN HANDLE Handle
23267 );
23268
23269NTSYSAPI
23270NTSTATUS
23271NTAPI
23272ZwCreateDirectoryObject(
23273 OUT PHANDLE DirectoryHandle,
23274 IN ACCESS_MASK DesiredAccess,
23275 IN POBJECT_ATTRIBUTES ObjectAttributes
23276 );
23277
23278NTSYSAPI
23279NTSTATUS
23280NTAPI
23281ZwMakeTemporaryObject(
23282 IN HANDLE Handle
23283 );
23284
23285NTSYSAPI
23286NTSTATUS
23287NTAPI
23288ZwCreateSection (
23289 OUT PHANDLE SectionHandle,
23290 IN ACCESS_MASK DesiredAccess,
23291 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
23292 IN PLARGE_INTEGER MaximumSize OPTIONAL,
23293 IN ULONG SectionPageProtection,
23294 IN ULONG AllocationAttributes,
23295 IN HANDLE FileHandle OPTIONAL
23296 );
23297
23298NTSYSAPI
23299NTSTATUS
23300NTAPI
23301ZwOpenSection(
23302 OUT PHANDLE SectionHandle,
23303 IN ACCESS_MASK DesiredAccess,
23304 IN POBJECT_ATTRIBUTES ObjectAttributes
23305 );
23306
23307NTSYSAPI
23308NTSTATUS
23309NTAPI
23310ZwMapViewOfSection(
23311 IN HANDLE SectionHandle,
23312 IN HANDLE ProcessHandle,
23313 IN OUT PVOID *BaseAddress,
23314 IN ULONG ZeroBits,
23315 IN SIZE_T CommitSize,
23316 IN OUT PLARGE_INTEGER SectionOffset OPTIONAL,
23317 IN OUT PSIZE_T ViewSize,
23318 IN SECTION_INHERIT InheritDisposition,
23319 IN ULONG AllocationType,
23320 IN ULONG Protect
23321 );
23322
23323NTSYSAPI
23324NTSTATUS
23325NTAPI
23326ZwUnmapViewOfSection(
23327 IN HANDLE ProcessHandle,
23328 IN PVOID BaseAddress
23329 );
23330
23331NTSYSAPI
23332NTSTATUS
23333NTAPI
23334ZwSetInformationThread(
23335 IN HANDLE ThreadHandle,
23336 IN THREADINFOCLASS ThreadInformationClass,
23337 IN PVOID ThreadInformation,
23338 IN ULONG ThreadInformationLength
23339 );
23340
23341NTSYSAPI
23342NTSTATUS
23343NTAPI
23344ZwCreateKey(
23345 OUT PHANDLE KeyHandle,
23346 IN ACCESS_MASK DesiredAccess,
23347 IN POBJECT_ATTRIBUTES ObjectAttributes,
23348 IN ULONG TitleIndex,
23349 IN PUNICODE_STRING Class OPTIONAL,
23350 IN ULONG CreateOptions,
23351 OUT PULONG Disposition OPTIONAL
23352 );
23353
23354NTSYSAPI
23355NTSTATUS
23356NTAPI
23357ZwOpenKey(
23358 OUT PHANDLE KeyHandle,
23359 IN ACCESS_MASK DesiredAccess,
23360 IN POBJECT_ATTRIBUTES ObjectAttributes
23361 );
23362
23363NTSYSAPI
23364NTSTATUS
23365NTAPI
23366ZwDeleteKey(
23367 IN HANDLE KeyHandle
23368 );
23369
23370NTSYSAPI
23371NTSTATUS
23372NTAPI
23373ZwDeleteValueKey(
23374 IN HANDLE KeyHandle,
23375 IN PUNICODE_STRING ValueName
23376 );
23377
23378NTSYSAPI
23379NTSTATUS
23380NTAPI
23381ZwEnumerateKey(
23382 IN HANDLE KeyHandle,
23383 IN ULONG Index,
23384 IN KEY_INFORMATION_CLASS KeyInformationClass,
23385 OUT PVOID KeyInformation,
23386 IN ULONG Length,
23387 OUT PULONG ResultLength
23388 );
23389
23390NTSYSAPI
23391NTSTATUS
23392NTAPI
23393ZwEnumerateValueKey(
23394 IN HANDLE KeyHandle,
23395 IN ULONG Index,
23396 IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
23397 OUT PVOID KeyValueInformation,
23398 IN ULONG Length,
23399 OUT PULONG ResultLength
23400 );
23401
23402NTSYSAPI
23403NTSTATUS
23404NTAPI
23405ZwFlushKey(
23406 IN HANDLE KeyHandle
23407 );
23408
23409NTSYSAPI
23410NTSTATUS
23411NTAPI
23412ZwQueryKey(
23413 IN HANDLE KeyHandle,
23414 IN KEY_INFORMATION_CLASS KeyInformationClass,
23415 OUT PVOID KeyInformation,
23416 IN ULONG Length,
23417 OUT PULONG ResultLength
23418 );
23419
23420NTSYSAPI
23421NTSTATUS
23422NTAPI
23423ZwQueryValueKey(
23424 IN HANDLE KeyHandle,
23425 IN PUNICODE_STRING ValueName,
23426 IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
23427 OUT PVOID KeyValueInformation,
23428 IN ULONG Length,
23429 OUT PULONG ResultLength
23430 );
23431
23432NTSYSAPI
23433NTSTATUS
23434NTAPI
23435ZwSetValueKey(
23436 IN HANDLE KeyHandle,
23437 IN PUNICODE_STRING ValueName,
23438 IN ULONG TitleIndex OPTIONAL,
23439 IN ULONG Type,
23440 IN PVOID Data,
23441 IN ULONG DataSize
23442 );
23443
23444NTSYSAPI
23445NTSTATUS
23446NTAPI
23447ZwOpenSymbolicLinkObject(
23448 OUT PHANDLE LinkHandle,
23449 IN ACCESS_MASK DesiredAccess,
23450 IN POBJECT_ATTRIBUTES ObjectAttributes
23451 );
23452
23453NTSYSAPI
23454NTSTATUS
23455NTAPI
23456ZwQuerySymbolicLinkObject(
23457 IN HANDLE LinkHandle,
23458 IN OUT PUNICODE_STRING LinkTarget,
23459 OUT PULONG ReturnedLength OPTIONAL
23460 );
23461
23462NTSTATUS
23463ZwCreateTimer (
23464 OUT PHANDLE TimerHandle,
23465 IN ACCESS_MASK DesiredAccess,
23466 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
23467 IN TIMER_TYPE TimerType
23468 );
23469
23470NTSTATUS
23471ZwOpenTimer (
23472 OUT PHANDLE TimerHandle,
23473 IN ACCESS_MASK DesiredAccess,
23474 IN POBJECT_ATTRIBUTES ObjectAttributes
23475 );
23476
23477NTSTATUS
23478ZwCancelTimer (
23479 IN HANDLE TimerHandle,
23480 OUT PBOOLEAN CurrentState OPTIONAL
23481 );
23482
23483NTSTATUS
23484ZwSetTimer (
23485 IN HANDLE TimerHandle,
23486 IN PLARGE_INTEGER DueTime,
23487 IN PTIMER_APC_ROUTINE TimerApcRoutine OPTIONAL,
23488 IN PVOID TimerContext OPTIONAL,
23489 IN BOOLEAN WakeTimer,
23490 IN LONG Period OPTIONAL,
23491 OUT PBOOLEAN PreviousState OPTIONAL
23492 );
23493
23494#ifdef VERIFIER_DDK_EXTENSIONS
23495#include <ddk_ext.h>
23496#endif
23497
23498#endif // _NTDDK_
23499
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette