Thanks for replying my question. I did solve this problem by moving handler_pre function
declared before the assignment [kp.pre_handler=hander_pre];
but I don't know the reason why.
Would you please to tell me the reason why?
That's my new first question.
Second, I encounter new one after compiling source code. It has messenges like "***
Warning: "kallsyms_lookup_name"
[/root/program/kernel/module/sample/probe.ko] undefined!",
which results in the error when 'inmode my_module.ko' ( error message
is "insmod: error inserting 'probe.ko': -1 Unknown symbol in module");
but I've already had kallsyms.h decleared in my source code.
How to solve it? I know it maybe a stupid question, but I'm new to
such kind of programming and willing to know how.
I appreciate any suggestion,
Sincerely
env is debian 3.0r2 with kernel updated to 2.6.9; gcc 2.95.4.
below is my source code:
==========Kprobe.c==========BEG
#include <linux/kallsyms.h>
#include <linux/module.h>
#include <linux/kernel.h>
/* kprobes */
#include <linux/kprobes.h>
int
handler_pre(struct kprobe *p, struct pt_regs *regs)
{
printk("pre_hanlder: p->addr=0x%p, eflags=0x%lx\n",
p->addr, regs->eflags);
return 0;
}
void
handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long
eflags)
{
printk("post_handler: p->addr=0x%p, eflags=0x%lx \n",
p->addr, regs->eflags);
}
int
handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr)
{
printk("fault_handler

->addr=0x%p, eflags=0x%lx\n",
p->addr, regs->eflags);
return 0;
}
int
init_module(void)
{
struct kprobe kp;
printk(KERN_ALERT"init module!\n");
kp.pre_handler=handler_pre;
kp.post_handler=handler_post;
kp.fault_handler=handler_fault;
kp.addr=(kprobe_opcode_t *)kallsyms_lookup_name("do_fork");
if(kp.addr==NULL){
printk("kallsyms_lookup_name could not find address for the
specified sumbol name!\n");
return 1;
}
register_kprobe(&kp);
return 0;
}
void
cleanup_module()
{
printk(KERN_ALERT"cleanup module!\n");
}
==========Kprobe.c==========END
Quote:
Originally posted by UsualTuxpect
Did you include/define the structures "struct kprobe" , and "struct pt_regs" defined in -->
int handler_pre(struct kprobe *p, struct pt_regs *regs) .
|