# FreeBSD kernel system call



## goia.i.alexandru (Jun 19, 2019)

Greetings !

I am trying to write the code to a Unix system call, on the
FreeBSD 12.0 system. I managed to do that on Linux :

http://romania-acknowledges-stars.blogspot.com/2018/10/angel-call-in-kernel.html

but I find hard, without proper documentation, to implement it
on FreeBSD.

Please help.
Thank you.
Alexander Goia


----------



## SirDice (Jun 19, 2019)

FreeBSD is not Linux and system calls are implemented differently.









						Chapter 11. x86 Assembly Language Programming
					

x86 Assembly Language Programming




					www.freebsd.org
				












						How to create a system call for FreeBSD kernel
					

This is a short note on how to create a system call for FreeBSD.  First of all, assume that you already have a kernel function that you would like to call. Let gives a more complicate example than …




					joekuan.wordpress.com
				





			How to Implement a New System Call in FreeBSD


----------



## ralphbsz (Jun 19, 2019)

As background for any kernel programmer, it would probably be a good idea to read the "daemon book", a.k.a. The Design and Implementation of *BSD, by Kirk McKusick and friends.


----------



## goia.i.alexandru (Jun 20, 2019)

I have tried, but it seems that the relation thread/process is different in FreeBSD than that of Linux, where process almost congruent to thread.
Indeed FreeBSD is more mature and complex that Linux (at the level of quality and maturity of code), but system calls theoretically are equivalent, at  least at the level of concepts and of implementation in source code (do that and that, in that and that files, and not forget to #include that and that header).
I will try once more, and more, and more, till I get the final and perfect, proper result.
Thank you.


----------



## goia.i.alexandru (Jun 20, 2019)

As I try to understand FreeBSD kernel programming (and eventually the design), I have only the support of my (limited) knowledge of Linux kernel programming and UNIX design (may it be Bach's book, and Linux : ULK & Robert Love). I try to put them - FreeBSD , Linux - in parallel, in comparation...


----------



## drhowarddrfine (Jun 20, 2019)

You will have better access to more people deeply involved in this on the mailing lists than you will find here, though a few do hang out here.


----------



## ralphbsz (Jun 20, 2019)

goia.i.alexandru said:


> ...  system calls theoretically are equivalent, at  least at the level of concepts and of implementation in source code (do that and that, in that and that files, and not forget to #include that and that header).


Only theoretically. In practice, kernel interfaces are wildly different. That's why writing kernel code that needs to run in multiple OSes is very difficult and time-consuming.



goia.i.alexandru said:


> As I try to understand FreeBSD kernel programming (and eventually the design), I have only the support of my (limited) knowledge of Linux kernel programming and UNIX design (may it be Bach's book, and Linux : ULK & Robert Love). I try to put them - FreeBSD , Linux - in parallel, in comparation...


The Bach book is about SysV, and has very little to do with Linux (which pretty much started from scratch), and not very much with BSD (which diverged from AT&T and SysV about 40 years ago). Using Linux books for BSD kernel programming is ... to put it politely, unproductive. It is like telling a young person to learn to drive in Japan or England, and then making them take the driver's license exam in the US or France. That will hurt.


----------



## _martin (Jun 22, 2019)

Just FYI if you missed it:  this category Development/FreeBSD development has a sticky thread. There's lots of nice reading material there.


----------

