aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kprobes.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kprobes.h')
-rw-r--r--include/linux/kprobes.h90
1 files changed, 88 insertions, 2 deletions
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 99ddba5a4e00..fba39f87efec 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -25,21 +25,31 @@
25 * Rusty Russell). 25 * Rusty Russell).
26 * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes 26 * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
27 * interface to access function arguments. 27 * interface to access function arguments.
28 * 2005-May Hien Nguyen <hien@us.ibm.com> and Jim Keniston
29 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
30 * <prasanna@in.ibm.com> added function-return probes.
28 */ 31 */
29#include <linux/config.h> 32#include <linux/config.h>
30#include <linux/list.h> 33#include <linux/list.h>
31#include <linux/notifier.h> 34#include <linux/notifier.h>
32#include <linux/smp.h> 35#include <linux/smp.h>
36#include <linux/spinlock.h>
37
33#include <asm/kprobes.h> 38#include <asm/kprobes.h>
34 39
35struct kprobe; 40struct kprobe;
36struct pt_regs; 41struct pt_regs;
42struct kretprobe;
43struct kretprobe_instance;
37typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *); 44typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
38typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *); 45typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
39typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *, 46typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
40 unsigned long flags); 47 unsigned long flags);
41typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *, 48typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
42 int trapnr); 49 int trapnr);
50typedef int (*kretprobe_handler_t) (struct kretprobe_instance *,
51 struct pt_regs *);
52
43struct kprobe { 53struct kprobe {
44 struct hlist_node hlist; 54 struct hlist_node hlist;
45 55
@@ -85,6 +95,62 @@ struct jprobe {
85 kprobe_opcode_t *entry; /* probe handling code to jump to */ 95 kprobe_opcode_t *entry; /* probe handling code to jump to */
86}; 96};
87 97
98#ifdef ARCH_SUPPORTS_KRETPROBES
99extern int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs);
100extern void trampoline_post_handler(struct kprobe *p, struct pt_regs *regs,
101 unsigned long flags);
102extern struct task_struct *arch_get_kprobe_task(void *ptr);
103extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs);
104extern void arch_kprobe_flush_task(struct task_struct *tk, spinlock_t *kp_lock);
105#else /* ARCH_SUPPORTS_KRETPROBES */
106static inline void kretprobe_trampoline(void)
107{
108}
109static inline int trampoline_probe_handler(struct kprobe *p,
110 struct pt_regs *regs)
111{
112 return 0;
113}
114static inline void trampoline_post_handler(struct kprobe *p,
115 struct pt_regs *regs, unsigned long flags)
116{
117}
118static inline void arch_prepare_kretprobe(struct kretprobe *rp,
119 struct pt_regs *regs)
120{
121}
122static inline void arch_kprobe_flush_task(struct task_struct *tk)
123{
124}
125#define arch_get_kprobe_task(ptr) ((struct task_struct *)NULL)
126#endif /* ARCH_SUPPORTS_KRETPROBES */
127/*
128 * Function-return probe -
129 * Note:
130 * User needs to provide a handler function, and initialize maxactive.
131 * maxactive - The maximum number of instances of the probed function that
132 * can be active concurrently.
133 * nmissed - tracks the number of times the probed function's return was
134 * ignored, due to maxactive being too low.
135 *
136 */
137struct kretprobe {
138 struct kprobe kp;
139 kretprobe_handler_t handler;
140 int maxactive;
141 int nmissed;
142 struct hlist_head free_instances;
143 struct hlist_head used_instances;
144};
145
146struct kretprobe_instance {
147 struct hlist_node uflist; /* either on free list or used list */
148 struct hlist_node hlist;
149 struct kretprobe *rp;
150 void *ret_addr;
151 void *stack_addr;
152};
153
88#ifdef CONFIG_KPROBES 154#ifdef CONFIG_KPROBES
89/* Locks kprobe: irq must be disabled */ 155/* Locks kprobe: irq must be disabled */
90void lock_kprobes(void); 156void lock_kprobes(void);
@@ -104,6 +170,7 @@ extern void show_registers(struct pt_regs *regs);
104 170
105/* Get the kprobe at this addr (if any). Must have called lock_kprobes */ 171/* Get the kprobe at this addr (if any). Must have called lock_kprobes */
106struct kprobe *get_kprobe(void *addr); 172struct kprobe *get_kprobe(void *addr);
173struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk);
107 174
108int register_kprobe(struct kprobe *p); 175int register_kprobe(struct kprobe *p);
109void unregister_kprobe(struct kprobe *p); 176void unregister_kprobe(struct kprobe *p);
@@ -113,7 +180,16 @@ int register_jprobe(struct jprobe *p);
113void unregister_jprobe(struct jprobe *p); 180void unregister_jprobe(struct jprobe *p);
114void jprobe_return(void); 181void jprobe_return(void);
115 182
116#else 183int register_kretprobe(struct kretprobe *rp);
184void unregister_kretprobe(struct kretprobe *rp);
185
186struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp);
187struct kretprobe_instance *get_rp_inst(void *sara);
188struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk);
189void add_rp_inst(struct kretprobe_instance *ri);
190void kprobe_flush_task(struct task_struct *tk);
191void recycle_rp_inst(struct kretprobe_instance *ri);
192#else /* CONFIG_KPROBES */
117static inline int kprobe_running(void) 193static inline int kprobe_running(void)
118{ 194{
119 return 0; 195 return 0;
@@ -135,5 +211,15 @@ static inline void unregister_jprobe(struct jprobe *p)
135static inline void jprobe_return(void) 211static inline void jprobe_return(void)
136{ 212{
137} 213}
138#endif 214static inline int register_kretprobe(struct kretprobe *rp)
215{
216 return -ENOSYS;
217}
218static inline void unregister_kretprobe(struct kretprobe *rp)
219{
220}
221static inline void kprobe_flush_task(struct task_struct *tk)
222{
223}
224#endif /* CONFIG_KPROBES */
139#endif /* _LINUX_KPROBES_H */ 225#endif /* _LINUX_KPROBES_H */