- 论坛徽章:
- 0
|
大家好!
本人刚刚接触linux内核开发,想在内核中添加几个系统调用,内核的版本为2.6.32.63。在网上搜了一下类似于教程的博文,照着上面的方法实验了一下,可是每次编译内核的时候总是警告: syscall ***** not implemented。一开始以为是我没有严格按照教程上说的将系统调用的服务例程放到kernel/sys.c里面去实现,而是将他放到了ppp_generic.c里面。后来我去查看了内核中的sys_perf_event_open系统调用的实现,发现它也是放到了perf_event.c里面,也没有放到sys.c。我尝试模仿它的定义和添加方式,在syscalls.h中添加我定义的系统调用的asmlinkage声明。然后在ppp_generic.c里面用SYSCALL_DEFINE宏定义的方式定义系统调用的实现。在syscall_table_32.s和unistd_32.h里面也都添加了相应的表项和系统调用号,但是编译内核的时候又报告了一个错误——
ppp_generic.c:86:错误:与“sys_add_vr_record”类型冲突
syscalls.h:889:附注:“sys_add_vr_record”的上一个声明在此。
有没有哪位大牛也遇到类似的问题或者有这方面的经验指点一下我,不胜感激!!下面为我定义的系统调用的服务例程实现。在syscalls.h添加的声明为:
asmlinkage int sys_add_vr_record(int id, char *ip, int status);
asmlinkage int sys_del_vr_record(int id);
asmlinkage int sys_update_vr_record(int id, int status);
SYSCALL_DEFINE3(add_vr_record,int,id,char *,ip,int,status){
struct vr_record *new_record = make_record(id, ip, status);
if(new_record == NULL) return 0;
INIT_HLIST_NODE(&new_record->list);
hlist_add_head(&new_record->list, &vr_table_head);
printk("U just add a vr_record:");
printk("id:%d\t",id);
printk("ip:%s\t",ip);
printk("status:%d\n",status);
return 1;
}
SYSCALL_DEFINE1(del_vr_record,int,id){
struct vr_record *ops;
ops = NULL;
struct hlist_node *node;
hlist_for_each_entry(ops, node, &vr_table_head, list){
if(ops->id == id)
break;
}
if(ops == NULL){
printk("ERROR:can`t find vr_record with given id!\n");
return 0;
}
hlist_del(&ops->list);
printk("delete vr_record(%d) successfully!\n",id);
return 1;
}
SYSCALL_DEFINE2(update_vr_record,int,id,int,status){
struct vr_record *ops;
ops = NULL;
struct hlist_node *node;
hlist_for_each_entry(ops, node, &vr_table_head, list){
if(ops->id == id)
break;
}
if(ops == NULL){
printk("ERROR:can not update vr_record,no such record!");
return 0;
}
printk("update vr_record(%d,%d) successfully!", id, status);
ops->status = status;
return 1;
} |
|