在FreeBSD 10.1中添加新的系统调用

use*_*884 1 unix kernel freebsd system-calls

我想在FreeBSD上添加新的系统调用.我的系统调用代码是:

#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/mount.h>
#include <sys/sysproto.h>

int Sum(int a, int b);

int
Sum(a,b)
{
   int c;
   c = a + b;
   return (0);
}
Run Code Online (Sandbox Code Playgroud)

但是当我重建内核时,我有一个错误:

在此输入图像描述

怎么了?你能帮助我吗?

非常感谢.

Rau*_*l M 5

以下是我使用setkey的示例系统调用的方法,该调用采用两个无符号整数.我将系统调用添加到了结束/kern/syscalls.master

546 AUE_NULL    STD { int setkey(unsigned int k0, unsigned int k1);}
Run Code Online (Sandbox Code Playgroud)

然后我做了

cd /usr/src
sudo make -C /sys/kern/ sysent
Run Code Online (Sandbox Code Playgroud)

接下来,我将文件添加到/ sys/conf/files

kern/sys_setkey.c       standard
Run Code Online (Sandbox Code Playgroud)

我的sys_setkey.c如下

#include <sys/sysproto.h>
#include <sys/proc.h>

//required for printf
#include <sys/types.h>
#include <sys/systm.h>

#ifndef _SYS_SYSPROTO_H_
struct setkey_args {
    unsigned int k0;
    unsigned int k1;
};
#endif
/* ARGSUSED */
int sys_setkey(struct thread *td, struct setkey_args *args)
{
    printf("Hello, Kernel!\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

另外,我将系统调用添加到/kern/capabilities.conf

##
## Allow associating SHA1 key with user
##
setkey
Run Code Online (Sandbox Code Playgroud)

最后,在/ usr/src /中运行命令

sudo make -j8 kernel
sudo reboot
Run Code Online (Sandbox Code Playgroud)

这是一个运行系统调用的程序

#include <sys/syscall.h>
#include <unistd.h>
#include <stdio.h>
int main(){
//syscall takes syscall.master offset,and the system call arguments
printf("out = %d\n",syscall(546,1,1));
return 0;
}
Run Code Online (Sandbox Code Playgroud)