在FreeBSD 10.1上添加新的系统调用 [英] Add new system call at FreeBSD 10.1

查看:141
本文介绍了在FreeBSD 10.1上添加新的系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wanna add new system call at FreeBSD. My system call code is:

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

但是当我重建内核时,出现错误:

But when I rebuild the kernel, I have an error:

怎么了?你能帮我吗?

非常感谢.

推荐答案

这是我使用setkey示例系统调用(它需要两个未签名的整数)来实现的. 我将系统调用添加到/kern/syscalls.master

Here's how I did it with my example system call of setkey which takes two unsigned ints. I added my system call to the end /kern/syscalls.master

546 AUE_NULL    STD { int setkey(unsigned int k0, unsigned int k1);}

然后我做了

cd /usr/src
sudo make -C /sys/kern/ sysent

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

Next, I added the file to /sys/conf/files

kern/sys_setkey.c       standard

我的sys_setkey.c如下

My sys_setkey.c is as follows

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

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

Also, I added the system call to /kern/capabilities.conf

##
## Allow associating SHA1 key with user
##
setkey

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

Finally, while in /usr/src/ I ran the command

sudo make -j8 kernel
sudo reboot

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

This is a program which runs the system call

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

这篇关于在FreeBSD 10.1上添加新的系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