2 * Dynamic Binary Instrumentation Module based on KProbes
3 * modules/kprobe/arch/asm-arm/dbi_kprobes.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2006-2010
21 * 2006-2007 Ekaterina Gorelkina <e.gorelkina@samsung.com>: initial implementation for ARM/MIPS
22 * 2008-2009 Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
23 * Probes initial implementation; Support x86.
24 * 2010 Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
25 * 2010-2011 Alexander Shirshikov <a.shirshikov@samsung.com>: initial implementation for Thumb
26 * 2012 Stanislav Andreev <s.andreev@samsung.com>: added time debug profiling support; BUG() message fix
27 * 2012 Stanislav Andreev <s.andreev@samsung.com>: redesign of kprobe functionality -
28 * kprobe_handler() now called via undefined instruction hooks
29 * 2012 Stanislav Andreev <s.andreev@samsung.com>: hash tables search implemented for uprobes
32 #include <linux/module.h>
35 #include "dbi_kprobes.h"
36 #include "dbi_kprobes_arm.h"
37 #include "dbi_kprobes_thumb.h"
38 #include "../dbi_kprobes.h"
39 #include "../../dbi_kprobes.h"
41 #include "../../dbi_kdebug.h"
42 #include "../../dbi_insn_slots.h"
43 #include "../../dbi_kprobes_deps.h"
46 #include <asm/cacheflush.h>
48 #ifdef TRAP_OVERHEAD_DEBUG
49 #include <linux/pid.h>
50 #include <linux/signal.h>
54 #include <linux/time.h>
57 #include <asm/traps.h>
58 #include <asm/ptrace.h>
59 #include <linux/list.h>
60 #include <linux/hash.h>
62 #define SUPRESS_BUG_MESSAGES
64 extern struct kprobe * per_cpu__current_kprobe;
65 extern struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
67 static void (*__swap_register_undef_hook)(struct undef_hook *hook);
68 static void (*__swap_unregister_undef_hook)(struct undef_hook *hook);
71 unsigned long swap_sum_time = 0;
72 unsigned long swap_sum_hit = 0;
73 EXPORT_SYMBOL_GPL (swap_sum_time);
74 EXPORT_SYMBOL_GPL (swap_sum_hit);
77 static struct kprobe trampoline_p =
79 .addr = (kprobe_opcode_t *) & kretprobe_trampoline,
80 .pre_handler = trampoline_probe_handler
83 int prep_pc_dep_insn_execbuf(kprobe_opcode_t *insns, kprobe_opcode_t insn, int uregs)
91 for (i = 0; i < 13; i++, reg_mask <<= 1)
93 if (!(insn & reg_mask))
99 for (i = 0; i < 13; i++)
101 if ((uregs & 0x1) && (ARM_INSN_REG_RN (insn) == i))
103 if ((uregs & 0x2) && (ARM_INSN_REG_RD (insn) == i))
105 if ((uregs & 0x4) && (ARM_INSN_REG_RS (insn) == i))
107 if ((uregs & 0x8) && (ARM_INSN_REG_RM (insn) == i))
114 DBPRINTF ("there are no free register %x in insn %lx!", uregs, insn);
117 DBPRINTF ("prep_pc_dep_insn_execbuf: using R%d, changing regs %x", i, uregs);
119 // set register to save
120 ARM_INSN_REG_SET_RD (insns[0], i);
121 // set register to load address to
122 ARM_INSN_REG_SET_RD (insns[1], i);
123 // set instruction to execute and patch it
126 ARM_INSN_REG_CLEAR_MR (insn, 15);
127 ARM_INSN_REG_SET_MR (insn, i);
131 if ((uregs & 0x1) && (ARM_INSN_REG_RN (insn) == 15))
132 ARM_INSN_REG_SET_RN (insn, i);
133 if ((uregs & 0x2) && (ARM_INSN_REG_RD (insn) == 15))
134 ARM_INSN_REG_SET_RD (insn, i);
135 if ((uregs & 0x4) && (ARM_INSN_REG_RS (insn) == 15))
136 ARM_INSN_REG_SET_RS (insn, i);
137 if ((uregs & 0x8) && (ARM_INSN_REG_RM (insn) == 15))
138 ARM_INSN_REG_SET_RM (insn, i);
140 insns[UPROBES_TRAMP_INSN_IDX] = insn;
141 // set register to restore
142 ARM_INSN_REG_SET_RD (insns[3], i);
145 EXPORT_SYMBOL_GPL(prep_pc_dep_insn_execbuf);
147 int arch_check_insn_arm(struct arch_specific_insn *ainsn)
151 // check instructions that can change PC by nature
153 // ARM_INSN_MATCH (UNDEF, ainsn->insn_arm[0]) ||
154 ARM_INSN_MATCH (AUNDEF, ainsn->insn_arm[0]) ||
155 ARM_INSN_MATCH (SWI, ainsn->insn_arm[0]) ||
156 ARM_INSN_MATCH (BREAK, ainsn->insn_arm[0]) ||
157 ARM_INSN_MATCH (BL, ainsn->insn_arm[0]) ||
158 ARM_INSN_MATCH (BLX1, ainsn->insn_arm[0]) ||
159 ARM_INSN_MATCH (BLX2, ainsn->insn_arm[0]) ||
160 ARM_INSN_MATCH (BX, ainsn->insn_arm[0]) ||
161 ARM_INSN_MATCH (BXJ, ainsn->insn_arm[0]))
163 DBPRINTF ("Bad insn arch_check_insn_arm: %lx\n", ainsn->insn_arm[0]);
166 #ifndef CONFIG_CPU_V7
167 // check instructions that can write result to PC
168 else if ((ARM_INSN_MATCH (DPIS, ainsn->insn_arm[0]) ||
169 ARM_INSN_MATCH (DPRS, ainsn->insn_arm[0]) ||
170 ARM_INSN_MATCH (DPI, ainsn->insn_arm[0]) ||
171 ARM_INSN_MATCH (LIO, ainsn->insn_arm[0]) ||
172 ARM_INSN_MATCH (LRO, ainsn->insn_arm[0])) &&
173 (ARM_INSN_REG_RD (ainsn->insn_arm[0]) == 15))
175 DBPRINTF ("Bad arch_check_insn_arm: %lx\n", ainsn->insn_arm[0]);
178 #endif // CONFIG_CPU_V7
179 // check special instruction loads store multiple registers
180 else if ((ARM_INSN_MATCH (LM, ainsn->insn_arm[0]) || ARM_INSN_MATCH (SM, ainsn->insn_arm[0])) &&
181 // store pc or load to pc
182 (ARM_INSN_REG_MR (ainsn->insn_arm[0], 15) ||
183 // store/load with pc update
184 ((ARM_INSN_REG_RN (ainsn->insn_arm[0]) == 15) && (ainsn->insn_arm[0] & 0x200000))))
186 DBPRINTF ("Bad insn arch_check_insn_arm: %lx\n", ainsn->insn_arm[0]);
191 EXPORT_SYMBOL_GPL(arch_check_insn_arm);
193 int arch_prepare_kretprobe (struct kretprobe *p)
195 DBPRINTF("Warrning: arch_prepare_kretprobe is not implemented\n");
199 int arch_prepare_kprobe (struct kprobe *p)
201 kprobe_opcode_t insns[KPROBES_TRAMP_LEN];
202 int uregs, pc_dep, ret = 0;
203 kprobe_opcode_t insn[MAX_INSN_SIZE];
204 struct arch_specific_insn ainsn;
206 /* insn: must be on special executable page on i386. */
207 p->ainsn.insn = get_insn_slot(NULL, &kprobe_insn_pages, 0);
211 memcpy (insn, p->addr, MAX_INSN_SIZE * sizeof (kprobe_opcode_t));
212 ainsn.insn_arm = ainsn.insn = insn;
213 ret = arch_check_insn_arm (&ainsn);
216 p->opcode = *p->addr;
220 if(ARM_INSN_MATCH (DPIS, insn[0]) || ARM_INSN_MATCH (LRO, insn[0]) ||
221 ARM_INSN_MATCH (SRO, insn[0]))
224 if( (ARM_INSN_REG_RN (insn[0]) == 15) || (ARM_INSN_REG_RM (insn[0]) == 15) ||
225 (ARM_INSN_MATCH (SRO, insn[0]) && (ARM_INSN_REG_RD (insn[0]) == 15)) )
227 DBPRINTF ("Unboostable insn %lx, DPIS/LRO/SRO\n", insn[0]);
232 else if(ARM_INSN_MATCH (DPI, insn[0]) || ARM_INSN_MATCH (LIO, insn[0]) ||
233 ARM_INSN_MATCH (SIO, insn[0]))
236 if ((ARM_INSN_REG_RN (insn[0]) == 15) || (ARM_INSN_MATCH (SIO, insn[0]) &&
237 (ARM_INSN_REG_RD (insn[0]) == 15)))
240 DBPRINTF ("Unboostable insn %lx/%p, DPI/LIO/SIO\n", insn[0], p);
244 else if(ARM_INSN_MATCH (DPRS, insn[0]))
247 if ((ARM_INSN_REG_RN (insn[0]) == 15) || (ARM_INSN_REG_RM (insn[0]) == 15) ||
248 (ARM_INSN_REG_RS (insn[0]) == 15))
251 DBPRINTF ("Unboostable insn %lx, DPRS\n", insn[0]);
255 else if(ARM_INSN_MATCH (SM, insn[0]))
258 if (ARM_INSN_REG_MR (insn[0], 15))
260 DBPRINTF ("Unboostable insn %lx, SM\n", insn[0]);
264 // check instructions that can write result to SP andu uses PC
265 if (pc_dep && (ARM_INSN_REG_RD (ainsn.insn[0]) == 13))
267 free_insn_slot(&kprobe_insn_pages, NULL, p->ainsn.insn);
274 memcpy (insns, pc_dep_insn_execbuf, sizeof (insns));
275 if (prep_pc_dep_insn_execbuf (insns, insn[0], uregs) != 0)
277 DBPRINTF ("failed to prepare exec buffer for insn %lx!", insn[0]);
278 free_insn_slot(&kprobe_insn_pages, NULL, p->ainsn.insn);
281 insns[6] = (kprobe_opcode_t) (p->addr + 2);
285 memcpy (insns, gen_insn_execbuf, sizeof (insns));
286 insns[KPROBES_TRAMP_INSN_IDX] = insn[0];
288 insns[7] = (kprobe_opcode_t) (p->addr + 1);
289 DBPRINTF ("arch_prepare_kprobe: insn %lx", insn[0]);
290 DBPRINTF ("arch_prepare_kprobe: to %p - %lx %lx %lx %lx %lx %lx %lx %lx %lx",
291 p->ainsn.insn, insns[0], insns[1], insns[2], insns[3], insns[4],
292 insns[5], insns[6], insns[7], insns[8]);
293 memcpy (p->ainsn.insn, insns, sizeof(insns));
294 flush_icache_range((long unsigned)p->ainsn.insn, (long unsigned)(p->ainsn.insn) + sizeof(insns));
302 free_insn_slot(&kprobe_insn_pages, NULL, p->ainsn.insn);
303 printk("arch_prepare_kprobe: instruction 0x%lx not instrumentation, addr=0x%p\n", insn[0], p->addr);
309 void prepare_singlestep (struct kprobe *p, struct pt_regs *regs)
312 regs->ARM_pc = (unsigned long)p->ss_addr;
315 regs->ARM_pc = (unsigned long)p->ainsn.insn;
318 EXPORT_SYMBOL_GPL(prepare_singlestep);
320 void save_previous_kprobe(struct kprobe_ctlblk *kcb, struct kprobe *p_run)
322 kcb->prev_kprobe.kp = kprobe_running();
323 kcb->prev_kprobe.status = kcb->kprobe_status;
326 void restore_previous_kprobe(struct kprobe_ctlblk *kcb)
328 __get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
329 kcb->kprobe_status = kcb->prev_kprobe.status;
332 void set_current_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
334 __get_cpu_var(current_kprobe) = p;
335 DBPRINTF ("set_current_kprobe: p=%p addr=%p\n", p, p->addr);
338 #ifdef TRAP_OVERHEAD_DEBUG
339 static unsigned long trap_handler_counter_debug = 0;
340 #define SAMPLING_COUNTER 100000
343 static int kprobe_handler(struct pt_regs *regs)
345 struct kprobe *p, *cur;
346 struct kprobe_ctlblk *kcb;
348 kcb = get_kprobe_ctlblk();
349 cur = kprobe_running();
350 p = get_kprobe((kprobe_opcode_t *)regs->ARM_pc, 0);
354 /* Kprobe is pending, so we're recursing. */
355 switch (kcb->kprobe_status) {
356 case KPROBE_HIT_ACTIVE:
357 case KPROBE_HIT_SSDONE:
358 /* A pre- or post-handler probe got us here. */
359 kprobes_inc_nmissed_count(p);
360 save_previous_kprobe(kcb, NULL);
361 set_current_kprobe(p, 0, 0);
362 kcb->kprobe_status = KPROBE_REENTER;
363 prepare_singlestep(p, regs);
364 restore_previous_kprobe(kcb);
367 /* impossible cases */
371 set_current_kprobe(p, 0, 0);
372 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
374 if (!p->pre_handler || !p->pre_handler(p, regs)) {
375 kcb->kprobe_status = KPROBE_HIT_SS;
376 prepare_singlestep(p, regs);
377 reset_current_kprobe();
387 printk("no_kprobe\n");
391 int kprobe_trap_handler(struct pt_regs *regs, unsigned int instr)
396 #ifdef SUPRESS_BUG_MESSAGES
397 int swap_oops_in_progress;
398 /* oops_in_progress used to avoid BUG() messages
399 * that slow down kprobe_handler() execution */
400 swap_oops_in_progress = oops_in_progress;
401 oops_in_progress = 1;
404 local_irq_save(flags);
406 ret = kprobe_handler(regs);
407 preempt_enable_no_resched();
408 local_irq_restore(flags);
410 #ifdef SUPRESS_BUG_MESSAGES
411 oops_in_progress = swap_oops_in_progress;
417 int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
419 struct jprobe *jp = container_of(p, struct jprobe, kp);
420 kprobe_pre_entry_handler_t pre_entry = (kprobe_pre_entry_handler_t)jp->pre_entry;
421 entry_point_t entry = (entry_point_t)jp->entry;
422 pre_entry = (kprobe_pre_entry_handler_t)jp->pre_entry;
425 panic("setjmp_pre_handler: p->tgid == 0");
428 if (((unsigned long)p->addr == sched_addr) && sched_rp) {
429 struct thread_info *tinfo = (struct thread_info *)regs->ARM_r2;
430 patch_suspended_task(sched_rp, tinfo->task);
434 p->ss_addr = (void *)pre_entry (jp->priv_arg, regs);
438 entry(regs->ARM_r0, regs->ARM_r1, regs->ARM_r2,
439 regs->ARM_r3, regs->ARM_r4, regs->ARM_r5);
447 void dbi_jprobe_return (void)
451 int longjmp_break_handler (struct kprobe *p, struct pt_regs *regs)
454 //kprobe_opcode_t insn = BREAKPOINT_INSTRUCTION;
455 kprobe_opcode_t insns[2];
459 insns[0] = BREAKPOINT_INSTRUCTION;
460 insns[1] = p->opcode;
461 //p->opcode = *p->addr;
462 if (read_proc_vm_atomic (current, (unsigned long) (p->addr), &(p->opcode), sizeof (p->opcode)) < sizeof (p->opcode))
464 printk ("ERROR[%lu]: failed to read vm of proc %s/%u addr %p.", nCount, current->comm, current->pid, p->addr);
467 //*p->addr = BREAKPOINT_INSTRUCTION;
468 //*(p->addr+1) = p->opcode;
469 if (write_proc_vm_atomic (current, (unsigned long) (p->addr), insns, sizeof (insns)) < sizeof (insns))
471 printk ("ERROR[%lu]: failed to write vm of proc %s/%u addr %p.", nCount, current->comm, current->pid, p->addr);
477 DBPRINTF ("p->opcode = 0x%lx *p->addr = 0x%lx p->addr = 0x%p\n", p->opcode, *p->addr, p->addr);
478 *(p->addr + 1) = p->opcode;
479 p->opcode = *p->addr;
480 *p->addr = BREAKPOINT_INSTRUCTION;
482 flush_icache_range ((unsigned int) p->addr, (unsigned int) (((unsigned int) p->addr) + (sizeof (kprobe_opcode_t) * 2)));
485 reset_current_kprobe();
491 EXPORT_SYMBOL_GPL(longjmp_break_handler);
493 void arch_arm_kprobe (struct kprobe *p)
495 *p->addr = BREAKPOINT_INSTRUCTION;
496 flush_icache_range ((unsigned long) p->addr, (unsigned long) p->addr + sizeof (kprobe_opcode_t));
499 void arch_disarm_kprobe (struct kprobe *p)
501 *p->addr = p->opcode;
502 flush_icache_range ((unsigned long) p->addr, (unsigned long) p->addr + sizeof (kprobe_opcode_t));
506 int trampoline_probe_handler (struct kprobe *p, struct pt_regs *regs)
508 struct kretprobe_instance *ri = NULL;
509 struct hlist_head *head;
510 struct hlist_node *node, *tmp;
511 unsigned long flags, orig_ret_address = 0;
512 unsigned long trampoline_address = (unsigned long) &kretprobe_trampoline;
514 struct kretprobe *crp = NULL;
515 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk ();
520 // in case of user space retprobe trampoline is at the Nth instruction of US tramp
521 if (!thumb_mode( regs ))
522 trampoline_address = (unsigned long)(p->ainsn.insn + UPROBES_TRAMP_RET_BREAK_IDX);
524 trampoline_address = (unsigned long)(p->ainsn.insn) + 0x1b;
527 spin_lock_irqsave (&kretprobe_lock, flags);
530 * We are using different hash keys (current and mm) for finding kernel
531 * space and user space probes. Kernel space probes can change mm field in
532 * task_struct. User space probes can be shared between threads of one
533 * process so they have different current but same mm.
536 head = kretprobe_inst_table_head(current->mm);
538 head = kretprobe_inst_table_head(current);
542 * It is possible to have multiple instances associated with a given
543 * task either because an multiple functions in the call path
544 * have a return probe installed on them, and/or more then one
545 * return probe was registered for a target function.
547 * We can handle this because:
548 * - instances are always inserted at the head of the list
549 * - when multiple return probes are registered for the same
550 * function, the first instance's ret_addr will point to the
551 * real return address, and all the rest will point to
552 * kretprobe_trampoline
554 hlist_for_each_entry_safe (ri, node, tmp, head, hlist)
556 if (ri->task != current)
557 /* another task is sharing our hash bucket */
559 if (ri->rp && ri->rp->handler){
560 ri->rp->handler (ri, regs, ri->rp->priv_arg);
563 orig_ret_address = (unsigned long) ri->ret_addr;
564 recycle_rp_inst (ri);
565 if (orig_ret_address != trampoline_address)
567 * This is the real return address. Any other
568 * instances associated with this task are for
569 * other calls deeper on the call stack
573 kretprobe_assert (ri, orig_ret_address, trampoline_address);
574 //BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
575 //E.G. Check this code in case of __switch_to function instrumentation -- currently this code generates dump in this case
576 //if (trampoline_address != (unsigned long) &kretprobe_trampoline){
577 //if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0);
578 //if (ri->rp) BUG_ON (ri->rp->kp.tgid == 0);
579 //else if (ri->rp2) BUG_ON (ri->rp2->kp.tgid == 0);
581 if ((ri->rp && ri->rp->kp.tgid) || (ri->rp2 && ri->rp2->kp.tgid))
582 BUG_ON (trampoline_address == (unsigned long) &kretprobe_trampoline);
584 regs->uregs[14] = orig_ret_address;
585 DBPRINTF ("regs->uregs[14] = 0x%lx\n", regs->uregs[14]);
586 DBPRINTF ("regs->uregs[15] = 0x%lx\n", regs->uregs[15]);
588 if (trampoline_address != (unsigned long) &kretprobe_trampoline)
590 regs->uregs[15] = orig_ret_address;
592 if (!thumb_mode( regs )) regs->uregs[15] += 4;
593 else regs->uregs[15] += 2;
596 DBPRINTF ("regs->uregs[15] = 0x%lx\n", regs->uregs[15]);
598 if(p){ // ARM, MIPS, X86 user space
599 if (thumb_mode( regs ) && !(regs->uregs[14] & 0x01))
601 regs->ARM_cpsr &= 0xFFFFFFDF;
603 if (user_mode( regs ) && (regs->uregs[14] & 0x01))
605 regs->ARM_cpsr |= 0x20;
609 //TODO: test - enter function, delete us retprobe, exit function
610 // for user space retprobes only - deferred deletion
612 if (trampoline_address != (unsigned long) &kretprobe_trampoline)
614 // if we are not at the end of the list and current retprobe should be disarmed
617 struct hlist_node *current_node = node;
619 /*sprintf(die_msg, "deferred disarm p->addr = %p [%lx %lx %lx]\n",
620 crp->kp.addr, *kaddrs[0], *kaddrs[1], *kaddrs[2]);
621 DIE(die_msg, regs); */
622 // look for other instances for the same retprobe
623 hlist_for_each_entry_safe (ri, node, tmp, head, hlist)
626 * Trying to find another retprobe instance associated with
629 if (ri->rp2 == crp && node != current_node)
635 // if there are no more instances for this retprobe
637 struct kprobe *is_p = &crp->kp;
638 DBPRINTF ("defered retprobe deletion p->addr = %p", crp->kp.addr);
640 If there is no any retprobe instances of this retprobe
641 we can free the resources related to the probe.
643 if (!(hlist_unhashed(&is_p->is_hlist_arm))) {
644 hlist_del_rcu(&is_p->is_hlist_arm);
646 if (!(hlist_unhashed(&is_p->is_hlist_thumb))) {
647 hlist_del_rcu(&is_p->is_hlist_thumb);
650 dbi_unregister_kprobe(&crp->kp, current);
653 hlist_del(current_node);
657 if (kcb->kprobe_status == KPROBE_REENTER) {
658 restore_previous_kprobe(kcb);
660 reset_current_kprobe();
664 spin_unlock_irqrestore (&kretprobe_lock, flags);
667 * By returning a non-zero value, we are telling
668 * kprobe_handler() that we don't want the post_handler
669 * to run (and have re-enabled preemption)
674 EXPORT_SYMBOL_GPL(trampoline_probe_handler);
676 void __arch_prepare_kretprobe (struct kretprobe *rp, struct pt_regs *regs)
678 struct kretprobe_instance *ri;
680 DBPRINTF ("start\n");
681 //TODO: test - remove retprobe after func entry but before its exit
682 if ((ri = get_free_rp_inst (rp)) != NULL)
687 ri->ret_addr = (kprobe_opcode_t *) regs->uregs[14];
688 ri->sp = (kprobe_opcode_t *)regs->ARM_sp; //uregs[13];
690 /* Set flag of current mode */
691 ri->sp = (kprobe_opcode_t *)((long)ri->sp | !!thumb_mode(regs));
694 panic("__arch_prepare_kretprobe: rp->kp.tgid != 0");
697 /* Replace the return addr with trampoline addr */
698 regs->uregs[14] = (unsigned long) &kretprobe_trampoline;
700 // DBPRINTF ("ret addr set to %p->%lx\n", ri->ret_addr, regs->uregs[14]);
704 DBPRINTF ("WARNING: missed retprobe %p\n", rp->kp.addr);
710 int asm_init_module_dependencies(void)
712 //No module dependencies
716 void swap_register_undef_hook(struct undef_hook *hook)
718 __swap_register_undef_hook(hook);
720 EXPORT_SYMBOL_GPL(swap_register_undef_hook);
722 void swap_unregister_undef_hook(struct undef_hook *hook)
724 __swap_unregister_undef_hook(hook);
726 EXPORT_SYMBOL_GPL(swap_unregister_undef_hook);
728 // kernel probes hook
729 static struct undef_hook undef_ho_k = {
730 .instr_mask = 0xffffffff,
731 .instr_val = BREAKPOINT_INSTRUCTION,
732 .cpsr_mask = MODE_MASK,
733 .cpsr_val = SVC_MODE,
734 .fn = kprobe_trap_handler
737 int __init arch_init_kprobes (void)
741 if (arch_init_module_dependencies())
743 DBPRINTF ("Unable to init module dependencies\n");
747 // Register hooks (kprobe_handler)
748 __swap_register_undef_hook = swap_ksyms("register_undef_hook");
749 if (__swap_register_undef_hook == NULL) {
750 printk("no register_undef_hook symbol found!\n");
754 // Unregister hooks (kprobe_handler)
755 __swap_unregister_undef_hook = swap_ksyms("unregister_undef_hook");
756 if (__swap_unregister_undef_hook == NULL) {
757 printk("no unregister_undef_hook symbol found!\n");
761 swap_register_undef_hook(&undef_ho_k);
762 if ((ret = dbi_register_kprobe (&trampoline_p)) != 0) {
763 //dbi_unregister_jprobe(&do_exit_p, 0);
769 void __exit dbi_arch_exit_kprobes (void)
771 swap_unregister_undef_hook(&undef_ho_k);
774 //EXPORT_SYMBOL_GPL (dbi_arch_exit_kprobes);
776 /* export symbol for dbi_kprobes_arm.h */
777 EXPORT_SYMBOL_GPL(gen_insn_execbuf);
778 EXPORT_SYMBOL_GPL(pc_dep_insn_execbuf);