Blame view
include/linux/kprobes.h
12.3 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#ifndef _LINUX_KPROBES_H #define _LINUX_KPROBES_H /* * Kernel Probes (KProbes) * include/linux/kprobes.h * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 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 [PATCH] kprobes: ... |
28 29 30 |
* 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 Linux-2.6.12-rc2 |
31 |
*/ |
36dcd67ae ftrace: ignore fu... |
32 |
#include <linux/linkage.h> |
1da177e4c Linux-2.6.12-rc2 |
33 34 35 |
#include <linux/list.h> #include <linux/notifier.h> #include <linux/smp.h> |
e65845235 [PATCH] Kprobes: ... |
36 |
#include <linux/percpu.h> |
3516a4604 [PATCH] Kprobes: ... |
37 38 |
#include <linux/spinlock.h> #include <linux/rcupdate.h> |
7a7d1cf95 [PATCH] sem2mutex... |
39 |
#include <linux/mutex.h> |
b94cce926 [PATCH] kprobes: ... |
40 |
|
00d7c05ab [PATCH] kprobes: ... |
41 |
#ifdef CONFIG_KPROBES |
1da177e4c Linux-2.6.12-rc2 |
42 |
#include <asm/kprobes.h> |
ea32c65cc [PATCH] kprobes: ... |
43 44 45 46 47 |
/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001 #define KPROBE_HIT_SS 0x00000002 #define KPROBE_REENTER 0x00000004 #define KPROBE_HIT_SSDONE 0x00000008 |
d0aaff979 [PATCH] Kprobes: ... |
48 |
/* Attach to insert probes on any functions which should be ignored*/ |
fe832a3a4 tracing: remove n... |
49 |
#define __kprobes __attribute__((__section__(".kprobes.text"))) |
dc19835df kprobes: fix modu... |
50 51 52 53 54 |
#else /* CONFIG_KPROBES */ typedef int kprobe_opcode_t; struct arch_specific_insn { int dummy; }; |
fe832a3a4 tracing: remove n... |
55 |
#define __kprobes |
dc19835df kprobes: fix modu... |
56 |
#endif /* CONFIG_KPROBES */ |
d0aaff979 [PATCH] Kprobes: ... |
57 |
|
1da177e4c Linux-2.6.12-rc2 |
58 59 |
struct kprobe; struct pt_regs; |
b94cce926 [PATCH] kprobes: ... |
60 61 |
struct kretprobe; struct kretprobe_instance; |
1da177e4c Linux-2.6.12-rc2 |
62 63 64 65 66 67 |
typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *); typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *); 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 [PATCH] kprobes: ... |
68 69 |
typedef int (*kretprobe_handler_t) (struct kretprobe_instance *, struct pt_regs *); |
1da177e4c Linux-2.6.12-rc2 |
70 71 |
struct kprobe { struct hlist_node hlist; |
64f562c6d [PATCH] kprobes: ... |
72 73 |
/* list of kprobes for multi-handler support */ struct list_head list; |
ea32c65cc [PATCH] kprobes: ... |
74 75 |
/*count the number of times this probe was temporarily disarmed */ unsigned long nmissed; |
1da177e4c Linux-2.6.12-rc2 |
76 77 |
/* location of the probe point */ kprobe_opcode_t *addr; |
3a872d89b [PATCH] Kprobes: ... |
78 |
/* Allow user to indicate symbol name of the probe point */ |
9b3af29bf Kprobes: Make kpr... |
79 |
const char *symbol_name; |
3a872d89b [PATCH] Kprobes: ... |
80 81 82 |
/* Offset into the symbol */ unsigned int offset; |
1da177e4c Linux-2.6.12-rc2 |
83 84 85 86 87 |
/* Called before addr is executed. */ kprobe_pre_handler_t pre_handler; /* Called after addr is executed, unless... */ kprobe_post_handler_t post_handler; |
cc00e9cfe kprobes: cleanup ... |
88 89 90 91 |
/* * ... called if executing addr causes a fault (eg. page fault). * Return 1 if it handled fault, otherwise kernel will see it. */ |
1da177e4c Linux-2.6.12-rc2 |
92 |
kprobe_fault_handler_t fault_handler; |
cc00e9cfe kprobes: cleanup ... |
93 94 95 96 |
/* * ... called if breakpoint trap occurs in probe handler. * Return 1 if it handled break, otherwise kernel will see it. */ |
1da177e4c Linux-2.6.12-rc2 |
97 98 99 100 101 102 103 |
kprobe_break_handler_t break_handler; /* Saved opcode (which has been replaced with breakpoint) */ kprobe_opcode_t opcode; /* copy of the original instruction */ struct arch_specific_insn ainsn; |
e8386a0cb kprobes: support ... |
104 |
|
de5bd88d5 kprobes: support ... |
105 106 107 108 |
/* * Indicates various status flags. * Protected by kprobe_mutex after this kprobe is registered. */ |
e8386a0cb kprobes: support ... |
109 |
u32 flags; |
1da177e4c Linux-2.6.12-rc2 |
110 |
}; |
e8386a0cb kprobes: support ... |
111 112 |
/* Kprobe status flags */ #define KPROBE_FLAG_GONE 1 /* breakpoint has already gone */ |
de5bd88d5 kprobes: support ... |
113 |
#define KPROBE_FLAG_DISABLED 2 /* probe is temporarily disabled */ |
afd66255b kprobes: Introduc... |
114 115 116 117 118 |
#define KPROBE_FLAG_OPTIMIZED 4 /* * probe is really optimized. * NOTE: * this flag is only for optimized_kprobe. */ |
e8386a0cb kprobes: support ... |
119 |
|
de5bd88d5 kprobes: support ... |
120 |
/* Has this kprobe gone ? */ |
e8386a0cb kprobes: support ... |
121 122 123 124 |
static inline int kprobe_gone(struct kprobe *p) { return p->flags & KPROBE_FLAG_GONE; } |
de5bd88d5 kprobes: support ... |
125 126 127 128 129 |
/* Is this kprobe disabled ? */ static inline int kprobe_disabled(struct kprobe *p) { return p->flags & (KPROBE_FLAG_DISABLED | KPROBE_FLAG_GONE); } |
afd66255b kprobes: Introduc... |
130 131 132 133 134 135 |
/* Is this kprobe really running optimized path ? */ static inline int kprobe_optimized(struct kprobe *p) { return p->flags & KPROBE_FLAG_OPTIMIZED; } |
1da177e4c Linux-2.6.12-rc2 |
136 137 138 139 140 141 142 143 144 145 146 147 |
/* * Special probe type that uses setjmp-longjmp type tricks to resume * execution at a specified entry with a matching prototype corresponding * to the probed function - a trick to enable arguments to become * accessible seamlessly by probe handling logic. * Note: * Because of the way compilers allocate stack space for local variables * etc upfront, regardless of sub-scopes within a function, this mirroring * principle currently works only for probes placed on function entry points. */ struct jprobe { struct kprobe kp; |
81eae375e jprobes: make str... |
148 |
void *entry; /* probe handling code to jump to */ |
1da177e4c Linux-2.6.12-rc2 |
149 |
}; |
9e367d859 jprobes: remove J... |
150 151 |
/* For backward compatibility with old code using JPROBE_ENTRY() */ #define JPROBE_ENTRY(handler) (handler) |
b94cce926 [PATCH] kprobes: ... |
152 153 154 155 156 157 158 159 160 161 162 163 164 |
/* * 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 kprobes: kretprob... |
165 |
kretprobe_handler_t entry_handler; |
b94cce926 [PATCH] kprobes: ... |
166 167 |
int maxactive; int nmissed; |
f47cd9b55 kprobes: kretprob... |
168 |
size_t data_size; |
b94cce926 [PATCH] kprobes: ... |
169 |
struct hlist_head free_instances; |
ec484608c locking, kprobes:... |
170 |
raw_spinlock_t lock; |
b94cce926 [PATCH] kprobes: ... |
171 172 173 |
}; struct kretprobe_instance { |
b94cce926 [PATCH] kprobes: ... |
174 175 |
struct hlist_node hlist; struct kretprobe *rp; |
802eae7c8 [PATCH] Return pr... |
176 177 |
kprobe_opcode_t *ret_addr; struct task_struct *task; |
f47cd9b55 kprobes: kretprob... |
178 |
char data[0]; |
b94cce926 [PATCH] kprobes: ... |
179 |
}; |
f438d914b kprobes: support ... |
180 181 182 183 |
struct kretprobe_blackpoint { const char *name; void *addr; }; |
3d8d996e0 kprobes: prevent ... |
184 185 186 187 188 189 |
struct kprobe_blackpoint { const char *name; unsigned long start_addr; unsigned long range; }; |
dc19835df kprobes: fix modu... |
190 191 192 |
#ifdef CONFIG_KPROBES DECLARE_PER_CPU(struct kprobe *, current_kprobe); DECLARE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); |
b18018126 x86, mm, kprobes:... |
193 194 195 196 197 198 199 |
/* * For #ifdef avoidance: */ static inline int kprobes_built_in(void) { return 1; } |
dc19835df kprobes: fix modu... |
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
#ifdef CONFIG_KRETPROBES extern void arch_prepare_kretprobe(struct kretprobe_instance *ri, struct pt_regs *regs); extern int arch_trampoline_kprobe(struct kprobe *p); #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 kprobes: support ... |
214 |
extern struct kretprobe_blackpoint kretprobe_blacklist[]; |
0f95b7fc8 Kprobes: print de... |
215 216 217 218 219 220 221 222 223 224 |
static inline void kretprobe_assert(struct kretprobe_instance *ri, unsigned long orig_ret_address, unsigned long trampoline_address) { if (!orig_ret_address || (orig_ret_address == trampoline_address)) { printk("kretprobe BUG!: Processing kretprobe %p @ %p ", ri->rp, ri->rp->kp.addr); BUG(); } } |
8c1c93564 x86: kprobes: add... |
225 226 227 228 229 230 231 232 |
#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 Linux-2.6.12-rc2 |
233 |
extern int arch_prepare_kprobe(struct kprobe *p); |
7e1048b11 [PATCH] Move kpro... |
234 235 |
extern void arch_arm_kprobe(struct kprobe *p); extern void arch_disarm_kprobe(struct kprobe *p); |
6772926be [PATCH] kprobes: ... |
236 |
extern int arch_init_kprobes(void); |
1da177e4c Linux-2.6.12-rc2 |
237 |
extern void show_registers(struct pt_regs *regs); |
9ec4b1f35 [PATCH] kprobes: ... |
238 |
extern kprobe_opcode_t *get_insn_slot(void); |
b4c6c34a5 [PATCH] kprobes: ... |
239 |
extern void free_insn_slot(kprobe_opcode_t *slot, int dirty); |
bf8d5c52c [PATCH] kprobes: ... |
240 |
extern void kprobes_inc_nmissed_count(struct kprobe *p); |
1da177e4c Linux-2.6.12-rc2 |
241 |
|
afd66255b kprobes: Introduc... |
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
#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); extern int arch_prepare_optimized_kprobe(struct optimized_kprobe *op); extern void arch_remove_optimized_kprobe(struct optimized_kprobe *op); |
cd7ebe229 kprobes: Use text... |
257 |
extern void arch_optimize_kprobes(struct list_head *oplist); |
f984ba4eb kprobes: Use text... |
258 259 |
extern void arch_unoptimize_kprobes(struct list_head *oplist, struct list_head *done_list); |
afd66255b kprobes: Introduc... |
260 261 262 263 264 265 266 |
extern void arch_unoptimize_kprobe(struct optimized_kprobe *op); extern kprobe_opcode_t *get_optinsn_slot(void); extern void free_optinsn_slot(kprobe_opcode_t *slot, int dirty); 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 kprobes: Jump opt... |
267 268 269 270 271 272 273 |
#ifdef CONFIG_SYSCTL extern int sysctl_kprobes_optimization; extern int proc_kprobes_optimization_handler(struct ctl_table *table, int write, void __user *buffer, size_t *length, loff_t *ppos); #endif |
afd66255b kprobes: Introduc... |
274 |
#endif /* CONFIG_OPTPROBES */ |
d217d5450 [PATCH] Kprobes: ... |
275 |
/* Get the kprobe at this addr (if any) - called with preemption disabled */ |
1da177e4c Linux-2.6.12-rc2 |
276 |
struct kprobe *get_kprobe(void *addr); |
ef53d9c5e kprobes: improve ... |
277 278 279 |
void kretprobe_hash_lock(struct task_struct *tsk, struct hlist_head **head, unsigned long *flags); void kretprobe_hash_unlock(struct task_struct *tsk, unsigned long *flags); |
b94cce926 [PATCH] kprobes: ... |
280 |
struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk); |
1da177e4c Linux-2.6.12-rc2 |
281 |
|
e65845235 [PATCH] Kprobes: ... |
282 283 284 |
/* kprobe_running() will just return the current_kprobe on this CPU */ static inline struct kprobe *kprobe_running(void) { |
b76834bc1 kprobes: Use this... |
285 |
return (__this_cpu_read(current_kprobe)); |
e65845235 [PATCH] Kprobes: ... |
286 287 288 289 |
} static inline void reset_current_kprobe(void) { |
b76834bc1 kprobes: Use this... |
290 |
__this_cpu_write(current_kprobe, NULL); |
e65845235 [PATCH] Kprobes: ... |
291 292 293 294 295 296 |
} static inline struct kprobe_ctlblk *get_kprobe_ctlblk(void) { return (&__get_cpu_var(kprobe_ctlblk)); } |
1da177e4c Linux-2.6.12-rc2 |
297 298 |
int register_kprobe(struct kprobe *p); void unregister_kprobe(struct kprobe *p); |
9861668f7 kprobes: add (un)... |
299 300 |
int register_kprobes(struct kprobe **kps, int num); void unregister_kprobes(struct kprobe **kps, int num); |
1da177e4c Linux-2.6.12-rc2 |
301 302 303 304 |
int setjmp_pre_handler(struct kprobe *, struct pt_regs *); int longjmp_break_handler(struct kprobe *, struct pt_regs *); int register_jprobe(struct jprobe *p); void unregister_jprobe(struct jprobe *p); |
26b31c190 kprobes: add (un)... |
305 306 |
int register_jprobes(struct jprobe **jps, int num); void unregister_jprobes(struct jprobe **jps, int num); |
1da177e4c Linux-2.6.12-rc2 |
307 |
void jprobe_return(void); |
3d7e33825 jprobes: make jpr... |
308 |
unsigned long arch_deref_entry_point(void *); |
1da177e4c Linux-2.6.12-rc2 |
309 |
|
b94cce926 [PATCH] kprobes: ... |
310 311 |
int register_kretprobe(struct kretprobe *rp); void unregister_kretprobe(struct kretprobe *rp); |
4a296e07c kprobes: add (un)... |
312 313 |
int register_kretprobes(struct kretprobe **rps, int num); void unregister_kretprobes(struct kretprobe **rps, int num); |
b94cce926 [PATCH] kprobes: ... |
314 |
|
b94cce926 [PATCH] kprobes: ... |
315 |
void kprobe_flush_task(struct task_struct *tk); |
99219a3fb [PATCH] kretprobe... |
316 |
void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head); |
8c1c93564 x86: kprobes: add... |
317 |
|
de5bd88d5 kprobes: support ... |
318 319 |
int disable_kprobe(struct kprobe *kp); int enable_kprobe(struct kprobe *kp); |
24851d244 tracing/kprobes: ... |
320 |
void dump_kprobe(struct kprobe *kp); |
b18018126 x86, mm, kprobes:... |
321 |
#else /* !CONFIG_KPROBES: */ |
00d7c05ab [PATCH] kprobes: ... |
322 |
|
b18018126 x86, mm, kprobes:... |
323 324 325 326 327 328 329 330 |
static inline int kprobes_built_in(void) { return 0; } static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr) { return 0; } |
785656a41 kprobes: enable c... |
331 332 333 334 |
static inline struct kprobe *get_kprobe(void *addr) { return NULL; } |
e65845235 [PATCH] Kprobes: ... |
335 |
static inline struct kprobe *kprobe_running(void) |
1da177e4c Linux-2.6.12-rc2 |
336 |
{ |
e65845235 [PATCH] Kprobes: ... |
337 |
return NULL; |
1da177e4c Linux-2.6.12-rc2 |
338 339 340 341 342 |
} static inline int register_kprobe(struct kprobe *p) { return -ENOSYS; } |
9861668f7 kprobes: add (un)... |
343 344 345 346 |
static inline int register_kprobes(struct kprobe **kps, int num) { return -ENOSYS; } |
1da177e4c Linux-2.6.12-rc2 |
347 348 349 |
static inline void unregister_kprobe(struct kprobe *p) { } |
9861668f7 kprobes: add (un)... |
350 351 352 |
static inline void unregister_kprobes(struct kprobe **kps, int num) { } |
1da177e4c Linux-2.6.12-rc2 |
353 354 355 356 |
static inline int register_jprobe(struct jprobe *p) { return -ENOSYS; } |
26b31c190 kprobes: add (un)... |
357 358 359 360 |
static inline int register_jprobes(struct jprobe **jps, int num) { return -ENOSYS; } |
1da177e4c Linux-2.6.12-rc2 |
361 362 363 |
static inline void unregister_jprobe(struct jprobe *p) { } |
26b31c190 kprobes: add (un)... |
364 365 366 |
static inline void unregister_jprobes(struct jprobe **jps, int num) { } |
1da177e4c Linux-2.6.12-rc2 |
367 368 369 |
static inline void jprobe_return(void) { } |
b94cce926 [PATCH] kprobes: ... |
370 371 372 373 |
static inline int register_kretprobe(struct kretprobe *rp) { return -ENOSYS; } |
4a296e07c kprobes: add (un)... |
374 375 376 377 |
static inline int register_kretprobes(struct kretprobe **rps, int num) { return -ENOSYS; } |
b94cce926 [PATCH] kprobes: ... |
378 379 380 |
static inline void unregister_kretprobe(struct kretprobe *rp) { } |
4a296e07c kprobes: add (un)... |
381 382 383 |
static inline void unregister_kretprobes(struct kretprobe **rps, int num) { } |
b94cce926 [PATCH] kprobes: ... |
384 385 386 |
static inline void kprobe_flush_task(struct task_struct *tk) { } |
de5bd88d5 kprobes: support ... |
387 388 389 390 391 392 393 394 |
static inline int disable_kprobe(struct kprobe *kp) { return -ENOSYS; } static inline int enable_kprobe(struct kprobe *kp) { return -ENOSYS; } |
b18018126 x86, mm, kprobes:... |
395 |
#endif /* CONFIG_KPROBES */ |
8f9b15286 kprobes: support ... |
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
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); } static inline int disable_jprobe(struct jprobe *jp) { return disable_kprobe(&jp->kp); } static inline int enable_jprobe(struct jprobe *jp) { return enable_kprobe(&jp->kp); } |
b18018126 x86, mm, kprobes:... |
412 |
#endif /* _LINUX_KPROBES_H */ |