开发者

How do I call Linux syscall from kernel space?

开发者 https://www.devze.com 2022-12-16 23:57 出处:网络
I\'m porting linux kernel module written for Linux 2.4 to work with Linux 2.6. Some syscalls开发者_JAVA百科 declared through syscallN() macros and wrapped in set_fs() calls were used in the code.

I'm porting linux kernel module written for Linux 2.4 to work with Linux 2.6. Some syscalls开发者_JAVA百科 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消