当前位置: 技术问答>linux和unix
菜鸟问题:内核模块编程,大家给看看出了什么问题
来源: 互联网 发布时间:2015-08-10
本文导语: [root@localhost testmodule]# cat TestModule.c #include #include #include #include #include #include #include #include #if CONFIG_MODVERSIONS==1 #define MODVERSIONS #include #endif MODULE_LICENSE("GPL"); int init_module(void) { printk("Hello!...
[root@localhost testmodule]# cat TestModule.c
#include
#include
#include
#include
#include
#include
#include
#include
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include
#endif
MODULE_LICENSE("GPL");
int init_module(void)
{
printk("Hello! this is a testing module!n");
return 0;
}
int open(struct inode *inode,struct file *filp)
{
MOD_INC_USE_COUNT;
printk("This module is in open!n");
return 0;
}
void release(struct inode *inode,struct file *filp)
{
MOD_DEC_USE_COUNT;
printk("this module is in release!n");
#ifdef DEBUG
printk("release(%p,%p)n",inode,filp);
#endif
}
int read(struct inode *inode, struct file *filp,char *buf,int count)
{
int leave;
if (verify_area(VERIFY_WRITE,buf,count)== -EFAULT)
return -EFAULT;
for(leave=count;leave>0;leave--)
{
__put_user(1,buf,1);
buf++;
}
return count;
}
int write(struct inode *inode, struct file *filp,const char *buf,int count)
{
return count;
}
void cleanup_module(void)
{
printk("bye,byen");
}
用gcc编译: gcc -O2 -g -Wall -DMODULE -D__KERNEL__ -I /usr/src/linux-2.4.20-8/include -c TestModule.c
可是老是出问题,大家给看看
[root@localhost testmodule]# gcc -O2 -g -Wall -DMODULE -D__KERNEL__ -I /usr/src/linux-2.4.20-8/include -c TestModule.c
TestModule.c: In function `init_module':
TestModule.c:21: warning: implicit declaration of function `printk_R1b7d4074'
TestModule.c: In function `read':
TestModule.c:47: warning: implicit declaration of function `verify_area'
TestModule.c:47: `VERIFY_WRITE' undeclared (first use in this function)
TestModule.c:47: (Each undeclared identifier is reported only once
TestModule.c:47: for each function it appears in.)
TestModule.c:52: warning: implicit declaration of function `__put_user'
谢谢大家.
|
我把#include 这个头文件删除,还把VERIFY_WRITE定义为1编译就能通过了!