4 * Kernel Probes (KProbes)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Copyright (C) IBM Corporation, 2002, 2004
25 * Dynamic Binary Instrumentation Module based on KProbes
26 * modules/kprobe/dbi_kprobes.h
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
42 * Copyright (C) Samsung Electronics, 2006-2010
44 * 2006-2007 Ekaterina Gorelkina <e.gorelkina@samsung.com>: initial implementation for ARM and MIPS
45 * 2008-2009 Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
46 * Probes initial implementation; Support x86/ARM/MIPS for both user and kernel spaces.
47 * 2010 Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
51 #include "dbi_kprobes.h"
52 #include "arch/dbi_kprobes.h"
53 #include "arch/asm/dbi_kprobes.h"
55 #include "dbi_kdebug.h"
56 #include "dbi_kprobes_deps.h"
57 #include "dbi_insn_slots.h"
58 #include "dbi_uprobes.h"
61 #include <linux/version.h>
62 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
63 #include <linux/config.h>
66 #include <linux/hash.h>
67 #include <linux/module.h>
69 #include <linux/pagemap.h>
71 extern struct hlist_head kprobe_insn_pages;
73 DEFINE_PER_CPU (struct kprobe *, current_kprobe) = NULL;
74 static DEFINE_PER_CPU (struct kprobe_ctlblk, kprobe_ctlblk);
76 DEFINE_SPINLOCK (kretprobe_lock); /* Protects kretprobe_inst_table */
77 static DEFINE_PER_CPU (struct kprobe *, kprobe_instance) = NULL;
79 struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
80 static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
82 atomic_t kprobe_count;
85 void kretprobe_assert (struct kretprobe_instance *ri, unsigned long orig_ret_address, unsigned long trampoline_address)
87 if (!orig_ret_address || (orig_ret_address == trampoline_address)) {
88 struct task_struct *task;
90 panic ("kretprobe BUG!: ri = NULL\n");
96 panic ("kretprobe BUG!: task = NULL\n");
100 panic ("kretprobe BUG!: ri->rp = NULL\n");
103 panic ("kretprobe BUG!: Processing kretprobe %p @ %p (%d/%d - %s)\n",
104 ri->rp, ri->rp->kp.addr, ri->task->tgid, ri->task->pid, ri->task->comm);
109 /* We have preemption disabled.. so it is safe to use __ versions */
111 void set_kprobe_instance (struct kprobe *kp)
113 __get_cpu_var (kprobe_instance) = kp;
117 void reset_kprobe_instance (void)
119 __get_cpu_var (kprobe_instance) = NULL;
122 /* kprobe_running() will just return the current_kprobe on this CPU */
123 struct kprobe *kprobe_running (void)
125 return (__get_cpu_var (current_kprobe));
128 void reset_current_kprobe (void)
130 __get_cpu_var (current_kprobe) = NULL;
133 struct kprobe_ctlblk *get_kprobe_ctlblk (void)
135 return (&__get_cpu_var (kprobe_ctlblk));
139 * This routine is called either:
140 * - under the kprobe_mutex - during kprobe_[un]register()
142 * - with preemption disabled - from arch/xxx/kernel/kprobes.c
144 struct kprobe *get_kprobe(kprobe_opcode_t *addr, pid_t tgid)
146 struct hlist_head *head;
147 struct hlist_node *node;
148 struct kprobe *p, *retVal = NULL;
150 head = &kprobe_table[hash_ptr (addr, KPROBE_HASH_BITS)];
151 hlist_for_each_entry_rcu(p, node, head, hlist) {
152 if (p->addr == addr && p->tgid == tgid) {
158 DBPRINTF ("get_kprobe: probe %p", retVal);
163 * Aggregate handlers for multiple kprobes support - these handlers
164 * take care of invoking the individual kprobe handlers on p->list
167 int aggr_pre_handler (struct kprobe *p, struct pt_regs *regs)
172 list_for_each_entry_rcu (kp, &p->list, list)
176 set_kprobe_instance (kp);
177 ret = kp->pre_handler (kp, regs);
181 reset_kprobe_instance ();
187 void aggr_post_handler (struct kprobe *p, struct pt_regs *regs, unsigned long flags)
191 list_for_each_entry_rcu (kp, &p->list, list)
193 if (kp->post_handler)
195 set_kprobe_instance (kp);
196 kp->post_handler (kp, regs, flags);
197 reset_kprobe_instance ();
203 int aggr_fault_handler (struct kprobe *p, struct pt_regs *regs, int trapnr)
205 struct kprobe *cur = __get_cpu_var (kprobe_instance);
208 * if we faulted "during" the execution of a user specified
209 * probe handler, invoke just that probe's fault handler
211 if (cur && cur->fault_handler)
213 if (cur->fault_handler (cur, regs, trapnr))
220 int aggr_break_handler (struct kprobe *p, struct pt_regs *regs)
222 struct kprobe *cur = __get_cpu_var (kprobe_instance);
224 DBPRINTF ("cur = 0x%p\n", cur);
226 DBPRINTF ("cur = 0x%p cur->break_handler = 0x%p\n", cur, cur->break_handler);
228 if (cur && cur->break_handler)
230 if (cur->break_handler (cur, regs /*, vma, page, kaddr */ ))
233 reset_kprobe_instance ();
237 /* Walks the list and increments nmissed count for multiprobe case */
238 void kprobes_inc_nmissed_count (struct kprobe *p)
241 if (p->pre_handler != aggr_pre_handler)
247 list_for_each_entry_rcu (kp, &p->list, list) kp->nmissed++;
252 /* Called with kretprobe_lock held */
253 struct kretprobe_instance *get_free_rp_inst (struct kretprobe *rp)
255 struct hlist_node *node;
256 struct kretprobe_instance *ri;
257 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
259 if(!alloc_nodes_kretprobe(rp)){
260 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
266 /* Called with kretprobe_lock held */
267 struct kretprobe_instance *get_free_rp_inst_no_alloc (struct kretprobe *rp)
269 struct hlist_node *node;
270 struct kretprobe_instance *ri;
271 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
276 /* Called with kretprobe_lock held */
277 struct kretprobe_instance *get_used_rp_inst (struct kretprobe *rp)
279 struct hlist_node *node;
280 struct kretprobe_instance *ri;
281 hlist_for_each_entry (ri, node, &rp->used_instances, uflist) return ri;
285 /* Called with kretprobe_lock held */
286 void add_rp_inst (struct kretprobe_instance *ri)
289 * Remove rp inst off the free list -
290 * Add it back when probed function returns
292 hlist_del (&ri->uflist);
294 /* Add rp inst onto table */
295 INIT_HLIST_NODE (&ri->hlist);
297 * We are using different hash keys (task and mm) for finding kernel
298 * space and user space probes. Kernel space probes can change mm field in
299 * task_struct. User space probes can be shared between threads of one
300 * process so they have different task but same mm.
302 if (ri->rp->kp.tgid) {
303 hlist_add_head (&ri->hlist, &kretprobe_inst_table[hash_ptr (ri->task->mm, KPROBE_HASH_BITS)]);
305 hlist_add_head (&ri->hlist, &kretprobe_inst_table[hash_ptr (ri->task, KPROBE_HASH_BITS)]);
308 /* Also add this rp inst to the used list. */
309 INIT_HLIST_NODE (&ri->uflist);
310 hlist_add_head (&ri->uflist, &ri->rp->used_instances);
313 /* Called with kretprobe_lock held */
314 void recycle_rp_inst (struct kretprobe_instance *ri)
318 hlist_del (&ri->hlist);
319 /* remove rp inst off the used list */
320 hlist_del (&ri->uflist);
321 /* put rp inst back onto the free list */
322 INIT_HLIST_NODE (&ri->uflist);
323 hlist_add_head (&ri->uflist, &ri->rp->free_instances);
324 } else if (!ri->rp2) {
326 * This is __switch_to retprobe instance. It has neither rp nor rp2.
328 hlist_del (&ri->hlist);
332 int dbi_disarm_urp_inst(struct kretprobe_instance *ri, struct task_struct *rm_task);
334 int dbi_disarm_urp_inst_for_task(struct task_struct *parent, struct task_struct *task)
337 unsigned long table_size, flags;
338 struct kretprobe_instance *ri;
339 struct hlist_node *node, *tmp;
340 struct hlist_head *head;
342 table_size = (1 << KPROBE_HASH_BITS);
344 spin_lock_irqsave(&kretprobe_lock, flags);
345 for (i = 0; i < table_size; ++i) {
346 head = &kretprobe_inst_table[i];
347 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
348 if (parent == ri->task) {
349 dbi_disarm_urp_inst(ri, task);
353 spin_unlock_irqrestore(&kretprobe_lock, flags);
357 EXPORT_SYMBOL_GPL(dbi_disarm_urp_inst_for_task);
359 struct hlist_head * kretprobe_inst_table_head (void *hash_key)
361 return &kretprobe_inst_table[hash_ptr (hash_key, KPROBE_HASH_BITS)];
364 void free_rp_inst (struct kretprobe *rp)
366 struct kretprobe_instance *ri;
367 while ((ri = get_free_rp_inst_no_alloc (rp)) != NULL)
369 hlist_del (&ri->uflist);
375 * Keep all fields in the kprobe consistent
378 void copy_kprobe (struct kprobe *old_p, struct kprobe *p)
380 memcpy (&p->opcode, &old_p->opcode, sizeof (kprobe_opcode_t));
381 memcpy (&p->ainsn, &old_p->ainsn, sizeof (struct arch_specific_insn));
382 p->tgid = old_p->tgid;
383 p->ss_addr = old_p->ss_addr;
385 p->safe_arm = old_p->safe_arm;
386 p->safe_thumb = old_p->safe_thumb;
388 //p->spid = old_p->spid;
392 * Add the new probe to old_p->list. Fail if this is the
393 * second jprobe at the address - two jprobes can't coexist
395 static int add_new_kprobe (struct kprobe *old_p, struct kprobe *p)
397 if (p->break_handler)
399 if (old_p->break_handler)
401 list_add_tail_rcu (&p->list, &old_p->list);
402 old_p->break_handler = aggr_break_handler;
405 list_add_rcu (&p->list, &old_p->list);
406 if (p->post_handler && !old_p->post_handler)
407 old_p->post_handler = aggr_post_handler;
412 * hlist_replace_rcu - replace old entry by new one
413 * @old : the element to be replaced
414 * @new : the new element to insert
416 * The @old entry will be replaced with the @new entry atomically.
418 inline void dbi_hlist_replace_rcu (struct hlist_node *old, struct hlist_node *new)
420 struct hlist_node *next = old->next;
423 new->pprev = old->pprev;
426 new->next->pprev = &new->next;
429 old->pprev = LIST_POISON2;
434 * Fill in the required fields of the "manager kprobe". Replace the
435 * earlier kprobe in the hlist with the manager kprobe
438 void add_aggr_kprobe (struct kprobe *ap, struct kprobe *p)
441 //flush_insn_slot (ap);
443 ap->pre_handler = aggr_pre_handler;
444 ap->fault_handler = aggr_fault_handler;
446 ap->post_handler = aggr_post_handler;
447 if (p->break_handler)
448 ap->break_handler = aggr_break_handler;
450 INIT_LIST_HEAD (&ap->list);
451 list_add_rcu (&p->list, &ap->list);
453 dbi_hlist_replace_rcu (&p->hlist, &ap->hlist);
457 * This is the second or subsequent kprobe at the address - handle
460 int register_aggr_kprobe (struct kprobe *old_p, struct kprobe *p)
464 DBPRINTF ("start\n");
466 DBPRINTF ("p = %p old_p = %p \n", p, old_p);
467 if (old_p->pre_handler == aggr_pre_handler)
469 DBPRINTF ("aggr_pre_handler \n");
471 copy_kprobe (old_p, p);
472 ret = add_new_kprobe (old_p, p);
476 DBPRINTF ("kzalloc\n");
479 ap = kzalloc (sizeof (struct kprobe), GFP_KERNEL);
481 ap = kmalloc (sizeof (struct kprobe), GFP_KERNEL);
483 memset (ap, 0, sizeof (struct kprobe));
487 add_aggr_kprobe (ap, old_p);
489 DBPRINTF ("ap = %p p = %p old_p = %p \n", ap, p, old_p);
490 ret = add_new_kprobe (ap, p);
495 int dbi_register_kprobe (struct kprobe *p)
497 struct kprobe *old_p;
500 * If we have a symbol_name argument look it up,
501 * and add it to the address. That way the addr
502 * field can either be global or relative to a symbol.
508 p->addr = (kprobe_opcode_t *)swap_ksyms(p->symbol_name);
513 DBPRINTF ("p->addr = 0x%p\n", p->addr);
514 p->addr = (kprobe_opcode_t *) (((char *) p->addr) + p->offset);
515 DBPRINTF ("p->addr = 0x%p p = 0x%p\n", p->addr, p);
517 #ifdef KPROBES_PROFILE
518 p->start_tm.tv_sec = p->start_tm.tv_usec = 0;
519 p->hnd_tm_sum.tv_sec = p->hnd_tm_sum.tv_usec = 0;
522 p->mod_refcounted = 0;
525 old_p = get_kprobe(p->addr, 0);
528 ret = register_aggr_kprobe (old_p, p);
530 atomic_inc (&kprobe_count);
534 if ((ret = arch_prepare_kprobe (p)) != 0)
537 DBPRINTF ("before out ret = 0x%x\n", ret);
538 INIT_HLIST_NODE (&p->hlist);
539 hlist_add_head_rcu (&p->hlist, &kprobe_table[hash_ptr (p->addr, KPROBE_HASH_BITS)]);
543 DBPRINTF ("out ret = 0x%x\n", ret);
547 void dbi_unregister_kprobe (struct kprobe *p, struct task_struct *task)
549 struct kprobe *old_p, *list_p;
550 int cleanup_p, pid = p->tgid;
552 old_p = get_kprobe(p->addr, pid);
553 DBPRINTF ("dbi_unregister_kprobe p=%p old_p=%p", p, old_p);
554 if (unlikely (!old_p))
559 list_for_each_entry_rcu (list_p, &old_p->list, list)
561 /* kprobe p is a valid probe */
567 DBPRINTF ("dbi_unregister_kprobe valid_p");
568 if ((old_p == p) || ((old_p->pre_handler == aggr_pre_handler) &&
569 (p->list.next == &old_p->list) && (p->list.prev == &old_p->list)))
571 /* Only probe on the hash list */
572 DBPRINTF ("dbi_unregister_kprobe disarm pid=%d", pid);
574 arch_disarm_uprobe (p, task);//vma, page, kaddr);
576 arch_disarm_kprobe (p);
577 hlist_del_rcu (&old_p->hlist);
582 list_del_rcu (&p->list);
585 DBPRINTF ("dbi_unregister_kprobe cleanup_p=%d", cleanup_p);
591 list_del_rcu (&p->list);
594 arch_remove_kprobe (p, task);
598 if (p->break_handler)
599 old_p->break_handler = NULL;
602 list_for_each_entry_rcu (list_p, &old_p->list, list)
604 if (list_p->post_handler)
611 old_p->post_handler = NULL;
616 int dbi_register_jprobe (struct jprobe *jp)
618 /* Todo: Verify probepoint is a function entry point */
619 jp->kp.pre_handler = setjmp_pre_handler;
620 jp->kp.break_handler = longjmp_break_handler;
622 return dbi_register_kprobe (&jp->kp);
625 void dbi_unregister_jprobe (struct jprobe *jp)
627 dbi_unregister_kprobe (&jp->kp, NULL);
631 * This kprobe pre_handler is registered with every kretprobe. When probe
632 * hits it will set up the return probe.
634 int pre_handler_kretprobe (struct kprobe *p, struct pt_regs *regs)
636 struct kretprobe *rp = container_of (p, struct kretprobe, kp);
637 unsigned long flags = 0;
638 DBPRINTF ("START\n");
640 /*TODO: consider to only swap the RA after the last pre_handler fired */
641 spin_lock_irqsave (&kretprobe_lock, flags);
643 __arch_prepare_kretprobe (rp, regs);
644 spin_unlock_irqrestore (&kretprobe_lock, flags);
649 struct kretprobe *sched_rp;
651 #define SCHED_RP_NR 200
652 #define COMMON_RP_NR 10
654 int alloc_nodes_kretprobe(struct kretprobe *rp)
657 struct kretprobe_instance *inst;
660 DBPRINTF("Alloc aditional mem for retprobes");
662 if ((unsigned long)rp->kp.addr == sched_addr){
663 rp->maxactive += SCHED_RP_NR;//max (100, 2 * NR_CPUS);
664 alloc_nodes = SCHED_RP_NR;
668 #if 1//def CONFIG_PREEMPT
669 rp->maxactive += max (COMMON_RP_NR, 2 * NR_CPUS);
671 rp->maxacpptive += NR_CPUS;
673 alloc_nodes = COMMON_RP_NR;
675 /* INIT_HLIST_HEAD (&rp->used_instances); */
676 /* INIT_HLIST_HEAD (&rp->free_instances); */
677 for (i = 0; i < alloc_nodes; i++)
679 inst = kmalloc (sizeof (struct kretprobe_instance), GFP_ATOMIC);
685 INIT_HLIST_NODE (&inst->uflist);
686 hlist_add_head (&inst->uflist, &rp->free_instances);
689 DBPRINTF ("addr=%p, *addr=[%lx %lx %lx]", rp->kp.addr, (unsigned long) (*(rp->kp.addr)), (unsigned long) (*(rp->kp.addr + 1)), (unsigned long) (*(rp->kp.addr + 2)));
693 int dbi_register_kretprobe (struct kretprobe *rp)
696 struct kretprobe_instance *inst;
700 rp->kp.pre_handler = pre_handler_kretprobe;
701 rp->kp.post_handler = NULL;
702 rp->kp.fault_handler = NULL;
703 rp->kp.break_handler = NULL;
707 /* Pre-allocate memory for max kretprobe instances */
708 if ((unsigned long)rp->kp.addr == sched_addr) {
709 rp->maxactive = SCHED_RP_NR;//max (100, 2 * NR_CPUS);
710 rp->kp.pre_handler = NULL; //not needed for __switch_to
711 } else if ((unsigned long)rp->kp.addr == exit_addr) {
712 rp->kp.pre_handler = NULL; //not needed for do_exit
714 } else if (rp->maxactive <= 0) {
715 #if 1//def CONFIG_PREEMPT
716 rp->maxactive = max (COMMON_RP_NR, 2 * NR_CPUS);
718 rp->maxactive = NR_CPUS;
721 INIT_HLIST_HEAD (&rp->used_instances);
722 INIT_HLIST_HEAD (&rp->free_instances);
723 for (i = 0; i < rp->maxactive; i++)
725 inst = kmalloc (sizeof (struct kretprobe_instance), GFP_KERNEL);
731 INIT_HLIST_NODE (&inst->uflist);
732 hlist_add_head (&inst->uflist, &rp->free_instances);
735 DBPRINTF ("addr=%p, *addr=[%lx %lx %lx]", rp->kp.addr, (unsigned long) (*(rp->kp.addr)), (unsigned long) (*(rp->kp.addr + 1)), (unsigned long) (*(rp->kp.addr + 2)));
737 /* Establish function entry probe point */
738 if ((ret = dbi_register_kprobe (&rp->kp)) != 0)
741 DBPRINTF ("addr=%p, *addr=[%lx %lx %lx]", rp->kp.addr, (unsigned long) (*(rp->kp.addr)), (unsigned long) (*(rp->kp.addr + 1)), (unsigned long) (*(rp->kp.addr + 2)));
742 if ((unsigned long)rp->kp.addr == sched_addr) {
749 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri);
751 void dbi_unregister_kretprobe (struct kretprobe *rp)
754 struct kretprobe_instance *ri;
756 dbi_unregister_kprobe (&rp->kp, NULL);
759 spin_lock_irqsave (&kretprobe_lock, flags);
761 if ((unsigned long)rp->kp.addr == sched_addr)
764 while ((ri = get_used_rp_inst (rp)) != NULL) {
765 if (dbi_disarm_krp_inst(ri) == 0)
768 panic("%s (%d/%d): cannot disarm krp instance (%08lx)",
769 ri->task->comm, ri->task->tgid, ri->task->pid,
770 (unsigned long)rp->kp.addr);
773 spin_unlock_irqrestore (&kretprobe_lock, flags);
777 struct kretprobe * clone_kretprobe (struct kretprobe *rp)
779 struct kprobe *old_p;
780 struct kretprobe *clone = NULL;
783 clone = kmalloc (sizeof (struct kretprobe), GFP_KERNEL);
786 DBPRINTF ("failed to alloc memory for clone probe %p!", rp->kp.addr);
789 memcpy (clone, rp, sizeof (struct kretprobe));
790 clone->kp.pre_handler = pre_handler_kretprobe;
791 clone->kp.post_handler = NULL;
792 clone->kp.fault_handler = NULL;
793 clone->kp.break_handler = NULL;
794 old_p = get_kprobe(rp->kp.addr, rp->kp.tgid);
797 ret = register_aggr_kprobe (old_p, &clone->kp);
803 atomic_inc (&kprobe_count);
809 static void inline set_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri, unsigned long tramp_addr)
811 unsigned long pc = arch_get_task_pc(p);
812 if (pc == tramp_addr)
813 panic("[%d] %s (%d/%d): pc = %08lx --- [%d] %s (%d/%d)\n",
814 task_cpu(p), p->comm, p->tgid, p->pid, pc,
815 task_cpu(current), current->comm, current->tgid, current->pid);
816 ri->ret_addr = (kprobe_opcode_t *)pc;
817 arch_set_task_pc(p, tramp_addr);
820 static void inline rm_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri)
822 arch_set_task_pc(p, (unsigned long)ri->ret_addr);
825 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri)
827 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
828 kprobe_opcode_t *sp = ri->sp;
829 kprobe_opcode_t *found = NULL;
830 int retval = -ENOENT;
833 unsigned long pc = arch_get_task_pc(ri->task);
835 printk("---> [%d] %s (%d/%d): pc = %08lx, ra = %08lx, tramp= %08lx (%08lx)\n",
837 ri->task->comm, ri->task->tgid, ri->task->pid,
838 pc, (unsigned long)ri->ret_addr,
839 (unsigned long)tramp,
840 (unsigned long)(ri->rp ? ri->rp->kp.addr: NULL));
842 /* __switch_to retprobe handling */
843 if (pc == (unsigned long)tramp) {
844 rm_task_trampoline(ri->task, ri);
851 while (sp > ri->sp - RETPROBE_STACK_DEPTH) {
852 if ((unsigned long)*sp == (unsigned long)tramp) {
860 printk("---> [%d] %s (%d/%d): tramp (%08lx) found at %08lx (%08lx /%+d) - %p\n",
862 ri->task->comm, ri->task->tgid, ri->task->pid,
863 (unsigned long)tramp,
864 (unsigned long)found, (unsigned long)ri->sp, found - ri->sp,
865 ri->rp ? ri->rp->kp.addr: NULL);
866 *found = (unsigned long)ri->ret_addr;
869 printk("---> [%d] %s (%d/%d): tramp (%08lx) NOT found at sp = %08lx - %p\n",
871 ri->task->comm, ri->task->tgid, ri->task->pid,
872 (unsigned long)tramp,
873 (unsigned long)ri->sp, ri->rp ? ri->rp->kp.addr: NULL);
879 int patch_suspended_task(struct kretprobe *rp, struct task_struct *task)
881 struct kretprobe_instance *ri;
883 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
885 spin_lock_irqsave(&kretprobe_lock, flags);
887 ri = get_free_rp_inst(rp);
895 set_task_trampoline(task, ri, (unsigned long)tramp);
898 spin_unlock_irqrestore(&kretprobe_lock, flags);
902 static int __init init_kprobes (void)
906 /* FIXME allocate the probe table, currently defined statically */
907 /* initialize all list heads */
908 for (i = 0; i < KPROBE_TABLE_SIZE; i++)
910 INIT_HLIST_HEAD (&kprobe_table[i]);
911 INIT_HLIST_HEAD (&kretprobe_inst_table[i]);
913 init_uprobes_insn_slots(i);
915 atomic_set (&kprobe_count, 0);
917 err = arch_init_kprobes ();
919 DBPRINTF ("init_kprobes: arch_init_kprobes - %d", err);
924 static void __exit exit_kprobes (void)
926 dbi_arch_exit_kprobes ();
929 module_init (init_kprobes);
930 module_exit (exit_kprobes);
932 EXPORT_SYMBOL_GPL (dbi_register_kprobe);
933 EXPORT_SYMBOL_GPL (dbi_unregister_kprobe);
934 EXPORT_SYMBOL_GPL (dbi_register_jprobe);
935 EXPORT_SYMBOL_GPL (dbi_unregister_jprobe);
936 EXPORT_SYMBOL_GPL (dbi_jprobe_return);
937 EXPORT_SYMBOL_GPL (dbi_register_kretprobe);
938 EXPORT_SYMBOL_GPL (dbi_unregister_kretprobe);
940 MODULE_LICENSE ("Dual BSD/GPL");