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