如何使用从Linux内核模块Linux系统调用 [英] How do I use a Linux System call from a Linux Kernel Module
问题描述
我有一些困难,呼吁从一个Linux内核模块内部的系统调用。系统调用已经过测试,从一个标准的C用户空间程序正常工作,但我似乎无法获得内核模块编译和运行它们。
在我的用户我的程序包括以下code和系统调用的作品:
的#include< Linux的/ unistd.h中>
#定义__NR_sys_mycall 343EXTERN长整型_syscall(长int_sysno,...)__ THROW;//然后一个简单的电话是这样做的
长值=系统调用(__ NR_sys_mycall);的printf(该值是%ld个\\ N,值);
但是,当我尝试在我的Linux内核模块同样的事情,我收到了一堆错误,要么说错误:函数'系统调用'隐式声明(如果我不包括_syscall定义)或错误的一个长长的清单有关语法如果我这样做...所以我的假设是,我需要的内核太空版调用系统调用。我是对还是错?
//我的LKM code
#包括LT&; Linux的/ - module.h中GT;
#包括LT&; Linux的/ unistd.h中>
#定义__NR_sys_mycall 343静态INT start_init(无效)
{
长值=系统调用(__ NR_sys_mycall);
printk的(的值%LD \\ N,值); 返回0;
}静态无效finish_exit(无效)
{
printk的(完成\\ n!);
}宏module_init(start_init);
宏module_exit(finish_exit);
您可以直接调用的 sys_mycall
的#include< Linux的/ - module.h中GT;
#包括LT&; Linux的/ unistd.h中>
静态INT start_init(无效)
{
长值= sys_mycall(pass_arguments)
printk的(的值%LD \\ N,值); 返回0;
}静态无效finish_exit(无效)
{
printk的(完成\\ n!);
}宏module_init(start_init);
宏module_exit(finish_exit);
I am having some difficulty calling a system call from inside a Linux Kernel Module. The system calls have been tested and work properly from a standard c user space program but I can't seem to get the kernel module to compile and run them.
In my user program I include the following code and the system call works:
#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);
But when I try the same thing in my Linux Kernel Module I get a bunch of errors that either say error: implicit declaration of function 'syscall' (if I don't include the _syscall definition) or a long list of errors about syntax if I do...so my assumption is that I need the kernel space version to call the system call. Am I right or wrong?
//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);
You can directly call sys_mycall.
#include <linux/module.h>
#include <linux/unistd.h>
static int start_init(void)
{
long value = sys_mycall (pass_arguments)
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);
这篇关于如何使用从Linux内核模块Linux系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!