1

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:

enter image description here

What's wrong? Can you help me?

Thanks a lot.

user3228884
  • 131
  • 1
  • 12

2 Answers2

7

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;
}
Raul M
  • 124
  • 6
0

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 ).

Community
  • 1
  • 1
Roman Zaitsev
  • 1,328
  • 5
  • 20
  • 28
  • I enter my syscall name in usr/src/sys/conf ---> files... Is it true? If not, where is the make file directory that I should change? – user3228884 Feb 19 '16 at 10:42
  • I'm talking about file with name `Makefile`. If you are not familiar with makefiles, than read some tutorial about it ( for start - https://en.wikipedia.org/wiki/Makefile ) – Roman Zaitsev Feb 19 '16 at 10:52