Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_KPROBES_H |
2 | #define _LINUX_KPROBES_H | |
3 | /* | |
4 | * Kernel Probes (KProbes) | |
5 | * include/linux/kprobes.h | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 | * | |
21 | * Copyright (C) IBM Corporation, 2002, 2004 | |
22 | * | |
23 | * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel | |
24 | * Probes initial implementation ( includes suggestions from | |
25 | * Rusty Russell). | |
26 | * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes | |
27 | * interface to access function arguments. | |
28 | */ | |
29 | #include <linux/config.h> | |
30 | #include <linux/list.h> | |
31 | #include <linux/notifier.h> | |
32 | #include <linux/smp.h> | |
33 | #include <asm/kprobes.h> | |
34 | ||
35 | struct kprobe; | |
36 | struct pt_regs; | |
37 | typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *); | |
38 | typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *); | |
39 | typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *, | |
40 | unsigned long flags); | |
41 | typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *, | |
42 | int trapnr); | |
43 | struct kprobe { | |
44 | struct hlist_node hlist; | |
45 | ||
46 | /* location of the probe point */ | |
47 | kprobe_opcode_t *addr; | |
48 | ||
49 | /* Called before addr is executed. */ | |
50 | kprobe_pre_handler_t pre_handler; | |
51 | ||
52 | /* Called after addr is executed, unless... */ | |
53 | kprobe_post_handler_t post_handler; | |
54 | ||
55 | /* ... called if executing addr causes a fault (eg. page fault). | |
56 | * Return 1 if it handled fault, otherwise kernel will see it. */ | |
57 | kprobe_fault_handler_t fault_handler; | |
58 | ||
59 | /* ... called if breakpoint trap occurs in probe handler. | |
60 | * Return 1 if it handled break, otherwise kernel will see it. */ | |
61 | kprobe_break_handler_t break_handler; | |
62 | ||
63 | /* Saved opcode (which has been replaced with breakpoint) */ | |
64 | kprobe_opcode_t opcode; | |
65 | ||
66 | /* copy of the original instruction */ | |
67 | struct arch_specific_insn ainsn; | |
68 | }; | |
69 | ||
70 | /* | |
71 | * Special probe type that uses setjmp-longjmp type tricks to resume | |
72 | * execution at a specified entry with a matching prototype corresponding | |
73 | * to the probed function - a trick to enable arguments to become | |
74 | * accessible seamlessly by probe handling logic. | |
75 | * Note: | |
76 | * Because of the way compilers allocate stack space for local variables | |
77 | * etc upfront, regardless of sub-scopes within a function, this mirroring | |
78 | * principle currently works only for probes placed on function entry points. | |
79 | */ | |
80 | struct jprobe { | |
81 | struct kprobe kp; | |
82 | kprobe_opcode_t *entry; /* probe handling code to jump to */ | |
83 | }; | |
84 | ||
85 | #ifdef CONFIG_KPROBES | |
86 | /* Locks kprobe: irq must be disabled */ | |
87 | void lock_kprobes(void); | |
88 | void unlock_kprobes(void); | |
89 | ||
90 | /* kprobe running now on this CPU? */ | |
91 | static inline int kprobe_running(void) | |
92 | { | |
93 | extern unsigned int kprobe_cpu; | |
94 | return kprobe_cpu == smp_processor_id(); | |
95 | } | |
96 | ||
97 | extern int arch_prepare_kprobe(struct kprobe *p); | |
98 | extern void arch_copy_kprobe(struct kprobe *p); | |
99 | extern void arch_remove_kprobe(struct kprobe *p); | |
100 | extern void show_registers(struct pt_regs *regs); | |
101 | ||
102 | /* Get the kprobe at this addr (if any). Must have called lock_kprobes */ | |
103 | struct kprobe *get_kprobe(void *addr); | |
104 | ||
105 | int register_kprobe(struct kprobe *p); | |
106 | void unregister_kprobe(struct kprobe *p); | |
107 | int setjmp_pre_handler(struct kprobe *, struct pt_regs *); | |
108 | int longjmp_break_handler(struct kprobe *, struct pt_regs *); | |
109 | int register_jprobe(struct jprobe *p); | |
110 | void unregister_jprobe(struct jprobe *p); | |
111 | void jprobe_return(void); | |
112 | ||
113 | #else | |
114 | static inline int kprobe_running(void) | |
115 | { | |
116 | return 0; | |
117 | } | |
118 | static inline int register_kprobe(struct kprobe *p) | |
119 | { | |
120 | return -ENOSYS; | |
121 | } | |
122 | static inline void unregister_kprobe(struct kprobe *p) | |
123 | { | |
124 | } | |
125 | static inline int register_jprobe(struct jprobe *p) | |
126 | { | |
127 | return -ENOSYS; | |
128 | } | |
129 | static inline void unregister_jprobe(struct jprobe *p) | |
130 | { | |
131 | } | |
132 | static inline void jprobe_return(void) | |
133 | { | |
134 | } | |
135 | #endif | |
136 | #endif /* _LINUX_KPROBES_H */ |