blob: 90f778c04b3f1b847ea6c8653ae2f0c9503a8e39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Kernel Probes (KProbes)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) IBM Corporation, 2002, 2004
19 *
20 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
21 * Probes initial implementation ( includes contributions from
22 * Rusty Russell).
23 * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
24 * interface to access function arguments.
Hien Nguyenb94cce92005-06-23 00:09:19 -070025 * 2005-May Hien Nguyen <hien@us.ibm.com>, Jim Keniston
26 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
27 * <prasanna@in.ibm.com> added function-return probes.
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 */
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/kprobes.h>
31#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/preempt.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070033#include <linux/kdebug.h>
Rusty Lynch7e1048b2005-06-23 00:09:25 -070034#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/desc.h>
Prasanna S Panchamukhib4026512006-03-26 01:38:22 -080036#include <asm/uaccess.h>
Andi Kleen19d36cc2007-07-22 11:12:31 +020037#include <asm/alternative.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039void jprobe_return_end(void);
40
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -080041DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
42DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
43
Masami Hiramatsuf438d912007-10-16 01:27:49 -070044struct kretprobe_blackpoint kretprobe_blacklist[] = {
45 {"__switch_to", }, /* This function switches only current task, but
46 doesn't switch kernel stack.*/
47 {NULL, NULL} /* Terminator */
48};
49const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
50
Masami Hiramatsu311ac882006-03-26 01:38:17 -080051/* insert a jmp code */
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -070052static __always_inline void set_jmp_op(void *from, void *to)
Masami Hiramatsu311ac882006-03-26 01:38:17 -080053{
54 struct __arch_jmp_op {
55 char op;
56 long raddr;
57 } __attribute__((packed)) *jop;
58 jop = (struct __arch_jmp_op *)from;
59 jop->raddr = (long)(to) - ((long)(from) + 5);
60 jop->op = RELATIVEJUMP_INSTRUCTION;
61}
62
63/*
64 * returns non-zero if opcodes can be boosted.
65 */
Masami Hiramatsu585deac2006-06-26 00:25:19 -070066static __always_inline int can_boost(kprobe_opcode_t *opcodes)
Masami Hiramatsu311ac882006-03-26 01:38:17 -080067{
Masami Hiramatsu585deac2006-06-26 00:25:19 -070068#define W(row,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,ba,bb,bc,bd,be,bf) \
69 (((b0##UL << 0x0)|(b1##UL << 0x1)|(b2##UL << 0x2)|(b3##UL << 0x3) | \
70 (b4##UL << 0x4)|(b5##UL << 0x5)|(b6##UL << 0x6)|(b7##UL << 0x7) | \
71 (b8##UL << 0x8)|(b9##UL << 0x9)|(ba##UL << 0xa)|(bb##UL << 0xb) | \
72 (bc##UL << 0xc)|(bd##UL << 0xd)|(be##UL << 0xe)|(bf##UL << 0xf)) \
73 << (row % 32))
74 /*
75 * Undefined/reserved opcodes, conditional jump, Opcode Extension
76 * Groups, and some special opcodes can not be boost.
77 */
78 static const unsigned long twobyte_is_boostable[256 / 32] = {
79 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
80 /* ------------------------------- */
81 W(0x00, 0,0,1,1,0,0,1,0,1,1,0,0,0,0,0,0)| /* 00 */
82 W(0x10, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), /* 10 */
83 W(0x20, 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0)| /* 20 */
84 W(0x30, 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0), /* 30 */
85 W(0x40, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)| /* 40 */
86 W(0x50, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), /* 50 */
87 W(0x60, 1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1)| /* 60 */
88 W(0x70, 0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1), /* 70 */
89 W(0x80, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)| /* 80 */
90 W(0x90, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1), /* 90 */
91 W(0xa0, 1,1,0,1,1,1,0,0,1,1,0,1,1,1,0,1)| /* a0 */
92 W(0xb0, 1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1), /* b0 */
93 W(0xc0, 1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1)| /* c0 */
94 W(0xd0, 0,1,1,1,0,1,0,0,1,1,0,1,1,1,0,1), /* d0 */
95 W(0xe0, 0,1,1,0,0,1,0,0,1,1,0,1,1,1,0,1)| /* e0 */
96 W(0xf0, 0,1,1,1,0,1,0,0,1,1,1,0,1,1,1,0) /* f0 */
97 /* ------------------------------- */
98 /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */
99 };
100#undef W
101 kprobe_opcode_t opcode;
102 kprobe_opcode_t *orig_opcodes = opcodes;
103retry:
104 if (opcodes - orig_opcodes > MAX_INSN_SIZE - 1)
105 return 0;
106 opcode = *(opcodes++);
107
108 /* 2nd-byte opcode */
109 if (opcode == 0x0f) {
110 if (opcodes - orig_opcodes > MAX_INSN_SIZE - 1)
111 return 0;
112 return test_bit(*opcodes, twobyte_is_boostable);
113 }
114
115 switch (opcode & 0xf0) {
116 case 0x60:
117 if (0x63 < opcode && opcode < 0x67)
118 goto retry; /* prefixes */
119 /* can't boost Address-size override and bound */
120 return (opcode != 0x62 && opcode != 0x67);
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800121 case 0x70:
122 return 0; /* can't boost conditional jump */
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800123 case 0xc0:
Masami Hiramatsu585deac2006-06-26 00:25:19 -0700124 /* can't boost software-interruptions */
125 return (0xc1 < opcode && opcode < 0xcc) || opcode == 0xcf;
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800126 case 0xd0:
127 /* can boost AA* and XLAT */
128 return (opcode == 0xd4 || opcode == 0xd5 || opcode == 0xd7);
129 case 0xe0:
Masami Hiramatsu585deac2006-06-26 00:25:19 -0700130 /* can boost in/out and absolute jmps */
131 return ((opcode & 0x04) || opcode == 0xea);
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800132 case 0xf0:
Masami Hiramatsu585deac2006-06-26 00:25:19 -0700133 if ((opcode & 0x0c) == 0 && opcode != 0xf1)
134 goto retry; /* lock/rep(ne) prefix */
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800135 /* clear and set flags can be boost */
136 return (opcode == 0xf5 || (0xf7 < opcode && opcode < 0xfe));
137 default:
Masami Hiramatsu585deac2006-06-26 00:25:19 -0700138 if (opcode == 0x26 || opcode == 0x36 || opcode == 0x3e)
139 goto retry; /* prefixes */
140 /* can't boost CS override and call */
141 return (opcode != 0x2e && opcode != 0x9a);
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800142 }
143}
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*
146 * returns non-zero if opcode modifies the interrupt flag.
147 */
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -0700148static int __kprobes is_IF_modifier(kprobe_opcode_t opcode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 switch (opcode) {
151 case 0xfa: /* cli */
152 case 0xfb: /* sti */
153 case 0xcf: /* iret/iretd */
154 case 0x9d: /* popf/popfd */
155 return 1;
156 }
157 return 0;
158}
159
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700160int __kprobes arch_prepare_kprobe(struct kprobe *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
Prasanna S Panchamukhi124d90b2006-02-24 13:04:08 -0800162 /* insn: must be on special executable page on i386. */
163 p->ainsn.insn = get_insn_slot();
164 if (!p->ainsn.insn)
165 return -ENOMEM;
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
Rusty Lynch7e1048b2005-06-23 00:09:25 -0700168 p->opcode = *p->addr;
Masami Hiramatsu585deac2006-06-26 00:25:19 -0700169 if (can_boost(p->addr)) {
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800170 p->ainsn.boostable = 0;
171 } else {
172 p->ainsn.boostable = -1;
173 }
Anil S Keshavamurthy49a2a1b2006-01-09 20:52:43 -0800174 return 0;
Rusty Lynch7e1048b2005-06-23 00:09:25 -0700175}
176
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700177void __kprobes arch_arm_kprobe(struct kprobe *p)
Rusty Lynch7e1048b2005-06-23 00:09:25 -0700178{
Andi Kleen19d36cc2007-07-22 11:12:31 +0200179 text_poke(p->addr, ((unsigned char []){BREAKPOINT_INSTRUCTION}), 1);
Rusty Lynch7e1048b2005-06-23 00:09:25 -0700180}
181
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700182void __kprobes arch_disarm_kprobe(struct kprobe *p)
Rusty Lynch7e1048b2005-06-23 00:09:25 -0700183{
Andi Kleen19d36cc2007-07-22 11:12:31 +0200184 text_poke(p->addr, &p->opcode, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
Prasanna S Panchamukhi124d90b2006-02-24 13:04:08 -0800187void __kprobes arch_remove_kprobe(struct kprobe *p)
188{
Ingo Molnar7a7d1cf2006-03-23 03:00:35 -0800189 mutex_lock(&kprobe_mutex);
Masami Hiramatsub4c6c342006-12-06 20:38:11 -0800190 free_insn_slot(p->ainsn.insn, (p->ainsn.boostable == 1));
Ingo Molnar7a7d1cf2006-03-23 03:00:35 -0800191 mutex_unlock(&kprobe_mutex);
Prasanna S Panchamukhi124d90b2006-02-24 13:04:08 -0800192}
193
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -0700194static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700195{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800196 kcb->prev_kprobe.kp = kprobe_running();
197 kcb->prev_kprobe.status = kcb->kprobe_status;
198 kcb->prev_kprobe.old_eflags = kcb->kprobe_old_eflags;
199 kcb->prev_kprobe.saved_eflags = kcb->kprobe_saved_eflags;
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700200}
201
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -0700202static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700203{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800204 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
205 kcb->kprobe_status = kcb->prev_kprobe.status;
206 kcb->kprobe_old_eflags = kcb->prev_kprobe.old_eflags;
207 kcb->kprobe_saved_eflags = kcb->prev_kprobe.saved_eflags;
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700208}
209
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -0700210static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800211 struct kprobe_ctlblk *kcb)
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700212{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800213 __get_cpu_var(current_kprobe) = p;
214 kcb->kprobe_saved_eflags = kcb->kprobe_old_eflags
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700215 = (regs->eflags & (TF_MASK | IF_MASK));
216 if (is_IF_modifier(p->opcode))
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800217 kcb->kprobe_saved_eflags &= ~IF_MASK;
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700218}
219
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -0700220static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 regs->eflags |= TF_MASK;
223 regs->eflags &= ~IF_MASK;
224 /*single step inline if the instruction is an int3*/
225 if (p->opcode == BREAKPOINT_INSTRUCTION)
226 regs->eip = (unsigned long)p->addr;
227 else
Prasanna S Panchamukhi124d90b2006-02-24 13:04:08 -0800228 regs->eip = (unsigned long)p->ainsn.insn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800231/* Called with kretprobe_lock held */
Christoph Hellwig4c4308c2007-05-08 00:34:14 -0700232void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700233 struct pt_regs *regs)
Hien Nguyenb94cce92005-06-23 00:09:19 -0700234{
235 unsigned long *sara = (unsigned long *)&regs->esp;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700236
Christoph Hellwig4c4308c2007-05-08 00:34:14 -0700237 ri->ret_addr = (kprobe_opcode_t *) *sara;
bibo,mao62c27be2006-10-02 02:17:33 -0700238
Christoph Hellwig4c4308c2007-05-08 00:34:14 -0700239 /* Replace the return addr with trampoline addr */
240 *sara = (unsigned long) &kretprobe_trampoline;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700241}
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*
244 * Interrupts are disabled on entry as trap3 is an interrupt gate and they
245 * remain disabled thorough out this function.
246 */
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700247static int __kprobes kprobe_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 struct kprobe *p;
250 int ret = 0;
bibo,mao2326c772006-03-26 01:38:21 -0800251 kprobe_opcode_t *addr;
Ananth N Mavinakayanahallid217d542005-11-07 01:00:14 -0800252 struct kprobe_ctlblk *kcb;
253
bibo,mao2326c772006-03-26 01:38:21 -0800254 addr = (kprobe_opcode_t *)(regs->eip - sizeof(kprobe_opcode_t));
255
Ananth N Mavinakayanahallid217d542005-11-07 01:00:14 -0800256 /*
257 * We don't want to be preempted for the entire
258 * duration of kprobe processing
259 */
260 preempt_disable();
261 kcb = get_kprobe_ctlblk();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /* Check we're not actually recursing */
264 if (kprobe_running()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 p = get_kprobe(addr);
266 if (p) {
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800267 if (kcb->kprobe_status == KPROBE_HIT_SS &&
Keshavamurthy Anil Sdeac66a2005-09-06 15:19:35 -0700268 *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 regs->eflags &= ~TF_MASK;
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800270 regs->eflags |= kcb->kprobe_saved_eflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 goto no_kprobe;
272 }
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700273 /* We have reentered the kprobe_handler(), since
274 * another probe was hit while within the handler.
275 * We here save the original kprobes variables and
276 * just single step on the instruction of the new probe
277 * without calling any user handlers.
278 */
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800279 save_previous_kprobe(kcb);
280 set_current_kprobe(p, regs, kcb);
Keshavamurthy Anil Sbf8d5c52005-12-12 00:37:34 -0800281 kprobes_inc_nmissed_count(p);
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700282 prepare_singlestep(p, regs);
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800283 kcb->kprobe_status = KPROBE_REENTER;
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700284 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 } else {
Keshavamurthy Anil Seb3a7292006-01-11 12:17:42 -0800286 if (*addr != BREAKPOINT_INSTRUCTION) {
287 /* The breakpoint instruction was removed by
288 * another cpu right after we hit, no further
289 * handling of this interrupt is appropriate
290 */
291 regs->eip -= sizeof(kprobe_opcode_t);
292 ret = 1;
293 goto no_kprobe;
294 }
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800295 p = __get_cpu_var(current_kprobe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (p->break_handler && p->break_handler(p, regs)) {
297 goto ss_probe;
298 }
299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 goto no_kprobe;
301 }
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 p = get_kprobe(addr);
304 if (!p) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (*addr != BREAKPOINT_INSTRUCTION) {
306 /*
307 * The breakpoint instruction was removed right
308 * after we hit it. Another cpu has removed
309 * either a probepoint or a debugger breakpoint
310 * at this address. In either case, no further
311 * handling of this interrupt is appropriate.
Jim Kenistonbce06492005-09-06 15:19:34 -0700312 * Back up over the (now missing) int3 and run
313 * the original instruction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 */
Jim Kenistonbce06492005-09-06 15:19:34 -0700315 regs->eip -= sizeof(kprobe_opcode_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 ret = 1;
317 }
318 /* Not one of ours: let kernel handle it */
319 goto no_kprobe;
320 }
321
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800322 set_current_kprobe(p, regs, kcb);
323 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 if (p->pre_handler && p->pre_handler(p, regs))
326 /* handler has already set things up, so skip ss setup */
327 return 1;
328
mao, bibo36721652006-06-26 00:25:22 -0700329ss_probe:
Masami Hiramatsub4c6c342006-12-06 20:38:11 -0800330#if !defined(CONFIG_PREEMPT) || defined(CONFIG_PM)
Masami Hiramatsuc39df472006-07-30 03:03:21 -0700331 if (p->ainsn.boostable == 1 && !p->post_handler){
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800332 /* Boost up -- we can execute copied instructions directly */
333 reset_current_kprobe();
334 regs->eip = (unsigned long)p->ainsn.insn;
335 preempt_enable_no_resched();
336 return 1;
337 }
Masami Hiramatsuc39df472006-07-30 03:03:21 -0700338#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 prepare_singlestep(p, regs);
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800340 kcb->kprobe_status = KPROBE_HIT_SS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return 1;
342
343no_kprobe:
Ananth N Mavinakayanahallid217d542005-11-07 01:00:14 -0800344 preempt_enable_no_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 return ret;
346}
347
348/*
Hien Nguyenb94cce92005-06-23 00:09:19 -0700349 * For function-return probes, init_kprobes() establishes a probepoint
350 * here. When a retprobed function returns, this probe is hit and
351 * trampoline_probe_handler() runs, calling the kretprobe's handler.
352 */
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800353 void __kprobes kretprobe_trampoline_holder(void)
Hien Nguyenb94cce92005-06-23 00:09:19 -0700354 {
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800355 asm volatile ( ".global kretprobe_trampoline\n"
bibo,mao62c27be2006-10-02 02:17:33 -0700356 "kretprobe_trampoline: \n"
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800357 " pushf\n"
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800358 /* skip cs, eip, orig_eax */
359 " subl $12, %esp\n"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100360 " pushl %fs\n"
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800361 " pushl %ds\n"
362 " pushl %es\n"
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800363 " pushl %eax\n"
364 " pushl %ebp\n"
365 " pushl %edi\n"
366 " pushl %esi\n"
367 " pushl %edx\n"
368 " pushl %ecx\n"
369 " pushl %ebx\n"
370 " movl %esp, %eax\n"
371 " call trampoline_handler\n"
372 /* move eflags to cs */
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800373 " movl 52(%esp), %edx\n"
374 " movl %edx, 48(%esp)\n"
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800375 /* save true return address on eflags */
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800376 " movl %eax, 52(%esp)\n"
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800377 " popl %ebx\n"
378 " popl %ecx\n"
379 " popl %edx\n"
380 " popl %esi\n"
381 " popl %edi\n"
382 " popl %ebp\n"
383 " popl %eax\n"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100384 /* skip eip, orig_eax, es, ds, fs */
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800385 " addl $20, %esp\n"
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800386 " popf\n"
387 " ret\n");
388}
Hien Nguyenb94cce92005-06-23 00:09:19 -0700389
390/*
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800391 * Called from kretprobe_trampoline
Hien Nguyenb94cce92005-06-23 00:09:19 -0700392 */
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800393fastcall void *__kprobes trampoline_handler(struct pt_regs *regs)
Hien Nguyenb94cce92005-06-23 00:09:19 -0700394{
bibo,mao62c27be2006-10-02 02:17:33 -0700395 struct kretprobe_instance *ri = NULL;
bibo,mao99219a32006-10-02 02:17:35 -0700396 struct hlist_head *head, empty_rp;
bibo,mao62c27be2006-10-02 02:17:33 -0700397 struct hlist_node *node, *tmp;
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800398 unsigned long flags, orig_ret_address = 0;
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700399 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700400
bibo,mao99219a32006-10-02 02:17:35 -0700401 INIT_HLIST_HEAD(&empty_rp);
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800402 spin_lock_irqsave(&kretprobe_lock, flags);
bibo,mao62c27be2006-10-02 02:17:33 -0700403 head = kretprobe_inst_table_head(current);
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800404 /* fixup registers */
Zachary Amsdenac3b6fa2007-02-13 13:26:21 +0100405 regs->xcs = __KERNEL_CS | get_kernel_rpl();
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800406 regs->eip = trampoline_address;
407 regs->orig_eax = 0xffffffff;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700408
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700409 /*
410 * It is possible to have multiple instances associated with a given
411 * task either because an multiple functions in the call path
412 * have a return probe installed on them, and/or more then one return
413 * return probe was registered for a target function.
414 *
415 * We can handle this because:
416 * - instances are always inserted at the head of the list
417 * - when multiple return probes are registered for the same
bibo,mao62c27be2006-10-02 02:17:33 -0700418 * function, the first instance's ret_addr will point to the
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700419 * real return address, and all the rest will point to
420 * kretprobe_trampoline
421 */
422 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
bibo,mao62c27be2006-10-02 02:17:33 -0700423 if (ri->task != current)
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700424 /* another task is sharing our hash bucket */
bibo,mao62c27be2006-10-02 02:17:33 -0700425 continue;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700426
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800427 if (ri->rp && ri->rp->handler){
428 __get_cpu_var(current_kprobe) = &ri->rp->kp;
Masami Hiramatsu8bdc0522006-11-08 17:44:49 -0800429 get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700430 ri->rp->handler(ri, regs);
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800431 __get_cpu_var(current_kprobe) = NULL;
432 }
Hien Nguyenb94cce92005-06-23 00:09:19 -0700433
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700434 orig_ret_address = (unsigned long)ri->ret_addr;
bibo,mao99219a32006-10-02 02:17:35 -0700435 recycle_rp_inst(ri, &empty_rp);
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700436
437 if (orig_ret_address != trampoline_address)
438 /*
439 * This is the real return address. Any other
440 * instances associated with this task are for
441 * other calls deeper on the call stack
442 */
443 break;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700444 }
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700445
Ananth N Mavinakayanahalli0f95b7f2007-05-08 00:28:27 -0700446 kretprobe_assert(ri, orig_ret_address, trampoline_address);
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800447 spin_unlock_irqrestore(&kretprobe_lock, flags);
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700448
bibo,mao99219a32006-10-02 02:17:35 -0700449 hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
450 hlist_del(&ri->hlist);
451 kfree(ri);
452 }
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800453 return (void*)orig_ret_address;
Hien Nguyenb94cce92005-06-23 00:09:19 -0700454}
455
456/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 * Called after single-stepping. p->addr is the address of the
458 * instruction whose first byte has been replaced by the "int 3"
459 * instruction. To avoid the SMP problems that can occur when we
460 * temporarily put back the original opcode to single-step, we
461 * single-stepped a copy of the instruction. The address of this
462 * copy is p->ainsn.insn.
463 *
464 * This function prepares to return from the post-single-step
465 * interrupt. We have to fix up the stack as follows:
466 *
467 * 0) Except in the case of absolute or indirect jump or call instructions,
468 * the new eip is relative to the copied instruction. We need to make
469 * it relative to the original instruction.
470 *
471 * 1) If the single-stepped instruction was pushfl, then the TF and IF
472 * flags are set in the just-pushed eflags, and may need to be cleared.
473 *
474 * 2) If the single-stepped instruction was a call, the return address
475 * that is atop the stack is the address following the copied instruction.
476 * We need to make it the address following the original instruction.
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800477 *
478 * This function also checks instruction size for preparing direct execution.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 */
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800480static void __kprobes resume_execution(struct kprobe *p,
481 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482{
483 unsigned long *tos = (unsigned long *)&regs->esp;
Prasanna S Panchamukhi124d90b2006-02-24 13:04:08 -0800484 unsigned long copy_eip = (unsigned long)p->ainsn.insn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 unsigned long orig_eip = (unsigned long)p->addr;
486
Masami Hiramatsub50ea742006-03-26 01:38:13 -0800487 regs->eflags &= ~TF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 switch (p->ainsn.insn[0]) {
489 case 0x9c: /* pushfl */
490 *tos &= ~(TF_MASK | IF_MASK);
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800491 *tos |= kcb->kprobe_old_eflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 break;
Masami Hiramatsubcff5cd2006-04-27 18:39:55 -0700493 case 0xc2: /* iret/ret/lret */
494 case 0xc3:
Prasanna S Panchamukhi0b9e2ca2005-05-05 16:15:40 -0700495 case 0xca:
Masami Hiramatsubcff5cd2006-04-27 18:39:55 -0700496 case 0xcb:
497 case 0xcf:
Masami Hiramatsub50ea742006-03-26 01:38:13 -0800498 case 0xea: /* jmp absolute -- eip is correct */
499 /* eip is already adjusted, no more changes required */
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800500 p->ainsn.boostable = 1;
Masami Hiramatsub50ea742006-03-26 01:38:13 -0800501 goto no_change;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 case 0xe8: /* call relative - Fix return addr */
503 *tos = orig_eip + (*tos - copy_eip);
504 break;
Masami Hiramatsubcff5cd2006-04-27 18:39:55 -0700505 case 0x9a: /* call absolute -- same as call absolute, indirect */
506 *tos = orig_eip + (*tos - copy_eip);
507 goto no_change;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 case 0xff:
509 if ((p->ainsn.insn[1] & 0x30) == 0x10) {
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800510 /*
Masami Hiramatsubcff5cd2006-04-27 18:39:55 -0700511 * call absolute, indirect
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800512 * Fix return addr; eip is correct.
513 * But this is not boostable
514 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 *tos = orig_eip + (*tos - copy_eip);
Masami Hiramatsub50ea742006-03-26 01:38:13 -0800516 goto no_change;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 } else if (((p->ainsn.insn[1] & 0x31) == 0x20) || /* jmp near, absolute indirect */
518 ((p->ainsn.insn[1] & 0x31) == 0x21)) { /* jmp far, absolute indirect */
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800519 /* eip is correct. And this is boostable */
520 p->ainsn.boostable = 1;
Masami Hiramatsub50ea742006-03-26 01:38:13 -0800521 goto no_change;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 default:
524 break;
525 }
526
Masami Hiramatsu311ac882006-03-26 01:38:17 -0800527 if (p->ainsn.boostable == 0) {
528 if ((regs->eip > copy_eip) &&
529 (regs->eip - copy_eip) + 5 < MAX_INSN_SIZE) {
530 /*
531 * These instructions can be executed directly if it
532 * jumps back to correct address.
533 */
534 set_jmp_op((void *)regs->eip,
535 (void *)orig_eip + (regs->eip - copy_eip));
536 p->ainsn.boostable = 1;
537 } else {
538 p->ainsn.boostable = -1;
539 }
540 }
541
Masami Hiramatsub50ea742006-03-26 01:38:13 -0800542 regs->eip = orig_eip + (regs->eip - copy_eip);
543
544no_change:
545 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
548/*
549 * Interrupts are disabled on entry as trap1 is an interrupt gate and they
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800550 * remain disabled thoroughout this function.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 */
Prasanna S Panchamukhi34c37e12006-04-18 22:21:59 -0700552static int __kprobes post_kprobe_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800554 struct kprobe *cur = kprobe_running();
555 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
556
557 if (!cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 return 0;
559
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800560 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
561 kcb->kprobe_status = KPROBE_HIT_SSDONE;
562 cur->post_handler(cur, regs, 0);
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800565 resume_execution(cur, regs, kcb);
566 regs->eflags |= kcb->kprobe_saved_eflags;
Peter Zijlstra58dfe882007-10-11 22:25:25 +0200567#ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
568 if (raw_irqs_disabled_flags(regs->eflags))
569 trace_hardirqs_off();
570 else
571 trace_hardirqs_on();
572#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700574 /*Restore back the original saved kprobes variables and continue. */
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800575 if (kcb->kprobe_status == KPROBE_REENTER) {
576 restore_previous_kprobe(kcb);
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700577 goto out;
578 }
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800579 reset_current_kprobe();
Prasanna S Panchamukhi417c8da2005-06-23 00:09:37 -0700580out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 preempt_enable_no_resched();
582
583 /*
584 * if somebody else is singlestepping across a probe point, eflags
585 * will have TF set, in which case, continue the remaining processing
586 * of do_debug, as if this is not a probe hit.
587 */
588 if (regs->eflags & TF_MASK)
589 return 0;
590
591 return 1;
592}
593
Christoph Hellwig74a0b572007-10-16 01:24:07 -0700594int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800596 struct kprobe *cur = kprobe_running();
597 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
598
Prasanna S Panchamukhib4026512006-03-26 01:38:22 -0800599 switch(kcb->kprobe_status) {
600 case KPROBE_HIT_SS:
601 case KPROBE_REENTER:
602 /*
603 * We are here because the instruction being single
604 * stepped caused a page fault. We reset the current
605 * kprobe and the eip points back to the probe address
606 * and allow the page fault handler to continue as a
607 * normal page fault.
608 */
609 regs->eip = (unsigned long)cur->addr;
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800610 regs->eflags |= kcb->kprobe_old_eflags;
Prasanna S Panchamukhib4026512006-03-26 01:38:22 -0800611 if (kcb->kprobe_status == KPROBE_REENTER)
612 restore_previous_kprobe(kcb);
613 else
614 reset_current_kprobe();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 preempt_enable_no_resched();
Prasanna S Panchamukhib4026512006-03-26 01:38:22 -0800616 break;
617 case KPROBE_HIT_ACTIVE:
618 case KPROBE_HIT_SSDONE:
619 /*
620 * We increment the nmissed count for accounting,
621 * we can also use npre/npostfault count for accouting
622 * these specific fault cases.
623 */
624 kprobes_inc_nmissed_count(cur);
625
626 /*
627 * We come here because instructions in the pre/post
628 * handler caused the page_fault, this could happen
629 * if handler tries to access user space by
630 * copy_from_user(), get_user() etc. Let the
631 * user-specified handler try to fix it first.
632 */
633 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
634 return 1;
635
636 /*
637 * In case the user-specified fault handler returned
638 * zero, try to fix up.
639 */
640 if (fixup_exception(regs))
641 return 1;
642
643 /*
644 * fixup_exception() could not handle it,
645 * Let do_page_fault() fix it.
646 */
647 break;
648 default:
649 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651 return 0;
652}
653
654/*
655 * Wrapper routine to for handling exceptions.
656 */
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700657int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
658 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
660 struct die_args *args = (struct die_args *)data;
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800661 int ret = NOTIFY_DONE;
662
Zachary Amsden64445412006-06-23 02:04:30 -0700663 if (args->regs && user_mode_vm(args->regs))
bibo,mao2326c772006-03-26 01:38:21 -0800664 return ret;
665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 switch (val) {
667 case DIE_INT3:
668 if (kprobe_handler(args->regs))
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800669 ret = NOTIFY_STOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 break;
671 case DIE_DEBUG:
672 if (post_kprobe_handler(args->regs))
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800673 ret = NOTIFY_STOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 break;
675 case DIE_GPF:
Ananth N Mavinakayanahallid217d542005-11-07 01:00:14 -0800676 /* kprobe_running() needs smp_processor_id() */
677 preempt_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (kprobe_running() &&
679 kprobe_fault_handler(args->regs, args->trapnr))
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800680 ret = NOTIFY_STOP;
Ananth N Mavinakayanahallid217d542005-11-07 01:00:14 -0800681 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 break;
683 default:
684 break;
685 }
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800686 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700689int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 struct jprobe *jp = container_of(p, struct jprobe, kp);
692 unsigned long addr;
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800693 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800695 kcb->jprobe_saved_regs = *regs;
696 kcb->jprobe_saved_esp = &regs->esp;
697 addr = (unsigned long)(kcb->jprobe_saved_esp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 /*
700 * TBD: As Linus pointed out, gcc assumes that the callee
701 * owns the argument space and could overwrite it, e.g.
702 * tailcall optimization. So, to be absolutely safe
703 * we also save and restore enough stack bytes to cover
704 * the argument area.
705 */
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800706 memcpy(kcb->jprobes_stack, (kprobe_opcode_t *)addr,
707 MIN_STACK_SIZE(addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 regs->eflags &= ~IF_MASK;
Peter Zijlstra58dfe882007-10-11 22:25:25 +0200709 trace_hardirqs_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 regs->eip = (unsigned long)(jp->entry);
711 return 1;
712}
713
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700714void __kprobes jprobe_return(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800716 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 asm volatile (" xchgl %%ebx,%%esp \n"
719 " int3 \n"
720 " .globl jprobe_return_end \n"
721 " jprobe_return_end: \n"
722 " nop \n"::"b"
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800723 (kcb->jprobe_saved_esp):"memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
725
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700726int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800728 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 u8 *addr = (u8 *) (regs->eip - 1);
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800730 unsigned long stack_addr = (unsigned long)(kcb->jprobe_saved_esp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 struct jprobe *jp = container_of(p, struct jprobe, kp);
732
733 if ((addr > (u8 *) jprobe_return) && (addr < (u8 *) jprobe_return_end)) {
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800734 if (&regs->esp != kcb->jprobe_saved_esp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 struct pt_regs *saved_regs =
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800736 container_of(kcb->jprobe_saved_esp,
737 struct pt_regs, esp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 printk("current esp %p does not match saved esp %p\n",
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800739 &regs->esp, kcb->jprobe_saved_esp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 printk("Saved registers for jprobe %p\n", jp);
741 show_registers(saved_regs);
742 printk("Current registers\n");
743 show_registers(regs);
744 BUG();
745 }
Ananth N Mavinakayanahalli9a0e3a82005-11-07 01:00:08 -0800746 *regs = kcb->jprobe_saved_regs;
747 memcpy((kprobe_opcode_t *) stack_addr, kcb->jprobes_stack,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 MIN_STACK_SIZE(stack_addr));
Ananth N Mavinakayanahallid217d542005-11-07 01:00:14 -0800749 preempt_enable_no_resched();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 return 1;
751 }
752 return 0;
753}
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700754
Ananth N Mavinakayanahallibf8f6e52007-05-08 00:34:16 -0700755int __kprobes arch_trampoline_kprobe(struct kprobe *p)
756{
757 return 0;
758}
759
Rusty Lynch67729262005-07-05 18:54:50 -0700760int __init arch_init_kprobes(void)
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700761{
Masami Hiramatsuc9becf52006-03-26 01:38:19 -0800762 return 0;
Rusty Lynch4bdbd372005-06-27 15:17:09 -0700763}