免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1538 | 回复: 0
打印 上一主题 下一主题

[学习分享] CentOS添加系统调用的疑惑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-07-24 16:29 |只看该作者 |倒序浏览
大家好!
      本人刚刚接触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;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP