- Move more stuff to wdm.h
[reactos.git] / include / ddk / wdm.h
1 #ifndef _WDMDDK_
2 #define _WDMDDK_
3
4 /* Helper macro to enable gcc's extension. */
5 #ifndef __GNU_EXTENSION
6 #ifdef __GNUC__
7 #define __GNU_EXTENSION __extension__
8 #else
9 #define __GNU_EXTENSION
10 #endif
11 #endif
12
13 //
14 // Dependencies
15 //
16 #define NT_INCLUDED
17 #include <excpt.h>
18 #include <ntdef.h>
19 #include <ntstatus.h>
20
21 #ifndef GUID_DEFINED
22 #include <guiddef.h>
23 #endif /* GUID_DEFINED */
24
25 #include "intrin.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #define NTKERNELAPI DECLSPEC_IMPORT
32
33 #ifdef _WIN64
34 #define PORT_MAXIMUM_MESSAGE_LENGTH 512
35 #else
36 #define PORT_MAXIMUM_MESSAGE_LENGTH 256
37 #endif
38
39
40 #if defined(_MSC_VER)
41
42 //
43 // Indicate if #pragma alloc_text() is supported
44 //
45 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64)
46 #define ALLOC_PRAGMA 1
47 #endif
48
49 //
50 // Indicate if #pragma data_seg() is supported
51 //
52 #if defined(_M_IX86) || defined(_M_AMD64)
53 #define ALLOC_DATA_PRAGMA 1
54 #endif
55
56 #endif
57
58
59 /*
60 * Alignment Macros
61 */
62 #define ALIGN_DOWN(s, t) \
63 ((ULONG)(s) & ~(sizeof(t) - 1))
64
65 #define ALIGN_UP(s, t) \
66 (ALIGN_DOWN(((ULONG)(s) + sizeof(t) - 1), t))
67
68 #define ALIGN_DOWN_POINTER(p, t) \
69 ((PVOID)((ULONG_PTR)(p) & ~((ULONG_PTR)sizeof(t) - 1)))
70
71 #define ALIGN_UP_POINTER(p, t) \
72 (ALIGN_DOWN_POINTER(((ULONG_PTR)(p) + sizeof(t) - 1), t))
73
74 /*
75 * GUID Comparison
76 */
77
78 #ifndef __IID_ALIGNED__
79 #define __IID_ALIGNED__
80 #ifdef __cplusplus
81 inline int IsEqualGUIDAligned(REFGUID guid1, REFGUID guid2)
82 {
83 return ((*(PLONGLONG)(&guid1) == *(PLONGLONG)(&guid2)) && (*((PLONGLONG)(&guid1) + 1) == *((PLONGLONG)(&guid2) + 1)));
84 }
85 #else
86 #define IsEqualGUIDAligned(guid1, guid2) \
87 ((*(PLONGLONG)(guid1) == *(PLONGLONG)(guid2)) && (*((PLONGLONG)(guid1) + 1) == *((PLONGLONG)(guid2) + 1)))
88 #endif
89 #endif
90
91 #if defined(_WIN64)
92 #define POINTER_ALIGNMENT DECLSPEC_ALIGN(8)
93 #else
94 #define POINTER_ALIGNMENT
95 #endif
96
97 /*
98 ** Forward declarations
99 */
100
101 struct 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 /* Simple types */
1539 typedef UCHAR KPROCESSOR_MODE;
1540 typedef LONG KPRIORITY;
1541 typedef PVOID PSECURITY_DESCRIPTOR;
1542 typedef ULONG SECURITY_INFORMATION, *PSECURITY_INFORMATION;
1543
1544 /* Structures not exposed to drivers */
1545 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
1546 typedef struct _HAL_DISPATCH_TABLE *PHAL_DISPATCH_TABLE;
1547 typedef struct _HAL_PRIVATE_DISPATCH_TABLE *PHAL_PRIVATE_DISPATCH_TABLE;
1548 typedef struct _DEVICE_HANDLER_OBJECT *PDEVICE_HANDLER_OBJECT;
1549 typedef struct _BUS_HANDLER *PBUS_HANDLER;
1550
1551 typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
1552 typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
1553 typedef struct _ETHREAD *PETHREAD;
1554 typedef struct _EPROCESS *PEPROCESS;
1555 typedef struct _IO_TIMER *PIO_TIMER;
1556 typedef struct _KINTERRUPT *PKINTERRUPT;
1557 typedef struct _KPROCESS *PKPROCESS;
1558 typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
1559
1560
1561 typedef struct _CONTEXT *PCONTEXT;
1562
1563 //
1564 // Resource list definitions
1565 //
1566 typedef int CM_RESOURCE_TYPE;
1567
1568 #define CmResourceTypeNull 0
1569 #define CmResourceTypePort 1
1570 #define CmResourceTypeInterrupt 2
1571 #define CmResourceTypeMemory 3
1572 #define CmResourceTypeDma 4
1573 #define CmResourceTypeDeviceSpecific 5
1574 #define CmResourceTypeBusNumber 6
1575 #define CmResourceTypeNonArbitrated 128
1576 #define CmResourceTypeConfigData 128
1577 #define CmResourceTypeDevicePrivate 129
1578 #define CmResourceTypePcCardConfig 130
1579 #define CmResourceTypeMfCardConfig 131
1580
1581 typedef enum _INTERFACE_TYPE {
1582 InterfaceTypeUndefined = -1,
1583 Internal,
1584 Isa,
1585 Eisa,
1586 MicroChannel,
1587 TurboChannel,
1588 PCIBus,
1589 VMEBus,
1590 NuBus,
1591 PCMCIABus,
1592 CBus,
1593 MPIBus,
1594 MPSABus,
1595 ProcessorInternal,
1596 InternalPowerBus,
1597 PNPISABus,
1598 PNPBus,
1599 MaximumInterfaceType
1600 } INTERFACE_TYPE, *PINTERFACE_TYPE;
1601
1602 /* IO_RESOURCE_DESCRIPTOR.Option */
1603
1604 #define IO_RESOURCE_PREFERRED 0x01
1605 #define IO_RESOURCE_DEFAULT 0x02
1606 #define IO_RESOURCE_ALTERNATIVE 0x08
1607
1608 typedef struct _IO_RESOURCE_DESCRIPTOR {
1609 UCHAR Option;
1610 UCHAR Type;
1611 UCHAR ShareDisposition;
1612 UCHAR Spare1;
1613 USHORT Flags;
1614 USHORT Spare2;
1615 union {
1616 struct {
1617 ULONG Length;
1618 ULONG Alignment;
1619 PHYSICAL_ADDRESS MinimumAddress;
1620 PHYSICAL_ADDRESS MaximumAddress;
1621 } Port;
1622 struct {
1623 ULONG Length;
1624 ULONG Alignment;
1625 PHYSICAL_ADDRESS MinimumAddress;
1626 PHYSICAL_ADDRESS MaximumAddress;
1627 } Memory;
1628 struct {
1629 ULONG MinimumVector;
1630 ULONG MaximumVector;
1631 } Interrupt;
1632 struct {
1633 ULONG MinimumChannel;
1634 ULONG MaximumChannel;
1635 } Dma;
1636 struct {
1637 ULONG Length;
1638 ULONG Alignment;
1639 PHYSICAL_ADDRESS MinimumAddress;
1640 PHYSICAL_ADDRESS MaximumAddress;
1641 } Generic;
1642 struct {
1643 ULONG Data[3];
1644 } DevicePrivate;
1645 struct {
1646 ULONG Length;
1647 ULONG MinBusNumber;
1648 ULONG MaxBusNumber;
1649 ULONG Reserved;
1650 } BusNumber;
1651 struct {
1652 ULONG Priority;
1653 ULONG Reserved1;
1654 ULONG Reserved2;
1655 } ConfigData;
1656 } u;
1657 } IO_RESOURCE_DESCRIPTOR, *PIO_RESOURCE_DESCRIPTOR;
1658
1659 typedef struct _IO_RESOURCE_LIST {
1660 USHORT Version;
1661 USHORT Revision;
1662 ULONG Count;
1663 IO_RESOURCE_DESCRIPTOR Descriptors[1];
1664 } IO_RESOURCE_LIST, *PIO_RESOURCE_LIST;
1665
1666 typedef struct _IO_RESOURCE_REQUIREMENTS_LIST {
1667 ULONG ListSize;
1668 INTERFACE_TYPE InterfaceType;
1669 ULONG BusNumber;
1670 ULONG SlotNumber;
1671 ULONG Reserved[3];
1672 ULONG AlternativeLists;
1673 IO_RESOURCE_LIST List[1];
1674 } IO_RESOURCE_REQUIREMENTS_LIST, *PIO_RESOURCE_REQUIREMENTS_LIST;
1675
1676 //
1677 // Global debug flag
1678 //
1679 extern ULONG NtGlobalFlag;
1680
1681
1682 #include <pshpack4.h>
1683 typedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {
1684 UCHAR Type;
1685 UCHAR ShareDisposition;
1686 USHORT Flags;
1687 union {
1688 struct {
1689 PHYSICAL_ADDRESS Start;
1690 ULONG Length;
1691 } Generic;
1692 struct {
1693 PHYSICAL_ADDRESS Start;
1694 ULONG Length;
1695 } Port;
1696 struct {
1697 ULONG Level;
1698 ULONG Vector;
1699 KAFFINITY Affinity;
1700 } Interrupt;
1701 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1702 struct {
1703 __GNU_EXTENSION union {
1704 struct {
1705 USHORT Reserved;
1706 USHORT MessageCount;
1707 ULONG Vector;
1708 KAFFINITY Affinity;
1709 } Raw;
1710 struct {
1711 ULONG Level;
1712 ULONG Vector;
1713 KAFFINITY Affinity;
1714 } Translated;
1715 };
1716 } MessageInterrupt;
1717 #endif
1718 struct {
1719 PHYSICAL_ADDRESS Start;
1720 ULONG Length;
1721 } Memory;
1722 struct {
1723 ULONG Channel;
1724 ULONG Port;
1725 ULONG Reserved1;
1726 } Dma;
1727 struct {
1728 ULONG Data[3];
1729 } DevicePrivate;
1730 struct {
1731 ULONG Start;
1732 ULONG Length;
1733 ULONG Reserved;
1734 } BusNumber;
1735 struct {
1736 ULONG DataSize;
1737 ULONG Reserved1;
1738 ULONG Reserved2;
1739 } DeviceSpecificData;
1740 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
1741 struct {
1742 PHYSICAL_ADDRESS Start;
1743 ULONG Length40;
1744 } Memory40;
1745 struct {
1746 PHYSICAL_ADDRESS Start;
1747 ULONG Length48;
1748 } Memory48;
1749 struct {
1750 PHYSICAL_ADDRESS Start;
1751 ULONG Length64;
1752 } Memory64;
1753 #endif
1754 } u;
1755 } CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;
1756 #include <poppack.h>
1757
1758 //
1759 // Section map options
1760 //
1761 typedef enum _SECTION_INHERIT {
1762 ViewShare = 1,
1763 ViewUnmap = 2
1764 } SECTION_INHERIT;
1765
1766 //
1767 // Section access rights
1768 //
1769 #define SECTION_QUERY 0x0001
1770 #define SECTION_MAP_WRITE 0x0002
1771 #define SECTION_MAP_READ 0x0004
1772 #define SECTION_MAP_EXECUTE 0x0008
1773 #define SECTION_EXTEND_SIZE 0x0010
1774 #define SECTION_MAP_EXECUTE_EXPLICIT 0x0020
1775
1776 #define SECTION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED|SECTION_QUERY|\
1777 SECTION_MAP_WRITE | \
1778 SECTION_MAP_READ | \
1779 SECTION_MAP_EXECUTE | \
1780 SECTION_EXTEND_SIZE)
1781
1782 #define SESSION_QUERY_ACCESS 0x0001
1783 #define SESSION_MODIFY_ACCESS 0x0002
1784
1785 #define SESSION_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
1786 SESSION_QUERY_ACCESS | \
1787 SESSION_MODIFY_ACCESS)
1788
1789
1790
1791 #define SEGMENT_ALL_ACCESS SECTION_ALL_ACCESS
1792
1793 #define PAGE_NOACCESS 0x01
1794 #define PAGE_READONLY 0x02
1795 #define PAGE_READWRITE 0x04
1796 #define PAGE_WRITECOPY 0x08
1797 #define PAGE_EXECUTE 0x10
1798 #define PAGE_EXECUTE_READ 0x20
1799 #define PAGE_EXECUTE_READWRITE 0x40
1800 #define PAGE_EXECUTE_WRITECOPY 0x80
1801 #define PAGE_GUARD 0x100
1802 #define PAGE_NOCACHE 0x200
1803 #define PAGE_WRITECOMBINE 0x400
1804
1805 #define MEM_COMMIT 0x1000
1806 #define MEM_RESERVE 0x2000
1807 #define MEM_DECOMMIT 0x4000
1808 #define MEM_RELEASE 0x8000
1809 #define MEM_FREE 0x10000
1810 #define MEM_PRIVATE 0x20000
1811 #define MEM_MAPPED 0x40000
1812 #define MEM_RESET 0x80000
1813 #define MEM_TOP_DOWN 0x100000
1814 #define MEM_LARGE_PAGES 0x20000000
1815 #define MEM_4MB_PAGES 0x80000000
1816
1817 #define SEC_RESERVE 0x4000000
1818 #define SEC_LARGE_PAGES 0x80000000
1819
1820 #define PROCESS_DUP_HANDLE (0x0040)
1821
1822 #if (NTDDI_VERSION >= NTDDI_VISTA)
1823 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
1824 0xFFFF)
1825 #else
1826 #define PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
1827 0xFFF)
1828 #endif
1829
1830
1831
1832 //
1833 // Processor features
1834 //
1835 #define PF_FLOATING_POINT_PRECISION_ERRATA 0
1836 #define PF_FLOATING_POINT_EMULATED 1
1837 #define PF_COMPARE_EXCHANGE_DOUBLE 2
1838 #define PF_MMX_INSTRUCTIONS_AVAILABLE 3
1839 #define PF_PPC_MOVEMEM_64BIT_OK 4
1840 #define PF_ALPHA_BYTE_INSTRUCTIONS 5
1841 #define PF_XMMI_INSTRUCTIONS_AVAILABLE 6
1842 #define PF_3DNOW_INSTRUCTIONS_AVAILABLE 7
1843 #define PF_RDTSC_INSTRUCTION_AVAILABLE 8
1844 #define PF_PAE_ENABLED 9
1845 #define PF_XMMI64_INSTRUCTIONS_AVAILABLE 10
1846 #define PF_SSE_DAZ_MODE_AVAILABLE 11
1847 #define PF_NX_ENABLED 12
1848 #define PF_SSE3_INSTRUCTIONS_AVAILABLE 13
1849 #define PF_COMPARE_EXCHANGE128 14
1850 #define PF_COMPARE64_EXCHANGE128 15
1851 #define PF_CHANNELS_ENABLED 16
1852
1853
1854
1855 //
1856 // Intrinsics (note: taken from our winnt.h)
1857 // FIXME: 64-bit
1858 //
1859 #if defined(__GNUC__)
1860
1861 static __inline__ BOOLEAN
1862 InterlockedBitTestAndSet(IN LONG volatile *Base,
1863 IN LONG Bit)
1864 {
1865 #if defined(_M_IX86)
1866 LONG OldBit;
1867 __asm__ __volatile__("lock "
1868 "btsl %2,%1\n\t"
1869 "sbbl %0,%0\n\t"
1870 :"=r" (OldBit),"+m" (*Base)
1871 :"Ir" (Bit)
1872 : "memory");
1873 return OldBit;
1874 #else
1875 return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
1876 #endif
1877 }
1878
1879 static __inline__ BOOLEAN
1880 InterlockedBitTestAndReset(IN LONG volatile *Base,
1881 IN LONG Bit)
1882 {
1883 #if defined(_M_IX86)
1884 LONG OldBit;
1885 __asm__ __volatile__("lock "
1886 "btrl %2,%1\n\t"
1887 "sbbl %0,%0\n\t"
1888 :"=r" (OldBit),"+m" (*Base)
1889 :"Ir" (Bit)
1890 : "memory");
1891 return OldBit;
1892 #else
1893 return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
1894 #endif
1895 }
1896
1897 #endif
1898
1899 #define BitScanForward _BitScanForward
1900 #define BitScanReverse _BitScanReverse
1901
1902 #define BitTest _bittest
1903 #define BitTestAndComplement _bittestandcomplement
1904 #define BitTestAndSet _bittestandset
1905 #define BitTestAndReset _bittestandreset
1906 #define InterlockedBitTestAndSet _interlockedbittestandset
1907 #define InterlockedBitTestAndReset _interlockedbittestandreset
1908
1909
1910 /** INTERLOCKED FUNCTIONS *****************************************************/
1911
1912 #if !defined(__INTERLOCKED_DECLARED)
1913 #define __INTERLOCKED_DECLARED
1914
1915 #if defined (_X86_)
1916 #if defined(NO_INTERLOCKED_INTRINSICS)
1917 NTKERNELAPI
1918 LONG
1919 FASTCALL
1920 InterlockedIncrement(
1921 IN OUT LONG volatile *Addend);
1922
1923 NTKERNELAPI
1924 LONG
1925 FASTCALL
1926 InterlockedDecrement(
1927 IN OUT LONG volatile *Addend);
1928
1929 NTKERNELAPI
1930 LONG
1931 FASTCALL
1932 InterlockedCompareExchange(
1933 IN OUT LONG volatile *Destination,
1934 IN LONG Exchange,
1935 IN LONG Comparand);
1936
1937 NTKERNELAPI
1938 LONG
1939 FASTCALL
1940 InterlockedExchange(
1941 IN OUT LONG volatile *Destination,
1942 IN LONG Value);
1943
1944 NTKERNELAPI
1945 LONG
1946 FASTCALL
1947 InterlockedExchangeAdd(
1948 IN OUT LONG volatile *Addend,
1949 IN LONG Value);
1950
1951 #else // !defined(NO_INTERLOCKED_INTRINSICS)
1952
1953 #define InterlockedExchange _InterlockedExchange
1954 #define InterlockedIncrement _InterlockedIncrement
1955 #define InterlockedDecrement _InterlockedDecrement
1956 #define InterlockedExchangeAdd _InterlockedExchangeAdd
1957 #define InterlockedCompareExchange _InterlockedCompareExchange
1958 #define InterlockedOr _InterlockedOr
1959 #define InterlockedAnd _InterlockedAnd
1960 #define InterlockedXor _InterlockedXor
1961
1962 #endif // !defined(NO_INTERLOCKED_INTRINSICS)
1963
1964 #endif // defined (_X86_)
1965
1966 #if !defined (_WIN64)
1967 /*
1968 * PVOID
1969 * InterlockedExchangePointer(
1970 * IN OUT PVOID volatile *Target,
1971 * IN PVOID Value)
1972 */
1973 #define InterlockedExchangePointer(Target, Value) \
1974 ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
1975
1976 /*
1977 * PVOID
1978 * InterlockedCompareExchangePointer(
1979 * IN OUT PVOID *Destination,
1980 * IN PVOID Exchange,
1981 * IN PVOID Comparand)
1982 */
1983 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
1984 ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
1985
1986 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
1987 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
1988 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
1989
1990 #endif // !defined (_WIN64)
1991
1992 #if defined (_M_AMD64)
1993
1994 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
1995 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
1996 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
1997 #define InterlockedAnd _InterlockedAnd
1998 #define InterlockedOr _InterlockedOr
1999 #define InterlockedXor _InterlockedXor
2000 #define InterlockedIncrement _InterlockedIncrement
2001 #define InterlockedDecrement _InterlockedDecrement
2002 #define InterlockedAdd _InterlockedAdd
2003 #define InterlockedExchange _InterlockedExchange
2004 #define InterlockedExchangeAdd _InterlockedExchangeAdd
2005 #define InterlockedCompareExchange _InterlockedCompareExchange
2006 #define InterlockedAnd64 _InterlockedAnd64
2007 #define InterlockedOr64 _InterlockedOr64
2008 #define InterlockedXor64 _InterlockedXor64
2009 #define InterlockedIncrement64 _InterlockedIncrement64
2010 #define InterlockedDecrement64 _InterlockedDecrement64
2011 #define InterlockedAdd64 _InterlockedAdd64
2012 #define InterlockedExchange64 _InterlockedExchange64
2013 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
2014 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
2015 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
2016 #define InterlockedExchangePointer _InterlockedExchangePointer
2017 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
2018 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
2019
2020 #endif // _M_AMD64
2021
2022 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
2023 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
2024 FORCEINLINE
2025 LONG64
2026 InterlockedAdd64(
2027 IN OUT LONG64 volatile *Addend,
2028 IN LONG64 Value)
2029 {
2030 return InterlockedExchangeAdd64(Addend, Value) + Value;
2031 }
2032 //#endif
2033 #endif
2034
2035 #endif /* !__INTERLOCKED_DECLARED */
2036
2037 #if defined(_M_IX86)
2038 #define YieldProcessor _mm_pause
2039 #elif defined (_M_AMD64)
2040 #define YieldProcessor _mm_pause
2041 #elif defined(_M_PPC)
2042 #define YieldProcessor() __asm__ __volatile__("nop");
2043 #elif defined(_M_MIPS)
2044 #define YieldProcessor() __asm__ __volatile__("nop");
2045 #elif defined(_M_ARM)
2046 #define YieldProcessor()
2047 #else
2048 #error Unknown architecture
2049 #endif
2050
2051
2052
2053 //
2054 // Slist Header
2055 //
2056 #ifndef _SLIST_HEADER_
2057 #define _SLIST_HEADER_
2058
2059 #if defined(_WIN64)
2060 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY *PSLIST_ENTRY;
2061 typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
2062 PSLIST_ENTRY Next;
2063 } SLIST_ENTRY;
2064 typedef union DECLSPEC_ALIGN(16) _SLIST_HEADER {
2065 struct {
2066 ULONGLONG Alignment;
2067 ULONGLONG Region;
2068 } DUMMYSTRUCTNAME;
2069 struct {
2070 ULONGLONG Depth:16;
2071 ULONGLONG Sequence:9;
2072 ULONGLONG NextEntry:39;
2073 ULONGLONG HeaderType:1;
2074 ULONGLONG Init:1;
2075 ULONGLONG Reserved:59;
2076 ULONGLONG Region:3;
2077 } Header8;
2078 struct {
2079 ULONGLONG Depth:16;
2080 ULONGLONG Sequence:48;
2081 ULONGLONG HeaderType:1;
2082 ULONGLONG Init:1;
2083 ULONGLONG Reserved:2;
2084 ULONGLONG NextEntry:60;
2085 } Header16;
2086 } SLIST_HEADER, *PSLIST_HEADER;
2087 #else
2088 #define SLIST_ENTRY SINGLE_LIST_ENTRY
2089 #define _SLIST_ENTRY _SINGLE_LIST_ENTRY
2090 #define PSLIST_ENTRY PSINGLE_LIST_ENTRY
2091 typedef union _SLIST_HEADER {
2092 ULONGLONG Alignment;
2093 struct {
2094 SLIST_ENTRY Next;
2095 USHORT Depth;
2096 USHORT Sequence;
2097 } DUMMYSTRUCTNAME;
2098 } SLIST_HEADER, *PSLIST_HEADER;
2099 #endif
2100
2101 #endif /* _SLIST_HEADER_ */
2102
2103
2104
2105 //
2106 // Power States/Levels
2107 //
2108 typedef enum _SYSTEM_POWER_STATE {
2109 PowerSystemUnspecified,
2110 PowerSystemWorking,
2111 PowerSystemSleeping1,
2112 PowerSystemSleeping2,
2113 PowerSystemSleeping3,
2114 PowerSystemHibernate,
2115 PowerSystemShutdown,
2116 PowerSystemMaximum
2117 } SYSTEM_POWER_STATE, *PSYSTEM_POWER_STATE;
2118
2119 #define POWER_SYSTEM_MAXIMUM PowerSystemMaximum
2120
2121 typedef enum _POWER_INFORMATION_LEVEL {
2122 SystemPowerPolicyAc,
2123 SystemPowerPolicyDc,
2124 VerifySystemPolicyAc,
2125 VerifySystemPolicyDc,
2126 SystemPowerCapabilities,
2127 SystemBatteryState,
2128 SystemPowerStateHandler,
2129 ProcessorStateHandler,
2130 SystemPowerPolicyCurrent,
2131 AdministratorPowerPolicy,
2132 SystemReserveHiberFile,
2133 ProcessorInformation,
2134 SystemPowerInformation,
2135 ProcessorStateHandler2,
2136 LastWakeTime,
2137 LastSleepTime,
2138 SystemExecutionState,
2139 SystemPowerStateNotifyHandler,
2140 ProcessorPowerPolicyAc,
2141 ProcessorPowerPolicyDc,
2142 VerifyProcessorPowerPolicyAc,
2143 VerifyProcessorPowerPolicyDc,
2144 ProcessorPowerPolicyCurrent
2145 } POWER_INFORMATION_LEVEL;
2146
2147 typedef enum {
2148 PowerActionNone,
2149 PowerActionReserved,
2150 PowerActionSleep,
2151 PowerActionHibernate,
2152 PowerActionShutdown,
2153 PowerActionShutdownReset,
2154 PowerActionShutdownOff,
2155 PowerActionWarmEject
2156 } POWER_ACTION, *PPOWER_ACTION;
2157
2158 typedef enum _DEVICE_POWER_STATE {
2159 PowerDeviceUnspecified,
2160 PowerDeviceD0,
2161 PowerDeviceD1,
2162 PowerDeviceD2,
2163 PowerDeviceD3,
2164 PowerDeviceMaximum
2165 } DEVICE_POWER_STATE, *PDEVICE_POWER_STATE;
2166
2167 #define ES_SYSTEM_REQUIRED 0x00000001
2168 #define ES_DISPLAY_REQUIRED 0x00000002
2169 #define ES_USER_PRESENT 0x00000004
2170 #define ES_CONTINUOUS 0x80000000
2171
2172 typedef ULONG EXECUTION_STATE;
2173
2174 typedef enum {
2175 LT_DONT_CARE,
2176 LT_LOWEST_LATENCY
2177 } LATENCY_TIME;
2178
2179
2180
2181 //
2182 // Access/Security Stuff
2183 //
2184 typedef ULONG ACCESS_MASK, *PACCESS_MASK;
2185 typedef PVOID PACCESS_TOKEN;
2186
2187 #define DELETE 0x00010000L
2188 #define READ_CONTROL 0x00020000L
2189 #define WRITE_DAC 0x00040000L
2190 #define WRITE_OWNER 0x00080000L
2191 #define SYNCHRONIZE 0x00100000L
2192 #define STANDARD_RIGHTS_REQUIRED 0x000F0000L
2193 #define STANDARD_RIGHTS_READ READ_CONTROL
2194 #define STANDARD_RIGHTS_WRITE READ_CONTROL
2195 #define STANDARD_RIGHTS_EXECUTE READ_CONTROL
2196 #define STANDARD_RIGHTS_ALL 0x001F0000L
2197 #define SPECIFIC_RIGHTS_ALL 0x0000FFFFL
2198 #define ACCESS_SYSTEM_SECURITY 0x01000000L
2199 #define MAXIMUM_ALLOWED 0x02000000L
2200 #define GENERIC_READ 0x80000000L
2201 #define GENERIC_WRITE 0x40000000L
2202 #define GENERIC_EXECUTE 0x20000000L
2203 #define GENERIC_ALL 0x10000000L
2204
2205 typedef struct _GENERIC_MAPPING {
2206 ACCESS_MASK GenericRead;
2207 ACCESS_MASK GenericWrite;
2208 ACCESS_MASK GenericExecute;
2209 ACCESS_MASK GenericAll;
2210 } GENERIC_MAPPING, *PGENERIC_MAPPING;
2211
2212 #define ACL_REVISION 2
2213 #define ACL_REVISION_DS 4
2214
2215 #define ACL_REVISION1 1
2216 #define ACL_REVISION2 2
2217 #define ACL_REVISION3 3
2218 #define ACL_REVISION4 4
2219 #define MIN_ACL_REVISION ACL_REVISION2
2220 #define MAX_ACL_REVISION ACL_REVISION4
2221
2222 typedef struct _ACL {
2223 UCHAR AclRevision;
2224 UCHAR Sbz1;
2225 USHORT AclSize;
2226 USHORT AceCount;
2227 USHORT Sbz2;
2228 } ACL, *PACL;
2229
2230
2231
2232 //
2233 // Current security descriptor revision value
2234 //
2235 #define SECURITY_DESCRIPTOR_REVISION (1)
2236 #define SECURITY_DESCRIPTOR_REVISION1 (1)
2237
2238 //
2239 // Privilege attributes
2240 //
2241 #define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
2242 #define SE_PRIVILEGE_ENABLED (0x00000002L)
2243 #define SE_PRIVILEGE_REMOVED (0X00000004L)
2244 #define SE_PRIVILEGE_USED_FOR_ACCESS (0x80000000L)
2245
2246 #define SE_PRIVILEGE_VALID_ATTRIBUTES (SE_PRIVILEGE_ENABLED_BY_DEFAULT | \
2247 SE_PRIVILEGE_ENABLED | \
2248 SE_PRIVILEGE_REMOVED | \
2249 SE_PRIVILEGE_USED_FOR_ACCESS)
2250
2251 #include <pshpack4.h>
2252 typedef struct _LUID_AND_ATTRIBUTES {
2253 LUID Luid;
2254 ULONG Attributes;
2255 } LUID_AND_ATTRIBUTES, *PLUID_AND_ATTRIBUTES;
2256 #include <poppack.h>
2257 typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
2258 typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
2259
2260
2261
2262 //
2263 // Privilege sets
2264 //
2265 #define PRIVILEGE_SET_ALL_NECESSARY (1)
2266
2267 typedef struct _PRIVILEGE_SET {
2268 ULONG PrivilegeCount;
2269 ULONG Control;
2270 LUID_AND_ATTRIBUTES Privilege[ANYSIZE_ARRAY];
2271 } PRIVILEGE_SET,*PPRIVILEGE_SET;
2272
2273 typedef enum _SECURITY_IMPERSONATION_LEVEL {
2274 SecurityAnonymous,
2275 SecurityIdentification,
2276 SecurityImpersonation,
2277 SecurityDelegation
2278 } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;
2279
2280 #define SECURITY_MAX_IMPERSONATION_LEVEL SecurityDelegation
2281 #define SECURITY_MIN_IMPERSONATION_LEVEL SecurityAnonymous
2282 #define DEFAULT_IMPERSONATION_LEVEL SecurityImpersonation
2283 #define VALID_IMPERSONATION_LEVEL(Level) (((Level) >= SECURITY_MIN_IMPERSONATION_LEVEL) && ((Level) <= SECURITY_MAX_IMPERSONATION_LEVEL))
2284
2285 #define SECURITY_DYNAMIC_TRACKING (TRUE)
2286 #define SECURITY_STATIC_TRACKING (FALSE)
2287
2288 typedef BOOLEAN SECURITY_CONTEXT_TRACKING_MODE, *PSECURITY_CONTEXT_TRACKING_MODE;
2289
2290 typedef struct _SECURITY_QUALITY_OF_SERVICE {
2291 ULONG Length;
2292 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
2293 SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode;
2294 BOOLEAN EffectiveOnly;
2295 } SECURITY_QUALITY_OF_SERVICE, *PSECURITY_QUALITY_OF_SERVICE;
2296
2297 typedef struct _SE_IMPERSONATION_STATE {
2298 PACCESS_TOKEN Token;
2299 BOOLEAN CopyOnOpen;
2300 BOOLEAN EffectiveOnly;
2301 SECURITY_IMPERSONATION_LEVEL Level;
2302 } SE_IMPERSONATION_STATE, *PSE_IMPERSONATION_STATE;
2303
2304 #define OWNER_SECURITY_INFORMATION (0x00000001L)
2305 #define GROUP_SECURITY_INFORMATION (0x00000002L)
2306 #define DACL_SECURITY_INFORMATION (0x00000004L)
2307 #define SACL_SECURITY_INFORMATION (0x00000008L)
2308 #define LABEL_SECURITY_INFORMATION (0x00000010L)
2309
2310 #define PROTECTED_DACL_SECURITY_INFORMATION (0x80000000L)
2311 #define PROTECTED_SACL_SECURITY_INFORMATION (0x40000000L)
2312 #define UNPROTECTED_DACL_SECURITY_INFORMATION (0x20000000L)
2313 #define UNPROTECTED_SACL_SECURITY_INFORMATION (0x10000000L)
2314
2315
2316
2317 //
2318 // Registry Access Rights
2319 //
2320 #define KEY_QUERY_VALUE (0x0001)
2321 #define KEY_SET_VALUE (0x0002)
2322 #define KEY_CREATE_SUB_KEY (0x0004)
2323 #define KEY_ENUMERATE_SUB_KEYS (0x0008)
2324 #define KEY_NOTIFY (0x0010)
2325 #define KEY_CREATE_LINK (0x0020)
2326 #define KEY_WOW64_32KEY (0x0200)
2327 #define KEY_WOW64_64KEY (0x0100)
2328 #define KEY_WOW64_RES (0x0300)
2329
2330 #define KEY_READ ((STANDARD_RIGHTS_READ |\
2331 KEY_QUERY_VALUE |\
2332 KEY_ENUMERATE_SUB_KEYS |\
2333 KEY_NOTIFY) \
2334 & \
2335 (~SYNCHRONIZE))
2336
2337 #define KEY_WRITE ((STANDARD_RIGHTS_WRITE |\
2338 KEY_SET_VALUE |\
2339 KEY_CREATE_SUB_KEY) \
2340 & \
2341 (~SYNCHRONIZE))
2342
2343 #define KEY_EXECUTE ((KEY_READ) \
2344 & \
2345 (~SYNCHRONIZE))
2346
2347 #define KEY_ALL_ACCESS ((STANDARD_RIGHTS_ALL |\
2348 KEY_QUERY_VALUE |\
2349 KEY_SET_VALUE |\
2350 KEY_CREATE_SUB_KEY |\
2351 KEY_ENUMERATE_SUB_KEYS |\
2352 KEY_NOTIFY |\
2353 KEY_CREATE_LINK) \
2354 & \
2355 (~SYNCHRONIZE))
2356
2357 //
2358 // Registry Open/Create Options
2359 //
2360 #define REG_OPTION_RESERVED (0x00000000L)
2361 #define REG_OPTION_NON_VOLATILE (0x00000000L)
2362 #define REG_OPTION_VOLATILE (0x00000001L)
2363 #define REG_OPTION_CREATE_LINK (0x00000002L)
2364 #define REG_OPTION_BACKUP_RESTORE (0x00000004L)
2365 #define REG_OPTION_OPEN_LINK (0x00000008L)
2366
2367 #define REG_LEGAL_OPTION \
2368 (REG_OPTION_RESERVED |\
2369 REG_OPTION_NON_VOLATILE |\
2370 REG_OPTION_VOLATILE |\
2371 REG_OPTION_CREATE_LINK |\
2372 REG_OPTION_BACKUP_RESTORE |\
2373 REG_OPTION_OPEN_LINK)
2374
2375 //
2376 // Key creation/open disposition
2377 //
2378 #define REG_CREATED_NEW_KEY (0x00000001L)
2379 #define REG_OPENED_EXISTING_KEY (0x00000002L)
2380
2381 //
2382 // Key restore & hive load flags
2383 //
2384 #define REG_WHOLE_HIVE_VOLATILE (0x00000001L)
2385 #define REG_REFRESH_HIVE (0x00000002L)
2386 #define REG_NO_LAZY_FLUSH (0x00000004L)
2387 #define REG_FORCE_RESTORE (0x00000008L)
2388 #define REG_APP_HIVE (0x00000010L)
2389 #define REG_PROCESS_PRIVATE (0x00000020L)
2390 #define REG_START_JOURNAL (0x00000040L)
2391 #define REG_HIVE_EXACT_FILE_GROWTH (0x00000080L)
2392 #define REG_HIVE_NO_RM (0x00000100L)
2393 #define REG_HIVE_SINGLE_LOG (0x00000200L)
2394
2395 //
2396 // Unload Flags
2397 //
2398 #define REG_FORCE_UNLOAD 1
2399
2400 //
2401 // Notify Filter Values
2402 //
2403 #define REG_NOTIFY_CHANGE_NAME (0x00000001L)
2404 #define REG_NOTIFY_CHANGE_ATTRIBUTES (0x00000002L)
2405 #define REG_NOTIFY_CHANGE_LAST_SET (0x00000004L)
2406 #define REG_NOTIFY_CHANGE_SECURITY (0x00000008L)
2407
2408 #define REG_LEGAL_CHANGE_FILTER \
2409 (REG_NOTIFY_CHANGE_NAME |\
2410 REG_NOTIFY_CHANGE_ATTRIBUTES |\
2411 REG_NOTIFY_CHANGE_LAST_SET |\
2412 REG_NOTIFY_CHANGE_SECURITY)
2413
2414
2415
2416 //
2417 // Thread Access Rights
2418 //
2419 #define THREAD_TERMINATE (0x0001)
2420 #define THREAD_SUSPEND_RESUME (0x0002)
2421 #define THREAD_ALERT (0x0004)
2422 #define THREAD_GET_CONTEXT (0x0008)
2423 #define THREAD_SET_CONTEXT (0x0010)
2424 #define THREAD_SET_INFORMATION (0x0020)
2425 #define THREAD_SET_LIMITED_INFORMATION (0x0400)
2426 #define THREAD_QUERY_LIMITED_INFORMATION (0x0800)
2427 #if (NTDDI_VERSION >= NTDDI_VISTA)
2428 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
2429 0xFFFF)
2430 #else
2431 #define THREAD_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \
2432 0x3FF)
2433 #endif
2434
2435 //
2436 // Service Start Types
2437 //
2438 #define SERVICE_BOOT_START 0x00000000
2439 #define SERVICE_SYSTEM_START 0x00000001
2440 #define SERVICE_AUTO_START 0x00000002
2441 #define SERVICE_DEMAND_START 0x00000003
2442 #define SERVICE_DISABLED 0x00000004
2443
2444 //
2445 // Exception Records
2446 //
2447 #define EXCEPTION_NONCONTINUABLE 1
2448 #define EXCEPTION_MAXIMUM_PARAMETERS 15
2449
2450 typedef struct _EXCEPTION_RECORD {
2451 NTSTATUS ExceptionCode;
2452 ULONG ExceptionFlags;
2453 struct _EXCEPTION_RECORD *ExceptionRecord;
2454 PVOID ExceptionAddress;
2455 ULONG NumberParameters;
2456 ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2457 } EXCEPTION_RECORD, *PEXCEPTION_RECORD;
2458
2459 typedef struct _EXCEPTION_RECORD32 {
2460 NTSTATUS ExceptionCode;
2461 ULONG ExceptionFlags;
2462 ULONG ExceptionRecord;
2463 ULONG ExceptionAddress;
2464 ULONG NumberParameters;
2465 ULONG ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2466 } EXCEPTION_RECORD32, *PEXCEPTION_RECORD32;
2467
2468 typedef struct _EXCEPTION_RECORD64 {
2469 NTSTATUS ExceptionCode;
2470 ULONG ExceptionFlags;
2471 ULONG64 ExceptionRecord;
2472 ULONG64 ExceptionAddress;
2473 ULONG NumberParameters;
2474 ULONG __unusedAlignment;
2475 ULONG64 ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS];
2476 } EXCEPTION_RECORD64, *PEXCEPTION_RECORD64;
2477
2478 typedef struct _EXCEPTION_POINTERS {
2479 PEXCEPTION_RECORD ExceptionRecord;
2480 PCONTEXT ContextRecord;
2481 } EXCEPTION_POINTERS, *PEXCEPTION_POINTERS;
2482
2483
2484
2485 //
2486 // Process Qoutas
2487 //
2488 typedef struct _QUOTA_LIMITS {
2489 SIZE_T PagedPoolLimit;
2490 SIZE_T NonPagedPoolLimit;
2491 SIZE_T MinimumWorkingSetSize;
2492 SIZE_T MaximumWorkingSetSize;
2493 SIZE_T PagefileLimit;
2494 LARGE_INTEGER TimeLimit;
2495 } QUOTA_LIMITS, *PQUOTA_LIMITS;
2496
2497 #define QUOTA_LIMITS_HARDWS_MIN_ENABLE 0x00000001
2498 #define QUOTA_LIMITS_HARDWS_MIN_DISABLE 0x00000002
2499 #define QUOTA_LIMITS_HARDWS_MAX_ENABLE 0x00000004
2500 #define QUOTA_LIMITS_HARDWS_MAX_DISABLE 0x00000008
2501 #define QUOTA_LIMITS_USE_DEFAULT_LIMITS 0x00000010
2502
2503
2504 /******************************************************************************
2505 * WINBASE Functions *
2506 ******************************************************************************/
2507 #if !defined(_WINBASE_)
2508
2509 #if defined(_WIN64)
2510
2511 #define InterlockedPopEntrySList(Head) \
2512 ExpInterlockedPopEntrySList(Head)
2513
2514 #define InterlockedPushEntrySList(Head, Entry) \
2515 ExpInterlockedPushEntrySList(Head, Entry)
2516
2517 #define InterlockedFlushSList(Head) \
2518 ExpInterlockedFlushSList(Head)
2519
2520 #define QueryDepthSList(Head) \
2521 ExQueryDepthSList(Head)
2522
2523 #else // !defined(_WIN64)
2524
2525 NTKERNELAPI
2526 PSLIST_ENTRY
2527 FASTCALL
2528 InterlockedPopEntrySList(
2529 IN PSLIST_HEADER ListHead);
2530
2531 NTKERNELAPI
2532 PSLIST_ENTRY
2533 FASTCALL
2534 InterlockedPushEntrySList(
2535 IN PSLIST_HEADER ListHead,
2536 IN PSLIST_ENTRY ListEntry);
2537
2538 #define InterlockedFlushSList(ListHead) \
2539 ExInterlockedFlushSList(ListHead)
2540
2541 #define QueryDepthSList(Head) \
2542 ExQueryDepthSList(Head)
2543
2544 #endif // !defined(_WIN64)
2545
2546 #endif // !defined(_WINBASE_)
2547
2548
2549 /******************************************************************************
2550 * Kernel Types *
2551 ******************************************************************************/
2552
2553 typedef struct _DISPATCHER_HEADER
2554 {
2555 __GNU_EXTENSION union
2556 {
2557 __GNU_EXTENSION struct
2558 {
2559 UCHAR Type;
2560 __GNU_EXTENSION union
2561 {
2562 UCHAR Absolute;
2563 UCHAR NpxIrql;
2564 };
2565 __GNU_EXTENSION union
2566 {
2567 UCHAR Size;
2568 UCHAR Hand;
2569 };
2570 __GNU_EXTENSION union
2571 {
2572 UCHAR Inserted;
2573 BOOLEAN DebugActive;
2574 };
2575 };
2576 volatile LONG Lock;
2577 };
2578 LONG SignalState;
2579 LIST_ENTRY WaitListHead;
2580 } DISPATCHER_HEADER, *PDISPATCHER_HEADER;
2581
2582 typedef ULONG_PTR KSPIN_LOCK, *PKSPIN_LOCK;
2583
2584 typedef struct _KEVENT {
2585 DISPATCHER_HEADER Header;
2586 } KEVENT, *PKEVENT, *RESTRICTED_POINTER PRKEVENT;
2587
2588 typedef struct _KSEMAPHORE {
2589 DISPATCHER_HEADER Header;
2590 LONG Limit;
2591 } KSEMAPHORE, *PKSEMAPHORE, *RESTRICTED_POINTER PRKSEMAPHORE;
2592
2593 /******************************************************************************
2594 * RTL Types *
2595 ******************************************************************************/
2596
2597 #define RTL_REGISTRY_ABSOLUTE 0
2598 #define RTL_REGISTRY_SERVICES 1
2599 #define RTL_REGISTRY_CONTROL 2
2600 #define RTL_REGISTRY_WINDOWS_NT 3
2601 #define RTL_REGISTRY_DEVICEMAP 4
2602 #define RTL_REGISTRY_USER 5
2603 #define RTL_REGISTRY_MAXIMUM 6
2604 #define RTL_REGISTRY_HANDLE 0x40000000
2605 #define RTL_REGISTRY_OPTIONAL 0x80000000
2606
2607 /* RTL_QUERY_REGISTRY_TABLE.Flags */
2608 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
2609 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
2610 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
2611 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
2612 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
2613 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
2614 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
2615
2616 typedef struct _RTL_BITMAP {
2617 ULONG SizeOfBitMap;
2618 PULONG Buffer;
2619 } RTL_BITMAP, *PRTL_BITMAP;
2620
2621 typedef struct _RTL_BITMAP_RUN {
2622 ULONG StartingIndex;
2623 ULONG NumberOfBits;
2624 } RTL_BITMAP_RUN, *PRTL_BITMAP_RUN;
2625
2626 typedef NTSTATUS
2627 (DDKAPI *PRTL_QUERY_REGISTRY_ROUTINE)(
2628 IN PWSTR ValueName,
2629 IN ULONG ValueType,
2630 IN PVOID ValueData,
2631 IN ULONG ValueLength,
2632 IN PVOID Context,
2633 IN PVOID EntryContext);
2634
2635 typedef struct _RTL_QUERY_REGISTRY_TABLE {
2636 PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine;
2637 ULONG Flags;
2638 PCWSTR Name;
2639 PVOID EntryContext;
2640 ULONG DefaultType;
2641 PVOID DefaultData;
2642 ULONG DefaultLength;
2643 } RTL_QUERY_REGISTRY_TABLE, *PRTL_QUERY_REGISTRY_TABLE;
2644
2645 typedef struct _TIME_FIELDS {
2646 CSHORT Year;
2647 CSHORT Month;
2648 CSHORT Day;
2649 CSHORT Hour;
2650 CSHORT Minute;
2651 CSHORT Second;
2652 CSHORT Milliseconds;
2653 CSHORT Weekday;
2654 } TIME_FIELDS, *PTIME_FIELDS;
2655
2656
2657 /******************************************************************************
2658 * RTL Functions *
2659 ******************************************************************************/
2660
2661 NTSYSAPI
2662 VOID
2663 NTAPI
2664 RtlAssert(
2665 IN PVOID FailedAssertion,
2666 IN PVOID FileName,
2667 IN ULONG LineNumber,
2668 IN PCHAR Message);
2669
2670 /* VOID
2671 * RtlCopyMemory(
2672 * IN VOID UNALIGNED *Destination,
2673 * IN CONST VOID UNALIGNED *Source,
2674 * IN SIZE_T Length)
2675 */
2676 #define RtlCopyMemory(Destination, Source, Length) \
2677 memcpy(Destination, Source, Length)
2678
2679 #define RtlCopyBytes RtlCopyMemory
2680
2681 #if defined(_M_AMD64)
2682 NTSYSAPI
2683 VOID
2684 NTAPI
2685 RtlCopyMemoryNonTemporal(
2686 VOID UNALIGNED *Destination,
2687 CONST VOID UNALIGNED *Source,
2688 SIZE_T Length);
2689 #else
2690 #define RtlCopyMemoryNonTemporal RtlCopyMemory
2691 #endif
2692
2693 /* BOOLEAN
2694 * RtlEqualLuid(
2695 * IN PLUID Luid1,
2696 * IN PLUID Luid2)
2697 */
2698 #define RtlEqualLuid(Luid1, Luid2) \
2699 (((Luid1)->LowPart == (Luid2)->LowPart) && ((Luid1)->HighPart == (Luid2)->HighPart))
2700
2701 /* ULONG
2702 * RtlEqualMemory(
2703 * IN VOID UNALIGNED *Destination,
2704 * IN CONST VOID UNALIGNED *Source,
2705 * IN SIZE_T Length)
2706 */
2707 #define RtlEqualMemory(Destination, Source, Length) \
2708 (!memcmp(Destination, Source, Length))
2709
2710 /* VOID
2711 * RtlFillMemory(
2712 * IN VOID UNALIGNED *Destination,
2713 * IN SIZE_T Length,
2714 * IN UCHAR Fill)
2715 */
2716 #define RtlFillMemory(Destination, Length, Fill) \
2717 memset(Destination, Fill, Length)
2718
2719 #define RtlFillBytes RtlFillMemory
2720
2721 NTSYSAPI
2722 VOID
2723 NTAPI
2724 RtlFreeUnicodeString(
2725 IN PUNICODE_STRING UnicodeString);
2726
2727 NTSYSAPI
2728 NTSTATUS
2729 NTAPI
2730 RtlGUIDFromString(
2731 IN PUNICODE_STRING GuidString,
2732 OUT GUID *Guid);
2733
2734 NTSYSAPI
2735 VOID
2736 NTAPI
2737 RtlInitUnicodeString(
2738 IN OUT PUNICODE_STRING DestinationString,
2739 IN PCWSTR SourceString);
2740
2741 /* VOID
2742 * RtlMoveMemory(
2743 * IN VOID UNALIGNED *Destination,
2744 * IN CONST VOID UNALIGNED *Source,
2745 * IN SIZE_T Length)
2746 */
2747 #define RtlMoveMemory(Destination, Source, Length) \
2748 memmove(Destination, Source, Length)
2749
2750 NTSYSAPI
2751 NTSTATUS
2752 NTAPI
2753 RtlStringFromGUID(
2754 IN REFGUID Guid,
2755 OUT PUNICODE_STRING GuidString);
2756
2757 /* VOID
2758 * RtlZeroMemory(
2759 * IN VOID UNALIGNED *Destination,
2760 * IN SIZE_T Length)
2761 */
2762 #define RtlZeroMemory(Destination, Length) \
2763 memset(Destination, 0, Length)
2764
2765 #define RtlZeroBytes RtlZeroMemory
2766
2767
2768 #if (NTDDI_VERSION >= NTDDI_WIN2K)
2769 NTSYSAPI
2770 BOOLEAN
2771 NTAPI
2772 RtlAreBitsClear(
2773 IN PRTL_BITMAP BitMapHeader,
2774 IN ULONG StartingIndex,
2775 IN ULONG Length);
2776
2777 NTSYSAPI
2778 BOOLEAN
2779 NTAPI
2780 RtlAreBitsSet(
2781 IN PRTL_BITMAP BitMapHeader,
2782 IN ULONG StartingIndex,
2783 IN ULONG Length);
2784
2785 NTSYSAPI
2786 NTSTATUS
2787 NTAPI
2788 RtlAnsiStringToUnicodeString(
2789 IN OUT PUNICODE_STRING DestinationString,
2790 IN PANSI_STRING SourceString,
2791 IN BOOLEAN AllocateDestinationString);
2792
2793 NTSYSAPI
2794 ULONG
2795 NTAPI
2796 RtlxAnsiStringToUnicodeSize(
2797 IN PCANSI_STRING AnsiString);
2798
2799 #define RtlAnsiStringToUnicodeSize(String) ( \
2800 NLS_MB_CODE_PAGE_TAG ? \
2801 RtlxAnsiStringToUnicodeSize(String) : \
2802 ((String)->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR) \
2803 )
2804
2805 NTSYSAPI
2806 NTSTATUS
2807 NTAPI
2808 RtlAppendUnicodeStringToString(
2809 IN OUT PUNICODE_STRING Destination,
2810 IN PCUNICODE_STRING Source);
2811
2812 NTSYSAPI
2813 NTSTATUS
2814 NTAPI
2815 RtlAppendUnicodeToString(
2816 IN OUT PUNICODE_STRING Destination,
2817 IN PCWSTR Source);
2818
2819 NTSYSAPI
2820 NTSTATUS
2821 NTAPI
2822 RtlCheckRegistryKey(
2823 IN ULONG RelativeTo,
2824 IN PWSTR Path);
2825
2826 NTSYSAPI
2827 VOID
2828 NTAPI
2829 RtlClearAllBits(
2830 IN PRTL_BITMAP BitMapHeader);
2831
2832 NTSYSAPI
2833 VOID
2834 NTAPI
2835 RtlClearBits(
2836 IN PRTL_BITMAP BitMapHeader,
2837 IN ULONG StartingIndex,
2838 IN ULONG NumberToClear);
2839
2840 NTSYSAPI
2841 SIZE_T
2842 NTAPI
2843 RtlCompareMemory(
2844 IN CONST VOID *Source1,
2845 IN CONST VOID *Source2,
2846 IN SIZE_T Length);
2847
2848 NTSYSAPI
2849 LONG
2850 NTAPI
2851 RtlCompareUnicodeString(
2852 IN PCUNICODE_STRING String1,
2853 IN PCUNICODE_STRING String2,
2854 IN BOOLEAN CaseInSensitive);
2855
2856 NTSYSAPI
2857 LONG
2858 NTAPI
2859 RtlCompareUnicodeStrings(
2860 IN PCWCH String1,
2861 IN SIZE_T String1Length,
2862 IN PCWCH String2,
2863 IN SIZE_T String2Length,
2864 IN BOOLEAN CaseInSensitive);
2865
2866 NTSYSAPI
2867 VOID
2868 NTAPI
2869 RtlCopyUnicodeString(
2870 IN OUT PUNICODE_STRING DestinationString,
2871 IN PCUNICODE_STRING SourceString);
2872
2873 NTSYSAPI
2874 NTSTATUS
2875 NTAPI
2876 RtlCreateRegistryKey(
2877 IN ULONG RelativeTo,
2878 IN PWSTR Path);
2879
2880 NTSYSAPI
2881 NTSTATUS
2882 NTAPI
2883 RtlCreateSecurityDescriptor(
2884 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
2885 IN ULONG Revision);
2886
2887 NTSYSAPI
2888 NTSTATUS
2889 NTAPI
2890 RtlDeleteRegistryValue(
2891 IN ULONG RelativeTo,
2892 IN PCWSTR Path,
2893 IN PCWSTR ValueName);
2894
2895 NTSYSAPI
2896 BOOLEAN
2897 NTAPI
2898 RtlEqualUnicodeString(
2899 IN CONST UNICODE_STRING *String1,
2900 IN CONST UNICODE_STRING *String2,
2901 IN BOOLEAN CaseInSensitive);
2902
2903 #if !defined(_AMD64_) && !defined(_IA64_)
2904 NTSYSAPI
2905 LARGE_INTEGER
2906 NTAPI
2907 RtlExtendedIntegerMultiply(
2908 IN LARGE_INTEGER Multiplicand,
2909 IN LONG Multiplier);
2910
2911 NTSYSAPI
2912 LARGE_INTEGER
2913 NTAPI
2914 RtlExtendedLargeIntegerDivide(
2915 IN LARGE_INTEGER Dividend,
2916 IN ULONG Divisor,
2917 IN OUT PULONG Remainder);
2918 #endif
2919
2920 #if defined(_X86_) || defined(_IA64_)
2921 NTSYSAPI
2922 LARGE_INTEGER
2923 NTAPI
2924 RtlExtendedMagicDivide(
2925 IN LARGE_INTEGER Dividend,
2926 IN LARGE_INTEGER MagicDivisor,
2927 IN CCHAR ShiftCount);
2928 #endif
2929
2930 NTSYSAPI
2931 VOID
2932 NTAPI
2933 RtlFreeAnsiString(
2934 IN PANSI_STRING AnsiString);
2935
2936 NTSYSAPI
2937 ULONG
2938 NTAPI
2939 RtlFindClearBits(
2940 IN PRTL_BITMAP BitMapHeader,
2941 IN ULONG NumberToFind,
2942 IN ULONG HintIndex);
2943
2944 NTSYSAPI
2945 ULONG
2946 NTAPI
2947 RtlFindClearBitsAndSet(
2948 IN PRTL_BITMAP BitMapHeader,
2949 IN ULONG NumberToFind,
2950 IN ULONG HintIndex);
2951
2952 NTSYSAPI
2953 ULONG
2954 NTAPI
2955 RtlFindFirstRunClear(
2956 IN PRTL_BITMAP BitMapHeader,
2957 OUT PULONG StartingIndex);
2958
2959 NTSYSAPI
2960 ULONG
2961 NTAPI
2962 RtlFindClearRuns(
2963 IN PRTL_BITMAP BitMapHeader,
2964 OUT PRTL_BITMAP_RUN RunArray,
2965 IN ULONG SizeOfRunArray,
2966 IN BOOLEAN LocateLongestRuns);
2967
2968 NTSYSAPI
2969 ULONG
2970 NTAPI
2971 RtlFindLastBackwardRunClear(
2972 IN PRTL_BITMAP BitMapHeader,
2973 IN ULONG FromIndex,
2974 OUT PULONG StartingRunIndex);
2975
2976 NTSYSAPI
2977 CCHAR
2978 NTAPI
2979 RtlFindLeastSignificantBit(
2980 IN ULONGLONG Set);
2981
2982 NTSYSAPI
2983 ULONG
2984 NTAPI
2985 RtlFindLongestRunClear(
2986 IN PRTL_BITMAP BitMapHeader,
2987 OUT PULONG StartingIndex);
2988
2989 NTSYSAPI
2990 CCHAR
2991 NTAPI
2992 RtlFindMostSignificantBit(
2993 IN ULONGLONG Set);
2994
2995 NTSYSAPI
2996 ULONG
2997 NTAPI
2998 RtlFindNextForwardRunClear(
2999 IN PRTL_BITMAP BitMapHeader,
3000 IN ULONG FromIndex,
3001 OUT PULONG StartingRunIndex);
3002
3003 NTSYSAPI
3004 ULONG
3005 NTAPI
3006 RtlFindSetBits(
3007 IN PRTL_BITMAP BitMapHeader,
3008 IN ULONG NumberToFind,
3009 IN ULONG HintIndex);
3010
3011 NTSYSAPI
3012 ULONG
3013 NTAPI
3014 RtlFindSetBitsAndClear(
3015 IN PRTL_BITMAP BitMapHeader,
3016 IN ULONG NumberToFind,
3017 IN ULONG HintIndex);
3018
3019 NTSYSAPI
3020 NTSTATUS
3021 NTAPI
3022 RtlHashUnicodeString(
3023 IN CONST UNICODE_STRING *String,
3024 IN BOOLEAN CaseInSensitive,
3025 IN ULONG HashAlgorithm,
3026 OUT PULONG HashValue);
3027
3028 NTSYSAPI
3029 VOID
3030 NTAPI
3031 RtlInitAnsiString(
3032 IN OUT PANSI_STRING DestinationString,
3033 IN PCSZ SourceString);
3034
3035 NTSYSAPI
3036 VOID
3037 NTAPI
3038 RtlInitializeBitMap(
3039 IN PRTL_BITMAP BitMapHeader,
3040 IN PULONG BitMapBuffer,
3041 IN ULONG SizeOfBitMap);
3042
3043 NTSYSAPI
3044 VOID
3045 NTAPI
3046 RtlInitString(
3047 IN OUT PSTRING DestinationString,
3048 IN PCSZ SourceString);
3049
3050 NTSYSAPI
3051 NTSTATUS
3052 NTAPI
3053 RtlIntegerToUnicodeString(
3054 IN ULONG Value,
3055 IN ULONG Base OPTIONAL,
3056 IN OUT PUNICODE_STRING String);
3057
3058 NTSYSAPI
3059 NTSTATUS
3060 NTAPI
3061 RtlInt64ToUnicodeString(
3062 IN ULONGLONG Value,
3063 IN ULONG Base OPTIONAL,
3064 IN OUT PUNICODE_STRING String);
3065
3066 #ifdef _WIN64
3067 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3068 RtlInt64ToUnicodeString(Value, Base, String)
3069 #else
3070 #define RtlIntPtrToUnicodeString(Value, Base, String) \
3071 RtlIntegerToUnicodeString(Value, Base, String)
3072 #endif
3073
3074 /* BOOLEAN
3075 * RtlIsZeroLuid(
3076 * IN PLUID L1);
3077 */
3078 #define RtlIsZeroLuid(_L1) \
3079 ((BOOLEAN) ((!(_L1)->LowPart) && (!(_L1)->HighPart)))
3080
3081 NTSYSAPI
3082 ULONG
3083 NTAPI
3084 RtlLengthSecurityDescriptor(
3085 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3086
3087 NTSYSAPI
3088 ULONG
3089 NTAPI
3090 RtlNumberOfClearBits(
3091 IN PRTL_BITMAP BitMapHeader);
3092
3093 NTSYSAPI
3094 ULONG
3095 NTAPI
3096 RtlNumberOfSetBits(
3097 IN PRTL_BITMAP BitMapHeader);
3098
3099 NTSYSAPI
3100 NTSTATUS
3101 NTAPI
3102 RtlQueryRegistryValues(
3103 IN ULONG RelativeTo,
3104 IN PCWSTR Path,
3105 IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
3106 IN PVOID Context,
3107 IN PVOID Environment OPTIONAL);
3108
3109 #define LONG_SIZE (sizeof(LONG))
3110 #define LONG_MASK (LONG_SIZE - 1)
3111
3112 /* VOID
3113 * RtlRetrieveUlong(
3114 * PULONG DestinationAddress,
3115 * PULONG SourceAddress);
3116 */
3117 #if defined(_AMD64_)
3118 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3119 *(ULONG UNALIGNED *)(DestAddress) = *(PULONG)(SrcAddress)
3120 #else
3121 #define RtlRetrieveUlong(DestAddress,SrcAddress) \
3122 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3123 { \
3124 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3125 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3126 ((PUCHAR)(DestAddress))[2]=((PUCHAR)(SrcAddress))[2]; \
3127 ((PUCHAR)(DestAddress))[3]=((PUCHAR)(SrcAddress))[3]; \
3128 } \
3129 else \
3130 { \
3131 *((PULONG)(DestAddress))=*((PULONG)(SrcAddress)); \
3132 }
3133 #endif
3134
3135 /* VOID
3136 * RtlRetrieveUshort(
3137 * PUSHORT DestinationAddress,
3138 * PUSHORT SourceAddress);
3139 */
3140 #if defined(_AMD64_)
3141 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3142 *(USHORT UNALIGNED *)(DestAddress) = *(USHORT)(SrcAddress)
3143 #else
3144 #define RtlRetrieveUshort(DestAddress,SrcAddress) \
3145 if ((ULONG_PTR)(SrcAddress) & LONG_MASK) \
3146 { \
3147 ((PUCHAR)(DestAddress))[0]=((PUCHAR)(SrcAddress))[0]; \
3148 ((PUCHAR)(DestAddress))[1]=((PUCHAR)(SrcAddress))[1]; \
3149 } \
3150 else \
3151 { \
3152 *((PUSHORT)(DestAddress))=*((PUSHORT)(SrcAddress)); \
3153 }
3154 #endif
3155
3156 NTSYSAPI
3157 VOID
3158 NTAPI
3159 RtlSetAllBits(
3160 IN PRTL_BITMAP BitMapHeader);
3161
3162 NTSYSAPI
3163 VOID
3164 NTAPI
3165 RtlSetBits(
3166 IN PRTL_BITMAP BitMapHeader,
3167 IN ULONG StartingIndex,
3168 IN ULONG NumberToSet);
3169
3170 NTSYSAPI
3171 NTSTATUS
3172 NTAPI
3173 RtlSetDaclSecurityDescriptor(
3174 IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor,
3175 IN BOOLEAN DaclPresent,
3176 IN PACL Dacl OPTIONAL,
3177 IN BOOLEAN DaclDefaulted OPTIONAL);
3178
3179 /* VOID
3180 * RtlStoreUlong(
3181 * IN PULONG Address,
3182 * IN ULONG Value);
3183 */
3184 #if defined(_AMD64_)
3185 #define RtlStoreUlong(Address,Value) \
3186 *(ULONG UNALIGNED *)(Address) = (Value)
3187 #else
3188 #define RtlStoreUlong(Address,Value) \
3189 if ((ULONG_PTR)(Address) & LONG_MASK) { \
3190 ((PUCHAR) (Address))[LONG_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3191 ((PUCHAR) (Address))[LONG_3RD_MOST_SIGNIFICANT_BIT] = (UCHAR)(SECONDBYTE(Value)); \
3192 ((PUCHAR) (Address))[LONG_2ND_MOST_SIGNIFICANT_BIT] = (UCHAR)(THIRDBYTE(Value)); \
3193 ((PUCHAR) (Address))[LONG_MOST_SIGNIFICANT_BIT] = (UCHAR)(FOURTHBYTE(Value)); \
3194 } \
3195 else { \
3196 *((PULONG)(Address)) = (ULONG) (Value); \
3197 }
3198 #endif
3199
3200 /* VOID
3201 * RtlStoreUlonglong(
3202 * IN OUT PULONGLONG Address,
3203 * ULONGLONG Value);
3204 */
3205 #if defined(_AMD64_)
3206 #define RtlStoreUlonglong(Address,Value) \
3207 *(ULONGLONG UNALIGNED *)(Address) = (Value)
3208 #else
3209 #define RtlStoreUlonglong(Address,Value) \
3210 if ((ULONG_PTR)(Address) & LONGLONG_MASK) { \
3211 RtlStoreUlong((ULONG_PTR)(Address), \
3212 (ULONGLONG)(Value) & 0xFFFFFFFF); \
3213 RtlStoreUlong((ULONG_PTR)(Address)+sizeof(ULONG), \
3214 (ULONGLONG)(Value) >> 32); \
3215 } else { \
3216 *((PULONGLONG)(Address)) = (ULONGLONG)(Value); \
3217 }
3218 #endif
3219
3220 /* VOID
3221 * RtlStoreUlongPtr(
3222 * IN OUT PULONG_PTR Address,
3223 * IN ULONG_PTR Value);
3224 */
3225 #ifdef _WIN64
3226 #define RtlStoreUlongPtr(Address,Value) \
3227 RtlStoreUlonglong(Address,Value)
3228 #else
3229 #define RtlStoreUlongPtr(Address,Value) \
3230 RtlStoreUlong(Address,Value)
3231 #endif
3232
3233 /* VOID
3234 * RtlStoreUshort(
3235 * IN PUSHORT Address,
3236 * IN USHORT Value);
3237 */
3238 #if defined(_AMD64_)
3239 #define RtlStoreUshort(Address,Value) \
3240 *(USHORT UNALIGNED *)(Address) = (Value)
3241 #else
3242 #define RtlStoreUshort(Address,Value) \
3243 if ((ULONG_PTR)(Address) & SHORT_MASK) { \
3244 ((PUCHAR) (Address))[SHORT_LEAST_SIGNIFICANT_BIT] = (UCHAR)(FIRSTBYTE(Value)); \
3245 ((PUCHAR) (Address))[SHORT_MOST_SIGNIFICANT_BIT ] = (UCHAR)(SECONDBYTE(Value)); \
3246 } \
3247 else { \
3248 *((PUSHORT) (Address)) = (USHORT)Value; \
3249 }
3250 #endif
3251
3252 NTSYSAPI
3253 BOOLEAN
3254 NTAPI
3255 RtlTimeFieldsToTime(
3256 IN PTIME_FIELDS TimeFields,
3257 IN PLARGE_INTEGER Time);
3258
3259 NTSYSAPI
3260 VOID
3261 NTAPI
3262 RtlTimeToTimeFields(
3263 IN PLARGE_INTEGER Time,
3264 IN PTIME_FIELDS TimeFields);
3265
3266 NTSYSAPI
3267 ULONG
3268 FASTCALL
3269 RtlUlongByteSwap(
3270 IN ULONG Source);
3271
3272 NTSYSAPI
3273 ULONGLONG
3274 FASTCALL
3275 RtlUlonglongByteSwap(
3276 IN ULONGLONG Source);
3277
3278 NTSYSAPI
3279 NTSTATUS
3280 NTAPI
3281 RtlUnicodeStringToAnsiString(
3282 IN OUT PANSI_STRING DestinationString,
3283 IN PCUNICODE_STRING SourceString,
3284 IN BOOLEAN AllocateDestinationString);
3285
3286 NTSYSAPI
3287 ULONG
3288 NTAPI
3289 RtlxUnicodeStringToAnsiSize(
3290 IN PCUNICODE_STRING UnicodeString);
3291
3292 #define RtlUnicodeStringToAnsiSize(String) ( \
3293 NLS_MB_CODE_PAGE_TAG ? \
3294 RtlxUnicodeStringToAnsiSize(String) : \
3295 ((String)->Length + sizeof(UNICODE_NULL)) / sizeof(WCHAR) \
3296 )
3297
3298 NTSYSAPI
3299 NTSTATUS
3300 NTAPI
3301 RtlUnicodeStringToInteger(
3302 IN PCUNICODE_STRING String,
3303 IN ULONG Base OPTIONAL,
3304 OUT PULONG Value);
3305
3306 NTSYSAPI
3307 WCHAR
3308 NTAPI
3309 RtlUpcaseUnicodeChar(
3310 IN WCHAR SourceCharacter);
3311
3312 NTSYSAPI
3313 USHORT
3314 FASTCALL
3315 RtlUshortByteSwap(
3316 IN USHORT Source);
3317
3318 NTSYSAPI
3319 BOOLEAN
3320 NTAPI
3321 RtlValidRelativeSecurityDescriptor(
3322 IN PSECURITY_DESCRIPTOR SecurityDescriptorInput,
3323 IN ULONG SecurityDescriptorLength,
3324 IN SECURITY_INFORMATION RequiredInformation);
3325
3326 NTSYSAPI
3327 BOOLEAN
3328 NTAPI
3329 RtlValidSecurityDescriptor(
3330 IN PSECURITY_DESCRIPTOR SecurityDescriptor);
3331
3332 NTSYSAPI
3333 NTSTATUS
3334 NTAPI
3335 RtlWriteRegistryValue(
3336 IN ULONG RelativeTo,
3337 IN PCWSTR Path,
3338 IN PCWSTR ValueName,
3339 IN ULONG ValueType,
3340 IN PVOID ValueData,
3341 IN ULONG ValueLength);
3342
3343 #endif // (NTDDI_VERSION >= NTDDI_WIN2K)
3344
3345 #if (NTDDI_VERSION >= NTDDI_WIN2KSP3)
3346 NTSYSAPI
3347 VOID
3348 FASTCALL
3349 RtlPrefetchMemoryNonTemporal(
3350 IN PVOID Source,
3351 IN SIZE_T Length);
3352 #endif
3353
3354 #if (NTDDI_VERSION >= NTDDI_WINXP)
3355 NTSYSAPI
3356 VOID
3357 NTAPI
3358 RtlClearBit(
3359 PRTL_BITMAP BitMapHeader,
3360 ULONG BitNumber);
3361
3362 NTSYSAPI
3363 WCHAR
3364 NTAPI
3365 RtlDowncaseUnicodeChar(
3366 IN WCHAR SourceCharacter);
3367
3368 NTSYSAPI
3369 VOID
3370 NTAPI
3371 RtlSetBit(
3372 PRTL_BITMAP BitMapHeader,
3373 ULONG BitNumber);
3374
3375 NTSYSAPI
3376 BOOLEAN
3377 NTAPI
3378 RtlTestBit(
3379 IN PRTL_BITMAP BitMapHeader,
3380 IN ULONG BitNumber);
3381
3382 #endif // (NTDDI_VERSION >= NTDDI_WINXP)
3383
3384 #if (NTDDI_VERSION >= NTDDI_VISTA)
3385 NTSYSAPI
3386 ULONG
3387 NTAPI
3388 RtlNumberOfSetBitsUlongPtr(
3389 IN ULONG_PTR Target);
3390
3391 NTSYSAPI
3392 ULONGLONG
3393 NTAPI
3394 RtlIoDecodeMemIoResource (
3395 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
3396 OUT PULONGLONG Alignment OPTIONAL,
3397 OUT PULONGLONG MinimumAddress OPTIONAL,
3398 OUT PULONGLONG MaximumAddress OPTIONAL);
3399
3400 NTSYSAPI
3401 NTSTATUS
3402 NTAPI
3403 RtlIoEncodeMemIoResource(
3404 IN PIO_RESOURCE_DESCRIPTOR Descriptor,
3405 IN UCHAR Type,
3406 IN ULONGLONG Length,
3407 IN ULONGLONG Alignment,
3408 IN ULONGLONG MinimumAddress,
3409 IN ULONGLONG MaximumAddress);
3410
3411 NTSYSAPI
3412 ULONGLONG
3413 NTAPI
3414 RtlCmDecodeMemIoResource(
3415 IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
3416 OUT PULONGLONG Start OPTIONAL);
3417
3418 NTSYSAPI
3419 NTSTATUS
3420 NTAPI
3421 RtlFindClosestEncodableLength(
3422 IN ULONGLONG SourceLength,
3423 OUT PULONGLONG TargetLength);
3424
3425 #endif
3426
3427 #if !defined(MIDL_PASS)
3428 /* inline funftions */
3429 //DECLSPEC_DEPRECATED_DDK_WINXP
3430 static __inline
3431 LARGE_INTEGER
3432 NTAPI_INLINE
3433 RtlConvertLongToLargeInteger(LONG SignedInteger)
3434 {
3435 LARGE_INTEGER ret;
3436 ret.QuadPart = SignedInteger;
3437 return ret;
3438 }
3439
3440 //DECLSPEC_DEPRECATED_DDK_WINXP
3441 static __inline
3442 LARGE_INTEGER
3443 NTAPI_INLINE
3444 RtlConvertUlongToLargeInteger(
3445 ULONG UnsignedInteger)
3446 {
3447 LARGE_INTEGER ret;
3448 ret.QuadPart = UnsignedInteger;
3449 return ret;
3450 }
3451
3452 //DECLSPEC_DEPRECATED_DDK
3453 static __inline
3454 ULONG
3455 NTAPI_INLINE
3456 RtlEnlargedUnsignedDivide(
3457 IN ULARGE_INTEGER Dividend,
3458 IN ULONG Divisor,
3459 IN OUT PULONG Remainder)
3460 {
3461 if (Remainder)
3462 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3463 return (ULONG)(Dividend.QuadPart / Divisor);
3464 }
3465
3466 //DECLSPEC_DEPRECATED_DDK
3467 static __inline
3468 LARGE_INTEGER
3469 NTAPI_INLINE
3470 RtlEnlargedUnsignedMultiply(
3471 IN ULONG Multiplicand,
3472 IN ULONG Multiplier)
3473 {
3474 LARGE_INTEGER ret;
3475 ret.QuadPart = (ULONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3476 return ret;
3477 }
3478
3479 //DECLSPEC_DEPRECATED_DDK
3480 static __inline
3481 LARGE_INTEGER
3482 NTAPI_INLINE
3483 RtlEnlargedIntegerMultiply(
3484 IN LONG Multiplicand,
3485 IN LONG Multiplier)
3486 {
3487 LARGE_INTEGER ret;
3488 ret.QuadPart = (LONGLONG)Multiplicand * (ULONGLONG)Multiplier;
3489 return ret;
3490 }
3491
3492 FORCEINLINE
3493 VOID
3494 RtlInitEmptyAnsiString(OUT PANSI_STRING AnsiString,
3495 IN PCHAR Buffer,
3496 IN USHORT BufferSize)
3497 {
3498 AnsiString->Length = 0;
3499 AnsiString->MaximumLength = BufferSize;
3500 AnsiString->Buffer = Buffer;
3501 }
3502
3503 FORCEINLINE
3504 VOID
3505 RtlInitEmptyUnicodeString(
3506 OUT PUNICODE_STRING UnicodeString,
3507 IN PWSTR Buffer,
3508 IN USHORT BufferSize)
3509 {
3510 UnicodeString->Length = 0;
3511 UnicodeString->MaximumLength = BufferSize;
3512 UnicodeString->Buffer = Buffer;
3513 }
3514
3515 #if defined(_AMD64_) || defined(_IA64_)
3516 static __inline
3517 LARGE_INTEGER
3518 NTAPI_INLINE
3519 RtlExtendedIntegerMultiply(
3520 LARGE_INTEGER Multiplicand,
3521 LONG Multiplier)
3522 {
3523 LARGE_INTEGER ret;
3524 ret.QuadPart = Multiplicand.QuadPart * Multiplier;
3525 return ret;
3526 }
3527
3528 static __inline
3529 LARGE_INTEGER
3530 NTAPI_INLINE
3531 RtlExtendedLargeIntegerDivide(
3532 LARGE_INTEGER Dividend,
3533 ULONG Divisor,
3534 PULONG Remainder)
3535 {
3536 LARGE_INTEGER ret;
3537 ret.QuadPart = (ULONG64)Dividend.QuadPart / Divisor;
3538 if (Remainder)
3539 *Remainder = (ULONG)(Dividend.QuadPart % Divisor);
3540 return ret;
3541 }
3542 #endif
3543
3544 #if defined(_AMD64_)
3545
3546 #define MultiplyHigh __mulh
3547 #define UnsignedMultiplyHigh __umulh
3548
3549 //DECLSPEC_DEPRECATED_DDK
3550 static __inline
3551 LARGE_INTEGER
3552 NTAPI_INLINE
3553 RtlExtendedMagicDivide(
3554 IN LARGE_INTEGER Dividend,
3555 IN LARGE_INTEGER MagicDivisor,
3556 IN CCHAR ShiftCount)
3557 {
3558 LARGE_INTEGER ret;
3559 ULONG64 ret64;
3560 BOOLEAN Pos;
3561 Pos = (Dividend.QuadPart >= 0);
3562 ret64 = UnsignedMultiplyHigh(Pos ? Dividend.QuadPart : -Dividend.QuadPart,
3563 MagicDivisor.QuadPart);
3564 ret64 >>= ShiftCount;
3565 ret.QuadPart = Pos ? ret64 : -ret64;
3566 return ret;
3567 }
3568 #endif
3569
3570 //DECLSPEC_DEPRECATED_DDK
3571 static __inline
3572 LARGE_INTEGER
3573 NTAPI_INLINE
3574 RtlLargeIntegerAdd(
3575 IN LARGE_INTEGER Addend1,
3576 IN LARGE_INTEGER Addend2)
3577 {
3578 LARGE_INTEGER ret;
3579 ret.QuadPart = Addend1.QuadPart + Addend2.QuadPart;
3580 return ret;
3581 }
3582
3583 /* VOID
3584 * RtlLargeIntegerAnd(
3585 * IN OUT LARGE_INTEGER Result,
3586 * IN LARGE_INTEGER Source,
3587 * IN LARGE_INTEGER Mask);
3588 */
3589 #define RtlLargeIntegerAnd(Result, Source, Mask) \
3590 Result.QuadPart = Source.QuadPart & Mask.QuadPart
3591
3592 //DECLSPEC_DEPRECATED_DDK
3593 static __inline
3594 LARGE_INTEGER
3595 NTAPI_INLINE
3596 RtlLargeIntegerArithmeticShift(
3597 IN LARGE_INTEGER LargeInteger,
3598 IN CCHAR ShiftCount)
3599 {
3600 LARGE_INTEGER ret;
3601 ret.QuadPart = LargeInteger.QuadPart >> ShiftCount;
3602 return ret;
3603 }
3604
3605 /* BOOLEAN
3606 * RtlLargeIntegerEqualTo(
3607 * IN LARGE_INTEGER Operand1,
3608 * IN LARGE_INTEGER Operand2);
3609 */
3610 #define RtlLargeIntegerEqualTo(X,Y) \
3611 (!(((X).LowPart ^ (Y).LowPart) | ((X).HighPart ^ (Y).HighPart)))
3612
3613 FORCEINLINE
3614 PVOID
3615 RtlSecureZeroMemory(
3616 OUT PVOID Pointer,
3617 IN SIZE_T Size)
3618 {
3619 volatile char* vptr = (volatile char*)Pointer;
3620 #if defined(_M_AMD64)
3621 __stosb((PUCHAR)vptr, 0, Size);
3622 #else
3623 char * endptr = (char *)vptr + Size;
3624 while (vptr < endptr)
3625 {
3626 *vptr = 0; vptr++;
3627 }
3628 #endif
3629 return Pointer;
3630 }
3631
3632 #if defined(_M_AMD64)
3633 FORCEINLINE
3634 ULONG
3635 RtlCheckBit(
3636 IN PRTL_BITMAP BitMapHeader,
3637 IN ULONG BitPosition)
3638 {
3639 return BitTest((LONG CONST*)BitMapHeader->Buffer, BitPosition);
3640 }
3641 #else
3642 #define RtlCheckBit(BMH,BP) (((((PLONG)(BMH)->Buffer)[(BP)/32]) >> ((BP)%32)) & 0x1)
3643 #endif // defined(_M_AMD64)
3644
3645 #endif // !defined(MIDL_PASS)
3646
3647 //
3648 // Byte Swap Functions
3649 //
3650 #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037 || defined(__GNUC__))) || \
3651 ((defined(_M_AMD64) || defined(_M_IA64)) \
3652 && (_MSC_FULL_VER > 13009175 || defined(__GNUC__)))
3653
3654 #define RtlUshortByteSwap(_x) _byteswap_ushort((USHORT)(_x))
3655 #define RtlUlongByteSwap(_x) _byteswap_ulong((_x))
3656 #define RtlUlonglongByteSwap(_x) _byteswap_uint64((_x))
3657
3658 #endif
3659
3660 /******************************************************************************
3661 * Memory manager Types *
3662 ******************************************************************************/
3663
3664 typedef struct _MDL {
3665 struct _MDL *Next;
3666 CSHORT Size;
3667 CSHORT MdlFlags;
3668 struct _EPROCESS *Process;
3669 PVOID MappedSystemVa;
3670 PVOID StartVa;
3671 ULONG ByteCount;
3672 ULONG ByteOffset;
3673 } MDL, *PMDL;
3674
3675
3676 /******************************************************************************
3677 * Memory manager Functions *
3678 ******************************************************************************/
3679
3680 /* PVOID MmGetSystemAddressForMdl(
3681 * IN PMDL Mdl);
3682 */
3683 #define MmGetSystemAddressForMdl(Mdl) \
3684 (((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
3685 MDL_SOURCE_IS_NONPAGED_POOL)) ? \
3686 ((Mdl)->MappedSystemVa) : \
3687 (MmMapLockedPages((Mdl), KernelMode)))
3688
3689 /* PVOID
3690 * MmGetSystemAddressForMdlSafe(
3691 * IN PMDL Mdl,
3692 * IN MM_PAGE_PRIORITY Priority)
3693 */
3694 #define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
3695 (((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
3696 | MDL_SOURCE_IS_NONPAGED_POOL)) ? \
3697 (_Mdl)->MappedSystemVa : \
3698 (PVOID) MmMapLockedPagesSpecifyCache((_Mdl), \
3699 KernelMode, MmCached, NULL, FALSE, (_Priority)))
3700
3701 #if (NTDDI_VERSION >= NTDDI_WIN2K)
3702 NTKERNELAPI
3703 PMDL
3704 NTAPI
3705 MmCreateMdl(
3706 IN PMDL MemoryDescriptorList OPTIONAL,
3707 IN PVOID Base,
3708 IN SIZE_T Length);
3709
3710 #endif
3711
3712
3713 /******************************************************************************
3714 * I/O Manager Functions *
3715 ******************************************************************************/
3716
3717 #if defined(USE_DMA_MACROS) && !defined(_NTHAL_) && \
3718 (defined(_NTDDK_) || defined(_NTDRIVER_)) || defined(_WDM_INCLUDED_)
3719
3720 #define DMA_MACROS_DEFINED
3721
3722 FORCEINLINE
3723 NTSTATUS
3724 IoAllocateAdapterChannel(
3725 IN PADAPTER_OBJECT AdapterObject,
3726 IN PDEVICE_OBJECT DeviceObject,
3727 IN ULONG NumberOfMapRegisters,
3728 IN PDRIVER_CONTROL ExecutionRoutine,
3729 IN PVOID Context)
3730 {
3731 PALLOCATE_ADAPTER_CHANNEL AllocateAdapterChannel;
3732 AllocateAdapterChannel =
3733 *(DmaAdapter)->DmaOperations->AllocateAdapterChannel;
3734 ASSERT(AllocateAdapterChannel);
3735 return AllocateAdapterChannel(DmaAdapter,
3736 DeviceObject,
3737 NumberOfMapRegisters,
3738 ExecutionRoutine,
3739 Context );
3740 }
3741
3742 FORCEINLINE
3743 BOOLEAN
3744 IoFlushAdapterBuffers(
3745 IN PADAPTER_OBJECT AdapterObject,
3746 IN PMDL Mdl,
3747 IN PVOID MapRegisterBase,
3748 IN PVOID CurrentVa,
3749 IN ULONG Length,
3750 IN BOOLEAN WriteToDevice)
3751 {
3752 PFLUSH_ADAPTER_BUFFERS FlushAdapterBuffers;
3753 FlushAdapterBuffers = *(DmaAdapter)->DmaOperations->FlushAdapterBuffers;
3754 ASSERT(FlushAdapterBuffers);
3755 return FlushAdapterBuffers(DmaAdapter,
3756 Mdl,
3757 MapRegisterBase,
3758 CurrentVa,
3759 Length,
3760 WriteToDevice );
3761 }
3762
3763 FORCEINLINE
3764 VOID
3765 IoFreeAdapterChannel(
3766 IN PADAPTER_OBJECT AdapterObject)
3767 {
3768 PFREE_ADAPTER_CHANNEL FreeAdapterChannel;
3769 FreeAdapterChannel = *(DmaAdapter)->DmaOperations->FreeAdapterChannel;
3770 ASSERT(FreeAdapterChannel);
3771 FreeAdapterChannel(DmaAdapter);
3772 }
3773
3774 FORCEINLINE
3775 VOID
3776 IoFreeMapRegisters(
3777 IN PADAPTER_OBJECT AdapterObject,
3778 IN PVOID MapRegisterBase,
3779 IN ULONG NumberOfMapRegisters)
3780 {
3781 PFREE_MAP_REGISTERS FreeMapRegisters;
3782 FreeMapRegisters = *(DmaAdapter)->DmaOperations->FreeMapRegisters;
3783 ASSERT(FreeMapRegisters);
3784 FreeMapRegisters(DmaAdapter, MapRegisterBase, NumberOfMapRegisters);
3785 }
3786
3787 FORCEINLINE
3788 PHYSICAL_ADDRESS
3789 IoMapTransfer(
3790 IN PDMA_ADAPTER DmaAdapter,
3791 IN PMDL Mdl,
3792 IN PVOID MapRegisterBase,
3793 IN PVOID CurrentVa,
3794 IN OUT PULONG Length,
3795 IN BOOLEAN WriteToDevice)
3796 {
3797 PMAP_TRANSFER MapTransfer;
3798
3799 MapTransfer = *(DmaAdapter)->DmaOperations->MapTransfer;
3800 ASSERT(MapTransfer);
3801 return MapTransfer(DmaAdapter,
3802 Mdl,
3803 MapRegisterBase,
3804 CurrentVa,
3805 Length,
3806 WriteToDevice);
3807 }
3808 #endif
3809
3810
3811 /******************************************************************************
3812 * Executive Types *
3813 ******************************************************************************/
3814
3815 typedef enum _POOL_TYPE {
3816 NonPagedPool,
3817 PagedPool,
3818 NonPagedPoolMustSucceed,
3819 DontUseThisType,
3820 NonPagedPoolCacheAligned,
3821 PagedPoolCacheAligned,
3822 NonPagedPoolCacheAlignedMustS,
3823 MaxPoolType,
3824 NonPagedPoolSession = 32,
3825 PagedPoolSession,
3826 NonPagedPoolMustSucceedSession,
3827 DontUseThisTypeSession,
3828 NonPagedPoolCacheAlignedSession,
3829 PagedPoolCacheAlignedSession,
3830 NonPagedPoolCacheAlignedMustSSession
3831 } POOL_TYPE;
3832
3833 typedef enum _SUITE_TYPE {
3834 SmallBusiness,
3835 Enterprise,
3836 BackOffice,
3837 CommunicationServer,
3838 TerminalServer,
3839 SmallBusinessRestricted,
3840 EmbeddedNT,
3841 DataCenter,
3842 SingleUserTS,
3843 Personal,
3844 Blade,
3845 MaxSuiteType
3846 } SUITE_TYPE;
3847
3848 typedef enum _EX_POOL_PRIORITY {
3849 LowPoolPriority,
3850 LowPoolPrioritySpecialPoolOverrun = 8,
3851 LowPoolPrioritySpecialPoolUnderrun = 9,
3852 NormalPoolPriority = 16,
3853 NormalPoolPrioritySpecialPoolOverrun = 24,
3854 NormalPoolPrioritySpecialPoolUnderrun = 25,
3855 HighPoolPriority = 32,
3856 HighPoolPrioritySpecialPoolOverrun = 40,
3857 HighPoolPrioritySpecialPoolUnderrun = 41
3858 } EX_POOL_PRIORITY;
3859
3860 typedef struct _FAST_MUTEX
3861 {
3862 LONG Count;
3863 PKTHREAD Owner;
3864 ULONG Contention;
3865 KEVENT Gate;
3866 ULONG OldIrql;
3867 } FAST_MUTEX, *PFAST_MUTEX;
3868
3869 typedef ULONG_PTR ERESOURCE_THREAD, *PERESOURCE_THREAD;
3870
3871 typedef struct _OWNER_ENTRY {
3872 ERESOURCE_THREAD OwnerThread;
3873 _ANONYMOUS_UNION union {
3874 LONG OwnerCount;
3875 ULONG TableSize;
3876 } DUMMYUNIONNAME;
3877 } OWNER_ENTRY, *POWNER_ENTRY;
3878
3879 typedef struct _ERESOURCE
3880 {
3881 LIST_ENTRY SystemResourcesList;
3882 POWNER_ENTRY OwnerTable;
3883 SHORT ActiveCount;
3884 USHORT Flag;
3885 volatile PKSEMAPHORE SharedWaiters;
3886 volatile PKEVENT ExclusiveWaiters;
3887 OWNER_ENTRY OwnerEntry;
3888 ULONG ActiveEntries;
3889 ULONG ContentionCount;
3890 ULONG NumberOfSharedWaiters;
3891 ULONG NumberOfExclusiveWaiters;
3892 __GNU_EXTENSION union
3893 {
3894 PVOID Address;
3895 ULONG_PTR CreatorBackTraceIndex;
3896 };
3897 KSPIN_LOCK SpinLock;
3898 } ERESOURCE, *PERESOURCE;
3899
3900 #if !defined(_WIN64) && (defined(_NTDDK_) || defined(_NTIFS_) || defined(_NDIS_))
3901 #define LOOKASIDE_ALIGN
3902 #else
3903 #define LOOKASIDE_ALIGN /* FIXME: DECLSPEC_CACHEALIGN */
3904 #endif
3905
3906 typedef struct _LOOKASIDE_LIST_EX *PLOOKASIDE_LIST_EX;
3907
3908 typedef PVOID
3909 (DDKAPI *PALLOCATE_FUNCTION)(
3910 IN POOL_TYPE PoolType,
3911 IN SIZE_T NumberOfBytes,
3912 IN ULONG Tag);
3913
3914 typedef PVOID
3915 (DDKAPI *PALLOCATE_FUNCTION_EX)(
3916 IN POOL_TYPE PoolType,
3917 IN SIZE_T NumberOfBytes,
3918 IN ULONG Tag,
3919 IN OUT PLOOKASIDE_LIST_EX Lookaside);
3920
3921 typedef VOID
3922 (DDKAPI *PFREE_FUNCTION)(
3923 IN PVOID Buffer);
3924
3925 typedef VOID
3926 (DDKAPI *PFREE_FUNCTION_EX)(
3927 IN PVOID Buffer,
3928 IN OUT PLOOKASIDE_LIST_EX Lookaside);
3929
3930 typedef VOID
3931 (DDKAPI *PCALLBACK_FUNCTION)(
3932 IN PVOID CallbackContext,
3933 IN PVOID Argument1,
3934 IN PVOID Argument2);
3935
3936 typedef struct LOOKASIDE_ALIGN _GENERAL_LOOKASIDE {
3937 union {
3938 SLIST_HEADER ListHead;
3939 SINGLE_LIST_ENTRY SingleListHead;
3940 } DUMMYUNIONNAME;
3941 USHORT Depth;
3942 USHORT MaximumDepth;
3943 ULONG TotalAllocates;
3944 union {
3945 ULONG AllocateMisses;
3946 ULONG AllocateHits;
3947 } DUMMYUNIONNAME2;
3948 ULONG TotalFrees;
3949 union {
3950 ULONG FreeMisses;
3951 ULONG FreeHits;
3952 } DUMMYUNIONNAME3;
3953 POOL_TYPE Type;
3954 ULONG Tag;
3955 ULONG Size;
3956 union {
3957 PALLOCATE_FUNCTION_EX AllocateEx;
3958 PALLOCATE_FUNCTION Allocate;
3959 } DUMMYUNIONNAME4;
3960 union {
3961 PFREE_FUNCTION_EX FreeEx;
3962 PFREE_FUNCTION Free;
3963 } DUMMYUNIONNAME5;
3964 LIST_ENTRY ListEntry;
3965 ULONG LastTotalAllocates;
3966 union {
3967 ULONG LastAllocateMisses;
3968 ULONG LastAllocateHits;
3969 } DUMMYUNIONNAME6;
3970 ULONG Future[2];
3971 } GENERAL_LOOKASIDE, *PGENERAL_LOOKASIDE;
3972
3973 typedef struct _PAGED_LOOKASIDE_LIST {