【问题标题】:Add a new system call at FreeBSD-11 for calculating sum of two values在 FreeBSD-11 添加一个新的系统调用来计算两个值的总和
【发布时间】:2017-07-03 06:37:21
【问题描述】:

我是 FreeBSD 的初学者。我在 VM 上安装了 FreeBSD-11.0-RELEASE-amd64。我想添加第一个用于计算两个值之和的新系统调用。 但我的功能有错误! mykern.c

#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 thread *td, struct myargs *uap)

/usr/src/sys/sys/sysproto.h:2180:5: 注意:之前的声明在这里 int sys_func(struct thread *, struct func_args *);

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

    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

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

    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? 有什么解决办法吗?

【问题讨论】:

  • 您可能会在 FreeBSD IRC 频道或邮件列表上获得更多支持。

标签: kernel system-calls freebsd


【解决方案1】:

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

#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);
}

【讨论】:

  • cmps111?我被困在同一件事上
猜你喜欢
  • 2017-06-30
  • 2016-06-02
  • 2016-05-31
  • 1970-01-01
  • 1970-01-01
  • 2017-06-22
  • 1970-01-01
  • 1970-01-01
  • 2018-08-07
相关资源
最近更新 更多