Blame view

include/linux/kprobes.h 13.8 KB
1a59d1b8e   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
  #ifndef _LINUX_KPROBES_H
  #define _LINUX_KPROBES_H
  /*
   *  Kernel Probes (KProbes)
   *  include/linux/kprobes.h
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
13
14
   * Copyright (C) IBM Corporation, 2002, 2004
   *
   * 2002-Oct	Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
   *		Probes initial implementation ( includes suggestions from
   *		Rusty Russell).
   * 2004-July	Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
   *		interface to access function arguments.
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
15
16
17
   * 2005-May	Hien Nguyen <hien@us.ibm.com> and Jim Keniston
   *		<jkenisto@us.ibm.com>  and Prasanna S Panchamukhi
   *		<prasanna@in.ibm.com> added function-return probes.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
   */
7d134b2ce   Luis R. Rodriguez   kprobes: move kpr...
19
  #include <linux/compiler.h>
36dcd67ae   Ingo Molnar   ftrace: ignore fu...
20
  #include <linux/linkage.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
23
  #include <linux/list.h>
  #include <linux/notifier.h>
  #include <linux/smp.h>
187f1882b   Paul Gortmaker   BUG: headers with...
24
  #include <linux/bug.h>
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
25
  #include <linux/percpu.h>
3516a4604   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
26
27
  #include <linux/spinlock.h>
  #include <linux/rcupdate.h>
7a7d1cf95   Ingo Molnar   [PATCH] sem2mutex...
28
  #include <linux/mutex.h>
ae6aa16fd   Masami Hiramatsu   kprobes: introduc...
29
  #include <linux/ftrace.h>
7d134b2ce   Luis R. Rodriguez   kprobes: move kpr...
30
  #include <asm/kprobes.h>
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
31

00d7c05ab   Keshavamurthy Anil S   [PATCH] kprobes: ...
32
  #ifdef CONFIG_KPROBES
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33

ea32c65cc   Prasanna S Panchamukhi   [PATCH] kprobes: ...
34
35
36
37
38
  /* kprobe_status settings */
  #define KPROBE_HIT_ACTIVE	0x00000001
  #define KPROBE_HIT_SS		0x00000002
  #define KPROBE_REENTER		0x00000004
  #define KPROBE_HIT_SSDONE	0x00000008
dc19835df   Masami Hiramatsu   kprobes: fix modu...
39
  #else /* CONFIG_KPROBES */
7d134b2ce   Luis R. Rodriguez   kprobes: move kpr...
40
  #include <asm-generic/kprobes.h>
dc19835df   Masami Hiramatsu   kprobes: fix modu...
41
42
43
44
  typedef int kprobe_opcode_t;
  struct arch_specific_insn {
  	int dummy;
  };
dc19835df   Masami Hiramatsu   kprobes: fix modu...
45
  #endif /* CONFIG_KPROBES */
d0aaff979   Prasanna S Panchamukhi   [PATCH] Kprobes: ...
46

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
  struct kprobe;
  struct pt_regs;
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
49
50
  struct kretprobe;
  struct kretprobe_instance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
  typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
