From 361515a4123365d5eb5137c5f6a99d0db50f2532 Mon Sep 17 00:00:00 2001 From: wpaul Date: Mon, 24 Jan 2005 18:18:12 +0000 Subject: Begin the first phase of trying to add IRP support (and ultimately USB device support): - Convert all of my locally chosen function names to their actual Windows equivalents, where applicable. This is a big no-op change since it doesn't affect functionality, but it helps avoid a bit of confusion (it's now a lot easier to see which functions are emulated Windows API routines and which are just locally defined). - Turn ndis_buffer into an mdl, like it should have been. The structure is the same, but now it belongs to the subr_ntoskrnl module. - Implement a bunch of MDL handling macros from Windows and use them where applicable. - Correct the implementation of IoFreeMdl(). - Properly implement IoAllocateMdl() and MmBuildMdlForNonPagedPool(). - Add the definitions for struct irp and struct driver_object. - Add IMPORT_FUNC() and IMPORT_FUNC_MAP() macros to make formatting the module function tables a little cleaner. (Should also help with AMD64 support later on.) - Fix if_ndis.c to use KeRaiseIrql() and KeLowerIrql() instead of the previous calls to hal_raise_irql() and hal_lower_irql() which have been renamed. The function renaming generated a lot of churn here, but there should be very little operational effect. --- sys/compat/ndis/hal_var.h | 10 +- sys/compat/ndis/kern_ndis.c | 38 +- sys/compat/ndis/ndis_var.h | 2 + sys/compat/ndis/ntoskrnl_var.h | 538 +++++++++++++++++++++++-- sys/compat/ndis/pe_var.h | 4 + sys/compat/ndis/subr_hal.c | 122 +++--- sys/compat/ndis/subr_ndis.c | 870 ++++++++++++++++++++-------------------- sys/compat/ndis/subr_ntoskrnl.c | 572 ++++++++++++++------------ 8 files changed, 1338 insertions(+), 818 deletions(-) (limited to 'sys/compat') diff --git a/sys/compat/ndis/hal_var.h b/sys/compat/ndis/hal_var.h index ad753d9..6386895 100644 --- a/sys/compat/ndis/hal_var.h +++ b/sys/compat/ndis/hal_var.h @@ -46,11 +46,11 @@ extern image_patch_table hal_functbl[]; __BEGIN_DECLS -__fastcall extern uint8_t hal_lock(REGARGS1(kspin_lock *lock)); -__fastcall void hal_unlock(REGARGS2(kspin_lock *lock, uint8_t newirql)); -__fastcall extern uint8_t hal_raise_irql(REGARGS1(uint8_t irql)); -__fastcall extern void hal_lower_irql(REGARGS1(uint8_t oldirql)); -__stdcall extern uint8_t hal_irql(void); +__fastcall extern uint8_t KfAcquireSpinLock(REGARGS1(kspin_lock *lock)); +__fastcall void KfReleaseSpinLock(REGARGS2(kspin_lock *lock, uint8_t newirql)); +__fastcall extern uint8_t KfRaiseIrql(REGARGS1(uint8_t irql)); +__fastcall extern void KfLowerIrql(REGARGS1(uint8_t oldirql)); +__stdcall extern uint8_t KeGetCurrentIrql(void); __END_DECLS #endif /* _HAL_VAR_H_ */ diff --git a/sys/compat/ndis/kern_ndis.c b/sys/compat/ndis/kern_ndis.c index c0efdae..f6db9c7 100644 --- a/sys/compat/ndis/kern_ndis.c +++ b/sys/compat/ndis/kern_ndis.c @@ -786,9 +786,9 @@ ndis_return(arg) return; returnfunc = sc->ndis_chars.nmc_return_packet_func; - irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); + irql = KeRaiseIrql(DISPATCH_LEVEL); returnfunc(adapter, p); - ntoskrnl_lower_irql(irql); + KeLowerIrql(irql); return; } @@ -827,7 +827,7 @@ ndis_free_bufs(b0) return; while(b0 != NULL) { - next = b0->nb_next; + next = b0->mdl_next; uma_zfree (ndis_buffer_zone, b0); b0 = next; } @@ -989,7 +989,7 @@ ndis_ptom(m0, p) buf = priv->npp_head; p->np_refcnt = 0; - for (buf = priv->npp_head; buf != NULL; buf = buf->nb_next) { + for (buf = priv->npp_head; buf != NULL; buf = buf->mdl_next) { if (buf == priv->npp_head) MGETHDR(m, M_DONTWAIT, MT_HEADER); else @@ -999,8 +999,8 @@ ndis_ptom(m0, p) *m0 = NULL; return(ENOBUFS); } - m->m_len = buf->nb_bytecount; - m->m_data = MDL_VA(buf); + m->m_len = MmGetMdlByteCount(buf); + m->m_data = MmGetMdlVirtualAddress(buf); MEXTADD(m, m->m_data, m->m_len, ndis_return_packet, p, 0, EXT_NDIS); p->np_refcnt++; @@ -1067,11 +1067,11 @@ ndis_mtop(m0, p) return(ENOMEM); } - MDL_INIT(buf, m->m_data, m->m_len); + MmInitializeMdl(buf, m->m_data, m->m_len); if (priv->npp_head == NULL) priv->npp_head = buf; else - prev->nb_next = buf; + prev->mdl_next = buf; prev = buf; } @@ -1136,10 +1136,10 @@ ndis_set_info(arg, oid, buf, buflen) if (adapter == NULL || setfunc == NULL) return(ENXIO); - ntoskrnl_acquire_spinlock(&sc->ndis_block.nmb_lock, &irql); + KeAcquireSpinLock(&sc->ndis_block.nmb_lock, &irql); rval = setfunc(adapter, oid, buf, *buflen, &byteswritten, &bytesneeded); - ntoskrnl_release_spinlock(&sc->ndis_block.nmb_lock, irql); + KeReleaseSpinLock(&sc->ndis_block.nmb_lock, irql); if (rval == NDIS_STATUS_PENDING) { mtx_lock(&ndis_req_mtx); @@ -1193,9 +1193,9 @@ ndis_send_packets(arg, packets, cnt) return(ENXIO); sendfunc = sc->ndis_chars.nmc_sendmulti_func; senddonefunc = sc->ndis_block.nmb_senddone_func; - irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); + irql = KeRaiseIrql(DISPATCH_LEVEL); sendfunc(adapter, packets, cnt); - ntoskrnl_lower_irql(irql); + KeLowerIrql(irql); for (i = 0; i < cnt; i++) { p = packets[i]; @@ -1232,9 +1232,9 @@ ndis_send_packet(arg, packet) sendfunc = sc->ndis_chars.nmc_sendsingle_func; senddonefunc = sc->ndis_block.nmb_senddone_func; - irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); + irql = KeRaiseIrql(DISPATCH_LEVEL); status = sendfunc(adapter, packet, packet->np_private.npp_flags); - ntoskrnl_lower_irql(irql); + KeLowerIrql(irql); if (status == NDIS_STATUS_PENDING) return(0); @@ -1321,9 +1321,9 @@ ndis_reset_nic(arg) if (adapter == NULL || resetfunc == NULL) return(EIO); - irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); + irql = KeRaiseIrql(DISPATCH_LEVEL); rval = resetfunc(&addressing_reset, adapter); - ntoskrnl_lower_irql(irql); + KeLowerIrql(irql); if (rval == NDIS_STATUS_PENDING) { mtx_lock(&ndis_req_mtx); @@ -1554,10 +1554,10 @@ ndis_get_info(arg, oid, buf, buflen) if (adapter == NULL || queryfunc == NULL) return(ENXIO); - ntoskrnl_acquire_spinlock(&sc->ndis_block.nmb_lock, &irql); + KeAcquireSpinLock(&sc->ndis_block.nmb_lock, &irql); rval = queryfunc(adapter, oid, buf, *buflen, &byteswritten, &bytesneeded); - ntoskrnl_release_spinlock(&sc->ndis_block.nmb_lock, irql); + KeReleaseSpinLock(&sc->ndis_block.nmb_lock, irql); /* Wait for requests that block. */ @@ -1711,7 +1711,7 @@ ndis_load_driver(img, arg) ndis_enlarge_thrqueue(8); TAILQ_INSERT_TAIL(&ndis_devhead, block, link); - ntoskrnl_init_lock(&block->nmb_lock); + KeInitializeSpinLock(&block->nmb_lock); return(0); } diff --git a/sys/compat/ndis/ndis_var.h b/sys/compat/ndis/ndis_var.h index 481dec3..2a3b583 100644 --- a/sys/compat/ndis/ndis_var.h +++ b/sys/compat/ndis/ndis_var.h @@ -953,6 +953,7 @@ struct ndis_work_item { typedef struct ndis_work_item ndis_work_item; +#ifdef notdef struct ndis_buffer { struct ndis_buffer *nb_next; uint16_t nb_size; @@ -965,6 +966,7 @@ struct ndis_buffer { }; typedef struct ndis_buffer ndis_buffer; +#endif struct ndis_sc_element { ndis_physaddr nse_addr; diff --git a/sys/compat/ndis/ntoskrnl_var.h b/sys/compat/ndis/ntoskrnl_var.h index 60eceaf..1767d2e 100644 --- a/sys/compat/ndis/ntoskrnl_var.h +++ b/sys/compat/ndis/ntoskrnl_var.h @@ -35,25 +35,109 @@ #ifndef _NTOSKRNL_VAR_H_ #define _NTOSKRNL_VAR_H_ +/* + * us_buf is really a wchar_t *, but it's inconvenient to include + * all the necessary header goop needed to define it, and it's a + * pointer anyway, so for now, just make it a uint16_t *. + */ +struct unicode_string { + uint16_t us_len; + uint16_t us_maxlen; + uint16_t *us_buf; +}; + +typedef struct unicode_string unicode_string; + +/* + * Windows memory descriptor list. In Windows, it's possible for + * buffers to be passed between user and kernel contexts without + * copying. Buffers may also be allocated in either paged or + * non-paged memory regions. An MDL describes the pages of memory + * used to contain a particular buffer. Note that a single MDL + * may describe a buffer that spans multiple pages. An array of + * page addresses appears immediately after the MDL structure itself. + * MDLs are therefore implicitly variably sized, even though they + * don't look it. + * + * Note that in FreeBSD, we can take many shortcuts in the way + * we handle MDLs because: + * + * - We are only concerned with pages in kernel context. This means + * we will only ever use the kernel's memory map, and remapping + * of buffers is never needed. + * + * - Kernel pages can never be paged out, so we don't have to worry + * about whether or not a page is actually mapped before going to + * touch it. + */ + +struct mdl { + struct mdl *mdl_next; + uint16_t mdl_size; + uint16_t mdl_flags; + void *mdl_process; + void *mdl_mappedsystemva; + void *mdl_startva; + uint32_t mdl_bytecount; + uint32_t mdl_byteoffset; +}; + +typedef struct mdl mdl, ndis_buffer; + +/* MDL flags */ + +#define MDL_MAPPED_TO_SYSTEM_VA 0x0001 +#define MDL_PAGES_LOCKED 0x0002 +#define MDL_SOURCE_IS_NONPAGED_POOL 0x0004 +#define MDL_ALLOCATED_FIXED_SIZE 0x0008 +#define MDL_PARTIAL 0x0010 +#define MDL_PARTIAL_HAS_BEEN_MAPPED 0x0020 +#define MDL_IO_PAGE_READ 0x0040 +#define MDL_WRITE_OPERATION 0x0080 +#define MDL_PARENT_MAPPED_SYSTEM_VA 0x0100 +#define MDL_FREE_EXTRA_PTES 0x0200 +#define MDL_IO_SPACE 0x0800 +#define MDL_NETWORK_HEADER 0x1000 +#define MDL_MAPPING_CAN_FAIL 0x2000 +#define MDL_ALLOCATED_MUST_SUCCEED 0x4000 + /* Note: assumes x86 page size of 4K. */ + +#if PAGE_SIZE == 4096 #define PAGE_SHIFT 12 +#elif PAGE_SIZE == 8192 +#define PAGE_SHIFT 13 +#else +#error PAGE_SHIFT undefined! +#endif + #define SPAN_PAGES(ptr, len) \ - ((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE -1)) + \ + ((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE - 1)) + \ (len) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)) + #define PAGE_ALIGN(ptr) \ ((void *)((uintptr_t)(ptr) & ~(PAGE_SIZE - 1))) + #define BYTE_OFFSET(ptr) \ ((uint32_t)((uintptr_t)(ptr) & (PAGE_SIZE - 1))) -#define MDL_INIT(b, baseva, len) \ - (b)->nb_next = NULL; \ - (b)->nb_size = (uint16_t)(sizeof(struct ndis_buffer) + \ + +#define MDL_PAGES(m) (vm_offset_t *)(m + 1) + +#define MmInitializeMdl(b, baseva, len) \ + (b)->mdl_next = NULL; \ + (b)->mdl_size = (uint16_t)(sizeof(mdl) + \ (sizeof(uint32_t) * SPAN_PAGES((baseva), (len)))); \ - (b)->nb_flags = 0; \ - (b)->nb_startva = (void *)PAGE_ALIGN((baseva)); \ - (b)->nb_byteoffset = BYTE_OFFSET((baseva)); \ - (b)->nb_bytecount = (uint32_t)(len); -#define MDL_VA(b) \ - ((void *)((char *)((b)->nb_startva) + (b)->nb_byteoffset)) + (b)->mdl_flags = 0; \ + (b)->mdl_startva = (void *)PAGE_ALIGN((baseva)); \ + (b)->mdl_byteoffset = BYTE_OFFSET((baseva)); \ + (b)->mdl_bytecount = (uint32_t)(len); + +#define MmGetMdlByteOffset(mdl) ((mdl)->mdl_byteoffset) +#define MmGetMdlByteCount(mdl) ((mdl)->mdl_bytecount) +#define MmGetMdlVirtualAddress(mdl) \ + ((void *)((char *)((mdl)->mdl_startva) + (mdl)->mdl_byteoffset)) +#define MmGetMdlStartVa(mdl) ((mdl)->mdl_startva) +#define MmGetMdlPfnArray(mdl) MDL_PAGES(mdl) #define WDM_MAJOR 1 #define WDM_MINOR_WIN98 0x00 @@ -405,6 +489,35 @@ struct thread_context { typedef struct thread_context thread_context; +/* Forward declaration */ +struct driver_object; +struct devobj_extension; + +struct driver_extension { + struct driver_object *dre_driverobj; + void *dre_adddevicefunc; + uint32_t dre_reinitcnt; + unicode_string dre_srvname; +}; + +typedef struct driver_extension driver_extension; + +/* + * In Windows, there are Physical Device Objects (PDOs) and + * Functional Device Objects (FDOs). Physical Device Objects are + * created and maintained by bus drivers. For example, the PCI + * bus driver might detect two PCI ethernet cards on a given + * bus. The PCI bus driver will then allocate two device_objects + * for its own internal bookeeping purposes. This is analagous + * to the device_t that the FreeBSD PCI code allocates and passes + * into each PCI driver's probe and attach routines. + * + * When an ethernet driver claims one of the ethernet cards + * on the bus, it will create its own device_object. This is + * the Functional Device Object. This object is analagous to the + * device-specific softc structure. + */ + struct device_object { uint16_t do_type; uint16_t do_size; @@ -431,20 +544,372 @@ struct device_object { struct nt_kevent do_devlock; uint16_t do_sectorsz; uint16_t do_spare1; - void *do_devobj_ext; + struct devobj_extension *do_devobj_ext; void *do_rsvd; }; typedef struct device_object device_object; +struct devobj_extension { + uint16_t dve_type; + uint16_t dve_size; + device_object *dve_devobj; +}; + +typedef struct devobj_extension devobj_extension; + +#define IO_NO_INCREMENT 0 +#define IO_CD_ROM_INCREMENT 1 +#define IO_DISK_INCREMENT 1 +#define IO_KEYBOARD_INCREMENT 6 +#define IO_MAILSLOT_INCREMENT 2 +#define IO_MOUSE_INCREMENT 6 +#define IO_NAMED_PIPE_INCREMENT 2 +#define IO_NETWORK_INCREMENT 2 +#define IO_PARALLEL_INCREMENT 1 +#define IO_SERIAL_INCREMENT 2 +#define IO_SOUND_INCREMENT 8 +#define IO_VIDEO_INCREMENT 1 + +/* IRP major codes */ + +#define IRP_MJ_CREATE 0x00 +#define IRP_MJ_CREATE_NAMED_PIPE 0x01 +#define IRP_MJ_CLOSE 0x02 +#define IRP_MJ_READ 0x03 +#define IRP_MJ_WRITE 0x04 +#define IRP_MJ_QUERY_INFORMATION 0x05 +#define IRP_MJ_SET_INFORMATION 0x06 +#define IRP_MJ_QUERY_EA 0x07 +#define IRP_MJ_SET_EA 0x08 +#define IRP_MJ_FLUSH_BUFFERS 0x09 +#define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a +#define IRP_MJ_SET_VOLUME_INFORMATION 0x0b +#define IRP_MJ_DIRECTORY_CONTROL 0x0c +#define IRP_MJ_FILE_SYSTEM_CONTROL 0x0d +#define IRP_MJ_DEVICE_CONTROL 0x0e +#define IRP_MJ_INTERNAL_DEVICE_CONTROL 0x0f +#define IRP_MJ_SHUTDOWN 0x10 +#define IRP_MJ_LOCK_CONTROL 0x11 +#define IRP_MJ_CLEANUP 0x12 +#define IRP_MJ_CREATE_MAILSLOT 0x13 +#define IRP_MJ_QUERY_SECURITY 0x14 +#define IRP_MJ_SET_SECURITY 0x15 +#define IRP_MJ_POWER 0x16 +#define IRP_MJ_SYSTEM_CONTROL 0x17 +#define IRP_MJ_DEVICE_CHANGE 0x18 +#define IRP_MJ_QUERY_QUOTA 0x19 +#define IRP_MJ_SET_QUOTA 0x1a +#define IRP_MJ_PNP 0x1b +#define IRP_MJ_PNP_POWER IRP_MJ_PNP // Obsolete.... +#define IRP_MJ_MAXIMUM_FUNCTION 0x1b +#define IRP_MJ_SCSI IRP_MJ_INTERNAL_DEVICE_CONTROL + +/* IRP minor codes */ + +#define IRP_MN_QUERY_DIRECTORY 0x01 +#define IRP_MN_NOTIFY_CHANGE_DIRECTORY 0x02 +#define IRP_MN_USER_FS_REQUEST 0x00 + +#define IRP_MN_MOUNT_VOLUME 0x01 +#define IRP_MN_VERIFY_VOLUME 0x02 +#define IRP_MN_LOAD_FILE_SYSTEM 0x03 +#define IRP_MN_TRACK_LINK 0x04 // To be obsoleted soon +#define IRP_MN_KERNEL_CALL 0x04 + +#define IRP_MN_LOCK 0x01 +#define IRP_MN_UNLOCK_SINGLE 0x02 +#define IRP_MN_UNLOCK_ALL 0x03 +#define IRP_MN_UNLOCK_ALL_BY_KEY 0x04 + +#define IRP_MN_NORMAL 0x00 +#define IRP_MN_DPC 0x01 +#define IRP_MN_MDL 0x02 +#define IRP_MN_COMPLETE 0x04 +#define IRP_MN_COMPRESSED 0x08 + +#define IRP_MN_MDL_DPC (IRP_MN_MDL | IRP_MN_DPC) +#define IRP_MN_COMPLETE_MDL (IRP_MN_COMPLETE | IRP_MN_MDL) +#define IRP_MN_COMPLETE_MDL_DPC (IRP_MN_COMPLETE_MDL | IRP_MN_DPC) + +#define IRP_MN_SCSI_CLASS 0x01 + +#define IRP_MN_START_DEVICE 0x00 +#define IRP_MN_QUERY_REMOVE_DEVICE 0x01 +#define IRP_MN_REMOVE_DEVICE 0x02 +#define IRP_MN_CANCEL_REMOVE_DEVICE 0x03 +#define IRP_MN_STOP_DEVICE 0x04 +#define IRP_MN_QUERY_STOP_DEVICE 0x05 +#define IRP_MN_CANCEL_STOP_DEVICE 0x06 + +#define IRP_MN_QUERY_DEVICE_RELATIONS 0x07 +#define IRP_MN_QUERY_INTERFACE 0x08 +#define IRP_MN_QUERY_CAPABILITIES 0x09 +#define IRP_MN_QUERY_RESOURCES 0x0A +#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS 0x0B +#define IRP_MN_QUERY_DEVICE_TEXT 0x0C +#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS 0x0D + +#define IRP_MN_READ_CONFIG 0x0F +#define IRP_MN_WRITE_CONFIG 0x10 +#define IRP_MN_EJECT 0x11 +#define IRP_MN_SET_LOCK 0x12 +#define IRP_MN_QUERY_ID 0x13 +#define IRP_MN_QUERY_PNP_DEVICE_STATE 0x14 +#define IRP_MN_QUERY_BUS_INFORMATION 0x15 +#define IRP_MN_DEVICE_USAGE_NOTIFICATION 0x16 +#define IRP_MN_SURPRISE_REMOVAL 0x17 +#define IRP_MN_QUERY_LEGACY_BUS_INFORMATION 0x18 + +#define IRP_MN_WAIT_WAKE 0x00 +#define IRP_MN_POWER_SEQUENCE 0x01 +#define IRP_MN_SET_POWER 0x02 +#define IRP_MN_QUERY_POWER 0x03 + +#define IRP_MN_QUERY_ALL_DATA 0x00 +#define IRP_MN_QUERY_SINGLE_INSTANCE 0x01 +#define IRP_MN_CHANGE_SINGLE_INSTANCE 0x02 +#define IRP_MN_CHANGE_SINGLE_ITEM 0x03 +#define IRP_MN_ENABLE_EVENTS 0x04 +#define IRP_MN_DISABLE_EVENTS 0x05 +#define IRP_MN_ENABLE_COLLECTION 0x06 +#define IRP_MN_DISABLE_COLLECTION 0x07 +#define IRP_MN_REGINFO 0x08 +#define IRP_MN_EXECUTE_METHOD 0x09 +#define IRP_MN_REGINFO_EX 0x0b + +/* IRP flags */ + +#define IRP_NOCACHE 0x00000001 +#define IRP_PAGING_IO 0x00000002 +#define IRP_MOUNT_COMPLETION 0x00000002 +#define IRP_SYNCHRONOUS_API 0x00000004 +#define IRP_ASSOCIATED_IRP 0x00000008 +#define IRP_BUFFERED_IO 0x00000010 +#define IRP_DEALLOCATE_BUFFER 0x00000020 +#define IRP_INPUT_OPERATION 0x00000040 +#define IRP_SYNCHRONOUS_PAGING_IO 0x00000040 +#define IRP_CREATE_OPERATION 0x00000080 +#define IRP_READ_OPERATION 0x00000100 +#define IRP_WRITE_OPERATION 0x00000200 +#define IRP_CLOSE_OPERATION 0x00000400 +#define IRP_DEFER_IO_COMPLETION 0x00000800 +#define IRP_OB_QUERY_NAME 0x00001000 +#define IRP_HOLD_DEVICE_QUEUE 0x00002000 +#define IRP_RETRY_IO_COMPLETION 0x00004000 +#define IRP_CLASS_CACHE_OPERATION 0x00008000 +#define IRP_SET_USER_EVENT IRP_CLOSE_OPERATION + +/* IRP I/O control flags */ + +#define IRP_QUOTA_CHARGED 0x01 +#define IRP_ALLOCATED_MUST_SUCCEED 0x02 +#define IRP_ALLOCATED_FIXED_SIZE 0x04 +#define IRP_LOOKASIDE_ALLOCATION 0x08 + +struct io_status_block { + union { + uint32_t isb_status; + void *isb_ptr; + } u; + register_t isb_info; +}; + +typedef struct io_status_block io_status_block; + +struct kapc { + uint16_t apc_type; + uint16_t apc_size; + uint32_t apc_spare0; + void *apc_thread; + list_entry apc_list; + void *apc_kernfunc; + void *apc_rundownfunc; + void *apc_normalfunc; + void *apc_normctx; + void *apc_sysarg1; + void *apc_sysarg2; + uint8_t apc_stateidx; + uint8_t apc_cpumode; + uint8_t apc_inserted; +}; + +typedef struct kapc kapc; + +struct io_stack_location { + uint8_t isl_major; + uint8_t isl_minor; + uint8_t isl_flags; + uint8_t isl_ctl; + + /* + * There's a big-ass union here in the actual Windows + * definition of the stucture, but it contains stuff + * that doesn't really apply to BSD, and defining it + * all properly would require duplicating over a dozen + * other structures that we'll never use. Since the + * io_stack_location structure is opaque to drivers + * anyway, I'm not going to bother with the extra crap. + */ + + union { + struct { + void *isl_arg1; + void *isl_arg2; + void *isl_arg3; + void *isl_arg4; + } isl_others; + } isl_parameters; + + void *isl_devobj; + void *isl_fileobj; + void *isl_completionfunc; + void *isl_completionctx; +}; + +typedef struct io_stack_location io_stack_location; + +/* Stack location control flags */ + +#define SL_PENDING_RETURNED 0x01 +#define SL_INVOKE_ON_CANCEL 0x20 +#define SL_INVOKE_ON_SUCCESS 0x40 +#define SL_INVOKE_ON_ERROR 0x80 + struct irp { - uint32_t i_dummy; + uint16_t irp_type; + uint16_t irp_size; + mdl *irp_mdl; + uint32_t irp_flags; + union { + struct irp *irp_master; + uint32_t irp_irpcnt; + void *irp_sysbuf; + } irp_assoc; + list_entry irp_thlist; + io_status_block irp_iostat; + uint8_t irp_reqmode; + uint8_t irp_pendingreturned; + uint8_t irp_stackcnt; + uint8_t irp_currentstackloc; + uint8_t irp_cancel; + uint8_t irp_cancelirql; + uint8_t irp_apcenv; + uint8_t irp_allocflags; + io_status_block *irp_usriostat; + nt_kevent irp_userevent; + union { + struct { + void *irp_apcfunc; + void *irp_apcctx; + } irp_asyncparms; + uint64_t irp_allocsz; + } irp_overlay; + void *irp_cancelfunc; + void *irp_userbuf; + + /* Windows kernel info */ + + union { + struct { + union { + kdevice_qentry irp_dqe; + struct { + void *irp_drvctx[4]; + } s1; + } u1; + void *irp_thread; + char *irp_auxbuf; + struct { + list_entry irp_list; + union { + io_stack_location *irp_csl; + uint32_t irp_pkttype; + } u2; + } s2; + void *irp_fileobj; + } irp_overlay; + kapc irp_apc; + void *irp_compkey; + } irp_tail; }; +#define irp_csl s2.u2.irp_csl +#define irp_pkttype s2.u2.irp_pkttype + typedef struct irp irp; +#define IoGetCurrentIrpStackLocation(irp) \ + (irp)->irp_tail.irp_overlay.irp_csl + +#define IoGetNextIrpStackLocation(irp) \ + ((irp)->irp_tail.irp_overlay.irp_csl - 1) + +#define IoSetCompletionRoutine(irp, func, ctx, ok, err, cancel) \ + do { \ + io_stack_location *s; \ + s = IoGetNextIrpStackLocation((irp)); \ + s->isl_completionfunc = (func); \ + s->isl_completionctx = (ctx); \ + s->isl_ctl = 0; \ + if (ok) irp->ctl = SL_INVOKE_ON_SUCCESS; \ + if (err) irp->ctl |= SL_INVOKE_ON_ERROR; \ + if (cancel) irp->ctl |= SL_INVOKE_ON_CANCEL; \ + } while(0) + +#define IoMarkIrpPending(irp) \ + IoGetCurrentIrpStackLocation(irp)->isl_ctl |= SL_PENDING_RETURNED + +#define IoSizeOfIrp(s) \ + ((uint16_t) (sizeof(itp) + ((s) * (sizeof(io_stack_location))))) + +#define IoCopyCurrentIrpStackLocationToNext(irp) \ + do { \ + io_stack_location *src, *dst; \ + src = IoGetCurrentIrpStackLocation(irp); \ + dst = IoGetNextIrpStackLocation(irp); \ + bcopy((char *)src, (char *)dst, \ + offsetof(io_stack_location, isl_completionfunc)); \ + } while(0) + +#define IoSkipCurrentIrpStackLocation(irp) \ + do { \ + (irp)->irp_currentstackloc++; \ + (irp)->irp_tail.irp_overlay.irp_csl++; \ + } while(0) + typedef uint32_t (*driver_dispatch)(device_object *, irp *); +/* + * The driver_object is allocated once for each driver that's loaded + * into the system. A new one is allocated for each driver and + * populated a bit via the driver's DriverEntry function. + * In general, a Windows DriverEntry() function will provide a pointer + * to its AddDevice() method and set up the dispatch table. + * For NDIS drivers, this is all done behind the scenes in the + * NdisInitializeWrapper() and/or NdisMRegisterMiniport() routines. + */ + +struct driver_object { + uint16_t dro_type; + uint16_t dro_size; + device_object *dro_devobj; + uint32_t dro_flags; + void *dro_driverstart; + uint32_t dro_driversize; + void *dro_driversection; + driver_extension dro_driverext; + unicode_string dro_drivername; + unicode_string *dro_hwdb; + void *dro_pfastiodispatch; + void *dro_driverinitfunc; + void *dro_driverstartiofunc; + void *dro_driverunloadfunc; + void *dro_dispatch[IRP_MJ_MAXIMUM_FUNCTION + 1]; +}; + +typedef struct driver_object driver_object; + #define DEVPROP_DEVICE_DESCRIPTION 0x00000000 #define DEVPROP_HARDWARE_ID 0x00000001 #define DEVPROP_COMPATIBLE_IDS 0x00000002 @@ -491,36 +956,41 @@ extern image_patch_table ntoskrnl_functbl[]; __BEGIN_DECLS extern int ntoskrnl_libinit(void); extern int ntoskrnl_libfini(void); -__stdcall extern void ntoskrnl_init_dpc(kdpc *, void *, void *); -__stdcall extern uint8_t ntoskrnl_queue_dpc(kdpc *, void *, void *); -__stdcall extern uint8_t ntoskrnl_dequeue_dpc(kdpc *); -__stdcall extern void ntoskrnl_init_timer(ktimer *); -__stdcall extern void ntoskrnl_init_timer_ex(ktimer *, uint32_t); -__stdcall extern uint8_t ntoskrnl_set_timer(ktimer *, int64_t, kdpc *); -__stdcall extern uint8_t ntoskrnl_set_timer_ex(ktimer *, int64_t, +__stdcall extern void KeInitializeDpc(kdpc *, void *, void *); +__stdcall extern uint8_t KeInsertQueueDpc(kdpc *, void *, void *); +__stdcall extern uint8_t KeRemoveQueueDpc(kdpc *); +__stdcall extern void KeInitializeTimer(ktimer *); +__stdcall extern void KeInitializeTimerEx(ktimer *, uint32_t); +__stdcall extern uint8_t KeSetTimer(ktimer *, int64_t, kdpc *); +__stdcall extern uint8_t KeSetTimerEx(ktimer *, int64_t, uint32_t, kdpc *); -__stdcall extern uint8_t ntoskrnl_cancel_timer(ktimer *); -__stdcall extern uint8_t ntoskrnl_read_timer(ktimer *); -__stdcall extern uint32_t ntoskrnl_waitforobj(nt_dispatch_header *, uint32_t, +__stdcall extern uint8_t KeCancelTimer(ktimer *); +__stdcall extern uint8_t KeReadStateTimer(ktimer *); +__stdcall extern uint32_t KeWaitForSingleObject(nt_dispatch_header *, uint32_t, uint32_t, uint8_t, int64_t *); -__stdcall extern void ntoskrnl_init_event(nt_kevent *, uint32_t, uint8_t); -__stdcall extern void ntoskrnl_clear_event(nt_kevent *); -__stdcall extern uint32_t ntoskrnl_read_event(nt_kevent *); -__stdcall extern uint32_t ntoskrnl_set_event(nt_kevent *, uint32_t, uint8_t); -__stdcall extern uint32_t ntoskrnl_reset_event(nt_kevent *); -__stdcall extern void ntoskrnl_init_lock(kspin_lock *); -__fastcall extern void ntoskrnl_lock_dpc(REGARGS1(kspin_lock *)); -__fastcall extern void ntoskrnl_unlock_dpc(REGARGS1(kspin_lock *)); +__stdcall extern void KeInitializeEvent(nt_kevent *, uint32_t, uint8_t); +__stdcall extern void KeClearEvent(nt_kevent *); +__stdcall extern uint32_t KeReadStateEvent(nt_kevent *); +__stdcall extern uint32_t KeSetEvent(nt_kevent *, uint32_t, uint8_t); +__stdcall extern uint32_t KeResetEvent(nt_kevent *); +__fastcall extern void KefAcquireSpinLockAtDpcLevel(REGARGS1(kspin_lock *)); +__fastcall extern void KefReleaseSpinLockFromDpcLevel(REGARGS1(kspin_lock *)); +__stdcall extern void KeInitializeSpinLock(kspin_lock *); +__fastcall extern uint32_t IofCallDriver(REGARGS2(device_object *, irp *)); +__fastcall extern void IofCompleteRequest(REGARGS2(irp *, uint8_t)); + +#define IoCallDriver(a, b) FASTCALL2(IofCallDriver, a, b) +#define IoCompleteRequest(a, b) FASTCALL2(IofCompleteRequest, a, b) /* * On the Windows x86 arch, KeAcquireSpinLock() and KeReleaseSpinLock() * routines live in the HAL. We try to imitate this behavior. */ #ifdef __i386__ -#define ntoskrnl_acquire_spinlock(a, b) *(b) = FASTCALL1(hal_lock, a) -#define ntoskrnl_release_spinlock(a, b) FASTCALL2(hal_unlock, a, b) -#define ntoskrnl_raise_irql(a) FASTCALL1(hal_raise_irql, a) -#define ntoskrnl_lower_irql(a) FASTCALL1(hal_lower_irql, a) +#define KeAcquireSpinLock(a, b) *(b) = FASTCALL1(KfAcquireSpinLock, a) +#define KeReleaseSpinLock(a, b) FASTCALL2(KfReleaseSpinLock, a, b) +#define KeRaiseIrql(a) FASTCALL1(KfRaiseIrql, a) +#define KeLowerIrql(a) FASTCALL1(KfLowerIrql, a) #endif /* __i386__ */ __END_DECLS diff --git a/sys/compat/ndis/pe_var.h b/sys/compat/ndis/pe_var.h index 6df1a05..fa635d4 100644 --- a/sys/compat/ndis/pe_var.h +++ b/sys/compat/ndis/pe_var.h @@ -476,6 +476,10 @@ fastcall3(fcall3 f, uint32_t a, uint32_t b, uint32_t c) #define FASTCALL3(f, a, b, c) (f)((a), (b), (c)) #endif /* __i386__ */ +#define FUNC void(*)(void) +#define IMPORT_FUNC(x) { #x, (FUNC)x } +#define IMPORT_FUNC_MAP(x, y) { #x, (FUNC)y } + __BEGIN_DECLS extern int pe_get_dos_header(vm_offset_t, image_dos_header *); extern int pe_is_nt_image(vm_offset_t); diff --git a/sys/compat/ndis/subr_hal.c b/sys/compat/ndis/subr_hal.c index ab7238e..81dcade 100644 --- a/sys/compat/ndis/subr_hal.c +++ b/sys/compat/ndis/subr_hal.c @@ -57,34 +57,32 @@ __FBSDID("$FreeBSD$"); #include #include -#define FUNC void(*)(void) - -__stdcall static void hal_stall_exec_cpu(uint32_t); -__stdcall static void hal_writeport_buf_ulong(uint32_t *, +__stdcall static void KeStallExecutionProcessor(uint32_t); +__stdcall static void WRITE_PORT_BUFFER_ULONG(uint32_t *, uint32_t *, uint32_t); -__stdcall static void hal_writeport_buf_ushort(uint16_t *, +__stdcall static void WRITE_PORT_BUFFER_USHORT(uint16_t *, uint16_t *, uint32_t); -__stdcall static void hal_writeport_buf_uchar(uint8_t *, +__stdcall static void WRITE_PORT_BUFFER_UCHAR(uint8_t *, uint8_t *, uint32_t); -__stdcall static void hal_writeport_ulong(uint32_t *, uint32_t); -__stdcall static void hal_writeport_ushort(uint16_t *, uint16_t); -__stdcall static void hal_writeport_uchar(uint8_t *, uint8_t); -__stdcall static uint32_t hal_readport_ulong(uint32_t *); -__stdcall static uint16_t hal_readport_ushort(uint16_t *); -__stdcall static uint8_t hal_readport_uchar(uint8_t *); -__stdcall static void hal_readport_buf_ulong(uint32_t *, +__stdcall static void WRITE_PORT_ULONG(uint32_t *, uint32_t); +__stdcall static void WRITE_PORT_USHORT(uint16_t *, uint16_t); +__stdcall static void WRITE_PORT_UCHAR(uint8_t *, uint8_t); +__stdcall static uint32_t READ_PORT_ULONG(uint32_t *); +__stdcall static uint16_t READ_PORT_USHORT(uint16_t *); +__stdcall static uint8_t READ_PORT_UCHAR(uint8_t *); +__stdcall static void READ_PORT_BUFFER_ULONG(uint32_t *, uint32_t *, uint32_t); -__stdcall static void hal_readport_buf_ushort(uint16_t *, +__stdcall static void READ_PORT_BUFFER_USHORT(uint16_t *, uint16_t *, uint32_t); -__stdcall static void hal_readport_buf_uchar(uint8_t *, +__stdcall static void READ_PORT_BUFFER_UCHAR(uint8_t *, uint8_t *, uint32_t); -__stdcall static uint64_t hal_perfcount(uint64_t *); +__stdcall static uint64_t KeQueryPerformanceCounter(uint64_t *); __stdcall static void dummy (void); extern struct mtx_pool *ndis_mtxpool; __stdcall static void -hal_stall_exec_cpu(usecs) +KeStallExecutionProcessor(usecs) uint32_t usecs; { DELAY(usecs); @@ -92,7 +90,7 @@ hal_stall_exec_cpu(usecs) } __stdcall static void -hal_writeport_ulong(port, val) +WRITE_PORT_ULONG(port, val) uint32_t *port; uint32_t val; { @@ -101,7 +99,7 @@ hal_writeport_ulong(port, val) } __stdcall static void -hal_writeport_ushort(port, val) +WRITE_PORT_USHORT(port, val) uint16_t *port; uint16_t val; { @@ -110,7 +108,7 @@ hal_writeport_ushort(port, val) } __stdcall static void -hal_writeport_uchar(port, val) +WRITE_PORT_UCHAR(port, val) uint8_t *port; uint8_t val; { @@ -119,7 +117,7 @@ hal_writeport_uchar(port, val) } __stdcall static void -hal_writeport_buf_ulong(port, val, cnt) +WRITE_PORT_BUFFER_ULONG(port, val, cnt) uint32_t *port; uint32_t *val; uint32_t cnt; @@ -130,7 +128,7 @@ hal_writeport_buf_ulong(port, val, cnt) } __stdcall static void -hal_writeport_buf_ushort(port, val, cnt) +WRITE_PORT_BUFFER_USHORT(port, val, cnt) uint16_t *port; uint16_t *val; uint32_t cnt; @@ -141,7 +139,7 @@ hal_writeport_buf_ushort(port, val, cnt) } __stdcall static void -hal_writeport_buf_uchar(port, val, cnt) +WRITE_PORT_BUFFER_UCHAR(port, val, cnt) uint8_t *port; uint8_t *val; uint32_t cnt; @@ -152,28 +150,28 @@ hal_writeport_buf_uchar(port, val, cnt) } __stdcall static uint16_t -hal_readport_ushort(port) +READ_PORT_USHORT(port) uint16_t *port; { return(bus_space_read_2(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port)); } __stdcall static uint32_t -hal_readport_ulong(port) +READ_PORT_ULONG(port) uint32_t *port; { return(bus_space_read_4(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port)); } __stdcall static uint8_t -hal_readport_uchar(port) +READ_PORT_UCHAR(port) uint8_t *port; { return(bus_space_read_1(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port)); } __stdcall static void -hal_readport_buf_ulong(port, val, cnt) +READ_PORT_BUFFER_ULONG(port, val, cnt) uint32_t *port; uint32_t *val; uint32_t cnt; @@ -184,7 +182,7 @@ hal_readport_buf_ulong(port, val, cnt) } __stdcall static void -hal_readport_buf_ushort(port, val, cnt) +READ_PORT_BUFFER_USHORT(port, val, cnt) uint16_t *port; uint16_t *val; uint32_t cnt; @@ -195,7 +193,7 @@ hal_readport_buf_ushort(port, val, cnt) } __stdcall static void -hal_readport_buf_uchar(port, val, cnt) +READ_PORT_BUFFER_UCHAR(port, val, cnt) uint8_t *port; uint8_t *val; uint32_t cnt; @@ -253,31 +251,31 @@ hal_readport_buf_uchar(port, val, cnt) */ __fastcall uint8_t -hal_lock(REGARGS1(kspin_lock *lock)) +KfAcquireSpinLock(REGARGS1(kspin_lock *lock)) { uint8_t oldirql; /* I am so going to hell for this. */ - if (hal_irql() > DISPATCH_LEVEL) + if (KeGetCurrentIrql() > DISPATCH_LEVEL) panic("IRQL_NOT_LESS_THAN_OR_EQUAL"); - oldirql = FASTCALL1(hal_raise_irql, DISPATCH_LEVEL); - FASTCALL1(ntoskrnl_lock_dpc, lock); + oldirql = FASTCALL1(KfRaiseIrql, DISPATCH_LEVEL); + FASTCALL1(KefAcquireSpinLockAtDpcLevel, lock); return(oldirql); } __fastcall void -hal_unlock(REGARGS2(kspin_lock *lock, uint8_t newirql)) +KfReleaseSpinLock(REGARGS2(kspin_lock *lock, uint8_t newirql)) { - FASTCALL1(ntoskrnl_unlock_dpc, lock); - FASTCALL1(hal_lower_irql, newirql); + FASTCALL1(KefReleaseSpinLockFromDpcLevel, lock); + FASTCALL1(KfLowerIrql, newirql); return; } __stdcall uint8_t -hal_irql(void) +KeGetCurrentIrql(void) { if (AT_DISPATCH_LEVEL(curthread)) return(DISPATCH_LEVEL); @@ -285,7 +283,7 @@ hal_irql(void) } __stdcall static uint64_t -hal_perfcount(freq) +KeQueryPerformanceCounter(freq) uint64_t *freq; { if (freq != NULL) @@ -295,14 +293,14 @@ hal_perfcount(freq) } __fastcall uint8_t -hal_raise_irql(REGARGS1(uint8_t irql)) +KfRaiseIrql(REGARGS1(uint8_t irql)) { uint8_t oldirql; - if (irql < hal_irql()) + if (irql < KeGetCurrentIrql()) panic("IRQL_NOT_LESS_THAN"); - if (hal_irql() == DISPATCH_LEVEL) + if (KeGetCurrentIrql() == DISPATCH_LEVEL) return(DISPATCH_LEVEL); mtx_lock_spin(&sched_lock); @@ -314,12 +312,12 @@ hal_raise_irql(REGARGS1(uint8_t irql)) } __fastcall void -hal_lower_irql(REGARGS1(uint8_t oldirql)) +KfLowerIrql(REGARGS1(uint8_t oldirql)) { if (oldirql == DISPATCH_LEVEL) return; - if (hal_irql() != DISPATCH_LEVEL) + if (KeGetCurrentIrql() != DISPATCH_LEVEL) panic("IRQL_NOT_GREATER_THAN"); mtx_lock_spin(&sched_lock); @@ -337,25 +335,25 @@ static void dummy() } image_patch_table hal_functbl[] = { - { "KeStallExecutionProcessor", (FUNC)hal_stall_exec_cpu }, - { "WRITE_PORT_ULONG", (FUNC)hal_writeport_ulong }, - { "WRITE_PORT_USHORT", (FUNC)hal_writeport_ushort }, - { "WRITE_PORT_UCHAR", (FUNC)hal_writeport_uchar }, - { "WRITE_PORT_BUFFER_ULONG", (FUNC)hal_writeport_buf_ulong }, - { "WRITE_PORT_BUFFER_USHORT", (FUNC)hal_writeport_buf_ushort }, - { "WRITE_PORT_BUFFER_UCHAR", (FUNC)hal_writeport_buf_uchar }, - { "READ_PORT_ULONG", (FUNC)hal_readport_ulong }, - { "READ_PORT_USHORT", (FUNC)hal_readport_ushort }, - { "READ_PORT_UCHAR", (FUNC)hal_readport_uchar }, - { "READ_PORT_BUFFER_ULONG", (FUNC)hal_readport_buf_ulong }, - { "READ_PORT_BUFFER_USHORT", (FUNC)hal_readport_buf_ushort }, - { "READ_PORT_BUFFER_UCHAR", (FUNC)hal_readport_buf_uchar }, - { "KfAcquireSpinLock", (FUNC)hal_lock }, - { "KfReleaseSpinLock", (FUNC)hal_unlock }, - { "KeGetCurrentIrql", (FUNC)hal_irql }, - { "KeQueryPerformanceCounter", (FUNC)hal_perfcount }, - { "KfLowerIrql", (FUNC)hal_lower_irql }, - { "KfRaiseIrql", (FUNC)hal_raise_irql }, + IMPORT_FUNC(KeStallExecutionProcessor), + IMPORT_FUNC(WRITE_PORT_ULONG), + IMPORT_FUNC(WRITE_PORT_USHORT), + IMPORT_FUNC(WRITE_PORT_UCHAR), + IMPORT_FUNC(WRITE_PORT_BUFFER_ULONG), + IMPORT_FUNC(WRITE_PORT_BUFFER_USHORT), + IMPORT_FUNC(WRITE_PORT_BUFFER_UCHAR), + IMPORT_FUNC(READ_PORT_ULONG), + IMPORT_FUNC(READ_PORT_USHORT), + IMPORT_FUNC(READ_PORT_UCHAR), + IMPORT_FUNC(READ_PORT_BUFFER_ULONG), + IMPORT_FUNC(READ_PORT_BUFFER_USHORT), + IMPORT_FUNC(READ_PORT_BUFFER_UCHAR), + IMPORT_FUNC(KfAcquireSpinLock), + IMPORT_FUNC(KfReleaseSpinLock), + IMPORT_FUNC(KeGetCurrentIrql), + IMPORT_FUNC(KeQueryPerformanceCounter), + IMPORT_FUNC(KfLowerIrql), + IMPORT_FUNC(KfRaiseIrql), /* * This last entry is a catch-all for any function we haven't diff --git a/sys/compat/ndis/subr_ndis.c b/sys/compat/ndis/subr_ndis.c index 7953fe1..bc2b8f9 100644 --- a/sys/compat/ndis/subr_ndis.c +++ b/sys/compat/ndis/subr_ndis.c @@ -106,186 +106,191 @@ __FBSDID("$FreeBSD$"); #include #include -#define FUNC void(*)(void) - static char ndis_filepath[MAXPATHLEN]; extern struct nd_head ndis_devhead; SYSCTL_STRING(_hw, OID_AUTO, ndis_filepath, CTLFLAG_RW, ndis_filepath, MAXPATHLEN, "Path used by NdisOpenFile() to search for files"); -__stdcall static void ndis_initwrap(ndis_handle *, +__stdcall static void NdisInitializeWrapper(ndis_handle *, device_object *, void *, void *); -__stdcall static ndis_status ndis_register_miniport(ndis_handle, +__stdcall static ndis_status NdisMRegisterMiniport(ndis_handle, ndis_miniport_characteristics *, int); -__stdcall static ndis_status ndis_malloc_withtag(void **, uint32_t, uint32_t); -__stdcall static ndis_status ndis_malloc(void **, +__stdcall static ndis_status NdisAllocateMemoryWithTag(void **, + uint32_t, uint32_t); +__stdcall static ndis_status NdisAllocateMemory(void **, uint32_t, uint32_t, ndis_physaddr); -__stdcall static void ndis_free(void *, uint32_t, uint32_t); -__stdcall static ndis_status ndis_setattr_ex(ndis_handle, ndis_handle, +__stdcall static void NdisFreeMemory(void *, uint32_t, uint32_t); +__stdcall static ndis_status NdisMSetAttributesEx(ndis_handle, ndis_handle, uint32_t, uint32_t, ndis_interface_type); -__stdcall static void ndis_open_cfg(ndis_status *, ndis_handle *, ndis_handle); -__stdcall static void ndis_open_cfgbyidx(ndis_status *, ndis_handle, - uint32_t, ndis_unicode_string *, ndis_handle *); -__stdcall static void ndis_open_cfgbyname(ndis_status *, ndis_handle, - ndis_unicode_string *, ndis_handle *); +__stdcall static void NdisOpenConfiguration(ndis_status *, + ndis_handle *, ndis_handle); +__stdcall static void NdisOpenConfigurationKeyByIndex(ndis_status *, + ndis_handle, uint32_t, ndis_unicode_string *, ndis_handle *); +__stdcall static void NdisOpenConfigurationKeyByName(ndis_status *, + ndis_handle, ndis_unicode_string *, ndis_handle *); static ndis_status ndis_encode_parm(ndis_miniport_block *, struct sysctl_oid *, ndis_parm_type, ndis_config_parm **); static ndis_status ndis_decode_parm(ndis_miniport_block *, ndis_config_parm *, char *); -__stdcall static void ndis_read_cfg(ndis_status *, ndis_config_parm **, +__stdcall static void NdisReadConfiguration(ndis_status *, ndis_config_parm **, ndis_handle, ndis_unicode_string *, ndis_parm_type); -__stdcall static void ndis_write_cfg(ndis_status *, ndis_handle, +__stdcall static void NdisWriteConfiguration(ndis_status *, ndis_handle, ndis_unicode_string *, ndis_config_parm *); -__stdcall static void ndis_close_cfg(ndis_handle); -__stdcall static void ndis_create_lock(ndis_spin_lock *); -__stdcall static void ndis_destroy_lock(ndis_spin_lock *); -__stdcall static void ndis_lock(ndis_spin_lock *); -__stdcall static void ndis_unlock(ndis_spin_lock *); -__stdcall static void ndis_lock_dpr(ndis_spin_lock *); -__stdcall static void ndis_unlock_dpr(ndis_spin_lock *); -__stdcall static uint32_t ndis_read_pci(ndis_handle, uint32_t, +__stdcall static void NdisCloseConfiguration(ndis_handle); +__stdcall static void NdisAllocateSpinLock(ndis_spin_lock *); +__stdcall static void NdisFreeSpinLock(ndis_spin_lock *); +__stdcall static void NdisAcquireSpinLock(ndis_spin_lock *); +__stdcall static void NdisReleaseSpinLock(ndis_spin_lock *); +__stdcall static void NdisDprAcquireSpinLock(ndis_spin_lock *); +__stdcall static void NdisDprReleaseSpinLock(ndis_spin_lock *); +__stdcall static uint32_t NdisReadPciSlotInformation(ndis_handle, uint32_t, uint32_t, void *, uint32_t); -__stdcall static uint32_t ndis_write_pci(ndis_handle, uint32_t, +__stdcall static uint32_t NdisWritePciSlotInformation(ndis_handle, uint32_t, uint32_t, void *, uint32_t); -static void ndis_syslog(ndis_handle, ndis_error_code, uint32_t, ...); +static void NdisWriteErrorLogEntry(ndis_handle, ndis_error_code, uint32_t, ...); static void ndis_map_cb(void *, bus_dma_segment_t *, int, int); -__stdcall static void ndis_vtophys_load(ndis_handle, ndis_buffer *, - uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *); -__stdcall static void ndis_vtophys_unload(ndis_handle, ndis_buffer *, uint32_t); -__stdcall static void ndis_create_timer(ndis_miniport_timer *, ndis_handle, +__stdcall static void NdisMStartBufferPhysicalMapping(ndis_handle, + ndis_buffer *, uint32_t, uint8_t, ndis_paddr_unit *, uint32_t *); +__stdcall static void NdisMCompleteBufferPhysicalMapping(ndis_handle, + ndis_buffer *, uint32_t); +__stdcall static void NdisMInitializeTimer(ndis_miniport_timer *, ndis_handle, ndis_timer_function, void *); -__stdcall static void ndis_init_timer(ndis_timer *, +__stdcall static void NdisInitializeTimer(ndis_timer *, ndis_timer_function, void *); -__stdcall static void ndis_set_timer(ndis_timer *, uint32_t); -__stdcall static void ndis_set_periodic_timer(ndis_miniport_timer *, uint32_t); -__stdcall static void ndis_cancel_timer(ndis_timer *, uint8_t *); -__stdcall static void ndis_query_resources(ndis_status *, ndis_handle, +__stdcall static void NdisSetTimer(ndis_timer *, uint32_t); +__stdcall static void NdisMSetPeriodicTimer(ndis_miniport_timer *, uint32_t); +__stdcall static void NdisMCancelTimer(ndis_timer *, uint8_t *); +__stdcall static void NdisMQueryAdapterResources(ndis_status *, ndis_handle, ndis_resource_list *, uint32_t *); -__stdcall static ndis_status ndis_register_ioport(void **, +__stdcall static ndis_status NdisMRegisterIoPortRange(void **, ndis_handle, uint32_t, uint32_t); -__stdcall static void ndis_deregister_ioport(ndis_handle, +__stdcall static void NdisMDeregisterIoPortRange(ndis_handle, uint32_t, uint32_t, void *); -__stdcall static void ndis_read_netaddr(ndis_status *, void **, +__stdcall static void NdisReadNetworkAddress(ndis_status *, void **, uint32_t *, ndis_handle); -__stdcall static ndis_status ndis_mapreg_cnt(uint32_t, uint32_t *); -__stdcall static ndis_status ndis_alloc_mapreg(ndis_handle, +__stdcall static ndis_status NdisQueryMapRegisterCount(uint32_t, uint32_t *); +__stdcall static ndis_status NdisMAllocateMapRegisters(ndis_handle, uint32_t, uint8_t, uint32_t, uint32_t); -__stdcall static void ndis_free_mapreg(ndis_handle); +__stdcall static void NdisMFreeMapRegisters(ndis_handle); static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int); -__stdcall static void ndis_alloc_sharedmem(ndis_handle, uint32_t, +__stdcall static void NdisMAllocateSharedMemory(ndis_handle, uint32_t, uint8_t, void **, ndis_physaddr *); static void ndis_asyncmem_complete(void *); -__stdcall static ndis_status ndis_alloc_sharedmem_async(ndis_handle, +__stdcall static ndis_status NdisMAllocateSharedMemoryAsync(ndis_handle, uint32_t, uint8_t, void *); -__stdcall static void ndis_free_sharedmem(ndis_handle, uint32_t, +__stdcall static void NdisMFreeSharedMemory(ndis_handle, uint32_t, uint8_t, void *, ndis_physaddr); -__stdcall static ndis_status ndis_map_iospace(void **, ndis_handle, +__stdcall static ndis_status NdisMMapIoSpace(void **, ndis_handle, ndis_physaddr, uint32_t); -__stdcall static void ndis_unmap_iospace(ndis_handle, void *, uint32_t); -__stdcall static uint32_t ndis_cachefill(void); -__stdcall static uint32_t ndis_dma_align(ndis_handle); -__stdcall static ndis_status ndis_init_sc_dma(ndis_handle, +__stdcall static void NdisMUnmapIoSpace(ndis_handle, void *, uint32_t); +__stdcall static uint32_t NdisGetCacheFillSize(void); +__stdcall static uint32_t NdisMGetDmaAlignment(ndis_handle); +__stdcall static ndis_status NdisMInitializeScatterGatherDma(ndis_handle, uint8_t, uint32_t); -__stdcall static void ndis_alloc_packetpool(ndis_status *, +__stdcall static void NdisAllocatePacketPool(ndis_status *, ndis_handle *, uint32_t, uint32_t); -__stdcall static void ndis_ex_alloc_packetpool(ndis_status *, +__stdcall static void NdisAllocatePacketPoolEx(ndis_status *, ndis_handle *, uint32_t, uint32_t, uint32_t); -__stdcall static uint32_t ndis_packetpool_use(ndis_handle); -__stdcall static void ndis_free_packetpool(ndis_handle); -__stdcall static void ndis_alloc_packet(ndis_status *, +__stdcall static uint32_t NdisPacketPoolUsage(ndis_handle); +__stdcall static void NdisFreePacketPool(ndis_handle); +__stdcall static void NdisAllocatePacket(ndis_status *, ndis_packet **, ndis_handle); -__stdcall static void ndis_release_packet(ndis_packet *); -__stdcall static void ndis_unchain_headbuf(ndis_packet *, ndis_buffer **); -__stdcall static void ndis_unchain_tailbuf(ndis_packet *, ndis_buffer **); -__stdcall static void ndis_alloc_bufpool(ndis_status *, +__stdcall static void NdisFreePacket(ndis_packet *); +__stdcall static void NdisUnchainBufferAtFront(ndis_packet *, ndis_buffer **); +__stdcall static void NdisUnchainBufferAtBack(ndis_packet *, ndis_buffer **); +__stdcall static void NdisAllocateBufferPool(ndis_status *, ndis_handle *, uint32_t); -__stdcall static void ndis_free_bufpool(ndis_handle); -__stdcall static void ndis_alloc_buf(ndis_status *, ndis_buffer **, +__stdcall static void NdisFreeBufferPool(ndis_handle); +__stdcall static void NdisAllocateBuffer(ndis_status *, ndis_buffer **, ndis_handle, void *, uint32_t); -__stdcall static void ndis_release_buf(ndis_buffer *); -__stdcall static uint32_t ndis_buflen(ndis_buffer *); -__stdcall static void ndis_query_buf(ndis_buffer *, void **, uint32_t *); -__stdcall static void ndis_query_buf_safe(ndis_buffer *, void **, +__stdcall static void NdisFreeBuffer(ndis_buffer *); +__stdcall static uint32_t NdisBufferLength(ndis_buffer *); +__stdcall static void NdisQueryBuffer(ndis_buffer *, void **, uint32_t *); +__stdcall static void NdisQueryBufferSafe(ndis_buffer *, void **, uint32_t *, uint32_t); -__stdcall static void *ndis_buf_vaddr(ndis_buffer *); -__stdcall static void *ndis_buf_vaddr_safe(ndis_buffer *, uint32_t); -__stdcall static void ndis_adjust_buflen(ndis_buffer *, int); -__stdcall static uint32_t ndis_interlock_inc(uint32_t *); -__stdcall static uint32_t ndis_interlock_dec(uint32_t *); -__stdcall static void ndis_init_event(ndis_event *); -__stdcall static void ndis_set_event(ndis_event *); -__stdcall static void ndis_reset_event(ndis_event *); -__stdcall static uint8_t ndis_wait_event(ndis_event *, uint32_t); -__stdcall static ndis_status ndis_unicode2ansi(ndis_ansi_string *, +__stdcall static void *NdisBufferVirtualAddress(ndis_buffer *); +__stdcall static void *NdisBufferVirtualAddressSafe(ndis_buffer *, uint32_t); +__stdcall static void NdisAdjustBufferLength(ndis_buffer *, int); +__stdcall static uint32_t NdisInterlockedIncrement(uint32_t *); +__stdcall static uint32_t NdisInterlockedDecrement(uint32_t *); +__stdcall static void NdisInitializeEvent(ndis_event *); +__stdcall static void NdisSetEvent(ndis_event *); +__stdcall static void NdisResetEvent(ndis_event *); +__stdcall static uint8_t NdisWaitEvent(ndis_event *, uint32_t); +__stdcall static ndis_status NdisUnicodeStringToAnsiString(ndis_ansi_string *, ndis_unicode_string *); -__stdcall static ndis_status ndis_ansi2unicode(ndis_unicode_string *, +__stdcall static ndis_status + NdisAnsiStringToUnicodeString(ndis_unicode_string *, ndis_ansi_string *); -__stdcall static ndis_status ndis_assign_pcirsrc(ndis_handle, +__stdcall static ndis_status NdisMPciAssignResources(ndis_handle, uint32_t, ndis_resource_list **); -__stdcall static ndis_status ndis_register_intr(ndis_miniport_interrupt *, +__stdcall static ndis_status NdisMRegisterInterrupt(ndis_miniport_interrupt *, ndis_handle, uint32_t, uint32_t, uint8_t, uint8_t, ndis_interrupt_mode); -__stdcall static void ndis_deregister_intr(ndis_miniport_interrupt *); -__stdcall static void ndis_register_shutdown(ndis_handle, void *, +__stdcall static void NdisMDeregisterInterrupt(ndis_miniport_interrupt *); +__stdcall static void NdisMRegisterAdapterShutdownHandler(ndis_handle, void *, ndis_shutdown_handler); -__stdcall static void ndis_deregister_shutdown(ndis_handle); -__stdcall static uint32_t ndis_numpages(ndis_buffer *); -__stdcall static void ndis_buf_physpages(ndis_buffer *, uint32_t *); -__stdcall static void ndis_query_bufoffset(ndis_buffer *, +__stdcall static void NdisMDeregisterAdapterShutdownHandler(ndis_handle); +__stdcall static uint32_t NDIS_BUFFER_TO_SPAN_PAGES(ndis_buffer *); +__stdcall static void NdisGetBufferPhysicalArraySize(ndis_buffer *, + uint32_t *); +__stdcall static void NdisQueryBufferOffset(ndis_buffer *, uint32_t *, uint32_t *); -__stdcall static void ndis_sleep(uint32_t); -__stdcall static uint32_t ndis_read_pccard_amem(ndis_handle, +__stdcall static void NdisMSleep(uint32_t); +__stdcall static uint32_t NdisReadPcmciaAttributeMemory(ndis_handle, uint32_t, void *, uint32_t); -__stdcall static uint32_t ndis_write_pccard_amem(ndis_handle, +__stdcall static uint32_t NdisWritePcmciaAttributeMemory(ndis_handle, uint32_t, void *, uint32_t); -__stdcall static list_entry *ndis_insert_head(list_entry *, +__stdcall static list_entry *NdisInterlockedInsertHeadList(list_entry *, list_entry *, ndis_spin_lock *); -__stdcall static list_entry *ndis_remove_head(list_entry *, +__stdcall static list_entry *NdisInterlockedRemoveHeadList(list_entry *, ndis_spin_lock *); -__stdcall static list_entry *ndis_insert_tail(list_entry *, +__stdcall static list_entry *NdisInterlockedInsertTailList(list_entry *, list_entry *, ndis_spin_lock *); -__stdcall static uint8_t ndis_sync_with_intr(ndis_miniport_interrupt *, +__stdcall static uint8_t + NdisMSynchronizeWithInterrupt(ndis_miniport_interrupt *, void *, void *); -__stdcall static void ndis_time(uint64_t *); -__stdcall static void ndis_uptime(uint32_t *); -__stdcall static void ndis_init_string(ndis_unicode_string *, char *); -__stdcall static void ndis_init_ansi_string(ndis_ansi_string *, char *); -__stdcall static void ndis_init_unicode_string(ndis_unicode_string *, +__stdcall static void NdisGetCurrentSystemTime(uint64_t *); +__stdcall static void NdisGetSystemUpTime(uint32_t *); +__stdcall static void NdisInitializeString(ndis_unicode_string *, char *); +__stdcall static void NdisInitAnsiString(ndis_ansi_string *, char *); +__stdcall static void NdisInitUnicodeString(ndis_unicode_string *, uint16_t *); -__stdcall static void ndis_free_string(ndis_unicode_string *); -__stdcall static ndis_status ndis_remove_miniport(ndis_handle *); -__stdcall static void ndis_termwrap(ndis_handle, void *); -__stdcall static void ndis_get_devprop(ndis_handle, device_object **, +__stdcall static void NdisFreeString(ndis_unicode_string *); +__stdcall static ndis_status NdisMRemoveMiniport(ndis_handle *); +__stdcall static void NdisTerminateWrapper(ndis_handle, void *); +__stdcall static void NdisMGetDeviceProperty(ndis_handle, device_object **, device_object **, device_object **, cm_resource_list *, cm_resource_list *); -__stdcall static void ndis_firstbuf(ndis_packet *, ndis_buffer **, - void **, uint32_t *, uint32_t *); -__stdcall static void ndis_firstbuf_safe(ndis_packet *, ndis_buffer **, - void **, uint32_t *, uint32_t *, uint32_t); +__stdcall static void NdisGetFirstBufferFromPacket(ndis_packet *, + ndis_buffer **, void **, uint32_t *, uint32_t *); +__stdcall static void NdisGetFirstBufferFromPacketSafe(ndis_packet *, + ndis_buffer **, void **, uint32_t *, uint32_t *, uint32_t); static int ndis_find_sym(linker_file_t, char *, char *, caddr_t *); -__stdcall static void ndis_open_file(ndis_status *, ndis_handle *, uint32_t *, +__stdcall static void NdisOpenFile(ndis_status *, ndis_handle *, uint32_t *, ndis_unicode_string *, ndis_physaddr); -__stdcall static void ndis_map_file(ndis_status *, void **, ndis_handle); -__stdcall static void ndis_unmap_file(ndis_handle); -__stdcall static void ndis_close_file(ndis_handle); -__stdcall static u_int8_t ndis_cpu_cnt(void); -__stdcall static void ndis_ind_statusdone(ndis_handle); -__stdcall static void ndis_ind_status(ndis_handle, ndis_status, +__stdcall static void NdisMapFile(ndis_status *, void **, ndis_handle); +__stdcall static void NdisUnmapFile(ndis_handle); +__stdcall static void NdisCloseFile(ndis_handle); +__stdcall static u_int8_t NdisSystemProcessorCount(void); +__stdcall static void NdisMIndicateStatusComplete(ndis_handle); +__stdcall static void NdisMIndicateStatus(ndis_handle, ndis_status, void *, uint32_t); static void ndis_workfunc(void *); -__stdcall static ndis_status ndis_sched_workitem(ndis_work_item *); -__stdcall static void ndis_pkt_to_pkt(ndis_packet *, uint32_t, uint32_t, - ndis_packet *, uint32_t, uint32_t *); -__stdcall static void ndis_pkt_to_pkt_safe(ndis_packet *, uint32_t, uint32_t, - ndis_packet *, uint32_t, uint32_t *, uint32_t); -__stdcall static ndis_status ndis_register_dev(ndis_handle, +__stdcall static ndis_status NdisScheduleWorkItem(ndis_work_item *); +__stdcall static void NdisCopyFromPacketToPacket(ndis_packet *, + uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *); +__stdcall static void NdisCopyFromPacketToPacketSafe(ndis_packet *, + uint32_t, uint32_t, ndis_packet *, uint32_t, uint32_t *, uint32_t); +__stdcall static ndis_status NdisMRegisterDevice(ndis_handle, ndis_unicode_string *, ndis_unicode_string *, driver_dispatch **, void **, ndis_handle *); -__stdcall static ndis_status ndis_deregister_dev(ndis_handle); -__stdcall static ndis_status ndis_query_name(ndis_unicode_string *, +__stdcall static ndis_status NdisMDeregisterDevice(ndis_handle); +__stdcall static ndis_status + NdisMQueryAdapterInstanceName(ndis_unicode_string *, ndis_handle); -__stdcall static void ndis_register_unload(ndis_handle, void *); +__stdcall static void NdisMRegisterUnloadHandler(ndis_handle, void *); __stdcall static void dummy(void); /* @@ -363,7 +368,7 @@ ndis_unicode_to_ascii(unicode, ulen, ascii) } __stdcall static void -ndis_initwrap(wrapper, drv_obj, path, unused) +NdisInitializeWrapper(wrapper, drv_obj, path, unused) ndis_handle *wrapper; device_object *drv_obj; void *path; @@ -378,7 +383,7 @@ ndis_initwrap(wrapper, drv_obj, path, unused) } __stdcall static void -ndis_termwrap(handle, syspec) +NdisTerminateWrapper(handle, syspec) ndis_handle handle; void *syspec; { @@ -386,7 +391,7 @@ ndis_termwrap(handle, syspec) } __stdcall static ndis_status -ndis_register_miniport(handle, characteristics, len) +NdisMRegisterMiniport(handle, characteristics, len) ndis_handle handle; ndis_miniport_characteristics *characteristics; int len; @@ -409,7 +414,7 @@ ndis_register_miniport(handle, characteristics, len) } __stdcall static ndis_status -ndis_malloc_withtag(vaddr, len, tag) +NdisAllocateMemoryWithTag(vaddr, len, tag) void **vaddr; uint32_t len; uint32_t tag; @@ -425,7 +430,7 @@ ndis_malloc_withtag(vaddr, len, tag) } __stdcall static ndis_status -ndis_malloc(vaddr, len, flags, highaddr) +NdisAllocateMemory(vaddr, len, flags, highaddr) void **vaddr; uint32_t len; uint32_t flags; @@ -442,7 +447,7 @@ ndis_malloc(vaddr, len, flags, highaddr) } __stdcall static void -ndis_free(vaddr, len, flags) +NdisFreeMemory(vaddr, len, flags) void *vaddr; uint32_t len; uint32_t flags; @@ -455,7 +460,7 @@ ndis_free(vaddr, len, flags) } __stdcall static ndis_status -ndis_setattr_ex(adapter_handle, adapter_ctx, hangsecs, +NdisMSetAttributesEx(adapter_handle, adapter_ctx, hangsecs, flags, iftype) ndis_handle adapter_handle; ndis_handle adapter_ctx; @@ -478,7 +483,7 @@ ndis_setattr_ex(adapter_handle, adapter_ctx, hangsecs, } __stdcall static void -ndis_open_cfg(status, cfg, wrapctx) +NdisOpenConfiguration(status, cfg, wrapctx) ndis_status *status; ndis_handle *cfg; ndis_handle wrapctx; @@ -489,7 +494,7 @@ ndis_open_cfg(status, cfg, wrapctx) } __stdcall static void -ndis_open_cfgbyname(status, cfg, subkey, subhandle) +NdisOpenConfigurationKeyByName(status, cfg, subkey, subhandle) ndis_status *status; ndis_handle cfg; ndis_unicode_string *subkey; @@ -501,7 +506,7 @@ ndis_open_cfgbyname(status, cfg, subkey, subhandle) } __stdcall static void -ndis_open_cfgbyidx(status, cfg, idx, subkey, subhandle) +NdisOpenConfigurationKeyByIndex(status, cfg, idx, subkey, subhandle) ndis_status *status; ndis_handle cfg; uint32_t idx; @@ -607,7 +612,7 @@ ndis_strncasecmp(s1, s2, n) } __stdcall static void -ndis_read_cfg(status, parm, cfg, key, type) +NdisReadConfiguration(status, parm, cfg, key, type) ndis_status *status; ndis_config_parm **parm; ndis_handle cfg; @@ -711,7 +716,7 @@ ndis_decode_parm(block, parm, val) } __stdcall static void -ndis_write_cfg(status, cfg, key, parm) +NdisWriteConfiguration(status, cfg, key, parm) ndis_status *status; ndis_handle cfg; ndis_unicode_string *key; @@ -763,7 +768,7 @@ ndis_write_cfg(status, cfg, key, parm) } __stdcall static void -ndis_close_cfg(cfg) +NdisCloseConfiguration(cfg) ndis_handle cfg; { return; @@ -773,10 +778,10 @@ ndis_close_cfg(cfg) * Initialize a Windows spinlock. */ __stdcall static void -ndis_create_lock(lock) +NdisAllocateSpinLock(lock) ndis_spin_lock *lock; { - ntoskrnl_init_lock(&lock->nsl_spinlock); + KeInitializeSpinLock(&lock->nsl_spinlock); lock->nsl_kirql = 0; return; @@ -791,11 +796,11 @@ ndis_create_lock(lock) * talking to you.) */ __stdcall static void -ndis_destroy_lock(lock) +NdisFreeSpinLock(lock) ndis_spin_lock *lock; { #ifdef notdef - ntoskrnl_init_lock(&lock->nsl_spinlock); + KeInitializeSpinLock(&lock->nsl_spinlock); lock->nsl_kirql = 0; #endif return; @@ -806,10 +811,10 @@ ndis_destroy_lock(lock) */ __stdcall static void -ndis_lock(lock) +NdisAcquireSpinLock(lock) ndis_spin_lock *lock; { - ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); + KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql); return; } @@ -818,10 +823,10 @@ ndis_lock(lock) */ __stdcall static void -ndis_unlock(lock) +NdisReleaseSpinLock(lock) ndis_spin_lock *lock; { - ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); + KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql); return; } @@ -829,10 +834,10 @@ ndis_unlock(lock) * Acquire a spinlock when already running at IRQL == DISPATCH_LEVEL. */ __stdcall static void -ndis_lock_dpr(lock) +NdisDprAcquireSpinLock(lock) ndis_spin_lock *lock; { - FASTCALL1(ntoskrnl_lock_dpc, &lock->nsl_spinlock); + FASTCALL1(KefAcquireSpinLockAtDpcLevel, &lock->nsl_spinlock); return; } @@ -840,15 +845,15 @@ ndis_lock_dpr(lock) * Release a spinlock without leaving IRQL == DISPATCH_LEVEL. */ __stdcall static void -ndis_unlock_dpr(lock) +NdisDprReleaseSpinLock(lock) ndis_spin_lock *lock; { - FASTCALL1(ntoskrnl_unlock_dpc, &lock->nsl_spinlock); + FASTCALL1(KefReleaseSpinLockFromDpcLevel, &lock->nsl_spinlock); return; } __stdcall static uint32_t -ndis_read_pci(adapter, slot, offset, buf, len) +NdisReadPciSlotInformation(adapter, slot, offset, buf, len) ndis_handle adapter; uint32_t slot; uint32_t offset; @@ -871,7 +876,7 @@ ndis_read_pci(adapter, slot, offset, buf, len) } __stdcall static uint32_t -ndis_write_pci(adapter, slot, offset, buf, len) +NdisWritePciSlotInformation(adapter, slot, offset, buf, len) ndis_handle adapter; uint32_t slot; uint32_t offset; @@ -900,7 +905,7 @@ ndis_write_pci(adapter, slot, offset, buf, len) */ #define ERRMSGLEN 512 static void -ndis_syslog(ndis_handle adapter, ndis_error_code code, +NdisWriteErrorLogEntry(ndis_handle adapter, ndis_error_code code, uint32_t numerrors, ...) { ndis_miniport_block *block; @@ -959,7 +964,7 @@ ndis_map_cb(arg, segs, nseg, error) } __stdcall static void -ndis_vtophys_load(adapter, buf, mapreg, writedev, addrarray, arraysize) +NdisMStartBufferPhysicalMapping(adapter, buf, mapreg, writedev, addrarray, arraysize) ndis_handle adapter; ndis_buffer *buf; uint32_t mapreg; @@ -986,7 +991,7 @@ ndis_vtophys_load(adapter, buf, mapreg, writedev, addrarray, arraysize) nma.nma_fraglist = addrarray; error = bus_dmamap_load(sc->ndis_mtag, map, - MDL_VA(buf), buf->nb_bytecount, ndis_map_cb, + MmGetMdlVirtualAddress(buf), MmGetMdlByteCount(buf), ndis_map_cb, (void *)&nma, BUS_DMA_NOWAIT); if (error) @@ -1001,7 +1006,7 @@ ndis_vtophys_load(adapter, buf, mapreg, writedev, addrarray, arraysize) } __stdcall static void -ndis_vtophys_unload(adapter, buf, mapreg) +NdisMCompleteBufferPhysicalMapping(adapter, buf, mapreg) ndis_handle adapter; ndis_buffer *buf; uint32_t mapreg; @@ -1042,19 +1047,19 @@ ndis_vtophys_unload(adapter, buf, mapreg) */ __stdcall static void -ndis_init_timer(timer, func, ctx) +NdisInitializeTimer(timer, func, ctx) ndis_timer *timer; ndis_timer_function func; void *ctx; { - ntoskrnl_init_timer(&timer->nt_ktimer); - ntoskrnl_init_dpc(&timer->nt_kdpc, func, ctx); + KeInitializeTimer(&timer->nt_ktimer); + KeInitializeDpc(&timer->nt_kdpc, func, ctx); return; } __stdcall static void -ndis_create_timer(timer, handle, func, ctx) +NdisMInitializeTimer(timer, handle, func, ctx) ndis_miniport_timer *timer; ndis_handle handle; ndis_timer_function func; @@ -1066,8 +1071,8 @@ ndis_create_timer(timer, handle, func, ctx) timer->nmt_timerctx = ctx; timer->nmt_block = handle; - ntoskrnl_init_timer(&timer->nmt_ktimer); - ntoskrnl_init_dpc(&timer->nmt_kdpc, func, ctx); + KeInitializeTimer(&timer->nmt_ktimer); + KeInitializeDpc(&timer->nmt_kdpc, func, ctx); return; } @@ -1077,7 +1082,7 @@ ndis_create_timer(timer, handle, func, ctx) * but the former is just a macro wrapper around the latter. */ __stdcall static void -ndis_set_timer(timer, msecs) +NdisSetTimer(timer, msecs) ndis_timer *timer; uint32_t msecs; { @@ -1085,18 +1090,18 @@ ndis_set_timer(timer, msecs) * KeSetTimer() wants the period in * hundred nanosecond intervals. */ - ntoskrnl_set_timer(&timer->nt_ktimer, + KeSetTimer(&timer->nt_ktimer, ((int64_t)msecs * -10000), &timer->nt_kdpc); return; } __stdcall static void -ndis_set_periodic_timer(timer, msecs) +NdisMSetPeriodicTimer(timer, msecs) ndis_miniport_timer *timer; uint32_t msecs; { - ntoskrnl_set_timer_ex(&timer->nmt_ktimer, + KeSetTimerEx(&timer->nmt_ktimer, ((int64_t)msecs * -10000), msecs, &timer->nmt_kdpc); return; @@ -1110,17 +1115,17 @@ ndis_set_periodic_timer(timer, msecs) */ __stdcall static void -ndis_cancel_timer(timer, cancelled) +NdisMCancelTimer(timer, cancelled) ndis_timer *timer; uint8_t *cancelled; { - *cancelled = ntoskrnl_cancel_timer(&timer->nt_ktimer); + *cancelled = KeCancelTimer(&timer->nt_ktimer); return; } __stdcall static void -ndis_query_resources(status, adapter, list, buflen) +NdisMQueryAdapterResources(status, adapter, list, buflen) ndis_status *status; ndis_handle adapter; ndis_resource_list *list; @@ -1147,7 +1152,7 @@ ndis_query_resources(status, adapter, list, buflen) } __stdcall static ndis_status -ndis_register_ioport(offset, adapter, port, numports) +NdisMRegisterIoPortRange(offset, adapter, port, numports) void **offset; ndis_handle adapter; uint32_t port; @@ -1175,7 +1180,7 @@ ndis_register_ioport(offset, adapter, port, numports) } __stdcall static void -ndis_deregister_ioport(adapter, port, numports, offset) +NdisMDeregisterIoPortRange(adapter, port, numports, offset) ndis_handle adapter; uint32_t port; uint32_t numports; @@ -1185,7 +1190,7 @@ ndis_deregister_ioport(adapter, port, numports, offset) } __stdcall static void -ndis_read_netaddr(status, addr, addrlen, adapter) +NdisReadNetworkAddress(status, addr, addrlen, adapter) ndis_status *status; void **addr; uint32_t *addrlen; @@ -1210,7 +1215,7 @@ ndis_read_netaddr(status, addr, addrlen, adapter) } __stdcall static ndis_status -ndis_mapreg_cnt(bustype, cnt) +NdisQueryMapRegisterCount(bustype, cnt) uint32_t bustype; uint32_t *cnt; { @@ -1219,7 +1224,7 @@ ndis_mapreg_cnt(bustype, cnt) } __stdcall static ndis_status -ndis_alloc_mapreg(adapter, dmachannel, dmasize, physmapneeded, maxmap) +NdisMAllocateMapRegisters(adapter, dmachannel, dmasize, physmapneeded, maxmap) ndis_handle adapter; uint32_t dmachannel; uint8_t dmasize; @@ -1258,7 +1263,7 @@ ndis_alloc_mapreg(adapter, dmachannel, dmasize, physmapneeded, maxmap) } __stdcall static void -ndis_free_mapreg(adapter) +NdisMFreeMapRegisters(adapter) ndis_handle adapter; { struct ndis_softc *sc; @@ -1301,7 +1306,7 @@ ndis_mapshared_cb(arg, segs, nseg, error) * This maps to bus_dmamem_alloc(). */ __stdcall static void -ndis_alloc_sharedmem(adapter, len, cached, vaddr, paddr) +NdisMAllocateSharedMemory(adapter, len, cached, vaddr, paddr) ndis_handle adapter; uint32_t len; uint8_t cached; @@ -1399,7 +1404,7 @@ ndis_asyncmem_complete(arg) paddr.np_quad = 0; donefunc = sc->ndis_chars.nmc_allocate_complete_func; - ndis_alloc_sharedmem(w->na_adapter, w->na_len, + NdisMAllocateSharedMemory(w->na_adapter, w->na_len, w->na_cached, &vaddr, &paddr); donefunc(w->na_adapter, vaddr, &paddr, w->na_len, w->na_ctx); @@ -1409,7 +1414,7 @@ ndis_asyncmem_complete(arg) } __stdcall static ndis_status -ndis_alloc_sharedmem_async(adapter, len, cached, ctx) +NdisMAllocateSharedMemoryAsync(adapter, len, cached, ctx) ndis_handle adapter; uint32_t len; uint8_t cached; @@ -1443,7 +1448,7 @@ ndis_alloc_sharedmem_async(adapter, len, cached, ctx) } __stdcall static void -ndis_free_sharedmem(adapter, len, cached, vaddr, paddr) +NdisMFreeSharedMemory(adapter, len, cached, vaddr, paddr) ndis_handle adapter; uint32_t len; uint8_t cached; @@ -1483,7 +1488,7 @@ ndis_free_sharedmem(adapter, len, cached, vaddr, paddr) } __stdcall static ndis_status -ndis_map_iospace(vaddr, adapter, paddr, len) +NdisMMapIoSpace(vaddr, adapter, paddr, len) void **vaddr; ndis_handle adapter; ndis_physaddr paddr; @@ -1514,7 +1519,7 @@ ndis_map_iospace(vaddr, adapter, paddr, len) } __stdcall static void -ndis_unmap_iospace(adapter, vaddr, len) +NdisMUnmapIoSpace(adapter, vaddr, len) ndis_handle adapter; void *vaddr; uint32_t len; @@ -1523,13 +1528,13 @@ ndis_unmap_iospace(adapter, vaddr, len) } __stdcall static uint32_t -ndis_cachefill(void) +NdisGetCacheFillSize(void) { return(128); } __stdcall static uint32_t -ndis_dma_align(handle) +NdisMGetDmaAlignment(handle) ndis_handle handle; { return(128); @@ -1547,7 +1552,7 @@ ndis_dma_align(handle) */ __stdcall static ndis_status -ndis_init_sc_dma(adapter, is64, maxphysmap) +NdisMInitializeScatterGatherDma(adapter, is64, maxphysmap) ndis_handle adapter; uint8_t is64; uint32_t maxphysmap; @@ -1576,7 +1581,7 @@ ndis_init_sc_dma(adapter, is64, maxphysmap) } __stdcall static void -ndis_alloc_packetpool(status, pool, descnum, protrsvdlen) +NdisAllocatePacketPool(status, pool, descnum, protrsvdlen) ndis_status *status; ndis_handle *pool; uint32_t descnum; @@ -1607,19 +1612,19 @@ ndis_alloc_packetpool(status, pool, descnum, protrsvdlen) } __stdcall static void -ndis_ex_alloc_packetpool(status, pool, descnum, oflowdescnum, protrsvdlen) +NdisAllocatePacketPoolEx(status, pool, descnum, oflowdescnum, protrsvdlen) ndis_status *status; ndis_handle *pool; uint32_t descnum; uint32_t oflowdescnum; uint32_t protrsvdlen; { - return(ndis_alloc_packetpool(status, pool, + return(NdisAllocatePacketPool(status, pool, descnum + oflowdescnum, protrsvdlen)); } __stdcall static uint32_t -ndis_packetpool_use(pool) +NdisPacketPoolUsage(pool) ndis_handle pool; { ndis_packet *head; @@ -1630,7 +1635,7 @@ ndis_packetpool_use(pool) } __stdcall static void -ndis_free_packetpool(pool) +NdisFreePacketPool(pool) ndis_handle pool; { ndis_packet *head; @@ -1652,7 +1657,7 @@ ndis_free_packetpool(pool) } __stdcall static void -ndis_alloc_packet(status, packet, pool) +NdisAllocatePacket(status, packet, pool) ndis_status *status; ndis_packet **packet; ndis_handle pool; @@ -1708,7 +1713,7 @@ ndis_alloc_packet(status, packet, pool) } __stdcall static void -ndis_release_packet(packet) +NdisFreePacket(packet) ndis_packet *packet; { ndis_packet *head; @@ -1736,7 +1741,7 @@ ndis_release_packet(packet) } __stdcall static void -ndis_unchain_headbuf(packet, buf) +NdisUnchainBufferAtFront(packet, buf) ndis_packet *packet; ndis_buffer **buf; { @@ -1754,14 +1759,14 @@ ndis_unchain_headbuf(packet, buf) priv->npp_head = priv->npp_tail = NULL; } else { *buf = priv->npp_head; - priv->npp_head = (*buf)->nb_next; + priv->npp_head = (*buf)->mdl_next; } return; } __stdcall static void -ndis_unchain_tailbuf(packet, buf) +NdisUnchainBufferAtBack(packet, buf) ndis_packet *packet; ndis_buffer **buf; { @@ -1781,10 +1786,10 @@ ndis_unchain_tailbuf(packet, buf) } else { *buf = priv->npp_tail; tmp = priv->npp_head; - while (tmp->nb_next != priv->npp_tail) - tmp = tmp->nb_next; + while (tmp->mdl_next != priv->npp_tail) + tmp = tmp->mdl_next; priv->npp_tail = tmp; - tmp->nb_next = NULL; + tmp->mdl_next = NULL; } return; @@ -1796,11 +1801,11 @@ ndis_unchain_tailbuf(packet, buf) * The idea is you reserve a chunk of DMA-able memory using * NdisMAllocateSharedMemory() and then use NdisAllocateBuffer() * to obtain the virtual address of the DMA-able region. - * ndis_alloc_bufpool() is analagous to bus_dma_tag_create(). + * NdisAllocateBufferPool() is analagous to bus_dma_tag_create(). */ __stdcall static void -ndis_alloc_bufpool(status, pool, descnum) +NdisAllocateBufferPool(status, pool, descnum) ndis_status *status; ndis_handle *pool; uint32_t descnum; @@ -1818,11 +1823,11 @@ ndis_alloc_bufpool(status, pool, descnum) } cur = (ndis_buffer *)*pool; - cur->nb_flags = 0x1; /* mark the head of the list */ - cur->nb_bytecount = 0; /* init usage count */ - cur->nb_byteoffset = 0; /* init deletetion flag */ + cur->mdl_flags = 0x1; /* mark the head of the list */ + MmGetMdlByteCount(cur) = 0; /* init usage count */ + MmGetMdlByteOffset(cur) = 0; /* init deletetion flag */ for (i = 0; i < (descnum + NDIS_POOL_EXTRA); i++) { - cur->nb_next = cur + 1; + cur->mdl_next = cur + 1; cur++; } @@ -1831,7 +1836,7 @@ ndis_alloc_bufpool(status, pool, descnum) } __stdcall static void -ndis_free_bufpool(pool) +NdisFreeBufferPool(pool) ndis_handle pool; { ndis_buffer *head; @@ -1840,10 +1845,10 @@ ndis_free_bufpool(pool) /* Mark this pool as 'going away.' */ - head->nb_byteoffset = 1; + MmGetMdlByteOffset(head) = 1; /* If there are no buffers loaned out, destroy the pool. */ - if (head->nb_bytecount == 0) + if (MmGetMdlByteCount(head) == 0) free(pool, M_DEVBUF); else printf("NDIS: buggy driver deleting active buffer pool!\n"); @@ -1855,7 +1860,7 @@ ndis_free_bufpool(pool) * This maps to a bus_dmamap_create() and bus_dmamap_load(). */ __stdcall static void -ndis_alloc_buf(status, buffer, pool, vaddr, len) +NdisAllocateBuffer(status, buffer, pool, vaddr, len) ndis_status *status; ndis_buffer **buffer; ndis_handle pool; @@ -1865,7 +1870,7 @@ ndis_alloc_buf(status, buffer, pool, vaddr, len) ndis_buffer *head, *buf; head = (ndis_buffer *)pool; - if (head->nb_flags != 0x1) { + if (head->mdl_flags != 0x1) { *status = NDIS_STATUS_FAILURE; return; } @@ -1875,62 +1880,62 @@ ndis_alloc_buf(status, buffer, pool, vaddr, len) * more buffers out of it. */ - if (head->nb_byteoffset) { + if (MmGetMdlByteOffset(head)) { *status = NDIS_STATUS_FAILURE; return; } - buf = head->nb_next; + buf = head->mdl_next; if (buf == NULL) { *status = NDIS_STATUS_RESOURCES; return; } - head->nb_next = buf->nb_next; + head->mdl_next = buf->mdl_next; /* Save pointer to the pool. */ - buf->nb_process = head; + buf->mdl_process = head; - MDL_INIT(buf, vaddr, len); + MmInitializeMdl(buf, vaddr, len); *buffer = buf; /* Increment count of busy buffers. */ - head->nb_bytecount++; + MmGetMdlByteCount(head)++; *status = NDIS_STATUS_SUCCESS; return; } __stdcall static void -ndis_release_buf(buf) +NdisFreeBuffer(buf) ndis_buffer *buf; { ndis_buffer *head; - if (buf == NULL || buf->nb_process == NULL) + if (buf == NULL || buf->mdl_process == NULL) return; - head = buf->nb_process; + head = buf->mdl_process; - if (head->nb_flags != 0x1) + if (head->mdl_flags != 0x1) return; - buf->nb_next = head->nb_next; - head->nb_next = buf; + buf->mdl_next = head->mdl_next; + head->mdl_next = buf; /* Decrement count of busy buffers. */ - head->nb_bytecount--; + MmGetMdlByteCount(head)--; /* * If the pool has been marked for deletion and there are * no more buffers outstanding, nuke the pool. */ - if (head->nb_byteoffset && head->nb_bytecount == 0) + if (MmGetMdlByteOffset(head) && MmGetMdlByteCount(head) == 0) free(head, M_DEVBUF); return; @@ -1939,10 +1944,10 @@ ndis_release_buf(buf) /* Aw c'mon. */ __stdcall static uint32_t -ndis_buflen(buf) +NdisBufferLength(buf) ndis_buffer *buf; { - return(buf->nb_bytecount); + return(MmGetMdlByteCount(buf)); } /* @@ -1951,14 +1956,14 @@ ndis_buflen(buf) */ __stdcall static void -ndis_query_buf(buf, vaddr, len) +NdisQueryBuffer(buf, vaddr, len) ndis_buffer *buf; void **vaddr; uint32_t *len; { if (vaddr != NULL) - *vaddr = MDL_VA(buf); - *len = buf->nb_bytecount; + *vaddr = MmGetMdlVirtualAddress(buf); + *len = MmGetMdlByteCount(buf); return; } @@ -1966,15 +1971,15 @@ ndis_query_buf(buf, vaddr, len) /* Same as above -- we don't care about the priority. */ __stdcall static void -ndis_query_buf_safe(buf, vaddr, len, prio) +NdisQueryBufferSafe(buf, vaddr, len, prio) ndis_buffer *buf; void **vaddr; uint32_t *len; uint32_t prio; { if (vaddr != NULL) - *vaddr = MDL_VA(buf); - *len = buf->nb_bytecount; + *vaddr = MmGetMdlVirtualAddress(buf); + *len = MmGetMdlByteCount(buf); return; } @@ -1982,32 +1987,32 @@ ndis_query_buf_safe(buf, vaddr, len, prio) /* Damnit Microsoft!! How many ways can you do the same thing?! */ __stdcall static void * -ndis_buf_vaddr(buf) +NdisBufferVirtualAddress(buf) ndis_buffer *buf; { - return(MDL_VA(buf)); + return(MmGetMdlVirtualAddress(buf)); } __stdcall static void * -ndis_buf_vaddr_safe(buf, prio) +NdisBufferVirtualAddressSafe(buf, prio) ndis_buffer *buf; uint32_t prio; { - return(MDL_VA(buf)); + return(MmGetMdlVirtualAddress(buf)); } __stdcall static void -ndis_adjust_buflen(buf, len) +NdisAdjustBufferLength(buf, len) ndis_buffer *buf; int len; { - buf->nb_bytecount = len; + MmGetMdlByteCount(buf) = len; return; } __stdcall static uint32_t -ndis_interlock_inc(addend) +NdisInterlockedIncrement(addend) uint32_t *addend; { atomic_add_long((u_long *)addend, 1); @@ -2015,7 +2020,7 @@ ndis_interlock_inc(addend) } __stdcall static uint32_t -ndis_interlock_dec(addend) +NdisInterlockedDecrement(addend) uint32_t *addend; { atomic_subtract_long((u_long *)addend, 1); @@ -2023,7 +2028,7 @@ ndis_interlock_dec(addend) } __stdcall static void -ndis_init_event(event) +NdisInitializeEvent(event) ndis_event *event; { /* @@ -2032,28 +2037,28 @@ ndis_init_event(event) * not signaled state. */ - ntoskrnl_init_event(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE); + KeInitializeEvent(&event->ne_event, EVENT_TYPE_NOTIFY, FALSE); return; } __stdcall static void -ndis_set_event(event) +NdisSetEvent(event) ndis_event *event; { - ntoskrnl_set_event(&event->ne_event, 0, 0); + KeSetEvent(&event->ne_event, 0, 0); return; } __stdcall static void -ndis_reset_event(event) +NdisResetEvent(event) ndis_event *event; { - ntoskrnl_reset_event(&event->ne_event); + KeResetEvent(&event->ne_event); return; } __stdcall static uint8_t -ndis_wait_event(event, msecs) +NdisWaitEvent(event, msecs) ndis_event *event; uint32_t msecs; { @@ -2062,7 +2067,7 @@ ndis_wait_event(event, msecs) duetime = ((int64_t)msecs * -10000); - rval = ntoskrnl_waitforobj((nt_dispatch_header *)event, + rval = KeWaitForSingleObject((nt_dispatch_header *)event, 0, 0, TRUE, msecs ? &duetime : NULL); if (rval == STATUS_TIMEOUT) @@ -2072,7 +2077,7 @@ ndis_wait_event(event, msecs) } __stdcall static ndis_status -ndis_unicode2ansi(dstr, sstr) +NdisUnicodeStringToAnsiString(dstr, sstr) ndis_ansi_string *dstr; ndis_unicode_string *sstr; { @@ -2086,7 +2091,7 @@ ndis_unicode2ansi(dstr, sstr) } __stdcall static ndis_status -ndis_ansi2unicode(dstr, sstr) +NdisAnsiStringToUnicodeString(dstr, sstr) ndis_unicode_string *dstr; ndis_ansi_string *sstr; { @@ -2108,7 +2113,7 @@ ndis_ansi2unicode(dstr, sstr) } __stdcall static ndis_status -ndis_assign_pcirsrc(adapter, slot, list) +NdisMPciAssignResources(adapter, slot, list) ndis_handle adapter; uint32_t slot; ndis_resource_list **list; @@ -2125,7 +2130,7 @@ ndis_assign_pcirsrc(adapter, slot, list) } __stdcall static ndis_status -ndis_register_intr(intr, adapter, ivec, ilevel, reqisr, shared, imode) +NdisMRegisterInterrupt(intr, adapter, ivec, ilevel, reqisr, shared, imode) ndis_miniport_interrupt *intr; ndis_handle adapter; uint32_t ivec; @@ -2146,14 +2151,14 @@ ndis_register_intr(intr, adapter, ivec, ilevel, reqisr, shared, imode) } __stdcall static void -ndis_deregister_intr(intr) +NdisMDeregisterInterrupt(intr) ndis_miniport_interrupt *intr; { return; } __stdcall static void -ndis_register_shutdown(adapter, shutdownctx, shutdownfunc) +NdisMRegisterAdapterShutdownHandler(adapter, shutdownctx, shutdownfunc) ndis_handle adapter; void *shutdownctx; ndis_shutdown_handler shutdownfunc; @@ -2176,7 +2181,7 @@ ndis_register_shutdown(adapter, shutdownctx, shutdownfunc) } __stdcall static void -ndis_deregister_shutdown(adapter) +NdisMDeregisterAdapterShutdownHandler(adapter) ndis_handle adapter; { ndis_miniport_block *block; @@ -2197,30 +2202,31 @@ ndis_deregister_shutdown(adapter) } __stdcall static uint32_t -ndis_numpages(buf) +NDIS_BUFFER_TO_SPAN_PAGES(buf) ndis_buffer *buf; { if (buf == NULL) return(0); - if (buf->nb_bytecount == 0) + if (MmGetMdlByteCount(buf) == 0) return(1); - return(SPAN_PAGES(MDL_VA(buf), buf->nb_bytecount)); + return(SPAN_PAGES(MmGetMdlVirtualAddress(buf), + MmGetMdlByteCount(buf))); } __stdcall static void -ndis_buf_physpages(buf, pages) +NdisGetBufferPhysicalArraySize(buf, pages) ndis_buffer *buf; uint32_t *pages; { if (buf == NULL) return; - *pages = ndis_numpages(buf); + *pages = NDIS_BUFFER_TO_SPAN_PAGES(buf); return; } __stdcall static void -ndis_query_bufoffset(buf, off, len) +NdisQueryBufferOffset(buf, off, len) ndis_buffer *buf; uint32_t *off; uint32_t *len; @@ -2228,14 +2234,14 @@ ndis_query_bufoffset(buf, off, len) if (buf == NULL) return; - *off = buf->nb_byteoffset; - *len = buf->nb_bytecount; + *off = MmGetMdlByteOffset(buf); + *len = MmGetMdlByteCount(buf); return; } __stdcall static void -ndis_sleep(usecs) +NdisMSleep(usecs) uint32_t usecs; { struct timeval tv; @@ -2249,7 +2255,7 @@ ndis_sleep(usecs) } __stdcall static uint32_t -ndis_read_pccard_amem(handle, offset, buf, len) +NdisReadPcmciaAttributeMemory(handle, offset, buf, len) ndis_handle handle; uint32_t offset; void *buf; @@ -2279,7 +2285,7 @@ ndis_read_pccard_amem(handle, offset, buf, len) } __stdcall static uint32_t -ndis_write_pccard_amem(handle, offset, buf, len) +NdisWritePcmciaAttributeMemory(handle, offset, buf, len) ndis_handle handle; uint32_t offset; void *buf; @@ -2309,63 +2315,63 @@ ndis_write_pccard_amem(handle, offset, buf, len) } __stdcall static list_entry * -ndis_insert_head(head, entry, lock) +NdisInterlockedInsertHeadList(head, entry, lock) list_entry *head; list_entry *entry; ndis_spin_lock *lock; { list_entry *flink; - ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); + KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql); flink = head->nle_flink; entry->nle_flink = flink; entry->nle_blink = head; flink->nle_blink = entry; head->nle_flink = entry; - ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); + KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql); return(flink); } __stdcall static list_entry * -ndis_remove_head(head, lock) +NdisInterlockedRemoveHeadList(head, lock) list_entry *head; ndis_spin_lock *lock; { list_entry *flink; list_entry *entry; - ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); + KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql); entry = head->nle_flink; flink = entry->nle_flink; head->nle_flink = flink; flink->nle_blink = head; - ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); + KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql); return(entry); } __stdcall static list_entry * -ndis_insert_tail(head, entry, lock) +NdisInterlockedInsertTailList(head, entry, lock) list_entry *head; list_entry *entry; ndis_spin_lock *lock; { list_entry *blink; - ntoskrnl_acquire_spinlock(&lock->nsl_spinlock, &lock->nsl_kirql); + KeAcquireSpinLock(&lock->nsl_spinlock, &lock->nsl_kirql); blink = head->nle_blink; entry->nle_flink = head; entry->nle_blink = blink; blink->nle_flink = entry; head->nle_blink = entry; - ntoskrnl_release_spinlock(&lock->nsl_spinlock, lock->nsl_kirql); + KeReleaseSpinLock(&lock->nsl_spinlock, lock->nsl_kirql); return(blink); } __stdcall static uint8_t -ndis_sync_with_intr(intr, syncfunc, syncctx) +NdisMSynchronizeWithInterrupt(intr, syncfunc, syncctx) ndis_miniport_interrupt *intr; void *syncfunc; void *syncctx; @@ -2391,7 +2397,7 @@ ndis_sync_with_intr(intr, syncfunc, syncctx) * January 1, 1601. (?!?!) */ __stdcall static void -ndis_time(tval) +NdisGetCurrentSystemTime(tval) uint64_t *tval; { struct timespec ts; @@ -2407,7 +2413,7 @@ ndis_time(tval) * Return the number of milliseconds since the system booted. */ __stdcall static void -ndis_uptime(tval) +NdisGetSystemUpTime(tval) uint32_t *tval; { struct timespec ts; @@ -2419,7 +2425,7 @@ ndis_uptime(tval) } __stdcall static void -ndis_init_string(dst, src) +NdisInitializeString(dst, src) ndis_unicode_string *dst; char *src; { @@ -2434,7 +2440,7 @@ ndis_init_string(dst, src) } __stdcall static void -ndis_free_string(str) +NdisFreeString(str) ndis_unicode_string *str; { if (str == NULL) @@ -2446,14 +2452,14 @@ ndis_free_string(str) } __stdcall static ndis_status -ndis_remove_miniport(adapter) +NdisMRemoveMiniport(adapter) ndis_handle *adapter; { return(NDIS_STATUS_SUCCESS); } __stdcall static void -ndis_init_ansi_string(dst, src) +NdisInitAnsiString(dst, src) ndis_ansi_string *dst; char *src; { @@ -2474,7 +2480,7 @@ ndis_init_ansi_string(dst, src) } __stdcall static void -ndis_init_unicode_string(dst, src) +NdisInitUnicodeString(dst, src) ndis_unicode_string *dst; uint16_t *src; { @@ -2498,7 +2504,7 @@ ndis_init_unicode_string(dst, src) return; } -__stdcall static void ndis_get_devprop(adapter, phydevobj, +__stdcall static void NdisMGetDeviceProperty(adapter, phydevobj, funcdevobj, nextdevobj, resources, transresources) ndis_handle adapter; device_object **phydevobj; @@ -2520,7 +2526,7 @@ __stdcall static void ndis_get_devprop(adapter, phydevobj, } __stdcall static void -ndis_firstbuf(packet, buf, firstva, firstlen, totlen) +NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen) ndis_packet *packet; ndis_buffer **buf; void **firstva; @@ -2535,17 +2541,17 @@ ndis_firstbuf(packet, buf, firstva, firstlen, totlen) *firstva = NULL; *firstlen = *totlen = 0; } else { - *firstva = MDL_VA(tmp); - *firstlen = *totlen = tmp->nb_bytecount; - for (tmp = tmp->nb_next; tmp != NULL; tmp = tmp->nb_next) - *totlen += tmp->nb_bytecount; + *firstva = MmGetMdlVirtualAddress(tmp); + *firstlen = *totlen = MmGetMdlByteCount(tmp); + for (tmp = tmp->mdl_next; tmp != NULL; tmp = tmp->mdl_next) + *totlen += MmGetMdlByteCount(tmp); } return; } __stdcall static void -ndis_firstbuf_safe(packet, buf, firstva, firstlen, totlen, prio) +NdisGetFirstBufferFromPacketSafe(packet, buf, firstva, firstlen, totlen, prio) ndis_packet *packet; ndis_buffer **buf; void **firstva; @@ -2553,7 +2559,7 @@ ndis_firstbuf_safe(packet, buf, firstva, firstlen, totlen, prio) uint32_t *totlen; uint32_t prio; { - ndis_firstbuf(packet, buf, firstva, firstlen, totlen); + NdisGetFirstBufferFromPacket(packet, buf, firstva, firstlen, totlen); } static int @@ -2593,7 +2599,7 @@ ndis_find_sym(lf, filename, suffix, sym) /* can also return NDIS_STATUS_RESOURCES/NDIS_STATUS_ERROR_READING_FILE */ __stdcall static void -ndis_open_file(status, filehandle, filelength, filename, highestaddr) +NdisOpenFile(status, filehandle, filelength, filename, highestaddr) ndis_status *status; ndis_handle *filehandle; uint32_t *filelength; @@ -2715,7 +2721,7 @@ ndis_open_file(status, filehandle, filelength, filename, highestaddr) } __stdcall static void -ndis_map_file(status, mappedbuffer, filehandle) +NdisMapFile(status, mappedbuffer, filehandle) ndis_status *status; void **mappedbuffer; ndis_handle filehandle; @@ -2778,7 +2784,7 @@ ndis_map_file(status, mappedbuffer, filehandle) } __stdcall static void -ndis_unmap_file(filehandle) +NdisUnmapFile(filehandle) ndis_handle filehandle; { ndis_fh *fh; @@ -2795,7 +2801,7 @@ ndis_unmap_file(filehandle) } __stdcall static void -ndis_close_file(filehandle) +NdisCloseFile(filehandle) ndis_handle filehandle; { struct thread *td = curthread; @@ -2827,7 +2833,7 @@ ndis_close_file(filehandle) } __stdcall static uint8_t -ndis_cpu_cnt() +NdisSystemProcessorCount() { return(mp_ncpus); } @@ -2837,7 +2843,7 @@ typedef void (*ndis_status_handler)(ndis_handle, ndis_status, void *, uint32_t); __stdcall static void -ndis_ind_statusdone(adapter) +NdisMIndicateStatusComplete(adapter) ndis_handle adapter; { ndis_miniport_block *block; @@ -2851,7 +2857,7 @@ ndis_ind_statusdone(adapter) } __stdcall static void -ndis_ind_status(adapter, status, sbuf, slen) +NdisMIndicateStatus(adapter, status, sbuf, slen) ndis_handle adapter; ndis_status status; void *sbuf; @@ -2881,7 +2887,7 @@ ndis_workfunc(ctx) } __stdcall static ndis_status -ndis_sched_workitem(work) +NdisScheduleWorkItem(work) ndis_work_item *work; { ndis_sched(ndis_workfunc, work, NDIS_TASKQUEUE); @@ -2889,7 +2895,7 @@ ndis_sched_workitem(work) } __stdcall static void -ndis_pkt_to_pkt(dpkt, doff, reqlen, spkt, soff, cpylen) +NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen) ndis_packet *dpkt; uint32_t doff; uint32_t reqlen; @@ -2906,35 +2912,35 @@ ndis_pkt_to_pkt(dpkt, doff, reqlen, spkt, soff, cpylen) src = spkt->np_private.npp_head; dst = dpkt->np_private.npp_head; - sptr = MDL_VA(src); - dptr = MDL_VA(dst); - scnt = src->nb_bytecount; - dcnt = dst->nb_bytecount; + sptr = MmGetMdlVirtualAddress(src); + dptr = MmGetMdlVirtualAddress(dst); + scnt = MmGetMdlByteCount(src); + dcnt = MmGetMdlByteCount(dst); while (soff) { - if (src->nb_bytecount > soff) { + if (MmGetMdlByteCount(src) > soff) { sptr += soff; - scnt = src->nb_bytecount - soff; + scnt = MmGetMdlByteCount(src)- soff; break; } - soff -= src->nb_bytecount; - src = src->nb_next; + soff -= MmGetMdlByteCount(src); + src = src->mdl_next; if (src == NULL) return; - sptr = MDL_VA(src); + sptr = MmGetMdlVirtualAddress(src); } while (doff) { - if (dst->nb_bytecount > doff) { + if (MmGetMdlByteCount(dst) > doff) { dptr += doff; - dcnt = dst->nb_bytecount - doff; + dcnt = MmGetMdlByteCount(dst) - doff; break; } - doff -= dst->nb_bytecount; - dst = dst->nb_next; + doff -= MmGetMdlByteCount(dst); + dst = dst->mdl_next; if (dst == NULL) return; - dptr = MDL_VA(dst); + dptr = MmGetMdlVirtualAddress(dst); } resid = reqlen; @@ -2957,20 +2963,20 @@ ndis_pkt_to_pkt(dpkt, doff, reqlen, spkt, soff, cpylen) dcnt -= len; if (dcnt == 0) { - dst = dst->nb_next; + dst = dst->mdl_next; if (dst == NULL) break; - dptr = MDL_VA(dst); - dcnt = dst->nb_bytecount; + dptr = MmGetMdlVirtualAddress(dst); + dcnt = MmGetMdlByteCount(dst); } scnt -= len; if (scnt == 0) { - src = src->nb_next; + src = src->mdl_next; if (src == NULL) break; - sptr = MDL_VA(src); - scnt = src->nb_bytecount; + sptr = MmGetMdlVirtualAddress(src); + scnt = MmGetMdlByteCount(src); } } @@ -2979,7 +2985,7 @@ ndis_pkt_to_pkt(dpkt, doff, reqlen, spkt, soff, cpylen) } __stdcall static void -ndis_pkt_to_pkt_safe(dpkt, doff, reqlen, spkt, soff, cpylen, prio) +NdisCopyFromPacketToPacketSafe(dpkt, doff, reqlen, spkt, soff, cpylen, prio) ndis_packet *dpkt; uint32_t doff; uint32_t reqlen; @@ -2988,12 +2994,12 @@ ndis_pkt_to_pkt_safe(dpkt, doff, reqlen, spkt, soff, cpylen, prio) uint32_t *cpylen; uint32_t prio; { - ndis_pkt_to_pkt(dpkt, doff, reqlen, spkt, soff, cpylen); + NdisCopyFromPacketToPacket(dpkt, doff, reqlen, spkt, soff, cpylen); return; } __stdcall static ndis_status -ndis_register_dev(handle, devname, symname, majorfuncs, devobj, devhandle) +NdisMRegisterDevice(handle, devname, symname, majorfuncs, devobj, devhandle) ndis_handle handle; ndis_unicode_string *devname; ndis_unicode_string *symname; @@ -3011,14 +3017,14 @@ ndis_register_dev(handle, devname, symname, majorfuncs, devobj, devhandle) } __stdcall static ndis_status -ndis_deregister_dev(handle) +NdisMDeregisterDevice(handle) ndis_handle handle; { return(NDIS_STATUS_SUCCESS); } __stdcall static ndis_status -ndis_query_name(name, handle) +NdisMQueryAdapterInstanceName(name, handle) ndis_unicode_string *name; ndis_handle handle; { @@ -3033,7 +3039,7 @@ ndis_query_name(name, handle) } __stdcall static void -ndis_register_unload(handle, func) +NdisMRegisterUnloadHandler(handle, func) ndis_handle handle; void *func; { @@ -3048,120 +3054,122 @@ dummy() } image_patch_table ndis_functbl[] = { - { "NdisCopyFromPacketToPacket", (FUNC)ndis_pkt_to_pkt }, - { "NdisCopyFromPacketToPacketSafe", (FUNC)ndis_pkt_to_pkt_safe }, - { "NdisScheduleWorkItem", (FUNC)ndis_sched_workitem }, - { "NdisMIndicateStatusComplete", (FUNC)ndis_ind_statusdone }, - { "NdisMIndicateStatus", (FUNC)ndis_ind_status }, - { "NdisSystemProcessorCount", (FUNC)ndis_cpu_cnt }, - { "NdisUnchainBufferAtBack", (FUNC)ndis_unchain_tailbuf, }, - { "NdisGetFirstBufferFromPacket", (FUNC)ndis_firstbuf }, - { "NdisGetFirstBufferFromPacketSafe", (FUNC)ndis_firstbuf_safe }, - { "NdisGetBufferPhysicalArraySize", (FUNC)ndis_buf_physpages }, - { "NdisMGetDeviceProperty", (FUNC)ndis_get_devprop }, - { "NdisInitAnsiString", (FUNC)ndis_init_ansi_string }, - { "NdisInitUnicodeString", (FUNC)ndis_init_unicode_string }, - { "NdisWriteConfiguration", (FUNC)ndis_write_cfg }, - { "NdisAnsiStringToUnicodeString", (FUNC)ndis_ansi2unicode }, - { "NdisTerminateWrapper", (FUNC)ndis_termwrap }, - { "NdisOpenConfigurationKeyByName", (FUNC)ndis_open_cfgbyname }, - { "NdisOpenConfigurationKeyByIndex", (FUNC)ndis_open_cfgbyidx }, - { "NdisMRemoveMiniport", (FUNC)ndis_remove_miniport }, - { "NdisInitializeString", (FUNC)ndis_init_string }, - { "NdisFreeString", (FUNC)ndis_free_string }, - { "NdisGetCurrentSystemTime", (FUNC)ndis_time }, - { "NdisGetSystemUpTime", (FUNC)ndis_uptime }, - { "NdisMSynchronizeWithInterrupt", (FUNC)ndis_sync_with_intr }, - { "NdisMAllocateSharedMemoryAsync", (FUNC)ndis_alloc_sharedmem_async }, - { "NdisInterlockedInsertHeadList", (FUNC)ndis_insert_head }, - { "NdisInterlockedInsertTailList", (FUNC)ndis_insert_tail }, - { "NdisInterlockedRemoveHeadList", (FUNC)ndis_remove_head }, - { "NdisInitializeWrapper", (FUNC)ndis_initwrap }, - { "NdisMRegisterMiniport", (FUNC)ndis_register_miniport }, - { "NdisAllocateMemoryWithTag", (FUNC)ndis_malloc_withtag }, - { "NdisAllocateMemory", (FUNC)ndis_malloc }, - { "NdisMSetAttributesEx", (FUNC)ndis_setattr_ex }, - { "NdisCloseConfiguration", (FUNC)ndis_close_cfg }, - { "NdisReadConfiguration", (FUNC)ndis_read_cfg }, - { "NdisOpenConfiguration", (FUNC)ndis_open_cfg }, - { "NdisAcquireSpinLock", (FUNC)ndis_lock }, - { "NdisReleaseSpinLock", (FUNC)ndis_unlock }, - { "NdisDprAcquireSpinLock", (FUNC)ndis_lock_dpr }, - { "NdisDprReleaseSpinLock", (FUNC)ndis_unlock_dpr }, - { "NdisAllocateSpinLock", (FUNC)ndis_create_lock }, - { "NdisFreeSpinLock", (FUNC)ndis_destroy_lock }, - { "NdisFreeMemory", (FUNC)ndis_free }, - { "NdisReadPciSlotInformation", (FUNC)ndis_read_pci }, - { "NdisWritePciSlotInformation",(FUNC)ndis_write_pci }, - { "NdisImmediateReadPciSlotInformation", (FUNC)ndis_read_pci }, - { "NdisImmediateWritePciSlotInformation", (FUNC)ndis_write_pci }, - { "NdisWriteErrorLogEntry", (FUNC)ndis_syslog }, - { "NdisMStartBufferPhysicalMapping", (FUNC)ndis_vtophys_load }, - { "NdisMCompleteBufferPhysicalMapping", (FUNC)ndis_vtophys_unload }, - { "NdisMInitializeTimer", (FUNC)ndis_create_timer }, - { "NdisInitializeTimer", (FUNC)ndis_init_timer }, - { "NdisSetTimer", (FUNC)ndis_set_timer }, - { "NdisMCancelTimer", (FUNC)ndis_cancel_timer }, - { "NdisCancelTimer", (FUNC)ndis_cancel_timer }, - { "NdisMSetPeriodicTimer", (FUNC)ndis_set_periodic_timer }, - { "NdisMQueryAdapterResources", (FUNC)ndis_query_resources }, - { "NdisMRegisterIoPortRange", (FUNC)ndis_register_ioport }, - { "NdisMDeregisterIoPortRange", (FUNC)ndis_deregister_ioport }, - { "NdisReadNetworkAddress", (FUNC)ndis_read_netaddr }, - { "NdisQueryMapRegisterCount", (FUNC)ndis_mapreg_cnt }, - { "NdisMAllocateMapRegisters", (FUNC)ndis_alloc_mapreg }, - { "NdisMFreeMapRegisters", (FUNC)ndis_free_mapreg }, - { "NdisMAllocateSharedMemory", (FUNC)ndis_alloc_sharedmem }, - { "NdisMMapIoSpace", (FUNC)ndis_map_iospace }, - { "NdisMUnmapIoSpace", (FUNC)ndis_unmap_iospace }, - { "NdisGetCacheFillSize", (FUNC)ndis_cachefill }, - { "NdisMGetDmaAlignment", (FUNC)ndis_dma_align }, - { "NdisMInitializeScatterGatherDma", (FUNC)ndis_init_sc_dma }, - { "NdisAllocatePacketPool", (FUNC)ndis_alloc_packetpool }, - { "NdisAllocatePacketPoolEx", (FUNC)ndis_ex_alloc_packetpool }, - { "NdisAllocatePacket", (FUNC)ndis_alloc_packet }, - { "NdisFreePacket", (FUNC)ndis_release_packet }, - { "NdisFreePacketPool", (FUNC)ndis_free_packetpool }, - { "NdisDprAllocatePacket", (FUNC)ndis_alloc_packet }, - { "NdisDprFreePacket", (FUNC)ndis_release_packet }, - { "NdisAllocateBufferPool", (FUNC)ndis_alloc_bufpool }, - { "NdisAllocateBuffer", (FUNC)ndis_alloc_buf }, - { "NdisQueryBuffer", (FUNC)ndis_query_buf }, - { "NdisQueryBufferSafe", (FUNC)ndis_query_buf_safe }, - { "NdisBufferVirtualAddress", (FUNC)ndis_buf_vaddr }, - { "NdisBufferVirtualAddressSafe", (FUNC)ndis_buf_vaddr_safe }, - { "NdisBufferLength", (FUNC)ndis_buflen }, - { "NdisFreeBuffer", (FUNC)ndis_release_buf }, - { "NdisFreeBufferPool", (FUNC)ndis_free_bufpool }, - { "NdisInterlockedIncrement", (FUNC)ndis_interlock_inc }, - { "NdisInterlockedDecrement", (FUNC)ndis_interlock_dec }, - { "NdisInitializeEvent", (FUNC)ndis_init_event }, - { "NdisSetEvent", (FUNC)ndis_set_event }, - { "NdisResetEvent", (FUNC)ndis_reset_event }, - { "NdisWaitEvent", (FUNC)ndis_wait_event }, - { "NdisUnicodeStringToAnsiString", (FUNC)ndis_unicode2ansi }, - { "NdisMPciAssignResources", (FUNC)ndis_assign_pcirsrc }, - { "NdisMFreeSharedMemory", (FUNC)ndis_free_sharedmem }, - { "NdisMRegisterInterrupt", (FUNC)ndis_register_intr }, - { "NdisMDeregisterInterrupt", (FUNC)ndis_deregister_intr }, - { "NdisMRegisterAdapterShutdownHandler", (FUNC)ndis_register_shutdown }, - { "NdisMDeregisterAdapterShutdownHandler", (FUNC)ndis_deregister_shutdown }, - { "NDIS_BUFFER_TO_SPAN_PAGES", (FUNC)ndis_numpages }, - { "NdisQueryBufferOffset", (FUNC)ndis_query_bufoffset }, - { "NdisAdjustBufferLength", (FUNC)ndis_adjust_buflen }, - { "NdisPacketPoolUsage", (FUNC)ndis_packetpool_use }, - { "NdisMSleep", (FUNC)ndis_sleep }, - { "NdisUnchainBufferAtFront", (FUNC)ndis_unchain_headbuf }, - { "NdisReadPcmciaAttributeMemory", (FUNC)ndis_read_pccard_amem }, - { "NdisWritePcmciaAttributeMemory", (FUNC)ndis_write_pccard_amem }, - { "NdisOpenFile", (FUNC)ndis_open_file }, - { "NdisMapFile", (FUNC)ndis_map_file }, - { "NdisUnmapFile", (FUNC)ndis_unmap_file }, - { "NdisCloseFile", (FUNC)ndis_close_file }, - { "NdisMRegisterDevice", (FUNC)ndis_register_dev }, - { "NdisMDeregisterDevice", (FUNC)ndis_deregister_dev }, - { "NdisMQueryAdapterInstanceName", (FUNC)ndis_query_name }, - { "NdisMRegisterUnloadHandler", (FUNC)ndis_register_unload }, + IMPORT_FUNC(NdisCopyFromPacketToPacket), + IMPORT_FUNC(NdisCopyFromPacketToPacketSafe), + IMPORT_FUNC(NdisScheduleWorkItem), + IMPORT_FUNC(NdisMIndicateStatusComplete), + IMPORT_FUNC(NdisMIndicateStatus), + IMPORT_FUNC(NdisSystemProcessorCount), + IMPORT_FUNC(NdisUnchainBufferAtBack), + IMPORT_FUNC(NdisGetFirstBufferFromPacket), + IMPORT_FUNC(NdisGetFirstBufferFromPacketSafe), + IMPORT_FUNC(NdisGetBufferPhysicalArraySize), + IMPORT_FUNC(NdisMGetDeviceProperty), + IMPORT_FUNC(NdisInitAnsiString), + IMPORT_FUNC(NdisInitUnicodeString), + IMPORT_FUNC(NdisWriteConfiguration), + IMPORT_FUNC(NdisAnsiStringToUnicodeString), + IMPORT_FUNC(NdisTerminateWrapper), + IMPORT_FUNC(NdisOpenConfigurationKeyByName), + IMPORT_FUNC(NdisOpenConfigurationKeyByIndex), + IMPORT_FUNC(NdisMRemoveMiniport), + IMPORT_FUNC(NdisInitializeString), + IMPORT_FUNC(NdisFreeString), + IMPORT_FUNC(NdisGetCurrentSystemTime), + IMPORT_FUNC(NdisGetSystemUpTime), + IMPORT_FUNC(NdisMSynchronizeWithInterrupt), + IMPORT_FUNC(NdisMAllocateSharedMemoryAsync), + IMPORT_FUNC(NdisInterlockedInsertHeadList), + IMPORT_FUNC(NdisInterlockedInsertTailList), + IMPORT_FUNC(NdisInterlockedRemoveHeadList), + IMPORT_FUNC(NdisInitializeWrapper), + IMPORT_FUNC(NdisMRegisterMiniport), + IMPORT_FUNC(NdisAllocateMemoryWithTag), + IMPORT_FUNC(NdisAllocateMemory), + IMPORT_FUNC(NdisMSetAttributesEx), + IMPORT_FUNC(NdisCloseConfiguration), + IMPORT_FUNC(NdisReadConfiguration), + IMPORT_FUNC(NdisOpenConfiguration), + IMPORT_FUNC(NdisAcquireSpinLock), + IMPORT_FUNC(NdisReleaseSpinLock), + IMPORT_FUNC(NdisDprAcquireSpinLock), + IMPORT_FUNC(NdisDprReleaseSpinLock), + IMPORT_FUNC(NdisAllocateSpinLock), + IMPORT_FUNC(NdisFreeSpinLock), + IMPORT_FUNC(NdisFreeMemory), + IMPORT_FUNC(NdisReadPciSlotInformation), + IMPORT_FUNC(NdisWritePciSlotInformation), + IMPORT_FUNC_MAP(NdisImmediateReadPciSlotInformation, + NdisReadPciSlotInformation), + IMPORT_FUNC_MAP(NdisImmediateWritePciSlotInformation, + NdisWritePciSlotInformation), + IMPORT_FUNC(NdisWriteErrorLogEntry), + IMPORT_FUNC(NdisMStartBufferPhysicalMapping), + IMPORT_FUNC(NdisMCompleteBufferPhysicalMapping), + IMPORT_FUNC(NdisMInitializeTimer), + IMPORT_FUNC(NdisInitializeTimer), + IMPORT_FUNC(NdisSetTimer), + IMPORT_FUNC(NdisMCancelTimer), + IMPORT_FUNC_MAP(NdisCancelTimer, NdisMCancelTimer), + IMPORT_FUNC(NdisMSetPeriodicTimer), + IMPORT_FUNC(NdisMQueryAdapterResources), + IMPORT_FUNC(NdisMRegisterIoPortRange), + IMPORT_FUNC(NdisMDeregisterIoPortRange), + IMPORT_FUNC(NdisReadNetworkAddress), + IMPORT_FUNC(NdisQueryMapRegisterCount), + IMPORT_FUNC(NdisMAllocateMapRegisters), + IMPORT_FUNC(NdisMFreeMapRegisters), + IMPORT_FUNC(NdisMAllocateSharedMemory), + IMPORT_FUNC(NdisMMapIoSpace), + IMPORT_FUNC(NdisMUnmapIoSpace), + IMPORT_FUNC(NdisGetCacheFillSize), + IMPORT_FUNC(NdisMGetDmaAlignment), + IMPORT_FUNC(NdisMInitializeScatterGatherDma), + IMPORT_FUNC(NdisAllocatePacketPool), + IMPORT_FUNC(NdisAllocatePacketPoolEx), + IMPORT_FUNC(NdisAllocatePacket), + IMPORT_FUNC(NdisFreePacket), + IMPORT_FUNC(NdisFreePacketPool), + IMPORT_FUNC_MAP(NdisDprAllocatePacket, NdisAllocatePacket), + IMPORT_FUNC_MAP(NdisDprFreePacket, NdisFreePacket), + IMPORT_FUNC(NdisAllocateBufferPool), + IMPORT_FUNC(NdisAllocateBuffer), + IMPORT_FUNC(NdisQueryBuffer), + IMPORT_FUNC(NdisQueryBufferSafe), + IMPORT_FUNC(NdisBufferVirtualAddress), + IMPORT_FUNC(NdisBufferVirtualAddressSafe), + IMPORT_FUNC(NdisBufferLength), + IMPORT_FUNC(NdisFreeBuffer), + IMPORT_FUNC(NdisFreeBufferPool), + IMPORT_FUNC(NdisInterlockedIncrement), + IMPORT_FUNC(NdisInterlockedDecrement), + IMPORT_FUNC(NdisInitializeEvent), + IMPORT_FUNC(NdisSetEvent), + IMPORT_FUNC(NdisResetEvent), + IMPORT_FUNC(NdisWaitEvent), + IMPORT_FUNC(NdisUnicodeStringToAnsiString), + IMPORT_FUNC(NdisMPciAssignResources), + IMPORT_FUNC(NdisMFreeSharedMemory), + IMPORT_FUNC(NdisMRegisterInterrupt), + IMPORT_FUNC(NdisMDeregisterInterrupt), + IMPORT_FUNC(NdisMRegisterAdapterShutdownHandler), + IMPORT_FUNC(NdisMDeregisterAdapterShutdownHandler), + IMPORT_FUNC(NDIS_BUFFER_TO_SPAN_PAGES), + IMPORT_FUNC(NdisQueryBufferOffset), + IMPORT_FUNC(NdisAdjustBufferLength), + IMPORT_FUNC(NdisPacketPoolUsage), + IMPORT_FUNC(NdisMSleep), + IMPORT_FUNC(NdisUnchainBufferAtFront), + IMPORT_FUNC(NdisReadPcmciaAttributeMemory), + IMPORT_FUNC(NdisWritePcmciaAttributeMemory), + IMPORT_FUNC(NdisOpenFile), + IMPORT_FUNC(NdisMapFile), + IMPORT_FUNC(NdisUnmapFile), + IMPORT_FUNC(NdisCloseFile), + IMPORT_FUNC(NdisMRegisterDevice), + IMPORT_FUNC(NdisMDeregisterDevice), + IMPORT_FUNC(NdisMQueryAdapterInstanceName), + IMPORT_FUNC(NdisMRegisterUnloadHandler), /* * This last entry is a catch-all for any function we haven't diff --git a/sys/compat/ndis/subr_ntoskrnl.c b/sys/compat/ndis/subr_ntoskrnl.c index 5cfa724..e78795e 100644 --- a/sys/compat/ndis/subr_ntoskrnl.c +++ b/sys/compat/ndis/subr_ntoskrnl.c @@ -61,6 +61,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include +#include + #include #include #include @@ -69,34 +73,28 @@ __FBSDID("$FreeBSD$"); #define __regparm __attribute__((regparm(3))) -#define FUNC void(*)(void) - -__stdcall static uint8_t ntoskrnl_unicode_equal(ndis_unicode_string *, +__stdcall static uint8_t RtlEqualUnicodeString(ndis_unicode_string *, ndis_unicode_string *, uint8_t); -__stdcall static void ntoskrnl_unicode_copy(ndis_unicode_string *, +__stdcall static void RtlCopyUnicodeString(ndis_unicode_string *, ndis_unicode_string *); -__stdcall static ndis_status ntoskrnl_unicode_to_ansi(ndis_ansi_string *, +__stdcall static ndis_status RtlUnicodeStringToAnsiString(ndis_ansi_string *, ndis_unicode_string *, uint8_t); -__stdcall static ndis_status ntoskrnl_ansi_to_unicode(ndis_unicode_string *, +__stdcall static ndis_status RtlAnsiStringToUnicodeString(ndis_unicode_string *, ndis_ansi_string *, uint8_t); -__stdcall static void *ntoskrnl_iobuildsynchfsdreq(uint32_t, void *, +__stdcall static void *IoBuildSynchronousFsdRequest(uint32_t, void *, void *, uint32_t, uint32_t *, void *, void *); -__fastcall static uint32_t ntoskrnl_iofcalldriver(REGARGS2(void *dobj, - void *irp)); -__fastcall static void ntoskrnl_iofcompletereq(REGARGS2(void *irp, - uint8_t prioboost)); -__stdcall static uint32_t ntoskrnl_waitforobjs(uint32_t, +__stdcall static uint32_t KeWaitForMultipleObjects(uint32_t, nt_dispatch_header **, uint32_t, uint32_t, uint32_t, uint8_t, int64_t *, wait_block *); static void ntoskrnl_wakeup(void *); static void ntoskrnl_timercall(void *); static void ntoskrnl_run_dpc(void *); -__stdcall static void ntoskrnl_writereg_ushort(uint16_t *, uint16_t); -__stdcall static uint16_t ntoskrnl_readreg_ushort(uint16_t *); -__stdcall static void ntoskrnl_writereg_ulong(uint32_t *, uint32_t); -__stdcall static uint32_t ntoskrnl_readreg_ulong(uint32_t *); -__stdcall static void ntoskrnl_writereg_uchar(uint8_t *, uint8_t); -__stdcall static uint8_t ntoskrnl_readreg_uchar(uint8_t *); +__stdcall static void WRITE_REGISTER_USHORT(uint16_t *, uint16_t); +__stdcall static uint16_t READ_REGISTER_USHORT(uint16_t *); +__stdcall static void WRITE_REGISTER_ULONG(uint32_t *, uint32_t); +__stdcall static uint32_t READ_REGISTER_ULONG(uint32_t *); +__stdcall static void WRITE_REGISTER_UCHAR(uint8_t *, uint8_t); +__stdcall static uint8_t READ_REGISTER_UCHAR(uint8_t *); __stdcall static int64_t _allmul(int64_t, int64_t); __stdcall static int64_t _alldiv(int64_t, int64_t); __stdcall static int64_t _allrem(int64_t, int64_t); @@ -111,66 +109,68 @@ __stdcall static void *ntoskrnl_allocfunc(uint32_t, size_t, uint32_t); __stdcall static void ntoskrnl_freefunc(void *); static slist_entry *ntoskrnl_pushsl(slist_header *, slist_entry *); static slist_entry *ntoskrnl_popsl(slist_header *); -__stdcall static void ntoskrnl_init_lookaside(paged_lookaside_list *, +__stdcall static void ExInitializePagedLookasideList(paged_lookaside_list *, lookaside_alloc_func *, lookaside_free_func *, uint32_t, size_t, uint32_t, uint16_t); -__stdcall static void ntoskrnl_delete_lookaside(paged_lookaside_list *); -__stdcall static void ntoskrnl_init_nplookaside(npaged_lookaside_list *, +__stdcall static void ExDeletePagedLookasideList(paged_lookaside_list *); +__stdcall static void ExInitializeNPagedLookasideList(npaged_lookaside_list *, lookaside_alloc_func *, lookaside_free_func *, uint32_t, size_t, uint32_t, uint16_t); -__stdcall static void ntoskrnl_delete_nplookaside(npaged_lookaside_list *); -__fastcall static slist_entry *ntoskrnl_push_slist(REGARGS2(slist_header *head, +__stdcall static void ExDeleteNPagedLookasideList(npaged_lookaside_list *); +__fastcall static slist_entry + *InterlockedPushEntrySList(REGARGS2(slist_header *head, slist_entry *entry)); -__fastcall static slist_entry *ntoskrnl_pop_slist(REGARGS1(slist_header +__fastcall static slist_entry *InterlockedPopEntrySList(REGARGS1(slist_header *head)); __fastcall static slist_entry - *ntoskrnl_push_slist_ex(REGARGS2(slist_header *head, + *ExInterlockedPushEntrySList(REGARGS2(slist_header *head, slist_entry *entry), kspin_lock *lock); __fastcall static slist_entry - *ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head, + *ExInterlockedPopEntrySList(REGARGS2(slist_header *head, kspin_lock *lock)); __fastcall static uint32_t - ntoskrnl_interlock_inc(REGARGS1(volatile uint32_t *addend)); + InterlockedIncrement(REGARGS1(volatile uint32_t *addend)); __fastcall static uint32_t - ntoskrnl_interlock_dec(REGARGS1(volatile uint32_t *addend)); -__fastcall static void ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend, - uint32_t inc)); -__stdcall static void ntoskrnl_freemdl(ndis_buffer *); -__stdcall static uint32_t ntoskrnl_sizeofmdl(void *, size_t); -__stdcall static void ntoskrnl_build_npaged_mdl(ndis_buffer *); -__stdcall static void *ntoskrnl_mmaplockedpages(ndis_buffer *, uint8_t); -__stdcall static void *ntoskrnl_mmaplockedpages_cache(ndis_buffer *, + InterlockedDecrement(REGARGS1(volatile uint32_t *addend)); +__fastcall static void + ExInterlockedAddLargeStatistic(REGARGS2(uint64_t *addend, uint32_t)); +__stdcall static mdl *IoAllocateMdl(void *, uint32_t, uint8_t, uint8_t, irp *); +__stdcall static void IoFreeMdl(mdl *); +__stdcall static uint32_t MmSizeOfMdl(void *, size_t); +__stdcall static void MmBuildMdlForNonPagedPool(mdl *); +__stdcall static void *MmMapLockedPages(mdl *, uint8_t); +__stdcall static void *MmMapLockedPagesSpecifyCache(mdl *, uint8_t, uint32_t, void *, uint32_t, uint32_t); -__stdcall static void ntoskrnl_munmaplockedpages(void *, ndis_buffer *); -__stdcall static size_t ntoskrnl_memcmp(const void *, const void *, size_t); -__stdcall static void ntoskrnl_init_ansi_string(ndis_ansi_string *, char *); -__stdcall static void ntoskrnl_init_unicode_string(ndis_unicode_string *, +__stdcall static void MmUnmapLockedPages(void *, mdl *); +__stdcall static size_t RtlCompareMemory(const void *, const void *, size_t); +__stdcall static void RtlInitAnsiString(ndis_ansi_string *, char *); +__stdcall static void RtlInitUnicodeString(ndis_unicode_string *, uint16_t *); -__stdcall static void ntoskrnl_free_unicode_string(ndis_unicode_string *); -__stdcall static void ntoskrnl_free_ansi_string(ndis_ansi_string *); -__stdcall static ndis_status ntoskrnl_unicode_to_int(ndis_unicode_string *, +__stdcall static void RtlFreeUnicodeString(ndis_unicode_string *); +__stdcall static void RtlFreeAnsiString(ndis_ansi_string *); +__stdcall static ndis_status RtlUnicodeStringToInteger(ndis_unicode_string *, uint32_t, uint32_t *); static int atoi (const char *); static long atol (const char *); static int rand(void); static void srand(unsigned int); static void ntoskrnl_time(uint64_t *); -__stdcall static uint8_t ntoskrnl_wdmver(uint8_t, uint8_t); +__stdcall static uint8_t IoIsWdmVersionAvailable(uint8_t, uint8_t); static void ntoskrnl_thrfunc(void *); -__stdcall static ndis_status ntoskrnl_create_thread(ndis_handle *, +__stdcall static ndis_status PsCreateSystemThread(ndis_handle *, uint32_t, void *, ndis_handle, void *, void *, void *); -__stdcall static ndis_status ntoskrnl_thread_exit(ndis_status); -__stdcall static ndis_status ntoskrnl_devprop(device_object *, uint32_t, +__stdcall static ndis_status PsTerminateSystemThread(ndis_status); +__stdcall static ndis_status IoGetDeviceProperty(device_object *, uint32_t, uint32_t, void *, uint32_t *); -__stdcall static void ntoskrnl_init_mutex(kmutant *, uint32_t); -__stdcall static uint32_t ntoskrnl_release_mutex(kmutant *, uint8_t); -__stdcall static uint32_t ntoskrnl_read_mutex(kmutant *); -__stdcall static ndis_status ntoskrnl_objref(ndis_handle, uint32_t, void *, - uint8_t, void **, void **); -__fastcall static void ntoskrnl_objderef(REGARGS1(void *object)); -__stdcall static uint32_t ntoskrnl_zwclose(ndis_handle); -static uint32_t ntoskrnl_dbgprint(char *, ...); -__stdcall static void ntoskrnl_debugger(void); +__stdcall static void KeInitializeMutex(kmutant *, uint32_t); +__stdcall static uint32_t KeReleaseMutex(kmutant *, uint8_t); +__stdcall static uint32_t KeReadStateMutex(kmutant *); +__stdcall static ndis_status ObReferenceObjectByHandle(ndis_handle, + uint32_t, void *, uint8_t, void **, void **); +__fastcall static void ObfDereferenceObject(REGARGS1(void *object)); +__stdcall static uint32_t ZwClose(ndis_handle); +static uint32_t DbgPrint(char *, ...); +__stdcall static void DbgBreakPoint(void); __stdcall static void dummy(void); static struct mtx ntoskrnl_dispatchlock; @@ -183,7 +183,7 @@ ntoskrnl_libinit() { mtx_init(&ntoskrnl_dispatchlock, "ntoskrnl dispatch lock", MTX_NDIS_LOCK, MTX_DEF); - ntoskrnl_init_lock(&ntoskrnl_global); + KeInitializeSpinLock(&ntoskrnl_global); TAILQ_INIT(&ntoskrnl_reflist); return(0); } @@ -196,7 +196,7 @@ ntoskrnl_libfini() } __stdcall static uint8_t -ntoskrnl_unicode_equal(str1, str2, caseinsensitive) +RtlEqualUnicodeString(str1, str2, caseinsensitive) ndis_unicode_string *str1; ndis_unicode_string *str2; uint8_t caseinsensitive; @@ -221,7 +221,7 @@ ntoskrnl_unicode_equal(str1, str2, caseinsensitive) } __stdcall static void -ntoskrnl_unicode_copy(dest, src) +RtlCopyUnicodeString(dest, src) ndis_unicode_string *dest; ndis_unicode_string *src; { @@ -235,7 +235,7 @@ ntoskrnl_unicode_copy(dest, src) } __stdcall static ndis_status -ntoskrnl_unicode_to_ansi(dest, src, allocate) +RtlUnicodeStringToAnsiString(dest, src, allocate) ndis_ansi_string *dest; ndis_unicode_string *src; uint8_t allocate; @@ -261,7 +261,7 @@ ntoskrnl_unicode_to_ansi(dest, src, allocate) } __stdcall static ndis_status -ntoskrnl_ansi_to_unicode(dest, src, allocate) +RtlAnsiStringToUnicodeString(dest, src, allocate) ndis_unicode_string *dest; ndis_ansi_string *src; uint8_t allocate; @@ -286,7 +286,7 @@ ntoskrnl_ansi_to_unicode(dest, src, allocate) } __stdcall static void * -ntoskrnl_iobuildsynchfsdreq(func, dobj, buf, len, off, event, status) +IoBuildSynchronousFsdRequest(func, dobj, buf, len, off, event, status) uint32_t func; void *dobj; void *buf; @@ -298,14 +298,14 @@ ntoskrnl_iobuildsynchfsdreq(func, dobj, buf, len, off, event, status) return(NULL); } -__fastcall static uint32_t -ntoskrnl_iofcalldriver(REGARGS2(void *dobj, void *irp)) +__fastcall uint32_t +IofCallDriver(REGARGS2(device_object *dobj, irp *ip)) { return(0); } -__fastcall static void -ntoskrnl_iofcompletereq(REGARGS2(void *irp, uint8_t prioboost)) +__fastcall void +IofCompleteRequest(REGARGS2(irp *ip, uint8_t prioboost)) { return; } @@ -407,7 +407,7 @@ ntoskrnl_time(tval) */ __stdcall uint32_t -ntoskrnl_waitforobj(obj, reason, mode, alertable, duetime) +KeWaitForSingleObject(obj, reason, mode, alertable, duetime) nt_dispatch_header *obj; uint32_t reason; uint32_t mode; @@ -524,7 +524,7 @@ ntoskrnl_waitforobj(obj, reason, mode, alertable, duetime) } __stdcall static uint32_t -ntoskrnl_waitforobjs(cnt, obj, wtype, reason, mode, +KeWaitForMultipleObjects(cnt, obj, wtype, reason, mode, alertable, duetime, wb_array) uint32_t cnt; nt_dispatch_header *obj[]; @@ -671,7 +671,7 @@ ntoskrnl_waitforobjs(cnt, obj, wtype, reason, mode, } __stdcall static void -ntoskrnl_writereg_ushort(reg, val) +WRITE_REGISTER_USHORT(reg, val) uint16_t *reg; uint16_t val; { @@ -680,14 +680,14 @@ ntoskrnl_writereg_ushort(reg, val) } __stdcall static uint16_t -ntoskrnl_readreg_ushort(reg) +READ_REGISTER_USHORT(reg) uint16_t *reg; { return(bus_space_read_2(NDIS_BUS_SPACE_MEM, 0x0, (bus_size_t)reg)); } __stdcall static void -ntoskrnl_writereg_ulong(reg, val) +WRITE_REGISTER_ULONG(reg, val) uint32_t *reg; uint32_t val; { @@ -696,21 +696,21 @@ ntoskrnl_writereg_ulong(reg, val) } __stdcall static uint32_t -ntoskrnl_readreg_ulong(reg) +READ_REGISTER_ULONG(reg) uint32_t *reg; { return(bus_space_read_4(NDIS_BUS_SPACE_MEM, 0x0, (bus_size_t)reg)); } __stdcall static uint8_t -ntoskrnl_readreg_uchar(reg) +READ_REGISTER_UCHAR(reg) uint8_t *reg; { return(bus_space_read_1(NDIS_BUS_SPACE_MEM, 0x0, (bus_size_t)reg)); } __stdcall static void -ntoskrnl_writereg_uchar(reg, val) +WRITE_REGISTER_UCHAR(reg, val) uint8_t *reg; uint8_t val; { @@ -848,7 +848,7 @@ ntoskrnl_freefunc(buf) } __stdcall static void -ntoskrnl_init_lookaside(lookaside, allocfunc, freefunc, +ExInitializePagedLookasideList(lookaside, allocfunc, freefunc, flags, size, tag, depth) paged_lookaside_list *lookaside; lookaside_alloc_func *allocfunc; @@ -875,7 +875,7 @@ ntoskrnl_init_lookaside(lookaside, allocfunc, freefunc, else lookaside->nll_l.gl_freefunc = freefunc; - ntoskrnl_init_lock(&lookaside->nll_obsoletelock); + KeInitializeSpinLock(&lookaside->nll_obsoletelock); lookaside->nll_l.gl_depth = LOOKASIDE_DEPTH; lookaside->nll_l.gl_maxdepth = LOOKASIDE_DEPTH; @@ -884,7 +884,7 @@ ntoskrnl_init_lookaside(lookaside, allocfunc, freefunc, } __stdcall static void -ntoskrnl_delete_lookaside(lookaside) +ExDeletePagedLookasideList(lookaside) paged_lookaside_list *lookaside; { void *buf; @@ -898,7 +898,7 @@ ntoskrnl_delete_lookaside(lookaside) } __stdcall static void -ntoskrnl_init_nplookaside(lookaside, allocfunc, freefunc, +ExInitializeNPagedLookasideList(lookaside, allocfunc, freefunc, flags, size, tag, depth) npaged_lookaside_list *lookaside; lookaside_alloc_func *allocfunc; @@ -925,7 +925,7 @@ ntoskrnl_init_nplookaside(lookaside, allocfunc, freefunc, else lookaside->nll_l.gl_freefunc = freefunc; - ntoskrnl_init_lock(&lookaside->nll_obsoletelock); + KeInitializeSpinLock(&lookaside->nll_obsoletelock); lookaside->nll_l.gl_depth = LOOKASIDE_DEPTH; lookaside->nll_l.gl_maxdepth = LOOKASIDE_DEPTH; @@ -934,7 +934,7 @@ ntoskrnl_init_nplookaside(lookaside, allocfunc, freefunc, } __stdcall static void -ntoskrnl_delete_nplookaside(lookaside) +ExDeleteNPagedLookasideList(lookaside) npaged_lookaside_list *lookaside; { void *buf; @@ -956,56 +956,56 @@ ntoskrnl_delete_nplookaside(lookaside) */ __fastcall static slist_entry * -ntoskrnl_push_slist(REGARGS2(slist_header *head, slist_entry *entry)) +InterlockedPushEntrySList(REGARGS2(slist_header *head, slist_entry *entry)) { slist_entry *oldhead; - oldhead = (slist_entry *)FASTCALL3(ntoskrnl_push_slist_ex, + oldhead = (slist_entry *)FASTCALL3(ExInterlockedPushEntrySList, head, entry, &ntoskrnl_global); return(oldhead); } __fastcall static slist_entry * -ntoskrnl_pop_slist(REGARGS1(slist_header *head)) +InterlockedPopEntrySList(REGARGS1(slist_header *head)) { slist_entry *first; - first = (slist_entry *)FASTCALL2(ntoskrnl_pop_slist_ex, + first = (slist_entry *)FASTCALL2(ExInterlockedPopEntrySList, head, &ntoskrnl_global); return(first); } __fastcall static slist_entry * -ntoskrnl_push_slist_ex(REGARGS2(slist_header *head, +ExInterlockedPushEntrySList(REGARGS2(slist_header *head, slist_entry *entry), kspin_lock *lock) { slist_entry *oldhead; uint8_t irql; - ntoskrnl_acquire_spinlock(lock, &irql); + KeAcquireSpinLock(lock, &irql); oldhead = ntoskrnl_pushsl(head, entry); - ntoskrnl_release_spinlock(lock, irql); + KeReleaseSpinLock(lock, irql); return(oldhead); } __fastcall static slist_entry * -ntoskrnl_pop_slist_ex(REGARGS2(slist_header *head, kspin_lock *lock)) +ExInterlockedPopEntrySList(REGARGS2(slist_header *head, kspin_lock *lock)) { slist_entry *first; uint8_t irql; - ntoskrnl_acquire_spinlock(lock, &irql); + KeAcquireSpinLock(lock, &irql); first = ntoskrnl_popsl(head); - ntoskrnl_release_spinlock(lock, irql); + KeReleaseSpinLock(lock, irql); return(first); } __fastcall void -ntoskrnl_lock_dpc(REGARGS1(kspin_lock *lock)) +KefAcquireSpinLockAtDpcLevel(REGARGS1(kspin_lock *lock)) { while (atomic_cmpset_acq_int((volatile u_int *)lock, 0, 1) == 0) /* sit and spin */; @@ -1014,7 +1014,7 @@ ntoskrnl_lock_dpc(REGARGS1(kspin_lock *lock)) } __fastcall void -ntoskrnl_unlock_dpc(REGARGS1(kspin_lock *lock)) +KefReleaseSpinLockFromDpcLevel(REGARGS1(kspin_lock *lock)) { atomic_store_rel_int((volatile u_int *)lock, 0); @@ -1022,110 +1022,148 @@ ntoskrnl_unlock_dpc(REGARGS1(kspin_lock *lock)) } __fastcall static uint32_t -ntoskrnl_interlock_inc(REGARGS1(volatile uint32_t *addend)) +InterlockedIncrement(REGARGS1(volatile uint32_t *addend)) { atomic_add_long((volatile u_long *)addend, 1); return(*addend); } __fastcall static uint32_t -ntoskrnl_interlock_dec(REGARGS1(volatile uint32_t *addend)) +InterlockedDecrement(REGARGS1(volatile uint32_t *addend)) { atomic_subtract_long((volatile u_long *)addend, 1); return(*addend); } __fastcall static void -ntoskrnl_interlock_addstat(REGARGS2(uint64_t *addend, uint32_t inc)) +ExInterlockedAddLargeStatistic(REGARGS2(uint64_t *addend, uint32_t inc)) { uint8_t irql; - ntoskrnl_acquire_spinlock(&ntoskrnl_global, &irql); + KeAcquireSpinLock(&ntoskrnl_global, &irql); *addend += inc; - ntoskrnl_release_spinlock(&ntoskrnl_global, irql); + KeReleaseSpinLock(&ntoskrnl_global, irql); return; }; -__stdcall static void -ntoskrnl_freemdl(mdl) - ndis_buffer *mdl; +__stdcall static mdl * +IoAllocateMdl(vaddr, len, secondarybuf, chargequota, iopkt) + void *vaddr; + uint32_t len; + uint8_t secondarybuf; + uint8_t chargequota; + irp *iopkt; { - ndis_buffer *head; - - if (mdl == NULL || mdl->nb_process == NULL) - return; + mdl *m; - head = mdl->nb_process; + m = malloc(MmSizeOfMdl(vaddr, len), M_DEVBUF, M_NOWAIT|M_ZERO); - if (head->nb_flags != 0x1) - return; + if (m == NULL) + return (NULL); - mdl->nb_next = head->nb_next; - head->nb_next = mdl; + MmInitializeMdl(m, vaddr, len); - /* Decrement count of busy buffers. */ + if (iopkt != NULL) { + if (secondarybuf == TRUE) { + mdl *last; + last = iopkt->irp_mdl; + while (last->mdl_next != NULL) + last = last->mdl_next; + last->mdl_next = m; + } else { + if (iopkt->irp_mdl != NULL) + panic("leaking an MDL in IoAllocateMdl()"); + iopkt->irp_mdl = m; + } + } - head->nb_bytecount--; + return (NULL); +} - /* - * If the pool has been marked for deletion and there are - * no more buffers outstanding, nuke the pool. - */ +__stdcall static void +IoFreeMdl(m) + mdl *m; +{ + if (m == NULL) + return; - if (head->nb_byteoffset && head->nb_bytecount == 0) - free(head, M_DEVBUF); + free (m, M_DEVBUF); return; } __stdcall static uint32_t -ntoskrnl_sizeofmdl(vaddr, len) +MmSizeOfMdl(vaddr, len) void *vaddr; size_t len; { uint32_t l; - l = sizeof(struct ndis_buffer) + - (sizeof(uint32_t) * SPAN_PAGES(vaddr, len)); + l = sizeof(struct mdl) + + (sizeof(vm_offset_t *) * SPAN_PAGES(vaddr, len)); return(l); } +/* + * The Microsoft documentation says this routine fills in the + * page array of an MDL with the _physical_ page addresses that + * comprise the buffer, but we don't really want to do that here. + * Instead, we just fill in the page array with the kernel virtual + * addresses of the buffers. + */ __stdcall static void -ntoskrnl_build_npaged_mdl(mdl) - ndis_buffer *mdl; +MmBuildMdlForNonPagedPool(m) + mdl *m; { - mdl->nb_mappedsystemva = (char *)mdl->nb_startva + mdl->nb_byteoffset; + vm_offset_t *mdl_pages; + int pagecnt, i; + + pagecnt = SPAN_PAGES(m->mdl_byteoffset, m->mdl_bytecount); + + if (pagecnt > (m->mdl_size - sizeof(mdl)) / sizeof(vm_offset_t *)) + panic("not enough pages in MDL to describe buffer"); + + mdl_pages = MmGetMdlPfnArray(m); + + for (i = 0; i < pagecnt; i++) + *mdl_pages = (vm_offset_t)m->mdl_startva + (i * PAGE_SIZE); + + m->mdl_flags |= MDL_SOURCE_IS_NONPAGED_POOL; + m->mdl_mappedsystemva = MmGetMdlVirtualAddress(m); + return; } __stdcall static void * -ntoskrnl_mmaplockedpages(buf, accessmode) - ndis_buffer *buf; +MmMapLockedPages(buf, accessmode) + mdl *buf; uint8_t accessmode; { - return(MDL_VA(buf)); + buf->mdl_flags |= MDL_MAPPED_TO_SYSTEM_VA; + return(MmGetMdlVirtualAddress(buf)); } __stdcall static void * -ntoskrnl_mmaplockedpages_cache(buf, accessmode, cachetype, vaddr, +MmMapLockedPagesSpecifyCache(buf, accessmode, cachetype, vaddr, bugcheck, prio) - ndis_buffer *buf; + mdl *buf; uint8_t accessmode; uint32_t cachetype; void *vaddr; uint32_t bugcheck; uint32_t prio; { - return(MDL_VA(buf)); + return(MmMapLockedPages(buf, accessmode)); } __stdcall static void -ntoskrnl_munmaplockedpages(vaddr, buf) +MmUnmapLockedPages(vaddr, buf) void *vaddr; - ndis_buffer *buf; + mdl *buf; { + buf->mdl_flags &= ~MDL_MAPPED_TO_SYSTEM_VA; return; } @@ -1137,7 +1175,7 @@ ntoskrnl_munmaplockedpages(vaddr, buf) * function. Instead, we grab a mutex from the mutex pool. */ __stdcall void -ntoskrnl_init_lock(lock) +KeInitializeSpinLock(lock) kspin_lock *lock; { *lock = 0; @@ -1146,7 +1184,7 @@ ntoskrnl_init_lock(lock) } __stdcall static size_t -ntoskrnl_memcmp(s1, s2, len) +RtlCompareMemory(s1, s2, len) const void *s1; const void *s2; size_t len; @@ -1165,7 +1203,7 @@ ntoskrnl_memcmp(s1, s2, len) } __stdcall static void -ntoskrnl_init_ansi_string(dst, src) +RtlInitAnsiString(dst, src) ndis_ansi_string *dst; char *src; { @@ -1186,7 +1224,7 @@ ntoskrnl_init_ansi_string(dst, src) } __stdcall static void -ntoskrnl_init_unicode_string(dst, src) +RtlInitUnicodeString(dst, src) ndis_unicode_string *dst; uint16_t *src; { @@ -1211,7 +1249,7 @@ ntoskrnl_init_unicode_string(dst, src) } __stdcall ndis_status -ntoskrnl_unicode_to_int(ustr, base, val) +RtlUnicodeStringToInteger(ustr, base, val) ndis_unicode_string *ustr; uint32_t base; uint32_t *val; @@ -1265,7 +1303,7 @@ ntoskrnl_unicode_to_int(ustr, base, val) } __stdcall static void -ntoskrnl_free_unicode_string(ustr) +RtlFreeUnicodeString(ustr) ndis_unicode_string *ustr; { if (ustr->nus_buf == NULL) @@ -1276,7 +1314,7 @@ ntoskrnl_free_unicode_string(ustr) } __stdcall static void -ntoskrnl_free_ansi_string(astr) +RtlFreeAnsiString(astr) ndis_ansi_string *astr; { if (astr->nas_buf == NULL) @@ -1319,7 +1357,7 @@ srand(seed) } __stdcall static uint8_t -ntoskrnl_wdmver(major, minor) +IoIsWdmVersionAvailable(major, minor) uint8_t major; uint8_t minor; { @@ -1329,7 +1367,7 @@ ntoskrnl_wdmver(major, minor) } __stdcall static ndis_status -ntoskrnl_devprop(devobj, regprop, buflen, prop, reslen) +IoGetDeviceProperty(devobj, regprop, buflen, prop, reslen) device_object *devobj; uint32_t regprop; uint32_t buflen; @@ -1355,7 +1393,7 @@ ntoskrnl_devprop(devobj, regprop, buflen, prop, reslen) } __stdcall static void -ntoskrnl_init_mutex(kmutex, level) +KeInitializeMutex(kmutex, level) kmutant *kmutex; uint32_t level; { @@ -1371,7 +1409,7 @@ ntoskrnl_init_mutex(kmutex, level) } __stdcall static uint32_t -ntoskrnl_release_mutex(kmutex, kwait) +KeReleaseMutex(kmutex, kwait) kmutant *kmutex; uint8_t kwait; { @@ -1392,14 +1430,14 @@ ntoskrnl_release_mutex(kmutex, kwait) } __stdcall static uint32_t -ntoskrnl_read_mutex(kmutex) +KeReadStateMutex(kmutex) kmutant *kmutex; { return(kmutex->km_header.dh_sigstate); } __stdcall void -ntoskrnl_init_event(kevent, type, state) +KeInitializeEvent(kevent, type, state) nt_kevent *kevent; uint32_t type; uint8_t state; @@ -1412,7 +1450,7 @@ ntoskrnl_init_event(kevent, type, state) } __stdcall uint32_t -ntoskrnl_reset_event(kevent) +KeResetEvent(kevent) nt_kevent *kevent; { uint32_t prevstate; @@ -1426,7 +1464,7 @@ ntoskrnl_reset_event(kevent) } __stdcall uint32_t -ntoskrnl_set_event(kevent, increment, kwait) +KeSetEvent(kevent, increment, kwait) nt_kevent *kevent; uint32_t increment; uint8_t kwait; @@ -1440,7 +1478,7 @@ ntoskrnl_set_event(kevent, increment, kwait) } __stdcall void -ntoskrnl_clear_event(kevent) +KeClearEvent(kevent) nt_kevent *kevent; { kevent->k_header.dh_sigstate = FALSE; @@ -1448,14 +1486,15 @@ ntoskrnl_clear_event(kevent) } __stdcall uint32_t -ntoskrnl_read_event(kevent) +KeReadStateEvent(kevent) nt_kevent *kevent; { return(kevent->k_header.dh_sigstate); } __stdcall static ndis_status -ntoskrnl_objref(handle, reqaccess, otype, accessmode, object, handleinfo) +ObReferenceObjectByHandle(handle, reqaccess, otype, + accessmode, object, handleinfo) ndis_handle handle; uint32_t reqaccess; void *otype; @@ -1479,7 +1518,7 @@ ntoskrnl_objref(handle, reqaccess, otype, accessmode, object, handleinfo) } __fastcall static void -ntoskrnl_objderef(REGARGS1(void *object)) +ObfDereferenceObject(REGARGS1(void *object)) { nt_objref *nr; @@ -1491,7 +1530,7 @@ ntoskrnl_objderef(REGARGS1(void *object)) } __stdcall static uint32_t -ntoskrnl_zwclose(handle) +ZwClose(handle) ndis_handle handle; { return(STATUS_SUCCESS); @@ -1517,12 +1556,12 @@ ntoskrnl_thrfunc(arg) rval = tfunc(tctx); - ntoskrnl_thread_exit(rval); + PsTerminateSystemThread(rval); return; /* notreached */ } __stdcall static ndis_status -ntoskrnl_create_thread(handle, reqaccess, objattrs, phandle, +PsCreateSystemThread(handle, reqaccess, objattrs, phandle, clientid, thrfunc, thrctx) ndis_handle *handle; uint32_t reqaccess; @@ -1563,7 +1602,7 @@ ntoskrnl_create_thread(handle, reqaccess, objattrs, phandle, * them. */ __stdcall static ndis_status -ntoskrnl_thread_exit(status) +PsTerminateSystemThread(status) ndis_status status; { struct nt_objref *nr; @@ -1585,7 +1624,7 @@ ntoskrnl_thread_exit(status) } static uint32_t -ntoskrnl_dbgprint(char *fmt, ...) +DbgPrint(char *fmt, ...) { va_list ap; @@ -1598,13 +1637,13 @@ ntoskrnl_dbgprint(char *fmt, ...) } __stdcall static void -ntoskrnl_debugger(void) +DbgBreakPoint(void) { #if __FreeBSD_version < 502113 - Debugger("ntoskrnl_debugger(): breakpoint"); + Debugger("DbgBreakPoint(): breakpoint"); #else - kdb_enter("ntoskrnl_debugger(): breakpoint"); + kdb_enter("DbgBreakPoint(): breakpoint"); #endif } @@ -1639,7 +1678,7 @@ ntoskrnl_timercall(arg) } if (timer->k_dpc != NULL) - ntoskrnl_queue_dpc(timer->k_dpc, NULL, NULL); + KeInsertQueueDpc(timer->k_dpc, NULL, NULL); ntoskrnl_wakeup(&timer->k_header); @@ -1649,19 +1688,19 @@ ntoskrnl_timercall(arg) } __stdcall void -ntoskrnl_init_timer(timer) +KeInitializeTimer(timer) ktimer *timer; { if (timer == NULL) return; - ntoskrnl_init_timer_ex(timer, EVENT_TYPE_NOTIFY); + KeInitializeTimerEx(timer, EVENT_TYPE_NOTIFY); return; } __stdcall void -ntoskrnl_init_timer_ex(timer, type) +KeInitializeTimerEx(timer, type) ktimer *timer; uint32_t type; { @@ -1694,15 +1733,15 @@ ntoskrnl_run_dpc(arg) dpc = arg; dpcfunc = (__stdcall kdpc_func) dpc->k_deferedfunc; - irql = ntoskrnl_raise_irql(DISPATCH_LEVEL); + irql = KeRaiseIrql(DISPATCH_LEVEL); dpcfunc(dpc, dpc->k_deferredctx, dpc->k_sysarg1, dpc->k_sysarg2); - ntoskrnl_lower_irql(irql); + KeLowerIrql(irql); return; } __stdcall void -ntoskrnl_init_dpc(dpc, dpcfunc, dpcctx) +KeInitializeDpc(dpc, dpcfunc, dpcctx) kdpc *dpc; void *dpcfunc; void *dpcctx; @@ -1717,7 +1756,7 @@ ntoskrnl_init_dpc(dpc, dpcfunc, dpcctx) } __stdcall uint8_t -ntoskrnl_queue_dpc(dpc, sysarg1, sysarg2) +KeInsertQueueDpc(dpc, sysarg1, sysarg2) kdpc *dpc; void *sysarg1; void *sysarg2; @@ -1731,7 +1770,7 @@ ntoskrnl_queue_dpc(dpc, sysarg1, sysarg2) } __stdcall uint8_t -ntoskrnl_dequeue_dpc(dpc) +KeRemoveQueueDpc(dpc) kdpc *dpc; { if (ndis_unsched(ntoskrnl_run_dpc, dpc, NDIS_SWI)) @@ -1741,7 +1780,7 @@ ntoskrnl_dequeue_dpc(dpc) } __stdcall uint8_t -ntoskrnl_set_timer_ex(timer, duetime, period, dpc) +KeSetTimerEx(timer, duetime, period, dpc) ktimer *timer; int64_t duetime; uint32_t period; @@ -1788,16 +1827,16 @@ ntoskrnl_set_timer_ex(timer, duetime, period, dpc) } __stdcall uint8_t -ntoskrnl_set_timer(timer, duetime, dpc) +KeSetTimer(timer, duetime, dpc) ktimer *timer; int64_t duetime; kdpc *dpc; { - return (ntoskrnl_set_timer_ex(timer, duetime, 0, dpc)); + return (KeSetTimerEx(timer, duetime, 0, dpc)); } __stdcall uint8_t -ntoskrnl_cancel_timer(timer) +KeCancelTimer(timer) ktimer *timer; { uint8_t pending; @@ -1808,7 +1847,7 @@ ntoskrnl_cancel_timer(timer) if (timer->k_header.dh_inserted == TRUE) { untimeout(ntoskrnl_timercall, timer, timer->k_handle); if (timer->k_dpc != NULL) - ntoskrnl_dequeue_dpc(timer->k_dpc); + KeRemoveQueueDpc(timer->k_dpc); pending = TRUE; } else pending = FALSE; @@ -1818,7 +1857,7 @@ ntoskrnl_cancel_timer(timer) } __stdcall uint8_t -ntoskrnl_read_timer(timer) +KeReadStateTimer(timer) ktimer *timer; { return(timer->k_header.dh_sigstate); @@ -1833,101 +1872,100 @@ dummy() image_patch_table ntoskrnl_functbl[] = { - { "RtlCompareMemory", (FUNC)ntoskrnl_memcmp }, - { "RtlEqualUnicodeString", (FUNC)ntoskrnl_unicode_equal }, - { "RtlCopyUnicodeString", (FUNC)ntoskrnl_unicode_copy }, - { "RtlUnicodeStringToAnsiString", (FUNC)ntoskrnl_unicode_to_ansi }, - { "RtlAnsiStringToUnicodeString", (FUNC)ntoskrnl_ansi_to_unicode }, - { "RtlInitAnsiString", (FUNC)ntoskrnl_init_ansi_string }, - { "RtlInitUnicodeString", (FUNC)ntoskrnl_init_unicode_string }, - { "RtlFreeAnsiString", (FUNC)ntoskrnl_free_ansi_string }, - { "RtlFreeUnicodeString", (FUNC)ntoskrnl_free_unicode_string }, - { "RtlUnicodeStringToInteger", (FUNC)ntoskrnl_unicode_to_int }, - { "sprintf", (FUNC)sprintf }, - { "vsprintf", (FUNC)vsprintf }, - { "_snprintf", (FUNC)snprintf }, - { "_vsnprintf", (FUNC)vsnprintf }, - { "DbgPrint", (FUNC)ntoskrnl_dbgprint }, - { "DbgBreakPoint", (FUNC)ntoskrnl_debugger }, - { "strncmp", (FUNC)strncmp }, - { "strcmp", (FUNC)strcmp }, - { "strncpy", (FUNC)strncpy }, - { "strcpy", (FUNC)strcpy }, - { "strlen", (FUNC)strlen }, - { "memcpy", (FUNC)memcpy }, - { "memmove", (FUNC)memcpy }, - { "memset", (FUNC)memset }, - { "IofCallDriver", (FUNC)ntoskrnl_iofcalldriver }, - { "IofCompleteRequest", (FUNC)ntoskrnl_iofcompletereq }, - { "IoBuildSynchronousFsdRequest", (FUNC)ntoskrnl_iobuildsynchfsdreq }, - { "KeWaitForSingleObject", (FUNC)ntoskrnl_waitforobj }, - { "KeWaitForMultipleObjects", (FUNC)ntoskrnl_waitforobjs }, - { "_allmul", (FUNC)_allmul }, - { "_alldiv", (FUNC)_alldiv }, - { "_allrem", (FUNC)_allrem }, - { "_allshr", (FUNC)_allshr }, - { "_allshl", (FUNC)_allshl }, - { "_aullmul", (FUNC)_aullmul }, - { "_aulldiv", (FUNC)_aulldiv }, - { "_aullrem", (FUNC)_aullrem }, - { "_aullshr", (FUNC)_aullshr }, - { "_aullshl", (FUNC)_aullshl }, - { "atoi", (FUNC)atoi }, - { "atol", (FUNC)atol }, - { "rand", (FUNC)rand }, - { "srand", (FUNC)srand }, - { "WRITE_REGISTER_USHORT", (FUNC)ntoskrnl_writereg_ushort }, - { "READ_REGISTER_USHORT", (FUNC)ntoskrnl_readreg_ushort }, - { "WRITE_REGISTER_ULONG", (FUNC)ntoskrnl_writereg_ulong }, - { "READ_REGISTER_ULONG", (FUNC)ntoskrnl_readreg_ulong }, - { "READ_REGISTER_UCHAR", (FUNC)ntoskrnl_readreg_uchar }, - { "WRITE_REGISTER_UCHAR", (FUNC)ntoskrnl_writereg_uchar }, - { "ExInitializePagedLookasideList", (FUNC)ntoskrnl_init_lookaside }, - { "ExDeletePagedLookasideList", (FUNC)ntoskrnl_delete_lookaside }, - { "ExInitializeNPagedLookasideList", (FUNC)ntoskrnl_init_nplookaside }, - { "ExDeleteNPagedLookasideList", (FUNC)ntoskrnl_delete_nplookaside }, - { "InterlockedPopEntrySList", (FUNC)ntoskrnl_pop_slist }, - { "InterlockedPushEntrySList", (FUNC)ntoskrnl_push_slist }, - { "ExInterlockedPopEntrySList", (FUNC)ntoskrnl_pop_slist_ex }, - { "ExInterlockedPushEntrySList",(FUNC)ntoskrnl_push_slist_ex }, - { "KefAcquireSpinLockAtDpcLevel", (FUNC)ntoskrnl_lock_dpc }, - { "KefReleaseSpinLockFromDpcLevel", (FUNC)ntoskrnl_unlock_dpc }, - { "InterlockedIncrement", (FUNC)ntoskrnl_interlock_inc }, - { "InterlockedDecrement", (FUNC)ntoskrnl_interlock_dec }, - { "ExInterlockedAddLargeStatistic", - (FUNC)ntoskrnl_interlock_addstat }, - { "IoFreeMdl", (FUNC)ntoskrnl_freemdl }, - { "MmSizeOfMdl", (FUNC)ntoskrnl_sizeofmdl }, - { "MmMapLockedPages", (FUNC)ntoskrnl_mmaplockedpages }, - { "MmMapLockedPagesSpecifyCache", - (FUNC)ntoskrnl_mmaplockedpages_cache }, - { "MmUnmapLockedPages", (FUNC)ntoskrnl_munmaplockedpages }, - { "MmBuildMdlForNonPagedPool", (FUNC)ntoskrnl_build_npaged_mdl }, - { "KeInitializeSpinLock", (FUNC)ntoskrnl_init_lock }, - { "IoIsWdmVersionAvailable", (FUNC)ntoskrnl_wdmver }, - { "IoGetDeviceProperty", (FUNC)ntoskrnl_devprop }, - { "KeInitializeMutex", (FUNC)ntoskrnl_init_mutex }, - { "KeReleaseMutex", (FUNC)ntoskrnl_release_mutex }, - { "KeReadStateMutex", (FUNC)ntoskrnl_read_mutex }, - { "KeInitializeEvent", (FUNC)ntoskrnl_init_event }, - { "KeSetEvent", (FUNC)ntoskrnl_set_event }, - { "KeResetEvent", (FUNC)ntoskrnl_reset_event }, - { "KeClearEvent", (FUNC)ntoskrnl_clear_event }, - { "KeReadStateEvent", (FUNC)ntoskrnl_read_event }, - { "KeInitializeTimer", (FUNC)ntoskrnl_init_timer }, - { "KeInitializeTimerEx", (FUNC)ntoskrnl_init_timer_ex }, - { "KeSetTimer", (FUNC)ntoskrnl_set_timer }, - { "KeSetTimerEx", (FUNC)ntoskrnl_set_timer_ex }, - { "KeCancelTimer", (FUNC)ntoskrnl_cancel_timer }, - { "KeReadStateTimer", (FUNC)ntoskrnl_read_timer }, - { "KeInitializeDpc", (FUNC)ntoskrnl_init_dpc }, - { "KeInsertQueueDpc", (FUNC)ntoskrnl_queue_dpc }, - { "KeRemoveQueueDpc", (FUNC)ntoskrnl_dequeue_dpc }, - { "ObReferenceObjectByHandle", (FUNC)ntoskrnl_objref }, - { "ObfDereferenceObject", (FUNC)ntoskrnl_objderef }, - { "ZwClose", (FUNC)ntoskrnl_zwclose }, - { "PsCreateSystemThread", (FUNC)ntoskrnl_create_thread }, - { "PsTerminateSystemThread", (FUNC)ntoskrnl_thread_exit }, + IMPORT_FUNC(RtlCompareMemory), + IMPORT_FUNC(RtlEqualUnicodeString), + IMPORT_FUNC(RtlCopyUnicodeString), + IMPORT_FUNC(RtlUnicodeStringToAnsiString), + IMPORT_FUNC(RtlAnsiStringToUnicodeString), + IMPORT_FUNC(RtlInitAnsiString), + IMPORT_FUNC(RtlInitUnicodeString), + IMPORT_FUNC(RtlFreeAnsiString), + IMPORT_FUNC(RtlFreeUnicodeString), + IMPORT_FUNC(RtlUnicodeStringToInteger), + IMPORT_FUNC(sprintf), + IMPORT_FUNC(vsprintf), + IMPORT_FUNC_MAP(_snprintf, snprintf), + IMPORT_FUNC_MAP(_vsnprintf, vsnprintf), + IMPORT_FUNC(DbgPrint), + IMPORT_FUNC(DbgBreakPoint), + IMPORT_FUNC(strncmp), + IMPORT_FUNC(strcmp), + IMPORT_FUNC(strncpy), + IMPORT_FUNC(strcpy), + IMPORT_FUNC(strlen), + IMPORT_FUNC(memcpy), + IMPORT_FUNC_MAP(memmove, memset), + IMPORT_FUNC(memset), + IMPORT_FUNC(IofCallDriver), + IMPORT_FUNC(IofCompleteRequest), + IMPORT_FUNC(IoBuildSynchronousFsdRequest), + IMPORT_FUNC(KeWaitForSingleObject), + IMPORT_FUNC(KeWaitForMultipleObjects), + IMPORT_FUNC(_allmul), + IMPORT_FUNC(_alldiv), + IMPORT_FUNC(_allrem), + IMPORT_FUNC(_allshr), + IMPORT_FUNC(_allshl), + IMPORT_FUNC(_aullmul), + IMPORT_FUNC(_aulldiv), + IMPORT_FUNC(_aullrem), + IMPORT_FUNC(_aullshr), + IMPORT_FUNC(_aullshl), + IMPORT_FUNC(atoi), + IMPORT_FUNC(atol), + IMPORT_FUNC(rand), + IMPORT_FUNC(srand), + IMPORT_FUNC(WRITE_REGISTER_USHORT), + IMPORT_FUNC(READ_REGISTER_USHORT), + IMPORT_FUNC(WRITE_REGISTER_ULONG), + IMPORT_FUNC(READ_REGISTER_ULONG), + IMPORT_FUNC(READ_REGISTER_UCHAR), + IMPORT_FUNC(WRITE_REGISTER_UCHAR), + IMPORT_FUNC(ExInitializePagedLookasideList), + IMPORT_FUNC(ExDeletePagedLookasideList), + IMPORT_FUNC(ExInitializeNPagedLookasideList), + IMPORT_FUNC(ExDeleteNPagedLookasideList), + IMPORT_FUNC(InterlockedPopEntrySList), + IMPORT_FUNC(InterlockedPushEntrySList), + IMPORT_FUNC(ExInterlockedPopEntrySList), + IMPORT_FUNC(ExInterlockedPushEntrySList), + IMPORT_FUNC(KefAcquireSpinLockAtDpcLevel), + IMPORT_FUNC(KefReleaseSpinLockFromDpcLevel), + IMPORT_FUNC(InterlockedIncrement), + IMPORT_FUNC(InterlockedDecrement), + IMPORT_FUNC(ExInterlockedAddLargeStatistic), + IMPORT_FUNC(IoAllocateMdl), + IMPORT_FUNC(IoFreeMdl), + IMPORT_FUNC(MmSizeOfMdl), + IMPORT_FUNC(MmMapLockedPages), + IMPORT_FUNC(MmMapLockedPagesSpecifyCache), + IMPORT_FUNC(MmUnmapLockedPages), + IMPORT_FUNC(MmBuildMdlForNonPagedPool), + IMPORT_FUNC(KeInitializeSpinLock), + IMPORT_FUNC(IoIsWdmVersionAvailable), + IMPORT_FUNC(IoGetDeviceProperty), + IMPORT_FUNC(KeInitializeMutex), + IMPORT_FUNC(KeReleaseMutex), + IMPORT_FUNC(KeReadStateMutex), + IMPORT_FUNC(KeInitializeEvent), + IMPORT_FUNC(KeSetEvent), + IMPORT_FUNC(KeResetEvent), + IMPORT_FUNC(KeClearEvent), + IMPORT_FUNC(KeReadStateEvent), + IMPORT_FUNC(KeInitializeTimer), + IMPORT_FUNC(KeInitializeTimerEx), + IMPORT_FUNC(KeSetTimer), + IMPORT_FUNC(KeSetTimerEx), + IMPORT_FUNC(KeCancelTimer), + IMPORT_FUNC(KeReadStateTimer), + IMPORT_FUNC(KeInitializeDpc), + IMPORT_FUNC(KeInsertQueueDpc), + IMPORT_FUNC(KeRemoveQueueDpc), + IMPORT_FUNC(ObReferenceObjectByHandle), + IMPORT_FUNC(ObfDereferenceObject), + IMPORT_FUNC(ZwClose), + IMPORT_FUNC(PsCreateSystemThread), + IMPORT_FUNC(PsTerminateSystemThread), /* * This last entry is a catch-all for any function we haven't -- cgit v1.1