- 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 /* KEY_VALUE_Xxx.Type */
1590
1591 #define REG_NONE 0
1592 #define REG_SZ 1
1593 #define REG_EXPAND_SZ 2
1594 #define REG_BINARY 3
1595 #define REG_DWORD 4
1596 #define REG_DWORD_LITTLE_ENDIAN 4
1597 #define REG_DWORD_BIG_ENDIAN 5
1598 #define REG_LINK 6
1599 #define REG_MULTI_SZ 7
1600 #define REG_RESOURCE_LIST 8
1601 #define REG_FULL_RESOURCE_DESCRIPTOR 9
1602 #define REG_RESOURCE_REQUIREMENTS_LIST 10
1603 #define REG_QWORD 11
1604 #define REG_QWORD_LITTLE_ENDIAN 11
1605
1606 //
1607 // Registry Access Rights
1608 //
1609 #define KEY_QUERY_VALUE (0x0001)
1610 #define KEY_SET_VALUE (0x0002)
1611 #define KEY_CREATE_SUB_KEY (0x0004)
1612 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
1613 #define KEY_NOTIFY (0x0010)
1614 #define KEY_CREATE_LINK (0x0020)
1615 #define KEY_WOW64_32KEY (0x0200)
1616 #define KEY_WOW64_64KEY (0x0100)
1617 #define KEY_WOW64_RES (0x0300)
1618
1619 #define KEY_READ ((STANDARD_RIGHTS_READ |\
1620 KEY_QUERY_VALUE |\
1621 KEY_ENUMERATE_SUB_KEYS |\
1622 KEY_NOTIFY) \
1623 & \
1624 (~SYNCHRONIZE))
1625
1626 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
1627 KEY_SET_VALUE |\
1628 KEY_CREATE_SUB_KEY) \
1629 & \
1630 (~SYNCHRONIZE))
1631
1632 #define KEY_EXECUTE ((KEY_READ) \
1633 & \
1634 (~SYNCHRONIZE))
1635
1636 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
1637 KEY_QUERY_VALUE |\
1638 KEY_SET_VALUE |\
1639 KEY_CREATE_SUB_KEY |\
1640 KEY_ENUMERATE_SUB_KEYS |\
1641 KEY_NOTIFY |\
1642 KEY_CREATE_LINK) \
1643 & \
1644 (~SYNCHRONIZE))
1645
1646 //
1647 // Registry Open/Create Options
1648 //
1649 #define REG_OPTION_RESERVED (0x00000000L)
1650 #define REG_OPTION_NON_VOLATILE (0x00000000L)
1651 #define REG_OPTION_VOLATILE (0x00000001L)
1652 #define REG_OPTION_CREATE_LINK (0x00000002L)
1653 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
1654 #define REG_OPTION_OPEN_LINK (0x00000008L)
1655
1656 #define REG_LEGAL_OPTION \
1657 (REG_OPTION_RESERVED |\
1658 REG_OPTION_NON_VOLATILE |\
1659 REG_OPTION_VOLATILE |\
1660 REG_OPTION_CREATE_LINK |\
1661 REG_OPTION_BACKUP_RESTORE |\
1662 REG_OPTION_OPEN_LINK)
1663
1664 //
1665 // Key creation/open disposition
1666 //
1667 #define REG_CREATED_NEW_KEY (0x00000001L)
1668 #define REG_OPENED_EXISTING_KEY (0x00000002L)
1669
1670 //
1671 // Key restore & hive load flags
1672 //
1673 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
1674 #define REG_REFRESH_HIVE (0x00000002L)
1675 #define REG_NO_LAZY_FLUSH (0x00000004L)
1676 #define REG_FORCE_RESTORE (0x00000008L)
1677 #define REG_APP_HIVE (0x00000010L)
1678 #define REG_PROCESS_PRIVATE (0x00000020L)
1679 #define REG_START_JOURNAL (0x00000040L)
1680 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
1681 #define REG_HIVE_NO_RM (0x00000100L)
1682 #define REG_HIVE_SINGLE_LOG (0x00000200L)
1683
1684 //
1685 // Unload Flags
1686 //
1687 #define REG_FORCE_UNLOAD 1
1688
1689 //
1690 // Notify Filter Values
1691 //
1692 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
1693 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
1694 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
1695 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
1696
1697 #define REG_LEGAL_CHANGE_FILTER \
1698 (REG_NOTIFY_CHANGE_NAME |\
1699 REG_NOTIFY_CHANGE_ATTRIBUTES |\
1700 REG_NOTIFY_CHANGE_LAST_SET |\
1701 REG_NOTIFY_CHANGE_SECURITY)
1702
1703 typedef struct _CM_FLOPPY_DEVICE_DATA {
1704 USHORT Version;
1705 USHORT Revision;
1706 CHAR Size[8];
1707 ULONG MaxDensity;
1708 ULONG MountDensity;
1709 UCHAR StepRateHeadUnloadTime;
1710 UCHAR HeadLoadTime;
1711 UCHAR MotorOffTime;
1712 UCHAR SectorLengthCode;
1713 UCHAR SectorPerTrack;
1714 UCHAR ReadWriteGapLength;
1715 UCHAR DataTransferLength;
1716 UCHAR FormatGapLength;
1717 UCHAR FormatFillCharacter;
1718 UCHAR HeadSettleTime;
1719 UCHAR MotorSettleTime;
1720 UCHAR MaximumTrackValue;
1721 UCHAR DataTransferRate;
1722 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
1723
1724 #include <pshpack4.h>
1725 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
1726 UCHAR Type;
1727 UCHAR ShareDisposition;
1728 USHORT Flags;
1729 union {
1730 struct {
1731 PHYSICAL_ADDRESS Start;
1732 ULONG Length;
1733 } Generic;
1734 struct {
1735 PHYSICAL_ADDRESS Start;
1736 ULONG Length;
1737 } Port;
1738 struct {
1739 ULONG Level;
1740 ULONG Vector;
1741 KAFFINITY Affinity;
1742 } Interrupt;
1743 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1744 struct {
1745 __GNU_EXTENSION union {
1746 struct {
1747 USHORT Reserved;
1748 USHORT MessageCount;
1749 ULONG Vector;
1750 KAFFINITY Affinity;
1751 } Raw;
1752 struct {
1753 ULONG Level;
1754 ULONG Vector;
1755 KAFFINITY Affinity;
1756 } Translated;
1757 };
1758 } MessageInterrupt;
1759 #endif
1760 struct {
1761 PHYSICAL_ADDRESS Start;
1762 ULONG Length;
1763 } Memory;
1764 struct {
1765 ULONG Channel;
1766 ULONG Port;
1767 ULONG Reserved1;
1768 } Dma;
1769 struct {
1770 ULONG Data[3];
1771 } DevicePrivate;
1772 struct {
1773 ULONG Start;
1774 ULONG Length;
1775 ULONG Reserved;
1776 } BusNumber;
1777 struct {
1778 ULONG DataSize;
1779 ULONG Reserved1;
1780 ULONG Reserved2;
1781 } DeviceSpecificData;
1782 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1783 struct {
1784 PHYSICAL_ADDRESS Start;
1785 ULONG Length40;
1786 } Memory40;
1787 struct {
1788 PHYSICAL_ADDRESS Start;
1789 ULONG Length48;
1790 } Memory48;
1791 struct {
1792 PHYSICAL_ADDRESS Start;
1793 ULONG Length64;
1794 } Memory64;
1795 #endif
1796 } u;
1797 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
1798 #include <poppack.h>
1799
1800 #include <pshpack1.h>
1801 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
1802
1803 #define CmResourceTypeNull 0
1804 #define CmResourceTypePort 1
1805 #define CmResourceTypeInterrupt 2
1806 #define CmResourceTypeMemory 3
1807 #define CmResourceTypeDma 4
1808 #define CmResourceTypeDeviceSpecific 5
1809 #define CmResourceTypeBusNumber 6
1810 #define CmResourceTypeMemoryLarge 7
1811 #define CmResourceTypeNonArbitrated 128
1812 #define CmResourceTypeConfigData 128
1813 #define CmResourceTypeDevicePrivate 129
1814 #define CmResourceTypePcCardConfig 130
1815 #define CmResourceTypeMfCardConfig 131
1816
1817 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
1818
1819 typedef enum _CM_SHARE_DISPOSITION {
1820 CmResourceShareUndetermined,
1821 CmResourceShareDeviceExclusive,
1822 CmResourceShareDriverExclusive,
1823 CmResourceShareShared
1824 } CM_SHARE_DISPOSITION;
1825
1826 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
1827
1828 #define CM_RESOURCE_PORT_MEMORY 0x0000
1829 #define CM_RESOURCE_PORT_IO 0x0001
1830 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
1831 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
1832 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
1833 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
1834 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
1835 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
1836 #define CM_RESOURCE_PORT_BAR 0x0100
1837
1838 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
1839
1840 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
1841 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
1842 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
1843 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
1844
1845 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
1846
1847 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
1848 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
1849 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
1850 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
1851 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
1852 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
1853 #define CM_RESOURCE_MEMORY_24 0x0010
1854 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
1855 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
1856 #define CM_RESOURCE_MEMORY_BAR 0x0080
1857 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
1858
1859 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
1860
1861 #define CM_RESOURCE_DMA_8 0x0000
1862 #define CM_RESOURCE_DMA_16 0x0001
1863 #define CM_RESOURCE_DMA_32 0x0002
1864 #define CM_RESOURCE_DMA_8_AND_16 0x0004
1865 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
1866 #define CM_RESOURCE_DMA_TYPE_A 0x0010
1867 #define CM_RESOURCE_DMA_TYPE_B 0x0020
1868 #define CM_RESOURCE_DMA_TYPE_F 0x0040
1869
1870 typedef struct _CM_PARTIAL_RESOURCE_LIST {
1871 USHORT Version;
1872 USHORT Revision;
1873 ULONG Count;
1874 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
1875 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
1876
1877 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
1878 INTERFACE_TYPE InterfaceType;
1879 ULONG BusNumber;
1880 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
1881 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
1882
1883 typedef struct _CM_RESOURCE_LIST {
1884 ULONG Count;
1885 CM_FULL_RESOURCE_DESCRIPTOR List[1];
1886 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
1887
1888 typedef struct _CM_INT13_DRIVE_PARAMETER {
1889 USHORT DriveSelect;
1890 ULONG MaxCylinders;
1891 USHORT SectorsPerTrack;
1892 USHORT MaxHeads;
1893 USHORT NumberDrives;
1894 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
1895
1896 typedef struct _CM_PNP_BIOS_DEVICE_NODE
1897 {
1898 USHORT Size;
1899 UCHAR Node;
1900 ULONG ProductId;
1901 UCHAR DeviceType[3];
1902 USHORT DeviceAttributes;
1903 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
1904
1905 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
1906 {
1907 UCHAR Signature[4];
1908 UCHAR Revision;
1909 UCHAR Length;
1910 USHORT ControlField;
1911 UCHAR Checksum;
1912 ULONG EventFlagAddress;
1913 USHORT RealModeEntryOffset;
1914 USHORT RealModeEntrySegment;
1915 USHORT ProtectedModeEntryOffset;
1916 ULONG ProtectedModeCodeBaseAddress;
1917 ULONG OemDeviceId;
1918 USHORT RealModeDataBaseAddress;
1919 ULONG ProtectedModeDataBaseAddress;
1920 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
1921
1922 #include <poppack.h>
1923
1924 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
1925 {
1926 ULONG BytesPerSector;
1927 ULONG NumberOfCylinders;
1928 ULONG SectorsPerTrack;
1929 ULONG NumberOfHeads;
1930 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
1931
1932 typedef struct _CM_KEYBOARD_DEVICE_DATA {
1933 USHORT Version;
1934 USHORT Revision;
1935 UCHAR Type;
1936 UCHAR Subtype;
1937 USHORT KeyboardFlags;
1938 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
1939
1940 typedef struct _CM_MCA_POS_DATA {
1941 USHORT AdapterId;
1942 UCHAR PosData1;
1943 UCHAR PosData2;
1944 UCHAR PosData3;
1945 UCHAR PosData4;
1946 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
1947
1948 #if (NTDDI_VERSION >= NTDDI_WINXP)
1949 typedef struct CM_Power_Data_s {
1950 ULONG PD_Size;
1951 DEVICE_POWER_STATE PD_MostRecentPowerState;
1952 ULONG PD_Capabilities;
1953 ULONG PD_D1Latency;
1954 ULONG PD_D2Latency;
1955 ULONG PD_D3Latency;
1956 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
1957 SYSTEM_POWER_STATE PD_DeepestSystemWake;
1958 } CM_POWER_DATA, *PCM_POWER_DATA;
1959
1960 #define PDCAP_D0_SUPPORTED 0x00000001
1961 #define PDCAP_D1_SUPPORTED 0x00000002
1962 #define PDCAP_D2_SUPPORTED 0x00000004
1963 #define PDCAP_D3_SUPPORTED 0x00000008
1964 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
1965 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
1966 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
1967 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
1968 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
1969
1970 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
1971
1972 typedef struct _CM_SCSI_DEVICE_DATA {
1973 USHORT Version;
1974 USHORT Revision;
1975 UCHAR HostIdentifier;
1976 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
1977
1978 typedef struct _CM_SERIAL_DEVICE_DATA {
1979 USHORT Version;
1980 USHORT Revision;
1981 ULONG BaudClock;
1982 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
1983
1984 typedef enum _KEY_INFORMATION_CLASS {
1985 KeyBasicInformation,
1986 KeyNodeInformation,
1987 KeyFullInformation,
1988 KeyNameInformation,
1989 KeyCachedInformation,
1990 KeyFlagsInformation
1991 } KEY_INFORMATION_CLASS;
1992
1993 typedef struct _KEY_BASIC_INFORMATION {
1994 LARGE_INTEGER LastWriteTime;
1995 ULONG TitleIndex;
1996 ULONG NameLength;
1997 WCHAR Name[1];
1998 } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
1999
2000 typedef struct _KEY_FULL_INFORMATION {
2001 LARGE_INTEGER LastWriteTime;
2002 ULONG TitleIndex;
2003 ULONG ClassOffset;
2004 ULONG ClassLength;
2005 ULONG SubKeys;
2006 ULONG MaxNameLen;
2007 ULONG MaxClassLen;
2008 ULONG Values;
2009 ULONG MaxValueNameLen;
2010 ULONG MaxValueDataLen;
2011 WCHAR Class[1];
2012 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
2013
2014 typedef struct _KEY_NODE_INFORMATION {
2015 LARGE_INTEGER LastWriteTime;
2016 ULONG TitleIndex;
2017 ULONG ClassOffset;
2018 ULONG ClassLength;
2019 ULONG NameLength;
2020 WCHAR Name[1];
2021 } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
2022
2023 typedef struct _KEY_VALUE_BASIC_INFORMATION {
2024 ULONG TitleIndex;
2025 ULONG Type;
2026 ULONG NameLength;
2027 WCHAR Name[1];
2028 } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
2029
2030 typedef struct _KEY_VALUE_FULL_INFORMATION {
2031 ULONG TitleIndex;
2032 ULONG Type;
2033 ULONG DataOffset;
2034 ULONG DataLength;
2035 ULONG NameLength;
2036 WCHAR Name[1];
2037 } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
2038
2039 typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
2040 ULONG TitleIndex;
2041 ULONG Type;
2042 ULONG DataLength;
2043 UCHAR Data[1];
2044 } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
2045
2046 typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
2047 ULONG Type;
2048 ULONG DataLength;
2049 UCHAR Data[1];
2050 } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
2051
2052 typedef struct _KEY_VALUE_ENTRY {
2053 PUNICODE_STRING ValueName;
2054 ULONG DataLength;
2055 ULONG DataOffset;
2056 ULONG Type;
2057 } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
2058
2059 typedef enum _KEY_VALUE_INFORMATION_CLASS {
2060 KeyValueBasicInformation,
2061 KeyValueFullInformation,
2062 KeyValuePartialInformation,
2063 KeyValueFullInformationAlign64,
2064 KeyValuePartialInformationAlign64
2065 } KEY_VALUE_INFORMATION_CLASS;
2066
2067 typedef struct _KEY_WRITE_TIME_INFORMATION {
2068 LARGE_INTEGER LastWriteTime;
2069 } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
2070
2071 typedef enum _KEY_SET_INFORMATION_CLASS {
2072 KeyWriteTimeInformation,
2073 KeyWow64FlagsInformation,
2074 KeyControlFlagsInformation,
2075 KeySetVirtualizationInformation,
2076 KeySetDebugInformation,
2077 KeySetHandleTagsInformation,
2078 MaxKeySetInfoClass
2079 } KEY_SET_INFORMATION_CLASS;
2080
2081 /******************************************************************************
2082 * I/O Manager Functions *
2083 ******************************************************************************/
2084
2085 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
2086 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
2087
2088 #define DMA_MACROS_DEFINED
2089
2090 FORCEINLINE
2091 NTSTATUS
2092 IoAllocateAdapterChannel(
2093 IN PADAPTER_OBJECT AdapterObject,
2094 IN PDEVICE_OBJECT DeviceObject,
2095 IN ULONG NumberOfMapRegisters,
2096 IN PDRIVER_CONTROL ExecutionRoutine,
2097 IN PVOID Context)
2098 {
2099 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
2100 AllocateAdapterChannel =
2101 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
2102 ASSERT(AllocateAdapterChannel);
2103 return AllocateAdapterChannel(DmaAdapter,
2104 DeviceObject,
2105 NumberOfMapRegisters,
2106 ExecutionRoutine,
2107 Context );
2108 }
2109
2110 FORCEINLINE
2111 BOOLEAN
2112 IoFlushAdapterBuffers(
2113 IN PADAPTER_OBJECT AdapterObject,
2114 IN PMDL Mdl,
2115 IN PVOID MapRegisterBase,
2116 IN PVOID CurrentVa,
2117 IN ULONG Length,
2118 IN BOOLEAN WriteToDevice)
2119 {
2120 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
2121 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
2122 ASSERT(FlushAdapterBuffers);
2123 return FlushAdapterBuffers(DmaAdapter,
2124 Mdl,
2125 MapRegisterBase,
2126 CurrentVa,
2127 Length,
2128 WriteToDevice );
2129 }
2130
2131 FORCEINLINE
2132 VOID
2133 IoFreeAdapterChannel(
2134 IN PADAPTER_OBJECT AdapterObject)
2135 {
2136 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
2137 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
2138 ASSERT(FreeAdapterChannel);
2139 FreeAdapterChannel(DmaAdapter);
2140 }
2141
2142 FORCEINLINE
2143 VOID
2144 IoFreeMapRegisters(
2145 IN PADAPTER_OBJECT AdapterObject,
2146 IN PVOID MapRegisterBase,
2147 IN ULONG NumberOfMapRegisters)
2148 {
2149 PFREE_MAP_REGISTERS FreeMapRegisters;
2150 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
2151 ASSERT(FreeMapRegisters);
2152 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
2153 }
2154
2155 FORCEINLINE
2156 PHYSICAL_ADDRESS
2157 IoMapTransfer(
2158 IN PDMA_ADAPTER DmaAdapter,
2159 IN PMDL Mdl,
2160 IN PVOID MapRegisterBase,
2161 IN PVOID CurrentVa,
2162 IN OUT PULONG Length,
2163 IN BOOLEAN WriteToDevice)
2164 {
2165 PMAP_TRANSFER MapTransfer;
2166
2167 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
2168 ASSERT(MapTransfer);
2169 return MapTransfer(DmaAdapter,
2170 Mdl,
2171 MapRegisterBase,
2172 CurrentVa,
2173 Length,
2174 WriteToDevice);
2175 }
2176 #endif
2177
2178 /* PCI_COMMON_CONFIG.Command */
2179
2180 #define PCI_ENABLE_IO_SPACE 0x0001
2181 #define PCI_ENABLE_MEMORY_SPACE 0x0002
2182 #define PCI_ENABLE_BUS_MASTER 0x0004
2183 #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
2184 #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
2185 #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
2186 #define PCI_ENABLE_PARITY 0x0040
2187 #define PCI_ENABLE_WAIT_CYCLE 0x0080
2188 #define PCI_ENABLE_SERR 0x0100
2189 #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200
2190 #define PCI_DISABLE_LEVEL_INTERRUPT 0x0400
2191
2192 /* PCI_COMMON_CONFIG.Status */
2193
2194 #define PCI_STATUS_INTERRUPT_PENDING 0x0008
2195 #define PCI_STATUS_CAPABILITIES_LIST 0x0010
2196 #define PCI_STATUS_66MHZ_CAPABLE 0x0020
2197 #define PCI_STATUS_UDF_SUPPORTED 0x0040
2198 #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080
2199 #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
2200 #define PCI_STATUS_DEVSEL 0x0600
2201 #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
2202 #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
2203 #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
2204 #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
2205 #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
2206
2207 /* PCI_COMMON_CONFIG.HeaderType */
2208
2209 #define PCI_MULTIFUNCTION 0x80
2210 #define PCI_DEVICE_TYPE 0x00
2211 #define PCI_BRIDGE_TYPE 0x01
2212 #define PCI_CARDBUS_BRIDGE_TYPE 0x02
2213
2214 #define PCI_CONFIGURATION_TYPE(PciData) \
2215 (((PPCI_COMMON_CONFIG) (PciData))->HeaderType & ~PCI_MULTIFUNCTION)
2216
2217 #define PCI_MULTIFUNCTION_DEVICE(PciData) \
2218 ((((PPCI_COMMON_CONFIG) (PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
2219
2220 /* PCI device classes */
2221
2222 #define PCI_CLASS_PRE_20 0x00
2223 #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
2224 #define PCI_CLASS_NETWORK_CTLR 0x02
2225 #define PCI_CLASS_DISPLAY_CTLR 0x03
2226 #define PCI_CLASS_MULTIMEDIA_DEV 0x04
2227 #define PCI_CLASS_MEMORY_CTLR 0x05
2228 #define PCI_CLASS_BRIDGE_DEV 0x06
2229 #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
2230 #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
2231 #define PCI_CLASS_INPUT_DEV 0x09
2232 #define PCI_CLASS_DOCKING_STATION 0x0a
2233 #define PCI_CLASS_PROCESSOR 0x0b
2234 #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
2235 #define PCI_CLASS_WIRELESS_CTLR 0x0d
2236 #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
2237 #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
2238 #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
2239 #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
2240
2241 /* PCI device subclasses for class 0 */
2242
2243 #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
2244 #define PCI_SUBCLASS_PRE_20_VGA 0x01
2245
2246 /* PCI device subclasses for class 1 (mass storage controllers)*/
2247
2248 #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
2249 #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
2250 #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
2251 #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
2252 #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
2253 #define PCI_SUBCLASS_MSC_OTHER 0x80
2254
2255 /* PCI device subclasses for class 2 (network controllers)*/
2256
2257 #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
2258 #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
2259 #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
2260 #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
2261 #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
2262 #define PCI_SUBCLASS_NET_OTHER 0x80
2263
2264 /* PCI device subclasses for class 3 (display controllers)*/
2265
2266 #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
2267 #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
2268 #define PCI_SUBCLASS_VID_3D_CTLR 0x02
2269 #define PCI_SUBCLASS_VID_OTHER 0x80
2270
2271 /* PCI device subclasses for class 4 (multimedia device)*/
2272
2273 #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
2274 #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
2275 #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
2276 #define PCI_SUBCLASS_MM_OTHER 0x80
2277
2278 /* PCI device subclasses for class 5 (memory controller)*/
2279
2280 #define PCI_SUBCLASS_MEM_RAM 0x00
2281 #define PCI_SUBCLASS_MEM_FLASH 0x01
2282 #define PCI_SUBCLASS_MEM_OTHER 0x80
2283
2284 /* PCI device subclasses for class 6 (bridge device)*/
2285
2286 #define PCI_SUBCLASS_BR_HOST 0x00
2287 #define PCI_SUBCLASS_BR_ISA 0x01
2288 #define PCI_SUBCLASS_BR_EISA 0x02
2289 #define PCI_SUBCLASS_BR_MCA 0x03
2290 #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
2291 #define PCI_SUBCLASS_BR_PCMCIA 0x05
2292 #define PCI_SUBCLASS_BR_NUBUS 0x06
2293 #define PCI_SUBCLASS_BR_CARDBUS 0x07
2294 #define PCI_SUBCLASS_BR_RACEWAY 0x08
2295 #define PCI_SUBCLASS_BR_OTHER 0x80
2296
2297 /* PCI device subclasses for class C (serial bus controller)*/
2298
2299 #define PCI_SUBCLASS_SB_IEEE1394 0x00
2300 #define PCI_SUBCLASS_SB_ACCESS 0x01
2301 #define PCI_SUBCLASS_SB_SSA 0x02
2302 #define PCI_SUBCLASS_SB_USB 0x03
2303 #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
2304 #define PCI_SUBCLASS_SB_SMBUS 0x05
2305
2306 #define PCI_MAX_DEVICES 32
2307 #define PCI_MAX_FUNCTION 8
2308 #define PCI_MAX_BRIDGE_NUMBER 0xFF
2309 #define PCI_INVALID_VENDORID 0xFFFF
2310 #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET(PCI_COMMON_CONFIG, DeviceSpecific))
2311
2312 #define PCI_ADDRESS_IO_SPACE 0x00000001
2313 #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006
2314 #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008
2315 #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
2316 #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
2317 #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
2318
2319 #define PCI_TYPE_32BIT 0
2320 #define PCI_TYPE_20BIT 2
2321 #define PCI_TYPE_64BIT 4
2322
2323 #define POOL_COLD_ALLOCATION 256
2324 #define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 8
2325 #define POOL_RAISE_IF_ALLOCATION_FAILURE 16
2326
2327 #define PCI_TYPE0_ADDRESSES 6
2328 #define PCI_TYPE1_ADDRESSES 2
2329 #define PCI_TYPE2_ADDRESSES 5
2330
2331 #define IO_TYPE_ADAPTER 1
2332 #define IO_TYPE_CONTROLLER 2
2333 #define IO_TYPE_DEVICE 3
2334 #define IO_TYPE_DRIVER 4
2335 #define IO_TYPE_FILE 5
2336 #define IO_TYPE_IRP 6
2337 #define IO_TYPE_MASTER_ADAPTER 7
2338 #define IO_TYPE_OPEN_PACKET 8
2339 #define IO_TYPE_TIMER 9
2340 #define IO_TYPE_VPB 10
2341 #define IO_TYPE_ERROR_LOG 11
2342 #define IO_TYPE_ERROR_MESSAGE 12
2343 #define IO_TYPE_DEVICE_OBJECT_EXTENSION 13
2344
2345 #define IO_TYPE_CSQ_IRP_CONTEXT 1
2346 #define IO_TYPE_CSQ 2
2347 #define IO_TYPE_CSQ_EX 3
2348
2349 /* IO_RESOURCE_DESCRIPTOR.Option */
2350
2351 #define IO_RESOURCE_PREFERRED 0x01
2352 #define IO_RESOURCE_DEFAULT 0x02
2353 #define IO_RESOURCE_ALTERNATIVE 0x08
2354
2355 /* DEVICE_OBJECT.Flags */
2356
2357 #define DO_VERIFY_VOLUME 0x00000002
2358 #define DO_BUFFERED_IO 0x00000004
2359 #define DO_EXCLUSIVE 0x00000008
2360 #define DO_DIRECT_IO 0x00000010
2361 #define DO_MAP_IO_BUFFER 0x00000020
2362 #define DO_DEVICE_INITIALIZING 0x00000080
2363 #define DO_SHUTDOWN_REGISTERED 0x00000800
2364 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
2365 #define DO_POWER_PAGABLE 0x00002000
2366 #define DO_POWER_INRUSH 0x00004000
2367
2368 /* DEVICE_OBJECT.Characteristics */
2369
2370 #define FILE_REMOVABLE_MEDIA 0x00000001
2371 #define FILE_READ_ONLY_DEVICE 0x00000002
2372 #define FILE_FLOPPY_DISKETTE 0x00000004
2373 #define FILE_WRITE_ONCE_MEDIA 0x00000008
2374 #define FILE_REMOTE_DEVICE 0x00000010
2375 #define FILE_DEVICE_IS_MOUNTED 0x00000020
2376 #define FILE_VIRTUAL_VOLUME 0x00000040
2377 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
2378 #define FILE_DEVICE_SECURE_OPEN 0x00000100
2379 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
2380 #define FILE_CHARACTERISTIC_TS_DEVICE 0x00001000
2381 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE 0x00002000
2382
2383 /* DEVICE_OBJECT.AlignmentRequirement */
2384
2385 #define FILE_BYTE_ALIGNMENT 0x00000000
2386 #define FILE_WORD_ALIGNMENT 0x00000001
2387 #define FILE_LONG_ALIGNMENT 0x00000003
2388 #define FILE_QUAD_ALIGNMENT 0x00000007
2389 #define FILE_OCTA_ALIGNMENT 0x0000000f
2390 #define FILE_32_BYTE_ALIGNMENT 0x0000001f
2391 #define FILE_64_BYTE_ALIGNMENT 0x0000003f
2392 #define FILE_128_BYTE_ALIGNMENT 0x0000007f
2393 #define FILE_256_BYTE_ALIGNMENT 0x000000ff
2394 #define FILE_512_BYTE_ALIGNMENT 0x000001ff
2395
2396 /* DEVICE_OBJECT.DeviceType */
2397
2398 #define DEVICE_TYPE ULONG
2399
2400 #define FILE_DEVICE_BEEP 0x00000001
2401 #define FILE_DEVICE_CD_ROM 0x00000002
2402 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
2403 #define FILE_DEVICE_CONTROLLER 0x00000004
2404 #define FILE_DEVICE_DATALINK 0x00000005
2405 #define FILE_DEVICE_DFS 0x00000006
2406 #define FILE_DEVICE_DISK 0x00000007
2407 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
2408 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
2409 #define FILE_DEVICE_INPORT_PORT 0x0000000a
2410 #define FILE_DEVICE_KEYBOARD 0x0000000b
2411 #define FILE_DEVICE_MAILSLOT 0x0000000c
2412 #define FILE_DEVICE_MIDI_IN 0x0000000d
2413 #define FILE_DEVICE_MIDI_OUT 0x0000000e
2414 #define FILE_DEVICE_MOUSE 0x0000000f
2415 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
2416 #define FILE_DEVICE_NAMED_PIPE 0x00000011
2417 #define FILE_DEVICE_NETWORK 0x00000012
2418 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
2419 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
2420 #define FILE_DEVICE_NULL 0x00000015
2421 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
2422 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
2423 #define FILE_DEVICE_PRINTER 0x00000018
2424 #define FILE_DEVICE_SCANNER 0x00000019
2425 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
2426 #define FILE_DEVICE_SERIAL_PORT 0x0000001b
2427 #define FILE_DEVICE_SCREEN 0x0000001c
2428 #define FILE_DEVICE_SOUND 0x0000001d
2429 #define FILE_DEVICE_STREAMS 0x0000001e
2430 #define FILE_DEVICE_TAPE 0x0000001f
2431 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
2432 #define FILE_DEVICE_TRANSPORT 0x00000021
2433 #define FILE_DEVICE_UNKNOWN 0x00000022
2434 #define FILE_DEVICE_VIDEO 0x00000023
2435 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
2436 #define FILE_DEVICE_WAVE_IN 0x00000025
2437 #define FILE_DEVICE_WAVE_OUT 0x00000026
2438 #define FILE_DEVICE_8042_PORT 0x00000027
2439 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
2440 #define FILE_DEVICE_BATTERY 0x00000029
2441 #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
2442 #define FILE_DEVICE_MODEM 0x0000002b
2443 #define FILE_DEVICE_VDM 0x0000002c
2444 #define FILE_DEVICE_MASS_STORAGE 0x0000002d
2445 #define FILE_DEVICE_SMB 0x0000002e
2446 #define FILE_DEVICE_KS 0x0000002f
2447 #define FILE_DEVICE_CHANGER 0x00000030
2448 #define FILE_DEVICE_SMARTCARD 0x00000031
2449 #define FILE_DEVICE_ACPI 0x00000032
2450 #define FILE_DEVICE_DVD 0x00000033
2451 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
2452 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
2453 #define FILE_DEVICE_DFS_VOLUME 0x00000036
2454 #define FILE_DEVICE_SERENUM 0x00000037
2455 #define FILE_DEVICE_TERMSRV 0x00000038
2456 #define FILE_DEVICE_KSEC 0x00000039
2457 #define FILE_DEVICE_FIPS 0x0000003a
2458 #define FILE_DEVICE_INFINIBAND 0x0000003b
2459 #define FILE_DEVICE_VMBUS 0x0000003e
2460 #define FILE_DEVICE_CRYPT_PROVIDER 0x0000003f
2461 #define FILE_DEVICE_WPD 0x00000040
2462 #define FILE_DEVICE_BLUETOOTH 0x00000041
2463 #define FILE_DEVICE_MT_COMPOSITE 0x00000042
2464 #define FILE_DEVICE_MT_TRANSPORT 0x00000043
2465 #define FILE_DEVICE_BIOMETRIC 0x00000044
2466 #define FILE_DEVICE_PMI 0x00000045
2467
2468 typedef struct _PCI_SLOT_NUMBER {
2469 union {
2470 struct {
2471 ULONG DeviceNumber : 5;
2472 ULONG FunctionNumber : 3;
2473 ULONG Reserved : 24;
2474 } bits;
2475 ULONG AsULONG;
2476 } u;
2477 } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
2478
2479 typedef struct _IO_STATUS_BLOCK {
2480 _ANONYMOUS_UNION union {
2481 NTSTATUS Status;
2482 PVOID Pointer;
2483 } DUMMYUNIONNAME;
2484 ULONG_PTR Information;
2485 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
2486
2487 typedef VOID
2488 (DDKAPI *PIO_APC_ROUTINE)(
2489 IN PVOID ApcContext,
2490 IN PIO_STATUS_BLOCK IoStatusBlock,
2491 IN ULONG Reserved);
2492
2493 #define EVENT_INCREMENT 1
2494 #define IO_NO_INCREMENT 0
2495 #define IO_CD_ROM_INCREMENT 1
2496 #define IO_DISK_INCREMENT 1
2497 #define IO_KEYBOARD_INCREMENT 6
2498 #define IO_MAILSLOT_INCREMENT 2
2499 #define IO_MOUSE_INCREMENT 6
2500 #define IO_NAMED_PIPE_INCREMENT 2
2501 #define IO_NETWORK_INCREMENT 2
2502 #define IO_PARALLEL_INCREMENT 1
2503 #define IO_SERIAL_INCREMENT 2
2504 #define IO_SOUND_INCREMENT 8
2505 #define IO_VIDEO_INCREMENT 1
2506 #define SEMAPHORE_INCREMENT 1
2507
2508 #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
2509
2510 typedef struct _BOOTDISK_INFORMATION {
2511 LONGLONG BootPartitionOffset;
2512 LONGLONG SystemPartitionOffset;
2513 ULONG BootDeviceSignature;
2514 ULONG SystemDeviceSignature;
2515 } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
2516
2517 typedef struct _BOOTDISK_INFORMATION_EX {
2518 LONGLONG BootPartitionOffset;
2519 LONGLONG SystemPartitionOffset;
2520 ULONG BootDeviceSignature;
2521 ULONG SystemDeviceSignature;
2522 GUID BootDeviceGuid;
2523 GUID SystemDeviceGuid;
2524 BOOLEAN BootDeviceIsGpt;
2525 BOOLEAN SystemDeviceIsGpt;
2526 } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
2527
2528 typedef struct _EISA_MEMORY_TYPE {
2529 UCHAR ReadWrite : 1;
2530 UCHAR Cached : 1;
2531 UCHAR Reserved0 : 1;
2532 UCHAR Type : 2;
2533 UCHAR Shared : 1;
2534 UCHAR Reserved1 : 1;
2535 UCHAR MoreEntries : 1;
2536 } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
2537
2538 #include <pshpack1.h>
2539 typedef struct _EISA_MEMORY_CONFIGURATION {
2540 EISA_MEMORY_TYPE ConfigurationByte;
2541 UCHAR DataSize;
2542 USHORT AddressLowWord;
2543 UCHAR AddressHighByte;
2544 USHORT MemorySize;
2545 } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
2546 #include <poppack.h>
2547
2548 typedef struct _EISA_IRQ_DESCRIPTOR {
2549 UCHAR Interrupt : 4;
2550 UCHAR Reserved : 1;
2551 UCHAR LevelTriggered : 1;
2552 UCHAR Shared : 1;
2553 UCHAR MoreEntries : 1;
2554 } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
2555
2556 typedef struct _EISA_IRQ_CONFIGURATION {
2557 EISA_IRQ_DESCRIPTOR ConfigurationByte;
2558 UCHAR Reserved;
2559 } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
2560
2561 typedef struct _DMA_CONFIGURATION_BYTE0 {
2562 UCHAR Channel : 3;
2563 UCHAR Reserved : 3;
2564 UCHAR Shared : 1;
2565 UCHAR MoreEntries : 1;
2566 } DMA_CONFIGURATION_BYTE0;
2567
2568 typedef struct _DMA_CONFIGURATION_BYTE1 {
2569 UCHAR Reserved0 : 2;
2570 UCHAR TransferSize : 2;
2571 UCHAR Timing : 2;
2572 UCHAR Reserved1 : 2;
2573 } DMA_CONFIGURATION_BYTE1;
2574
2575 typedef struct _EISA_DMA_CONFIGURATION {
2576 DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
2577 DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
2578 } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
2579
2580 #include <pshpack1.h>
2581 typedef struct _EISA_PORT_DESCRIPTOR {
2582 UCHAR NumberPorts : 5;
2583 UCHAR Reserved : 1;
2584 UCHAR Shared : 1;
2585 UCHAR MoreEntries : 1;
2586 } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
2587
2588 typedef struct _EISA_PORT_CONFIGURATION {
2589 EISA_PORT_DESCRIPTOR Configuration;
2590 USHORT PortAddress;
2591 } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
2592 #include <poppack.h>
2593
2594 typedef struct _CM_EISA_FUNCTION_INFORMATION {
2595 ULONG CompressedId;
2596 UCHAR IdSlotFlags1;
2597 UCHAR IdSlotFlags2;
2598 UCHAR MinorRevision;
2599 UCHAR MajorRevision;
2600 UCHAR Selections[26];
2601 UCHAR FunctionFlags;
2602 UCHAR TypeString[80];
2603 EISA_MEMORY_CONFIGURATION EisaMemory[9];
2604 EISA_IRQ_CONFIGURATION EisaIrq[7];
2605 EISA_DMA_CONFIGURATION EisaDma[4];
2606 EISA_PORT_CONFIGURATION EisaPort[20];
2607 UCHAR InitializationData[60];
2608 } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
2609
2610 /* CM_EISA_FUNCTION_INFORMATION.FunctionFlags */
2611
2612 #define EISA_FUNCTION_ENABLED 0x80
2613 #define EISA_FREE_FORM_DATA 0x40
2614 #define EISA_HAS_PORT_INIT_ENTRY 0x20
2615 #define EISA_HAS_PORT_RANGE 0x10
2616 #define EISA_HAS_DMA_ENTRY 0x08
2617 #define EISA_HAS_IRQ_ENTRY 0x04
2618 #define EISA_HAS_MEMORY_ENTRY 0x02
2619 #define EISA_HAS_TYPE_ENTRY 0x01
2620 #define EISA_HAS_INFORMATION \
2621 (EISA_HAS_PORT_RANGE + EISA_HAS_DMA_ENTRY + EISA_HAS_IRQ_ENTRY \
2622 + EISA_HAS_MEMORY_ENTRY + EISA_HAS_TYPE_ENTRY)
2623
2624 typedef struct _CM_EISA_SLOT_INFORMATION {
2625 UCHAR ReturnCode;
2626 UCHAR ReturnFlags;
2627 UCHAR MajorRevision;
2628 UCHAR MinorRevision;
2629 USHORT Checksum;
2630 UCHAR NumberFunctions;
2631 UCHAR FunctionInformation;
2632 ULONG CompressedId;
2633 } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
2634
2635 /* CM_EISA_SLOT_INFORMATION.ReturnCode */
2636
2637 #define EISA_INVALID_SLOT 0x80
2638 #define EISA_INVALID_FUNCTION 0x81
2639 #define EISA_INVALID_CONFIGURATION 0x82
2640 #define EISA_EMPTY_SLOT 0x83
2641 #define EISA_INVALID_BIOS_CALL 0x86
2642
2643 /*
2644 ** Plug and Play structures
2645 */
2646
2647 typedef VOID
2648 (DDKAPI *PINTERFACE_REFERENCE)(
2649 PVOID Context);
2650
2651 typedef VOID
2652 (DDKAPI *PINTERFACE_DEREFERENCE)(
2653 PVOID Context);
2654
2655 typedef BOOLEAN
2656 (DDKAPI *PTRANSLATE_BUS_ADDRESS)(
2657 IN PVOID Context,
2658 IN PHYSICAL_ADDRESS BusAddress,
2659 IN ULONG Length,
2660 IN OUT PULONG AddressSpace,
2661 OUT PPHYSICAL_ADDRESS TranslatedAddress);
2662
2663 typedef struct _DMA_ADAPTER*
2664 (DDKAPI *PGET_DMA_ADAPTER)(
2665 IN PVOID Context,
2666 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
2667 OUT PULONG NumberOfMapRegisters);
2668
2669 typedef ULONG
2670 (DDKAPI *PGET_SET_DEVICE_DATA)(
2671 IN PVOID Context,
2672 IN ULONG DataType,
2673 IN PVOID Buffer,
2674 IN ULONG Offset,
2675 IN ULONG Length);
2676
2677 /* PCI_DEVICE_PRESENCE_PARAMETERS.Flags */
2678 #define PCI_USE_SUBSYSTEM_IDS 0x00000001
2679 #define PCI_USE_REVISION 0x00000002
2680 #define PCI_USE_VENDEV_IDS 0x00000004
2681 #define PCI_USE_CLASS_SUBCLASS 0x00000008
2682 #define PCI_USE_PROGIF 0x00000010
2683 #define PCI_USE_LOCAL_BUS 0x00000020
2684 #define PCI_USE_LOCAL_DEVICE 0x00000040
2685
2686 typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
2687 ULONG Size;
2688 ULONG Flags;
2689 USHORT VendorID;
2690 USHORT DeviceID;
2691 UCHAR RevisionID;
2692 USHORT SubVendorID;
2693 USHORT SubSystemID;
2694 UCHAR BaseClass;
2695 UCHAR SubClass;
2696 UCHAR ProgIf;
2697 } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
2698
2699 typedef BOOLEAN
2700 (DDKAPI *PPCI_IS_DEVICE_PRESENT)(
2701 IN USHORT VendorID,
2702 IN USHORT DeviceID,
2703 IN UCHAR RevisionID,
2704 IN USHORT SubVendorID,
2705 IN USHORT SubSystemID,
2706 IN ULONG Flags);
2707
2708 typedef BOOLEAN
2709 (DDKAPI *PPCI_IS_DEVICE_PRESENT_EX)(
2710 IN PVOID Context,
2711 IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters);
2712
2713 typedef union _POWER_STATE {
2714 SYSTEM_POWER_STATE SystemState;
2715 DEVICE_POWER_STATE DeviceState;
2716 } POWER_STATE, *PPOWER_STATE;
2717
2718 typedef enum _POWER_STATE_TYPE {
2719 SystemPowerState = 0,
2720 DevicePowerState
2721 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
2722
2723 typedef struct _BUS_INTERFACE_STANDARD {
2724 USHORT Size;
2725 USHORT Version;
2726 PVOID Context;
2727 PINTERFACE_REFERENCE InterfaceReference;
2728 PINTERFACE_DEREFERENCE InterfaceDereference;
2729 PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
2730 PGET_DMA_ADAPTER GetDmaAdapter;
2731 PGET_SET_DEVICE_DATA SetBusData;
2732 PGET_SET_DEVICE_DATA GetBusData;
2733 } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
2734
2735 typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
2736 USHORT Size;
2737 USHORT Version;
2738 PVOID Context;
2739 PINTERFACE_REFERENCE InterfaceReference;
2740 PINTERFACE_DEREFERENCE InterfaceDereference;
2741 PPCI_IS_DEVICE_PRESENT IsDevicePresent;
2742 PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
2743 } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
2744
2745 typedef struct _DEVICE_CAPABILITIES {
2746 USHORT Size;
2747 USHORT Version;
2748 ULONG DeviceD1 : 1;
2749 ULONG DeviceD2 : 1;
2750 ULONG LockSupported : 1;
2751 ULONG EjectSupported : 1;
2752 ULONG Removable : 1;
2753 ULONG DockDevice : 1;
2754 ULONG UniqueID : 1;
2755 ULONG SilentInstall : 1;
2756 ULONG RawDeviceOK : 1;
2757 ULONG SurpriseRemovalOK : 1;
2758 ULONG WakeFromD0 : 1;
2759 ULONG WakeFromD1 : 1;
2760 ULONG WakeFromD2 : 1;
2761 ULONG WakeFromD3 : 1;
2762 ULONG HardwareDisabled : 1;
2763 ULONG NonDynamic : 1;
2764 ULONG WarmEjectSupported : 1;
2765 ULONG NoDisplayInUI : 1;
2766 ULONG Reserved : 14;
2767 ULONG Address;
2768 ULONG UINumber;
2769 DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
2770 SYSTEM_POWER_STATE SystemWake;
2771 DEVICE_POWER_STATE DeviceWake;
2772 ULONG D1Latency;
2773 ULONG D2Latency;
2774 ULONG D3Latency;
2775 } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
2776
2777 typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
2778 USHORT Version;
2779 USHORT Size;
2780 GUID Event;
2781 GUID InterfaceClassGuid;
2782 PUNICODE_STRING SymbolicLinkName;
2783 } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
2784
2785 typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
2786 USHORT Version;
2787 USHORT Size;
2788 GUID Event;
2789 } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
2790
2791 #undef INTERFACE
2792
2793 typedef struct _INTERFACE {
2794 USHORT Size;
2795 USHORT Version;
2796 PVOID Context;
2797 PINTERFACE_REFERENCE InterfaceReference;
2798 PINTERFACE_DEREFERENCE InterfaceDereference;
2799 } INTERFACE, *PINTERFACE;
2800
2801 typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
2802 USHORT Version;
2803 USHORT Size;
2804 GUID Event;
2805 } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
2806
2807 typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
2808
2809 /* PNP_DEVICE_STATE */
2810
2811 #define PNP_DEVICE_DISABLED 0x00000001
2812 #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
2813 #define PNP_DEVICE_FAILED 0x00000004
2814 #define PNP_DEVICE_REMOVED 0x00000008
2815 #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
2816 #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
2817
2818 typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
2819 USHORT Version;
2820 USHORT Size;
2821 GUID Event;
2822 struct _FILE_OBJECT *FileObject;
2823 LONG NameBufferOffset;
2824 UCHAR CustomDataBuffer[1];
2825 } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
2826
2827 typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
2828 USHORT Version;
2829 USHORT Size;
2830 GUID Event;
2831 struct _FILE_OBJECT *FileObject;
2832 } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
2833
2834 typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
2835 DeviceUsageTypeUndefined,
2836 DeviceUsageTypePaging,
2837 DeviceUsageTypeHibernation,
2838 DeviceUsageTypeDumpFile
2839 } DEVICE_USAGE_NOTIFICATION_TYPE;
2840
2841 typedef struct _POWER_SEQUENCE {
2842 ULONG SequenceD1;
2843 ULONG SequenceD2;
2844 ULONG SequenceD3;
2845 } POWER_SEQUENCE, *PPOWER_SEQUENCE;
2846
2847 typedef enum {
2848 DevicePropertyDeviceDescription = 0x0,
2849 DevicePropertyHardwareID = 0x1,
2850 DevicePropertyCompatibleIDs = 0x2,
2851 DevicePropertyBootConfiguration = 0x3,
2852 DevicePropertyBootConfigurationTranslated = 0x4,
2853 DevicePropertyClassName = 0x5,
2854 DevicePropertyClassGuid = 0x6,
2855 DevicePropertyDriverKeyName = 0x7,
2856 DevicePropertyManufacturer = 0x8,
2857 DevicePropertyFriendlyName = 0x9,
2858 DevicePropertyLocationInformation = 0xa,
2859 DevicePropertyPhysicalDeviceObjectName = 0xb,
2860 DevicePropertyBusTypeGuid = 0xc,
2861 DevicePropertyLegacyBusType = 0xd,
2862 DevicePropertyBusNumber = 0xe,
2863 DevicePropertyEnumeratorName = 0xf,
2864 DevicePropertyAddress = 0x10,
2865 DevicePropertyUINumber = 0x11,
2866 DevicePropertyInstallState = 0x12,
2867 DevicePropertyRemovalPolicy = 0x13,
2868 DevicePropertyResourceRequirements = 0x14,
2869 DevicePropertyAllocatedResources = 0x15,
2870 DevicePropertyContainerID = 0x16
2871 } DEVICE_REGISTRY_PROPERTY;
2872
2873 typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
2874 EventCategoryReserved,
2875 EventCategoryHardwareProfileChange,
2876 EventCategoryDeviceInterfaceChange,
2877 EventCategoryTargetDeviceChange
2878 } IO_NOTIFICATION_EVENT_CATEGORY;
2879
2880 #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
2881
2882 typedef NTSTATUS
2883 (DDKAPI *PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)(
2884 IN PVOID NotificationStructure,
2885 IN PVOID Context);
2886
2887 typedef VOID
2888 (DDKAPI *PDEVICE_CHANGE_COMPLETE_CALLBACK)(
2889 IN PVOID Context);
2890
2891 typedef enum _FILE_INFORMATION_CLASS {
2892 FileDirectoryInformation = 1,
2893 FileFullDirectoryInformation,
2894 FileBothDirectoryInformation,
2895 FileBasicInformation,
2896 FileStandardInformation,
2897 FileInternalInformation,
2898 FileEaInformation,
2899 FileAccessInformation,
2900 FileNameInformation,
2901 FileRenameInformation,
2902 FileLinkInformation,
2903 FileNamesInformation,
2904 FileDispositionInformation,
2905 FilePositionInformation,
2906 FileFullEaInformation,
2907 FileModeInformation,
2908 FileAlignmentInformation,
2909 FileAllInformation,
2910 FileAllocationInformation,
2911 FileEndOfFileInformation,
2912 FileAlternateNameInformation,
2913 FileStreamInformation,
2914 FilePipeInformation,
2915 FilePipeLocalInformation,
2916 FilePipeRemoteInformation,
2917 FileMailslotQueryInformation,
2918 FileMailslotSetInformation,
2919 FileCompressionInformation,
2920 FileObjectIdInformation,
2921 FileCompletionInformation,
2922 FileMoveClusterInformation,
2923 FileQuotaInformation,
2924 FileReparsePointInformation,
2925 FileNetworkOpenInformation,
2926 FileAttributeTagInformation,
2927 FileTrackingInformation,
2928 FileIdBothDirectoryInformation,
2929 FileIdFullDirectoryInformation,
2930 FileValidDataLengthInformation,
2931 FileShortNameInformation,
2932 FileIoCompletionNotificationInformation,
2933 FileIoStatusBlockRangeInformation,
2934 FileIoPriorityHintInformation,
2935 FileSfioReserveInformation,
2936 FileSfioVolumeInformation,
2937 FileHardLinkInformation,
2938 FileProcessIdsUsingFileInformation,
2939 FileNormalizedNameInformation,
2940 FileNetworkPhysicalNameInformation,
2941 FileIdGlobalTxDirectoryInformation,
2942 FileIsRemoteDeviceInformation,
2943 FileAttributeCacheInformation,
2944 FileNumaNodeInformation,
2945 FileStandardLinkInformation,
2946 FileRemoteProtocolInformation,
2947 FileMaximumInformation
2948 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
2949
2950 typedef struct _FILE_POSITION_INFORMATION {
2951 LARGE_INTEGER CurrentByteOffset;
2952 } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
2953
2954 #include <pshpack8.h>
2955 typedef struct _FILE_BASIC_INFORMATION {
2956 LARGE_INTEGER CreationTime;
2957 LARGE_INTEGER LastAccessTime;
2958 LARGE_INTEGER LastWriteTime;
2959 LARGE_INTEGER ChangeTime;
2960 ULONG FileAttributes;
2961 } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
2962 #include <poppack.h>
2963
2964 typedef struct _FILE_STANDARD_INFORMATION {
2965 LARGE_INTEGER AllocationSize;
2966 LARGE_INTEGER EndOfFile;
2967 ULONG NumberOfLinks;
2968 BOOLEAN DeletePending;
2969 BOOLEAN Directory;
2970 } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
2971
2972 typedef struct _FILE_NETWORK_OPEN_INFORMATION {
2973 LARGE_INTEGER CreationTime;
2974 LARGE_INTEGER LastAccessTime;
2975 LARGE_INTEGER LastWriteTime;
2976 LARGE_INTEGER ChangeTime;
2977 LARGE_INTEGER AllocationSize;
2978 LARGE_INTEGER EndOfFile;
2979 ULONG FileAttributes;
2980 } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
2981
2982 typedef enum _FSINFOCLASS {
2983 FileFsVolumeInformation = 1,
2984 FileFsLabelInformation,
2985 FileFsSizeInformation,
2986 FileFsDeviceInformation,
2987 FileFsAttributeInformation,
2988 FileFsControlInformation,
2989 FileFsFullSizeInformation,
2990 FileFsObjectIdInformation,
2991 FileFsDriverPathInformation,
2992 FileFsVolumeFlagsInformation,
2993 FileFsMaximumInformation
2994 } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
2995
2996 typedef struct _FILE_FS_DEVICE_INFORMATION {
2997 DEVICE_TYPE DeviceType;
2998 ULONG Characteristics;
2999 } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
3000
3001 typedef struct _FILE_FULL_EA_INFORMATION {
3002 ULONG NextEntryOffset;
3003 UCHAR Flags;
3004 UCHAR EaNameLength;
3005 USHORT EaValueLength;
3006 CHAR EaName[1];
3007 } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
3008
3009 typedef struct _FAST_MUTEX
3010 {
3011 LONG Count;
3012 PKTHREAD Owner;
3013 ULONG Contention;
3014 KEVENT Gate;
3015 ULONG OldIrql;
3016 } FAST_MUTEX, *PFAST_MUTEX;
3017
3018 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
3019
3020 typedef struct _OWNER_ENTRY {
3021 ERESOURCE_THREAD OwnerThread;
3022 _ANONYMOUS_UNION union {
3023 LONG OwnerCount;
3024 ULONG TableSize;
3025 } DUMMYUNIONNAME;
3026 } OWNER_ENTRY, *POWNER_ENTRY;
3027
3028 typedef struct _ERESOURCE
3029 {
3030 LIST_ENTRY SystemResourcesList;
3031 POWNER_ENTRY OwnerTable;
3032 SHORT ActiveCount;
3033 USHORT Flag;
3034 volatile PKSEMAPHORE SharedWaiters;
3035 volatile PKEVENT ExclusiveWaiters;
3036 OWNER_ENTRY OwnerEntry;
3037 ULONG ActiveEntries;
3038 ULONG ContentionCount;
3039 ULONG NumberOfSharedWaiters;
3040 ULONG NumberOfExclusiveWaiters;
3041 __GNU_EXTENSION union
3042 {
3043 PVOID Address;
3044 ULONG_PTR CreatorBackTraceIndex;
3045 };
3046 KSPIN_LOCK SpinLock;
3047 } ERESOURCE, *PERESOURCE;
3048
3049 /* ERESOURCE.Flag */
3050
3051 #define ResourceNeverExclusive 0x0010
3052 #define ResourceReleaseByOtherThread 0x0020
3053 #define ResourceOwnedExclusive 0x0080
3054
3055 #define RESOURCE_HASH_TABLE_SIZE 64
3056
3057 typedef BOOLEAN
3058 (DDKAPI *PFAST_IO_CHECK_IF_POSSIBLE)(
3059 IN struct _FILE_OBJECT *FileObject,
3060 IN PLARGE_INTEGER FileOffset,
3061 IN ULONG Length,
3062 IN BOOLEAN Wait,
3063 IN ULONG LockKey,
3064 IN BOOLEAN CheckForReadOperation,
3065 OUT PIO_STATUS_BLOCK IoStatus,
3066 IN struct _DEVICE_OBJECT *DeviceObject);
3067
3068 typedef BOOLEAN
3069 (DDKAPI *PFAST_IO_READ)(
3070 IN struct _FILE_OBJECT *FileObject,
3071 IN PLARGE_INTEGER FileOffset,
3072 IN ULONG Length,
3073 IN BOOLEAN Wait,
3074 IN ULONG LockKey,
3075 OUT PVOID Buffer,
3076 OUT PIO_STATUS_BLOCK IoStatus,
3077 IN struct _DEVICE_OBJECT *DeviceObject);
3078
3079 typedef BOOLEAN
3080 (DDKAPI *PFAST_IO_WRITE)(
3081 IN struct _FILE_OBJECT *FileObject,
3082 IN PLARGE_INTEGER FileOffset,
3083 IN ULONG Length,
3084 IN BOOLEAN Wait,
3085 IN ULONG LockKey,
3086 IN PVOID Buffer,
3087 OUT PIO_STATUS_BLOCK IoStatus,
3088 IN struct _DEVICE_OBJECT *DeviceObject);
3089
3090 typedef BOOLEAN
3091 (DDKAPI *PFAST_IO_QUERY_BASIC_INFO)(
3092 IN struct _FILE_OBJECT *FileObject,
3093 IN BOOLEAN Wait,
3094 OUT PFILE_BASIC_INFORMATION Buffer,
3095 OUT PIO_STATUS_BLOCK IoStatus,
3096 IN struct _DEVICE_OBJECT *DeviceObject);
3097
3098 typedef BOOLEAN
3099 (DDKAPI *PFAST_IO_QUERY_STANDARD_INFO)(
3100 IN struct _FILE_OBJECT *FileObject,
3101 IN BOOLEAN Wait,
3102 OUT PFILE_STANDARD_INFORMATION Buffer,
3103 OUT PIO_STATUS_BLOCK IoStatus,
3104 IN struct _DEVICE_OBJECT *DeviceObject);
3105
3106 typedef BOOLEAN
3107 (DDKAPI *PFAST_IO_LOCK)(
3108 IN struct _FILE_OBJECT *FileObject,
3109 IN PLARGE_INTEGER FileOffset,
3110 IN PLARGE_INTEGER Length,
3111 PEPROCESS ProcessId,
3112 ULONG Key,
3113 BOOLEAN FailImmediately,
3114 BOOLEAN ExclusiveLock,
3115 OUT PIO_STATUS_BLOCK IoStatus,
3116 IN struct _DEVICE_OBJECT *DeviceObject);
3117
3118 typedef BOOLEAN
3119 (DDKAPI *PFAST_IO_UNLOCK_SINGLE)(
3120 IN struct _FILE_OBJECT *FileObject,
3121 IN PLARGE_INTEGER FileOffset,
3122 IN PLARGE_INTEGER Length,
3123 PEPROCESS ProcessId,
3124 ULONG Key,
3125 OUT PIO_STATUS_BLOCK IoStatus,
3126 IN struct _DEVICE_OBJECT *DeviceObject);
3127
3128 typedef BOOLEAN
3129 (DDKAPI *PFAST_IO_UNLOCK_ALL)(
3130 IN struct _FILE_OBJECT *FileObject,
3131 PEPROCESS ProcessId,
3132 OUT PIO_STATUS_BLOCK IoStatus,
3133 IN struct _DEVICE_OBJECT *DeviceObject);
3134
3135 typedef BOOLEAN
3136 (DDKAPI *PFAST_IO_UNLOCK_ALL_BY_KEY)(
3137 IN struct _FILE_OBJECT *FileObject,
3138 PVOID ProcessId,
3139 ULONG Key,
3140 OUT PIO_STATUS_BLOCK IoStatus,
3141 IN struct _DEVICE_OBJECT *DeviceObject);
3142
3143 typedef BOOLEAN
3144 (DDKAPI *PFAST_IO_DEVICE_CONTROL)(
3145 IN struct _FILE_OBJECT *FileObject,
3146 IN BOOLEAN Wait,
3147 IN PVOID InputBuffer OPTIONAL,
3148 IN ULONG InputBufferLength,
3149 OUT PVOID OutputBuffer OPTIONAL,
3150 IN ULONG OutputBufferLength,
3151 IN ULONG IoControlCode,
3152 OUT PIO_STATUS_BLOCK IoStatus,
3153 IN struct _DEVICE_OBJECT *DeviceObject);
3154
3155 typedef VOID
3156 (DDKAPI *PFAST_IO_ACQUIRE_FILE)(
3157 IN struct _FILE_OBJECT *FileObject);
3158
3159 typedef VOID
3160 (DDKAPI *PFAST_IO_RELEASE_FILE)(
3161 IN struct _FILE_OBJECT *FileObject);
3162
3163 typedef VOID
3164 (DDKAPI *PFAST_IO_DETACH_DEVICE)(
3165 IN struct _DEVICE_OBJECT *SourceDevice,
3166 IN struct _DEVICE_OBJECT *TargetDevice);
3167
3168 typedef BOOLEAN
3169 (DDKAPI *PFAST_IO_QUERY_NETWORK_OPEN_INFO)(
3170 IN struct _FILE_OBJECT *FileObject,
3171 IN BOOLEAN Wait,
3172 OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
3173 OUT struct _IO_STATUS_BLOCK *IoStatus,
3174 IN struct _DEVICE_OBJECT *DeviceObject);
3175
3176 typedef NTSTATUS
3177 (DDKAPI *PFAST_IO_ACQUIRE_FOR_MOD_WRITE)(
3178 IN struct _FILE_OBJECT *FileObject,
3179 IN PLARGE_INTEGER EndingOffset,
3180 OUT struct _ERESOURCE **ResourceToRelease,
3181 IN struct _DEVICE_OBJECT *DeviceObject);
3182
3183 typedef BOOLEAN
3184 (DDKAPI *PFAST_IO_MDL_READ)(
3185 IN struct _FILE_OBJECT *FileObject,
3186 IN PLARGE_INTEGER FileOffset,
3187 IN ULONG Length,
3188 IN ULONG LockKey,
3189 OUT PMDL *MdlChain,
3190 OUT PIO_STATUS_BLOCK IoStatus,
3191 IN struct _DEVICE_OBJECT *DeviceObject);
3192
3193 typedef BOOLEAN
3194 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE)(
3195 IN struct _FILE_OBJECT *FileObject,
3196 IN PMDL MdlChain,
3197 IN struct _DEVICE_OBJECT *DeviceObject);
3198
3199 typedef BOOLEAN
3200 (DDKAPI *PFAST_IO_PREPARE_MDL_WRITE)(
3201 IN struct _FILE_OBJECT *FileObject,
3202 IN PLARGE_INTEGER FileOffset,
3203 IN ULONG Length,
3204 IN ULONG LockKey,
3205 OUT PMDL *MdlChain,
3206 OUT PIO_STATUS_BLOCK IoStatus,
3207 IN struct _DEVICE_OBJECT *DeviceObject);
3208
3209 typedef BOOLEAN
3210 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE)(
3211 IN struct _FILE_OBJECT *FileObject,
3212 IN PLARGE_INTEGER FileOffset,
3213 IN PMDL MdlChain,
3214 IN struct _DEVICE_OBJECT *DeviceObject);
3215
3216 typedef BOOLEAN
3217 (DDKAPI *PFAST_IO_READ_COMPRESSED)(
3218 IN struct _FILE_OBJECT *FileObject,
3219 IN PLARGE_INTEGER FileOffset,
3220 IN ULONG Length,
3221 IN ULONG LockKey,
3222 OUT PVOID Buffer,
3223 OUT PMDL *MdlChain,
3224 OUT PIO_STATUS_BLOCK IoStatus,
3225 OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3226 IN ULONG CompressedDataInfoLength,
3227 IN struct _DEVICE_OBJECT *DeviceObject);
3228
3229 typedef BOOLEAN
3230 (DDKAPI *PFAST_IO_WRITE_COMPRESSED)(
3231 IN struct _FILE_OBJECT *FileObject,
3232 IN PLARGE_INTEGER FileOffset,
3233 IN ULONG Length,
3234 IN ULONG LockKey,
3235 IN PVOID Buffer,
3236 OUT PMDL *MdlChain,
3237 OUT PIO_STATUS_BLOCK IoStatus,
3238 IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3239 IN ULONG CompressedDataInfoLength,
3240 IN struct _DEVICE_OBJECT *DeviceObject);
3241
3242 typedef BOOLEAN
3243 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE_COMPRESSED)(
3244 IN struct _FILE_OBJECT *FileObject,
3245 IN PMDL MdlChain,
3246 IN struct _DEVICE_OBJECT *DeviceObject);
3247
3248 typedef BOOLEAN
3249 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED)(
3250 IN struct _FILE_OBJECT *FileObject,
3251 IN PLARGE_INTEGER FileOffset,
3252 IN PMDL MdlChain,
3253 IN struct _DEVICE_OBJECT *DeviceObject);
3254
3255 typedef BOOLEAN
3256 (DDKAPI *PFAST_IO_QUERY_OPEN)(
3257 IN struct _IRP *Irp,
3258 OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
3259 IN struct _DEVICE_OBJECT *DeviceObject);
3260
3261 typedef NTSTATUS
3262 (DDKAPI *PFAST_IO_RELEASE_FOR_MOD_WRITE)(
3263 IN struct _FILE_OBJECT *FileObject,
3264 IN struct _ERESOURCE *ResourceToRelease,
3265 IN struct _DEVICE_OBJECT *DeviceObject);
3266
3267 typedef NTSTATUS
3268 (DDKAPI *PFAST_IO_ACQUIRE_FOR_CCFLUSH)(
3269 IN struct _FILE_OBJECT *FileObject,
3270 IN struct _DEVICE_OBJECT *DeviceObject);
3271
3272 typedef NTSTATUS
3273 (DDKAPI *PFAST_IO_RELEASE_FOR_CCFLUSH) (
3274 IN struct _FILE_OBJECT *FileObject,
3275 IN struct _DEVICE_OBJECT *DeviceObject);
3276
3277 typedef struct _FAST_IO_DISPATCH {
3278 ULONG SizeOfFastIoDispatch;
3279 PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
3280 PFAST_IO_READ FastIoRead;
3281 PFAST_IO_WRITE FastIoWrite;
3282 PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
3283 PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
3284 PFAST_IO_LOCK FastIoLock;
3285 PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
3286 PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
3287 PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
3288 PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
3289 PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
3290 PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
3291 PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
3292 PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
3293 PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
3294 PFAST_IO_MDL_READ MdlRead;
3295 PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
3296 PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
3297 PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
3298 PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
3299 PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
3300 PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
3301 PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
3302 PFAST_IO_QUERY_OPEN FastIoQueryOpen;
3303 PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
3304 PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
3305 PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
3306 } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
3307
3308 typedef struct _SECTION_OBJECT_POINTERS {
3309 PVOID DataSectionObject;
3310 PVOID SharedCacheMap;
3311 PVOID ImageSectionObject;
3312 } SECTION_OBJECT_POINTERS, *PSECTION_OBJECT_POINTERS;
3313
3314 typedef struct _IO_COMPLETION_CONTEXT {
3315 PVOID Port;
3316 PVOID Key;
3317 } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
3318
3319 /* FILE_OBJECT.Flags */
3320
3321 #define FO_FILE_OPEN 0x00000001
3322 #define FO_SYNCHRONOUS_IO 0x00000002
3323 #define FO_ALERTABLE_IO 0x00000004
3324 #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
3325 #define FO_WRITE_THROUGH 0x00000010
3326 #define FO_SEQUENTIAL_ONLY 0x00000020
3327 #define FO_CACHE_SUPPORTED 0x00000040
3328 #define FO_NAMED_PIPE 0x00000080
3329 #define FO_STREAM_FILE 0x00000100
3330 #define FO_MAILSLOT 0x00000200
3331 #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
3332 #define FO_QUEUE_IRP_TO_THREAD 0x00000400
3333 #define FO_DIRECT_DEVICE_OPEN 0x00000800
3334 #define FO_FILE_MODIFIED 0x00001000
3335 #define FO_FILE_SIZE_CHANGED 0x00002000
3336 #define FO_CLEANUP_COMPLETE 0x00004000
3337 #define FO_TEMPORARY_FILE 0x00008000
3338 #define FO_DELETE_ON_CLOSE 0x00010000
3339 #define FO_OPENED_CASE_SENSITIVE 0x00020000
3340 #define FO_HANDLE_CREATED 0x00040000
3341 #define FO_FILE_FAST_IO_READ 0x00080000
3342 #define FO_RANDOM_ACCESS 0x00100000
3343 #define FO_FILE_OPEN_CANCELLED 0x00200000
3344 #define FO_VOLUME_OPEN 0x00400000
3345 #define FO_REMOTE_ORIGIN 0x01000000
3346 #define FO_DISALLOW_EXCLUSIVE 0x02000000
3347 #define FO_SKIP_COMPLETION_PORT 0x02000000
3348 #define FO_SKIP_SET_EVENT 0x04000000
3349 #define FO_SKIP_SET_FAST_IO 0x08000000
3350
3351 /* VPB.Flags */
3352 #define VPB_MOUNTED 0x0001
3353 #define VPB_LOCKED 0x0002
3354 #define VPB_PERSISTENT 0x0004
3355 #define VPB_REMOVE_PENDING 0x0008
3356 #define VPB_RAW_MOUNT 0x0010
3357 #define VPB_DIRECT_WRITES_ALLOWED 0x0020
3358
3359 #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR))
3360
3361 /* IRP.Flags */
3362
3363 #define SL_FORCE_ACCESS_CHECK 0x01
3364 #define SL_OPEN_PAGING_FILE 0x02
3365 #define SL_OPEN_TARGET_DIRECTORY 0x04
3366 #define SL_CASE_SENSITIVE 0x80
3367
3368 #define SL_KEY_SPECIFIED 0x01
3369 #define SL_OVERRIDE_VERIFY_VOLUME 0x02
3370 #define SL_WRITE_THROUGH 0x04
3371 #define SL_FT_SEQUENTIAL_WRITE 0x08
3372
3373 #define SL_FAIL_IMMEDIATELY 0x01
3374 #define SL_EXCLUSIVE_LOCK 0x02
3375
3376 #define SL_RESTART_SCAN 0x01
3377 #define SL_RETURN_SINGLE_ENTRY 0x02
3378 #define SL_INDEX_SPECIFIED 0x04
3379
3380 #define SL_WATCH_TREE 0x01
3381
3382 #define SL_ALLOW_RAW_MOUNT 0x01
3383
3384 #define CTL_CODE(DeviceType, Function, Method, Access)( \
3385 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
3386
3387 #define DEVICE_TYPE_FROM_CTL_CODE(ctl) (((ULONG) (ctl & 0xffff0000)) >> 16)
3388
3389 #define IRP_NOCACHE 0x00000001
3390 #define IRP_PAGING_IO 0x00000002
3391 #define IRP_MOUNT_COMPLETION 0x00000002
3392 #define IRP_SYNCHRONOUS_API 0x00000004
3393 #define IRP_ASSOCIATED_IRP 0x00000008
3394 #define IRP_BUFFERED_IO 0x00000010
3395 #define IRP_DEALLOCATE_BUFFER 0x00000020
3396 #define IRP_INPUT_OPERATION 0x00000040
3397 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
3398 #define IRP_CREATE_OPERATION 0x00000080
3399 #define IRP_READ_OPERATION 0x00000100
3400 #define IRP_WRITE_OPERATION 0x00000200
3401 #define IRP_CLOSE_OPERATION 0x00000400
3402 #define IRP_DEFER_IO_COMPLETION 0x00000800
3403 #define IRP_OB_QUERY_NAME 0x00001000
3404 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
3405
3406 #define IRP_QUOTA_CHARGED 0x01
3407 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
3408 #define IRP_ALLOCATED_FIXED_SIZE 0x04
3409 #define IRP_LOOKASIDE_ALLOCATION 0x08
3410
3411 /*
3412 ** IRP function codes
3413 */
3414
3415 #define IRP_MJ_CREATE 0x00
3416 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
3417 #define IRP_MJ_CLOSE 0x02
3418 #define IRP_MJ_READ 0x03
3419 #define IRP_MJ_WRITE 0x04
3420 #define IRP_MJ_QUERY_INFORMATION 0x05
3421 #define IRP_MJ_SET_INFORMATION 0x06
3422 #define IRP_MJ_QUERY_EA 0x07
3423 #define IRP_MJ_SET_EA 0x08
3424 #define IRP_MJ_FLUSH_BUFFERS 0x09
3425 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
3426 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
3427 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
3428 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
3429 #define IRP_MJ_DEVICE_CONTROL 0x0e
3430 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
3431 #define IRP_MJ_SCSI 0x0f
3432 #define IRP_MJ_SHUTDOWN 0x10
3433 #define IRP_MJ_LOCK_CONTROL 0x11
3434 #define IRP_MJ_CLEANUP 0x12
3435 #define IRP_MJ_CREATE_MAILSLOT 0x13
3436 #define IRP_MJ_QUERY_SECURITY 0x14
3437 #define IRP_MJ_SET_SECURITY 0x15
3438 #define IRP_MJ_POWER 0x16
3439 #define IRP_MJ_SYSTEM_CONTROL 0x17
3440 #define IRP_MJ_DEVICE_CHANGE 0x18
3441 #define IRP_MJ_QUERY_QUOTA 0x19
3442 #define IRP_MJ_SET_QUOTA 0x1a
3443 #define IRP_MJ_PNP 0x1b
3444 #define IRP_MJ_PNP_POWER 0x1b
3445 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
3446
3447 #define IRP_MN_SCSI_CLASS 0x01
3448
3449 #define IRP_MN_START_DEVICE 0x00
3450 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
3451 #define IRP_MN_REMOVE_DEVICE 0x02
3452 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
3453 #define IRP_MN_STOP_DEVICE 0x04
3454 #define IRP_MN_QUERY_STOP_DEVICE 0x05
3455 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
3456
3457 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
3458 #define IRP_MN_QUERY_INTERFACE 0x08
3459 #define IRP_MN_QUERY_CAPABILITIES 0x09
3460 #define IRP_MN_QUERY_RESOURCES 0x0A
3461 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
3462 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
3463 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
3464
3465 #define IRP_MN_READ_CONFIG 0x0F
3466 #define IRP_MN_WRITE_CONFIG 0x10
3467 #define IRP_MN_EJECT 0x11
3468 #define IRP_MN_SET_LOCK 0x12
3469 #define IRP_MN_QUERY_ID 0x13
3470 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
3471 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
3472 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
3473 #define IRP_MN_SURPRISE_REMOVAL 0x17
3474
3475 #define IRP_MN_WAIT_WAKE 0x00
3476 #define IRP_MN_POWER_SEQUENCE 0x01
3477 #define IRP_MN_SET_POWER 0x02
3478 #define IRP_MN_QUERY_POWER 0x03
3479
3480 #define IRP_MN_QUERY_ALL_DATA 0x00
3481 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
3482 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
3483 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
3484 #define IRP_MN_ENABLE_EVENTS 0x04
3485 #define IRP_MN_DISABLE_EVENTS 0x05
3486 #define IRP_MN_ENABLE_COLLECTION 0x06
3487 #define IRP_MN_DISABLE_COLLECTION 0x07
3488 #define IRP_MN_REGINFO 0x08
3489 #define IRP_MN_EXECUTE_METHOD 0x09
3490
3491 #define IRP_MN_REGINFO_EX 0x0b
3492
3493 typedef struct _VPB {
3494 CSHORT Type;
3495 CSHORT Size;
3496 USHORT Flags;
3497 USHORT VolumeLabelLength;
3498 struct _DEVICE_OBJECT *DeviceObject;
3499 struct _DEVICE_OBJECT *RealDevice;
3500 ULONG SerialNumber;
3501 ULONG ReferenceCount;
3502 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
3503 } VPB, *PVPB;
3504
3505 typedef struct _DEVICE_OBJECT {
3506 CSHORT Type;
3507 USHORT Size;
3508 LONG ReferenceCount;
3509 struct _DRIVER_OBJECT *DriverObject;
3510 struct _DEVICE_OBJECT *NextDevice;
3511 struct _DEVICE_OBJECT *AttachedDevice;
3512 struct _IRP *CurrentIrp;
3513 PIO_TIMER Timer;
3514 ULONG Flags;
3515 ULONG Characteristics;
3516 volatile PVPB Vpb;
3517 PVOID DeviceExtension;
3518 DEVICE_TYPE DeviceType;
3519 CCHAR StackSize;
3520 union {
3521 LIST_ENTRY ListEntry;
3522 WAIT_CONTEXT_BLOCK Wcb;
3523 } Queue;
3524 ULONG AlignmentRequirement;
3525 KDEVICE_QUEUE DeviceQueue;
3526 KDPC Dpc;
3527 ULONG ActiveThreadCount;
3528 PSECURITY_DESCRIPTOR SecurityDescriptor;
3529 KEVENT DeviceLock;
3530 USHORT SectorSize;
3531 USHORT Spare1;
3532 struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
3533 PVOID Reserved;
3534 } DEVICE_OBJECT, *PDEVICE_OBJECT;
3535
3536 typedef struct _FILE_OBJECT
3537 {
3538 CSHORT Type;
3539 CSHORT Size;
3540 PDEVICE_OBJECT DeviceObject;
3541 PVPB Vpb;
3542 PVOID FsContext;
3543 PVOID FsContext2;
3544 PSECTION_OBJECT_POINTERS SectionObjectPointer;
3545 PVOID PrivateCacheMap;
3546 NTSTATUS FinalStatus;
3547 struct _FILE_OBJECT *RelatedFileObject;
3548 BOOLEAN LockOperation;
3549 BOOLEAN DeletePending;
3550 BOOLEAN ReadAccess;
3551 BOOLEAN WriteAccess;
3552 BOOLEAN DeleteAccess;
3553 BOOLEAN SharedRead;
3554 BOOLEAN SharedWrite;
3555 BOOLEAN SharedDelete;
3556 ULONG Flags;
3557 UNICODE_STRING FileName;
3558 LARGE_INTEGER CurrentByteOffset;
3559 volatile ULONG Waiters;
3560 volatile ULONG Busy;
3561 PVOID LastLock;
3562 KEVENT Lock;
3563 KEVENT Event;
3564 volatile PIO_COMPLETION_CONTEXT CompletionContext;
3565 KSPIN_LOCK IrpListLock;
3566 LIST_ENTRY IrpList;
3567 volatile PVOID FileObjectExtension;
3568 } FILE_OBJECT;
3569 typedef struct _FILE_OBJECT *PFILE_OBJECT;
3570
3571 typedef struct _IO_ERROR_LOG_PACKET {
3572 UCHAR MajorFunctionCode;
3573 UCHAR RetryCount;
3574 USHORT DumpDataSize;
3575 USHORT NumberOfStrings;
3576 USHORT StringOffset;
3577 USHORT EventCategory;
3578 NTSTATUS ErrorCode;
3579 ULONG UniqueErrorValue;
3580 NTSTATUS FinalStatus;
3581 ULONG SequenceNumber;
3582 ULONG IoControlCode;
3583 LARGE_INTEGER DeviceOffset;
3584 ULONG DumpData[1];
3585 } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
3586
3587 typedef struct _IO_ERROR_LOG_MESSAGE {
3588 USHORT Type;
3589 USHORT Size;
3590 USHORT DriverNameLength;
3591 LARGE_INTEGER TimeStamp;
3592 ULONG DriverNameOffset;
3593 IO_ERROR_LOG_PACKET EntryData;
3594 } IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
3595
3596 #define ERROR_LOG_LIMIT_SIZE 240
3597 #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
3598 sizeof(IO_ERROR_LOG_PACKET) + \
3599 (sizeof(WCHAR) * 40))
3600 #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
3601 (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
3602 #define IO_ERROR_LOG_MESSAGE_LENGTH \
3603 ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
3604 ERROR_LOG_MESSAGE_LIMIT_SIZE : \
3605 PORT_MAXIMUM_MESSAGE_LENGTH)
3606 #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
3607 IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
3608
3609 typedef enum _DMA_WIDTH {
3610 Width8Bits,
3611 Width16Bits,
3612 Width32Bits,
3613 MaximumDmaWidth
3614 } DMA_WIDTH, *PDMA_WIDTH;
3615
3616 typedef enum _DMA_SPEED {
3617 Compatible,
3618 TypeA,
3619 TypeB,
3620 TypeC,
3621 TypeF,
3622 MaximumDmaSpeed
3623 } DMA_SPEED, *PDMA_SPEED;
3624
3625 /* DEVICE_DESCRIPTION.Version */
3626
3627 #define DEVICE_DESCRIPTION_VERSION 0x0000
3628 #define DEVICE_DESCRIPTION_VERSION1 0x0001
3629 #define DEVICE_DESCRIPTION_VERSION2 0x0002
3630
3631 typedef struct _DEVICE_DESCRIPTION {
3632 ULONG Version;
3633 BOOLEAN Master;
3634 BOOLEAN ScatterGather;
3635 BOOLEAN DemandMode;
3636 BOOLEAN AutoInitialize;
3637 BOOLEAN Dma32BitAddresses;
3638 BOOLEAN IgnoreCount;
3639 BOOLEAN Reserved1;
3640 BOOLEAN Dma64BitAddresses;
3641 ULONG BusNumber;
3642 ULONG DmaChannel;
3643 INTERFACE_TYPE InterfaceType;
3644 DMA_WIDTH DmaWidth;
3645 DMA_SPEED DmaSpeed;
3646 ULONG MaximumLength;
3647 ULONG DmaPort;
3648 } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
3649
3650 typedef enum _DEVICE_RELATION_TYPE {
3651 BusRelations,
3652 EjectionRelations,
3653 PowerRelations,
3654 RemovalRelations,
3655 TargetDeviceRelation,
3656 SingleBusRelations,
3657 TransportRelations
3658 } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
3659
3660 typedef struct _DEVICE_RELATIONS {
3661 ULONG Count;
3662 PDEVICE_OBJECT Objects[1];
3663 } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
3664
3665 typedef struct _DEVOBJ_EXTENSION
3666 {
3667 CSHORT Type;
3668 USHORT Size;
3669 PDEVICE_OBJECT DeviceObject;
3670 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
3671
3672 typedef struct _SCATTER_GATHER_ELEMENT {
3673 PHYSICAL_ADDRESS Address;
3674 ULONG Length;
3675 ULONG_PTR Reserved;
3676 } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
3677
3678 #if defined(_MSC_EXTENSIONS)
3679
3680 #if _MSC_VER >= 1200
3681 #pragma warning(push)
3682 #endif
3683 #pragma warning(disable:4200)
3684 typedef struct _SCATTER_GATHER_LIST {
3685 ULONG NumberOfElements;
3686 ULONG_PTR Reserved;
3687 SCATTER_GATHER_ELEMENT Elements[1];
3688 } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
3689
3690 #if _MSC_VER >= 1200
3691 #pragma warning(pop)
3692 #else
3693 #pragma warning(default:4200)
3694 #endif
3695
3696 #else
3697
3698 struct _SCATTER_GATHER_LIST;
3699 typedef struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
3700
3701 #endif
3702
3703 typedef NTSTATUS
3704 (DDKAPI DRIVER_ADD_DEVICE)(
3705 IN struct _DRIVER_OBJECT *DriverObject,
3706 IN struct _DEVICE_OBJECT *PhysicalDeviceObject);
3707 typedef DRIVER_ADD_DEVICE *PDRIVER_ADD_DEVICE;
3708
3709 typedef struct _DRIVER_EXTENSION {
3710 struct _DRIVER_OBJECT *DriverObject;
3711 PDRIVER_ADD_DEVICE AddDevice;
3712 ULONG Count;
3713 UNICODE_STRING ServiceKeyName;
3714 } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
3715
3716 #define DRVO_UNLOAD_INVOKED 0x00000001
3717 #define DRVO_LEGACY_DRIVER 0x00000002
3718 #define DRVO_BUILTIN_DRIVER 0x00000004
3719
3720 typedef NTSTATUS
3721 (DDKAPI DRIVER_INITIALIZE)(
3722 IN struct _DRIVER_OBJECT *DriverObject,
3723 IN PUNICODE_STRING RegistryPath);
3724 typedef DRIVER_INITIALIZE *PDRIVER_INITIALIZE;
3725
3726 typedef VOID
3727 (DDKAPI DRIVER_STARTIO)(
3728 IN struct _DEVICE_OBJECT *DeviceObject,
3729 IN struct _IRP *Irp);
3730 typedef DRIVER_STARTIO *PDRIVER_STARTIO;
3731
3732 typedef VOID
3733 (DDKAPI DRIVER_UNLOAD)(
3734 IN struct _DRIVER_OBJECT *DriverObject);
3735 typedef DRIVER_UNLOAD *PDRIVER_UNLOAD;
3736
3737 typedef NTSTATUS
3738 (DDKAPI DRIVER_DISPATCH)(
3739 IN struct _DEVICE_OBJECT *DeviceObject,
3740 IN struct _IRP *Irp);
3741 typedef DRIVER_DISPATCH *PDRIVER_DISPATCH;
3742
3743 typedef struct _DRIVER_OBJECT {
3744 CSHORT Type;
3745 CSHORT Size;
3746 PDEVICE_OBJECT DeviceObject;
3747 ULONG Flags;
3748 PVOID DriverStart;
3749 ULONG DriverSize;
3750 PVOID DriverSection;
3751 PDRIVER_EXTENSION DriverExtension;
3752 UNICODE_STRING DriverName;
3753 PUNICODE_STRING HardwareDatabase;
3754 struct _FAST_IO_DISPATCH *FastIoDispatch;
3755 PDRIVER_INITIALIZE DriverInit;
3756 PDRIVER_STARTIO DriverStartIo;
3757 PDRIVER_UNLOAD DriverUnload;
3758 PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
3759 } DRIVER_OBJECT;
3760 typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
3761
3762 typedef struct _DMA_ADAPTER {
3763 USHORT Version;
3764 USHORT Size;
3765 struct _DMA_OPERATIONS* DmaOperations;
3766 } DMA_ADAPTER, *PDMA_ADAPTER;
3767
3768 typedef VOID
3769 (DDKAPI *PPUT_DMA_ADAPTER)(
3770 IN PDMA_ADAPTER DmaAdapter);
3771
3772 typedef PVOID
3773 (DDKAPI *PALLOCATE_COMMON_BUFFER)(
3774 IN PDMA_ADAPTER DmaAdapter,
3775 IN ULONG Length,
3776 OUT PPHYSICAL_ADDRESS LogicalAddress,
3777 IN BOOLEAN CacheEnabled);
3778
3779 typedef VOID
3780 (DDKAPI *PFREE_COMMON_BUFFER)(
3781 IN PDMA_ADAPTER DmaAdapter,
3782 IN ULONG Length,
3783 IN PHYSICAL_ADDRESS LogicalAddress,
3784 IN PVOID VirtualAddress,
3785 IN BOOLEAN CacheEnabled);
3786
3787 typedef NTSTATUS
3788 (DDKAPI *PALLOCATE_ADAPTER_CHANNEL)(
3789 IN PDMA_ADAPTER DmaAdapter,
3790 IN PDEVICE_OBJECT DeviceObject,
3791 IN ULONG NumberOfMapRegisters,
3792 IN PDRIVER_CONTROL ExecutionRoutine,
3793 IN PVOID Context);
3794
3795 typedef BOOLEAN
3796 (DDKAPI *PFLUSH_ADAPTER_BUFFERS)(
3797 IN PDMA_ADAPTER DmaAdapter,
3798 IN PMDL Mdl,
3799 IN PVOID MapRegisterBase,
3800 IN PVOID CurrentVa,
3801 IN ULONG Length,
3802 IN BOOLEAN WriteToDevice);
3803
3804 typedef VOID
3805 (DDKAPI *PFREE_ADAPTER_CHANNEL)(
3806 IN PDMA_ADAPTER DmaAdapter);
3807
3808 typedef VOID
3809 (DDKAPI *PFREE_MAP_REGISTERS)(
3810 IN PDMA_ADAPTER DmaAdapter,
3811 PVOID MapRegisterBase,
3812 ULONG NumberOfMapRegisters);
3813
3814 typedef PHYSICAL_ADDRESS
3815 (DDKAPI *PMAP_TRANSFER)(
3816 IN PDMA_ADAPTER DmaAdapter,
3817 IN PMDL Mdl,
3818 IN PVOID MapRegisterBase,
3819 IN PVOID CurrentVa,
3820 IN OUT PULONG Length,
3821 IN BOOLEAN WriteToDevice);
3822
3823 typedef ULONG
3824 (DDKAPI *PGET_DMA_ALIGNMENT)(
3825 IN PDMA_ADAPTER DmaAdapter);
3826
3827 typedef ULONG
3828 (DDKAPI *PREAD_DMA_COUNTER)(
3829 IN PDMA_ADAPTER DmaAdapter);
3830
3831 typedef VOID
3832 (DDKAPI *PDRIVER_LIST_CONTROL)(
3833 IN struct _DEVICE_OBJECT *DeviceObject,
3834 IN struct _IRP *Irp,
3835 IN struct _SCATTER_GATHER_LIST *ScatterGather,
3836 IN PVOID Context);
3837
3838 typedef NTSTATUS
3839 (DDKAPI *PGET_SCATTER_GATHER_LIST)(
3840 IN PDMA_ADAPTER DmaAdapter,
3841 IN PDEVICE_OBJECT DeviceObject,
3842 IN PMDL Mdl,
3843 IN PVOID CurrentVa,
3844 IN ULONG Length,
3845 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
3846 IN PVOID Context,
3847 IN BOOLEAN WriteToDevice);
3848
3849 typedef VOID
3850 (DDKAPI *PPUT_SCATTER_GATHER_LIST)(
3851 IN PDMA_ADAPTER DmaAdapter,
3852 IN PSCATTER_GATHER_LIST ScatterGather,
3853 IN BOOLEAN WriteToDevice);
3854
3855 typedef NTSTATUS
3856 (DDKAPI *PCALCULATE_SCATTER_GATHER_LIST_SIZE)(
3857 IN PDMA_ADAPTER DmaAdapter,
3858 IN PMDL Mdl OPTIONAL,
3859 IN PVOID CurrentVa,
3860 IN ULONG Length,
3861 OUT PULONG ScatterGatherListSize,
3862 OUT PULONG pNumberOfMapRegisters OPTIONAL);
3863
3864 typedef NTSTATUS
3865 (DDKAPI *PBUILD_SCATTER_GATHER_LIST)(
3866 IN PDMA_ADAPTER DmaAdapter,
3867 IN PDEVICE_OBJECT DeviceObject,
3868 IN PMDL Mdl,
3869 IN PVOID CurrentVa,
3870 IN ULONG Length,
3871 IN PDRIVER_LIST_CONTROL ExecutionRoutine,
3872 IN PVOID Context,
3873 IN BOOLEAN WriteToDevice,
3874 IN PVOID ScatterGatherBuffer,
3875 IN ULONG ScatterGatherLength);
3876
3877 typedef NTSTATUS
3878 (DDKAPI *PBUILD_MDL_FROM_SCATTER_GATHER_LIST)(
3879 IN PDMA_ADAPTER DmaAdapter,
3880 IN PSCATTER_GATHER_LIST ScatterGather,
3881 IN PMDL OriginalMdl,
3882 OUT PMDL *TargetMdl);
3883
3884 typedef struct _DMA_OPERATIONS {
3885 ULONG Size;
3886 PPUT_DMA_ADAPTER PutDmaAdapter;
3887 PALLOCATE_COMMON_BUFFER AllocateCommonBuffer;
3888 PFREE_COMMON_BUFFER FreeCommonBuffer;
3889 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
3890 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;