55
  typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
  				       unsigned long flags);
  typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
  				       int trapnr);
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
56
57
  typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
  				    struct pt_regs *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
  struct kprobe {
  	struct hlist_node hlist;
64f562c6d   Ananth N Mavinakayanahalli   [PATCH] kprobes: ...
60
61
  	/* list of kprobes for multi-handler support */
  	struct list_head list;
ea32c65cc   Prasanna S Panchamukhi   [PATCH] kprobes: ...
62
63
  	/*count the number of times this probe was temporarily disarmed */
  	unsigned long nmissed;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
  	/* location of the probe point */
  	kprobe_opcode_t *addr;
3a872d89b   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
66
  	/* Allow user to indicate symbol name of the probe point */
9b3af29bf   Ananth N Mavinakayanahalli   Kprobes: Make kpr...
67
  	const char *symbol_name;
3a872d89b   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
68
69
70
  
  	/* Offset into the symbol */
  	unsigned int offset;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
75
  	/* Called before addr is executed. */
  	kprobe_pre_handler_t pre_handler;
  
  	/* Called after addr is executed, unless... */
  	kprobe_post_handler_t post_handler;
cc00e9cfe   Masami Hiramatsu   kprobes: cleanup ...
76
77
78
79
  	/*
  	 * ... called if executing addr causes a fault (eg. page fault).
  	 * Return 1 if it handled fault, otherwise kernel will see it.
  	 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  	kprobe_fault_handler_t fault_handler;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
82
83
84
85
  	/* Saved opcode (which has been replaced with breakpoint) */
  	kprobe_opcode_t opcode;
  
  	/* copy of the original instruction */
  	struct arch_specific_insn ainsn;
e8386a0cb   Masami Hiramatsu   kprobes: support ...
86

de5bd88d5   Masami Hiramatsu   kprobes: support ...
87
88
89
90
  	/*
  	 * Indicates various status flags.
  	 * Protected by kprobe_mutex after this kprobe is registered.
  	 */
e8386a0cb   Masami Hiramatsu   kprobes: support ...
91
  	u32 flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
  };
e8386a0cb   Masami Hiramatsu   kprobes: support ...
93
94
  /* Kprobe status flags */
  #define KPROBE_FLAG_GONE	1 /* breakpoint has already gone */
de5bd88d5   Masami Hiramatsu   kprobes: support ...
95
  #define KPROBE_FLAG_DISABLED	2 /* probe is temporarily disabled */
afd66255b   Masami Hiramatsu   kprobes: Introduc...
96
97
98
99
100
  #define KPROBE_FLAG_OPTIMIZED	4 /*
  				   * probe is really optimized.
  				   * NOTE:
  				   * this flag is only for optimized_kprobe.
  				   */
ae6aa16fd   Masami Hiramatsu   kprobes: introduc...
101
  #define KPROBE_FLAG_FTRACE	8 /* probe is using ftrace */
e8386a0cb   Masami Hiramatsu   kprobes: support ...
102

de5bd88d5   Masami Hiramatsu   kprobes: support ...
103
  /* Has this kprobe gone ? */
e8386a0cb   Masami Hiramatsu   kprobes: support ...
104
105
106
107
  static inline int kprobe_gone(struct kprobe *p)
  {
  	return p->flags & KPROBE_FLAG_GONE;
  }
de5bd88d5   Masami Hiramatsu   kprobes: support ...
108
109
110
111
112
  /* Is this kprobe disabled ? */
  static inline int kprobe_disabled(struct kprobe *p)
  {
  	return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE);
  }
afd66255b   Masami Hiramatsu   kprobes: Introduc...
113
114
115
116
117
118
  
  /* Is this kprobe really running optimized path ? */
  static inline int kprobe_optimized(struct kprobe *p)
  {
  	return p->flags & KPROBE_FLAG_OPTIMIZED;
  }
