UBUNTU: ubuntu: ndiswrapper -- fix interaction between __packed and packed
[linux-flexiantxendom0-natty.git] / ubuntu / ndiswrapper / winnt_types.h
1 /*
2  *  Copyright (C) 2003-2005 Pontus Fuchs, Giridhar Pemmasani
3  *
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.
8  *
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.
13  *
14  */
15
16 #ifndef _WINNT_TYPES_H_
17 #define _WINNT_TYPES_H_
18
19 #define TRUE                            1
20 #define FALSE                           0
21
22 #define PASSIVE_LEVEL                   0
23 #define APC_LEVEL                       1
24 #define DISPATCH_LEVEL                  2
25 #define DEVICE_LEVEL_BASE               4
26
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)
30
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
54
55 #define STATUS_BUFFER_OVERFLOW          0x80000005
56
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
61
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
67
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
74
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
79
80 #define IRP_MN_REGINFO                  0x08
81 #define IRP_MN_REGINFO_EX               0x0b
82
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
92
93 #define IRP_BUFFERED_IO                 0x00000010
94 #define IRP_DEALLOCATE_BUFFER           0x00000020
95 #define IRP_INPUT_OPERATION             0x00000040
96
97 #define IRP_DEFFER_IO_COMPLETION        0x00000800
98
99 #define THREAD_WAIT_OBJECTS             3
100 #define MAX_WAIT_OBJECTS                64
101
102 #define LOW_PRIORITY                    0
103 #define LOW_REALTIME_PRIORITY           16
104 #define HIGH_PRIORITY                   31
105 #define MAXIMUM_PRIORITY                32
106
107 #define PROCESSOR_FEATURE_MAX           64
108
109 #define IO_NO_INCREMENT                 0
110
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
115
116 #define WMIREGISTER                     0
117 #define WMIUPDATE                       1
118
119 #ifdef CONFIG_X86_64
120 #define wstdcall
121 #define wfastcall
122 #define noregparm
123
124 #define KI_USER_SHARED_DATA 0xfffff78000000000UL
125
126 #else
127
128 #define noregparm __attribute__((regparm(0)))
129 #define wstdcall __attribute__((__stdcall__, regparm(0)))
130 #if defined(__GNUC__) && ((__GNUC__ == 3 && __GNUC_MINOR__ > 3) || __GNUC__ > 3)
131 #undef fastcall
132 #define wfastcall __attribute__((fastcall))
133 #else
134 #error "gcc 3.4 or newer should be used for compiling this module"
135 #endif
136
137 #define KI_USER_SHARED_DATA 0xffdf0000
138
139 #endif
140
141 // #define packed __attribute__((packed))
142 #define no_warn_unused __attribute__((unused))
143
144 typedef u8      BOOLEAN;
145 typedef u8      BYTE;
146 typedef u8      *LPBYTE;
147 typedef s8      CHAR;
148 typedef u8      UCHAR;
149 typedef s16     SHORT;
150 typedef u16     USHORT;
151 typedef u16     WORD;
152 typedef s32     INT;
153 typedef u32     UINT;
154 typedef u32     DWORD;
155 typedef s32     LONG;
156 typedef u32     ULONG;
157 typedef s64     LONGLONG;
158 typedef u64     ULONGLONG;
159 typedef u64     ULONGULONG;
160 typedef u64     ULONG64;
161
162 typedef CHAR CCHAR;
163 typedef USHORT wchar_t;
164 typedef SHORT CSHORT;
165 typedef LONGLONG LARGE_INTEGER;
166
167 typedef LONG NTSTATUS;
168
169 typedef LONG KPRIORITY;
170 typedef LARGE_INTEGER PHYSICAL_ADDRESS;
171 typedef UCHAR KIRQL;
172 typedef CHAR KPROCESSOR_MODE;
173
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;
177
178 typedef ULONG_PTR SIZE_T;
179 typedef ULONG_PTR KAFFINITY;
180 typedef ULONG ACCESS_MASK;
181
182 typedef ULONG_PTR PFN_NUMBER;
183 typedef ULONG SECURITY_INFORMATION;
184
185 /* non-negative numbers indicate success */
186 #define NT_SUCCESS(status)  ((NTSTATUS)(status) >= 0)
187
188 struct ansi_string {
189         USHORT length;
190         USHORT max_length;
191         char *buf;
192 };
193
194 struct unicode_string {
195         USHORT length;
196         USHORT max_length;
197         wchar_t *buf;
198 };
199
200 struct nt_slist {
201         struct nt_slist *next;
202 };
203
204 #ifdef CONFIG_X86_64
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 {
209         union {
210                 USHORT depth;
211                 ULONGLONG align;
212         };
213         union {
214                 ULONGLONG region;
215                 struct nt_slist *next;
216         };
217 } __attribute__((aligned(16)));
218 typedef struct nt_slist_head nt_slist_header;
219 #else
220 union nt_slist_head {
221         ULONGLONG align;
222         struct {
223                 struct nt_slist *next;
224                 USHORT depth;
225                 USHORT sequence;
226         };
227 };
228 typedef union nt_slist_head nt_slist_header;
229 #endif
230
231 struct nt_list {
232         struct nt_list *next;
233         struct nt_list *prev;
234 };
235
236 typedef ULONG_PTR NT_SPIN_LOCK;
237
238 enum kdpc_importance {LowImportance, MediumImportance, HighImportance};
239
240 struct kdpc;
241 typedef void (*DPC)(struct kdpc *kdpc, void *ctx, void *arg1,
242                     void *arg2) wstdcall;
243 struct kdpc {
244         SHORT type;
245         UCHAR nr_cpu;
246         UCHAR importance;
247         struct nt_list list;
248         DPC func;
249         void *ctx;
250         void *arg1;
251         void *arg2;
252         union {
253                 NT_SPIN_LOCK *lock;
254                 /* 'lock' is not used; 'queued' represents whether
255                  * kdpc is queued or not */
256                 int queued;
257         };
258 };
259
260 enum pool_type {
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
271 };
272
273 enum memory_caching_type_orig {
274         MmFrameBufferCached = 2
275 };
276
277 enum memory_caching_type {
278         MmNonCached = FALSE, MmCached = TRUE,
279         MmWriteCombined = MmFrameBufferCached, MmHardwareCoherentCached,
280         MmNonCachedUnordered, MmUSWCCached, MmMaximumCacheType
281 };
282
283 enum lock_operation {
284         IoReadAccess, IoWriteAccess, IoModifyAccess
285 };
286
287 enum mode {
288         KernelMode, UserMode, MaximumMode
289 };
290
291 struct mdl {
292         struct mdl *next;
293         CSHORT size;
294         CSHORT flags;
295         /* NdisFreeBuffer doesn't pass pool, so we store pool in
296          * unused field 'process' */
297         union {
298                 void *process;
299                 void *pool;
300         };
301         void *mappedsystemva;
302         void *startva;
303         ULONG bytecount;
304         ULONG byteoffset;
305 };
306
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
321
322 #define MDL_POOL_ALLOCATED              0x0400
323 #define MDL_CACHE_ALLOCATED             0x8000
324
325 #define PAGE_START(ptr) ((void *)((ULONG_PTR)(ptr) & ~(PAGE_SIZE - 1)))
326 #define BYTE_OFFSET(ptr) ((ULONG)((ULONG_PTR)(ptr) & (PAGE_SIZE - 1)))
327
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)                            \
335 do {                                                                    \
336         (mdl)->next = NULL;                                             \
337         (mdl)->size = MmSizeOfMdl(baseva, length);                      \
338         (mdl)->flags = 0;                                               \
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);                           \
345 } while (0)
346
347 struct kdevice_queue_entry {
348         struct nt_list list;
349         ULONG sort_key;
350         BOOLEAN inserted;
351 };
352
353 struct kdevice_queue {
354         USHORT type;
355         USHORT size;
356         struct nt_list list;
357         NT_SPIN_LOCK lock;
358         BOOLEAN busy;
359 };
360
361 struct wait_context_block {
362         struct kdevice_queue_entry wait_queue_entry;
363         void *device_routine;
364         void *device_context;
365         ULONG num_regs;
366         void *device_object;
367         void *current_irp;
368         void *buffer_chaining_dpc;
369 };
370
371 struct wait_block {
372         struct nt_list list;
373         struct task_struct *thread;
374         void *object;
375         int *wait_done;
376         USHORT wait_key;
377         USHORT wait_type;
378 };
379
380 struct dispatcher_header {
381         UCHAR type;
382         UCHAR absolute;
383         UCHAR size;
384         UCHAR inserted;
385         LONG signal_state;
386         struct nt_list wait_blocks;
387 };
388
389 enum event_type {
390         NotificationEvent,
391         SynchronizationEvent,
392 };
393
394 enum timer_type {
395         NotificationTimer = NotificationEvent,
396         SynchronizationTimer = SynchronizationEvent,
397 };
398
399 enum dh_type {
400         NotificationObject = NotificationEvent,
401         SynchronizationObject = SynchronizationEvent,
402         MutexObject,
403         SemaphoreObject,
404         ThreadObject,
405 };
406
407 enum wait_type {
408         WaitAll, WaitAny
409 };
410
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 */
414 struct nt_event {
415         struct dispatcher_header dh;
416 };
417
418 struct wrap_timer;
419
420 #define WRAP_TIMER_MAGIC 47697249
421
422 struct nt_timer {
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
427          * initialized */
428         union {
429                 ULONGLONG due_time;
430                 struct wrap_timer *wrap_timer;
431         };
432         struct nt_list nt_timer_list;
433         struct kdpc *kdpc;
434         union {
435                 LONG period;
436                 LONG wrap_timer_magic;
437         };
438 };
439
440 struct nt_mutex {
441         struct dispatcher_header dh;
442         struct nt_list list;
443         struct task_struct *owner_thread;
444         BOOLEAN abandoned;
445         BOOLEAN apc_disable;
446 };
447
448 struct nt_semaphore {
449         struct dispatcher_header dh;
450         LONG limit;
451 };
452
453 struct nt_thread {
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
457          * need */
458         int pid;
459         NTSTATUS status;
460         struct task_struct *task;
461         struct nt_list irps;
462         NT_SPIN_LOCK lock;
463         KPRIORITY prio;
464 };
465
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)
472
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
480
481 struct irp;
482 struct dev_obj_ext;
483 struct driver_object;
484
485 struct device_object {
486         CSHORT type;
487         USHORT size;
488         LONG ref_count;
489         struct driver_object *drv_obj;
490         struct device_object *next;
491         struct device_object *attached;
492         struct irp *current_irp;
493         void *io_timer;
494         ULONG flags;
495         ULONG characteristics;
496         void *vpb;
497         void *dev_ext;
498         CCHAR stack_count;
499         union {
500                 struct nt_list queue_list;
501                 struct wait_context_block wcb;
502         } queue;
503         ULONG align_req;
504         struct kdevice_queue dev_queue;
505         struct kdpc dpc;
506         ULONG active_threads;
507         void *security_desc;
508         struct nt_event lock;
509         USHORT sector_size;
510         USHORT spare1;
511         struct dev_obj_ext *dev_obj_ext;
512         void *reserved;
513 };
514
515 struct dev_obj_ext {
516         CSHORT type;
517         CSHORT size;
518         struct device_object *dev_obj;
519         struct device_object *attached_to;
520 };
521
522 struct io_status_block {
523         union {
524                 NTSTATUS status;
525                 void *pointer;
526         };
527         ULONG_PTR info;
528 };
529
530 #ifdef CONFIG_X86_64
531 struct io_status_block32 {
532         NTSTATUS status;
533         ULONG info;
534 };
535 #endif
536
537 #define DEVICE_TYPE ULONG
538
539 struct driver_extension;
540
541 typedef NTSTATUS driver_dispatch_t(struct device_object *dev_obj,
542                                    struct irp *irp) wstdcall;
543
544 struct driver_object {
545         CSHORT type;
546         CSHORT size;
547         struct device_object *dev_obj;
548         ULONG flags;
549         void *start;
550         ULONG driver_size;
551         void *section;
552         struct driver_extension *drv_ext;
553         struct unicode_string name;
554         struct unicode_string *hardware_database;
555         void *fast_io_dispatch;
556         void *init;
557         void *start_io;
558         void (*unload)(struct driver_object *driver) wstdcall;
559         driver_dispatch_t *major_func[IRP_MJ_MAXIMUM_FUNCTION + 1];
560 };
561
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;
566         ULONG count;
567         struct unicode_string service_key_name;
568         struct nt_list custom_ext;
569 };
570
571 struct custom_ext {
572         struct nt_list list;
573         void *client_id;
574 };
575
576 struct wrap_bin_file;
577
578 struct file_object {
579         CSHORT type;
580         CSHORT size;
581         struct device_object *dev_obj;
582         void *volume_parameter_block;
583         void *fs_context;
584         void *fs_context2;
585         void *section_object_pointer;
586         void *private_cache_map;
587         NTSTATUS final_status;
588         union {
589                 struct file_object *related_file_object;
590                 struct wrap_bin_file *wrap_bin_file;
591         };
592         BOOLEAN lock_operation;
593         BOOLEAN delete_pending;
594         BOOLEAN read_access;
595         BOOLEAN write_access;
596         BOOLEAN delete_access;
597         BOOLEAN shared_read;
598         BOOLEAN shared_write;
599         BOOLEAN shared_delete;
600         ULONG flags;
601         struct unicode_string _name_;
602         LARGE_INTEGER current_byte_offset;
603         ULONG waiters;
604         ULONG busy;
605         void *last_lock;
606         struct nt_event lock;
607         struct nt_event event;
608         void *completion_context;
609 };
610
611 #ifdef CONFIG_X86_64
612 #define POINTER_ALIGN __attribute__((aligned(8)))
613 #else
614 #define POINTER_ALIGN
615 #endif
616
617 #define CACHE_ALIGN __attribute__((aligned(128)))
618
619 enum system_power_state {
620         PowerSystemUnspecified = 0,
621         PowerSystemWorking, PowerSystemSleeping1, PowerSystemSleeping2,
622         PowerSystemSleeping3, PowerSystemHibernate, PowerSystemShutdown,
623         PowerSystemMaximum,
624 };
625
626 enum device_power_state {
627         PowerDeviceUnspecified = 0,
628         PowerDeviceD0, PowerDeviceD1, PowerDeviceD2, PowerDeviceD3,
629         PowerDeviceMaximum,
630 };
631
632 union power_state {
633         enum system_power_state system_state;
634         enum device_power_state device_state;
635 };
636
637 enum power_state_type {
638         SystemPowerState = 0, DevicePowerState,
639 };
640
641 enum power_action {
642         PowerActionNone = 0,
643         PowerActionReserved, PowerActionSleep, PowerActionHibernate,
644         PowerActionShutdown, PowerActionShutdownReset, PowerActionShutdownOff,
645         PowerActionWarmEject,
646 };
647
648 struct guid {
649         ULONG data1;
650         USHORT data2;
651         USHORT data3;
652         UCHAR data4[8];
653 };
654
655 struct nt_interface {
656         USHORT size;
657         USHORT version;
658         void *context;
659         void (*reference)(void *context) wstdcall;
660         void (*dereference)(void *context) wstdcall;
661 };
662
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,
668 };
669
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
678
679 #define CmResourceTypeNonArbitrated     128
680 #define CmResourceTypeConfigData        128
681 #define CmResourceTypeDevicePrivate     129
682 #define CmResourceTypePcCardConfig      130
683 #define CmResourceTypeMfCardConfig      131
684
685 enum cm_share_disposition {
686         CmResourceShareUndetermined = 0, CmResourceShareDeviceExclusive,
687         CmResourceShareDriverExclusive, CmResourceShareShared
688 };
689
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
696
697 #define CM_RESOURCE_MEMORY_COMBINEDWRITE        0x0008
698 #define CM_RESOURCE_MEMORY_24                   0x0010
699 #define CM_RESOURCE_MEMORY_CACHEABLE            0x0020
700
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
709
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
718
719 #define MAX_RESOURCES 20
720
721 #pragma pack(push,4)
722 struct cm_partial_resource_descriptor {
723         UCHAR type;
724         UCHAR share;
725         USHORT flags;
726         union {
727                 struct {
728                         PHYSICAL_ADDRESS start;
729                         ULONG length;
730                 } generic;
731                 struct {
732                         PHYSICAL_ADDRESS start;
733                         ULONG length;
734                 } port;
735                 struct {
736                         ULONG level;
737                         ULONG vector;
738                         KAFFINITY affinity;
739                 } interrupt;
740                 struct {
741                         PHYSICAL_ADDRESS start;
742                         ULONG length;
743                 } memory;
744                 struct {
745                         ULONG channel;
746                         ULONG port;
747                         ULONG reserved1;
748                 } dma;
749                 struct {
750                         ULONG data[3];
751                 } device_private;
752                 struct {
753                         ULONG start;
754                         ULONG length;
755                         ULONG reserved;
756                 } bus_number;
757                 struct {
758                         ULONG data_size;
759                         ULONG reserved1;
760                         ULONG reserved2;
761                 } device_specific_data;
762         } u;
763 };
764 #pragma pack(pop)
765
766 struct cm_partial_resource_list {
767         USHORT version;
768         USHORT revision;
769         ULONG count;
770         struct cm_partial_resource_descriptor partial_descriptors[1];
771 };
772
773 struct cm_full_resource_descriptor {
774         enum interface_type interface_type;
775         ULONG bus_number;
776         struct cm_partial_resource_list partial_resource_list;
777 };
778
779 struct cm_resource_list {
780         ULONG count;
781         struct cm_full_resource_descriptor list[1];
782 };
783
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,
794 };
795
796 enum fs_info_class {
797         FileFsVolumeInformation = 1,
798         /* ... */
799         FileFsMaximumInformation = 9,
800 };
801
802 enum device_relation_type {
803         BusRelations, EjectionRelations, PowerRelations, RemovalRelations,
804         TargetDeviceRelation, SingleBusRelations,
805 };
806
807 enum bus_query_id_type {
808         BusQueryDeviceID = 0, BusQueryHardwareIDs = 1,
809         BusQueryCompatibleIDs = 2, BusQueryInstanceID = 3,
810         BusQueryDeviceSerialNumber = 4,
811 };
812
813 enum device_text_type {
814         DeviceTextDescription = 0, DeviceTextLocationInformation = 1,
815 };
816
817 enum device_usage_notification_type {
818         DeviceUsageTypeUndefined, DeviceUsageTypePaging,
819         DeviceUsageTypeHibernation, DevbiceUsageTypeDumpFile,
820 };
821
822 #define METHOD_BUFFERED         0
823 #define METHOD_IN_DIRECT        1
824 #define METHOD_OUT_DIRECT       2
825 #define METHOD_NEITHER          3
826
827 #define CTL_CODE(dev_type, func, method, access)                        \
828         (((dev_type) << 16) | ((access) << 14) | ((func) << 2) | (method))
829
830 #define IO_METHOD_FROM_CTL_CODE(code) (code & 0x3)
831
832 #ifndef CONFIG_X86_64
833 #pragma pack(push,4)
834 #endif
835 struct io_stack_location {
836         UCHAR major_fn;
837         UCHAR minor_fn;
838         UCHAR flags;
839         UCHAR control;
840         union {
841                 struct {
842                         void *security_context;
843                         ULONG options;
844                         USHORT POINTER_ALIGN file_attributes;
845                         USHORT share_access;
846                         ULONG POINTER_ALIGN ea_length;
847                 } create;
848                 struct {
849                         ULONG length;
850                         ULONG POINTER_ALIGN key;
851                         LARGE_INTEGER byte_offset;
852                 } read;
853                 struct {
854                         ULONG length;
855                         ULONG POINTER_ALIGN key;
856                         LARGE_INTEGER byte_offset;
857                 } write;
858                 struct {
859                         ULONG length;
860                         enum file_info_class POINTER_ALIGN file_info_class;
861                 } query_file;
862                 struct {
863                         ULONG length;
864                         enum file_info_class POINTER_ALIGN file_info_class;
865                         struct file_object *file_object;
866                         union {
867                                 struct {
868                                         BOOLEAN replace_if_exists;
869                                         BOOLEAN advance_only;
870                                 };
871                                 ULONG cluster_count;
872                                 void *delete_handle;
873                         };
874                 } set_file;
875                 struct {
876                         ULONG length;
877                         enum fs_info_class POINTER_ALIGN fs_info_class;
878                 } query_volume;
879                 struct {
880                         ULONG output_buf_len;
881                         ULONG POINTER_ALIGN input_buf_len;
882                         ULONG POINTER_ALIGN code;
883                         void *type3_input_buf;
884                 } dev_ioctl;
885                 struct {
886                         SECURITY_INFORMATION security_info;
887                         ULONG POINTER_ALIGN length;
888                 } query_security;
889                 struct {
890                         SECURITY_INFORMATION security_info;
891                         void *security_descriptor;
892                 } set_security;
893                 struct {
894                         void *vpb;
895                         struct device_object *device_object;
896                 } mount_volume;
897                 struct {
898                         void *vpb;
899                         struct device_object *device_object;
900                 } verify_volume;
901                 struct {
902                         void *srb;
903                 } scsi;
904                 struct {
905                         enum device_relation_type type;
906                 } query_device_relations;
907                 struct {
908                         const struct guid *type;
909                         USHORT size;
910                         USHORT version;
911                         struct nt_interface *intf;
912                         void *intf_data;
913                 } query_intf;
914                 struct {
915                         void *capabilities;
916                 } device_capabilities;
917                 struct {
918                         void *io_resource_requirement_list;
919                 } filter_resource_requirements;
920                 struct {
921                         ULONG which_space;
922                         void *buffer;
923                         ULONG offset;
924                         ULONG POINTER_ALIGN length;
925                 } read_write_config;
926                 struct {
927                         BOOLEAN lock;
928                 } set_lock;
929                 struct {
930                         enum bus_query_id_type id_type;
931                 } query_id;
932                 struct {
933                         enum device_text_type device_text_type;
934                         ULONG POINTER_ALIGN locale_id;
935                 } query_device_text;
936                 struct {
937                         BOOLEAN in_path;
938                         BOOLEAN reserved[3];
939                         enum device_usage_notification_type POINTER_ALIGN type;
940                 } usage_notification;
941                 struct {
942                         enum system_power_state power_state;
943                 } wait_wake;
944                 struct {
945                         void *power_sequence;
946                 } power_sequence;
947                 struct {
948                         ULONG sys_context;
949                         enum power_state_type POINTER_ALIGN type;
950                         union power_state POINTER_ALIGN state;
951                         enum power_action POINTER_ALIGN shutdown_type;
952                 } power;
953                 struct {
954                         struct cm_resource_list *allocated_resources;
955                         struct cm_resource_list *allocated_resources_translated;
956                 } start_device;
957                 struct {
958                         ULONG_PTR provider_id;
959                         void *data_path;
960                         ULONG buf_len;
961                         void *buf;
962                 } wmi;
963                 struct {
964                         void *arg1;
965                         void *arg2;
966                         void *arg3;
967                         void *arg4;
968                 } others;
969         } params;
970         struct device_object *dev_obj;
971         struct file_object *file_obj;
972         NTSTATUS (*completion_routine)(struct device_object *,
973                                        struct irp *, void *) wstdcall;
974         void *context;
975 };
976 #ifndef CONFIG_X86_64
977 #pragma pack(pop)
978 #endif
979
980 struct kapc {
981         CSHORT type;
982         CSHORT size;
983         ULONG spare0;
984         struct nt_thread *thread;
985         struct nt_list list;
986         void *kernele_routine;
987         void *rundown_routine;
988         void *normal_routine;
989         void *normal_context;
990         void *sys_arg1;
991         void *sys_arg2;
992         CCHAR apc_state_index;
993         KPROCESSOR_MODE apc_mode;
994         BOOLEAN inserted;
995 };
996
997 #define IRP_NOCACHE                     0x00000001
998 #define IRP_SYNCHRONOUS_API             0x00000004
999 #define IRP_ASSOCIATED_IRP              0x00000008
1000
1001 enum urb_state {
1002         URB_INVALID = 1, URB_ALLOCATED, URB_SUBMITTED,
1003         URB_COMPLETED, URB_FREE, URB_SUSPEND, URB_INT_UNLINKED };
1004
1005 struct wrap_urb {
1006         struct nt_list list;
1007         enum urb_state state;
1008         struct nt_list complete_list;
1009         unsigned int flags;
1010         struct urb *urb;
1011         struct irp *irp;
1012 #ifdef USB_DEBUG
1013         unsigned int id;
1014 #endif
1015 };
1016
1017 struct irp {
1018         SHORT type;
1019         USHORT size;
1020         struct mdl *mdl;
1021         ULONG flags;
1022         union {
1023                 struct irp *master_irp;
1024                 LONG irp_count;
1025                 void *system_buffer;
1026         } associated_irp;
1027         struct nt_list thread_list;
1028         struct io_status_block io_status;
1029         KPROCESSOR_MODE requestor_mode;
1030         BOOLEAN pending_returned;
1031         CHAR stack_count;
1032         CHAR current_location;
1033         BOOLEAN cancel;
1034         KIRQL cancel_irql;
1035         CCHAR apc_env;
1036         UCHAR alloc_flags;
1037         struct io_status_block *user_status;
1038         struct nt_event *user_event;
1039         union {
1040                 struct {
1041                         void *user_apc_routine;
1042                         void *user_apc_context;
1043                 } async_params;
1044                 LARGE_INTEGER alloc_size;
1045         } overlay;
1046         void (*cancel_routine)(struct device_object *, struct irp *) wstdcall;
1047         void *user_buf;
1048         union {
1049                 struct {
1050                         union {
1051                                 struct kdevice_queue_entry dev_q_entry;
1052                                 struct {
1053                                         void *driver_context[4];
1054                                 };
1055                         };
1056                         void *thread;
1057                         char *aux_buf;
1058                         struct {
1059                                 struct nt_list list;
1060                                 union {
1061                                         struct io_stack_location *csl;
1062                                         ULONG packet_type;
1063                                 };
1064                         };
1065                         struct file_object *file_object;
1066                 } overlay;
1067                 union {
1068                         struct kapc apc;
1069                         /* space for apc is used for ndiswrapper
1070                          * specific fields */
1071                         struct {
1072                                 struct wrap_urb *wrap_urb;
1073                                 struct wrap_device *wrap_device;
1074                         };
1075                 };
1076                 void *completion_key;
1077         } tail;
1078 };
1079
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)
1089
1090 #define IoSetNextIrpStackLocation(irp)                          \
1091 do {                                                            \
1092         KIRQL _irql_;                                           \
1093         IoAcquireCancelSpinLock(&_irql_);                       \
1094         (irp)->current_location--;                              \
1095         IoGetCurrentIrpStackLocation(irp)--;                    \
1096         IoReleaseCancelSpinLock(_irql_);                        \
1097 } while (0)
1098
1099 #define IoSkipCurrentIrpStackLocation(irp)                      \
1100 do {                                                            \
1101         KIRQL _irql_;                                           \
1102         IoAcquireCancelSpinLock(&_irql_);                       \
1103         (irp)->current_location++;                              \
1104         IoGetCurrentIrpStackLocation(irp)++;                    \
1105         IoReleaseCancelSpinLock(_irql_);                        \
1106 } while (0)
1107
1108 static inline void
1109 IoCopyCurrentIrpStackLocationToNext(struct irp *irp)
1110 {
1111         struct io_stack_location *next;
1112         next = IoGetNextIrpStackLocation(irp);
1113         memcpy(next, IoGetCurrentIrpStackLocation(irp),
1114                offsetof(struct io_stack_location, completion_routine));
1115         next->control = 0;
1116 }
1117
1118 static inline void
1119 IoSetCompletionRoutine(struct irp *irp, void *routine, void *context,
1120                        BOOLEAN success, BOOLEAN error, BOOLEAN cancel)
1121 {
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;
1126         if (success)
1127                 irp_sl->control |= SL_INVOKE_ON_SUCCESS;
1128         if (error)
1129                 irp_sl->control |= SL_INVOKE_ON_ERROR;
1130         if (cancel)
1131                 irp_sl->control |= SL_INVOKE_ON_CANCEL;
1132 }
1133
1134 #define IoMarkIrpPending(irp)                                           \
1135         (IoGetCurrentIrpStackLocation((irp))->control |= SL_PENDING_RETURNED)
1136 #define IoUnmarkIrpPending(irp)                                         \
1137         (IoGetCurrentIrpStackLocation((irp))->control &= ~SL_PENDING_RETURNED)
1138
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)
1142
1143 #define IRP_URB(irp)                                                    \
1144         (union nt_urb *)(IoGetCurrentIrpStackLocation(irp)->params.others.arg1)
1145
1146 #define IRP_WRAP_DEVICE(irp) (irp)->tail.wrap_device
1147 #define IRP_WRAP_URB(irp) (irp)->tail.wrap_urb
1148
1149 struct wmi_guid_reg_info {
1150         struct guid *guid;
1151         ULONG instance_count;
1152         ULONG flags;
1153 };
1154
1155 struct wmilib_context {
1156         ULONG guid_count;
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;
1164 };
1165
1166 enum key_value_information_class {
1167         KeyValueBasicInformation, KeyValueFullInformation,
1168         KeyValuePartialInformation, KeyValueFullInformationAlign64,
1169         KeyValuePartialInformationAlign64
1170 };
1171
1172 struct file_name_info {
1173         ULONG length;
1174         wchar_t *name;
1175 };
1176
1177 struct file_std_info {
1178         LARGE_INTEGER alloc_size;
1179         LARGE_INTEGER eof;
1180         ULONG num_links;
1181         BOOLEAN delete_pending;
1182         BOOLEAN dir;
1183 };
1184
1185 enum nt_obj_type {
1186         NT_OBJ_EVENT = 10, NT_OBJ_MUTEX, NT_OBJ_THREAD, NT_OBJ_TIMER,
1187         NT_OBJ_SEMAPHORE,
1188 };
1189
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,
1193 };
1194
1195 struct common_object_header {
1196         struct nt_list list;
1197         enum common_object_type type;
1198         UINT size;
1199         UINT ref_count;
1200         BOOLEAN close_in_process;
1201         BOOLEAN permanent;
1202         struct unicode_string name;
1203 };
1204
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)
1214
1215 enum work_queue_type {
1216         CriticalWorkQueue, DelayedWorkQueue, HyperCriticalWorkQueue,
1217         MaximumWorkQueue
1218 };
1219
1220 typedef void (*NTOS_WORK_FUNC)(void *arg1, void *arg2) wstdcall;
1221
1222 struct io_workitem {
1223         enum work_queue_type type;
1224         struct device_object *dev_obj;
1225         NTOS_WORK_FUNC worker_routine;
1226         void *context;
1227 };
1228
1229 struct io_workitem_entry {
1230         struct nt_list list;
1231         struct io_workitem *io_workitem;
1232 };
1233
1234 enum mm_page_priority {
1235         LowPagePriority, NormalPagePriority = 16, HighPagePriority = 32
1236 };
1237
1238 enum kinterrupt_mode {
1239         LevelSensitive, Latched
1240 };
1241
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
1249 };
1250
1251 typedef enum ntos_wait_reason KWAIT_REASON;
1252
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;
1256
1257 struct npaged_lookaside_list {
1258         nt_slist_header head;
1259         USHORT depth;
1260         USHORT maxdepth;
1261         ULONG totalallocs;
1262         union {
1263                 ULONG allocmisses;
1264                 ULONG allochits;
1265         } u1;
1266         ULONG totalfrees;
1267         union {
1268                 ULONG freemisses;
1269                 ULONG freehits;
1270         } u2;
1271         enum pool_type pool_type;
1272         ULONG tag;
1273         ULONG size;
1274         LOOKASIDE_ALLOC_FUNC *alloc_func;
1275         LOOKASIDE_FREE_FUNC *free_func;
1276         struct nt_list list;
1277         ULONG lasttotallocs;
1278         union {
1279                 ULONG lastallocmisses;
1280                 ULONG lastallochits;
1281         } u3;
1282         ULONG pad[2];
1283 #ifndef CONFIG_X86_64
1284         NT_SPIN_LOCK obsolete;
1285 #endif
1286 }
1287 #ifdef CONFIG_X86_64
1288 CACHE_ALIGN
1289 #endif
1290 ;
1291
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
1304 };
1305
1306 enum trace_information_class {
1307         TraceIdClass, TraceHandleClass, TraceEnableFlagsClass,
1308         TraceEnableLevelClass, GlobalLoggerHandleClass, EventLoggerHandleClass,
1309         AllLoggerHandlesClass, TraceHandleByNameClass
1310 };
1311
1312 struct kinterrupt;
1313 typedef BOOLEAN (*PKSERVICE_ROUTINE)(struct kinterrupt *interrupt,
1314                                      void *context) wstdcall;
1315 typedef BOOLEAN (*PKSYNCHRONIZE_ROUTINE)(void *context) wstdcall;
1316
1317 struct kinterrupt {
1318         ULONG vector;
1319         KAFFINITY cpu_mask;
1320         NT_SPIN_LOCK lock;
1321         NT_SPIN_LOCK *actual_lock;
1322         BOOLEAN shared;
1323         BOOLEAN save_fp;
1324         union {
1325                 CHAR processor_number;
1326 #ifdef CONFIG_DEBUG_SHIRQ
1327                 CHAR enabled;
1328 #endif
1329         } u;
1330         PKSERVICE_ROUTINE isr;
1331         void *isr_ctx;
1332         struct nt_list list;
1333         KIRQL irql;
1334         KIRQL synch_irql;
1335         enum kinterrupt_mode mode;
1336 };
1337
1338 struct time_fields {
1339         CSHORT year;
1340         CSHORT month;
1341         CSHORT day;
1342         CSHORT hour;
1343         CSHORT minute;
1344         CSHORT second;
1345         CSHORT milliseconds;
1346         CSHORT weekday;
1347 };
1348
1349 struct object_attributes {
1350         ULONG length;
1351         void *root_dir;
1352         struct unicode_string *name;
1353         ULONG attributes;
1354         void *security_descr;
1355         void *security_qos;
1356 };
1357
1358 typedef void (*PCALLBACK_FUNCTION)(void *context, void *arg1,
1359                                    void *arg2) wstdcall;
1360
1361 struct callback_object;
1362 struct callback_func {
1363         PCALLBACK_FUNCTION func;
1364         void *context;
1365         struct nt_list list;
1366         struct callback_object *object;
1367 };
1368
1369 struct callback_object {
1370         NT_SPIN_LOCK lock;
1371         struct nt_list list;
1372         struct nt_list callback_funcs;
1373         BOOLEAN allow_multiple_callbacks;
1374         struct object_attributes *attributes;
1375 };
1376
1377 enum section_inherit {
1378         ViewShare = 1, ViewUnmap = 2
1379 };
1380
1381 struct ksystem_time {
1382         ULONG low_part;
1383         LONG high1_time;
1384         LONG high2_time;
1385 };
1386
1387 enum nt_product_type {
1388         nt_product_win_nt = 1, nt_product_lan_man_nt, nt_product_server
1389 };
1390
1391 enum alt_arch_type {
1392         arch_type_standard, arch_type_nex98x86, end_alternatives
1393 };
1394
1395 struct kuser_shared_data {
1396         ULONG tick_count;
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;
1406         ULONG time_zone_id;
1407         ULONG large_page_min;
1408         ULONG reserved2[7];
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];
1414         ULONG reserved1;
1415         ULONG reserved3;
1416         volatile LONG time_slip;
1417         enum alt_arch_type alt_arch_type;
1418         LARGE_INTEGER system_expiration_date;
1419         ULONG suite_mask;
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;
1427         ULONG trace_log;
1428         ULONGLONG fill0;
1429         ULONGLONG sys_call[4];
1430         union {
1431                 volatile struct ksystem_time tick_count;
1432                 volatile ULONG64 tick_count_quad;
1433         } tick;
1434 };
1435
1436 #define REG_NONE                        (0)
1437 #define REG_SZ                          (1)
1438 #define REG_EXPAND_SZ                   (2)
1439 #define REG_BINARY                      (3)
1440 #define REG_DWORD                       (4)
1441
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
1451
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
1459
1460 typedef NTSTATUS (*PRTL_QUERY_REGISTRY_ROUTINE)(wchar_t *name, ULONG type,
1461                                                 void *data, ULONG length,
1462                                                 void *context,
1463                                                 void *entry) wstdcall;
1464
1465 struct rtl_query_registry_table {
1466         PRTL_QUERY_REGISTRY_ROUTINE query_func;
1467         ULONG flags;
1468         wchar_t *name;
1469         void *context;
1470         ULONG def_type;
1471         void *def_data;
1472         ULONG def_length;
1473 };
1474
1475 struct io_remove_lock {
1476         BOOLEAN removed;
1477         BOOLEAN reserved[3];
1478         LONG io_count;
1479         struct nt_event remove_event;
1480 };
1481
1482 struct io_error_log_packet {
1483         UCHAR major_fn_code;
1484         UCHAR retry_count;
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;
1495         ULONG dump_data[1];
1496 };
1497
1498 /* some of the functions below are slightly different from DDK's
1499  * implementation; e.g., Insert functions return appropriate
1500  * pointer */
1501
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) */
1506
1507 static inline void InitializeListHead(struct nt_list *head)
1508 {
1509         head->next = head->prev = head;
1510 }
1511
1512 static inline BOOLEAN IsListEmpty(struct nt_list *head)
1513 {
1514         if (head == head->next)
1515                 return TRUE;
1516         else
1517                 return FALSE;
1518 }
1519
1520 static inline void RemoveEntryList(struct nt_list *entry)
1521 {
1522         entry->prev->next = entry->next;
1523         entry->next->prev = entry->prev;
1524 }
1525
1526 static inline struct nt_list *RemoveHeadList(struct nt_list *head)
1527 {
1528         struct nt_list *entry;
1529
1530         entry = head->next;
1531         if (entry == head)
1532                 return NULL;
1533         else {
1534                 RemoveEntryList(entry);
1535                 return entry;
1536         }
1537 }
1538
1539 static inline struct nt_list *RemoveTailList(struct nt_list *head)
1540 {
1541         struct nt_list *entry;
1542
1543         entry = head->prev;
1544         if (entry == head)
1545                 return NULL;
1546         else {
1547                 RemoveEntryList(entry);
1548                 return entry;
1549         }
1550 }
1551
1552 static inline void InsertListEntry(struct nt_list *entry, struct nt_list *prev,
1553                                    struct nt_list *next)
1554 {
1555         next->prev = entry;
1556         entry->next = next;
1557         entry->prev = prev;
1558         prev->next = entry;
1559 }
1560
1561 static inline struct nt_list *InsertHeadList(struct nt_list *head,
1562                                              struct nt_list *entry)
1563 {
1564         struct nt_list *ret;
1565
1566         if (IsListEmpty(head))
1567                 ret = NULL;
1568         else
1569                 ret = head->next;
1570
1571         InsertListEntry(entry, head, head->next);
1572         return ret;
1573 }
1574
1575 static inline struct nt_list *InsertTailList(struct nt_list *head,
1576                                              struct nt_list *entry)
1577 {
1578         struct nt_list *ret;
1579
1580         if (IsListEmpty(head))
1581                 ret = NULL;
1582         else
1583                 ret = head->prev;
1584
1585         InsertListEntry(entry, head->prev, head);
1586         return ret;
1587 }
1588
1589 #define nt_list_for_each(pos, head)                                     \
1590         for (pos = (head)->next; pos != (head); pos = pos->next)
1591
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))
1596
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)
1600
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
1617
1618 /* Various supported device types (used with IoCreateDevice()) */
1619
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
1678
1679 /* Device characteristics */
1680
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
1690
1691 #define FILE_READ_DATA                  0x0001
1692 #define FILE_WRITE_DATA                 0x0002
1693
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
1700
1701
1702 #endif /* WINNT_TYPES_H */