将大数字参数传递给内核模块
Pass a big number parameter to kernel module
我想传递一个虚拟地址参数(例如0xf23fa44)给一个小内核模块。
我得到:Numerical result out of range
错误,无论我使用的参数类型是什么(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);
来自宏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).
对于 C 类型 unsigned long
type 参数对应的值 module_param
是 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);
并将字符串解析为适合该值的任何类型。
我想传递一个虚拟地址参数(例如0xf23fa44)给一个小内核模块。
我得到:Numerical result out of range
错误,无论我使用的参数类型是什么(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);
来自宏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).
对于 C 类型 unsigned long
type 参数对应的值 module_param
是 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);
并将字符串解析为适合该值的任何类型。