xref: /linux/include/linux/kprobes.h (revision e5779e8e12299f77c2421a707855d8d124171d85)
11da177e4SLinus Torvalds #ifndef _LINUX_KPROBES_H
21da177e4SLinus Torvalds #define _LINUX_KPROBES_H
31da177e4SLinus Torvalds /*
41da177e4SLinus Torvalds  *  Kernel Probes (KProbes)
51da177e4SLinus Torvalds  *  include/linux/kprobes.h
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
81da177e4SLinus Torvalds  * it under the terms of the GNU General Public License as published by
91da177e4SLinus Torvalds  * the Free Software Foundation; either version 2 of the License, or
101da177e4SLinus Torvalds  * (at your option) any later version.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful,
131da177e4SLinus Torvalds  * but WITHOUT ANY WARRANTY; without even the implied warranty of
141da177e4SLinus Torvalds  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151da177e4SLinus Torvalds  * GNU General Public License for more details.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
181da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
191da177e4SLinus Torvalds  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  * Copyright (C) IBM Corporation, 2002, 2004
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  * 2002-Oct	Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
241da177e4SLinus Torvalds  *		Probes initial implementation ( includes suggestions from
251da177e4SLinus Torvalds  *		Rusty Russell).
261da177e4SLinus Torvalds  * 2004-July	Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
271da177e4SLinus Torvalds  *		interface to access function arguments.
28b94cce92SHien Nguyen  * 2005-May	Hien Nguyen <hien@us.ibm.com> and Jim Keniston
29b94cce92SHien Nguyen  *		<jkenisto@us.ibm.com>  and Prasanna S Panchamukhi
30b94cce92SHien Nguyen  *		<prasanna@in.ibm.com> added function-return probes.
311da177e4SLinus Torvalds  */
32324670b6SMasami Hiramatsu #include <linux/compiler.h>	/* for __kprobes */
3336dcd67aSIngo Molnar #include <linux/linkage.h>
341da177e4SLinus Torvalds #include <linux/list.h>
351da177e4SLinus Torvalds #include <linux/notifier.h>
361da177e4SLinus Torvalds #include <linux/smp.h>
37187f1882SPaul Gortmaker #include <linux/bug.h>
38e6584523SAnanth N Mavinakayanahalli #include <linux/percpu.h>
393516a460SAnanth N Mavinakayanahalli #include <linux/spinlock.h>
403516a460SAnanth N Mavinakayanahalli #include <linux/rcupdate.h>
417a7d1cf9SIngo Molnar #include <linux/mutex.h>
42ae6aa16fSMasami Hiramatsu #include <linux/ftrace.h>
43b94cce92SHien Nguyen 
4400d7c05aSKeshavamurthy Anil S #ifdef CONFIG_KPROBES
451da177e4SLinus Torvalds #include <asm/kprobes.h>
461da177e4SLinus Torvalds 
47ea32c65cSPrasanna S Panchamukhi /* kprobe_status settings */
48ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_ACTIVE	0x00000001
49ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SS		0x00000002
50ea32c65cSPrasanna S Panchamukhi #define KPROBE_REENTER		0x00000004
51ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SSDONE	0x00000008
52ea32c65cSPrasanna S Panchamukhi 
53dc19835dSMasami Hiramatsu #else /* CONFIG_KPROBES */
54dc19835dSMasami Hiramatsu typedef int kprobe_opcode_t;
55dc19835dSMasami Hiramatsu struct arch_specific_insn {
56dc19835dSMasami Hiramatsu 	int dummy;
57dc19835dSMasami Hiramatsu };
58dc19835dSMasami Hiramatsu #endif /* CONFIG_KPROBES */
59d0aaff97SPrasanna S Panchamukhi 
601da177e4SLinus Torvalds struct kprobe;
611da177e4SLinus Torvalds struct pt_regs;
62b94cce92SHien Nguyen struct kretprobe;
63b94cce92SHien Nguyen struct kretprobe_instance;
641da177e4SLinus Torvalds typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
651da177e4SLinus Torvalds typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
661da177e4SLinus Torvalds typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
671da177e4SLinus Torvalds 				       unsigned long flags);
681da177e4SLinus Torvalds typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
691da177e4SLinus Torvalds 				       int trapnr);
70b94cce92SHien Nguyen typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
71b94cce92SHien Nguyen 				    struct pt_regs *);
72b94cce92SHien Nguyen 
731da177e4SLinus Torvalds struct kprobe {
741da177e4SLinus Torvalds 	struct hlist_node hlist;
751da177e4SLinus Torvalds 
7664f562c6SAnanth N Mavinakayanahalli 	/* list of kprobes for multi-handler support */
7764f562c6SAnanth N Mavinakayanahalli 	struct list_head list;
7864f562c6SAnanth N Mavinakayanahalli 
79ea32c65cSPrasanna S Panchamukhi 	/*count the number of times this probe was temporarily disarmed */
80ea32c65cSPrasanna S Panchamukhi 	unsigned long nmissed;
81ea32c65cSPrasanna S Panchamukhi 
821da177e4SLinus Torvalds 	/* location of the probe point */
831da177e4SLinus Torvalds 	kprobe_opcode_t *addr;
841da177e4SLinus Torvalds 
853a872d89SAnanth N Mavinakayanahalli 	/* Allow user to indicate symbol name of the probe point */
869b3af29bSAnanth N Mavinakayanahalli 	const char *symbol_name;
873a872d89SAnanth N Mavinakayanahalli 
883a872d89SAnanth N Mavinakayanahalli 	/* Offset into the symbol */
893a872d89SAnanth N Mavinakayanahalli 	unsigned int offset;
903a872d89SAnanth N Mavinakayanahalli 
911da177e4SLinus Torvalds 	/* Called before addr is executed. */
921da177e4SLinus Torvalds 	kprobe_pre_handler_t pre_handler;
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 	/* Called after addr is executed, unless... */
951da177e4SLinus Torvalds 	kprobe_post_handler_t post_handler;
961da177e4SLinus Torvalds 
97cc00e9cfSMasami Hiramatsu 	/*
98cc00e9cfSMasami Hiramatsu 	 * ... called if executing addr causes a fault (eg. page fault).
99cc00e9cfSMasami Hiramatsu 	 * Return 1 if it handled fault, otherwise kernel will see it.
100cc00e9cfSMasami Hiramatsu 	 */
1011da177e4SLinus Torvalds 	kprobe_fault_handler_t fault_handler;
1021da177e4SLinus Torvalds 
103cc00e9cfSMasami Hiramatsu 	/*
104cc00e9cfSMasami Hiramatsu 	 * ... called if breakpoint trap occurs in probe handler.
105cc00e9cfSMasami Hiramatsu 	 * Return 1 if it handled break, otherwise kernel will see it.
106cc00e9cfSMasami Hiramatsu 	 */
1071da177e4SLinus Torvalds 	kprobe_break_handler_t break_handler;
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds 	/* Saved opcode (which has been replaced with breakpoint) */
1101da177e4SLinus Torvalds 	kprobe_opcode_t opcode;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	/* copy of the original instruction */
1131da177e4SLinus Torvalds 	struct arch_specific_insn ainsn;
114e8386a0cSMasami Hiramatsu 
115de5bd88dSMasami Hiramatsu 	/*
116de5bd88dSMasami Hiramatsu 	 * Indicates various status flags.
117de5bd88dSMasami Hiramatsu 	 * Protected by kprobe_mutex after this kprobe is registered.
118de5bd88dSMasami Hiramatsu 	 */
119e8386a0cSMasami Hiramatsu 	u32 flags;
1201da177e4SLinus Torvalds };
1211da177e4SLinus Torvalds 
122e8386a0cSMasami Hiramatsu /* Kprobe status flags */
123e8386a0cSMasami Hiramatsu #define KPROBE_FLAG_GONE	1 /* breakpoint has already gone */
124de5bd88dSMasami Hiramatsu #define KPROBE_FLAG_DISABLED	2 /* probe is temporarily disabled */
125afd66255SMasami Hiramatsu #define KPROBE_FLAG_OPTIMIZED	4 /*
126afd66255SMasami Hiramatsu 				   * probe is really optimized.
127afd66255SMasami Hiramatsu 				   * NOTE:
128afd66255SMasami Hiramatsu 				   * this flag is only for optimized_kprobe.
129afd66255SMasami Hiramatsu 				   */
130ae6aa16fSMasami Hiramatsu #define KPROBE_FLAG_FTRACE	8 /* probe is using ftrace */
131e8386a0cSMasami Hiramatsu 
132de5bd88dSMasami Hiramatsu /* Has this kprobe gone ? */
133e8386a0cSMasami Hiramatsu static inline int kprobe_gone(struct kprobe *p)
134e8386a0cSMasami Hiramatsu {
135e8386a0cSMasami Hiramatsu 	return p->flags & KPROBE_FLAG_GONE;
136e8386a0cSMasami Hiramatsu }
137e8386a0cSMasami Hiramatsu 
138de5bd88dSMasami Hiramatsu /* Is this kprobe disabled ? */
139de5bd88dSMasami Hiramatsu static inline int kprobe_disabled(struct kprobe *p)
140de5bd88dSMasami Hiramatsu {
141de5bd88dSMasami Hiramatsu 	return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE);
142de5bd88dSMasami Hiramatsu }
143afd66255SMasami Hiramatsu 
144afd66255SMasami Hiramatsu /* Is this kprobe really running optimized path ? */
145afd66255SMasami Hiramatsu static inline int kprobe_optimized(struct kprobe *p)
146afd66255SMasami Hiramatsu {
147afd66255SMasami Hiramatsu 	return p->flags & KPROBE_FLAG_OPTIMIZED;
148afd66255SMasami Hiramatsu }
149ae6aa16fSMasami Hiramatsu 
150ae6aa16fSMasami Hiramatsu /* Is this kprobe uses ftrace ? */
151ae6aa16fSMasami Hiramatsu static inline int kprobe_ftrace(struct kprobe *p)
152ae6aa16fSMasami Hiramatsu {
153ae6aa16fSMasami Hiramatsu 	return p->flags & KPROBE_FLAG_FTRACE;
154ae6aa16fSMasami Hiramatsu }
155ae6aa16fSMasami Hiramatsu 
1561da177e4SLinus Torvalds /*
1571da177e4SLinus Torvalds  * Special probe type that uses setjmp-longjmp type tricks to resume
1581da177e4SLinus Torvalds  * execution at a specified entry with a matching prototype corresponding
1591da177e4SLinus Torvalds  * to the probed function - a trick to enable arguments to become
1601da177e4SLinus Torvalds  * accessible seamlessly by probe handling logic.
1611da177e4SLinus Torvalds  * Note:
1621da177e4SLinus Torvalds  * Because of the way compilers allocate stack space for local variables
1631da177e4SLinus Torvalds  * etc upfront, regardless of sub-scopes within a function, this mirroring
1641da177e4SLinus Torvalds  * principle currently works only for probes placed on function entry points.
1651da177e4SLinus Torvalds  */
1661da177e4SLinus Torvalds struct jprobe {
1671da177e4SLinus Torvalds 	struct kprobe kp;
16881eae375SMichael Ellerman 	void *entry;	/* probe handling code to jump to */
1691da177e4SLinus Torvalds };
1701da177e4SLinus Torvalds 
1719e367d85SMichael Ellerman /* For backward compatibility with old code using JPROBE_ENTRY() */
1729e367d85SMichael Ellerman #define JPROBE_ENTRY(handler)	(handler)
1739e367d85SMichael Ellerman 
174b94cce92SHien Nguyen /*
175b94cce92SHien Nguyen  * Function-return probe -
176b94cce92SHien Nguyen  * Note:
177b94cce92SHien Nguyen  * User needs to provide a handler function, and initialize maxactive.
178b94cce92SHien Nguyen  * maxactive - The maximum number of instances of the probed function that
179b94cce92SHien Nguyen  * can be active concurrently.
180b94cce92SHien Nguyen  * nmissed - tracks the number of times the probed function's return was
181b94cce92SHien Nguyen  * ignored, due to maxactive being too low.
182b94cce92SHien Nguyen  *
183b94cce92SHien Nguyen  */
184b94cce92SHien Nguyen struct kretprobe {
185b94cce92SHien Nguyen 	struct kprobe kp;
186b94cce92SHien Nguyen 	kretprobe_handler_t handler;
187f47cd9b5SAbhishek Sagar 	kretprobe_handler_t entry_handler;
188b94cce92SHien Nguyen 	int maxactive;
189b94cce92SHien Nguyen 	int nmissed;
190f47cd9b5SAbhishek Sagar 	size_t data_size;
191b94cce92SHien Nguyen 	struct hlist_head free_instances;
192ec484608SThomas Gleixner 	raw_spinlock_t lock;
193b94cce92SHien Nguyen };
194b94cce92SHien Nguyen 
195b94cce92SHien Nguyen struct kretprobe_instance {
196b94cce92SHien Nguyen 	struct hlist_node hlist;
197b94cce92SHien Nguyen 	struct kretprobe *rp;
198802eae7cSRusty Lynch 	kprobe_opcode_t *ret_addr;
199802eae7cSRusty Lynch 	struct task_struct *task;
200f47cd9b5SAbhishek Sagar 	char data[0];
201b94cce92SHien Nguyen };
202b94cce92SHien Nguyen 
203f438d914SMasami Hiramatsu struct kretprobe_blackpoint {
204f438d914SMasami Hiramatsu 	const char *name;
205f438d914SMasami Hiramatsu 	void *addr;
206f438d914SMasami Hiramatsu };
2073d8d996eSSrinivasa Ds 
208376e2424SMasami Hiramatsu struct kprobe_blacklist_entry {
209376e2424SMasami Hiramatsu 	struct list_head list;
2103d8d996eSSrinivasa Ds 	unsigned long start_addr;
211376e2424SMasami Hiramatsu 	unsigned long end_addr;
2123d8d996eSSrinivasa Ds };
2133d8d996eSSrinivasa Ds 
214dc19835dSMasami Hiramatsu #ifdef CONFIG_KPROBES
215dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe *, current_kprobe);
216dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
217dc19835dSMasami Hiramatsu 
218b1801812SIngo Molnar /*
219b1801812SIngo Molnar  * For #ifdef avoidance:
220b1801812SIngo Molnar  */
221b1801812SIngo Molnar static inline int kprobes_built_in(void)
222b1801812SIngo Molnar {
223b1801812SIngo Molnar 	return 1;
224b1801812SIngo Molnar }
225b1801812SIngo Molnar 
226dc19835dSMasami Hiramatsu #ifdef CONFIG_KRETPROBES
227dc19835dSMasami Hiramatsu extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
228dc19835dSMasami Hiramatsu 				   struct pt_regs *regs);
229dc19835dSMasami Hiramatsu extern int arch_trampoline_kprobe(struct kprobe *p);
230dc19835dSMasami Hiramatsu #else /* CONFIG_KRETPROBES */
231dc19835dSMasami Hiramatsu static inline void arch_prepare_kretprobe(struct kretprobe *rp,
232dc19835dSMasami Hiramatsu 					struct pt_regs *regs)
233dc19835dSMasami Hiramatsu {
234dc19835dSMasami Hiramatsu }
235dc19835dSMasami Hiramatsu static inline int arch_trampoline_kprobe(struct kprobe *p)
236dc19835dSMasami Hiramatsu {
237dc19835dSMasami Hiramatsu 	return 0;
238dc19835dSMasami Hiramatsu }
239dc19835dSMasami Hiramatsu #endif /* CONFIG_KRETPROBES */
240dc19835dSMasami Hiramatsu 
241f438d914SMasami Hiramatsu extern struct kretprobe_blackpoint kretprobe_blacklist[];
242f438d914SMasami Hiramatsu 
2430f95b7fcSAnanth N Mavinakayanahalli static inline void kretprobe_assert(struct kretprobe_instance *ri,
2440f95b7fcSAnanth N Mavinakayanahalli 	unsigned long orig_ret_address, unsigned long trampoline_address)
2450f95b7fcSAnanth N Mavinakayanahalli {
2460f95b7fcSAnanth N Mavinakayanahalli 	if (!orig_ret_address || (orig_ret_address == trampoline_address)) {
2470f95b7fcSAnanth N Mavinakayanahalli 		printk("kretprobe BUG!: Processing kretprobe %p @ %p\n",
2480f95b7fcSAnanth N Mavinakayanahalli 				ri->rp, ri->rp->kp.addr);
2490f95b7fcSAnanth N Mavinakayanahalli 		BUG();
2500f95b7fcSAnanth N Mavinakayanahalli 	}
2510f95b7fcSAnanth N Mavinakayanahalli }
2520f95b7fcSAnanth N Mavinakayanahalli 
2538c1c9356SAnanth N Mavinakayanahalli #ifdef CONFIG_KPROBES_SANITY_TEST
2548c1c9356SAnanth N Mavinakayanahalli extern int init_test_probes(void);
2558c1c9356SAnanth N Mavinakayanahalli #else
2568c1c9356SAnanth N Mavinakayanahalli static inline int init_test_probes(void)
2578c1c9356SAnanth N Mavinakayanahalli {
2588c1c9356SAnanth N Mavinakayanahalli 	return 0;
2598c1c9356SAnanth N Mavinakayanahalli }
2608c1c9356SAnanth N Mavinakayanahalli #endif /* CONFIG_KPROBES_SANITY_TEST */
2618c1c9356SAnanth N Mavinakayanahalli 
2621da177e4SLinus Torvalds extern int arch_prepare_kprobe(struct kprobe *p);
2637e1048b1SRusty Lynch extern void arch_arm_kprobe(struct kprobe *p);
2647e1048b1SRusty Lynch extern void arch_disarm_kprobe(struct kprobe *p);
2656772926bSRusty Lynch extern int arch_init_kprobes(void);
2661da177e4SLinus Torvalds extern void show_registers(struct pt_regs *regs);
267bf8d5c52SKeshavamurthy Anil S extern void kprobes_inc_nmissed_count(struct kprobe *p);
268be8f2743SMasami Hiramatsu extern bool arch_within_kprobe_blacklist(unsigned long addr);
2691da177e4SLinus Torvalds 
270*e5779e8eSAndy Lutomirski extern bool within_kprobe_blacklist(unsigned long addr);
271*e5779e8eSAndy Lutomirski 
272c802d64aSHeiko Carstens struct kprobe_insn_cache {
273c802d64aSHeiko Carstens 	struct mutex mutex;
274af96397dSHeiko Carstens 	void *(*alloc)(void);	/* allocate insn page */
275af96397dSHeiko Carstens 	void (*free)(void *);	/* free insn page */
276c802d64aSHeiko Carstens 	struct list_head pages; /* list of kprobe_insn_page */
277c802d64aSHeiko Carstens 	size_t insn_size;	/* size of instruction slot */
278c802d64aSHeiko Carstens 	int nr_garbage;
279c802d64aSHeiko Carstens };
280c802d64aSHeiko Carstens 
281c802d64aSHeiko Carstens extern kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c);
282c802d64aSHeiko Carstens extern void __free_insn_slot(struct kprobe_insn_cache *c,
283c802d64aSHeiko Carstens 			     kprobe_opcode_t *slot, int dirty);
284c802d64aSHeiko Carstens 
285c802d64aSHeiko Carstens #define DEFINE_INSN_CACHE_OPS(__name)					\
286c802d64aSHeiko Carstens extern struct kprobe_insn_cache kprobe_##__name##_slots;		\
287c802d64aSHeiko Carstens 									\
288c802d64aSHeiko Carstens static inline kprobe_opcode_t *get_##__name##_slot(void)		\
289c802d64aSHeiko Carstens {									\
290c802d64aSHeiko Carstens 	return __get_insn_slot(&kprobe_##__name##_slots);		\
291c802d64aSHeiko Carstens }									\
292c802d64aSHeiko Carstens 									\
293c802d64aSHeiko Carstens static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\
294c802d64aSHeiko Carstens {									\
295c802d64aSHeiko Carstens 	__free_insn_slot(&kprobe_##__name##_slots, slot, dirty);	\
296c802d64aSHeiko Carstens }									\
297c802d64aSHeiko Carstens 
298c802d64aSHeiko Carstens DEFINE_INSN_CACHE_OPS(insn);
299c802d64aSHeiko Carstens 
300afd66255SMasami Hiramatsu #ifdef CONFIG_OPTPROBES
301afd66255SMasami Hiramatsu /*
302afd66255SMasami Hiramatsu  * Internal structure for direct jump optimized probe
303afd66255SMasami Hiramatsu  */
304afd66255SMasami Hiramatsu struct optimized_kprobe {
305afd66255SMasami Hiramatsu 	struct kprobe kp;
306afd66255SMasami Hiramatsu 	struct list_head list;	/* list for optimizing queue */
307afd66255SMasami Hiramatsu 	struct arch_optimized_insn optinsn;
308afd66255SMasami Hiramatsu };
309afd66255SMasami Hiramatsu 
310afd66255SMasami Hiramatsu /* Architecture dependent functions for direct jump optimization */
311afd66255SMasami Hiramatsu extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn);
312afd66255SMasami Hiramatsu extern int arch_check_optimized_kprobe(struct optimized_kprobe *op);
313cbf6ab52SMasami Hiramatsu extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op,
314cbf6ab52SMasami Hiramatsu 					 struct kprobe *orig);
315afd66255SMasami Hiramatsu extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op);
316cd7ebe22SMasami Hiramatsu extern void arch_optimize_kprobes(struct list_head *oplist);
317f984ba4eSMasami Hiramatsu extern void arch_unoptimize_kprobes(struct list_head *oplist,
318f984ba4eSMasami Hiramatsu 				    struct list_head *done_list);
319afd66255SMasami Hiramatsu extern void arch_unoptimize_kprobe(struct optimized_kprobe *op);
320afd66255SMasami Hiramatsu extern int arch_within_optimized_kprobe(struct optimized_kprobe *op,
321afd66255SMasami Hiramatsu 					unsigned long addr);
322afd66255SMasami Hiramatsu 
323afd66255SMasami Hiramatsu extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs);
324b2be84dfSMasami Hiramatsu 
325c802d64aSHeiko Carstens DEFINE_INSN_CACHE_OPS(optinsn);
326c802d64aSHeiko Carstens 
327b2be84dfSMasami Hiramatsu #ifdef CONFIG_SYSCTL
328b2be84dfSMasami Hiramatsu extern int sysctl_kprobes_optimization;
329b2be84dfSMasami Hiramatsu extern int proc_kprobes_optimization_handler(struct ctl_table *table,
330b2be84dfSMasami Hiramatsu 					     int write, void __user *buffer,
331b2be84dfSMasami Hiramatsu 					     size_t *length, loff_t *ppos);
332b2be84dfSMasami Hiramatsu #endif
333b2be84dfSMasami Hiramatsu 
334afd66255SMasami Hiramatsu #endif /* CONFIG_OPTPROBES */
335e7dbfe34SMasami Hiramatsu #ifdef CONFIG_KPROBES_ON_FTRACE
336ae6aa16fSMasami Hiramatsu extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
337e5253896SMasami Hiramatsu 				  struct ftrace_ops *ops, struct pt_regs *regs);
338ae6aa16fSMasami Hiramatsu extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
339ae6aa16fSMasami Hiramatsu #endif
340ae6aa16fSMasami Hiramatsu 
341f7f242ffSHeiko Carstens int arch_check_ftrace_location(struct kprobe *p);
342afd66255SMasami Hiramatsu 
343d217d545SAnanth N Mavinakayanahalli /* Get the kprobe at this addr (if any) - called with preemption disabled */
3441da177e4SLinus Torvalds struct kprobe *get_kprobe(void *addr);
345ef53d9c5SSrinivasa D S void kretprobe_hash_lock(struct task_struct *tsk,
346ef53d9c5SSrinivasa D S 			 struct hlist_head **head, unsigned long *flags);
347ef53d9c5SSrinivasa D S void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags);
348b94cce92SHien Nguyen struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk);
3491da177e4SLinus Torvalds 
350e6584523SAnanth N Mavinakayanahalli /* kprobe_running() will just return the current_kprobe on this CPU */
351e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void)
352e6584523SAnanth N Mavinakayanahalli {
353b76834bcSChristoph Lameter 	return (__this_cpu_read(current_kprobe));
354e6584523SAnanth N Mavinakayanahalli }
355e6584523SAnanth N Mavinakayanahalli 
356e6584523SAnanth N Mavinakayanahalli static inline void reset_current_kprobe(void)
357e6584523SAnanth N Mavinakayanahalli {
358b76834bcSChristoph Lameter 	__this_cpu_write(current_kprobe, NULL);
359e6584523SAnanth N Mavinakayanahalli }
360e6584523SAnanth N Mavinakayanahalli 
361e6584523SAnanth N Mavinakayanahalli static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
362e6584523SAnanth N Mavinakayanahalli {
363bdffd893SChristoph Lameter 	return this_cpu_ptr(&kprobe_ctlblk);
364e6584523SAnanth N Mavinakayanahalli }
365e6584523SAnanth N Mavinakayanahalli 
3661da177e4SLinus Torvalds int register_kprobe(struct kprobe *p);
3671da177e4SLinus Torvalds void unregister_kprobe(struct kprobe *p);
3689861668fSMasami Hiramatsu int register_kprobes(struct kprobe **kps, int num);
3699861668fSMasami Hiramatsu void unregister_kprobes(struct kprobe **kps, int num);
3701da177e4SLinus Torvalds int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
3711da177e4SLinus Torvalds int longjmp_break_handler(struct kprobe *, struct pt_regs *);
3721da177e4SLinus Torvalds int register_jprobe(struct jprobe *p);
3731da177e4SLinus Torvalds void unregister_jprobe(struct jprobe *p);
37426b31c19SMasami Hiramatsu int register_jprobes(struct jprobe **jps, int num);
37526b31c19SMasami Hiramatsu void unregister_jprobes(struct jprobe **jps, int num);
3761da177e4SLinus Torvalds void jprobe_return(void);
3773d7e3382SMichael Ellerman unsigned long arch_deref_entry_point(void *);
3781da177e4SLinus Torvalds 
379b94cce92SHien Nguyen int register_kretprobe(struct kretprobe *rp);
380b94cce92SHien Nguyen void unregister_kretprobe(struct kretprobe *rp);
3814a296e07SMasami Hiramatsu int register_kretprobes(struct kretprobe **rps, int num);
3824a296e07SMasami Hiramatsu void unregister_kretprobes(struct kretprobe **rps, int num);
383b94cce92SHien Nguyen 
384b94cce92SHien Nguyen void kprobe_flush_task(struct task_struct *tk);
38599219a3fSbibo,mao void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);
3868c1c9356SAnanth N Mavinakayanahalli 
387de5bd88dSMasami Hiramatsu int disable_kprobe(struct kprobe *kp);
388de5bd88dSMasami Hiramatsu int enable_kprobe(struct kprobe *kp);
389de5bd88dSMasami Hiramatsu 
39024851d24SFrederic Weisbecker void dump_kprobe(struct kprobe *kp);
39124851d24SFrederic Weisbecker 
392b1801812SIngo Molnar #else /* !CONFIG_KPROBES: */
39300d7c05aSKeshavamurthy Anil S 
394b1801812SIngo Molnar static inline int kprobes_built_in(void)
395b1801812SIngo Molnar {
396b1801812SIngo Molnar 	return 0;
397b1801812SIngo Molnar }
398b1801812SIngo Molnar static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
399b1801812SIngo Molnar {
400b1801812SIngo Molnar 	return 0;
401b1801812SIngo Molnar }
402785656a4SAbhishek Sagar static inline struct kprobe *get_kprobe(void *addr)
403785656a4SAbhishek Sagar {
404785656a4SAbhishek Sagar 	return NULL;
405785656a4SAbhishek Sagar }
406e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void)
4071da177e4SLinus Torvalds {
408e6584523SAnanth N Mavinakayanahalli 	return NULL;
4091da177e4SLinus Torvalds }
4101da177e4SLinus Torvalds static inline int register_kprobe(struct kprobe *p)
4111da177e4SLinus Torvalds {
4121da177e4SLinus Torvalds 	return -ENOSYS;
4131da177e4SLinus Torvalds }
4149861668fSMasami Hiramatsu static inline int register_kprobes(struct kprobe **kps, int num)
4159861668fSMasami Hiramatsu {
4169861668fSMasami Hiramatsu 	return -ENOSYS;
4179861668fSMasami Hiramatsu }
4181da177e4SLinus Torvalds static inline void unregister_kprobe(struct kprobe *p)
4191da177e4SLinus Torvalds {
4201da177e4SLinus Torvalds }
4219861668fSMasami Hiramatsu static inline void unregister_kprobes(struct kprobe **kps, int num)
4229861668fSMasami Hiramatsu {
4239861668fSMasami Hiramatsu }
4241da177e4SLinus Torvalds static inline int register_jprobe(struct jprobe *p)
4251da177e4SLinus Torvalds {
4261da177e4SLinus Torvalds 	return -ENOSYS;
4271da177e4SLinus Torvalds }
42826b31c19SMasami Hiramatsu static inline int register_jprobes(struct jprobe **jps, int num)
42926b31c19SMasami Hiramatsu {
43026b31c19SMasami Hiramatsu 	return -ENOSYS;
43126b31c19SMasami Hiramatsu }
4321da177e4SLinus Torvalds static inline void unregister_jprobe(struct jprobe *p)
4331da177e4SLinus Torvalds {
4341da177e4SLinus Torvalds }
43526b31c19SMasami Hiramatsu static inline void unregister_jprobes(struct jprobe **jps, int num)
43626b31c19SMasami Hiramatsu {
43726b31c19SMasami Hiramatsu }
4381da177e4SLinus Torvalds static inline void jprobe_return(void)
4391da177e4SLinus Torvalds {
4401da177e4SLinus Torvalds }
441b94cce92SHien Nguyen static inline int register_kretprobe(struct kretprobe *rp)
442b94cce92SHien Nguyen {
443b94cce92SHien Nguyen 	return -ENOSYS;
444b94cce92SHien Nguyen }
4454a296e07SMasami Hiramatsu static inline int register_kretprobes(struct kretprobe **rps, int num)
4464a296e07SMasami Hiramatsu {
4474a296e07SMasami Hiramatsu 	return -ENOSYS;
4484a296e07SMasami Hiramatsu }
449b94cce92SHien Nguyen static inline void unregister_kretprobe(struct kretprobe *rp)
450b94cce92SHien Nguyen {
451b94cce92SHien Nguyen }
4524a296e07SMasami Hiramatsu static inline void unregister_kretprobes(struct kretprobe **rps, int num)
4534a296e07SMasami Hiramatsu {
4544a296e07SMasami Hiramatsu }
455b94cce92SHien Nguyen static inline void kprobe_flush_task(struct task_struct *tk)
456b94cce92SHien Nguyen {
457b94cce92SHien Nguyen }
458de5bd88dSMasami Hiramatsu static inline int disable_kprobe(struct kprobe *kp)
459de5bd88dSMasami Hiramatsu {
460de5bd88dSMasami Hiramatsu 	return -ENOSYS;
461de5bd88dSMasami Hiramatsu }
462de5bd88dSMasami Hiramatsu static inline int enable_kprobe(struct kprobe *kp)
463de5bd88dSMasami Hiramatsu {
464de5bd88dSMasami Hiramatsu 	return -ENOSYS;
465de5bd88dSMasami Hiramatsu }
466b94cce92SHien Nguyen #endif /* CONFIG_KPROBES */
4678f9b1528SMasami Hiramatsu static inline int disable_kretprobe(struct kretprobe *rp)
4688f9b1528SMasami Hiramatsu {
4698f9b1528SMasami Hiramatsu 	return disable_kprobe(&rp->kp);
4708f9b1528SMasami Hiramatsu }
4718f9b1528SMasami Hiramatsu static inline int enable_kretprobe(struct kretprobe *rp)
4728f9b1528SMasami Hiramatsu {
4738f9b1528SMasami Hiramatsu 	return enable_kprobe(&rp->kp);
4748f9b1528SMasami Hiramatsu }
4758f9b1528SMasami Hiramatsu static inline int disable_jprobe(struct jprobe *jp)
4768f9b1528SMasami Hiramatsu {
4778f9b1528SMasami Hiramatsu 	return disable_kprobe(&jp->kp);
4788f9b1528SMasami Hiramatsu }
4798f9b1528SMasami Hiramatsu static inline int enable_jprobe(struct jprobe *jp)
4808f9b1528SMasami Hiramatsu {
4818f9b1528SMasami Hiramatsu 	return enable_kprobe(&jp->kp);
4828f9b1528SMasami Hiramatsu }
4838f9b1528SMasami Hiramatsu 
484376e2424SMasami Hiramatsu #ifdef CONFIG_KPROBES
485376e2424SMasami Hiramatsu /*
486376e2424SMasami Hiramatsu  * Blacklist ganerating macro. Specify functions which is not probed
487376e2424SMasami Hiramatsu  * by using this macro.
488376e2424SMasami Hiramatsu  */
489376e2424SMasami Hiramatsu #define __NOKPROBE_SYMBOL(fname)			\
490376e2424SMasami Hiramatsu static unsigned long __used				\
491376e2424SMasami Hiramatsu 	__attribute__((section("_kprobe_blacklist")))	\
492376e2424SMasami Hiramatsu 	_kbl_addr_##fname = (unsigned long)fname;
493376e2424SMasami Hiramatsu #define NOKPROBE_SYMBOL(fname)	__NOKPROBE_SYMBOL(fname)
494376e2424SMasami Hiramatsu #else
495376e2424SMasami Hiramatsu #define NOKPROBE_SYMBOL(fname)
496376e2424SMasami Hiramatsu #endif
497376e2424SMasami Hiramatsu 
4981da177e4SLinus Torvalds #endif /* _LINUX_KPROBES_H */
499