How can I call syscall linux from kernel space?

I am porting a Linux kernel module written for Linux 2.4 to work with Linux 2.6. The code used some system calls declared using syscallN() macros and wrapped in set_fs() calls. How can I use sycalls on Linux 2.6 where these macros are missing?

I know that the bad taste of using system calls from kernel space and the syscallN() macros syscallN() broken on most platforms. Any reasonable way to replace getuid , geteuid , mknod , chown , unlink , sched_yield syscalls in kernel space is appreciated.

+4
source share
1 answer

current->uid and current->euid can replace the first two.

schedule() should work for the latter.

File system operations look more complex: you can try and see if sys_chown() , sys_mknod() and sys_unlink() are sys_unlink() (available for use by any module). If they work, great. Here are some helpful helpful tips here . Otherwise, you have to dig a little deeper:

Syscall chown defined in fs/open.c At first glance, I don’t understand why you could not copy this code into your own kernel_chown function and try.

Syscalls mknodat and unlink are in fs/namei.c ; they end up calling vfs_mknod() and vfs_unlink() , respectively. Perhaps you can duplicate this code or find out how to do it from there.

+3
source

All Articles