[PATCH] Move kprobe [dis]arming into arch specific code
[deliverable/linux.git] / include / linux / kprobes.h
1 #ifndef _LINUX_KPROBES_H
2 #define _LINUX_KPROBES_H
3 /*
4 * Kernel Probes (KProbes)
5 * include/linux/kprobes.h
6 *
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.
11 *
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.
16 *
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.
20 *
21 * Copyright (C) IBM Corporation, 2002, 2004
22 *
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.
28 * 2005-May Hien Nguyen <hien@us.ibm.com> and Jim Keniston
29 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
30 * <prasanna@in.ibm.com> added function-return probes.
31 */
32 #include <linux/config.h>
33 #include <linux/list.h>
34 #include <linux/notifier.h>
35 #include <linux/smp.h>
36 #include <linux/spinlock.h>
37
38 #include <asm/kprobes.h>
39
40 struct kprobe;
41 struct pt_regs;
42 struct kretprobe;
43 struct kretprobe_instance;
44 typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
45 typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
46 typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
47 unsigned long flags);
48 typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
49 int trapnr);
50 typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
51 struct pt_regs *);
52
53 struct kprobe {
54 struct hlist_node hlist;
55
56 /* list of kprobes for multi-handler support */
57 struct list_head list;
58
59 /* location of the probe point */
60 kprobe_opcode_t *addr;
61
62 /* Called before addr is executed. */
63 kprobe_pre_handler_t pre_handler;
64
65 /* Called after addr is executed, unless... */
66 kprobe_post_handler_t post_handler;
67
68 /* ... called if executing addr causes a fault (eg. page fault).
69 * Return 1 if it handled fault, otherwise kernel will see it. */
70 kprobe_fault_handler_t fault_handler;
71
72 /* ... called if breakpoint trap occurs in probe handler.
73 * Return 1 if it handled break, otherwise kernel will see it. */
74 kprobe_break_handler_t break_handler;
75
76 /* Saved opcode (which has been replaced with breakpoint) */
77 kprobe_opcode_t opcode;
78
79 /* copy of the original instruction */
80 struct arch_specific_insn ainsn;
81 };
82
83 /*
84 * Special probe type that uses setjmp-longjmp type tricks to resume
85 * execution at a specified entry with a matching prototype corresponding
86 * to the probed function - a trick to enable arguments to become
87 * accessible seamlessly by probe handling logic.
88 * Note:
89 * Because of the way compilers allocate stack space for local variables
90 * etc upfront, regardless of sub-scopes within a function, this mirroring
91 * principle currently works only for probes placed on function entry points.
92 */
93 struct jprobe {
94 struct kprobe kp;
95 kprobe_opcode_t *entry; /* probe handling code to jump to */
96 };
97
98 #ifdef ARCH_SUPPORTS_KRETPROBES
99 extern int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs);
100 extern void trampoline_post_handler(struct kprobe *p, struct pt_regs *regs,
101 unsigned long flags);
102 extern struct task_struct *arch_get_kprobe_task(void *ptr);
103 extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs);
104 extern void arch_kprobe_flush_task(struct task_struct *tk, spinlock_t *kp_lock);
105 #else /* ARCH_SUPPORTS_KRETPROBES */
106 static inline void kretprobe_trampoline(void)
107 {
108 }
109 static inline int trampoline_probe_handler(struct kprobe *p,
110 struct pt_regs *regs)
111 {
112 return 0;
113 }
114 static inline void trampoline_post_handler(struct kprobe *p,
115 struct pt_regs *regs, unsigned long flags)
116 {
117 }
118 static inline void arch_prepare_kretprobe(struct kretprobe *rp,
119 struct pt_regs *regs)
120 {
121 }
122 static inline void arch_kprobe_flush_task(struct task_struct *tk)
123 {
124 }
125 #define arch_get_kprobe_task(ptr) ((struct task_struct *)NULL)
126 #endif /* ARCH_SUPPORTS_KRETPROBES */
127 /*
128 * Function-return probe -
129 * Note:
130 * User needs to provide a handler function, and initialize maxactive.
131 * maxactive - The maximum number of instances of the probed function that
132 * can be active concurrently.
133 * nmissed - tracks the number of times the probed function's return was
134 * ignored, due to maxactive being too low.
135 *
136 */
137 struct kretprobe {
138 struct kprobe kp;
139 kretprobe_handler_t handler;
140 int maxactive;
141 int nmissed;
142 struct hlist_head free_instances;
143 struct hlist_head used_instances;
144 };
145
146 struct kretprobe_instance {
147 struct hlist_node uflist; /* either on free list or used list */
148 struct hlist_node hlist;
149 struct kretprobe *rp;
150 void *ret_addr;
151 void *stack_addr;
152 };
153
154 #ifdef CONFIG_KPROBES
155 /* Locks kprobe: irq must be disabled */
156 void lock_kprobes(void);
157 void unlock_kprobes(void);
158
159 /* kprobe running now on this CPU? */
160 static inline int kprobe_running(void)
161 {
162 extern unsigned int kprobe_cpu;
163 return kprobe_cpu == smp_processor_id();
164 }
165
166 extern int arch_prepare_kprobe(struct kprobe *p);
167 extern void arch_copy_kprobe(struct kprobe *p);
168 extern void arch_arm_kprobe(struct kprobe *p);
169 extern void arch_disarm_kprobe(struct kprobe *p);
170 extern void arch_remove_kprobe(struct kprobe *p);
171 extern void show_registers(struct pt_regs *regs);
172
173 /* Get the kprobe at this addr (if any). Must have called lock_kprobes */
174 struct kprobe *get_kprobe(void *addr);
175 struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk);
176
177 int register_kprobe(struct kprobe *p);
178 void unregister_kprobe(struct kprobe *p);
179 int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
180 int longjmp_break_handler(struct kprobe *, struct pt_regs *);
181 int register_jprobe(struct jprobe *p);
182 void unregister_jprobe(struct jprobe *p);
183 void jprobe_return(void);
184
185 int register_kretprobe(struct kretprobe *rp);
186 void unregister_kretprobe(struct kretprobe *rp);
187
188 struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp);
189 struct kretprobe_instance *get_rp_inst(void *sara);
190 struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk);
191 void add_rp_inst(struct kretprobe_instance *ri);
192 void kprobe_flush_task(struct task_struct *tk);
193 void recycle_rp_inst(struct kretprobe_instance *ri);
194 #else /* CONFIG_KPROBES */
195 static inline int kprobe_running(void)
196 {
197 return 0;
198 }
199 static inline int register_kprobe(struct kprobe *p)
200 {
201 return -ENOSYS;
202 }
203 static inline void unregister_kprobe(struct kprobe *p)
204 {
205 }
206 static inline int register_jprobe(struct jprobe *p)
207 {
208 return -ENOSYS;
209 }
210 static inline void unregister_jprobe(struct jprobe *p)
211 {
212 }
213 static inline void jprobe_return(void)
214 {
215 }
216 static inline int register_kretprobe(struct kretprobe *rp)
217 {
218 return -ENOSYS;
219 }
220 static inline void unregister_kretprobe(struct kretprobe *rp)
221 {
222 }
223 static inline void kprobe_flush_task(struct task_struct *tk)
224 {
225 }
226 #endif /* CONFIG_KPROBES */
227 #endif /* _LINUX_KPROBES_H */
This page took 0.034226 seconds and 5 git commands to generate.