Add new system call at FreeBSD 10.1

落爺英雄遲暮 提交于 2019-12-07 06:07:25

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

Then I did

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

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

kern/sys_setkey.c       standard

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

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

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

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;
}
Roman Zaitsev

Please read this

I think, that you haven't included your file with sys_Sum function in kernel makefile ( notice, that in your code, that you have provided, function name is Sum and in error there is call to sys_Sum. I hope, that it's just a typo in your code and the name of function is sys_Sum ).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!