Automatic merge of rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver...
[linux-2.6/verdex.git] / include / linux / kprobes.h
blob99ddba5a4e009b553a56e2c25b1d89c41154fb8e
1 #ifndef _LINUX_KPROBES_H
2 #define _LINUX_KPROBES_H
3 /*
4 * Kernel Probes (KProbes)
5 * include/linux/kprobes.h
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Copyright (C) IBM Corporation, 2002, 2004
23 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
24 * Probes initial implementation ( includes suggestions from
25 * Rusty Russell).
26 * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
27 * interface to access function arguments.
29 #include <linux/config.h>
30 #include <linux/list.h>
31 #include <linux/notifier.h>
32 #include <linux/smp.h>
33 #include <asm/kprobes.h>
35 struct kprobe;
36 struct pt_regs;
37 typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
38 typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
39 typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
40 unsigned long flags);
41 typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
42 int trapnr);
43 struct kprobe {
44 struct hlist_node hlist;
46 /* list of kprobes for multi-handler support */
47 struct list_head list;
49 /* location of the probe point */
50 kprobe_opcode_t *addr;
52 /* Called before addr is executed. */
53 kprobe_pre_handler_t pre_handler;
55 /* Called after addr is executed, unless... */
56 kprobe_post_handler_t post_handler;
58 /* ... called if executing addr causes a fault (eg. page fault).
59 * Return 1 if it handled fault, otherwise kernel will see it. */
60 kprobe_fault_handler_t fault_handler;
62 /* ... called if breakpoint trap occurs in probe handler.
63 * Return 1 if it handled break, otherwise kernel will see it. */
64 kprobe_break_handler_t break_handler;
66 /* Saved opcode (which has been replaced with breakpoint) */
67 kprobe_opcode_t opcode;
69 /* copy of the original instruction */
70 struct arch_specific_insn ainsn;
74 * Special probe type that uses setjmp-longjmp type tricks to resume
75 * execution at a specified entry with a matching prototype corresponding
76 * to the probed function - a trick to enable arguments to become
77 * accessible seamlessly by probe handling logic.
78 * Note:
79 * Because of the way compilers allocate stack space for local variables
80 * etc upfront, regardless of sub-scopes within a function, this mirroring
81 * principle currently works only for probes placed on function entry points.
83 struct jprobe {
84 struct kprobe kp;
85 kprobe_opcode_t *entry; /* probe handling code to jump to */
88 #ifdef CONFIG_KPROBES
89 /* Locks kprobe: irq must be disabled */
90 void lock_kprobes(void);
91 void unlock_kprobes(void);
93 /* kprobe running now on this CPU? */
94 static inline int kprobe_running(void)
96 extern unsigned int kprobe_cpu;
97 return kprobe_cpu == smp_processor_id();
100 extern int arch_prepare_kprobe(struct kprobe *p);
101 extern void arch_copy_kprobe(struct kprobe *p);
102 extern void arch_remove_kprobe(struct kprobe *p);
103 extern void show_registers(struct pt_regs *regs);
105 /* Get the kprobe at this addr (if any). Must have called lock_kprobes */
106 struct kprobe *get_kprobe(void *addr);
108 int register_kprobe(struct kprobe *p);
109 void unregister_kprobe(struct kprobe *p);
110 int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
111 int longjmp_break_handler(struct kprobe *, struct pt_regs *);
112 int register_jprobe(struct jprobe *p);
113 void unregister_jprobe(struct jprobe *p);
114 void jprobe_return(void);
116 #else
117 static inline int kprobe_running(void)
119 return 0;
121 static inline int register_kprobe(struct kprobe *p)
123 return -ENOSYS;
125 static inline void unregister_kprobe(struct kprobe *p)
128 static inline int register_jprobe(struct jprobe *p)
130 return -ENOSYS;
132 static inline void unregister_jprobe(struct jprobe *p)
135 static inline void jprobe_return(void)
138 #endif
139 #endif /* _LINUX_KPROBES_H */