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