如何从内核空间中的另一个系统调用进行系统调用 [英] How to make system call from another system call in kernel space
问题描述
我是Linux内核开发的新手.我已经在Linux内核2.6中实现了一个名为my_pid的系统调用.我想从系统调用中调用getpid系统调用.我该怎么办?
I am new in Linux kernel development. I have implemented a system call say my_pid in linux kernel 2.6. I want to call getpid system call from my system call. How can I do it?
我想要类似的东西:
pid_t my_pid(){ 返回getpid(); }
pid_t my_pid(){ return getpid(); }
也可以从C在用户空间中使用以下命令调用任何系统调用:syscall();在内核模式下执行此操作的通用方法是什么?
Also from C in user-space I can call any system call using: syscall(); What is the generic way to do this in kernel mode?
推荐答案
没有 这样的通用方法.
如果您在内核空间中,则应调用直接实现系统调用功能 的内核函数,而不要使用syscall
类型的指令,或使用其他方法来提取所需的信息/影响所需的动作.
If you are in kernel space, you should invoke kernel functions that implement the system call functionality directly instead of using syscall
-type instructions, or use other means of extracting the desired information / affecting the desired action.
对于getpid()
的特定情况,您可以简单地使用current->pid
.
For the specific case of getpid()
, you can simply use current->pid
.
内核名称current
始终是指向当前task_struct
的指针,该指针是通过
The kernel name current
is always a pointer to the current task_struct
, which is defined via <linux/sched.h>
(search for struct task_struct
). Code that accesses members of that usually gets inlined, i.e. there's not even a function call (and much less a system call) required to get these when your code is running as part of the kernel.
这篇关于如何从内核空间中的另一个系统调用进行系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!