ac(8): Staticize and raise WARNS to 6.
[dragonfly.git] / sys / emulation / ndis / ntoskrnl_var.h
blob4786d1778da46ad291c43154299d1292b9e6b9cb
1 /*-
2 * Copyright (c) 2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/compat/ndis/ntoskrnl_var.h,v 1.51 2010/12/06 20:54:53 bschmidt Exp $
35 #ifndef _NTOSKRNL_VAR_H_
36 #define _NTOSKRNL_VAR_H_
38 #define MTX_NTOSKRNL_SPIN_LOCK "NDIS thread lock"
41 * us_buf is really a wchar_t *, but it's inconvenient to include
42 * all the necessary header goop needed to define it, and it's a
43 * pointer anyway, so for now, just make it a uint16_t *.
45 struct unicode_string {
46 uint16_t us_len;
47 uint16_t us_maxlen;
48 uint16_t *us_buf;
51 typedef struct unicode_string unicode_string;
53 struct ansi_string {
54 uint16_t as_len;
55 uint16_t as_maxlen;
56 char *as_buf;
59 typedef struct ansi_string ansi_string;
62 * Windows memory descriptor list. In Windows, it's possible for
63 * buffers to be passed between user and kernel contexts without
64 * copying. Buffers may also be allocated in either paged or
65 * non-paged memory regions. An MDL describes the pages of memory
66 * used to contain a particular buffer. Note that a single MDL
67 * may describe a buffer that spans multiple pages. An array of
68 * page addresses appears immediately after the MDL structure itself.
69 * MDLs are therefore implicitly variably sized, even though they
70 * don't look it.
72 * Note that in FreeBSD, we can take many shortcuts in the way
73 * we handle MDLs because:
75 * - We are only concerned with pages in kernel context. This means
76 * we will only ever use the kernel's memory map, and remapping
77 * of buffers is never needed.
79 * - Kernel pages can never be paged out, so we don't have to worry
80 * about whether or not a page is actually mapped before going to
81 * touch it.
84 struct mdl {
85 struct mdl *mdl_next;
86 uint16_t mdl_size;
87 uint16_t mdl_flags;
88 void *mdl_process;
89 void *mdl_mappedsystemva;
90 void *mdl_startva;
91 uint32_t mdl_bytecount;
92 uint32_t mdl_byteoffset;
95 typedef struct mdl mdl, ndis_buffer;
97 /* MDL flags */
99 #define MDL_MAPPED_TO_SYSTEM_VA 0x0001
100 #define MDL_PAGES_LOCKED 0x0002
101 #define MDL_SOURCE_IS_NONPAGED_POOL 0x0004
102 #define MDL_ALLOCATED_FIXED_SIZE 0x0008
103 #define MDL_PARTIAL 0x0010
104 #define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020
105 #define MDL_IO_PAGE_READ 0x0040
106 #define MDL_WRITE_OPERATION 0x0080
107 #define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100
108 #define MDL_FREE_EXTRA_PTES 0x0200
109 #define MDL_IO_SPACE 0x0800
110 #define MDL_NETWORK_HEADER 0x1000
111 #define MDL_MAPPING_CAN_FAIL 0x2000
112 #define MDL_ALLOCATED_MUST_SUCCEED 0x4000
113 #define MDL_ZONE_ALLOCED 0x8000 /* BSD private */
115 #define MDL_ZONE_PAGES 16
116 #define MDL_ZONE_SIZE (sizeof(mdl) + (sizeof(vm_offset_t) * MDL_ZONE_PAGES))
118 /* Note: assumes x86 page size of 4K. */
120 #ifndef PAGE_SHIFT
121 #if PAGE_SIZE == 4096
122 #define PAGE_SHIFT 12
123 #elif PAGE_SIZE == 8192
124 #define PAGE_SHIFT 13
125 #else
126 #error PAGE_SHIFT undefined!
127 #endif
128 #endif
130 #define SPAN_PAGES(ptr, len) \
131 ((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE - 1)) + \
132 (len) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
134 #define PAGE_ALIGN(ptr) \
135 ((void *)((uintptr_t)(ptr) & ~(PAGE_SIZE - 1)))
137 #define BYTE_OFFSET(ptr) \
138 ((uint32_t)((uintptr_t)(ptr) & (PAGE_SIZE - 1)))
140 #define MDL_PAGES(m) (vm_offset_t *)(m + 1)
142 #define MmInitializeMdl(b, baseva, len) \
143 (b)->mdl_next = NULL; \
144 (b)->mdl_size = (uint16_t)(sizeof(mdl) + \
145 (sizeof(vm_offset_t) * SPAN_PAGES((baseva), (len)))); \
146 (b)->mdl_flags = 0; \
147 (b)->mdl_startva = (void *)PAGE_ALIGN((baseva)); \
148 (b)->mdl_byteoffset = BYTE_OFFSET((baseva)); \
149 (b)->mdl_bytecount = (uint32_t)(len);
151 #define MmGetMdlByteOffset(mdl) ((mdl)->mdl_byteoffset)
152 #define MmGetMdlByteCount(mdl) ((mdl)->mdl_bytecount)
153 #define MmGetMdlVirtualAddress(mdl) \
154 ((void *)((char *)((mdl)->mdl_startva) + (mdl)->mdl_byteoffset))
155 #define MmGetMdlStartVa(mdl) ((mdl)->mdl_startva)
156 #define MmGetMdlPfnArray(mdl) MDL_PAGES(mdl)
158 #define WDM_MAJOR 1
159 #define WDM_MINOR_WIN98 0x00
160 #define WDM_MINOR_WINME 0x05
161 #define WDM_MINOR_WIN2000 0x10
162 #define WDM_MINOR_WINXP 0x20
163 #define WDM_MINOR_WIN2003 0x30
165 enum nt_caching_type {
166 MmNonCached = 0,
167 MmCached = 1,
168 MmWriteCombined = 2,
169 MmHardwareCoherentCached = 3,
170 MmNonCachedUnordered = 4,
171 MmUSWCCached = 5,
172 MmMaximumCacheType = 6
176 * The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows.
177 * According to the Windows DDK header files, KSPIN_LOCK is defined like this:
178 * typedef ULONG_PTR KSPIN_LOCK;
180 * From basetsd.h (SDK, Feb. 2003):
181 * typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
182 * typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
183 * typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
185 * The keyword __int3264 specifies an integral type that has the following
186 * properties:
187 * + It is 32-bit on 32-bit platforms
188 * + It is 64-bit on 64-bit platforms
189 * + It is 32-bit on the wire for backward compatibility.
190 * It gets truncated on the sending side and extended appropriately
191 * (signed or unsigned) on the receiving side.
193 * Thus register_t seems the proper mapping onto FreeBSD for spin locks.
196 typedef register_t kspin_lock;
198 struct slist_entry {
199 struct slist_entry *sl_next;
202 typedef struct slist_entry slist_entry;
204 union slist_header {
205 uint64_t slh_align;
206 struct {
207 struct slist_entry *slh_next;
208 uint16_t slh_depth;
209 uint16_t slh_seq;
210 } slh_list;
213 typedef union slist_header slist_header;
215 struct list_entry {
216 struct list_entry *nle_flink;
217 struct list_entry *nle_blink;
220 typedef struct list_entry list_entry;
222 #define InitializeListHead(l) \
223 (l)->nle_flink = (l)->nle_blink = (l)
225 #define IsListEmpty(h) \
226 ((h)->nle_flink == (h))
228 #define RemoveEntryList(e) \
229 do { \
230 list_entry *b; \
231 list_entry *f; \
233 f = (e)->nle_flink; \
234 b = (e)->nle_blink; \
235 b->nle_flink = f; \
236 f->nle_blink = b; \
237 } while (0)
239 /* These two have to be inlined since they return things. */
241 static __inline__ list_entry *
242 RemoveHeadList(list_entry *l)
244 list_entry *f;
245 list_entry *e;
247 e = l->nle_flink;
248 f = e->nle_flink;
249 l->nle_flink = f;
250 f->nle_blink = l;
252 return (e);
255 static __inline__ list_entry *
256 RemoveTailList(list_entry *l)
258 list_entry *b;
259 list_entry *e;
261 e = l->nle_blink;
262 b = e->nle_blink;
263 l->nle_blink = b;
264 b->nle_flink = l;
266 return (e);
269 #define InsertTailList(l, e) \
270 do { \
271 list_entry *b; \
273 b = l->nle_blink; \
274 e->nle_flink = l; \
275 e->nle_blink = b; \
276 b->nle_flink = (e); \
277 l->nle_blink = (e); \
278 } while (0)
280 #define InsertHeadList(l, e) \
281 do { \
282 list_entry *f; \
284 f = l->nle_flink; \
285 e->nle_flink = f; \
286 e->nle_blink = l; \
287 f->nle_blink = e; \
288 l->nle_flink = e; \
289 } while (0)
291 #define CONTAINING_RECORD(addr, type, field) \
292 ((type *)((vm_offset_t)(addr) - (vm_offset_t)(&((type *)0)->field)))
294 struct nt_dispatch_header {
295 uint8_t dh_type;
296 uint8_t dh_abs;
297 uint8_t dh_size;
298 uint8_t dh_inserted;
299 int32_t dh_sigstate;
300 list_entry dh_waitlisthead;
303 typedef struct nt_dispatch_header nt_dispatch_header;
305 /* Dispatcher object types */
307 #define DISP_TYPE_NOTIFICATION_EVENT 0 /* KEVENT */
308 #define DISP_TYPE_SYNCHRONIZATION_EVENT 1 /* KEVENT */
309 #define DISP_TYPE_MUTANT 2 /* KMUTANT/KMUTEX */
310 #define DISP_TYPE_PROCESS 3 /* KPROCESS */
311 #define DISP_TYPE_QUEUE 4 /* KQUEUE */
312 #define DISP_TYPE_SEMAPHORE 5 /* KSEMAPHORE */
313 #define DISP_TYPE_THREAD 6 /* KTHREAD */
314 #define DISP_TYPE_NOTIFICATION_TIMER 8 /* KTIMER */
315 #define DISP_TYPE_SYNCHRONIZATION_TIMER 9 /* KTIMER */
317 #define OTYPE_EVENT 0
318 #define OTYPE_MUTEX 1
319 #define OTYPE_THREAD 2
320 #define OTYPE_TIMER 3
322 /* Windows dispatcher levels. */
324 #define PASSIVE_LEVEL 0
325 #define LOW_LEVEL 0
326 #define APC_LEVEL 1
327 #define DISPATCH_LEVEL 2
328 #define DEVICE_LEVEL (DISPATCH_LEVEL + 1)
329 #define PROFILE_LEVEL 27
330 #define CLOCK1_LEVEL 28
331 #define CLOCK2_LEVEL 28
332 #define IPI_LEVEL 29
333 #define POWER_LEVEL 30
334 #define HIGH_LEVEL 31
336 #define SYNC_LEVEL_UP DISPATCH_LEVEL
337 #define SYNC_LEVEL_MP (IPI_LEVEL - 1)
339 #define AT_PASSIVE_LEVEL(td) \
340 ((td)->td_proc->p_flags & P_SYSTEM == FALSE)
342 #define AT_DISPATCH_LEVEL(td) \
343 (lwkt_getpri(td) == TDPRI_INT_HIGH)
345 #define AT_DIRQL_LEVEL(td) \
346 ((td)->td_priority <= PI_NET)
348 #define AT_HIGH_LEVEL(td) \
349 ((td)->td_critnest != 0)
351 struct nt_objref {
352 nt_dispatch_header no_dh;
353 void *no_obj;
354 TAILQ_ENTRY(nt_objref) link;
357 TAILQ_HEAD(nt_objref_head, nt_objref);
359 typedef struct nt_objref nt_objref;
361 #define EVENT_TYPE_NOTIFY 0
362 #define EVENT_TYPE_SYNC 1
365 * We need to use the timeout()/untimeout() API for ktimers
366 * since timers can be initialized, but not destroyed (so
367 * malloc()ing our own callout structures would mean a leak,
368 * since there'd be no way to free() them). This means we
369 * need to use struct callout_handle, which is really just a
370 * pointer. To make it easier to deal with, we use a union
371 * to overlay the callout_handle over the k_timerlistentry.
372 * The latter is a list_entry, which is two pointers, so
373 * there's enough space available to hide a callout_handle
374 * there.
377 struct ktimer {
378 nt_dispatch_header k_header;
379 uint64_t k_duetime;
380 union {
381 list_entry k_timerlistentry;
382 struct callout *k_callout;
383 } u;
384 void *k_dpc;
385 uint32_t k_period;
388 #define k_timerlistentry u.k_timerlistentry
389 #define k_callout u.k_callout
391 typedef struct ktimer ktimer;
393 struct nt_kevent {
394 nt_dispatch_header k_header;
397 typedef struct nt_kevent nt_kevent;
399 /* Kernel defered procedure call (i.e. timer callback) */
401 struct kdpc;
402 typedef void (*kdpc_func)(struct kdpc *, void *, void *, void *);
404 struct kdpc {
405 uint16_t k_type;
406 uint8_t k_num; /* CPU number */
407 uint8_t k_importance; /* priority */
408 list_entry k_dpclistentry;
409 void *k_deferedfunc;
410 void *k_deferredctx;
411 void *k_sysarg1;
412 void *k_sysarg2;
413 void *k_lock;
416 #define KDPC_IMPORTANCE_LOW 0
417 #define KDPC_IMPORTANCE_MEDIUM 1
418 #define KDPC_IMPORTANCE_HIGH 2
420 #define KDPC_CPU_DEFAULT 255
422 typedef struct kdpc kdpc;
425 * Note: the acquisition count is BSD-specific. The Microsoft
426 * documentation says that mutexes can be acquired recursively
427 * by a given thread, but that you must release the mutex as
428 * many times as you acquired it before it will be set to the
429 * signalled state (i.e. before any other threads waiting on
430 * the object will be woken up). However the Windows KMUTANT
431 * structure has no field for keeping track of the number of
432 * acquisitions, so we need to add one ourselves. As long as
433 * driver code treats the mutex as opaque, we should be ok.
435 struct kmutant {
436 nt_dispatch_header km_header;
437 list_entry km_listentry;
438 void *km_ownerthread;
439 uint8_t km_abandoned;
440 uint8_t km_apcdisable;
443 typedef struct kmutant kmutant;
445 #define LOOKASIDE_DEPTH 256
447 struct general_lookaside {
448 slist_header gl_listhead;
449 uint16_t gl_depth;
450 uint16_t gl_maxdepth;
451 uint32_t gl_totallocs;
452 union {
453 uint32_t gl_allocmisses;
454 uint32_t gl_allochits;
455 } u_a;
456 uint32_t gl_totalfrees;
457 union {
458 uint32_t gl_freemisses;
459 uint32_t gl_freehits;
460 } u_m;
461 uint32_t gl_type;
462 uint32_t gl_tag;
463 uint32_t gl_size;
464 void *gl_allocfunc;
465 void *gl_freefunc;
466 list_entry gl_listent;
467 uint32_t gl_lasttotallocs;
468 union {
469 uint32_t gl_lastallocmisses;
470 uint32_t gl_lastallochits;
471 } u_l;
472 uint32_t gl_rsvd[2];
475 typedef struct general_lookaside general_lookaside;
477 struct npaged_lookaside_list {
478 general_lookaside nll_l;
481 typedef struct npaged_lookaside_list npaged_lookaside_list;
482 typedef struct npaged_lookaside_list paged_lookaside_list;
484 typedef void * (*lookaside_alloc_func)(uint32_t, size_t, uint32_t);
485 typedef void (*lookaside_free_func)(void *);
487 struct irp;
489 struct kdevice_qentry {
490 list_entry kqe_devlistent;
491 uint32_t kqe_sortkey;
492 uint8_t kqe_inserted;
495 typedef struct kdevice_qentry kdevice_qentry;
497 struct kdevice_queue {
498 uint16_t kq_type;
499 uint16_t kq_size;
500 list_entry kq_devlisthead;
501 kspin_lock kq_lock;
502 uint8_t kq_busy;
505 typedef struct kdevice_queue kdevice_queue;
507 struct wait_ctx_block {
508 kdevice_qentry wcb_waitqueue;
509 void *wcb_devfunc;
510 void *wcb_devctx;
511 uint32_t wcb_mapregcnt;
512 void *wcb_devobj;
513 void *wcb_curirp;
514 void *wcb_bufchaindpc;
517 typedef struct wait_ctx_block wait_ctx_block;
519 struct wait_block {
520 list_entry wb_waitlist;
521 void *wb_kthread;
522 nt_dispatch_header *wb_object;
523 struct wait_block *wb_next;
524 #ifdef notdef
525 uint16_t wb_waitkey;
526 uint16_t wb_waittype;
527 #endif
528 uint8_t wb_waitkey;
529 uint8_t wb_waittype;
530 uint8_t wb_awakened;
531 uint8_t wb_oldpri;
534 typedef struct wait_block wait_block;
536 #define wb_ext wb_kthread
538 #define THREAD_WAIT_OBJECTS 3
539 #define MAX_WAIT_OBJECTS 64
541 #define WAITTYPE_ALL 0
542 #define WAITTYPE_ANY 1
544 #define WAITKEY_VALID 0x8000
546 /* kthread priority */
547 #define LOW_PRIORITY 0
548 #define LOW_REALTIME_PRIORITY 16
549 #define HIGH_PRIORITY 31
551 struct thread_context {
552 void *tc_thrctx;
553 void *tc_thrfunc;
556 typedef struct thread_context thread_context;
558 /* Forward declaration */
559 struct driver_object;
560 struct devobj_extension;
562 struct driver_extension {
563 struct driver_object *dre_driverobj;
564 void *dre_adddevicefunc;
565 uint32_t dre_reinitcnt;
566 unicode_string dre_srvname;
569 * Drivers are allowed to add one or more custom extensions
570 * to the driver object, but there's no special pointer
571 * for them. Hang them off here for now.
574 list_entry dre_usrext;
577 typedef struct driver_extension driver_extension;
579 struct custom_extension {
580 list_entry ce_list;
581 void *ce_clid;
584 typedef struct custom_extension custom_extension;
587 * The KINTERRUPT structure in Windows is opaque to drivers.
588 * We define our own custom version with things we need.
591 struct kinterrupt {
592 list_entry ki_list;
593 device_t ki_dev;
594 int ki_rid;
595 void *ki_cookie;
596 struct resource *ki_irq;
597 kspin_lock ki_lock_priv;
598 kspin_lock *ki_lock;
599 void *ki_svcfunc;
600 void *ki_svcctx;
603 typedef struct kinterrupt kinterrupt;
605 struct ksystem_time {
606 uint32_t low_part;
607 int32_t high1_time;
608 int32_t high2_time;
611 enum nt_product_type {
612 NT_PRODUCT_WIN_NT = 1,
613 NT_PRODUCT_LAN_MAN_NT,
614 NT_PRODUCT_SERVER
617 enum alt_arch_type {
618 STANDARD_DESIGN,
619 NEC98x86,
620 END_ALTERNATIVES
623 struct kuser_shared_data {
624 uint32_t tick_count;
625 uint32_t tick_count_multiplier;
626 volatile struct ksystem_time interrupt_time;
627 volatile struct ksystem_time system_time;
628 volatile struct ksystem_time time_zone_bias;
629 uint16_t image_number_low;
630 uint16_t image_number_high;
631 int16_t nt_system_root[260];
632 uint32_t max_stack_trace_depth;
633 uint32_t crypto_exponent;
634 uint32_t time_zone_id;
635 uint32_t large_page_min;
636 uint32_t reserved2[7];
637 enum nt_product_type nt_product_type;
638 uint8_t product_type_is_valid;
639 uint32_t nt_major_version;
640 uint32_t nt_minor_version;
641 uint8_t processor_features[64];
642 uint32_t reserved1;
643 uint32_t reserved3;
644 volatile uint32_t time_slip;
645 enum alt_arch_type alt_arch_type;
646 int64_t system_expiration_date;
647 uint32_t suite_mask;
648 uint8_t kdbg_enabled;
649 volatile uint32_t active_console;
650 volatile uint32_t dismount_count;
651 uint32_t com_plus_package;
652 uint32_t last_system_rit_event_tick_count;
653 uint32_t num_phys_pages;
654 uint8_t safe_boot_mode;
655 uint32_t trace_log;
656 uint64_t fill0;
657 uint64_t sys_call[4];
658 union {
659 volatile struct ksystem_time tick_count;
660 volatile uint64_t tick_count_quad;
661 } tick;
665 * In Windows, there are Physical Device Objects (PDOs) and
666 * Functional Device Objects (FDOs). Physical Device Objects are
667 * created and maintained by bus drivers. For example, the PCI
668 * bus driver might detect two PCI ethernet cards on a given
669 * bus. The PCI bus driver will then allocate two device_objects
670 * for its own internal bookeeping purposes. This is analagous
671 * to the device_t that the FreeBSD PCI code allocates and passes
672 * into each PCI driver's probe and attach routines.
674 * When an ethernet driver claims one of the ethernet cards
675 * on the bus, it will create its own device_object. This is
676 * the Functional Device Object. This object is analagous to the
677 * device-specific softc structure.
680 struct device_object {
681 uint16_t do_type;
682 uint16_t do_size;
683 uint32_t do_refcnt;
684 struct driver_object *do_drvobj;
685 struct device_object *do_nextdev;
686 struct device_object *do_attacheddev;
687 struct irp *do_currirp;
688 void *do_iotimer;
689 uint32_t do_flags;
690 uint32_t do_characteristics;
691 void *do_vpb;
692 void *do_devext;
693 uint32_t do_devtype;
694 uint8_t do_stacksize;
695 union {
696 list_entry do_listent;
697 wait_ctx_block do_wcb;
698 } queue;
699 uint32_t do_alignreq;
700 kdevice_queue do_devqueue;
701 struct kdpc do_dpc;
702 uint32_t do_activethreads;
703 void *do_securitydesc;
704 struct nt_kevent do_devlock;
705 uint16_t do_sectorsz;
706 uint16_t do_spare1;
707 struct devobj_extension *do_devobj_ext;
708 void *do_rsvd;
711 typedef struct device_object device_object;
713 struct devobj_extension {
714 uint16_t dve_type;
715 uint16_t dve_size;
716 device_object *dve_devobj;
719 typedef struct devobj_extension devobj_extension;
721 /* Device object flags */
723 #define DO_VERIFY_VOLUME 0x00000002
724 #define DO_BUFFERED_IO 0x00000004
725 #define DO_EXCLUSIVE 0x00000008
726 #define DO_DIRECT_IO 0x00000010
727 #define DO_MAP_IO_BUFFER 0x00000020
728 #define DO_DEVICE_HAS_NAME 0x00000040
729 #define DO_DEVICE_INITIALIZING 0x00000080
730 #define DO_SYSTEM_BOOT_PARTITION 0x00000100
731 #define DO_LONG_TERM_REQUESTS 0x00000200
732 #define DO_NEVER_LAST_DEVICE 0x00000400
733 #define DO_SHUTDOWN_REGISTERED 0x00000800
734 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
735 #define DO_POWER_PAGABLE 0x00002000
736 #define DO_POWER_INRUSH 0x00004000
737 #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
739 /* Priority boosts */
741 #define IO_NO_INCREMENT 0
742 #define IO_CD_ROM_INCREMENT 1
743 #define IO_DISK_INCREMENT 1
744 #define IO_KEYBOARD_INCREMENT 6
745 #define IO_MAILSLOT_INCREMENT 2
746 #define IO_MOUSE_INCREMENT 6
747 #define IO_NAMED_PIPE_INCREMENT 2
748 #define IO_NETWORK_INCREMENT 2
749 #define IO_PARALLEL_INCREMENT 1
750 #define IO_SERIAL_INCREMENT 2
751 #define IO_SOUND_INCREMENT 8
752 #define IO_VIDEO_INCREMENT 1
754 /* IRP major codes */
756 #define IRP_MJ_CREATE 0x00
757 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
758 #define IRP_MJ_CLOSE 0x02
759 #define IRP_MJ_READ 0x03
760 #define IRP_MJ_WRITE 0x04
761 #define IRP_MJ_QUERY_INFORMATION 0x05
762 #define IRP_MJ_SET_INFORMATION 0x06
763 #define IRP_MJ_QUERY_EA 0x07
764 #define IRP_MJ_SET_EA 0x08
765 #define IRP_MJ_FLUSH_BUFFERS 0x09
766 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
767 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
768 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
769 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
770 #define IRP_MJ_DEVICE_CONTROL 0x0e
771 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
772 #define IRP_MJ_SHUTDOWN 0x10
773 #define IRP_MJ_LOCK_CONTROL 0x11
774 #define IRP_MJ_CLEANUP 0x12
775 #define IRP_MJ_CREATE_MAILSLOT 0x13
776 #define IRP_MJ_QUERY_SECURITY 0x14
777 #define IRP_MJ_SET_SECURITY 0x15
778 #define IRP_MJ_POWER 0x16
779 #define IRP_MJ_SYSTEM_CONTROL 0x17
780 #define IRP_MJ_DEVICE_CHANGE 0x18
781 #define IRP_MJ_QUERY_QUOTA 0x19
782 #define IRP_MJ_SET_QUOTA 0x1a
783 #define IRP_MJ_PNP 0x1b
784 #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
785 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
786 #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
788 /* IRP minor codes */
790 #define IRP_MN_QUERY_DIRECTORY 0x01
791 #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
792 #define IRP_MN_USER_FS_REQUEST 0x00
794 #define IRP_MN_MOUNT_VOLUME 0x01
795 #define IRP_MN_VERIFY_VOLUME 0x02
796 #define IRP_MN_LOAD_FILE_SYSTEM 0x03
797 #define IRP_MN_TRACK_LINK 0x04
798 #define IRP_MN_KERNEL_CALL 0x04
800 #define IRP_MN_LOCK 0x01
801 #define IRP_MN_UNLOCK_SINGLE 0x02
802 #define IRP_MN_UNLOCK_ALL 0x03
803 #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
805 #define IRP_MN_NORMAL 0x00
806 #define IRP_MN_DPC 0x01
807 #define IRP_MN_MDL 0x02
808 #define IRP_MN_COMPLETE 0x04
809 #define IRP_MN_COMPRESSED 0x08
811 #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
812 #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
813 #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
815 #define IRP_MN_SCSI_CLASS 0x01
817 #define IRP_MN_START_DEVICE 0x00
818 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
819 #define IRP_MN_REMOVE_DEVICE 0x02
820 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
821 #define IRP_MN_STOP_DEVICE 0x04
822 #define IRP_MN_QUERY_STOP_DEVICE 0x05
823 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
825 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
826 #define IRP_MN_QUERY_INTERFACE 0x08
827 #define IRP_MN_QUERY_CAPABILITIES 0x09
828 #define IRP_MN_QUERY_RESOURCES 0x0A
829 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
830 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
831 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
833 #define IRP_MN_READ_CONFIG 0x0F
834 #define IRP_MN_WRITE_CONFIG 0x10
835 #define IRP_MN_EJECT 0x11
836 #define IRP_MN_SET_LOCK 0x12
837 #define IRP_MN_QUERY_ID 0x13
838 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
839 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
840 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
841 #define IRP_MN_SURPRISE_REMOVAL 0x17
842 #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
844 #define IRP_MN_WAIT_WAKE 0x00
845 #define IRP_MN_POWER_SEQUENCE 0x01
846 #define IRP_MN_SET_POWER 0x02
847 #define IRP_MN_QUERY_POWER 0x03
849 #define IRP_MN_QUERY_ALL_DATA 0x00
850 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
851 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
852 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
853 #define IRP_MN_ENABLE_EVENTS 0x04
854 #define IRP_MN_DISABLE_EVENTS 0x05
855 #define IRP_MN_ENABLE_COLLECTION 0x06
856 #define IRP_MN_DISABLE_COLLECTION 0x07
857 #define IRP_MN_REGINFO 0x08
858 #define IRP_MN_EXECUTE_METHOD 0x09
859 #define IRP_MN_REGINFO_EX 0x0b
861 /* IRP flags */
863 #define IRP_NOCACHE 0x00000001
864 #define IRP_PAGING_IO 0x00000002
865 #define IRP_MOUNT_COMPLETION 0x00000002
866 #define IRP_SYNCHRONOUS_API 0x00000004
867 #define IRP_ASSOCIATED_IRP 0x00000008
868 #define IRP_BUFFERED_IO 0x00000010
869 #define IRP_DEALLOCATE_BUFFER 0x00000020
870 #define IRP_INPUT_OPERATION 0x00000040
871 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
872 #define IRP_CREATE_OPERATION 0x00000080
873 #define IRP_READ_OPERATION 0x00000100
874 #define IRP_WRITE_OPERATION 0x00000200
875 #define IRP_CLOSE_OPERATION 0x00000400
876 #define IRP_DEFER_IO_COMPLETION 0x00000800
877 #define IRP_OB_QUERY_NAME 0x00001000
878 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
879 #define IRP_RETRY_IO_COMPLETION 0x00004000
880 #define IRP_CLASS_CACHE_OPERATION 0x00008000
881 #define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION
883 /* IRP I/O control flags */
885 #define IRP_QUOTA_CHARGED 0x01
886 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
887 #define IRP_ALLOCATED_FIXED_SIZE 0x04
888 #define IRP_LOOKASIDE_ALLOCATION 0x08
890 /* I/O method types */
892 #define METHOD_BUFFERED 0
893 #define METHOD_IN_DIRECT 1
894 #define METHOD_OUT_DIRECT 2
895 #define METHOD_NEITHER 3
897 /* File access types */
899 #define FILE_ANY_ACCESS 0x0000
900 #define FILE_SPECIAL_ACCESS FILE_ANY_ACCESS
901 #define FILE_READ_ACCESS 0x0001
902 #define FILE_WRITE_ACCESS 0x0002
904 /* Recover I/O access method from IOCTL code. */
906 #define IO_METHOD(x) ((x) & 0xFFFFFFFC)
908 /* Recover function code from IOCTL code */
910 #define IO_FUNC(x) (((x) & 0x7FFC) >> 2)
912 /* Macro to construct an IOCTL code. */
914 #define IOCTL_CODE(dev, func, iomethod, acc) \
915 ((dev) << 16) | (acc << 14) | (func << 2) | (iomethod))
918 struct io_status_block {
919 union {
920 uint32_t isb_status;
921 void *isb_ptr;
922 } u;
923 register_t isb_info;
925 #define isb_status u.isb_status
926 #define isb_ptr u.isb_ptr
928 typedef struct io_status_block io_status_block;
930 struct kapc {
931 uint16_t apc_type;
932 uint16_t apc_size;
933 uint32_t apc_spare0;
934 void *apc_thread;
935 list_entry apc_list;
936 void *apc_kernfunc;
937 void *apc_rundownfunc;
938 void *apc_normalfunc;
939 void *apc_normctx;
940 void *apc_sysarg1;
941 void *apc_sysarg2;
942 uint8_t apc_stateidx;
943 uint8_t apc_cpumode;
944 uint8_t apc_inserted;
947 typedef struct kapc kapc;
949 typedef uint32_t (*completion_func)(device_object *,
950 struct irp *, void *);
951 typedef uint32_t (*cancel_func)(device_object *,
952 struct irp *);
954 struct io_stack_location {
955 uint8_t isl_major;
956 uint8_t isl_minor;
957 uint8_t isl_flags;
958 uint8_t isl_ctl;
961 * There's a big-ass union here in the actual Windows
962 * definition of the stucture, but it contains stuff
963 * that doesn't really apply to BSD, and defining it
964 * all properly would require duplicating over a dozen
965 * other structures that we'll never use. Since the
966 * io_stack_location structure is opaque to drivers
967 * anyway, I'm not going to bother with the extra crap.
970 union {
971 struct {
972 uint32_t isl_len;
973 uint32_t *isl_key;
974 uint64_t isl_byteoff;
975 } isl_read;
976 struct {
977 uint32_t isl_len;
978 uint32_t *isl_key;
979 uint64_t isl_byteoff;
980 } isl_write;
981 struct {
982 uint32_t isl_obuflen;
983 uint32_t isl_ibuflen;
984 uint32_t isl_iocode;
985 void *isl_type3ibuf;
986 } isl_ioctl;
987 struct {
988 void *isl_arg1;
989 void *isl_arg2;
990 void *isl_arg3;
991 void *isl_arg4;
992 } isl_others;
993 } isl_parameters __attribute__((packed));
995 void *isl_devobj;
996 void *isl_fileobj;
997 completion_func isl_completionfunc;
998 void *isl_completionctx;
1001 typedef struct io_stack_location io_stack_location;
1003 /* Stack location control flags */
1005 #define SL_PENDING_RETURNED 0x01
1006 #define SL_INVOKE_ON_CANCEL 0x20
1007 #define SL_INVOKE_ON_SUCCESS 0x40
1008 #define SL_INVOKE_ON_ERROR 0x80
1010 struct irp {
1011 uint16_t irp_type;
1012 uint16_t irp_size;
1013 mdl *irp_mdl;
1014 uint32_t irp_flags;
1015 union {
1016 struct irp *irp_master;
1017 uint32_t irp_irpcnt;
1018 void *irp_sysbuf;
1019 } irp_assoc;
1020 list_entry irp_thlist;
1021 io_status_block irp_iostat;
1022 uint8_t irp_reqmode;
1023 uint8_t irp_pendingreturned;
1024 uint8_t irp_stackcnt;
1025 uint8_t irp_currentstackloc;
1026 uint8_t irp_cancel;
1027 uint8_t irp_cancelirql;
1028 uint8_t irp_apcenv;
1029 uint8_t irp_allocflags;
1030 io_status_block *irp_usriostat;
1031 nt_kevent *irp_usrevent;
1032 union {
1033 struct {
1034 void *irp_apcfunc;
1035 void *irp_apcctx;
1036 } irp_asyncparms;
1037 uint64_t irp_allocsz;
1038 } irp_overlay;
1039 cancel_func irp_cancelfunc;
1040 void *irp_userbuf;
1042 /* Windows kernel info */
1044 union {
1045 struct {
1046 union {
1047 kdevice_qentry irp_dqe;
1048 struct {
1049 void *irp_drvctx[4];
1050 } s1;
1051 } u1;
1052 void *irp_thread;
1053 char *irp_auxbuf;
1054 struct {
1055 list_entry irp_list;
1056 union {
1057 io_stack_location *irp_csl;
1058 uint32_t irp_pkttype;
1059 } u2;
1060 } s2;
1061 void *irp_fileobj;
1062 } irp_overlay;
1063 union {
1064 kapc irp_apc;
1065 struct {
1066 void *irp_ep;
1067 void *irp_dev;
1068 } irp_usb;
1069 } irp_misc;
1070 void *irp_compkey;
1071 } irp_tail;
1074 #define irp_csl s2.u2.irp_csl
1075 #define irp_pkttype s2.u2.irp_pkttype
1077 #define IRP_NDIS_DEV(irp) (irp)->irp_tail.irp_misc.irp_usb.irp_dev
1078 #define IRP_NDISUSB_EP(irp) (irp)->irp_tail.irp_misc.irp_usb.irp_ep
1080 typedef struct irp irp;
1082 #define InterlockedExchangePointer(dst, val) \
1083 (void *)InterlockedExchange((uint32_t *)(dst), (uintptr_t)(val))
1085 #define IoSizeOfIrp(ssize) \
1086 ((uint16_t) (sizeof(irp) + ((ssize) * (sizeof(io_stack_location)))))
1088 #define IoSetCancelRoutine(irp, func) \
1089 (cancel_func)InterlockedExchangePointer( \
1090 (void *)&(ip)->irp_cancelfunc, (void *)(func))
1092 #define IoSetCancelValue(irp, val) \
1093 (u_long)InterlockedExchangePointer( \
1094 (void *)&(ip)->irp_cancel, (void *)(val))
1096 #define IoGetCurrentIrpStackLocation(irp) \
1097 (irp)->irp_tail.irp_overlay.irp_csl
1099 #define IoGetNextIrpStackLocation(irp) \
1100 ((irp)->irp_tail.irp_overlay.irp_csl - 1)
1102 #define IoSetNextIrpStackLocation(irp) \
1103 do { \
1104 irp->irp_currentstackloc--; \
1105 irp->irp_tail.irp_overlay.irp_csl--; \
1106 } while(0)
1108 #define IoSetCompletionRoutine(irp, func, ctx, ok, err, cancel) \
1109 do { \
1110 io_stack_location *s; \
1111 s = IoGetNextIrpStackLocation((irp)); \
1112 s->isl_completionfunc = (func); \
1113 s->isl_completionctx = (ctx); \
1114 s->isl_ctl = 0; \
1115 if (ok) s->isl_ctl = SL_INVOKE_ON_SUCCESS; \
1116 if (err) s->isl_ctl |= SL_INVOKE_ON_ERROR; \
1117 if (cancel) s->isl_ctl |= SL_INVOKE_ON_CANCEL; \
1118 } while(0)
1120 #define IoMarkIrpPending(irp) \
1121 IoGetCurrentIrpStackLocation(irp)->isl_ctl |= SL_PENDING_RETURNED
1122 #define IoUnmarkIrpPending(irp) \
1123 IoGetCurrentIrpStackLocation(irp)->isl_ctl &= ~SL_PENDING_RETURNED
1125 #define IoCopyCurrentIrpStackLocationToNext(irp) \
1126 do { \
1127 io_stack_location *src, *dst; \
1128 src = IoGetCurrentIrpStackLocation(irp); \
1129 dst = IoGetNextIrpStackLocation(irp); \
1130 bcopy((char *)src, (char *)dst, \
1131 offsetof(io_stack_location, isl_completionfunc)); \
1132 } while(0)
1134 #define IoSkipCurrentIrpStackLocation(irp) \
1135 do { \
1136 (irp)->irp_currentstackloc++; \
1137 (irp)->irp_tail.irp_overlay.irp_csl++; \
1138 } while(0)
1140 #define IoInitializeDpcRequest(dobj, dpcfunc) \
1141 KeInitializeDpc(&(dobj)->do_dpc, dpcfunc, dobj)
1143 #define IoRequestDpc(dobj, irp, ctx) \
1144 KeInsertQueueDpc(&(dobj)->do_dpc, irp, ctx)
1146 typedef uint32_t (*driver_dispatch)(device_object *, irp *);
1149 * The driver_object is allocated once for each driver that's loaded
1150 * into the system. A new one is allocated for each driver and
1151 * populated a bit via the driver's DriverEntry function.
1152 * In general, a Windows DriverEntry() function will provide a pointer
1153 * to its AddDevice() method and set up the dispatch table.
1154 * For NDIS drivers, this is all done behind the scenes in the
1155 * NdisInitializeWrapper() and/or NdisMRegisterMiniport() routines.
1158 struct driver_object {
1159 uint16_t dro_type;
1160 uint16_t dro_size;
1161 device_object *dro_devobj;
1162 uint32_t dro_flags;
1163 void *dro_driverstart;
1164 uint32_t dro_driversize;
1165 void *dro_driversection;
1166 driver_extension *dro_driverext;
1167 unicode_string dro_drivername;
1168 unicode_string *dro_hwdb;
1169 void *dro_pfastiodispatch;
1170 void *dro_driverinitfunc;
1171 void *dro_driverstartiofunc;
1172 void *dro_driverunloadfunc;
1173 driver_dispatch dro_dispatch[IRP_MJ_MAXIMUM_FUNCTION + 1];
1176 typedef struct driver_object driver_object;
1178 #define DEVPROP_DEVICE_DESCRIPTION 0x00000000
1179 #define DEVPROP_HARDWARE_ID 0x00000001
1180 #define DEVPROP_COMPATIBLE_IDS 0x00000002
1181 #define DEVPROP_BOOTCONF 0x00000003
1182 #define DEVPROP_BOOTCONF_TRANSLATED 0x00000004
1183 #define DEVPROP_CLASS_NAME 0x00000005
1184 #define DEVPROP_CLASS_GUID 0x00000006
1185 #define DEVPROP_DRIVER_KEYNAME 0x00000007
1186 #define DEVPROP_MANUFACTURER 0x00000008
1187 #define DEVPROP_FRIENDLYNAME 0x00000009
1188 #define DEVPROP_LOCATION_INFO 0x0000000A
1189 #define DEVPROP_PHYSDEV_NAME 0x0000000B
1190 #define DEVPROP_BUSTYPE_GUID 0x0000000C
1191 #define DEVPROP_LEGACY_BUSTYPE 0x0000000D
1192 #define DEVPROP_BUS_NUMBER 0x0000000E
1193 #define DEVPROP_ENUMERATOR_NAME 0x0000000F
1194 #define DEVPROP_ADDRESS 0x00000010
1195 #define DEVPROP_UINUMBER 0x00000011
1196 #define DEVPROP_INSTALL_STATE 0x00000012
1197 #define DEVPROP_REMOVAL_POLICY 0x00000013
1199 /* Various supported device types (used with IoCreateDevice()) */
1201 #define FILE_DEVICE_BEEP 0x00000001
1202 #define FILE_DEVICE_CD_ROM 0x00000002
1203 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
1204 #define FILE_DEVICE_CONTROLLER 0x00000004
1205 #define FILE_DEVICE_DATALINK 0x00000005
1206 #define FILE_DEVICE_DFS 0x00000006
1207 #define FILE_DEVICE_DISK 0x00000007
1208 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
1209 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
1210 #define FILE_DEVICE_INPORT_PORT 0x0000000A
1211 #define FILE_DEVICE_KEYBOARD 0x0000000B
1212 #define FILE_DEVICE_MAILSLOT 0x0000000C
1213 #define FILE_DEVICE_MIDI_IN 0x0000000D
1214 #define FILE_DEVICE_MIDI_OUT 0x0000000E
1215 #define FILE_DEVICE_MOUSE 0x0000000F
1216 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
1217 #define FILE_DEVICE_NAMED_PIPE 0x00000011
1218 #define FILE_DEVICE_NETWORK 0x00000012
1219 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
1220 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
1221 #define FILE_DEVICE_NULL 0x00000015
1222 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
1223 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
1224 #define FILE_DEVICE_PRINTER 0x00000018
1225 #define FILE_DEVICE_SCANNER 0x00000019
1226 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001A
1227 #define FILE_DEVICE_SERIAL_PORT 0x0000001B
1228 #define FILE_DEVICE_SCREEN 0x0000001C
1229 #define FILE_DEVICE_SOUND 0x0000001D
1230 #define FILE_DEVICE_STREAMS 0x0000001E
1231 #define FILE_DEVICE_TAPE 0x0000001F
1232 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
1233 #define FILE_DEVICE_TRANSPORT 0x00000021
1234 #define FILE_DEVICE_UNKNOWN 0x00000022
1235 #define FILE_DEVICE_VIDEO 0x00000023
1236 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
1237 #define FILE_DEVICE_WAVE_IN 0x00000025
1238 #define FILE_DEVICE_WAVE_OUT 0x00000026
1239 #define FILE_DEVICE_8042_PORT 0x00000027
1240 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
1241 #define FILE_DEVICE_BATTERY 0x00000029
1242 #define FILE_DEVICE_BUS_EXTENDER 0x0000002A
1243 #define FILE_DEVICE_MODEM 0x0000002B
1244 #define FILE_DEVICE_VDM 0x0000002C
1245 #define FILE_DEVICE_MASS_STORAGE 0x0000002D
1246 #define FILE_DEVICE_SMB 0x0000002E
1247 #define FILE_DEVICE_KS 0x0000002F
1248 #define FILE_DEVICE_CHANGER 0x00000030
1249 #define FILE_DEVICE_SMARTCARD 0x00000031
1250 #define FILE_DEVICE_ACPI 0x00000032
1251 #define FILE_DEVICE_DVD 0x00000033
1252 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
1253 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
1254 #define FILE_DEVICE_DFS_VOLUME 0x00000036
1255 #define FILE_DEVICE_SERENUM 0x00000037
1256 #define FILE_DEVICE_TERMSRV 0x00000038
1257 #define FILE_DEVICE_KSEC 0x00000039
1258 #define FILE_DEVICE_FIPS 0x0000003A
1260 /* Device characteristics */
1262 #define FILE_REMOVABLE_MEDIA 0x00000001
1263 #define FILE_READ_ONLY_DEVICE 0x00000002
1264 #define FILE_FLOPPY_DISKETTE 0x00000004
1265 #define FILE_WRITE_ONCE_MEDIA 0x00000008
1266 #define FILE_REMOTE_DEVICE 0x00000010
1267 #define FILE_DEVICE_IS_MOUNTED 0x00000020
1268 #define FILE_VIRTUAL_VOLUME 0x00000040
1269 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
1270 #define FILE_DEVICE_SECURE_OPEN 0x00000100
1272 /* Status codes */
1274 #define STATUS_SUCCESS 0x00000000
1275 #define STATUS_USER_APC 0x000000C0
1276 #define STATUS_KERNEL_APC 0x00000100
1277 #define STATUS_ALERTED 0x00000101
1278 #define STATUS_TIMEOUT 0x00000102
1279 #define STATUS_PENDING 0x00000103
1280 #define STATUS_FAILURE 0xC0000001
1281 #define STATUS_NOT_IMPLEMENTED 0xC0000002
1282 #define STATUS_ACCESS_VIOLATION 0xC0000005
1283 #define STATUS_INVALID_PARAMETER 0xC000000D
1284 #define STATUS_INVALID_DEVICE_REQUEST 0xC0000010
1285 #define STATUS_MORE_PROCESSING_REQUIRED 0xC0000016
1286 #define STATUS_NO_MEMORY 0xC0000017
1287 #define STATUS_BUFFER_TOO_SMALL 0xC0000023
1288 #define STATUS_MUTANT_NOT_OWNED 0xC0000046
1289 #define STATUS_NOT_SUPPORTED 0xC00000BB
1290 #define STATUS_INVALID_PARAMETER_2 0xC00000F0
1291 #define STATUS_INSUFFICIENT_RESOURCES 0xC000009A
1292 #define STATUS_DEVICE_NOT_CONNECTED 0xC000009D
1293 #define STATUS_CANCELLED 0xC0000120
1294 #define STATUS_NOT_FOUND 0xC0000225
1295 #define STATUS_DEVICE_REMOVED 0xC00002B6
1297 #define STATUS_WAIT_0 0x00000000
1299 /* Memory pool types, for ExAllocatePoolWithTag() */
1301 #define NonPagedPool 0x00000000
1302 #define PagedPool 0x00000001
1303 #define NonPagedPoolMustSucceed 0x00000002
1304 #define DontUseThisType 0x00000003
1305 #define NonPagedPoolCacheAligned 0x00000004
1306 #define PagedPoolCacheAligned 0x00000005
1307 #define NonPagedPoolCacheAlignedMustS 0x00000006
1308 #define MaxPoolType 0x00000007
1311 * IO_WORKITEM is an opaque structures that must be allocated
1312 * via IoAllocateWorkItem() and released via IoFreeWorkItem().
1313 * Consequently, we can define it any way we want.
1315 typedef void (*io_workitem_func)(device_object *, void *);
1317 struct io_workitem {
1318 io_workitem_func iw_func;
1319 void *iw_ctx;
1320 list_entry iw_listentry;
1321 device_object *iw_dobj;
1322 int iw_idx;
1325 typedef struct io_workitem io_workitem;
1327 #define WORKQUEUE_CRITICAL 0
1328 #define WORKQUEUE_DELAYED 1
1329 #define WORKQUEUE_HYPERCRITICAL 2
1331 #define WORKITEM_THREADS 4
1332 #define WORKITEM_LEGACY_THREAD 3
1333 #define WORKIDX_INC(x) (x) = (x + 1) % WORKITEM_LEGACY_THREAD
1336 * Older, deprecated work item API, needed to support NdisQueueWorkItem().
1339 struct work_queue_item;
1341 typedef void (*work_item_func)(struct work_queue_item *, void *);
1343 struct work_queue_item {
1344 list_entry wqi_entry;
1345 work_item_func wqi_func;
1346 void *wqi_ctx;
1349 typedef struct work_queue_item work_queue_item;
1351 #define ExInitializeWorkItem(w, func, ctx) \
1352 do { \
1353 (w)->wqi_func = (func); \
1354 (w)->wqi_ctx = (ctx); \
1355 InitializeListHead(&((w)->wqi_entry)); \
1356 } while (0)
1359 * FreeBSD's kernel stack is 2 pages in size by default. The
1360 * Windows stack is larger, so we need to give our threads more
1361 * stack pages. 4 should be enough, we use 8 just to extra safe.
1363 #define NDIS_KSTACK_PAGES 8
1366 * Different kinds of function wrapping we can do.
1369 #define WINDRV_WRAP_STDCALL 1
1370 #define WINDRV_WRAP_FASTCALL 2
1371 #define WINDRV_WRAP_REGPARM 3
1372 #define WINDRV_WRAP_CDECL 4
1373 #define WINDRV_WRAP_AMD64 5
1375 struct drvdb_ent {
1376 driver_object *windrv_object;
1377 void *windrv_devlist;
1378 ndis_cfg *windrv_regvals;
1379 interface_type windrv_bustype;
1380 STAILQ_ENTRY(drvdb_ent) link;
1383 extern image_patch_table ntoskrnl_functbl[];
1384 #ifdef __x86_64__
1385 extern struct kuser_shared_data kuser_shared_data;
1386 #endif
1387 typedef void (*funcptr)(void);
1388 typedef int (*matchfuncptr)(interface_type, void *, void *);
1390 __BEGIN_DECLS
1391 extern int windrv_libinit(void);
1392 extern int windrv_libfini(void);
1393 extern driver_object *windrv_lookup(vm_offset_t, char *);
1394 extern struct drvdb_ent *windrv_match(matchfuncptr, void *);
1395 extern int windrv_load(module_t, vm_offset_t, int, interface_type,
1396 void *, ndis_cfg *);
1397 extern int windrv_unload(module_t, vm_offset_t, int);
1398 extern int windrv_create_pdo(driver_object *, device_t);
1399 extern void windrv_destroy_pdo(driver_object *, device_t);
1400 extern device_object *windrv_find_pdo(driver_object *, device_t);
1401 extern int windrv_bus_attach(driver_object *, char *);
1402 extern int windrv_wrap(funcptr, funcptr *, int, int);
1403 extern int windrv_unwrap(funcptr);
1404 extern void ctxsw_utow(void);
1405 extern void ctxsw_wtou(void);
1407 extern int ntoskrnl_libinit(void);
1408 extern int ntoskrnl_libfini(void);
1410 extern void ntoskrnl_intr(void *);
1411 extern void ntoskrnl_time(uint64_t *);
1413 extern uint16_t ExQueryDepthSList(slist_header *);
1414 extern slist_entry
1415 *InterlockedPushEntrySList(slist_header *, slist_entry *);
1416 extern slist_entry *InterlockedPopEntrySList(slist_header *);
1417 extern uint32_t RtlUnicodeStringToAnsiString(ansi_string *,
1418 unicode_string *, uint8_t);
1419 extern uint32_t RtlAnsiStringToUnicodeString(unicode_string *,
1420 ansi_string *, uint8_t);
1421 extern void RtlInitAnsiString(ansi_string *, char *);
1422 extern void RtlInitUnicodeString(unicode_string *,
1423 uint16_t *);
1424 extern void RtlFreeUnicodeString(unicode_string *);
1425 extern void RtlFreeAnsiString(ansi_string *);
1426 extern void KeInitializeDpc(kdpc *, void *, void *);
1427 extern uint8_t KeInsertQueueDpc(kdpc *, void *, void *);
1428 extern uint8_t KeRemoveQueueDpc(kdpc *);
1429 extern void KeSetImportanceDpc(kdpc *, uint32_t);
1430 extern void KeSetTargetProcessorDpc(kdpc *, uint8_t);
1431 extern void KeFlushQueuedDpcs(void);
1432 extern uint32_t KeGetCurrentProcessorNumber(void);
1433 extern void KeInitializeTimer(ktimer *);
1434 extern void KeInitializeTimerEx(ktimer *, uint32_t);
1435 extern uint8_t KeSetTimer(ktimer *, int64_t, kdpc *);
1436 extern uint8_t KeSetTimerEx(ktimer *, int64_t, uint32_t, kdpc *);
1437 extern uint8_t KeCancelTimer(ktimer *);
1438 extern uint8_t KeReadStateTimer(ktimer *);
1439 extern uint32_t KeWaitForSingleObject(void *, uint32_t,
1440 uint32_t, uint8_t, int64_t *);
1441 extern void KeInitializeEvent(nt_kevent *, uint32_t, uint8_t);
1442 extern void KeClearEvent(nt_kevent *);
1443 extern uint32_t KeReadStateEvent(nt_kevent *);
1444 extern uint32_t KeSetEvent(nt_kevent *, uint32_t, uint8_t);
1445 extern uint32_t KeResetEvent(nt_kevent *);
1446 extern void KeAcquireSpinLockAtDpcLevel(kspin_lock *);
1447 extern void KeReleaseSpinLockFromDpcLevel(kspin_lock *);
1448 extern void KeInitializeSpinLock(kspin_lock *);
1449 extern uint8_t KeAcquireInterruptSpinLock(kinterrupt *);
1450 extern void KeReleaseInterruptSpinLock(kinterrupt *, uint8_t);
1451 extern uint8_t KeSynchronizeExecution(kinterrupt *, void *, void *);
1452 extern uintptr_t InterlockedExchange(volatile uint32_t *,
1453 uintptr_t);
1454 extern void *ExAllocatePoolWithTag(uint32_t, size_t, uint32_t);
1455 extern void ExFreePool(void *);
1456 extern uint32_t IoConnectInterrupt(kinterrupt **, void *, void *,
1457 kspin_lock *, uint32_t, uint8_t, uint8_t, uint8_t, uint8_t,
1458 uint32_t, uint8_t);
1459 extern uint8_t MmIsAddressValid(void *);
1460 extern void *MmGetSystemRoutineAddress(unicode_string *);
1461 extern void *MmMapIoSpace(uint64_t, uint32_t, uint32_t);
1462 extern void MmUnmapIoSpace(void *, size_t);
1463 extern void MmBuildMdlForNonPagedPool(mdl *);
1464 extern void IoDisconnectInterrupt(kinterrupt *);
1465 extern uint32_t IoAllocateDriverObjectExtension(driver_object *,
1466 void *, uint32_t, void **);
1467 extern void *IoGetDriverObjectExtension(driver_object *, void *);
1468 extern uint32_t IoCreateDevice(driver_object *, uint32_t,
1469 unicode_string *, uint32_t, uint32_t, uint8_t, device_object **);
1470 extern void IoDeleteDevice(device_object *);
1471 extern device_object *IoGetAttachedDevice(device_object *);
1472 extern uint32_t IofCallDriver(device_object *, irp *);
1473 extern void IofCompleteRequest(irp *, uint8_t);
1474 extern void IoAcquireCancelSpinLock(uint8_t *);
1475 extern void IoReleaseCancelSpinLock(uint8_t);
1476 extern uint8_t IoCancelIrp(irp *);
1477 extern void IoDetachDevice(device_object *);
1478 extern device_object *IoAttachDeviceToDeviceStack(device_object *,
1479 device_object *);
1480 extern mdl *IoAllocateMdl(void *, uint32_t, uint8_t, uint8_t, irp *);
1481 extern void IoFreeMdl(mdl *);
1482 extern io_workitem *IoAllocateWorkItem(device_object *);
1483 extern void ExQueueWorkItem(work_queue_item *, u_int32_t);
1484 extern void IoFreeWorkItem(io_workitem *);
1485 extern void IoQueueWorkItem(io_workitem *, io_workitem_func,
1486 uint32_t, void *);
1488 #define IoCallDriver(a, b) IofCallDriver(a, b)
1489 #define IoCompleteRequest(a, b) IofCompleteRequest(a, b)
1492 * On the Windows x86 arch, KeAcquireSpinLock() and KeReleaseSpinLock()
1493 * routines live in the HAL. We try to imitate this behavior.
1495 #ifdef __x86_64__
1496 #define KI_USER_SHARED_DATA 0xfffff78000000000UL
1497 #define KeAcquireSpinLock(a, b) *(b) = KfAcquireSpinLock(a)
1498 #define KeReleaseSpinLock(a, b) KfReleaseSpinLock(a, b)
1501 * These may need to be redefined later;
1502 * not sure where they live on amd64 yet.
1504 #define KeRaiseIrql(a, b) *(b) = KfRaiseIrql(a)
1505 #define KeLowerIrql(a) KfLowerIrql(a)
1506 #endif /* __x86_64__ */
1508 __END_DECLS
1510 #endif /* _NTOSKRNL_VAR_H_ */