//所有的模块代码都包含下面两个头文件 #include#include #include //定义dev_t类型 #include //定义struct cdev结构体及相关 *** 作 #include //定义kmalloc接口 #include //定义virt_to_phys接口 #include //remap_pfn_range #include #define MAJOR_NUM 0 #define MM_SIZE 4096 static char driver_name[] = "mmap_driver1";//驱动模块名字 static int dev_major = MAJOR_NUM; static int dev_minor = 0; char *buf = NULL; struct cdev *cdev = NULL; static int device_open(struct inode *inode, struct file *file) { printk(KERN_alert"device openn"); buf = (char *)kmalloc(MM_SIZE, GFP_KERNEL);//内核申请内存只能按页申请,申请该内存以便后面把它当作虚拟设备 return 0; } static int device_close(struct inode *indoe, struct file *file) { printk("devi
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)