d0e135e38539ade5279224ea904cf27475c0a5f3
[reactos.git] / include / ddk / wdm.h
1 #ifndef _WDMDDK_
2 #define _WDMDDK_
3
4 /* Helper macro to enable gcc's extension. */
5 #ifndef __GNU_EXTENSION
6 #ifdef __GNUC__
7 #define __GNU_EXTENSION __extension__
8 #else
9 #define __GNU_EXTENSION
10 #endif
11 #endif
12
13 //
14 // Dependencies
15 //
16 #define NT_INCLUDED
17 #include <excpt.h>
18 #include <ntdef.h>
19 #include <ntstatus.h>
20
21 #ifndef GUID_DEFINED
22 #include <guiddef.h>
23 #endif /* GUID_DEFINED */
24
25 #include "intrin.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define NTKERNELAPI DECLSPEC_IMPORT
32
33 #ifdef _WIN64
34 #define PORT_MAXIMUM_MESSAGE_LENGTH 512
35 #else
36 #define PORT_MAXIMUM_MESSAGE_LENGTH 256
37 #endif
38
39
40 #if defined(_MSC_VER)
41
42 //
43 // Indicate if #pragma alloc_text() is supported
44 //
45 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)
46 #define ALLOC_PRAGMA 1
47 #endif
48
49 //
50 // Indicate if #pragma data_seg() is supported
51 //
52 #if defined(_M_IX86) || defined(_M_AMD64)
53 #define ALLOC_DATA_PRAGMA 1
54 #endif
55
56 #endif
57
58
59 /*
60 * Alignment Macros
61 */
62 #define ALIGN_DOWN(s, t) \
63 ((ULONG)(s) & ~(sizeof(t) - 1))
64
65 #define ALIGN_UP(s, t) \
66 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
67
68 #define ALIGN_DOWN_POINTER(p, t) \
69 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
70
71 #define ALIGN_UP_POINTER(p, t) \
72 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
73
74 /*
75 * GUID Comparison
76 */
77
78 #ifndef __IID_ALIGNED__
79 #define __IID_ALIGNED__
80 #ifdef __cplusplus
81 inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
82 {
83 return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
84 }
85 #else
86 #define IsEqualGUIDAligned(guid1, guid2) \
87 ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
88 #endif
89 #endif
90
91 #if defined(_WIN64)
92 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
93 #else
94 #define POINTER_ALIGNMENT
95 #endif
96
97 /*
98 ** Forward declarations
99 */
100
101 struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _IRP;
102 struct _MDL;
103 struct _KAPC;
104 struct _KDPC;
105 struct _FILE_OBJECT;
106 struct _DMA_ADAPTER;
107 struct _DEVICE_OBJECT;
108 struct _DRIVER_OBJECT;
109 struct _IO_STATUS_BLOCK;
110 struct _DEVICE_DESCRIPTION;
111 struct _SCATTER_GATHER_LIST;
112 struct _DRIVE_LAYOUT_INFORMATION;
113
114 typedef PVOID PSID;
115
116 /*
117 ** Simple structures
118 */
119
120 typedef UCHAR KIRQL, *PKIRQL;
121
122 typedef enum _MODE {
123 KernelMode,
124 UserMode,
125 MaximumMode
126 } MODE;
127
128 /* Constants */
129 #define NtCurrentProcess() ( (HANDLE)(LONG_PTR) -1 )
130 #define ZwCurrentProcess() NtCurrentProcess()
131 #define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
132 #define ZwCurrentThread() NtCurrentThread()
133
134 #if (_M_IX86)
135 #define KIP0PCRADDRESS 0xffdff000
136 #endif
137
138 #if defined(_WIN64)
139 #define MAXIMUM_PROCESSORS 64
140 #else
141 #define MAXIMUM_PROCESSORS 32
142 #endif
143
144 #define MAXIMUM_WAIT_OBJECTS 64
145
146 #define EX_RUNDOWN_ACTIVE 0x1
147 #define EX_RUNDOWN_COUNT_SHIFT 0x1
148 #define EX_RUNDOWN_COUNT_INC (1 << EX_RUNDOWN_COUNT_SHIFT)
149
150 #define METHOD_BUFFERED 0
151 #define METHOD_IN_DIRECT 1
152 #define METHOD_OUT_DIRECT 2
153 #define METHOD_NEITHER 3
154
155 #define LOW_PRIORITY 0
156 #define LOW_REALTIME_PRIORITY 16
157 #define HIGH_PRIORITY 31
158 #define MAXIMUM_PRIORITY 32
159
160 #define MAXIMUM_SUSPEND_COUNT MAXCHAR
161
162 #define MAXIMUM_FILENAME_LENGTH 256
163
164 #define FILE_SUPERSEDED 0x00000000
165 #define FILE_OPENED 0x00000001
166 #define FILE_CREATED 0x00000002
167 #define FILE_OVERWRITTEN 0x00000003
168 #define FILE_EXISTS 0x00000004
169 #define FILE_DOES_NOT_EXIST 0x00000005
170
171 #define FILE_USE_FILE_POINTER_POSITION 0xfffffffe
172 #define FILE_WRITE_TO_END_OF_FILE 0xffffffff
173
174 /* also in winnt.h */
175 #define FILE_LIST_DIRECTORY 0x00000001
176 #define FILE_READ_DATA 0x00000001
177 #define FILE_ADD_FILE 0x00000002
178 #define FILE_WRITE_DATA 0x00000002
179 #define FILE_ADD_SUBDIRECTORY 0x00000004
180 #define FILE_APPEND_DATA 0x00000004
181 #define FILE_CREATE_PIPE_INSTANCE 0x00000004
182 #define FILE_READ_EA 0x00000008
183 #define FILE_WRITE_EA 0x00000010
184 #define FILE_EXECUTE 0x00000020
185 #define FILE_TRAVERSE 0x00000020
186 #define FILE_DELETE_CHILD 0x00000040
187 #define FILE_READ_ATTRIBUTES 0x00000080
188 #define FILE_WRITE_ATTRIBUTES 0x00000100
189
190 #define FILE_SHARE_READ 0x00000001
191 #define FILE_SHARE_WRITE 0x00000002
192 #define FILE_SHARE_DELETE 0x00000004
193 #define FILE_SHARE_VALID_FLAGS 0x00000007
194
195 #define FILE_ATTRIBUTE_READONLY 0x00000001
196 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
197 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
198 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
199 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
200 #define FILE_ATTRIBUTE_DEVICE 0x00000040
201 #define FILE_ATTRIBUTE_NORMAL 0x00000080
202 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
203 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
204 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
205 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
206 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
207 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
208 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
209
210 #define FILE_ATTRIBUTE_VALID_FLAGS 0x00007fb7
211 #define FILE_ATTRIBUTE_VALID_SET_FLAGS 0x000031a7
212
213 #define FILE_VALID_OPTION_FLAGS 0x00ffffff
214 #define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032
215 #define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032
216 #define FILE_VALID_SET_FLAGS 0x00000036
217
218 #define FILE_SUPERSEDE 0x00000000
219 #define FILE_OPEN 0x00000001
220 #define FILE_CREATE 0x00000002
221 #define FILE_OPEN_IF 0x00000003
222 #define FILE_OVERWRITE 0x00000004
223 #define FILE_OVERWRITE_IF 0x00000005
224 #define FILE_MAXIMUM_DISPOSITION 0x00000005
225
226 #define FILE_DIRECTORY_FILE 0x00000001
227 #define FILE_WRITE_THROUGH 0x00000002
228 #define FILE_SEQUENTIAL_ONLY 0x00000004
229 #define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
230 #define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
231 #define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
232 #define FILE_NON_DIRECTORY_FILE 0x00000040
233 #define FILE_CREATE_TREE_CONNECTION 0x00000080
234 #define FILE_COMPLETE_IF_OPLOCKED 0x00000100
235 #define FILE_NO_EA_KNOWLEDGE 0x00000200
236 #define FILE_OPEN_REMOTE_INSTANCE 0x00000400
237 #define FILE_RANDOM_ACCESS 0x00000800
238 #define FILE_DELETE_ON_CLOSE 0x00001000
239 #define FILE_OPEN_BY_FILE_ID 0x00002000
240 #define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
241 #define FILE_NO_COMPRESSION 0x00008000
242 #define FILE_RESERVE_OPFILTER 0x00100000
243 #define FILE_OPEN_REPARSE_POINT 0x00200000
244 #define FILE_OPEN_NO_RECALL 0x00400000
245 #define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
246
247 #define FILE_ANY_ACCESS 0x00000000
248 #define FILE_SPECIAL_ACCESS FILE_ANY_ACCESS
249 #define FILE_READ_ACCESS 0x00000001
250 #define FILE_WRITE_ACCESS 0x00000002
251
252 #define FILE_ALL_ACCESS \
253 (STANDARD_RIGHTS_REQUIRED | \
254 SYNCHRONIZE | \
255 0x1FF)
256
257 #define FILE_GENERIC_EXECUTE \
258 (STANDARD_RIGHTS_EXECUTE | \
259 FILE_READ_ATTRIBUTES | \
260 FILE_EXECUTE | \
261 SYNCHRONIZE)
262
263 #define FILE_GENERIC_READ \
264 (STANDARD_RIGHTS_READ | \
265 FILE_READ_DATA | \
266 FILE_READ_ATTRIBUTES | \
267 FILE_READ_EA | \
268 SYNCHRONIZE)
269
270 #define FILE_GENERIC_WRITE \
271 (STANDARD_RIGHTS_WRITE | \
272 FILE_WRITE_DATA | \
273 FILE_WRITE_ATTRIBUTES | \
274 FILE_WRITE_EA | \
275 FILE_APPEND_DATA | \
276 SYNCHRONIZE)
277
278 /* end winnt.h */
279
280 #define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
281
282 #define OBJECT_TYPE_CREATE (0x0001)
283 #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
284
285 #define DIRECTORY_QUERY (0x0001)
286 #define DIRECTORY_TRAVERSE (0x0002)
287 #define DIRECTORY_CREATE_OBJECT (0x0004)
288 #define DIRECTORY_CREATE_SUBDIRECTORY (0x0008)
289 #define DIRECTORY_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0xF)
290
291 #define EVENT_QUERY_STATE (0x0001)
292 #define EVENT_MODIFY_STATE (0x0002)
293 #define EVENT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
294
295 #define SEMAPHORE_QUERY_STATE (0x0001)
296 #define SEMAPHORE_MODIFY_STATE (0x0002)
297 #define SEMAPHORE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3)
298
299 #define FM_LOCK_BIT (0x1)
300 #define FM_LOCK_BIT_V (0x0)
301 #define FM_LOCK_WAITER_WOKEN (0x2)
302 #define FM_LOCK_WAITER_INC (0x4)
303
304 #define PROCESSOR_FEATURE_MAX 64
305
306 typedef enum _ALTERNATIVE_ARCHITECTURE_TYPE
307 {
308 StandardDesign,
309 NEC98x86,
310 EndAlternatives
311 } ALTERNATIVE_ARCHITECTURE_TYPE;
312
313 typedef struct _KSYSTEM_TIME
314 {
315 ULONG LowPart;
316 LONG High1Time;
317 LONG High2Time;
318 } KSYSTEM_TIME, *PKSYSTEM_TIME;
319
320 /*
321 ** IRP function codes
322 */
323
324 #define IRP_MJ_CREATE 0x00
325 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
326 #define IRP_MJ_CLOSE 0x02
327 #define IRP_MJ_READ 0x03
328 #define IRP_MJ_WRITE 0x04
329 #define IRP_MJ_QUERY_INFORMATION 0x05
330 #define IRP_MJ_SET_INFORMATION 0x06
331 #define IRP_MJ_QUERY_EA 0x07
332 #define IRP_MJ_SET_EA 0x08
333 #define IRP_MJ_FLUSH_BUFFERS 0x09
334 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
335 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
336 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
337 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
338 #define IRP_MJ_DEVICE_CONTROL 0x0e
339 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
340 #define IRP_MJ_SCSI 0x0f
341 #define IRP_MJ_SHUTDOWN 0x10
342 #define IRP_MJ_LOCK_CONTROL 0x11
343 #define IRP_MJ_CLEANUP 0x12
344 #define IRP_MJ_CREATE_MAILSLOT 0x13
345 #define IRP_MJ_QUERY_SECURITY 0x14
346 #define IRP_MJ_SET_SECURITY 0x15
347 #define IRP_MJ_POWER 0x16
348 #define IRP_MJ_SYSTEM_CONTROL 0x17
349 #define IRP_MJ_DEVICE_CHANGE 0x18
350 #define IRP_MJ_QUERY_QUOTA 0x19
351 #define IRP_MJ_SET_QUOTA 0x1a
352 #define IRP_MJ_PNP 0x1b
353 #define IRP_MJ_PNP_POWER 0x1b
354 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
355
356 #define IRP_MN_SCSI_CLASS 0x01
357
358 #define IRP_MN_START_DEVICE 0x00
359 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
360 #define IRP_MN_REMOVE_DEVICE 0x02
361 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
362 #define IRP_MN_STOP_DEVICE 0x04
363 #define IRP_MN_QUERY_STOP_DEVICE 0x05
364 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
365
366 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
367 #define IRP_MN_QUERY_INTERFACE 0x08
368 #define IRP_MN_QUERY_CAPABILITIES 0x09
369 #define IRP_MN_QUERY_RESOURCES 0x0A
370 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
371 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
372 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
373
374 #define IRP_MN_READ_CONFIG 0x0F
375 #define IRP_MN_WRITE_CONFIG 0x10
376 #define IRP_MN_EJECT 0x11
377 #define IRP_MN_SET_LOCK 0x12
378 #define IRP_MN_QUERY_ID 0x13
379 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
380 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
381 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
382 #define IRP_MN_SURPRISE_REMOVAL 0x17
383
384 #define IRP_MN_WAIT_WAKE 0x00
385 #define IRP_MN_POWER_SEQUENCE 0x01
386 #define IRP_MN_SET_POWER 0x02
387 #define IRP_MN_QUERY_POWER 0x03
388
389 #define IRP_MN_QUERY_ALL_DATA 0x00
390 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
391 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
392 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
393 #define IRP_MN_ENABLE_EVENTS 0x04
394 #define IRP_MN_DISABLE_EVENTS 0x05
395 #define IRP_MN_ENABLE_COLLECTION 0x06
396 #define IRP_MN_DISABLE_COLLECTION 0x07
397 #define IRP_MN_REGINFO 0x08
398 #define IRP_MN_EXECUTE_METHOD 0x09
399
400 #define IRP_MN_REGINFO_EX 0x0b
401
402 typedef enum _IO_PAGING_PRIORITY {
403 IoPagingPriorityInvalid,
404 IoPagingPriorityNormal,
405 IoPagingPriorityHigh,
406 IoPagingPriorityReserved1,
407 IoPagingPriorityReserved2
408 } IO_PAGING_PRIORITY;
409
410 typedef enum _IO_ALLOCATION_ACTION {
411 KeepObject = 1,
412 DeallocateObject,
413 DeallocateObjectKeepRegisters
414 } IO_ALLOCATION_ACTION, *PIO_ALLOCATION_ACTION;
415
416 typedef IO_ALLOCATION_ACTION
417 (DDKAPI *PDRIVER_CONTROL)(
418 IN struct _DEVICE_OBJECT *DeviceObject,
419 IN struct _IRP *Irp,
420 IN PVOID MapRegisterBase,
421 IN PVOID Context);
422
423 typedef VOID
424 (DDKAPI *PDRIVER_LIST_CONTROL)(
425 IN struct _DEVICE_OBJECT *DeviceObject,
426 IN struct _IRP *Irp,
427 IN struct _SCATTER_GATHER_LIST *ScatterGather,
428 IN PVOID Context);
429
430 typedef NTSTATUS
431 (DDKAPI DRIVER_ADD_DEVICE)(
432 IN struct _DRIVER_OBJECT *DriverObject,
433 IN struct _DEVICE_OBJECT *PhysicalDeviceObject);
434 typedef DRIVER_ADD_DEVICE *PDRIVER_ADD_DEVICE;
435
436 typedef NTSTATUS
437 (DDKAPI IO_COMPLETION_ROUTINE)(
438 IN struct _DEVICE_OBJECT *DeviceObject,
439 IN struct _IRP *Irp,
440 IN PVOID Context);
441 typedef IO_COMPLETION_ROUTINE *PIO_COMPLETION_ROUTINE;
442
443 typedef VOID
444 (DDKAPI DRIVER_CANCEL)(
445 IN struct _DEVICE_OBJECT *DeviceObject,
446 IN struct _IRP *Irp);
447 typedef DRIVER_CANCEL *PDRIVER_CANCEL;
448
449 typedef VOID
450 (DDKAPI *PKDEFERRED_ROUTINE)(
451 IN struct _KDPC *Dpc,
452 IN PVOID DeferredContext,
453 IN PVOID SystemArgument1,
454 IN PVOID SystemArgument2);
455
456 typedef NTSTATUS
457 (DDKAPI DRIVER_DISPATCH)(
458 IN struct _DEVICE_OBJECT *DeviceObject,
459 IN struct _IRP *Irp);
460 typedef DRIVER_DISPATCH *PDRIVER_DISPATCH;
461
462 typedef VOID
463 (DDKAPI *PIO_DPC_ROUTINE)(
464 IN struct _KDPC *Dpc,
465 IN struct _DEVICE_OBJECT *DeviceObject,
466 IN struct _IRP *Irp,
467 IN PVOID Context);
468
469 typedef NTSTATUS
470 (DDKAPI *PMM_DLL_INITIALIZE)(
471 IN PUNICODE_STRING RegistryPath);
472
473 typedef NTSTATUS
474 (DDKAPI *PMM_DLL_UNLOAD)(
475 VOID);
476
477 typedef NTSTATUS
478 (DDKAPI DRIVER_INITIALIZE)(
479 IN struct _DRIVER_OBJECT *DriverObject,
480 IN PUNICODE_STRING RegistryPath);
481 typedef DRIVER_INITIALIZE *PDRIVER_INITIALIZE;
482
483 typedef BOOLEAN
484 (DDKAPI KSERVICE_ROUTINE)(
485 IN struct _KINTERRUPT *Interrupt,
486 IN PVOID ServiceContext);
487 typedef KSERVICE_ROUTINE *PKSERVICE_ROUTINE;
488
489 typedef VOID
490 (DDKAPI *PIO_TIMER_ROUTINE)(
491 IN struct _DEVICE_OBJECT *DeviceObject,
492 IN PVOID Context);
493
494 typedef VOID
495 (DDKAPI DRIVER_STARTIO)(
496 IN struct _DEVICE_OBJECT *DeviceObject,
497 IN struct _IRP *Irp);
498 typedef DRIVER_STARTIO *PDRIVER_STARTIO;
499
500 typedef BOOLEAN
501 (DDKAPI *PKSYNCHRONIZE_ROUTINE)(
502 IN PVOID SynchronizeContext);
503
504 typedef VOID
505 (DDKAPI DRIVER_UNLOAD)(
506 IN struct _DRIVER_OBJECT *DriverObject);
507 typedef DRIVER_UNLOAD *PDRIVER_UNLOAD;
508
509 /*
510 ** Plug and Play structures
511 */
512
513 typedef VOID
514 (DDKAPI *PINTERFACE_REFERENCE)(
515 PVOID Context);
516
517 typedef VOID
518 (DDKAPI *PINTERFACE_DEREFERENCE)(
519 PVOID Context);
520
521 typedef BOOLEAN
522 (DDKAPI *PTRANSLATE_BUS_ADDRESS)(
523 IN PVOID Context,
524 IN PHYSICAL_ADDRESS BusAddress,
525 IN ULONG Length,
526 IN OUT PULONG AddressSpace,
527 OUT PPHYSICAL_ADDRESS TranslatedAddress);
528
529 typedef struct _DMA_ADAPTER*
530 (DDKAPI *PGET_DMA_ADAPTER)(
531 IN PVOID Context,
532 IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
533 OUT PULONG NumberOfMapRegisters);
534
535 typedef ULONG
536 (DDKAPI *PGET_SET_DEVICE_DATA)(
537 IN PVOID Context,
538 IN ULONG DataType,
539 IN PVOID Buffer,
540 IN ULONG Offset,
541 IN ULONG Length);
542
543 /* PCI_DEVICE_PRESENCE_PARAMETERS.Flags */
544 #define PCI_USE_SUBSYSTEM_IDS 0x00000001
545 #define PCI_USE_REVISION 0x00000002
546 #define PCI_USE_VENDEV_IDS 0x00000004
547 #define PCI_USE_CLASS_SUBCLASS 0x00000008
548 #define PCI_USE_PROGIF 0x00000010
549 #define PCI_USE_LOCAL_BUS 0x00000020
550 #define PCI_USE_LOCAL_DEVICE 0x00000040
551
552 typedef struct _PCI_DEVICE_PRESENCE_PARAMETERS {
553 ULONG Size;
554 ULONG Flags;
555 USHORT VendorID;
556 USHORT DeviceID;
557 UCHAR RevisionID;
558 USHORT SubVendorID;
559 USHORT SubSystemID;
560 UCHAR BaseClass;
561 UCHAR SubClass;
562 UCHAR ProgIf;
563 } PCI_DEVICE_PRESENCE_PARAMETERS, *PPCI_DEVICE_PRESENCE_PARAMETERS;
564
565 typedef BOOLEAN
566 (DDKAPI *PPCI_IS_DEVICE_PRESENT)(
567 IN USHORT VendorID,
568 IN USHORT DeviceID,
569 IN UCHAR RevisionID,
570 IN USHORT SubVendorID,
571 IN USHORT SubSystemID,
572 IN ULONG Flags);
573
574 typedef BOOLEAN
575 (DDKAPI *PPCI_IS_DEVICE_PRESENT_EX)(
576 IN PVOID Context,
577 IN PPCI_DEVICE_PRESENCE_PARAMETERS Parameters);
578
579 typedef union _POWER_STATE {
580 SYSTEM_POWER_STATE SystemState;
581 DEVICE_POWER_STATE DeviceState;
582 } POWER_STATE, *PPOWER_STATE;
583
584 typedef enum _POWER_STATE_TYPE {
585 SystemPowerState = 0,
586 DevicePowerState
587 } POWER_STATE_TYPE, *PPOWER_STATE_TYPE;
588
589 typedef struct _BUS_INTERFACE_STANDARD {
590 USHORT Size;
591 USHORT Version;
592 PVOID Context;
593 PINTERFACE_REFERENCE InterfaceReference;
594 PINTERFACE_DEREFERENCE InterfaceDereference;
595 PTRANSLATE_BUS_ADDRESS TranslateBusAddress;
596 PGET_DMA_ADAPTER GetDmaAdapter;
597 PGET_SET_DEVICE_DATA SetBusData;
598 PGET_SET_DEVICE_DATA GetBusData;
599 } BUS_INTERFACE_STANDARD, *PBUS_INTERFACE_STANDARD;
600
601 typedef struct _PCI_DEVICE_PRESENT_INTERFACE {
602 USHORT Size;
603 USHORT Version;
604 PVOID Context;
605 PINTERFACE_REFERENCE InterfaceReference;
606 PINTERFACE_DEREFERENCE InterfaceDereference;
607 PPCI_IS_DEVICE_PRESENT IsDevicePresent;
608 PPCI_IS_DEVICE_PRESENT_EX IsDevicePresentEx;
609 } PCI_DEVICE_PRESENT_INTERFACE, *PPCI_DEVICE_PRESENT_INTERFACE;
610
611 typedef struct _DEVICE_CAPABILITIES {
612 USHORT Size;
613 USHORT Version;
614 ULONG DeviceD1 : 1;
615 ULONG DeviceD2 : 1;
616 ULONG LockSupported : 1;
617 ULONG EjectSupported : 1;
618 ULONG Removable : 1;
619 ULONG DockDevice : 1;
620 ULONG UniqueID : 1;
621 ULONG SilentInstall : 1;
622 ULONG RawDeviceOK : 1;
623 ULONG SurpriseRemovalOK : 1;
624 ULONG WakeFromD0 : 1;
625 ULONG WakeFromD1 : 1;
626 ULONG WakeFromD2 : 1;
627 ULONG WakeFromD3 : 1;
628 ULONG HardwareDisabled : 1;
629 ULONG NonDynamic : 1;
630 ULONG WarmEjectSupported : 1;
631 ULONG NoDisplayInUI : 1;
632 ULONG Reserved : 14;
633 ULONG Address;
634 ULONG UINumber;
635 DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
636 SYSTEM_POWER_STATE SystemWake;
637 DEVICE_POWER_STATE DeviceWake;
638 ULONG D1Latency;
639 ULONG D2Latency;
640 ULONG D3Latency;
641 } DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;
642
643 typedef struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION {
644 USHORT Version;
645 USHORT Size;
646 GUID Event;
647 GUID InterfaceClassGuid;
648 PUNICODE_STRING SymbolicLinkName;
649 } DEVICE_INTERFACE_CHANGE_NOTIFICATION, *PDEVICE_INTERFACE_CHANGE_NOTIFICATION;
650
651 typedef struct _HWPROFILE_CHANGE_NOTIFICATION {
652 USHORT Version;
653 USHORT Size;
654 GUID Event;
655 } HWPROFILE_CHANGE_NOTIFICATION, *PHWPROFILE_CHANGE_NOTIFICATION;
656
657 #undef INTERFACE
658
659 typedef struct _INTERFACE {
660 USHORT Size;
661 USHORT Version;
662 PVOID Context;
663 PINTERFACE_REFERENCE InterfaceReference;
664 PINTERFACE_DEREFERENCE InterfaceDereference;
665 } INTERFACE, *PINTERFACE;
666
667 typedef struct _PLUGPLAY_NOTIFICATION_HEADER {
668 USHORT Version;
669 USHORT Size;
670 GUID Event;
671 } PLUGPLAY_NOTIFICATION_HEADER, *PPLUGPLAY_NOTIFICATION_HEADER;
672
673 typedef ULONG PNP_DEVICE_STATE, *PPNP_DEVICE_STATE;
674
675 /* PNP_DEVICE_STATE */
676
677 #define PNP_DEVICE_DISABLED 0x00000001
678 #define PNP_DEVICE_DONT_DISPLAY_IN_UI 0x00000002
679 #define PNP_DEVICE_FAILED 0x00000004
680 #define PNP_DEVICE_REMOVED 0x00000008
681 #define PNP_DEVICE_RESOURCE_REQUIREMENTS_CHANGED 0x00000010
682 #define PNP_DEVICE_NOT_DISABLEABLE 0x00000020
683
684 typedef struct _TARGET_DEVICE_CUSTOM_NOTIFICATION {
685 USHORT Version;
686 USHORT Size;
687 GUID Event;
688 struct _FILE_OBJECT *FileObject;
689 LONG NameBufferOffset;
690 UCHAR CustomDataBuffer[1];
691 } TARGET_DEVICE_CUSTOM_NOTIFICATION, *PTARGET_DEVICE_CUSTOM_NOTIFICATION;
692
693 typedef struct _TARGET_DEVICE_REMOVAL_NOTIFICATION {
694 USHORT Version;
695 USHORT Size;
696 GUID Event;
697 struct _FILE_OBJECT *FileObject;
698 } TARGET_DEVICE_REMOVAL_NOTIFICATION, *PTARGET_DEVICE_REMOVAL_NOTIFICATION;
699
700 typedef enum _DEVICE_USAGE_NOTIFICATION_TYPE {
701 DeviceUsageTypeUndefined,
702 DeviceUsageTypePaging,
703 DeviceUsageTypeHibernation,
704 DeviceUsageTypeDumpFile
705 } DEVICE_USAGE_NOTIFICATION_TYPE;
706
707 typedef struct _POWER_SEQUENCE {
708 ULONG SequenceD1;
709 ULONG SequenceD2;
710 ULONG SequenceD3;
711 } POWER_SEQUENCE, *PPOWER_SEQUENCE;
712
713 typedef enum {
714 DevicePropertyDeviceDescription = 0x0 | __string_type,
715 DevicePropertyHardwareID = 0x1 | __multiString_type,
716 DevicePropertyCompatibleIDs = 0x2 | __multiString_type,
717 DevicePropertyBootConfiguration = 0x3,
718 DevicePropertyBootConfigurationTranslated = 0x4,
719 DevicePropertyClassName = 0x5 | __string_type,
720 DevicePropertyClassGuid = 0x6 | __string_type,
721 DevicePropertyDriverKeyName = 0x7 | __string_type,
722 DevicePropertyManufacturer = 0x8 | __string_type,
723 DevicePropertyFriendlyName = 0x9 | __string_type,
724 DevicePropertyLocationInformation = 0xa | __string_type,
725 DevicePropertyPhysicalDeviceObjectName = 0xb | __string_type,
726 DevicePropertyBusTypeGuid = 0xc | __guid_type,
727 DevicePropertyLegacyBusType = 0xd,
728 DevicePropertyBusNumber = 0xe,
729 DevicePropertyEnumeratorName = 0xf | __string_type,
730 DevicePropertyAddress = 0x10,
731 DevicePropertyUINumber = 0x11,
732 DevicePropertyInstallState = 0x12,
733 DevicePropertyRemovalPolicy = 0x13,
734 DevicePropertyResourceRequirements = 0x14,
735 DevicePropertyAllocatedResources = 0x15,
736 DevicePropertyContainerID = 0x16 | __string_type
737 } DEVICE_REGISTRY_PROPERTY;
738
739 typedef enum _IO_NOTIFICATION_EVENT_CATEGORY {
740 EventCategoryReserved,
741 EventCategoryHardwareProfileChange,
742 EventCategoryDeviceInterfaceChange,
743 EventCategoryTargetDeviceChange
744 } IO_NOTIFICATION_EVENT_CATEGORY;
745
746 #define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES 0x00000001
747
748 typedef NTSTATUS
749 (DDKAPI *PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)(
750 IN PVOID NotificationStructure,
751 IN PVOID Context);
752
753 typedef VOID
754 (DDKAPI *PDEVICE_CHANGE_COMPLETE_CALLBACK)(
755 IN PVOID Context);
756
757 /*
758 ** System structures
759 */
760
761 #define SYMBOLIC_LINK_QUERY 0x0001
762 #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)
763
764 /* also in winnt,h */
765 #define DUPLICATE_CLOSE_SOURCE 0x00000001
766 #define DUPLICATE_SAME_ACCESS 0x00000002
767 #define DUPLICATE_SAME_ATTRIBUTES 0x00000004
768 /* end winnt.h */
769
770 typedef struct _OBJECT_NAME_INFORMATION {
771 UNICODE_STRING Name;
772 } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION;
773
774 typedef struct _IO_STATUS_BLOCK {
775 _ANONYMOUS_UNION union {
776 NTSTATUS Status;
777 PVOID Pointer;
778 } DUMMYUNIONNAME;
779 ULONG_PTR Information;
780 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
781
782 typedef VOID
783 (DDKAPI *PIO_APC_ROUTINE)(
784 IN PVOID ApcContext,
785 IN PIO_STATUS_BLOCK IoStatusBlock,
786 IN ULONG Reserved);
787
788 typedef VOID
789 (DDKAPI *PKNORMAL_ROUTINE)(
790 IN PVOID NormalContext,
791 IN PVOID SystemArgument1,
792 IN PVOID SystemArgument2);
793
794 typedef VOID
795 (DDKAPI *PKKERNEL_ROUTINE)(
796 IN struct _KAPC *Apc,
797 IN OUT PKNORMAL_ROUTINE *NormalRoutine,
798 IN OUT PVOID *NormalContext,
799 IN OUT PVOID *SystemArgument1,
800 IN OUT PVOID *SystemArgument2);
801
802 typedef VOID
803 (DDKAPI *PKRUNDOWN_ROUTINE)(
804 IN struct _KAPC *Apc);
805
806 typedef struct _KAPC
807 {
808 UCHAR Type;
809 UCHAR SpareByte0;
810 UCHAR Size;
811 UCHAR SpareByte1;
812 ULONG SpareLong0;
813 struct _KTHREAD *Thread;
814 LIST_ENTRY ApcListEntry;
815 PKKERNEL_ROUTINE KernelRoutine;
816 PKRUNDOWN_ROUTINE RundownRoutine;
817 PKNORMAL_ROUTINE NormalRoutine;
818 PVOID NormalContext;
819 PVOID SystemArgument1;
820 PVOID SystemArgument2;
821 CCHAR ApcStateIndex;
822 KPROCESSOR_MODE ApcMode;
823 BOOLEAN Inserted;
824 } KAPC, *PKAPC, *RESTRICTED_POINTER PRKAPC;
825
826 typedef struct _KDEVICE_QUEUE_ENTRY {
827 LIST_ENTRY DeviceListEntry;
828 ULONG SortKey;
829 BOOLEAN Inserted;
830 } KDEVICE_QUEUE_ENTRY, *PKDEVICE_QUEUE_ENTRY,
831 *RESTRICTED_POINTER PRKDEVICE_QUEUE_ENTRY;
832
833 #define LOCK_QUEUE_WAIT 1
834 #define LOCK_QUEUE_OWNER 2
835
836 #if defined(_AMD64_)
837
838 typedef ULONG64 KSPIN_LOCK_QUEUE_NUMBER;
839
840 #define LockQueueUnusedSpare0 0
841 #define LockQueueExpansionLock 1
842 #define LockQueueUnusedSpare2 2
843 #define LockQueueSystemSpaceLock 3
844 #define LockQueueVacbLock 4
845 #define LockQueueMasterLock 5
846 #define LockQueueNonPagedPoolLock 6
847 #define LockQueueIoCancelLock 7
848 #define LockQueueWorkQueueLock 8
849 #define LockQueueIoVpbLock 9
850 #define LockQueueIoDatabaseLock 10
851 #define LockQueueIoCompletionLock 11
852 #define LockQueueNtfsStructLock 12
853 #define LockQueueAfdWorkQueueLock 13
854 #define LockQueueBcbLock 14
855 #define LockQueueMmNonPagedPoolLock 15
856 #define LockQueueUnusedSpare16 16
857 #define LockQueueMaximumLock (LockQueueUnusedSpare16 + 1)
858
859 #else
860
861 typedef enum _KSPIN_LOCK_QUEUE_NUMBER {
862 LockQueueUnusedSpare0,
863 LockQueueExpansionLock,
864 LockQueueUnusedSpare2,
865 LockQueueSystemSpaceLock,
866 LockQueueVacbLock,
867 LockQueueMasterLock,
868 LockQueueNonPagedPoolLock,
869 LockQueueIoCancelLock,
870 LockQueueWorkQueueLock,
871 LockQueueIoVpbLock,
872 LockQueueIoDatabaseLock,
873 LockQueueIoCompletionLock,
874 LockQueueNtfsStructLock,
875 LockQueueAfdWorkQueueLock,
876 LockQueueBcbLock,
877 LockQueueMmNonPagedPoolLock,
878 LockQueueUnusedSpare16,
879 LockQueueMaximumLock = LockQueueUnusedSpare16 + 1
880 } KSPIN_LOCK_QUEUE_NUMBER, *PKSPIN_LOCK_QUEUE_NUMBER;
881
882 #endif
883
884 typedef struct _KSPIN_LOCK_QUEUE {
885 struct _KSPIN_LOCK_QUEUE *volatile Next;
886 PKSPIN_LOCK volatile Lock;
887 } KSPIN_LOCK_QUEUE, *PKSPIN_LOCK_QUEUE;
888
889 typedef struct _KLOCK_QUEUE_HANDLE {
890 KSPIN_LOCK_QUEUE LockQueue;
891 KIRQL OldIrql;
892 } KLOCK_QUEUE_HANDLE, *PKLOCK_QUEUE_HANDLE;
893
894 #define DPC_NORMAL 0
895 #define DPC_THREADED 1
896
897 #define ASSERT_APC(Object) \
898 ASSERT((Object)->Type == ApcObject)
899
900 #define ASSERT_DPC(Object) \
901 ASSERT(((Object)->Type == 0) || \
902 ((Object)->Type == DpcObject) || \
903 ((Object)->Type == ThreadedDpcObject))
904
905 #define ASSERT_DEVICE_QUEUE(Object) \
906 ASSERT((Object)->Type == DeviceQueueObject)
907
908 typedef PVOID PKIPI_CONTEXT;
909
910 typedef
911 VOID
912 (NTAPI *PKIPI_WORKER)(
913 IN PKIPI_CONTEXT PacketContext,
914 IN PVOID Parameter1,
915 IN PVOID Parameter2,
916 IN PVOID Parameter3
917 );
918
919 typedef struct _WAIT_CONTEXT_BLOCK {
920 KDEVICE_QUEUE_ENTRY WaitQueueEntry;
921 PDRIVER_CONTROL DeviceRoutine;
922 PVOID DeviceContext;
923 ULONG NumberOfMapRegisters;
924 PVOID DeviceObject;
925 PVOID CurrentIrp;
926 PKDPC BufferChainingDpc;
927 } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK;
928
929 typedef struct _KDEVICE_QUEUE {
930 CSHORT Type;
931 CSHORT Size;
932 LIST_ENTRY DeviceListHead;
933 KSPIN_LOCK Lock;
934 #if defined(_AMD64_)
935 union {
936 BOOLEAN Busy;
937 struct {
938 LONG64 Reserved : 8;
939 LONG64 Hint : 56;
940 };
941 };
942 #else
943 BOOLEAN Busy;
944 #endif
945
946 } KDEVICE_QUEUE, *PKDEVICE_QUEUE, *RESTRICTED_POINTER PRKDEVICE_QUEUE;
947
948 typedef struct _KDPC
949 {
950 UCHAR Type;
951 UCHAR Importance;
952 volatile USHORT Number;
953 LIST_ENTRY DpcListEntry;
954 PKDEFERRED_ROUTINE DeferredRoutine;
955 PVOID DeferredContext;
956 PVOID SystemArgument1;
957 PVOID SystemArgument2;
958 volatile PVOID DpcData;
959 } KDPC, *PKDPC, *RESTRICTED_POINTER PRKDPC;
960
961 typedef struct _KGATE
962 {
963 DISPATCHER_HEADER Header;
964 } KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
965
966 #define GM_LOCK_BIT 0x1
967 #define GM_LOCK_BIT_V 0x0
968 #define GM_LOCK_WAITER_WOKEN 0x2
969 #define GM_LOCK_WAITER_INC 0x4
970
971 typedef struct _KGUARDED_MUTEX
972 {
973 volatile LONG Count;
974 PKTHREAD Owner;
975 ULONG Contention;
976 KGATE Gate;
977 __GNU_EXTENSION union
978 {
979 __GNU_EXTENSION struct
980 {
981 SHORT KernelApcDisable;
982 SHORT SpecialApcDisable;
983 };
984 ULONG CombinedApcDisable;
985 };
986 } KGUARDED_MUTEX, *PKGUARDED_MUTEX;
987
988 typedef struct _KMUTANT {
989 DISPATCHER_HEADER Header;
990 LIST_ENTRY MutantListEntry;
991 struct _KTHREAD *RESTRICTED_POINTER OwnerThread;
992 BOOLEAN Abandoned;
993 UCHAR ApcDisable;
994 } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
995
996 typedef struct _KTIMER {
997 DISPATCHER_HEADER Header;
998 ULARGE_INTEGER DueTime;
999 LIST_ENTRY TimerListEntry;
1000 struct _KDPC *Dpc;
1001 #if !defined(_X86_)
1002 ULONG Processor;
1003 #endif
1004 ULONG Period;
1005 } KTIMER, *PKTIMER, *RESTRICTED_POINTER PRKTIMER;
1006
1007
1008 #define EVENT_INCREMENT 1
1009 #define IO_NO_INCREMENT 0
1010 #define IO_CD_ROM_INCREMENT 1
1011 #define IO_DISK_INCREMENT 1
1012 #define IO_KEYBOARD_INCREMENT 6
1013 #define IO_MAILSLOT_INCREMENT 2
1014 #define IO_MOUSE_INCREMENT 6
1015 #define IO_NAMED_PIPE_INCREMENT 2
1016 #define IO_NETWORK_INCREMENT 2
1017 #define IO_PARALLEL_INCREMENT 1
1018 #define IO_SERIAL_INCREMENT 2
1019 #define IO_SOUND_INCREMENT 8
1020 #define IO_VIDEO_INCREMENT 1
1021 #define SEMAPHORE_INCREMENT 1
1022
1023 #define MM_MAXIMUM_DISK_IO_SIZE (0x10000)
1024
1025 typedef struct _IRP {
1026 CSHORT Type;
1027 USHORT Size;
1028 struct _MDL *MdlAddress;
1029 ULONG Flags;
1030 union {
1031 struct _IRP *MasterIrp;
1032 volatile LONG IrpCount;
1033 PVOID SystemBuffer;
1034 } AssociatedIrp;
1035 LIST_ENTRY ThreadListEntry;
1036 IO_STATUS_BLOCK IoStatus;
1037 KPROCESSOR_MODE RequestorMode;
1038 BOOLEAN PendingReturned;
1039 CHAR StackCount;
1040 CHAR CurrentLocation;
1041 BOOLEAN Cancel;
1042 KIRQL CancelIrql;
1043 CCHAR ApcEnvironment;
1044 UCHAR AllocationFlags;
1045 PIO_STATUS_BLOCK UserIosb;
1046 PKEVENT UserEvent;
1047 union {
1048 struct {
1049 _ANONYMOUS_UNION union {
1050 PIO_APC_ROUTINE UserApcRoutine;
1051 PVOID IssuingProcess;
1052 } DUMMYUNIONNAME;
1053 PVOID UserApcContext;
1054 } AsynchronousParameters;
1055 LARGE_INTEGER AllocationSize;
1056 } Overlay;
1057 volatile PDRIVER_CANCEL CancelRoutine;
1058 PVOID UserBuffer;
1059 union {
1060 struct {
1061 _ANONYMOUS_UNION union {
1062 KDEVICE_QUEUE_ENTRY DeviceQueueEntry;
1063 _ANONYMOUS_STRUCT struct {
1064 PVOID DriverContext[4];
1065 } DUMMYSTRUCTNAME;
1066 } DUMMYUNIONNAME;
1067 PETHREAD Thread;
1068 PCHAR AuxiliaryBuffer;
1069 _ANONYMOUS_STRUCT struct {
1070 LIST_ENTRY ListEntry;
1071 _ANONYMOUS_UNION union {
1072 struct _IO_STACK_LOCATION *CurrentStackLocation;
1073 ULONG PacketType;
1074 } DUMMYUNIONNAME;
1075 } DUMMYSTRUCTNAME;
1076 struct _FILE_OBJECT *OriginalFileObject;
1077 } Overlay;
1078 KAPC Apc;
1079 PVOID CompletionKey;
1080 } Tail;
1081 } IRP;
1082 typedef struct _IRP *PIRP;
1083
1084 /* IRP.Flags */
1085
1086 #define SL_FORCE_ACCESS_CHECK 0x01
1087 #define SL_OPEN_PAGING_FILE 0x02
1088 #define SL_OPEN_TARGET_DIRECTORY 0x04
1089 #define SL_CASE_SENSITIVE 0x80
1090
1091 #define SL_KEY_SPECIFIED 0x01
1092 #define SL_OVERRIDE_VERIFY_VOLUME 0x02
1093 #define SL_WRITE_THROUGH 0x04
1094 #define SL_FT_SEQUENTIAL_WRITE 0x08
1095
1096 #define SL_FAIL_IMMEDIATELY 0x01
1097 #define SL_EXCLUSIVE_LOCK 0x02
1098
1099 #define SL_RESTART_SCAN 0x01
1100 #define SL_RETURN_SINGLE_ENTRY 0x02
1101 #define SL_INDEX_SPECIFIED 0x04
1102
1103 #define SL_WATCH_TREE 0x01
1104
1105 #define SL_ALLOW_RAW_MOUNT 0x01
1106
1107 #define CTL_CODE(DeviceType, Function, Method, Access)( \
1108 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
1109
1110 #define DEVICE_TYPE_FROM_CTL_CODE(ctl) (((ULONG) (ctl & 0xffff0000)) >> 16)
1111
1112 #define IRP_NOCACHE 0x00000001
1113 #define IRP_PAGING_IO 0x00000002
1114 #define IRP_MOUNT_COMPLETION 0x00000002
1115 #define IRP_SYNCHRONOUS_API 0x00000004
1116 #define IRP_ASSOCIATED_IRP 0x00000008
1117 #define IRP_BUFFERED_IO 0x00000010
1118 #define IRP_DEALLOCATE_BUFFER 0x00000020
1119 #define IRP_INPUT_OPERATION 0x00000040
1120 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
1121 #define IRP_CREATE_OPERATION 0x00000080
1122 #define IRP_READ_OPERATION 0x00000100
1123 #define IRP_WRITE_OPERATION 0x00000200
1124 #define IRP_CLOSE_OPERATION 0x00000400
1125 #define IRP_DEFER_IO_COMPLETION 0x00000800
1126 #define IRP_OB_QUERY_NAME 0x00001000
1127 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
1128
1129 #define IRP_QUOTA_CHARGED 0x01
1130 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
1131 #define IRP_ALLOCATED_FIXED_SIZE 0x04
1132 #define IRP_LOOKASIDE_ALLOCATION 0x08
1133
1134 typedef struct _BOOTDISK_INFORMATION {
1135 LONGLONG BootPartitionOffset;
1136 LONGLONG SystemPartitionOffset;
1137 ULONG BootDeviceSignature;
1138 ULONG SystemDeviceSignature;
1139 } BOOTDISK_INFORMATION, *PBOOTDISK_INFORMATION;
1140
1141 typedef struct _BOOTDISK_INFORMATION_EX {
1142 LONGLONG BootPartitionOffset;
1143 LONGLONG SystemPartitionOffset;
1144 ULONG BootDeviceSignature;
1145 ULONG SystemDeviceSignature;
1146 GUID BootDeviceGuid;
1147 GUID SystemDeviceGuid;
1148 BOOLEAN BootDeviceIsGpt;
1149 BOOLEAN SystemDeviceIsGpt;
1150 } BOOTDISK_INFORMATION_EX, *PBOOTDISK_INFORMATION_EX;
1151
1152 typedef struct _EISA_MEMORY_TYPE {
1153 UCHAR ReadWrite : 1;
1154 UCHAR Cached : 1;
1155 UCHAR Reserved0 : 1;
1156 UCHAR Type : 2;
1157 UCHAR Shared : 1;
1158 UCHAR Reserved1 : 1;
1159 UCHAR MoreEntries : 1;
1160 } EISA_MEMORY_TYPE, *PEISA_MEMORY_TYPE;
1161
1162 #include <pshpack1.h>
1163 typedef struct _EISA_MEMORY_CONFIGURATION {
1164 EISA_MEMORY_TYPE ConfigurationByte;
1165 UCHAR DataSize;
1166 USHORT AddressLowWord;
1167 UCHAR AddressHighByte;
1168 USHORT MemorySize;
1169 } EISA_MEMORY_CONFIGURATION, *PEISA_MEMORY_CONFIGURATION;
1170 #include <poppack.h>
1171
1172 typedef struct _EISA_IRQ_DESCRIPTOR {
1173 UCHAR Interrupt : 4;
1174 UCHAR Reserved : 1;
1175 UCHAR LevelTriggered : 1;
1176 UCHAR Shared : 1;
1177 UCHAR MoreEntries : 1;
1178 } EISA_IRQ_DESCRIPTOR, *PEISA_IRQ_DESCRIPTOR;
1179
1180 typedef struct _EISA_IRQ_CONFIGURATION {
1181 EISA_IRQ_DESCRIPTOR ConfigurationByte;
1182 UCHAR Reserved;
1183 } EISA_IRQ_CONFIGURATION, *PEISA_IRQ_CONFIGURATION;
1184
1185 typedef struct _DMA_CONFIGURATION_BYTE0 {
1186 UCHAR Channel : 3;
1187 UCHAR Reserved : 3;
1188 UCHAR Shared : 1;
1189 UCHAR MoreEntries : 1;
1190 } DMA_CONFIGURATION_BYTE0;
1191
1192 typedef struct _DMA_CONFIGURATION_BYTE1 {
1193 UCHAR Reserved0 : 2;
1194 UCHAR TransferSize : 2;
1195 UCHAR Timing : 2;
1196 UCHAR Reserved1 : 2;
1197 } DMA_CONFIGURATION_BYTE1;
1198
1199 typedef struct _EISA_DMA_CONFIGURATION {
1200 DMA_CONFIGURATION_BYTE0 ConfigurationByte0;
1201 DMA_CONFIGURATION_BYTE1 ConfigurationByte1;
1202 } EISA_DMA_CONFIGURATION, *PEISA_DMA_CONFIGURATION;
1203
1204 #include <pshpack1.h>
1205 typedef struct _EISA_PORT_DESCRIPTOR {
1206 UCHAR NumberPorts : 5;
1207 UCHAR Reserved : 1;
1208 UCHAR Shared : 1;
1209 UCHAR MoreEntries : 1;
1210 } EISA_PORT_DESCRIPTOR, *PEISA_PORT_DESCRIPTOR;
1211
1212 typedef struct _EISA_PORT_CONFIGURATION {
1213 EISA_PORT_DESCRIPTOR Configuration;
1214 USHORT PortAddress;
1215 } EISA_PORT_CONFIGURATION, *PEISA_PORT_CONFIGURATION;
1216 #include <poppack.h>
1217
1218 typedef struct _CM_EISA_FUNCTION_INFORMATION {
1219 ULONG CompressedId;
1220 UCHAR IdSlotFlags1;
1221 UCHAR IdSlotFlags2;
1222 UCHAR MinorRevision;
1223 UCHAR MajorRevision;
1224 UCHAR Selections[26];
1225 UCHAR FunctionFlags;
1226 UCHAR TypeString[80];
1227 EISA_MEMORY_CONFIGURATION EisaMemory[9];
1228 EISA_IRQ_CONFIGURATION EisaIrq[7];
1229 EISA_DMA_CONFIGURATION EisaDma[4];
1230 EISA_PORT_CONFIGURATION EisaPort[20];
1231 UCHAR InitializationData[60];
1232 } CM_EISA_FUNCTION_INFORMATION, *PCM_EISA_FUNCTION_INFORMATION;
1233
1234 /* CM_EISA_FUNCTION_INFORMATION.FunctionFlags */
1235
1236 #define EISA_FUNCTION_ENABLED 0x80
1237 #define EISA_FREE_FORM_DATA 0x40
1238 #define EISA_HAS_PORT_INIT_ENTRY 0x20
1239 #define EISA_HAS_PORT_RANGE 0x10
1240 #define EISA_HAS_DMA_ENTRY 0x08
1241 #define EISA_HAS_IRQ_ENTRY 0x04
1242 #define EISA_HAS_MEMORY_ENTRY 0x02
1243 #define EISA_HAS_TYPE_ENTRY 0x01
1244 #define EISA_HAS_INFORMATION \
1245 (EISA_HAS_PORT_RANGE + EISA_HAS_DMA_ENTRY + EISA_HAS_IRQ_ENTRY \
1246 + EISA_HAS_MEMORY_ENTRY + EISA_HAS_TYPE_ENTRY)
1247
1248 typedef struct _CM_EISA_SLOT_INFORMATION {
1249 UCHAR ReturnCode;
1250 UCHAR ReturnFlags;
1251 UCHAR MajorRevision;
1252 UCHAR MinorRevision;
1253 USHORT Checksum;
1254 UCHAR NumberFunctions;
1255 UCHAR FunctionInformation;
1256 ULONG CompressedId;
1257 } CM_EISA_SLOT_INFORMATION, *PCM_EISA_SLOT_INFORMATION;
1258
1259 /* CM_EISA_SLOT_INFORMATION.ReturnCode */
1260
1261 #define EISA_INVALID_SLOT 0x80
1262 #define EISA_INVALID_FUNCTION 0x81
1263 #define EISA_INVALID_CONFIGURATION 0x82
1264 #define EISA_EMPTY_SLOT 0x83
1265 #define EISA_INVALID_BIOS_CALL 0x86
1266
1267 typedef struct _CM_FLOPPY_DEVICE_DATA {
1268 USHORT Version;
1269 USHORT Revision;
1270 CHAR Size[8];
1271 ULONG MaxDensity;
1272 ULONG MountDensity;
1273 UCHAR StepRateHeadUnloadTime;
1274 UCHAR HeadLoadTime;
1275 UCHAR MotorOffTime;
1276 UCHAR SectorLengthCode;
1277 UCHAR SectorPerTrack;
1278 UCHAR ReadWriteGapLength;
1279 UCHAR DataTransferLength;
1280 UCHAR FormatGapLength;
1281 UCHAR FormatFillCharacter;
1282 UCHAR HeadSettleTime;
1283 UCHAR MotorSettleTime;
1284 UCHAR MaximumTrackValue;
1285 UCHAR DataTransferRate;
1286 } CM_FLOPPY_DEVICE_DATA, *PCM_FLOPPY_DEVICE_DATA;
1287
1288 typedef struct _PNP_BUS_INFORMATION {
1289 GUID BusTypeGuid;
1290 INTERFACE_TYPE LegacyBusType;
1291 ULONG BusNumber;
1292 } PNP_BUS_INFORMATION, *PPNP_BUS_INFORMATION;
1293
1294 #include <pshpack1.h>
1295 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Type */
1296
1297 #define CmResourceTypeNull 0
1298 #define CmResourceTypePort 1
1299 #define CmResourceTypeInterrupt 2
1300 #define CmResourceTypeMemory 3
1301 #define CmResourceTypeDma 4
1302 #define CmResourceTypeDeviceSpecific 5
1303 #define CmResourceTypeBusNumber 6
1304 #define CmResourceTypeMemoryLarge 7
1305 #define CmResourceTypeNonArbitrated 128
1306 #define CmResourceTypeConfigData 128
1307 #define CmResourceTypeDevicePrivate 129
1308 #define CmResourceTypePcCardConfig 130
1309 #define CmResourceTypeMfCardConfig 131
1310
1311 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.ShareDisposition */
1312
1313 typedef enum _CM_SHARE_DISPOSITION {
1314 CmResourceShareUndetermined,
1315 CmResourceShareDeviceExclusive,
1316 CmResourceShareDriverExclusive,
1317 CmResourceShareShared
1318 } CM_SHARE_DISPOSITION;
1319
1320 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypePort */
1321
1322 #define CM_RESOURCE_PORT_MEMORY 0x0000
1323 #define CM_RESOURCE_PORT_IO 0x0001
1324 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
1325 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
1326 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
1327 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
1328 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
1329 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
1330 #define CM_RESOURCE_PORT_BAR 0x0100
1331
1332 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeInterrupt */
1333
1334 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0x0000
1335 #define CM_RESOURCE_INTERRUPT_LATCHED 0x0001
1336 #define CM_RESOURCE_INTERRUPT_MESSAGE 0x0002
1337 #define CM_RESOURCE_INTERRUPT_POLICY_INCLUDED 0x0004
1338
1339 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeMemory */
1340
1341 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
1342 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
1343 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
1344 #define CM_RESOURCE_MEMORY_WRITEABILITY_MASK 0x0003
1345 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
1346 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
1347 #define CM_RESOURCE_MEMORY_24 0x0010
1348 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
1349 #define CM_RESOURCE_MEMORY_WINDOW_DECODE 0x0040
1350 #define CM_RESOURCE_MEMORY_BAR 0x0080
1351 #define CM_RESOURCE_MEMORY_COMPAT_FOR_INACCESSIBLE_RANGE 0x0100
1352
1353 /* CM_PARTIAL_RESOURCE_DESCRIPTOR.Flags if Type = CmResourceTypeDma */
1354
1355 #define CM_RESOURCE_DMA_8 0x0000
1356 #define CM_RESOURCE_DMA_16 0x0001
1357 #define CM_RESOURCE_DMA_32 0x0002
1358 #define CM_RESOURCE_DMA_8_AND_16 0x0004
1359 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
1360 #define CM_RESOURCE_DMA_TYPE_A 0x0010
1361 #define CM_RESOURCE_DMA_TYPE_B 0x0020
1362 #define CM_RESOURCE_DMA_TYPE_F 0x0040
1363
1364 typedef struct _CM_PARTIAL_RESOURCE_LIST {
1365 USHORT Version;
1366 USHORT Revision;
1367 ULONG Count;
1368 CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];
1369 } CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;
1370
1371 typedef struct _CM_FULL_RESOURCE_DESCRIPTOR {
1372 INTERFACE_TYPE InterfaceType;
1373 ULONG BusNumber;
1374 CM_PARTIAL_RESOURCE_LIST PartialResourceList;
1375 } CM_FULL_RESOURCE_DESCRIPTOR, *PCM_FULL_RESOURCE_DESCRIPTOR;
1376
1377 typedef struct _CM_RESOURCE_LIST {
1378 ULONG Count;
1379 CM_FULL_RESOURCE_DESCRIPTOR List[1];
1380 } CM_RESOURCE_LIST, *PCM_RESOURCE_LIST;
1381
1382 typedef struct _CM_INT13_DRIVE_PARAMETER {
1383 USHORT DriveSelect;
1384 ULONG MaxCylinders;
1385 USHORT SectorsPerTrack;
1386 USHORT MaxHeads;
1387 USHORT NumberDrives;
1388 } CM_INT13_DRIVE_PARAMETER, *PCM_INT13_DRIVE_PARAMETER;
1389
1390 typedef struct _CM_PNP_BIOS_DEVICE_NODE
1391 {
1392 USHORT Size;
1393 UCHAR Node;
1394 ULONG ProductId;
1395 UCHAR DeviceType[3];
1396 USHORT DeviceAttributes;
1397 } CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;
1398
1399 typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
1400 {
1401 UCHAR Signature[4];
1402 UCHAR Revision;
1403 UCHAR Length;
1404 USHORT ControlField;
1405 UCHAR Checksum;
1406 ULONG EventFlagAddress;
1407 USHORT RealModeEntryOffset;
1408 USHORT RealModeEntrySegment;
1409 USHORT ProtectedModeEntryOffset;
1410 ULONG ProtectedModeCodeBaseAddress;
1411 ULONG OemDeviceId;
1412 USHORT RealModeDataBaseAddress;
1413 ULONG ProtectedModeDataBaseAddress;
1414 } CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;
1415
1416 #include <poppack.h>
1417
1418 typedef struct _CM_DISK_GEOMETRY_DEVICE_DATA
1419 {
1420 ULONG BytesPerSector;
1421 ULONG NumberOfCylinders;
1422 ULONG SectorsPerTrack;
1423 ULONG NumberOfHeads;
1424 } CM_DISK_GEOMETRY_DEVICE_DATA, *PCM_DISK_GEOMETRY_DEVICE_DATA;
1425
1426 typedef struct _CM_KEYBOARD_DEVICE_DATA {
1427 USHORT Version;
1428 USHORT Revision;
1429 UCHAR Type;
1430 UCHAR Subtype;
1431 USHORT KeyboardFlags;
1432 } CM_KEYBOARD_DEVICE_DATA, *PCM_KEYBOARD_DEVICE_DATA;
1433
1434 typedef struct _CM_MCA_POS_DATA {
1435 USHORT AdapterId;
1436 UCHAR PosData1;
1437 UCHAR PosData2;
1438 UCHAR PosData3;
1439 UCHAR PosData4;
1440 } CM_MCA_POS_DATA, *PCM_MCA_POS_DATA;
1441
1442 #if (NTDDI_VERSION >= NTDDI_WINXP)
1443 typedef struct CM_Power_Data_s {
1444 ULONG PD_Size;
1445 DEVICE_POWER_STATE PD_MostRecentPowerState;
1446 ULONG PD_Capabilities;
1447 ULONG PD_D1Latency;
1448 ULONG PD_D2Latency;
1449 ULONG PD_D3Latency;
1450 DEVICE_POWER_STATE PD_PowerStateMapping[PowerSystemMaximum];
1451 SYSTEM_POWER_STATE PD_DeepestSystemWake;
1452 } CM_POWER_DATA, *PCM_POWER_DATA;
1453
1454 #define PDCAP_D0_SUPPORTED 0x00000001
1455 #define PDCAP_D1_SUPPORTED 0x00000002
1456 #define PDCAP_D2_SUPPORTED 0x00000004
1457 #define PDCAP_D3_SUPPORTED 0x00000008
1458 #define PDCAP_WAKE_FROM_D0_SUPPORTED 0x00000010
1459 #define PDCAP_WAKE_FROM_D1_SUPPORTED 0x00000020
1460 #define PDCAP_WAKE_FROM_D2_SUPPORTED 0x00000040
1461 #define PDCAP_WAKE_FROM_D3_SUPPORTED 0x00000080
1462 #define PDCAP_WARM_EJECT_SUPPORTED 0x00000100
1463
1464 #endif /* (NTDDI_VERSION >= NTDDI_WINXP) */
1465
1466 typedef struct _CM_SCSI_DEVICE_DATA {
1467 USHORT Version;
1468 USHORT Revision;
1469 UCHAR HostIdentifier;
1470 } CM_SCSI_DEVICE_DATA, *PCM_SCSI_DEVICE_DATA;
1471
1472 typedef struct _CM_SERIAL_DEVICE_DATA {
1473 USHORT Version;
1474 USHORT Revision;
1475 ULONG BaudClock;
1476 } CM_SERIAL_DEVICE_DATA, *PCM_SERIAL_DEVICE_DATA;
1477
1478 typedef enum _KINTERRUPT_POLARITY {
1479 InterruptPolarityUnknown,
1480 InterruptActiveHigh,
1481 InterruptActiveLow
1482 } KINTERRUPT_POLARITY, *PKINTERRUPT_POLARITY;
1483
1484 typedef struct _IO_ERROR_LOG_PACKET {
1485 UCHAR MajorFunctionCode;
1486 UCHAR RetryCount;
1487 USHORT DumpDataSize;
1488 USHORT NumberOfStrings;
1489 USHORT StringOffset;
1490 USHORT EventCategory;
1491 NTSTATUS ErrorCode;
1492 ULONG UniqueErrorValue;
1493 NTSTATUS FinalStatus;
1494 ULONG SequenceNumber;
1495 ULONG IoControlCode;
1496 LARGE_INTEGER DeviceOffset;
1497 ULONG DumpData[1];
1498 } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET;
1499
1500 typedef struct _IO_ERROR_LOG_MESSAGE {
1501 USHORT Type;
1502 USHORT Size;
1503 USHORT DriverNameLength;
1504 LARGE_INTEGER TimeStamp;
1505 ULONG DriverNameOffset;
1506 IO_ERROR_LOG_PACKET EntryData;
1507 } IO_ERROR_LOG_MESSAGE, *PIO_ERROR_LOG_MESSAGE;
1508
1509 #define ERROR_LOG_LIMIT_SIZE 240
1510 #define IO_ERROR_LOG_MESSAGE_HEADER_LENGTH (sizeof(IO_ERROR_LOG_MESSAGE) - \
1511 sizeof(IO_ERROR_LOG_PACKET) + \
1512 (sizeof(WCHAR) * 40))
1513 #define ERROR_LOG_MESSAGE_LIMIT_SIZE \
1514 (ERROR_LOG_LIMIT_SIZE + IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
1515 #define IO_ERROR_LOG_MESSAGE_LENGTH \
1516 ((PORT_MAXIMUM_MESSAGE_LENGTH > ERROR_LOG_MESSAGE_LIMIT_SIZE) ? \
1517 ERROR_LOG_MESSAGE_LIMIT_SIZE : \
1518 PORT_MAXIMUM_MESSAGE_LENGTH)
1519 #define ERROR_LOG_MAXIMUM_SIZE (IO_ERROR_LOG_MESSAGE_LENGTH - \
1520 IO_ERROR_LOG_MESSAGE_HEADER_LENGTH)
1521
1522 typedef enum _DMA_WIDTH {
1523 Width8Bits,
1524 Width16Bits,
1525 Width32Bits,
1526 MaximumDmaWidth
1527 } DMA_WIDTH, *PDMA_WIDTH;
1528
1529 typedef enum _DMA_SPEED {
1530 Compatible,
1531 TypeA,
1532 TypeB,
1533 TypeC,
1534 TypeF,
1535 MaximumDmaSpeed
1536 } DMA_SPEED, *PDMA_SPEED;
1537
1538 /* DEVICE_DESCRIPTION.Version */
1539
1540 #define DEVICE_DESCRIPTION_VERSION 0x0000
1541 #define DEVICE_DESCRIPTION_VERSION1 0x0001
1542 #define DEVICE_DESCRIPTION_VERSION2 0x0002
1543
1544 typedef struct _DEVICE_DESCRIPTION {
1545 ULONG Version;
1546 BOOLEAN Master;
1547 BOOLEAN ScatterGather;
1548 BOOLEAN DemandMode;
1549 BOOLEAN AutoInitialize;
1550 BOOLEAN Dma32BitAddresses;
1551 BOOLEAN IgnoreCount;
1552 BOOLEAN Reserved1;
1553 BOOLEAN Dma64BitAddresses;
1554 ULONG BusNumber;
1555 ULONG DmaChannel;
1556 INTERFACE_TYPE InterfaceType;
1557 DMA_WIDTH DmaWidth;
1558 DMA_SPEED DmaSpeed;
1559 ULONG MaximumLength;
1560 ULONG DmaPort;
1561 } DEVICE_DESCRIPTION, *PDEVICE_DESCRIPTION;
1562
1563 /* VPB.Flags */
1564 #define VPB_MOUNTED 0x0001
1565 #define VPB_LOCKED 0x0002
1566 #define VPB_PERSISTENT 0x0004
1567 #define VPB_REMOVE_PENDING 0x0008
1568 #define VPB_RAW_MOUNT 0x0010
1569 #define VPB_DIRECT_WRITES_ALLOWED 0x0020
1570
1571 #define MAXIMUM_VOLUME_LABEL_LENGTH (32 * sizeof(WCHAR))
1572
1573 typedef struct _VPB {
1574 CSHORT Type;
1575 CSHORT Size;
1576 USHORT Flags;
1577 USHORT VolumeLabelLength;
1578 struct _DEVICE_OBJECT *DeviceObject;
1579 struct _DEVICE_OBJECT *RealDevice;
1580 ULONG SerialNumber;
1581 ULONG ReferenceCount;
1582 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
1583 } VPB, *PVPB;
1584
1585 /* DEVICE_OBJECT.Flags */
1586
1587 #define DO_VERIFY_VOLUME 0x00000002
1588 #define DO_BUFFERED_IO 0x00000004
1589 #define DO_EXCLUSIVE 0x00000008
1590 #define DO_DIRECT_IO 0x00000010
1591 #define DO_MAP_IO_BUFFER 0x00000020
1592 #define DO_DEVICE_INITIALIZING 0x00000080
1593 #define DO_SHUTDOWN_REGISTERED 0x00000800
1594 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
1595 #define DO_POWER_PAGABLE 0x00002000
1596 #define DO_POWER_INRUSH 0x00004000
1597
1598 /* DEVICE_OBJECT.Characteristics */
1599
1600 #define FILE_REMOVABLE_MEDIA 0x00000001
1601 #define FILE_READ_ONLY_DEVICE 0x00000002
1602 #define FILE_FLOPPY_DISKETTE 0x00000004
1603 #define FILE_WRITE_ONCE_MEDIA 0x00000008
1604 #define FILE_REMOTE_DEVICE 0x00000010
1605 #define FILE_DEVICE_IS_MOUNTED 0x00000020
1606 #define FILE_VIRTUAL_VOLUME 0x00000040
1607 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
1608 #define FILE_DEVICE_SECURE_OPEN 0x00000100
1609 #define FILE_CHARACTERISTIC_PNP_DEVICE 0x00000800
1610 #define FILE_CHARACTERISTIC_TS_DEVICE 0x00001000
1611 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE 0x00002000
1612
1613 /* DEVICE_OBJECT.AlignmentRequirement */
1614
1615 #define FILE_BYTE_ALIGNMENT 0x00000000
1616 #define FILE_WORD_ALIGNMENT 0x00000001
1617 #define FILE_LONG_ALIGNMENT 0x00000003
1618 #define FILE_QUAD_ALIGNMENT 0x00000007
1619 #define FILE_OCTA_ALIGNMENT 0x0000000f
1620 #define FILE_32_BYTE_ALIGNMENT 0x0000001f
1621 #define FILE_64_BYTE_ALIGNMENT 0x0000003f
1622 #define FILE_128_BYTE_ALIGNMENT 0x0000007f
1623 #define FILE_256_BYTE_ALIGNMENT 0x000000ff
1624 #define FILE_512_BYTE_ALIGNMENT 0x000001ff
1625
1626 /* DEVICE_OBJECT.DeviceType */
1627
1628 #define DEVICE_TYPE ULONG
1629
1630 #define FILE_DEVICE_BEEP 0x00000001
1631 #define FILE_DEVICE_CD_ROM 0x00000002
1632 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
1633 #define FILE_DEVICE_CONTROLLER 0x00000004
1634 #define FILE_DEVICE_DATALINK 0x00000005
1635 #define FILE_DEVICE_DFS 0x00000006
1636 #define FILE_DEVICE_DISK 0x00000007
1637 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
1638 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
1639 #define FILE_DEVICE_INPORT_PORT 0x0000000a
1640 #define FILE_DEVICE_KEYBOARD 0x0000000b
1641 #define FILE_DEVICE_MAILSLOT 0x0000000c
1642 #define FILE_DEVICE_MIDI_IN 0x0000000d
1643 #define FILE_DEVICE_MIDI_OUT 0x0000000e
1644 #define FILE_DEVICE_MOUSE 0x0000000f
1645 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
1646 #define FILE_DEVICE_NAMED_PIPE 0x00000011
1647 #define FILE_DEVICE_NETWORK 0x00000012
1648 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
1649 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
1650 #define FILE_DEVICE_NULL 0x00000015
1651 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
1652 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
1653 #define FILE_DEVICE_PRINTER 0x00000018
1654 #define FILE_DEVICE_SCANNER 0x00000019
1655 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
1656 #define FILE_DEVICE_SERIAL_PORT 0x0000001b
1657 #define FILE_DEVICE_SCREEN 0x0000001c
1658 #define FILE_DEVICE_SOUND 0x0000001d
1659 #define FILE_DEVICE_STREAMS 0x0000001e
1660 #define FILE_DEVICE_TAPE 0x0000001f
1661 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
1662 #define FILE_DEVICE_TRANSPORT 0x00000021
1663 #define FILE_DEVICE_UNKNOWN 0x00000022
1664 #define FILE_DEVICE_VIDEO 0x00000023
1665 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
1666 #define FILE_DEVICE_WAVE_IN 0x00000025
1667 #define FILE_DEVICE_WAVE_OUT 0x00000026
1668 #define FILE_DEVICE_8042_PORT 0x00000027
1669 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
1670 #define FILE_DEVICE_BATTERY 0x00000029
1671 #define FILE_DEVICE_BUS_EXTENDER 0x0000002a
1672 #define FILE_DEVICE_MODEM 0x0000002b
1673 #define FILE_DEVICE_VDM 0x0000002c
1674 #define FILE_DEVICE_MASS_STORAGE 0x0000002d
1675 #define FILE_DEVICE_SMB 0x0000002e
1676 #define FILE_DEVICE_KS 0x0000002f
1677 #define FILE_DEVICE_CHANGER 0x00000030
1678 #define FILE_DEVICE_SMARTCARD 0x00000031
1679 #define FILE_DEVICE_ACPI 0x00000032
1680 #define FILE_DEVICE_DVD 0x00000033
1681 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
1682 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
1683 #define FILE_DEVICE_DFS_VOLUME 0x00000036
1684 #define FILE_DEVICE_SERENUM 0x00000037
1685 #define FILE_DEVICE_TERMSRV 0x00000038
1686 #define FILE_DEVICE_KSEC 0x00000039
1687 #define FILE_DEVICE_FIPS 0x0000003a
1688 #define FILE_DEVICE_INFINIBAND 0x0000003b
1689 #define FILE_DEVICE_VMBUS 0x0000003e
1690 #define FILE_DEVICE_CRYPT_PROVIDER 0x0000003f
1691 #define FILE_DEVICE_WPD 0x00000040
1692 #define FILE_DEVICE_BLUETOOTH 0x00000041
1693 #define FILE_DEVICE_MT_COMPOSITE 0x00000042
1694 #define FILE_DEVICE_MT_TRANSPORT 0x00000043
1695 #define FILE_DEVICE_BIOMETRIC 0x00000044
1696 #define FILE_DEVICE_PMI 0x00000045
1697
1698 typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT {
1699 CSHORT Type;
1700 USHORT Size;
1701 LONG ReferenceCount;
1702 struct _DRIVER_OBJECT *DriverObject;
1703 struct _DEVICE_OBJECT *NextDevice;
1704 struct _DEVICE_OBJECT *AttachedDevice;
1705 struct _IRP *CurrentIrp;
1706 PIO_TIMER Timer;
1707 ULONG Flags;
1708 ULONG Characteristics;
1709 volatile PVPB Vpb;
1710 PVOID DeviceExtension;
1711 DEVICE_TYPE DeviceType;
1712 CCHAR StackSize;
1713 union {
1714 LIST_ENTRY ListEntry;
1715 WAIT_CONTEXT_BLOCK Wcb;
1716 } Queue;
1717 ULONG AlignmentRequirement;
1718 KDEVICE_QUEUE DeviceQueue;
1719 KDPC Dpc;
1720 ULONG ActiveThreadCount;
1721 PSECURITY_DESCRIPTOR SecurityDescriptor;
1722 KEVENT DeviceLock;
1723 USHORT SectorSize;
1724 USHORT Spare1;
1725 struct _DEVOBJ_EXTENSION *DeviceObjectExtension;
1726 PVOID Reserved;
1727 } DEVICE_OBJECT, *PDEVICE_OBJECT;
1728
1729 typedef enum _DEVICE_RELATION_TYPE {
1730 BusRelations,
1731 EjectionRelations,
1732 PowerRelations,
1733 RemovalRelations,
1734 TargetDeviceRelation,
1735 SingleBusRelations,
1736 TransportRelations
1737 } DEVICE_RELATION_TYPE, *PDEVICE_RELATION_TYPE;
1738
1739 typedef struct _DEVICE_RELATIONS {
1740 ULONG Count;
1741 PDEVICE_OBJECT Objects[1];
1742 } DEVICE_RELATIONS, *PDEVICE_RELATIONS;
1743
1744 typedef struct _SCATTER_GATHER_ELEMENT {
1745 PHYSICAL_ADDRESS Address;
1746 ULONG Length;
1747 ULONG_PTR Reserved;
1748 } SCATTER_GATHER_ELEMENT, *PSCATTER_GATHER_ELEMENT;
1749
1750 #if defined(_MSC_EXTENSIONS)
1751
1752 #if _MSC_VER >= 1200
1753 #pragma warning(push)
1754 #endif
1755 #pragma warning(disable:4200)
1756 typedef struct _SCATTER_GATHER_LIST {
1757 ULONG NumberOfElements;
1758 ULONG_PTR Reserved;
1759 SCATTER_GATHER_ELEMENT Elements[1];
1760 } SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
1761
1762 #if _MSC_VER >= 1200
1763 #pragma warning(pop)
1764 #else
1765 #pragma warning(default:4200)
1766 #endif
1767
1768 #else
1769
1770 struct _SCATTER_GATHER_LIST;
1771 typedef struct _SCATTER_GATHER_LIST SCATTER_GATHER_LIST, *PSCATTER_GATHER_LIST;
1772
1773 #endif
1774
1775 /* Simple types */
1776 typedef UCHAR KPROCESSOR_MODE;
1777 typedef LONG KPRIORITY;
1778 typedef PVOID PSECURITY_DESCRIPTOR;
1779 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
1780
1781 /* Structures not exposed to drivers */
1782 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
1783 typedef struct _HAL_DISPATCH_TABLE *PHAL_DISPATCH_TABLE;
1784 typedef struct _HAL_PRIVATE_DISPATCH_TABLE *PHAL_PRIVATE_DISPATCH_TABLE;
1785 typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
1786 typedef struct _BUS_HANDLER *PBUS_HANDLER;
1787
1788 typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
1789 typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
1790 typedef struct _ETHREAD *PETHREAD;
1791 typedef struct _EPROCESS *PEPROCESS;
1792 typedef struct _IO_TIMER *PIO_TIMER;
1793 typedef struct _KINTERRUPT *PKINTERRUPT;
1794 typedef struct _KPROCESS *PKPROCESS;
1795 typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
1796
1797
1798 typedef struct _CONTEXT *PCONTEXT;
1799
1800 //
1801 // Resource list definitions
1802 //
1803 typedef int CM_RESOURCE_TYPE;
1804
1805 #define CmResourceTypeNull 0
1806 #define CmResourceTypePort 1
1807 #define CmResourceTypeInterrupt 2
1808 #define CmResourceTypeMemory 3
1809 #define CmResourceTypeDma 4
1810 #define CmResourceTypeDeviceSpecific 5
1811 #define CmResourceTypeBusNumber 6
1812 #define CmResourceTypeNonArbitrated 128
1813 #define CmResourceTypeConfigData 128
1814 #define CmResourceTypeDevicePrivate 129
1815 #define CmResourceTypePcCardConfig 130
1816 #define CmResourceTypeMfCardConfig 131
1817
1818 typedef enum _INTERFACE_TYPE {
1819 InterfaceTypeUndefined = -1,
1820 Internal,
1821 Isa,
1822 Eisa,
1823 MicroChannel,
1824 TurboChannel,
1825 PCIBus,
1826 VMEBus,
1827 NuBus,
1828 PCMCIABus,
1829 CBus,
1830 MPIBus,
1831 MPSABus,
1832 ProcessorInternal,
1833 InternalPowerBus,
1834 PNPISABus,
1835 PNPBus,
1836 MaximumInterfaceType
1837 } INTERFACE_TYPE, *PINTERFACE_TYPE;
1838
1839 /* IO_RESOURCE_DESCRIPTOR.Option */
1840
1841 #define IO_RESOURCE_PREFERRED 0x01
1842 #define IO_RESOURCE_DEFAULT 0x02
1843 #define IO_RESOURCE_ALTERNATIVE 0x08
1844
1845 typedef struct _IO_RESOURCE_DESCRIPTOR {
1846 UCHAR Option;
1847 UCHAR Type;
1848 UCHAR ShareDisposition;
1849 UCHAR Spare1;
1850 USHORT Flags;
1851 USHORT Spare2;
1852 union {
1853 struct {
1854 ULONG Length;
1855 ULONG Alignment;
1856 PHYSICAL_ADDRESS MinimumAddress;
1857 PHYSICAL_ADDRESS MaximumAddress;
1858 } Port;
1859 struct {
1860 ULONG Length;
1861 ULONG Alignment;
1862 PHYSICAL_ADDRESS MinimumAddress;
1863 PHYSICAL_ADDRESS MaximumAddress;
1864 } Memory;
1865 struct {
1866 ULONG MinimumVector;
1867 ULONG MaximumVector;
1868 } Interrupt;
1869 struct {
1870 ULONG MinimumChannel;
1871 ULONG MaximumChannel;
1872 } Dma;
1873 struct {
1874 ULONG Length;
1875 ULONG Alignment;
1876 PHYSICAL_ADDRESS MinimumAddress;
1877 PHYSICAL_ADDRESS MaximumAddress;
1878 } Generic;
1879 struct {
1880 ULONG Data[3];
1881 } DevicePrivate;
1882 struct {
1883 ULONG Length;
1884 ULONG MinBusNumber;
1885 ULONG MaxBusNumber;
1886 ULONG Reserved;
1887 } BusNumber;
1888 struct {
1889 ULONG Priority;
1890 ULONG Reserved1;
1891 ULONG Reserved2;
1892 } ConfigData;
1893 } u;
1894 } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
1895
1896 typedef struct _IO_RESOURCE_LIST {
1897 USHORT Version;
1898 USHORT Revision;
1899 ULONG Count;
1900 IO_RESOURCE_DESCRIPTOR Descriptors[1];
1901 } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
1902
1903 typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
1904 ULONG ListSize;
1905 INTERFACE_TYPE InterfaceType;
1906 ULONG BusNumber;
1907 ULONG SlotNumber;
1908 ULONG Reserved[3];
1909 ULONG AlternativeLists;
1910 IO_RESOURCE_LIST List[1];
1911 } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
1912
1913 //
1914 // Global debug flag
1915 //
1916 extern ULONG NtGlobalFlag;
1917
1918
1919 #include <pshpack4.h>
1920 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
1921 UCHAR Type;
1922 UCHAR ShareDisposition;
1923 USHORT Flags;
1924 union {
1925 struct {
1926 PHYSICAL_ADDRESS Start;
1927 ULONG Length;
1928 } Generic;
1929 struct {
1930 PHYSICAL_ADDRESS Start;
1931 ULONG Length;
1932 } Port;
1933 struct {
1934 ULONG Level;
1935 ULONG Vector;
1936 KAFFINITY Affinity;
1937 } Interrupt;
1938 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1939 struct {
1940 __GNU_EXTENSION union {
1941 struct {
1942 USHORT Reserved;
1943 USHORT MessageCount;
1944 ULONG Vector;
1945 KAFFINITY Affinity;
1946 } Raw;
1947 struct {
1948 ULONG Level;
1949 ULONG Vector;
1950 KAFFINITY Affinity;
1951 } Translated;
1952 };
1953 } MessageInterrupt;
1954 #endif
1955 struct {
1956 PHYSICAL_ADDRESS Start;
1957 ULONG Length;
1958 } Memory;
1959 struct {
1960 ULONG Channel;
1961 ULONG Port;
1962 ULONG Reserved1;
1963 } Dma;
1964 struct {
1965 ULONG Data[3];
1966 } DevicePrivate;
1967 struct {
1968 ULONG Start;
1969 ULONG Length;
1970 ULONG Reserved;
1971 } BusNumber;
1972 struct {
1973 ULONG DataSize;
1974 ULONG Reserved1;
1975 ULONG Reserved2;
1976 } DeviceSpecificData;
1977 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1978 struct {
1979 PHYSICAL_ADDRESS Start;
1980 ULONG Length40;
1981 } Memory40;
1982 struct {
1983 PHYSICAL_ADDRESS Start;
1984 ULONG Length48;
1985 } Memory48;
1986 struct {
1987 PHYSICAL_ADDRESS Start;
1988 ULONG Length64;
1989 } Memory64;
1990 #endif
1991 } u;
1992 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
1993 #include <poppack.h>
1994
1995 //
1996 // Section map options
1997 //
1998 typedef enum _SECTION_INHERIT {
1999 ViewShare = 1,
2000 ViewUnmap = 2
2001 } SECTION_INHERIT;
2002
2003 //
2004 // Section access rights
2005 //
2006 #define SECTION_QUERY 0x0001
2007 #define SECTION_MAP_WRITE 0x0002
2008 #define SECTION_MAP_READ 0x0004
2009 #define SECTION_MAP_EXECUTE 0x0008
2010 #define SECTION_EXTEND_SIZE 0x0010
2011 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
2012
2013 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
2014 SECTION_MAP_WRITE | \
2015 SECTION_MAP_READ | \
2016 SECTION_MAP_EXECUTE | \
2017 SECTION_EXTEND_SIZE)
2018
2019 #define SESSION_QUERY_ACCESS 0x0001
2020 #define SESSION_MODIFY_ACCESS 0x0002
2021
2022 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
2023 SESSION_QUERY_ACCESS | \
2024 SESSION_MODIFY_ACCESS)
2025
2026
2027
2028 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
2029
2030 #define PAGE_NOACCESS 0x01
2031 #define PAGE_READONLY 0x02
2032 #define PAGE_READWRITE 0x04
2033 #define PAGE_WRITECOPY 0x08
2034 #define PAGE_EXECUTE 0x10
2035 #define PAGE_EXECUTE_READ 0x20
2036 #define PAGE_EXECUTE_READWRITE 0x40
2037 #define PAGE_EXECUTE_WRITECOPY 0x80
2038 #define PAGE_GUARD 0x100
2039 #define PAGE_NOCACHE 0x200
2040 #define PAGE_WRITECOMBINE 0x400
2041
2042 #define MEM_COMMIT 0x1000
2043 #define MEM_RESERVE 0x2000
2044 #define MEM_DECOMMIT 0x4000
2045 #define MEM_RELEASE 0x8000
2046 #define MEM_FREE 0x10000
2047 #define MEM_PRIVATE 0x20000
2048 #define MEM_MAPPED 0x40000
2049 #define MEM_RESET 0x80000
2050 #define MEM_TOP_DOWN 0x100000
2051 #define MEM_LARGE_PAGES 0x20000000
2052 #define MEM_4MB_PAGES 0x80000000
2053
2054 #define SEC_RESERVE 0x4000000
2055 #define SEC_LARGE_PAGES 0x80000000
2056
2057 #define PROCESS_DUP_HANDLE (0x0040)
2058
2059 #if (NTDDI_VERSION >= NTDDI_VISTA)
2060 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
2061 0xFFFF)
2062 #else
2063 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
2064 0xFFF)
2065 #endif
2066
2067
2068
2069 //
2070 // Processor features
2071 //
2072 #define PF_FLOATING_POINT_PRECISION_ERRATA 0
2073 #define PF_FLOATING_POINT_EMULATED 1
2074 #define PF_COMPARE_EXCHANGE_DOUBLE 2
2075 #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
2076 #define PF_PPC_MOVEMEM_64BIT_OK 4
2077 #define PF_ALPHA_BYTE_INSTRUCTIONS 5
2078 #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
2079 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
2080 #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
2081 #define PF_PAE_ENABLED 9
2082 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
2083 #define PF_SSE_DAZ_MODE_AVAILABLE 11
2084 #define PF_NX_ENABLED 12
2085 #define PF_SSE3_INSTRUCTIONS_AVAILABLE 13
2086 #define PF_COMPARE_EXCHANGE128 14
2087 #define PF_COMPARE64_EXCHANGE128 15
2088 #define PF_CHANNELS_ENABLED 16
2089
2090
2091
2092 //
2093 // Intrinsics (note: taken from our winnt.h)
2094 // FIXME: 64-bit
2095 //
2096 #if defined(__GNUC__)
2097
2098 static __inline__ BOOLEAN
2099 InterlockedBitTestAndSet(IN LONG volatile *Base,
2100 IN LONG Bit)
2101 {
2102 #if defined(_M_IX86)
2103 LONG OldBit;
2104 __asm__ __volatile__("lock "
2105 "btsl %2,%1\n\t"
2106 "sbbl %0,%0\n\t"
2107 :"=r" (OldBit),"+m" (*Base)
2108 :"Ir" (Bit)
2109 : "memory");
2110 return OldBit;
2111 #else
2112 return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
2113 #endif
2114 }
2115
2116 static __inline__ BOOLEAN
2117 InterlockedBitTestAndReset(IN LONG volatile *Base,
2118 IN LONG Bit)
2119 {
2120 #if defined(_M_IX86)
2121 LONG OldBit;
2122 __asm__ __volatile__("lock "
2123 "btrl %2,%1\n\t"
2124 "sbbl %0,%0\n\t"
2125 :"=r" (OldBit),"+m" (*Base)
2126 :"Ir" (Bit)
2127 : "memory");
2128 return OldBit;
2129 #else
2130 return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
2131 #endif
2132 }
2133
2134 #endif
2135
2136 #define BitScanForward _BitScanForward
2137 #define BitScanReverse _BitScanReverse
2138
2139 #define BitTest _bittest
2140 #define BitTestAndComplement _bittestandcomplement
2141 #define BitTestAndSet _bittestandset
2142 #define BitTestAndReset _bittestandreset
2143 #define InterlockedBitTestAndSet _interlockedbittestandset
2144 #define InterlockedBitTestAndReset _interlockedbittestandreset
2145
2146
2147 /** INTERLOCKED FUNCTIONS *****************************************************/
2148
2149 #if !defined(__INTERLOCKED_DECLARED)
2150 #define __INTERLOCKED_DECLARED
2151
2152 #if defined (_X86_)
2153 #if defined(NO_INTERLOCKED_INTRINSICS)
2154 NTKERNELAPI
2155 LONG
2156 FASTCALL
2157 InterlockedIncrement(
2158 IN OUT LONG volatile *Addend);
2159
2160 NTKERNELAPI
2161 LONG
2162 FASTCALL
2163 InterlockedDecrement(
2164 IN OUT LONG volatile *Addend);
2165
2166 NTKERNELAPI
2167 LONG
2168 FASTCALL
2169 InterlockedCompareExchange(
2170 IN OUT LONG volatile *Destination,
2171 IN LONG Exchange,
2172 IN LONG Comparand);
2173
2174 NTKERNELAPI
2175 LONG
2176 FASTCALL
2177 InterlockedExchange(
2178 IN OUT LONG volatile *Destination,
2179 IN LONG Value);
2180
2181 NTKERNELAPI
2182 LONG
2183 FASTCALL
2184 InterlockedExchangeAdd(
2185 IN OUT LONG volatile *Addend,
2186 IN LONG Value);
2187
2188 #else // !defined(NO_INTERLOCKED_INTRINSICS)
2189
2190 #define InterlockedExchange _InterlockedExchange
2191 #define InterlockedIncrement _InterlockedIncrement
2192 #define InterlockedDecrement _InterlockedDecrement
2193 #define InterlockedExchangeAdd _InterlockedExchangeAdd
2194 #define InterlockedCompareExchange _InterlockedCompareExchange
2195 #define InterlockedOr _InterlockedOr
2196 #define InterlockedAnd _InterlockedAnd
2197 #define InterlockedXor _InterlockedXor
2198
2199 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
2200
2201 #endif // defined (_X86_)
2202
2203 #if !defined (_WIN64)
2204 /*
2205 * PVOID
2206 * InterlockedExchangePointer(
2207 * IN OUT PVOID volatile *Target,
2208 * IN PVOID Value)
2209 */
2210 #define InterlockedExchangePointer(Target, Value) \
2211 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
2212
2213 /*
2214 * PVOID
2215 * InterlockedCompareExchangePointer(
2216 * IN OUT PVOID *Destination,
2217 * IN PVOID Exchange,
2218 * IN PVOID Comparand)
2219 */
2220 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
2221 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
2222
2223 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
2224 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
2225 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
2226
2227 #endif // !defined (_WIN64)
2228
2229 #if defined (_M_AMD64)
2230
2231 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
2232 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
2233 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
2234 #define InterlockedAnd _InterlockedAnd
2235 #define InterlockedOr _InterlockedOr
2236 #define InterlockedXor _InterlockedXor
2237 #define InterlockedIncrement _InterlockedIncrement
2238 #define InterlockedDecrement _InterlockedDecrement
2239 #define InterlockedAdd _InterlockedAdd
2240 #define InterlockedExchange _InterlockedExchange
2241 #define InterlockedExchangeAdd _InterlockedExchangeAdd
2242 #define InterlockedCompareExchange _InterlockedCompareExchange
2243 #define InterlockedAnd64 _InterlockedAnd64
2244 #define InterlockedOr64 _InterlockedOr64
2245 #define InterlockedXor64 _InterlockedXor64
2246 #define InterlockedIncrement64 _InterlockedIncrement64
2247 #define InterlockedDecrement64 _InterlockedDecrement64
2248 #define InterlockedAdd64 _InterlockedAdd64
2249 #define InterlockedExchange64 _InterlockedExchange64
2250 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
2251 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
2252 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
2253 #define InterlockedExchangePointer _InterlockedExchangePointer
2254 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
2255 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
2256
2257 #endif // _M_AMD64
2258
2259 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
2260 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
2261 FORCEINLINE
2262 LONG64
2263 InterlockedAdd64(
2264 IN OUT LONG64 volatile *Addend,
2265 IN LONG64 Value)
2266 {
2267 return InterlockedExchangeAdd64(Addend, Value) + Value;
2268 }
2269 //#endif
2270 #endif
2271
2272 #endif /* !__INTERLOCKED_DECLARED */
2273
2274 #if defined(_M_IX86)
2275 #define YieldProcessor _mm_pause
2276 #elif defined (_M_AMD64)
2277 #define YieldProcessor _mm_pause
2278 #elif defined(_M_PPC)
2279 #define YieldProcessor() __asm__ __volatile__("nop");
2280 #elif defined(_M_MIPS)
2281 #define YieldProcessor() __asm__ __volatile__("nop");
2282 #elif defined(_M_ARM)
2283 #define YieldProcessor()
2284 #else
2285 #error Unknown architecture
2286 #endif
2287
2288
2289
2290 //
2291 // Slist Header
2292 //
2293 #ifndef _SLIST_HEADER_
2294 #define _SLIST_HEADER_
2295
2296 #if defined(_WIN64)
2297 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
2298 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
2299 PSLIST_ENTRY Next;
2300 } SLIST_ENTRY;
2301 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
2302 struct {
2303 ULONGLONG Alignment;
2304 ULONGLONG Region;
2305 } DUMMYSTRUCTNAME;
2306 struct {
2307 ULONGLONG Depth:16;
2308 ULONGLONG Sequence:9;
2309 ULONGLONG NextEntry:39;
2310 ULONGLONG HeaderType:1;
2311 ULONGLONG Init:1;
2312 ULONGLONG Reserved:59;
2313 ULONGLONG Region:3;
2314 } Header8;
2315 struct {
2316 ULONGLONG Depth:16;
2317 ULONGLONG Sequence:48;
2318 ULONGLONG HeaderType:1;
2319 ULONGLONG Init:1;
2320 ULONGLONG Reserved:2;
2321 ULONGLONG NextEntry:60;
2322 } Header16;
2323 } SLIST_HEADER, *PSLIST_HEADER;
2324 #else
2325 #define SLIST_ENTRY SINGLE_LIST_ENTRY
2326 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
2327 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
2328 typedef union _SLIST_HEADER {
2329 ULONGLONG Alignment;
2330 struct {
2331 SLIST_ENTRY Next;
2332 USHORT Depth;
2333 USHORT Sequence;
2334 } DUMMYSTRUCTNAME;
2335 } SLIST_HEADER, *PSLIST_HEADER;
2336 #endif
2337
2338 #endif /* _SLIST_HEADER_ */
2339
2340
2341
2342 //
2343 // Power States/Levels
2344 //
2345 typedef enum _SYSTEM_POWER_STATE {
2346 PowerSystemUnspecified,
2347 PowerSystemWorking,
2348 PowerSystemSleeping1,
2349 PowerSystemSleeping2,
2350 PowerSystemSleeping3,
2351 PowerSystemHibernate,
2352 PowerSystemShutdown,
2353 PowerSystemMaximum
2354 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
2355
2356 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
2357
2358 typedef enum _POWER_INFORMATION_LEVEL {
2359 SystemPowerPolicyAc,
2360 SystemPowerPolicyDc,
2361 VerifySystemPolicyAc,
2362 VerifySystemPolicyDc,
2363 SystemPowerCapabilities,
2364 SystemBatteryState,
2365 SystemPowerStateHandler,
2366 ProcessorStateHandler,
2367 SystemPowerPolicyCurrent,
2368 AdministratorPowerPolicy,
2369 SystemReserveHiberFile,
2370 ProcessorInformation,
2371 SystemPowerInformation,
2372 ProcessorStateHandler2,
2373 LastWakeTime,
2374 LastSleepTime,
2375 SystemExecutionState,
2376 SystemPowerStateNotifyHandler,
2377 ProcessorPowerPolicyAc,
2378 ProcessorPowerPolicyDc,
2379 VerifyProcessorPowerPolicyAc,
2380 VerifyProcessorPowerPolicyDc,
2381 ProcessorPowerPolicyCurrent
2382 } POWER_INFORMATION_LEVEL;
2383
2384 typedef enum {
2385 PowerActionNone,
2386 PowerActionReserved,
2387 PowerActionSleep,
2388 PowerActionHibernate,
2389 PowerActionShutdown,
2390 PowerActionShutdownReset,
2391 PowerActionShutdownOff,
2392 PowerActionWarmEject
2393 } POWER_ACTION, *PPOWER_ACTION;
2394
2395 typedef enum _DEVICE_POWER_STATE {
2396 PowerDeviceUnspecified,
2397 PowerDeviceD0,
2398 PowerDeviceD1,
2399 PowerDeviceD2,
2400 PowerDeviceD3,
2401 PowerDeviceMaximum
2402 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
2403
2404 #define ES_SYSTEM_REQUIRED 0x00000001
2405 #define ES_DISPLAY_REQUIRED 0x00000002
2406 #define ES_USER_PRESENT 0x00000004
2407 #define ES_CONTINUOUS 0x80000000
2408
2409 typedef ULONG EXECUTION_STATE;
2410
2411 typedef enum {
2412 LT_DONT_CARE,
2413 LT_LOWEST_LATENCY
2414 } LATENCY_TIME;
2415
2416
2417
2418 //
2419 // Access/Security Stuff
2420 //
2421 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
2422 typedef PVOID PACCESS_TOKEN;
2423
2424 #define DELETE 0x00010000L
2425 #define READ_CONTROL 0x00020000L
2426 #define WRITE_DAC 0x00040000L
2427 #define WRITE_OWNER 0x00080000L
2428 #define SYNCHRONIZE 0x00100000L
2429 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
2430 #define STANDARD_RIGHTS_READ READ_CONTROL
2431 #define STANDARD_RIGHTS_WRITE READ_CONTROL
2432 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
2433 #define STANDARD_RIGHTS_ALL 0x001F0000L
2434 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
2435 #define ACCESS_SYSTEM_SECURITY 0x01000000L
2436 #define MAXIMUM_ALLOWED 0x02000000L
2437 #define GENERIC_READ 0x80000000L
2438 #define GENERIC_WRITE 0x40000000L
2439 #define GENERIC_EXECUTE 0x20000000L
2440 #define GENERIC_ALL 0x10000000L
2441
2442 typedef struct _GENERIC_MAPPING {
2443 ACCESS_MASK GenericRead;
2444 ACCESS_MASK GenericWrite;
2445 ACCESS_MASK GenericExecute;
2446 ACCESS_MASK GenericAll;
2447 } GENERIC_MAPPING, *PGENERIC_MAPPING;
2448
2449 #define ACL_REVISION 2
2450 #define ACL_REVISION_DS 4
2451
2452 #define ACL_REVISION1 1
2453 #define ACL_REVISION2 2
2454 #define ACL_REVISION3 3
2455 #define ACL_REVISION4 4
2456 #define MIN_ACL_REVISION ACL_REVISION2
2457 #define MAX_ACL_REVISION ACL_REVISION4
2458
2459 typedef struct _ACL {
2460 UCHAR AclRevision;
2461 UCHAR Sbz1;
2462 USHORT AclSize;
2463 USHORT AceCount;
2464 USHORT Sbz2;
2465 } ACL, *PACL;
2466
2467
2468
2469 //
2470 // Current security descriptor revision value
2471 //
2472 #define SECURITY_DESCRIPTOR_REVISION (1)
2473 #define SECURITY_DESCRIPTOR_REVISION1 (1)
2474
2475 //
2476 // Privilege attributes
2477 //
2478 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
2479 #define SE_PRIVILEGE_ENABLED (0x00000002L)
2480 #define SE_PRIVILEGE_REMOVED (0X00000004L)
2481 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
2482
2483 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
2484 SE_PRIVILEGE_ENABLED | \
2485 SE_PRIVILEGE_REMOVED | \
2486 SE_PRIVILEGE_USED_FOR_ACCESS)
2487
2488 #include <pshpack4.h>
2489 typedef struct _LUID_AND_ATTRIBUTES {
2490 LUID Luid;
2491 ULONG Attributes;
2492 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
2493 #include <poppack.h>
2494 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
2495 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
2496
2497
2498
2499 //
2500 // Privilege sets
2501 //
2502 #define PRIVILEGE_SET_ALL_NECESSARY (1)
2503
2504 typedef struct _PRIVILEGE_SET {
2505 ULONG PrivilegeCount;
2506 ULONG Control;
2507 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
2508 } PRIVILEGE_SET,*PPRIVILEGE_SET;
2509
2510 typedef enum _SECURITY_IMPERSONATION_LEVEL {
2511 SecurityAnonymous,
2512 SecurityIdentification,
2513 SecurityImpersonation,
2514 SecurityDelegation
2515 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
2516
2517 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
2518 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
2519 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
2520 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
2521
2522 #define SECURITY_DYNAMIC_TRACKING (TRUE)
2523 #define SECURITY_STATIC_TRACKING (FALSE)
2524
2525 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
2526
2527 typedef struct _SECURITY_QUALITY_OF_SERVICE {
2528 ULONG Length;
2529 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2530 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
2531 BOOLEAN EffectiveOnly;
2532 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
2533
2534 typedef struct _SE_IMPERSONATION_STATE {
2535 PACCESS_TOKEN Token;
2536 BOOLEAN CopyOnOpen;
2537 BOOLEAN EffectiveOnly;
2538 SECURITY_IMPERSONATION_LEVEL Level;
2539 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
2540
2541 #define OWNER_SECURITY_INFORMATION (0x00000001L)
2542 #define GROUP_SECURITY_INFORMATION (0x00000002L)
2543 #define DACL_SECURITY_INFORMATION (0x00000004L)
2544 #define SACL_SECURITY_INFORMATION (0x00000008L)
2545 #define LABEL_SECURITY_INFORMATION (0x00000010L)
2546
2547 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
2548 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
2549 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
2550 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
2551
2552
2553
2554 //
2555 // Registry Access Rights
2556 //
2557 #define KEY_QUERY_VALUE (0x0001)
2558 #define KEY_SET_VALUE (0x0002)
2559 #define KEY_CREATE_SUB_KEY (0x0004)
2560 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
2561 #define KEY_NOTIFY (0x0010)
2562 #define KEY_CREATE_LINK (0x0020)
2563 #define KEY_WOW64_32KEY (0x0200)
2564 #define KEY_WOW64_64KEY (0x0100)
2565 #define KEY_WOW64_RES (0x0300)
2566
2567 #define KEY_READ ((STANDARD_RIGHTS_READ |\
2568 KEY_QUERY_VALUE |\
2569 KEY_ENUMERATE_SUB_KEYS |\
2570 KEY_NOTIFY) \
2571 & \
2572 (~SYNCHRONIZE))
2573
2574 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
2575 KEY_SET_VALUE |\
2576 KEY_CREATE_SUB_KEY) \
2577 & \
2578 (~SYNCHRONIZE))
2579
2580 #define KEY_EXECUTE ((KEY_READ) \
2581 & \
2582 (~SYNCHRONIZE))
2583
2584 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
2585 KEY_QUERY_VALUE |\
2586 KEY_SET_VALUE |\
2587 KEY_CREATE_SUB_KEY |\
2588 KEY_ENUMERATE_SUB_KEYS |\
2589 KEY_NOTIFY |\
2590 KEY_CREATE_LINK) \
2591 & \
2592 (~SYNCHRONIZE))
2593
2594 //
2595 // Registry Open/Create Options
2596 //
2597 #define REG_OPTION_RESERVED (0x00000000L)
2598 #define REG_OPTION_NON_VOLATILE (0x00000000L)
2599 #define REG_OPTION_VOLATILE (0x00000001L)
2600 #define REG_OPTION_CREATE_LINK (0x00000002L)
2601 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
2602 #define REG_OPTION_OPEN_LINK (0x00000008L)
2603
2604 #define REG_LEGAL_OPTION \
2605 (REG_OPTION_RESERVED |\
2606 REG_OPTION_NON_VOLATILE |\
2607 REG_OPTION_VOLATILE |\
2608 REG_OPTION_CREATE_LINK |\
2609 REG_OPTION_BACKUP_RESTORE |\
2610 REG_OPTION_OPEN_LINK)
2611
2612 //
2613 // Key creation/open disposition
2614 //
2615 #define REG_CREATED_NEW_KEY (0x00000001L)
2616 #define REG_OPENED_EXISTING_KEY (0x00000002L)
2617
2618 //
2619 // Key restore & hive load flags
2620 //
2621 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
2622 #define REG_REFRESH_HIVE (0x00000002L)
2623 #define REG_NO_LAZY_FLUSH (0x00000004L)
2624 #define REG_FORCE_RESTORE (0x00000008L)
2625 #define REG_APP_HIVE (0x00000010L)
2626 #define REG_PROCESS_PRIVATE (0x00000020L)
2627 #define REG_START_JOURNAL (0x00000040L)
2628 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
2629 #define REG_HIVE_NO_RM (0x00000100L)
2630 #define REG_HIVE_SINGLE_LOG (0x00000200L)
2631
2632 //
2633 // Unload Flags
2634 //
2635 #define REG_FORCE_UNLOAD 1
2636
2637 //
2638 // Notify Filter Values
2639 //
2640 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
2641 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
2642 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
2643 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
2644
2645 #define REG_LEGAL_CHANGE_FILTER \
2646 (REG_NOTIFY_CHANGE_NAME |\
2647 REG_NOTIFY_CHANGE_ATTRIBUTES |\
2648 REG_NOTIFY_CHANGE_LAST_SET |\
2649 REG_NOTIFY_CHANGE_SECURITY)
2650
2651
2652
2653 //
2654 // Thread Access Rights
2655 //
2656 #define THREAD_TERMINATE (0x0001)
2657 #define THREAD_SUSPEND_RESUME (0x0002)
2658 #define THREAD_ALERT (0x0004)
2659 #define THREAD_GET_CONTEXT (0x0008)
2660 #define THREAD_SET_CONTEXT (0x0010)
2661 #define THREAD_SET_INFORMATION (0x0020)
2662 #define THREAD_SET_LIMITED_INFORMATION (0x0400)
2663 #define THREAD_QUERY_LIMITED_INFORMATION (0x0800)
2664 #if (NTDDI_VERSION >= NTDDI_VISTA)
2665 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
2666 0xFFFF)
2667 #else
2668 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
2669 0x3FF)
2670 #endif
2671
2672 //
2673 // Service Start Types
2674 //
2675 #define SERVICE_BOOT_START 0x00000000
2676 #define SERVICE_SYSTEM_START 0x00000001
2677 #define SERVICE_AUTO_START 0x00000002
2678 #define SERVICE_DEMAND_START 0x00000003
2679 #define SERVICE_DISABLED 0x00000004
2680
2681 //
2682 // Exception Records
2683 //
2684 #define EXCEPTION_NONCONTINUABLE 1
2685 #define EXCEPTION_MAXIMUM_PARAMETERS 15
2686
2687 typedef struct _EXCEPTION_RECORD {
2688 NTSTATUS ExceptionCode;
2689 ULONG ExceptionFlags;
2690 struct _EXCEPTION_RECORD *ExceptionRecord;
2691 PVOID ExceptionAddress;
2692 ULONG NumberParameters;
2693 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2694 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
2695
2696 typedef struct _EXCEPTION_RECORD32 {
2697 NTSTATUS ExceptionCode;
2698 ULONG ExceptionFlags;
2699 ULONG ExceptionRecord;
2700 ULONG ExceptionAddress;
2701 ULONG NumberParameters;
2702 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2703 } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
2704
2705 typedef struct _EXCEPTION_RECORD64 {
2706 NTSTATUS ExceptionCode;
2707 ULONG ExceptionFlags;
2708 ULONG64 ExceptionRecord;
2709 ULONG64 ExceptionAddress;
2710 ULONG NumberParameters;
2711 ULONG __unusedAlignment;
2712 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2713 } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
2714
2715 typedef struct _EXCEPTION_POINTERS {
2716 PEXCEPTION_RECORD ExceptionRecord;
2717 PCONTEXT ContextRecord;
2718 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
2719
2720
2721
2722 //
2723 // Process Qoutas
2724 //
2725 typedef struct _QUOTA_LIMITS {
2726 SIZE_T PagedPoolLimit;
2727 SIZE_T NonPagedPoolLimit;
2728 SIZE_T MinimumWorkingSetSize;
2729 SIZE_T MaximumWorkingSetSize;
2730 SIZE_T PagefileLimit;
2731 LARGE_INTEGER TimeLimit;
2732 } QUOTA_LIMITS, *PQUOTA_LIMITS;
2733
2734 #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
2735 #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
2736 #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
2737 #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
2738 #define QUOTA_LIMITS_USE_DEFAULT_LIMITS 0x00000010
2739
2740
2741 /******************************************************************************
2742 * WINBASE Functions *
2743 ******************************************************************************/
2744 #if !defined(_WINBASE_)
2745
2746 #if defined(_WIN64)
2747
2748 #define InterlockedPopEntrySList(Head) \
2749 ExpInterlockedPopEntrySList(Head)
2750
2751 #define InterlockedPushEntrySList(Head, Entry) \
2752 ExpInterlockedPushEntrySList(Head, Entry)
2753
2754 #define InterlockedFlushSList(Head) \
2755 ExpInterlockedFlushSList(Head)
2756
2757 #define QueryDepthSList(Head) \
2758 ExQueryDepthSList(Head)
2759
2760 #else // !defined(_WIN64)
2761
2762 NTKERNELAPI
2763 PSLIST_ENTRY
2764 FASTCALL
2765 InterlockedPopEntrySList(
2766 IN PSLIST_HEADER ListHead);
2767
2768 NTKERNELAPI
2769 PSLIST_ENTRY
2770 FASTCALL
2771 InterlockedPushEntrySList(
2772 IN PSLIST_HEADER ListHead,
2773 IN PSLIST_ENTRY ListEntry);
2774
2775 #define InterlockedFlushSList(ListHead) \
2776 ExInterlockedFlushSList(ListHead)
2777
2778 #define QueryDepthSList(Head) \
2779 ExQueryDepthSList(Head)
2780
2781 #endif // !defined(_WIN64)
2782
2783 #endif // !defined(_WINBASE_)
2784
2785
2786 /******************************************************************************
2787 * Kernel Types *
2788 ******************************************************************************/
2789
2790 typedef struct _DISPATCHER_HEADER
2791 {
2792 __GNU_EXTENSION union
2793 {
2794 __GNU_EXTENSION struct
2795 {
2796 UCHAR Type;
2797 __GNU_EXTENSION union
2798 {
2799 UCHAR Absolute;
2800 UCHAR NpxIrql;
2801 };
2802 __GNU_EXTENSION union
2803 {
2804 UCHAR Size;
2805 UCHAR Hand;
2806 };
2807 __GNU_EXTENSION union
2808 {
2809 UCHAR Inserted;
2810 BOOLEAN DebugActive;
2811 };
2812 };
2813 volatile LONG Lock;
2814 };
2815 LONG SignalState;
2816 LIST_ENTRY WaitListHead;
2817 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
2818
2819 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
2820
2821 typedef struct _KEVENT {
2822 DISPATCHER_HEADER Header;
2823 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
2824
2825 typedef struct _KSEMAPHORE {
2826 DISPATCHER_HEADER Header;
2827 LONG Limit;
2828 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
2829
2830 /******************************************************************************
2831 * RTL Types *
2832 ******************************************************************************/
2833
2834 #define RTL_REGISTRY_ABSOLUTE 0
2835 #define RTL_REGISTRY_SERVICES 1
2836 #define RTL_REGISTRY_CONTROL 2
2837 #define RTL_REGISTRY_WINDOWS_NT 3
2838 #define RTL_REGISTRY_DEVICEMAP 4
2839 #define RTL_REGISTRY_USER 5
2840 #define RTL_REGISTRY_MAXIMUM 6
2841 #define RTL_REGISTRY_HANDLE 0x40000000
2842 #define RTL_REGISTRY_OPTIONAL 0x80000000
2843
2844 /* RTL_QUERY_REGISTRY_TABLE.Flags */
2845 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
2846 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
2847 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
2848 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
2849 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
2850 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
2851 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
2852
2853 typedef struct _RTL_BITMAP {
2854 ULONG SizeOfBitMap;
2855 PULONG Buffer;
2856 } RTL_BITMAP, *PRTL_BITMAP;
2857
2858 typedef struct _RTL_BITMAP_RUN {
2859 ULONG StartingIndex;
2860 ULONG NumberOfBits;
2861 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
2862
2863 typedef NTSTATUS
2864 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
2865 IN PWSTR ValueName,
2866 IN ULONG ValueType,
2867 IN PVOID ValueData,
2868 IN ULONG ValueLength,
2869 IN PVOID Context,
2870 IN PVOID EntryContext);
2871
2872 typedef struct _RTL_QUERY_REGISTRY_TABLE {
2873 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
2874 ULONG Flags;
2875 PCWSTR Name;
2876 PVOID EntryContext;
2877 ULONG DefaultType;
2878 PVOID DefaultData;
2879 ULONG DefaultLength;
2880 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
2881
2882 typedef struct _TIME_FIELDS {
2883 CSHORT Year;
2884 CSHORT Month;
2885 CSHORT Day;
2886 CSHORT Hour;
2887 CSHORT Minute;
2888 CSHORT Second;
2889 CSHORT Milliseconds;
2890 CSHORT Weekday;
2891 } TIME_FIELDS, *PTIME_FIELDS;
2892
2893
2894 /******************************************************************************
2895 * RTL Functions *
2896 ******************************************************************************/
2897
2898 NTSYSAPI
2899 VOID
2900 NTAPI
2901 RtlAssert(
2902 IN PVOID FailedAssertion,
2903 IN PVOID FileName,
2904 IN ULONG LineNumber,
2905 IN PCHAR Message);
2906
2907 /* VOID
2908 * RtlCopyMemory(
2909 * IN VOID UNALIGNED *Destination,
2910 * IN CONST VOID UNALIGNED *Source,
2911 * IN SIZE_T Length)
2912 */
2913 #define RtlCopyMemory(Destination, Source, Length) \
2914 memcpy(Destination, Source, Length)
2915
2916 #define RtlCopyBytes RtlCopyMemory
2917
2918 #if defined(_M_AMD64)
2919 NTSYSAPI
2920 VOID
2921 NTAPI
2922 RtlCopyMemoryNonTemporal(
2923 VOID UNALIGNED *Destination,
2924 CONST VOID UNALIGNED *Source,
2925 SIZE_T Length);
2926 #else
2927 #define RtlCopyMemoryNonTemporal RtlCopyMemory
2928 #endif
2929
2930 /* BOOLEAN
2931 * RtlEqualLuid(
2932 * IN PLUID Luid1,
2933 * IN PLUID Luid2)
2934 */
2935 #define RtlEqualLuid(Luid1, Luid2) \
2936 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
2937
2938 /* ULONG
2939 * RtlEqualMemory(
2940 * IN VOID UNALIGNED *Destination,
2941 * IN CONST VOID UNALIGNED *Source,
2942 * IN SIZE_T Length)
2943 */
2944 #define RtlEqualMemory(Destination, Source, Length) \
2945 (!memcmp(Destination, Source, Length))
2946
2947 /* VOID
2948 * RtlFillMemory(
2949 * IN VOID UNALIGNED *Destination,
2950 * IN SIZE_T Length,
2951 * IN UCHAR Fill)
2952 */
2953 #define RtlFillMemory(Destination, Length, Fill) \
2954 memset(Destination, Fill, Length)
2955
2956 #define RtlFillBytes RtlFillMemory
2957
2958 NTSYSAPI
2959 VOID
2960 NTAPI
2961 RtlFreeUnicodeString(
2962 IN PUNICODE_STRING UnicodeString);
2963
2964 NTSYSAPI
2965 NTSTATUS
2966 NTAPI
2967 RtlGUIDFromString(
2968 IN PUNICODE_STRING GuidString,
2969 OUT GUID *Guid);
2970
2971 NTSYSAPI
2972 VOID
2973 NTAPI
2974 RtlInitUnicodeString(
2975 IN OUT PUNICODE_STRING DestinationString,
2976 IN PCWSTR SourceString);
2977
2978 /* VOID
2979 * RtlMoveMemory(
2980 * IN VOID UNALIGNED *Destination,
2981 * IN CONST VOID UNALIGNED *Source,
2982 * IN SIZE_T Length)
2983 */
2984 #define RtlMoveMemory(Destination, Source, Length) \
2985 memmove(Destination, Source, Length)
2986
2987 NTSYSAPI
2988 NTSTATUS
2989 NTAPI
2990 RtlStringFromGUID(
2991 IN REFGUID Guid,
2992 OUT PUNICODE_STRING GuidString);
2993
2994 /* VOID
2995 * RtlZeroMemory(
2996 * IN VOID UNALIGNED *Destination,
2997 * IN SIZE_T Length)
2998 */
2999 #define RtlZeroMemory(Destination, Length) \
3000 memset(Destination, 0, Length)
3001
3002 #define RtlZeroBytes RtlZeroMemory
3003
3004
3005 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3006 NTSYSAPI
3007 BOOLEAN
3008 NTAPI
3009 RtlAreBitsClear(
3010 IN PRTL_BITMAP BitMapHeader,
3011 IN ULONG StartingIndex,
3012 IN ULONG Length);
3013
3014 NTSYSAPI
3015 BOOLEAN
3016 NTAPI
3017 RtlAreBitsSet(
3018 IN PRTL_BITMAP BitMapHeader,
3019 IN ULONG StartingIndex,
3020 IN ULONG Length);
3021
3022 NTSYSAPI
3023 NTSTATUS
3024 NTAPI
3025 RtlAnsiStringToUnicodeString(
3026 IN OUT PUNICODE_STRING DestinationString,
3027 IN PANSI_STRING SourceString,
3028 IN BOOLEAN AllocateDestinationString);
3029
3030 NTSYSAPI
3031 ULONG
3032 NTAPI
3033 RtlxAnsiStringToUnicodeSize(
3034 IN PCANSI_STRING AnsiString);
3035
3036 #define RtlAnsiStringToUnicodeSize(String) ( \
3037 NLS_MB_CODE_PAGE_TAG ? \
3038 RtlxAnsiStringToUnicodeSize(String) : \
3039 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
3040 )
3041
3042 NTSYSAPI
3043 NTSTATUS
3044 NTAPI
3045 RtlAppendUnicodeStringToString(
3046 IN OUT PUNICODE_STRING Destination,
3047 IN PCUNICODE_STRING Source);
3048
3049 NTSYSAPI
3050 NTSTATUS
3051 NTAPI
3052 RtlAppendUnicodeToString(
3053 IN OUT PUNICODE_STRING Destination,
3054 IN PCWSTR Source);
3055
3056 NTSYSAPI
3057 NTSTATUS
3058 NTAPI
3059 RtlCheckRegistryKey(
3060 IN ULONG RelativeTo,
3061 IN PWSTR Path);
3062
3063 NTSYSAPI
3064 VOID
3065 NTAPI
3066 RtlClearAllBits(
3067 IN PRTL_BITMAP BitMapHeader);
3068
3069 NTSYSAPI
3070 VOID
3071 NTAPI
3072 RtlClearBits(
3073 IN PRTL_BITMAP BitMapHeader,
3074 IN ULONG StartingIndex,
3075 IN ULONG NumberToClear);
3076
3077 NTSYSAPI
3078 SIZE_T
3079 NTAPI
3080 RtlCompareMemory(
3081 IN CONST VOID *Source1,
3082 IN CONST VOID *Source2,
3083 IN SIZE_T Length);
3084
3085 NTSYSAPI
3086 LONG
3087 NTAPI
3088 RtlCompareUnicodeString(
3089 IN PCUNICODE_STRING String1,
3090 IN PCUNICODE_STRING String2,
3091 IN BOOLEAN CaseInSensitive);
3092
3093 NTSYSAPI
3094 LONG
3095 NTAPI
3096 RtlCompareUnicodeStrings(
3097 IN PCWCH String1,
3098 IN SIZE_T String1Length,
3099 IN PCWCH String2,
3100 IN SIZE_T String2Length,
3101 IN BOOLEAN CaseInSensitive);
3102
3103 NTSYSAPI
3104 VOID
3105 NTAPI
3106 RtlCopyUnicodeString(
3107 IN OUT PUNICODE_STRING DestinationString,
3108 IN PCUNICODE_STRING SourceString);
3109
3110 NTSYSAPI
3111 NTSTATUS
3112 NTAPI
3113 RtlCreateRegistryKey(
3114 IN ULONG RelativeTo,
3115 IN PWSTR Path);
3116
3117 NTSYSAPI
3118 NTSTATUS
3119 NTAPI
3120 RtlCreateSecurityDescriptor(
3121 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3122 IN ULONG Revision);
3123
3124 NTSYSAPI
3125 NTSTATUS
3126 NTAPI
3127 RtlDeleteRegistryValue(
3128 IN ULONG RelativeTo,
3129 IN PCWSTR Path,
3130 IN PCWSTR ValueName);
3131
3132 NTSYSAPI
3133 BOOLEAN
3134 NTAPI
3135 RtlEqualUnicodeString(
3136 IN CONST UNICODE_STRING *String1,
3137 IN CONST UNICODE_STRING *String2,
3138 IN BOOLEAN CaseInSensitive);
3139
3140 #if !defined(_AMD64_) && !defined(_IA64_)
3141 NTSYSAPI
3142 LARGE_INTEGER
3143 NTAPI
3144 RtlExtendedIntegerMultiply(
3145 IN LARGE_INTEGER Multiplicand,
3146 IN LONG Multiplier);
3147
3148 NTSYSAPI
3149 LARGE_INTEGER
3150 NTAPI
3151 RtlExtendedLargeIntegerDivide(
3152 IN LARGE_INTEGER Dividend,
3153 IN ULONG Divisor,
3154 IN OUT PULONG Remainder);
3155 #endif
3156
3157 #if defined(_X86_) || defined(_IA64_)
3158 NTSYSAPI
3159 LARGE_INTEGER
3160 NTAPI
3161 RtlExtendedMagicDivide(
3162 IN LARGE_INTEGER Dividend,
3163 IN LARGE_INTEGER MagicDivisor,
3164 IN CCHAR ShiftCount);
3165 #endif
3166
3167 NTSYSAPI
3168 VOID
3169 NTAPI
3170 RtlFreeAnsiString(
3171 IN PANSI_STRING AnsiString);
3172
3173 NTSYSAPI
3174 ULONG
3175 NTAPI
3176 RtlFindClearBits(
3177 IN PRTL_BITMAP BitMapHeader,
3178 IN ULONG NumberToFind,
3179 IN ULONG HintIndex);
3180
3181 NTSYSAPI
3182 ULONG
3183 NTAPI
3184 RtlFindClearBitsAndSet(
3185 IN PRTL_BITMAP BitMapHeader,
3186 IN ULONG NumberToFind,
3187 IN ULONG HintIndex);
3188
3189 NTSYSAPI
3190 ULONG
3191 NTAPI
3192 RtlFindFirstRunClear(
3193 IN PRTL_BITMAP BitMapHeader,
3194 OUT PULONG StartingIndex);
3195
3196 NTSYSAPI
3197 ULONG
3198 NTAPI
3199 RtlFindClearRuns(
3200 IN PRTL_BITMAP BitMapHeader,
3201 OUT PRTL_BITMAP_RUN RunArray,
3202 IN ULONG SizeOfRunArray,
3203 IN BOOLEAN LocateLongestRuns);
3204
3205 NTSYSAPI
3206 ULONG
3207 NTAPI
3208 RtlFindLastBackwardRunClear(
3209 IN PRTL_BITMAP BitMapHeader,
3210 IN ULONG FromIndex,
3211 OUT PULONG StartingRunIndex);
3212
3213 NTSYSAPI
3214 CCHAR
3215 NTAPI
3216 RtlFindLeastSignificantBit(
3217 IN ULONGLONG Set);
3218
3219 NTSYSAPI
3220 ULONG
3221 NTAPI
3222 RtlFindLongestRunClear(
3223 IN PRTL_BITMAP BitMapHeader,
3224 OUT PULONG StartingIndex);
3225
3226 NTSYSAPI
3227 CCHAR
3228 NTAPI
3229 RtlFindMostSignificantBit(
3230 IN ULONGLONG Set);
3231
3232 NTSYSAPI
3233 ULONG
3234 NTAPI
3235 RtlFindNextForwardRunClear(
3236 IN PRTL_BITMAP BitMapHeader,
3237 IN ULONG FromIndex,
3238 OUT PULONG StartingRunIndex);
3239
3240 NTSYSAPI
3241 ULONG
3242 NTAPI
3243 RtlFindSetBits(
3244 IN PRTL_BITMAP BitMapHeader,
3245 IN ULONG NumberToFind,
3246 IN ULONG HintIndex);
3247
3248 NTSYSAPI
3249 ULONG
3250 NTAPI
3251 RtlFindSetBitsAndClear(
3252 IN PRTL_BITMAP BitMapHeader,
3253 IN ULONG NumberToFind,
3254 IN ULONG HintIndex);
3255
3256 NTSYSAPI
3257 NTSTATUS
3258 NTAPI
3259 RtlHashUnicodeString(
3260 IN CONST UNICODE_STRING *String,
3261 IN BOOLEAN CaseInSensitive,
3262 IN ULONG HashAlgorithm,
3263 OUT PULONG HashValue);
3264
3265 NTSYSAPI
3266 VOID
3267 NTAPI
3268 RtlInitAnsiString(
3269 IN OUT PANSI_STRING DestinationString,
3270 IN PCSZ SourceString);
3271
3272 NTSYSAPI
3273 VOID
3274 NTAPI
3275 RtlInitializeBitMap(
3276 IN PRTL_BITMAP BitMapHeader,
3277 IN PULONG BitMapBuffer,
3278 IN ULONG SizeOfBitMap);
3279
3280 NTSYSAPI
3281 VOID
3282 NTAPI
3283 RtlInitString(
3284 IN OUT PSTRING DestinationString,
3285 IN PCSZ SourceString);
3286
3287 NTSYSAPI
3288 NTSTATUS
3289 NTAPI
3290 RtlIntegerToUnicodeString(
3291 IN ULONG Value,
3292 IN ULONG Base OPTIONAL,
3293 IN OUT PUNICODE_STRING String);
3294
3295 NTSYSAPI
3296 NTSTATUS
3297 NTAPI
3298 RtlInt64ToUnicodeString(
3299 IN ULONGLONG Value,
3300 IN ULONG Base OPTIONAL,
3301 IN OUT PUNICODE_STRING String);
3302
3303 #ifdef _WIN64
3304 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3305 RtlInt64ToUnicodeString(Value, Base, String)
3306 #else
3307 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3308 RtlIntegerToUnicodeString(Value, Base, String)
3309 #endif
3310
3311 /* BOOLEAN
3312 * RtlIsZeroLuid(
3313 * IN PLUID L1);
3314 */
3315 #define RtlIsZeroLuid(_L1) \
3316 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
3317
3318 NTSYSAPI
3319 ULONG
3320 NTAPI
3321 RtlLengthSecurityDescriptor(
3322 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3323
3324 NTSYSAPI
3325 ULONG
3326 NTAPI
3327 RtlNumberOfClearBits(
3328 IN PRTL_BITMAP BitMapHeader);
3329
3330 NTSYSAPI
3331 ULONG
3332 NTAPI
3333 RtlNumberOfSetBits(
3334 IN PRTL_BITMAP BitMapHeader);
3335
3336 NTSYSAPI
3337 NTSTATUS
3338 NTAPI
3339 RtlQueryRegistryValues(
3340 IN ULONG RelativeTo,
3341 IN PCWSTR Path,
3342 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
3343 IN PVOID Context,
3344 IN PVOID Environment OPTIONAL);
3345
3346 #define LONG_SIZE (sizeof(LONG))
3347 #define LONG_MASK (LONG_SIZE - 1)
3348
3349 /* VOID
3350 * RtlRetrieveUlong(
3351 * PULONG DestinationAddress,
3352 * PULONG SourceAddress);
3353 */
3354 #if defined(_AMD64_)
3355 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3356 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
3357 #else
3358 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3359 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3360 { \
3361 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3362 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3363 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
3364 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
3365 } \
3366 else \
3367 { \
3368 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
3369 }
3370 #endif
3371
3372 /* VOID
3373 * RtlRetrieveUshort(
3374 * PUSHORT DestinationAddress,
3375 * PUSHORT SourceAddress);
3376 */
3377 #if defined(_AMD64_)
3378 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3379 *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
3380 #else
3381 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3382 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3383 { \
3384 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3385 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3386 } \
3387 else \
3388 { \
3389 *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
3390 }
3391 #endif
3392
3393 NTSYSAPI
3394 VOID
3395 NTAPI
3396 RtlSetAllBits(
3397 IN PRTL_BITMAP BitMapHeader);
3398
3399 NTSYSAPI
3400 VOID
3401 NTAPI
3402 RtlSetBits(
3403 IN PRTL_BITMAP BitMapHeader,
3404 IN ULONG StartingIndex,
3405 IN ULONG NumberToSet);
3406
3407 NTSYSAPI
3408 NTSTATUS
3409 NTAPI
3410 RtlSetDaclSecurityDescriptor(
3411 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3412 IN BOOLEAN DaclPresent,
3413 IN PACL Dacl OPTIONAL,
3414 IN BOOLEAN DaclDefaulted OPTIONAL);
3415
3416 /* VOID
3417 * RtlStoreUlong(
3418 * IN PULONG Address,
3419 * IN ULONG Value);
3420 */
3421 #if defined(_AMD64_)
3422 #define RtlStoreUlong(Address,Value) \
3423 *(ULONG UNALIGNED *)(Address) = (Value)
3424 #else
3425 #define RtlStoreUlong(Address,Value) \
3426 if ((ULONG_PTR)(Address) & LONG_MASK) { \
3427 ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3428 ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
3429 ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
3430 ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT] = (UCHAR)(FOURTHBYTE(Value)); \
3431 } \
3432 else { \
3433 *((PULONG)(Address)) = (ULONG) (Value); \
3434 }
3435 #endif
3436
3437 /* VOID
3438 * RtlStoreUlonglong(
3439 * IN OUT PULONGLONG Address,
3440 * ULONGLONG Value);
3441 */
3442 #if defined(_AMD64_)
3443 #define RtlStoreUlonglong(Address,Value) \
3444 *(ULONGLONG UNALIGNED *)(Address) = (Value)
3445 #else
3446 #define RtlStoreUlonglong(Address,Value) \
3447 if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
3448 RtlStoreUlong((ULONG_PTR)(Address), \
3449 (ULONGLONG)(Value) & 0xFFFFFFFF); \
3450 RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
3451 (ULONGLONG)(Value) >> 32); \
3452 } else { \
3453 *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
3454 }
3455 #endif
3456
3457 /* VOID
3458 * RtlStoreUlongPtr(
3459 * IN OUT PULONG_PTR Address,
3460 * IN ULONG_PTR Value);
3461 */
3462 #ifdef _WIN64
3463 #define RtlStoreUlongPtr(Address,Value) \
3464 RtlStoreUlonglong(Address,Value)
3465 #else
3466 #define RtlStoreUlongPtr(Address,Value) \
3467 RtlStoreUlong(Address,Value)
3468 #endif
3469
3470 /* VOID
3471 * RtlStoreUshort(
3472 * IN PUSHORT Address,
3473 * IN USHORT Value);
3474 */
3475 #if defined(_AMD64_)
3476 #define RtlStoreUshort(Address,Value) \
3477 *(USHORT UNALIGNED *)(Address) = (Value)
3478 #else
3479 #define RtlStoreUshort(Address,Value) \
3480 if ((ULONG_PTR)(Address) & SHORT_MASK) { \
3481 ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3482 ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
3483 } \
3484 else { \
3485 *((PUSHORT) (Address)) = (USHORT)Value; \
3486 }
3487 #endif
3488
3489 NTSYSAPI
3490 BOOLEAN
3491 NTAPI
3492 RtlTimeFieldsToTime(
3493 IN PTIME_FIELDS TimeFields,
3494 IN PLARGE_INTEGER Time);
3495
3496 NTSYSAPI
3497 VOID
3498 NTAPI
3499 RtlTimeToTimeFields(
3500 IN PLARGE_INTEGER Time,
3501 IN PTIME_FIELDS TimeFields);
3502
3503 NTSYSAPI
3504 ULONG
3505 FASTCALL
3506 RtlUlongByteSwap(
3507 IN ULONG Source);
3508
3509 NTSYSAPI
3510 ULONGLONG
3511 FASTCALL
3512 RtlUlonglongByteSwap(
3513 IN ULONGLONG Source);
3514
3515 NTSYSAPI
3516 NTSTATUS
3517 NTAPI
3518 RtlUnicodeStringToAnsiString(
3519 IN OUT PANSI_STRING DestinationString,
3520 IN PCUNICODE_STRING SourceString,
3521 IN BOOLEAN AllocateDestinationString);
3522
3523 NTSYSAPI
3524 ULONG
3525 NTAPI
3526 RtlxUnicodeStringToAnsiSize(
3527 IN PCUNICODE_STRING UnicodeString);
3528
3529 #define RtlUnicodeStringToAnsiSize(String) ( \
3530 NLS_MB_CODE_PAGE_TAG ? \
3531 RtlxUnicodeStringToAnsiSize(String) : \
3532 ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
3533 )
3534
3535 NTSYSAPI
3536 NTSTATUS
3537 NTAPI
3538 RtlUnicodeStringToInteger(
3539 IN PCUNICODE_STRING String,
3540 IN ULONG Base OPTIONAL,
3541 OUT PULONG Value);
3542
3543 NTSYSAPI
3544 WCHAR
3545 NTAPI
3546 RtlUpcaseUnicodeChar(
3547 IN WCHAR SourceCharacter);
3548
3549 NTSYSAPI
3550 USHORT
3551 FASTCALL
3552 RtlUshortByteSwap(
3553 IN USHORT Source);
3554
3555 NTSYSAPI
3556 BOOLEAN
3557 NTAPI
3558 RtlValidRelativeSecurityDescriptor(
3559 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
3560 IN ULONG SecurityDescriptorLength,
3561 IN SECURITY_INFORMATION RequiredInformation);
3562
3563 NTSYSAPI
3564 BOOLEAN
3565 NTAPI
3566 RtlValidSecurityDescriptor(
3567 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3568
3569 NTSYSAPI
3570 NTSTATUS
3571 NTAPI
3572 RtlWriteRegistryValue(
3573 IN ULONG RelativeTo,
3574 IN PCWSTR Path,
3575 IN PCWSTR ValueName,
3576 IN ULONG ValueType,
3577 IN PVOID ValueData,
3578 IN ULONG ValueLength);
3579
3580 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
3581
3582 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
3583 NTSYSAPI
3584 VOID
3585 FASTCALL
3586 RtlPrefetchMemoryNonTemporal(
3587 IN PVOID Source,
3588 IN SIZE_T Length);
3589 #endif
3590
3591 #if (NTDDI_VERSION >= NTDDI_WINXP)
3592 NTSYSAPI
3593 VOID
3594 NTAPI
3595 RtlClearBit(
3596 PRTL_BITMAP BitMapHeader,
3597 ULONG BitNumber);
3598
3599 NTSYSAPI
3600 WCHAR
3601 NTAPI
3602 RtlDowncaseUnicodeChar(
3603 IN WCHAR SourceCharacter);
3604
3605 NTSYSAPI
3606 VOID
3607 NTAPI
3608 RtlSetBit(
3609 PRTL_BITMAP BitMapHeader,
3610 ULONG BitNumber);
3611
3612 NTSYSAPI
3613 BOOLEAN
3614 NTAPI
3615 RtlTestBit(
3616 IN PRTL_BITMAP BitMapHeader,
3617 IN ULONG BitNumber);
3618
3619 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
3620
3621 #if (NTDDI_VERSION >= NTDDI_VISTA)
3622 NTSYSAPI
3623 ULONG
3624 NTAPI
3625 RtlNumberOfSetBitsUlongPtr(
3626 IN ULONG_PTR Target);
3627
3628 NTSYSAPI
3629 ULONGLONG
3630 NTAPI
3631 RtlIoDecodeMemIoResource (
3632 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
3633 OUT PULONGLONG Alignment OPTIONAL,
3634 OUT PULONGLONG MinimumAddress OPTIONAL,
3635 OUT PULONGLONG MaximumAddress OPTIONAL);
3636
3637 NTSYSAPI
3638 NTSTATUS
3639 NTAPI
3640 RtlIoEncodeMemIoResource(
3641 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
3642 IN UCHAR Type,
3643 IN ULONGLONG Length,
3644 IN ULONGLONG Alignment,
3645 IN ULONGLONG MinimumAddress,
3646 IN ULONGLONG MaximumAddress);
3647
3648 NTSYSAPI
3649 ULONGLONG
3650 NTAPI
3651 RtlCmDecodeMemIoResource(
3652 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
3653 OUT PULONGLONG Start OPTIONAL);
3654
3655 NTSYSAPI
3656 NTSTATUS
3657 NTAPI
3658 RtlFindClosestEncodableLength(
3659 IN ULONGLONG SourceLength,
3660 OUT PULONGLONG TargetLength);
3661
3662 #endif
3663
3664 #if !defined(MIDL_PASS)
3665 /* inline funftions */
3666 //DECLSPEC_DEPRECATED_DDK_WINXP
3667 static __inline
3668 LARGE_INTEGER
3669 NTAPI_INLINE
3670 RtlConvertLongToLargeInteger(LONG SignedInteger)
3671 {
3672 LARGE_INTEGER ret;
3673 ret.QuadPart = SignedInteger;
3674 return ret;
3675 }
3676
3677 //DECLSPEC_DEPRECATED_DDK_WINXP
3678 static __inline
3679 LARGE_INTEGER
3680 NTAPI_INLINE
3681 RtlConvertUlongToLargeInteger(
3682 ULONG UnsignedInteger)
3683 {
3684 LARGE_INTEGER ret;
3685 ret.QuadPart = UnsignedInteger;
3686 return ret;
3687 }
3688
3689 //DECLSPEC_DEPRECATED_DDK
3690 static __inline
3691 ULONG
3692 NTAPI_INLINE
3693 RtlEnlargedUnsignedDivide(
3694 IN ULARGE_INTEGER Dividend,
3695 IN ULONG Divisor,
3696 IN OUT PULONG Remainder)
3697 {
3698 if (Remainder)
3699 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3700 return (ULONG)(Dividend.QuadPart / Divisor);
3701 }
3702
3703 //DECLSPEC_DEPRECATED_DDK
3704 static __inline
3705 LARGE_INTEGER
3706 NTAPI_INLINE
3707 RtlEnlargedUnsignedMultiply(
3708 IN ULONG Multiplicand,
3709 IN ULONG Multiplier)
3710 {
3711 LARGE_INTEGER ret;
3712 ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3713 return ret;
3714 }
3715
3716 //DECLSPEC_DEPRECATED_DDK
3717 static __inline
3718 LARGE_INTEGER
3719 NTAPI_INLINE
3720 RtlEnlargedIntegerMultiply(
3721 IN LONG Multiplicand,
3722 IN LONG Multiplier)
3723 {
3724 LARGE_INTEGER ret;
3725 ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3726 return ret;
3727 }
3728
3729 FORCEINLINE
3730 VOID
3731 RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
3732 IN PCHAR Buffer,
3733 IN USHORT BufferSize)
3734 {
3735 AnsiString->Length = 0;
3736 AnsiString->MaximumLength = BufferSize;
3737 AnsiString->Buffer = Buffer;
3738 }
3739
3740 FORCEINLINE
3741 VOID
3742 RtlInitEmptyUnicodeString(
3743 OUT PUNICODE_STRING UnicodeString,
3744 IN PWSTR Buffer,
3745 IN USHORT BufferSize)
3746 {
3747 UnicodeString->Length = 0;
3748 UnicodeString->MaximumLength = BufferSize;
3749 UnicodeString->Buffer = Buffer;
3750 }
3751
3752 #if defined(_AMD64_) || defined(_IA64_)
3753 static __inline
3754 LARGE_INTEGER
3755 NTAPI_INLINE
3756 RtlExtendedIntegerMultiply(
3757 LARGE_INTEGER Multiplicand,
3758 LONG Multiplier)
3759 {
3760 LARGE_INTEGER ret;
3761 ret.QuadPart = Multiplicand.QuadPart * Multiplier;
3762 return ret;
3763 }
3764
3765 static __inline
3766 LARGE_INTEGER
3767 NTAPI_INLINE
3768 RtlExtendedLargeIntegerDivide(
3769 LARGE_INTEGER Dividend,
3770 ULONG Divisor,
3771 PULONG Remainder)
3772 {
3773 LARGE_INTEGER ret;
3774 ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
3775 if (Remainder)
3776 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3777 return ret;
3778 }
3779 #endif
3780
3781 #if defined(_AMD64_)
3782
3783 #define MultiplyHigh __mulh
3784 #define UnsignedMultiplyHigh __umulh
3785
3786 //DECLSPEC_DEPRECATED_DDK
3787 static __inline
3788 LARGE_INTEGER
3789 NTAPI_INLINE
3790 RtlExtendedMagicDivide(
3791 IN LARGE_INTEGER Dividend,
3792 IN LARGE_INTEGER MagicDivisor,
3793 IN CCHAR ShiftCount)
3794 {
3795 LARGE_INTEGER ret;
3796 ULONG64 ret64;
3797 BOOLEAN Pos;
3798 Pos = (Dividend.QuadPart >= 0);
3799 ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
3800 MagicDivisor.QuadPart);
3801 ret64 >>= ShiftCount;
3802 ret.QuadPart = Pos ? ret64 : -ret64;
3803 return ret;
3804 }
3805 #endif
3806
3807 //DECLSPEC_DEPRECATED_DDK
3808 static __inline
3809 LARGE_INTEGER
3810 NTAPI_INLINE
3811 RtlLargeIntegerAdd(
3812 IN LARGE_INTEGER Addend1,
3813 IN LARGE_INTEGER Addend2)
3814 {
3815 LARGE_INTEGER ret;
3816 ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
3817 return ret;
3818 }
3819
3820 /* VOID
3821 * RtlLargeIntegerAnd(
3822 * IN OUT LARGE_INTEGER Result,
3823 * IN LARGE_INTEGER Source,
3824 * IN LARGE_INTEGER Mask);
3825 */
3826 #define RtlLargeIntegerAnd(Result, Source, Mask) \
3827 Result.QuadPart = Source.QuadPart & Mask.QuadPart
3828
3829 //DECLSPEC_DEPRECATED_DDK
3830 static __inline
3831 LARGE_INTEGER
3832 NTAPI_INLINE
3833 RtlLargeIntegerArithmeticShift(
3834 IN LARGE_INTEGER LargeInteger,
3835 IN CCHAR ShiftCount)
3836 {
3837 LARGE_INTEGER ret;
3838 ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
3839 return ret;
3840 }
3841
3842 /* BOOLEAN
3843 * RtlLargeIntegerEqualTo(
3844 * IN LARGE_INTEGER Operand1,
3845 * IN LARGE_INTEGER Operand2);
3846 */
3847 #define RtlLargeIntegerEqualTo(X,Y) \
3848 (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
3849
3850 FORCEINLINE
3851 PVOID
3852 RtlSecureZeroMemory(
3853 OUT PVOID Pointer,
3854 IN SIZE_T Size)
3855 {
3856 volatile char* vptr = (volatile char*)Pointer;
3857 #if defined(_M_AMD64)
3858 __stosb((PUCHAR)vptr, 0, Size);
3859 #else
3860 char * endptr = (char *)vptr + Size;
3861 while (vptr < endptr)
3862 {
3863 *vptr = 0; vptr++;
3864 }
3865 #endif
3866 return Pointer;
3867 }
3868
3869 #if defined(_M_AMD64)
3870 FORCEINLINE
3871 ULONG
3872 RtlCheckBit(
3873 IN PRTL_BITMAP BitMapHeader,
3874 IN ULONG BitPosition)
3875 {
3876 return BitTest((LONG CONST*)BitMapHeader->Buffer, BitPosition);
3877 }
3878 #else
3879 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
3880 #endif // defined(_M_AMD64)
3881
3882 #endif // !defined(MIDL_PASS)
3883
3884 //
3885 // Byte Swap Functions
3886 //
3887 #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037 || defined(__GNUC__))) || \
3888 ((defined(_M_AMD64) || defined(_M_IA64)) \
3889 && (_MSC_FULL_VER > 13009175 || defined(__GNUC__)))
3890
3891 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
3892 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
3893 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
3894
3895 #endif
3896
3897 /******************************************************************************
3898 * Memory manager Types *
3899 ******************************************************************************/
3900
3901 typedef struct _MDL {
3902 struct _MDL *Next;
3903 CSHORT Size;
3904 CSHORT MdlFlags;
3905 struct _EPROCESS *Process;
3906 PVOID MappedSystemVa;
3907 PVOID StartVa;
3908 ULONG ByteCount;
3909 ULONG ByteOffset;
3910 } MDL, *PMDL;
3911
3912
3913 /******************************************************************************
3914 * Memory manager Functions *
3915 ******************************************************************************/
3916
3917 /* PVOID MmGetSystemAddressForMdl(
3918 * IN PMDL Mdl);
3919 */
3920 #define MmGetSystemAddressForMdl(Mdl) \
3921 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
3922 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
3923 ((Mdl)->MappedSystemVa) : \
3924 (MmMapLockedPages((Mdl), KernelMode)))
3925
3926 /* PVOID
3927 * MmGetSystemAddressForMdlSafe(
3928 * IN PMDL Mdl,
3929 * IN MM_PAGE_PRIORITY Priority)
3930 */
3931 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
3932 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
3933 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
3934 (_Mdl)->MappedSystemVa : \
3935 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
3936 KernelMode, MmCached, NULL, FALSE, (_Priority)))
3937
3938 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3939 NTKERNELAPI
3940 PMDL
3941 NTAPI
3942 MmCreateMdl(
3943 IN PMDL MemoryDescriptorList OPTIONAL,
3944 IN PVOID Base,
3945 IN SIZE_T Length);
3946
3947 #endif
3948
3949
3950 /******************************************************************************
3951 * I/O Manager Functions *
3952 ******************************************************************************/
3953
3954 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
3955 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
3956
3957 #define DMA_MACROS_DEFINED
3958
3959 FORCEINLINE
3960 NTSTATUS
3961 IoAllocateAdapterChannel(
3962 IN PADAPTER_OBJECT AdapterObject,
3963 IN PDEVICE_OBJECT DeviceObject,
3964 IN ULONG NumberOfMapRegisters,
3965 IN PDRIVER_CONTROL ExecutionRoutine,
3966 IN PVOID Context)
3967 {
3968 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
3969 AllocateAdapterChannel =
3970 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
3971 ASSERT(AllocateAdapterChannel);
3972 return AllocateAdapterChannel(DmaAdapter,
3973 DeviceObject,
3974 NumberOfMapRegisters,
3975 ExecutionRoutine,
3976 Context );
3977 }
3978
3979 FORCEINLINE
3980 BOOLEAN
3981 IoFlushAdapterBuffers(
3982 IN PADAPTER_OBJECT AdapterObject,
3983 IN PMDL Mdl,
3984 IN PVOID MapRegisterBase,
3985 IN PVOID CurrentVa,
3986 IN ULONG Length,
3987 IN BOOLEAN WriteToDevice)
3988 {
3989 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
3990 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
3991 ASSERT(FlushAdapterBuffers);
3992 return FlushAdapterBuffers(DmaAdapter,
3993 Mdl,
3994 MapRegisterBase,
3995 CurrentVa,
3996 Length,
3997 WriteToDevice );
3998 }
3999
4000 FORCEINLINE
4001 VOID
4002 IoFreeAdapterChannel(
4003 IN PADAPTER_OBJECT AdapterObject)
4004 {
4005 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
4006 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
4007 ASSERT(FreeAdapterChannel);
4008 FreeAdapterChannel(DmaAdapter);
4009 }
4010
4011 FORCEINLINE
4012 VOID
4013 IoFreeMapRegisters(
4014 IN PADAPTER_OBJECT AdapterObject,
4015 IN PVOID MapRegisterBase,
4016 IN ULONG NumberOfMapRegisters)
4017 {
4018 PFREE_MAP_REGISTERS FreeMapRegisters;
4019 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
4020 ASSERT(FreeMapRegisters);
4021 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
4022 }
4023
4024 FORCEINLINE
4025 PHYSICAL_ADDRESS
4026 IoMapTransfer(
4027 IN PDMA_ADAPTER DmaAdapter,
4028 IN PMDL Mdl,
4029 IN PVOID MapRegisterBase,
4030 IN PVOID CurrentVa,
4031 IN OUT PULONG Length,
4032 IN BOOLEAN WriteToDevice)
4033 {
4034 PMAP_TRANSFER MapTransfer;
4035
4036 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
4037 ASSERT(MapTransfer);
4038 return MapTransfer(DmaAdapter,
4039 Mdl,
4040 MapRegisterBase,
4041 CurrentVa,
4042 Length,
4043 WriteToDevice);
4044 }
4045 #endif
4046
4047
4048 /******************************************************************************
4049 * Executive Types *
4050 ******************************************************************************/
4051
4052 typedef enum _POOL_TYPE {
4053 NonPagedPool,
4054 PagedPool,
4055 NonPagedPoolMustSucceed,
4056 DontUseThisType,
4057 NonPagedPoolCacheAligned,
4058 PagedPoolCacheAligned,
4059 NonPagedPoolCacheAlignedMustS,
4060 MaxPoolType,
4061 NonPagedPoolSession = 32,
4062 PagedPoolSession,
4063 NonPagedPoolMustSucceedSession,
4064 DontUseThisTypeSession,
4065 NonPagedPoolCacheAlignedSession,
4066 PagedPoolCacheAlignedSession,
4067 NonPagedPoolCacheAlignedMustSSession
4068 } POOL_TYPE;
4069
4070 typedef enum _SUITE_TYPE {
4071 SmallBusiness,
4072 Enterprise,
4073 BackOffice,
4074 CommunicationServer,
4075 TerminalServer,
4076 SmallBusinessRestricted,
4077 EmbeddedNT,
4078 DataCenter,
4079 SingleUserTS,
4080 Personal,
4081 Blade,
4082 MaxSuiteType
4083 } SUITE_TYPE;
4084
4085 typedef enum _EX_POOL_PRIORITY {
4086 LowPoolPriority,
4087 LowPoolPrioritySpecialPoolOverrun = 8,
4088 LowPoolPrioritySpecialPoolUnderrun = 9,
4089 NormalPoolPriority = 16,
4090 NormalPoolPrioritySpecialPoolOverrun = 24,
4091 NormalPoolPrioritySpecialPoolUnderrun = 25,
4092 HighPoolPriority = 32,
4093 HighPoolPrioritySpecialPoolOverrun = 40,
4094 HighPoolPrioritySpecialPoolUnderrun = 41
4095 } EX_POOL_PRIORITY;
4096
4097 typedef struct _FAST_MUTEX
4098 {
4099 LONG Count;
4100 PKTHREAD Owner;
4101 ULONG Contention;
4102 KEVENT Gate;
4103 ULONG OldIrql;
4104 } FAST_MUTEX, *PFAST_MUTEX;
4105
4106 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
4107
4108 typedef struct _OWNER_ENTRY {
4109 ERESOURCE_THREAD OwnerThread;
4110 _ANONYMOUS_UNION union {
4111 LONG OwnerCount;
4112 ULONG TableSize;
4113 } DUMMYUNIONNAME;
4114 } OWNER_ENTRY, *POWNER_ENTRY;
4115
4116 typedef struct _ERESOURCE
4117 {
4118 LIST_ENTRY SystemResourcesList;
4119 POWNER_ENTRY OwnerTable;
4120 SHORT ActiveCount;
4121 USHORT Flag;
4122 volatile PKSEMAPHORE SharedWaiters;
4123 volatile PKEVENT ExclusiveWaiters;
4124 OWNER_ENTRY OwnerEntry;
4125 ULONG ActiveEntries;
4126 ULONG ContentionCount;
4127 ULONG NumberOfSharedWaiters;
4128 ULONG NumberOfExclusiveWaiters;
4129 __GNU_EXTENSION union
4130 {
4131 PVOID Address;
4132 ULONG_PTR CreatorBackTraceIndex;
4133 };
4134 KSPIN_LOCK SpinLock;
4135 } ERESOURCE, *PERESOURCE;
4136
4137 #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
4138 #define LOOKASIDE_ALIGN
4139 #else
4140 #define LOOKASIDE_ALIGN /* FIXME: DECLSPEC_CACHEALIGN */
4141 #endif
4142
4143 typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
4144
4145 typedef PVOID
4146 (DDKAPI *PALLOCATE_FUNCTION)(
4147 IN POOL_TYPE PoolType,
4148 IN SIZE_T NumberOfBytes,
4149 IN ULONG Tag);
4150
4151 typedef PVOID
4152 (DDKAPI *PALLOCATE_FUNCTION_EX)(
4153 IN POOL_TYPE PoolType,
4154 IN SIZE_T NumberOfBytes,
4155 IN ULONG Tag,
4156 IN OUT PLOOKASIDE_LIST_EX Lookaside);
4157
4158 typedef VOID
4159 (DDKAPI *PFREE_FUNCTION)(
4160 IN PVOID Buffer);
4161
4162 typedef VOID
4163 (DDKAPI *PFREE_FUNCTION_EX)(
4164 IN PVOID Buffer,
4165 IN OUT PLOOKASIDE_LIST_EX Lookaside);
4166
4167 typedef VOID
4168 (DDKAPI *PCALLBACK_FUNCTION)(
4169 IN PVOID CallbackContext,
4170 IN PVOID Argument1,
4171 IN PVOID Argument2);
4172
4173 typedef struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE {
4174 union {
4175 SLIST_HEADER ListHead;
4176 SINGLE_LIST_ENTRY SingleListHead;
4177 } DUMMYUNIONNAME;
4178 USHORT Depth;
4179 USHORT MaximumDepth;
4180 ULONG TotalAllocates;
4181 union {
4182 ULONG AllocateMisses;
4183 ULONG AllocateHits;
4184 } DUMMYUNIONNAME2;
4185 ULONG TotalFrees;
4186 union {
4187 ULONG FreeMisses;
4188 ULONG FreeHits;
4189 } DUMMYUNIONNAME3;
4190 POOL_TYPE Type;
4191 ULONG Tag;
4192 ULONG Size;
4193 union {
4194 PALLOCATE_FUNCTION_EX AllocateEx;
4195 PALLOCATE_FUNCTION Allocate;
4196 } DUMMYUNIONNAME4;
4197 union {
4198 PFREE_FUNCTION_EX FreeEx;
4199 PFREE_FUNCTION Free;
4200 } DUMMYUNIONNAME5;
4201 LIST_ENTRY ListEntry;
4202 ULONG LastTotalAllocates;
4203 union {
4204 ULONG LastAllocateMisses;
4205 ULONG LastAllocateHits;
4206 } DUMMYUNIONNAME6;
4207 ULONG Future[2];
4208 } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
4209
4210 typedef struct _PAGED_LOOKASIDE_LIST {
4211 GENERAL_LOOKASIDE L;
4212 #if !defined(_AMD64_) && !defined(_IA64_)
4213 FAST_MUTEX Lock__ObsoleteButDoNotDelete;
4214 #endif
4215 } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST;
4216
4217 typedef struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST {
4218 GENERAL_LOOKASIDE L;
4219 #if !defined(_AMD64_) && !defined(_IA64_)
4220 KSPIN_LOCK Lock__ObsoleteButDoNotDelete;
4221 #endif
4222 } NPAGED_LOOKASIDE_LIST, *PNPAGED_LOOKASIDE_LIST;
4223
4224 //typedef struct _LOOKASIDE_LIST_EX {
4225 // GENERAL_LOOKASIDE_POOL L;
4226 //} LOOKASIDE_LIST_EX, *PLOOKASIDE_LIST_EX;
4227
4228 typedef struct _EX_RUNDOWN_REF {
4229 __GNU_EXTENSION union {
4230 volatile ULONG_PTR Count;
4231 volatile PVOID Ptr;
4232 };
4233 } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
4234
4235 typedef struct _EX_RUNDOWN_REF_CACHE_AWARE *PEX_RUNDOWN_REF_CACHE_AWARE;
4236
4237 typedef enum _WORK_QUEUE_TYPE {
4238 CriticalWorkQueue,
4239 DelayedWorkQueue,
4240 HyperCriticalWorkQueue,
4241 MaximumWorkQueue
4242 } WORK_QUEUE_TYPE;
4243
4244 typedef VOID
4245 (DDKAPI *PWORKER_THREAD_ROUTINE)(
4246 IN PVOID Parameter);
4247
4248 typedef struct _WORK_QUEUE_ITEM {
4249 LIST_ENTRY List;
4250 PWORKER_THREAD_ROUTINE WorkerRoutine;
4251 volatile PVOID Parameter;
4252 } WORK_QUEUE_ITEM, *PWORK_QUEUE_ITEM;
4253
4254
4255 /******************************************************************************
4256 * Executive Functions *
4257 ******************************************************************************/
4258
4259 #if defined(_X86_)
4260 #if defined(_NTHAL_)
4261 #define ExAcquireFastMutex ExiAcquireFastMutex
4262 #define ExReleaseFastMutex ExiReleaseFastMutex
4263 #define ExTryToAcquireFastMutex ExiTryToAcquireFastMutex
4264 #endif
4265 #define ExInterlockedAddUlong ExfInterlockedAddUlong
4266 #define ExInterlockedInsertHeadList ExfInterlockedInsertHeadList
4267 #define ExInterlockedInsertTailList ExfInterlockedInsertTailList
4268 #define ExInterlockedRemoveHeadList ExfInterlockedRemoveHeadList
4269 #define ExInterlockedPopEntryList ExfInterlockedPopEntryList
4270 #define ExInterlockedPushEntryList ExfInterlockedPushEntryList
4271 #endif
4272
4273 #if defined(_WIN64)
4274
4275 #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || \
4276 defined(_NTHAL_) || defined(_NTOSP_)
4277 NTKERNELAPI
4278 USHORT
4279 ExQueryDepthSList(IN PSLIST_HEADER ListHead);
4280 #else
4281 FORCEINLINE
4282 USHORT
4283 ExQueryDepthSList(IN PSLIST_HEADER ListHead)
4284 {
4285 return (USHORT)(ListHead->Alignment & 0xffff);
4286 }
4287 #endif
4288
4289 NTKERNELAPI
4290 PSLIST_ENTRY
4291 ExpInterlockedFlushSList(
4292 PSLIST_HEADER ListHead);
4293
4294 NTKERNELAPI
4295 PSLIST_ENTRY
4296 ExpInterlockedPopEntrySList(
4297 PSLIST_HEADER ListHead);
4298
4299 NTKERNELAPI
4300 PSLIST_ENTRY
4301 ExpInterlockedPushEntrySList(
4302 PSLIST_HEADER ListHead,
4303 PSLIST_ENTRY ListEntry);
4304
4305 #define ExInterlockedFlushSList(Head) \
4306 ExpInterlockedFlushSList(Head)
4307 #define ExInterlockedPopEntrySList(Head, Lock) \
4308 ExpInterlockedPopEntrySList(Head)
4309 #define ExInterlockedPushEntrySList(Head, Entry, Lock) \
4310 ExpInterlockedPushEntrySList(Head, Entry)
4311
4312 #else // !defined(_WIN64)
4313
4314 #define ExQueryDepthSList(listhead) (listhead)->Depth
4315
4316 NTKERNELAPI
4317 PSINGLE_LIST_ENTRY
4318 FASTCALL
4319 ExInterlockedFlushSList(
4320 IN PSLIST_HEADER ListHead);
4321
4322 #if defined(_WIN2K_COMPAT_SLIST_USAGE) && defined(_X86_)
4323 NTKERNELAPI
4324 PSINGLE_LIST_ENTRY
4325 FASTCALL
4326 ExInterlockedPopEntrySList(
4327 IN PSLIST_HEADER ListHead,
4328 IN PKSPIN_LOCK Lock);
4329
4330 NTKERNELAPI
4331 PSINGLE_LIST_ENTRY
4332 FASTCALL
4333 ExInterlockedPushEntrySList(
4334 IN PSLIST_HEADER ListHead,
4335 IN PSINGLE_LIST_ENTRY ListEntry,
4336 IN PKSPIN_LOCK Lock);
4337 #else
4338 #define ExInterlockedPopEntrySList(_ListHead, _Lock) \
4339 InterlockedPopEntrySList(_ListHead)
4340 #define ExInterlockedPushEntrySList(_ListHead, _ListEntry, _Lock) \
4341 InterlockedPushEntrySList(_ListHead, _ListEntry)
4342 #endif // _WIN2K_COMPAT_SLIST_USAGE
4343
4344 #endif // !defined(_WIN64)
4345
4346 /* ERESOURCE_THREAD
4347 * ExGetCurrentResourceThread(
4348 * VOID);
4349 */
4350 #define ExGetCurrentResourceThread() ((ERESOURCE_THREAD)PsGetCurrentThread())
4351
4352 #define ExReleaseResource(R) (ExReleaseResourceLite(R))
4353
4354 /* VOID
4355 * ExInitializeWorkItem(
4356 * IN PWORK_QUEUE_ITEM Item,
4357 * IN PWORKER_THREAD_ROUTINE Routine,
4358 * IN PVOID Context)
4359 */
4360 #define ExInitializeWorkItem(Item, Routine, Context) \
4361 { \
4362 (Item)->WorkerRoutine = Routine; \
4363 (Item)->Parameter = Context; \
4364 (Item)->List.Flink = NULL; \
4365 }
4366
4367 #if (NTDDI_VERSION >= NTDDI_WIN2K)
4368
4369 NTKERNELAPI
4370 VOID
4371 FASTCALL
4372 ExAcquireFastMutex(
4373 IN OUT PFAST_MUTEX FastMutex);
4374
4375 NTKERNELAPI
4376 VOID
4377 FASTCALL
4378 ExReleaseFastMutex(
4379 IN OUT PFAST_MUTEX FastMutex);
4380
4381 NTKERNELAPI
4382 BOOLEAN
4383 FASTCALL
4384 ExTryToAcquireFastMutex(
4385 IN OUT PFAST_MUTEX FastMutex);
4386
4387 NTKERNELAPI
4388 VOID
4389 FASTCALL
4390 ExAcquireFastMutexUnsafe(
4391 IN OUT PFAST_MUTEX FastMutex);
4392
4393 NTKERNELAPI
4394 VOID
4395 FASTCALL
4396 ExReleaseFastMutexUnsafe(
4397 IN OUT PFAST_MUTEX FastMutex);
4398
4399 NTKERNELAPI
4400 BOOLEAN
4401 NTAPI
4402 ExAcquireResourceExclusiveLite(
4403 IN PERESOURCE Resource,
4404 IN BOOLEAN Wait);
4405
4406 NTKERNELAPI
4407 BOOLEAN
4408 NTAPI
4409 ExAcquireResourceSharedLite(
4410 IN PERESOURCE Resource,
4411 IN BOOLEAN Wait);
4412
4413 NTKERNELAPI
4414 BOOLEAN
4415 NTAPI
4416 ExAcquireSharedStarveExclusive(
4417 IN PERESOURCE Resource,
4418 IN BOOLEAN Wait);
4419
4420 NTKERNELAPI
4421 BOOLEAN
4422 NTAPI
4423 ExAcquireSharedWaitForExclusive(
4424 IN PERESOURCE Resource,
4425 IN BOOLEAN Wait);
4426
4427 NTKERNELAPI
4428 PVOID
4429 NTAPI
4430 ExAllocatePool(
4431 IN POOL_TYPE PoolType,
4432 IN SIZE_T NumberOfBytes);
4433
4434 #ifdef POOL_TAGGING
4435 #define ExAllocatePool(p,n) ExAllocatePoolWithTag(p,n,' kdD')
4436 #endif /* POOL_TAGGING */
4437
4438 NTKERNELAPI
4439 PVOID
4440 NTAPI
4441 ExAllocatePoolWithQuota(
4442 IN POOL_TYPE PoolType,
4443 IN SIZE_T NumberOfBytes);
4444
4445 #ifdef POOL_TAGGING
4446 #define ExAllocatePoolWithQuota(p,n) ExAllocatePoolWithQuotaTag(p,n,' kdD')
4447 #endif /* POOL_TAGGING */
4448
4449 NTKERNELAPI
4450 PVOID
4451 NTAPI
4452 ExAllocatePoolWithQuotaTag(
4453 IN POOL_TYPE PoolType,
4454 IN SIZE_T NumberOfBytes,
4455 IN ULONG Tag);
4456
4457 #ifndef POOL_TAGGING
4458 #define ExAllocatePoolWithQuotaTag(a,b,c) ExAllocatePoolWithQuota(a,b)
4459 #endif /* POOL_TAGGING */
4460
4461 NTKERNELAPI
4462 PVOID
4463 NTAPI
4464 ExAllocatePoolWithTag(
4465 IN POOL_TYPE PoolType,
4466 IN SIZE_T NumberOfBytes,
4467 IN ULONG Tag);
4468
4469 NTKERNELAPI
4470 PVOID
4471 NTAPI
4472 ExAllocatePoolWithTagPriority(
4473 IN POOL_TYPE PoolType,
4474 IN SIZE_T NumberOfBytes,
4475 IN ULONG Tag,
4476 IN EX_POOL_PRIORITY Priority);
4477
4478 NTKERNELAPI
4479 VOID
4480 NTAPI
4481 ExConvertExclusiveToSharedLite(
4482 IN PERESOURCE Resource);
4483
4484 NTKERNELAPI
4485 NTSTATUS
4486 NTAPI
4487 ExCreateCallback(
4488 OUT PCALLBACK_OBJECT *CallbackObject,
4489 IN POBJECT_ATTRIBUTES ObjectAttributes,
4490 IN BOOLEAN Create,
4491 IN BOOLEAN AllowMultipleCallbacks);
4492
4493 NTKERNELAPI
4494 VOID
4495 NTAPI
4496 ExDeleteNPagedLookasideList(
4497 IN PNPAGED_LOOKASIDE_LIST Lookaside);
4498
4499 NTKERNELAPI
4500 VOID
4501 NTAPI
4502 ExDeletePagedLookasideList(
4503 IN PPAGED_LOOKASIDE_LIST Lookaside);
4504
4505 NTKERNELAPI
4506 NTSTATUS
4507 NTAPI
4508 ExDeleteResourceLite(
4509 IN PERESOURCE Resource);
4510
4511 NTKERNELAPI
4512 VOID
4513 NTAPI
4514 ExFreePool(
4515 IN PVOID P);
4516
4517 #ifdef POOL_TAGGING
4518 #define ExFreePool(P) ExFreePoolWithTag(P, 0)
4519 #endif
4520
4521 NTKERNELAPI
4522 VOID
4523 NTAPI
4524 ExFreePoolWithTag(
4525 IN PVOID P,
4526 IN ULONG Tag);
4527
4528 NTKERNELAPI
4529 ULONG
4530 NTAPI
4531 ExGetExclusiveWaiterCount(
4532 IN PERESOURCE Resource);
4533
4534 NTKERNELAPI
4535 KPROCESSOR_MODE
4536 NTAPI
4537 ExGetPreviousMode(
4538 VOID);
4539
4540 NTKERNELAPI
4541 ULONG
4542 NTAPI
4543 ExGetSharedWaiterCount(
4544 IN PERESOURCE Resource);
4545
4546 NTKERNELAPI
4547 VOID
4548 NTAPI
4549 ExInitializeNPagedLookasideList(
4550 IN PNPAGED_LOOKASIDE_LIST Lookaside,
4551 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
4552 IN PFREE_FUNCTION Free OPTIONAL,
4553 IN ULONG Flags,
4554 IN SIZE_T Size,
4555 IN ULONG Tag,
4556 IN USHORT Depth);
4557
4558 NTKERNELAPI
4559 VOID
4560 NTAPI
4561 ExInitializePagedLookasideList(
4562 IN PPAGED_LOOKASIDE_LIST Lookaside,
4563 IN PALLOCATE_FUNCTION Allocate OPTIONAL,
4564 IN PFREE_FUNCTION Free OPTIONAL,
4565 IN ULONG Flags,
4566 IN SIZE_T Size,
4567 IN ULONG Tag,
4568 IN USHORT Depth);
4569
4570 NTKERNELAPI
4571 NTSTATUS
4572 NTAPI
4573 ExInitializeResourceLite(
4574 IN PERESOURCE Resource);
4575
4576 NTKERNELAPI
4577 LARGE_INTEGER
4578 NTAPI
4579 ExInterlockedAddLargeInteger(
4580 IN PLARGE_INTEGER Addend,
4581 IN LARGE_INTEGER Increment,
4582 IN PKSPIN_LOCK Lock);
4583
4584 #if defined(_WIN64)
4585 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
4586 (VOID)InterlockedAdd64(&(Addend)->QuadPart, Increment)
4587 #else
4588 #define ExInterlockedAddLargeStatistic(Addend, Increment) \
4589 _InterlockedAddLargeStatistic((PLONGLONG)&(Addend)->QuadPart, Increment)
4590 #endif
4591
4592 NTKERNELAPI
4593 ULONG
4594 FASTCALL
4595 ExInterlockedAddUlong(
4596 IN PULONG Addend,
4597 IN ULONG Increment,
4598 PKSPIN_LOCK Lock);
4599
4600 #if defined(_AMD64_) || defined(_IA64_)
4601 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
4602 InterlockedCompareExchange64(Destination, *(Exchange), *(Comperand))
4603 #elif defined(_X86_)
4604 NTKERNELAPI
4605 LONGLONG
4606 FASTCALL
4607 ExfInterlockedCompareExchange64(
4608 IN OUT LONGLONG volatile *Destination,
4609 IN PLONGLONG Exchange,
4610 IN PLONGLONG Comperand);
4611 #define ExInterlockedCompareExchange64(Destination, Exchange, Comperand, Lock) \
4612 ExfInterlockedCompareExchange64(Destination, Exchange, Comperand)
4613 #else
4614 NTKERNELAPI
4615 LONGLONG
4616 FASTCALL
4617 ExInterlockedCompareExchange64(
4618 IN OUT LONGLONG volatile *Destination,
4619 IN PLONGLONG Exchange,
4620 IN PLONGLONG Comparand,
4621 IN PKSPIN_LOCK Lock);
4622 #endif
4623
4624 NTKERNELAPI
4625 PLIST_ENTRY
4626 FASTCALL
4627 ExInterlockedInsertHeadList(
4628 IN PLIST_ENTRY ListHead,
4629 IN PLIST_ENTRY ListEntry,
4630 IN PKSPIN_LOCK Lock);
4631
4632 NTKERNELAPI
4633 PLIST_ENTRY
4634 FASTCALL
4635 ExInterlockedInsertTailList(
4636 IN PLIST_ENTRY ListHead,
4637 IN PLIST_ENTRY ListEntry,
4638 IN PKSPIN_LOCK Lock);
4639
4640 NTKERNELAPI
4641 PSINGLE_LIST_ENTRY
4642 FASTCALL
4643 ExInterlockedPopEntryList(
4644 IN PSINGLE_LIST_ENTRY ListHead,
4645 IN PKSPIN_LOCK Lock);
4646
4647 NTKERNELAPI
4648 PSINGLE_LIST_ENTRY
4649 FASTCALL
4650 ExInterlockedPushEntryList(
4651 IN PSINGLE_LIST_ENTRY ListHead,
4652 IN PSINGLE_LIST_ENTRY ListEntry,
4653 IN PKSPIN_LOCK Lock);
4654
4655 NTKERNELAPI
4656 PLIST_ENTRY
4657 FASTCALL
4658 ExInterlockedRemoveHeadList(
4659 IN PLIST_ENTRY ListHead,
4660 IN PKSPIN_LOCK Lock);
4661
4662 NTKERNELAPI
4663 BOOLEAN
4664 NTAPI
4665 ExIsProcessorFeaturePresent(
4666 IN ULONG ProcessorFeature);
4667
4668 NTKERNELAPI
4669 BOOLEAN
4670 NTAPI
4671 ExIsResourceAcquiredExclusiveLite(
4672 IN PERESOURCE Resource);
4673
4674 NTKERNELAPI
4675 ULONG
4676 NTAPI
4677 ExIsResourceAcquiredSharedLite(
4678 IN PERESOURCE Resource);
4679
4680 #define ExIsResourceAcquiredLite ExIsResourceAcquiredSharedLite
4681
4682 NTKERNELAPI
4683 VOID
4684 NTAPI
4685 ExLocalTimeToSystemTime(
4686 IN PLARGE_INTEGER LocalTime,
4687 OUT PLARGE_INTEGER SystemTime);
4688
4689 NTKERNELAPI
4690 VOID
4691 NTAPI
4692 ExNotifyCallback(
4693 IN PCALLBACK_OBJECT CallbackObject,
4694 IN PVOID Argument1,
4695 IN PVOID Argument2);
4696
4697 NTKERNELAPI
4698 VOID
4699 NTAPI
4700 ExQueueWorkItem(
4701 IN PWORK_QUEUE_ITEM WorkItem,
4702 IN WORK_QUEUE_TYPE QueueType);
4703
4704 NTKERNELAPI
4705 DECLSPEC_NORETURN
4706 VOID
4707 NTAPI
4708 ExRaiseStatus(
4709 IN NTSTATUS Status);
4710
4711 NTKERNELAPI
4712 PVOID
4713 NTAPI
4714 ExRegisterCallback(
4715 IN PCALLBACK_OBJECT CallbackObject,
4716 IN PCALLBACK_FUNCTION CallbackFunction,
4717 IN PVOID CallbackContext);
4718
4719 NTKERNELAPI
4720 NTSTATUS
4721 NTAPI
4722 ExReinitializeResourceLite(
4723 IN PERESOURCE Resource);
4724
4725 NTKERNELAPI
4726 VOID
4727 NTAPI
4728 ExReleaseResourceForThreadLite(
4729 IN PERESOURCE Resource,
4730 IN ERESOURCE_THREAD ResourceThreadId);
4731
4732 NTKERNELAPI
4733 VOID
4734 FASTCALL
4735 ExReleaseResourceLite(
4736 IN PERESOURCE Resource);
4737
4738 NTKERNELAPI
4739 VOID
4740 NTAPI
4741 ExSetResourceOwnerPointer(
4742 IN PERESOURCE Resource,
4743 IN PVOID OwnerPointer);
4744
4745 NTKERNELAPI
4746 ULONG
4747 NTAPI
4748 ExSetTimerResolution(
4749 IN ULONG DesiredTime,
4750 IN BOOLEAN SetResolution);
4751
4752 NTKERNELAPI
4753 VOID
4754 NTAPI
4755 ExSystemTimeToLocalTime(
4756 IN PLARGE_INTEGER SystemTime,
4757 OUT PLARGE_INTEGER LocalTime);
4758
4759 NTKERNELAPI
4760 VOID
4761 NTAPI
4762 ExUnregisterCallback(
4763 IN PVOID CbRegistration);
4764
4765
4766 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
4767
4768 #if (NTDDI_VERSION >= NTDDI_WINXP)
4769 NTKERNELAPI
4770 BOOLEAN
4771 FASTCALL
4772 ExAcquireRundownProtection(
4773 IN OUT PEX_RUNDOWN_REF RunRef);
4774
4775 NTKERNELAPI
4776 VOID
4777 FASTCALL
4778 ExInitializeRundownProtection(
4779 OUT PEX_RUNDOWN_REF RunRef);
4780
4781 NTKERNELAPI
4782 VOID
4783 FASTCALL
4784 ExReInitializeRundownProtection(
4785 OUT PEX_RUNDOWN_REF RunRef);
4786
4787 NTKERNELAPI
4788 VOID
4789 FASTCALL
4790 ExReleaseRundownProtection(
4791 IN OUT PEX_RUNDOWN_REF RunRef);
4792
4793 NTKERNELAPI
4794 VOID
4795 FASTCALL
4796 ExRundownCompleted(
4797 OUT PEX_RUNDOWN_REF RunRef);
4798
4799 NTKERNELAPI
4800 BOOLEAN
4801 NTAPI
4802 ExVerifySuite(
4803 IN SUITE_TYPE SuiteType);
4804
4805 NTKERNELAPI
4806 VOID
4807 FASTCALL
4808 ExWaitForRundownProtectionRelease(
4809 IN OUT PEX_RUNDOWN_REF RunRef);
4810
4811 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
4812
4813 #if (NTDDI_VERSION >= NTDDI_WINXPSP2)
4814 NTKERNELAPI
4815 BOOLEAN
4816 FASTCALL
4817 ExAcquireRundownProtectionEx(
4818 IN OUT PEX_RUNDOWN_REF RunRef,
4819 IN UL