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