ae6aa16fd   Masami Hiramatsu   kprobes: introduc...
119
120
121
122
123
124
  
  /* Is this kprobe uses ftrace ? */
  static inline int kprobe_ftrace(struct kprobe *p)
  {
  	return p->flags & KPROBE_FLAG_FTRACE;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
  /*
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
126
127
128
129
130
131
132
133
134
135
136
137
   * Function-return probe -
   * Note:
   * User needs to provide a handler function, and initialize maxactive.
   * maxactive - The maximum number of instances of the probed function that
   * can be active concurrently.
   * nmissed - tracks the number of times the probed function's return was
   * ignored, due to maxactive being too low.
   *
   */
  struct kretprobe {
  	struct kprobe kp;
  	kretprobe_handler_t handler;
f47cd9b55   Abhishek Sagar   kprobes: kretprob...
138
  	kretprobe_handler_t entry_handler;
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
139
140
  	int maxactive;
  	int nmissed;
f47cd9b55   Abhishek Sagar   kprobes: kretprob...
141
  	size_t data_size;
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
142
  	struct hlist_head free_instances;
ec484608c   Thomas Gleixner   locking, kprobes:...
143
  	raw_spinlock_t lock;
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
144
145
146
  };
  
  struct kretprobe_instance {
b33881780   Masami Hiramatsu   kprobes: Free kre...
147
148
149
150
  	union {
  		struct hlist_node hlist;
  		struct rcu_head rcu;
  	};
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
151
  	struct kretprobe *rp;
802eae7c8   Rusty Lynch   [PATCH] Return pr...
152
153
  	kprobe_opcode_t *ret_addr;
  	struct task_struct *task;
3ff9c075c   Masami Hiramatsu   x86/kprobes: Veri...
154
  	void *fp;
67a862a94   Gustavo A. R. Silva   kprobes: Replace ...
155
  	char data[];
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
156
  };
f438d914b   Masami Hiramatsu   kprobes: support ...
157
158
159
160
  struct kretprobe_blackpoint {
  	const char *name;
  	void *addr;
  };
3d8d996e0   Srinivasa Ds   kprobes: prevent ...
161

376e24242   Masami Hiramatsu   kprobes: Introduc...
162
163
  struct kprobe_blacklist_entry {
  	struct list_head list;
3d8d996e0   Srinivasa Ds   kprobes: prevent ...
164
  	unsigned long start_addr;
376e24242   Masami Hiramatsu   kprobes: Introduc...
165
  	unsigned long end_addr;
3d8d996e0   Srinivasa Ds   kprobes: prevent ...
166
  };
dc19835df   Masami Hiramatsu   kprobes: fix modu...
167
168
169
  #ifdef CONFIG_KPROBES
  DECLARE_PER_CPU(struct kprobe *, current_kprobe);
  DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
b18018126   Ingo Molnar   x86, mm, kprobes:...
170
171
172
173
174
175
176
  /*
   * For #ifdef avoidance:
   */
  static inline int kprobes_built_in(void)
  {
  	return 1;
  }
66ada2cca   Masami Hiramatsu   kprobes: Add gene...
177
178
  extern void kprobe_busy_begin(void);
  extern void kprobe_busy_end(void);
dc19835df   Masami Hiramatsu   kprobes: fix modu...
179
180
181
182
  #ifdef CONFIG_KRETPROBES
  extern void arch_prepare_kretprobe(struct kretprobe_instance *ri,
  				   struct pt_regs *regs);
  extern int arch_trampoline_kprobe(struct kprobe *p);
66ada2cca   Masami Hiramatsu   kprobes: Add gene...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  
  /* If the trampoline handler called from a kprobe, use this version */
  unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs,
  				void *trampoline_address,
  				void *frame_pointer);
  
  static nokprobe_inline
  unsigned long kretprobe_trampoline_handler(struct pt_regs *regs,
  				void *trampoline_address,
  				void *frame_pointer)
  {
  	unsigned long ret;
  	/*
  	 * Set a dummy kprobe for avoiding kretprobe recursion.
  	 * Since kretprobe never runs in kprobe handler, no kprobe must
  	 * be running at this point.
  	 */
  	kprobe_busy_begin();
  	ret = __kretprobe_trampoline_handler(regs, trampoline_address, frame_pointer);
  	kprobe_busy_end();
  
  	return ret;
  }
dc19835df   Masami Hiramatsu   kprobes: fix modu...
206
207
208
209
210
211
212
213
214
215
  #else /* CONFIG_KRETPROBES */
  static inline void arch_prepare_kretprobe(struct kretprobe *rp,
  					struct pt_regs *regs)
  {
  }
  static inline int arch_trampoline_kprobe(struct kprobe *p)
  {
  	return 0;
  }
  #endif /* CONFIG_KRETPROBES */
f438d914b   Masami Hiramatsu   kprobes: support ...
216
  extern struct kretprobe_blackpoint kretprobe_blacklist[];
