📄 linux_wrapper.h
字号:
/*
* linux-wrapper.h
*
* Hard coded Linux kernel replacements for x86
*
* (c) 2003 Georg Acher (georg@acher.org)
*
* Emulation of:
* typedefs
* structs
* macros
*
* All structs and prototypes are based on kernel source 2.5.72
*
* Modified by Aleksey Bragin (aleksey@reactos.com) for ReactOS needs
*
*
* #include <standard-GPL-header.h>
*/
/*------------------------------------------------------------------------*/
/* Typedefs */
/*------------------------------------------------------------------------*/
#include "cromwell_types.h"
typedef unsigned int __u32;
//typedef __u32 u32;
typedef unsigned short __u16;
//typedef __u16 u16;
typedef unsigned char __u8;
//typedef __u8 u8;
typedef short s16;
typedef u32 dma_addr_t;
typedef struct
{
KSPIN_LOCK SpinLock;
KIRQL OldIrql;
} spinlock_t;
typedef int atomic_t;
#ifndef STANDALONE
#ifndef _MODE_T_
#define _MODE_T_
typedef int mode_t;
#endif
#ifndef _PID_T_
#define _PID_T_
typedef int pid_t;
#endif
#ifndef _SSIZE_T_
#define _SSIZE_T_
typedef int ssize_t;
#endif
#endif
typedef int irqreturn_t;
typedef unsigned long kernel_ulong_t;
typedef int wait_queue_head_t;
/*------------------------------------------------------------------------*/
/* Stuff from xbox/linux environment */
/*------------------------------------------------------------------------*/
#include "list.h"
#ifndef STANDALONE
#ifdef MODULE
typedef int size_t;
#define NULL ((void*)0)
extern void * memset(void *,int,unsigned int);
extern void * memcpy(void *,const void *,unsigned int);
#if 0
extern char * strcpy(char *,const char *);
#else
static inline char * strcpy(char * dest,const char *src)
{
int d0, d1, d2;
__asm__ __volatile__(
"1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
: "=&S" (d0), "=&D" (d1), "=&a" (d2)
:"0" (src),"1" (dest) : "memory");
return dest;
}
#endif
extern size_t strlen(const char *);
extern int memcmp(const void *,const void *,unsigned int);
#else
#include "boot.h"
#include "config.h"
#endif
#else
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "consts.h"
#include <string.h>
#endif
/*------------------------------------------------------------------------*/
/* General structs */
/*------------------------------------------------------------------------*/
struct timer_list {
void (*function)(unsigned long);
unsigned long data;
int expires;
struct list_head timer_list;
};
struct work_struct {
void (*func)(void *);
};
struct device {
char name[128];
struct bus_type *bus;
int dma_mask;
char bus_id[16];
struct device_driver* driver;
void *driver_data;
struct device *parent;
struct list_head driver_list;
void (*release)(struct device * dev);
PDEVICE_OBJECT dev_ext; // ReactOS-specific: pointer to windows device object
};
struct class_device{int a;};
struct semaphore{int a;};
struct device_driver{
char *name;
struct bus_type *bus;
int (*probe) (struct device * dev);
int (*remove) (struct device * dev);
struct list_head devices;
};
struct bus_type {
char * name;
int (*match)(struct device * dev, struct device_driver * drv);
struct device * (*add) (struct device * parent, char * bus_id);
int (*hotplug) (struct device *dev, char **envp,
int num_envp, char *buffer, int buffer_size);
};
struct dummy_process
{
int flags;
};
struct pt_regs
{
int a;
};
struct completion {
unsigned int done;
KEVENT wait;
//wait_queue_head_t wait;
};
// windows lookaside list head
typedef void* kmem_cache_t;
struct dma_pool
{
int dummy;
};
/* These definitions mirror those in pci.h, so they can be used
* interchangeably with their PCI_ counterparts */
enum dma_data_direction {
DMA_BIDIRECTIONAL = 0,
DMA_TO_DEVICE = 1,
DMA_FROM_DEVICE = 2,
DMA_NONE = 3,
};
/* compatibility */
#define PCI_DMA_TODEVICE DMA_TO_DEVICE
#define PCI_DMA_FROMDEVICE DMA_FROM_DEVICE
/* from mod_devicetable.h */
struct usb_device_id {
/* which fields to match against? */
__u16 match_flags;
/* Used for product specific matches; range is inclusive */
__u16 idVendor;
__u16 idProduct;
__u16 bcdDevice_lo;
__u16 bcdDevice_hi;
/* Used for device class matches */
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
/* Used for interface class matches */
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
/* not matched against */
kernel_ulong_t driver_info;
};
/* Some useful macros to use to create struct usb_device_id */
#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
/*------------------------------------------------------------------------*/
/* imported functions from top-level */
/*------------------------------------------------------------------------*/
//void zxprintf(char* fmt, ...);
//void zxsprintf(char *buffer, char* fmt, ...);
//int zxsnprintf(char *buffer, size_t s, char* fmt, ...);
/*------------------------------------------------------------------------*/
/* PCI structs (taken from linux/pci.h et al., but slightly modified) */
/*------------------------------------------------------------------------*/
struct pci_dev {
int vendor;
int device;
struct pci_bus *bus;
int irq;
char *slot_name;
struct device dev;
int base[4];
int flags[4];
void * data;
void * dev_ext; // link to Windows DeviceExtension
};
struct pci_bus {
unsigned char number;
};
struct pci_device_id {
__u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
__u32 subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
__u32 class, class_mask; /* (class,subclass,prog-if) triplet */
kernel_ulong_t driver_data; /* Data private to the driver */
};
struct pci_driver {
struct list_head node;
char *name;
const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
int STDCALL (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
void STDCALL (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
int (*save_state) (struct pci_dev *dev, u32 state); /* Save Device Context */
int (*suspend) (struct pci_dev *dev, u32 state); /* Device suspended */
int (*resume) (struct pci_dev *dev); /* Device woken up */
int (*enable_wake) (struct pci_dev *dev, u32 state, int enable); /* Enable wake event */
};
struct scatterlist
{
int page;
int offset;
int length;
};
struct usbdevfs_hub_portinfo
{
int nports;
int port[8];
};
/*------------------------------------------------------------------------*/
/* constant defines */
/*------------------------------------------------------------------------*/
#define TASK_UNINTERRUPTIBLE 0
#define HZ 100 /* Don't rely on that... */
#define KERN_DEBUG "DBG: "
#define KERN_ERR "ERR: "
#define KERN_WARNING "WRN: "
#define KERN_INFO "INF: "
#define GFP_KERNEL 0
#define GFP_ATOMIC 0x20
#define GFP_NOIO 0
#define SLAB_ATOMIC 0
#define PCI_ANY_ID (~0)
#define SIGKILL 9
#define THIS_MODULE 0
//#define PAGE_SIZE 4096
#define CLONE_FS 0
#define CLONE_FILES 0
#define CLONE_SIGHAND 0
#define PF_FREEZE 0
#define PF_IOTHREAD 0
#define USBDEVFS_HUB_PORTINFO 1234
#define SA_SHIRQ 0
#undef PCI_COMMAND
#define PCI_COMMAND 0
#undef PCI_COMMAND_MASTER
#define PCI_COMMAND_MASTER 0
/*------------------------------------------------------------------------*/
/* Module/export macros */
/*------------------------------------------------------------------------*/
#define MODULE_AUTHOR(a)
#define MODULE_DESCRIPTION(a)
#define MODULE_LICENSE(a)
#define MODULE_DEVICE_TABLE(type,name) void* module_table_##name=&name
#define MODULE_PARM(a,b)
#define MODULE_PARM_DESC(a,b)
#define __devinit
#define __exit
#define __init
#define __devinitdata
#define module_init(x) static void module_init_##x(void){ x();}
#define module_exit(x) void module_exit_##x(void){ x();}
#define EXPORT_SYMBOL_GPL(x)
#define EXPORT_SYMBOL(x)
#define __setup(x,y) int setup_##y=(int)y
#define subsys_initcall(x) void subsys_##x(void){x();}
/*------------------------------------------------------------------------*/
/* Access macros */
/*------------------------------------------------------------------------*/
#define dev_get_drvdata(a) (a)->driver_data
#define dev_set_drvdata(a,b) (a)->driver_data=(b)
#define __io_virt(x) ((void *)(x))
#define readl(addr) (*(volatile unsigned int *) __io_virt(addr))
#define writel(b,addr) (*(volatile unsigned int *) __io_virt(addr) = (b))
#define likely(x) (x)
#define unlikely(x) (x)
#define prefetch(x) 1
#define inw(x) READ_PORT_USHORT((PUSHORT)(x))
#define outw(x,p) WRITE_PORT_USHORT((PUSHORT)(p),(x))
#define outl(x,p) WRITE_PORT_ULONG((PULONG)(p),(x))
/* The kernel macro for list_for_each_entry makes nonsense (have no clue
* why, this is just the same definition...) */
#undef list_for_each_entry
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member), \
prefetch(pos->member.next))
/*------------------------------------------------------------------------*/
/* function wrapper macros */
/*------------------------------------------------------------------------*/
#define kmalloc(x,y) ExAllocatePool(PagedPool,x)
#define kfree(x) ExFreePool(x)
//#define sprintf(a,b,format, arg...) zxsprintf((a),(b),format, ## arg)
//#define snprintf(a,b,format, arg...) zxsnprintf((a),(b),format, ##arg)
//#define printk(format, arg...) zxprintf(format, ## arg)
#define snprintf(a,b,format, arg...) _snprintf((a),(b),format, ##arg)
#define printk(format, arg...) DPRINT1(format, ## arg)
#define BUG(...) do {} while(0)
/* Locks & friends */
#define DECLARE_MUTEX(x) struct semaphore x
#define init_MUTEX(x)
#define SPIN_LOCK_UNLOCKED 0
#define spin_lock_init(a) my_spin_lock_init(a)
void my_spin_lock_init(spinlock_t *sl);
#define spin_lock(a) my_spin_lock(a)
void my_spin_lock(spinlock_t *sl);
#define spin_unlock(a) my_spin_unlock(a)
void my_spin_unlock(spinlock_t *sl);
#define spin_lock_irqsave(a,b) b=0, my_spin_lock_irqsave(a,b)
void my_spin_lock_irqsave(spinlock_t *sl, int flags);
#define spin_unlock_irqrestore(a,b) my_spin_unlock(a)
#if 0
#define local_irq_save(x) __asm__ __volatile__("pushfl ; popl %0 ; cli":"=g" (x): /* no input */ :"memory")
#define local_irq_restore(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory", "cc")
#else
#define local_irq_save(x) do {} while(0)
#define local_irq_restore(x) do {} while(0)
#endif
#define atomic_inc(x) *(x)+=1
#define atomic_dec(x) *(x)-=1
#define atomic_dec_and_test(x) (*(x)-=1,(*(x))==0)
#define atomic_set(x,a) *(x)=a
#define atomic_read(x) *(x)
#define ATOMIC_INIT(x) (x)
#define down(x) do {} while(0)
#define up(x) do {} while(0)
#define down_trylock(a) 0
#define down_read(a) do {} while(0)
#define up_read(a) do {} while(0)
#define DECLARE_WAIT_QUEUE_HEAD(x) KEVENT x
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -