xref: /linux-6.15/include/linux/kprobes.h (revision e7dbfe34)
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 <[email protected]> Kernel
241da177e4SLinus Torvalds  *		Probes initial implementation ( includes suggestions from
251da177e4SLinus Torvalds  *		Rusty Russell).
261da177e4SLinus Torvalds  * 2004-July	Suparna Bhattacharya <[email protected]> added jumper probes
271da177e4SLinus Torvalds  *		interface to access function arguments.
28b94cce92SHien Nguyen  * 2005-May	Hien Nguyen <[email protected]> and Jim Keniston
29b94cce92SHien Nguyen  *		<[email protected]>  and Prasanna S Panchamukhi
30b94cce92SHien Nguyen  *		<[email protected]> added function-return probes.
311da177e4SLinus Torvalds  */
3236dcd67aSIngo Molnar #include <linux/linkage.h>
331da177e4SLinus Torvalds #include <linux/list.h>
341da177e4SLinus Torvalds #include <linux/notifier.h>
351da177e4SLinus Torvalds #include <linux/smp.h>
36187f1882SPaul Gortmaker #include <linux/bug.h>
37e6584523SAnanth N Mavinakayanahalli #include <linux/percpu.h>
383516a460SAnanth N Mavinakayanahalli #include <linux/spinlock.h>
393516a460SAnanth N Mavinakayanahalli #include <linux/rcupdate.h>
407a7d1cf9SIngo Molnar #include <linux/mutex.h>
41ae6aa16fSMasami Hiramatsu #include <linux/ftrace.h>
42b94cce92SHien Nguyen 
4300d7c05aSKeshavamurthy Anil S #ifdef CONFIG_KPROBES
441da177e4SLinus Torvalds #include <asm/kprobes.h>
451da177e4SLinus Torvalds 
46ea32c65cSPrasanna S Panchamukhi /* kprobe_status settings */
47ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_ACTIVE	0x00000001
48ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SS		0x00000002
49ea32c65cSPrasanna S Panchamukhi #define KPROBE_REENTER		0x00000004
50ea32c65cSPrasanna S Panchamukhi #define KPROBE_HIT_SSDONE	0x00000008
51ea32c65cSPrasanna S Panchamukhi 
52d0aaff97SPrasanna S Panchamukhi /* Attach to insert probes on any functions which should be ignored*/
53fe832a3aSSteven Rostedt #define __kprobes	__attribute__((__section__(".kprobes.text")))
54ae6aa16fSMasami Hiramatsu 
55dc19835dSMasami Hiramatsu #else /* CONFIG_KPROBES */
56dc19835dSMasami Hiramatsu typedef int kprobe_opcode_t;
57dc19835dSMasami Hiramatsu struct arch_specific_insn {
58dc19835dSMasami Hiramatsu 	int dummy;
59dc19835dSMasami Hiramatsu };
60fe832a3aSSteven Rostedt #define __kprobes
61ae6aa16fSMasami Hiramatsu 
62dc19835dSMasami Hiramatsu #endif /* CONFIG_KPROBES */
63d0aaff97SPrasanna S Panchamukhi 
641da177e4SLinus Torvalds struct kprobe;
651da177e4SLinus Torvalds struct pt_regs;
66b94cce92SHien Nguyen struct kretprobe;
67b94cce92SHien Nguyen struct kretprobe_instance;
681da177e4SLinus Torvalds typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
691da177e4SLinus Torvalds typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
701da177e4SLinus Torvalds typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
711da177e4SLinus Torvalds 				       unsigned long flags);
721da177e4SLinus Torvalds typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
731da177e4SLinus Torvalds 				       int trapnr);
74b94cce92SHien Nguyen typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
75b94cce92SHien Nguyen 				    struct pt_regs *);
76b94cce92SHien Nguyen 
771da177e4SLinus Torvalds struct kprobe {
781da177e4SLinus Torvalds 	struct hlist_node hlist;
791da177e4SLinus Torvalds 
8064f562c6SAnanth N Mavinakayanahalli 	/* list of kprobes for multi-handler support */
8164f562c6SAnanth N Mavinakayanahalli 	struct list_head list;
8264f562c6SAnanth N Mavinakayanahalli 
83ea32c65cSPrasanna S Panchamukhi 	/*count the number of times this probe was temporarily disarmed */
84ea32c65cSPrasanna S Panchamukhi 	unsigned long nmissed;
85ea32c65cSPrasanna S Panchamukhi 
861da177e4SLinus Torvalds 	/* location of the probe point */
871da177e4SLinus Torvalds 	kprobe_opcode_t *addr;
881da177e4SLinus Torvalds 
893a872d89SAnanth N Mavinakayanahalli 	/* Allow user to indicate symbol name of the probe point */
909b3af29bSAnanth N Mavinakayanahalli 	const char *symbol_name;
913a872d89SAnanth N Mavinakayanahalli 
923a872d89SAnanth N Mavinakayanahalli 	/* Offset into the symbol */
933a872d89SAnanth N Mavinakayanahalli 	unsigned int offset;
943a872d89SAnanth N Mavinakayanahalli 
951da177e4SLinus Torvalds 	/* Called before addr is executed. */
961da177e4SLinus Torvalds 	kprobe_pre_handler_t pre_handler;
971da177e4SLinus Torvalds 
981da177e4SLinus Torvalds 	/* Called after addr is executed, unless... */
991da177e4SLinus Torvalds 	kprobe_post_handler_t post_handler;
1001da177e4SLinus Torvalds 
101cc00e9cfSMasami Hiramatsu 	/*
102cc00e9cfSMasami Hiramatsu 	 * ... called if executing addr causes a fault (eg. page fault).
103cc00e9cfSMasami Hiramatsu 	 * Return 1 if it handled fault, otherwise kernel will see it.
104cc00e9cfSMasami Hiramatsu 	 */
1051da177e4SLinus Torvalds 	kprobe_fault_handler_t fault_handler;
1061da177e4SLinus Torvalds 
107cc00e9cfSMasami Hiramatsu 	/*
108cc00e9cfSMasami Hiramatsu 	 * ... called if breakpoint trap occurs in probe handler.
109cc00e9cfSMasami Hiramatsu 	 * Return 1 if it handled break, otherwise kernel will see it.
110cc00e9cfSMasami Hiramatsu 	 */
1111da177e4SLinus Torvalds 	kprobe_break_handler_t break_handler;
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 	/* Saved opcode (which has been replaced with breakpoint) */
1141da177e4SLinus Torvalds 	kprobe_opcode_t opcode;
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	/* copy of the original instruction */
1171da177e4SLinus Torvalds 	struct arch_specific_insn ainsn;
118e8386a0cSMasami Hiramatsu 
119de5bd88dSMasami Hiramatsu 	/*
120de5bd88dSMasami Hiramatsu 	 * Indicates various status flags.
121de5bd88dSMasami Hiramatsu 	 * Protected by kprobe_mutex after this kprobe is registered.
122de5bd88dSMasami Hiramatsu 	 */
123e8386a0cSMasami Hiramatsu 	u32 flags;
1241da177e4SLinus Torvalds };
1251da177e4SLinus Torvalds 
126e8386a0cSMasami Hiramatsu /* Kprobe status flags */
127e8386a0cSMasami Hiramatsu #define KPROBE_FLAG_GONE	1 /* breakpoint has already gone */
128de5bd88dSMasami Hiramatsu #define KPROBE_FLAG_DISABLED	2 /* probe is temporarily disabled */
129afd66255SMasami Hiramatsu #define KPROBE_FLAG_OPTIMIZED	4 /*
130afd66255SMasami Hiramatsu 				   * probe is really optimized.
131afd66255SMasami Hiramatsu 				   * NOTE:
132afd66255SMasami Hiramatsu 				   * this flag is only for optimized_kprobe.
133afd66255SMasami Hiramatsu 				   */
134ae6aa16fSMasami Hiramatsu #define KPROBE_FLAG_FTRACE	8 /* probe is using ftrace */
135e8386a0cSMasami Hiramatsu 
136de5bd88dSMasami Hiramatsu /* Has this kprobe gone ? */
137e8386a0cSMasami Hiramatsu static inline int kprobe_gone(struct kprobe *p)
138e8386a0cSMasami Hiramatsu {
139e8386a0cSMasami Hiramatsu 	return p->flags & KPROBE_FLAG_GONE;
140e8386a0cSMasami Hiramatsu }
141e8386a0cSMasami Hiramatsu 
142de5bd88dSMasami Hiramatsu /* Is this kprobe disabled ? */
143de5bd88dSMasami Hiramatsu static inline int kprobe_disabled(struct kprobe *p)
144de5bd88dSMasami Hiramatsu {
145de5bd88dSMasami Hiramatsu 	return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE);
146de5bd88dSMasami Hiramatsu }
147afd66255SMasami Hiramatsu 
148afd66255SMasami Hiramatsu /* Is this kprobe really running optimized path ? */
149afd66255SMasami Hiramatsu static inline int kprobe_optimized(struct kprobe *p)
150afd66255SMasami Hiramatsu {
151afd66255SMasami Hiramatsu 	return p->flags & KPROBE_FLAG_OPTIMIZED;
152afd66255SMasami Hiramatsu }
153ae6aa16fSMasami Hiramatsu 
154ae6aa16fSMasami Hiramatsu /* Is this kprobe uses ftrace ? */
155ae6aa16fSMasami Hiramatsu static inline int kprobe_ftrace(struct kprobe *p)
156ae6aa16fSMasami Hiramatsu {
157ae6aa16fSMasami Hiramatsu 	return p->flags & KPROBE_FLAG_FTRACE;
158ae6aa16fSMasami Hiramatsu }
159ae6aa16fSMasami Hiramatsu 
1601da177e4SLinus Torvalds /*
1611da177e4SLinus Torvalds  * Special probe type that uses setjmp-longjmp type tricks to resume
1621da177e4SLinus Torvalds  * execution at a specified entry with a matching prototype corresponding
1631da177e4SLinus Torvalds  * to the probed function - a trick to enable arguments to become
1641da177e4SLinus Torvalds  * accessible seamlessly by probe handling logic.
1651da177e4SLinus Torvalds  * Note:
1661da177e4SLinus Torvalds  * Because of the way compilers allocate stack space for local variables
1671da177e4SLinus Torvalds  * etc upfront, regardless of sub-scopes within a function, this mirroring
1681da177e4SLinus Torvalds  * principle currently works only for probes placed on function entry points.
1691da177e4SLinus Torvalds  */
1701da177e4SLinus Torvalds struct jprobe {
1711da177e4SLinus Torvalds 	struct kprobe kp;
17281eae375SMichael Ellerman 	void *entry;	/* probe handling code to jump to */
1731da177e4SLinus Torvalds };
1741da177e4SLinus Torvalds 
1759e367d85SMichael Ellerman /* For backward compatibility with old code using JPROBE_ENTRY() */
1769e367d85SMichael Ellerman #define JPROBE_ENTRY(handler)	(handler)
1779e367d85SMichael Ellerman 
178b94cce92SHien Nguyen /*
179b94cce92SHien Nguyen  * Function-return probe -
180b94cce92SHien Nguyen  * Note:
181b94cce92SHien Nguyen  * User needs to provide a handler function, and initialize maxactive.
182b94cce92SHien Nguyen  * maxactive - The maximum number of instances of the probed function that
183b94cce92SHien Nguyen  * can be active concurrently.
184b94cce92SHien Nguyen  * nmissed - tracks the number of times the probed function's return was
185b94cce92SHien Nguyen  * ignored, due to maxactive being too low.
186b94cce92SHien Nguyen  *
187b94cce92SHien Nguyen  */
188b94cce92SHien Nguyen struct kretprobe {
189b94cce92SHien Nguyen 	struct kprobe kp;
190b94cce92SHien Nguyen 	kretprobe_handler_t handler;
191f47cd9b5SAbhishek Sagar 	kretprobe_handler_t entry_handler;
192b94cce92SHien Nguyen 	int maxactive;
193b94cce92SHien Nguyen 	int nmissed;
194f47cd9b5SAbhishek Sagar 	size_t data_size;
195b94cce92SHien Nguyen 	struct hlist_head free_instances;
196ec484608SThomas Gleixner 	raw_spinlock_t lock;
197b94cce92SHien Nguyen };
198b94cce92SHien Nguyen 
199b94cce92SHien Nguyen struct kretprobe_instance {
200b94cce92SHien Nguyen 	struct hlist_node hlist;
201b94cce92SHien Nguyen 	struct kretprobe *rp;
202802eae7cSRusty Lynch 	kprobe_opcode_t *ret_addr;
203802eae7cSRusty Lynch 	struct task_struct *task;
204f47cd9b5SAbhishek Sagar 	char data[0];
205b94cce92SHien Nguyen };
206b94cce92SHien Nguyen 
207f438d914SMasami Hiramatsu struct kretprobe_blackpoint {
208f438d914SMasami Hiramatsu 	const char *name;
209f438d914SMasami Hiramatsu 	void *addr;
210f438d914SMasami Hiramatsu };
2113d8d996eSSrinivasa Ds 
2123d8d996eSSrinivasa Ds struct kprobe_blackpoint {
2133d8d996eSSrinivasa Ds 	const char *name;
2143d8d996eSSrinivasa Ds 	unsigned long start_addr;
2153d8d996eSSrinivasa Ds 	unsigned long range;
2163d8d996eSSrinivasa Ds };
2173d8d996eSSrinivasa Ds 
218dc19835dSMasami Hiramatsu #ifdef CONFIG_KPROBES
219dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe *, current_kprobe);
220dc19835dSMasami Hiramatsu DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
221dc19835dSMasami Hiramatsu 
222b1801812SIngo Molnar /*
223b1801812SIngo Molnar  * For #ifdef avoidance:
224b1801812SIngo Molnar  */
225b1801812SIngo Molnar static inline int kprobes_built_in(void)
226b1801812SIngo Molnar {
227b1801812SIngo Molnar 	return 1;
228b1801812SIngo Molnar }
229b1801812SIngo Molnar 
230dc19835dSMasami Hiramatsu #ifdef CONFIG_KRETPROBES
231dc19835dSMasami Hiramatsu extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
232dc19835dSMasami Hiramatsu 				   struct pt_regs *regs);
233dc19835dSMasami Hiramatsu extern int arch_trampoline_kprobe(struct kprobe *p);
234dc19835dSMasami Hiramatsu #else /* CONFIG_KRETPROBES */
235dc19835dSMasami Hiramatsu static inline void arch_prepare_kretprobe(struct kretprobe *rp,
236dc19835dSMasami Hiramatsu 					struct pt_regs *regs)
237dc19835dSMasami Hiramatsu {
238dc19835dSMasami Hiramatsu }
239dc19835dSMasami Hiramatsu static inline int arch_trampoline_kprobe(struct kprobe *p)
240dc19835dSMasami Hiramatsu {
241dc19835dSMasami Hiramatsu 	return 0;
242dc19835dSMasami Hiramatsu }
243dc19835dSMasami Hiramatsu #endif /* CONFIG_KRETPROBES */
244dc19835dSMasami Hiramatsu 
245f438d914SMasami Hiramatsu extern struct kretprobe_blackpoint kretprobe_blacklist[];
246f438d914SMasami Hiramatsu 
2470f95b7fcSAnanth N Mavinakayanahalli static inline void kretprobe_assert(struct kretprobe_instance *ri,
2480f95b7fcSAnanth N Mavinakayanahalli 	unsigned long orig_ret_address, unsigned long trampoline_address)
2490f95b7fcSAnanth N Mavinakayanahalli {
2500f95b7fcSAnanth N Mavinakayanahalli 	if (!orig_ret_address || (orig_ret_address == trampoline_address)) {
2510f95b7fcSAnanth N Mavinakayanahalli 		printk("kretprobe BUG!: Processing kretprobe %p @ %p\n",
2520f95b7fcSAnanth N Mavinakayanahalli 				ri->rp, ri->rp->kp.addr);
2530f95b7fcSAnanth N Mavinakayanahalli 		BUG();
2540f95b7fcSAnanth N Mavinakayanahalli 	}
2550f95b7fcSAnanth N Mavinakayanahalli }
2560f95b7fcSAnanth N Mavinakayanahalli 
2578c1c9356SAnanth N Mavinakayanahalli #ifdef CONFIG_KPROBES_SANITY_TEST
2588c1c9356SAnanth N Mavinakayanahalli extern int init_test_probes(void);
2598c1c9356SAnanth N Mavinakayanahalli #else
2608c1c9356SAnanth N Mavinakayanahalli static inline int init_test_probes(void)
2618c1c9356SAnanth N Mavinakayanahalli {
2628c1c9356SAnanth N Mavinakayanahalli 	return 0;
2638c1c9356SAnanth N Mavinakayanahalli }
2648c1c9356SAnanth N Mavinakayanahalli #endif /* CONFIG_KPROBES_SANITY_TEST */
2658c1c9356SAnanth N Mavinakayanahalli 
2661da177e4SLinus Torvalds extern int arch_prepare_kprobe(struct kprobe *p);
2677e1048b1SRusty Lynch extern void arch_arm_kprobe(struct kprobe *p);
2687e1048b1SRusty Lynch extern void arch_disarm_kprobe(struct kprobe *p);
2696772926bSRusty Lynch extern int arch_init_kprobes(void);
2701da177e4SLinus Torvalds extern void show_registers(struct pt_regs *regs);
2719ec4b1f3SAnanth N Mavinakayanahalli extern kprobe_opcode_t *get_insn_slot(void);
272b4c6c34aSMasami Hiramatsu extern void free_insn_slot(kprobe_opcode_t *slot, int dirty);
273bf8d5c52SKeshavamurthy Anil S extern void kprobes_inc_nmissed_count(struct kprobe *p);
2741da177e4SLinus Torvalds 
275afd66255SMasami Hiramatsu #ifdef CONFIG_OPTPROBES
276afd66255SMasami Hiramatsu /*
277afd66255SMasami Hiramatsu  * Internal structure for direct jump optimized probe
278afd66255SMasami Hiramatsu  */
279afd66255SMasami Hiramatsu struct optimized_kprobe {
280afd66255SMasami Hiramatsu 	struct kprobe kp;
281afd66255SMasami Hiramatsu 	struct list_head list;	/* list for optimizing queue */
282afd66255SMasami Hiramatsu 	struct arch_optimized_insn optinsn;
283afd66255SMasami Hiramatsu };
284afd66255SMasami Hiramatsu 
285afd66255SMasami Hiramatsu /* Architecture dependent functions for direct jump optimization */
286afd66255SMasami Hiramatsu extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn);
287afd66255SMasami Hiramatsu extern int arch_check_optimized_kprobe(struct optimized_kprobe *op);
288afd66255SMasami Hiramatsu extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op);
289afd66255SMasami Hiramatsu extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op);
290cd7ebe22SMasami Hiramatsu extern void arch_optimize_kprobes(struct list_head *oplist);
291f984ba4eSMasami Hiramatsu extern void arch_unoptimize_kprobes(struct list_head *oplist,
292f984ba4eSMasami Hiramatsu 				    struct list_head *done_list);
293afd66255SMasami Hiramatsu extern void arch_unoptimize_kprobe(struct optimized_kprobe *op);
294afd66255SMasami Hiramatsu extern kprobe_opcode_t *get_optinsn_slot(void);
295afd66255SMasami Hiramatsu extern void free_optinsn_slot(kprobe_opcode_t *slot, int dirty);
296afd66255SMasami Hiramatsu extern int arch_within_optimized_kprobe(struct optimized_kprobe *op,
297afd66255SMasami Hiramatsu 					unsigned long addr);
298afd66255SMasami Hiramatsu 
299afd66255SMasami Hiramatsu extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs);
300b2be84dfSMasami Hiramatsu 
301b2be84dfSMasami Hiramatsu #ifdef CONFIG_SYSCTL
302b2be84dfSMasami Hiramatsu extern int sysctl_kprobes_optimization;
303b2be84dfSMasami Hiramatsu extern int proc_kprobes_optimization_handler(struct ctl_table *table,
304b2be84dfSMasami Hiramatsu 					     int write, void __user *buffer,
305b2be84dfSMasami Hiramatsu 					     size_t *length, loff_t *ppos);
306b2be84dfSMasami Hiramatsu #endif
307b2be84dfSMasami Hiramatsu 
308afd66255SMasami Hiramatsu #endif /* CONFIG_OPTPROBES */
309*e7dbfe34SMasami Hiramatsu #ifdef CONFIG_KPROBES_ON_FTRACE
310ae6aa16fSMasami Hiramatsu extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
311e5253896SMasami Hiramatsu 				  struct ftrace_ops *ops, struct pt_regs *regs);
312ae6aa16fSMasami Hiramatsu extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
313ae6aa16fSMasami Hiramatsu #endif
314ae6aa16fSMasami Hiramatsu 
315afd66255SMasami Hiramatsu 
316d217d545SAnanth N Mavinakayanahalli /* Get the kprobe at this addr (if any) - called with preemption disabled */
3171da177e4SLinus Torvalds struct kprobe *get_kprobe(void *addr);
318ef53d9c5SSrinivasa D S void kretprobe_hash_lock(struct task_struct *tsk,
319ef53d9c5SSrinivasa D S 			 struct hlist_head **head, unsigned long *flags);
320ef53d9c5SSrinivasa D S void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags);
321b94cce92SHien Nguyen struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk);
3221da177e4SLinus Torvalds 
323e6584523SAnanth N Mavinakayanahalli /* kprobe_running() will just return the current_kprobe on this CPU */
324e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void)
325e6584523SAnanth N Mavinakayanahalli {
326b76834bcSChristoph Lameter 	return (__this_cpu_read(current_kprobe));
327e6584523SAnanth N Mavinakayanahalli }
328e6584523SAnanth N Mavinakayanahalli 
329e6584523SAnanth N Mavinakayanahalli static inline void reset_current_kprobe(void)
330e6584523SAnanth N Mavinakayanahalli {
331b76834bcSChristoph Lameter 	__this_cpu_write(current_kprobe, NULL);
332e6584523SAnanth N Mavinakayanahalli }
333e6584523SAnanth N Mavinakayanahalli 
334e6584523SAnanth N Mavinakayanahalli static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
335e6584523SAnanth N Mavinakayanahalli {
336e6584523SAnanth N Mavinakayanahalli 	return (&__get_cpu_var(kprobe_ctlblk));
337e6584523SAnanth N Mavinakayanahalli }
338e6584523SAnanth N Mavinakayanahalli 
3391da177e4SLinus Torvalds int register_kprobe(struct kprobe *p);
3401da177e4SLinus Torvalds void unregister_kprobe(struct kprobe *p);
3419861668fSMasami Hiramatsu int register_kprobes(struct kprobe **kps, int num);
3429861668fSMasami Hiramatsu void unregister_kprobes(struct kprobe **kps, int num);
3431da177e4SLinus Torvalds int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
3441da177e4SLinus Torvalds int longjmp_break_handler(struct kprobe *, struct pt_regs *);
3451da177e4SLinus Torvalds int register_jprobe(struct jprobe *p);
3461da177e4SLinus Torvalds void unregister_jprobe(struct jprobe *p);
34726b31c19SMasami Hiramatsu int register_jprobes(struct jprobe **jps, int num);
34826b31c19SMasami Hiramatsu void unregister_jprobes(struct jprobe **jps, int num);
3491da177e4SLinus Torvalds void jprobe_return(void);
3503d7e3382SMichael Ellerman unsigned long arch_deref_entry_point(void *);
3511da177e4SLinus Torvalds 
352b94cce92SHien Nguyen int register_kretprobe(struct kretprobe *rp);
353b94cce92SHien Nguyen void unregister_kretprobe(struct kretprobe *rp);
3544a296e07SMasami Hiramatsu int register_kretprobes(struct kretprobe **rps, int num);
3554a296e07SMasami Hiramatsu void unregister_kretprobes(struct kretprobe **rps, int num);
356b94cce92SHien Nguyen 
357b94cce92SHien Nguyen void kprobe_flush_task(struct task_struct *tk);
35899219a3fSbibo,mao void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);
3598c1c9356SAnanth N Mavinakayanahalli 
360de5bd88dSMasami Hiramatsu int disable_kprobe(struct kprobe *kp);
361de5bd88dSMasami Hiramatsu int enable_kprobe(struct kprobe *kp);
362de5bd88dSMasami Hiramatsu 
36324851d24SFrederic Weisbecker void dump_kprobe(struct kprobe *kp);
36424851d24SFrederic Weisbecker 
365b1801812SIngo Molnar #else /* !CONFIG_KPROBES: */
36600d7c05aSKeshavamurthy Anil S 
367b1801812SIngo Molnar static inline int kprobes_built_in(void)
368b1801812SIngo Molnar {
369b1801812SIngo Molnar 	return 0;
370b1801812SIngo Molnar }
371b1801812SIngo Molnar static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
372b1801812SIngo Molnar {
373b1801812SIngo Molnar 	return 0;
374b1801812SIngo Molnar }
375785656a4SAbhishek Sagar static inline struct kprobe *get_kprobe(void *addr)
376785656a4SAbhishek Sagar {
377785656a4SAbhishek Sagar 	return NULL;
378785656a4SAbhishek Sagar }
379e6584523SAnanth N Mavinakayanahalli static inline struct kprobe *kprobe_running(void)
3801da177e4SLinus Torvalds {
381e6584523SAnanth N Mavinakayanahalli 	return NULL;
3821da177e4SLinus Torvalds }
3831da177e4SLinus Torvalds static inline int register_kprobe(struct kprobe *p)
3841da177e4SLinus Torvalds {
3851da177e4SLinus Torvalds 	return -ENOSYS;
3861da177e4SLinus Torvalds }
3879861668fSMasami Hiramatsu static inline int register_kprobes(struct kprobe **kps, int num)
3889861668fSMasami Hiramatsu {
3899861668fSMasami Hiramatsu 	return -ENOSYS;
3909861668fSMasami Hiramatsu }
3911da177e4SLinus Torvalds static inline void unregister_kprobe(struct kprobe *p)
3921da177e4SLinus Torvalds {
3931da177e4SLinus Torvalds }
3949861668fSMasami Hiramatsu static inline void unregister_kprobes(struct kprobe **kps, int num)
3959861668fSMasami Hiramatsu {
3969861668fSMasami Hiramatsu }
3971da177e4SLinus Torvalds static inline int register_jprobe(struct jprobe *p)
3981da177e4SLinus Torvalds {
3991da177e4SLinus Torvalds 	return -ENOSYS;
4001da177e4SLinus Torvalds }
40126b31c19SMasami Hiramatsu static inline int register_jprobes(struct jprobe **jps, int num)
40226b31c19SMasami Hiramatsu {
40326b31c19SMasami Hiramatsu 	return -ENOSYS;
40426b31c19SMasami Hiramatsu }
4051da177e4SLinus Torvalds static inline void unregister_jprobe(struct jprobe *p)
4061da177e4SLinus Torvalds {
4071da177e4SLinus Torvalds }
40826b31c19SMasami Hiramatsu static inline void unregister_jprobes(struct jprobe **jps, int num)
40926b31c19SMasami Hiramatsu {
41026b31c19SMasami Hiramatsu }
4111da177e4SLinus Torvalds static inline void jprobe_return(void)
4121da177e4SLinus Torvalds {
4131da177e4SLinus Torvalds }
414b94cce92SHien Nguyen static inline int register_kretprobe(struct kretprobe *rp)
415b94cce92SHien Nguyen {
416b94cce92SHien Nguyen 	return -ENOSYS;
417b94cce92SHien Nguyen }
4184a296e07SMasami Hiramatsu static inline int register_kretprobes(struct kretprobe **rps, int num)
4194a296e07SMasami Hiramatsu {
4204a296e07SMasami Hiramatsu 	return -ENOSYS;
4214a296e07SMasami Hiramatsu }
422b94cce92SHien Nguyen static inline void unregister_kretprobe(struct kretprobe *rp)
423b94cce92SHien Nguyen {
424b94cce92SHien Nguyen }
4254a296e07SMasami Hiramatsu static inline void unregister_kretprobes(struct kretprobe **rps, int num)
4264a296e07SMasami Hiramatsu {
4274a296e07SMasami Hiramatsu }
428b94cce92SHien Nguyen static inline void kprobe_flush_task(struct task_struct *tk)
429b94cce92SHien Nguyen {
430b94cce92SHien Nguyen }
431de5bd88dSMasami Hiramatsu static inline int disable_kprobe(struct kprobe *kp)
432de5bd88dSMasami Hiramatsu {
433de5bd88dSMasami Hiramatsu 	return -ENOSYS;
434de5bd88dSMasami Hiramatsu }
435de5bd88dSMasami Hiramatsu static inline int enable_kprobe(struct kprobe *kp)
436de5bd88dSMasami Hiramatsu {
437de5bd88dSMasami Hiramatsu 	return -ENOSYS;
438de5bd88dSMasami Hiramatsu }
439b94cce92SHien Nguyen #endif /* CONFIG_KPROBES */
4408f9b1528SMasami Hiramatsu static inline int disable_kretprobe(struct kretprobe *rp)
4418f9b1528SMasami Hiramatsu {
4428f9b1528SMasami Hiramatsu 	return disable_kprobe(&rp->kp);
4438f9b1528SMasami Hiramatsu }
4448f9b1528SMasami Hiramatsu static inline int enable_kretprobe(struct kretprobe *rp)
4458f9b1528SMasami Hiramatsu {
4468f9b1528SMasami Hiramatsu 	return enable_kprobe(&rp->kp);
4478f9b1528SMasami Hiramatsu }
4488f9b1528SMasami Hiramatsu static inline int disable_jprobe(struct jprobe *jp)
4498f9b1528SMasami Hiramatsu {
4508f9b1528SMasami Hiramatsu 	return disable_kprobe(&jp->kp);
4518f9b1528SMasami Hiramatsu }
4528f9b1528SMasami Hiramatsu static inline int enable_jprobe(struct jprobe *jp)
4538f9b1528SMasami Hiramatsu {
4548f9b1528SMasami Hiramatsu 	return enable_kprobe(&jp->kp);
4558f9b1528SMasami Hiramatsu }
4568f9b1528SMasami Hiramatsu 
4571da177e4SLinus Torvalds #endif /* _LINUX_KPROBES_H */
458