8c1c93564   Ananth N Mavinakayanahalli   x86: kprobes: add...
217
218
219
220
221
222
223
224
  #ifdef CONFIG_KPROBES_SANITY_TEST
  extern int init_test_probes(void);
  #else
  static inline int init_test_probes(void)
  {
  	return 0;
  }
  #endif /* CONFIG_KPROBES_SANITY_TEST */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
  extern int arch_prepare_kprobe(struct kprobe *p);
7e1048b11   Rusty Lynch   [PATCH] Move kpro...
226
227
  extern void arch_arm_kprobe(struct kprobe *p);
  extern void arch_disarm_kprobe(struct kprobe *p);
6772926be   Rusty Lynch   [PATCH] kprobes: ...
228
  extern int arch_init_kprobes(void);
bf8d5c52c   Keshavamurthy Anil S   [PATCH] kprobes: ...
229
  extern void kprobes_inc_nmissed_count(struct kprobe *p);
be8f27432   Masami Hiramatsu   kprobes: Prohibit...
230
  extern bool arch_within_kprobe_blacklist(unsigned long addr);
fb1a59fae   Masami Hiramatsu   kprobes: Blacklis...
231
  extern int arch_populate_kprobe_blacklist(void);
659b957f2   Naveen N. Rao   kprobes: Rename [...
232
233
  extern bool arch_kprobe_on_func_entry(unsigned long offset);
  extern bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234

e5779e8e1   Andy Lutomirski   perf/x86/hw_break...
235
  extern bool within_kprobe_blacklist(unsigned long addr);
fb1a59fae   Masami Hiramatsu   kprobes: Blacklis...
236
237
  extern int kprobe_add_ksym_blacklist(unsigned long entry);
  extern int kprobe_add_area_blacklist(unsigned long start, unsigned long end);
e5779e8e1   Andy Lutomirski   perf/x86/hw_break...
238

c802d64a3   Heiko Carstens   kprobes: unify in...
239
240
  struct kprobe_insn_cache {
  	struct mutex mutex;
af96397de   Heiko Carstens   kprobes: allow to...
241
242
  	void *(*alloc)(void);	/* allocate insn page */
  	void (*free)(void *);	/* free insn page */
d002b8bc6   Adrian Hunter   kprobes: Add symb...
243
  	const char *sym;	/* symbol for insn pages */
c802d64a3   Heiko Carstens   kprobes: unify in...
244
245
246
247
  	struct list_head pages; /* list of kprobe_insn_page */
  	size_t insn_size;	/* size of instruction slot */
  	int nr_garbage;
  };
5b485629b   Masami Hiramatsu   kprobes, extable:...
248
  #ifdef __ARCH_WANT_KPROBES_INSN_SLOT
c802d64a3   Heiko Carstens   kprobes: unify in...
249
250
251
  extern kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c);
  extern void __free_insn_slot(struct kprobe_insn_cache *c,
  			     kprobe_opcode_t *slot, int dirty);
5b485629b   Masami Hiramatsu   kprobes, extable:...
252
253
254
  /* sleep-less address checking routine  */
  extern bool __is_insn_slot_addr(struct kprobe_insn_cache *c,
  				unsigned long addr);
