如何从内核空间调用Linux syscall? [英] How do I call Linux syscall from kernel space?
问题描述
我正在移植为Linux 2.4编写的linux内核模块,以便与Linux 2.6一起使用.
在代码中使用了一些通过syscallN()
宏声明并包装在set_fs()
调用中的系统调用.
在那些宏不存在的Linux 2.6中,我仍如何使用sycall?
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?
我知道在内核平台上使用syscall是不好的口味,并且syscallN()
宏在大多数平台上都是坏的.赞赏在内核空间中替换getuid
,geteuid
,mknod
,chown
,unlink
,sched_yield
syscall的任何合理方法.
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
和current->euid
可以代替前两个.
schedule()
应该适用于最后一个.
schedule()
should work for the last one.
文件系统操作看起来更加复杂:您可以尝试查看是否导出了sys_chown()
,sys_mknod()
和sys_unlink()
(可用于任何模块).如果他们有效,那就太好了.这里有一些有用的提示.否则,您必须进行更深入的研究:
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:
chown
系统调用在fs/open.c
中定义.乍一看,我不明白为什么您不能将该代码复制到自己的"kernel_chown"函数中并进行尝试.
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.
mknodat
和unlink
系统调用位于fs/namei.c
中;他们最终最终分别调用vfs_mknod()
和vfs_unlink()
.也许您可以复制该代码或从那里弄清楚它是如何完成的.
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.
这篇关于如何从内核空间调用Linux syscall?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!