kprobes.c 17 KB

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