⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntoskernel.h

📁 ndiswrapper工具
💻 H
📖 第 1 页 / 共 2 页
字号:
	BOOLEAN surprise_removed;};#define wrap_is_pci_bus(dev_bus)			\	(WRAP_BUS(dev_bus) == WRAP_PCI_BUS ||		\	 WRAP_BUS(dev_bus) == WRAP_PCMCIA_BUS)#ifdef CONFIG_USB/* earlier versions of ndiswrapper used 0 as USB_BUS */#define wrap_is_usb_bus(dev_bus)			\	(WRAP_BUS(dev_bus) == WRAP_USB_BUS ||		\	 WRAP_BUS(dev_bus) == WRAP_INTERNAL_BUS)#else#define wrap_is_usb_bus(dev_bus) 0#endif#define wrap_is_bluetooth_device(dev_bus)			\	(WRAP_DEVICE(dev_bus) == WRAP_BLUETOOTH_DEVICE1 ||	\	 WRAP_DEVICE(dev_bus) == WRAP_BLUETOOTH_DEVICE2)/* Some drivers use worker entries to complete functions called from * within other worker threads. So we should have separate workqueues * to make sure worker entries run properly */#define USE_OWN_WORKQUEUE 1#ifdef USE_OWN_WORKQUEUEextern struct workqueue_struct *wrap_wq;#define schedule_ndis_work(work_struct) queue_work(ndis_wq, (work_struct))#define schedule_wrap_work(work_struct) queue_work(wrap_wq, (work_struct))/* Normally workqueue for ntos is not required, as worker entries in * it are not supposed to wait; however, it helps to have separate * workqueue so keyboard etc. work when kernel crashes */#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,41)#define USE_OWN_NTOS_WORKQUEUE 1#endif//#define USE_OWN_NTOS_WORKQUEUE 1#ifdef USE_OWN_NTOS_WORKQUEUEextern struct workqueue_struct *ntos_wq;#define schedule_ntos_work(work_struct) queue_work(ntos_wq, (work_struct))#else#define schedule_ntos_work(work_struct) schedule_work(work_struct)#endif#else // USE_OWN_WORKQUEUE#define schedule_ndis_work(work_struct) schedule_work(work_struct)#define schedule_wrap_work(work_struct) schedule_work(work_struct)#endif // USE_OWN_WORKQUEUEint ntoskernel_init(void);void ntoskernel_exit(void);int ntoskernel_init_device(struct wrap_device *wd);void ntoskernel_exit_device(struct wrap_device *wd);void *allocate_object(ULONG size, enum common_object_type type,		      struct unicode_string *name);void free_object(void *object);int usb_init(void);void usb_exit(void);int usb_init_device(struct wrap_device *wd);void usb_exit_device(struct wrap_device *wd);void usb_cancel_pending_urbs(void);int crt_init(void);void crt_exit(void);int rtl_init(void);void rtl_exit(void);int wrap_procfs_init(void);void wrap_procfs_remove(void);int link_pe_images(struct pe_image *pe_image, unsigned short n);int stricmp(const char *s1, const char *s2);void dump_bytes(const char *name, const u8 *from, int len);struct mdl *allocate_init_mdl(void *virt, ULONG length);void free_mdl(struct mdl *mdl);struct driver_object *find_bus_driver(const char *name);void free_custom_extensions(struct driver_extension *drv_obj_ext);struct nt_thread *get_current_nt_thread(void);u64 ticks_1601(void);int schedule_ntos_work_item(NTOS_WORK_FUNC func, void *arg1, void *arg2);void wrap_init_timer(struct nt_timer *nt_timer, enum timer_type type,		     struct kdpc *kdpc, struct ndis_miniport_block *nmb);BOOLEAN wrap_set_timer(struct nt_timer *nt_timer, unsigned long expires_hz,		       unsigned long repeat_hz, struct kdpc *kdpc);LONG InterlockedDecrement(LONG volatile *val) wfastcall;LONG InterlockedIncrement(LONG volatile *val) wfastcall;struct nt_list *ExInterlockedInsertHeadList	(struct nt_list *head, struct nt_list *entry,	 NT_SPIN_LOCK *lock) wfastcall;struct nt_list *ExInterlockedInsertTailList	(struct nt_list *head, struct nt_list *entry,	 NT_SPIN_LOCK *lock) wfastcall;struct nt_list *ExInterlockedRemoveHeadList	(struct nt_list *head, NT_SPIN_LOCK *lock) wfastcall;NTSTATUS IofCallDriver(struct device_object *dev_obj, struct irp *irp) wfastcall;KIRQL KfRaiseIrql(KIRQL newirql) wfastcall;void KfLowerIrql(KIRQL oldirql) wfastcall;KIRQL KfAcquireSpinLock(NT_SPIN_LOCK *lock) wfastcall;void KfReleaseSpinLock(NT_SPIN_LOCK *lock, KIRQL oldirql) wfastcall;void IofCompleteRequest(struct irp *irp, CHAR prio_boost) wfastcall;void KefReleaseSpinLockFromDpcLevel(NT_SPIN_LOCK *lock) wfastcall;LONG ObfReferenceObject(void *object) wfastcall;void ObfDereferenceObject(void *object) wfastcall;int dereference_object(void *object);#define ObReferenceObject(object) ObfReferenceObject(object)#define ObDereferenceObject(object) ObfDereferenceObject(object)void WRITE_PORT_UCHAR(ULONG_PTR port, UCHAR value) wstdcall;UCHAR READ_PORT_UCHAR(ULONG_PTR port) wstdcall;#undef ExAllocatePoolWithTagvoid *ExAllocatePoolWithTag(enum pool_type pool_type, SIZE_T size,			    ULONG tag) wstdcall;#if defined(ALLOC_DEBUG) && ALLOC_DEBUG > 1#define ExAllocatePoolWithTag(pool_type, size, tag)			\	wrap_ExAllocatePoolWithTag(pool_type, size, tag, __FILE__, __LINE__)#endifvoid ExFreePool(void *p) wstdcall;ULONG MmSizeOfMdl(void *base, ULONG length) wstdcall;void *MmMapIoSpace(PHYSICAL_ADDRESS phys_addr, SIZE_T size,		   enum memory_caching_type cache) wstdcall;void MmUnmapIoSpace(void *addr, SIZE_T size) wstdcall;void MmProbeAndLockPages(struct mdl *mdl, KPROCESSOR_MODE access_mode,			 enum lock_operation operation) wstdcall;void MmUnlockPages(struct mdl *mdl) wstdcall;void KeInitializeEvent(struct nt_event *nt_event,		       enum event_type type, BOOLEAN state) wstdcall;LONG KeSetEvent(struct nt_event *nt_event, KPRIORITY incr,		BOOLEAN wait) wstdcall;LONG KeResetEvent(struct nt_event *nt_event) wstdcall;void KeClearEvent(struct nt_event *nt_event) wstdcall;void KeInitializeDpc(struct kdpc *kdpc, void *func, void *ctx) wstdcall;BOOLEAN KeInsertQueueDpc(struct kdpc *kdpc, void *arg1, void *arg2) wstdcall;BOOLEAN KeRemoveQueueDpc(struct kdpc *kdpc) wstdcall;void KeFlushQueuedDpcs(void) wstdcall;NTSTATUS KeWaitForSingleObject(void *object, KWAIT_REASON reason,			       KPROCESSOR_MODE waitmode, BOOLEAN alertable,			       LARGE_INTEGER *timeout) wstdcall;struct mdl *IoAllocateMdl(void *virt, ULONG length, BOOLEAN second_buf,			  BOOLEAN charge_quota, struct irp *irp) wstdcall;void MmBuildMdlForNonPagedPool(struct mdl *mdl) wstdcall;void IoFreeMdl(struct mdl *mdl) wstdcall;NTSTATUS IoCreateDevice(struct driver_object *driver, ULONG dev_ext_length,			struct unicode_string *dev_name, DEVICE_TYPE dev_type,			ULONG dev_chars, BOOLEAN exclusive,			struct device_object **dev_obj) wstdcall;NTSTATUS IoCreateSymbolicLink(struct unicode_string *link,			      struct unicode_string *dev_name) wstdcall;void IoDeleteDevice(struct device_object *dev) wstdcall;void IoDetachDevice(struct device_object *topdev) wstdcall;struct device_object *IoGetAttachedDevice(struct device_object *dev) wstdcall;struct device_object *IoGetAttachedDeviceReference	(struct device_object *dev) wstdcall;NTSTATUS IoAllocateDriverObjectExtension	(struct driver_object *drv_obj, void *client_id, ULONG extlen,	 void **ext) wstdcall;void *IoGetDriverObjectExtension(struct driver_object *drv,				 void *client_id) wstdcall;struct device_object *IoAttachDeviceToDeviceStack	(struct device_object *src, struct device_object *dst) wstdcall;void KeInitializeEvent(struct nt_event *nt_event, enum event_type type,		       BOOLEAN state) wstdcall;struct irp *IoAllocateIrp(char stack_count, BOOLEAN charge_quota) wstdcall;void IoFreeIrp(struct irp *irp) wstdcall;BOOLEAN IoCancelIrp(struct irp *irp) wstdcall;struct irp *IoBuildSynchronousFsdRequest	(ULONG major_func, struct device_object *dev_obj, void *buf,	 ULONG length, LARGE_INTEGER *offset, struct nt_event *event,	 struct io_status_block *status) wstdcall;struct irp *IoBuildAsynchronousFsdRequest	(ULONG major_func, struct device_object *dev_obj, void *buf,	 ULONG length, LARGE_INTEGER *offset,	 struct io_status_block *status) wstdcall;NTSTATUS PoCallDriver(struct device_object *dev_obj, struct irp *irp) wstdcall;NTSTATUS IoPassIrpDown(struct device_object *dev_obj, struct irp *irp) wstdcall;WIN_FUNC_DECL(IoPassIrpDown,2)NTSTATUS IoSyncForwardIrp(struct device_object *dev_obj,			  struct irp *irp) wstdcall;NTSTATUS IoAsyncForwardIrp (struct device_object *dev_obj,			    struct irp *irp) wstdcall;NTSTATUS IoInvalidDeviceRequest(struct device_object *dev_obj,				struct irp *irp) wstdcall;KIRQL KeGetCurrentIrql(void) wstdcall;void KeInitializeSpinLock(NT_SPIN_LOCK *lock) wstdcall;void KeAcquireSpinLock(NT_SPIN_LOCK *lock, KIRQL *irql) wstdcall;void KeReleaseSpinLock(NT_SPIN_LOCK *lock, KIRQL oldirql) wstdcall;KIRQL KeAcquireSpinLockRaiseToDpc(NT_SPIN_LOCK *lock) wstdcall;void IoAcquireCancelSpinLock(KIRQL *irql) wstdcall;void IoReleaseCancelSpinLock(KIRQL irql) wstdcall;void RtlCopyMemory(void *dst, const void *src, SIZE_T length) wstdcall;NTSTATUS RtlUnicodeStringToAnsiString	(struct ansi_string *dst, const struct unicode_string *src,	 BOOLEAN dup) wstdcall;NTSTATUS RtlAnsiStringToUnicodeString	(struct unicode_string *dst, const struct ansi_string *src,	 BOOLEAN dup) wstdcall;void RtlInitAnsiString(struct ansi_string *dst, const char *src) wstdcall;void RtlInitString(struct ansi_string *dst, const char *src) wstdcall;void RtlInitUnicodeString(struct unicode_string *dest,			  const wchar_t *src) wstdcall;void RtlFreeUnicodeString(struct unicode_string *string) wstdcall;void RtlFreeAnsiString(struct ansi_string *string) wstdcall;LONG RtlCompareUnicodeString(const struct unicode_string *s1,			     const struct unicode_string *s2,			     BOOLEAN case_insensitive) wstdcall;void RtlCopyUnicodeString(struct unicode_string *dst,			  struct unicode_string *src) wstdcall;void KeInitializeTimer(struct nt_timer *nt_timer) wstdcall;void KeInitializeTimerEx(struct nt_timer *nt_timer,			 enum timer_type type) wstdcall;BOOLEAN KeSetTimerEx(struct nt_timer *nt_timer, LARGE_INTEGER duetime_ticks,		     LONG period_ms, struct kdpc *kdpc) wstdcall;BOOLEAN KeSetTimer(struct nt_timer *nt_timer, LARGE_INTEGER duetime_ticks,		   struct kdpc *kdpc) wstdcall;BOOLEAN KeCancelTimer(struct nt_timer *nt_timer) wstdcall;void KeInitializeDpc(struct kdpc *kdpc, void *func, void *ctx) wstdcall;struct task_struct *KeGetCurrentThread(void) wstdcall;NTSTATUS ObReferenceObjectByHandle(void *handle, ACCESS_MASK desired_access,				   void *obj_type, KPROCESSOR_MODE access_mode,				   void **object, void *handle_info) wstdcall;void adjust_user_shared_data_addr(char *driver, unsigned long length);#define IoCompleteRequest(irp, prio) IofCompleteRequest(irp, prio)#define IoCallDriver(dev, irp) IofCallDriver(dev, irp)static inline KIRQL current_irql(void){	if (in_irq() || irqs_disabled())		TRACEEXIT5(return DEVICE_LEVEL);	else if (in_atomic())		TRACEEXIT5(return DISPATCH_LEVEL);	else		TRACEEXIT5(return PASSIVE_LEVEL);}static inline KIRQL raise_irql(KIRQL newirql){	KIRQL irql = current_irql();//	assert (newirql == DISPATCH_LEVEL);	if (irql < DISPATCH_LEVEL && newirql == DISPATCH_LEVEL) {		local_bh_disable();		preempt_disable();	}	DBGTRACE5("%d, %d", irql, newirql);	return irql;}static inline void lower_irql(KIRQL oldirql){	KIRQL irql = current_irql();	DBGTRACE5("%d, %d", irql, oldirql);	DBG_BLOCK(2) {		if (irql < oldirql)			ERROR("invalid irql: %d < %d", irql, oldirql);	}	if (oldirql < DISPATCH_LEVEL && irql == DISPATCH_LEVEL) {		preempt_enable();		local_bh_enable();	}}#define gfp_irql() (current_irql() < DISPATCH_LEVEL ? GFP_KERNEL : GFP_ATOMIC)/* Windows spinlocks are of type ULONG_PTR which is not big enough to * store Linux spinlocks; so we implement Windows spinlocks using * ULONG_PTR space with our own functions/macros *//* Windows seems to use 0 for unlocked state of spinlock - if Linux * convention of 1 for unlocked state is used, at least prism54 driver * crashes */#define NT_SPIN_LOCK_UNLOCKED 0#define NT_SPIN_LOCK_LOCKED 1static inline void  nt_spin_lock_init(volatile NT_SPIN_LOCK *lock){	*lock = NT_SPIN_LOCK_UNLOCKED;}#ifdef CONFIG_SMPstatic inline void nt_spin_lock(volatile NT_SPIN_LOCK *lock){	__asm__ __volatile__(		"\n"		"1:\t"		"  xchgl %1, %0\n\t"		"  cmpl %2, %1\n\t"		"  je 3f\n"		"2:\t"		"  rep; nop\n\t"		"  cmpl %2, %0\n\t"		"  jne 2b\n\t"		"  jmp 1b\n"		"3:\n\t"		: "+m" (*lock)		: "r" (NT_SPIN_LOCK_LOCKED), "i" (NT_SPIN_LOCK_UNLOCKED));}static inline void nt_spin_unlock(volatile NT_SPIN_LOCK *lock){	*lock = NT_SPIN_LOCK_UNLOCKED;}#else // CONFIG_SMP#define nt_spin_lock(lock) do { } while (0)#define nt_spin_unlock(lock)  do { } while (0)#endif // CONFIG_SMP/* raise IRQL to given (higher) IRQL if necessary before locking */static inline KIRQL nt_spin_lock_irql(NT_SPIN_LOCK *lock, KIRQL newirql){	KIRQL oldirql = raise_irql(newirql);	nt_spin_lock(lock);	return oldirql;}/* lower IRQL to given (lower) IRQL if necessary after unlocking */static inline void nt_spin_unlock_irql(NT_SPIN_LOCK *lock, KIRQL oldirql){	nt_spin_unlock(lock);	lower_irql(oldirql);}#ifdef CONFIG_PREEMPT_RT#define save_local_irq(flags) raw_local_irq_save(flags)#define restore_local_irq(flags) raw_local_irq_restore(flags)#else#define save_local_irq(flags) local_irq_save(flags)#define restore_local_irq(flags) local_irq_restore(flags)#endif#define nt_spin_lock_irqsave(lock, flags)				\do {									\	save_local_irq(flags);						\	preempt_disable();						\	nt_spin_lock(lock);						\} while (0)#define nt_spin_unlock_irqrestore(lock, flags)				\do {									\	nt_spin_unlock(lock);						\	restore_local_irq(flags);					\	preempt_enable();						\} while (0)#define atomic_unary_op(var, size, oper)			\	do {							\		if (size == 1)					\			__asm__ __volatile__(			\				LOCK_PREFIX oper "b %b0\n\t"	\				: "+m" (var));			\		else if (size == 2)				\			__asm__ __volatile__(			\				LOCK_PREFIX oper "w %w0\n\t"	\				: "+m" (var));			\		else if (size == 4)				\			__asm__ __volatile__(			\				LOCK_PREFIX oper "l %0\n\t"	\				: "+m" (var));			\		else if (size == 8)				\			__asm__ __volatile__(			\				LOCK_PREFIX oper "q %q0\n\t"	\				: "+m" (var));			\		else						\			ERROR("invalid size %d", (int)size);	\	} while (0)#define atomic_inc_var_size(var, size) atomic_unary_op(var, size, "inc")#define atomic_inc_var(var) atomic_inc_var_size(var, sizeof(var))#define atomic_dec_var_size(var, size) atomic_unary_op(var, size, "dec")#define atomic_dec_var(var) atomic_dec_var_size(var, sizeof(var))#define pre_atomic_add(var, i)					\({								\	typeof(var) pre;					\	__asm__ __volatile__(					\		LOCK_PREFIX "xadd %0, %1\n\t"			\		: "=r"(pre), "+m"(var)				\		: "0"(i));					\	pre;							\})#define post_atomic_add(var, i) (pre_atomic_add(var, i) + i)#define atomic_insert_list_head(head, oldhead, newhead)			\	do {								\		oldhead = head;						\	} while (cmpxchg(&(head), oldhead, newhead) != oldhead)#define atomic_remove_list_head(head, newhead)				\({									\	typeof(head) oldhead;						\	do {								\		oldhead = head;						\		if (!oldhead)						\			break;						\	} while (cmpxchg(&(head), oldhead, newhead) != oldhead);	\	oldhead;							\})static inline ULONG SPAN_PAGES(void *ptr, SIZE_T length){	return PAGE_ALIGN(((unsigned long)ptr & (PAGE_SIZE - 1)) + length)			  >> PAGE_SHIFT;}#ifdef CONFIG_X86_64/* TODO: can these be implemented without using spinlock? */static inline struct nt_slist *PushEntrySList(nt_slist_header *head,					      struct nt_slist *entry,					      NT_SPIN_LOCK *lock){	KIRQL irql = nt_spin_lock_irql(lock, DISPATCH_LEVEL);	entry->next = head->next;	head->next = entry;	head->depth++;	nt_spin_unlock_irql(lock, irql);	DBGTRACE4("%p, %p, %p", head, entry, entry->next);	return entry->next;}static inline struct nt_slist *PopEntrySList(nt_slist_header *head,					     NT_SPIN_LOCK *lock){	struct nt_slist *entry;	KIRQL irql = nt_spin_lock_irql(lock, DISPATCH_LEVEL);	entry = head->next;	if (entry) {		head->next = entry->next;		head->depth--;	}	nt_spin_unlock_irql(lock, irql);	DBGTRACE4("%p, %p", head, entry);	return entry;}#else#define u64_low_32(x) ((u32)x)#define u64_high_32(x) ((u32)(x >> 32))static inline u64 cmpxchg8b(volatile u64 *ptr, u64 old, u64 new){	u64 prev;	__asm__ __volatile__(		"\n"		LOCK_PREFIX "cmpxchg8b %0\n"		: "+m" (*ptr), "=A" (prev)		: "A" (old), "b" (u64_low_32(new)), "c" (u64_high_32(new)));	return prev;}/* slist routines below update slist atomically - no need for * spinlocks */static inline struct nt_slist *PushEntrySList(nt_slist_header *head,					      struct nt_slist *entry,					      NT_SPIN_LOCK *lock){	nt_slist_header old, new;	do {		old.align = head->align;		entry->next = old.next;		new.next = entry;		new.depth = old.depth + 1;	} while (cmpxchg8b(&head->align, old.align, new.align) != old.align);	DBGTRACE4("%p, %p, %p", head, entry, old.next);	return old.next;}static inline struct nt_slist *PopEntrySList(nt_slist_header *head,					     NT_SPIN_LOCK *lock){	struct nt_slist *entry;	nt_slist_header old, new;	do {		old.align = head->align;		entry = old.next;		if (!entry)			break;		new.next = entry->next;		new.depth = old.depth - 1;	} while (cmpxchg8b(&head->align, old.align, new.align) != old.align);	DBGTRACE4("%p, %p", head, entry);	return entry;}#endif#define sleep_hz(n)					\do {							\	set_current_state(TASK_INTERRUPTIBLE);		\	schedule_timeout(n);				\} while (0)#endif // _NTOSKERNEL_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -