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



## suraty (Feb 7, 2017)

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`


```
#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


```
kern/mykern.c       standard
```

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


```
##
    ## 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:


```
make don't know how to make kernel. Stop

make stopped in /usr/src
```


`make buildkernel KERNCONF=MYKERNEL`
Same error!


----------



## SirDice (Feb 7, 2017)

I suggest you get acquainted with the build process first.

Handbook: 23.6. Rebuilding World


----------



## suraty (Feb 7, 2017)

SirDice said:


> I suggest you get acquainted with the build process first.
> 
> Handbook: 23.6. Rebuilding World


Other steps are correct?
by adding file to conf/files, it doesn't configure to how to make?
In Handbook: 23.6. Rebuilding World, in* make buildworld *I get same error again!
Please help me. I searched again and again! The results are for old version of freebsd.


----------



## SirDice (Feb 7, 2017)

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.


----------



## suraty (Feb 8, 2017)

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?


----------



## SirDice (Feb 8, 2017)

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.


----------



## suraty (Feb 8, 2017)

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!!

```
/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!)?


----------

