views:

305

answers:

1

I'm porting linux kernel module written for Linux 2.4 to work with Linux 2.6. Some syscalls declared through syscallN() macros and wrapped in set_fs() calls were used in the code. How can I still use sycalls in Linux 2.6 where those macros are absent?

I know it's a bad taste to use syscalls from kernel space and syscallN() macros are broken on most platforms. Any reasonable way to replace getuid, geteuid, mknod, chown, unlink, sched_yield syscalls in kernel space is appreciated.

+1  A: 

current->uid and current->euid can substitute for the first two.

schedule() should work for the last one.

The filesystem operations look more complicated: you might try and see if sys_chown(), sys_mknod(), and sys_unlink() are exported (available for use by any module). If they work, great. There are some useful tips here. Otherwise, you have to dig a little deeper:

The chown syscall is defined in fs/open.c. At a glance I don't see why you couldn't copy that code into your own "kernel_chown" function and give it a try.

The mknodat and unlink syscalls are in fs/namei.c; they eventually wind up calling vfs_mknod() and vfs_unlink(), respectively. Maybe you can duplicate that code or figure out how it's done from there.

Eric Seppanen
current->uid and current->euid are no more available in 2.6.
Basilevs
It was present in early 2.6 kernels, but it looks like it was replaced with the `current_uid()` macro in 2.6.27. See `include/linux/cred.h`.
Eric Seppanen