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