Linux kernel 向内核模块传递一个大数字参数
我想将虚拟地址参数(例如0xf23fa44)传递给一个小型内核模块 我得到:Linux kernel 向内核模块传递一个大数字参数,linux-kernel,kernel-module,Linux Kernel,Kernel Module,我想将虚拟地址参数(例如0xf23fa44)传递给一个小型内核模块 我得到:数值结果超出范围错误,与我使用的参数类型无关(int,long)。Unsigned int&Unsigned long给出编译错误 我怎样才能解决这个问题 以下是我的源代码: #include <...headers...> static long address = 0; module_param(address, long, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
数值结果超出范围
错误,与我使用的参数类型无关(int,long)。Unsigned int&Unsigned long给出编译错误
我怎样才能解决这个问题
以下是我的源代码:
#include <...headers...>
static long address = 0;
module_param(address, long, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
static int hello_init(void){
struct task_struct *task_struct = (struct task_struct*) address;
printk(KERN_ALERT "----BEGIN-------\n");
printk("pid: %x\n" task_struct->pid)
printk(KERN_ALERT "----END-------\n");
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "----EXIT---------\n");
}
module_init(hello_init);
module_exit(hello_exit);
#包括
静态长地址=0;
模块参数(地址,长,S|u IRUSR | S|u IWUSR | S|u IRGRP | S|IROTH);
静态int hello_init(void){
结构任务\结构*任务\结构=(结构任务\结构*)地址;
printk(内核警报“---BEGIN-----\n”);
printk(“pid:%x\n”任务结构->pid)
printk(内核警报“-----结束----\n”);
返回0;
}
静态void hello_退出(void){
printk(内核警报“-----退出----------n”);
}
模块_init(hello_init);
模块退出(你好退出);
从宏模块参数的描述中:
Standard types are:
byte, short, ushort, int, uint, long, ulong
charp: a character pointer
bool: a bool, values 0/1, y/n, Y/N.
invbool: the above, only sense-reversed (N = true).
对于C类型无符号长
模块参数
的类型参数对应的值为ulong
:
static unsigned long address = 0;
module_param(address, ulong, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
潜在的解决方案;你可以用字符串代替
static char *str_name = "1231241233213213123123423";
module_param(str_name,charp,0000);
并将字符串解析为适合该值的任何类型。不清楚“将参数传递给内核模块”是什么意思。它是否像一个
insmod modname.ko param=0xf23fa44
?如果是,请显示模块的代码(它是如何定义参数的)。是的,这就是我的意思。我不知道消息来源。基本上,我使用module_param(my_long,long,…)添加了源代码