Naser Hamidi
Naser Hamidi

Reputation: 176

freebsd compile is so complicated?

I want to add custom syscall to freebsd(school work). I google hundreds of time. there is no right solution for it. my homework is: "Add custom syscall to freebsd kernel and recompile the kernel and use it". finally I find that I should follow instructions in these two pages:

1 : http://www.onlamp.com/pub/a/bsd/2003/10/09/adding_system_calls.html

then

2: https://www.freebsd.org/doc/en/books/handbook/kernelconfig-building.html

will it shows errors in compile time:

<sys/parma.h> no such file or directory
<sys/kern.h> no such file or directory
<sys/syscallargs.h> no such file or directory

I removed these three header include form my file then recompile it. now shows other errors like: MAXCPU undeclered in pcpu.h file.

what I missed? how can I do my school work?

NOTE: I use freebsd8 in vbox

Upvotes: 1

Views: 484

Answers (2)

user4822941
user4822941

Reputation:

Well take a look at share/examples/kld/syscall for a complete implementation as a module.

Adding a new file to teh kernel is left as an exercise for the reader.

Here is a hint: find the newest added file within kern/* subdir AND CHECK WHAT COMMITS WERE DONE TO MAKE IT COMPILE.

In fact you could have done exactly the same with syscall: FIND THE NEWEST ADDED SYSCALL AND CHECK HOW IT WAS ACHIEVED.

All this is available in svn/git repository history.

Upvotes: 1

Roland Smith
Roland Smith

Reputation: 43533

Look at what the error messages say; the files don't exist.

  • The first include file is a typo; it's param.h, not parma.h!
  • There is no kern.h. Maybe you mean sys/kernel.h?
  • Idem for syscallargs.h. Do you perhaps mean syscall.h?

You can find header files with e.g:

find /usr/src/sys/ -type f -name '*.h'|grep 'sys/.*kern.*\.h'
/usr/src/sys/ofed/include/linux/kernel.h
/usr/src/sys/dev/netmap/netmap_kern.h
...

Update: More important is determining which includes you actually need.

FreeBSD has pretty good documentation. If you want to use a kernel function or data-structure, it is probably covered in section 9 of the manual pages.

You can list all the manual pages in that section with ls /usr/share/man/man9/ | less. Or you can use the apropos command. Since you want to implement a syscall, start with e.g.

apropos syscall

It will return:

SYSCALL_MODULE(9)        - syscall kernel module declaration macro
syscall(2), __syscall(2) - indirect system call

It seems to me that the first one could be relevant to your assignment. (The second one is how to call a system call from user space.) So read it with man SYSCALL_MODULE. Or read it online.

Note that:

     A minimal example for a syscall module can be found in
     /usr/share/examples/kld/syscall/module/syscall.c.

That example should be enough to get you started on writing your own system call module...

Upvotes: 2

Related Questions