我正在科学Linux6.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’
...发布于 2013-01-09 02:57:16
定义__KERNEL__时,pt_reg的定义会发生变化。请尝试使用di。
https://stackoverflow.com/questions/14221590
复制相似问题