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
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.
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 {
51 typedef struct unicode_string unicode_string;
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
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
89 void *mdl_mappedsystemva;
91 uint32_t mdl_bytecount;
92 uint32_t mdl_byteoffset;
95 typedef struct mdl mdl, ndis_buffer;
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. */
121 #if PAGE_SIZE == 4096
122 #define PAGE_SHIFT 12
123 #elif PAGE_SIZE == 8192
124 #define PAGE_SHIFT 13
126 #error PAGE_SHIFT undefined!
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)
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
166 * The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows.
167 * According to the Windows DDK header files, KSPIN_LOCK is defined like this:
168 * typedef ULONG_PTR KSPIN_LOCK;
170 * From basetsd.h (SDK, Feb. 2003):
171 * typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
172 * typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
173 * typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
175 * The keyword __int3264 specifies an integral type that has the following
177 * + It is 32-bit on 32-bit platforms
178 * + It is 64-bit on 64-bit platforms
179 * + It is 32-bit on the wire for backward compatibility.
180 * It gets truncated on the sending side and extended appropriately
181 * (signed or unsigned) on the receiving side.
183 * Thus register_t seems the proper mapping onto FreeBSD for spin locks.
186 typedef register_t kspin_lock;
189 struct slist_entry *sl_next;
192 typedef struct slist_entry slist_entry;
197 struct slist_entry *slh_next;
203 typedef union slist_header slist_header;
206 struct list_entry *nle_flink;
207 struct list_entry *nle_blink;
210 typedef struct list_entry list_entry;
212 #define InitializeListHead(l) \
213 (l)->nle_flink = (l)->nle_blink = (l)
215 #define IsListEmpty(h) \
216 ((h)->nle_flink == (h))
218 #define RemoveEntryList(e) \
223 f = (e)->nle_flink; \
224 b = (e)->nle_blink; \
229 /* These two have to be inlined since they return things. */
231 static __inline__ list_entry *
232 RemoveHeadList(list_entry *l)
245 static __inline__ list_entry *
246 RemoveTailList(list_entry *l)
259 #define InsertTailList(l, e) \
266 b->nle_flink = (e); \
267 l->nle_blink = (e); \
270 #define InsertHeadList(l, e) \
281 #define CONTAINING_RECORD(addr, type, field) \
282 ((type *)((vm_offset_t)(addr) - (vm_offset_t)(&((type *)0)->field)))
284 struct nt_dispatch_header {
290 list_entry dh_waitlisthead;
293 typedef struct nt_dispatch_header nt_dispatch_header;
295 /* Dispatcher object types */
297 #define DISP_TYPE_NOTIFICATION_EVENT 0 /* KEVENT */
298 #define DISP_TYPE_SYNCHRONIZATION_EVENT 1 /* KEVENT */
299 #define DISP_TYPE_MUTANT 2 /* KMUTANT/KMUTEX */
300 #define DISP_TYPE_PROCESS 3 /* KPROCESS */
301 #define DISP_TYPE_QUEUE 4 /* KQUEUE */
302 #define DISP_TYPE_SEMAPHORE 5 /* KSEMAPHORE */
303 #define DISP_TYPE_THREAD 6 /* KTHREAD */
304 #define DISP_TYPE_NOTIFICATION_TIMER 8 /* KTIMER */
305 #define DISP_TYPE_SYNCHRONIZATION_TIMER 9 /* KTIMER */
307 #define OTYPE_EVENT 0
308 #define OTYPE_MUTEX 1
309 #define OTYPE_THREAD 2
310 #define OTYPE_TIMER 3
312 /* Windows dispatcher levels. */
314 #define PASSIVE_LEVEL 0
317 #define DISPATCH_LEVEL 2
318 #define DEVICE_LEVEL (DISPATCH_LEVEL + 1)
319 #define PROFILE_LEVEL 27
320 #define CLOCK1_LEVEL 28
321 #define CLOCK2_LEVEL 28
323 #define POWER_LEVEL 30
324 #define HIGH_LEVEL 31
326 #define SYNC_LEVEL_UP DISPATCH_LEVEL
327 #define SYNC_LEVEL_MP (IPI_LEVEL - 1)
329 #define AT_PASSIVE_LEVEL(td) \
330 ((td)->td_proc->p_flag & P_KTHREAD == FALSE)
332 #define AT_DISPATCH_LEVEL(td) \
333 ((td)->td_base_pri == PI_REALTIME)
335 #define AT_DIRQL_LEVEL(td) \
336 ((td)->td_priority <= PI_NET)
338 #define AT_HIGH_LEVEL(td) \
339 ((td)->td_critnest != 0)
342 nt_dispatch_header no_dh;
344 TAILQ_ENTRY(nt_objref) link;
347 TAILQ_HEAD(nt_objref_head, nt_objref);
349 typedef struct nt_objref nt_objref;
351 #define EVENT_TYPE_NOTIFY 0
352 #define EVENT_TYPE_SYNC 1
355 * We need to use the timeout()/untimeout() API for ktimers
356 * since timers can be initialized, but not destroyed (so
357 * malloc()ing our own callout structures would mean a leak,
358 * since there'd be no way to free() them). This means we
359 * need to use struct callout_handle, which is really just a
360 * pointer. To make it easier to deal with, we use a union
361 * to overlay the callout_handle over the k_timerlistentry.
362 * The latter is a list_entry, which is two pointers, so
363 * there's enough space available to hide a callout_handle
368 nt_dispatch_header k_header;
371 list_entry k_timerlistentry;
372 struct callout *k_callout;
378 #define k_timerlistentry u.k_timerlistentry
379 #define k_callout u.k_callout
381 typedef struct ktimer ktimer;
384 nt_dispatch_header k_header;
387 typedef struct nt_kevent nt_kevent;
389 /* Kernel defered procedure call (i.e. timer callback) */
392 typedef void (*kdpc_func)(struct kdpc *, void *, void *, void *);
396 uint8_t k_num; /* CPU number */
397 uint8_t k_importance; /* priority */
398 list_entry k_dpclistentry;
406 #define KDPC_IMPORTANCE_LOW 0
407 #define KDPC_IMPORTANCE_MEDIUM 1
408 #define KDPC_IMPORTANCE_HIGH 2
410 #define KDPC_CPU_DEFAULT 255
412 typedef struct kdpc kdpc;
415 * Note: the acquisition count is BSD-specific. The Microsoft
416 * documentation says that mutexes can be acquired recursively
417 * by a given thread, but that you must release the mutex as
418 * many times as you acquired it before it will be set to the
419 * signalled state (i.e. before any other threads waiting on
420 * the object will be woken up). However the Windows KMUTANT
421 * structure has no field for keeping track of the number of
422 * acquisitions, so we need to add one ourselves. As long as
423 * driver code treats the mutex as opaque, we should be ok.
426 nt_dispatch_header km_header;
427 list_entry km_listentry;
428 void *km_ownerthread;
429 uint8_t km_abandoned;
430 uint8_t km_apcdisable;
433 typedef struct kmutant kmutant;
435 #define LOOKASIDE_DEPTH 256
437 struct general_lookaside {
438 slist_header gl_listhead;
440 uint16_t gl_maxdepth;
441 uint32_t gl_totallocs;
443 uint32_t gl_allocmisses;
444 uint32_t gl_allochits;
446 uint32_t gl_totalfrees;
448 uint32_t gl_freemisses;
449 uint32_t gl_freehits;
456 list_entry gl_listent;
457 uint32_t gl_lasttotallocs;
459 uint32_t gl_lastallocmisses;
460 uint32_t gl_lastallochits;
465 typedef struct general_lookaside general_lookaside;
467 struct npaged_lookaside_list {
468 general_lookaside nll_l;
470 kspin_lock nll_obsoletelock;
474 typedef struct npaged_lookaside_list npaged_lookaside_list;
475 typedef struct npaged_lookaside_list paged_lookaside_list;
477 typedef void * (*lookaside_alloc_func)(uint32_t, size_t, uint32_t);
478 typedef void (*lookaside_free_func)(void *);
482 struct kdevice_qentry {
483 list_entry kqe_devlistent;
484 uint32_t kqe_sortkey;
485 uint8_t kqe_inserted;
488 typedef struct kdevice_qentry kdevice_qentry;
490 struct kdevice_queue {
493 list_entry kq_devlisthead;
498 typedef struct kdevice_queue kdevice_queue;
500 struct wait_ctx_block {
501 kdevice_qentry wcb_waitqueue;
504 uint32_t wcb_mapregcnt;
507 void *wcb_bufchaindpc;
510 typedef struct wait_ctx_block wait_ctx_block;
513 list_entry wb_waitlist;
515 nt_dispatch_header *wb_object;
516 struct wait_block *wb_next;
519 uint16_t wb_waittype;
527 typedef struct wait_block wait_block;
529 #define wb_ext wb_kthread
531 #define THREAD_WAIT_OBJECTS 3
532 #define MAX_WAIT_OBJECTS 64
534 #define WAITTYPE_ALL 0
535 #define WAITTYPE_ANY 1
537 #define WAITKEY_VALID 0x8000
539 /* kthread priority */
540 #define LOW_PRIORITY 0
541 #define LOW_REALTIME_PRIORITY 16
542 #define HIGH_PRIORITY 31
544 struct thread_context {
549 typedef struct thread_context thread_context;
551 /* Forward declaration */
552 struct driver_object;
553 struct devobj_extension;
555 struct driver_extension {
556 struct driver_object *dre_driverobj;
557 void *dre_adddevicefunc;
558 uint32_t dre_reinitcnt;
559 unicode_string dre_srvname;
562 * Drivers are allowed to add one or more custom extensions
563 * to the driver object, but there's no special pointer
564 * for them. Hang them off here for now.
567 list_entry dre_usrext;
570 typedef struct driver_extension driver_extension;
572 struct custom_extension {
577 typedef struct custom_extension custom_extension;
580 * The KINTERRUPT structure in Windows is opaque to drivers.
581 * We define our own custom version with things we need.
589 struct resource *ki_irq;
590 kspin_lock ki_lock_priv;
596 typedef struct kinterrupt kinterrupt;
599 * In Windows, there are Physical Device Objects (PDOs) and
600 * Functional Device Objects (FDOs). Physical Device Objects are
601 * created and maintained by bus drivers. For example, the PCI
602 * bus driver might detect two PCI ethernet cards on a given
603 * bus. The PCI bus driver will then allocate two device_objects
604 * for its own internal bookeeping purposes. This is analagous
605 * to the device_t that the FreeBSD PCI code allocates and passes
606 * into each PCI driver's probe and attach routines.
608 * When an ethernet driver claims one of the ethernet cards
609 * on the bus, it will create its own device_object. This is
610 * the Functional Device Object. This object is analagous to the
611 * device-specific softc structure.
614 struct device_object {
618 struct driver_object *do_drvobj;
619 struct device_object *do_nextdev;
620 struct device_object *do_attacheddev;
621 struct irp *do_currirp;
624 uint32_t do_characteristics;
628 uint8_t do_stacksize;
630 list_entry do_listent;
631 wait_ctx_block do_wcb;
633 uint32_t do_alignreq;
634 kdevice_queue do_devqueue;
636 uint32_t do_activethreads;
637 void *do_securitydesc;
638 struct nt_kevent do_devlock;
639 uint16_t do_sectorsz;
641 struct devobj_extension *do_devobj_ext;
645 typedef struct device_object device_object;
647 struct devobj_extension {
650 device_object *dve_devobj;
653 typedef struct devobj_extension devobj_extension;
655 /* Device object flags */
657 #define DO_VERIFY_VOLUME 0x00000002
658 #define DO_BUFFERED_IO 0x00000004
659 #define DO_EXCLUSIVE 0x00000008
660 #define DO_DIRECT_IO 0x00000010
661 #define DO_MAP_IO_BUFFER 0x00000020
662 #define DO_DEVICE_HAS_NAME 0x00000040
663 #define DO_DEVICE_INITIALIZING 0x00000080
664 #define DO_SYSTEM_BOOT_PARTITION 0x00000100
665 #define DO_LONG_TERM_REQUESTS 0x00000200
666 #define DO_NEVER_LAST_DEVICE 0x00000400
667 #define DO_SHUTDOWN_REGISTERED 0x00000800
668 #define DO_BUS_ENUMERATED_DEVICE 0x00001000
669 #define DO_POWER_PAGABLE 0x00002000
670 #define DO_POWER_INRUSH 0x00004000
671 #define DO_LOW_PRIORITY_FILESYSTEM 0x00010000
673 /* Priority boosts */
675 #define IO_NO_INCREMENT 0
676 #define IO_CD_ROM_INCREMENT 1
677 #define IO_DISK_INCREMENT 1
678 #define IO_KEYBOARD_INCREMENT 6
679 #define IO_MAILSLOT_INCREMENT 2
680 #define IO_MOUSE_INCREMENT 6
681 #define IO_NAMED_PIPE_INCREMENT 2
682 #define IO_NETWORK_INCREMENT 2
683 #define IO_PARALLEL_INCREMENT 1
684 #define IO_SERIAL_INCREMENT 2
685 #define IO_SOUND_INCREMENT 8
686 #define IO_VIDEO_INCREMENT 1
688 /* IRP major codes */
690 #define IRP_MJ_CREATE 0x00
691 #define IRP_MJ_CREATE_NAMED_PIPE 0x01
692 #define IRP_MJ_CLOSE 0x02
693 #define IRP_MJ_READ 0x03
694 #define IRP_MJ_WRITE 0x04
695 #define IRP_MJ_QUERY_INFORMATION 0x05
696 #define IRP_MJ_SET_INFORMATION 0x06
697 #define IRP_MJ_QUERY_EA 0x07
698 #define IRP_MJ_SET_EA 0x08
699 #define IRP_MJ_FLUSH_BUFFERS 0x09
700 #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
701 #define IRP_MJ_SET_VOLUME_INFORMATION 0x0b
702 #define IRP_MJ_DIRECTORY_CONTROL 0x0c
703 #define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d
704 #define IRP_MJ_DEVICE_CONTROL 0x0e
705 #define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f
706 #define IRP_MJ_SHUTDOWN 0x10
707 #define IRP_MJ_LOCK_CONTROL 0x11
708 #define IRP_MJ_CLEANUP 0x12
709 #define IRP_MJ_CREATE_MAILSLOT 0x13
710 #define IRP_MJ_QUERY_SECURITY 0x14
711 #define IRP_MJ_SET_SECURITY 0x15
712 #define IRP_MJ_POWER 0x16
713 #define IRP_MJ_SYSTEM_CONTROL 0x17
714 #define IRP_MJ_DEVICE_CHANGE 0x18
715 #define IRP_MJ_QUERY_QUOTA 0x19
716 #define IRP_MJ_SET_QUOTA 0x1a
717 #define IRP_MJ_PNP 0x1b
718 #define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete....
719 #define IRP_MJ_MAXIMUM_FUNCTION 0x1b
720 #define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL
722 /* IRP minor codes */
724 #define IRP_MN_QUERY_DIRECTORY 0x01
725 #define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02
726 #define IRP_MN_USER_FS_REQUEST 0x00
728 #define IRP_MN_MOUNT_VOLUME 0x01
729 #define IRP_MN_VERIFY_VOLUME 0x02
730 #define IRP_MN_LOAD_FILE_SYSTEM 0x03
731 #define IRP_MN_TRACK_LINK 0x04
732 #define IRP_MN_KERNEL_CALL 0x04
734 #define IRP_MN_LOCK 0x01
735 #define IRP_MN_UNLOCK_SINGLE 0x02
736 #define IRP_MN_UNLOCK_ALL 0x03
737 #define IRP_MN_UNLOCK_ALL_BY_KEY 0x04
739 #define IRP_MN_NORMAL 0x00
740 #define IRP_MN_DPC 0x01
741 #define IRP_MN_MDL 0x02
742 #define IRP_MN_COMPLETE 0x04
743 #define IRP_MN_COMPRESSED 0x08
745 #define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC)
746 #define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL)
747 #define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC)
749 #define IRP_MN_SCSI_CLASS 0x01
751 #define IRP_MN_START_DEVICE 0x00
752 #define IRP_MN_QUERY_REMOVE_DEVICE 0x01
753 #define IRP_MN_REMOVE_DEVICE 0x02
754 #define IRP_MN_CANCEL_REMOVE_DEVICE 0x03
755 #define IRP_MN_STOP_DEVICE 0x04
756 #define IRP_MN_QUERY_STOP_DEVICE 0x05
757 #define IRP_MN_CANCEL_STOP_DEVICE 0x06
759 #define IRP_MN_QUERY_DEVICE_RELATIONS 0x07
760 #define IRP_MN_QUERY_INTERFACE 0x08
761 #define IRP_MN_QUERY_CAPABILITIES 0x09
762 #define IRP_MN_QUERY_RESOURCES 0x0A
763 #define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B
764 #define IRP_MN_QUERY_DEVICE_TEXT 0x0C
765 #define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D
767 #define IRP_MN_READ_CONFIG 0x0F
768 #define IRP_MN_WRITE_CONFIG 0x10
769 #define IRP_MN_EJECT 0x11
770 #define IRP_MN_SET_LOCK 0x12
771 #define IRP_MN_QUERY_ID 0x13
772 #define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14
773 #define IRP_MN_QUERY_BUS_INFORMATION 0x15
774 #define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16
775 #define IRP_MN_SURPRISE_REMOVAL 0x17
776 #define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18
778 #define IRP_MN_WAIT_WAKE 0x00
779 #define IRP_MN_POWER_SEQUENCE 0x01
780 #define IRP_MN_SET_POWER 0x02
781 #define IRP_MN_QUERY_POWER 0x03
783 #define IRP_MN_QUERY_ALL_DATA 0x00
784 #define IRP_MN_QUERY_SINGLE_INSTANCE 0x01
785 #define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02
786 #define IRP_MN_CHANGE_SINGLE_ITEM 0x03
787 #define IRP_MN_ENABLE_EVENTS 0x04
788 #define IRP_MN_DISABLE_EVENTS 0x05
789 #define IRP_MN_ENABLE_COLLECTION 0x06
790 #define IRP_MN_DISABLE_COLLECTION 0x07
791 #define IRP_MN_REGINFO 0x08
792 #define IRP_MN_EXECUTE_METHOD 0x09
793 #define IRP_MN_REGINFO_EX 0x0b
797 #define IRP_NOCACHE 0x00000001
798 #define IRP_PAGING_IO 0x00000002
799 #define IRP_MOUNT_COMPLETION 0x00000002
800 #define IRP_SYNCHRONOUS_API 0x00000004
801 #define IRP_ASSOCIATED_IRP 0x00000008
802 #define IRP_BUFFERED_IO 0x00000010
803 #define IRP_DEALLOCATE_BUFFER 0x00000020
804 #define IRP_INPUT_OPERATION 0x00000040
805 #define IRP_SYNCHRONOUS_PAGING_IO 0x00000040
806 #define IRP_CREATE_OPERATION 0x00000080
807 #define IRP_READ_OPERATION 0x00000100
808 #define IRP_WRITE_OPERATION 0x00000200
809 #define IRP_CLOSE_OPERATION 0x00000400
810 #define IRP_DEFER_IO_COMPLETION 0x00000800
811 #define IRP_OB_QUERY_NAME 0x00001000
812 #define IRP_HOLD_DEVICE_QUEUE 0x00002000
813 #define IRP_RETRY_IO_COMPLETION 0x00004000
814 #define IRP_CLASS_CACHE_OPERATION 0x00008000
815 #define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION
817 /* IRP I/O control flags */
819 #define IRP_QUOTA_CHARGED 0x01
820 #define IRP_ALLOCATED_MUST_SUCCEED 0x02
821 #define IRP_ALLOCATED_FIXED_SIZE 0x04
822 #define IRP_LOOKASIDE_ALLOCATION 0x08
824 /* I/O method types */
826 #define METHOD_BUFFERED 0
827 #define METHOD_IN_DIRECT 1
828 #define METHOD_OUT_DIRECT 2
829 #define METHOD_NEITHER 3
831 /* File access types */
833 #define FILE_ANY_ACCESS 0x0000
834 #define FILE_SPECIAL_ACCESS FILE_ANY_ACCESS
835 #define FILE_READ_ACCESS 0x0001
836 #define FILE_WRITE_ACCESS 0x0002
838 /* Recover I/O access method from IOCTL code. */
840 #define IO_METHOD(x) ((x) & 0xFFFFFFFC)
842 /* Recover function code from IOCTL code */
844 #define IO_FUNC(x) (((x) & 0x7FFC) >> 2)
846 /* Macro to construct an IOCTL code. */
848 #define IOCTL_CODE(dev, func, iomethod, acc) \
849 ((dev) << 16) | (acc << 14) | (func << 2) | (iomethod))
852 struct io_status_block {
859 #define isb_status u.isb_status
860 #define isb_ptr u.isb_ptr
862 typedef struct io_status_block io_status_block;
871 void *apc_rundownfunc;
872 void *apc_normalfunc;
876 uint8_t apc_stateidx;
878 uint8_t apc_inserted;
881 typedef struct kapc kapc;
883 typedef uint32_t (*completion_func)(device_object *,
884 struct irp *, void *);
885 typedef uint32_t (*cancel_func)(device_object *,
888 struct io_stack_location {
895 * There's a big-ass union here in the actual Windows
896 * definition of the stucture, but it contains stuff
897 * that doesn't really apply to BSD, and defining it
898 * all properly would require duplicating over a dozen
899 * other structures that we'll never use. Since the
900 * io_stack_location structure is opaque to drivers
901 * anyway, I'm not going to bother with the extra crap.
908 uint64_t isl_byteoff;
913 uint64_t isl_byteoff;
916 uint32_t isl_obuflen;
917 uint32_t isl_ibuflen;
927 } isl_parameters __attribute__((packed));
931 completion_func isl_completionfunc;
932 void *isl_completionctx;
935 typedef struct io_stack_location io_stack_location;
937 /* Stack location control flags */
939 #define SL_PENDING_RETURNED 0x01
940 #define SL_INVOKE_ON_CANCEL 0x20
941 #define SL_INVOKE_ON_SUCCESS 0x40
942 #define SL_INVOKE_ON_ERROR 0x80
950 struct irp *irp_master;
954 list_entry irp_thlist;
955 io_status_block irp_iostat;
957 uint8_t irp_pendingreturned;
958 uint8_t irp_stackcnt;
959 uint8_t irp_currentstackloc;
961 uint8_t irp_cancelirql;
963 uint8_t irp_allocflags;
964 io_status_block *irp_usriostat;
965 nt_kevent *irp_usrevent;
971 uint64_t irp_allocsz;
973 cancel_func irp_cancelfunc;
976 /* Windows kernel info */
981 kdevice_qentry irp_dqe;
991 io_stack_location *irp_csl;
992 uint32_t irp_pkttype;
1008 #define irp_csl s2.u2.irp_csl
1009 #define irp_pkttype s2.u2.irp_pkttype
1011 #define IRP_NDIS_DEV(irp) (irp)->irp_tail.irp_misc.irp_usb.irp_dev
1012 #define IRP_NDISUSB_EP(irp) (irp)->irp_tail.irp_misc.irp_usb.irp_ep
1014 typedef struct irp irp;
1016 #define InterlockedExchangePointer(dst, val) \
1017 (void *)InterlockedExchange((uint32_t *)(dst), (uintptr_t)(val))
1019 #define IoSizeOfIrp(ssize) \
1020 ((uint16_t) (sizeof(irp) + ((ssize) * (sizeof(io_stack_location)))))
1022 #define IoSetCancelRoutine(irp, func) \
1023 (cancel_func)InterlockedExchangePointer( \
1024 (void *)&(ip)->irp_cancelfunc, (void *)(func))
1026 #define IoSetCancelValue(irp, val) \
1027 (u_long)InterlockedExchangePointer( \
1028 (void *)&(ip)->irp_cancel, (void *)(val))
1030 #define IoGetCurrentIrpStackLocation(irp) \
1031 (irp)->irp_tail.irp_overlay.irp_csl
1033 #define IoGetNextIrpStackLocation(irp) \
1034 ((irp)->irp_tail.irp_overlay.irp_csl - 1)
1036 #define IoSetNextIrpStackLocation(irp) \
1038 irp->irp_currentstackloc--; \
1039 irp->irp_tail.irp_overlay.irp_csl--; \
1042 #define IoSetCompletionRoutine(irp, func, ctx, ok, err, cancel) \
1044 io_stack_location *s; \
1045 s = IoGetNextIrpStackLocation((irp)); \
1046 s->isl_completionfunc = (func); \
1047 s->isl_completionctx = (ctx); \
1049 if (ok) s->isl_ctl = SL_INVOKE_ON_SUCCESS; \
1050 if (err) s->isl_ctl |= SL_INVOKE_ON_ERROR; \
1051 if (cancel) s->isl_ctl |= SL_INVOKE_ON_CANCEL; \
1054 #define IoMarkIrpPending(irp) \
1055 IoGetCurrentIrpStackLocation(irp)->isl_ctl |= SL_PENDING_RETURNED
1056 #define IoUnmarkIrpPending(irp) \
1057 IoGetCurrentIrpStackLocation(irp)->isl_ctl &= ~SL_PENDING_RETURNED
1059 #define IoCopyCurrentIrpStackLocationToNext(irp) \
1061 io_stack_location *src, *dst; \
1062 src = IoGetCurrentIrpStackLocation(irp); \
1063 dst = IoGetNextIrpStackLocation(irp); \
1064 bcopy((char *)src, (char *)dst, \
1065 offsetof(io_stack_location, isl_completionfunc)); \
1068 #define IoSkipCurrentIrpStackLocation(irp) \
1070 (irp)->irp_currentstackloc++; \
1071 (irp)->irp_tail.irp_overlay.irp_csl++; \
1074 #define IoInitializeDpcRequest(dobj, dpcfunc) \
1075 KeInitializeDpc(&(dobj)->do_dpc, dpcfunc, dobj)
1077 #define IoRequestDpc(dobj, irp, ctx) \
1078 KeInsertQueueDpc(&(dobj)->do_dpc, irp, ctx)
1080 typedef uint32_t (*driver_dispatch)(device_object *, irp *);
1083 * The driver_object is allocated once for each driver that's loaded
1084 * into the system. A new one is allocated for each driver and
1085 * populated a bit via the driver's DriverEntry function.
1086 * In general, a Windows DriverEntry() function will provide a pointer
1087 * to its AddDevice() method and set up the dispatch table.
1088 * For NDIS drivers, this is all done behind the scenes in the
1089 * NdisInitializeWrapper() and/or NdisMRegisterMiniport() routines.
1092 struct driver_object {
1095 device_object *dro_devobj;
1097 void *dro_driverstart;
1098 uint32_t dro_driversize;
1099 void *dro_driversection;
1100 driver_extension *dro_driverext;
1101 unicode_string dro_drivername;
1102 unicode_string *dro_hwdb;
1103 void *dro_pfastiodispatch;
1104 void *dro_driverinitfunc;
1105 void *dro_driverstartiofunc;
1106 void *dro_driverunloadfunc;
1107 driver_dispatch dro_dispatch[IRP_MJ_MAXIMUM_FUNCTION + 1];
1110 typedef struct driver_object driver_object;
1112 #define DEVPROP_DEVICE_DESCRIPTION 0x00000000
1113 #define DEVPROP_HARDWARE_ID 0x00000001
1114 #define DEVPROP_COMPATIBLE_IDS 0x00000002
1115 #define DEVPROP_BOOTCONF 0x00000003
1116 #define DEVPROP_BOOTCONF_TRANSLATED 0x00000004
1117 #define DEVPROP_CLASS_NAME 0x00000005
1118 #define DEVPROP_CLASS_GUID 0x00000006
1119 #define DEVPROP_DRIVER_KEYNAME 0x00000007
1120 #define DEVPROP_MANUFACTURER 0x00000008
1121 #define DEVPROP_FRIENDLYNAME 0x00000009
1122 #define DEVPROP_LOCATION_INFO 0x0000000A
1123 #define DEVPROP_PHYSDEV_NAME 0x0000000B
1124 #define DEVPROP_BUSTYPE_GUID 0x0000000C
1125 #define DEVPROP_LEGACY_BUSTYPE 0x0000000D
1126 #define DEVPROP_BUS_NUMBER 0x0000000E
1127 #define DEVPROP_ENUMERATOR_NAME 0x0000000F
1128 #define DEVPROP_ADDRESS 0x00000010
1129 #define DEVPROP_UINUMBER 0x00000011
1130 #define DEVPROP_INSTALL_STATE 0x00000012
1131 #define DEVPROP_REMOVAL_POLICY 0x00000013
1133 /* Various supported device types (used with IoCreateDevice()) */
1135 #define FILE_DEVICE_BEEP 0x00000001
1136 #define FILE_DEVICE_CD_ROM 0x00000002
1137 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
1138 #define FILE_DEVICE_CONTROLLER 0x00000004
1139 #define FILE_DEVICE_DATALINK 0x00000005
1140 #define FILE_DEVICE_DFS 0x00000006
1141 #define FILE_DEVICE_DISK 0x00000007
1142 #define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
1143 #define FILE_DEVICE_FILE_SYSTEM 0x00000009
1144 #define FILE_DEVICE_INPORT_PORT 0x0000000A
1145 #define FILE_DEVICE_KEYBOARD 0x0000000B
1146 #define FILE_DEVICE_MAILSLOT 0x0000000C
1147 #define FILE_DEVICE_MIDI_IN 0x0000000D
1148 #define FILE_DEVICE_MIDI_OUT 0x0000000E
1149 #define FILE_DEVICE_MOUSE 0x0000000F
1150 #define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
1151 #define FILE_DEVICE_NAMED_PIPE 0x00000011
1152 #define FILE_DEVICE_NETWORK 0x00000012
1153 #define FILE_DEVICE_NETWORK_BROWSER 0x00000013
1154 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
1155 #define FILE_DEVICE_NULL 0x00000015
1156 #define FILE_DEVICE_PARALLEL_PORT 0x00000016
1157 #define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
1158 #define FILE_DEVICE_PRINTER 0x00000018
1159 #define FILE_DEVICE_SCANNER 0x00000019
1160 #define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001A
1161 #define FILE_DEVICE_SERIAL_PORT 0x0000001B
1162 #define FILE_DEVICE_SCREEN 0x0000001C
1163 #define FILE_DEVICE_SOUND 0x0000001D
1164 #define FILE_DEVICE_STREAMS 0x0000001E
1165 #define FILE_DEVICE_TAPE 0x0000001F
1166 #define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
1167 #define FILE_DEVICE_TRANSPORT 0x00000021
1168 #define FILE_DEVICE_UNKNOWN 0x00000022
1169 #define FILE_DEVICE_VIDEO 0x00000023
1170 #define FILE_DEVICE_VIRTUAL_DISK 0x00000024
1171 #define FILE_DEVICE_WAVE_IN 0x00000025
1172 #define FILE_DEVICE_WAVE_OUT 0x00000026
1173 #define FILE_DEVICE_8042_PORT 0x00000027
1174 #define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
1175 #define FILE_DEVICE_BATTERY 0x00000029
1176 #define FILE_DEVICE_BUS_EXTENDER 0x0000002A
1177 #define FILE_DEVICE_MODEM 0x0000002B
1178 #define FILE_DEVICE_VDM 0x0000002C
1179 #define FILE_DEVICE_MASS_STORAGE 0x0000002D
1180 #define FILE_DEVICE_SMB 0x0000002E
1181 #define FILE_DEVICE_KS 0x0000002F
1182 #define FILE_DEVICE_CHANGER 0x00000030
1183 #define FILE_DEVICE_SMARTCARD 0x00000031
1184 #define FILE_DEVICE_ACPI 0x00000032
1185 #define FILE_DEVICE_DVD 0x00000033
1186 #define FILE_DEVICE_FULLSCREEN_VIDEO 0x00000034
1187 #define FILE_DEVICE_DFS_FILE_SYSTEM 0x00000035
1188 #define FILE_DEVICE_DFS_VOLUME 0x00000036
1189 #define FILE_DEVICE_SERENUM 0x00000037
1190 #define FILE_DEVICE_TERMSRV 0x00000038
1191 #define FILE_DEVICE_KSEC 0x00000039
1192 #define FILE_DEVICE_FIPS 0x0000003A
1194 /* Device characteristics */
1196 #define FILE_REMOVABLE_MEDIA 0x00000001
1197 #define FILE_READ_ONLY_DEVICE 0x00000002
1198 #define FILE_FLOPPY_DISKETTE 0x00000004
1199 #define FILE_WRITE_ONCE_MEDIA 0x00000008
1200 #define FILE_REMOTE_DEVICE 0x00000010
1201 #define FILE_DEVICE_IS_MOUNTED 0x00000020
1202 #define FILE_VIRTUAL_VOLUME 0x00000040
1203 #define FILE_AUTOGENERATED_DEVICE_NAME 0x00000080
1204 #define FILE_DEVICE_SECURE_OPEN 0x00000100
1208 #define STATUS_SUCCESS 0x00000000
1209 #define STATUS_USER_APC 0x000000C0
1210 #define STATUS_KERNEL_APC 0x00000100
1211 #define STATUS_ALERTED 0x00000101
1212 #define STATUS_TIMEOUT 0x00000102
1213 #define STATUS_PENDING 0x00000103
1214 #define STATUS_FAILURE 0xC0000001
1215 #define STATUS_NOT_IMPLEMENTED 0xC0000002
1216 #define STATUS_INVALID_PARAMETER 0xC000000D
1217 #define STATUS_INVALID_DEVICE_REQUEST 0xC0000010
1218 #define STATUS_MORE_PROCESSING_REQUIRED 0xC0000016
1219 #define STATUS_NO_MEMORY 0xC0000017
1220 #define STATUS_BUFFER_TOO_SMALL 0xC0000023
1221 #define STATUS_MUTANT_NOT_OWNED 0xC0000046
1222 #define STATUS_NOT_SUPPORTED 0xC00000BB
1223 #define STATUS_INVALID_PARAMETER_2 0xC00000F0
1224 #define STATUS_INSUFFICIENT_RESOURCES 0xC000009A
1225 #define STATUS_DEVICE_NOT_CONNECTED 0xC000009D
1226 #define STATUS_CANCELLED 0xC0000120
1227 #define STATUS_NOT_FOUND 0xC0000225
1228 #define STATUS_DEVICE_REMOVED 0xC00002B6
1230 #define STATUS_WAIT_0 0x00000000
1232 /* Memory pool types, for ExAllocatePoolWithTag() */
1234 #define NonPagedPool 0x00000000
1235 #define PagedPool 0x00000001
1236 #define NonPagedPoolMustSucceed 0x00000002
1237 #define DontUseThisType 0x00000003
1238 #define NonPagedPoolCacheAligned 0x00000004
1239 #define PagedPoolCacheAligned 0x00000005
1240 #define NonPagedPoolCacheAlignedMustS 0x00000006
1241 #define MaxPoolType 0x00000007
1244 * IO_WORKITEM is an opaque structures that must be allocated
1245 * via IoAllocateWorkItem() and released via IoFreeWorkItem().
1246 * Consequently, we can define it any way we want.
1248 typedef void (*io_workitem_func)(device_object *, void *);
1250 struct io_workitem {
1251 io_workitem_func iw_func;
1253 list_entry iw_listentry;
1254 device_object *iw_dobj;
1258 typedef struct io_workitem io_workitem;
1260 #define WORKQUEUE_CRITICAL 0
1261 #define WORKQUEUE_DELAYED 1
1262 #define WORKQUEUE_HYPERCRITICAL 2
1264 #define WORKITEM_THREADS 4
1265 #define WORKITEM_LEGACY_THREAD 3
1266 #define WORKIDX_INC(x) (x) = (x + 1) % WORKITEM_LEGACY_THREAD
1269 * Older, deprecated work item API, needed to support NdisQueueWorkItem().
1272 struct work_queue_item;
1274 typedef void (*work_item_func)(struct work_queue_item *, void *);
1276 struct work_queue_item {
1277 list_entry wqi_entry;
1278 work_item_func wqi_func;
1282 typedef struct work_queue_item work_queue_item;
1284 #define ExInitializeWorkItem(w, func, ctx) \
1286 (w)->wqi_func = (func); \
1287 (w)->wqi_ctx = (ctx); \
1288 InitializeListHead(&((w)->wqi_entry)); \
1292 * FreeBSD's kernel stack is 2 pages in size by default. The
1293 * Windows stack is larger, so we need to give our threads more
1294 * stack pages. 4 should be enough, we use 8 just to extra safe.
1296 #define NDIS_KSTACK_PAGES 8
1299 * Different kinds of function wrapping we can do.
1302 #define WINDRV_WRAP_STDCALL 1
1303 #define WINDRV_WRAP_FASTCALL 2
1304 #define WINDRV_WRAP_REGPARM 3
1305 #define WINDRV_WRAP_CDECL 4
1306 #define WINDRV_WRAP_AMD64 5
1309 driver_object *windrv_object;
1310 void *windrv_devlist;
1311 ndis_cfg *windrv_regvals;
1312 interface_type windrv_bustype;
1313 STAILQ_ENTRY(drvdb_ent) link;
1316 extern image_patch_table ntoskrnl_functbl[];
1317 typedef void (*funcptr)(void);
1318 typedef int (*matchfuncptr)(interface_type, void *, void *);
1321 extern int windrv_libinit(void);
1322 extern int windrv_libfini(void);
1323 extern driver_object *windrv_lookup(vm_offset_t, char *);
1324 extern struct drvdb_ent *windrv_match(matchfuncptr, void *);
1325 extern int windrv_load(module_t, vm_offset_t, int, interface_type,
1326 void *, ndis_cfg *);
1327 extern int windrv_unload(module_t, vm_offset_t, int);
1328 extern int windrv_create_pdo(driver_object *, device_t);
1329 extern void windrv_destroy_pdo(driver_object *, device_t);
1330 extern device_object *windrv_find_pdo(driver_object *, device_t);
1331 extern int windrv_bus_attach(driver_object *, char *);
1332 extern int windrv_wrap(funcptr, funcptr *, int, int);
1333 extern int windrv_unwrap(funcptr);
1334 extern void ctxsw_utow(void);
1335 extern void ctxsw_wtou(void);
1337 extern int ntoskrnl_libinit(void);
1338 extern int ntoskrnl_libfini(void);
1340 extern void ntoskrnl_intr(void *);
1341 extern void ntoskrnl_time(uint64_t *);
1343 extern uint16_t ExQueryDepthSList(slist_header *);
1345 *InterlockedPushEntrySList(slist_header *, slist_entry *);
1346 extern slist_entry *InterlockedPopEntrySList(slist_header *);
1347 extern uint32_t RtlUnicodeStringToAnsiString(ansi_string *,
1348 unicode_string *, uint8_t);
1349 extern uint32_t RtlAnsiStringToUnicodeString(unicode_string *,
1350 ansi_string *, uint8_t);
1351 extern void RtlInitAnsiString(ansi_string *, char *);
1352 extern void RtlInitUnicodeString(unicode_string *,
1354 extern void RtlFreeUnicodeString(unicode_string *);
1355 extern void RtlFreeAnsiString(ansi_string *);
1356 extern void KeInitializeDpc(kdpc *, void *, void *);
1357 extern uint8_t KeInsertQueueDpc(kdpc *, void *, void *);
1358 extern uint8_t KeRemoveQueueDpc(kdpc *);
1359 extern void KeSetImportanceDpc(kdpc *, uint32_t);
1360 extern void KeSetTargetProcessorDpc(kdpc *, uint8_t);
1361 extern void KeFlushQueuedDpcs(void);
1362 extern uint32_t KeGetCurrentProcessorNumber(void);
1363 extern void KeInitializeTimer(ktimer *);
1364 extern void KeInitializeTimerEx(ktimer *, uint32_t);
1365 extern uint8_t KeSetTimer(ktimer *, int64_t, kdpc *);
1366 extern uint8_t KeSetTimerEx(ktimer *, int64_t, uint32_t, kdpc *);
1367 extern uint8_t KeCancelTimer(ktimer *);
1368 extern uint8_t KeReadStateTimer(ktimer *);
1369 extern uint32_t KeWaitForSingleObject(void *, uint32_t,
1370 uint32_t, uint8_t, int64_t *);
1371 extern void KeInitializeEvent(nt_kevent *, uint32_t, uint8_t);
1372 extern void KeClearEvent(nt_kevent *);
1373 extern uint32_t KeReadStateEvent(nt_kevent *);
1374 extern uint32_t KeSetEvent(nt_kevent *, uint32_t, uint8_t);
1375 extern uint32_t KeResetEvent(nt_kevent *);
1377 extern void KefAcquireSpinLockAtDpcLevel(kspin_lock *);
1378 extern void KefReleaseSpinLockFromDpcLevel(kspin_lock *);
1379 extern uint8_t KeAcquireSpinLockRaiseToDpc(kspin_lock *);
1381 extern void KeAcquireSpinLockAtDpcLevel(kspin_lock *);
1382 extern void KeReleaseSpinLockFromDpcLevel(kspin_lock *);
1384 extern void KeInitializeSpinLock(kspin_lock *);
1385 extern uint8_t KeAcquireInterruptSpinLock(kinterrupt *);
1386 extern void KeReleaseInterruptSpinLock(kinterrupt *, uint8_t);
1387 extern uint8_t KeSynchronizeExecution(kinterrupt *, void *, void *);
1388 extern uintptr_t InterlockedExchange(volatile uint32_t *,
1390 extern void *ExAllocatePoolWithTag(uint32_t, size_t, uint32_t);
1391 extern void ExFreePool(void *);
1392 extern uint32_t IoConnectInterrupt(kinterrupt **, void *, void *,
1393 kspin_lock *, uint32_t, uint8_t, uint8_t, uint8_t, uint8_t,
1395 extern uint8_t MmIsAddressValid(void *);
1396 extern void *MmMapIoSpace(uint64_t, uint32_t, uint32_t);
1397 extern void MmUnmapIoSpace(void *, size_t);
1398 extern void MmBuildMdlForNonPagedPool(mdl *);
1399 extern void IoDisconnectInterrupt(kinterrupt *);
1400 extern uint32_t IoAllocateDriverObjectExtension(driver_object *,
1401 void *, uint32_t, void **);
1402 extern void *IoGetDriverObjectExtension(driver_object *, void *);
1403 extern uint32_t IoCreateDevice(driver_object *, uint32_t,
1404 unicode_string *, uint32_t, uint32_t, uint8_t, device_object **);
1405 extern void IoDeleteDevice(device_object *);
1406 extern device_object *IoGetAttachedDevice(device_object *);
1407 extern uint32_t IofCallDriver(device_object *, irp *);
1408 extern void IofCompleteRequest(irp *, uint8_t);
1409 extern void IoAcquireCancelSpinLock(uint8_t *);
1410 extern void IoReleaseCancelSpinLock(uint8_t);
1411 extern uint8_t IoCancelIrp(irp *);
1412 extern void IoDetachDevice(device_object *);
1413 extern device_object *IoAttachDeviceToDeviceStack(device_object *,
1415 extern mdl *IoAllocateMdl(void *, uint32_t, uint8_t, uint8_t, irp *);
1416 extern void IoFreeMdl(mdl *);
1417 extern io_workitem *IoAllocateWorkItem(device_object *);
1418 extern void ExQueueWorkItem(work_queue_item *, u_int32_t);
1419 extern void IoFreeWorkItem(io_workitem *);
1420 extern void IoQueueWorkItem(io_workitem *, io_workitem_func,
1423 #define IoCallDriver(a, b) IofCallDriver(a, b)
1424 #define IoCompleteRequest(a, b) IofCompleteRequest(a, b)
1427 * On the Windows x86 arch, KeAcquireSpinLock() and KeReleaseSpinLock()
1428 * routines live in the HAL. We try to imitate this behavior.
1431 #define KeAcquireSpinLock(a, b) *(b) = KfAcquireSpinLock(a)
1432 #define KeReleaseSpinLock(a, b) KfReleaseSpinLock(a, b)
1433 #define KeRaiseIrql(a, b) *(b) = KfRaiseIrql(a)
1434 #define KeLowerIrql(a) KfLowerIrql(a)
1435 #define KeAcquireSpinLockAtDpcLevel(a) KefAcquireSpinLockAtDpcLevel(a)
1436 #define KeReleaseSpinLockFromDpcLevel(a) KefReleaseSpinLockFromDpcLevel(a)
1437 #endif /* __i386__ */
1440 #define KeAcquireSpinLock(a, b) *(b) = KfAcquireSpinLock(a)
1441 #define KeReleaseSpinLock(a, b) KfReleaseSpinLock(a, b)
1444 * These may need to be redefined later;
1445 * not sure where they live on amd64 yet.
1447 #define KeRaiseIrql(a, b) *(b) = KfRaiseIrql(a)
1448 #define KeLowerIrql(a) KfLowerIrql(a)
1449 #endif /* __amd64__ */
1453 #endif /* _NTOSKRNL_VAR_H_ */