我遇到了一些困难,无法从Linux内核模块中调用系统调用。这些系统调用已经通过标准的c用户空间程序进行了测试,并且运行正常,但我似乎无法让内核模块对其进行编译和运行。
在我的用户程序中,我包含以下代码,系统调用可以正常工作:
在我的用户程序中,我包含以下代码,系统调用可以正常工作:
#include <linux/unistd.h>
#define __NR_sys_mycall 343
extern long int _syscall(long int_sysno,...)__THROW;
//and then a simple call is done as such
long value = syscall(__NR_sys_mycall);
printf("The value is %ld\n",value);
但是当我在我的Linux内核模块中尝试同样的操作时,我会遇到一堆错误,其中有些会说error: implicit declaration of function 'syscall'(如果我没有包含_syscall定义),或者是如果我这样做的话语法上有很多错误,那么我的假设是我需要内核空间版本来调用系统调用。我的想法对吗?
//My LKM code
#include <linux/module.h>
#include <linux/unistd.h>
#define __NR_sys_mycall 343
static int start_init(void)
{
long value = syscall(__NR_sys_mycall);
printk("The value is %ld\n",value);
return 0;
}
static void finish_exit(void)
{
printk("Done!\n");
}
module_init(start_init);
module_exit(finish_exit);