kprobes.c 17 KB

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