A simple new system call in FreeBSD-11.0-RELEASE-amd64

I am a newbie in FreeBSD. I installed FreeBSD-11.0-RELEASE-amd64 on VM. I want to add first new system call. I find this link.

I Did:

cd /usr/src/sys/kern
ee mykern.c


Code:
#include <sys/sysproto.h>
#include <sys/proc.h>
#include <sys/types.h>
#include <sys/systm.h>

#ifndef _SYS_SYSPROTO_H_
struct myargs {
   int k;
};
#endif

int func(struct thread *p, struct myargs *uap)
{
printf("Hello");
return (0);
}

I added my system call to the end /kern/syscalls.master

550 AUE_NULL STD { int func(int k);}

Then I did

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


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

Code:
 kern/mykern.c       standard

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

Code:
  ##
    ## Allow associating SHA1 key with user
    ##
    func

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

sudo make -j8 kernel

And in this step I get:

Code:
make don't know how to make kernel. Stop

make stopped in /usr/src



make buildkernel KERNCONF=MYKERNEL

Same error!
 
Last edited:
Forget adding your own module, first learn how to build world and the kernel. You need to learn to walk before you're able to run.


Make sure you have the full source in /usr/src/, not just parts of it. Then follow the handbook.
 
Thank you for your patience. I updated svn again with no error! Then I referred to Handbook and command make buildworld is running yet, after 4 hours!
I am a beginner and I want to add my first system call! It may possible that I want to test and edit my function and test again!
Should I use make buildworld command every time after I edit?
 
Yes, it's quite a lengthy process. It should not be needed to run it every time. It's recommended to run it first because it also sets up the build environment. But once it's there you can buildkernel as many times as you like.
 
Thank you so much for helping me! Finally, command make buildworld is finished. I referred to handbook again and continue.
But command make buildkernel has errors!!
Code:
/usr/src/sys/kern/mykern.c:12:35: error: declaration of 'struct myargs' will not be visible outside of this function [-Werror, Wvisibility]
int func(struct thread *p, struct myargs *uap)

/usr/src/sys/kern/mykern.c:12:5: error:no previous prototype for function 'func' [-Werror, -Wmissing-prototypes]
int func(struct thread *p, struct myargs *uap)

2 errors generated.
*** Error code 1

Stop.
make[2] stopped in /usr/obj/usr/src/sys/GENERIC
*** Error code 1

Stop.
make[1]: stopped in /usr/src/
*** Error code 1

Stop.
make: stopped in /usr/src
How can I solve problem?
How can I clean last make buildkernel that is corrupted (not make buildworld command that took many times!)?
 
Back
Top