2 * Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #ifndef _WINNT_TYPES_H_
17 #define _WINNT_TYPES_H_
22 #define PASSIVE_LEVEL 0
24 #define DISPATCH_LEVEL 2
25 #define DEVICE_LEVEL_BASE 4
27 /* soft interrupts / bottom-half's are disabled at SOFT_IRQL */
28 #define SOFT_IRQL (DEVICE_LEVEL_BASE + 1)
29 #define DIRQL (DEVICE_LEVEL_BASE + 2)
31 #define STATUS_WAIT_0 0
32 #define STATUS_SUCCESS 0
33 #define STATUS_ALERTED 0x00000101
34 #define STATUS_TIMEOUT 0x00000102
35 #define STATUS_PENDING 0x00000103
36 #define STATUS_FAILURE 0xC0000001
37 #define STATUS_NOT_IMPLEMENTED 0xC0000002
38 #define STATUS_INVALID_PARAMETER 0xC000000D
39 #define STATUS_INVALID_DEVICE_REQUEST 0xC0000010
40 #define STATUS_MORE_PROCESSING_REQUIRED 0xC0000016
41 #define STATUS_ACCESS_DENIED 0xC0000022
42 #define STATUS_BUFFER_TOO_SMALL 0xC0000023
43 #define STATUS_OBJECT_NAME_INVALID 0xC0000023
44 #define STATUS_MUTANT_NOT_OWNED 0xC0000046
45 #define STATUS_RESOURCES 0xC000009A
46 #define STATUS_DELETE_PENDING 0xC0000056
47 #define STATUS_INSUFFICIENT_RESOURCES 0xC000009A
48 #define STATUS_NOT_SUPPORTED 0xC00000BB
49 #define STATUS_INVALID_PARAMETER_2 0xC00000F0
50 #define STATUS_NO_MEMORY 0xC0000017
51 #define STATUS_CANCELLED 0xC0000120
52 #define STATUS_DEVICE_REMOVED 0xC00002B6
53 #define STATUS_DEVICE_NOT_CONNECTED 0xC000009D
55 #define STATUS_BUFFER_OVERFLOW 0x80000005
57 #define SL_PENDING_RETURNED 0x01
58 #define SL_INVOKE_ON_CANCEL 0x20
59 #define SL_INVOKE_ON_SUCCESS 0x40
60 #define SL_INVOKE_ON_ERROR 0x80
62 #define IRP_MJ_CREATE 0x00
63 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
64 #define IRP_MJ_CLOSE 0x02
65 #define IRP_MJ_READ 0x03
66 #define IRP_MJ_WRITE 0x04
68 #define IRP_MJ_DEVICE_CONTROL 0x0E
69 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0F
70 #define IRP_MJ_POWER 0x16
71 #define IRP_MJ_SYSTEM_CONTROL 0x0E
72 #define IRP_MJ_PNP 0x1b
73 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
75 #define IRP_MN_WAIT_WAKE 0x00
76 #define IRP_MN_POWER_SEQUENCE 0x01
77 #define IRP_MN_SET_POWER 0x02
78 #define IRP_MN_QUERY_POWER 0x03
80 #define IRP_MN_REGINFO 0x08
81 #define IRP_MN_REGINFO_EX 0x0b
83 #define IRP_MN_START_DEVICE 0x00
84 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
85 #define IRP_MN_REMOVE_DEVICE 0x02
86 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
87 #define IRP_MN_STOP_DEVICE 0x04
88 #define IRP_MN_QUERY_STOP_DEVICE 0x05
89 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
90 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
91 #define IRP_MN_QUERY_INTERFACE 0x08
93 #define IRP_BUFFERED_IO 0x00000010
94 #define IRP_DEALLOCATE_BUFFER 0x00000020
95 #define IRP_INPUT_OPERATION 0x00000040
97 #define IRP_DEFFER_IO_COMPLETION 0x00000800
99 #define THREAD_WAIT_OBJECTS 3
100 #define MAX_WAIT_OBJECTS 64
102 #define LOW_PRIORITY 0
103 #define LOW_REALTIME_PRIORITY 16
104 #define HIGH_PRIORITY 31
105 #define MAXIMUM_PRIORITY 32
107 #define PROCESSOR_FEATURE_MAX 64
109 #define IO_NO_INCREMENT 0
111 #define WMIREG_ACTION_REGISTER 1
112 #define WMIREG_ACTION_DEREGISTER 2
113 #define WMIREG_ACTION_REREGISTER 3
114 #define WMIREG_ACTION_UPDATE_GUIDS 4
116 #define WMIREGISTER 0
124 #define KI_USER_SHARED_DATA 0xfffff78000000000UL
128 #define noregparm __attribute__((regparm(0)))
129 #define wstdcall __attribute__((__stdcall__, regparm(0)))
130 #if defined(__GNUC__) && ((__GNUC__ == 3 && __GNUC_MINOR__ > 3) || __GNUC__ > 3)
132 #define wfastcall __attribute__((fastcall))
134 #error "gcc 3.4 or newer should be used for compiling this module"
137 #define KI_USER_SHARED_DATA 0xffdf0000
141 // #define packed __attribute__((packed))
142 #define no_warn_unused __attribute__((unused))
157 typedef s64 LONGLONG;
158 typedef u64 ULONGLONG;
159 typedef u64 ULONGULONG;
163 typedef USHORT wchar_t;
164 typedef SHORT CSHORT;
165 typedef LONGLONG LARGE_INTEGER;
167 typedef LONG NTSTATUS;
169 typedef LONG KPRIORITY;
170 typedef LARGE_INTEGER PHYSICAL_ADDRESS;
172 typedef CHAR KPROCESSOR_MODE;
174 /* ULONG_PTR is 32 bits on 32-bit platforms and 64 bits on 64-bit
175 * platform, which is same as 'unsigned long' in Linux */
176 typedef unsigned long ULONG_PTR;
178 typedef ULONG_PTR SIZE_T;
179 typedef ULONG_PTR KAFFINITY;
180 typedef ULONG ACCESS_MASK;
182 typedef ULONG_PTR PFN_NUMBER;
183 typedef ULONG SECURITY_INFORMATION;
185 /* non-negative numbers indicate success */
186 #define NT_SUCCESS(status) ((NTSTATUS)(status) >= 0)
194 struct unicode_string {
201 struct nt_slist *next;
205 /* it is not clear how nt_slist_head is used to store pointer to
206 * slists and depth; here we assume 'align' field is used to store
207 * depth and 'region' field is used to store slist pointers */
208 struct nt_slist_head {
215 struct nt_slist *next;
217 } __attribute__((aligned(16)));
218 typedef struct nt_slist_head nt_slist_header;
220 union nt_slist_head {
223 struct nt_slist *next;
228 typedef union nt_slist_head nt_slist_header;
232 struct nt_list *next;
233 struct nt_list *prev;
236 typedef ULONG_PTR NT_SPIN_LOCK;
238 enum kdpc_importance {LowImportance, MediumImportance, HighImportance};
241 typedef void (*DPC)(struct kdpc *kdpc, void *ctx, void *arg1,
242 void *arg2) wstdcall;
254 /* 'lock' is not used; 'queued' represents whether
255 * kdpc is queued or not */
261 NonPagedPool, PagedPool, NonPagedPoolMustSucceed, DontUseThisType,
262 NonPagedPoolCacheAligned, PagedPoolCacheAligned,
263 NonPagedPoolCacheAlignedMustS, MaxPoolType,
264 NonPagedPoolSession = 32,
265 PagedPoolSession = NonPagedPoolSession + 1,
266 NonPagedPoolMustSucceedSession = PagedPoolSession + 1,
267 DontUseThisTypeSession = NonPagedPoolMustSucceedSession + 1,
268 NonPagedPoolCacheAlignedSession = DontUseThisTypeSession + 1,
269 PagedPoolCacheAlignedSession = NonPagedPoolCacheAlignedSession + 1,
270 NonPagedPoolCacheAlignedMustSSession = PagedPoolCacheAlignedSession + 1
273 enum memory_caching_type_orig {
274 MmFrameBufferCached = 2
277 enum memory_caching_type {
278 MmNonCached = FALSE, MmCached = TRUE,
279 MmWriteCombined = MmFrameBufferCached, MmHardwareCoherentCached,
280 MmNonCachedUnordered, MmUSWCCached, MmMaximumCacheType
283 enum lock_operation {
284 IoReadAccess, IoWriteAccess, IoModifyAccess
288 KernelMode, UserMode, MaximumMode
295 /* NdisFreeBuffer doesn't pass pool, so we store pool in
296 * unused field 'process' */
301 void *mappedsystemva;
307 #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
308 #define MDL_PAGES_LOCKED 0x0002
309 #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
310 #define MDL_ALLOCATED_FIXED_SIZE 0x0008
311 #define MDL_PARTIAL 0x0010
312 #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
313 #define MDL_IO_PAGE_READ 0x0040
314 #define MDL_WRITE_OPERATION 0x0080
315 #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
316 #define MDL_FREE_EXTRA_PTES 0x0200
317 #define MDL_IO_SPACE 0x0800
318 #define MDL_NETWORK_HEADER 0x1000
319 #define MDL_MAPPING_CAN_FAIL 0x2000
320 #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
322 #define MDL_POOL_ALLOCATED 0x0400
323 #define MDL_CACHE_ALLOCATED 0x8000
325 #define PAGE_START(ptr) ((void *)((ULONG_PTR)(ptr) & ~(PAGE_SIZE - 1)))
326 #define BYTE_OFFSET(ptr) ((ULONG)((ULONG_PTR)(ptr) & (PAGE_SIZE - 1)))
328 #define MmGetMdlByteCount(mdl) ((mdl)->bytecount)
329 #define MmGetMdlVirtualAddress(mdl) ((mdl)->startva + (mdl)->byteoffset)
330 #define MmGetMdlByteOffset(mdl) ((mdl)->byteoffset)
331 #define MmGetSystemAddressForMdl(mdl) ((mdl)->mappedsystemva)
332 #define MmGetSystemAddressForMdlSafe(mdl, priority) ((mdl)->mappedsystemva)
333 #define MmGetMdlPfnArray(mdl) ((PFN_NUMBER *)(mdl + 1))
334 #define MmInitializeMdl(mdl, baseva, length) \
336 (mdl)->next = NULL; \
337 (mdl)->size = MmSizeOfMdl(baseva, length); \
339 (mdl)->startva = PAGE_START(baseva); \
340 (mdl)->byteoffset = BYTE_OFFSET(baseva); \
341 (mdl)->bytecount = length; \
342 (mdl)->mappedsystemva = baseva; \
343 TRACE4("%p %p %p %d %d", (mdl), baseva, (mdl)->startva, \
344 (mdl)->byteoffset, length); \
347 struct kdevice_queue_entry {
353 struct kdevice_queue {
361 struct wait_context_block {
362 struct kdevice_queue_entry wait_queue_entry;
363 void *device_routine;
364 void *device_context;
368 void *buffer_chaining_dpc;
373 struct task_struct *thread;
380 struct dispatcher_header {
386 struct nt_list wait_blocks;
391 SynchronizationEvent,
395 NotificationTimer = NotificationEvent,
396 SynchronizationTimer = SynchronizationEvent,
400 NotificationObject = NotificationEvent,
401 SynchronizationObject = SynchronizationEvent,
411 /* objects that use dispatcher_header have it as the first field, so
412 * whenever we need to initialize dispatcher_header, we can convert
413 * that object into a nt_event and access dispatcher_header */
415 struct dispatcher_header dh;
420 #define WRAP_TIMER_MAGIC 47697249
423 struct dispatcher_header dh;
424 /* We can't fit Linux timer in this structure. Instead of
425 * padding the nt_timer structure, we replace due_time field
426 * with *wrap_timer and allocate memory for it when nt_timer is
430 struct wrap_timer *wrap_timer;
432 struct nt_list nt_timer_list;
436 LONG wrap_timer_magic;
441 struct dispatcher_header dh;
443 struct task_struct *owner_thread;
448 struct nt_semaphore {
449 struct dispatcher_header dh;
454 struct dispatcher_header dh;
455 /* the rest in Windows is a long structure; since this
456 * structure is opaque to drivers, we just define what we
460 struct task_struct *task;
466 #define set_object_type(dh, type) ((dh)->type = (type))
467 #define is_notify_object(dh) ((dh)->type == NotificationObject)
468 #define is_synch_object(dh) ((dh)->type == SynchronizationObject)
469 #define is_mutex_object(dh) ((dh)->type == MutexObject)
470 #define is_semaphore_object(dh) ((dh)->type == SemaphoreObject)
471 #define is_nt_thread_object(dh) ((dh)->type == ThreadObject)
473 #define IO_TYPE_ADAPTER 1
474 #define IO_TYPE_CONTROLLER 2
475 #define IO_TYPE_DEVICE 3
476 #define IO_TYPE_DRIVER 4
477 #define IO_TYPE_FILE 5
478 #define IO_TYPE_IRP 6
479 #define IO_TYPE_DEVICE_OBJECT_EXTENSION 13
483 struct driver_object;
485 struct device_object {
489 struct driver_object *drv_obj;
490 struct device_object *next;
491 struct device_object *attached;
492 struct irp *current_irp;
495 ULONG characteristics;
500 struct nt_list queue_list;
501 struct wait_context_block wcb;
504 struct kdevice_queue dev_queue;
506 ULONG active_threads;
508 struct nt_event lock;
511 struct dev_obj_ext *dev_obj_ext;
518 struct device_object *dev_obj;
519 struct device_object *attached_to;
522 struct io_status_block {
531 struct io_status_block32 {
537 #define DEVICE_TYPE ULONG
539 struct driver_extension;
541 typedef NTSTATUS driver_dispatch_t(struct device_object *dev_obj,
542 struct irp *irp) wstdcall;
544 struct driver_object {
547 struct device_object *dev_obj;
552 struct driver_extension *drv_ext;
553 struct unicode_string name;
554 struct unicode_string *hardware_database;
555 void *fast_io_dispatch;
558 void (*unload)(struct driver_object *driver) wstdcall;
559 driver_dispatch_t *major_func[IRP_MJ_MAXIMUM_FUNCTION + 1];
562 struct driver_extension {
563 struct driver_object *drv_obj;
564 NTSTATUS (*add_device)(struct driver_object *drv_obj,
565 struct device_object *dev_obj) wstdcall;
567 struct unicode_string service_key_name;
568 struct nt_list custom_ext;
576 struct wrap_bin_file;
581 struct device_object *dev_obj;
582 void *volume_parameter_block;
585 void *section_object_pointer;
586 void *private_cache_map;
587 NTSTATUS final_status;
589 struct file_object *related_file_object;
590 struct wrap_bin_file *wrap_bin_file;
592 BOOLEAN lock_operation;
593 BOOLEAN delete_pending;
595 BOOLEAN write_access;
596 BOOLEAN delete_access;
598 BOOLEAN shared_write;
599 BOOLEAN shared_delete;
601 struct unicode_string _name_;
602 LARGE_INTEGER current_byte_offset;
606 struct nt_event lock;
607 struct nt_event event;
608 void *completion_context;
612 #define POINTER_ALIGN __attribute__((aligned(8)))
614 #define POINTER_ALIGN
617 #define CACHE_ALIGN __attribute__((aligned(128)))
619 enum system_power_state {
620 PowerSystemUnspecified = 0,
621 PowerSystemWorking, PowerSystemSleeping1, PowerSystemSleeping2,
622 PowerSystemSleeping3, PowerSystemHibernate, PowerSystemShutdown,
626 enum device_power_state {
627 PowerDeviceUnspecified = 0,
628 PowerDeviceD0, PowerDeviceD1, PowerDeviceD2, PowerDeviceD3,
633 enum system_power_state system_state;
634 enum device_power_state device_state;
637 enum power_state_type {
638 SystemPowerState = 0, DevicePowerState,
643 PowerActionReserved, PowerActionSleep, PowerActionHibernate,
644 PowerActionShutdown, PowerActionShutdownReset, PowerActionShutdownOff,
645 PowerActionWarmEject,
655 struct nt_interface {
659 void (*reference)(void *context) wstdcall;
660 void (*dereference)(void *context) wstdcall;
663 enum interface_type {
664 InterfaceTypeUndefined = -1, Internal, Isa, Eisa, MicroChannel,
665 TurboChannel, PCIBus, VMEBus, NuBus, PCMCIABus, CBus, MPIBus,
666 MPSABus, ProcessorInternal, InternalPowerBus, PNPISABus,
667 PNPBus, MaximumInterfaceType,
670 #define CmResourceTypeNull 0
671 #define CmResourceTypePort 1
672 #define CmResourceTypeInterrupt 2
673 #define CmResourceTypeMemory 3
674 #define CmResourceTypeDma 4
675 #define CmResourceTypeDeviceSpecific 5
676 #define CmResourceTypeBusNumber 6
677 #define CmResourceTypeMaximum 7
679 #define CmResourceTypeNonArbitrated 128
680 #define CmResourceTypeConfigData 128
681 #define CmResourceTypeDevicePrivate 129
682 #define CmResourceTypePcCardConfig 130
683 #define CmResourceTypeMfCardConfig 131
685 enum cm_share_disposition {
686 CmResourceShareUndetermined = 0, CmResourceShareDeviceExclusive,
687 CmResourceShareDriverExclusive, CmResourceShareShared
690 #define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE 0
691 #define CM_RESOURCE_INTERRUPT_LATCHED 1
692 #define CM_RESOURCE_MEMORY_READ_WRITE 0x0000
693 #define CM_RESOURCE_MEMORY_READ_ONLY 0x0001
694 #define CM_RESOURCE_MEMORY_WRITE_ONLY 0x0002
695 #define CM_RESOURCE_MEMORY_PREFETCHABLE 0x0004
697 #define CM_RESOURCE_MEMORY_COMBINEDWRITE 0x0008
698 #define CM_RESOURCE_MEMORY_24 0x0010
699 #define CM_RESOURCE_MEMORY_CACHEABLE 0x0020
701 #define CM_RESOURCE_PORT_MEMORY 0x0000
702 #define CM_RESOURCE_PORT_IO 0x0001
703 #define CM_RESOURCE_PORT_10_BIT_DECODE 0x0004
704 #define CM_RESOURCE_PORT_12_BIT_DECODE 0x0008
705 #define CM_RESOURCE_PORT_16_BIT_DECODE 0x0010
706 #define CM_RESOURCE_PORT_POSITIVE_DECODE 0x0020
707 #define CM_RESOURCE_PORT_PASSIVE_DECODE 0x0040
708 #define CM_RESOURCE_PORT_WINDOW_DECODE 0x0080
710 #define CM_RESOURCE_DMA_8 0x0000
711 #define CM_RESOURCE_DMA_16 0x0001
712 #define CM_RESOURCE_DMA_32 0x0002
713 #define CM_RESOURCE_DMA_8_AND_16 0x0004
714 #define CM_RESOURCE_DMA_BUS_MASTER 0x0008
715 #define CM_RESOURCE_DMA_TYPE_A 0x0010
716 #define CM_RESOURCE_DMA_TYPE_B 0x0020
717 #define CM_RESOURCE_DMA_TYPE_F 0x0040
719 #define MAX_RESOURCES 20
722 struct cm_partial_resource_descriptor {
728 PHYSICAL_ADDRESS start;
732 PHYSICAL_ADDRESS start;
741 PHYSICAL_ADDRESS start;
761 } device_specific_data;
766 struct cm_partial_resource_list {
770 struct cm_partial_resource_descriptor partial_descriptors[1];
773 struct cm_full_resource_descriptor {
774 enum interface_type interface_type;
776 struct cm_partial_resource_list partial_resource_list;
779 struct cm_resource_list {
781 struct cm_full_resource_descriptor list[1];
784 enum file_info_class {
785 FileDirectoryInformation = 1,
786 FileBasicInformation = 4,
787 FileStandardInformation = 5,
788 FileNameInformation = 9,
789 FilePositionInformation = 14,
790 FileAlignmentInformation = 17,
791 FileNetworkOpenInformation = 34,
792 FileAttributeTagInformation = 35,
793 FileMaximumInformation = 41,
797 FileFsVolumeInformation = 1,
799 FileFsMaximumInformation = 9,
802 enum device_relation_type {
803 BusRelations, EjectionRelations, PowerRelations, RemovalRelations,
804 TargetDeviceRelation, SingleBusRelations,
807 enum bus_query_id_type {
808 BusQueryDeviceID = 0, BusQueryHardwareIDs = 1,
809 BusQueryCompatibleIDs = 2, BusQueryInstanceID = 3,
810 BusQueryDeviceSerialNumber = 4,
813 enum device_text_type {
814 DeviceTextDescription = 0, DeviceTextLocationInformation = 1,
817 enum device_usage_notification_type {
818 DeviceUsageTypeUndefined, DeviceUsageTypePaging,
819 DeviceUsageTypeHibernation, DevbiceUsageTypeDumpFile,
822 #define METHOD_BUFFERED 0
823 #define METHOD_IN_DIRECT 1
824 #define METHOD_OUT_DIRECT 2
825 #define METHOD_NEITHER 3
827 #define CTL_CODE(dev_type, func, method, access) \
828 (((dev_type) << 16) | ((access) << 14) | ((func) << 2) | (method))
830 #define IO_METHOD_FROM_CTL_CODE(code) (code & 0x3)
832 #ifndef CONFIG_X86_64
835 struct io_stack_location {
842 void *security_context;
844 USHORT POINTER_ALIGN file_attributes;
846 ULONG POINTER_ALIGN ea_length;
850 ULONG POINTER_ALIGN key;
851 LARGE_INTEGER byte_offset;
855 ULONG POINTER_ALIGN key;
856 LARGE_INTEGER byte_offset;
860 enum file_info_class POINTER_ALIGN file_info_class;
864 enum file_info_class POINTER_ALIGN file_info_class;
865 struct file_object *file_object;
868 BOOLEAN replace_if_exists;
869 BOOLEAN advance_only;
877 enum fs_info_class POINTER_ALIGN fs_info_class;
880 ULONG output_buf_len;
881 ULONG POINTER_ALIGN input_buf_len;
882 ULONG POINTER_ALIGN code;
883 void *type3_input_buf;
886 SECURITY_INFORMATION security_info;
887 ULONG POINTER_ALIGN length;
890 SECURITY_INFORMATION security_info;
891 void *security_descriptor;
895 struct device_object *device_object;
899 struct device_object *device_object;
905 enum device_relation_type type;
906 } query_device_relations;
908 const struct guid *type;
911 struct nt_interface *intf;
916 } device_capabilities;
918 void *io_resource_requirement_list;
919 } filter_resource_requirements;
924 ULONG POINTER_ALIGN length;
930 enum bus_query_id_type id_type;
933 enum device_text_type device_text_type;
934 ULONG POINTER_ALIGN locale_id;
939 enum device_usage_notification_type POINTER_ALIGN type;
940 } usage_notification;
942 enum system_power_state power_state;
945 void *power_sequence;
949 enum power_state_type POINTER_ALIGN type;
950 union power_state POINTER_ALIGN state;
951 enum power_action POINTER_ALIGN shutdown_type;
954 struct cm_resource_list *allocated_resources;
955 struct cm_resource_list *allocated_resources_translated;
958 ULONG_PTR provider_id;
970 struct device_object *dev_obj;
971 struct file_object *file_obj;
972 NTSTATUS (*completion_routine)(struct device_object *,
973 struct irp *, void *) wstdcall;
976 #ifndef CONFIG_X86_64
984 struct nt_thread *thread;
986 void *kernele_routine;
987 void *rundown_routine;
988 void *normal_routine;
989 void *normal_context;
992 CCHAR apc_state_index;
993 KPROCESSOR_MODE apc_mode;
997 #define IRP_NOCACHE 0x00000001
998 #define IRP_SYNCHRONOUS_API 0x00000004
999 #define IRP_ASSOCIATED_IRP 0x00000008
1002 URB_INVALID = 1, URB_ALLOCATED, URB_SUBMITTED,
1003 URB_COMPLETED, URB_FREE, URB_SUSPEND, URB_INT_UNLINKED };
1006 struct nt_list list;
1007 enum urb_state state;
1008 struct nt_list complete_list;
1023 struct irp *master_irp;
1025 void *system_buffer;
1027 struct nt_list thread_list;
1028 struct io_status_block io_status;
1029 KPROCESSOR_MODE requestor_mode;
1030 BOOLEAN pending_returned;
1032 CHAR current_location;
1037 struct io_status_block *user_status;
1038 struct nt_event *user_event;
1041 void *user_apc_routine;
1042 void *user_apc_context;
1044 LARGE_INTEGER alloc_size;
1046 void (*cancel_routine)(struct device_object *, struct irp *) wstdcall;
1051 struct kdevice_queue_entry dev_q_entry;
1053 void *driver_context[4];
1059 struct nt_list list;
1061 struct io_stack_location *csl;
1065 struct file_object *file_object;
1069 /* space for apc is used for ndiswrapper
1070 * specific fields */
1072 struct wrap_urb *wrap_urb;
1073 struct wrap_device *wrap_device;
1076 void *completion_key;
1080 #define IoSizeOfIrp(stack_count) \
1081 ((USHORT)(sizeof(struct irp) + \
1082 ((stack_count) * sizeof(struct io_stack_location))))
1083 #define IoGetCurrentIrpStackLocation(irp) \
1084 (irp)->tail.overlay.csl
1085 #define IoGetNextIrpStackLocation(irp) \
1086 (IoGetCurrentIrpStackLocation(irp) - 1)
1087 #define IoGetPreviousIrpStackLocation(irp) \
1088 (IoGetCurrentIrpStackLocation(irp) + 1)
1090 #define IoSetNextIrpStackLocation(irp) \
1093 IoAcquireCancelSpinLock(&_irql_); \
1094 (irp)->current_location--; \
1095 IoGetCurrentIrpStackLocation(irp)--; \
1096 IoReleaseCancelSpinLock(_irql_); \
1099 #define IoSkipCurrentIrpStackLocation(irp) \
1102 IoAcquireCancelSpinLock(&_irql_); \
1103 (irp)->current_location++; \
1104 IoGetCurrentIrpStackLocation(irp)++; \
1105 IoReleaseCancelSpinLock(_irql_); \
1109 IoCopyCurrentIrpStackLocationToNext(struct irp *irp)
1111 struct io_stack_location *next;
1112 next = IoGetNextIrpStackLocation(irp);
1113 memcpy(next, IoGetCurrentIrpStackLocation(irp),
1114 offsetof(struct io_stack_location, completion_routine));
1119 IoSetCompletionRoutine(struct irp *irp, void *routine, void *context,
1120 BOOLEAN success, BOOLEAN error, BOOLEAN cancel)
1122 struct io_stack_location *irp_sl = IoGetNextIrpStackLocation(irp);
1123 irp_sl->completion_routine = routine;
1124 irp_sl->context = context;
1125 irp_sl->control = 0;
1127 irp_sl->control |= SL_INVOKE_ON_SUCCESS;
1129 irp_sl->control |= SL_INVOKE_ON_ERROR;
1131 irp_sl->control |= SL_INVOKE_ON_CANCEL;
1134 #define IoMarkIrpPending(irp) \
1135 (IoGetCurrentIrpStackLocation((irp))->control |= SL_PENDING_RETURNED)
1136 #define IoUnmarkIrpPending(irp) \
1137 (IoGetCurrentIrpStackLocation((irp))->control &= ~SL_PENDING_RETURNED)
1139 #define IRP_SL(irp, n) (((struct io_stack_location *)((irp) + 1)) + (n))
1140 #define IRP_DRIVER_CONTEXT(irp) (irp)->tail.overlay.driver_context
1141 #define IoIrpThread(irp) ((irp)->tail.overlay.thread)
1143 #define IRP_URB(irp) \
1144 (union nt_urb *)(IoGetCurrentIrpStackLocation(irp)->params.others.arg1)
1146 #define IRP_WRAP_DEVICE(irp) (irp)->tail.wrap_device
1147 #define IRP_WRAP_URB(irp) (irp)->tail.wrap_urb
1149 struct wmi_guid_reg_info {
1151 ULONG instance_count;
1155 struct wmilib_context {
1157 struct wmi_guid_reg_info *guid_list;
1158 void *query_wmi_reg_info;
1159 void *query_wmi_data_block;
1160 void *set_wmi_data_block;
1161 void *set_wmi_data_item;
1162 void *execute_wmi_method;
1163 void *wmi_function_control;
1166 enum key_value_information_class {
1167 KeyValueBasicInformation, KeyValueFullInformation,
1168 KeyValuePartialInformation, KeyValueFullInformationAlign64,
1169 KeyValuePartialInformationAlign64
1172 struct file_name_info {
1177 struct file_std_info {
1178 LARGE_INTEGER alloc_size;
1181 BOOLEAN delete_pending;
1186 NT_OBJ_EVENT = 10, NT_OBJ_MUTEX, NT_OBJ_THREAD, NT_OBJ_TIMER,
1190 enum common_object_type {
1191 OBJECT_TYPE_NONE, OBJECT_TYPE_DEVICE, OBJECT_TYPE_DRIVER,
1192 OBJECT_TYPE_NT_THREAD, OBJECT_TYPE_FILE, OBJECT_TYPE_CALLBACK,
1195 struct common_object_header {
1196 struct nt_list list;
1197 enum common_object_type type;
1200 BOOLEAN close_in_process;
1202 struct unicode_string name;
1205 #define OBJECT_TO_HEADER(object) \
1206 (struct common_object_header *)((void *)(object) - \
1207 sizeof(struct common_object_header))
1208 #define OBJECT_SIZE(size) \
1209 ((size) + sizeof(struct common_object_header))
1210 #define HEADER_TO_OBJECT(hdr) \
1211 ((void *)(hdr) + sizeof(struct common_object_header))
1212 #define HANDLE_TO_OBJECT(handle) HEADER_TO_OBJECT(handle)
1213 #define HANDLE_TO_HEADER(handle) (handle)
1215 enum work_queue_type {
1216 CriticalWorkQueue, DelayedWorkQueue, HyperCriticalWorkQueue,
1220 typedef void (*NTOS_WORK_FUNC)(void *arg1, void *arg2) wstdcall;
1222 struct io_workitem {
1223 enum work_queue_type type;
1224 struct device_object *dev_obj;
1225 NTOS_WORK_FUNC worker_routine;
1229 struct io_workitem_entry {
1230 struct nt_list list;
1231 struct io_workitem *io_workitem;
1234 enum mm_page_priority {
1235 LowPagePriority, NormalPagePriority = 16, HighPagePriority = 32
1238 enum kinterrupt_mode {
1239 LevelSensitive, Latched
1242 enum ntos_wait_reason {
1243 Executive, FreePage, PageIn, PoolAllocation, DelayExecution,
1244 Suspended, UserRequest, WrExecutive, WrFreePage, WrPageIn,
1245 WrPoolAllocation, WrDelayExecution, WrSuspended, WrUserRequest,
1246 WrEventPair, WrQueue, WrLpcReceive, WrLpcReply, WrVirtualMemory,
1247 WrPageOut, WrRendezvous, Spare2, Spare3, Spare4, Spare5, Spare6,
1248 WrKernel, MaximumWaitReason
1251 typedef enum ntos_wait_reason KWAIT_REASON;
1253 typedef void *LOOKASIDE_ALLOC_FUNC(enum pool_type pool_type,
1254 SIZE_T size, ULONG tag) wstdcall;
1255 typedef void LOOKASIDE_FREE_FUNC(void *) wstdcall;
1257 struct npaged_lookaside_list {
1258 nt_slist_header head;
1271 enum pool_type pool_type;
1274 LOOKASIDE_ALLOC_FUNC *alloc_func;
1275 LOOKASIDE_FREE_FUNC *free_func;
1276 struct nt_list list;
1277 ULONG lasttotallocs;
1279 ULONG lastallocmisses;
1280 ULONG lastallochits;
1283 #ifndef CONFIG_X86_64
1284 NT_SPIN_LOCK obsolete;
1287 #ifdef CONFIG_X86_64
1292 enum device_registry_property {
1293 DevicePropertyDeviceDescription, DevicePropertyHardwareID,
1294 DevicePropertyCompatibleIDs, DevicePropertyBootConfiguration,
1295 DevicePropertyBootConfigurationTranslated,
1296 DevicePropertyClassName, DevicePropertyClassGuid,
1297 DevicePropertyDriverKeyName, DevicePropertyManufacturer,
1298 DevicePropertyFriendlyName, DevicePropertyLocationInformation,
1299 DevicePropertyPhysicalDeviceObjectName, DevicePropertyBusTypeGuid,
1300 DevicePropertyLegacyBusType, DevicePropertyBusNumber,
1301 DevicePropertyEnumeratorName, DevicePropertyAddress,
1302 DevicePropertyUINumber, DevicePropertyInstallState,
1303 DevicePropertyRemovalPolicy
1306 enum trace_information_class {
1307 TraceIdClass, TraceHandleClass, TraceEnableFlagsClass,
1308 TraceEnableLevelClass, GlobalLoggerHandleClass, EventLoggerHandleClass,
1309 AllLoggerHandlesClass, TraceHandleByNameClass
1313 typedef BOOLEAN (*PKSERVICE_ROUTINE)(struct kinterrupt *interrupt,
1314 void *context) wstdcall;
1315 typedef BOOLEAN (*PKSYNCHRONIZE_ROUTINE)(void *context) wstdcall;
1321 NT_SPIN_LOCK *actual_lock;
1325 CHAR processor_number;
1326 #ifdef CONFIG_DEBUG_SHIRQ
1330 PKSERVICE_ROUTINE isr;
1332 struct nt_list list;
1335 enum kinterrupt_mode mode;
1338 struct time_fields {
1345 CSHORT milliseconds;
1349 struct object_attributes {
1352 struct unicode_string *name;
1354 void *security_descr;
1358 typedef void (*PCALLBACK_FUNCTION)(void *context, void *arg1,
1359 void *arg2) wstdcall;
1361 struct callback_object;
1362 struct callback_func {
1363 PCALLBACK_FUNCTION func;
1365 struct nt_list list;
1366 struct callback_object *object;
1369 struct callback_object {
1371 struct nt_list list;
1372 struct nt_list callback_funcs;
1373 BOOLEAN allow_multiple_callbacks;
1374 struct object_attributes *attributes;
1377 enum section_inherit {
1378 ViewShare = 1, ViewUnmap = 2
1381 struct ksystem_time {
1387 enum nt_product_type {
1388 nt_product_win_nt = 1, nt_product_lan_man_nt, nt_product_server
1391 enum alt_arch_type {
1392 arch_type_standard, arch_type_nex98x86, end_alternatives
1395 struct kuser_shared_data {
1397 ULONG tick_count_multiplier;
1398 volatile struct ksystem_time interrupt_time;
1399 volatile struct ksystem_time system_time;
1400 volatile struct ksystem_time time_zone_bias;
1401 USHORT image_number_low;
1402 USHORT image_number_high;
1403 wchar_t nt_system_root[260];
1404 ULONG max_stack_trace_depth;
1405 ULONG crypto_exponent;
1407 ULONG large_page_min;
1409 enum nt_product_type nt_product_type;
1410 BOOLEAN product_type_is_valid;
1411 ULONG nt_major_version;
1412 ULONG nt_minor_version;
1413 BOOLEAN processor_features[PROCESSOR_FEATURE_MAX];
1416 volatile LONG time_slip;
1417 enum alt_arch_type alt_arch_type;
1418 LARGE_INTEGER system_expiration_date;
1420 BOOLEAN kdbg_enabled;
1421 volatile ULONG active_console;
1422 volatile ULONG dismount_count;
1423 ULONG com_plus_package;
1424 ULONG last_system_rite_event_tick_count;
1425 ULONG num_phys_pages;
1426 BOOLEAN safe_boot_mode;
1429 ULONGLONG sys_call[4];
1431 volatile struct ksystem_time tick_count;
1432 volatile ULONG64 tick_count_quad;
1436 #define REG_NONE (0)
1438 #define REG_EXPAND_SZ (2)
1439 #define REG_BINARY (3)
1440 #define REG_DWORD (4)
1442 #define RTL_REGISTRY_ABSOLUTE 0
1443 #define RTL_REGISTRY_SERVICES 1
1444 #define RTL_REGISTRY_CONTROL 2
1445 #define RTL_REGISTRY_WINDOWS_NT 3
1446 #define RTL_REGISTRY_DEVICEMAP 4
1447 #define RTL_REGISTRY_USER 5
1448 #define RTL_REGISTRY_MAXIMUM 6
1449 #define RTL_REGISTRY_HANDLE 0x40000000
1450 #define RTL_REGISTRY_OPTIONAL 0x80000000
1452 #define RTL_QUERY_REGISTRY_SUBKEY 0x00000001
1453 #define RTL_QUERY_REGISTRY_TOPKEY 0x00000002
1454 #define RTL_QUERY_REGISTRY_REQUIRED 0x00000004
1455 #define RTL_QUERY_REGISTRY_NOVALUE 0x00000008
1456 #define RTL_QUERY_REGISTRY_NOEXPAND 0x00000010
1457 #define RTL_QUERY_REGISTRY_DIRECT 0x00000020
1458 #define RTL_QUERY_REGISTRY_DELETE 0x00000040
1460 typedef NTSTATUS (*PRTL_QUERY_REGISTRY_ROUTINE)(wchar_t *name, ULONG type,
1461 void *data, ULONG length,
1463 void *entry) wstdcall;
1465 struct rtl_query_registry_table {
1466 PRTL_QUERY_REGISTRY_ROUTINE query_func;
1475 struct io_remove_lock {
1477 BOOLEAN reserved[3];
1479 struct nt_event remove_event;
1482 struct io_error_log_packet {
1483 UCHAR major_fn_code;
1485 USHORT dump_data_size;
1486 USHORT nr_of_strings;
1487 USHORT string_offset;
1488 USHORT event_category;
1489 NTSTATUS error_code;
1490 ULONG unique_error_value;
1491 NTSTATUS final_status;
1492 ULONG sequence_number;
1493 ULONG io_control_code;
1494 LARGE_INTEGER device_offset;
1498 /* some of the functions below are slightly different from DDK's
1499 * implementation; e.g., Insert functions return appropriate
1502 /* instead of using Linux's lists, we implement list manipulation
1503 * functions because nt_list is used by drivers and we don't want to
1504 * worry about Linux's list being different from nt_list (right now
1505 * they are same, but in future they could be different) */
1507 static inline void InitializeListHead(struct nt_list *head)
1509 head->next = head->prev = head;
1512 static inline BOOLEAN IsListEmpty(struct nt_list *head)
1514 if (head == head->next)
1520 static inline void RemoveEntryList(struct nt_list *entry)
1522 entry->prev->next = entry->next;
1523 entry->next->prev = entry->prev;
1526 static inline struct nt_list *RemoveHeadList(struct nt_list *head)
1528 struct nt_list *entry;
1534 RemoveEntryList(entry);
1539 static inline struct nt_list *RemoveTailList(struct nt_list *head)
1541 struct nt_list *entry;
1547 RemoveEntryList(entry);
1552 static inline void InsertListEntry(struct nt_list *entry, struct nt_list *prev,
1553 struct nt_list *next)
1561 static inline struct nt_list *InsertHeadList(struct nt_list *head,
1562 struct nt_list *entry)
1564 struct nt_list *ret;
1566 if (IsListEmpty(head))
1571 InsertListEntry(entry, head, head->next);
1575 static inline struct nt_list *InsertTailList(struct nt_list *head,
1576 struct nt_list *entry)
1578 struct nt_list *ret;
1580 if (IsListEmpty(head))
1585 InsertListEntry(entry, head->prev, head);
1589 #define nt_list_for_each(pos, head) \
1590 for (pos = (head)->next; pos != (head); pos = pos->next)
1592 #define nt_list_for_each_entry(pos, head, member) \
1593 for (pos = container_of((head)->next, typeof(*pos), member); \
1594 &pos->member != (head); \
1595 pos = container_of(pos->member.next, typeof(*pos), member))
1597 #define nt_list_for_each_safe(pos, n, head) \
1598 for (pos = (head)->next, n = pos->next; pos != (head); \
1599 pos = n, n = pos->next)
1601 /* device object flags */
1602 #define DO_VERIFY_VOLUME 0x00000002
1603 #define DO_BUFFERED_IO 0x00000004
1604 #define DO_EXCLUSIVE 0x00000008
1605 #define DO_DIRECT_IO 0x00000010
1606 #define DO_MAP_IO_BUFFER 0x00000020
1607 #define DO_DEVICE_HAS_NAME 0x00000040
1608 #define DO_DEVICE_INITIALIZING 0x00000080
1609 #define DO_SYSTEM_BOOT_PARTITION 0x00000100
1610 #define DO_LONG_TERM_REQUESTS 0x00000200
1611 #define DO_NEVER_LAST_DEVICE 0x00000400
1612 #define DO_SHUTDOWN_REGISTERED 0x00000800
1613 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
1614 #define DO_POWER_PAGABLE 0x00002000
1615 #define DO_POWER_INRUSH 0x00004000
1616 #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
1618 /* Various supported device types (used with IoCreateDevice()) */
1620 #define FILE_DEVICE_BEEP 0x00000001
1621 #define FILE_DEVICE_CD_ROM 0x00000002
1622 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
1623 #define FILE_DEVICE_CONTROLLER 0x00000004
1624 #define FILE_DEVICE_DATALINK 0x00000005
1625 #define FILE_DEVICE_DFS 0x00000006
1626 #define FILE_DEVICE_DISK 0x00000007
1627 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
1628 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
1629 #define FILE_DEVICE_INPORT_PORT 0x0000000A
1630 #define FILE_DEVICE_KEYBOARD 0x0000000B
1631 #define FILE_DEVICE_MAILSLOT 0x0000000C
1632 #define FILE_DEVICE_MIDI_IN 0x0000000D
1633 #define FILE_DEVICE_MIDI_OUT 0x0000000E
1634 #define FILE_DEVICE_MOUSE 0x0000000F
1635 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
1636 #define FILE_DEVICE_NAMED_PIPE 0x00000011
1637 #define FILE_DEVICE_NETWORK 0x00000012
1638 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
1639 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
1640 #define FILE_DEVICE_NULL 0x00000015
1641 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
1642 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
1643 #define FILE_DEVICE_PRINTER 0x00000018
1644 #define FILE_DEVICE_SCANNER 0x00000019
1645 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001A
1646 #define FILE_DEVICE_SERIAL_PORT 0x0000001B
1647 #define FILE_DEVICE_SCREEN 0x0000001C
1648 #define FILE_DEVICE_SOUND 0x0000001D
1649 #define FILE_DEVICE_STREAMS 0x0000001E
1650 #define FILE_DEVICE_TAPE 0x0000001F
1651 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
1652 #define FILE_DEVICE_TRANSPORT 0x00000021
1653 #define FILE_DEVICE_UNKNOWN 0x00000022
1654 #define FILE_DEVICE_VIDEO 0x00000023
1655 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
1656 #define FILE_DEVICE_WAVE_IN 0x00000025
1657 #define FILE_DEVICE_WAVE_OUT 0x00000026
1658 #define FILE_DEVICE_8042_PORT 0x00000027
1659 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
1660 #define FILE_DEVICE_BATTERY 0x00000029
1661 #define FILE_DEVICE_BUS_EXTENDER 0x0000002A
1662 #define FILE_DEVICE_MODEM 0x0000002B
1663 #define FILE_DEVICE_VDM 0x0000002C
1664 #define FILE_DEVICE_MASS_STORAGE 0x0000002D
1665 #define FILE_DEVICE_SMB 0x0000002E
1666 #define FILE_DEVICE_KS 0x0000002F
1667 #define FILE_DEVICE_CHANGER 0x00000030
1668 #define FILE_DEVICE_SMARTCARD 0x00000031
1669 #define FILE_DEVICE_ACPI 0x00000032
1670 #define FILE_DEVICE_DVD 0x00000033
1671 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
1672 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
1673 #define FILE_DEVICE_DFS_VOLUME 0x00000036
1674 #define FILE_DEVICE_SERENUM 0x00000037
1675 #define FILE_DEVICE_TERMSRV 0x00000038
1676 #define FILE_DEVICE_KSEC 0x00000039
1677 #define FILE_DEVICE_FIPS 0x0000003A
1679 /* Device characteristics */
1681 #define FILE_REMOVABLE_MEDIA 0x00000001
1682 #define FILE_READ_ONLY_DEVICE 0x00000002
1683 #define FILE_FLOPPY_DISKETTE 0x00000004
1684 #define FILE_WRITE_ONCE_MEDIA 0x00000008
1685 #define FILE_REMOTE_DEVICE 0x00000010
1686 #define FILE_DEVICE_IS_MOUNTED 0x00000020
1687 #define FILE_VIRTUAL_VOLUME 0x00000040
1688 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
1689 #define FILE_DEVICE_SECURE_OPEN 0x00000100
1691 #define FILE_READ_DATA 0x0001
1692 #define FILE_WRITE_DATA 0x0002
1694 #define FILE_SUPERSEDED 0x00000000
1695 #define FILE_OPENED 0x00000001
1696 #define FILE_CREATED 0x00000002
1697 #define FILE_OVERWRITTEN 0x00000003
1698 #define FILE_EXISTS 0x00000004
1699 #define FILE_DOES_NOT_EXIST 0x00000005
1702 #endif /* WINNT_TYPES_H */