How to make system call from another system call in kernel space

前端 未结 1 1811
[愿得一人]
[愿得一人] 2021-01-24 04:36

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?

相关标签:
1条回答
  • 2021-01-24 05:27

    There is no generic way of doing this.

    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.

    For the specific case of getpid(), you can simply use current->pid.

    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.

    0 讨论(0)
提交回复
热议问题