kprobes.c 17 KB

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