kprobe_example.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | kprobe_example.c (d04659ac94528e9224dbf1aed37dd11dd952cacc) |
---|---|
1/* 2 * NOTE: This example is works on x86 and powerpc. 3 * Here's a sample kernel module showing the use of kprobes to dump a 4 * stack trace and selected registers when _do_fork() is called. 5 * 6 * For more information on theory of operation of kprobes, see 7 * Documentation/kprobes.txt 8 * 9 * You will see the trace data in /var/log/messages and on the console 10 * whenever _do_fork() is invoked to create a new process. 11 */ 12 13#include <linux/kernel.h> 14#include <linux/module.h> 15#include <linux/kprobes.h> 16 | 1/* 2 * NOTE: This example is works on x86 and powerpc. 3 * Here's a sample kernel module showing the use of kprobes to dump a 4 * stack trace and selected registers when _do_fork() is called. 5 * 6 * For more information on theory of operation of kprobes, see 7 * Documentation/kprobes.txt 8 * 9 * You will see the trace data in /var/log/messages and on the console 10 * whenever _do_fork() is invoked to create a new process. 11 */ 12 13#include <linux/kernel.h> 14#include <linux/module.h> 15#include <linux/kprobes.h> 16 |
17#define MAX_SYMBOL_LEN 64 18static char symbol[MAX_SYMBOL_LEN] = "_do_fork"; 19module_param_string(symbol, symbol, sizeof(symbol), 0644); 20 |
|
17/* For each probe you need to allocate a kprobe structure */ 18static struct kprobe kp = { | 21/* For each probe you need to allocate a kprobe structure */ 22static struct kprobe kp = { |
19 .symbol_name = "_do_fork", | 23 .symbol_name = symbol, |
20}; 21 22/* kprobe pre_handler: called just before the probed instruction is executed */ 23static int handler_pre(struct kprobe *p, struct pt_regs *regs) 24{ 25#ifdef CONFIG_X86 26 printk(KERN_INFO "pre_handler: p->addr = 0x%p, ip = %lx," 27 " flags = 0x%lx\n", --- 82 unchanged lines hidden --- | 24}; 25 26/* kprobe pre_handler: called just before the probed instruction is executed */ 27static int handler_pre(struct kprobe *p, struct pt_regs *regs) 28{ 29#ifdef CONFIG_X86 30 printk(KERN_INFO "pre_handler: p->addr = 0x%p, ip = %lx," 31 " flags = 0x%lx\n", --- 82 unchanged lines hidden --- |