kprobes.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. * arch/arm/kernel/kprobes.c
  3. *
  4. * Kprobes on ARM
  5. *
  6. * Abhishek Sagar <sagar.abhishek@gmail.com>
  7. * Copyright (C) 2006, 2007 Motorola Inc.
  8. *
  9. * Nicolas Pitre <nico@marvell.com>
  10. * Copyright (C) 2007 Marvell Ltd.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/kprobes.h>
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #include <linux/stop_machine.h>
  26. #include <linux/stringify.h>
  27. #include <asm/traps.h>
  28. #include <asm/opcodes.h>
  29. #include <asm/cacheflush.h>
  30. #include <linux/percpu.h>
  31. #include <linux/bug.h>
  32. #include "kprobes.h"
  33. #include "probes-arm.h"
  34. #include "probes-thumb.h"
  35. #include "patch.h"
  36. #define MIN_STACK_SIZE(addr) \
  37. min((unsigned long)MAX_STACK_SIZE, \
  38. (unsigned long)current_thread_info() + THREAD_START_SP - (addr))
  39. #define flush_insns(addr, size) \
  40. flush_icache_range((unsigned long)(addr), \
  41. (unsigned long)(addr) + \
  42. (size))
  43. /* Used as a marker in ARM_pc to note when we're in a jprobe. */
  44. #define JPROBE_MAGIC_ADDR 0xffffffff
  45. DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
  46. DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
  47. int __kprobes arch_prepare_kprobe(struct kprobe *p)
  48. {
  49. kprobe_opcode_t insn;
  50. kprobe_opcode_t tmp_insn[MAX_INSN_SIZE];
  51. unsigned long addr = (unsigned long)p->addr;
  52. bool thumb;
  53. kprobe_decode_insn_t *decode_insn;
  54. const union decode_action *actions;
  55. int is;
  56. if (in_exception_text(addr))
  57. return -EINVAL;
  58. #ifdef CONFIG_THUMB2_KERNEL
  59. thumb = true;
  60. addr &= ~1; /* Bit 0 would normally be set to indicate Thumb code */
  61. insn = __mem_to_opcode_thumb16(((u16 *)addr)[0]);
  62. if (is_wide_instruction(insn)) {
  63. u16 inst2 = __mem_to_opcode_thumb16(((u16 *)addr)[1]);
  64. insn = __opcode_thumb32_compose(insn, inst2);
  65. decode_insn = thumb32_probes_decode_insn;
  66. actions = kprobes_t32_actions;
  67. } else {
  68. decode_insn = thumb16_probes_decode_insn;
  69. actions = kprobes_t16_actions;
  70. }
  71. #else /* !CONFIG_THUMB2_KERNEL */
  72. thumb = false;
  73. if (addr & 0x3)
  74. return -EINVAL;
  75. insn = __mem_to_opcode_arm(*p->addr);
  76. decode_insn = arm_probes_decode_insn;
  77. actions = kprobes_arm_actions;
  78. #endif
  79. p->opcode = insn;
  80. p->ainsn.insn = tmp_insn;
  81. switch ((*decode_insn)(insn, &p->ainsn, true, actions)) {
  82. case INSN_REJECTED: /* not supported */
  83. return -EINVAL;
  84. case INSN_GOOD: /* instruction uses slot */
  85. p->ainsn.insn = get_insn_slot();
  86. if (!p->ainsn.insn)
  87. return -ENOMEM;
  88. for (is = 0; is < MAX_INSN_SIZE; ++is)
  89. p->ainsn.insn[is] = tmp_insn[is];
  90. flush_insns(p->ainsn.insn,
  91. sizeof(p->ainsn.insn[0]) * MAX_INSN_SIZE);
  92. p->ainsn.insn_fn = (probes_insn_fn_t *)
  93. ((uintptr_t)p->ainsn.insn | thumb);
  94. break;
  95. case INSN_GOOD_NO_SLOT: /* instruction doesn't need insn slot */
  96. p->ainsn.insn = NULL;
  97. break;
  98. }
  99. return 0;
  100. }
  101. void __kprobes arch_arm_kprobe(struct kprobe *p)
  102. {
  103. unsigned int brkp;
  104. void *addr;
  105. if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
  106. /* Remove any Thumb flag */
  107. addr = (void *)((uintptr_t)p->addr & ~1);
  108. if (is_wide_instruction(p->opcode))
  109. brkp = KPROBE_THUMB32_BREAKPOINT_INSTRUCTION;
  110. else
  111. brkp = KPROBE_THUMB16_BREAKPOINT_INSTRUCTION;
  112. } else {
  113. kprobe_opcode_t insn = p->opcode;
  114. addr = p->addr;
  115. brkp = KPROBE_ARM_BREAKPOINT_INSTRUCTION;
  116. if (insn >= 0xe0000000)
  117. brkp |= 0xe0000000; /* Unconditional instruction */
  118. else
  119. brkp |= insn & 0xf0000000; /* Copy condition from insn */
  120. }
  121. patch_text(addr, brkp);
  122. }
  123. /*
  124. * The actual disarming is done here on each CPU and synchronized using
  125. * stop_machine. This synchronization is necessary on SMP to avoid removing
  126. * a probe between the moment the 'Undefined Instruction' exception is raised
  127. * and the moment the exception handler reads the faulting instruction from
  128. * memory. It is also needed to atomically set the two half-words of a 32-bit
  129. * Thumb breakpoint.
  130. */
  131. int __kprobes __arch_disarm_kprobe(void *p)
  132. {
  133. struct kprobe *kp = p;
  134. void *addr = (void *)((uintptr_t)kp->addr & ~1);
  135. __patch_text(addr, kp->opcode);
  136. return 0;
  137. }
  138. void __kprobes arch_disarm_kprobe(struct kprobe *p)
  139. {
  140. stop_machine(__arch_disarm_kprobe, p, cpu_online_mask);
  141. }
  142. void __kprobes arch_remove_kprobe(struct kprobe *p)
  143. {
  144. if (p->ainsn.insn) {
  145. free_insn_slot(p->ainsn.insn, 0);
  146. p->ainsn.insn = NULL;
  147. }
  148. }
  149. static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
  150. {
  151. kcb->prev_kprobe.kp = kprobe_running();
  152. kcb->prev_kprobe.status = kcb->kprobe_status;
  153. }
  154. static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
  155. {
  156. __this_cpu_write(current_kprobe, kcb->prev_kprobe.kp);
  157. kcb->kprobe_status = kcb->prev_kprobe.status;
  158. }
  159. static void __kprobes set_current_kprobe(struct kprobe *p)
  160. {
  161. __this_cpu_write(current_kprobe, p);
  162. }
  163. static void __kprobes
  164. singlestep_skip(struct kprobe *p, struct pt_regs *regs)
  165. {
  166. #ifdef CONFIG_THUMB2_KERNEL
  167. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  168. if (is_wide_instruction(p->opcode))
  169. regs->ARM_pc += 4;
  170. else
  171. regs->ARM_pc += 2;
  172. #else
  173. regs->ARM_pc += 4;
  174. #endif
  175. }
  176. static inline void __kprobes
  177. singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
  178. {
  179. p->ainsn.insn_singlestep(p->opcode, &p->ainsn, regs);
  180. }
  181. /*
  182. * Called with IRQs disabled. IRQs must remain disabled from that point
  183. * all the way until processing this kprobe is complete. The current
  184. * kprobes implementation cannot process more than one nested level of
  185. * kprobe, and that level is reserved for user kprobe handlers, so we can't
  186. * risk encountering a new kprobe in an interrupt handler.
  187. */
  188. void __kprobes kprobe_handler(struct pt_regs *regs)
  189. {
  190. struct kprobe *p, *cur;
  191. struct kprobe_ctlblk *kcb;
  192. kcb = get_kprobe_ctlblk();
  193. cur = kprobe_running();
  194. #ifdef CONFIG_THUMB2_KERNEL
  195. /*
  196. * First look for a probe which was registered using an address with
  197. * bit 0 set, this is the usual situation for pointers to Thumb code.
  198. * If not found, fallback to looking for one with bit 0 clear.
  199. */
  200. p = get_kprobe((kprobe_opcode_t *)(regs->ARM_pc | 1));
  201. if (!p)
  202. p = get_kprobe((kprobe_opcode_t *)regs->ARM_pc);
  203. #else /* ! CONFIG_THUMB2_KERNEL */
  204. p = get_kprobe((kprobe_opcode_t *)regs->ARM_pc);
  205. #endif
  206. if (p) {
  207. if (cur) {
  208. /* Kprobe is pending, so we're recursing. */
  209. switch (kcb->kprobe_status) {
  210. case KPROBE_HIT_ACTIVE:
  211. case KPROBE_HIT_SSDONE:
  212. /* A pre- or post-handler probe got us here. */
  213. kprobes_inc_nmissed_count(p);
  214. save_previous_kprobe(kcb);
  215. set_current_kprobe(p);
  216. kcb->kprobe_status = KPROBE_REENTER;
  217. singlestep(p, regs, kcb);
  218. restore_previous_kprobe(kcb);
  219. break;
  220. default:
  221. /* impossible cases */
  222. BUG();
  223. }
  224. } else if (p->ainsn.insn_check_cc(regs->ARM_cpsr)) {
  225. /* Probe hit and conditional execution check ok. */
  226. set_current_kprobe(p);
  227. kcb->kprobe_status = KPROBE_HIT_ACTIVE;
  228. /*
  229. * If we have no pre-handler or it returned 0, we
  230. * continue with normal processing. If we have a
  231. * pre-handler and it returned non-zero, it prepped
  232. * for calling the break_handler below on re-entry,
  233. * so get out doing nothing more here.
  234. */
  235. if (!p->pre_handler || !p->pre_handler(p, regs)) {
  236. kcb->kprobe_status = KPROBE_HIT_SS;
  237. singlestep(p, regs, kcb);
  238. if (p->post_handler) {
  239. kcb->kprobe_status = KPROBE_HIT_SSDONE;
  240. p->post_handler(p, regs, 0);
  241. }
  242. reset_current_kprobe();
  243. }
  244. } else {
  245. /*
  246. * Probe hit but conditional execution check failed,
  247. * so just skip the instruction and continue as if
  248. * nothing had happened.
  249. */
  250. singlestep_skip(p, regs);
  251. }
  252. } else if (cur) {
  253. /* We probably hit a jprobe. Call its break handler. */
  254. if (cur->break_handler && cur->break_handler(cur, regs)) {
  255. kcb->kprobe_status = KPROBE_HIT_SS;
  256. singlestep(cur, regs, kcb);
  257. if (cur->post_handler) {
  258. kcb->kprobe_status = KPROBE_HIT_SSDONE;
  259. cur->post_handler(cur, regs, 0);
  260. }
  261. }
  262. reset_current_kprobe();
  263. } else {
  264. /*
  265. * The probe was removed and a race is in progress.
  266. * There is nothing we can do about it. Let's restart
  267. * the instruction. By the time we can restart, the
  268. * real instruction will be there.
  269. */
  270. }
  271. }
  272. static int __kprobes kprobe_trap_handler(struct pt_regs *regs, unsigned int instr)
  273. {
  274. unsigned long flags;
  275. local_irq_save(flags);
  276. kprobe_handler(regs);
  277. local_irq_restore(flags);
  278. return 0;
  279. }
  280. int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
  281. {
  282. struct kprobe *cur = kprobe_running();
  283. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  284. switch (kcb->kprobe_status) {
  285. case KPROBE_HIT_SS:
  286. case KPROBE_REENTER:
  287. /*
  288. * We are here because the instruction being single
  289. * stepped caused a page fault. We reset the current
  290. * kprobe and the PC to point back to the probe address
  291. * and allow the page fault handler to continue as a
  292. * normal page fault.
  293. */
  294. regs->ARM_pc = (long)cur->addr;
  295. if (kcb->kprobe_status == KPROBE_REENTER) {
  296. restore_previous_kprobe(kcb);
  297. } else {
  298. reset_current_kprobe();
  299. }
  300. break;
  301. case KPROBE_HIT_ACTIVE:
  302. case KPROBE_HIT_SSDONE:
  303. /*
  304. * We increment the nmissed count for accounting,
  305. * we can also use npre/npostfault count for accounting
  306. * these specific fault cases.
  307. */
  308. kprobes_inc_nmissed_count(cur);
  309. /*
  310. * We come here because instructions in the pre/post
  311. * handler caused the page_fault, this could happen
  312. * if handler tries to access user space by
  313. * copy_from_user(), get_user() etc. Let the
  314. * user-specified handler try to fix it.
  315. */
  316. if (cur->fault_handler && cur->fault_handler(cur, regs, fsr))
  317. return 1;
  318. break;
  319. default:
  320. break;
  321. }
  322. return 0;
  323. }
  324. int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
  325. unsigned long val, void *data)
  326. {
  327. /*
  328. * notify_die() is currently never called on ARM,
  329. * so this callback is currently empty.
  330. */
  331. return NOTIFY_DONE;
  332. }
  333. /*
  334. * When a retprobed function returns, trampoline_handler() is called,
  335. * calling the kretprobe's handler. We construct a struct pt_regs to
  336. * give a view of registers r0-r11 to the user return-handler. This is
  337. * not a complete pt_regs structure, but that should be plenty sufficient
  338. * for kretprobe handlers which should normally be interested in r0 only
  339. * anyway.
  340. */
  341. void __naked __kprobes kretprobe_trampoline(void)
  342. {
  343. __asm__ __volatile__ (
  344. "stmdb sp!, {r0 - r11} \n\t"
  345. "mov r0, sp \n\t"
  346. "bl trampoline_handler \n\t"
  347. "mov lr, r0 \n\t"
  348. "ldmia sp!, {r0 - r11} \n\t"
  349. #ifdef CONFIG_THUMB2_KERNEL
  350. "bx lr \n\t"
  351. #else
  352. "mov pc, lr \n\t"
  353. #endif
  354. : : : "memory");
  355. }
  356. /* Called from kretprobe_trampoline */
  357. static __used __kprobes void *trampoline_handler(struct pt_regs *regs)
  358. {
  359. struct kretprobe_instance *ri = NULL;
  360. struct hlist_head *head, empty_rp;
  361. struct hlist_node *tmp;
  362. unsigned long flags, orig_ret_address = 0;
  363. unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
  364. INIT_HLIST_HEAD(&empty_rp);
  365. kretprobe_hash_lock(current, &head, &flags);
  366. /*
  367. * It is possible to have multiple instances associated with a given
  368. * task either because multiple functions in the call path have
  369. * a return probe installed on them, and/or more than one return
  370. * probe was registered for a target function.
  371. *
  372. * We can handle this because:
  373. * - instances are always inserted at the head of the list
  374. * - when multiple return probes are registered for the same
  375. * function, the first instance's ret_addr will point to the
  376. * real return address, and all the rest will point to
  377. * kretprobe_trampoline
  378. */
  379. hlist_for_each_entry_safe(ri, tmp, head, hlist) {
  380. if (ri->task != current)
  381. /* another task is sharing our hash bucket */
  382. continue;
  383. if (ri->rp && ri->rp->handler) {
  384. __this_cpu_write(current_kprobe, &ri->rp->kp);
  385. get_kprobe_ctlblk()->kprobe_status = KPROBE_HIT_ACTIVE;
  386. ri->rp->handler(ri, regs);
  387. __this_cpu_write(current_kprobe, NULL);
  388. }
  389. orig_ret_address = (unsigned long)ri->ret_addr;
  390. recycle_rp_inst(ri, &empty_rp);
  391. if (orig_ret_address != trampoline_address)
  392. /*
  393. * This is the real return address. Any other
  394. * instances associated with this task are for
  395. * other calls deeper on the call stack
  396. */
  397. break;
  398. }
  399. kretprobe_assert(ri, orig_ret_address, trampoline_address);
  400. kretprobe_hash_unlock(current, &flags);
  401. hlist_for_each_entry_safe(ri, tmp, &empty_rp, hlist) {
  402. hlist_del(&ri->hlist);
  403. kfree(ri);
  404. }
  405. return (void *)orig_ret_address;
  406. }
  407. void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
  408. struct pt_regs *regs)
  409. {
  410. ri->ret_addr = (kprobe_opcode_t *)regs->ARM_lr;
  411. /* Replace the return addr with trampoline addr. */
  412. regs->ARM_lr = (unsigned long)&kretprobe_trampoline;
  413. }
  414. int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
  415. {
  416. struct jprobe *jp = container_of(p, struct jprobe, kp);
  417. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  418. long sp_addr = regs->ARM_sp;
  419. long cpsr;
  420. kcb->jprobe_saved_regs = *regs;
  421. memcpy(kcb->jprobes_stack, (void *)sp_addr, MIN_STACK_SIZE(sp_addr));
  422. regs->ARM_pc = (long)jp->entry;
  423. cpsr = regs->ARM_cpsr | PSR_I_BIT;
  424. #ifdef CONFIG_THUMB2_KERNEL
  425. /* Set correct Thumb state in cpsr */
  426. if (regs->ARM_pc & 1)
  427. cpsr |= PSR_T_BIT;
  428. else
  429. cpsr &= ~PSR_T_BIT;
  430. #endif
  431. regs->ARM_cpsr = cpsr;
  432. preempt_disable();
  433. return 1;
  434. }
  435. void __kprobes jprobe_return(void)
  436. {
  437. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  438. __asm__ __volatile__ (
  439. /*
  440. * Setup an empty pt_regs. Fill SP and PC fields as
  441. * they're needed by longjmp_break_handler.
  442. *
  443. * We allocate some slack between the original SP and start of
  444. * our fabricated regs. To be precise we want to have worst case
  445. * covered which is STMFD with all 16 regs so we allocate 2 *
  446. * sizeof(struct_pt_regs)).
  447. *
  448. * This is to prevent any simulated instruction from writing
  449. * over the regs when they are accessing the stack.
  450. */
  451. #ifdef CONFIG_THUMB2_KERNEL
  452. "sub r0, %0, %1 \n\t"
  453. "mov sp, r0 \n\t"
  454. #else
  455. "sub sp, %0, %1 \n\t"
  456. #endif
  457. "ldr r0, ="__stringify(JPROBE_MAGIC_ADDR)"\n\t"
  458. "str %0, [sp, %2] \n\t"
  459. "str r0, [sp, %3] \n\t"
  460. "mov r0, sp \n\t"
  461. "bl kprobe_handler \n\t"
  462. /*
  463. * Return to the context saved by setjmp_pre_handler
  464. * and restored by longjmp_break_handler.
  465. */
  466. #ifdef CONFIG_THUMB2_KERNEL
  467. "ldr lr, [sp, %2] \n\t" /* lr = saved sp */
  468. "ldrd r0, r1, [sp, %5] \n\t" /* r0,r1 = saved lr,pc */
  469. "ldr r2, [sp, %4] \n\t" /* r2 = saved psr */
  470. "stmdb lr!, {r0, r1, r2} \n\t" /* push saved lr and */
  471. /* rfe context */
  472. "ldmia sp, {r0 - r12} \n\t"
  473. "mov sp, lr \n\t"
  474. "ldr lr, [sp], #4 \n\t"
  475. "rfeia sp! \n\t"
  476. #else
  477. "ldr r0, [sp, %4] \n\t"
  478. "msr cpsr_cxsf, r0 \n\t"
  479. "ldmia sp, {r0 - pc} \n\t"
  480. #endif
  481. :
  482. : "r" (kcb->jprobe_saved_regs.ARM_sp),
  483. "I" (sizeof(struct pt_regs) * 2),
  484. "J" (offsetof(struct pt_regs, ARM_sp)),
  485. "J" (offsetof(struct pt_regs, ARM_pc)),
  486. "J" (offsetof(struct pt_regs, ARM_cpsr)),
  487. "J" (offsetof(struct pt_regs, ARM_lr))
  488. : "memory", "cc");
  489. }
  490. int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
  491. {
  492. struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
  493. long stack_addr = kcb->jprobe_saved_regs.ARM_sp;
  494. long orig_sp = regs->ARM_sp;
  495. struct jprobe *jp = container_of(p, struct jprobe, kp);
  496. if (regs->ARM_pc == JPROBE_MAGIC_ADDR) {
  497. if (orig_sp != stack_addr) {
  498. struct pt_regs *saved_regs =
  499. (struct pt_regs *)kcb->jprobe_saved_regs.ARM_sp;
  500. printk("current sp %lx does not match saved sp %lx\n",
  501. orig_sp, stack_addr);
  502. printk("Saved registers for jprobe %p\n", jp);
  503. show_regs(saved_regs);
  504. printk("Current registers\n");
  505. show_regs(regs);
  506. BUG();
  507. }
  508. *regs = kcb->jprobe_saved_regs;
  509. memcpy((void *)stack_addr, kcb->jprobes_stack,
  510. MIN_STACK_SIZE(stack_addr));
  511. preempt_enable_no_resched();
  512. return 1;
  513. }
  514. return 0;
  515. }
  516. int __kprobes arch_trampoline_kprobe(struct kprobe *p)
  517. {
  518. return 0;
  519. }
  520. #ifdef CONFIG_THUMB2_KERNEL
  521. static struct undef_hook kprobes_thumb16_break_hook = {
  522. .instr_mask = 0xffff,
  523. .instr_val = KPROBE_THUMB16_BREAKPOINT_INSTRUCTION,
  524. .cpsr_mask = MODE_MASK,
  525. .cpsr_val = SVC_MODE,
  526. .fn = kprobe_trap_handler,
  527. };
  528. static struct undef_hook kprobes_thumb32_break_hook = {
  529. .instr_mask = 0xffffffff,
  530. .instr_val = KPROBE_THUMB32_BREAKPOINT_INSTRUCTION,
  531. .cpsr_mask = MODE_MASK,
  532. .cpsr_val = SVC_MODE,
  533. .fn = kprobe_trap_handler,
  534. };
  535. #else /* !CONFIG_THUMB2_KERNEL */
  536. static struct undef_hook kprobes_arm_break_hook = {
  537. .instr_mask = 0x0fffffff,
  538. .instr_val = KPROBE_ARM_BREAKPOINT_INSTRUCTION,
  539. .cpsr_mask = MODE_MASK,
  540. .cpsr_val = SVC_MODE,
  541. .fn = kprobe_trap_handler,
  542. };
  543. #endif /* !CONFIG_THUMB2_KERNEL */
  544. int __init arch_init_kprobes()
  545. {
  546. arm_probes_decode_init();
  547. #ifdef CONFIG_THUMB2_KERNEL
  548. register_undef_hook(&kprobes_thumb16_break_hook);
  549. register_undef_hook(&kprobes_thumb32_break_hook);
  550. #else
  551. register_undef_hook(&kprobes_arm_break_hook);
  552. #endif
  553. return 0;
  554. }