c802d64a3   Heiko Carstens   kprobes: unify in...
255
256
257
258
259
260
261
262
263
264
265
266
267
  
  #define DEFINE_INSN_CACHE_OPS(__name)					\
  extern struct kprobe_insn_cache kprobe_##__name##_slots;		\
  									\
  static inline kprobe_opcode_t *get_##__name##_slot(void)		\
  {									\
  	return __get_insn_slot(&kprobe_##__name##_slots);		\
  }									\
  									\
  static inline void free_##__name##_slot(kprobe_opcode_t *slot, int dirty)\
  {									\
  	__free_insn_slot(&kprobe_##__name##_slots, slot, dirty);	\
  }									\
5b485629b   Masami Hiramatsu   kprobes, extable:...
268
269
270
271
272
  									\
  static inline bool is_kprobe_##__name##_slot(unsigned long addr)	\
  {									\
  	return __is_insn_slot_addr(&kprobe_##__name##_slots, addr);	\
  }
d002b8bc6   Adrian Hunter   kprobes: Add symb...
273
274
275
276
  #define KPROBE_INSN_PAGE_SYM		"kprobe_insn_page"
  #define KPROBE_OPTINSN_PAGE_SYM		"kprobe_optinsn_page"
  int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum,
  			     unsigned long *value, char *type, char *sym);
5b485629b   Masami Hiramatsu   kprobes, extable:...
277
278
279
280
281
282
283
  #else /* __ARCH_WANT_KPROBES_INSN_SLOT */
  #define DEFINE_INSN_CACHE_OPS(__name)					\
  static inline bool is_kprobe_##__name##_slot(unsigned long addr)	\
  {									\
  	return 0;							\
  }
  #endif
c802d64a3   Heiko Carstens   kprobes: unify in...
284
285
  
  DEFINE_INSN_CACHE_OPS(insn);
afd66255b   Masami Hiramatsu   kprobes: Introduc...
286
287
288
289
290
291
292
293
294
295
296
297
298
  #ifdef CONFIG_OPTPROBES
  /*
   * Internal structure for direct jump optimized probe
   */
  struct optimized_kprobe {
  	struct kprobe kp;
  	struct list_head list;	/* list for optimizing queue */
  	struct arch_optimized_insn optinsn;
  };
  
  /* Architecture dependent functions for direct jump optimization */
  extern int arch_prepared_optinsn(struct arch_optimized_insn *optinsn);
  extern int arch_check_optimized_kprobe(struct optimized_kprobe *op);
cbf6ab52a   Masami Hiramatsu   kprobes: Pass the...
299
300
  extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op,
  					 struct kprobe *orig);
afd66255b   Masami Hiramatsu   kprobes: Introduc...
301
  extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op);
cd7ebe229   Masami Hiramatsu   kprobes: Use text...
302
  extern void arch_optimize_kprobes(struct list_head *oplist);
f984ba4eb   Masami Hiramatsu   kprobes: Use text...
303
304
  extern void arch_unoptimize_kprobes(struct list_head *oplist,
  				    struct list_head *done_list);
afd66255b   Masami Hiramatsu   kprobes: Introduc...
305
  extern void arch_unoptimize_kprobe(struct optimized_kprobe *op);
afd66255b   Masami Hiramatsu   kprobes: Introduc...
306
307
308
309
  extern int arch_within_optimized_kprobe(struct optimized_kprobe *op,
  					unsigned long addr);
  
  extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs);
b2be84df9   Masami Hiramatsu   kprobes: Jump opt...
310

c802d64a3   Heiko Carstens   kprobes: unify in...
311
  DEFINE_INSN_CACHE_OPS(optinsn);
b2be84df9   Masami Hiramatsu   kprobes: Jump opt...
312
313
314
  #ifdef CONFIG_SYSCTL
  extern int sysctl_kprobes_optimization;
  extern int proc_kprobes_optimization_handler(struct ctl_table *table,
32927393d   Christoph Hellwig   sysctl: pass kern...
315
  					     int write, void *buffer,
b2be84df9   Masami Hiramatsu   kprobes: Jump opt...
316
317
  					     size_t *length, loff_t *ppos);
  #endif
30e7d894c   Thomas Gleixner   tracing/kprobes: ...
318
319
320
  extern void wait_for_kprobe_optimizer(void);
  #else
  static inline void wait_for_kprobe_optimizer(void) { }
afd66255b   Masami Hiramatsu   kprobes: Introduc...
321
  #endif /* CONFIG_OPTPROBES */
e7dbfe349   Masami Hiramatsu   kprobes/x86: Move...
322
  #ifdef CONFIG_KPROBES_ON_FTRACE
ae6aa16fd   Masami Hiramatsu   kprobes: introduc...
323
  extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
e52538965   Masami Hiramatsu   kprobes/x86: ftra...
324
  				  struct ftrace_ops *ops, struct pt_regs *regs);
ae6aa16fd   Masami Hiramatsu   kprobes: introduc...
325
326
  extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
  #endif
f7f242ff0   Heiko Carstens   kprobes: introduc...
327
  int arch_check_ftrace_location(struct kprobe *p);
afd66255b   Masami Hiramatsu   kprobes: Introduc...
328

d217d5450   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
329
  /* Get the kprobe at this addr (if any) - called with preemption disabled */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
  struct kprobe *get_kprobe(void *addr);
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
331
332
333
  /* kprobe_running() will just return the current_kprobe on this CPU */
  static inline struct kprobe *kprobe_running(void)
  {
b76834bc1   Christoph Lameter   kprobes: Use this...
334
  	return (__this_cpu_read(current_kprobe));
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
335
336
337
338
  }
  
  static inline void reset_current_kprobe(void)
  {
b76834bc1   Christoph Lameter   kprobes: Use this...
339
  	__this_cpu_write(current_kprobe, NULL);
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
340
341
342
343
  }
  
  static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void)
  {
bdffd893a   Christoph Lameter   tracing: Replace ...
344
  	return this_cpu_ptr(&kprobe_ctlblk);
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
345
  }
290e30707   Naveen N. Rao   powerpc/kprobes: ...
346
  kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
  int register_kprobe(struct kprobe *p);
  void unregister_kprobe(struct kprobe *p);
9861668f7   Masami Hiramatsu   kprobes: add (un)...
349
350
  int register_kprobes(struct kprobe **kps, int num);
  void unregister_kprobes(struct kprobe **kps, int num);
3d7e33825   Michael Ellerman   jprobes: make jpr...
351
  unsigned long arch_deref_entry_point(void *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352

b94cce926   Hien Nguyen   [PATCH] kprobes: ...
353
354
  int register_kretprobe(struct kretprobe *rp);
  void unregister_kretprobe(struct kretprobe *rp);
4a296e07c   Masami Hiramatsu   kprobes: add (un)...
355
356
  int register_kretprobes(struct kretprobe **rps, int num);
  void unregister_kretprobes(struct kretprobe **rps, int num);
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
357

b94cce926   Hien Nguyen   [PATCH] kprobes: ...
358
  void kprobe_flush_task(struct task_struct *tk);
8c1c93564   Ananth N Mavinakayanahalli   x86: kprobes: add...
359

82d083ab6   Masami Hiramatsu   kprobes: tracing/...
360
  void kprobe_free_init_mem(void);
de5bd88d5   Masami Hiramatsu   kprobes: support ...
361
362
  int disable_kprobe(struct kprobe *kp);
  int enable_kprobe(struct kprobe *kp);
24851d244   Frederic Weisbecker   tracing/kprobes: ...
363
  void dump_kprobe(struct kprobe *kp);
ad3bc25a3   Borislav Petkov   x86/kernel: Fix m...
364
365
  void *alloc_insn_page(void);
  void free_insn_page(void *page);
d002b8bc6   Adrian Hunter   kprobes: Add symb...
366
367
368
369
370
  int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
  		       char *sym);
  
  int arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value,
  			    char *type, char *sym);
b18018126   Ingo Molnar   x86, mm, kprobes:...
371
  #else /* !CONFIG_KPROBES: */
00d7c05ab   Keshavamurthy Anil S   [PATCH] kprobes: ...
372

b18018126   Ingo Molnar   x86, mm, kprobes:...
373
374
375
376
377
378
379
380
  static inline int kprobes_built_in(void)
  {
  	return 0;
  }
  static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
  {
  	return 0;
  }
