- 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 typedef struct _PCI_COMMON_HEADER {
2602 USHORT VendorID;
2603 USHORT DeviceID;
2604 USHORT Command;
2605 USHORT Status;
2606 UCHAR RevisionID;
2607 UCHAR ProgIf;
2608 UCHAR SubClass;
2609 UCHAR BaseClass;
2610 UCHAR CacheLineSize;
2611 UCHAR LatencyTimer;
2612 UCHAR HeaderType;
2613 UCHAR BIST;
2614 union {
2615 struct _PCI_HEADER_TYPE_0 {
2616 ULONG BaseAddresses[PCI_TYPE0_ADDRESSES];
2617 ULONG CIS;
2618 USHORT SubVendorID;
2619 USHORT SubSystemID;
2620 ULONG ROMBaseAddress;
2621 UCHAR CapabilitiesPtr;
2622 UCHAR Reserved1[3];
2623 ULONG Reserved2;
2624 UCHAR InterruptLine;
2625 UCHAR InterruptPin;
2626 UCHAR MinimumGrant;
2627 UCHAR MaximumLatency;
2628 } type0;
2629 struct _PCI_HEADER_TYPE_1 {
2630 ULONG BaseAddresses[PCI_TYPE1_ADDRESSES];
2631 UCHAR PrimaryBus;
2632 UCHAR SecondaryBus;
2633 UCHAR SubordinateBus;
2634 UCHAR SecondaryLatency;
2635 UCHAR IOBase;
2636 UCHAR IOLimit;
2637 USHORT SecondaryStatus;
2638 USHORT MemoryBase;
2639 USHORT MemoryLimit;
2640 USHORT PrefetchBase;
2641 USHORT PrefetchLimit;
2642 ULONG PrefetchBaseUpper32;
2643 ULONG PrefetchLimitUpper32;
2644 USHORT IOBaseUpper16;
2645 USHORT IOLimitUpper16;
2646 UCHAR CapabilitiesPtr;
2647 UCHAR Reserved1[3];
2648 ULONG ROMBaseAddress;
2649 UCHAR InterruptLine;
2650 UCHAR InterruptPin;
2651 USHORT BridgeControl;
2652 } type1;
2653 struct _PCI_HEADER_TYPE_2 {
2654 ULONG SocketRegistersBaseAddress;
2655 UCHAR CapabilitiesPtr;
2656 UCHAR Reserved;
2657 USHORT SecondaryStatus;
2658 UCHAR PrimaryBus;
2659 UCHAR SecondaryBus;
2660 UCHAR SubordinateBus;
2661 UCHAR SecondaryLatency;
2662 struct {
2663 ULONG Base;
2664 ULONG Limit;
2665 } Range[PCI_TYPE2_ADDRESSES-1];
2666 UCHAR InterruptLine;
2667 UCHAR InterruptPin;
2668 USHORT BridgeControl;
2669 } type2;
2670 } u;
2671 } PCI_COMMON_HEADER, *PPCI_COMMON_HEADER;
2672
2673 #ifdef __cplusplus
2674
2675 typedef struct _PCI_COMMON_CONFIG : PCI_COMMON_HEADER {
2676 UCHAR DeviceSpecific[192];
2677 } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
2678
2679 #else
2680
2681 typedef struct _PCI_COMMON_CONFIG {
2682 PCI_COMMON_HEADER DUMMYSTRUCTNAME;
2683 UCHAR DeviceSpecific[192];
2684 } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
2685
2686 #endif
2687
2688 typedef struct _PCI_SLOT_NUMBER {
2689 union {
2690 struct {
2691 ULONG DeviceNumber : 5;
2692 ULONG FunctionNumber : 3;
2693 ULONG Reserved : 24;
2694 } bits;
2695 ULONG AsULONG;
2696 } u;
2697 } PCI_SLOT_NUMBER, *PPCI_SLOT_NUMBER;
2698
2699 typedef struct _IO_STATUS_BLOCK {
2700 _ANONYMOUS_UNION union {
2701 NTSTATUS Status;
2702 PVOID Pointer;
2703 } DUMMYUNIONNAME;
2704 ULONG_PTR Information;
2705 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
2706
2707 typedef VOID
2708 (DDKAPI *PIO_APC_ROUTINE)(
2709 IN PVOID ApcContext,
2710 IN PIO_STATUS_BLOCK IoStatusBlock,
2711 IN ULONG Reserved);
2712
2713 #define EVENT_INCREMENT 1
2714 #define IO_NO_INCREMENT 0
2715 #define IO_CD_ROM_INCREMENT 1
2716 #define IO_DISK_INCREMENT 1
2717 #define IO_KEYBOARD_INCREMENT 6
2718 #define IO_MAILSLOT_INCREMENT 2
2719 #define IO_MOUSE_INCREMENT 6
2720 #define IO_NAMED_PIPE_INCREMENT 2
2721 #define IO_NETWORK_INCREMENT 2
2722 #define IO_PARALLEL_INCREMENT 1
2723 #define IO_SERIAL_INCREMENT 2
2724 #define IO_SOUND_INCREMENT 8
2725 #define IO_VIDEO_INCREMENT 1
2726 #define SEMAPHORE_INCREMENT 1
2727
2728 #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
2729
2730 typedef struct _BOOTDISK_INFORMATION {
2731 LONGLONG BootPartitionOffset;
2732 LONGLONG SystemPartitionOffset;
2733 ULONG BootDeviceSignature;
2734 ULONG SystemDeviceSignature;
2735 } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
2736
2737 typedef struct _BOOTDISK_INFORMATION_EX {
2738 LONGLONG BootPartitionOffset;
2739 LONGLONG SystemPartitionOffset;
2740 ULONG BootDeviceSignature;
2741 ULONG SystemDeviceSignature;
2742 GUID BootDeviceGuid;
2743 GUID SystemDeviceGuid;
2744 BOOLEAN BootDeviceIsGpt;
2745 BOOLEAN SystemDeviceIsGpt;
2746 } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
2747
2748 typedef struct _EISA_MEMORY_TYPE {
2749 UCHAR ReadWrite : 1;
2750 UCHAR Cached : 1;
2751 UCHAR Reserved0 : 1;
2752 UCHAR Type : 2;
2753 UCHAR Shared : 1;
2754 UCHAR Reserved1 : 1;
2755 UCHAR MoreEntries : 1;
2756 } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
2757
2758 #include <pshpack1.h>
2759 typedef struct _EISA_MEMORY_CONFIGURATION {
2760 EISA_MEMORY_TYPE ConfigurationByte;
2761 UCHAR DataSize;
2762 USHORT AddressLowWord;
2763 UCHAR AddressHighByte;
2764 USHORT MemorySize;
2765 } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
2766 #include <poppack.h>
2767
2768 typedef struct _EISA_IRQ_DESCRIPTOR {
2769 UCHAR Interrupt : 4;
2770 UCHAR Reserved : 1;
2771 UCHAR LevelTriggered : 1;
2772 UCHAR Shared : 1;
2773 UCHAR MoreEntries : 1;
2774 } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
2775
2776 typedef struct _EISA_IRQ_CONFIGURATION {
2777 EISA_IRQ_DESCRIPTOR ConfigurationByte;
2778 UCHAR Reserved;
2779 } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
2780
2781 typedef struct _DMA_CONFIGURATION_BYTE0 {
2782 UCHAR Channel : 3;
2783 UCHAR Reserved : 3;
2784 UCHAR Shared : 1;
2785 UCHAR MoreEntries : 1;
2786 } DMA_CONFIGURATION_BYTE0;
2787
2788 typedef struct _DMA_CONFIGURATION_BYTE1 {
2789 UCHAR Reserved0 : 2;
2790 UCHAR TransferSize : 2;
2791 UCHAR Timing : 2;
2792 UCHAR Reserved1 : 2;
2793 } DMA_CONFIGURATION_BYTE1;
2794
2795 typedef struct _EISA_DMA_CONFIGURATION {
2796 DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
2797 DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
2798 } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
2799
2800 #include <pshpack1.h>
2801 typedef struct _EISA_PORT_DESCRIPTOR {
2802 UCHAR NumberPorts : 5;
2803 UCHAR Reserved : 1;
2804 UCHAR Shared : 1;
2805 UCHAR MoreEntries : 1;
2806 } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
2807
2808 typedef struct _EISA_PORT_CONFIGURATION {
2809 EISA_PORT_DESCRIPTOR Configuration;
2810 USHORT PortAddress;
2811 } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
2812 #include <poppack.h>
2813
2814 typedef struct _CM_EISA_FUNCTION_INFORMATION {
2815 ULONG CompressedId;
2816 UCHAR IdSlotFlags1;
2817 UCHAR IdSlotFlags2;
2818 UCHAR MinorRevision;
2819 UCHAR MajorRevision;
2820 UCHAR Selections[26];
2821 UCHAR FunctionFlags;
2822 UCHAR TypeString[80];
2823 EISA_MEMORY_CONFIGURATION EisaMemory[9];
2824 EISA_IRQ_CONFIGURATION EisaIrq[7];
2825 EISA_DMA_CONFIGURATION EisaDma[4];
2826 EISA_PORT_CONFIGURATION EisaPort[20];
2827 UCHAR InitializationData[60];
2828 } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
2829
2830 /* CM_EISA_FUNCTION_INFORMATION.FunctionFlags */
2831
2832 #define EISA_FUNCTION_ENABLED 0x80
2833 #define EISA_FREE_FORM_DATA 0x40
2834 #define EISA_HAS_PORT_INIT_ENTRY 0x20
2835 #define EISA_HAS_PORT_RANGE 0x10
2836 #define EISA_HAS_DMA_ENTRY 0x08
2837 #define EISA_HAS_IRQ_ENTRY 0x04
2838 #define EISA_HAS_MEMORY_ENTRY 0x02
2839 #define EISA_HAS_TYPE_ENTRY 0x01
2840 #define EISA_HAS_INFORMATION \
2841 (EISA_HAS_PORT_RANGE + EISA_HAS_DMA_ENTRY + EISA_HAS_IRQ_ENTRY \
2842 + EISA_HAS_MEMORY_ENTRY + EISA_HAS_TYPE_ENTRY)
2843
2844 typedef struct _CM_EISA_SLOT_INFORMATION {
2845 UCHAR ReturnCode;
2846 UCHAR ReturnFlags;
2847 UCHAR MajorRevision;
2848 UCHAR MinorRevision;
2849 USHORT Checksum;
2850 UCHAR NumberFunctions;
2851 UCHAR FunctionInformation;
2852 ULONG CompressedId;
2853 } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
2854
2855 /* CM_EISA_SLOT_INFORMATION.ReturnCode */
2856
2857 #define EISA_INVALID_SLOT 0x80
2858 #define EISA_INVALID_FUNCTION 0x81
2859 #define EISA_INVALID_CONFIGURATION 0x82
2860 #define EISA_EMPTY_SLOT 0x83
2861 #define EISA_INVALID_BIOS_CALL 0x86
2862
2863 /*
2864 ** Plug and Play structures
2865 */
2866
2867 typedef VOID
2868 (DDKAPI *PINTERFACE_REFERENCE)(
2869 PVOID Context);
2870
2871 typedef VOID
2872 (DDKAPI *PINTERFACE_DEREFERENCE)(
2873 PVOID Context);
2874
2875 typedef BOOLEAN
2876 (DDKAPI *PTRANSLATE_BUS_ADDRESS)(
2877 IN PVOID Context,
2878 IN PHYSICAL_ADDRESS BusAddress,
2879 IN ULONG Length,
2880 IN OUT PULONG AddressSpace,
2881 OUT PPHYSICAL_ADDRESS TranslatedAddress);
2882
2883 typedef struct _DMA_ADAPTER*
2884 (DDKAPI *PGET_DMA_ADAPTER)(
2885 IN PVOID Context,
2886 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
2887 OUT PULONG NumberOfMapRegisters);
2888
2889 typedef ULONG
2890 (DDKAPI *PGET_SET_DEVICE_DATA)(
2891 IN PVOID Context,
2892 IN ULONG DataType,
2893 IN PVOID Buffer,
2894 IN ULONG Offset,
2895 IN ULONG Length);
2896
2897 /* PCI_DEVICE_PRESENCE_PARAMETERS.Flags */
2898 #define PCI_USE_SUBSYSTEM_IDS 0x00000001
2899 #define PCI_USE_REVISION 0x00000002
2900 #define PCI_USE_VENDEV_IDS 0x00000004
2901 #define PCI_USE_CLASS_SUBCLASS 0x00000008
2902 #define PCI_USE_PROGIF 0x00000010
2903 #define PCI_USE_LOCAL_BUS 0x00000020
2904 #define PCI_USE_LOCAL_DEVICE 0x00000040
2905
2906 typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
2907 ULONG Size;
2908 ULONG Flags;
2909 USHORT VendorID;
2910 USHORT DeviceID;
2911 UCHAR RevisionID;
2912 USHORT SubVendorID;
2913 USHORT SubSystemID;
2914 UCHAR BaseClass;
2915 UCHAR SubClass;
2916 UCHAR ProgIf;
2917 } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
2918
2919 typedef BOOLEAN
2920 (DDKAPI *PPCI_IS_DEVICE_PRESENT)(
2921 IN USHORT VendorID,
2922 IN USHORT DeviceID,
2923 IN UCHAR RevisionID,
2924 IN USHORT SubVendorID,
2925 IN USHORT SubSystemID,
2926 IN ULONG Flags);
2927
2928 typedef BOOLEAN
2929 (DDKAPI *PPCI_IS_DEVICE_PRESENT_EX)(
2930 IN PVOID Context,
2931 IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters);
2932
2933 typedef union _POWER_STATE {
2934 SYSTEM_POWER_STATE SystemState;
2935 DEVICE_POWER_STATE DeviceState;
2936 } POWER_STATE, *PPOWER_STATE;
2937
2938 typedef enum _POWER_STATE_TYPE {
2939 SystemPowerState = 0,
2940 DevicePowerState
2941 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
2942
2943 typedef struct _BUS_INTERFACE_STANDARD {
2944 USHORT Size;
2945 USHORT Version;
2946 PVOID Context;
2947 PINTERFACE_REFERENCE InterfaceReference;
2948 PINTERFACE_DEREFERENCE InterfaceDereference;
2949 PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
2950 PGET_DMA_ADAPTER GetDmaAdapter;
2951 PGET_SET_DEVICE_DATA SetBusData;
2952 PGET_SET_DEVICE_DATA GetBusData;
2953 } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
2954
2955 typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
2956 USHORT Size;
2957 USHORT Version;
2958 PVOID Context;
2959 PINTERFACE_REFERENCE InterfaceReference;
2960 PINTERFACE_DEREFERENCE InterfaceDereference;
2961 PPCI_IS_DEVICE_PRESENT IsDevicePresent;
2962 PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
2963 } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
2964
2965 typedef struct _DEVICE_CAPABILITIES {
2966 USHORT Size;
2967 USHORT Version;
2968 ULONG DeviceD1 : 1;
2969 ULONG DeviceD2 : 1;
2970 ULONG LockSupported : 1;
2971 ULONG EjectSupported : 1;
2972 ULONG Removable : 1;
2973 ULONG DockDevice : 1;
2974 ULONG UniqueID : 1;
2975 ULONG SilentInstall : 1;
2976 ULONG RawDeviceOK : 1;
2977 ULONG SurpriseRemovalOK : 1;
2978 ULONG WakeFromD0 : 1;
2979 ULONG WakeFromD1 : 1;
2980 ULONG WakeFromD2 : 1;
2981 ULONG WakeFromD3 : 1;
2982 ULONG HardwareDisabled : 1;
2983 ULONG NonDynamic : 1;
2984 ULONG WarmEjectSupported : 1;
2985 ULONG NoDisplayInUI : 1;
2986 ULONG Reserved : 14;
2987 ULONG Address;
2988 ULONG UINumber;
2989 DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
2990 SYSTEM_POWER_STATE SystemWake;
2991 DEVICE_POWER_STATE DeviceWake;
2992 ULONG D1Latency;
2993 ULONG D2Latency;
2994 ULONG D3Latency;
2995 } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
2996
2997 typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
2998 USHORT Version;
2999 USHORT Size;
3000 GUID Event;
3001 GUID InterfaceClassGuid;
3002 PUNICODE_STRING SymbolicLinkName;
3003 } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
3004
3005 typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
3006 USHORT Version;
3007 USHORT Size;
3008 GUID Event;
3009 } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
3010
3011 #undef INTERFACE
3012
3013 typedef struct _INTERFACE {
3014 USHORT Size;
3015 USHORT Version;
3016 PVOID Context;
3017 PINTERFACE_REFERENCE InterfaceReference;
3018 PINTERFACE_DEREFERENCE InterfaceDereference;
3019 } INTERFACE, *PINTERFACE;
3020
3021 typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
3022 USHORT Version;
3023 USHORT Size;
3024 GUID Event;
3025 } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
3026
3027 typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
3028
3029 /* PNP_DEVICE_STATE */
3030
3031 #define PNP_DEVICE_DISABLED 0x00000001
3032 #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
3033 #define PNP_DEVICE_FAILED 0x00000004
3034 #define PNP_DEVICE_REMOVED 0x00000008
3035 #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
3036 #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
3037
3038 typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
3039 USHORT Version;
3040 USHORT Size;
3041 GUID Event;
3042 struct _FILE_OBJECT *FileObject;
3043 LONG NameBufferOffset;
3044 UCHAR CustomDataBuffer[1];
3045 } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
3046
3047 typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
3048 USHORT Version;
3049 USHORT Size;
3050 GUID Event;
3051 struct _FILE_OBJECT *FileObject;
3052 } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
3053
3054 typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
3055 DeviceUsageTypeUndefined,
3056 DeviceUsageTypePaging,
3057 DeviceUsageTypeHibernation,
3058 DeviceUsageTypeDumpFile
3059 } DEVICE_USAGE_NOTIFICATION_TYPE;
3060
3061 typedef struct _POWER_SEQUENCE {
3062 ULONG SequenceD1;
3063 ULONG SequenceD2;
3064 ULONG SequenceD3;
3065 } POWER_SEQUENCE, *PPOWER_SEQUENCE;
3066
3067 typedef enum {
3068 DevicePropertyDeviceDescription = 0x0,
3069 DevicePropertyHardwareID = 0x1,
3070 DevicePropertyCompatibleIDs = 0x2,
3071 DevicePropertyBootConfiguration = 0x3,
3072 DevicePropertyBootConfigurationTranslated = 0x4,
3073 DevicePropertyClassName = 0x5,
3074 DevicePropertyClassGuid = 0x6,
3075 DevicePropertyDriverKeyName = 0x7,
3076 DevicePropertyManufacturer = 0x8,
3077 DevicePropertyFriendlyName = 0x9,
3078 DevicePropertyLocationInformation = 0xa,
3079 DevicePropertyPhysicalDeviceObjectName = 0xb,
3080 DevicePropertyBusTypeGuid = 0xc,
3081 DevicePropertyLegacyBusType = 0xd,
3082 DevicePropertyBusNumber = 0xe,
3083 DevicePropertyEnumeratorName = 0xf,
3084 DevicePropertyAddress = 0x10,
3085 DevicePropertyUINumber = 0x11,
3086 DevicePropertyInstallState = 0x12,
3087 DevicePropertyRemovalPolicy = 0x13,
3088 DevicePropertyResourceRequirements = 0x14,
3089 DevicePropertyAllocatedResources = 0x15,
3090 DevicePropertyContainerID = 0x16
3091 } DEVICE_REGISTRY_PROPERTY;
3092
3093 typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
3094 EventCategoryReserved,
3095 EventCategoryHardwareProfileChange,
3096 EventCategoryDeviceInterfaceChange,
3097 EventCategoryTargetDeviceChange
3098 } IO_NOTIFICATION_EVENT_CATEGORY;
3099
3100 #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
3101
3102 typedef NTSTATUS
3103 (DDKAPI *PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)(
3104 IN PVOID NotificationStructure,
3105 IN PVOID Context);
3106
3107 typedef VOID
3108 (DDKAPI *PDEVICE_CHANGE_COMPLETE_CALLBACK)(
3109 IN PVOID Context);
3110
3111 typedef enum _FILE_INFORMATION_CLASS {
3112 FileDirectoryInformation = 1,
3113 FileFullDirectoryInformation,
3114 FileBothDirectoryInformation,
3115 FileBasicInformation,
3116 FileStandardInformation,
3117 FileInternalInformation,
3118 FileEaInformation,
3119 FileAccessInformation,
3120 FileNameInformation,
3121 FileRenameInformation,
3122 FileLinkInformation,
3123 FileNamesInformation,
3124 FileDispositionInformation,
3125 FilePositionInformation,
3126 FileFullEaInformation,
3127 FileModeInformation,
3128 FileAlignmentInformation,
3129 FileAllInformation,
3130 FileAllocationInformation,
3131 FileEndOfFileInformation,
3132 FileAlternateNameInformation,
3133 FileStreamInformation,
3134 FilePipeInformation,
3135 FilePipeLocalInformation,
3136 FilePipeRemoteInformation,
3137 FileMailslotQueryInformation,
3138 FileMailslotSetInformation,
3139 FileCompressionInformation,
3140 FileObjectIdInformation,
3141 FileCompletionInformation,
3142 FileMoveClusterInformation,
3143 FileQuotaInformation,
3144 FileReparsePointInformation,
3145 FileNetworkOpenInformation,
3146 FileAttributeTagInformation,
3147 FileTrackingInformation,
3148 FileIdBothDirectoryInformation,
3149 FileIdFullDirectoryInformation,
3150 FileValidDataLengthInformation,
3151 FileShortNameInformation,
3152 FileIoCompletionNotificationInformation,
3153 FileIoStatusBlockRangeInformation,
3154 FileIoPriorityHintInformation,
3155 FileSfioReserveInformation,
3156 FileSfioVolumeInformation,
3157 FileHardLinkInformation,
3158 FileProcessIdsUsingFileInformation,
3159 FileNormalizedNameInformation,
3160 FileNetworkPhysicalNameInformation,
3161 FileIdGlobalTxDirectoryInformation,
3162 FileIsRemoteDeviceInformation,
3163 FileAttributeCacheInformation,
3164 FileNumaNodeInformation,
3165 FileStandardLinkInformation,
3166 FileRemoteProtocolInformation,
3167 FileMaximumInformation
3168 } FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
3169
3170 typedef struct _FILE_POSITION_INFORMATION {
3171 LARGE_INTEGER CurrentByteOffset;
3172 } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION;
3173
3174 #include <pshpack8.h>
3175 typedef struct _FILE_BASIC_INFORMATION {
3176 LARGE_INTEGER CreationTime;
3177 LARGE_INTEGER LastAccessTime;
3178 LARGE_INTEGER LastWriteTime;
3179 LARGE_INTEGER ChangeTime;
3180 ULONG FileAttributes;
3181 } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
3182 #include <poppack.h>
3183
3184 typedef struct _FILE_STANDARD_INFORMATION {
3185 LARGE_INTEGER AllocationSize;
3186 LARGE_INTEGER EndOfFile;
3187 ULONG NumberOfLinks;
3188 BOOLEAN DeletePending;
3189 BOOLEAN Directory;
3190 } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
3191
3192 typedef struct _FILE_NETWORK_OPEN_INFORMATION {
3193 LARGE_INTEGER CreationTime;
3194 LARGE_INTEGER LastAccessTime;
3195 LARGE_INTEGER LastWriteTime;
3196 LARGE_INTEGER ChangeTime;
3197 LARGE_INTEGER AllocationSize;
3198 LARGE_INTEGER EndOfFile;
3199 ULONG FileAttributes;
3200 } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION;
3201
3202 typedef enum _FSINFOCLASS {
3203 FileFsVolumeInformation = 1,
3204 FileFsLabelInformation,
3205 FileFsSizeInformation,
3206 FileFsDeviceInformation,
3207 FileFsAttributeInformation,
3208 FileFsControlInformation,
3209 FileFsFullSizeInformation,
3210 FileFsObjectIdInformation,
3211 FileFsDriverPathInformation,
3212 FileFsVolumeFlagsInformation,
3213 FileFsMaximumInformation
3214 } FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS;
3215
3216 typedef struct _FILE_FS_DEVICE_INFORMATION {
3217 DEVICE_TYPE DeviceType;
3218 ULONG Characteristics;
3219 } FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION;
3220
3221 typedef struct _FILE_FULL_EA_INFORMATION {
3222 ULONG NextEntryOffset;
3223 UCHAR Flags;
3224 UCHAR EaNameLength;
3225 USHORT EaValueLength;
3226 CHAR EaName[1];
3227 } FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
3228
3229 typedef struct _FAST_MUTEX
3230 {
3231 LONG Count;
3232 PKTHREAD Owner;
3233 ULONG Contention;
3234 KEVENT Gate;
3235 ULONG OldIrql;
3236 } FAST_MUTEX, *PFAST_MUTEX;
3237
3238 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
3239
3240 typedef struct _OWNER_ENTRY {
3241 ERESOURCE_THREAD OwnerThread;
3242 _ANONYMOUS_UNION union {
3243 LONG OwnerCount;
3244 ULONG TableSize;
3245 } DUMMYUNIONNAME;
3246 } OWNER_ENTRY, *POWNER_ENTRY;
3247
3248 typedef struct _ERESOURCE
3249 {
3250 LIST_ENTRY SystemResourcesList;
3251 POWNER_ENTRY OwnerTable;
3252 SHORT ActiveCount;
3253 USHORT Flag;
3254 volatile PKSEMAPHORE SharedWaiters;
3255 volatile PKEVENT ExclusiveWaiters;
3256 OWNER_ENTRY OwnerEntry;
3257 ULONG ActiveEntries;
3258 ULONG ContentionCount;
3259 ULONG NumberOfSharedWaiters;
3260 ULONG NumberOfExclusiveWaiters;
3261 __GNU_EXTENSION union
3262 {
3263 PVOID Address;
3264 ULONG_PTR CreatorBackTraceIndex;
3265 };
3266 KSPIN_LOCK SpinLock;
3267 } ERESOURCE, *PERESOURCE;
3268
3269 /* ERESOURCE.Flag */
3270
3271 #define ResourceNeverExclusive 0x0010
3272 #define ResourceReleaseByOtherThread 0x0020
3273 #define ResourceOwnedExclusive 0x0080
3274
3275 #define RESOURCE_HASH_TABLE_SIZE 64
3276
3277 typedef BOOLEAN
3278 (DDKAPI *PFAST_IO_CHECK_IF_POSSIBLE)(
3279 IN struct _FILE_OBJECT *FileObject,
3280 IN PLARGE_INTEGER FileOffset,
3281 IN ULONG Length,
3282 IN BOOLEAN Wait,
3283 IN ULONG LockKey,
3284 IN BOOLEAN CheckForReadOperation,
3285 OUT PIO_STATUS_BLOCK IoStatus,
3286 IN struct _DEVICE_OBJECT *DeviceObject);
3287
3288 typedef BOOLEAN
3289 (DDKAPI *PFAST_IO_READ)(
3290 IN struct _FILE_OBJECT *FileObject,
3291 IN PLARGE_INTEGER FileOffset,
3292 IN ULONG Length,
3293 IN BOOLEAN Wait,
3294 IN ULONG LockKey,
3295 OUT PVOID Buffer,
3296 OUT PIO_STATUS_BLOCK IoStatus,
3297 IN struct _DEVICE_OBJECT *DeviceObject);
3298
3299 typedef BOOLEAN
3300 (DDKAPI *PFAST_IO_WRITE)(
3301 IN struct _FILE_OBJECT *FileObject,
3302 IN PLARGE_INTEGER FileOffset,
3303 IN ULONG Length,
3304 IN BOOLEAN Wait,
3305 IN ULONG LockKey,
3306 IN PVOID Buffer,
3307 OUT PIO_STATUS_BLOCK IoStatus,
3308 IN struct _DEVICE_OBJECT *DeviceObject);
3309
3310 typedef BOOLEAN
3311 (DDKAPI *PFAST_IO_QUERY_BASIC_INFO)(
3312 IN struct _FILE_OBJECT *FileObject,
3313 IN BOOLEAN Wait,
3314 OUT PFILE_BASIC_INFORMATION Buffer,
3315 OUT PIO_STATUS_BLOCK IoStatus,
3316 IN struct _DEVICE_OBJECT *DeviceObject);
3317
3318 typedef BOOLEAN
3319 (DDKAPI *PFAST_IO_QUERY_STANDARD_INFO)(
3320 IN struct _FILE_OBJECT *FileObject,
3321 IN BOOLEAN Wait,
3322 OUT PFILE_STANDARD_INFORMATION Buffer,
3323 OUT PIO_STATUS_BLOCK IoStatus,
3324 IN struct _DEVICE_OBJECT *DeviceObject);
3325
3326 typedef BOOLEAN
3327 (DDKAPI *PFAST_IO_LOCK)(
3328 IN struct _FILE_OBJECT *FileObject,
3329 IN PLARGE_INTEGER FileOffset,
3330 IN PLARGE_INTEGER Length,
3331 PEPROCESS ProcessId,
3332 ULONG Key,
3333 BOOLEAN FailImmediately,
3334 BOOLEAN ExclusiveLock,
3335 OUT PIO_STATUS_BLOCK IoStatus,
3336 IN struct _DEVICE_OBJECT *DeviceObject);
3337
3338 typedef BOOLEAN
3339 (DDKAPI *PFAST_IO_UNLOCK_SINGLE)(
3340 IN struct _FILE_OBJECT *FileObject,
3341 IN PLARGE_INTEGER FileOffset,
3342 IN PLARGE_INTEGER Length,
3343 PEPROCESS ProcessId,
3344 ULONG Key,
3345 OUT PIO_STATUS_BLOCK IoStatus,
3346 IN struct _DEVICE_OBJECT *DeviceObject);
3347
3348 typedef BOOLEAN
3349 (DDKAPI *PFAST_IO_UNLOCK_ALL)(
3350 IN struct _FILE_OBJECT *FileObject,
3351 PEPROCESS ProcessId,
3352 OUT PIO_STATUS_BLOCK IoStatus,
3353 IN struct _DEVICE_OBJECT *DeviceObject);
3354
3355 typedef BOOLEAN
3356 (DDKAPI *PFAST_IO_UNLOCK_ALL_BY_KEY)(
3357 IN struct _FILE_OBJECT *FileObject,
3358 PVOID ProcessId,
3359 ULONG Key,
3360 OUT PIO_STATUS_BLOCK IoStatus,
3361 IN struct _DEVICE_OBJECT *DeviceObject);
3362
3363 typedef BOOLEAN
3364 (DDKAPI *PFAST_IO_DEVICE_CONTROL)(
3365 IN struct _FILE_OBJECT *FileObject,
3366 IN BOOLEAN Wait,
3367 IN PVOID InputBuffer OPTIONAL,
3368 IN ULONG InputBufferLength,
3369 OUT PVOID OutputBuffer OPTIONAL,
3370 IN ULONG OutputBufferLength,
3371 IN ULONG IoControlCode,
3372 OUT PIO_STATUS_BLOCK IoStatus,
3373 IN struct _DEVICE_OBJECT *DeviceObject);
3374
3375 typedef VOID
3376 (DDKAPI *PFAST_IO_ACQUIRE_FILE)(
3377 IN struct _FILE_OBJECT *FileObject);
3378
3379 typedef VOID
3380 (DDKAPI *PFAST_IO_RELEASE_FILE)(
3381 IN struct _FILE_OBJECT *FileObject);
3382
3383 typedef VOID
3384 (DDKAPI *PFAST_IO_DETACH_DEVICE)(
3385 IN struct _DEVICE_OBJECT *SourceDevice,
3386 IN struct _DEVICE_OBJECT *TargetDevice);
3387
3388 typedef BOOLEAN
3389 (DDKAPI *PFAST_IO_QUERY_NETWORK_OPEN_INFO)(
3390 IN struct _FILE_OBJECT *FileObject,
3391 IN BOOLEAN Wait,
3392 OUT struct _FILE_NETWORK_OPEN_INFORMATION *Buffer,
3393 OUT struct _IO_STATUS_BLOCK *IoStatus,
3394 IN struct _DEVICE_OBJECT *DeviceObject);
3395
3396 typedef NTSTATUS
3397 (DDKAPI *PFAST_IO_ACQUIRE_FOR_MOD_WRITE)(
3398 IN struct _FILE_OBJECT *FileObject,
3399 IN PLARGE_INTEGER EndingOffset,
3400 OUT struct _ERESOURCE **ResourceToRelease,
3401 IN struct _DEVICE_OBJECT *DeviceObject);
3402
3403 typedef BOOLEAN
3404 (DDKAPI *PFAST_IO_MDL_READ)(
3405 IN struct _FILE_OBJECT *FileObject,
3406 IN PLARGE_INTEGER FileOffset,
3407 IN ULONG Length,
3408 IN ULONG LockKey,
3409 OUT PMDL *MdlChain,
3410 OUT PIO_STATUS_BLOCK IoStatus,
3411 IN struct _DEVICE_OBJECT *DeviceObject);
3412
3413 typedef BOOLEAN
3414 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE)(
3415 IN struct _FILE_OBJECT *FileObject,
3416 IN PMDL MdlChain,
3417 IN struct _DEVICE_OBJECT *DeviceObject);
3418
3419 typedef BOOLEAN
3420 (DDKAPI *PFAST_IO_PREPARE_MDL_WRITE)(
3421 IN struct _FILE_OBJECT *FileObject,
3422 IN PLARGE_INTEGER FileOffset,
3423 IN ULONG Length,
3424 IN ULONG LockKey,
3425 OUT PMDL *MdlChain,
3426 OUT PIO_STATUS_BLOCK IoStatus,
3427 IN struct _DEVICE_OBJECT *DeviceObject);
3428
3429 typedef BOOLEAN
3430 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE)(
3431 IN struct _FILE_OBJECT *FileObject,
3432 IN PLARGE_INTEGER FileOffset,
3433 IN PMDL MdlChain,
3434 IN struct _DEVICE_OBJECT *DeviceObject);
3435
3436 typedef BOOLEAN
3437 (DDKAPI *PFAST_IO_READ_COMPRESSED)(
3438 IN struct _FILE_OBJECT *FileObject,
3439 IN PLARGE_INTEGER FileOffset,
3440 IN ULONG Length,
3441 IN ULONG LockKey,
3442 OUT PVOID Buffer,
3443 OUT PMDL *MdlChain,
3444 OUT PIO_STATUS_BLOCK IoStatus,
3445 OUT struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3446 IN ULONG CompressedDataInfoLength,
3447 IN struct _DEVICE_OBJECT *DeviceObject);
3448
3449 typedef BOOLEAN
3450 (DDKAPI *PFAST_IO_WRITE_COMPRESSED)(
3451 IN struct _FILE_OBJECT *FileObject,
3452 IN PLARGE_INTEGER FileOffset,
3453 IN ULONG Length,
3454 IN ULONG LockKey,
3455 IN PVOID Buffer,
3456 OUT PMDL *MdlChain,
3457 OUT PIO_STATUS_BLOCK IoStatus,
3458 IN struct _COMPRESSED_DATA_INFO *CompressedDataInfo,
3459 IN ULONG CompressedDataInfoLength,
3460 IN struct _DEVICE_OBJECT *DeviceObject);
3461
3462 typedef BOOLEAN
3463 (DDKAPI *PFAST_IO_MDL_READ_COMPLETE_COMPRESSED)(
3464 IN struct _FILE_OBJECT *FileObject,
3465 IN PMDL MdlChain,
3466 IN struct _DEVICE_OBJECT *DeviceObject);
3467
3468 typedef BOOLEAN
3469 (DDKAPI *PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED)(
3470 IN struct _FILE_OBJECT *FileObject,
3471 IN PLARGE_INTEGER FileOffset,
3472 IN PMDL MdlChain,
3473 IN struct _DEVICE_OBJECT *DeviceObject);
3474
3475 typedef BOOLEAN
3476 (DDKAPI *PFAST_IO_QUERY_OPEN)(
3477 IN struct _IRP *Irp,
3478 OUT PFILE_NETWORK_OPEN_INFORMATION NetworkInformation,
3479 IN struct _DEVICE_OBJECT *DeviceObject);
3480
3481 typedef NTSTATUS
3482 (DDKAPI *PFAST_IO_RELEASE_FOR_MOD_WRITE)(
3483 IN struct _FILE_OBJECT *FileObject,
3484 IN struct _ERESOURCE *ResourceToRelease,
3485 IN struct _DEVICE_OBJECT *DeviceObject);
3486
3487 typedef NTSTATUS
3488 (DDKAPI *PFAST_IO_ACQUIRE_FOR_CCFLUSH)(
3489 IN struct _FILE_OBJECT *FileObject,
3490 IN struct _DEVICE_OBJECT *DeviceObject);
3491
3492 typedef NTSTATUS
3493 (DDKAPI *PFAST_IO_RELEASE_FOR_CCFLUSH) (
3494 IN struct _FILE_OBJECT *FileObject,
3495 IN struct _DEVICE_OBJECT *DeviceObject);
3496
3497 typedef struct _FAST_IO_DISPATCH {
3498 ULONG SizeOfFastIoDispatch;
3499 PFAST_IO_CHECK_IF_POSSIBLE FastIoCheckIfPossible;
3500 PFAST_IO_READ FastIoRead;
3501 PFAST_IO_WRITE FastIoWrite;
3502 PFAST_IO_QUERY_BASIC_INFO FastIoQueryBasicInfo;
3503 PFAST_IO_QUERY_STANDARD_INFO FastIoQueryStandardInfo;
3504 PFAST_IO_LOCK FastIoLock;
3505 PFAST_IO_UNLOCK_SINGLE FastIoUnlockSingle;
3506 PFAST_IO_UNLOCK_ALL FastIoUnlockAll;
3507 PFAST_IO_UNLOCK_ALL_BY_KEY FastIoUnlockAllByKey;
3508 PFAST_IO_DEVICE_CONTROL FastIoDeviceControl;
3509 PFAST_IO_ACQUIRE_FILE AcquireFileForNtCreateSection;
3510 PFAST_IO_RELEASE_FILE ReleaseFileForNtCreateSection;
3511 PFAST_IO_DETACH_DEVICE FastIoDetachDevice;
3512 PFAST_IO_QUERY_NETWORK_OPEN_INFO FastIoQueryNetworkOpenInfo;
3513 PFAST_IO_ACQUIRE_FOR_MOD_WRITE AcquireForModWrite;
3514 PFAST_IO_MDL_READ MdlRead;
3515 PFAST_IO_MDL_READ_COMPLETE MdlReadComplete;
3516 PFAST_IO_PREPARE_MDL_WRITE PrepareMdlWrite;
3517 PFAST_IO_MDL_WRITE_COMPLETE MdlWriteComplete;
3518 PFAST_IO_READ_COMPRESSED FastIoReadCompressed;
3519 PFAST_IO_WRITE_COMPRESSED FastIoWriteCompressed;
3520 PFAST_IO_MDL_READ_COMPLETE_COMPRESSED MdlReadCompleteCompressed;
3521 PFAST_IO_MDL_WRITE_COMPLETE_COMPRESSED MdlWriteCompleteCompressed;
3522 PFAST_IO_QUERY_OPEN FastIoQueryOpen;
3523 PFAST_IO_RELEASE_FOR_MOD_WRITE ReleaseForModWrite;
3524 PFAST_IO_ACQUIRE_FOR_CCFLUSH AcquireForCcFlush;
3525 PFAST_IO_RELEASE_FOR_CCFLUSH ReleaseForCcFlush;
3526 } FAST_IO_DISPATCH, *PFAST_IO_DISPATCH;
3527
3528 typedef struct _SECTION_OBJECT_POINTERS {
3529 PVOID DataSectionObject;
3530 PVOID SharedCacheMap;
3531 PVOID ImageSectionObject;
3532 } SECTION_OBJECT_POINTERS, *PSECTION_OBJECT_POINTERS;
3533
3534 typedef struct _IO_COMPLETION_CONTEXT {
3535 PVOID Port;
3536 PVOID Key;
3537 } IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT;
3538
3539 /* FILE_OBJECT.Flags */
3540
3541 #define FO_FILE_OPEN 0x00000001
3542 #define FO_SYNCHRONOUS_IO 0x00000002
3543 #define FO_ALERTABLE_IO 0x00000004
3544 #define FO_NO_INTERMEDIATE_BUFFERING 0x00000008
3545 #define FO_WRITE_THROUGH 0x00000010
3546 #define FO_SEQUENTIAL_ONLY 0x00000020
3547 #define FO_CACHE_SUPPORTED 0x00000040
3548 #define FO_NAMED_PIPE 0x00000080
3549 #define FO_STREAM_FILE 0x00000100
3550 #define FO_MAILSLOT 0x00000200
3551 #define FO_GENERATE_AUDIT_ON_CLOSE 0x00000400
3552 #define FO_QUEUE_IRP_TO_THREAD 0x00000400
3553 #define FO_DIRECT_DEVICE_OPEN 0x00000800
3554 #define FO_FILE_MODIFIED 0x00001000
3555 #define FO_FILE_SIZE_CHANGED 0x00002000
3556 #define FO_CLEANUP_COMPLETE 0x00004000
3557 #define FO_TEMPORARY_FILE 0x00008000
3558 #define FO_DELETE_ON_CLOSE 0x00010000
3559 #define FO_OPENED_CASE_SENSITIVE 0x00020000
3560 #define FO_HANDLE_CREATED 0x00040000
3561 #define FO_FILE_FAST_IO_READ 0x00080000
3562 #define FO_RANDOM_ACCESS 0x00100000
3563 #define FO_FILE_OPEN_CANCELLED 0x00200000
3564 #define FO_VOLUME_OPEN 0x00400000
3565 #define FO_REMOTE_ORIGIN 0x01000000
3566 #define FO_DISALLOW_EXCLUSIVE 0x02000000
3567 #define FO_SKIP_COMPLETION_PORT 0x02000000
3568 #define FO_SKIP_SET_EVENT 0x04000000
3569 #define FO_SKIP_SET_FAST_IO 0x08000000
3570
3571 /* VPB.Flags */
3572 #define VPB_MOUNTED 0x0001
3573 #define VPB_LOCKED 0x0002
3574 #define VPB_PERSISTENT 0x0004
3575 #define VPB_REMOVE_PENDING 0x0008
3576 #define VPB_RAW_MOUNT 0x0010
3577 #define VPB_DIRECT_WRITES_ALLOWED 0x0020
3578
3579 /* IRP.Flags */
3580
3581 #define SL_FORCE_ACCESS_CHECK 0x01
3582 #define SL_OPEN_PAGING_FILE 0x02
3583 #define SL_OPEN_TARGET_DIRECTORY 0x04
3584 #define SL_CASE_SENSITIVE 0x80
3585
3586 #define SL_KEY_SPECIFIED 0x01
3587 #define SL_OVERRIDE_VERIFY_VOLUME 0x02
3588 #define SL_WRITE_THROUGH 0x04
3589 #define SL_FT_SEQUENTIAL_WRITE 0x08
3590
3591 #define SL_FAIL_IMMEDIATELY 0x01
3592 #define SL_EXCLUSIVE_LOCK 0x02
3593
3594 #define SL_RESTART_SCAN 0x01
3595 #define SL_RETURN_SINGLE_ENTRY 0x02
3596 #define SL_INDEX_SPECIFIED 0x04
3597
3598 #define SL_WATCH_TREE 0x01
3599
3600 #define SL_ALLOW_RAW_MOUNT 0x01
3601
3602 #define CTL_CODE(DeviceType, Function, Method, Access)( \
3603 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
3604
3605 #define DEVICE_TYPE_FROM_CTL_CODE(ctl) (((ULONG) (ctl & 0xffff0000)) >> 16)
3606
3607 #define IRP_NOCACHE 0x00000001
3608 #define IRP_PAGING_IO 0x00000002
3609 #define IRP_MOUNT_COMPLETION 0x00000002
3610 #define IRP_SYNCHRONOUS_API 0x00000004
3611 #define IRP_ASSOCIATED_IRP 0x00000008
3612 #define IRP_BUFFERED_IO 0x00000010
3613 #define IRP_DEALLOCATE_BUFFER 0x00000020
3614 #define IRP_INPUT_OPERATION 0x00000040
3615 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
3616 #define IRP_CREATE_OPERATION 0x00000080
3617 #define IRP_READ_OPERATION 0x00000100
3618 #define IRP_WRITE_OPERATION 0x00000200
3619 #define IRP_CLOSE_OPERATION 0x00000400
3620 #define IRP_DEFER_IO_COMPLETION 0x00000800
3621 #define IRP_OB_QUERY_NAME 0x00001000
3622 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
3623
3624 #define IRP_QUOTA_CHARGED 0x01
3625 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
3626 #define IRP_ALLOCATED_FIXED_SIZE 0x04
3627 #define IRP_LOOKASIDE_ALLOCATION 0x08
3628
3629 /*
3630 ** IRP function codes
3631 */
3632
3633 #define IRP_MJ_CREATE 0x00
3634 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
3635 #define IRP_MJ_CLOSE 0x02
3636 #define IRP_MJ_READ 0x03
3637 #define IRP_MJ_WRITE 0x04
3638 #define IRP_MJ_QUERY_INFORMATION 0x05
3639 #define IRP_MJ_SET_INFORMATION 0x06
3640 #define IRP_MJ_QUERY_EA 0x07
3641 #define IRP_MJ_SET_EA 0x08
3642 #define IRP_MJ_FLUSH_BUFFERS 0x09
3643 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
3644 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
3645 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
3646 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
3647 #define IRP_MJ_DEVICE_CONTROL 0x0e
3648 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
3649 #define IRP_MJ_SCSI 0x0f
3650 #define IRP_MJ_SHUTDOWN 0x10
3651 #define IRP_MJ_LOCK_CONTROL 0x11
3652 #define IRP_MJ_CLEANUP 0x12
3653 #define IRP_MJ_CREATE_MAILSLOT 0x13
3654 #define IRP_MJ_QUERY_SECURITY 0x14
3655 #define IRP_MJ_SET_SECURITY 0x15
3656 #define IRP_MJ_POWER 0x16
3657 #define IRP_MJ_SYSTEM_CONTROL 0x17
3658 #define IRP_MJ_DEVICE_CHANGE 0x18
3659 #define IRP_MJ_QUERY_QUOTA 0x19
3660 #define IRP_MJ_SET_QUOTA 0x1a
3661 #define IRP_MJ_PNP 0x1b
3662 #define IRP_MJ_PNP_POWER 0x1b
3663 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
3664
3665 #define IRP_MN_SCSI_CLASS 0x01
3666
3667 #define IRP_MN_START_DEVICE 0x00
3668 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
3669 #define IRP_MN_REMOVE_DEVICE 0x02
3670 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
3671 #define IRP_MN_STOP_DEVICE 0x04
3672 #define IRP_MN_QUERY_STOP_DEVICE 0x05
3673 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
3674
3675 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
3676 #define IRP_MN_QUERY_INTERFACE 0x08
3677 #define IRP_MN_QUERY_CAPABILITIES 0x09
3678 #define IRP_MN_QUERY_RESOURCES 0x0A
3679 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
3680 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
3681 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
3682
3683 #define IRP_MN_READ_CONFIG 0x0F
3684 #define IRP_MN_WRITE_CONFIG 0x10
3685 #define IRP_MN_EJECT 0x11
3686 #define IRP_MN_SET_LOCK 0x12
3687 #define IRP_MN_QUERY_ID 0x13
3688 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
3689 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
3690 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
3691 #define IRP_MN_SURPRISE_REMOVAL 0x17
3692
3693 #define IRP_MN_WAIT_WAKE 0x00
3694 #define IRP_MN_POWER_SEQUENCE 0x01
3695 #define IRP_MN_SET_POWER 0x02
3696 #define IRP_MN_QUERY_POWER 0x03
3697
3698 #define IRP_MN_QUERY_ALL_DATA 0x00
3699 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
3700 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
3701 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
3702 #define IRP_MN_ENABLE_EVENTS 0x04
3703 #define IRP_MN_DISABLE_EVENTS 0x05
3704 #define IRP_MN_ENABLE_COLLECTION 0x06
3705 #define IRP_MN_DISABLE_COLLECTION 0x07
3706 #define IRP_MN_REGINFO 0x08
3707 #define IRP_MN_EXECUTE_METHOD 0x09
3708
3709 #define IRP_MN_REGINFO_EX 0x0b
3710
3711 typedef struct _FILE_OBJECT
3712 {
3713 CSHORT Type;
3714 CSHORT Size;
3715 PDEVICE_OBJECT DeviceObject;
3716 PVPB Vpb;
3717 PVOID FsContext;
3718 PVOID FsContext2;
3719 PSECTION_OBJECT_POINTERS SectionObjectPointer;
3720 PVOID PrivateCacheMap;
3721 NTSTATUS FinalStatus;
3722 struct _FILE_OBJECT *RelatedFileObject;
3723 BOOLEAN LockOperation;
3724 BOOLEAN DeletePending;
3725 BOOLEAN ReadAccess;
3726 BOOLEAN WriteAccess;
3727 BOOLEAN DeleteAccess;
3728 BOOLEAN SharedRead;
3729 BOOLEAN SharedWrite;
3730 BOOLEAN SharedDelete;
3731 ULONG Flags;
3732 UNICODE_STRING FileName;
3733 LARGE_INTEGER CurrentByteOffset;
3734 volatile ULONG Waiters;
3735 volatile ULONG Busy;
3736 PVOID LastLock;
3737 KEVENT Lock;
3738 KEVENT Event;
3739 volatile PIO_COMPLETION_CONTEXT CompletionContext;
3740 KSPIN_LOCK IrpListLock;
3741 LIST_ENTRY IrpList;
3742 volatile PVOID FileObjectExtension;
3743 } FILE_OBJECT;
3744 typedef struct _FILE_OBJECT *PFILE_OBJECT;
3745
3746 typedef struct _IO_ERROR_LOG_PACKET {
3747 UCHAR MajorFunctionCode;
3748 UCHAR RetryCount;
3749 USHORT DumpDataSize;
3750 USHORT NumberOfStrings;
3751 USHORT StringOffset;
3752 USHORT EventCategory;
3753 NTSTATUS ErrorCode;
3754 ULONG UniqueErrorValue;
3755 NTSTATUS FinalStatus;
3756 ULONG SequenceNumber;
3757 ULONG IoControlCode;
3758 LARGE_INTEGER DeviceOffset;
3759 ULONG DumpData[1];
3760 } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
3761
3762 typedef struct _IO_ERROR_LOG_MESSAGE {
3763 USHORT Type;
3764 USHORT Size;
3765 USHORT DriverNameLength;
3766 LARGE_INTEGER TimeStamp;
3767 ULONG DriverNameOffset;
3768 IO_ERROR_LOG_PACKET EntryData;
3769 } IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
3770
3771 #define ERROR_LOG_LIMIT_SIZE 240
3772 #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
3773 sizeof(IO_ERROR_LOG_PACKET) + \
3774 (sizeof(WCHAR) * 40))
3775 #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
3776 (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
3777 #define IO_ERROR_LOG_MESSAGE_LENGTH \
3778 ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
3779 ERROR_LOG_MESSAGE_LIMIT_SIZE : \
3780 PORT_MAXIMUM_MESSAGE_LENGTH)
3781 #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
3782 IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
3783
3784 typedef enum _DMA_WIDTH {
3785 Width8Bits,
3786 Width16Bits,
3787 Width32Bits,
3788 MaximumDmaWidth
3789 } DMA_WIDTH, *PDMA_WIDTH;
3790
3791 typedef enum _DMA_SPEED {
3792 Compatible,
3793 TypeA,
3794 TypeB,
3795 TypeC,
3796 TypeF,
3797 MaximumDmaSpeed
3798 } DMA_SPEED, *PDMA_SPEED;
3799
3800 /* DEVICE_DESCRIPTION.Version */
3801
3802 #define DEVICE_DESCRIPTION_VERSION 0x0000
3803 #define DEVICE_DESCRIPTION_VERSION1 0x0001
3804 #define DEVICE_DESCRIPTION_VERSION2 0x0002
3805
3806 typedef struct _DEVICE_DESCRIPTION {
3807 ULONG Version;
3808 BOOLEAN Master;
3809 BOOLEAN ScatterGather;
3810 BOOLEAN DemandMode;
3811 BOOLEAN AutoInitialize;
3812 BOOLEAN Dma32BitAddresses;
3813 BOOLEAN IgnoreCount;
3814 BOOLEAN Reserved1;
3815 BOOLEAN Dma64BitAddresses;
3816 ULONG BusNumber;
3817 ULONG DmaChannel;
3818 INTERFACE_TYPE InterfaceType;
3819 DMA_WIDTH DmaWidth;
3820 DMA_SPEED DmaSpeed;
3821 ULONG MaximumLength;
3822 ULONG DmaPort;
3823 } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
3824
3825 typedef enum _DEVICE_RELATION_TYPE {
3826 BusRelations,
3827 EjectionRelations,
3828 PowerRelations,
3829 RemovalRelations,
3830 TargetDeviceRelation,
3831 SingleBusRelations,
3832 TransportRelations
3833 } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
3834
3835 typedef struct _DEVICE_RELATIONS {
3836 ULONG Count;
3837 PDEVICE_OBJECT Objects[1];
3838 } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
3839
3840 typedef struct _DEVOBJ_EXTENSION
3841 {
3842 CSHORT Type;
3843 USHORT Size;
3844 PDEVICE_OBJECT DeviceObject;
3845 } DEVOBJ_EXTENSION, *PDEVOBJ_EXTENSION;
3846
3847 typedef struct _SCATTER_GATHER_ELEMENT {
3848 PHYSICAL_ADDRESS Address;
3849 ULONG Length;
3850 ULONG_PTR Reserved;
3851 } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
3852
3853 #if defined(_MSC_EXTENSIONS)
3854
3855 #if _MSC_VER >= 1200
3856 #pragma warning(push)
3857 #endif
3858 #pragma warning(disable:4200)
3859 typedef struct _SCATTER_GATHER_LIST {
3860 ULONG NumberOfElements;
3861 ULONG_PTR Reserved;
3862 SCATTER_GATHER_ELEMENT Elements[1];
3863 } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
3864
3865 #if _MSC_VER >= 1200
3866 #pragma warning(pop)
3867 #else
3868 #pragma warning(default:4200)
3869 #endif
3870
3871 #else
3872
3873 struct _SCATTER_GATHER_LIST;
3874 typedef struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
3875
3876 #endif
3877
3878 typedef NTSTATUS
3879 (DDKAPI DRIVER_ADD_DEVICE)(
3880 IN struct _DRIVER_OBJECT *DriverObject,
3881 IN struct _DEVICE_OBJECT *PhysicalDeviceObject);
3882 typedef DRIVER_ADD_DEVICE *PDRIVER_ADD_DEVICE;
3883
3884 typedef struct _DRIVER_EXTENSION {
3885 struct _DRIVER_OBJECT *DriverObject;
3886 PDRIVER_ADD_DEVICE AddDevice;
3887 ULONG Count;
3888 UNICODE_STRING ServiceKeyName;
3889 } DRIVER_EXTENSION, *PDRIVER_EXTENSION;
3890
3891 #define DRVO_UNLOAD_INVOKED 0x00000001
3892 #define DRVO_LEGACY_DRIVER 0x00000002