我想将虚拟地址参数(例如0xf23fa44)传递给小型内核模块。
无论我使用哪种参数类型(int,long),我都会得到Numerical result out of range
错误。无符号的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 :(得分:1)
来自宏module_param
的描述:
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).
对于unsigned long
的C类module_param
类型参数的对应值为ulong
:
static unsigned long address = 0;
module_param(address, ulong, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
答案 1 :(得分:0)
潜在的解决方案;您可以改用字符串
static char *str_name = "1231241233213213123123423";
module_param(str_name,charp,0000);
然后将字符串解析为适合该值的任何类型。