我正在 Scientific Linux 6.3 x86_64 下编写内核模块,我希望使用 kprobes。在这个模块中,我需要在返回时访问函数的第一个参数,所以 jprobes 不可用。
我发现这篇非常有用的帖子:Getting function arguments using kprobes
但是,当我尝试在我的探测器中访问 regs->rdi
时,编译器会报错
error: ‘struct pt_regs’ has no member named ‘rdi’
在我的模块初始化期间,我毫无问题地运行了这个检查:
#ifndef CONFIG_X86_64
printk(KERN_ALERT "Error: this module only supports x86_64!\n");
return -EINVAL;
#endif
还有什么我应该看的吗?
uname -r
返回 2.6.32-279.14.1.el6.x86_64.debug
这是一个 MWE:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/kprobes.h>
#include <linux/blkdev.h>
static int kprobe_test(struct kprobe *p, struct pt_regs *regs) {
printk(KERN_INFO "rdi: %p\n", regs->rdi);
return 0;
}
static struct kprobe myprobe = {
.pre_handler = NULL,
.post_handler = kprobe_test,
.fault_handler = NULL,
.addr = (kprobe_opcode_t *) generic_make_request,
};
int init_module(void) {
register_kprobe(&myprobe);
return 0;
}
void cleanup_module(void) {
unregister_kprobe(&myprobe);
}
结果是:
...
/home/user/kmod/kprobe_64_mwe/kprobe_mwe.c:7: error: ‘struct pt_regs’ has no member named ‘rdi’
...
最佳答案
当 __KERNEL__
被定义时,pt_reg
的定义发生改变。尝试改用 di
。
关于linux - 从 kprobe 获取参数未找到 regs->rdi x86_64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14221590/