785656a41   Abhishek Sagar   kprobes: enable c...
381
382
383
384
  static inline struct kprobe *get_kprobe(void *addr)
  {
  	return NULL;
  }
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
385
  static inline struct kprobe *kprobe_running(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
  {
e65845235   Ananth N Mavinakayanahalli   [PATCH] Kprobes: ...
387
  	return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
388
389
390
391
392
  }
  static inline int register_kprobe(struct kprobe *p)
  {
  	return -ENOSYS;
  }
9861668f7   Masami Hiramatsu   kprobes: add (un)...
393
394
395
396
  static inline int register_kprobes(struct kprobe **kps, int num)
  {
  	return -ENOSYS;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
398
399
  static inline void unregister_kprobe(struct kprobe *p)
  {
  }
9861668f7   Masami Hiramatsu   kprobes: add (un)...
400
401
402
  static inline void unregister_kprobes(struct kprobe **kps, int num)
  {
  }
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
403
404
405
406
  static inline int register_kretprobe(struct kretprobe *rp)
  {
  	return -ENOSYS;
  }
4a296e07c   Masami Hiramatsu   kprobes: add (un)...
407
408
409
410
  static inline int register_kretprobes(struct kretprobe **rps, int num)
  {
  	return -ENOSYS;
  }
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
411
412
413
  static inline void unregister_kretprobe(struct kretprobe *rp)
  {
  }
4a296e07c   Masami Hiramatsu   kprobes: add (un)...
414
415
416
  static inline void unregister_kretprobes(struct kretprobe **rps, int num)
  {
  }
b94cce926   Hien Nguyen   [PATCH] kprobes: ...
417
418
419
  static inline void kprobe_flush_task(struct task_struct *tk)
  {
  }
82d083ab6   Masami Hiramatsu   kprobes: tracing/...
420
421
422
  static inline void kprobe_free_init_mem(void)
  {
  }
de5bd88d5   Masami Hiramatsu   kprobes: support ...
423
424
425
426
427
428
429
430
  static inline int disable_kprobe(struct kprobe *kp)
  {
  	return -ENOSYS;
  }
  static inline int enable_kprobe(struct kprobe *kp)
  {
  	return -ENOSYS;
  }
fab940755   Borislav Petkov   x86/hw_breakpoint...
431
432
433
434
435
  
  static inline bool within_kprobe_blacklist(unsigned long addr)
  {
  	return true;
  }
d002b8bc6   Adrian Hunter   kprobes: Add symb...
436
437
438
439
440
  static inline int kprobe_get_kallsym(unsigned int symnum, unsigned long *value,
  				     char *type, char *sym)
  {
  	return -ERANGE;
  }
b18018126   Ingo Molnar   x86, mm, kprobes:...
441
  #endif /* CONFIG_KPROBES */
8f9b15286   Masami Hiramatsu   kprobes: support ...
442
443
444
445
446
447
448
449
  static inline int disable_kretprobe(struct kretprobe *rp)
  {
  	return disable_kprobe(&rp->kp);
  }
  static inline int enable_kretprobe(struct kretprobe *rp)
  {
  	return enable_kprobe(&rp->kp);
  }
8f9b15286   Masami Hiramatsu   kprobes: support ...
450

5b485629b   Masami Hiramatsu   kprobes, extable:...
451
452
453
454
455
456
457
458
459
460
461
462
  #ifndef CONFIG_KPROBES
  static inline bool is_kprobe_insn_slot(unsigned long addr)
  {
  	return false;
  }
  #endif
  #ifndef CONFIG_OPTPROBES
  static inline bool is_kprobe_optinsn_slot(unsigned long addr)
  {
  	return false;
  }
  #endif
b98cca444   Anshuman Khandual   mm, kprobes: gene...
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
  /* Returns true if kprobes handled the fault */
  static nokprobe_inline bool kprobe_page_fault(struct pt_regs *regs,
  					      unsigned int trap)
  {
  	if (!kprobes_built_in())
  		return false;
  	if (user_mode(regs))
  		return false;
  	/*
  	 * To be potentially processing a kprobe fault and to be allowed
  	 * to call kprobe_running(), we have to be non-preemptible.
  	 */
  	if (preemptible())
  		return false;
  	if (!kprobe_running())
  		return false;
  	return kprobe_fault_handler(regs, trap);
  }
b18018126   Ingo Molnar   x86, mm, kprobes:...
481
  #endif /* _LINUX_KPROBES_H */