How do I call Linux syscall from kernel space?

泪湿孤枕 提交于 2019-12-10 15:02:30

问题


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:


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.



来源:https://stackoverflow.com/questions/2070514/how-do-i-call-linux-syscall-from-kernel-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!