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

📄 oscompat.h

📁 一个Linux下的软猫驱动
💻 H
📖 第 1 页 / 共 2 页
字号:
/* *  oscompat.h: Compatibility defines to handle various Linux versions *//* * Copyright (c) 2003-2004 Linuxant inc. *  * 1.  General Public License. This program is free software, and may * be redistributed or modified subject to the terms of the GNU General * Public License (version 2) or the GNU Lesser General Public License, * or (at your option) any later versions ("Open Source" code). You may * obtain a copy of the GNU General Public License at * http://www.fsf.org/copyleft/gpl.html and a copy of the GNU Lesser * General Public License at http://www.fsf.org/copyleft/less.html, * or you may alternatively write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA. *  * 2.   Disclaimer of Warranties. LINUXANT AND OTHER CONTRIBUTORS MAKE NO * REPRESENTATION ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. * IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTIES OF ANY KIND. * LINUXANT AND OTHER CONTRIBUTORS DISCLAIMS ALL WARRANTIES WITH REGARD TO * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE, GOOD TITLE AND AGAINST INFRINGEMENT. *  * This software has not been formally tested, and there is no guarantee that * it is free of errors including, but not limited to, bugs, defects, * interrupted operation, or unexpected results. Any use of this software is * at user's own risk. *  * 3.   No Liability. *  * (a) Linuxant or contributors shall not be responsible for any loss or * damage to Company, its customers, or any third parties for any reason * whatsoever, and LINUXANT OR CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY * ACTUAL, DIRECT, INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL, OR CONSEQUENTIAL * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED, WHETHER IN CONTRACT, STRICT OR OTHER LEGAL THEORY OF * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. *  * (b) User agrees to hold Linuxant and contributors harmless from any * liability, loss, cost, damage or expense, including attorney's fees, * as a result of any claims which may be made by any person, including * but not limited to User, its agents and employees, its customers, or * any third parties that arise out of or result from the manufacture, * delivery, actual or alleged ownership, performance, use, operation * or possession of the software furnished hereunder, whether such claims * are based on negligence, breach of contract, absolute liability or any * other legal theory. *  * 4.   Notices. User hereby agrees not to remove, alter or destroy any * copyright, trademark, credits, other proprietary notices or confidential * legends placed upon, contained within or associated with the Software, * and shall include all such unaltered copyright, trademark, credits, * other proprietary notices or confidential legends on or in every copy of * the Software. *  */#ifndef __OSCOMPAT_H#define __OSCOMPAT_H#ifdef __cplusplusextern "C"{#endif#include "osuniqredef.h"#include <linux/version.h>#include <linux/config.h>#include <linux/types.h>#if defined(STATIC_ERRNO)#ifndef _LINUX_UNISTD_H_#define _LINUX_UNISTD_H_#endifstatic int errno;#include <asm/unistd.h>#endif#include <linux/sched.h>#include <linux/mm.h>#include <linux/interrupt.h>#include <linux/wait.h>#include <linux/module.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/string.h>#include <linux/kdev_t.h>#include <linux/byteorder/swab.h>#ifdef FOUND_MODULE_PARAM#include <linux/moduleparam.h>#endif#if LINUX_VERSION_CODE == KERNEL_VERSION(2,4,9)/* get rid of non-standard min/max macros */#undef min#undef max#endif#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)#include <linux/tqueue.h>#else#include <linux/spinlock.h>#include <linux/list.h>#include <asm/bitops.h>#include <asm/system.h>/* * New proposed "bottom half" handlers: * (C) 1994 Kai Petzke, wpp@marie.physik.tu-berlin.de * * Advantages: * - Bottom halfs are implemented as a linked list.  You can have as many *   of them, as you want. * - No more scanning of a bit field is required upon call of a bottom half. * - Support for chained bottom half lists.  The run_task_queue() function can be *   used as a bottom half handler.  This is for example useful for bottom *   halfs, which want to be delayed until the next clock tick. * * Notes: * - Bottom halfs are called in the reverse order that they were linked into *   the list. */struct tq_struct {	struct list_head list;		/* linked list of active bh's */	unsigned long sync;		/* must be initialized to zero */	void (*routine)(void *);	/* function to call */	void *data;			/* argument to function */};/* * Emit code to initialise a tq_struct's routine and data pointers */#define PREPARE_TQUEUE(_tq, _routine, _data)			\	do {							\		(_tq)->routine = _routine;			\		(_tq)->data = _data;				\	} while (0)/* * Emit code to initialise all of a tq_struct */#define INIT_TQUEUE(_tq, _routine, _data)			\	do {							\		INIT_LIST_HEAD(&(_tq)->list);			\		(_tq)->sync = 0;				\		PREPARE_TQUEUE((_tq), (_routine), (_data));	\	} while (0)typedef struct list_head task_queue;#define DECLARE_TASK_QUEUE(q)	LIST_HEAD(q)#define TQ_ACTIVE(q)		(!list_empty(&q))extern task_queue tq_timer, tq_immediate, tq_disk;/* * To implement your own list of active bottom halfs, use the following * two definitions: * * DECLARE_TASK_QUEUE(my_tqueue); * struct tq_struct my_task = { * 	routine: (void (*)(void *)) my_routine, *	data: &my_data * }; * * To activate a bottom half on a list, use: * *	queue_task(&my_task, &my_tqueue); * * To later run the queued tasks use * *	run_task_queue(&my_tqueue); * * This allows you to do deferred processing.  For example, you could * have a task queue called tq_timer, which is executed within the timer * interrupt. */#ifdef STATIC_TQUEUE_LOCKstatic spinlock_t tqueue_lock __attribute__((unused)) = SPIN_LOCK_UNLOCKED;#elseextern spinlock_t tqueue_lock;#endif/* * Queue a task on a tq.  Return non-zero if it was successfully * added. */static inline int queue_task(struct tq_struct *bh_pointer, task_queue *bh_list){	int ret = 0;	if (!test_and_set_bit(0,&bh_pointer->sync)) {		unsigned long flags;		spin_lock_irqsave(&tqueue_lock, flags);		list_add_tail(&bh_pointer->list, bh_list);		spin_unlock_irqrestore(&tqueue_lock, flags);		ret = 1;	}	return ret;}/* * Call all "bottom halfs" on a given list. */static inline void run_task_queue(task_queue *list){    if (TQ_ACTIVE(*list)) {	struct list_head head, *next;	unsigned long flags;	spin_lock_irqsave(&tqueue_lock, flags);	list_add(&head, list);	list_del_init(list);	spin_unlock_irqrestore(&tqueue_lock, flags);	next = head.next;	while (next != &head) {	    void (*f) (void *);	    struct tq_struct *p;	    void *data;	    p = list_entry(next, struct tq_struct, list);	    next = next->next;	    f = p->routine;	    data = p->data;	    wmb();	    p->sync = 0;	    if (f)		f(data);	}    }}#define devfs_register_chrdev register_chrdev#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) */#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,2)#include <linux/circ_buf.h>#elsestruct circ_buf {	char *buf;	int head;	int tail;};/* Return count in buffer.  */#define CIRC_CNT(head,tail,size) (((head) - (tail)) & ((size)-1))/* Return space available, 0..size-1.  We always leave one free char   as a completely full buffer has head == tail, which is the same as   empty.  */#define CIRC_SPACE(head,tail,size) CIRC_CNT((tail),((head)+1),(size))/* Return count up to the end of the buffer.  Carefully avoid   accessing head and tail more than once, so they can change   underneath us without returning inconsistent results.  */#define CIRC_CNT_TO_END(head,tail,size) \	({int end = (size) - (tail); \	  int n = ((head) + end) & ((size)-1); \	  n < end ? n : end;})/* Return space available up to the end of the buffer.  */#define CIRC_SPACE_TO_END(head,tail,size) \	({int end = (size) - 1 - (head); \	  int n = (end + (tail)) & ((size)-1); \	  n <= end ? n : end+1;})#endif#ifdef CONFIG_KDB#define KDB_ENTER() asm("\tint $129\n")#else#define KDB_ENTER() do {} while(0)#endif#ifndef minor#define minor(d) MINOR(d)#endif#ifndef unlikely#define unlikely(x) (x)#endif#ifdef MODULE#ifndef THIS_MODULE#define THIS_MODULE (&__this_module)#endif#ifndef module_init#define module_init(x)  int init_module(void) { return x(); }

⌨️ 快捷键说明

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