Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6] / arch / s390 / kernel / kprobes.c
1 /*
2  *  Kernel Probes (KProbes)
3  *
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, 2006
19  *
20  * s390 port, used ppc64 as template. Mike Grundy <grundym@us.ibm.com>
21  */
22
23 #include <linux/kprobes.h>
24 #include <linux/ptrace.h>
25 #include <linux/preempt.h>
26 #include <linux/stop_machine.h>
27 #include <asm/cacheflush.h>
28 #include <asm/kdebug.h>
29 #include <asm/sections.h>
30 #include <asm/uaccess.h>
31 #include <linux/module.h>
32
33 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
34 DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
35
36 int __kprobes arch_prepare_kprobe(struct kprobe *p)
37 {
38         /* Make sure the probe isn't going on a difficult instruction */
39         if (is_prohibited_opcode((kprobe_opcode_t *) p->addr))
40                 return -EINVAL;
41
42         if ((unsigned long)p->addr & 0x01) {
43                 printk("Attempt to register kprobe at an unaligned address\n");
44                 return -EINVAL;
45                 }
46
47         /* Use the get_insn_slot() facility for correctness */
48         if (!(p->ainsn.insn = get_insn_slot()))
49                 return -ENOMEM;
50
51         memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
52
53         get_instruction_type(&p->ainsn);
54         p->opcode = *p->addr;
55         return 0;
56 }
57
58 int __kprobes is_prohibited_opcode(kprobe_opcode_t *instruction)
59 {
60         switch (*(__u8 *) instruction) {
61         case 0x0c:      /* bassm */
62         case 0x0b:      /* bsm   */
63         case 0x83:      /* diag  */
64         case 0x44:      /* ex    */
65                 return -EINVAL;
66         }
67         switch (*(__u16 *) instruction) {
68         case 0x0101:    /* pr    */
69         case 0xb25a:    /* bsa   */
70         case 0xb240:    /* bakr  */
71         case 0xb258:    /* bsg   */
72         case 0xb218:    /* pc    */
73         case 0xb228:    /* pt    */
74                 return -EINVAL;
75         }
76         return 0;
77 }
78
79 void __kprobes get_instruction_type(struct arch_specific_insn *ainsn)
80 {
81         /* default fixup method */
82         ainsn->fixup = FIXUP_PSW_NORMAL;
83
84         /* save r1 operand */
85         ainsn->reg = (*ainsn->insn & 0xf0) >> 4;
86
87         /* save the instruction length (pop 5-5) in bytes */
88         switch (*(__u8 *) (ainsn->insn) >> 4) {
89         case 0:
90                 ainsn->ilen = 2;
91                 break;
92         case 1:
93         case 2:
94                 ainsn->ilen = 4;
95                 break;
96         case 3:
97                 ainsn->ilen = 6;
98                 break;
99         }
100
101         switch (*(__u8 *) ainsn->insn) {
102         case 0x05:      /* balr */
103         case 0x0d:      /* basr */
104                 ainsn->fixup = FIXUP_RETURN_REGISTER;
105                 /* if r2 = 0, no branch will be taken */
106                 if ((*ainsn->insn & 0x0f) == 0)
107                         ainsn->fixup |= FIXUP_BRANCH_NOT_TAKEN;
108                 break;
109         case 0x06:      /* bctr */
110         case 0x07:      /* bcr  */
111                 ainsn->fixup = FIXUP_BRANCH_NOT_TAKEN;
112                 break;
113         case 0x45:      /* bal  */
114         case 0x4d:      /* bas  */
115                 ainsn->fixup = FIXUP_RETURN_REGISTER;
116                 break;
117         case 0x47:      /* bc   */
118         case 0x46:      /* bct  */
119         case 0x86:      /* bxh  */
120         case 0x87:      /* bxle */
121                 ainsn->fixup = FIXUP_BRANCH_NOT_TAKEN;
122                 break;
123         case 0x82:      /* lpsw */
124                 ainsn->fixup = FIXUP_NOT_REQUIRED;
125                 break;
126         case 0xb2:      /* lpswe */
127                 if (*(((__u8 *) ainsn->insn) + 1) == 0xb2) {
128                         ainsn->fixup = FIXUP_NOT_REQUIRED;
129                 }
130                 break;
131         case 0xa7:      /* bras */
132                 if ((*ainsn->insn & 0x0f) == 0x05) {
133                         ainsn->fixup |= FIXUP_RETURN_REGISTER;
134                 }
135                 break;
136         case 0xc0:
137                 if ((*ainsn->insn & 0x0f) == 0x00  /* larl  */
138                         || (*ainsn->insn & 0x0f) == 0x05) /* brasl */
139                 ainsn->fixup |= FIXUP_RETURN_REGISTER;
140                 break;
141         case 0xeb:
142                 if (*(((__u8 *) ainsn->insn) + 5 ) == 0x44 ||   /* bxhg  */
143                         *(((__u8 *) ainsn->insn) + 5) == 0x45) {/* bxleg */
144                         ainsn->fixup = FIXUP_BRANCH_NOT_TAKEN;
145                 }
146                 break;
147         case 0xe3:      /* bctg */
148                 if (*(((__u8 *) ainsn->insn) + 5) == 0x46) {
149                         ainsn->fixup = FIXUP_BRANCH_NOT_TAKEN;
150                 }
151                 break;
152         }
153 }
154
155 static int __kprobes swap_instruction(void *aref)
156 {
157         struct ins_replace_args *args = aref;
158         int err = -EFAULT;
159
160         asm volatile(
161                 "0: mvc  0(2,%2),0(%3)\n"
162                 "1: la   %0,0\n"
163                 "2:\n"
164                 EX_TABLE(0b,2b)
165                 : "+d" (err), "=m" (*args->ptr)
166                 : "a" (args->ptr), "a" (&args->new), "m" (args->new));
167         return err;
168 }
169
170 void __kprobes arch_arm_kprobe(struct kprobe *p)
171 {
172         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
173         unsigned long status = kcb->kprobe_status;
174         struct ins_replace_args args;
175
176         args.ptr = p->addr;
177         args.old = p->opcode;
178         args.new = BREAKPOINT_INSTRUCTION;
179
180         kcb->kprobe_status = KPROBE_SWAP_INST;
181         stop_machine_run(swap_instruction, &args, NR_CPUS);
182         kcb->kprobe_status = status;
183 }
184
185 void __kprobes arch_disarm_kprobe(struct kprobe *p)
186 {
187         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
188         unsigned long status = kcb->kprobe_status;
189         struct ins_replace_args args;
190
191         args.ptr = p->addr;
192         args.old = BREAKPOINT_INSTRUCTION;
193         args.new = p->opcode;
194
195         kcb->kprobe_status = KPROBE_SWAP_INST;
196         stop_machine_run(swap_instruction, &args, NR_CPUS);
197         kcb->kprobe_status = status;
198 }
199
200 void __kprobes arch_remove_kprobe(struct kprobe *p)
201 {
202         mutex_lock(&kprobe_mutex);
203         free_insn_slot(p->ainsn.insn, 0);
204         mutex_unlock(&kprobe_mutex);
205 }
206
207 static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
208 {
209         per_cr_bits kprobe_per_regs[1];
210
211         memset(kprobe_per_regs, 0, sizeof(per_cr_bits));
212         regs->psw.addr = (unsigned long)p->ainsn.insn | PSW_ADDR_AMODE;
213
214         /* Set up the per control reg info, will pass to lctl */
215         kprobe_per_regs[0].em_instruction_fetch = 1;
216         kprobe_per_regs[0].starting_addr = (unsigned long)p->ainsn.insn;
217         kprobe_per_regs[0].ending_addr = (unsigned long)p->ainsn.insn + 1;
218
219         /* Set the PER control regs, turns on single step for this address */
220         __ctl_load(kprobe_per_regs, 9, 11);
221         regs->psw.mask |= PSW_MASK_PER;
222         regs->psw.mask &= ~(PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK);
223 }
224
225 static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
226 {
227         kcb->prev_kprobe.kp = kprobe_running();
228         kcb->prev_kprobe.status = kcb->kprobe_status;
229         kcb->prev_kprobe.kprobe_saved_imask = kcb->kprobe_saved_imask;
230         memcpy(kcb->prev_kprobe.kprobe_saved_ctl, kcb->kprobe_saved_ctl,
231                                         sizeof(kcb->kprobe_saved_ctl));
232 }
233
234 static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
235 {
236         __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
237         kcb->kprobe_status = kcb->prev_kprobe.status;
238         kcb->kprobe_saved_imask = kcb->prev_kprobe.kprobe_saved_imask;
239         memcpy(kcb->kprobe_saved_ctl, kcb->prev_kprobe.kprobe_saved_ctl,
240                                         sizeof(kcb->kprobe_saved_ctl));
241 }
242
243 static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
244                                                 struct kprobe_ctlblk *kcb)
245 {
246         __get_cpu_var(current_kprobe) = p;
247         /* Save the interrupt and per flags */
248         kcb->kprobe_saved_imask = regs->psw.mask &
249             (PSW_MASK_PER | PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK);
250         /* Save the control regs that govern PER */
251         __ctl_store(kcb->kprobe_saved_ctl, 9, 11);
252 }
253
254 /* Called with kretprobe_lock held */
255 void __kprobes arch_prepare_kretprobe(struct kretprobe *rp,
256                                         struct pt_regs *regs)
257 {
258         struct kretprobe_instance *ri;
259
260         if ((ri = get_free_rp_inst(rp)) != NULL) {
261                 ri->rp = rp;
262                 ri->task = current;
263                 ri->ret_addr = (kprobe_opcode_t *) regs->gprs[14];
264
265                 /* Replace the return addr with trampoline addr */
266                 regs->gprs[14] = (unsigned long)&kretprobe_trampoline;
267
268                 add_rp_inst(ri);
269         } else {
270                 rp->nmissed++;
271         }
272 }
273
274 static int __kprobes kprobe_handler(struct pt_regs *regs)
275 {
276         struct kprobe *p;
277         int ret = 0;
278         unsigned long *addr = (unsigned long *)
279                 ((regs->psw.addr & PSW_ADDR_INSN) - 2);
280         struct kprobe_ctlblk *kcb;
281
282         /*
283          * We don't want to be preempted for the entire
284          * duration of kprobe processing
285          */
286         preempt_disable();
287         kcb = get_kprobe_ctlblk();
288
289         /* Check we're not actually recursing */
290         if (kprobe_running()) {
291                 p = get_kprobe(addr);
292                 if (p) {
293                         if (kcb->kprobe_status == KPROBE_HIT_SS &&
294                             *p->ainsn.insn == BREAKPOINT_INSTRUCTION) {
295                                 regs->psw.mask &= ~PSW_MASK_PER;
296                                 regs->psw.mask |= kcb->kprobe_saved_imask;
297                                 goto no_kprobe;
298                         }
299                         /* We have reentered the kprobe_handler(), since
300                          * another probe was hit while within the handler.
301                          * We here save the original kprobes variables and
302                          * just single step on the instruction of the new probe
303                          * without calling any user handlers.
304                          */
305                         save_previous_kprobe(kcb);
306                         set_current_kprobe(p, regs, kcb);
307                         kprobes_inc_nmissed_count(p);
308                         prepare_singlestep(p, regs);
309                         kcb->kprobe_status = KPROBE_REENTER;
310                         return 1;
311                 } else {
312                         p = __get_cpu_var(current_kprobe);
313                         if (p->break_handler && p->break_handler(p, regs)) {
314                                 goto ss_probe;
315                         }
316                 }
317                 goto no_kprobe;
318         }
319
320         p = get_kprobe(addr);
321         if (!p) {
322                 if (*addr != BREAKPOINT_INSTRUCTION) {
323                         /*
324                          * The breakpoint instruction was removed right
325                          * after we hit it.  Another cpu has removed
326                          * either a probepoint or a debugger breakpoint
327                          * at this address.  In either case, no further
328                          * handling of this interrupt is appropriate.
329                          *
330                          */
331                         ret = 1;
332                 }
333                 /* Not one of ours: let kernel handle it */
334                 goto no_kprobe;
335         }
336
337         kcb->kprobe_status = KPROBE_HIT_ACTIVE;
338         set_current_kprobe(p, regs, kcb);
339         if (p->pre_handler && p->pre_handler(p, regs))
340                 /* handler has already set things up, so skip ss setup */
341                 return 1;
342
343 ss_probe:
344         prepare_singlestep(p, regs);
345         kcb->kprobe_status = KPROBE_HIT_SS;
346         return 1;
347
348 no_kprobe:
349         preempt_enable_no_resched();
350         return ret;
351 }
352
353 /*
354  * Function return probe trampoline:
355  *      - init_kprobes() establishes a probepoint here
356  *      - When the probed function returns, this probe
357  *              causes the handlers to fire
358  */
359 void __kprobes kretprobe_trampoline_holder(void)
360 {
361         asm volatile(".global kretprobe_trampoline\n"
362                      "kretprobe_trampoline: bcr 0,0\n");
363 }
364
365 /*
366  * Called when the probe at kretprobe trampoline is hit
367  */
368 int __kprobes trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
369 {
370         struct kretprobe_instance *ri = NULL;
371         struct hlist_head *head, empty_rp;
372         struct hlist_node *node, *tmp;
373         unsigned long flags, orig_ret_address = 0;
374         unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
375
376         INIT_HLIST_HEAD(&empty_rp);
377         spin_lock_irqsave(&kretprobe_lock, flags);
378         head = kretprobe_inst_table_head(current);
379
380         /*
381          * It is possible to have multiple instances associated with a given
382          * task either because an multiple functions in the call path
383          * have a return probe installed on them, and/or more then one return
384          * return probe was registered for a target function.
385          *
386          * We can handle this because:
387          *     - instances are always inserted at the head of the list
388          *     - when multiple return probes are registered for the same
389          *       function, the first instance's ret_addr will point to the
390          *       real return address, and all the rest will point to
391          *       kretprobe_trampoline
392          */
393         hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
394                 if (ri->task != current)
395                         /* another task is sharing our hash bucket */
396                         continue;
397
398                 if (ri->rp && ri->rp->handler)
399                         ri->rp->handler(ri, regs);
400
401                 orig_ret_address = (unsigned long)ri->ret_addr;
402                 recycle_rp_inst(ri, &empty_rp);
403
404                 if (orig_ret_address != trampoline_address) {
405                         /*
406                          * This is the real return address. Any other
407                          * instances associated with this task are for
408                          * other calls deeper on the call stack
409                          */
410                         break;
411                 }
412         }
413         BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
414         regs->psw.addr = orig_ret_address | PSW_ADDR_AMODE;
415
416         reset_current_kprobe();
417         spin_unlock_irqrestore(&kretprobe_lock, flags);
418         preempt_enable_no_resched();
419
420         hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
421                 hlist_del(&ri->hlist);
422                 kfree(ri);
423         }
424         /*
425          * By returning a non-zero value, we are telling
426          * kprobe_handler() that we don't want the post_handler
427          * to run (and have re-enabled preemption)
428          */
429         return 1;
430 }
431
432 /*
433  * Called after single-stepping.  p->addr is the address of the
434  * instruction whose first byte has been replaced by the "breakpoint"
435  * instruction.  To avoid the SMP problems that can occur when we
436  * temporarily put back the original opcode to single-step, we
437  * single-stepped a copy of the instruction.  The address of this
438  * copy is p->ainsn.insn.
439  */
440 static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
441 {
442         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
443
444         regs->psw.addr &= PSW_ADDR_INSN;
445
446         if (p->ainsn.fixup & FIXUP_PSW_NORMAL)
447                 regs->psw.addr = (unsigned long)p->addr +
448                                 ((unsigned long)regs->psw.addr -
449                                  (unsigned long)p->ainsn.insn);
450
451         if (p->ainsn.fixup & FIXUP_BRANCH_NOT_TAKEN)
452                 if ((unsigned long)regs->psw.addr -
453                     (unsigned long)p->ainsn.insn == p->ainsn.ilen)
454                         regs->psw.addr = (unsigned long)p->addr + p->ainsn.ilen;
455
456         if (p->ainsn.fixup & FIXUP_RETURN_REGISTER)
457                 regs->gprs[p->ainsn.reg] = ((unsigned long)p->addr +
458                                                 (regs->gprs[p->ainsn.reg] -
459                                                 (unsigned long)p->ainsn.insn))
460                                                 | PSW_ADDR_AMODE;
461
462         regs->psw.addr |= PSW_ADDR_AMODE;
463         /* turn off PER mode */
464         regs->psw.mask &= ~PSW_MASK_PER;
465         /* Restore the original per control regs */
466         __ctl_load(kcb->kprobe_saved_ctl, 9, 11);
467         regs->psw.mask |= kcb->kprobe_saved_imask;
468 }
469
470 static int __kprobes post_kprobe_handler(struct pt_regs *regs)
471 {
472         struct kprobe *cur = kprobe_running();
473         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
474
475         if (!cur)
476                 return 0;
477
478         if ((kcb->kprobe_status != KPROBE_REENTER) && cur->post_handler) {
479                 kcb->kprobe_status = KPROBE_HIT_SSDONE;
480                 cur->post_handler(cur, regs, 0);
481         }
482
483         resume_execution(cur, regs);
484
485         /*Restore back the original saved kprobes variables and continue. */
486         if (kcb->kprobe_status == KPROBE_REENTER) {
487                 restore_previous_kprobe(kcb);
488                 goto out;
489         }
490         reset_current_kprobe();
491 out:
492         preempt_enable_no_resched();
493
494         /*
495          * if somebody else is singlestepping across a probe point, psw mask
496          * will have PER set, in which case, continue the remaining processing
497          * of do_single_step, as if this is not a probe hit.
498          */
499         if (regs->psw.mask & PSW_MASK_PER) {
500                 return 0;
501         }
502
503         return 1;
504 }
505
506 static int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
507 {
508         struct kprobe *cur = kprobe_running();
509         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
510         const struct exception_table_entry *entry;
511
512         switch(kcb->kprobe_status) {
513         case KPROBE_SWAP_INST:
514                 /* We are here because the instruction replacement failed */
515                 return 0;
516         case KPROBE_HIT_SS:
517         case KPROBE_REENTER:
518                 /*
519                  * We are here because the instruction being single
520                  * stepped caused a page fault. We reset the current
521                  * kprobe and the nip points back to the probe address
522                  * and allow the page fault handler to continue as a
523                  * normal page fault.
524                  */
525                 regs->psw.addr = (unsigned long)cur->addr | PSW_ADDR_AMODE;
526                 regs->psw.mask &= ~PSW_MASK_PER;
527                 regs->psw.mask |= kcb->kprobe_saved_imask;
528                 if (kcb->kprobe_status == KPROBE_REENTER)
529                         restore_previous_kprobe(kcb);
530                 else
531                         reset_current_kprobe();
532                 preempt_enable_no_resched();
533                 break;
534         case KPROBE_HIT_ACTIVE:
535         case KPROBE_HIT_SSDONE:
536                 /*
537                  * We increment the nmissed count for accounting,
538                  * we can also use npre/npostfault count for accouting
539                  * these specific fault cases.
540                  */
541                 kprobes_inc_nmissed_count(cur);
542
543                 /*
544                  * We come here because instructions in the pre/post
545                  * handler caused the page_fault, this could happen
546                  * if handler tries to access user space by
547                  * copy_from_user(), get_user() etc. Let the
548                  * user-specified handler try to fix it first.
549                  */
550                 if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
551                         return 1;
552
553                 /*
554                  * In case the user-specified fault handler returned
555                  * zero, try to fix up.
556                  */
557                 entry = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
558                 if (entry) {
559                         regs->psw.addr = entry->fixup | PSW_ADDR_AMODE;
560                         return 1;
561                 }
562
563                 /*
564                  * fixup_exception() could not handle it,
565                  * Let do_page_fault() fix it.
566                  */
567                 break;
568         default:
569                 break;
570         }
571         return 0;
572 }
573
574 /*
575  * Wrapper routine to for handling exceptions.
576  */
577 int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
578                                        unsigned long val, void *data)
579 {
580         struct die_args *args = (struct die_args *)data;
581         int ret = NOTIFY_DONE;
582
583         switch (val) {
584         case DIE_BPT:
585                 if (kprobe_handler(args->regs))
586                         ret = NOTIFY_STOP;
587                 break;
588         case DIE_SSTEP:
589                 if (post_kprobe_handler(args->regs))
590                         ret = NOTIFY_STOP;
591                 break;
592         case DIE_TRAP:
593         case DIE_PAGE_FAULT:
594                 /* kprobe_running() needs smp_processor_id() */
595                 preempt_disable();
596                 if (kprobe_running() &&
597                     kprobe_fault_handler(args->regs, args->trapnr))
598                         ret = NOTIFY_STOP;
599                 preempt_enable();
600                 break;
601         default:
602                 break;
603         }
604         return ret;
605 }
606
607 int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
608 {
609         struct jprobe *jp = container_of(p, struct jprobe, kp);
610         unsigned long addr;
611         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
612
613         memcpy(&kcb->jprobe_saved_regs, regs, sizeof(struct pt_regs));
614
615         /* setup return addr to the jprobe handler routine */
616         regs->psw.addr = (unsigned long)(jp->entry) | PSW_ADDR_AMODE;
617
618         /* r14 is the function return address */
619         kcb->jprobe_saved_r14 = (unsigned long)regs->gprs[14];
620         /* r15 is the stack pointer */
621         kcb->jprobe_saved_r15 = (unsigned long)regs->gprs[15];
622         addr = (unsigned long)kcb->jprobe_saved_r15;
623
624         memcpy(kcb->jprobes_stack, (kprobe_opcode_t *) addr,
625                MIN_STACK_SIZE(addr));
626         return 1;
627 }
628
629 void __kprobes jprobe_return(void)
630 {
631         asm volatile(".word 0x0002");
632 }
633
634 void __kprobes jprobe_return_end(void)
635 {
636         asm volatile("bcr 0,0");
637 }
638
639 int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
640 {
641         struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
642         unsigned long stack_addr = (unsigned long)(kcb->jprobe_saved_r15);
643
644         /* Put the regs back */
645         memcpy(regs, &kcb->jprobe_saved_regs, sizeof(struct pt_regs));
646         /* put the stack back */
647         memcpy((kprobe_opcode_t *) stack_addr, kcb->jprobes_stack,
648                MIN_STACK_SIZE(stack_addr));
649         preempt_enable_no_resched();
650         return 1;
651 }
652
653 static struct kprobe trampoline_p = {
654         .addr = (kprobe_opcode_t *) & kretprobe_trampoline,
655         .pre_handler = trampoline_probe_handler
656 };
657
658 int __init arch_init_kprobes(void)
659 {
660         return register_kprobe(&trampoline_p);
661 }