blob: e0a25b35437f70aeed3264bd5287e490bb51bcbf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Kernel Probes (KProbes)
3 * arch/ppc64/kernel/kprobes.c
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * Copyright (C) IBM Corporation, 2002, 2004
20 *
21 * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
22 * Probes initial implementation ( includes contributions from
23 * Rusty Russell).
24 * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
25 * interface to access function arguments.
26 * 2004-Nov Ananth N Mavinakayanahalli <ananth@in.ibm.com> kprobes port
27 * for PPC64
28 */
29
30#include <linux/config.h>
31#include <linux/kprobes.h>
32#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/preempt.h>
Rusty Lynch7e1048b2005-06-23 00:09:25 -070034#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/kdebug.h>
36#include <asm/sstep.h>
37
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070038static DECLARE_MUTEX(kprobe_mutex);
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -080039DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
40DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -070042int __kprobes arch_prepare_kprobe(struct kprobe *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Ananth N Mavinakayanahalli63224d1e82005-06-08 15:49:41 -070044 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 kprobe_opcode_t insn = *p->addr;
46
Ananth N Mavinakayanahalli63224d1e82005-06-08 15:49:41 -070047 if ((unsigned long)p->addr & 0x03) {
48 printk("Attempt to register kprobe at an unaligned address\n");
49 ret = -EINVAL;
50 } else if (IS_MTMSRD(insn) || IS_RFID(insn)) {
51 printk("Cannot register a kprobe on rfid or mtmsrd\n");
52 ret = -EINVAL;
53 }
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070054
55 /* insn must be on a special executable page on ppc64 */
56 if (!ret) {
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070057 down(&kprobe_mutex);
Ananth N Mavinakayanahalli2d8ab6a2005-10-01 13:14:17 -040058 p->ainsn.insn = get_insn_slot();
59 up(&kprobe_mutex);
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070060 if (!p->ainsn.insn)
61 ret = -ENOMEM;
62 }
Ananth N Mavinakayanahalli63224d1e82005-06-08 15:49:41 -070063 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -070066void __kprobes arch_copy_kprobe(struct kprobe *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
Rusty Lynch7e1048b2005-06-23 00:09:25 -070069 p->opcode = *p->addr;
70}
71
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -070072void __kprobes arch_arm_kprobe(struct kprobe *p)
Rusty Lynch7e1048b2005-06-23 00:09:25 -070073{
74 *p->addr = BREAKPOINT_INSTRUCTION;
75 flush_icache_range((unsigned long) p->addr,
76 (unsigned long) p->addr + sizeof(kprobe_opcode_t));
77}
78
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -070079void __kprobes arch_disarm_kprobe(struct kprobe *p)
Rusty Lynch7e1048b2005-06-23 00:09:25 -070080{
81 *p->addr = p->opcode;
82 flush_icache_range((unsigned long) p->addr,
83 (unsigned long) p->addr + sizeof(kprobe_opcode_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -070086void __kprobes arch_remove_kprobe(struct kprobe *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070088 down(&kprobe_mutex);
Ananth N Mavinakayanahalli2d8ab6a2005-10-01 13:14:17 -040089 free_insn_slot(p->ainsn.insn);
90 up(&kprobe_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static inline void prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
94{
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070095 kprobe_opcode_t insn = *p->ainsn.insn;
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 regs->msr |= MSR_SE;
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -070098
99 /* single step inline if it is a trap variant */
Keshavamurthy Anil Sdeac66a2005-09-06 15:19:35 -0700100 if (is_trap(insn))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 regs->nip = (unsigned long)p->addr;
102 else
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -0700103 regs->nip = (unsigned long)p->ainsn.insn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800106static inline void save_previous_kprobe(struct kprobe_ctlblk *kcb)
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700107{
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800108 kcb->prev_kprobe.kp = kprobe_running();
109 kcb->prev_kprobe.status = kcb->kprobe_status;
110 kcb->prev_kprobe.saved_msr = kcb->kprobe_saved_msr;
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700111}
112
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800113static inline void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700114{
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800115 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
116 kcb->kprobe_status = kcb->prev_kprobe.status;
117 kcb->kprobe_saved_msr = kcb->prev_kprobe.saved_msr;
118}
119
120static inline void set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
121 struct kprobe_ctlblk *kcb)
122{
123 __get_cpu_var(current_kprobe) = p;
124 kcb->kprobe_saved_msr = regs->msr;
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700125}
126
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800127/* Called with kretprobe_lock held */
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700128void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
129 struct pt_regs *regs)
Rusty Lynch97f79432005-06-27 15:17:15 -0700130{
131 struct kretprobe_instance *ri;
132
133 if ((ri = get_free_rp_inst(rp)) != NULL) {
134 ri->rp = rp;
135 ri->task = current;
136 ri->ret_addr = (kprobe_opcode_t *)regs->link;
137
138 /* Replace the return addr with trampoline addr */
139 regs->link = (unsigned long)kretprobe_trampoline;
140 add_rp_inst(ri);
141 } else {
142 rp->nmissed++;
143 }
144}
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static inline int kprobe_handler(struct pt_regs *regs)
147{
148 struct kprobe *p;
149 int ret = 0;
150 unsigned int *addr = (unsigned int *)regs->nip;
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800151 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* Check we're not actually recursing */
154 if (kprobe_running()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 p = get_kprobe(addr);
156 if (p) {
Keshavamurthy Anil Sdeac66a2005-09-06 15:19:35 -0700157 kprobe_opcode_t insn = *p->ainsn.insn;
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800158 if (kcb->kprobe_status == KPROBE_HIT_SS &&
Keshavamurthy Anil Sdeac66a2005-09-06 15:19:35 -0700159 is_trap(insn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 regs->msr &= ~MSR_SE;
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800161 regs->msr |= kcb->kprobe_saved_msr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 goto no_kprobe;
163 }
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700164 /* We have reentered the kprobe_handler(), since
165 * another probe was hit while within the handler.
166 * We here save the original kprobes variables and
167 * just single step on the instruction of the new probe
168 * without calling any user handlers.
169 */
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800170 save_previous_kprobe(kcb);
171 set_current_kprobe(p, regs, kcb);
172 kcb->kprobe_saved_msr = regs->msr;
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700173 p->nmissed++;
174 prepare_singlestep(p, regs);
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800175 kcb->kprobe_status = KPROBE_REENTER;
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700176 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 } else {
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800178 p = __get_cpu_var(current_kprobe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (p->break_handler && p->break_handler(p, regs)) {
180 goto ss_probe;
181 }
182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 goto no_kprobe;
184 }
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 p = get_kprobe(addr);
187 if (!p) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 if (*addr != BREAKPOINT_INSTRUCTION) {
189 /*
190 * PowerPC has multiple variants of the "trap"
191 * instruction. If the current instruction is a
192 * trap variant, it could belong to someone else
193 */
194 kprobe_opcode_t cur_insn = *addr;
Keshavamurthy Anil Sdeac66a2005-09-06 15:19:35 -0700195 if (is_trap(cur_insn))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 goto no_kprobe;
197 /*
198 * The breakpoint instruction was removed right
199 * after we hit it. Another cpu has removed
200 * either a probepoint or a debugger breakpoint
201 * at this address. In either case, no further
202 * handling of this interrupt is appropriate.
203 */
204 ret = 1;
205 }
206 /* Not one of ours: let kernel handle it */
207 goto no_kprobe;
208 }
209
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800210 /*
211 * This preempt_disable() matches the preempt_enable_no_resched()
212 * in post_kprobe_handler().
213 */
214 preempt_disable();
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800215 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
216 set_current_kprobe(p, regs, kcb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (p->pre_handler && p->pre_handler(p, regs))
218 /* handler has already set things up, so skip ss setup */
219 return 1;
220
221ss_probe:
222 prepare_singlestep(p, regs);
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800223 kcb->kprobe_status = KPROBE_HIT_SS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return 1;
225
226no_kprobe:
227 return ret;
228}
229
230/*
Rusty Lynch97f79432005-06-27 15:17:15 -0700231 * Function return probe trampoline:
232 * - init_kprobes() establishes a probepoint here
233 * - When the probed function returns, this probe
234 * causes the handlers to fire
235 */
236void kretprobe_trampoline_holder(void)
237{
238 asm volatile(".global kretprobe_trampoline\n"
239 "kretprobe_trampoline:\n"
240 "nop\n");
241}
242
243/*
244 * Called when the probe at kretprobe trampoline is hit
245 */
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700246int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
Rusty Lynch97f79432005-06-27 15:17:15 -0700247{
248 struct kretprobe_instance *ri = NULL;
249 struct hlist_head *head;
250 struct hlist_node *node, *tmp;
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800251 unsigned long flags, orig_ret_address = 0;
Rusty Lynch97f79432005-06-27 15:17:15 -0700252 unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;
253
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800254 spin_lock_irqsave(&kretprobe_lock, flags);
Rusty Lynch97f79432005-06-27 15:17:15 -0700255 head = kretprobe_inst_table_head(current);
256
257 /*
258 * It is possible to have multiple instances associated with a given
259 * task either because an multiple functions in the call path
260 * have a return probe installed on them, and/or more then one return
261 * return probe was registered for a target function.
262 *
263 * We can handle this because:
264 * - instances are always inserted at the head of the list
265 * - when multiple return probes are registered for the same
266 * function, the first instance's ret_addr will point to the
267 * real return address, and all the rest will point to
268 * kretprobe_trampoline
269 */
270 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
271 if (ri->task != current)
272 /* another task is sharing our hash bucket */
273 continue;
274
275 if (ri->rp && ri->rp->handler)
276 ri->rp->handler(ri, regs);
277
278 orig_ret_address = (unsigned long)ri->ret_addr;
279 recycle_rp_inst(ri);
280
281 if (orig_ret_address != trampoline_address)
282 /*
283 * This is the real return address. Any other
284 * instances associated with this task are for
285 * other calls deeper on the call stack
286 */
287 break;
288 }
289
290 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
291 regs->nip = orig_ret_address;
292
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800293 reset_current_kprobe();
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800294 spin_unlock_irqrestore(&kretprobe_lock, flags);
Ananth N Mavinakayanahalli66ff2d02005-11-07 01:00:07 -0800295 preempt_enable_no_resched();
Rusty Lynch97f79432005-06-27 15:17:15 -0700296
297 /*
298 * By returning a non-zero value, we are telling
299 * kprobe_handler() that we have handled unlocking
300 * and re-enabling preemption.
301 */
302 return 1;
303}
304
305/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 * Called after single-stepping. p->addr is the address of the
307 * instruction whose first byte has been replaced by the "breakpoint"
308 * instruction. To avoid the SMP problems that can occur when we
309 * temporarily put back the original opcode to single-step, we
310 * single-stepped a copy of the instruction. The address of this
311 * copy is p->ainsn.insn.
312 */
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700313static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 int ret;
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -0700316 unsigned int insn = *p->ainsn.insn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 regs->nip = (unsigned long)p->addr;
Ananth N Mavinakayanahalli9ec4b1f2005-06-27 15:17:01 -0700319 ret = emulate_step(regs, insn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (ret == 0)
321 regs->nip = (unsigned long)p->addr + 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324static inline int post_kprobe_handler(struct pt_regs *regs)
325{
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800326 struct kprobe *cur = kprobe_running();
327 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
328
329 if (!cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 return 0;
331
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800332 if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
333 kcb->kprobe_status = KPROBE_HIT_SSDONE;
334 cur->post_handler(cur, regs, 0);
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800337 resume_execution(cur, regs);
338 regs->msr |= kcb->kprobe_saved_msr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700340 /*Restore back the original saved kprobes variables and continue. */
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800341 if (kcb->kprobe_status == KPROBE_REENTER) {
342 restore_previous_kprobe(kcb);
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700343 goto out;
344 }
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800345 reset_current_kprobe();
Prasanna S Panchamukhi42cc2062005-06-23 00:09:38 -0700346out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 preempt_enable_no_resched();
348
349 /*
350 * if somebody else is singlestepping across a probe point, msr
351 * will have SE set, in which case, continue the remaining processing
352 * of do_debug, as if this is not a probe hit.
353 */
354 if (regs->msr & MSR_SE)
355 return 0;
356
357 return 1;
358}
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360static inline int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
361{
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800362 struct kprobe *cur = kprobe_running();
363 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
364
365 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return 1;
367
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800368 if (kcb->kprobe_status & KPROBE_HIT_SS) {
369 resume_execution(cur, regs);
Ananth N Mavinakayanahallif829fd22005-06-08 15:50:00 -0700370 regs->msr &= ~MSR_SE;
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800371 regs->msr |= kcb->kprobe_saved_msr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800373 reset_current_kprobe();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 preempt_enable_no_resched();
375 }
376 return 0;
377}
378
379/*
380 * Wrapper routine to for handling exceptions.
381 */
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700382int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
383 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 struct die_args *args = (struct die_args *)data;
386 int ret = NOTIFY_DONE;
387
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800388 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 switch (val) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 case DIE_BPT:
391 if (kprobe_handler(args->regs))
392 ret = NOTIFY_STOP;
393 break;
394 case DIE_SSTEP:
395 if (post_kprobe_handler(args->regs))
396 ret = NOTIFY_STOP;
397 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 case DIE_PAGE_FAULT:
399 if (kprobe_running() &&
400 kprobe_fault_handler(args->regs, args->trapnr))
401 ret = NOTIFY_STOP;
402 break;
403 default:
404 break;
405 }
Ananth N Mavinakayanahalli991a51d2005-11-07 01:00:14 -0800406 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return ret;
408}
409
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700410int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
412 struct jprobe *jp = container_of(p, struct jprobe, kp);
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800413 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800415 memcpy(&kcb->jprobe_saved_regs, regs, sizeof(struct pt_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 /* setup return addr to the jprobe handler routine */
418 regs->nip = (unsigned long)(((func_descr_t *)jp->entry)->entry);
419 regs->gpr[2] = (unsigned long)(((func_descr_t *)jp->entry)->toc);
420
421 return 1;
422}
423
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700424void __kprobes jprobe_return(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
426 asm volatile("trap" ::: "memory");
427}
428
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700429void __kprobes jprobe_return_end(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
431};
432
Prasanna S Panchamukhibb144a82005-09-06 15:19:29 -0700433int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800435 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 /*
438 * FIXME - we should ideally be validating that we got here 'cos
439 * of the "trap" in jprobe_return() above, before restoring the
440 * saved regs...
441 */
Ananth N Mavinakayanahalli0dc036c2005-11-07 01:00:10 -0800442 memcpy(regs, &kcb->jprobe_saved_regs, sizeof(struct pt_regs));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return 1;
444}
Rusty Lynch97f79432005-06-27 15:17:15 -0700445
446static struct kprobe trampoline_p = {
447 .addr = (kprobe_opcode_t *) &kretprobe_trampoline,
448 .pre_handler = trampoline_probe_handler
449};
450
Rusty Lynch67729262005-07-05 18:54:50 -0700451int __init arch_init_kprobes(void)
Rusty Lynch97f79432005-06-27 15:17:15 -0700452{
453 return register_kprobe(&trampoline_p);
454}