501b91aab3d8e9cfe49ffef6ec248854cba1dc2e
[reactos.git] / include / ddk / wdm.h
1 #ifndef _WDMDDK_
2 #define _WDMDDK_
3
4 /* Helper macro to enable gcc's extension. */
5 #ifndef __GNU_EXTENSION
6 #ifdef __GNUC__
7 #define __GNU_EXTENSION __extension__
8 #else
9 #define __GNU_EXTENSION
10 #endif
11 #endif
12
13 //
14 // Dependencies
15 //
16 #define NT_INCLUDED
17 #include <excpt.h>
18 #include <ntdef.h>
19 #include <ntstatus.h>
20
21 #ifndef GUID_DEFINED
22 #include <guiddef.h>
23 #endif /* GUID_DEFINED */
24
25 #include "intrin.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #if !defined(_NTHALDLL_) && !defined(_BLDR_)
32
33 #define NTHALAPI DECLSPEC_IMPORT
34
35 #else
36
37 #define NTHALAPI
38
39 #endif
40
41 #define NTKERNELAPI DECLSPEC_IMPORT
42
43 #if defined(_WIN64)
44 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
45 #else
46 #define POINTER_ALIGNMENT
47 #endif
48
49 #ifdef _WIN64
50 #define PORT_MAXIMUM_MESSAGE_LENGTH 512
51 #else
52 #define PORT_MAXIMUM_MESSAGE_LENGTH 256
53 #endif
54
55
56 #if defined(_MSC_VER)
57
58 //
59 // Indicate if #pragma alloc_text() is supported
60 //
61 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)
62 #define ALLOC_PRAGMA 1
63 #endif
64
65 //
66 // Indicate if #pragma data_seg() is supported
67 //
68 #if defined(_M_IX86) || defined(_M_AMD64)
69 #define ALLOC_DATA_PRAGMA 1
70 #endif
71
72 #endif
73
74
75 /*
76 * Alignment Macros
77 */
78 #define ALIGN_DOWN(s, t) \
79 ((ULONG)(s) & ~(sizeof(t) - 1))
80
81 #define ALIGN_UP(s, t) \
82 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
83
84 #define ALIGN_DOWN_POINTER(p, t) \
85 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
86
87 #define ALIGN_UP_POINTER(p, t) \
88 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
89
90 /*
91 * GUID Comparison
92 */
93
94 #ifndef __IID_ALIGNED__
95 #define __IID_ALIGNED__
96 #ifdef __cplusplus
97 inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
98 {
99 return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
100 }
101 #else
102 #define IsEqualGUIDAligned(guid1, guid2) \
103 ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
104 #endif
105 #endif
106
107 #if defined(_WIN64)
108 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
109 #else
110 #define POINTER_ALIGNMENT
111 #endif
112
113 /*
114 ** Forward declarations
115 */
116
117 struct _IRP;
118 struct _MDL;
119 struct _KAPC;
120 struct _KDPC;
121 struct _FILE_OBJECT;
122 struct _DMA_ADAPTER;
123 struct _DEVICE_OBJECT;
124 struct _DRIVER_OBJECT;
125 struct _IO_STATUS_BLOCK;
126 struct _DEVICE_DESCRIPTION;
127 struct _SCATTER_GATHER_LIST;
128 struct _DRIVE_LAYOUT_INFORMATION;
129
130 struct _COMPRESSED_DATA_INFO;
131
132 typedef PVOID PSID;
133
134 /* Simple types */
135 typedef UCHAR KPROCESSOR_MODE;
136 typedef LONG KPRIORITY;
137 typedef PVOID PSECURITY_DESCRIPTOR;
138 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
139
140 /* Structures not exposed to drivers */
141 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
142 typedef struct _HAL_DISPATCH_TABLE *PHAL_DISPATCH_TABLE;
143 typedef struct _HAL_PRIVATE_DISPATCH_TABLE *PHAL_PRIVATE_DISPATCH_TABLE;
144 typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
145 typedef struct _BUS_HANDLER *PBUS_HANDLER;
146
147 typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
148 typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
149 typedef struct _ETHREAD *PETHREAD;
150 typedef struct _EPROCESS *PEPROCESS;
151 typedef struct _IO_TIMER *PIO_TIMER;
152 typedef struct _KINTERRUPT *PKINTERRUPT;
153 typedef struct _KPROCESS *PKPROCESS;
154 typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
155
156
157 typedef struct _CONTEXT *PCONTEXT;
158
159 /*
160 ** Simple structures
161 */
162
163 typedef UCHAR KIRQL, *PKIRQL;
164
165 typedef enum _MODE {
166 KernelMode,
167 UserMode,
168 MaximumMode
169 } MODE;
170
171 //
172 // Power States/Levels
173 //
174 typedef enum _SYSTEM_POWER_STATE {
175 PowerSystemUnspecified,
176 PowerSystemWorking,
177 PowerSystemSleeping1,
178 PowerSystemSleeping2,
179 PowerSystemSleeping3,
180 PowerSystemHibernate,
181 PowerSystemShutdown,
182 PowerSystemMaximum
183 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
184
185 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
186
187 typedef enum _POWER_INFORMATION_LEVEL {
188 SystemPowerPolicyAc,
189 SystemPowerPolicyDc,
190 VerifySystemPolicyAc,
191 VerifySystemPolicyDc,
192 SystemPowerCapabilities,
193 SystemBatteryState,
194 SystemPowerStateHandler,
195 ProcessorStateHandler,
196 SystemPowerPolicyCurrent,
197 AdministratorPowerPolicy,
198 SystemReserveHiberFile,
199 ProcessorInformation,
200 SystemPowerInformation,
201 ProcessorStateHandler2,
202 LastWakeTime,
203 LastSleepTime,
204 SystemExecutionState,
205 SystemPowerStateNotifyHandler,
206 ProcessorPowerPolicyAc,
207 ProcessorPowerPolicyDc,
208 VerifyProcessorPowerPolicyAc,
209 VerifyProcessorPowerPolicyDc,
210 ProcessorPowerPolicyCurrent
211 } POWER_INFORMATION_LEVEL;
212
213 typedef enum {
214 PowerActionNone,
215 PowerActionReserved,
216 PowerActionSleep,
217 PowerActionHibernate,
218 PowerActionShutdown,
219 PowerActionShutdownReset,
220 PowerActionShutdownOff,
221 PowerActionWarmEject
222 } POWER_ACTION, *PPOWER_ACTION;
223
224 typedef enum _DEVICE_POWER_STATE {
225 PowerDeviceUnspecified,
226 PowerDeviceD0,
227 PowerDeviceD1,
228 PowerDeviceD2,
229 PowerDeviceD3,
230 PowerDeviceMaximum
231 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
232
233 #define ES_SYSTEM_REQUIRED 0x00000001
234 #define ES_DISPLAY_REQUIRED 0x00000002
235 #define ES_USER_PRESENT 0x00000004
236 #define ES_CONTINUOUS 0x80000000
237
238 typedef ULONG EXECUTION_STATE;
239
240 typedef enum {
241 LT_DONT_CARE,
242 LT_LOWEST_LATENCY
243 } LATENCY_TIME;
244
245 /* Constants */
246 #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
247 #define ZwCurrentProcess() NtCurrentProcess()
248 #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
249 #define ZwCurrentThread() NtCurrentThread()
250
251 #if (_M_IX86)
252 #define KIP0PCRADDRESS 0xffdff000
253 #endif
254
255 #if defined(_WIN64)
256 #define MAXIMUM_PROCESSORS 64
257 #else
258 #define MAXIMUM_PROCESSORS 32
259 #endif
260
261 #define MAXIMUM_WAIT_OBJECTS 64
262
263 #define EX_RUNDOWN_ACTIVE 0x1
264 #define EX_RUNDOWN_COUNT_SHIFT 0x1
265 #define EX_RUNDOWN_COUNT_INC (1 << EX_RUNDOWN_COUNT_SHIFT)
266
267 #define METHOD_BUFFERED 0
268 #define METHOD_IN_DIRECT 1
269 #define METHOD_OUT_DIRECT 2
270 #define METHOD_NEITHER 3
271
272 #define LOW_PRIORITY 0
273 #define LOW_REALTIME_PRIORITY 16
274 #define HIGH_PRIORITY 31
275 #define MAXIMUM_PRIORITY 32
276
277 #define MAXIMUM_SUSPEND_COUNT MAXCHAR
278
279 #define MAXIMUM_FILENAME_LENGTH 256
280
281 #define FILE_SUPERSEDED 0x00000000
282 #define FILE_OPENED 0x00000001
283 #define FILE_CREATED 0x00000002
284 #define FILE_OVERWRITTEN 0x00000003
285 #define FILE_EXISTS 0x00000004
286 #define FILE_DOES_NOT_EXIST 0x00000005
287
288 #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
289 #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
290
291 /* also in winnt.h */
292 #define FILE_LIST_DIRECTORY 0x00000001
293 #define FILE_READ_DATA 0x00000001
294 #define FILE_ADD_FILE 0x00000002
295 #define FILE_WRITE_DATA 0x00000002
296 #define FILE_ADD_SUBDIRECTORY 0x00000004
297 #define FILE_APPEND_DATA 0x00000004
298 #define FILE_CREATE_PIPE_INSTANCE 0x00000004
299 #define FILE_READ_EA 0x00000008
300 #define FILE_WRITE_EA 0x00000010
301 #define FILE_EXECUTE 0x00000020
302 #define FILE_TRAVERSE 0x00000020
303 #define FILE_DELETE_CHILD 0x00000040
304 #define FILE_READ_ATTRIBUTES 0x00000080
305 #define FILE_WRITE_ATTRIBUTES 0x00000100
306
307 #define FILE_SHARE_READ 0x00000001
308 #define FILE_SHARE_WRITE 0x00000002
309 #define FILE_SHARE_DELETE 0x00000004
310 #define FILE_SHARE_VALID_FLAGS 0x00000007
311
312 #define FILE_ATTRIBUTE_READONLY 0x00000001
313 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
314 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
315 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
316 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
317 #define FILE_ATTRIBUTE_DEVICE 0x00000040
318 #define FILE_ATTRIBUTE_NORMAL 0x00000080
319 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
320 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
321 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
322 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
323 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
324 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
325 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
326
327 #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
328 #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
329
330 #define FILE_VALID_OPTION_FLAGS 0x00ffffff
331 #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
332 #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
333 #define FILE_VALID_SET_FLAGS 0x00000036
334
335 #define FILE_SUPERSEDE 0x00000000
336 #define FILE_OPEN 0x00000001
337 #define FILE_CREATE 0x00000002
338 #define FILE_OPEN_IF 0x00000003
339 #define FILE_OVERWRITE 0x00000004
340 #define FILE_OVERWRITE_IF 0x00000005
341 #define FILE_MAXIMUM_DISPOSITION 0x00000005
342
343 #define FILE_DIRECTORY_FILE 0x00000001
344 #define FILE_WRITE_THROUGH 0x00000002
345 #define FILE_SEQUENTIAL_ONLY 0x00000004
346 #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
347 #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
348 #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
349 #define FILE_NON_DIRECTORY_FILE 0x00000040
350 #define FILE_CREATE_TREE_CONNECTION 0x00000080
351 #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
352 #define FILE_NO_EA_KNOWLEDGE 0x00000200
353 #define FILE_OPEN_REMOTE_INSTANCE 0x00000400
354 #define FILE_RANDOM_ACCESS 0x00000800
355 #define FILE_DELETE_ON_CLOSE 0x00001000
356 #define FILE_OPEN_BY_FILE_ID 0x00002000
357 #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
358 #define FILE_NO_COMPRESSION 0x00008000
359 #define FILE_RESERVE_OPFILTER 0x00100000
360 #define FILE_OPEN_REPARSE_POINT 0x00200000
361 #define FILE_OPEN_NO_RECALL 0x00400000
362 #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
363
364 #define FILE_ANY_ACCESS 0x00000000
365 #define FILE_SPECIAL_ACCESS FILE_ANY_ACCESS
366 #define FILE_READ_ACCESS 0x00000001
367 #define FILE_WRITE_ACCESS 0x00000002
368
369 #define FILE_ALL_ACCESS \
370 (STANDARD_RIGHTS_REQUIRED | \
371 SYNCHRONIZE | \
372 0x1FF)
373
374 #define FILE_GENERIC_EXECUTE \
375 (STANDARD_RIGHTS_EXECUTE | \
376 FILE_READ_ATTRIBUTES | \
377 FILE_EXECUTE | \
378 SYNCHRONIZE)
379
380 #define FILE_GENERIC_READ \
381 (STANDARD_RIGHTS_READ | \
382 FILE_READ_DATA | \
383 FILE_READ_ATTRIBUTES | \
384 FILE_READ_EA | \
385 SYNCHRONIZE)
386
387 #define FILE_GENERIC_WRITE \
388 (STANDARD_RIGHTS_WRITE | \
389 FILE_WRITE_DATA | \
390 FILE_WRITE_ATTRIBUTES | \
391 FILE_WRITE_EA | \
392 FILE_APPEND_DATA | \
393 SYNCHRONIZE)
394
395 /* end winnt.h */
396
397 #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
398
399 #define OBJECT_TYPE_CREATE (0x0001)
400 #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
401
402 #define DIRECTORY_QUERY (0x0001)
403 #define DIRECTORY_TRAVERSE (0x0002)
404 #define DIRECTORY_CREATE_OBJECT (0x0004)
405 #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
406 #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
407
408 #define EVENT_QUERY_STATE (0x0001)
409 #define EVENT_MODIFY_STATE (0x0002)
410 #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
411
412 #define SEMAPHORE_QUERY_STATE (0x0001)
413 #define SEMAPHORE_MODIFY_STATE (0x0002)
414 #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
415
416 #define FM_LOCK_BIT (0x1)
417 #define FM_LOCK_BIT_V (0x0)
418 #define FM_LOCK_WAITER_WOKEN (0x2)
419 #define FM_LOCK_WAITER_INC (0x4)
420
421 /*
422 ** System structures
423 */
424
425 #define SYMBOLIC_LINK_QUERY 0x0001
426 #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
427
428 /* also in winnt,h */
429 #define DUPLICATE_CLOSE_SOURCE 0x00000001
430 #define DUPLICATE_SAME_ACCESS 0x00000002
431 #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
432 /* end winnt.h */
433
434 typedef struct _OBJECT_NAME_INFORMATION {
435 UNICODE_STRING Name;
436 } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
437
438 //
439 // Resource list definitions
440 //
441 typedef int CM_RESOURCE_TYPE;
442
443 #define CmResourceTypeNull 0
444 #define CmResourceTypePort 1
445 #define CmResourceTypeInterrupt 2
446 #define CmResourceTypeMemory 3
447 #define CmResourceTypeDma 4
448 #define CmResourceTypeDeviceSpecific 5
449 #define CmResourceTypeBusNumber 6
450 #define CmResourceTypeNonArbitrated 128
451 #define CmResourceTypeConfigData 128
452 #define CmResourceTypeDevicePrivate 129
453 #define CmResourceTypePcCardConfig 130
454 #define CmResourceTypeMfCardConfig 131
455
456 //
457 // Global debug flag
458 //
459 extern ULONG NtGlobalFlag;
460
461 //
462 // Section map options
463 //
464 typedef enum _SECTION_INHERIT {
465 ViewShare = 1,
466 ViewUnmap = 2
467 } SECTION_INHERIT;
468
469 //
470 // Section access rights
471 //
472 #define SECTION_QUERY 0x0001
473 #define SECTION_MAP_WRITE 0x0002
474 #define SECTION_MAP_READ 0x0004
475 #define SECTION_MAP_EXECUTE 0x0008
476 #define SECTION_EXTEND_SIZE 0x0010
477 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
478
479 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
480 SECTION_MAP_WRITE | \
481 SECTION_MAP_READ | \
482 SECTION_MAP_EXECUTE | \
483 SECTION_EXTEND_SIZE)
484
485 #define SESSION_QUERY_ACCESS 0x0001
486 #define SESSION_MODIFY_ACCESS 0x0002
487
488 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
489 SESSION_QUERY_ACCESS | \
490 SESSION_MODIFY_ACCESS)
491
492
493
494 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
495
496 #define PAGE_NOACCESS 0x01
497 #define PAGE_READONLY 0x02
498 #define PAGE_READWRITE 0x04
499 #define PAGE_WRITECOPY 0x08
500 #define PAGE_EXECUTE 0x10
501 #define PAGE_EXECUTE_READ 0x20
502 #define PAGE_EXECUTE_READWRITE 0x40
503 #define PAGE_EXECUTE_WRITECOPY 0x80
504 #define PAGE_GUARD 0x100
505 #define PAGE_NOCACHE 0x200
506 #define PAGE_WRITECOMBINE 0x400
507
508 #define MEM_COMMIT 0x1000
509 #define MEM_RESERVE 0x2000
510 #define MEM_DECOMMIT 0x4000
511 #define MEM_RELEASE 0x8000
512 #define MEM_FREE 0x10000
513 #define MEM_PRIVATE 0x20000
514 #define MEM_MAPPED 0x40000
515 #define MEM_RESET 0x80000
516 #define MEM_TOP_DOWN 0x100000
517 #define MEM_LARGE_PAGES 0x20000000
518 #define MEM_4MB_PAGES 0x80000000
519
520 #define SEC_RESERVE 0x4000000
521 #define SEC_LARGE_PAGES 0x80000000
522
523 #define PROCESS_DUP_HANDLE (0x0040)
524
525 #if (NTDDI_VERSION >= NTDDI_VISTA)
526 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
527 0xFFFF)
528 #else
529 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
530 0xFFF)
531 #endif
532
533
534
535 //
536 // Processor features
537 //
538 #define PF_FLOATING_POINT_PRECISION_ERRATA 0
539 #define PF_FLOATING_POINT_EMULATED 1
540 #define PF_COMPARE_EXCHANGE_DOUBLE 2
541 #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
542 #define PF_PPC_MOVEMEM_64BIT_OK 4
543 #define PF_ALPHA_BYTE_INSTRUCTIONS 5
544 #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
545 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
546 #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
547 #define PF_PAE_ENABLED 9
548 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
549 #define PF_SSE_DAZ_MODE_AVAILABLE 11
550 #define PF_NX_ENABLED 12
551 #define PF_SSE3_INSTRUCTIONS_AVAILABLE 13
552 #define PF_COMPARE_EXCHANGE128 14
553 #define PF_COMPARE64_EXCHANGE128 15
554 #define PF_CHANNELS_ENABLED 16
555
556
557
558 //
559 // Intrinsics (note: taken from our winnt.h)
560 // FIXME: 64-bit
561 //
562 #if defined(__GNUC__)
563
564 static __inline__ BOOLEAN
565 InterlockedBitTestAndSet(IN LONG volatile *Base,
566 IN LONG Bit)
567 {
568 #if defined(_M_IX86)
569 LONG OldBit;
570 __asm__ __volatile__("lock "
571 "btsl %2,%1\n\t"
572 "sbbl %0,%0\n\t"
573 :"=r" (OldBit),"+m" (*Base)
574 :"Ir" (Bit)
575 : "memory");
576 return OldBit;
577 #else
578 return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
579 #endif
580 }
581
582 static __inline__ BOOLEAN
583 InterlockedBitTestAndReset(IN LONG volatile *Base,
584 IN LONG Bit)
585 {
586 #if defined(_M_IX86)
587 LONG OldBit;
588 __asm__ __volatile__("lock "
589 "btrl %2,%1\n\t"
590 "sbbl %0,%0\n\t"
591 :"=r" (OldBit),"+m" (*Base)
592 :"Ir" (Bit)
593 : "memory");
594 return OldBit;
595 #else
596 return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
597 #endif
598 }
599
600 #endif
601
602 #define BitScanForward _BitScanForward
603 #define BitScanReverse _BitScanReverse
604
605 #define BitTest _bittest
606 #define BitTestAndComplement _bittestandcomplement
607 #define BitTestAndSet _bittestandset
608 #define BitTestAndReset _bittestandreset
609 #define InterlockedBitTestAndSet _interlockedbittestandset
610 #define InterlockedBitTestAndReset _interlockedbittestandreset
611
612
613 /** INTERLOCKED FUNCTIONS *****************************************************/
614
615 #if !defined(__INTERLOCKED_DECLARED)
616 #define __INTERLOCKED_DECLARED
617
618 #if defined (_X86_)
619 #if defined(NO_INTERLOCKED_INTRINSICS)
620 NTKERNELAPI
621 LONG
622 FASTCALL
623 InterlockedIncrement(
624 IN OUT LONG volatile *Addend);
625
626 NTKERNELAPI
627 LONG
628 FASTCALL
629 InterlockedDecrement(
630 IN OUT LONG volatile *Addend);
631
632 NTKERNELAPI
633 LONG
634 FASTCALL
635 InterlockedCompareExchange(
636 IN OUT LONG volatile *Destination,
637 IN LONG Exchange,
638 IN LONG Comparand);
639
640 NTKERNELAPI
641 LONG
642 FASTCALL
643 InterlockedExchange(
644 IN OUT LONG volatile *Destination,
645 IN LONG Value);
646
647 NTKERNELAPI
648 LONG
649 FASTCALL
650 InterlockedExchangeAdd(
651 IN OUT LONG volatile *Addend,
652 IN LONG Value);
653
654 #else // !defined(NO_INTERLOCKED_INTRINSICS)
655
656 #define InterlockedExchange _InterlockedExchange
657 #define InterlockedIncrement _InterlockedIncrement
658 #define InterlockedDecrement _InterlockedDecrement
659 #define InterlockedExchangeAdd _InterlockedExchangeAdd
660 #define InterlockedCompareExchange _InterlockedCompareExchange
661 #define InterlockedOr _InterlockedOr
662 #define InterlockedAnd _InterlockedAnd
663 #define InterlockedXor _InterlockedXor
664
665 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
666
667 #endif // defined (_X86_)
668
669 #if !defined (_WIN64)
670 /*
671 * PVOID
672 * InterlockedExchangePointer(
673 * IN OUT PVOID volatile *Target,
674 * IN PVOID Value)
675 */
676 #define InterlockedExchangePointer(Target, Value) \
677 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
678
679 /*
680 * PVOID
681 * InterlockedCompareExchangePointer(
682 * IN OUT PVOID *Destination,
683 * IN PVOID Exchange,
684 * IN PVOID Comparand)
685 */
686 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
687 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
688
689 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
690 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
691 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
692
693 #endif // !defined (_WIN64)
694
695 #if defined (_M_AMD64)
696
697 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
698 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
699 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
700 #define InterlockedAnd _InterlockedAnd
701 #define InterlockedOr _InterlockedOr
702 #define InterlockedXor _InterlockedXor
703 #define InterlockedIncrement _InterlockedIncrement
704 #define InterlockedDecrement _InterlockedDecrement
705 #define InterlockedAdd _InterlockedAdd
706 #define InterlockedExchange _InterlockedExchange
707 #define InterlockedExchangeAdd _InterlockedExchangeAdd
708 #define InterlockedCompareExchange _InterlockedCompareExchange
709 #define InterlockedAnd64 _InterlockedAnd64
710 #define InterlockedOr64 _InterlockedOr64
711 #define InterlockedXor64 _InterlockedXor64
712 #define InterlockedIncrement64 _InterlockedIncrement64
713 #define InterlockedDecrement64 _InterlockedDecrement64
714 #define InterlockedAdd64 _InterlockedAdd64
715 #define InterlockedExchange64 _InterlockedExchange64
716 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
717 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
718 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
719 #define InterlockedExchangePointer _InterlockedExchangePointer
720 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
721 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
722
723 #endif // _M_AMD64
724
725 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
726 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
727 FORCEINLINE
728 LONG64
729 InterlockedAdd64(
730 IN OUT LONG64 volatile *Addend,
731 IN LONG64 Value)
732 {
733 return InterlockedExchangeAdd64(Addend, Value) + Value;
734 }
735 //#endif
736 #endif
737
738 #endif /* !__INTERLOCKED_DECLARED */
739
740 #if defined(_M_IX86)
741 #define YieldProcessor _mm_pause
742 #elif defined (_M_AMD64)
743 #define YieldProcessor _mm_pause
744 #elif defined(_M_PPC)
745 #define YieldProcessor() __asm__ __volatile__("nop");
746 #elif defined(_M_MIPS)
747 #define YieldProcessor() __asm__ __volatile__("nop");
748 #elif defined(_M_ARM)
749 #define YieldProcessor()
750 #else
751 #error Unknown architecture
752 #endif
753
754 //
755 // Slist Header
756 //
757 #ifndef _SLIST_HEADER_
758 #define _SLIST_HEADER_
759
760 #if defined(_WIN64)
761 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
762 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
763 PSLIST_ENTRY Next;
764 } SLIST_ENTRY;
765 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
766 struct {
767 ULONGLONG Alignment;
768 ULONGLONG Region;
769 } DUMMYSTRUCTNAME;
770 struct {
771 ULONGLONG Depth:16;
772 ULONGLONG Sequence:9;
773 ULONGLONG NextEntry:39;
774 ULONGLONG HeaderType:1;
775 ULONGLONG Init:1;
776 ULONGLONG Reserved:59;
777 ULONGLONG Region:3;
778 } Header8;
779 struct {
780 ULONGLONG Depth:16;
781 ULONGLONG Sequence:48;
782 ULONGLONG HeaderType:1;
783 ULONGLONG Init:1;
784 ULONGLONG Reserved:2;
785 ULONGLONG NextEntry:60;
786 } Header16;
787 } SLIST_HEADER, *PSLIST_HEADER;
788 #else
789 #define SLIST_ENTRY SINGLE_LIST_ENTRY
790 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
791 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
792 typedef union _SLIST_HEADER {
793 ULONGLONG Alignment;
794 struct {
795 SLIST_ENTRY Next;
796 USHORT Depth;
797 USHORT Sequence;
798 } DUMMYSTRUCTNAME;
799 } SLIST_HEADER, *PSLIST_HEADER;
800 #endif
801
802 #endif /* _SLIST_HEADER_ */
803
804 //
805 // Thread Access Rights
806 //
807 #define THREAD_TERMINATE (0x0001)
808 #define THREAD_SUSPEND_RESUME (0x0002)
809 #define THREAD_ALERT (0x0004)
810 #define THREAD_GET_CONTEXT (0x0008)
811 #define THREAD_SET_CONTEXT (0x0010)
812 #define THREAD_SET_INFORMATION (0x0020)
813 #define THREAD_SET_LIMITED_INFORMATION (0x0400)
814 #define THREAD_QUERY_LIMITED_INFORMATION (0x0800)
815 #if (NTDDI_VERSION >= NTDDI_VISTA)
816 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
817 0xFFFF)
818 #else
819 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
820 0x3FF)
821 #endif
822
823 //
824 // Service Start Types
825 //
826 #define SERVICE_BOOT_START 0x00000000
827 #define SERVICE_SYSTEM_START 0x00000001
828 #define SERVICE_AUTO_START 0x00000002
829 #define SERVICE_DEMAND_START 0x00000003
830 #define SERVICE_DISABLED 0x00000004
831
832 //
833 // Exception Records
834 //
835 #define EXCEPTION_NONCONTINUABLE 1
836 #define EXCEPTION_MAXIMUM_PARAMETERS 15
837
838 typedef struct _EXCEPTION_RECORD {
839 NTSTATUS ExceptionCode;
840 ULONG ExceptionFlags;
841 struct _EXCEPTION_RECORD *ExceptionRecord;
842 PVOID ExceptionAddress;
843 ULONG NumberParameters;
844 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
845 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
846
847 typedef struct _EXCEPTION_RECORD32 {
848 NTSTATUS ExceptionCode;
849 ULONG ExceptionFlags;
850 ULONG ExceptionRecord;
851 ULONG ExceptionAddress;
852 ULONG NumberParameters;
853 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
854 } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
855
856 typedef struct _EXCEPTION_RECORD64 {
857 NTSTATUS ExceptionCode;
858 ULONG ExceptionFlags;
859 ULONG64 ExceptionRecord;
860 ULONG64 ExceptionAddress;
861 ULONG NumberParameters;
862 ULONG __unusedAlignment;
863 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
864 } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
865
866 typedef struct _EXCEPTION_POINTERS {
867 PEXCEPTION_RECORD ExceptionRecord;
868 PCONTEXT ContextRecord;
869 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
870
871
872
873 //
874 // Process Qoutas
875 //
876 typedef struct _QUOTA_LIMITS {
877 SIZE_T PagedPoolLimit;
878 SIZE_T NonPagedPoolLimit;
879 SIZE_T MinimumWorkingSetSize;
880 SIZE_T MaximumWorkingSetSize;
881 SIZE_T PagefileLimit;
882 LARGE_INTEGER TimeLimit;
883 } QUOTA_LIMITS, *PQUOTA_LIMITS;
884
885 #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
886 #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
887 #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
888 #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
889 #define QUOTA_LIMITS_USE_DEFAULT_LIMITS 0x00000010
890
891
892 /******************************************************************************
893 * WINBASE Functions *
894 ******************************************************************************/
895 #if !defined(_WINBASE_)
896
897 #if defined(_WIN64)
898
899 #define InterlockedPopEntrySList(Head) \
900 ExpInterlockedPopEntrySList(Head)
901
902 #define InterlockedPushEntrySList(Head, Entry) \
903 ExpInterlockedPushEntrySList(Head, Entry)
904
905 #define InterlockedFlushSList(Head) \
906 ExpInterlockedFlushSList(Head)
907
908 #define QueryDepthSList(Head) \
909 ExQueryDepthSList(Head)
910
911 #else // !defined(_WIN64)
912
913 NTKERNELAPI
914 PSLIST_ENTRY
915 FASTCALL
916 InterlockedPopEntrySList(
917 IN PSLIST_HEADER ListHead);
918
919 NTKERNELAPI
920 PSLIST_ENTRY
921 FASTCALL
922 InterlockedPushEntrySList(
923 IN PSLIST_HEADER ListHead,
924 IN PSLIST_ENTRY ListEntry);
925
926 #define InterlockedFlushSList(ListHead) \
927 ExInterlockedFlushSList(ListHead)
928
929 #define QueryDepthSList(Head) \
930 ExQueryDepthSList(Head)
931
932 #endif // !defined(_WIN64)
933
934 #endif // !defined(_WINBASE_)
935
936 /******************************************************************************
937 * Kernel Types *
938 ******************************************************************************/
939
940 #define ASSERT_APC(Object) \
941 ASSERT((Object)->Type == ApcObject)
942
943 #define ASSERT_DPC(Object) \
944 ASSERT(((Object)->Type == 0) || \
945 ((Object)->Type == DpcObject) || \
946 ((Object)->Type == ThreadedDpcObject))
947
948 #define ASSERT_DEVICE_QUEUE(Object) \
949 ASSERT((Object)->Type == DeviceQueueObject)
950
951 #define DPC_NORMAL 0
952 #define DPC_THREADED 1
953
954 #define GM_LOCK_BIT 0x1
955 #define GM_LOCK_BIT_V 0x0
956 #define GM_LOCK_WAITER_WOKEN 0x2
957 #define GM_LOCK_WAITER_INC 0x4
958
959 #define LOCK_QUEUE_WAIT 1
960 #define LOCK_QUEUE_OWNER 2
961 #define LOCK_QUEUE_TIMER_LOCK_SHIFT 4
962 #define LOCK_QUEUE_TIMER_TABLE_LOCKS (1 << (8 - LOCK_QUEUE_TIMER_LOCK_SHIFT))
963
964 #define PROCESSOR_FEATURE_MAX 64
965
966 #define DBG_STATUS_CONTROL_C 1
967 #define DBG_STATUS_SYSRQ 2
968 #define DBG_STATUS_BUGCHECK_FIRST 3
969 #define DBG_STATUS_BUGCHECK_SECOND 4
970 #define DBG_STATUS_FATAL 5
971 #define DBG_STATUS_DEBUG_CONTROL 6
972 #define DBG_STATUS_WORKER 7
973
974 #define KI_USER_SHARED_DATA 0xffdf0000
975
976 #define PAGE_SIZE 0x1000
977 #define PAGE_SHIFT 12L
978
979 #define SharedUserData ((KUSER_SHARED_DATA * CONST) KI_USER_SHARED_DATA)
980
981 typedef enum _TRACE_INFORMATION_CLASS {
982 TraceIdClass,
983 TraceHandleClass,
984 TraceEnableFlagsClass,
985 TraceEnableLevelClass,
986 GlobalLoggerHandleClass,
987 EventLoggerHandleClass,
988 AllLoggerHandlesClass,
989 TraceHandleByNameClass,
990 LoggerEventsLostClass,
991 TraceSessionSettingsClass,
992 LoggerEventsLoggedClass,
993 MaxTraceInformationClass
994 } TRACE_INFORMATION_CLASS;
995
996 typedef enum _KINTERRUPT_POLARITY {
997 InterruptPolarityUnknown,
998 InterruptActiveHigh,
999 InterruptActiveLow
1000 } KINTERRUPT_POLARITY, *PKINTERRUPT_POLARITY;
1001
1002 typedef enum _KPROFILE_SOURCE {
1003 ProfileTime,
1004 ProfileAlignmentFixup,
1005 ProfileTotalIssues,
1006 ProfilePipelineDry,
1007 ProfileLoadInstructions,
1008 ProfilePipelineFrozen,
1009 ProfileBranchInstructions,
1010 ProfileTotalNonissues,
1011 ProfileDcacheMisses,
1012 ProfileIcacheMisses,
1013 ProfileCacheMisses,
1014 ProfileBranchMispredictions,
1015 ProfileStoreInstructions,
1016 ProfileFpInstructions,
1017 ProfileIntegerInstructions,
1018 Profile2Issue,
1019 Profile3Issue,
1020 Profile4Issue,
1021 ProfileSpecialInstructions,
1022 ProfileTotalCycles,
1023 ProfileIcacheIssues,
1024 ProfileDcacheAccesses,
1025 ProfileMemoryBarrierCycles,
1026 ProfileLoadLinkedIssues,
1027 ProfileMaximum
1028 } KPROFILE_SOURCE;
1029
1030 typedef enum _KWAIT_REASON {
1031 Executive,
1032 FreePage,
1033 PageIn,
1034 PoolAllocation,
1035 DelayExecution,
1036 Suspended,
1037 UserRequest,
1038 WrExecutive,
1039 WrFreePage,
1040 WrPageIn,
1041 WrPoolAllocation,
1042 WrDelayExecution,
1043 WrSuspended,
1044 WrUserRequest,
1045 WrEventPair,
1046 WrQueue,
1047 WrLpcReceive,
1048 WrLpcReply,
1049 WrVirtualMemory,
1050 WrPageOut,
1051 WrRendezvous,
1052 WrKeyedEvent,
1053 WrTerminated,
1054 WrProcessInSwap,
1055 WrCpuRateControl,
1056 WrCalloutStack,
1057 WrKernel,
1058 WrResource,
1059 WrPushLock,
1060 WrMutex,
1061 WrQuantumEnd,
1062 WrDispatchInt,
1063 WrPreempted,
1064 WrYieldExecution,
1065 WrFastMutex,
1066 WrGuardedMutex,
1067 WrRundown,
1068 MaximumWaitReason
1069 } KWAIT_REASON;
1070
1071 typedef struct _KWAIT_BLOCK {
1072 LIST_ENTRY WaitListEntry;
1073 struct _KTHREAD *Thread;
1074 PVOID Object;
1075 struct _KWAIT_BLOCK *NextWaitBlock;
1076 USHORT WaitKey;
1077 UCHAR WaitType;
1078 volatile UCHAR BlockState;
1079
1080 #if defined(_WIN64)
1081
1082 LONG SpareLong;
1083
1084 #endif
1085
1086 } KWAIT_BLOCK, *PKWAIT_BLOCK, *PRKWAIT_BLOCK;
1087
1088 typedef enum _KINTERRUPT_MODE {
1089 LevelSensitive,
1090 Latched
1091 } KINTERRUPT_MODE;
1092
1093 #define THREAD_WAIT_OBJECTS 3
1094
1095 typedef VOID
1096 (DDKAPI *PKINTERRUPT_ROUTINE)(
1097 VOID);
1098
1099 typedef enum _KD_OPTION {
1100 KD_OPTION_SET_BLOCK_ENABLE,
1101 } KD_OPTION;
1102
1103 typedef enum _INTERFACE_TYPE {
1104 InterfaceTypeUndefined = -1,
1105 Internal,
1106 Isa,
1107 Eisa,
1108 MicroChannel,
1109 TurboChannel,
1110 PCIBus,
1111 VMEBus,
1112 NuBus,
1113 PCMCIABus,
1114 CBus,
1115 MPIBus,
1116 MPSABus,
1117 ProcessorInternal,
1118 InternalPowerBus,
1119 PNPISABus,
1120 PNPBus,
1121 MaximumInterfaceType
1122 } INTERFACE_TYPE, *PINTERFACE_TYPE;
1123
1124 typedef VOID
1125 (DDKAPI *PKNORMAL_ROUTINE)(
1126 IN PVOID NormalContext,
1127 IN PVOID SystemArgument1,
1128 IN PVOID SystemArgument2);
1129
1130 typedef VOID
1131 (DDKAPI *PKRUNDOWN_ROUTINE)(
1132 IN struct _KAPC *Apc);
1133
1134 typedef VOID
1135 (DDKAPI *PKKERNEL_ROUTINE)(
1136 IN struct _KAPC *Apc,
1137 IN OUT PKNORMAL_ROUTINE *NormalRoutine,
1138 IN OUT PVOID *NormalContext,
1139 IN OUT PVOID *SystemArgument1,
1140 IN OUT PVOID *SystemArgument2);
1141
1142 typedef struct _KAPC
1143 {
1144 UCHAR Type;
1145 UCHAR SpareByte0;
1146 UCHAR Size;
1147 UCHAR SpareByte1;
1148 ULONG SpareLong0;
1149 struct _KTHREAD *Thread;
1150 LIST_ENTRY ApcListEntry;
1151 PKKERNEL_ROUTINE KernelRoutine;
1152 PKRUNDOWN_ROUTINE RundownRoutine;
1153 PKNORMAL_ROUTINE NormalRoutine;
1154 PVOID NormalContext;
1155 PVOID SystemArgument1;
1156 PVOID SystemArgument2;
1157 CCHAR ApcStateIndex;
1158 KPROCESSOR_MODE ApcMode;
1159 BOOLEAN Inserted;
1160 } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
1161
1162 typedef struct _KDEVICE_QUEUE_ENTRY {
1163 LIST_ENTRY DeviceListEntry;
1164 ULONG SortKey;
1165 BOOLEAN Inserted;
1166 } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY,
1167 *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
1168
1169 typedef PVOID PKIPI_CONTEXT;
1170
1171 typedef
1172 VOID
1173 (NTAPI *PKIPI_WORKER)(
1174 IN PKIPI_CONTEXT PacketContext,
1175 IN PVOID Parameter1,
1176 IN PVOID Parameter2,
1177 IN PVOID Parameter3
1178 );
1179
1180 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
1181
1182 typedef struct _KSPIN_LOCK_QUEUE {
1183 struct _KSPIN_LOCK_QUEUE *volatile Next;
1184 PKSPIN_LOCK volatile Lock;
1185 } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
1186
1187 typedef struct _KLOCK_QUEUE_HANDLE {
1188 KSPIN_LOCK_QUEUE LockQueue;
1189 KIRQL OldIrql;
1190 } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
1191
1192 #if defined(_AMD64_)
1193
1194 typedef ULONG64 KSPIN_LOCK_QUEUE_NUMBER;
1195
1196 #define LockQueueDispatcherLock 0
1197 #define LockQueueExpansionLock 1
1198 #define LockQueuePfnLock 2
1199 #define LockQueueSystemSpaceLock 3
1200 #define LockQueueVacbLock 4
1201 #define LockQueueMasterLock 5
1202 #define LockQueueNonPagedPoolLock 6
1203 #define LockQueueIoCancelLock 7
1204 #define LockQueueWorkQueueLock 8
1205 #define LockQueueIoVpbLock 9
1206 #define LockQueueIoDatabaseLock 10
1207 #define LockQueueIoCompletionLock 11
1208 #define LockQueueNtfsStructLock 12
1209 #define LockQueueAfdWorkQueueLock 13
1210 #define LockQueueBcbLock 14
1211 #define LockQueueMmNonPagedPoolLock 15
1212 #define LockQueueUnusedSpare16 16
1213 #define LockQueueTimerTableLock 17
1214 #define LockQueueMaximumLock (LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS)
1215
1216 #else
1217
1218 typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
1219 LockQueueDispatcherLock,
1220 LockQueueExpansionLock,
1221 LockQueuePfnLock,
1222 LockQueueSystemSpaceLock,
1223 LockQueueVacbLock,
1224 LockQueueMasterLock,
1225 LockQueueNonPagedPoolLock,
1226 LockQueueIoCancelLock,
1227 LockQueueWorkQueueLock,
1228 LockQueueIoVpbLock,
1229 LockQueueIoDatabaseLock,
1230 LockQueueIoCompletionLock,
1231 LockQueueNtfsStructLock,
1232 LockQueueAfdWorkQueueLock,
1233 LockQueueBcbLock,
1234 LockQueueMmNonPagedPoolLock,
1235 LockQueueUnusedSpare16,
1236 LockQueueTimerTableLock,
1237 LockQueueMaximumLock = LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS
1238 } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
1239
1240 #endif
1241
1242 typedef VOID
1243 (DDKAPI *PKDEFERRED_ROUTINE)(
1244 IN struct _KDPC *Dpc,
1245 IN PVOID DeferredContext,
1246 IN PVOID SystemArgument1,
1247 IN PVOID SystemArgument2);
1248
1249 typedef struct _KDPC
1250 {
1251 UCHAR Type;
1252 UCHAR Importance;
1253 volatile USHORT Number;
1254 LIST_ENTRY DpcListEntry;
1255 PKDEFERRED_ROUTINE DeferredRoutine;
1256 PVOID DeferredContext;
1257 PVOID SystemArgument1;
1258 PVOID SystemArgument2;
1259 volatile PVOID DpcData;
1260 } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
1261
1262 typedef enum _IO_ALLOCATION_ACTION {
1263 KeepObject = 1,
1264 DeallocateObject,
1265 DeallocateObjectKeepRegisters
1266 } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
1267
1268 typedef IO_ALLOCATION_ACTION
1269 (DDKAPI *PDRIVER_CONTROL)(
1270 IN struct _DEVICE_OBJECT *DeviceObject,
1271 IN struct _IRP *Irp,
1272 IN PVOID MapRegisterBase,
1273 IN PVOID Context);
1274
1275 typedef struct _WAIT_CONTEXT_BLOCK {
1276 KDEVICE_QUEUE_ENTRY WaitQueueEntry;
1277 PDRIVER_CONTROL DeviceRoutine;
1278 PVOID DeviceContext;
1279 ULONG NumberOfMapRegisters;
1280 PVOID DeviceObject;
1281 PVOID CurrentIrp;
1282 PKDPC BufferChainingDpc;
1283 } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
1284
1285 typedef struct _KDEVICE_QUEUE {
1286 CSHORT Type;
1287 CSHORT Size;
1288 LIST_ENTRY DeviceListHead;
1289 KSPIN_LOCK Lock;
1290 #if defined(_AMD64_)
1291 union {
1292 BOOLEAN Busy;
1293 struct {
1294 LONG64 Reserved : 8;
1295 LONG64 Hint : 56;
1296 };
1297 };
1298 #else
1299 BOOLEAN Busy;
1300 #endif
1301
1302 } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
1303
1304 typedef struct _DISPATCHER_HEADER
1305 {
1306 __GNU_EXTENSION union
1307 {
1308 __GNU_EXTENSION struct
1309 {
1310 UCHAR Type;
1311 __GNU_EXTENSION union
1312 {
1313 UCHAR Absolute;
1314 UCHAR NpxIrql;
1315 };
1316 __GNU_EXTENSION union
1317 {
1318 UCHAR Size;
1319 UCHAR Hand;
1320 };
1321 __GNU_EXTENSION union
1322 {
1323 UCHAR Inserted;
1324 BOOLEAN DebugActive;
1325 };
1326 };
1327 volatile LONG Lock;
1328 };
1329 LONG SignalState;
1330 LIST_ENTRY WaitListHead;
1331 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
1332
1333 typedef struct _KGATE
1334 {
1335 DISPATCHER_HEADER Header;
1336 } KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
1337
1338 typedef struct _KGUARDED_MUTEX
1339 {
1340 volatile LONG Count;
1341 PKTHREAD Owner;
1342 ULONG Contention;
1343 KGATE Gate;
1344 __GNU_EXTENSION union
1345 {
1346 __GNU_EXTENSION struct
1347 {
1348 SHORT KernelApcDisable;
1349 SHORT SpecialApcDisable;
1350 };
1351 ULONG CombinedApcDisable;
1352 };
1353 } KGUARDED_MUTEX, *PKGUARDED_MUTEX;
1354
1355 typedef struct _KMUTANT {
1356 DISPATCHER_HEADER Header;
1357 LIST_ENTRY MutantListEntry;
1358 struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
1359 BOOLEAN Abandoned;
1360 UCHAR ApcDisable;
1361 } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
1362
1363 typedef struct _KTIMER {
1364 DISPATCHER_HEADER Header;
1365 ULARGE_INTEGER DueTime;
1366 LIST_ENTRY TimerListEntry;
1367 struct _KDPC *Dpc;
1368 #if !defined(_X86_)
1369 ULONG Processor;
1370 #endif
1371 ULONG Period;
1372 } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
1373
1374 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
1375 {
1376 StandardDesign,
1377 NEC98x86,
1378 EndAlternatives
1379 } ALTERNATIVE_ARCHITECTURE_TYPE;
1380
1381 typedef struct _KSYSTEM_TIME
1382 {
1383 ULONG LowPart;
1384 LONG High1Time;
1385 LONG High2Time;
1386 } KSYSTEM_TIME, *PKSYSTEM_TIME;
1387
1388 typedef struct _KEVENT {
1389 DISPATCHER_HEADER Header;
1390 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
1391
1392 typedef struct _KSEMAPHORE {
1393 DISPATCHER_HEADER Header;
1394 LONG Limit;
1395 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
1396
1397 typedef struct _PNP_BUS_INFORMATION {
1398 GUID BusTypeGuid;
1399 INTERFACE_TYPE LegacyBusType;
1400 ULONG BusNumber;
1401 } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
1402
1403 typedef struct DECLSPEC_ALIGN(16) _M128A {
1404 ULONGLONG Low;
1405 LONGLONG High;
1406 } M128A, *PM128A;
1407
1408 typedef struct DECLSPEC_ALIGN(16) _XSAVE_FORMAT {
1409 USHORT ControlWord;
1410 USHORT StatusWord;
1411 UCHAR TagWord;
1412 UCHAR Reserved1;
1413 USHORT ErrorOpcode;
1414 ULONG ErrorOffset;
1415 USHORT ErrorSelector;
1416 USHORT Reserved2;
1417 ULONG DataOffset;
1418 USHORT DataSelector;
1419 USHORT Reserved3;
1420 ULONG MxCsr;
1421 ULONG MxCsr_Mask;
1422 M128A FloatRegisters[8];
1423
1424 #if defined(_WIN64)
1425
1426 M128A XmmRegisters[16];
1427 UCHAR Reserved4[96];
1428
1429 #else
1430
1431 M128A XmmRegisters[8];
1432 UCHAR Reserved4[192];
1433
1434 ULONG StackControl[7];
1435 ULONG Cr0NpxState;
1436
1437 #endif
1438
1439 } XSAVE_FORMAT, *PXSAVE_FORMAT;
1440
1441 #ifdef _AMD64_
1442
1443 typedef XSAVE_FORMAT XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
1444
1445 #endif // _AMD64_
1446
1447 /******************************************************************************
1448 * Memory manager Types *
1449 ******************************************************************************/
1450
1451 #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
1452 #define MDL_PAGES_LOCKED 0x0002
1453 #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
1454 #define MDL_ALLOCATED_FIXED_SIZE 0x0008
1455 #define MDL_PARTIAL 0x0010
1456 #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
1457 #define MDL_IO_PAGE_READ 0x0040
1458 #define MDL_WRITE_OPERATION 0x0080
1459 #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
1460 #define MDL_FREE_EXTRA_PTES 0x0200
1461 #define MDL_DESCRIBES_AWE 0x0400
1462 #define MDL_IO_SPACE 0x0800
1463 #define MDL_NETWORK_HEADER 0x1000
1464 #define MDL_MAPPING_CAN_FAIL 0x2000
1465 #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
1466 #define MDL_INTERNAL 0x8000
1467
1468 #define MDL_MAPPING_FLAGS ( \
1469 MDL_MAPPED_TO_SYSTEM_VA | \
1470 MDL_PAGES_LOCKED | \
1471 MDL_SOURCE_IS_NONPAGED_POOL | \
1472 MDL_PARTIAL_HAS_BEEN_MAPPED | \
1473 MDL_PARENT_MAPPED_SYSTEM_VA | \
1474 MDL_SYSTEM_VA | \
1475 MDL_IO_SPACE)
1476
1477 #define FLUSH_MULTIPLE_MAXIMUM 32
1478
1479 typedef struct _MDL {
1480 struct _MDL *Next;
1481 CSHORT Size;
1482 CSHORT MdlFlags;
1483 struct _EPROCESS *Process;
1484 PVOID MappedSystemVa;
1485 PVOID StartVa;
1486 ULONG ByteCount;
1487 ULONG ByteOffset;
1488 } MDL, *PMDL;
1489
1490 typedef enum _MEMORY_CACHING_TYPE_ORIG {
1491 MmFrameBufferCached = 2
1492 } MEMORY_CACHING_TYPE_ORIG;
1493
1494 typedef enum _MEMORY_CACHING_TYPE {
1495 MmNonCached = FALSE,
1496 MmCached = TRUE,
1497 MmWriteCombined = MmFrameBufferCached,
1498 MmHardwareCoherentCached,
1499 MmNonCachedUnordered,
1500 MmUSWCCached,
1501 MmMaximumCacheType
1502 } MEMORY_CACHING_TYPE;
1503
1504 typedef enum _MM_PAGE_PRIORITY {
1505 LowPagePriority,
1506 NormalPagePriority = 16,
1507 HighPagePriority = 32
1508 } MM_PAGE_PRIORITY;
1509
1510 typedef enum _LOCK_OPERATION {
1511 IoReadAccess,
1512 IoWriteAccess,
1513 IoModifyAccess
1514 } LOCK_OPERATION;
1515
1516 typedef enum _MM_SYSTEM_SIZE {
1517 MmSmallSystem,
1518 MmMediumSystem,
1519 MmLargeSystem
1520 } MM_SYSTEMSIZE;
1521
1522
1523
1524 /******************************************************************************
1525 * Memory manager Functions *
1526 ******************************************************************************/
1527
1528 /* PVOID MmGetSystemAddressForMdl(
1529 * IN PMDL Mdl);
1530 */
1531 #define MmGetSystemAddressForMdl(Mdl) \
1532 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
1533 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1534 ((Mdl)->MappedSystemVa) : \
1535 (MmMapLockedPages((Mdl), KernelMode)))
1536
1537 /* PVOID
1538 * MmGetSystemAddressForMdlSafe(
1539 * IN PMDL Mdl,
1540 * IN MM_PAGE_PRIORITY Priority)
1541 */
1542 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
1543 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
1544 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1545 (_Mdl)->MappedSystemVa : \
1546 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
1547 KernelMode, MmCached, NULL, FALSE, (_Priority)))
1548
1549 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1550 NTKERNELAPI
1551 PMDL
1552 NTAPI
1553 MmCreateMdl(
1554 IN PMDL MemoryDescriptorList OPTIONAL,
1555 IN PVOID Base,
1556 IN SIZE_T Length);
1557
1558 #endif
1559
1560 /******************************************************************************
1561 * Security Manager Types *
1562 ******************************************************************************/
1563
1564 //
1565 // Access/Security Stuff
1566 //
1567 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
1568 typedef PVOID PACCESS_TOKEN;
1569
1570 #define DELETE 0x00010000L
1571 #define READ_CONTROL 0x00020000L
1572 #define WRITE_DAC 0x00040000L
1573 #define WRITE_OWNER 0x00080000L
1574 #define SYNCHRONIZE 0x00100000L
1575 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
1576 #define STANDARD_RIGHTS_READ READ_CONTROL
1577 #define STANDARD_RIGHTS_WRITE READ_CONTROL
1578 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
1579 #define STANDARD_RIGHTS_ALL 0x001F0000L
1580 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
1581 #define ACCESS_SYSTEM_SECURITY 0x01000000L
1582 #define MAXIMUM_ALLOWED 0x02000000L
1583 #define GENERIC_READ 0x80000000L
1584 #define GENERIC_WRITE 0x40000000L
1585 #define GENERIC_EXECUTE 0x20000000L
1586 #define GENERIC_ALL 0x10000000L
1587
1588 typedef struct _GENERIC_MAPPING {
1589 ACCESS_MASK GenericRead;
1590 ACCESS_MASK GenericWrite;
1591 ACCESS_MASK GenericExecute;
1592 ACCESS_MASK GenericAll;
1593 } GENERIC_MAPPING, *PGENERIC_MAPPING;
1594
1595 #define ACL_REVISION 2
1596 #define ACL_REVISION_DS 4
1597
1598 #define ACL_REVISION1 1
1599 #define ACL_REVISION2 2
1600 #define ACL_REVISION3 3
1601 #define ACL_REVISION4 4
1602 #define MIN_ACL_REVISION ACL_REVISION2
1603 #define MAX_ACL_REVISION ACL_REVISION4
1604
1605 typedef struct _ACL {
1606 UCHAR AclRevision;
1607 UCHAR Sbz1;
1608 USHORT AclSize;
1609 USHORT AceCount;
1610 USHORT Sbz2;
1611 } ACL, *PACL;
1612
1613 //
1614 // Current security descriptor revision value
1615 //
1616 #define SECURITY_DESCRIPTOR_REVISION (1)
1617 #define SECURITY_DESCRIPTOR_REVISION1 (1)
1618
1619 //
1620 // Privilege attributes
1621 //
1622 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
1623 #define SE_PRIVILEGE_ENABLED (0x00000002L)
1624 #define SE_PRIVILEGE_REMOVED (0X00000004L)
1625 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
1626
1627 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
1628 SE_PRIVILEGE_ENABLED | \
1629 SE_PRIVILEGE_REMOVED | \
1630 SE_PRIVILEGE_USED_FOR_ACCESS)
1631
1632 #include <pshpack4.h>
1633 typedef struct _LUID_AND_ATTRIBUTES {
1634 LUID Luid;
1635 ULONG Attributes;
1636 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
1637 #include <poppack.h>
1638
1639 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
1640 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
1641
1642 //
1643 // Privilege sets
1644 //
1645 #define PRIVILEGE_SET_ALL_NECESSARY (1)
1646
1647 typedef struct _PRIVILEGE_SET {
1648 ULONG PrivilegeCount;
1649 ULONG Control;
1650 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
1651 } PRIVILEGE_SET,*PPRIVILEGE_SET;
1652
1653 typedef enum _SECURITY_IMPERSONATION_LEVEL {
1654 SecurityAnonymous,
1655 SecurityIdentification,
1656 SecurityImpersonation,
1657 SecurityDelegation
1658 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
1659
1660 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
1661 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
1662 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
1663 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
1664
1665 #define SECURITY_DYNAMIC_TRACKING (TRUE)
1666 #define SECURITY_STATIC_TRACKING (FALSE)
1667
1668 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
1669
1670 typedef struct _SECURITY_QUALITY_OF_SERVICE {
1671 ULONG Length;
1672 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1673 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
1674 BOOLEAN EffectiveOnly;
1675 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
1676
1677 typedef struct _SE_IMPERSONATION_STATE {
1678 PACCESS_TOKEN Token;
1679 BOOLEAN CopyOnOpen;
1680 BOOLEAN EffectiveOnly;
1681 SECURITY_IMPERSONATION_LEVEL Level;
1682 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
1683
1684 #define OWNER_SECURITY_INFORMATION (0x00000001L)
1685 #define GROUP_SECURITY_INFORMATION (0x00000002L)
1686 #define DACL_SECURITY_INFORMATION (0x00000004L)
1687 #define SACL_SECURITY_INFORMATION (0x00000008L)
1688 #define LABEL_SECURITY_INFORMATION (0x00000010L)
1689
1690 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
1691 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
1692 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
1693 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
1694
1695 typedef enum _SECURITY_OPERATION_CODE {
1696 SetSecurityDescriptor,
1697 QuerySecurityDescriptor,
1698 DeleteSecurityDescriptor,
1699 AssignSecurityDescriptor
1700 } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
1701
1702 #define INITIAL_PRIVILEGE_COUNT 3
1703
1704 typedef struct _INITIAL_PRIVILEGE_SET {
1705 ULONG PrivilegeCount;
1706 ULONG Control;
1707 LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
1708 } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
1709
1710 #define SE_MIN_WELL_KNOWN_PRIVILEGE 2
1711 #define SE_CREATE_TOKEN_PRIVILEGE 2
1712 #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3
1713 #define SE_LOCK_MEMORY_PRIVILEGE 4
1714 #define SE_INCREASE_QUOTA_PRIVILEGE 5
1715 #define SE_MACHINE_ACCOUNT_PRIVILEGE 6
1716 #define SE_TCB_PRIVILEGE 7
1717 #define SE_SECURITY_PRIVILEGE 8
1718 #define SE_TAKE_OWNERSHIP_PRIVILEGE 9
1719 #define SE_LOAD_DRIVER_PRIVILEGE 10
1720 #define SE_SYSTEM_PROFILE_PRIVILEGE 11
1721 #define SE_SYSTEMTIME_PRIVILEGE 12
1722 #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13
1723 #define SE_INC_BASE_PRIORITY_PRIVILEGE 14
1724 #define SE_CREATE_PAGEFILE_PRIVILEGE 15
1725 #define SE_CREATE_PERMANENT_PRIVILEGE 16
1726 #define SE_BACKUP_PRIVILEGE 17
1727 #define SE_RESTORE_PRIVILEGE 18
1728 #define SE_SHUTDOWN_PRIVILEGE 19
1729 #define SE_DEBUG_PRIVILEGE 20
1730 #define SE_AUDIT_PRIVILEGE 21
1731 #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22
1732 #define SE_CHANGE_NOTIFY_PRIVILEGE 23
1733 #define SE_REMOTE_SHUTDOWN_PRIVILEGE 24
1734 #define SE_UNDOCK_PRIVILEGE 25
1735 #define SE_SYNC_AGENT_PRIVILEGE 26
1736 #define SE_ENABLE_DELEGATION_PRIVILEGE 27
1737 #define SE_MANAGE_VOLUME_PRIVILEGE 28
1738 #define SE_IMPERSONATE_PRIVILEGE 29
1739 #define SE_CREATE_GLOBAL_PRIVILEGE 30
1740 #define SE_TRUSTED_CREDMAN_ACCESS_PRIVILEGE 31
1741 #define SE_RELABEL_PRIVILEGE 32
1742 #define SE_INC_WORKING_SET_PRIVILEGE 33
1743 #define SE_TIME_ZONE_PRIVILEGE 34
1744 #define SE_CREATE_SYMBOLIC_LINK_PRIVILEGE 35
1745 #define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_SYMBOLIC_LINK_PRIVILEGE
1746
1747 typedef struct _SECURITY_SUBJECT_CONTEXT {
1748 PACCESS_TOKEN ClientToken;
1749 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1750 PACCESS_TOKEN PrimaryToken;
1751 PVOID ProcessAuditId;
1752 } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
1753
1754 #include <pshpack4.h>
1755 typedef struct _ACCESS_STATE {
1756 LUID OperationID;
1757 BOOLEAN SecurityEvaluated;
1758 BOOLEAN GenerateAudit;
1759 BOOLEAN GenerateOnClose;
1760 BOOLEAN PrivilegesAllocated;
1761 ULONG Flags;
1762 ACCESS_MASK RemainingDesiredAccess;
1763 ACCESS_MASK PreviouslyGrantedAccess;
1764 ACCESS_MASK OriginalDesiredAccess;
1765 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
1766 PSECURITY_DESCRIPTOR SecurityDescriptor;
1767 PVOID AuxData;
1768 union {
1769 INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
1770 PRIVILEGE_SET PrivilegeSet;
1771 } Privileges;
1772
1773 BOOLEAN AuditPrivileges;
1774 UNICODE_STRING ObjectName;
1775 UNICODE_STRING ObjectTypeName;
1776 } ACCESS_STATE, *PACCESS_STATE;
1777 #include <poppack.h>
1778
1779 /******************************************************************************
1780 * Configuration Manager Types *
1781 ******************************************************************************/
1782
1783 /* KEY_VALUE_Xxx.Type */
1784
1785 #define REG_NONE 0
1786 #define REG_SZ 1
1787 #define REG_EXPAND_SZ 2
1788 #define REG_BINARY 3
1789 #define REG_DWORD 4
1790 #define REG_DWORD_LITTLE_ENDIAN 4
1791 #define REG_DWORD_BIG_ENDIAN 5
1792 #define REG_LINK 6
1793 #define REG_MULTI_SZ 7
1794 #define REG_RESOURCE_LIST 8
1795 #define REG_FULL_RESOURCE_DESCRIPTOR 9
1796 #define REG_RESOURCE_REQUIREMENTS_LIST 10
1797 #define REG_QWORD 11
1798 #define REG_QWORD_LITTLE_ENDIAN 11
1799
1800 //
1801 // Registry Access Rights
1802 //
1803 #define KEY_QUERY_VALUE (0x0001)
1804 #define KEY_SET_VALUE (0x0002)
1805 #define KEY_CREATE_SUB_KEY (0x0004)
1806 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
1807 #define KEY_NOTIFY (0x0010)
1808 #define KEY_CREATE_LINK (0x0020)
1809 #define KEY_WOW64_32KEY (0x0200)
1810 #define KEY_WOW64_64KEY (0x0100)
1811 #define KEY_WOW64_RES (0x0300)
1812
1813 #define KEY_READ ((STANDARD_RIGHTS_READ |\
1814 KEY_QUERY_VALUE |\
1815 KEY_ENUMERATE_SUB_KEYS |\
1816 KEY_NOTIFY) \
1817 & \
1818 (~SYNCHRONIZE))
1819
1820 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
1821 KEY_SET_VALUE |\
1822 KEY_CREATE_SUB_KEY) \
1823 & \
1824 (~SYNCHRONIZE))
1825
1826 #define KEY_EXECUTE ((KEY_READ) \
1827 & \
1828 (~SYNCHRONIZE))
1829
1830 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
1831 KEY_QUERY_VALUE |\
1832 KEY_SET_VALUE |\
1833 KEY_CREATE_SUB_KEY |\
1834 KEY_ENUMERATE_SUB_KEYS |\
1835 KEY_NOTIFY |\
1836 KEY_CREATE_LINK) \
1837 & \
1838 (~SYNCHRONIZE))
1839
1840 //
1841 // Registry Open/Create Options
1842 //
1843 #define REG_OPTION_RESERVED (0x00000000L)
1844 #define REG_OPTION_NON_VOLATILE (0x00000000L)
1845 #define REG_OPTION_VOLATILE (0x00000001L)
1846 #define REG_OPTION_CREATE_LINK (0x00000002L)
1847 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
1848 #define REG_OPTION_OPEN_LINK (0x00000008L)
1849
1850 #define REG_LEGAL_OPTION \
1851 (REG_OPTION_RESERVED |\
1852 REG_OPTION_NON_VOLATILE |\
1853 REG_OPTION_VOLATILE |\
1854 REG_OPTION_CREATE_LINK |\
1855 REG_OPTION_BACKUP_RESTORE |\
1856 REG_OPTION_OPEN_LINK)
1857
1858 //
1859 // Key creation/open disposition
1860 //
1861 #define REG_CREATED_NEW_KEY (0x00000001L)
1862 #define REG_OPENED_EXISTING_KEY (0x00000002L)
1863
1864 //
1865 // Key restore & hive load flags
1866 //
1867 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
1868 #define REG_REFRESH_HIVE (0x00000002L)
1869 #define REG_NO_LAZY_FLUSH (0x00000004L)
1870 #define REG_FORCE_RESTORE (0x00000008L)
1871 #define REG_APP_HIVE (0x00000010L)
1872 #define REG_PROCESS_PRIVATE (0x00000020L)
1873 #define REG_START_JOURNAL (0x00000040L)
1874 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
1875 #define REG_HIVE_NO_RM (0x00000100L)
1876 #define REG_HIVE_SINGLE_LOG (0x00000200L)
1877
1878 //
1879 // Unload Flags
1880 //
1881 #define REG_FORCE_UNLOAD 1
1882
1883 //
1884 // Notify Filter Values
1885 //
1886 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
1887 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
1888 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
1889 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
1890
1891 #define REG_LEGAL_CHANGE_FILTER \
1892 (REG_NOTIFY_CHANGE_NAME |\
1893 REG_NOTIFY_CHANGE_ATTRIBUTES |\
1894 REG_NOTIFY_CHANGE_LAST_SET |\
1895 REG_NOTIFY_CHANGE_SECURITY)
1896
1897 typedef struct _CM_FLOPPY_DEVICE_DATA {
1898 USHORT Version;
1899 USHORT Revision;
1900 CHAR Size[8];
1901 ULONG MaxDensity;
1902 ULONG MountDensity;
1903 UCHAR StepRateHeadUnloadTime;
1904 UCHAR HeadLoadTime;
1905 UCHAR MotorOffTime;
1906 UCHAR SectorLengthCode;
1907 UCHAR SectorPerTrack;
1908 UCHAR ReadWriteGapLength;
1909 UCHAR DataTransferLength;
1910 UCHAR FormatGapLength;
1911 UCHAR FormatFillCharacter;
1912 UCHAR HeadSettleTime;
1913 UCHAR MotorSettleTime;
1914 UCHAR MaximumTrackValue;
1915 UCHAR DataTransferRate;
1916 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
1917
1918 #include <pshpack4.h>
1919 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
1920 UCHAR Type;
1921 UCHAR ShareDisposition;
1922 USHORT Flags;
1923 union {
1924 struct {
1925 PHYSICAL_ADDRESS Start;
1926 ULONG Length;
1927 } Generic;
1928 struct {
1929 PHYSICAL_ADDRESS Start;
1930 ULONG Length;
1931 } Port;
1932 struct {
1933 ULONG Level;
1934 ULONG Vector;
1935 KAFFINITY Affinity;
1936 } Interrupt;
1937 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1938 struct {
1939 __GNU_EXTENSION union {
1940 struct {
1941 USHORT Reserved;
1942 USHORT MessageCount;
1943 ULONG Vector;
1944 KAFFINITY Affinity;
1945 } Raw;
1946 struct {
1947 ULONG Level;
1948 ULONG Vector;
1949 KAFFINITY Affinity;
1950 } Translated;
1951 };
1952 } MessageInterrupt;
1953 #endif
1954 struct {
1955 PHYSICAL_ADDRESS Start;
1956 ULONG Length;
1957 } Memory;
1958 struct {
1959 ULONG Channel;
1960 ULONG Port;
1961 ULONG Reserved1;
1962 } Dma;
1963 struct {
1964 ULONG Data[3];
1965 } DevicePrivate;
1966 struct {
1967 ULONG Start;
1968 ULONG Length;
1969 ULONG Reserved;
1970 } BusNumber;
1971 struct {
1972 ULONG DataSize;
1973 ULONG Reserved1;
1974 ULONG Reserved2;
1975 } DeviceSpecificData;
1976 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1977 struct {
1978 PHYSICAL_ADDRESS Start;
1979 ULONG Length40;
1980 } Memory40;
1981 struct {
1982 PHYSICAL_ADDRESS Start;
1983 ULONG Length48;
1984 } Memory48;
1985 struct {
1986 PHYSICAL_ADDRESS Start;
1987 ULONG Length64;
1988 } Memory64;
1989 #endif
1990 } u;
1991 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
1992 #include <poppack.h>
1993
1994 #include <pshpack1.h>
1995 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
1996
1997 #define CmResourceTypeNull 0
1998 #define CmResourceTypePort 1
1999 #define CmResourceTypeInterrupt 2
2000 #define CmResourceTypeMemory 3
2001 #define CmResourceTypeDma 4
2002 #define CmResourceTypeDeviceSpecific 5
2003 #define CmResourceTypeBusNumber 6
2004 #define CmResourceTypeMemoryLarge 7
2005 #define CmResourceTypeNonArbitrated 128
2006 #define CmResourceTypeConfigData 128
2007 #define CmResourceTypeDevicePrivate 129
2008 #define CmResourceTypePcCardConfig 130
2009 #define CmResourceTypeMfCardConfig 131
2010
2011 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
2012
2013 typedef enum _CM_SHARE_DISPOSITION {
2014 CmResourceShareUndetermined,
2015 CmResourceShareDeviceExclusive,
2016 CmResourceShareDriverExclusive,
2017 CmResourceShareShared
2018 } CM_SHARE_DISPOSITION;
2019
2020 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
2021
2022 #define CM_RESOURCE_PORT_MEMORY 0x0000
2023 #define CM_RESOURCE_PORT_IO 0x0001
2024 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
2025 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
2026 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
2027 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
2028 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
2029 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
2030 #define CM_RESOURCE_PORT_BAR 0x0100
2031
2032 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
2033
2034 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
2035 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
2036 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
2037 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
2038
2039 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
2040
2041 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
2042 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
2043 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
2044 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
2045 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
2046 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
2047 #define CM_RESOURCE_MEMORY_24 0x0010
2048 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
2049 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
2050 #define CM_RESOURCE_MEMORY_BAR 0x0080
2051 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
2052
2053 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
2054
2055 #define CM_RESOURCE_DMA_8 0x0000
2056 #define CM_RESOURCE_DMA_16 0x0001
2057 #define CM_RESOURCE_DMA_32 0x0002
2058 #define CM_RESOURCE_DMA_8_AND_16 0x0004
2059 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
2060 #define CM_RESOURCE_DMA_TYPE_A 0x0010
2061 #define CM_RESOURCE_DMA_TYPE_B 0x0020
2062 #define CM_RESOURCE_DMA_TYPE_F 0x0040
2063
2064 typedef struct _CM_PARTIAL_RESOURCE_LIST {
2065 USHORT Version;
2066 USHORT Revision;
2067 ULONG Count;
2068 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
2069 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
2070
2071 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
2072 INTERFACE_TYPE InterfaceType;
2073 ULONG BusNumber;
2074 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
2075 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
2076
2077 typedef struct _CM_RESOURCE_LIST {
2078 ULONG Count;
2079 CM_FULL_RESOURCE_DESCRIPTOR List[1];
2080 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
2081
2082 typedef struct _CM_INT13_DRIVE_PARAMETER {
2083 USHORT DriveSelect;
2084 ULONG MaxCylinders;
2085 USHORT SectorsPerTrack;
2086 USHORT MaxHeads;
2087 USHORT NumberDrives;
2088 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
2089
2090 typedef struct _CM_PNP_BIOS_DEVICE_NODE
2091 {
2092 USHORT Size;
2093 UCHAR Node;
2094 ULONG ProductId;
2095 UCHAR DeviceType[3];
2096 USHORT DeviceAttributes;
2097 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
2098
2099 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
2100 {
2101 UCHAR Signature[4];
2102 UCHAR Revision;
2103 UCHAR Length;
2104 USHORT ControlField;
2105 UCHAR Checksum;
2106 ULONG EventFlagAddress;
2107 USHORT RealModeEntryOffset;
2108 USHORT RealModeEntrySegment;
2109 USHORT ProtectedModeEntryOffset;
2110 ULONG ProtectedModeCodeBaseAddress;
2111 ULONG OemDeviceId;
2112 USHORT RealModeDataBaseAddress;
2113 ULONG ProtectedModeDataBaseAddress;
2114 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
2115
2116 #include <poppack.h>
2117
2118 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
2119 {
2120 ULONG BytesPerSector;
2121 ULONG NumberOfCylinders;
2122 ULONG SectorsPerTrack;
2123 ULONG NumberOfHeads;
2124 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
2125
2126 typedef struct _CM_KEYBOARD_DEVICE_DATA {
2127 USHORT Version;
2128 USHORT Revision;
2129 UCHAR Type;
2130 UCHAR Subtype;
2131 USHORT KeyboardFlags;
2132 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
2133
2134 typedef struct _CM_MCA_POS_DATA {
2135 USHORT AdapterId;
2136 UCHAR PosData1;
2137 UCHAR PosData2;
2138 UCHAR PosData3;
2139 UCHAR PosData4;
2140 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
2141
2142 #if (NTDDI_VERSION >= NTDDI_WINXP)
2143 typedef struct CM_Power_Data_s {
2144 ULONG PD_Size;
2145 DEVICE_POWER_STATE PD_MostRecentPowerState;
2146 ULONG PD_Capabilities;
2147 ULONG PD_D1Latency;
2148 ULONG PD_D2Latency;
2149 ULONG PD_D3Latency;
2150 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
2151 SYSTEM_POWER_STATE PD_DeepestSystemWake;
2152 } CM_POWER_DATA, *PCM_POWER_DATA;
2153
2154 #define PDCAP_D0_SUPPORTED 0x00000001
2155 #define PDCAP_D1_SUPPORTED 0x00000002
2156 #define PDCAP_D2_SUPPORTED 0x00000004
2157 #define PDCAP_D3_SUPPORTED 0x00000008
2158 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
2159 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
2160 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
2161 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
2162 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
2163
2164 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
2165
2166 typedef struct _CM_SCSI_DEVICE_DATA {
2167 USHORT Version;
2168 USHORT Revision;
2169 UCHAR HostIdentifier;
2170 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
2171
2172 typedef struct _CM_SERIAL_DEVICE_DATA {
2173 USHORT Version;
2174 USHORT Revision;
2175 ULONG BaudClock;
2176 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
2177
2178 typedef enum _KEY_INFORMATION_CLASS {
2179 KeyBasicInformation,
2180 KeyNodeInformation,
2181 KeyFullInformation,
2182 KeyNameInformation,
2183 KeyCachedInformation,
2184 KeyFlagsInformation
2185 } KEY_INFORMATION_CLASS;
2186
2187 typedef struct _KEY_BASIC_INFORMATION {
2188 LARGE_INTEGER LastWriteTime;
2189 ULONG TitleIndex;
2190 ULONG NameLength;
2191 WCHAR Name[1];
2192 } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
2193
2194 typedef struct _KEY_FULL_INFORMATION {
2195 LARGE_INTEGER LastWriteTime;
2196 ULONG TitleIndex;
2197 ULONG ClassOffset;
2198 ULONG ClassLength;
2199 ULONG SubKeys;
2200 ULONG MaxNameLen;
2201 ULONG MaxClassLen;
2202 ULONG Values;
2203 ULONG MaxValueNameLen;
2204 ULONG MaxValueDataLen;
2205 WCHAR Class[1];
2206 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
2207
2208 typedef struct _KEY_NODE_INFORMATION {
2209 LARGE_INTEGER LastWriteTime;
2210 ULONG TitleIndex;
2211 ULONG ClassOffset;
2212 ULONG ClassLength;
2213 ULONG NameLength;
2214 WCHAR Name[1];
2215 } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
2216
2217 typedef struct _KEY_VALUE_BASIC_INFORMATION {
2218 ULONG TitleIndex;
2219 ULONG Type;
2220 ULONG NameLength;
2221 WCHAR Name[1];
2222 } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
2223
2224 typedef struct _KEY_VALUE_FULL_INFORMATION {
2225 ULONG TitleIndex;
2226 ULONG Type;
2227 ULONG DataOffset;
2228 ULONG DataLength;
2229 ULONG NameLength;
2230 WCHAR Name[1];
2231 } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
2232
2233 typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
2234 ULONG TitleIndex;
2235 ULONG Type;
2236 ULONG DataLength;
2237 UCHAR Data[1];
2238 } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
2239
2240 typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
2241 ULONG Type;
2242 ULONG DataLength;
2243 UCHAR Data[1];
2244 } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
2245
2246 typedef struct _KEY_VALUE_ENTRY {
2247 PUNICODE_STRING ValueName;
2248 ULONG DataLength;
2249 ULONG DataOffset;
2250 ULONG Type;
2251 } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
2252
2253 typedef enum _KEY_VALUE_INFORMATION_CLASS {
2254 KeyValueBasicInformation,
2255 KeyValueFullInformation,
2256 KeyValuePartialInformation,
2257 KeyValueFullInformationAlign64,
2258 KeyValuePartialInformationAlign64
2259 } KEY_VALUE_INFORMATION_CLASS;
2260
2261 typedef struct _KEY_WRITE_TIME_INFORMATION {
2262 LARGE_INTEGER LastWriteTime;
2263 } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
2264
2265 typedef enum _KEY_SET_INFORMATION_CLASS {
2266 KeyWriteTimeInformation,
2267 KeyWow64FlagsInformation,
2268 KeyControlFlagsInformation,
2269 KeySetVirtualizationInformation,
2270 KeySetDebugInformation,
2271 KeySetHandleTagsInformation,
2272 MaxKeySetInfoClass
2273 } KEY_SET_INFORMATION_CLASS;
2274
2275 typedef enum _REG_NOTIFY_CLASS {
2276 RegNtDeleteKey,
2277 RegNtPreDeleteKey = RegNtDeleteKey,
2278 RegNtSetValueKey,
2279 RegNtPreSetValueKey = RegNtSetValueKey,
2280 RegNtDeleteValueKey,
2281 RegNtPreDeleteValueKey = RegNtDeleteValueKey,
2282 RegNtSetInformationKey,
2283 RegNtPreSetInformationKey = RegNtSetInformationKey,
2284 RegNtRenameKey,
2285 RegNtPreRenameKey = RegNtRenameKey,
2286 RegNtEnumerateKey,
2287 RegNtPreEnumerateKey = RegNtEnumerateKey,
2288 RegNtEnumerateValueKey,
2289 RegNtPreEnumerateValueKey = RegNtEnumerateValueKey,
2290 RegNtQueryKey,
2291 RegNtPreQueryKey = RegNtQueryKey,
2292 RegNtQueryValueKey,
2293 RegNtPreQueryValueKey = RegNtQueryValueKey,
2294 RegNtQueryMultipleValueKey,
2295 RegNtPreQueryMultipleValueKey = RegNtQueryMultipleValueKey,
2296 RegNtPreCreateKey,
2297 RegNtPostCreateKey,
2298 RegNtPreOpenKey,
2299 RegNtPostOpenKey,
2300 RegNtKeyHandleClose,
2301 RegNtPreKeyHandleClose = RegNtKeyHandleClose,
2302 RegNtPostDeleteKey,
2303 RegNtPostSetValueKey,
2304 RegNtPostDeleteValueKey,
2305 RegNtPostSetInformationKey,
2306 RegNtPostRenameKey,
2307 RegNtPostEnumerateKey,
2308 RegNtPostEnumerateValueKey,
2309 RegNtPostQueryKey,
2310 RegNtPostQueryValueKey,
2311 RegNtPostQueryMultipleValueKey,
2312 RegNtPostKeyHandleClose,
2313 RegNtPreCreateKeyEx,
2314 RegNtPostCreateKeyEx,
2315 RegNtPreOpenKeyEx,
2316 RegNtPostOpenKeyEx,
2317 RegNtPreFlushKey,
2318 RegNtPostFlushKey,
2319 RegNtPreLoadKey,
2320 RegNtPostLoadKey,
2321 RegNtPreUnLoadKey,
2322 RegNtPostUnLoadKey,
2323 RegNtPreQueryKeySecurity,
2324 RegNtPostQueryKeySecurity,
2325 RegNtPreSetKeySecurity,
2326 RegNtPostSetKeySecurity,
2327 RegNtCallbackObjectContextCleanup,
2328 RegNtPreRestoreKey,
2329 RegNtPostRestoreKey,
2330 RegNtPreSaveKey,
2331 RegNtPostSaveKey,
2332 RegNtPreReplaceKey,
2333 RegNtPostReplaceKey,
2334 MaxRegNtNotifyClass
2335 } REG_NOTIFY_CLASS, *PREG_NOTIFY_CLASS;
2336
2337 typedef NTSTATUS
2338 (NTAPI *PEX_CALLBACK_FUNCTION)(
2339 IN PVOID CallbackContext,
2340 IN PVOID Argument1,
2341 IN PVOID Argument2
2342 );
2343
2344 typedef struct _REG_DELETE_KEY_INFORMATION {
2345 PVOID Object;
2346 PVOID CallContext;
2347 PVOID ObjectContext;
2348 PVOID Reserved;
2349 } REG_DELETE_KEY_INFORMATION, *PREG_DELETE_KEY_INFORMATION
2350 #if (NTDDI_VERSION >= NTDDI_VISTA)
2351 , REG_FLUSH_KEY_INFORMATION, *PREG_FLUSH_KEY_INFORMATION
2352 #endif
2353 ;
2354
2355 typedef struct _REG_SET_VALUE_KEY_INFORMATION {
2356 PVOID Object;
2357 PUNICODE_STRING ValueName;
2358 ULONG TitleIndex;
2359 ULONG Type;
2360 PVOID Data;
2361 ULONG DataSize;
2362 PVOID CallContext;
2363 PVOID ObjectContext;
2364 PVOID Reserved;
2365 } REG_SET_VALUE_KEY_INFORMATION, *PREG_SET_VALUE_KEY_INFORMATION;
2366
2367 typedef struct _REG_DELETE_VALUE_KEY_INFORMATION {
2368 PVOID Object;
2369 PUNICODE_STRING ValueName;
2370 PVOID CallContext;
2371 PVOID ObjectContext;
2372 PVOID Reserved;
2373 } REG_DELETE_VALUE_KEY_INFORMATION, *PREG_DELETE_VALUE_KEY_INFORMATION;
2374
2375 typedef struct _REG_SET_INFORMATION_KEY_INFORMATION {
2376 PVOID Object;
2377 KEY_SET_INFORMATION_CLASS KeySetInformationClass;
2378 PVOID KeySetInformation;
2379 ULONG KeySetInformationLength;
2380 PVOID CallContext;
2381 PVOID ObjectContext;
2382 PVOID Reserved;
2383 } REG_SET_INFORMATION_KEY_INFORMATION, *PREG_SET_INFORMATION_KEY_INFORMATION;
2384
2385 typedef struct _REG_ENUMERATE_KEY_INFORMATION {
2386 PVOID Object;
2387 ULONG Index;
2388 KEY_INFORMATION_CLASS KeyInformationClass;
2389 PVOID KeyInformation;
2390 ULONG Length;
2391 PULONG ResultLength;
2392 PVOID CallContext;
2393 PVOID ObjectContext;
2394 PVOID Reserved;
2395 } REG_ENUMERATE_KEY_INFORMATION, *PREG_ENUMERATE_KEY_INFORMATION;
2396
2397 typedef struct _REG_ENUMERATE_VALUE_KEY_INFORMATION {
2398 PVOID Object;
2399 ULONG Index;
2400 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
2401 PVOID KeyValueInformation;
2402 ULONG Length;
2403 PULONG ResultLength;
2404 PVOID CallContext;
2405 PVOID ObjectContext;
2406 PVOID Reserved;
2407 } REG_ENUMERATE_VALUE_KEY_INFORMATION, *PREG_ENUMERATE_VALUE_KEY_INFORMATION;
2408
2409 typedef struct _REG_QUERY_KEY_INFORMATION {
2410 PVOID Object;
2411 KEY_INFORMATION_CLASS KeyInformationClass;
2412 PVOID KeyInformation;
2413 ULONG Length;
2414 PULONG ResultLength;
2415 PVOID CallContext;
2416 PVOID ObjectContext;
2417 PVOID Reserved;
2418 } REG_QUERY_KEY_INFORMATION, *PREG_QUERY_KEY_INFORMATION;
2419
2420 typedef struct _REG_QUERY_VALUE_KEY_INFORMATION {
2421 PVOID Object;
2422 PUNICODE_STRING ValueName;
2423 KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass;
2424 PVOID KeyValueInformation;
2425 ULONG Length;
2426 PULONG ResultLength;
2427 PVOID CallContext;
2428 PVOID ObjectContext;
2429 PVOID Reserved;
2430 } REG_QUERY_VALUE_KEY_INFORMATION, *PREG_QUERY_VALUE_KEY_INFORMATION;
2431
2432 typedef struct _REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION {
2433 PVOID Object;
2434 PKEY_VALUE_ENTRY ValueEntries;
2435 ULONG EntryCount;
2436 PVOID ValueBuffer;
2437 PULONG BufferLength;
2438 PULONG RequiredBufferLength;
2439 PVOID CallContext;
2440 PVOID ObjectContext;
2441 PVOID Reserved;
2442 } REG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION, *PREG_QUERY_MULTIPLE_VALUE_KEY_INFORMATION;
2443
2444 typedef struct _REG_PRE_CREATE_KEY_INFORMATION {
2445 PUNICODE_STRING CompleteName;
2446 } REG_PRE_CREATE_KEY_INFORMATION, REG_PRE_OPEN_KEY_INFORMATION,*PREG_PRE_CREATE_KEY_INFORMATION, *PREG_PRE_OPEN_KEY_INFORMATION;;
2447
2448 typedef struct _REG_POST_CREATE_KEY_INFORMATION {
2449 PUNICODE_STRING CompleteName;
2450 PVOID Object;
2451 NTSTATUS Status;
2452 } REG_POST_CREATE_KEY_INFORMATION,REG_POST_OPEN_KEY_INFORMATION, *PREG_POST_CREATE_KEY_INFORMATION, *PREG_POST_OPEN_KEY_INFORMATION;
2453
2454 typedef struct _REG_POST_OPERATION_INFORMATION {
2455 PVOID Object;
2456 NTSTATUS Status;
2457 PVOID PreInformation;
2458 NTSTATUS ReturnStatus;
2459 PVOID CallContext;
2460 PVOID ObjectContext;
2461 PVOID Reserved;
2462 } REG_POST_OPERATION_INFORMATION,*PREG_POST_OPERATION_INFORMATION;
2463
2464 typedef struct _REG_KEY_HANDLE_CLOSE_INFORMATION {
2465 PVOID Object;
2466 PVOID CallContext;
2467 PVOID ObjectContext;
2468 PVOID Reserved;
2469 } REG_KEY_HANDLE_CLOSE_INFORMATION, *PREG_KEY_HANDLE_CLOSE_INFORMATION;
2470
2471 /******************************************************************************
2472 * I/O Manager Functions *
2473 ******************************************************************************/
2474
2475 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
2476 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
2477
2478 #define DMA_MACROS_DEFINED
2479
2480 FORCEINLINE
2481 NTSTATUS
2482 IoAllocateAdapterChannel(
2483 IN PADAPTER_OBJECT AdapterObject,
2484 IN PDEVICE_OBJECT DeviceObject,
2485 IN ULONG NumberOfMapRegisters,
2486 IN PDRIVER_CONTROL ExecutionRoutine,
2487 IN PVOID Context)
2488 {
2489 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
2490 AllocateAdapterChannel =
2491 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
2492 ASSERT(AllocateAdapterChannel);
2493 return AllocateAdapterChannel(DmaAdapter,
2494 DeviceObject,
2495 NumberOfMapRegisters,
2496 ExecutionRoutine,
2497 Context );
2498 }
2499
2500 FORCEINLINE
2501 BOOLEAN
2502 IoFlushAdapterBuffers(
2503 IN PADAPTER_OBJECT AdapterObject,
2504 IN PMDL Mdl,
2505 IN PVOID MapRegisterBase,
2506 IN PVOID CurrentVa,
2507 IN ULONG Length,
2508 IN BOOLEAN WriteToDevice)
2509 {
2510 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
2511 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
2512 ASSERT(FlushAdapterBuffers);
2513 return FlushAdapterBuffers(DmaAdapter,
2514 Mdl,
2515 MapRegisterBase,
2516 CurrentVa,
2517 Length,
2518 WriteToDevice );
2519 }
2520
2521 FORCEINLINE
2522 VOID
2523 IoFreeAdapterChannel(
2524 IN PADAPTER_OBJECT AdapterObject)
2525 {
2526 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
2527 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
2528 ASSERT(FreeAdapterChannel);
2529 FreeAdapterChannel(DmaAdapter);
2530 }
2531
2532 FORCEINLINE
2533 VOID
2534 IoFreeMapRegisters(
2535 IN PADAPTER_OBJECT AdapterObject,
2536 IN PVOID MapRegisterBase,
2537 IN ULONG NumberOfMapRegisters)
2538 {
2539 PFREE_MAP_REGISTERS FreeMapRegisters;
2540 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
2541 ASSERT(FreeMapRegisters);
2542 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
2543 }
2544
2545 FORCEINLINE
2546 PHYSICAL_ADDRESS
2547 IoMapTransfer(
2548 IN PDMA_ADAPTER DmaAdapter,
2549 IN PMDL Mdl,
2550 IN PVOID MapRegisterBase,
2551 IN PVOID CurrentVa,
2552 IN OUT PULONG Length,
2553 IN BOOLEAN WriteToDevice)
2554 {
2555 PMAP_TRANSFER MapTransfer;
2556
2557 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
2558 ASSERT(MapTransfer);
2559 return MapTransfer(DmaAdapter,
2560 Mdl,
2561 MapRegisterBase,
2562 CurrentVa,
2563 Length,
2564 WriteToDevice);
2565 }
2566 #endif
2567
2568 /* PCI_COMMON_CONFIG.Command */
2569
2570 #define PCI_ENABLE_IO_SPACE 0x0001
2571 #define PCI_ENABLE_MEMORY_SPACE 0x0002
2572 #define PCI_ENABLE_BUS_MASTER 0x0004
2573 #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
2574 #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
2575 #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
2576 #define PCI_ENABLE_PARITY 0x0040
2577 #define PCI_ENABLE_WAIT_CYCLE 0x0080
2578 #define PCI_ENABLE_SERR 0x0100
2579 #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200
2580 #define PCI_DISABLE_LEVEL_INTERRUPT 0x0400
2581
2582 /* PCI_COMMON_CONFIG.Status */
2583
2584 #define PCI_STATUS_INTERRUPT_PENDING 0x0008
2585 #define PCI_STATUS_CAPABILITIES_LIST 0x0010
2586 #define PCI_STATUS_66MHZ_CAPABLE 0x0020
2587 #define PCI_STATUS_UDF_SUPPORTED 0x0040
2588 #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080
2589 #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
2590 #define PCI_STATUS_DEVSEL 0x0600
2591 #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
2592 #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
2593 #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
2594 #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
2595 #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
2596
2597 /* PCI_COMMON_CONFIG.HeaderType */
2598
2599 #define PCI_MULTIFUNCTION 0x80
2600 #define PCI_DEVICE_TYPE 0x00
2601 #define PCI_BRIDGE_TYPE 0x01
2602 #define PCI_CARDBUS_BRIDGE_TYPE 0x02
2603
2604 #define PCI_CONFIGURATION_TYPE(PciData) \
2605 (((PPCI_COMMON_CONFIG) (PciData))->HeaderType & ~PCI_MULTIFUNCTION)
2606
2607 #define PCI_MULTIFUNCTION_DEVICE(PciData) \
2608 ((((PPCI_COMMON_CONFIG) (PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
2609
2610 /* PCI device classes */
2611
2612 #define PCI_CLASS_PRE_20 0x00
2613 #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
2614 #define PCI_CLASS_NETWORK_CTLR 0x02
2615 #define PCI_CLASS_DISPLAY_CTLR 0x03
2616 #define PCI_CLASS_MULTIMEDIA_DEV 0x04
2617 #define PCI_CLASS_MEMORY_CTLR 0x05
2618 #define PCI_CLASS_BRIDGE_DEV 0x06
2619 #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
2620 #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
2621 #define PCI_CLASS_INPUT_DEV 0x09
2622 #define PCI_CLASS_DOCKING_STATION 0x0a
2623 #define PCI_CLASS_PROCESSOR 0x0b
2624 #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
2625 #define PCI_CLASS_WIRELESS_CTLR 0x0d
2626 #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
2627 #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
2628 #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
2629 #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
2630
2631 /* PCI device subclasses for class 0 */
2632
2633 #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
2634 #define PCI_SUBCLASS_PRE_20_VGA 0x01
2635
2636 /* PCI device subclasses for class 1 (mass storage controllers)*/
2637
2638 #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
2639 #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
2640 #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
2641 #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
2642 #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
2643 #define PCI_SUBCLASS_MSC_OTHER 0x80
2644
2645 /* PCI device subclasses for class 2 (network controllers)*/
2646
2647 #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
2648 #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
2649 #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
2650 #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
2651 #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
2652 #define PCI_SUBCLASS_NET_OTHER 0x80
2653
2654 /* PCI device subclasses for class 3 (display controllers)*/
2655
2656 #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
2657 #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
2658 #define PCI_SUBCLASS_VID_3D_CTLR 0x02
2659 #define PCI_SUBCLASS_VID_OTHER 0x80
2660
2661 /* PCI device subclasses for class 4 (multimedia device)*/
2662
2663 #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
2664 #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
2665 #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
2666 #define PCI_SUBCLASS_MM_OTHER 0x80
2667
2668 /* PCI device subclasses for class 5 (memory controller)*/
2669
2670 #define PCI_SUBCLASS_MEM_RAM 0x00
2671 #define PCI_SUBCLASS_MEM_FLASH 0x01
2672 #define PCI_SUBCLASS_MEM_OTHER 0x80
2673
2674 /* PCI device subclasses for class 6 (bridge device)*/
2675
2676 #define PCI_SUBCLASS_BR_HOST 0x00
2677 #define PCI_SUBCLASS_BR_ISA 0x01
2678 #define PCI_SUBCLASS_BR_EISA 0x02
2679 #define PCI_SUBCLASS_BR_MCA 0x03
2680 #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
2681 #define PCI_SUBCLASS_BR_PCMCIA 0x05
2682 #define PCI_SUBCLASS_BR_NUBUS 0x06
2683 #define PCI_SUBCLASS_BR_CARDBUS 0x07
2684 #define PCI_SUBCLASS_BR_RACEWAY 0x08
2685 #define PCI_SUBCLASS_BR_OTHER 0x80
2686
2687 /* PCI device subclasses for class C (serial bus controller)*/
2688
2689 #define PCI_SUBCLASS_SB_IEEE1394 0x00
2690 #define PCI_SUBCLASS_SB_ACCESS 0x01
2691 #define PCI_SUBCLASS_SB_SSA 0x02
2692 #define PCI_SUBCLASS_SB_USB 0x03
2693 #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
2694 #define PCI_SUBCLASS_SB_SMBUS 0x05
2695
2696 #define PCI_MAX_DEVICES 32
2697 #define PCI_MAX_FUNCTION 8
2698 #define PCI_MAX_BRIDGE_NUMBER 0xFF
2699 #define PCI_INVALID_VENDORID 0xFFFF
2700 #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET(PCI_COMMON_CONFIG, DeviceSpecific))
2701
2702 #define PCI_ADDRESS_IO_SPACE 0x00000001
2703 #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006
2704 #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008
2705 #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
2706 #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
2707 #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
2708
2709 #define PCI_TYPE_32BIT 0
2710 #define PCI_TYPE_20BIT 2
2711 #define PCI_TYPE_64BIT 4
2712
2713 #define POOL_COLD_ALLOCATION 256
2714 #define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 8
2715 #define POOL_RAISE_IF_ALLOCATION_FAILURE 16
2716
2717 #define PCI_TYPE0_ADDRESSES 6
2718 #define PCI_TYPE1_ADDRESSES 2
2719 #define PCI_TYPE2_ADDRESSES 5
2720
2721 #define IO_TYPE_ADAPTER 1
2722 #define IO_TYPE_CONTROLLER 2
2723 #define IO_TYPE_DEVICE 3
2724 #define IO_TYPE_DRIVER 4
2725 #define IO_TYPE_FILE 5
2726 #define IO_TYPE_IRP 6
2727 #define IO_TYPE_MASTER_ADAPTER 7
2728 #define IO_TYPE_OPEN_PACKET 8
2729 #define IO_TYPE_TIMER 9
2730 #define IO_TYPE_VPB 10
2731 #define IO_TYPE_ERROR_LOG 11
2732 #define IO_TYPE_ERROR_MESSAGE 12
2733 #define IO_TYPE_DEVICE_OBJECT_EXTENSION 13
2734
2735 #define IO_TYPE_CSQ_IRP_CONTEXT 1
2736 #define IO_TYPE_CSQ 2
2737 #define IO_TYPE_CSQ_EX 3
2738
2739 /* IO_RESOURCE_DESCRIPTOR.Option */
2740
2741 #define IO_RESOURCE_PREFERRED 0x01
2742 #define IO_RESOURCE_DEFAULT 0x02
2743 #define IO_RESOURCE_ALTERNATIVE 0x08
2744
2745 /* DEVICE_OBJECT.Flags */
2746
2747 #define DO_VERIFY_VOLUME 0x00000002
2748 #define DO_BUFFERED_IO 0x00000004
2749 #define DO_EXCLUSIVE 0x00000008
2750 #define DO_DIRECT_IO 0x00000010
2751 #define DO_MAP_IO_BUFFER 0x00000020
2752 #define DO_DEVICE_INITIALIZING 0x00000080
2753 #define DO_SHUTDOWN_REGISTERED 0x00000800
2754 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
2755 #define DO_POWER_PAGABLE 0x00002000
2756 #define DO_POWER_INRUSH 0x00004000
2757
2758 /* DEVICE_OBJECT.Characteristics */
2759
2760 #define FILE_REMOVABLE_MEDIA 0x00000001
2761 #define FILE_READ_ONLY_DEVICE 0x00000002
2762 #define FILE_FLOPPY_DISKETTE 0x00000004
2763 #define FILE_WRITE_ONCE_MEDIA 0x00000008
2764 #define FILE_REMOTE_DEVICE 0x00000010
2765 #define FILE_DEVICE_IS_MOUNTED 0x00000020
2766 #define FILE_VIRTUAL_VOLUME 0x00000040
2767 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
2768 #define FILE_DEVICE_SECURE_OPEN 0x00000100
2769 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
2770 #define FILE_CHARACTERISTIC_TS_DEVICE 0x00001000
2771 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE 0x00002000
2772
2773 /* DEVICE_OBJECT.AlignmentRequirement */
2774
2775 #define FILE_BYTE_ALIGNMENT 0x00000000
2776 #define FILE_WORD_ALIGNMENT 0x00000001
2777 #define FILE_LONG_ALIGNMENT 0x00000003
2778 #define FILE_QUAD_ALIGNMENT 0x00000007
2779 #define FILE_OCTA_ALIGNMENT 0x0000000f
2780 #define FILE_32_BYTE_ALIGNMENT 0x0000001f
2781 #define FILE_64_BYTE_ALIGNMENT 0x0000003f
2782 #define FILE_128_BYTE_ALIGNMENT 0x0000007f
2783 #define FILE_256_BYTE_ALIGNMENT 0x000000ff
2784 #define FILE_512_BYTE_ALIGNMENT 0x000001ff
2785
2786 /* DEVICE_OBJECT.DeviceType */
2787
2788 #define DEVICE_TYPE ULONG
2789
2790 #define FILE_DEVICE_BEEP 0x00000001
2791 #define FILE_DEVICE_CD_ROM 0x00000002
2792 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
2793 #define FILE_DEVICE_CONTROLLER 0x00000004
2794 #define FILE_DEVICE_DATALINK 0x00000005
2795 #define FILE_DEVICE_DFS 0x00000006
2796 #define FILE_DEVICE_DISK 0x00000007
2797 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
2798 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
2799 #define FILE_DEVICE_INPORT_PORT 0x0000000a
2800 #define FILE_DEVICE_KEYBOARD 0x0000000b
2801 #define FILE_DEVICE_MAILSLOT 0x0000000c
2802 #define FILE_DEVICE_MIDI_IN 0x0000000d
2803 #define FILE_DEVICE_MIDI_OUT 0x0000000e
2804 #define FILE_DEVICE_MOUSE 0x0000000f
2805 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
2806 #define FILE_DEVICE_NAMED_PIPE 0x00000011
2807 #define FILE_DEVICE_NETWORK 0x00000012
2808 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
2809 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
2810 #define FILE_DEVICE_NULL 0x00000015
2811 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
2812 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
2813 #define FILE_DEVICE_PRINTER 0x00000018
2814 #define FILE_DEVICE_SCANNER 0x00000019
2815 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
2816 #define FILE_DEVICE_SERIAL_PORT 0x0000001b
2817 #define FILE_DEVICE_SCREEN 0x0000001c
2818 #define FILE_DEVICE_SOUND 0x0000001d
2819 #define FILE_DEVICE_STREAMS 0x0000001e
2820 #define FILE_DEVICE_TAPE 0x0000001f
2821 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
2822 #define FILE_DEVICE_TRANSPORT 0x00000021
2823 #define FILE_DEVICE_UNKNOWN 0x00000022
2824 #define FILE_DEVICE_VIDEO 0x00000023
2825 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
2826 #define FILE_DEVICE_WAVE_IN 0x00000025
2827 #define FILE_DEVICE_WAVE_OUT 0x00000026
2828 #define FILE_DEVICE_8042_PORT 0x00000027
2829 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
2830 #define FILE_DEVICE_BATTERY 0x00000029
2831 #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
2832 #define FILE_DEVICE_MODEM 0x0000002b
2833 #define FILE_DEVICE_VDM 0x0000002c
2834 #define FILE_DEVICE_MASS_STORAGE 0x0000002d
2835 #define FILE_DEVICE_SMB 0x0000002e
2836 #define FILE_DEVICE_KS 0x0000002f
2837 #define FILE_DEVICE_CHANGER 0x00000030
2838 #define FILE_DEVICE_SMARTCARD 0x00000031
2839 #define FILE_DEVICE_ACPI 0x00000032
2840 #define FILE_DEVICE_DVD 0x00000033
2841 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
2842 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
2843 #define FILE_DEVICE_DFS_VOLUME 0x00000036
2844 #define FILE_DEVICE_SERENUM 0x00000037
2845 #define FILE_DEVICE_TERMSRV 0x00000038
2846 #define FILE_DEVICE_KSEC 0x00000039
2847 #define FILE_DEVICE_FIPS 0x0000003a
2848 #define FILE_DEVICE_INFINIBAND 0x0000003b
2849 #define FILE_DEVICE_VMBUS 0x0000003e
2850 #define FILE_DEVICE_CRYPT_PROVIDER 0x0000003f
2851 #define FILE_DEVICE_WPD 0x00000040
2852 #define FILE_DEVICE_BLUETOOTH 0x00000041
2853 #define FILE_DEVICE_MT_COMPOSITE 0x00000042
2854 #define FILE_DEVICE_MT_TRANSPORT 0x00000043
2855 #define FILE_DEVICE_BIOMETRIC 0x00000044
2856 #define FILE_DEVICE_PMI 0x00000045
2857
2858 #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR))
2859
2860 typedef struct _OBJECT_HANDLE_INFORMATION {
2861 ULONG HandleAttributes;
2862 ACCESS_MASK GrantedAccess;
2863 } OBJECT_HANDLE_INFORMATION, *POBJECT_HANDLE_INFORMATION;
2864
2865 typedef struct _CLIENT_ID {
2866 HANDLE UniqueProcess;
2867 HANDLE UniqueThread;
2868 } CLIENT_ID, *PCLIENT_ID;
2869
2870 typedef VOID
2871 (DDKAPI *PKSTART_ROUTINE)(
2872 IN PVOID StartContext);
2873
2874 typedef struct _VPB {
2875 CSHORT Type;
2876 CSHORT Size;
2877 USHORT Flags;
2878 USHORT VolumeLabelLength;
2879 struct _DEVICE_OBJECT *DeviceObject;
2880 struct _DEVICE_OBJECT *RealDevice;
2881 ULONG SerialNumber;
2882 ULONG ReferenceCount;
2883 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
2884 } VPB, *PVPB;
2885
2886 typedef struct _DEVICE_OBJECT {
2887 CSHORT Type;
2888 USHORT Size;
2889 LONG ReferenceCount;
2890 struct _DRIVER_OBJECT *DriverObject;
2891 struct _DEVICE_OBJECT *NextDevice;
2892 struct _DEVICE_OBJECT *AttachedDevice;
2893 struct _IRP *CurrentIrp;
2894 PIO_TIMER Timer;
2895 ULONG Flags;
2896 ULONG Characteristics;
2897 volatile PVPB Vpb;
2898 PVOID DeviceExtension;
2899 DEVICE_TYPE DeviceType;
2900 CCHAR StackSize;
2901 union {
2902 LIST_ENTRY ListEntry;
2903 WAIT_CONTEXT_BLOCK Wcb;
2904 } Queue;
2905 ULONG AlignmentRequirement;
2906 KDEVICE_QUEUE DeviceQueue;
2907 KDPC Dpc;
2908 ULONG ActiveThreadCount;
2909 PSECURITY_DESCRIPTOR SecurityDescriptor;
2910 KEVENT DeviceLock;
2911 USHORT SectorSize;
2912 USHORT Spare1;
2913 struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
2914 PVOID Reserved;
2915 } DEVICE_OBJECT, *PDEVICE_OBJECT;
2916
2917 typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
2918
2919 typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
2920 BOOLEAN Removed;
2921 BOOLEAN Reserved[3];
2922 volatile LONG IoCount;
2923 KEVENT RemoveEvent;
2924 } IO_REMOVE_LOCK_COMMON_BLOCK;
2925
2926 typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
2927 LONG Signature;
2928 LONG HighWatermark;
2929 LONGLONG MaxLockedTicks;
2930 LONG AllocateTag;
2931 LIST_ENTRY LockList;
2932 KSPIN_LOCK Spin;
2933 volatile LONG LowMemoryCount;
2934 ULONG Reserved1[4];
2935 PVOID Reserved2;
2936 PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
2937 } IO_REMOVE_LOCK_DBG_BLOCK;
2938
2939 typedef struct _IO_REMOVE_LOCK {
2940 IO_REMOVE_LOCK_COMMON_BLOCK Common;
2941 #if DBG
2942 IO_REMOVE_LOCK_DBG_BLOCK Dbg;
2943 #endif
2944 } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
2945
2946 typedef struct _IO_WORKITEM *PIO_WORKITEM;
2947
2948 typedef VOID
2949 (DDKAPI IO_WORKITEM_ROUTINE)(
2950 IN PDEVICE_OBJECT DeviceObject,
2951 IN PVOID Context);
2952 typedef IO_WORKITEM_ROUTINE *PIO_WORKITEM_ROUTINE;
2953
2954 typedef struct _SHARE_ACCESS {
2955 ULONG OpenCount;
2956 ULONG Readers;
2957 ULONG Writers;
2958 ULONG Deleters;
2959 ULONG SharedRead;
2960 ULONG SharedWrite;
2961 ULONG SharedDelete;
2962 } SHARE_ACCESS, *PSHARE_ACCESS;
2963
2964 typedef struct _PCI_COMMON_HEADER {
2965 USHORT VendorID;
2966 USHORT DeviceID;
2967 USHORT Command;
2968 USHORT Status;
2969 UCHAR RevisionID;
2970 UCHAR ProgIf;
2971 UCHAR SubClass;
2972 UCHAR BaseClass;
2973 UCHAR CacheLineSize;
2974 UCHAR LatencyTimer;
2975 UCHAR HeaderType;
2976 UCHAR BIST;
2977 union {
2978 struct _PCI_HEADER_TYPE_0 {
2979 ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
2980 ULONG CIS;
2981 USHORT SubVendorID;
2982 USHORT SubSystemID;
2983 ULONG ROMBaseAddress;
2984 UCHAR CapabilitiesPtr;
2985 UCHAR Reserved1[3];
2986 ULONG Reserved2;
2987 UCHAR InterruptLine;
2988 UCHAR InterruptPin;
2989 UCHAR MinimumGrant;
2990 UCHAR MaximumLatency;
2991 } type0;
2992 struct _PCI_HEADER_TYPE_1 {
2993 ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
2994 UCHAR PrimaryBus;
2995 UCHAR SecondaryBus;
2996 UCHAR SubordinateBus;
2997 UCHAR SecondaryLatency;
2998 UCHAR IOBase;
2999 UCHAR IOLimit;
3000 USHORT SecondaryStatus;
3001 USHORT MemoryBase;
3002 USHORT MemoryLimit;
3003 USHORT PrefetchBase;
3004 USHORT PrefetchLimit;
3005 ULONG PrefetchBaseUpper32;
3006 ULONG PrefetchLimitUpper32;
3007 USHORT IOBaseUpper16;
3008 USHORT IOLimitUpper16;
3009 UCHAR CapabilitiesPtr;
3010 UCHAR Reserved1[3];
3011 ULONG ROMBaseAddress;
3012 UCHAR InterruptLine;
3013 UCHAR InterruptPin;
3014 USHORT BridgeControl;
3015 } type1;
3016 struct _PCI_HEADER_TYPE_2 {
3017 ULONG SocketRegistersBaseAddress;
3018 UCHAR CapabilitiesPtr;
3019 UCHAR Reserved;
3020 USHORT SecondaryStatus;
3021 UCHAR PrimaryBus;
3022 UCHAR SecondaryBus;
3023 UCHAR SubordinateBus;
3024 UCHAR SecondaryLatency;
3025 struct {
3026 ULONG Base;
3027 ULONG Limit;
3028 } Range[PCI_TYPE2_ADDRESSES-1];
3029 UCHAR InterruptLine;
3030 UCHAR InterruptPin;
3031 USHORT BridgeControl;
3032 } type2;
3033 } u;
3034 } PCI_COMMON_HEADER, *PPCI_COMMON_HEADER;
3035
3036 #ifdef __cplusplus
3037
3038 typedef struct _PCI_COMMON_CONFIG : PCI_COMMON_HEADER {
3039 UCHAR DeviceSpecific[192];
3040 } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
3041
3042 #else
3043
3044 typedef struct _PCI_COMMON_CONFIG {
3045 PCI_COMMON_HEADER DUMMYSTRUCTNAME;
3046 UCHAR DeviceSpecific[192];
3047 } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
3048
3049 #endif
3050
3051 typedef enum _CREATE_FILE_TYPE {
3052 CreateFileTypeNone,
3053 CreateFileTypeNamedPipe,
3054 CreateFileTypeMailslot
3055 } CREATE_FILE_TYPE;
3056
3057 #define IO_FORCE_ACCESS_CHECK 0x001
3058 #define IO_NO_PARAMETER_CHECKING 0x100
3059
3060 #define IO_REPARSE 0x0
3061 #define IO_REMOUNT 0x1
3062
3063 typedef union _POWER_STATE {
3064 SYSTEM_POWER_STATE SystemState;
3065 DEVICE_POWER_STATE DeviceState;
3066 } POWER_STATE, *PPOWER_STATE;
3067
3068 typedef enum _POWER_STATE_TYPE {
3069 SystemPowerState = 0,
3070 DevicePowerState
3071 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
3072
3073 typedef struct _IO_STATUS_BLOCK {
3074 _ANONYMOUS_UNION union {
3075 NTSTATUS Status;
3076 PVOID Pointer;
3077 } DUMMYUNIONNAME;
3078 ULONG_PTR Information;
3079 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
3080
3081 typedef VOID
3082 (DDKAPI *PREQUEST_POWER_COMPLETE)(
3083 IN PDEVICE_OBJECT DeviceObject,
3084 IN UCHAR MinorFunction,
3085 IN POWER_STATE PowerState,
3086 IN PVOID Context,
3087 IN PIO_STATUS_BLOCK IoStatus);
3088
3089 typedef struct _PCI_SLOT_NUMBER {
3090 union {
3091 struct {
3092 ULONG DeviceNumber : 5;
3093 ULONG FunctionNumber : 3;
3094 ULONG Reserved : 24;
3095 } bits;
3096 ULONG AsULONG;
3097 } u;
3098 } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
3099
3100 typedef VOID
3101 (DDKAPI *PIO_APC_ROUTINE)(
3102 IN PVOID ApcContext,
3103 IN PIO_STATUS_BLOCK IoStatusBlock,
3104 IN ULONG Reserved);
3105
3106 #define EVENT_INCREMENT 1
3107 #define IO_NO_INCREMENT 0
3108 #define IO_CD_ROM_INCREMENT 1
3109 #define IO_DISK_INCREMENT 1
3110 #define IO_KEYBOARD_INCREMENT 6
3111 #define IO_MAILSLOT_INCREMENT 2
3112 #define IO_MOUSE_INCREMENT 6
3113 #define IO_NAMED_PIPE_INCREMENT 2
3114 #define IO_NETWORK_INCREMENT 2
3115 #define IO_PARALLEL_INCREMENT 1
3116 #define IO_SERIAL_INCREMENT 2
3117 #define IO_SOUND_INCREMENT 8
3118 #define IO_VIDEO_INCREMENT 1
3119 #define SEMAPHORE_INCREMENT 1
3120
3121 #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
3122
3123 typedef struct _BOOTDISK_INFORMATION {
3124 LONGLONG BootPartitionOffset;
3125 LONGLONG SystemPartitionOffset;
3126 ULONG BootDeviceSignature;
3127 ULONG SystemDeviceSignature;
3128 } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
3129
3130 typedef struct _BOOTDISK_INFORMATION_EX {
3131 LONGLONG BootPartitionOffset;
3132 LONGLONG SystemPartitionOffset;
3133 ULONG BootDeviceSignature;
3134 ULONG SystemDeviceSignature;
3135 GUID BootDeviceGuid;
3136 GUID SystemDeviceGuid;
3137 BOOLEAN BootDeviceIsGpt;
3138 BOOLEAN SystemDeviceIsGpt;
3139 } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
3140
3141 typedef struct _EISA_MEMORY_TYPE {
3142 UCHAR ReadWrite : 1;
3143 UCHAR Cached : 1;
3144 UCHAR Reserved0 : 1;
3145 UCHAR Type : 2;
3146 UCHAR Shared : 1;
3147 UCHAR Reserved1 : 1;
3148 UCHAR MoreEntries : 1;
3149 } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
3150
3151 #include <pshpack1.h>
3152 typedef struct _EISA_MEMORY_CONFIGURATION {
3153 EISA_MEMORY_TYPE ConfigurationByte;
3154 UCHAR DataSize;
3155 USHORT AddressLowWord;
3156 UCHAR AddressHighByte;
3157 USHORT MemorySize;
3158 } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
3159 #include <poppack.h>
3160
3161 typedef struct _EISA_IRQ_DESCRIPTOR {
3162 UCHAR Interrupt : 4;
3163 UCHAR Reserved : 1;
3164 UCHAR LevelTriggered : 1;
3165 UCHAR Shared : 1;
3166 UCHAR MoreEntries : 1;
3167 } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
3168
3169 typedef struct _EISA_IRQ_CONFIGURATION {
3170 EISA_IRQ_DESCRIPTOR ConfigurationByte;
3171 UCHAR Reserved;
3172 } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
3173
3174 typedef struct _DMA_CONFIGURATION_BYTE0 {
3175 UCHAR Channel : 3;
3176 UCHAR Reserved : 3;
3177 UCHAR Shared : 1;
3178 UCHAR MoreEntries : 1;
3179 } DMA_CONFIGURATION_BYTE0;
3180
3181 typedef struct _DMA_CONFIGURATION_BYTE1 {
3182 UCHAR Reserved0 : 2;
3183 UCHAR TransferSize : 2;
3184 UCHAR Timing : 2;
3185 UCHAR Reserved1 : 2;
3186 } DMA_CONFIGURATION_BYTE1;
3187
3188 typedef struct _EISA_DMA_CONFIGURATION {
3189 DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
3190 DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
3191 } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
3192
3193 #include <pshpack1.h>
3194 typedef struct _EISA_PORT_DESCRIPTOR {
3195 UCHAR NumberPorts : 5;
3196 UCHAR Reserved : 1;
3197 UCHAR Shared : 1;
3198 UCHAR MoreEntries : 1;
3199 } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
3200
3201 typedef struct _EISA_PORT_CONFIGURATION {
3202 EISA_PORT_DESCRIPTOR Configuration;
3203 USHORT PortAddress;
3204 } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
3205 #include <poppack.h>
3206
3207 typedef struct _CM_EISA_FUNCTION_INFORMATION {
3208 ULONG CompressedId;
3209 UCHAR IdSlotFlags1;
3210 UCHAR IdSlotFlags2;
3211 UCHAR MinorRevision;
3212 UCHAR MajorRevision;
3213 UCHAR Selections[26];
3214 UCHAR FunctionFlags;
3215 UCHAR TypeString[80];
3216 EISA_MEMORY_CONFIGURATION EisaMemory[9];
3217 EISA_IRQ_CONFIGURATION EisaIrq[7];
3218 EISA_DMA_CONFIGURATION EisaDma[4];
3219 EISA_PORT_CONFIGURATION EisaPort[20];
3220 UCHAR InitializationData[60];
3221 } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
3222
3223 /* CM_EISA_FUNCTION_INFORMATION.FunctionFlags */
3224
3225 #define EISA_FUNCTION_ENABLED 0x80
3226 #define EISA_FREE_FORM_DATA 0x40
3227 #define EISA_HAS_PORT_INIT_ENTRY 0x20
3228 #define EISA_HAS_PORT_RANGE 0x10
3229 #define EISA_HAS_DMA_ENTRY 0x08
3230 #define EISA_HAS_IRQ_ENTRY 0x04
3231 #define EISA_HAS_MEMORY_ENTRY 0x02
3232 #define EISA_HAS_TYPE_ENTRY 0x01
3233 #define EISA_HAS_INFORMATION \
3234 (EISA_HAS_PORT_RANGE + EISA_HAS_DMA_ENTRY + EISA_HAS_IRQ_ENTRY \
3235 + EISA_HAS_MEMORY_ENTRY + EISA_HAS_TYPE_ENTRY)
3236
3237 typedef struct _CM_EISA_SLOT_INFORMATION {
3238 UCHAR ReturnCode;
3239 UCHAR ReturnFlags;
3240 UCHAR MajorRevision;
3241 UCHAR MinorRevision;
3242 USHORT Checksum;
3243 UCHAR NumberFunctions;
3244 UCHAR FunctionInformation;
3245 ULONG CompressedId;
3246 } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
3247
3248 /* CM_EISA_SLOT_INFORMATION.ReturnCode */
3249
3250 #define EISA_INVALID_SLOT 0x80
3251 #define EISA_INVALID_FUNCTION 0x81
3252 #define EISA_INVALID_CONFIGURATION 0x82
3253 #define EISA_EMPTY_SLOT 0x83
3254 #define EISA_INVALID_BIOS_CALL 0x86
3255
3256 /*
3257 ** Plug and Play structures
3258 */
3259
3260 typedef VOID
3261 (DDKAPI *PINTERFACE_REFERENCE)(
3262 PVOID Context);
3263
3264 typedef VOID
3265 (DDKAPI *PINTERFACE_DEREFERENCE)(
3266 PVOID Context);
3267
3268 typedef BOOLEAN
3269 (DDKAPI *PTRANSLATE_BUS_ADDRESS)(
3270 IN PVOID Context,
3271 IN PHYSICAL_ADDRESS BusAddress,
3272 IN ULONG Length,
3273 IN OUT PULONG AddressSpace,
3274 OUT PPHYSICAL_ADDRESS TranslatedAddress);
3275
3276 typedef struct _DMA_ADAPTER*
3277 (DDKAPI *PGET_DMA_ADAPTER)(
3278 IN PVOID Context,
3279 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
3280 OUT PULONG NumberOfMapRegisters);
3281
3282 typedef ULONG
3283 (DDKAPI *PGET_SET_DEVICE_DATA)(
3284 IN PVOID Context,
3285 IN ULONG DataType,
3286 IN PVOID Buffer,
3287 IN ULONG Offset,
3288 IN ULONG Length);
3289
3290 /* PCI_DEVICE_PRESENCE_PARAMETERS.Flags */
3291 #define PCI_USE_SUBSYSTEM_IDS 0x00000001
3292 #define PCI_USE_REVISION 0x00000002
3293 #define PCI_USE_VENDEV_IDS 0x00000004
3294 #define PCI_USE_CLASS_SUBCLASS 0x00000008
3295 #define PCI_USE_PROGIF 0x00000010
3296 #define PCI_USE_LOCAL_BUS 0x00000020
3297 #define PCI_USE_LOCAL_DEVICE 0x00000040
3298
3299 typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
3300 ULONG Size;
3301 ULONG Flags;
3302 USHORT VendorID;
3303 USHORT DeviceID;
3304 UCHAR RevisionID;
3305 USHORT SubVendorID;
3306 USHORT SubSystemID;
3307 UCHAR BaseClass;
3308 UCHAR SubClass;
3309 UCHAR ProgIf;
3310 } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
3311
3312 typedef BOOLEAN
3313 (DDKAPI *PPCI_IS_DEVICE_PRESENT)(
3314 IN USHORT VendorID,
3315 IN USHORT DeviceID,
3316 IN UCHAR RevisionID,
3317 IN USHORT SubVendorID,
3318 IN USHORT SubSystemID,
3319 IN ULONG Flags);
3320
3321 typedef BOOLEAN
3322 (DDKAPI *PPCI_IS_DEVICE_PRESENT_EX)(
3323 IN PVOID Context,
3324 IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters);
3325
3326 typedef struct _BUS_INTERFACE_STANDARD {
3327 USHORT Size;
3328 USHORT Version;
3329 PVOID Context;
3330 PINTERFACE_REFERENCE InterfaceReference;
3331 PINTERFACE_DEREFERENCE InterfaceDereference;
3332 PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
3333 PGET_DMA_ADAPTER GetDmaAdapter;
3334 PGET_SET_DEVICE_DATA SetBusData;
3335 PGET_SET_DEVICE_DATA GetBusData;
3336 } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
3337
3338 typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
3339 USHORT Size;
3340 USHORT Version;
3341 PVOID Context;
3342 PINTERFACE_REFERENCE InterfaceReference;
3343 PINTERFACE_DEREFERENCE InterfaceDereference;
3344 PPCI_IS_DEVICE_PRESENT IsDevicePresent;
3345 PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
3346 } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
3347
3348 typedef struct _DEVICE_CAPABILITIES {
3349 USHORT Size;
3350 USHORT Version;
3351 ULONG DeviceD1 : 1;
3352 ULONG DeviceD2 : 1;
3353 ULONG LockSupported : 1;
3354 ULONG EjectSupported : 1;
3355 ULONG Removable : 1;
3356 ULONG DockDevice : 1;
3357 ULONG UniqueID : 1;
3358 ULONG SilentInstall : 1;
3359 ULONG RawDeviceOK : 1;
3360 ULONG SurpriseRemovalOK : 1;
3361 ULONG WakeFromD0 : 1;
3362 ULONG WakeFromD1 : 1;
3363 ULONG WakeFromD2 : 1;
3364 ULONG WakeFromD3 : 1;
3365 ULONG HardwareDisabled : 1;
3366 ULONG NonDynamic : 1;
3367 ULONG WarmEjectSupported : 1;
3368 ULONG NoDisplayInUI : 1;
3369 ULONG Reserved : 14;
3370 ULONG Address;
3371 ULONG UINumber;
3372 DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
3373 SYSTEM_POWER_STATE SystemWake;
3374 DEVICE_POWER_STATE DeviceWake;
3375 ULONG D1Latency;
3376 ULONG D2Latency;
3377 ULONG D3Latency;
3378 } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
3379
3380 typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
3381 USHORT Version;
3382 USHORT Size;
3383 GUID Event;
3384 GUID InterfaceClassGuid;
3385 PUNICODE_STRING SymbolicLinkName;
3386 } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
3387
3388 typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
3389 USHORT Version;
3390 USHORT Size;
3391 GUID Event;
3392 } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
3393
3394 #undef INTERFACE
3395
3396 typedef struct _INTERFACE {
3397 USHORT Size;
3398 USHORT Version;
3399 PVOID Context;
3400 PINTERFACE_REFERENCE InterfaceReference;
3401 PINTERFACE_DEREFERENCE InterfaceDereference;
3402 } INTERFACE, *PINTERFACE;
3403
3404 typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
3405 USHORT Version;
3406 USHORT Size;
3407 GUID Event;
3408 } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
3409
3410 typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
3411
3412 /* PNP_DEVICE_STATE */
3413
3414 #define PNP_DEVICE_DISABLED 0x00000001
3415 #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
3416 #define PNP_DEVICE_FAILED 0x00000004
3417 #define PNP_DEVICE_REMOVED 0x00000008
3418 #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
3419 #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
3420
3421 typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
3422 USHORT Version;
3423 USHORT Size;
3424 GUID Event;
3425 struct _FILE_OBJECT *FileObject;
3426 LONG NameBufferOffset;
3427 UCHAR CustomDataBuffer[1];
3428 } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
3429
3430 typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
3431 USHORT Version;
3432 USHORT Size;
3433 GUID Event;
3434 struct _FILE_OBJECT *FileObject;
3435 } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
3436
3437 typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
3438 DeviceUsageTypeUndefined,
3439 DeviceUsageTypePaging,
3440 DeviceUsageTypeHibernation,
3441 DeviceUsageTypeDumpFile
3442 } DEVICE_USAGE_NOTIFICATION_TYPE;
3443
3444 typedef struct _POWER_SEQUENCE {
3445 ULONG SequenceD1;
3446 ULONG SequenceD2;
3447 ULONG SequenceD3;
3448 } POWER_SEQUENCE, *PPOWER_SEQUENCE;
3449
3450 typedef enum {
3451 DevicePropertyDeviceDescription = 0x0,
3452 DevicePropertyHardwareID = 0x1,
3453 DevicePropertyCompatibleIDs = 0x2,
3454 DevicePropertyBootConfiguration = 0x3,
3455 DevicePropertyBootConfigurationTranslated = 0x4,
3456 DevicePropertyClassName = 0x5,
3457 DevicePropertyClassGuid = 0x6,
3458 DevicePropertyDriverKeyName = 0x7,
3459 DevicePropertyManufacturer = 0x8,
3460 DevicePropertyFriendlyName = 0x9,
3461 DevicePropertyLocationInformation = 0xa,
3462 DevicePropertyPhysicalDeviceObjectName = 0xb,
3463 DevicePropertyBusTypeGuid = 0xc,
3464 DevicePropertyLegacyBusType = 0xd,
3465 DevicePropertyBusNumber = 0xe,
3466 DevicePropertyEnumeratorName = 0xf,
3467 DevicePropertyAddress = 0x10,
3468 DevicePropertyUINumber = 0x11,
3469 DevicePropertyInstallState = 0x12,
3470 DevicePropertyRemovalPolicy = 0x13,
3471 DevicePropertyResourceRequirements = 0x14,
3472 DevicePropertyAllocatedResources = 0x15,
3473 DevicePropertyContainerID = 0x16
3474 } DEVICE_REGISTRY_PROPERTY;
3475
3476 typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
3477 EventCategoryReserved,
3478 EventCategoryHardwareProfileChange,
3479 EventCategoryDeviceInterfaceChange,
3480 EventCategoryTargetDeviceChange
3481 } IO_NOTIFICATION_EVENT_CATEGORY;
3482
3483 #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
3484
3485 typedef NTSTATUS
3486 (DDKAPI *PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)(
3487 IN PVOID NotificationStructure,
3488 IN PVOID Context);
3489
3490 typedef VOID
3491 (DDKAPI *PDEVICE_CHANGE_COMPLETE_CALLBACK)(
3492 IN PVOID Context);
3493
3494 typedef enum _FILE_INFORMATION_CLASS {
3495 FileDirectoryInformation = 1,
3496 FileFullDirectoryInformation,
3497 FileBothDirectoryInformation,
3498 FileBasicInformation,
3499 FileStandardInformation,
3500 FileInternalInformation,
3501 FileEaInformation,
3502 FileAccessInformation,
3503 FileNameInformation,
3504 FileRenameInformation,
3505 FileLinkInformation,
3506 FileNamesInformation,
3507 FileDispositionInformation,
3508 FilePositionInformation,
3509 FileFullEaInformation,
3510 FileModeInformation,
3511 FileAlignmentInformation,
3512 FileAllInformation,
3513 FileAllocationInformation,
3514 FileEndOfFileInformation,
3515 FileAlternateNameInformation,
3516 FileStreamInformation,
3517 FilePipeInformation,
3518 FilePipeLocalInformation,
3519 FilePipeRemoteInformation,
3520 FileMailslotQueryInformation,
3521 FileMailslotSetInformation,
3522 FileCompressionInformation,
3523 FileObjectIdInformation,
3524 FileCompletionInformation,
3525 FileMoveClusterInformation,
3526 FileQuotaInformation,
3527 FileReparsePointInformation,
3528 FileNetworkOpenInformation,
3529 FileAttributeTagInformation,
3530 FileTrackingInformation,
3531 FileIdBothDirectoryInformation,
3532 FileIdFullDirectoryInformation,
3533 FileValidDataLengthInformation,
3534 FileShortNameInformation,
3535 FileIoCompletionNotificationInformation,
3536 FileIoStatusBlockRangeInformation,
3537 FileIoPriorityHintInformation,
3538 FileSfioReserveInformation,
3539 FileSfioVolumeInformation,
3540 FileHardLinkInformation,
3541 FileProcessIdsUsingFileInformation,
3542 FileNormalizedNameInformation,
3543 FileNetworkPhysicalNameInformation,
3544 FileIdGlobalTxDirectoryInformation,
3545 FileIsRemoteDeviceInformation,
3546 FileAttributeCacheInformation,
3547 FileNumaNodeInformation,
3548 FileStandardLinkInformation,
3549 FileRemoteProtocolInformation,
3550 FileMaximumInformation
3551 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
3552
3553 typedef struct _FILE_POSITION_INFORMATION {
3554 LARGE_INTEGER CurrentByteOffset;
3555 } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
3556
3557 #include <pshpack8.h>
3558 typedef struct _FILE_BASIC_INFORMATION {
3559 LARGE_INTEGER CreationTime;
3560 LARGE_INTEGER LastAccessTime;
3561 LARGE_INTEGER LastWriteTime;
3562 LARGE_INTEGER ChangeTime;
3563 ULONG FileAttributes;
3564 } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
3565 #include <poppack.h>
3566
3567 typedef struct _FILE_STANDARD_INFORMATION {
3568 LARGE_INTEGER AllocationSize;
3569 LARGE_INTEGER EndOfFile;
3570 ULONG NumberOfLinks;
3571 BOOLEAN DeletePending;
3572 BOOLEAN Directory;
3573 } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
3574
3575 typedef struct _FILE_NETWORK_OPEN_INFORMATION {
3576 LARGE_INTEGER CreationTime;
3577 LARGE_INTEGER LastAccessTime;
3578 LARGE_INTEGER LastWriteTime;
3579 LARGE_INTEGER ChangeTime;
3580 LARGE_INTEGER AllocationSize;
3581 LARGE_INTEGER EndOfFile;
3582 ULONG FileAttributes;
3583 } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
3584
3585 typedef enum _FSINFOCLASS {
3586 FileFsVolumeInformation = 1,
3587 FileFsLabelInformation,
3588 FileFsSizeInformation,
3589 FileFsDeviceInformation,
3590 FileFsAttributeInformation,
3591 FileFsControlInformation,
3592 FileFsFullSizeInformation,
3593 FileFsObjectIdInformation,
3594 FileFsDriverPathInformation,
3595 FileFsVolumeFlagsInformation,
3596 FileFsMaximumInformation
3597 } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
3598
3599 typedef struct _FILE_FS_DEVICE_INFORMATION {
3600 DEVICE_TYPE DeviceType;
3601 ULONG Characteristics;
3602 } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
3603
3604 typedef struct _FILE_FULL_EA_INFORMATION {
3605 ULONG NextEntryOffset;
3606 UCHAR Flags;
3607 UCHAR EaNameLength;
3608 USHORT EaValueLength;
3609 CHAR EaName[1];
3610 } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
3611
3612 typedef struct _FAST_MUTEX
3613 {
3614 LONG Count;
3615 PKTHREAD Owner;
3616 ULONG Contention;
3617 KEVENT Gate;
3618 ULONG OldIrql;
3619 } FAST_MUTEX, *PFAST_MUTEX;
3620
3621 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
3622
3623 typedef struct _OWNER_ENTRY {
3624 ERESOURCE_THREAD OwnerThread;
3625 _ANONYMOUS_UNION union {
3626 LONG OwnerCount;
3627 ULONG TableSize;
3628 } DUMMYUNIONNAME;
3629 } OWNER_ENTRY, *POWNER_ENTRY;
3630
3631 typedef struct _ERESOURCE
3632 {
3633 LIST_ENTRY SystemResourcesList;
3634 POWNER_ENTRY OwnerTable;
3635 SHORT ActiveCount;
3636 USHORT Flag;
3637 volatile PKSEMAPHORE SharedWaiters;
3638 volatile PKEVENT ExclusiveWaiters;
3639 OWNER_ENTRY OwnerEntry;
3640 ULONG ActiveEntries;
3641 ULONG ContentionCount;
3642 ULONG NumberOfSharedWaiters;
3643 ULONG NumberOfExclusiveWaiters;
3644 __GNU_EXTENSION union
3645 {
3646 PVOID Address;
3647 ULONG_PTR CreatorBackTraceIndex;
3648 };
3649 KSPIN_LOCK SpinLock;
3650 } ERESOURCE, *PERESOURCE;
3651
3652 /* ERESOURCE.Flag */
3653
3654 #define ResourceNeverExclusive 0x0010
3655 #define ResourceReleaseByOtherThread 0x0020
3656 #define ResourceOwnedExclusive 0x0080
3657
3658 #define RESOURCE_HASH_TABLE_SIZE 64
3659
3660 typedef BOOLEAN
3661 (DDKAPI *PFAST_IO_CHECK_IF_POSSIBLE)(
3662 IN struct _FILE_OBJECT *FileObject,
3663 IN PLARGE_INTEGER FileOffset,
3664 IN ULONG Length,
3665 IN BOOLEAN Wait,
3666 IN ULONG LockKey,
3667 IN BOOLEAN CheckForReadOperation,
3668 OUT PIO_STATUS_BLOCK IoStatus,
3669 IN struct _DEVICE_OBJECT *DeviceObject);
3670
3671 typedef BOOLEAN
3672 (DDKAPI *PFAST_IO_READ)(
3673 IN struct _FILE_OBJECT *FileObject,
3674 IN PLARGE_INTEGER FileOffset,
3675 IN ULONG Length,
3676 IN BOOLEAN Wait,
3677 IN ULONG LockKey,
3678 OUT PVOID Buffer,
3679 OUT PIO_STATUS_BLOCK IoStatus,
3680 IN struct _DEVICE_OBJECT *DeviceObject);
3681
3682 typedef BOOLEAN
3683 (DDKAPI *PFAST_IO_WRITE)(
3684 IN struct _FILE_OBJECT *FileObject,
3685 IN PLARGE_INTEGER FileOffset,
3686 IN ULONG Length,
3687 IN BOOLEAN Wait,
3688 IN ULONG LockKey,
3689 IN PVOID Buffer,
3690 OUT PIO_STATUS_BLOCK IoStatus,
3691 IN struct _DEVICE_OBJECT *DeviceObject);
3692
3693 typedef BOOLEAN
3694 (DDKAPI *PFAST_IO_QUERY_BASIC_INFO)(
3695 IN struct _FILE_OBJECT *FileObject,
3696 IN BOOLEAN Wait,
3697 OUT PFILE_BASIC_INFORMATION Buffer,
3698 OUT PIO_STATUS_BLOCK IoStatus,
3699 IN struct _DEVICE_OBJECT *DeviceObject);
3700
3701 typedef BOOLEAN
3702 (DDKAPI *PFAST_IO_QUERY_STANDARD_INFO)(
3703 IN struct _FILE_OBJECT *FileObject,
3704 IN BOOLEAN Wait,
3705 OUT PFILE_STANDARD_INFORMATION Buffer,
3706 OUT PIO_STATUS_BLOCK IoStatus,
3707 IN struct _DEVICE_OBJECT *DeviceObject);
3708
3709 typedef BOOLEAN
3710 (DDKAPI *PFAST_IO_LOCK)(
3711 IN struct _FILE_OBJECT *FileObject,
3712 IN PLARGE_INTEGER FileOffset,
3713 IN PLARGE_INTEGER Length,
3714 PEPROCESS ProcessId,
3715 ULONG Key,
3716 BOOLEAN FailImmediately,
3717 BOOLEAN ExclusiveLock,
3718 OUT PIO_STATUS_BLOCK IoStatus,
3719 IN struct _DEVICE_OBJECT *DeviceObject);
3720
3721 typedef BOOLEAN
3722 (DDKAPI *PFAST_IO_UNLOCK_SINGLE)(
3723 IN struct _FILE_OBJECT *FileObject,
3724 IN PLARGE_INTEGER FileOffset,
3725 IN PLARGE_INTEGER Length,
3726 PEPROCESS ProcessId,
3727 ULONG Key,
3728 OUT PIO_STATUS_BLOCK IoStatus,
3729 IN struct _DEVICE_OBJECT *DeviceObject);
3730
3731 typedef BOOLEAN
3732 (DDKAPI *PFAST_IO_UNLOCK_ALL)(
3733 IN struct _FILE_OBJECT *FileObject,
3734 PEPROCESS ProcessId,
3735 OUT PIO_STATUS_BLOCK IoStatus,
3736 IN struct _DEVICE_OBJECT *DeviceObject);
3737
3738 typedef BOOLEAN
3739 (DDKAPI *PFAST_IO_UNLOCK_ALL_BY_KEY)(
3740 IN struct _FILE_OBJECT *FileObject,
3741 PVOID ProcessId,
3742 ULONG Key,
3743 OUT PIO_STATUS_BLOCK IoStatus,
3744 IN struct _DEVICE_OBJECT *DeviceObject);
3745
3746 typedef BOOLEAN
3747 (DDKAPI *PFAST_IO_DEVICE_CONTROL)(
3748 IN struct _FILE_OBJECT *FileObject,
3749 IN BOOLEAN Wait,
3750 IN PVOID InputBuffer OPTIONAL,
3751 IN ULONG InputBufferLength,
3752 OUT PVOID OutputBuffer OPTIONAL,
3753 IN ULONG OutputBufferLength,
3754 IN ULONG IoControlCode,
3755 OUT PIO_STATUS_BLOCK IoStatus,
3756 IN struct _DEVICE_OBJECT *DeviceObject);
3757
3758 typedef VOID
3759 (DDKAPI *PFAST_IO_ACQUIRE_FILE)(
3760 IN struct _FILE_OBJECT *FileObject);
3761
3762 typedef VOID
3763 (DDKAPI *PFAST_IO_RELEASE_FILE)(
3764 IN struct _FILE_OBJECT *FileObject);
3765
3766 typedef VOID
3767 (DDKAPI *PFAST_IO_DETACH_DEVICE)(
3768 IN struct _DEVICE_OBJECT *SourceDevice,
3769 IN struct _DEVICE_OBJECT *TargetDevice);
3770
3771 typedef BOOLEAN
3772 (DDKAPI *PFAST_IO_QUERY_NETWORK_OPEN_INFO)(
3773 IN struct _FILE_OBJECT *FileObject,
3774 IN BOOLEAN Wait,
3775 OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
3776 OUT struct _IO_STATUS_BLOCK *IoStatus,
3777 IN struct _DEVICE_OBJECT *DeviceObject);
3778
3779 typedef NTSTATUS
3780 (DDKAPI *PFAST_IO_ACQUIRE_FOR_MOD_WRITE)(
3781 IN struct _FILE_OBJECT *FileObject,
3782 IN PLARGE_INTEGER EndingOffset,
3783 OUT struct _ERESOURCE **ResourceToRelease,
3784 IN struct _DEVICE_OBJECT *DeviceObject);
3785
3786 typedef BOOLEAN
3787 (DDKAPI *PFAST_IO_MDL_READ)(
3788 IN struct _FILE_OBJECT *FileObject,
3789 IN PLARGE_INTEGER FileOffset,
3790 IN ULONG Length,
3791 IN ULONG LockKey,
3792 OUT PMDL *MdlChain,
3793 OUT PIO_STATUS_BLOCK IoStatus,
3794 IN struct _DEVICE_OBJECT *DeviceObject);
3795
3796 typedef BOOLEAN
3797 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE)(
3798 IN struct _FILE_OBJECT *FileObject,
3799 IN PMDL MdlChain,
3800 IN struct _DEVICE_OBJECT *DeviceObject);
3801
3802 typedef BOOLEAN
3803 (DDKAPI *PFAST_IO_PREPARE_MDL_WRITE)(
3804 IN struct _FILE_OBJECT *FileObject,
3805 IN PLARGE_INTEGER FileOffset,
3806 IN ULONG Length,
3807 IN ULONG LockKey,
3808 OUT PMDL *MdlChain,
3809 OUT PIO_STATUS_BLOCK IoStatus,
3810 IN struct _DEVICE_OBJECT *DeviceObject);
3811
3812 typedef BOOLEAN
3813 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE)(
3814 IN struct _FILE_OBJECT *FileObject,
3815 IN PLARGE_INTEGER FileOffset,
3816 IN PMDL MdlChain,
3817 IN struct _DEVICE_OBJECT *DeviceObject);
3818
3819 typedef BOOLEAN
3820 (DDKAPI *PFAST_IO_READ_COMPRESSED)(
3821 IN struct _FILE_OBJECT *FileObject,
3822 IN PLARGE_INTEGER FileOffset,
3823 IN ULONG Length,
3824 IN ULONG LockKey,
3825 OUT PVOID Buffer,
3826 OUT PMDL *MdlChain,
3827 OUT PIO_STATUS_BLOCK IoStatus,
3828 OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3829 IN ULONG CompressedDataInfoLength,
3830 IN struct _DEVICE_OBJECT *DeviceObject);
3831
3832 typedef BOOLEAN
3833 (DDKAPI *PFAST_IO_WRITE_COMPRESSED)(
3834 IN struct _FILE_OBJECT *FileObject,
3835 IN PLARGE_INTEGER FileOffset,
3836 IN ULONG Length,
3837 IN ULONG LockKey,
3838 IN PVOID Buffer,
3839 OUT PMDL *MdlChain,
3840 OUT PIO_STATUS_BLOCK IoStatus,
3841 IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3842 IN ULONG CompressedDataInfoLength,
3843 IN struct _DEVICE_OBJECT *DeviceObject);
3844
3845 typedef BOOLEAN
3846 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE_COMPRESSED)(
3847 IN struct _FILE_OBJECT *FileObject,
3848 IN PMDL MdlChain,
3849 IN struct _DEVICE_OBJECT *DeviceObject);
3850
3851 typedef BOOLEAN
3852 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED)(
3853 IN struct _FILE_OBJECT *FileObject,
3854 IN PLARGE_INTEGER FileOffset,
3855 IN PMDL MdlChain,
3856 IN struct _DEVICE_OBJECT *DeviceObject);
3857
3858 typedef BOOLEAN
3859 (DDKAPI *PFAST_IO_QUERY_OPEN)(
3860 IN struct _IRP *Irp,
3861 OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
3862 IN struct _DEVICE_OBJECT *DeviceObject);
3863
3864 typedef NTSTATUS
3865 (DDKAPI *PFAST_IO_RELEASE_FOR_MOD_WRITE)(
3866 IN struct _FILE_OBJECT *FileObject,
3867 IN struct _ERESOURCE *ResourceToRelease,
3868 IN struct _DEVICE_OBJECT *DeviceObject);
3869
3870 typedef NTSTATUS
3871 (DDKAPI *PFAST_IO_ACQUIRE_FOR_CCFLUSH)(
3872 IN struct _FILE_OBJECT *FileObject,
3873 IN struct _DEVICE_OBJECT *DeviceObject);
3874
3875 typedef NTSTATUS
3876 (DDKAPI *PFAST_IO_RELEASE_FOR_CCFLUSH) (
3877 IN struct _FILE_OBJECT *FileObject,
3878 IN struct _DEVICE_OBJECT *DeviceObject);
3879
3880 typedef struct _FAST_IO_DISPATCH {
3881 ULONG SizeOfFastIoDispatch;
3882 PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
3883 PFAST_IO_READ FastIoRead;
3884 PFAST_IO_WRITE FastIoWrite;
3885 PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
3886 PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
3887 PFAST_IO_LOCK FastIoLock;
3888 PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
3889 PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
3890 PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
3891 PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
3892 PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
3893 PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
3894 PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
3895 PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
3896 PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
3897 PFAST_IO_MDL_READ MdlRead;
3898 PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
3899 PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
3900 PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
3901 PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
3902 PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
3903 PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
3904 PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
3905 PFAST_IO_QUERY_OPEN FastIoQueryOpen;
3906 PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
3907 PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
3908 PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
3909 } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
3910
3911 typedef struct _SECTION_OBJECT_POINTERS {
3912 PVOID DataSectionObject;
3913 PVOID SharedCacheMap;
3914 PVOID ImageSectionObject;
3915 } SECTION_OBJECT_POINTERS, *PSECTION_OBJECT_POINTERS;
3916
3917 typedef struct _IO_COMPLETION_CONTEXT {
3918 PVOID Port;
3919 PVOID Key;
3920 } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
3921
3922 /* FILE_OBJECT.Flags */
3923
3924 #define FO_FILE_OPEN 0x00000001
3925 #define FO_SYNCHRONOUS_IO 0x00000002
3926 #define FO_ALERTABLE_IO 0x00000004
3927 #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
3928 #define FO_WRITE_THROUGH 0x00000010
3929 #define FO_SEQUENTIAL_ONLY 0x00000020
3930 #define FO_CACHE_SUPPORTED 0x00000040
3931 #define FO_NAMED_PIPE 0x00000080
3932 #define FO_STREAM_FILE 0x00000100
3933 #define FO_MAILSLOT 0x00000200
3934 #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
3935 #define FO_QUEUE_IRP_TO_THREAD 0x00000400
3936 #define FO_DIRECT_DEVICE_OPEN 0x00000800
3937 #define FO_FILE_MODIFIED 0x00001000
3938 #define FO_FILE_SIZE_CHANGED 0x00002000
3939 #define FO_CLEANUP_COMPLETE 0x00004000
3940 #define FO_TEMPORARY_FILE 0x00008000
3941 #define FO_DELETE_ON_CLOSE 0x00010000
3942 #define FO_OPENED_CASE_SENSITIVE 0x00020000
3943 #define FO_HANDLE_CREATED 0x00040000
3944 #define FO_FILE_FAST_IO_READ 0x00080000
3945 #define FO_RANDOM_ACCESS 0x00100000
3946 #define FO_FILE_OPEN_CANCELLED 0x00200000
3947 #define FO_VOLUME_OPEN 0x00400000
3948 #define FO_REMOTE_ORIGIN 0x01000000
3949 #define FO_DISALLOW_EXCLUSIVE 0x02000000
3950 #define FO_SKIP_COMPLETION_PORT 0x02000000
3951 #define FO_SKIP_SET_EVENT 0x04000000
3952 #define FO_SKIP_SET_FAST_IO 0x08000000
3953
3954 /* VPB.Flags */
3955 #define VPB_MOUNTED 0x0001
3956 #define VPB_LOCKED 0x0002
3957 #define VPB_PERSISTENT 0x0004
3958 #define VPB_REMOVE_PENDING 0x0008
3959 #define VPB_RAW_MOUNT 0x0010
3960 #define VPB_DIRECT_WRITES_ALLOWED 0x0020
3961
3962 /* IRP.Flags */
3963
3964 #define SL_FORCE_ACCESS_CHECK 0x01
3965 #define SL_OPEN_PAGING_FILE 0x02
3966 #define SL_OPEN_TARGET_DIRECTORY 0x04
3967 #define SL_CASE_SENSITIVE 0x80
3968
3969 #define SL_KEY_SPECIFIED 0x01
3970 #define SL_OVERRIDE_VERIFY_VOLUME 0x02
3971 #define SL_WRITE_THROUGH 0x04
3972 #define SL_FT_SEQUENTIAL_WRITE 0x08
3973
3974 #define SL_FAIL_IMMEDIATELY 0x01
3975 #define SL_EXCLUSIVE_LOCK 0x02
3976
3977 #define SL_RESTART_SCAN 0x01
3978 #define SL_RETURN_SINGLE_ENTRY 0x02
3979 #define SL_INDEX_SPECIFIED 0x04
3980
3981 #define SL_WATCH_TREE 0x01
3982
3983 #define SL_ALLOW_RAW_MOUNT 0x01
3984
3985 #define CTL_CODE(DeviceType, Function, Method, Access)( \
3986 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
3987
3988 #define DEVICE_TYPE_FROM_CTL_CODE(ctl) (((ULONG) (ctl & 0xffff0000)) >> 16)
3989
3990 #define IRP_NOCACHE 0x00000001
3991 #define IRP_PAGING_IO 0x00000002
3992 #define IRP_MOUNT_COMPLETION 0x00000002
3993 #define IRP_SYNCHRONOUS_API 0x00000004
3994 #define IRP_ASSOCIATED_IRP 0x00000008
3995 #define IRP_BUFFERED_IO 0x00000010
3996 #define IRP_DEALLOCATE_BUFFER 0x00000020
3997 #define IRP_INPUT_OPERATION 0x00000040
3998 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
3999 #define IRP_CREATE_OPERATION 0x00000080
4000 #define IRP_READ_OPERATION 0x00000100
4001 #define IRP_WRITE_OPERATION 0x00000200
4002 #define IRP_CLOSE_OPERATION 0x00000400
4003 #define IRP_DEFER_IO_COMPLETION 0x00000800
4004 #define IRP_OB_QUERY_NAME 0x00001000
4005 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
4006
4007 #define IRP_QUOTA_CHARGED 0x01
4008 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
4009 #define IRP_ALLOCATED_FIXED_SIZE 0x04
4010 #define IRP_LOOKASIDE_ALLOCATION 0x08
4011
4012 /*
4013 ** IRP function codes
4014 */
4015
4016 #define IRP_MJ_CREATE 0x00
4017 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
4018 #define IRP_MJ_CLOSE 0x02
4019 #define IRP_MJ_READ 0x03
4020 #define IRP_MJ_WRITE 0x04
4021 #define IRP_MJ_QUERY_INFORMATION 0x05
4022 #define IRP_MJ_SET_INFORMATION 0x06
4023 #define IRP_MJ_QUERY_EA 0x07
4024 #define IRP_MJ_SET_EA 0x08
4025 #define IRP_MJ_FLUSH_BUFFERS 0x09
4026 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
4027 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
4028 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
4029 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
4030 #define IRP_MJ_DEVICE_CONTROL 0x0e
4031 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
4032 #define IRP_MJ_SCSI 0x0f
4033 #define IRP_MJ_SHUTDOWN 0x10
4034 #define IRP_MJ_LOCK_CONTROL 0x11
4035 #define IRP_MJ_CLEANUP 0x12
4036 #define IRP_MJ_CREATE_MAILSLOT 0x13
4037 #define IRP_MJ_QUERY_SECURITY 0x14
4038 #define IRP_MJ_SET_SECURITY 0x15
4039 #define IRP_MJ_POWER 0x16
4040 #define IRP_MJ_SYSTEM_CONTROL 0x17
4041 #define IRP_MJ_DEVICE_CHANGE 0x18
4042 #define IRP_MJ_QUERY_QUOTA 0x19
4043 #define IRP_MJ_SET_QUOTA 0x1a
4044 #define IRP_MJ_PNP 0x1b
4045 #define IRP_MJ_PNP_POWER 0x1b
4046 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
4047
4048 #define IRP_MN_SCSI_CLASS 0x01
4049
4050 #define IRP_MN_START_DEVICE 0x00
4051 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
4052 #define IRP_MN_REMOVE_DEVICE 0x02
4053 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
4054 #define IRP_MN_STOP_DEVICE 0x04
4055 #define IRP_MN_QUERY_STOP_DEVICE 0x05
4056 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
4057
4058 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
4059 #define IRP_MN_QUERY_INTERFACE 0x08
4060 #define IRP_MN_QUERY_CAPABILITIES 0x09
4061 #define IRP_MN_QUERY_RESOURCES 0x0A
4062 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
4063 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
4064 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
4065
4066 #define IRP_MN_READ_CONFIG 0x0F
4067 #define IRP_MN_WRITE_CONFIG 0x10
4068 #define IRP_MN_EJECT 0x11
4069 #define IRP_MN_SET_LOCK 0x12
4070 #define IRP_MN_QUERY_ID 0x13
4071 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
4072 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
4073 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
4074 #define IRP_MN_SURPRISE_REMOVAL 0x17
4075
4076 #define IRP_MN_WAIT_WAKE 0x00
4077 #define IRP_MN_POWER_SEQUENCE 0x01
4078 #define IRP_MN_SET_POWER 0x02
4079 #define IRP_MN_QUERY_POWER 0x03
4080
4081 #define IRP_MN_QUERY_ALL_DATA 0x00
4082 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
4083 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
4084 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
4085 #define IRP_MN_ENABLE_EVENTS 0x04
4086 #define IRP_MN_DISABLE_EVENTS 0x05
4087 #define IRP_MN_ENABLE_COLLECTION 0x06
4088 #define IRP_MN_DISABLE_COLLECTION 0x07
4089 #define IRP_MN_REGINFO 0x08
4090 #define IRP_MN_EXECUTE_METHOD 0x09
4091
4092 #define IRP_MN_REGINFO_EX 0x0b
4093
4094 typedef struct _FILE_OBJECT
4095 {
4096 CSHORT Type;
4097 CSHORT Size;
4098 PDEVICE_OBJECT DeviceObject;
4099 PVPB Vpb;
4100 PVOID FsContext;
4101 PVOID FsContext2;
4102 PSECTION_OBJECT_POINTERS SectionObjectPointer;
4103 PVOID PrivateCacheMap;
4104 NTSTATUS FinalStatus;
4105 struct _FILE_OBJECT *RelatedFileObject;
4106 BOOLEAN LockOperation;
4107 BOOLEAN DeletePending;
4108 BOOLEAN ReadAccess;
4109 BOOLEAN WriteAccess;
4110 BOOLEAN DeleteAccess;
4111 BOOLEAN SharedRead;
4112 BOOLEAN SharedWrite;
4113 BOOLEAN SharedDelete;
4114 ULONG Flags;
4115 UNICODE_STRING FileName;
4116 LARGE_INTEGER CurrentByteOffset;
4117 volatile ULONG Waiters;
4118 volatile ULONG Busy;
4119 PVOID LastLock;
4120 KEVENT Lock;
4121 KEVENT Event;
4122 volatile PIO_COMPLETION_CONTEXT CompletionContext;
4123 KSPIN_LOCK IrpListLock;
4124 LIST_ENTRY IrpList;
4125 volatile PVOID FileObjectExtension;
4126 } FILE_OBJECT;
4127 typedef struct _FILE_OBJECT *PFILE_OBJECT;
4128
4129 typedef struct _IO_ERROR_LOG_PACKET {
4130 UCHAR MajorFunctionCode;
4131 UCHAR RetryCount;
4132 USHORT DumpDataSize;
4133 USHORT NumberOfStrings;
4134 USHORT StringOffset;
4135 USHORT EventCategory;
4136 NTSTATUS ErrorCode;
4137 ULONG UniqueErrorValue;
4138 NTSTATUS FinalStatus;
4139 ULONG SequenceNumber;
4140 ULONG IoControlCode;
4141 LARGE_INTEGER DeviceOffset;
4142 ULONG DumpData[1];
4143 } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
4144
4145 typedef struct _IO_ERROR_LOG_MESSAGE {
4146 USHORT Type;
4147 USHORT Size;
4148 USHORT DriverNameLength;
4149 LARGE_INTEGER TimeStamp;
4150 ULONG DriverNameOffset;
4151 IO_ERROR_LOG_PACKET EntryData;
4152 } IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
4153
4154 #define ERROR_LOG_LIMIT_SIZE 240
4155 #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
4156 sizeof(IO_ERROR_LOG_PACKET) + \
4157 (sizeof(WCHAR) * 40))
4158 #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
4159 (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
4160 #define IO_ERROR_LOG_MESSAGE_LENGTH \
4161 ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
4162 ERROR_LOG_MESSAGE_LIMIT_SIZE : \
4163 PORT_MAXIMUM_MESSAGE_LENGTH)
4164 #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
4165 IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
4166
4167 typedef enum _DMA_WIDTH {
4168 Width8Bits,
4169 Width16Bits,
4170 Width32Bits,
4171 MaximumDmaWidth
4172 } DMA_WIDTH, *PDMA_WIDTH;
4173
4174 typedef enum _DMA_SPEED {
4175 Compatible,
4176 TypeA,
4177 TypeB,
4178 TypeC,
4179 TypeF,
4180 MaximumDmaSpeed
4181 } DMA_SPEED, *PDMA_SPEED;
4182
4183 /* DEVICE_DESCRIPTION.Version */
4184
4185 #define DEVICE_DESCRIPTION_VERSION 0x0000
4186 #define DEVICE_DESCRIPTION_VERSION1 0x0001
4187 #define DEVICE_DESCRIPTION_VERSION2 0x0002
4188
4189 typedef struct _DEVICE_DESCRIPTION {
4190 ULONG Version;
4191 BOOLEAN Master;
4192 BOOLEAN ScatterGather;
4193 BOOLEAN DemandMode;
4194 BOOLEAN AutoInitialize;
4195 BOOLEAN Dma32BitAddresses;
4196 BOOLEAN IgnoreCount;
4197 BOOLEAN Reserved1;
4198 BOOLEAN Dma64BitAddresses;
4199 ULONG BusNumber;
4200 ULONG DmaChannel;
4201 INTERFACE_TYPE InterfaceType;
4202 DMA_WIDTH DmaWidth;
4203 DMA_SPEED DmaSpeed;
4204 ULONG MaximumLength;
4205 ULONG DmaPort;
4206 } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
4207
4208 typedef enum _DEVICE_RELATION_TYPE {
4209 BusRelations,
4210 EjectionRelations,
4211 PowerRelations,
4212 RemovalRelations,
4213 TargetDeviceRelation,
4214 SingleBusRelations,
4215 TransportRelations
4216 } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
4217
4218 typedef struct _DEVICE_RELATIONS {
4219 ULONG Count;
4220 PDEVICE_OBJECT Objects[1];
4221 } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
4222
4223 typedef struct _DEVOBJ_EXTENSION
4224 {
4225 CSHORT Type;
4226 USHORT Size;
4227 PDEVICE_OBJECT DeviceObject;
4228 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
4229
4230 typedef struct _SCATTER_GATHER_ELEMENT {
4231 PHYSICAL_ADDRESS Address;
4232 ULONG Length;
4233 ULONG_PTR Reserved;
4234 } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
4235
4236 #if defined(_MSC_EXTENSIONS)
4237
4238 #if _MSC_VER >= 1200
4239 #pragma warning(push)
4240 #endif
4241 #pragma warning(disable:4200)
4242 typedef struct _SCATTER_GATHER_LIST {
4243 ULONG NumberOfElements;
4244 ULONG_PTR Reserved;
4245 SCATTER_GATHER_ELEMENT Elements[1];
4246 } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
4247
4248 #if _MSC_VER >= 1200
4249 #pragma warning(pop)
4250 #else
4251 #pragma warning(default:4200)
4252 #endif
4253
4254 #else
4255
4256 struct _SCATTER_GATHER_LIST;
4257 typedef struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
4258
4259 #endif
4260
4261 typedef NTSTATUS
4262 (DDKAPI DRIVER_ADD_DEVICE)(
4263 IN struct _DRIVER_OBJECT *DriverObject,
4264 IN struct _DEVICE_OBJECT *PhysicalDeviceObject);
4265 typedef DRIVER_ADD_DEVICE *PDRIVER_ADD_DEVICE;
4266
4267 typedef struct _DRIVER_EXTENSION {
4268 struct _DRIVER_OBJECT *DriverObject;
4269 PDRIVER_ADD_DEVICE AddDevice;
4270 ULONG Count;
4271 UNICODE_STRING ServiceKeyName;
4272 } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
4273
4274 #define DRVO_UNLOAD_INVOKED 0x00000001
4275 #define DRVO_LEGACY_DRIVER 0x00000002
4276 #define DRVO_BUILTIN_DRIVER 0x00000004
4277
4278 typedef NTSTATUS
4279 (DDKAPI DRIVER_INITIALIZE)(
4280 IN struct _DRIVER_OBJECT *DriverObject,
4281 IN PUNICODE_STRING RegistryPath);
4282 typedef DRIVER_INITIALIZE *PDRIVER_INITIALIZE;
4283
4284 typedef VOID
4285 (DDKAPI DRIVER_STARTIO)(
4286 IN struct _DEVICE_OBJECT *DeviceObject,
4287 IN struct _IRP *Irp);
4288 typedef DRIVER_STARTIO *PDRIVER_STARTIO;
4289
4290 typedef VOID
4291 (DDKAPI DRIVER_UNLOAD)(
4292 IN struct _DRIVER_OBJECT *DriverObject);
4293 typedef DRIVER_UNLOAD *PDRIVER_UNLOAD;
4294
4295 typedef NTSTATUS
4296 (DDKAPI DRIVER_DISPATCH)(
4297 IN struct _DEVICE_OBJECT *DeviceObject,
4298 IN struct _IRP *Irp);
4299 typedef DRIVER_DISPATCH *PDRIVER_DISPATCH;
4300
4301 typedef struct _DRIVER_OBJECT {
4302 CSHORT Type;
4303 CSHORT Size;
4304 PDEVICE_OBJECT DeviceObject;
4305 ULONG Flags;
4306 PVOID DriverStart;
4307 ULONG DriverSize;
4308 PVOID DriverSection;
4309 PDRIVER_EXTENSION DriverExtension;
4310 UNICODE_STRING DriverName;
4311 PUNICODE_STRING HardwareDatabase;
4312 struct _FAST_IO_DISPATCH *FastIoDispatch;
4313 PDRIVER_INITIALIZE DriverInit;
4314 PDRIVER_STARTIO DriverStartIo;
4315 PDRIVER_UNLOAD DriverUnload;
4316 PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
4317 } DRIVER_OBJECT;
4318 typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
4319
4320 typedef struct _DMA_ADAPTER {
4321 USHORT Version;
4322 USHORT Size;
4323 struct _DMA_OPERATIONS* DmaOperations;
4324 } DMA_ADAPTER, *PDMA_ADAPTER;
4325
4326 typedef VOID
4327 (DDKAPI *PPUT_DMA_ADAPTER)(
4328 IN PDMA_ADAPTER DmaAdapter);
4329
4330 typedef PVOID
4331 (DDKAPI *PALLOCATE_COMMON_BUFFER)(
4332 IN PDMA_ADAPTER DmaAdapter,
4333 IN ULONG Length,
4334 OUT PPHYSICAL_ADDRESS LogicalAddress,
4335 IN BOOLEAN CacheEnabled);
4336
4337 typedef VOID
4338 (DDKAPI *PFREE_COMMON_BUFFER)(
4339 IN PDMA_ADAPTER DmaAdapter,
4340 IN ULONG Length,
4341 IN PHYSICAL_ADDRESS LogicalAddress,
4342 IN PVOID VirtualAddress,
4343 IN BOOLEAN CacheEnabled);
4344
4345 typedef NTSTATUS
4346 (DDKAPI *PALLOCATE_ADAPTER_CHANNEL)(
4347 IN PDMA_ADAPTER DmaAdapter,
4348 IN PDEVICE_OBJECT DeviceObject,
4349 IN ULONG NumberOfMapRegisters,
4350 IN PDRIVER_CONTROL ExecutionRoutine,
4351 IN PVOID Context);
4352
4353 typedef BOOLEAN
4354 (DDKAPI *PFLUSH_ADAPTER_BUFFERS)(
4355 IN PDMA_ADAPTER DmaAdapter,
4356 IN PMDL Mdl,
4357 IN PVOID MapRegisterBase,
4358 IN PVOID CurrentVa,
4359 IN ULONG Length,
4360 IN BOOLEAN WriteToDevice);
4361
4362 typedef VOID
4363 (DDKAPI *PFREE_ADAPTER_CHANNEL)(
4364 IN PDMA_ADAPTER DmaAdapter);
4365
4366 typedef VOID
4367 (DDKAPI *PFREE_MAP_REGISTERS)(
4368 IN PDMA_ADAPTER DmaAdapter,
4369 PVOID MapRegisterBase,
4370 ULONG NumberOfMapRegisters);
4371
4372 typedef PHYSICAL_ADDRESS
4373 (DDKAPI *PMAP_TRANSFER)(
4374 IN PDMA_ADAPTER DmaAdapter,
4375 IN PMDL Mdl,
4376 IN PVOID MapRegisterBase,
4377 IN PVOID CurrentVa,
4378 IN OUT PULONG Length,
4379 IN BOOLEAN WriteToDevice);
4380
4381 typedef ULONG
4382 (DDKAPI *PGET_DMA_ALIGNMENT)(
4383 IN PDMA_ADAPTER DmaAdapter);
4384
4385 typedef ULONG
4386 (DDKAPI *PREAD_DMA_COUNTER)(
4387 IN PDMA_ADAPTER DmaAdapter);
4388
4389 typedef VOID
4390 (DDKAPI *PDRIVER_LIST_CONTROL)(
4391 IN struct _DEVICE_OBJECT *DeviceObject,
4392 IN struct _IRP *Irp,
4393 IN struct _SCATTER_GATHER_LIST *ScatterGather,
4394 IN PVOID Context);
4395
4396 typedef NTSTATUS
4397 (DDKAPI *PGET_SCATTER_GATHER_LIST)(
4398 IN PDMA_ADAPTER DmaAdapter,
4399 IN PDEVICE_OBJECT DeviceObject,
4400 IN PMDL Mdl,
4401 IN PVOID CurrentVa,
4402 IN ULONG Length,
4403 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
4404 IN PVOID Context,
4405 IN BOOLEAN WriteToDevice);
4406
4407 typedef VOID
4408 (DDKAPI *PPUT_SCATTER_GATHER_LIST)(
4409 IN PDMA_ADAPTER DmaAdapter,
4410 IN PSCATTER_GATHER_LIST ScatterGather,
4411 IN BOOLEAN WriteToDevice);
4412
4413 typedef NTSTATUS
4414 (DDKAPI *PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
4415 IN PDMA_ADAPTER DmaAdapter,
4416 IN PMDL Mdl OPTIONAL,
4417 IN PVOID CurrentVa,
4418 IN ULONG Length,
4419 OUT PULONG ScatterGatherListSize,
4420 OUT PULONG pNumberOfMapRegisters OPTIONAL);
4421
4422 typedef NTSTATUS
4423 (DDKAPI *PBUILD_SCATTER_GATHER_LIST)(
4424 IN PDMA_ADAPTER DmaAdapter,
4425 IN PDEVICE_OBJECT DeviceObject,
4426 IN PMDL Mdl,
4427 IN PVOID CurrentVa,
4428 IN ULONG Length,
4429 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
4430 IN PVOID Context,
4431 IN BOOLEAN WriteToDevice,
4432 IN PVOID ScatterGatherBuffer,
4433 IN ULONG ScatterGatherLength);
4434
4435 typedef NTSTATUS
4436 (DDKAPI *PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
4437 IN PDMA_ADAPTER DmaAdapter,
4438 IN PSCATTER_GATHER_LIST ScatterGather,
4439 IN PMDL OriginalMdl,
4440 OUT PMDL *TargetMdl);
4441
4442 typedef struct _DMA_OPERATIONS {
4443 ULONG Size;
4444 PPUT_DMA_ADAPTER PutDmaAdapter;
4445 PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
4446 PFREE_COMMON_BUFFER FreeCommonBuffer;
4447 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
4448 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
4449 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
4450 PFREE_MAP_REGISTERS FreeMapRegisters;
4451 PMAP_TRANSFER MapTransfer;
4452 PGET_DMA_ALIGNMENT GetDmaAlignment;
4453 PREAD_DMA_COUNTER ReadDmaCounter;
4454 PGET_SCATTER_GATHER_LIST GetScatterGatherList;
4455 PPUT_SCATTER_GATHER_LIST PutScatterGatherList;
4456 PCALCULATE_SCATTER_GATHER_LIST_SIZE CalculateScatterGatherList;
4457 PBUILD_SCATTER_GATHER_LIST BuildScatterGatherList;
4458 PBUILD_MDL_FROM_SCATTER_GATHER_LIST BuildMdlFromScatterGatherList;
4459 } DMA_OPERATIONS, *PDMA_OPERATIONS;
4460
4461 typedef struct _IO_RESOURCE_DESCRIPTOR {
4462 UCHAR Option;
4463 UCHAR Type;
4464 UCHAR ShareDisposition;
4465 UCHAR Spare1;
4466 USHORT Flags;
4467 USHORT Spare2;
4468 union {
4469 struct {
4470 ULONG Length;
4471 ULONG Alignment;
4472 PHYSICAL_ADDRESS MinimumAddress;
4473 PHYSICAL_ADDRESS MaximumAddress;
4474 } Port;
4475 struct {
4476 ULONG Length;
4477 ULONG Alignment;
4478 PHYSICAL_ADDRESS MinimumAddress;
4479 PHYSICAL_ADDRESS MaximumAddress;
4480 } Memory;
4481 struct {
4482 ULONG MinimumVector;
4483 ULONG MaximumVector;
4484 } Interrupt;
4485 struct {
4486 ULONG MinimumChannel;
4487 ULONG MaximumChannel;
4488 } Dma;
4489 struct {
4490 ULONG Length;
4491 ULONG Alignment;
4492 PHYSICAL_ADDRESS MinimumAddress;
4493 PHYSICAL_ADDRESS MaximumAddress;
4494 } Generic;
4495 struct {
4496 ULONG Data[3];
4497 } DevicePrivate;
4498 struct {
4499 ULONG Length;
4500 ULONG MinBusNumber;
4501 ULONG MaxBusNumber;
4502 ULONG Reserved;
4503 } BusNumber;
4504 struct {
4505 ULONG Priority;
4506 ULONG Reserved1;
4507 ULONG Reserved2;
4508 } ConfigData;
4509 } u;
4510 } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
4511
4512 typedef struct _IO_RESOURCE_LIST {
4513 USHORT Version;
4514 USHORT Revision;
4515 ULONG Count;
4516 IO_RESOURCE_DESCRIPTOR Descriptors[1];
4517 } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
4518
4519 typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
4520 ULONG ListSize;
4521 INTERFACE_TYPE InterfaceType;
4522 ULONG BusNumber;
4523 ULONG SlotNumber;
4524 ULONG Reserved[3];
4525 ULONG AlternativeLists;
4526 IO_RESOURCE_LIST List[1];
4527 } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
4528
4529 typedef VOID
4530 (DDKAPI DRIVER_CANCEL)(
4531 IN struct _DEVICE_OBJECT *DeviceObject,
4532 IN struct _IRP *Irp);
4533 typedef DRIVER_CANCEL *PDRIVER_CANCEL;
4534
4535 typedef struct _IRP {
4536 CSHORT Type;
4537 USHORT Size;
4538 struct _MDL *MdlAddress;
4539 ULONG Flags;
4540 union {
4541 struct _IRP *MasterIrp;
4542 volatile LONG IrpCount;
4543 PVOID SystemBuffer;
4544 } AssociatedIrp;
4545 LIST_ENTRY ThreadListEntry;
4546 IO_STATUS_BLOCK IoStatus;
4547 KPROCESSOR_MODE RequestorMode;
4548 BOOLEAN PendingReturned;
4549 CHAR StackCount;
4550 CHAR CurrentLocation;
4551 BOOLEAN Cancel;
4552 KIRQL CancelIrql;
4553 CCHAR ApcEnvironment;
4554 UCHAR AllocationFlags;
4555 PIO_STATUS_BLOCK UserIosb;
4556 PKEVENT UserEvent;
4557 union {
4558 struct {
4559 _ANONYMOUS_UNION union {
4560 PIO_APC_ROUTINE UserApcRoutine;
4561 PVOID IssuingProcess;
4562 } DUMMYUNIONNAME;
4563 PVOID UserApcContext;
4564 } AsynchronousParameters;
4565 LARGE_INTEGER AllocationSize;
4566 } Overlay;
4567 volatile PDRIVER_CANCEL CancelRoutine;
4568 PVOID UserBuffer;
4569 union {
4570 struct {
4571 _ANONYMOUS_UNION union {
4572 KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
4573 _ANONYMOUS_STRUCT struct {
4574 PVOID DriverContext[4];
4575 } DUMMYSTRUCTNAME;
4576 } DUMMYUNIONNAME;
4577 PETHREAD Thread;
4578 PCHAR AuxiliaryBuffer;
4579 _ANONYMOUS_STRUCT struct {
4580 LIST_ENTRY ListEntry;
4581 _ANONYMOUS_UNION union {
4582 struct _IO_STACK_LOCATION *CurrentStackLocation;
4583 ULONG PacketType;
4584 } DUMMYUNIONNAME;
4585 } DUMMYSTRUCTNAME;
4586 struct _FILE_OBJECT *OriginalFileObject;
4587 } Overlay;
4588 KAPC Apc;
4589 PVOID CompletionKey;
4590 } Tail;
4591 } IRP;
4592 typedef struct _IRP *PIRP;
4593
4594 typedef enum _IO_PAGING_PRIORITY {
4595 IoPagingPriorityInvalid,
4596 IoPagingPriorityNormal,
4597 IoPagingPriorityHigh,
4598 IoPagingPriorityReserved1,
4599 IoPagingPriorityReserved2
4600 } IO_PAGING_PRIORITY;
4601
4602 typedef NTSTATUS
4603 (DDKAPI IO_COMPLETION_ROUTINE)(
4604 IN struct _DEVICE_OBJECT *DeviceObject,
4605 IN struct _IRP *Irp,
4606 IN PVOID Context);
4607 typedef IO_COMPLETION_ROUTINE *PIO_COMPLETION_ROUTINE;
4608
4609 typedef VOID
4610 (DDKAPI *PIO_DPC_ROUTINE)(
4611 IN struct _KDPC *Dpc,
4612 IN struct _DEVICE_OBJECT *DeviceObject,
4613 IN struct _IRP *Irp,
4614 IN PVOID Context);
4615
4616 typedef NTSTATUS
4617 (DDKAPI *PMM_DLL_INITIALIZE)(
4618 IN PUNICODE_STRING RegistryPath);
4619
4620 typedef NTSTATUS
4621 (DDKAPI *PMM_DLL_UNLOAD)(
4622 VOID);
4623
4624 typedef BOOLEAN
4625 (DDKAPI KSERVICE_ROUTINE)(
4626 IN struct _KINTERRUPT *Interrupt,
4627 IN PVOID ServiceContext);
4628 typedef KSERVICE_ROUTINE *PKSERVICE_ROUTINE;
4629
4630 typedef VOID
4631 (DDKAPI *PIO_TIMER_ROUTINE)(
4632 IN struct _DEVICE_OBJECT *DeviceObject,
4633 IN PVOID Context);
4634
4635 typedef BOOLEAN
4636 (DDKAPI *PKSYNCHRONIZE_ROUTINE)(
4637 IN PVOID SynchronizeContext);
4638
4639 typedef struct _IO_SECURITY_CONTEXT {
4640 PSECURITY_QUALITY_OF_SERVICE SecurityQos;
4641 PACCESS_STATE AccessState;
4642 ACCESS_MASK DesiredAccess;
4643 ULONG FullCreateOptions;
4644 } IO_SECURITY_CONTEXT, *PIO_SECURITY_CONTEXT;
4645
4646 struct _IO_CSQ;
4647
4648 typedef struct _IO_CSQ_IRP_CONTEXT {
4649 ULONG Type;
4650 struct _IRP *Irp;
4651 struct _IO_CSQ *Csq;
4652 } IO_CSQ_IRP_CONTEXT, *PIO_CSQ_IRP_CONTEXT;
4653
4654 typedef VOID
4655 (DDKAPI *PIO_CSQ_INSERT_IRP)(
4656 IN struct _IO_CSQ *Csq,
4657 IN PIRP Irp);
4658
4659 typedef VOID
4660 (DDKAPI *PIO_CSQ_REMOVE_IRP)(
4661 IN struct _IO_CSQ *Csq,
4662 IN PIRP Irp);
4663
4664 typedef PIRP
4665 (DDKAPI *PIO_CSQ_PEEK_NEXT_IRP)(
4666 IN struct _IO_CSQ *Csq,