📄 oscompat.h
字号:
#endif#ifndef module_exit#define module_exit(x) void cleanup_module(void) { x(); }#endif#endif#ifndef MODULE_LICENSE#define MODULE_LICENSE(x)#endif#ifndef MODULE_INFO#define MODULE_INFO(x,y)#endif#ifndef EXPORT_SYMBOL_NOVERS#define EXPORT_SYMBOL_NOVERS(x) EXPORT_SYMBOL(x)#endif#ifndef __exit#define __exit#endif#ifndef __devexit_p#define __devexit_p(x) x#endif#ifndef DECLARE_MUTEX#define DECLARE_MUTEX(name) struct semaphore name=MUTEX#define init_MUTEX(x) *(x)=MUTEX#endif#ifndef DECLARE_WAITQUEUE#define DECLARE_WAITQUEUE(wait, current) struct wait_queue wait = { current, NULL }#define DECLARE_WAIT_QUEUE_HEAD(wait) wait_queue_head_t waittypedef struct wait_queue *wait_queue_head_t;#define init_waitqueue_head(x) *(x)=NULL#endif#ifndef set_current_state#define __set_current_state(state_value) do { current->state = state_value; } while (0)#ifdef __SMP__#define set_current_state(state_value) do { __set_current_state(state_value); mb(); } while (0)#else#define set_current_state(state_value) __set_current_state(state_value)#endif#endif // set_current_state#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)#define get_zeroed_page get_free_page#define try_inc_mod_count(mod) ((mod && !(mod->flags & MOD_DELETED)) ? __MOD_INC_USE_COUNT(mod), 1 : 0)#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)#ifndef PREPARE_TQUEUE/* * 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)#endif#ifndef INIT_TQUEUE/* * Emit code to initialise all of a tq_struct */#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)#define INIT_TQUEUE(_tq, _routine, _data) \ do { \ INIT_LIST_HEAD(&(_tq)->list); \ (_tq)->sync = 0; \ PREPARE_TQUEUE((_tq), (_routine), (_data)); \ } while (0)#else#define INIT_TQUEUE(_tq, _routine, _data) \ do { \ (_tq)->next = NULL; \ (_tq)->sync = 0; \ PREPARE_TQUEUE((_tq), (_routine), (_data)); \ } while (0)#endif#endif#ifndef DECLARE_TASKLET#define tasklet_struct tq_struct#define tasklet_init(tlet, func, parm) INIT_TQUEUE(tlet, (void (*)(void *))(func), (void *)(parm))#define tasklet_schedule(tlet) queue_task(tlet, &tq_immediate); mark_bh(IMMEDIATE_BH)static inline void tasklet_kill(struct tasklet_struct *t){ unsigned long flags; struct tq_struct **pp; spin_lock_irqsave(&tqueue_lock, flags); if(t->sync) { for(pp = &tq_immediate; *pp; pp = &(*pp)->next) { if(*pp == t) { *pp = t->next; t->sync = 0; break; } } } spin_unlock_irqrestore(&tqueue_lock, flags);}#endif#if defined(EXPORT_SYMTAB)#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)) && defined(memcpy)/* accomodate references to memcpy caused by gcc */void * memcpy_for_gcc(void *dest, const void *src, __kernel_size_t n){ return memcpy(dest, src, n);}#undef memcpyvoid * memcpy(void *dest, const void *src, __kernel_size_t n) __attribute__ ((weak, alias ("memcpy_for_gcc")));#endif#endif // EXPORT_SYMTABstatic inline void OsModuleUseCountInc(void){#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) MOD_INC_USE_COUNT;#else (void)try_module_get(THIS_MODULE);#endif}static inline void OsModuleUseCountDec(void){#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) MOD_DEC_USE_COUNT;#else module_put(THIS_MODULE);#endif}#if defined(DEBUG_CHECK_STACK) && (defined(EXPORT_SYMTAB) || defined(CNXTSERIAL_INCLUDE_CORE))/* inspired by Benjamin LaHaise's CONFIG_X86_STACK_CHECK patch */static void __attribute__ ((unused, used))_OSUNIQDEF(stack_overflow)(void *esp, void *eip){ printk(KERN_ERR "%s: from %p. esp: %p\n", __FUNCTION__, eip, esp); KDB_ENTER();}void mcount(void) __attribute__ ((alias (_OSUNIQDEF_STR(mcount))));static int __attribute__ ((unused)) stack_danger_zone = sizeof(struct task_struct) + 512;asm("\n""THREAD_SIZE = 8192\n" /* 2 * PAGE_SIZE */"\n"".data\n""\n""stack_overflowed:\n"" .long 0\n""\n"".text\n""\n"" .align 16\n""\n"" .type "_OSUNIQDEF_STR(mcount)",@function\n"" .globl "_OSUNIQDEF_STR(mcount)"\n""\n"_OSUNIQDEF_STR(mcount)":\n"" push %eax\n"" movl $(THREAD_SIZE - 1),%eax\n"" andl %esp,%eax\n"" cmpl stack_danger_zone, %eax\n"" jle 1f\n""2:\n"" popl %eax\n"" ret\n""\n""1:\n"" movl %esp,%eax\n""\n"" lock; btsl $0,stack_overflowed\n" /* prevent re-entry */" jc 2b\n""\n"" pushf\n"" cli\n""\n" /* push eip then esp of error for stack_overflow */" pushl 4(%eax)\n"" pushl %eax\n"" call "_OSUNIQDEF_STR(stack_overflow)"\n"" addl $8,%esp\n""\n"" popf\n""\n"" popl %eax\n"" movl $0,stack_overflowed\n"" ret\n");#warning stack check enabled#endif#ifndef irqs_disabled#define irqs_disabled() \({ \ unsigned long flags;\ __asm__ __volatile__("pushfl ; popl %0":"=g" (flags): /* no input */); \ !(flags & (1<<9)); \})#endifstatic inline int OsContextAllowsSleeping(void){ if(irqs_disabled()) return 0; if(in_irq()) return 0; if((in_interrupt())#ifdef in_atomic || (in_atomic())#endif || (in_softirq()) ) return 0; return 1;}#if defined(CONFIG_ALL_PPC) && !defined(CONFIG_PPC_PMAC) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))#define CONFIG_PPC_PMAC#endif#ifdef __cplusplus}#endif#ifdef FOUND_PCI_DEV_SLOT_NAME#define PCI_SLOT_NAME(x) (x)->slot_name#else#define PCI_SLOT_NAME(x) (x)->dev.bus_id#endif#ifdef FOUND_CLASS_SIMPLE#define CLASS_DEVICE_CREATE(class, dev, device, fmt, rest) class_simple_device_add(class, dev, device, fmt, rest)#define CLASS_DESTROY(class) class_simple_destroy(class)#define CLASS_DEVICE_DESTROY(class, dev) class_simple_device_remove(dev)#define CLASS_CREATE(owner, name) class_simple_create(owner, name)#else#ifdef FOUND_CLASS_DEVICE_PARENT#define CLASS_DEVICE_CREATE(class, dev, device, fmt, rest) class_device_create(class, NULL, dev, device, fmt, rest)#else#define CLASS_DEVICE_CREATE(class, dev, device, fmt, rest) class_device_create(class, dev, device, fmt, rest)#endif#define CLASS_DESTROY(class) class_destroy(class)#define CLASS_DEVICE_DESTROY(class, dev) class_device_destroy(class, dev)#define CLASS_CREATE(owner, name) class_create(owner, name)#endif#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) )#define USB_MS_TIMEOUT(ms) ((ms / 1000) * HZ)#else#define USB_MS_TIMEOUT(ms) (ms)#endif#ifdef FOUND_PM_MESSAGE_STRUCT#define GET_PM_MESSAGE_EVENT(pm_message) (pm_message.event)#else#define GET_PM_MESSAGE_EVENT(pm_message) ((u32)(pm_message))#endif#ifndef FOUND_PCI_CHOOSE_STATE#define pci_choose_state(pdev, state) (state)#endif#if !defined(FOUND_PM_MESSAGE_T) && !defined(FOUND_PM_MESSAGE_STRUCT)typedef u32 pm_message_t;#endif#ifdef FOUND_PCI_REGISTER_DRIVER#define PCI_REGISTER_DRIVER(pci_driver) pci_register_driver(pci_driver)#else#define PCI_REGISTER_DRIVER(pci_driver) pci_module_init(pci_driver)#endif#ifdef FOUND_TOUCH_ATIME#define TOUCH_ATIME(file) touch_atime((file)->f_vfsmnt,(file)->f_dentry);#else#define TOUCH_ATIME(file) update_atime((file)->f_dentry->d_inode);#endif#endif /* __OSCOMPAT_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -