- 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 _KWAIT_REASON {
985 Executive,
986 FreePage,
987 PageIn,
988 PoolAllocation,
989 DelayExecution,
990 Suspended,
991 UserRequest,
992 WrExecutive,
993 WrFreePage,
994 WrPageIn,
995 WrPoolAllocation,
996 WrDelayExecution,
997 WrSuspended,
998 WrUserRequest,
999 WrEventPair,
1000 WrQueue,
1001 WrLpcReceive,
1002 WrLpcReply,
1003 WrVirtualMemory,
1004 WrPageOut,
1005 WrRendezvous,
1006 WrKeyedEvent,
1007 WrTerminated,
1008 WrProcessInSwap,
1009 WrCpuRateControl,
1010 WrCalloutStack,
1011 WrKernel,
1012 WrResource,
1013 WrPushLock,
1014 WrMutex,
1015 WrQuantumEnd,
1016 WrDispatchInt,
1017 WrPreempted,
1018 WrYieldExecution,
1019 WrFastMutex,
1020 WrGuardedMutex,
1021 WrRundown,
1022 MaximumWaitReason
1023 } KWAIT_REASON;
1024
1025 typedef enum _KD_OPTION {
1026 KD_OPTION_SET_BLOCK_ENABLE,
1027 } KD_OPTION;
1028
1029 typedef enum _INTERFACE_TYPE {
1030 InterfaceTypeUndefined = -1,
1031 Internal,
1032 Isa,
1033 Eisa,
1034 MicroChannel,
1035 TurboChannel,
1036 PCIBus,
1037 VMEBus,
1038 NuBus,
1039 PCMCIABus,
1040 CBus,
1041 MPIBus,
1042 MPSABus,
1043 ProcessorInternal,
1044 InternalPowerBus,
1045 PNPISABus,
1046 PNPBus,
1047 MaximumInterfaceType
1048 } INTERFACE_TYPE, *PINTERFACE_TYPE;
1049
1050 typedef VOID
1051 (DDKAPI *PKNORMAL_ROUTINE)(
1052 IN PVOID NormalContext,
1053 IN PVOID SystemArgument1,
1054 IN PVOID SystemArgument2);
1055
1056 typedef VOID
1057 (DDKAPI *PKRUNDOWN_ROUTINE)(
1058 IN struct _KAPC *Apc);
1059
1060 typedef VOID
1061 (DDKAPI *PKKERNEL_ROUTINE)(
1062 IN struct _KAPC *Apc,
1063 IN OUT PKNORMAL_ROUTINE *NormalRoutine,
1064 IN OUT PVOID *NormalContext,
1065 IN OUT PVOID *SystemArgument1,
1066 IN OUT PVOID *SystemArgument2);
1067
1068 typedef struct _KAPC
1069 {
1070 UCHAR Type;
1071 UCHAR SpareByte0;
1072 UCHAR Size;
1073 UCHAR SpareByte1;
1074 ULONG SpareLong0;
1075 struct _KTHREAD *Thread;
1076 LIST_ENTRY ApcListEntry;
1077 PKKERNEL_ROUTINE KernelRoutine;
1078 PKRUNDOWN_ROUTINE RundownRoutine;
1079 PKNORMAL_ROUTINE NormalRoutine;
1080 PVOID NormalContext;
1081 PVOID SystemArgument1;
1082 PVOID SystemArgument2;
1083 CCHAR ApcStateIndex;
1084 KPROCESSOR_MODE ApcMode;
1085 BOOLEAN Inserted;
1086 } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
1087
1088 typedef struct _KDEVICE_QUEUE_ENTRY {
1089 LIST_ENTRY DeviceListEntry;
1090 ULONG SortKey;
1091 BOOLEAN Inserted;
1092 } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY,
1093 *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
1094
1095 typedef PVOID PKIPI_CONTEXT;
1096
1097 typedef
1098 VOID
1099 (NTAPI *PKIPI_WORKER)(
1100 IN PKIPI_CONTEXT PacketContext,
1101 IN PVOID Parameter1,
1102 IN PVOID Parameter2,
1103 IN PVOID Parameter3
1104 );
1105
1106 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
1107
1108 typedef struct _KSPIN_LOCK_QUEUE {
1109 struct _KSPIN_LOCK_QUEUE *volatile Next;
1110 PKSPIN_LOCK volatile Lock;
1111 } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
1112
1113 typedef struct _KLOCK_QUEUE_HANDLE {
1114 KSPIN_LOCK_QUEUE LockQueue;
1115 KIRQL OldIrql;
1116 } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
1117
1118 #if defined(_AMD64_)
1119
1120 typedef ULONG64 KSPIN_LOCK_QUEUE_NUMBER;
1121
1122 #define LockQueueDispatcherLock 0
1123 #define LockQueueExpansionLock 1
1124 #define LockQueuePfnLock 2
1125 #define LockQueueSystemSpaceLock 3
1126 #define LockQueueVacbLock 4
1127 #define LockQueueMasterLock 5
1128 #define LockQueueNonPagedPoolLock 6
1129 #define LockQueueIoCancelLock 7
1130 #define LockQueueWorkQueueLock 8
1131 #define LockQueueIoVpbLock 9
1132 #define LockQueueIoDatabaseLock 10
1133 #define LockQueueIoCompletionLock 11
1134 #define LockQueueNtfsStructLock 12
1135 #define LockQueueAfdWorkQueueLock 13
1136 #define LockQueueBcbLock 14
1137 #define LockQueueMmNonPagedPoolLock 15
1138 #define LockQueueUnusedSpare16 16
1139 #define LockQueueTimerTableLock 17
1140 #define LockQueueMaximumLock (LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS)
1141
1142 #else
1143
1144 typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
1145 LockQueueDispatcherLock,
1146 LockQueueExpansionLock,
1147 LockQueuePfnLock,
1148 LockQueueSystemSpaceLock,
1149 LockQueueVacbLock,
1150 LockQueueMasterLock,
1151 LockQueueNonPagedPoolLock,
1152 LockQueueIoCancelLock,
1153 LockQueueWorkQueueLock,
1154 LockQueueIoVpbLock,
1155 LockQueueIoDatabaseLock,
1156 LockQueueIoCompletionLock,
1157 LockQueueNtfsStructLock,
1158 LockQueueAfdWorkQueueLock,
1159 LockQueueBcbLock,
1160 LockQueueMmNonPagedPoolLock,
1161 LockQueueUnusedSpare16,
1162 LockQueueTimerTableLock,
1163 LockQueueMaximumLock = LockQueueTimerTableLock + LOCK_QUEUE_TIMER_TABLE_LOCKS
1164 } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
1165
1166 #endif
1167
1168 typedef VOID
1169 (DDKAPI *PKDEFERRED_ROUTINE)(
1170 IN struct _KDPC *Dpc,
1171 IN PVOID DeferredContext,
1172 IN PVOID SystemArgument1,
1173 IN PVOID SystemArgument2);
1174
1175 typedef struct _KDPC
1176 {
1177 UCHAR Type;
1178 UCHAR Importance;
1179 volatile USHORT Number;
1180 LIST_ENTRY DpcListEntry;
1181 PKDEFERRED_ROUTINE DeferredRoutine;
1182 PVOID DeferredContext;
1183 PVOID SystemArgument1;
1184 PVOID SystemArgument2;
1185 volatile PVOID DpcData;
1186 } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
1187
1188 typedef enum _IO_ALLOCATION_ACTION {
1189 KeepObject = 1,
1190 DeallocateObject,
1191 DeallocateObjectKeepRegisters
1192 } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
1193
1194 typedef IO_ALLOCATION_ACTION
1195 (DDKAPI *PDRIVER_CONTROL)(
1196 IN struct _DEVICE_OBJECT *DeviceObject,
1197 IN struct _IRP *Irp,
1198 IN PVOID MapRegisterBase,
1199 IN PVOID Context);
1200
1201 typedef struct _WAIT_CONTEXT_BLOCK {
1202 KDEVICE_QUEUE_ENTRY WaitQueueEntry;
1203 PDRIVER_CONTROL DeviceRoutine;
1204 PVOID DeviceContext;
1205 ULONG NumberOfMapRegisters;
1206 PVOID DeviceObject;
1207 PVOID CurrentIrp;
1208 PKDPC BufferChainingDpc;
1209 } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
1210
1211 typedef struct _KDEVICE_QUEUE {
1212 CSHORT Type;
1213 CSHORT Size;
1214 LIST_ENTRY DeviceListHead;
1215 KSPIN_LOCK Lock;
1216 #if defined(_AMD64_)
1217 union {
1218 BOOLEAN Busy;
1219 struct {
1220 LONG64 Reserved : 8;
1221 LONG64 Hint : 56;
1222 };
1223 };
1224 #else
1225 BOOLEAN Busy;
1226 #endif
1227
1228 } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
1229
1230 typedef struct _DISPATCHER_HEADER
1231 {
1232 __GNU_EXTENSION union
1233 {
1234 __GNU_EXTENSION struct
1235 {
1236 UCHAR Type;
1237 __GNU_EXTENSION union
1238 {
1239 UCHAR Absolute;
1240 UCHAR NpxIrql;
1241 };
1242 __GNU_EXTENSION union
1243 {
1244 UCHAR Size;
1245 UCHAR Hand;
1246 };
1247 __GNU_EXTENSION union
1248 {
1249 UCHAR Inserted;
1250 BOOLEAN DebugActive;
1251 };
1252 };
1253 volatile LONG Lock;
1254 };
1255 LONG SignalState;
1256 LIST_ENTRY WaitListHead;
1257 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
1258
1259 typedef struct _KGATE
1260 {
1261 DISPATCHER_HEADER Header;
1262 } KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
1263
1264 typedef struct _KGUARDED_MUTEX
1265 {
1266 volatile LONG Count;
1267 PKTHREAD Owner;
1268 ULONG Contention;
1269 KGATE Gate;
1270 __GNU_EXTENSION union
1271 {
1272 __GNU_EXTENSION struct
1273 {
1274 SHORT KernelApcDisable;
1275 SHORT SpecialApcDisable;
1276 };
1277 ULONG CombinedApcDisable;
1278 };
1279 } KGUARDED_MUTEX, *PKGUARDED_MUTEX;
1280
1281 typedef struct _KMUTANT {
1282 DISPATCHER_HEADER Header;
1283 LIST_ENTRY MutantListEntry;
1284 struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
1285 BOOLEAN Abandoned;
1286 UCHAR ApcDisable;
1287 } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
1288
1289 typedef struct _KTIMER {
1290 DISPATCHER_HEADER Header;
1291 ULARGE_INTEGER DueTime;
1292 LIST_ENTRY TimerListEntry;
1293 struct _KDPC *Dpc;
1294 #if !defined(_X86_)
1295 ULONG Processor;
1296 #endif
1297 ULONG Period;
1298 } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
1299
1300 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
1301 {
1302 StandardDesign,
1303 NEC98x86,
1304 EndAlternatives
1305 } ALTERNATIVE_ARCHITECTURE_TYPE;
1306
1307 typedef struct _KSYSTEM_TIME
1308 {
1309 ULONG LowPart;
1310 LONG High1Time;
1311 LONG High2Time;
1312 } KSYSTEM_TIME, *PKSYSTEM_TIME;
1313
1314 typedef struct _KEVENT {
1315 DISPATCHER_HEADER Header;
1316 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
1317
1318 typedef struct _KSEMAPHORE {
1319 DISPATCHER_HEADER Header;
1320 LONG Limit;
1321 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
1322
1323 typedef struct _PNP_BUS_INFORMATION {
1324 GUID BusTypeGuid;
1325 INTERFACE_TYPE LegacyBusType;
1326 ULONG BusNumber;
1327 } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
1328
1329 /******************************************************************************
1330 * Memory manager Types *
1331 ******************************************************************************/
1332
1333 #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
1334 #define MDL_PAGES_LOCKED 0x0002
1335 #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
1336 #define MDL_ALLOCATED_FIXED_SIZE 0x0008
1337 #define MDL_PARTIAL 0x0010
1338 #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
1339 #define MDL_IO_PAGE_READ 0x0040
1340 #define MDL_WRITE_OPERATION 0x0080
1341 #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
1342 #define MDL_FREE_EXTRA_PTES 0x0200
1343 #define MDL_DESCRIBES_AWE 0x0400
1344 #define MDL_IO_SPACE 0x0800
1345 #define MDL_NETWORK_HEADER 0x1000
1346 #define MDL_MAPPING_CAN_FAIL 0x2000
1347 #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
1348 #define MDL_INTERNAL 0x8000
1349
1350 #define MDL_MAPPING_FLAGS ( \
1351 MDL_MAPPED_TO_SYSTEM_VA | \
1352 MDL_PAGES_LOCKED | \
1353 MDL_SOURCE_IS_NONPAGED_POOL | \
1354 MDL_PARTIAL_HAS_BEEN_MAPPED | \
1355 MDL_PARENT_MAPPED_SYSTEM_VA | \
1356 MDL_SYSTEM_VA | \
1357 MDL_IO_SPACE)
1358
1359 typedef struct _MDL {
1360 struct _MDL *Next;
1361 CSHORT Size;
1362 CSHORT MdlFlags;
1363 struct _EPROCESS *Process;
1364 PVOID MappedSystemVa;
1365 PVOID StartVa;
1366 ULONG ByteCount;
1367 ULONG ByteOffset;
1368 } MDL, *PMDL;
1369
1370
1371 /******************************************************************************
1372 * Memory manager Functions *
1373 ******************************************************************************/
1374
1375 /* PVOID MmGetSystemAddressForMdl(
1376 * IN PMDL Mdl);
1377 */
1378 #define MmGetSystemAddressForMdl(Mdl) \
1379 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
1380 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1381 ((Mdl)->MappedSystemVa) : \
1382 (MmMapLockedPages((Mdl), KernelMode)))
1383
1384 /* PVOID
1385 * MmGetSystemAddressForMdlSafe(
1386 * IN PMDL Mdl,
1387 * IN MM_PAGE_PRIORITY Priority)
1388 */
1389 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
1390 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
1391 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
1392 (_Mdl)->MappedSystemVa : \
1393 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
1394 KernelMode, MmCached, NULL, FALSE, (_Priority)))
1395
1396 #if (NTDDI_VERSION >= NTDDI_WIN2K)
1397 NTKERNELAPI
1398 PMDL
1399 NTAPI
1400 MmCreateMdl(
1401 IN PMDL MemoryDescriptorList OPTIONAL,
1402 IN PVOID Base,
1403 IN SIZE_T Length);
1404
1405 #endif
1406
1407 /******************************************************************************
1408 * Security Manager Types *
1409 ******************************************************************************/
1410
1411 //
1412 // Access/Security Stuff
1413 //
1414 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
1415 typedef PVOID PACCESS_TOKEN;
1416
1417 #define DELETE 0x00010000L
1418 #define READ_CONTROL 0x00020000L
1419 #define WRITE_DAC 0x00040000L
1420 #define WRITE_OWNER 0x00080000L
1421 #define SYNCHRONIZE 0x00100000L
1422 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
1423 #define STANDARD_RIGHTS_READ READ_CONTROL
1424 #define STANDARD_RIGHTS_WRITE READ_CONTROL
1425 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
1426 #define STANDARD_RIGHTS_ALL 0x001F0000L
1427 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
1428 #define ACCESS_SYSTEM_SECURITY 0x01000000L
1429 #define MAXIMUM_ALLOWED 0x02000000L
1430 #define GENERIC_READ 0x80000000L
1431 #define GENERIC_WRITE 0x40000000L
1432 #define GENERIC_EXECUTE 0x20000000L
1433 #define GENERIC_ALL 0x10000000L
1434
1435 typedef struct _GENERIC_MAPPING {
1436 ACCESS_MASK GenericRead;
1437 ACCESS_MASK GenericWrite;
1438 ACCESS_MASK GenericExecute;
1439 ACCESS_MASK GenericAll;
1440 } GENERIC_MAPPING, *PGENERIC_MAPPING;
1441
1442 #define ACL_REVISION 2
1443 #define ACL_REVISION_DS 4
1444
1445 #define ACL_REVISION1 1
1446 #define ACL_REVISION2 2
1447 #define ACL_REVISION3 3
1448 #define ACL_REVISION4 4
1449 #define MIN_ACL_REVISION ACL_REVISION2
1450 #define MAX_ACL_REVISION ACL_REVISION4
1451
1452 typedef struct _ACL {
1453 UCHAR AclRevision;
1454 UCHAR Sbz1;
1455 USHORT AclSize;
1456 USHORT AceCount;
1457 USHORT Sbz2;
1458 } ACL, *PACL;
1459
1460 //
1461 // Current security descriptor revision value
1462 //
1463 #define SECURITY_DESCRIPTOR_REVISION (1)
1464 #define SECURITY_DESCRIPTOR_REVISION1 (1)
1465
1466 //
1467 // Privilege attributes
1468 //
1469 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
1470 #define SE_PRIVILEGE_ENABLED (0x00000002L)
1471 #define SE_PRIVILEGE_REMOVED (0X00000004L)
1472 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
1473
1474 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
1475 SE_PRIVILEGE_ENABLED | \
1476 SE_PRIVILEGE_REMOVED | \
1477 SE_PRIVILEGE_USED_FOR_ACCESS)
1478
1479 #include <pshpack4.h>
1480 typedef struct _LUID_AND_ATTRIBUTES {
1481 LUID Luid;
1482 ULONG Attributes;
1483 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
1484 #include <poppack.h>
1485
1486 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
1487 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
1488
1489 //
1490 // Privilege sets
1491 //
1492 #define PRIVILEGE_SET_ALL_NECESSARY (1)
1493
1494 typedef struct _PRIVILEGE_SET {
1495 ULONG PrivilegeCount;
1496 ULONG Control;
1497 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
1498 } PRIVILEGE_SET,*PPRIVILEGE_SET;
1499
1500 typedef enum _SECURITY_IMPERSONATION_LEVEL {
1501 SecurityAnonymous,
1502 SecurityIdentification,
1503 SecurityImpersonation,
1504 SecurityDelegation
1505 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
1506
1507 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
1508 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
1509 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
1510 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
1511
1512 #define SECURITY_DYNAMIC_TRACKING (TRUE)
1513 #define SECURITY_STATIC_TRACKING (FALSE)
1514
1515 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
1516
1517 typedef struct _SECURITY_QUALITY_OF_SERVICE {
1518 ULONG Length;
1519 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1520 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
1521 BOOLEAN EffectiveOnly;
1522 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
1523
1524 typedef struct _SE_IMPERSONATION_STATE {
1525 PACCESS_TOKEN Token;
1526 BOOLEAN CopyOnOpen;
1527 BOOLEAN EffectiveOnly;
1528 SECURITY_IMPERSONATION_LEVEL Level;
1529 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
1530
1531 #define OWNER_SECURITY_INFORMATION (0x00000001L)
1532 #define GROUP_SECURITY_INFORMATION (0x00000002L)
1533 #define DACL_SECURITY_INFORMATION (0x00000004L)
1534 #define SACL_SECURITY_INFORMATION (0x00000008L)
1535 #define LABEL_SECURITY_INFORMATION (0x00000010L)
1536
1537 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
1538 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
1539 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
1540 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
1541
1542 typedef enum _SECURITY_OPERATION_CODE {
1543 SetSecurityDescriptor,
1544 QuerySecurityDescriptor,
1545 DeleteSecurityDescriptor,
1546 AssignSecurityDescriptor
1547 } SECURITY_OPERATION_CODE, *PSECURITY_OPERATION_CODE;
1548
1549 #define INITIAL_PRIVILEGE_COUNT 3
1550
1551 typedef struct _INITIAL_PRIVILEGE_SET {
1552 ULONG PrivilegeCount;
1553 ULONG Control;
1554 LUID_AND_ATTRIBUTES Privilege[INITIAL_PRIVILEGE_COUNT];
1555 } INITIAL_PRIVILEGE_SET, * PINITIAL_PRIVILEGE_SET;
1556
1557 #define SE_MIN_WELL_KNOWN_PRIVILEGE 2
1558 #define SE_CREATE_TOKEN_PRIVILEGE 2
1559 #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3
1560 #define SE_LOCK_MEMORY_PRIVILEGE 4
1561 #define SE_INCREASE_QUOTA_PRIVILEGE 5
1562 #define SE_MACHINE_ACCOUNT_PRIVILEGE 6
1563 #define SE_TCB_PRIVILEGE 7
1564 #define SE_SECURITY_PRIVILEGE 8
1565 #define SE_TAKE_OWNERSHIP_PRIVILEGE 9
1566 #define SE_LOAD_DRIVER_PRIVILEGE 10
1567 #define SE_SYSTEM_PROFILE_PRIVILEGE 11
1568 #define SE_SYSTEMTIME_PRIVILEGE 12
1569 #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13
1570 #define SE_INC_BASE_PRIORITY_PRIVILEGE 14
1571 #define SE_CREATE_PAGEFILE_PRIVILEGE 15
1572 #define SE_CREATE_PERMANENT_PRIVILEGE 16
1573 #define SE_BACKUP_PRIVILEGE 17
1574 #define SE_RESTORE_PRIVILEGE 18
1575 #define SE_SHUTDOWN_PRIVILEGE 19
1576 #define SE_DEBUG_PRIVILEGE 20
1577 #define SE_AUDIT_PRIVILEGE 21
1578 #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22
1579 #define SE_CHANGE_NOTIFY_PRIVILEGE 23
1580 #define SE_REMOTE_SHUTDOWN_PRIVILEGE 24
1581 #define SE_UNDOCK_PRIVILEGE 25
1582 #define SE_SYNC_AGENT_PRIVILEGE 26
1583 #define SE_ENABLE_DELEGATION_PRIVILEGE 27
1584 #define SE_MANAGE_VOLUME_PRIVILEGE 28
1585 #define SE_IMPERSONATE_PRIVILEGE 29
1586 #define SE_CREATE_GLOBAL_PRIVILEGE 30
1587 #define SE_TRUSTED_CREDMAN_ACCESS_PRIVILEGE 31
1588 #define SE_RELABEL_PRIVILEGE 32
1589 #define SE_INC_WORKING_SET_PRIVILEGE 33
1590 #define SE_TIME_ZONE_PRIVILEGE 34
1591 #define SE_CREATE_SYMBOLIC_LINK_PRIVILEGE 35
1592 #define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_SYMBOLIC_LINK_PRIVILEGE
1593
1594 typedef struct _SECURITY_SUBJECT_CONTEXT {
1595 PACCESS_TOKEN ClientToken;
1596 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
1597 PACCESS_TOKEN PrimaryToken;
1598 PVOID ProcessAuditId;
1599 } SECURITY_SUBJECT_CONTEXT, *PSECURITY_SUBJECT_CONTEXT;
1600
1601 #include <pshpack4.h>
1602 typedef struct _ACCESS_STATE {
1603 LUID OperationID;
1604 BOOLEAN SecurityEvaluated;
1605 BOOLEAN GenerateAudit;
1606 BOOLEAN GenerateOnClose;
1607 BOOLEAN PrivilegesAllocated;
1608 ULONG Flags;
1609 ACCESS_MASK RemainingDesiredAccess;
1610 ACCESS_MASK PreviouslyGrantedAccess;
1611 ACCESS_MASK OriginalDesiredAccess;
1612 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext;
1613 PSECURITY_DESCRIPTOR SecurityDescriptor;
1614 PVOID AuxData;
1615 union {
1616 INITIAL_PRIVILEGE_SET InitialPrivilegeSet;
1617 PRIVILEGE_SET PrivilegeSet;
1618 } Privileges;
1619
1620 BOOLEAN AuditPrivileges;
1621 UNICODE_STRING ObjectName;
1622 UNICODE_STRING ObjectTypeName;
1623 } ACCESS_STATE, *PACCESS_STATE;
1624 #include <poppack.h>
1625
1626 /******************************************************************************
1627 * Configuration Manager Types *
1628 ******************************************************************************/
1629
1630 /* KEY_VALUE_Xxx.Type */
1631
1632 #define REG_NONE 0
1633 #define REG_SZ 1
1634 #define REG_EXPAND_SZ 2
1635 #define REG_BINARY 3
1636 #define REG_DWORD 4
1637 #define REG_DWORD_LITTLE_ENDIAN 4
1638 #define REG_DWORD_BIG_ENDIAN 5
1639 #define REG_LINK 6
1640 #define REG_MULTI_SZ 7
1641 #define REG_RESOURCE_LIST 8
1642 #define REG_FULL_RESOURCE_DESCRIPTOR 9
1643 #define REG_RESOURCE_REQUIREMENTS_LIST 10
1644 #define REG_QWORD 11
1645 #define REG_QWORD_LITTLE_ENDIAN 11
1646
1647 //
1648 // Registry Access Rights
1649 //
1650 #define KEY_QUERY_VALUE (0x0001)
1651 #define KEY_SET_VALUE (0x0002)
1652 #define KEY_CREATE_SUB_KEY (0x0004)
1653 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
1654 #define KEY_NOTIFY (0x0010)
1655 #define KEY_CREATE_LINK (0x0020)
1656 #define KEY_WOW64_32KEY (0x0200)
1657 #define KEY_WOW64_64KEY (0x0100)
1658 #define KEY_WOW64_RES (0x0300)
1659
1660 #define KEY_READ ((STANDARD_RIGHTS_READ |\
1661 KEY_QUERY_VALUE |\
1662 KEY_ENUMERATE_SUB_KEYS |\
1663 KEY_NOTIFY) \
1664 & \
1665 (~SYNCHRONIZE))
1666
1667 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
1668 KEY_SET_VALUE |\
1669 KEY_CREATE_SUB_KEY) \
1670 & \
1671 (~SYNCHRONIZE))
1672
1673 #define KEY_EXECUTE ((KEY_READ) \
1674 & \
1675 (~SYNCHRONIZE))
1676
1677 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
1678 KEY_QUERY_VALUE |\
1679 KEY_SET_VALUE |\
1680 KEY_CREATE_SUB_KEY |\
1681 KEY_ENUMERATE_SUB_KEYS |\
1682 KEY_NOTIFY |\
1683 KEY_CREATE_LINK) \
1684 & \
1685 (~SYNCHRONIZE))
1686
1687 //
1688 // Registry Open/Create Options
1689 //
1690 #define REG_OPTION_RESERVED (0x00000000L)
1691 #define REG_OPTION_NON_VOLATILE (0x00000000L)
1692 #define REG_OPTION_VOLATILE (0x00000001L)
1693 #define REG_OPTION_CREATE_LINK (0x00000002L)
1694 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
1695 #define REG_OPTION_OPEN_LINK (0x00000008L)
1696
1697 #define REG_LEGAL_OPTION \
1698 (REG_OPTION_RESERVED |\
1699 REG_OPTION_NON_VOLATILE |\
1700 REG_OPTION_VOLATILE |\
1701 REG_OPTION_CREATE_LINK |\
1702 REG_OPTION_BACKUP_RESTORE |\
1703 REG_OPTION_OPEN_LINK)
1704
1705 //
1706 // Key creation/open disposition
1707 //
1708 #define REG_CREATED_NEW_KEY (0x00000001L)
1709 #define REG_OPENED_EXISTING_KEY (0x00000002L)
1710
1711 //
1712 // Key restore & hive load flags
1713 //
1714 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
1715 #define REG_REFRESH_HIVE (0x00000002L)
1716 #define REG_NO_LAZY_FLUSH (0x00000004L)
1717 #define REG_FORCE_RESTORE (0x00000008L)
1718 #define REG_APP_HIVE (0x00000010L)
1719 #define REG_PROCESS_PRIVATE (0x00000020L)
1720 #define REG_START_JOURNAL (0x00000040L)
1721 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
1722 #define REG_HIVE_NO_RM (0x00000100L)
1723 #define REG_HIVE_SINGLE_LOG (0x00000200L)
1724
1725 //
1726 // Unload Flags
1727 //
1728 #define REG_FORCE_UNLOAD 1
1729
1730 //
1731 // Notify Filter Values
1732 //
1733 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
1734 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
1735 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
1736 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
1737
1738 #define REG_LEGAL_CHANGE_FILTER \
1739 (REG_NOTIFY_CHANGE_NAME |\
1740 REG_NOTIFY_CHANGE_ATTRIBUTES |\
1741 REG_NOTIFY_CHANGE_LAST_SET |\
1742 REG_NOTIFY_CHANGE_SECURITY)
1743
1744 typedef struct _CM_FLOPPY_DEVICE_DATA {
1745 USHORT Version;
1746 USHORT Revision;
1747 CHAR Size[8];
1748 ULONG MaxDensity;
1749 ULONG MountDensity;
1750 UCHAR StepRateHeadUnloadTime;
1751 UCHAR HeadLoadTime;
1752 UCHAR MotorOffTime;
1753 UCHAR SectorLengthCode;
1754 UCHAR SectorPerTrack;
1755 UCHAR ReadWriteGapLength;
1756 UCHAR DataTransferLength;
1757 UCHAR FormatGapLength;
1758 UCHAR FormatFillCharacter;
1759 UCHAR HeadSettleTime;
1760 UCHAR MotorSettleTime;
1761 UCHAR MaximumTrackValue;
1762 UCHAR DataTransferRate;
1763 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
1764
1765 #include <pshpack4.h>
1766 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
1767 UCHAR Type;
1768 UCHAR ShareDisposition;
1769 USHORT Flags;
1770 union {
1771 struct {
1772 PHYSICAL_ADDRESS Start;
1773 ULONG Length;
1774 } Generic;
1775 struct {
1776 PHYSICAL_ADDRESS Start;
1777 ULONG Length;
1778 } Port;
1779 struct {
1780 ULONG Level;
1781 ULONG Vector;
1782 KAFFINITY Affinity;
1783 } Interrupt;
1784 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1785 struct {
1786 __GNU_EXTENSION union {
1787 struct {
1788 USHORT Reserved;
1789 USHORT MessageCount;
1790 ULONG Vector;
1791 KAFFINITY Affinity;
1792 } Raw;
1793 struct {
1794 ULONG Level;
1795 ULONG Vector;
1796 KAFFINITY Affinity;
1797 } Translated;
1798 };
1799 } MessageInterrupt;
1800 #endif
1801 struct {
1802 PHYSICAL_ADDRESS Start;
1803 ULONG Length;
1804 } Memory;
1805 struct {
1806 ULONG Channel;
1807 ULONG Port;
1808 ULONG Reserved1;
1809 } Dma;
1810 struct {
1811 ULONG Data[3];
1812 } DevicePrivate;
1813 struct {
1814 ULONG Start;
1815 ULONG Length;
1816 ULONG Reserved;
1817 } BusNumber;
1818 struct {
1819 ULONG DataSize;
1820 ULONG Reserved1;
1821 ULONG Reserved2;
1822 } DeviceSpecificData;
1823 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1824 struct {
1825 PHYSICAL_ADDRESS Start;
1826 ULONG Length40;
1827 } Memory40;
1828 struct {
1829 PHYSICAL_ADDRESS Start;
1830 ULONG Length48;
1831 } Memory48;
1832 struct {
1833 PHYSICAL_ADDRESS Start;
1834 ULONG Length64;
1835 } Memory64;
1836 #endif
1837 } u;
1838 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
1839 #include <poppack.h>
1840
1841 #include <pshpack1.h>
1842 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
1843
1844 #define CmResourceTypeNull 0
1845 #define CmResourceTypePort 1
1846 #define CmResourceTypeInterrupt 2
1847 #define CmResourceTypeMemory 3
1848 #define CmResourceTypeDma 4
1849 #define CmResourceTypeDeviceSpecific 5
1850 #define CmResourceTypeBusNumber 6
1851 #define CmResourceTypeMemoryLarge 7
1852 #define CmResourceTypeNonArbitrated 128
1853 #define CmResourceTypeConfigData 128
1854 #define CmResourceTypeDevicePrivate 129
1855 #define CmResourceTypePcCardConfig 130
1856 #define CmResourceTypeMfCardConfig 131
1857
1858 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
1859
1860 typedef enum _CM_SHARE_DISPOSITION {
1861 CmResourceShareUndetermined,
1862 CmResourceShareDeviceExclusive,
1863 CmResourceShareDriverExclusive,
1864 CmResourceShareShared
1865 } CM_SHARE_DISPOSITION;
1866
1867 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
1868
1869 #define CM_RESOURCE_PORT_MEMORY 0x0000
1870 #define CM_RESOURCE_PORT_IO 0x0001
1871 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
1872 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
1873 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
1874 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
1875 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
1876 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
1877 #define CM_RESOURCE_PORT_BAR 0x0100
1878
1879 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
1880
1881 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
1882 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
1883 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
1884 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
1885
1886 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
1887
1888 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
1889 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
1890 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
1891 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
1892 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
1893 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
1894 #define CM_RESOURCE_MEMORY_24 0x0010
1895 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
1896 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
1897 #define CM_RESOURCE_MEMORY_BAR 0x0080
1898 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
1899
1900 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
1901
1902 #define CM_RESOURCE_DMA_8 0x0000
1903 #define CM_RESOURCE_DMA_16 0x0001
1904 #define CM_RESOURCE_DMA_32 0x0002
1905 #define CM_RESOURCE_DMA_8_AND_16 0x0004
1906 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
1907 #define CM_RESOURCE_DMA_TYPE_A 0x0010
1908 #define CM_RESOURCE_DMA_TYPE_B 0x0020
1909 #define CM_RESOURCE_DMA_TYPE_F 0x0040
1910
1911 typedef struct _CM_PARTIAL_RESOURCE_LIST {
1912 USHORT Version;
1913 USHORT Revision;
1914 ULONG Count;
1915 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
1916 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
1917
1918 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
1919 INTERFACE_TYPE InterfaceType;
1920 ULONG BusNumber;
1921 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
1922 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
1923
1924 typedef struct _CM_RESOURCE_LIST {
1925 ULONG Count;
1926 CM_FULL_RESOURCE_DESCRIPTOR List[1];
1927 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
1928
1929 typedef struct _CM_INT13_DRIVE_PARAMETER {
1930 USHORT DriveSelect;
1931 ULONG MaxCylinders;
1932 USHORT SectorsPerTrack;
1933 USHORT MaxHeads;
1934 USHORT NumberDrives;
1935 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
1936
1937 typedef struct _CM_PNP_BIOS_DEVICE_NODE
1938 {
1939 USHORT Size;
1940 UCHAR Node;
1941 ULONG ProductId;
1942 UCHAR DeviceType[3];
1943 USHORT DeviceAttributes;
1944 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
1945
1946 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
1947 {
1948 UCHAR Signature[4];
1949 UCHAR Revision;
1950 UCHAR Length;
1951 USHORT ControlField;
1952 UCHAR Checksum;
1953 ULONG EventFlagAddress;
1954 USHORT RealModeEntryOffset;
1955 USHORT RealModeEntrySegment;
1956 USHORT ProtectedModeEntryOffset;
1957 ULONG ProtectedModeCodeBaseAddress;
1958 ULONG OemDeviceId;
1959 USHORT RealModeDataBaseAddress;
1960 ULONG ProtectedModeDataBaseAddress;
1961 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
1962
1963 #include <poppack.h>
1964
1965 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
1966 {
1967 ULONG BytesPerSector;
1968 ULONG NumberOfCylinders;
1969 ULONG SectorsPerTrack;
1970 ULONG NumberOfHeads;
1971 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
1972
1973 typedef struct _CM_KEYBOARD_DEVICE_DATA {
1974 USHORT Version;
1975 USHORT Revision;
1976 UCHAR Type;
1977 UCHAR Subtype;
1978 USHORT KeyboardFlags;
1979 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
1980
1981 typedef struct _CM_MCA_POS_DATA {
1982 USHORT AdapterId;
1983 UCHAR PosData1;
1984 UCHAR PosData2;
1985 UCHAR PosData3;
1986 UCHAR PosData4;
1987 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
1988
1989 #if (NTDDI_VERSION >= NTDDI_WINXP)
1990 typedef struct CM_Power_Data_s {
1991 ULONG PD_Size;
1992 DEVICE_POWER_STATE PD_MostRecentPowerState;
1993 ULONG PD_Capabilities;
1994 ULONG PD_D1Latency;
1995 ULONG PD_D2Latency;
1996 ULONG PD_D3Latency;
1997 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
1998 SYSTEM_POWER_STATE PD_DeepestSystemWake;
1999 } CM_POWER_DATA, *PCM_POWER_DATA;
2000
2001 #define PDCAP_D0_SUPPORTED 0x00000001
2002 #define PDCAP_D1_SUPPORTED 0x00000002
2003 #define PDCAP_D2_SUPPORTED 0x00000004
2004 #define PDCAP_D3_SUPPORTED 0x00000008
2005 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
2006 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
2007 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
2008 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
2009 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
2010
2011 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
2012
2013 typedef struct _CM_SCSI_DEVICE_DATA {
2014 USHORT Version;
2015 USHORT Revision;
2016 UCHAR HostIdentifier;
2017 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
2018
2019 typedef struct _CM_SERIAL_DEVICE_DATA {
2020 USHORT Version;
2021 USHORT Revision;
2022 ULONG BaudClock;
2023 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
2024
2025 typedef enum _KEY_INFORMATION_CLASS {
2026 KeyBasicInformation,
2027 KeyNodeInformation,
2028 KeyFullInformation,
2029 KeyNameInformation,
2030 KeyCachedInformation,
2031 KeyFlagsInformation
2032 } KEY_INFORMATION_CLASS;
2033
2034 typedef struct _KEY_BASIC_INFORMATION {
2035 LARGE_INTEGER LastWriteTime;
2036 ULONG TitleIndex;
2037 ULONG NameLength;
2038 WCHAR Name[1];
2039 } KEY_BASIC_INFORMATION, *PKEY_BASIC_INFORMATION;
2040
2041 typedef struct _KEY_FULL_INFORMATION {
2042 LARGE_INTEGER LastWriteTime;
2043 ULONG TitleIndex;
2044 ULONG ClassOffset;
2045 ULONG ClassLength;
2046 ULONG SubKeys;
2047 ULONG MaxNameLen;
2048 ULONG MaxClassLen;
2049 ULONG Values;
2050 ULONG MaxValueNameLen;
2051 ULONG MaxValueDataLen;
2052 WCHAR Class[1];
2053 } KEY_FULL_INFORMATION, *PKEY_FULL_INFORMATION;
2054
2055 typedef struct _KEY_NODE_INFORMATION {
2056 LARGE_INTEGER LastWriteTime;
2057 ULONG TitleIndex;
2058 ULONG ClassOffset;
2059 ULONG ClassLength;
2060 ULONG NameLength;
2061 WCHAR Name[1];
2062 } KEY_NODE_INFORMATION, *PKEY_NODE_INFORMATION;
2063
2064 typedef struct _KEY_VALUE_BASIC_INFORMATION {
2065 ULONG TitleIndex;
2066 ULONG Type;
2067 ULONG NameLength;
2068 WCHAR Name[1];
2069 } KEY_VALUE_BASIC_INFORMATION, *PKEY_VALUE_BASIC_INFORMATION;
2070
2071 typedef struct _KEY_VALUE_FULL_INFORMATION {
2072 ULONG TitleIndex;
2073 ULONG Type;
2074 ULONG DataOffset;
2075 ULONG DataLength;
2076 ULONG NameLength;
2077 WCHAR Name[1];
2078 } KEY_VALUE_FULL_INFORMATION, *PKEY_VALUE_FULL_INFORMATION;
2079
2080 typedef struct _KEY_VALUE_PARTIAL_INFORMATION {
2081 ULONG TitleIndex;
2082 ULONG Type;
2083 ULONG DataLength;
2084 UCHAR Data[1];
2085 } KEY_VALUE_PARTIAL_INFORMATION, *PKEY_VALUE_PARTIAL_INFORMATION;
2086
2087 typedef struct _KEY_VALUE_PARTIAL_INFORMATION_ALIGN64 {
2088 ULONG Type;
2089 ULONG DataLength;
2090 UCHAR Data[1];
2091 } KEY_VALUE_PARTIAL_INFORMATION_ALIGN64, *PKEY_VALUE_PARTIAL_INFORMATION_ALIGN64;
2092
2093 typedef struct _KEY_VALUE_ENTRY {
2094 PUNICODE_STRING ValueName;
2095 ULONG DataLength;
2096 ULONG DataOffset;
2097 ULONG Type;
2098 } KEY_VALUE_ENTRY, *PKEY_VALUE_ENTRY;
2099
2100 typedef enum _KEY_VALUE_INFORMATION_CLASS {
2101 KeyValueBasicInformation,
2102 KeyValueFullInformation,
2103 KeyValuePartialInformation,
2104 KeyValueFullInformationAlign64,
2105 KeyValuePartialInformationAlign64
2106 } KEY_VALUE_INFORMATION_CLASS;
2107
2108 typedef struct _KEY_WRITE_TIME_INFORMATION {
2109 LARGE_INTEGER LastWriteTime;
2110 } KEY_WRITE_TIME_INFORMATION, *PKEY_WRITE_TIME_INFORMATION;
2111
2112 typedef enum _KEY_SET_INFORMATION_CLASS {
2113 KeyWriteTimeInformation,
2114 KeyWow64FlagsInformation,
2115 KeyControlFlagsInformation,
2116 KeySetVirtualizationInformation,
2117 KeySetDebugInformation,
2118 KeySetHandleTagsInformation,
2119 MaxKeySetInfoClass
2120 } KEY_SET_INFORMATION_CLASS;
2121
2122 /******************************************************************************
2123 * I/O Manager Functions *
2124 ******************************************************************************/
2125
2126 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
2127 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
2128
2129 #define DMA_MACROS_DEFINED
2130
2131 FORCEINLINE
2132 NTSTATUS
2133 IoAllocateAdapterChannel(
2134 IN PADAPTER_OBJECT AdapterObject,
2135 IN PDEVICE_OBJECT DeviceObject,
2136 IN ULONG NumberOfMapRegisters,
2137 IN PDRIVER_CONTROL ExecutionRoutine,
2138 IN PVOID Context)
2139 {
2140 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
2141 AllocateAdapterChannel =
2142 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
2143 ASSERT(AllocateAdapterChannel);
2144 return AllocateAdapterChannel(DmaAdapter,
2145 DeviceObject,
2146 NumberOfMapRegisters,
2147 ExecutionRoutine,
2148 Context );
2149 }
2150
2151 FORCEINLINE
2152 BOOLEAN
2153 IoFlushAdapterBuffers(
2154 IN PADAPTER_OBJECT AdapterObject,
2155 IN PMDL Mdl,
2156 IN PVOID MapRegisterBase,
2157 IN PVOID CurrentVa,
2158 IN ULONG Length,
2159 IN BOOLEAN WriteToDevice)
2160 {
2161 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
2162 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
2163 ASSERT(FlushAdapterBuffers);
2164 return FlushAdapterBuffers(DmaAdapter,
2165 Mdl,
2166 MapRegisterBase,
2167 CurrentVa,
2168 Length,
2169 WriteToDevice );
2170 }
2171
2172 FORCEINLINE
2173 VOID
2174 IoFreeAdapterChannel(
2175 IN PADAPTER_OBJECT AdapterObject)
2176 {
2177 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
2178 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
2179 ASSERT(FreeAdapterChannel);
2180 FreeAdapterChannel(DmaAdapter);
2181 }
2182
2183 FORCEINLINE
2184 VOID
2185 IoFreeMapRegisters(
2186 IN PADAPTER_OBJECT AdapterObject,
2187 IN PVOID MapRegisterBase,
2188 IN ULONG NumberOfMapRegisters)
2189 {
2190 PFREE_MAP_REGISTERS FreeMapRegisters;
2191 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
2192 ASSERT(FreeMapRegisters);
2193 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
2194 }
2195
2196 FORCEINLINE
2197 PHYSICAL_ADDRESS
2198 IoMapTransfer(
2199 IN PDMA_ADAPTER DmaAdapter,
2200 IN PMDL Mdl,
2201 IN PVOID MapRegisterBase,
2202 IN PVOID CurrentVa,
2203 IN OUT PULONG Length,
2204 IN BOOLEAN WriteToDevice)
2205 {
2206 PMAP_TRANSFER MapTransfer;
2207
2208 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
2209 ASSERT(MapTransfer);
2210 return MapTransfer(DmaAdapter,
2211 Mdl,
2212 MapRegisterBase,
2213 CurrentVa,
2214 Length,
2215 WriteToDevice);
2216 }
2217 #endif
2218
2219 /* PCI_COMMON_CONFIG.Command */
2220
2221 #define PCI_ENABLE_IO_SPACE 0x0001
2222 #define PCI_ENABLE_MEMORY_SPACE 0x0002
2223 #define PCI_ENABLE_BUS_MASTER 0x0004
2224 #define PCI_ENABLE_SPECIAL_CYCLES 0x0008
2225 #define PCI_ENABLE_WRITE_AND_INVALIDATE 0x0010
2226 #define PCI_ENABLE_VGA_COMPATIBLE_PALETTE 0x0020
2227 #define PCI_ENABLE_PARITY 0x0040
2228 #define PCI_ENABLE_WAIT_CYCLE 0x0080
2229 #define PCI_ENABLE_SERR 0x0100
2230 #define PCI_ENABLE_FAST_BACK_TO_BACK 0x0200
2231 #define PCI_DISABLE_LEVEL_INTERRUPT 0x0400
2232
2233 /* PCI_COMMON_CONFIG.Status */
2234
2235 #define PCI_STATUS_INTERRUPT_PENDING 0x0008
2236 #define PCI_STATUS_CAPABILITIES_LIST 0x0010
2237 #define PCI_STATUS_66MHZ_CAPABLE 0x0020
2238 #define PCI_STATUS_UDF_SUPPORTED 0x0040
2239 #define PCI_STATUS_FAST_BACK_TO_BACK 0x0080
2240 #define PCI_STATUS_DATA_PARITY_DETECTED 0x0100
2241 #define PCI_STATUS_DEVSEL 0x0600
2242 #define PCI_STATUS_SIGNALED_TARGET_ABORT 0x0800
2243 #define PCI_STATUS_RECEIVED_TARGET_ABORT 0x1000
2244 #define PCI_STATUS_RECEIVED_MASTER_ABORT 0x2000
2245 #define PCI_STATUS_SIGNALED_SYSTEM_ERROR 0x4000
2246 #define PCI_STATUS_DETECTED_PARITY_ERROR 0x8000
2247
2248 /* PCI_COMMON_CONFIG.HeaderType */
2249
2250 #define PCI_MULTIFUNCTION 0x80
2251 #define PCI_DEVICE_TYPE 0x00
2252 #define PCI_BRIDGE_TYPE 0x01
2253 #define PCI_CARDBUS_BRIDGE_TYPE 0x02
2254
2255 #define PCI_CONFIGURATION_TYPE(PciData) \
2256 (((PPCI_COMMON_CONFIG) (PciData))->HeaderType & ~PCI_MULTIFUNCTION)
2257
2258 #define PCI_MULTIFUNCTION_DEVICE(PciData) \
2259 ((((PPCI_COMMON_CONFIG) (PciData))->HeaderType & PCI_MULTIFUNCTION) != 0)
2260
2261 /* PCI device classes */
2262
2263 #define PCI_CLASS_PRE_20 0x00
2264 #define PCI_CLASS_MASS_STORAGE_CTLR 0x01
2265 #define PCI_CLASS_NETWORK_CTLR 0x02
2266 #define PCI_CLASS_DISPLAY_CTLR 0x03
2267 #define PCI_CLASS_MULTIMEDIA_DEV 0x04
2268 #define PCI_CLASS_MEMORY_CTLR 0x05
2269 #define PCI_CLASS_BRIDGE_DEV 0x06
2270 #define PCI_CLASS_SIMPLE_COMMS_CTLR 0x07
2271 #define PCI_CLASS_BASE_SYSTEM_DEV 0x08
2272 #define PCI_CLASS_INPUT_DEV 0x09
2273 #define PCI_CLASS_DOCKING_STATION 0x0a
2274 #define PCI_CLASS_PROCESSOR 0x0b
2275 #define PCI_CLASS_SERIAL_BUS_CTLR 0x0c
2276 #define PCI_CLASS_WIRELESS_CTLR 0x0d
2277 #define PCI_CLASS_INTELLIGENT_IO_CTLR 0x0e
2278 #define PCI_CLASS_SATELLITE_COMMS_CTLR 0x0f
2279 #define PCI_CLASS_ENCRYPTION_DECRYPTION 0x10
2280 #define PCI_CLASS_DATA_ACQ_SIGNAL_PROC 0x11
2281
2282 /* PCI device subclasses for class 0 */
2283
2284 #define PCI_SUBCLASS_PRE_20_NON_VGA 0x00
2285 #define PCI_SUBCLASS_PRE_20_VGA 0x01
2286
2287 /* PCI device subclasses for class 1 (mass storage controllers)*/
2288
2289 #define PCI_SUBCLASS_MSC_SCSI_BUS_CTLR 0x00
2290 #define PCI_SUBCLASS_MSC_IDE_CTLR 0x01
2291 #define PCI_SUBCLASS_MSC_FLOPPY_CTLR 0x02
2292 #define PCI_SUBCLASS_MSC_IPI_CTLR 0x03
2293 #define PCI_SUBCLASS_MSC_RAID_CTLR 0x04
2294 #define PCI_SUBCLASS_MSC_OTHER 0x80
2295
2296 /* PCI device subclasses for class 2 (network controllers)*/
2297
2298 #define PCI_SUBCLASS_NET_ETHERNET_CTLR 0x00
2299 #define PCI_SUBCLASS_NET_TOKEN_RING_CTLR 0x01
2300 #define PCI_SUBCLASS_NET_FDDI_CTLR 0x02
2301 #define PCI_SUBCLASS_NET_ATM_CTLR 0x03
2302 #define PCI_SUBCLASS_NET_ISDN_CTLR 0x04
2303 #define PCI_SUBCLASS_NET_OTHER 0x80
2304
2305 /* PCI device subclasses for class 3 (display controllers)*/
2306
2307 #define PCI_SUBCLASS_VID_VGA_CTLR 0x00
2308 #define PCI_SUBCLASS_VID_XGA_CTLR 0x01
2309 #define PCI_SUBCLASS_VID_3D_CTLR 0x02
2310 #define PCI_SUBCLASS_VID_OTHER 0x80
2311
2312 /* PCI device subclasses for class 4 (multimedia device)*/
2313
2314 #define PCI_SUBCLASS_MM_VIDEO_DEV 0x00
2315 #define PCI_SUBCLASS_MM_AUDIO_DEV 0x01
2316 #define PCI_SUBCLASS_MM_TELEPHONY_DEV 0x02
2317 #define PCI_SUBCLASS_MM_OTHER 0x80
2318
2319 /* PCI device subclasses for class 5 (memory controller)*/
2320
2321 #define PCI_SUBCLASS_MEM_RAM 0x00
2322 #define PCI_SUBCLASS_MEM_FLASH 0x01
2323 #define PCI_SUBCLASS_MEM_OTHER 0x80
2324
2325 /* PCI device subclasses for class 6 (bridge device)*/
2326
2327 #define PCI_SUBCLASS_BR_HOST 0x00
2328 #define PCI_SUBCLASS_BR_ISA 0x01
2329 #define PCI_SUBCLASS_BR_EISA 0x02
2330 #define PCI_SUBCLASS_BR_MCA 0x03
2331 #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
2332 #define PCI_SUBCLASS_BR_PCMCIA 0x05
2333 #define PCI_SUBCLASS_BR_NUBUS 0x06
2334 #define PCI_SUBCLASS_BR_CARDBUS 0x07
2335 #define PCI_SUBCLASS_BR_RACEWAY 0x08
2336 #define PCI_SUBCLASS_BR_OTHER 0x80
2337
2338 /* PCI device subclasses for class C (serial bus controller)*/
2339
2340 #define PCI_SUBCLASS_SB_IEEE1394 0x00
2341 #define PCI_SUBCLASS_SB_ACCESS 0x01
2342 #define PCI_SUBCLASS_SB_SSA 0x02
2343 #define PCI_SUBCLASS_SB_USB 0x03
2344 #define PCI_SUBCLASS_SB_FIBRE_CHANNEL 0x04
2345 #define PCI_SUBCLASS_SB_SMBUS 0x05
2346
2347 #define PCI_MAX_DEVICES 32
2348 #define PCI_MAX_FUNCTION 8
2349 #define PCI_MAX_BRIDGE_NUMBER 0xFF
2350 #define PCI_INVALID_VENDORID 0xFFFF
2351 #define PCI_COMMON_HDR_LENGTH (FIELD_OFFSET(PCI_COMMON_CONFIG, DeviceSpecific))
2352
2353 #define PCI_ADDRESS_IO_SPACE 0x00000001
2354 #define PCI_ADDRESS_MEMORY_TYPE_MASK 0x00000006
2355 #define PCI_ADDRESS_MEMORY_PREFETCHABLE 0x00000008
2356 #define PCI_ADDRESS_IO_ADDRESS_MASK 0xfffffffc
2357 #define PCI_ADDRESS_MEMORY_ADDRESS_MASK 0xfffffff0
2358 #define PCI_ADDRESS_ROM_ADDRESS_MASK 0xfffff800
2359
2360 #define PCI_TYPE_32BIT 0
2361 #define PCI_TYPE_20BIT 2
2362 #define PCI_TYPE_64BIT 4
2363
2364 #define POOL_COLD_ALLOCATION 256
2365 #define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 8
2366 #define POOL_RAISE_IF_ALLOCATION_FAILURE 16
2367
2368 #define PCI_TYPE0_ADDRESSES 6
2369 #define PCI_TYPE1_ADDRESSES 2
2370 #define PCI_TYPE2_ADDRESSES 5
2371
2372 #define IO_TYPE_ADAPTER 1
2373 #define IO_TYPE_CONTROLLER 2
2374 #define IO_TYPE_DEVICE 3
2375 #define IO_TYPE_DRIVER 4
2376 #define IO_TYPE_FILE 5
2377 #define IO_TYPE_IRP 6
2378 #define IO_TYPE_MASTER_ADAPTER 7
2379 #define IO_TYPE_OPEN_PACKET 8
2380 #define IO_TYPE_TIMER 9
2381 #define IO_TYPE_VPB 10
2382 #define IO_TYPE_ERROR_LOG 11
2383 #define IO_TYPE_ERROR_MESSAGE 12
2384 #define IO_TYPE_DEVICE_OBJECT_EXTENSION 13
2385
2386 #define IO_TYPE_CSQ_IRP_CONTEXT 1
2387 #define IO_TYPE_CSQ 2
2388 #define IO_TYPE_CSQ_EX 3
2389
2390 /* IO_RESOURCE_DESCRIPTOR.Option */
2391
2392 #define IO_RESOURCE_PREFERRED 0x01
2393 #define IO_RESOURCE_DEFAULT 0x02
2394 #define IO_RESOURCE_ALTERNATIVE 0x08
2395
2396 /* DEVICE_OBJECT.Flags */
2397
2398 #define DO_VERIFY_VOLUME 0x00000002
2399 #define DO_BUFFERED_IO 0x00000004
2400 #define DO_EXCLUSIVE 0x00000008
2401 #define DO_DIRECT_IO 0x00000010
2402 #define DO_MAP_IO_BUFFER 0x00000020
2403 #define DO_DEVICE_INITIALIZING 0x00000080
2404 #define DO_SHUTDOWN_REGISTERED 0x00000800
2405 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
2406 #define DO_POWER_PAGABLE 0x00002000
2407 #define DO_POWER_INRUSH 0x00004000
2408
2409 /* DEVICE_OBJECT.Characteristics */
2410
2411 #define FILE_REMOVABLE_MEDIA 0x00000001
2412 #define FILE_READ_ONLY_DEVICE 0x00000002
2413 #define FILE_FLOPPY_DISKETTE 0x00000004
2414 #define FILE_WRITE_ONCE_MEDIA 0x00000008
2415 #define FILE_REMOTE_DEVICE 0x00000010
2416 #define FILE_DEVICE_IS_MOUNTED 0x00000020
2417 #define FILE_VIRTUAL_VOLUME 0x00000040
2418 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
2419 #define FILE_DEVICE_SECURE_OPEN 0x00000100
2420 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
2421 #define FILE_CHARACTERISTIC_TS_DEVICE 0x00001000
2422 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE 0x00002000
2423
2424 /* DEVICE_OBJECT.AlignmentRequirement */
2425
2426 #define FILE_BYTE_ALIGNMENT 0x00000000
2427 #define FILE_WORD_ALIGNMENT 0x00000001
2428 #define FILE_LONG_ALIGNMENT 0x00000003
2429 #define FILE_QUAD_ALIGNMENT 0x00000007
2430 #define FILE_OCTA_ALIGNMENT 0x0000000f
2431 #define FILE_32_BYTE_ALIGNMENT 0x0000001f
2432 #define FILE_64_BYTE_ALIGNMENT 0x0000003f
2433 #define FILE_128_BYTE_ALIGNMENT 0x0000007f
2434 #define FILE_256_BYTE_ALIGNMENT 0x000000ff
2435 #define FILE_512_BYTE_ALIGNMENT 0x000001ff
2436
2437 /* DEVICE_OBJECT.DeviceType */
2438
2439 #define DEVICE_TYPE ULONG
2440
2441 #define FILE_DEVICE_BEEP 0x00000001
2442 #define FILE_DEVICE_CD_ROM 0x00000002
2443 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
2444 #define FILE_DEVICE_CONTROLLER 0x00000004
2445 #define FILE_DEVICE_DATALINK 0x00000005
2446 #define FILE_DEVICE_DFS 0x00000006
2447 #define FILE_DEVICE_DISK 0x00000007
2448 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
2449 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
2450 #define FILE_DEVICE_INPORT_PORT 0x0000000a
2451 #define FILE_DEVICE_KEYBOARD 0x0000000b
2452 #define FILE_DEVICE_MAILSLOT 0x0000000c
2453 #define FILE_DEVICE_MIDI_IN 0x0000000d
2454 #define FILE_DEVICE_MIDI_OUT 0x0000000e
2455 #define FILE_DEVICE_MOUSE 0x0000000f
2456 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
2457 #define FILE_DEVICE_NAMED_PIPE 0x00000011
2458 #define FILE_DEVICE_NETWORK 0x00000012
2459 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
2460 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
2461 #define FILE_DEVICE_NULL 0x00000015
2462 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
2463 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
2464 #define FILE_DEVICE_PRINTER 0x00000018
2465 #define FILE_DEVICE_SCANNER 0x00000019
2466 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
2467 #define FILE_DEVICE_SERIAL_PORT 0x0000001b
2468 #define FILE_DEVICE_SCREEN 0x0000001c
2469 #define FILE_DEVICE_SOUND 0x0000001d
2470 #define FILE_DEVICE_STREAMS 0x0000001e
2471 #define FILE_DEVICE_TAPE 0x0000001f
2472 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
2473 #define FILE_DEVICE_TRANSPORT 0x00000021
2474 #define FILE_DEVICE_UNKNOWN 0x00000022
2475 #define FILE_DEVICE_VIDEO 0x00000023
2476 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
2477 #define FILE_DEVICE_WAVE_IN 0x00000025
2478 #define FILE_DEVICE_WAVE_OUT 0x00000026
2479 #define FILE_DEVICE_8042_PORT 0x00000027
2480 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
2481 #define FILE_DEVICE_BATTERY 0x00000029
2482 #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
2483 #define FILE_DEVICE_MODEM 0x0000002b
2484 #define FILE_DEVICE_VDM 0x0000002c
2485 #define FILE_DEVICE_MASS_STORAGE 0x0000002d
2486 #define FILE_DEVICE_SMB 0x0000002e
2487 #define FILE_DEVICE_KS 0x0000002f
2488 #define FILE_DEVICE_CHANGER 0x00000030
2489 #define FILE_DEVICE_SMARTCARD 0x00000031
2490 #define FILE_DEVICE_ACPI 0x00000032
2491 #define FILE_DEVICE_DVD 0x00000033
2492 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
2493 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
2494 #define FILE_DEVICE_DFS_VOLUME 0x00000036
2495 #define FILE_DEVICE_SERENUM 0x00000037
2496 #define FILE_DEVICE_TERMSRV 0x00000038
2497 #define FILE_DEVICE_KSEC 0x00000039
2498 #define FILE_DEVICE_FIPS 0x0000003a
2499 #define FILE_DEVICE_INFINIBAND 0x0000003b
2500 #define FILE_DEVICE_VMBUS 0x0000003e
2501 #define FILE_DEVICE_CRYPT_PROVIDER 0x0000003f
2502 #define FILE_DEVICE_WPD 0x00000040
2503 #define FILE_DEVICE_BLUETOOTH 0x00000041
2504 #define FILE_DEVICE_MT_COMPOSITE 0x00000042
2505 #define FILE_DEVICE_MT_TRANSPORT 0x00000043
2506 #define FILE_DEVICE_BIOMETRIC 0x00000044
2507 #define FILE_DEVICE_PMI 0x00000045
2508
2509 #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR))
2510
2511 typedef struct _VPB {
2512 CSHORT Type;
2513 CSHORT Size;
2514 USHORT Flags;
2515 USHORT VolumeLabelLength;
2516 struct _DEVICE_OBJECT *DeviceObject;
2517 struct _DEVICE_OBJECT *RealDevice;
2518 ULONG SerialNumber;
2519 ULONG ReferenceCount;
2520 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
2521 } VPB, *PVPB;
2522
2523 typedef struct _DEVICE_OBJECT {
2524 CSHORT Type;
2525 USHORT Size;
2526 LONG ReferenceCount;
2527 struct _DRIVER_OBJECT *DriverObject;
2528 struct _DEVICE_OBJECT *NextDevice;
2529 struct _DEVICE_OBJECT *AttachedDevice;
2530 struct _IRP *CurrentIrp;
2531 PIO_TIMER Timer;
2532 ULONG Flags;
2533 ULONG Characteristics;
2534 volatile PVPB Vpb;
2535 PVOID DeviceExtension;
2536 DEVICE_TYPE DeviceType;
2537 CCHAR StackSize;
2538 union {
2539 LIST_ENTRY ListEntry;
2540 WAIT_CONTEXT_BLOCK Wcb;
2541 } Queue;
2542 ULONG AlignmentRequirement;
2543 KDEVICE_QUEUE DeviceQueue;
2544 KDPC Dpc;
2545 ULONG ActiveThreadCount;
2546 PSECURITY_DESCRIPTOR SecurityDescriptor;
2547 KEVENT DeviceLock;
2548 USHORT SectorSize;
2549 USHORT Spare1;
2550 struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
2551 PVOID Reserved;
2552 } DEVICE_OBJECT, *PDEVICE_OBJECT;
2553
2554 typedef struct _IO_REMOVE_LOCK_TRACKING_BLOCK * PIO_REMOVE_LOCK_TRACKING_BLOCK;
2555
2556 typedef struct _IO_REMOVE_LOCK_COMMON_BLOCK {
2557 BOOLEAN Removed;
2558 BOOLEAN Reserved[3];
2559 volatile LONG IoCount;
2560 KEVENT RemoveEvent;
2561 } IO_REMOVE_LOCK_COMMON_BLOCK;
2562
2563 typedef struct _IO_REMOVE_LOCK_DBG_BLOCK {
2564 LONG Signature;
2565 LONG HighWatermark;
2566 LONGLONG MaxLockedTicks;
2567 LONG AllocateTag;
2568 LIST_ENTRY LockList;
2569 KSPIN_LOCK Spin;
2570 volatile LONG LowMemoryCount;
2571 ULONG Reserved1[4];
2572 PVOID Reserved2;
2573 PIO_REMOVE_LOCK_TRACKING_BLOCK Blocks;
2574 } IO_REMOVE_LOCK_DBG_BLOCK;
2575
2576 typedef struct _IO_REMOVE_LOCK {
2577 IO_REMOVE_LOCK_COMMON_BLOCK Common;
2578 #if DBG
2579 IO_REMOVE_LOCK_DBG_BLOCK Dbg;
2580 #endif
2581 } IO_REMOVE_LOCK, *PIO_REMOVE_LOCK;
2582
2583 typedef struct _IO_WORKITEM *PIO_WORKITEM;
2584
2585 typedef VOID
2586 (DDKAPI IO_WORKITEM_ROUTINE)(
2587 IN PDEVICE_OBJECT DeviceObject,
2588 IN PVOID Context);
2589 typedef IO_WORKITEM_ROUTINE *PIO_WORKITEM_ROUTINE;
2590
2591 typedef struct _SHARE_ACCESS {
2592 ULONG OpenCount;
2593 ULONG Readers;
2594 ULONG Writers;
2595 ULONG Deleters;
2596 ULONG SharedRead;
2597 ULONG SharedWrite;
2598 ULONG SharedDelete;
2599 } SHARE_ACCESS, *PSHARE_ACCESS;
2600
2601
2602
2603
2604 typedef struct _PCI_SLOT_NUMBER {
2605 union {
2606 struct {
2607 ULONG DeviceNumber : 5;
2608 ULONG FunctionNumber : 3;
2609 ULONG Reserved : 24;
2610 } bits;
2611 ULONG AsULONG;
2612 } u;
2613 } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
2614
2615 typedef struct _IO_STATUS_BLOCK {
2616 _ANONYMOUS_UNION union {
2617 NTSTATUS Status;
2618 PVOID Pointer;
2619 } DUMMYUNIONNAME;
2620 ULONG_PTR Information;
2621 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
2622
2623 typedef VOID
2624 (DDKAPI *PIO_APC_ROUTINE)(
2625 IN PVOID ApcContext,
2626 IN PIO_STATUS_BLOCK IoStatusBlock,
2627 IN ULONG Reserved);
2628
2629 #define EVENT_INCREMENT 1
2630 #define IO_NO_INCREMENT 0
2631 #define IO_CD_ROM_INCREMENT 1
2632 #define IO_DISK_INCREMENT 1
2633 #define IO_KEYBOARD_INCREMENT 6
2634 #define IO_MAILSLOT_INCREMENT 2
2635 #define IO_MOUSE_INCREMENT 6
2636 #define IO_NAMED_PIPE_INCREMENT 2
2637 #define IO_NETWORK_INCREMENT 2
2638 #define IO_PARALLEL_INCREMENT 1
2639 #define IO_SERIAL_INCREMENT 2
2640 #define IO_SOUND_INCREMENT 8
2641 #define IO_VIDEO_INCREMENT 1
2642 #define SEMAPHORE_INCREMENT 1
2643
2644 #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
2645
2646 typedef struct _BOOTDISK_INFORMATION {
2647 LONGLONG BootPartitionOffset;
2648 LONGLONG SystemPartitionOffset;
2649 ULONG BootDeviceSignature;
2650 ULONG SystemDeviceSignature;
2651 } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
2652
2653 typedef struct _BOOTDISK_INFORMATION_EX {
2654 LONGLONG BootPartitionOffset;
2655 LONGLONG SystemPartitionOffset;
2656 ULONG BootDeviceSignature;
2657 ULONG SystemDeviceSignature;
2658 GUID BootDeviceGuid;
2659 GUID SystemDeviceGuid;
2660 BOOLEAN BootDeviceIsGpt;
2661 BOOLEAN SystemDeviceIsGpt;
2662 } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
2663
2664 typedef struct _EISA_MEMORY_TYPE {
2665 UCHAR ReadWrite : 1;
2666 UCHAR Cached : 1;
2667 UCHAR Reserved0 : 1;
2668 UCHAR Type : 2;
2669 UCHAR Shared : 1;
2670 UCHAR Reserved1 : 1;
2671 UCHAR MoreEntries : 1;
2672 } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
2673
2674 #include <pshpack1.h>
2675 typedef struct _EISA_MEMORY_CONFIGURATION {
2676 EISA_MEMORY_TYPE ConfigurationByte;
2677 UCHAR DataSize;
2678 USHORT AddressLowWord;
2679 UCHAR AddressHighByte;
2680 USHORT MemorySize;
2681 } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
2682 #include <poppack.h>
2683
2684 typedef struct _EISA_IRQ_DESCRIPTOR {
2685 UCHAR Interrupt : 4;
2686 UCHAR Reserved : 1;
2687 UCHAR LevelTriggered : 1;
2688 UCHAR Shared : 1;
2689 UCHAR MoreEntries : 1;
2690 } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
2691
2692 typedef struct _EISA_IRQ_CONFIGURATION {
2693 EISA_IRQ_DESCRIPTOR ConfigurationByte;
2694 UCHAR Reserved;
2695 } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
2696
2697 typedef struct _DMA_CONFIGURATION_BYTE0 {
2698 UCHAR Channel : 3;
2699 UCHAR Reserved : 3;
2700 UCHAR Shared : 1;
2701 UCHAR MoreEntries : 1;
2702 } DMA_CONFIGURATION_BYTE0;
2703
2704 typedef struct _DMA_CONFIGURATION_BYTE1 {
2705 UCHAR Reserved0 : 2;
2706 UCHAR TransferSize : 2;
2707 UCHAR Timing : 2;
2708 UCHAR Reserved1 : 2;
2709 } DMA_CONFIGURATION_BYTE1;
2710
2711 typedef struct _EISA_DMA_CONFIGURATION {
2712 DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
2713 DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
2714 } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
2715
2716 #include <pshpack1.h>
2717 typedef struct _EISA_PORT_DESCRIPTOR {
2718 UCHAR NumberPorts : 5;
2719 UCHAR Reserved : 1;
2720 UCHAR Shared : 1;
2721 UCHAR MoreEntries : 1;
2722 } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
2723
2724 typedef struct _EISA_PORT_CONFIGURATION {
2725 EISA_PORT_DESCRIPTOR Configuration;
2726 USHORT PortAddress;
2727 } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
2728 #include <poppack.h>
2729
2730 typedef struct _CM_EISA_FUNCTION_INFORMATION {
2731 ULONG CompressedId;
2732 UCHAR IdSlotFlags1;
2733 UCHAR IdSlotFlags2;
2734 UCHAR MinorRevision;
2735 UCHAR MajorRevision;
2736 UCHAR Selections[26];
2737 UCHAR FunctionFlags;
2738 UCHAR TypeString[80];
2739 EISA_MEMORY_CONFIGURATION EisaMemory[9];
2740 EISA_IRQ_CONFIGURATION EisaIrq[7];
2741 EISA_DMA_CONFIGURATION EisaDma[4];
2742 EISA_PORT_CONFIGURATION EisaPort[20];
2743 UCHAR InitializationData[60];
2744 } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
2745
2746 /* CM_EISA_FUNCTION_INFORMATION.FunctionFlags */
2747
2748 #define EISA_FUNCTION_ENABLED 0x80
2749 #define EISA_FREE_FORM_DATA 0x40
2750 #define EISA_HAS_PORT_INIT_ENTRY 0x20
2751 #define EISA_HAS_PORT_RANGE 0x10
2752 #define EISA_HAS_DMA_ENTRY 0x08
2753 #define EISA_HAS_IRQ_ENTRY 0x04
2754 #define EISA_HAS_MEMORY_ENTRY 0x02
2755 #define EISA_HAS_TYPE_ENTRY 0x01
2756 #define EISA_HAS_INFORMATION \
2757 (EISA_HAS_PORT_RANGE + EISA_HAS_DMA_ENTRY + EISA_HAS_IRQ_ENTRY \
2758 + EISA_HAS_MEMORY_ENTRY + EISA_HAS_TYPE_ENTRY)
2759
2760 typedef struct _CM_EISA_SLOT_INFORMATION {
2761 UCHAR ReturnCode;
2762 UCHAR ReturnFlags;
2763 UCHAR MajorRevision;
2764 UCHAR MinorRevision;
2765 USHORT Checksum;
2766 UCHAR NumberFunctions;
2767 UCHAR FunctionInformation;
2768 ULONG CompressedId;
2769 } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
2770
2771 /* CM_EISA_SLOT_INFORMATION.ReturnCode */
2772
2773 #define EISA_INVALID_SLOT 0x80
2774 #define EISA_INVALID_FUNCTION 0x81
2775 #define EISA_INVALID_CONFIGURATION 0x82
2776 #define EISA_EMPTY_SLOT 0x83
2777 #define EISA_INVALID_BIOS_CALL 0x86
2778
2779 /*
2780 ** Plug and Play structures
2781 */
2782
2783 typedef VOID
2784 (DDKAPI *PINTERFACE_REFERENCE)(
2785 PVOID Context);
2786
2787 typedef VOID
2788 (DDKAPI *PINTERFACE_DEREFERENCE)(
2789 PVOID Context);
2790
2791 typedef BOOLEAN
2792 (DDKAPI *PTRANSLATE_BUS_ADDRESS)(
2793 IN PVOID Context,
2794 IN PHYSICAL_ADDRESS BusAddress,
2795 IN ULONG Length,
2796 IN OUT PULONG AddressSpace,
2797 OUT PPHYSICAL_ADDRESS TranslatedAddress);
2798
2799 typedef struct _DMA_ADAPTER*
2800 (DDKAPI *PGET_DMA_ADAPTER)(
2801 IN PVOID Context,
2802 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
2803 OUT PULONG NumberOfMapRegisters);
2804
2805 typedef ULONG
2806 (DDKAPI *PGET_SET_DEVICE_DATA)(
2807 IN PVOID Context,
2808 IN ULONG DataType,
2809 IN PVOID Buffer,
2810 IN ULONG Offset,
2811 IN ULONG Length);
2812
2813 /* PCI_DEVICE_PRESENCE_PARAMETERS.Flags */
2814 #define PCI_USE_SUBSYSTEM_IDS 0x00000001
2815 #define PCI_USE_REVISION 0x00000002
2816 #define PCI_USE_VENDEV_IDS 0x00000004
2817 #define PCI_USE_CLASS_SUBCLASS 0x00000008
2818 #define PCI_USE_PROGIF 0x00000010
2819 #define PCI_USE_LOCAL_BUS 0x00000020
2820 #define PCI_USE_LOCAL_DEVICE 0x00000040
2821
2822 typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
2823 ULONG Size;
2824 ULONG Flags;
2825 USHORT VendorID;
2826 USHORT DeviceID;
2827 UCHAR RevisionID;
2828 USHORT SubVendorID;
2829 USHORT SubSystemID;
2830 UCHAR BaseClass;
2831 UCHAR SubClass;
2832 UCHAR ProgIf;
2833 } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
2834
2835 typedef BOOLEAN
2836 (DDKAPI *PPCI_IS_DEVICE_PRESENT)(
2837 IN USHORT VendorID,
2838 IN USHORT DeviceID,
2839 IN UCHAR RevisionID,
2840 IN USHORT SubVendorID,
2841 IN USHORT SubSystemID,
2842 IN ULONG Flags);
2843
2844 typedef BOOLEAN
2845 (DDKAPI *PPCI_IS_DEVICE_PRESENT_EX)(
2846 IN PVOID Context,
2847 IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters);
2848
2849 typedef union _POWER_STATE {
2850 SYSTEM_POWER_STATE SystemState;
2851 DEVICE_POWER_STATE DeviceState;
2852 } POWER_STATE, *PPOWER_STATE;
2853
2854 typedef enum _POWER_STATE_TYPE {
2855 SystemPowerState = 0,
2856 DevicePowerState
2857 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
2858
2859 typedef struct _BUS_INTERFACE_STANDARD {
2860 USHORT Size;
2861 USHORT Version;
2862 PVOID Context;
2863 PINTERFACE_REFERENCE InterfaceReference;
2864 PINTERFACE_DEREFERENCE InterfaceDereference;
2865 PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
2866 PGET_DMA_ADAPTER GetDmaAdapter;
2867 PGET_SET_DEVICE_DATA SetBusData;
2868 PGET_SET_DEVICE_DATA GetBusData;
2869 } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
2870
2871 typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
2872 USHORT Size;
2873 USHORT Version;
2874 PVOID Context;
2875 PINTERFACE_REFERENCE InterfaceReference;
2876 PINTERFACE_DEREFERENCE InterfaceDereference;
2877 PPCI_IS_DEVICE_PRESENT IsDevicePresent;
2878 PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
2879 } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
2880
2881 typedef struct _DEVICE_CAPABILITIES {
2882 USHORT Size;
2883 USHORT Version;
2884 ULONG DeviceD1 : 1;
2885 ULONG DeviceD2 : 1;
2886 ULONG LockSupported : 1;
2887 ULONG EjectSupported : 1;
2888 ULONG Removable : 1;
2889 ULONG DockDevice : 1;
2890 ULONG UniqueID : 1;
2891 ULONG SilentInstall : 1;
2892 ULONG RawDeviceOK : 1;
2893 ULONG SurpriseRemovalOK : 1;
2894 ULONG WakeFromD0 : 1;
2895 ULONG WakeFromD1 : 1;
2896 ULONG WakeFromD2 : 1;
2897 ULONG WakeFromD3 : 1;
2898 ULONG HardwareDisabled : 1;
2899 ULONG NonDynamic : 1;
2900 ULONG WarmEjectSupported : 1;
2901 ULONG NoDisplayInUI : 1;
2902 ULONG Reserved : 14;
2903 ULONG Address;
2904 ULONG UINumber;
2905 DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
2906 SYSTEM_POWER_STATE SystemWake;
2907 DEVICE_POWER_STATE DeviceWake;
2908 ULONG D1Latency;
2909 ULONG D2Latency;
2910 ULONG D3Latency;
2911 } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
2912
2913 typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
2914 USHORT Version;
2915 USHORT Size;
2916 GUID Event;
2917 GUID InterfaceClassGuid;
2918 PUNICODE_STRING SymbolicLinkName;
2919 } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
2920
2921 typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
2922 USHORT Version;
2923 USHORT Size;
2924 GUID Event;
2925 } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
2926
2927 #undef INTERFACE
2928
2929 typedef struct _INTERFACE {
2930 USHORT Size;
2931 USHORT Version;
2932 PVOID Context;
2933 PINTERFACE_REFERENCE InterfaceReference;
2934 PINTERFACE_DEREFERENCE InterfaceDereference;
2935 } INTERFACE, *PINTERFACE;
2936
2937 typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
2938 USHORT Version;
2939 USHORT Size;
2940 GUID Event;
2941 } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
2942
2943 typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
2944
2945 /* PNP_DEVICE_STATE */
2946
2947 #define PNP_DEVICE_DISABLED 0x00000001
2948 #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
2949 #define PNP_DEVICE_FAILED 0x00000004
2950 #define PNP_DEVICE_REMOVED 0x00000008
2951 #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
2952 #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
2953
2954 typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
2955 USHORT Version;
2956 USHORT Size;
2957 GUID Event;
2958 struct _FILE_OBJECT *FileObject;
2959 LONG NameBufferOffset;
2960 UCHAR CustomDataBuffer[1];
2961 } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
2962
2963 typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
2964 USHORT Version;
2965 USHORT Size;
2966 GUID Event;
2967 struct _FILE_OBJECT *FileObject;
2968 } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
2969
2970 typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
2971 DeviceUsageTypeUndefined,
2972 DeviceUsageTypePaging,
2973 DeviceUsageTypeHibernation,
2974 DeviceUsageTypeDumpFile
2975 } DEVICE_USAGE_NOTIFICATION_TYPE;
2976
2977 typedef struct _POWER_SEQUENCE {
2978 ULONG SequenceD1;
2979 ULONG SequenceD2;
2980 ULONG SequenceD3;
2981 } POWER_SEQUENCE, *PPOWER_SEQUENCE;
2982
2983 typedef enum {
2984 DevicePropertyDeviceDescription = 0x0,
2985 DevicePropertyHardwareID = 0x1,
2986 DevicePropertyCompatibleIDs = 0x2,
2987 DevicePropertyBootConfiguration = 0x3,
2988 DevicePropertyBootConfigurationTranslated = 0x4,
2989 DevicePropertyClassName = 0x5,
2990 DevicePropertyClassGuid = 0x6,
2991 DevicePropertyDriverKeyName = 0x7,
2992 DevicePropertyManufacturer = 0x8,
2993 DevicePropertyFriendlyName = 0x9,
2994 DevicePropertyLocationInformation = 0xa,
2995 DevicePropertyPhysicalDeviceObjectName = 0xb,
2996 DevicePropertyBusTypeGuid = 0xc,
2997 DevicePropertyLegacyBusType = 0xd,
2998 DevicePropertyBusNumber = 0xe,
2999 DevicePropertyEnumeratorName = 0xf,
3000 DevicePropertyAddress = 0x10,
3001 DevicePropertyUINumber = 0x11,
3002 DevicePropertyInstallState = 0x12,
3003 DevicePropertyRemovalPolicy = 0x13,
3004 DevicePropertyResourceRequirements = 0x14,
3005 DevicePropertyAllocatedResources = 0x15,
3006 DevicePropertyContainerID = 0x16
3007 } DEVICE_REGISTRY_PROPERTY;
3008
3009 typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
3010 EventCategoryReserved,
3011 EventCategoryHardwareProfileChange,
3012 EventCategoryDeviceInterfaceChange,
3013 EventCategoryTargetDeviceChange
3014 } IO_NOTIFICATION_EVENT_CATEGORY;
3015
3016 #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
3017
3018 typedef NTSTATUS
3019 (DDKAPI *PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)(
3020 IN PVOID NotificationStructure,
3021 IN PVOID Context);
3022
3023 typedef VOID
3024 (DDKAPI *PDEVICE_CHANGE_COMPLETE_CALLBACK)(
3025 IN PVOID Context);
3026
3027 typedef enum _FILE_INFORMATION_CLASS {
3028 FileDirectoryInformation = 1,
3029 FileFullDirectoryInformation,
3030 FileBothDirectoryInformation,
3031 FileBasicInformation,
3032 FileStandardInformation,
3033 FileInternalInformation,
3034 FileEaInformation,
3035 FileAccessInformation,
3036 FileNameInformation,
3037 FileRenameInformation,
3038 FileLinkInformation,
3039 FileNamesInformation,
3040 FileDispositionInformation,
3041 FilePositionInformation,
3042 FileFullEaInformation,
3043 FileModeInformation,
3044 FileAlignmentInformation,
3045 FileAllInformation,
3046 FileAllocationInformation,
3047 FileEndOfFileInformation,
3048 FileAlternateNameInformation,
3049 FileStreamInformation,
3050 FilePipeInformation,
3051 FilePipeLocalInformation,
3052 FilePipeRemoteInformation,
3053 FileMailslotQueryInformation,
3054 FileMailslotSetInformation,
3055 FileCompressionInformation,
3056 FileObjectIdInformation,
3057 FileCompletionInformation,
3058 FileMoveClusterInformation,
3059 FileQuotaInformation,
3060 FileReparsePointInformation,
3061 FileNetworkOpenInformation,
3062 FileAttributeTagInformation,
3063 FileTrackingInformation,
3064 FileIdBothDirectoryInformation,
3065 FileIdFullDirectoryInformation,
3066 FileValidDataLengthInformation,
3067 FileShortNameInformation,
3068 FileIoCompletionNotificationInformation,
3069 FileIoStatusBlockRangeInformation,
3070 FileIoPriorityHintInformation,
3071 FileSfioReserveInformation,
3072 FileSfioVolumeInformation,
3073 FileHardLinkInformation,
3074 FileProcessIdsUsingFileInformation,
3075 FileNormalizedNameInformation,
3076 FileNetworkPhysicalNameInformation,
3077 FileIdGlobalTxDirectoryInformation,
3078 FileIsRemoteDeviceInformation,
3079 FileAttributeCacheInformation,
3080 FileNumaNodeInformation,
3081 FileStandardLinkInformation,
3082 FileRemoteProtocolInformation,
3083 FileMaximumInformation
3084 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
3085
3086 typedef struct _FILE_POSITION_INFORMATION {
3087 LARGE_INTEGER CurrentByteOffset;
3088 } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
3089
3090 #include <pshpack8.h>
3091 typedef struct _FILE_BASIC_INFORMATION {
3092 LARGE_INTEGER CreationTime;
3093 LARGE_INTEGER LastAccessTime;
3094 LARGE_INTEGER LastWriteTime;
3095 LARGE_INTEGER ChangeTime;
3096 ULONG FileAttributes;
3097 } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
3098 #include <poppack.h>
3099
3100 typedef struct _FILE_STANDARD_INFORMATION {
3101 LARGE_INTEGER AllocationSize;
3102 LARGE_INTEGER EndOfFile;
3103 ULONG NumberOfLinks;
3104 BOOLEAN DeletePending;
3105 BOOLEAN Directory;
3106 } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
3107
3108 typedef struct _FILE_NETWORK_OPEN_INFORMATION {
3109 LARGE_INTEGER CreationTime;
3110 LARGE_INTEGER LastAccessTime;
3111 LARGE_INTEGER LastWriteTime;
3112 LARGE_INTEGER ChangeTime;
3113 LARGE_INTEGER AllocationSize;
3114 LARGE_INTEGER EndOfFile;
3115 ULONG FileAttributes;
3116 } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
3117
3118 typedef enum _FSINFOCLASS {
3119 FileFsVolumeInformation = 1,
3120 FileFsLabelInformation,
3121 FileFsSizeInformation,
3122 FileFsDeviceInformation,
3123 FileFsAttributeInformation,
3124 FileFsControlInformation,
3125 FileFsFullSizeInformation,
3126 FileFsObjectIdInformation,
3127 FileFsDriverPathInformation,
3128 FileFsVolumeFlagsInformation,
3129 FileFsMaximumInformation
3130 } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
3131
3132 typedef struct _FILE_FS_DEVICE_INFORMATION {
3133 DEVICE_TYPE DeviceType;
3134 ULONG Characteristics;
3135 } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
3136
3137 typedef struct _FILE_FULL_EA_INFORMATION {
3138 ULONG NextEntryOffset;
3139 UCHAR Flags;
3140 UCHAR EaNameLength;
3141 USHORT EaValueLength;
3142 CHAR EaName[1];
3143 } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
3144
3145 typedef struct _FAST_MUTEX
3146 {
3147 LONG Count;
3148 PKTHREAD Owner;
3149 ULONG Contention;
3150 KEVENT Gate;
3151 ULONG OldIrql;
3152 } FAST_MUTEX, *PFAST_MUTEX;
3153
3154 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
3155
3156 typedef struct _OWNER_ENTRY {
3157 ERESOURCE_THREAD OwnerThread;
3158 _ANONYMOUS_UNION union {
3159 LONG OwnerCount;
3160 ULONG TableSize;
3161 } DUMMYUNIONNAME;
3162 } OWNER_ENTRY, *POWNER_ENTRY;
3163
3164 typedef struct _ERESOURCE
3165 {
3166 LIST_ENTRY SystemResourcesList;
3167 POWNER_ENTRY OwnerTable;
3168 SHORT ActiveCount;
3169 USHORT Flag;
3170 volatile PKSEMAPHORE SharedWaiters;
3171 volatile PKEVENT ExclusiveWaiters;
3172 OWNER_ENTRY OwnerEntry;
3173 ULONG ActiveEntries;
3174 ULONG ContentionCount;
3175 ULONG NumberOfSharedWaiters;
3176 ULONG NumberOfExclusiveWaiters;
3177 __GNU_EXTENSION union
3178 {
3179 PVOID Address;
3180 ULONG_PTR CreatorBackTraceIndex;
3181 };
3182 KSPIN_LOCK SpinLock;
3183 } ERESOURCE, *PERESOURCE;
3184
3185 /* ERESOURCE.Flag */
3186
3187 #define ResourceNeverExclusive 0x0010
3188 #define ResourceReleaseByOtherThread 0x0020
3189 #define ResourceOwnedExclusive 0x0080
3190
3191 #define RESOURCE_HASH_TABLE_SIZE 64
3192
3193 typedef BOOLEAN
3194 (DDKAPI *PFAST_IO_CHECK_IF_POSSIBLE)(
3195 IN struct _FILE_OBJECT *FileObject,
3196 IN PLARGE_INTEGER FileOffset,
3197 IN ULONG Length,
3198 IN BOOLEAN Wait,
3199 IN ULONG LockKey,
3200 IN BOOLEAN CheckForReadOperation,
3201 OUT PIO_STATUS_BLOCK IoStatus,
3202 IN struct _DEVICE_OBJECT *DeviceObject);
3203
3204 typedef BOOLEAN
3205 (DDKAPI *PFAST_IO_READ)(
3206 IN struct _FILE_OBJECT *FileObject,
3207 IN PLARGE_INTEGER FileOffset,
3208 IN ULONG Length,
3209 IN BOOLEAN Wait,
3210 IN ULONG LockKey,
3211 OUT PVOID Buffer,
3212 OUT PIO_STATUS_BLOCK IoStatus,
3213 IN struct _DEVICE_OBJECT *DeviceObject);
3214
3215 typedef BOOLEAN
3216 (DDKAPI *PFAST_IO_WRITE)(
3217 IN struct _FILE_OBJECT *FileObject,
3218 IN PLARGE_INTEGER FileOffset,
3219 IN ULONG Length,
3220 IN BOOLEAN Wait,
3221 IN ULONG LockKey,
3222 IN PVOID Buffer,
3223 OUT PIO_STATUS_BLOCK IoStatus,
3224 IN struct _DEVICE_OBJECT *DeviceObject);
3225
3226 typedef BOOLEAN
3227 (DDKAPI *PFAST_IO_QUERY_BASIC_INFO)(
3228 IN struct _FILE_OBJECT *FileObject,
3229 IN BOOLEAN Wait,
3230 OUT PFILE_BASIC_INFORMATION Buffer,
3231 OUT PIO_STATUS_BLOCK IoStatus,
3232 IN struct _DEVICE_OBJECT *DeviceObject);
3233
3234 typedef BOOLEAN
3235 (DDKAPI *PFAST_IO_QUERY_STANDARD_INFO)(
3236 IN struct _FILE_OBJECT *FileObject,
3237 IN BOOLEAN Wait,
3238 OUT PFILE_STANDARD_INFORMATION Buffer,
3239 OUT PIO_STATUS_BLOCK IoStatus,
3240 IN struct _DEVICE_OBJECT *DeviceObject);
3241
3242 typedef BOOLEAN
3243 (DDKAPI *PFAST_IO_LOCK)(
3244 IN struct _FILE_OBJECT *FileObject,
3245 IN PLARGE_INTEGER FileOffset,
3246 IN PLARGE_INTEGER Length,
3247 PEPROCESS ProcessId,
3248 ULONG Key,
3249 BOOLEAN FailImmediately,
3250 BOOLEAN ExclusiveLock,
3251 OUT PIO_STATUS_BLOCK IoStatus,
3252 IN struct _DEVICE_OBJECT *DeviceObject);
3253
3254 typedef BOOLEAN
3255 (DDKAPI *PFAST_IO_UNLOCK_SINGLE)(
3256 IN struct _FILE_OBJECT *FileObject,
3257 IN PLARGE_INTEGER FileOffset,
3258 IN PLARGE_INTEGER Length,
3259 PEPROCESS ProcessId,
3260 ULONG Key,
3261 OUT PIO_STATUS_BLOCK IoStatus,
3262 IN struct _DEVICE_OBJECT *DeviceObject);
3263
3264 typedef BOOLEAN
3265 (DDKAPI *PFAST_IO_UNLOCK_ALL)(
3266 IN struct _FILE_OBJECT *FileObject,
3267 PEPROCESS ProcessId,
3268 OUT PIO_STATUS_BLOCK IoStatus,
3269 IN struct _DEVICE_OBJECT *DeviceObject);
3270
3271 typedef BOOLEAN
3272 (DDKAPI *PFAST_IO_UNLOCK_ALL_BY_KEY)(
3273 IN struct _FILE_OBJECT *FileObject,
3274 PVOID ProcessId,
3275 ULONG Key,
3276 OUT PIO_STATUS_BLOCK IoStatus,
3277 IN struct _DEVICE_OBJECT *DeviceObject);
3278
3279 typedef BOOLEAN
3280 (DDKAPI *PFAST_IO_DEVICE_CONTROL)(
3281 IN struct _FILE_OBJECT *FileObject,
3282 IN BOOLEAN Wait,
3283 IN PVOID InputBuffer OPTIONAL,
3284 IN ULONG InputBufferLength,
3285 OUT PVOID OutputBuffer OPTIONAL,
3286 IN ULONG OutputBufferLength,
3287 IN ULONG IoControlCode,
3288 OUT PIO_STATUS_BLOCK IoStatus,
3289 IN struct _DEVICE_OBJECT *DeviceObject);
3290
3291 typedef VOID
3292 (DDKAPI *PFAST_IO_ACQUIRE_FILE)(
3293 IN struct _FILE_OBJECT *FileObject);
3294
3295 typedef VOID
3296 (DDKAPI *PFAST_IO_RELEASE_FILE)(
3297 IN struct _FILE_OBJECT *FileObject);
3298
3299 typedef VOID
3300 (DDKAPI *PFAST_IO_DETACH_DEVICE)(
3301 IN struct _DEVICE_OBJECT *SourceDevice,
3302 IN struct _DEVICE_OBJECT *TargetDevice);
3303
3304 typedef BOOLEAN
3305 (DDKAPI *PFAST_IO_QUERY_NETWORK_OPEN_INFO)(
3306 IN struct _FILE_OBJECT *FileObject,
3307 IN BOOLEAN Wait,
3308 OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
3309 OUT struct _IO_STATUS_BLOCK *IoStatus,
3310 IN struct _DEVICE_OBJECT *DeviceObject);
3311
3312 typedef NTSTATUS
3313 (DDKAPI *PFAST_IO_ACQUIRE_FOR_MOD_WRITE)(
3314 IN struct _FILE_OBJECT *FileObject,
3315 IN PLARGE_INTEGER EndingOffset,
3316 OUT struct _ERESOURCE **ResourceToRelease,
3317 IN struct _DEVICE_OBJECT *DeviceObject);
3318
3319 typedef BOOLEAN
3320 (DDKAPI *PFAST_IO_MDL_READ)(
3321 IN struct _FILE_OBJECT *FileObject,
3322 IN PLARGE_INTEGER FileOffset,
3323 IN ULONG Length,
3324 IN ULONG LockKey,
3325 OUT PMDL *MdlChain,
3326 OUT PIO_STATUS_BLOCK IoStatus,
3327 IN struct _DEVICE_OBJECT *DeviceObject);
3328
3329 typedef BOOLEAN
3330 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE)(
3331 IN struct _FILE_OBJECT *FileObject,
3332 IN PMDL MdlChain,
3333 IN struct _DEVICE_OBJECT *DeviceObject);
3334
3335 typedef BOOLEAN
3336 (DDKAPI *PFAST_IO_PREPARE_MDL_WRITE)(
3337 IN struct _FILE_OBJECT *FileObject,
3338 IN PLARGE_INTEGER FileOffset,
3339 IN ULONG Length,
3340 IN ULONG LockKey,
3341 OUT PMDL *MdlChain,
3342 OUT PIO_STATUS_BLOCK IoStatus,
3343 IN struct _DEVICE_OBJECT *DeviceObject);
3344
3345 typedef BOOLEAN
3346 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE)(
3347 IN struct _FILE_OBJECT *FileObject,
3348 IN PLARGE_INTEGER FileOffset,
3349 IN PMDL MdlChain,
3350 IN struct _DEVICE_OBJECT *DeviceObject);
3351
3352 typedef BOOLEAN
3353 (DDKAPI *PFAST_IO_READ_COMPRESSED)(
3354 IN struct _FILE_OBJECT *FileObject,
3355 IN PLARGE_INTEGER FileOffset,
3356 IN ULONG Length,
3357 IN ULONG LockKey,
3358 OUT PVOID Buffer,
3359 OUT PMDL *MdlChain,
3360 OUT PIO_STATUS_BLOCK IoStatus,
3361 OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3362 IN ULONG CompressedDataInfoLength,
3363 IN struct _DEVICE_OBJECT *DeviceObject);
3364
3365 typedef BOOLEAN
3366 (DDKAPI *PFAST_IO_WRITE_COMPRESSED)(
3367 IN struct _FILE_OBJECT *FileObject,
3368 IN PLARGE_INTEGER FileOffset,
3369 IN ULONG Length,
3370 IN ULONG LockKey,
3371 IN PVOID Buffer,
3372 OUT PMDL *MdlChain,
3373 OUT PIO_STATUS_BLOCK IoStatus,
3374 IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3375 IN ULONG CompressedDataInfoLength,
3376 IN struct _DEVICE_OBJECT *DeviceObject);
3377
3378 typedef BOOLEAN
3379 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE_COMPRESSED)(
3380 IN struct _FILE_OBJECT *FileObject,
3381 IN PMDL MdlChain,
3382 IN struct _DEVICE_OBJECT *DeviceObject);
3383
3384 typedef BOOLEAN
3385 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED)(
3386 IN struct _FILE_OBJECT *FileObject,
3387 IN PLARGE_INTEGER FileOffset,
3388 IN PMDL MdlChain,
3389 IN struct _DEVICE_OBJECT *DeviceObject);
3390
3391 typedef BOOLEAN
3392 (DDKAPI *PFAST_IO_QUERY_OPEN)(
3393 IN struct _IRP *Irp,
3394 OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
3395 IN struct _DEVICE_OBJECT *DeviceObject);
3396
3397 typedef NTSTATUS
3398 (DDKAPI *PFAST_IO_RELEASE_FOR_MOD_WRITE)(
3399 IN struct _FILE_OBJECT *FileObject,
3400 IN struct _ERESOURCE *ResourceToRelease,
3401 IN struct _DEVICE_OBJECT *DeviceObject);
3402
3403 typedef NTSTATUS
3404 (DDKAPI *PFAST_IO_ACQUIRE_FOR_CCFLUSH)(
3405 IN struct _FILE_OBJECT *FileObject,
3406 IN struct _DEVICE_OBJECT *DeviceObject);
3407
3408 typedef NTSTATUS
3409 (DDKAPI *PFAST_IO_RELEASE_FOR_CCFLUSH) (
3410 IN struct _FILE_OBJECT *FileObject,
3411 IN struct _DEVICE_OBJECT *DeviceObject);
3412
3413 typedef struct _FAST_IO_DISPATCH {
3414 ULONG SizeOfFastIoDispatch;
3415 PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
3416 PFAST_IO_READ FastIoRead;
3417 PFAST_IO_WRITE FastIoWrite;
3418 PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
3419 PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
3420 PFAST_IO_LOCK FastIoLock;
3421 PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
3422 PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
3423 PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
3424 PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
3425 PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
3426 PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
3427 PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
3428 PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
3429 PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
3430 PFAST_IO_MDL_READ MdlRead;
3431 PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
3432 PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
3433 PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
3434 PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
3435 PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
3436 PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
3437 PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
3438 PFAST_IO_QUERY_OPEN FastIoQueryOpen;
3439 PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
3440 PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
3441 PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
3442 } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
3443
3444 typedef struct _SECTION_OBJECT_POINTERS {
3445 PVOID DataSectionObject;
3446 PVOID SharedCacheMap;
3447 PVOID ImageSectionObject;
3448 } SECTION_OBJECT_POINTERS, *PSECTION_OBJECT_POINTERS;
3449
3450 typedef struct _IO_COMPLETION_CONTEXT {
3451 PVOID Port;
3452 PVOID Key;
3453 } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
3454
3455 /* FILE_OBJECT.Flags */
3456
3457 #define FO_FILE_OPEN 0x00000001
3458 #define FO_SYNCHRONOUS_IO 0x00000002
3459 #define FO_ALERTABLE_IO 0x00000004
3460 #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
3461 #define FO_WRITE_THROUGH 0x00000010
3462 #define FO_SEQUENTIAL_ONLY 0x00000020
3463 #define FO_CACHE_SUPPORTED 0x00000040
3464 #define FO_NAMED_PIPE 0x00000080
3465 #define FO_STREAM_FILE 0x00000100
3466 #define FO_MAILSLOT 0x00000200
3467 #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
3468 #define FO_QUEUE_IRP_TO_THREAD 0x00000400
3469 #define FO_DIRECT_DEVICE_OPEN 0x00000800
3470 #define FO_FILE_MODIFIED 0x00001000
3471 #define FO_FILE_SIZE_CHANGED 0x00002000
3472 #define FO_CLEANUP_COMPLETE 0x00004000
3473 #define FO_TEMPORARY_FILE 0x00008000
3474 #define FO_DELETE_ON_CLOSE 0x00010000
3475 #define FO_OPENED_CASE_SENSITIVE 0x00020000
3476 #define FO_HANDLE_CREATED 0x00040000
3477 #define FO_FILE_FAST_IO_READ 0x00080000
3478 #define FO_RANDOM_ACCESS 0x00100000
3479 #define FO_FILE_OPEN_CANCELLED 0x00200000
3480 #define FO_VOLUME_OPEN 0x00400000
3481 #define FO_REMOTE_ORIGIN 0x01000000
3482 #define FO_DISALLOW_EXCLUSIVE 0x02000000
3483 #define FO_SKIP_COMPLETION_PORT 0x02000000
3484 #define FO_SKIP_SET_EVENT 0x04000000
3485 #define FO_SKIP_SET_FAST_IO 0x08000000
3486
3487 /* VPB.Flags */
3488 #define VPB_MOUNTED 0x0001
3489 #define VPB_LOCKED 0x0002
3490 #define VPB_PERSISTENT 0x0004
3491 #define VPB_REMOVE_PENDING 0x0008
3492 #define VPB_RAW_MOUNT 0x0010
3493 #define VPB_DIRECT_WRITES_ALLOWED 0x0020
3494
3495 /* IRP.Flags */
3496
3497 #define SL_FORCE_ACCESS_CHECK 0x01
3498 #define SL_OPEN_PAGING_FILE 0x02
3499 #define SL_OPEN_TARGET_DIRECTORY 0x04
3500 #define SL_CASE_SENSITIVE 0x80
3501
3502 #define SL_KEY_SPECIFIED 0x01
3503 #define SL_OVERRIDE_VERIFY_VOLUME 0x02
3504 #define SL_WRITE_THROUGH 0x04
3505 #define SL_FT_SEQUENTIAL_WRITE 0x08
3506
3507 #define SL_FAIL_IMMEDIATELY 0x01
3508 #define SL_EXCLUSIVE_LOCK 0x02
3509
3510 #define SL_RESTART_SCAN 0x01
3511 #define SL_RETURN_SINGLE_ENTRY 0x02
3512 #define SL_INDEX_SPECIFIED 0x04
3513
3514 #define SL_WATCH_TREE 0x01
3515
3516 #define SL_ALLOW_RAW_MOUNT 0x01
3517
3518 #define CTL_CODE(DeviceType, Function, Method, Access)( \
3519 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
3520
3521 #define DEVICE_TYPE_FROM_CTL_CODE(ctl) (((ULONG) (ctl & 0xffff0000)) >> 16)
3522
3523 #define IRP_NOCACHE 0x00000001
3524 #define IRP_PAGING_IO 0x00000002
3525 #define IRP_MOUNT_COMPLETION 0x00000002
3526 #define IRP_SYNCHRONOUS_API 0x00000004
3527 #define IRP_ASSOCIATED_IRP 0x00000008
3528 #define IRP_BUFFERED_IO 0x00000010
3529 #define IRP_DEALLOCATE_BUFFER 0x00000020
3530 #define IRP_INPUT_OPERATION 0x00000040
3531 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
3532 #define IRP_CREATE_OPERATION 0x00000080
3533 #define IRP_READ_OPERATION 0x00000100
3534 #define IRP_WRITE_OPERATION 0x00000200
3535 #define IRP_CLOSE_OPERATION 0x00000400
3536 #define IRP_DEFER_IO_COMPLETION 0x00000800
3537 #define IRP_OB_QUERY_NAME 0x00001000
3538 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
3539
3540 #define IRP_QUOTA_CHARGED 0x01
3541 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
3542 #define IRP_ALLOCATED_FIXED_SIZE 0x04
3543 #define IRP_LOOKASIDE_ALLOCATION 0x08
3544
3545 /*
3546 ** IRP function codes
3547 */
3548
3549 #define IRP_MJ_CREATE 0x00
3550 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
3551 #define IRP_MJ_CLOSE 0x02
3552 #define IRP_MJ_READ 0x03
3553 #define IRP_MJ_WRITE 0x04
3554 #define IRP_MJ_QUERY_INFORMATION 0x05
3555 #define IRP_MJ_SET_INFORMATION 0x06
3556 #define IRP_MJ_QUERY_EA 0x07
3557 #define IRP_MJ_SET_EA 0x08
3558 #define IRP_MJ_FLUSH_BUFFERS 0x09
3559 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
3560 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
3561 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
3562 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
3563 #define IRP_MJ_DEVICE_CONTROL 0x0e
3564 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
3565 #define IRP_MJ_SCSI 0x0f
3566 #define IRP_MJ_SHUTDOWN 0x10
3567 #define IRP_MJ_LOCK_CONTROL 0x11
3568 #define IRP_MJ_CLEANUP 0x12
3569 #define IRP_MJ_CREATE_MAILSLOT 0x13
3570 #define IRP_MJ_QUERY_SECURITY 0x14
3571 #define IRP_MJ_SET_SECURITY 0x15
3572 #define IRP_MJ_POWER 0x16
3573 #define IRP_MJ_SYSTEM_CONTROL 0x17
3574 #define IRP_MJ_DEVICE_CHANGE 0x18
3575 #define IRP_MJ_QUERY_QUOTA 0x19
3576 #define IRP_MJ_SET_QUOTA 0x1a
3577 #define IRP_MJ_PNP 0x1b
3578 #define IRP_MJ_PNP_POWER 0x1b
3579 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
3580
3581 #define IRP_MN_SCSI_CLASS 0x01
3582
3583 #define IRP_MN_START_DEVICE 0x00
3584 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
3585 #define IRP_MN_REMOVE_DEVICE 0x02
3586 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
3587 #define IRP_MN_STOP_DEVICE 0x04
3588 #define IRP_MN_QUERY_STOP_DEVICE 0x05
3589 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
3590
3591 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
3592 #define IRP_MN_QUERY_INTERFACE 0x08
3593 #define IRP_MN_QUERY_CAPABILITIES 0x09
3594 #define IRP_MN_QUERY_RESOURCES 0x0A
3595 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
3596 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
3597 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
3598
3599 #define IRP_MN_READ_CONFIG 0x0F
3600 #define IRP_MN_WRITE_CONFIG 0x10
3601 #define IRP_MN_EJECT 0x11
3602 #define IRP_MN_SET_LOCK 0x12
3603 #define IRP_MN_QUERY_ID 0x13
3604 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
3605 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
3606 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
3607 #define IRP_MN_SURPRISE_REMOVAL 0x17
3608
3609 #define IRP_MN_WAIT_WAKE 0x00
3610 #define IRP_MN_POWER_SEQUENCE 0x01
3611 #define IRP_MN_SET_POWER 0x02
3612 #define IRP_MN_QUERY_POWER 0x03
3613
3614 #define IRP_MN_QUERY_ALL_DATA 0x00
3615 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
3616 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
3617 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
3618 #define IRP_MN_ENABLE_EVENTS 0x04
3619 #define IRP_MN_DISABLE_EVENTS 0x05
3620 #define IRP_MN_ENABLE_COLLECTION 0x06
3621 #define IRP_MN_DISABLE_COLLECTION 0x07
3622 #define IRP_MN_REGINFO 0x08
3623 #define IRP_MN_EXECUTE_METHOD 0x09
3624
3625 #define IRP_MN_REGINFO_EX 0x0b
3626
3627 typedef struct _FILE_OBJECT
3628 {
3629 CSHORT Type;
3630 CSHORT Size;
3631 PDEVICE_OBJECT DeviceObject;
3632 PVPB Vpb;
3633 PVOID FsContext;
3634 PVOID FsContext2;
3635 PSECTION_OBJECT_POINTERS SectionObjectPointer;
3636 PVOID PrivateCacheMap;
3637 NTSTATUS FinalStatus;
3638 struct _FILE_OBJECT *RelatedFileObject;
3639 BOOLEAN LockOperation;
3640 BOOLEAN DeletePending;
3641 BOOLEAN ReadAccess;
3642 BOOLEAN WriteAccess;
3643 BOOLEAN DeleteAccess;
3644 BOOLEAN SharedRead;
3645 BOOLEAN SharedWrite;
3646 BOOLEAN SharedDelete;
3647 ULONG Flags;
3648 UNICODE_STRING FileName;
3649 LARGE_INTEGER CurrentByteOffset;
3650 volatile ULONG Waiters;
3651 volatile ULONG Busy;
3652 PVOID LastLock;
3653 KEVENT Lock;
3654 KEVENT Event;
3655 volatile PIO_COMPLETION_CONTEXT CompletionContext;
3656 KSPIN_LOCK IrpListLock;
3657 LIST_ENTRY IrpList;
3658 volatile PVOID FileObjectExtension;
3659 } FILE_OBJECT;
3660 typedef struct _FILE_OBJECT *PFILE_OBJECT;
3661
3662 typedef struct _IO_ERROR_LOG_PACKET {
3663 UCHAR MajorFunctionCode;
3664 UCHAR RetryCount;
3665 USHORT DumpDataSize;
3666 USHORT NumberOfStrings;
3667 USHORT StringOffset;
3668 USHORT EventCategory;
3669 NTSTATUS ErrorCode;
3670 ULONG UniqueErrorValue;
3671 NTSTATUS FinalStatus;
3672 ULONG SequenceNumber;
3673 ULONG IoControlCode;
3674 LARGE_INTEGER DeviceOffset;
3675 ULONG DumpData[1];
3676 } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
3677
3678 typedef struct _IO_ERROR_LOG_MESSAGE {
3679 USHORT Type;
3680 USHORT Size;
3681 USHORT DriverNameLength;
3682 LARGE_INTEGER TimeStamp;
3683 ULONG DriverNameOffset;
3684 IO_ERROR_LOG_PACKET EntryData;
3685 } IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
3686
3687 #define ERROR_LOG_LIMIT_SIZE 240
3688 #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
3689 sizeof(IO_ERROR_LOG_PACKET) + \
3690 (sizeof(WCHAR) * 40))
3691 #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
3692 (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
3693 #define IO_ERROR_LOG_MESSAGE_LENGTH \
3694 ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
3695 ERROR_LOG_MESSAGE_LIMIT_SIZE : \
3696 PORT_MAXIMUM_MESSAGE_LENGTH)
3697 #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
3698 IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
3699
3700 typedef enum _DMA_WIDTH {
3701 Width8Bits,
3702 Width16Bits,
3703 Width32Bits,
3704 MaximumDmaWidth
3705 } DMA_WIDTH, *PDMA_WIDTH;
3706
3707 typedef enum _DMA_SPEED {
3708 Compatible,
3709 TypeA,
3710 TypeB,
3711 TypeC,
3712 TypeF,
3713 MaximumDmaSpeed
3714 } DMA_SPEED, *PDMA_SPEED;
3715
3716 /* DEVICE_DESCRIPTION.Version */
3717
3718 #define DEVICE_DESCRIPTION_VERSION 0x0000
3719 #define DEVICE_DESCRIPTION_VERSION1 0x0001
3720 #define DEVICE_DESCRIPTION_VERSION2 0x0002
3721
3722 typedef struct _DEVICE_DESCRIPTION {
3723 ULONG Version;
3724 BOOLEAN Master;
3725 BOOLEAN ScatterGather;
3726 BOOLEAN DemandMode;
3727 BOOLEAN AutoInitialize;
3728 BOOLEAN Dma32BitAddresses;
3729 BOOLEAN IgnoreCount;
3730 BOOLEAN Reserved1;
3731 BOOLEAN Dma64BitAddresses;
3732 ULONG BusNumber;
3733 ULONG DmaChannel;
3734 INTERFACE_TYPE InterfaceType;
3735 DMA_WIDTH DmaWidth;
3736 DMA_SPEED DmaSpeed;
3737 ULONG MaximumLength;
3738 ULONG DmaPort;
3739 } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
3740
3741 typedef enum _DEVICE_RELATION_TYPE {
3742 BusRelations,
3743 EjectionRelations,
3744 PowerRelations,
3745 RemovalRelations,
3746 TargetDeviceRelation,
3747 SingleBusRelations,
3748 TransportRelations
3749 } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
3750
3751 typedef struct _DEVICE_RELATIONS {
3752 ULONG Count;
3753 PDEVICE_OBJECT Objects[1];
3754 } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
3755
3756 typedef struct _DEVOBJ_EXTENSION
3757 {
3758 CSHORT Type;
3759 USHORT Size;
3760 PDEVICE_OBJECT DeviceObject;
3761 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
3762
3763 typedef struct _SCATTER_GATHER_ELEMENT {
3764 PHYSICAL_ADDRESS Address;
3765 ULONG Length;
3766 ULONG_PTR Reserved;
3767 } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
3768
3769 #if defined(_MSC_EXTENSIONS)
3770
3771 #if _MSC_VER >= 1200
3772 #pragma warning(push)
3773 #endif
3774 #pragma warning(disable:4200)
3775 typedef struct _SCATTER_GATHER_LIST {
3776 ULONG NumberOfElements;
3777 ULONG_PTR Reserved;
3778 SCATTER_GATHER_ELEMENT Elements[1];
3779 } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
3780
3781 #if _MSC_VER >= 1200
3782 #pragma warning(pop)
3783 #else
3784 #pragma warning(default:4200)
3785 #endif
3786
3787 #else
3788
3789 struct _SCATTER_GATHER_LIST;
3790 typedef struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
3791
3792 #endif
3793
3794 typedef NTSTATUS
3795 (DDKAPI DRIVER_ADD_DEVICE)(
3796 IN struct _DRIVER_OBJECT *DriverObject,
3797 IN struct _DEVICE_OBJECT *PhysicalDeviceObject);
3798 typedef DRIVER_ADD_DEVICE *PDRIVER_ADD_DEVICE;
3799
3800 typedef struct _DRIVER_EXTENSION {
3801 struct _DRIVER_OBJECT *DriverObject;
3802 PDRIVER_ADD_DEVICE AddDevice;
3803 ULONG Count;
3804 UNICODE_STRING ServiceKeyName;
3805 } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
3806
3807 #define DRVO_UNLOAD_INVOKED 0x00000001
3808 #define DRVO_LEGACY_DRIVER 0x00000002
3809 #define DRVO_BUILTIN_DRIVER 0x00000004
3810
3811 typedef NTSTATUS
3812 (DDKAPI DRIVER_INITIALIZE)(
3813 IN struct _DRIVER_OBJECT *DriverObject,
3814 IN PUNICODE_STRING RegistryPath);
3815 typedef DRIVER_INITIALIZE *PDRIVER_INITIALIZE;
3816
3817 typedef VOID
3818 (DDKAPI DRIVER_STARTIO)(
3819 IN struct _DEVICE_OBJECT *DeviceObject,
3820 IN struct _IRP *Irp);
3821 typedef DRIVER_STARTIO *PDRIVER_STARTIO;
3822
3823 typedef VOID
3824 (DDKAPI DRIVER_UNLOAD)(
3825 IN struct _DRIVER_OBJECT *DriverObject);
3826 typedef DRIVER_UNLOAD *PDRIVER_UNLOAD;
3827
3828 typedef NTSTATUS
3829 (DDKAPI DRIVER_DISPATCH)(
3830 IN struct _DEVICE_OBJECT *DeviceObject,
3831 IN struct _IRP *Irp);
3832 typedef DRIVER_DISPATCH *PDRIVER_DISPATCH;
3833
3834 typedef struct _DRIVER_OBJECT {
3835 CSHORT Type;
3836 CSHORT Size;
3837 PDEVICE_OBJECT DeviceObject;
3838 ULONG Flags;
3839 PVOID DriverStart;
3840 ULONG DriverSize;
3841 PVOID DriverSection;
3842 PDRIVER_EXTENSION DriverExtension;
3843 UNICODE_STRING DriverName;
3844 PUNICODE_STRING HardwareDatabase;
3845 struct _FAST_IO_DISPATCH *FastIoDispatch;
3846 PDRIVER_INITIALIZE DriverInit;
3847 PDRIVER_STARTIO DriverStartIo;
3848 PDRIVER_UNLOAD DriverUnload;
3849 PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];
3850 } DRIVER_OBJECT;
3851 typedef struct _DRIVER_OBJECT *PDRIVER_OBJECT;
3852
3853 typedef struct _DMA_ADAPTER {
3854 USHORT Version;
3855 USHORT Size;
3856 struct _DMA_OPERATIONS* DmaOperations;
3857 } DMA_ADAPTER, *PDMA_ADAPTER;
3858
3859 typedef VOID
3860 (DDKAPI *PPUT_DMA_ADAPTER)(
3861 IN PDMA_ADAPTER DmaAdapter);
3862
3863 typedef PVOID
3864 (DDKAPI *PALLOCATE_COMMON_BUFFER)(
3865 IN PDMA_ADAPTER DmaAdapter,
3866 IN ULONG Length,
3867 OUT PPHYSICAL_ADDRESS LogicalAddress,
3868 IN BOOLEAN CacheEnabled);
3869
3870 typedef VOID
3871 (DDKAPI *PFREE_COMMON_BUFFER)(
3872 IN PDMA_ADAPTER DmaAdapter,
3873 IN ULONG Length,
3874 IN PHYSICAL_ADDRESS LogicalAddress,
3875 IN PVOID VirtualAddress,
3876 IN BOOLEAN CacheEnabled);
3877
3878 typedef NTSTATUS
3879 (DDKAPI *PALLOCATE_ADAPTER_CHANNEL)(
3880 IN PDMA_ADAPTER DmaAdapter,
3881 IN PDEVICE_OBJECT DeviceObject,
3882 IN ULONG NumberOfMapRegisters,
3883 IN PDRIVER_CONTROL ExecutionRoutine,
3884 IN PVOID Context);
3885
3886 typedef BOOLEAN
3887 (DDKAPI *PFLUSH_ADAPTER_BUFFERS)(
3888 IN PDMA_ADAPTER DmaAdapter,
3889 IN PMDL Mdl,
3890 IN PVOID MapRegisterBase,
3891 IN PVOID CurrentVa,
3892 IN ULONG Length,