如何编写由用户空间函数调用的内核空间函数?

时间:2013-06-02 12:27:20

标签: c linux kernel-mode

我想编写一个由Linux中的用户空间函数调用的内核空间函数,如下所示:

// kernel space function.
void hello_kernel()
{
  printk(KERN_INFO "Hello kernel space.");
  printk(KERN_INFO "I can do any thing!");
}

// user space function
void hello_kernel();
int main()
{
  printf("Invoking a kernel space function.");
  hello_kernel();
  return 0;
}

我不知道这个示例代码是否可行。

如何编写由用户空间函数调用的内核空间函数?

1 个答案:

答案 0 :(得分:3)

userland代码与内核代码接口的机制是系统调用,您可以阅读here

这意味着无法直接调用函数(这是用户区内存保护的重点),而是你需要将它添加到内核并重新编译它。

此信息可在互联网上找到(仅搜索),之前已被询问,例如here