how to call a syscall in a kernel module?

Terry Lambert tlambert2 at mindspring.com
Sun Jul 6 09:03:14 PDT 2003


zhuyi wrote:
> Dear all:
> How to call a syscall in a kernel module? In Linux, you can add two
> line into your source code.
> 
> #define __KERNEL_SYSCALLS__
> #include <linux/unistd.h>

Most system calls call "copyin" or "copyinstr" or "uiomove", which
assumes that the data is in the user process that is active at the
time of the system call.  This basically boils down to UIO_SYSSPACE
vs. UIO_USERSPACE.  Because of this, it's generally not possible to
call system calls from within the kernel.

It's probably reasonable to turn all the system calls into wrappers;
there would be an additional function call worth of overhead for all
system calls, but the benefit would be to enable calling of all calls
from kernel space.  The overhead is probably worth it (AIX works this
way, and it doesn't seem to hurt them at all).

-- Terry


More information about the freebsd-hackers mailing list