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;
84 void kretprobe_assert (struct kretprobe_instance *ri, unsigned long orig_ret_address, unsigned long trampoline_address)
86 if (!orig_ret_address || (orig_ret_address == trampoline_address)) {
87 struct task_struct *task;
89 panic ("kretprobe BUG!: ri = NULL\n");
95 panic ("kretprobe BUG!: task = NULL\n");
99 panic ("kretprobe BUG!: ri->rp = NULL\n");
102 panic ("kretprobe BUG!: Processing kretprobe %p @ %p (%d/%d - %s)\n",
103 ri->rp, ri->rp->kp.addr, ri->task->tgid, ri->task->pid, ri->task->comm);
108 /* We have preemption disabled.. so it is safe to use __ versions */
110 void set_kprobe_instance (struct kprobe *kp)
112 __get_cpu_var (kprobe_instance) = kp;
116 void reset_kprobe_instance (void)
118 __get_cpu_var (kprobe_instance) = NULL;
121 /* kprobe_running() will just return the current_kprobe on this CPU */
122 struct kprobe *kprobe_running (void)
124 return (__get_cpu_var (current_kprobe));
127 void reset_current_kprobe (void)
129 __get_cpu_var (current_kprobe) = NULL;
132 struct kprobe_ctlblk *get_kprobe_ctlblk (void)
134 return (&__get_cpu_var (kprobe_ctlblk));
138 * This routine is called either:
139 * - under the kprobe_mutex - during kprobe_[un]register()
141 * - with preemption disabled - from arch/xxx/kernel/kprobes.c
143 struct kprobe *get_kprobe(kprobe_opcode_t *addr, pid_t tgid)
145 struct hlist_head *head;
146 struct hlist_node *node;
147 struct kprobe *p, *retVal = NULL;
149 head = &kprobe_table[hash_ptr (addr, KPROBE_HASH_BITS)];
150 hlist_for_each_entry_rcu(p, node, head, hlist) {
151 if (p->addr == addr && p->tgid == tgid) {
157 DBPRINTF ("get_kprobe: probe %p", retVal);
162 * Aggregate handlers for multiple kprobes support - these handlers
163 * take care of invoking the individual kprobe handlers on p->list
166 int aggr_pre_handler (struct kprobe *p, struct pt_regs *regs)
171 list_for_each_entry_rcu (kp, &p->list, list)
175 set_kprobe_instance (kp);
176 ret = kp->pre_handler (kp, regs);
180 reset_kprobe_instance ();
186 void aggr_post_handler (struct kprobe *p, struct pt_regs *regs, unsigned long flags)
190 list_for_each_entry_rcu (kp, &p->list, list)
192 if (kp->post_handler)
194 set_kprobe_instance (kp);
195 kp->post_handler (kp, regs, flags);
196 reset_kprobe_instance ();
202 int aggr_fault_handler (struct kprobe *p, struct pt_regs *regs, int trapnr)
204 struct kprobe *cur = __get_cpu_var (kprobe_instance);
207 * if we faulted "during" the execution of a user specified
208 * probe handler, invoke just that probe's fault handler
210 if (cur && cur->fault_handler)
212 if (cur->fault_handler (cur, regs, trapnr))
219 int aggr_break_handler (struct kprobe *p, struct pt_regs *regs)
221 struct kprobe *cur = __get_cpu_var (kprobe_instance);
223 DBPRINTF ("cur = 0x%p\n", cur);
225 DBPRINTF ("cur = 0x%p cur->break_handler = 0x%p\n", cur, cur->break_handler);
227 if (cur && cur->break_handler)
229 if (cur->break_handler (cur, regs /*, vma, page, kaddr */ ))
232 reset_kprobe_instance ();
236 /* Walks the list and increments nmissed count for multiprobe case */
237 void kprobes_inc_nmissed_count (struct kprobe *p)
240 if (p->pre_handler != aggr_pre_handler)
246 list_for_each_entry_rcu (kp, &p->list, list) kp->nmissed++;
251 /* Called with kretprobe_lock held */
252 struct kretprobe_instance *get_free_rp_inst (struct kretprobe *rp)
254 struct hlist_node *node;
255 struct kretprobe_instance *ri;
256 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
258 if(!alloc_nodes_kretprobe(rp)){
259 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
265 /* Called with kretprobe_lock held */
266 struct kretprobe_instance *get_free_rp_inst_no_alloc (struct kretprobe *rp)
268 struct hlist_node *node;
269 struct kretprobe_instance *ri;
270 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
275 /* Called with kretprobe_lock held */
276 struct kretprobe_instance *get_used_rp_inst (struct kretprobe *rp)
278 struct hlist_node *node;
279 struct kretprobe_instance *ri;
280 hlist_for_each_entry (ri, node, &rp->used_instances, uflist) return ri;
284 /* Called with kretprobe_lock held */
285 void add_rp_inst (struct kretprobe_instance *ri)
288 * Remove rp inst off the free list -
289 * Add it back when probed function returns
291 hlist_del (&ri->uflist);
293 /* Add rp inst onto table */
294 INIT_HLIST_NODE (&ri->hlist);
296 * We are using different hash keys (task and mm) for finding kernel
297 * space and user space probes. Kernel space probes can change mm field in
298 * task_struct. User space probes can be shared between threads of one
299 * process so they have different task but same mm.
301 if (ri->rp->kp.tgid) {
302 hlist_add_head (&ri->hlist, &kretprobe_inst_table[hash_ptr (ri->task->mm, KPROBE_HASH_BITS)]);
304 hlist_add_head (&ri->hlist, &kretprobe_inst_table[hash_ptr (ri->task, KPROBE_HASH_BITS)]);
307 /* Also add this rp inst to the used list. */
308 INIT_HLIST_NODE (&ri->uflist);
309 hlist_add_head (&ri->uflist, &ri->rp->used_instances);
312 /* Called with kretprobe_lock held */
313 void recycle_rp_inst (struct kretprobe_instance *ri)
317 hlist_del (&ri->hlist);
318 /* remove rp inst off the used list */
319 hlist_del (&ri->uflist);
320 /* put rp inst back onto the free list */
321 INIT_HLIST_NODE (&ri->uflist);
322 hlist_add_head (&ri->uflist, &ri->rp->free_instances);
323 } else if (!ri->rp2) {
325 * This is __switch_to retprobe instance. It has neither rp nor rp2.
327 hlist_del (&ri->hlist);
331 int dbi_disarm_urp_inst(struct kretprobe_instance *ri, struct task_struct *rm_task);
333 /* Called with kretprobe_lock held */
334 int dbi_disarm_urp_inst_for_task(struct task_struct *parent, struct task_struct *task)
336 struct kretprobe_instance *ri;
337 struct hlist_node *node, *tmp;
338 struct hlist_head *head = kretprobe_inst_table_head(parent->mm);
340 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
341 if (parent == ri->task && ri->rp->kp.tgid) {
342 dbi_disarm_urp_inst(ri, task);
348 EXPORT_SYMBOL_GPL(dbi_disarm_urp_inst_for_task);
350 struct hlist_head * kretprobe_inst_table_head (void *hash_key)
352 return &kretprobe_inst_table[hash_ptr (hash_key, KPROBE_HASH_BITS)];
355 void free_rp_inst (struct kretprobe *rp)
357 struct kretprobe_instance *ri;
358 while ((ri = get_free_rp_inst_no_alloc (rp)) != NULL)
360 hlist_del (&ri->uflist);
366 * Keep all fields in the kprobe consistent
369 void copy_kprobe (struct kprobe *old_p, struct kprobe *p)
371 memcpy (&p->opcode, &old_p->opcode, sizeof (kprobe_opcode_t));
372 memcpy (&p->ainsn, &old_p->ainsn, sizeof (struct arch_specific_insn));
373 p->tgid = old_p->tgid;
374 p->ss_addr = old_p->ss_addr;
376 p->safe_arm = old_p->safe_arm;
377 p->safe_thumb = old_p->safe_thumb;
379 //p->spid = old_p->spid;
383 * Add the new probe to old_p->list. Fail if this is the
384 * second jprobe at the address - two jprobes can't coexist
386 static int add_new_kprobe (struct kprobe *old_p, struct kprobe *p)
388 if (p->break_handler)
390 if (old_p->break_handler)
392 list_add_tail_rcu (&p->list, &old_p->list);
393 old_p->break_handler = aggr_break_handler;
396 list_add_rcu (&p->list, &old_p->list);
397 if (p->post_handler && !old_p->post_handler)
398 old_p->post_handler = aggr_post_handler;
403 * hlist_replace_rcu - replace old entry by new one
404 * @old : the element to be replaced
405 * @new : the new element to insert
407 * The @old entry will be replaced with the @new entry atomically.
409 inline void dbi_hlist_replace_rcu (struct hlist_node *old, struct hlist_node *new)
411 struct hlist_node *next = old->next;
414 new->pprev = old->pprev;
417 new->next->pprev = &new->next;
420 old->pprev = LIST_POISON2;
425 * Fill in the required fields of the "manager kprobe". Replace the
426 * earlier kprobe in the hlist with the manager kprobe
429 void add_aggr_kprobe (struct kprobe *ap, struct kprobe *p)
432 //flush_insn_slot (ap);
434 ap->pre_handler = aggr_pre_handler;
435 ap->fault_handler = aggr_fault_handler;
437 ap->post_handler = aggr_post_handler;
438 if (p->break_handler)
439 ap->break_handler = aggr_break_handler;
441 INIT_LIST_HEAD (&ap->list);
442 list_add_rcu (&p->list, &ap->list);
444 dbi_hlist_replace_rcu (&p->hlist, &ap->hlist);
448 * This is the second or subsequent kprobe at the address - handle
451 int register_aggr_kprobe (struct kprobe *old_p, struct kprobe *p)
455 DBPRINTF ("start\n");
457 DBPRINTF ("p = %p old_p = %p \n", p, old_p);
458 if (old_p->pre_handler == aggr_pre_handler)
460 DBPRINTF ("aggr_pre_handler \n");
462 copy_kprobe (old_p, p);
463 ret = add_new_kprobe (old_p, p);
467 DBPRINTF ("kzalloc\n");
470 ap = kzalloc (sizeof (struct kprobe), GFP_KERNEL);
472 ap = kmalloc (sizeof (struct kprobe), GFP_KERNEL);
474 memset (ap, 0, sizeof (struct kprobe));
478 add_aggr_kprobe (ap, old_p);
480 DBPRINTF ("ap = %p p = %p old_p = %p \n", ap, p, old_p);
481 ret = add_new_kprobe (ap, p);
486 int dbi_register_kprobe (struct kprobe *p)
488 struct kprobe *old_p;
491 * If we have a symbol_name argument look it up,
492 * and add it to the address. That way the addr
493 * field can either be global or relative to a symbol.
499 p->addr = (kprobe_opcode_t *)swap_ksyms(p->symbol_name);
504 DBPRINTF ("p->addr = 0x%p\n", p->addr);
505 p->addr = (kprobe_opcode_t *) (((char *) p->addr) + p->offset);
506 DBPRINTF ("p->addr = 0x%p p = 0x%p\n", p->addr, p);
508 #ifdef KPROBES_PROFILE
509 p->start_tm.tv_sec = p->start_tm.tv_usec = 0;
510 p->hnd_tm_sum.tv_sec = p->hnd_tm_sum.tv_usec = 0;
513 p->mod_refcounted = 0;
516 old_p = get_kprobe(p->addr, 0);
519 ret = register_aggr_kprobe (old_p, p);
521 atomic_inc (&kprobe_count);
525 if ((ret = arch_prepare_kprobe (p)) != 0)
528 DBPRINTF ("before out ret = 0x%x\n", ret);
529 INIT_HLIST_NODE (&p->hlist);
530 hlist_add_head_rcu (&p->hlist, &kprobe_table[hash_ptr (p->addr, KPROBE_HASH_BITS)]);
534 DBPRINTF ("out ret = 0x%x\n", ret);
538 void dbi_unregister_kprobe (struct kprobe *p, struct task_struct *task)
540 struct kprobe *old_p, *list_p;
541 int cleanup_p, pid = p->tgid;
543 old_p = get_kprobe(p->addr, pid);
544 DBPRINTF ("dbi_unregister_kprobe p=%p old_p=%p", p, old_p);
545 if (unlikely (!old_p))
550 list_for_each_entry_rcu (list_p, &old_p->list, list)
552 /* kprobe p is a valid probe */
558 DBPRINTF ("dbi_unregister_kprobe valid_p");
559 if ((old_p == p) || ((old_p->pre_handler == aggr_pre_handler) &&
560 (p->list.next == &old_p->list) && (p->list.prev == &old_p->list)))
562 /* Only probe on the hash list */
563 DBPRINTF ("dbi_unregister_kprobe disarm pid=%d", pid);
565 arch_disarm_uprobe (p, task);//vma, page, kaddr);
567 arch_disarm_kprobe (p);
568 hlist_del_rcu (&old_p->hlist);
573 list_del_rcu (&p->list);
576 DBPRINTF ("dbi_unregister_kprobe cleanup_p=%d", cleanup_p);
582 list_del_rcu (&p->list);
590 arch_remove_kprobe (p, task);
594 if (p->break_handler)
595 old_p->break_handler = NULL;
598 list_for_each_entry_rcu (list_p, &old_p->list, list)
600 if (list_p->post_handler)
607 old_p->post_handler = NULL;
612 int dbi_register_jprobe (struct jprobe *jp)
614 /* Todo: Verify probepoint is a function entry point */
615 jp->kp.pre_handler = setjmp_pre_handler;
616 jp->kp.break_handler = longjmp_break_handler;
618 return dbi_register_kprobe (&jp->kp);
621 void dbi_unregister_jprobe (struct jprobe *jp)
623 dbi_unregister_kprobe (&jp->kp, NULL);
627 * This kprobe pre_handler is registered with every kretprobe. When probe
628 * hits it will set up the return probe.
630 int pre_handler_kretprobe (struct kprobe *p, struct pt_regs *regs)
632 struct kretprobe *rp = container_of (p, struct kretprobe, kp);
633 unsigned long flags = 0;
634 DBPRINTF ("START\n");
636 /*TODO: consider to only swap the RA after the last pre_handler fired */
637 spin_lock_irqsave (&kretprobe_lock, flags);
639 __arch_prepare_kretprobe (rp, regs);
640 spin_unlock_irqrestore (&kretprobe_lock, flags);
645 struct kretprobe *sched_rp;
647 #define SCHED_RP_NR 200
648 #define COMMON_RP_NR 10
650 int alloc_nodes_kretprobe(struct kretprobe *rp)
653 struct kretprobe_instance *inst;
656 DBPRINTF("Alloc aditional mem for retprobes");
658 if ((unsigned long)rp->kp.addr == sched_addr){
659 rp->maxactive += SCHED_RP_NR;//max (100, 2 * NR_CPUS);
660 alloc_nodes = SCHED_RP_NR;
664 #if 1//def CONFIG_PREEMPT
665 rp->maxactive += max (COMMON_RP_NR, 2 * NR_CPUS);
667 rp->maxacpptive += NR_CPUS;
669 alloc_nodes = COMMON_RP_NR;
671 /* INIT_HLIST_HEAD (&rp->used_instances); */
672 /* INIT_HLIST_HEAD (&rp->free_instances); */
673 for (i = 0; i < alloc_nodes; i++)
675 inst = kmalloc (sizeof (struct kretprobe_instance), GFP_ATOMIC);
681 INIT_HLIST_NODE (&inst->uflist);
682 hlist_add_head (&inst->uflist, &rp->free_instances);
685 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)));
689 int dbi_register_kretprobe (struct kretprobe *rp)
692 struct kretprobe_instance *inst;
696 rp->kp.pre_handler = pre_handler_kretprobe;
697 rp->kp.post_handler = NULL;
698 rp->kp.fault_handler = NULL;
699 rp->kp.break_handler = NULL;
703 /* Pre-allocate memory for max kretprobe instances */
704 if ((unsigned long)rp->kp.addr == sched_addr) {
705 rp->maxactive = SCHED_RP_NR;//max (100, 2 * NR_CPUS);
706 rp->kp.pre_handler = NULL; //not needed for __switch_to
707 } else if ((unsigned long)rp->kp.addr == exit_addr) {
708 rp->kp.pre_handler = NULL; //not needed for do_exit
710 } else if (rp->maxactive <= 0) {
711 #if 1//def CONFIG_PREEMPT
712 rp->maxactive = max (COMMON_RP_NR, 2 * NR_CPUS);
714 rp->maxactive = NR_CPUS;
717 INIT_HLIST_HEAD (&rp->used_instances);
718 INIT_HLIST_HEAD (&rp->free_instances);
719 for (i = 0; i < rp->maxactive; i++)
721 inst = kmalloc (sizeof (struct kretprobe_instance), GFP_KERNEL);
727 INIT_HLIST_NODE (&inst->uflist);
728 hlist_add_head (&inst->uflist, &rp->free_instances);
731 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)));
733 /* Establish function entry probe point */
734 if ((ret = dbi_register_kprobe (&rp->kp)) != 0)
737 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)));
738 if ((unsigned long)rp->kp.addr == sched_addr) {
745 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri);
747 void dbi_unregister_kretprobe (struct kretprobe *rp)
750 struct kretprobe_instance *ri;
752 dbi_unregister_kprobe (&rp->kp, NULL);
755 spin_lock_irqsave (&kretprobe_lock, flags);
757 if ((unsigned long)rp->kp.addr == sched_addr)
760 while ((ri = get_used_rp_inst (rp)) != NULL) {
761 if (dbi_disarm_krp_inst(ri) == 0)
764 panic("%s (%d/%d): cannot disarm krp instance (%08lx)",
765 ri->task->comm, ri->task->tgid, ri->task->pid,
766 (unsigned long)rp->kp.addr);
769 spin_unlock_irqrestore (&kretprobe_lock, flags);
773 struct kretprobe * clone_kretprobe (struct kretprobe *rp)
775 struct kprobe *old_p;
776 struct kretprobe *clone = NULL;
779 clone = kmalloc (sizeof (struct kretprobe), GFP_KERNEL);
782 DBPRINTF ("failed to alloc memory for clone probe %p!", rp->kp.addr);
785 memcpy (clone, rp, sizeof (struct kretprobe));
786 clone->kp.pre_handler = pre_handler_kretprobe;
787 clone->kp.post_handler = NULL;
788 clone->kp.fault_handler = NULL;
789 clone->kp.break_handler = NULL;
790 old_p = get_kprobe(rp->kp.addr, rp->kp.tgid);
793 ret = register_aggr_kprobe (old_p, &clone->kp);
799 atomic_inc (&kprobe_count);
805 static void inline set_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri, unsigned long tramp_addr)
807 unsigned long pc = arch_get_task_pc(p);
808 if (pc == tramp_addr)
809 panic("[%d] %s (%d/%d): pc = %08lx --- [%d] %s (%d/%d)\n",
810 task_cpu(p), p->comm, p->tgid, p->pid, pc,
811 task_cpu(current), current->comm, current->tgid, current->pid);
812 ri->ret_addr = (kprobe_opcode_t *)pc;
813 arch_set_task_pc(p, tramp_addr);
816 static void inline rm_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri)
818 arch_set_task_pc(p, (unsigned long)ri->ret_addr);
821 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri)
823 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
824 kprobe_opcode_t *sp = ri->sp;
825 kprobe_opcode_t *found = NULL;
826 int retval = -ENOENT;
829 unsigned long pc = arch_get_task_pc(ri->task);
831 printk("---> [%d] %s (%d/%d): pc = %08lx, ra = %08lx, tramp= %08lx (%08lx)\n",
833 ri->task->comm, ri->task->tgid, ri->task->pid,
834 pc, (unsigned long)ri->ret_addr,
835 (unsigned long)tramp,
836 (unsigned long)(ri->rp ? ri->rp->kp.addr: NULL));
838 /* __switch_to retprobe handling */
839 if (pc == (unsigned long)tramp) {
840 rm_task_trampoline(ri->task, ri);
847 while (sp > ri->sp - RETPROBE_STACK_DEPTH) {
848 if ((unsigned long)*sp == (unsigned long)tramp) {
856 printk("---> [%d] %s (%d/%d): tramp (%08lx) found at %08lx (%08lx /%+d) - %p\n",
858 ri->task->comm, ri->task->tgid, ri->task->pid,
859 (unsigned long)tramp,
860 (unsigned long)found, (unsigned long)ri->sp, found - ri->sp,
861 ri->rp ? ri->rp->kp.addr: NULL);
862 *found = (unsigned long)ri->ret_addr;
865 printk("---> [%d] %s (%d/%d): tramp (%08lx) NOT found at sp = %08lx - %p\n",
867 ri->task->comm, ri->task->tgid, ri->task->pid,
868 (unsigned long)tramp,
869 (unsigned long)ri->sp, ri->rp ? ri->rp->kp.addr: NULL);
875 int patch_suspended_task(struct kretprobe *rp, struct task_struct *task)
877 struct kretprobe_instance *ri;
879 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
881 spin_lock_irqsave(&kretprobe_lock, flags);
883 ri = get_free_rp_inst(rp);
891 set_task_trampoline(task, ri, (unsigned long)tramp);
894 spin_unlock_irqrestore(&kretprobe_lock, flags);
898 static int __init init_kprobes (void)
902 /* FIXME allocate the probe table, currently defined statically */
903 /* initialize all list heads */
904 for (i = 0; i < KPROBE_TABLE_SIZE; i++)
906 INIT_HLIST_HEAD (&kprobe_table[i]);
907 INIT_HLIST_HEAD (&kretprobe_inst_table[i]);
909 init_uprobes_insn_slots(i);
911 atomic_set (&kprobe_count, 0);
913 err = arch_init_kprobes ();
915 DBPRINTF ("init_kprobes: arch_init_kprobes - %d", err);
920 static void __exit exit_kprobes (void)
922 dbi_arch_exit_kprobes ();
925 module_init (init_kprobes);
926 module_exit (exit_kprobes);
928 EXPORT_SYMBOL_GPL (dbi_register_kprobe);
929 EXPORT_SYMBOL_GPL (dbi_unregister_kprobe);
930 EXPORT_SYMBOL_GPL (dbi_register_jprobe);
931 EXPORT_SYMBOL_GPL (dbi_unregister_jprobe);
932 EXPORT_SYMBOL_GPL (dbi_jprobe_return);
933 EXPORT_SYMBOL_GPL (dbi_register_kretprobe);
934 EXPORT_SYMBOL_GPL (dbi_unregister_kretprobe);
936 MODULE_LICENSE ("Dual BSD/GPL");