2013-01-08 13 views
2

我在Scientific Linux 6.3 x86_64下編寫了一個內核模塊,我正在使用kprobes。在這個模塊中,我需要訪問返回函數的第一個參數,所以jprobes不在了。從kprobe獲取參數找不到regs-> rdi x86_64

我發現這非常有幫助的帖子: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); 
} 

導致:當被定義__KERNEL__

... 
/home/user/kmod/kprobe_64_mwe/kprobe_mwe.c:7: error: ‘struct pt_regs’ has no member named ‘rdi’ 
... 

回答

2

pt_reg變化的定義。請嘗試使用di

+0

明白了,我正在通過ptrace.h進行查看,並且從來沒有想到這一點。非常感謝! – zje