首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在FreeBSD-11上添加一个新的系统调用,用于计算两个值的和。

在FreeBSD-11上添加一个新的系统调用,用于计算两个值的和。
EN

Stack Overflow用户
提问于 2017-02-14 20:02:49
回答 1查看 214关注 0票数 2

我是FreeBSD的初学者。我在VM上安装了FreeBSD-11.0版本-amd64 64。我想添加第一个新的系统调用,它用于计算两个值的和。但是我的函数有错误!mykern.c

代码语言:javascript
复制
#include <sys/sysproto.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/sysent.h>

  struct myargs {
       unsigned int k0;
       unsigned int k1;
};

int sys_func(struct thread *td, struct myargs *uap);

int sys_func (struct thread *td, struct myargs *uap)
{
     unsigned int a,b,c;
     a = uap->k0;
     b = uap->k1;
     c = a + b;
     printf("%u + %u = %u\n",a,b,c);
     return (0);
}

艾罗!

usr/src/sys/kern/mykern.c:17:5:错误:“sys_func”int sys_func的冲突类型(struct线程*td,struct *uap) /usr/src/sys/sys/syspri.h:2180:5:注意:前面的声明在int sys_func中( struct func_args *,struct func_args *);

我读了https://wiki.freebsd.org/AddingSyscalls的一个部分

代码语言:javascript
复制
    After adding an entry to sys/kern/syscalls.master, you must regenerate the generated files in sys/kern and sys/sys:
$ make -C sys/kern/ sysent
mv -f init_sysent.c init_sysent.c.bak
mv -f syscalls.c syscalls.c.bak
mv -f systrace_args.c systrace_args.c.bak
mv -f ../sys/syscall.h ../sys/syscall.h.bak
mv -f ../sys/syscall.mk ../sys/syscall.mk.bak
mv -f ../sys/sysproto.h ../sys/sysproto.h.bak
sh makesyscalls.sh syscalls.master

我检查了syspro.h文件,并在其中:

代码语言:javascript
复制
    struct func_args {
char uap_l_[PADL_(struct myargs *)]; struct myargs * uap; char uap_r_[PADR_(struct myargs *)];
};



sys_func(struct thread *, struct func_args*);

func_args是什么?有什么解决办法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-15 19:09:25

我编辑了我的代码,所以没有错误。我希望它能对其他人有所帮助。

代码语言:javascript
复制
#include <sys/sysproto.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/sysent.h>

#ifndef _SYS_SYSPROTO_H_
  struct func_args {
       unsigned int k0;
       unsigned int k1;
};
#endif


int sys_func (struct thread *td, struct func_args *uap)
{
     unsigned int a,b,c;
     a = uap->k0;
     b = uap->k1;
     c = a + b;
     printf("%u + %u = %u\n",a,b,c);
     return (0);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42235183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档