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"
60 #include <linux/version.h>
61 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
62 #include <linux/config.h>
65 #include <linux/hash.h>
66 #include <linux/module.h>
68 #include <linux/pagemap.h>
70 extern struct hlist_head kprobe_insn_pages;
72 DEFINE_PER_CPU (struct kprobe *, current_kprobe) = NULL;
73 static DEFINE_PER_CPU (struct kprobe_ctlblk, kprobe_ctlblk);
75 DEFINE_SPINLOCK (kretprobe_lock); /* Protects kretprobe_inst_table */
76 EXPORT_SYMBOL_GPL(kretprobe_lock);
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;
83 EXPORT_SYMBOL_GPL(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;
132 EXPORT_SYMBOL_GPL(reset_current_kprobe);
134 struct kprobe_ctlblk *get_kprobe_ctlblk (void)
136 return (&__get_cpu_var (kprobe_ctlblk));
138 EXPORT_SYMBOL_GPL(get_kprobe_ctlblk);
141 * This routine is called either:
142 * - under the kprobe_mutex - during kprobe_[un]register()
144 * - with preemption disabled - from arch/xxx/kernel/kprobes.c
146 struct kprobe *get_kprobe(kprobe_opcode_t *addr, pid_t tgid)
148 struct hlist_head *head;
149 struct hlist_node *node;
150 struct kprobe *p, *retVal = NULL;
152 head = &kprobe_table[hash_ptr (addr, KPROBE_HASH_BITS)];
153 hlist_for_each_entry_rcu(p, node, head, hlist) {
154 if (p->addr == addr && p->tgid == tgid) {
160 DBPRINTF ("get_kprobe: probe %p", retVal);
165 * Aggregate handlers for multiple kprobes support - these handlers
166 * take care of invoking the individual kprobe handlers on p->list
169 int aggr_pre_handler (struct kprobe *p, struct pt_regs *regs)
174 list_for_each_entry_rcu (kp, &p->list, list)
178 set_kprobe_instance (kp);
179 ret = kp->pre_handler (kp, regs);
183 reset_kprobe_instance ();
189 void aggr_post_handler (struct kprobe *p, struct pt_regs *regs, unsigned long flags)
193 list_for_each_entry_rcu (kp, &p->list, list)
195 if (kp->post_handler)
197 set_kprobe_instance (kp);
198 kp->post_handler (kp, regs, flags);
199 reset_kprobe_instance ();
205 int aggr_fault_handler (struct kprobe *p, struct pt_regs *regs, int trapnr)
207 struct kprobe *cur = __get_cpu_var (kprobe_instance);
210 * if we faulted "during" the execution of a user specified
211 * probe handler, invoke just that probe's fault handler
213 if (cur && cur->fault_handler)
215 if (cur->fault_handler (cur, regs, trapnr))
222 int aggr_break_handler (struct kprobe *p, struct pt_regs *regs)
224 struct kprobe *cur = __get_cpu_var (kprobe_instance);
226 DBPRINTF ("cur = 0x%p\n", cur);
228 DBPRINTF ("cur = 0x%p cur->break_handler = 0x%p\n", cur, cur->break_handler);
230 if (cur && cur->break_handler)
232 if (cur->break_handler (cur, regs /*, vma, page, kaddr */ ))
235 reset_kprobe_instance ();
239 /* Walks the list and increments nmissed count for multiprobe case */
240 void kprobes_inc_nmissed_count (struct kprobe *p)
243 if (p->pre_handler != aggr_pre_handler)
249 list_for_each_entry_rcu (kp, &p->list, list) kp->nmissed++;
254 /* Called with kretprobe_lock held */
255 struct kretprobe_instance *get_free_rp_inst (struct kretprobe *rp)
257 struct hlist_node *node;
258 struct kretprobe_instance *ri;
259 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
261 if(!alloc_nodes_kretprobe(rp)){
262 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
268 /* Called with kretprobe_lock held */
269 struct kretprobe_instance *get_free_rp_inst_no_alloc (struct kretprobe *rp)
271 struct hlist_node *node;
272 struct kretprobe_instance *ri;
273 hlist_for_each_entry (ri, node, &rp->free_instances, uflist)
278 /* Called with kretprobe_lock held */
279 struct kretprobe_instance *get_used_rp_inst (struct kretprobe *rp)
281 struct hlist_node *node;
282 struct kretprobe_instance *ri;
283 hlist_for_each_entry (ri, node, &rp->used_instances, uflist) return ri;
286 EXPORT_SYMBOL_GPL(get_used_rp_inst);
288 /* Called with kretprobe_lock held */
289 void add_rp_inst (struct kretprobe_instance *ri)
292 * Remove rp inst off the free list -
293 * Add it back when probed function returns
295 hlist_del (&ri->uflist);
297 /* Add rp inst onto table */
298 INIT_HLIST_NODE (&ri->hlist);
300 * We are using different hash keys (task and mm) for finding kernel
301 * space and user space probes. Kernel space probes can change mm field in
302 * task_struct. User space probes can be shared between threads of one
303 * process so they have different task but same mm.
305 if (ri->rp->kp.tgid) {
306 hlist_add_head (&ri->hlist, &kretprobe_inst_table[hash_ptr (ri->task->mm, KPROBE_HASH_BITS)]);
308 hlist_add_head (&ri->hlist, &kretprobe_inst_table[hash_ptr (ri->task, KPROBE_HASH_BITS)]);
311 /* Also add this rp inst to the used list. */
312 INIT_HLIST_NODE (&ri->uflist);
313 hlist_add_head (&ri->uflist, &ri->rp->used_instances);
316 /* Called with kretprobe_lock held */
317 void recycle_rp_inst (struct kretprobe_instance *ri)
321 hlist_del (&ri->hlist);
322 /* remove rp inst off the used list */
323 hlist_del (&ri->uflist);
324 /* put rp inst back onto the free list */
325 INIT_HLIST_NODE (&ri->uflist);
326 hlist_add_head (&ri->uflist, &ri->rp->free_instances);
327 } else if (!ri->rp2) {
329 * This is __switch_to retprobe instance. It has neither rp nor rp2.
331 hlist_del (&ri->hlist);
334 EXPORT_SYMBOL_GPL(recycle_rp_inst);
336 struct hlist_head * kretprobe_inst_table_head (void *hash_key)
338 return &kretprobe_inst_table[hash_ptr (hash_key, KPROBE_HASH_BITS)];
340 EXPORT_SYMBOL_GPL(kretprobe_inst_table_head);
342 void free_rp_inst (struct kretprobe *rp)
344 struct kretprobe_instance *ri;
345 while ((ri = get_free_rp_inst_no_alloc (rp)) != NULL)
347 hlist_del (&ri->uflist);
351 EXPORT_SYMBOL_GPL(free_rp_inst);
354 * Keep all fields in the kprobe consistent
357 void copy_kprobe (struct kprobe *old_p, struct kprobe *p)
359 memcpy (&p->opcode, &old_p->opcode, sizeof (kprobe_opcode_t));
360 memcpy (&p->ainsn, &old_p->ainsn, sizeof (struct arch_specific_insn));
361 p->tgid = old_p->tgid;
362 p->ss_addr = old_p->ss_addr;
364 p->safe_arm = old_p->safe_arm;
365 p->safe_thumb = old_p->safe_thumb;
367 //p->spid = old_p->spid;
371 * Add the new probe to old_p->list. Fail if this is the
372 * second jprobe at the address - two jprobes can't coexist
374 static int add_new_kprobe (struct kprobe *old_p, struct kprobe *p)
376 if (p->break_handler)
378 if (old_p->break_handler)
380 list_add_tail_rcu (&p->list, &old_p->list);
381 old_p->break_handler = aggr_break_handler;
384 list_add_rcu (&p->list, &old_p->list);
385 if (p->post_handler && !old_p->post_handler)
386 old_p->post_handler = aggr_post_handler;
391 * hlist_replace_rcu - replace old entry by new one
392 * @old : the element to be replaced
393 * @new : the new element to insert
395 * The @old entry will be replaced with the @new entry atomically.
397 inline void dbi_hlist_replace_rcu (struct hlist_node *old, struct hlist_node *new)
399 struct hlist_node *next = old->next;
402 new->pprev = old->pprev;
405 new->next->pprev = &new->next;
408 old->pprev = LIST_POISON2;
413 * Fill in the required fields of the "manager kprobe". Replace the
414 * earlier kprobe in the hlist with the manager kprobe
417 void add_aggr_kprobe (struct kprobe *ap, struct kprobe *p)
420 //flush_insn_slot (ap);
422 ap->pre_handler = aggr_pre_handler;
423 ap->fault_handler = aggr_fault_handler;
425 ap->post_handler = aggr_post_handler;
426 if (p->break_handler)
427 ap->break_handler = aggr_break_handler;
429 INIT_LIST_HEAD (&ap->list);
430 list_add_rcu (&p->list, &ap->list);
432 dbi_hlist_replace_rcu (&p->hlist, &ap->hlist);
436 * This is the second or subsequent kprobe at the address - handle
439 int register_aggr_kprobe (struct kprobe *old_p, struct kprobe *p)
443 DBPRINTF ("start\n");
445 DBPRINTF ("p = %p old_p = %p \n", p, old_p);
446 if (old_p->pre_handler == aggr_pre_handler)
448 DBPRINTF ("aggr_pre_handler \n");
450 copy_kprobe (old_p, p);
451 ret = add_new_kprobe (old_p, p);
455 DBPRINTF ("kzalloc\n");
458 ap = kzalloc (sizeof (struct kprobe), GFP_KERNEL);
460 ap = kmalloc (sizeof (struct kprobe), GFP_KERNEL);
462 memset (ap, 0, sizeof (struct kprobe));
466 add_aggr_kprobe (ap, old_p);
468 DBPRINTF ("ap = %p p = %p old_p = %p \n", ap, p, old_p);
469 ret = add_new_kprobe (ap, p);
473 EXPORT_SYMBOL_GPL(register_aggr_kprobe);
475 int dbi_register_kprobe (struct kprobe *p)
477 struct kprobe *old_p;
480 * If we have a symbol_name argument look it up,
481 * and add it to the address. That way the addr
482 * field can either be global or relative to a symbol.
488 p->addr = (kprobe_opcode_t *)swap_ksyms(p->symbol_name);
493 DBPRINTF ("p->addr = 0x%p\n", p->addr);
494 p->addr = (kprobe_opcode_t *) (((char *) p->addr) + p->offset);
495 DBPRINTF ("p->addr = 0x%p p = 0x%p\n", p->addr, p);
497 #ifdef KPROBES_PROFILE
498 p->start_tm.tv_sec = p->start_tm.tv_usec = 0;
499 p->hnd_tm_sum.tv_sec = p->hnd_tm_sum.tv_usec = 0;
502 p->mod_refcounted = 0;
505 old_p = get_kprobe(p->addr, 0);
508 ret = register_aggr_kprobe (old_p, p);
510 atomic_inc (&kprobe_count);
514 if ((ret = arch_prepare_kprobe (p)) != 0)
517 DBPRINTF ("before out ret = 0x%x\n", ret);
518 INIT_HLIST_NODE (&p->hlist);
519 hlist_add_head_rcu (&p->hlist, &kprobe_table[hash_ptr (p->addr, KPROBE_HASH_BITS)]);
523 DBPRINTF ("out ret = 0x%x\n", ret);
527 void dbi_unregister_kprobe (struct kprobe *p, struct task_struct *task)
529 struct kprobe *old_p, *list_p;
530 int cleanup_p, pid = p->tgid;
532 old_p = get_kprobe(p->addr, pid);
533 DBPRINTF ("dbi_unregister_kprobe p=%p old_p=%p", p, old_p);
534 if (unlikely (!old_p))
539 list_for_each_entry_rcu (list_p, &old_p->list, list)
541 /* kprobe p is a valid probe */
547 DBPRINTF ("dbi_unregister_kprobe valid_p");
548 if ((old_p == p) || ((old_p->pre_handler == aggr_pre_handler) &&
549 (p->list.next == &old_p->list) && (p->list.prev == &old_p->list)))
551 /* Only probe on the hash list */
552 DBPRINTF ("dbi_unregister_kprobe disarm pid=%d", pid);
554 arch_disarm_uprobe (p, task);//vma, page, kaddr);
556 arch_disarm_kprobe (p);
557 hlist_del_rcu (&old_p->hlist);
562 list_del_rcu (&p->list);
565 DBPRINTF ("dbi_unregister_kprobe cleanup_p=%d", cleanup_p);
571 list_del_rcu (&p->list);
580 arch_remove_uprobe(p, task);
582 arch_remove_kprobe(p);
587 if (p->break_handler)
588 old_p->break_handler = NULL;
591 list_for_each_entry_rcu (list_p, &old_p->list, list)
593 if (list_p->post_handler)
600 old_p->post_handler = NULL;
605 int dbi_register_jprobe (struct jprobe *jp)
607 /* Todo: Verify probepoint is a function entry point */
608 jp->kp.pre_handler = setjmp_pre_handler;
609 jp->kp.break_handler = longjmp_break_handler;
611 return dbi_register_kprobe (&jp->kp);
614 void dbi_unregister_jprobe (struct jprobe *jp)
616 dbi_unregister_kprobe (&jp->kp, NULL);
620 * This kprobe pre_handler is registered with every kretprobe. When probe
621 * hits it will set up the return probe.
623 int pre_handler_kretprobe (struct kprobe *p, struct pt_regs *regs)
625 struct kretprobe *rp = container_of (p, struct kretprobe, kp);
626 unsigned long flags = 0;
627 DBPRINTF ("START\n");
629 /*TODO: consider to only swap the RA after the last pre_handler fired */
630 spin_lock_irqsave (&kretprobe_lock, flags);
632 __arch_prepare_kretprobe (rp, regs);
633 spin_unlock_irqrestore (&kretprobe_lock, flags);
637 EXPORT_SYMBOL_GPL(pre_handler_kretprobe);
639 struct kretprobe *sched_rp;
641 #define SCHED_RP_NR 200
642 #define COMMON_RP_NR 10
644 int alloc_nodes_kretprobe(struct kretprobe *rp)
647 struct kretprobe_instance *inst;
650 DBPRINTF("Alloc aditional mem for retprobes");
652 if ((unsigned long)rp->kp.addr == sched_addr){
653 rp->maxactive += SCHED_RP_NR;//max (100, 2 * NR_CPUS);
654 alloc_nodes = SCHED_RP_NR;
658 #if 1//def CONFIG_PREEMPT
659 rp->maxactive += max (COMMON_RP_NR, 2 * NR_CPUS);
661 rp->maxacpptive += NR_CPUS;
663 alloc_nodes = COMMON_RP_NR;
665 /* INIT_HLIST_HEAD (&rp->used_instances); */
666 /* INIT_HLIST_HEAD (&rp->free_instances); */
667 for (i = 0; i < alloc_nodes; i++)
669 inst = kmalloc (sizeof (struct kretprobe_instance), GFP_ATOMIC);
675 INIT_HLIST_NODE (&inst->uflist);
676 hlist_add_head (&inst->uflist, &rp->free_instances);
679 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)));
683 int dbi_register_kretprobe (struct kretprobe *rp)
686 struct kretprobe_instance *inst;
690 rp->kp.pre_handler = pre_handler_kretprobe;
691 rp->kp.post_handler = NULL;
692 rp->kp.fault_handler = NULL;
693 rp->kp.break_handler = NULL;
697 /* Pre-allocate memory for max kretprobe instances */
698 if ((unsigned long)rp->kp.addr == sched_addr) {
699 rp->maxactive = SCHED_RP_NR;//max (100, 2 * NR_CPUS);
700 rp->kp.pre_handler = NULL; //not needed for __switch_to
701 } else if ((unsigned long)rp->kp.addr == exit_addr) {
702 rp->kp.pre_handler = NULL; //not needed for do_exit
704 } else if (rp->maxactive <= 0) {
705 #if 1//def CONFIG_PREEMPT
706 rp->maxactive = max (COMMON_RP_NR, 2 * NR_CPUS);
708 rp->maxactive = NR_CPUS;
711 INIT_HLIST_HEAD (&rp->used_instances);
712 INIT_HLIST_HEAD (&rp->free_instances);
713 for (i = 0; i < rp->maxactive; i++)
715 inst = kmalloc (sizeof (struct kretprobe_instance), GFP_KERNEL);
721 INIT_HLIST_NODE (&inst->uflist);
722 hlist_add_head (&inst->uflist, &rp->free_instances);
725 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)));
727 /* Establish function entry probe point */
728 if ((ret = dbi_register_kprobe (&rp->kp)) != 0)
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)));
732 if ((unsigned long)rp->kp.addr == sched_addr) {
739 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri);
741 void dbi_unregister_kretprobe (struct kretprobe *rp)
744 struct kretprobe_instance *ri;
746 dbi_unregister_kprobe (&rp->kp, NULL);
749 spin_lock_irqsave (&kretprobe_lock, flags);
751 if ((unsigned long)rp->kp.addr == sched_addr)
754 while ((ri = get_used_rp_inst (rp)) != NULL) {
755 if (dbi_disarm_krp_inst(ri) == 0)
758 panic("%s (%d/%d): cannot disarm krp instance (%08lx)",
759 ri->task->comm, ri->task->tgid, ri->task->pid,
760 (unsigned long)rp->kp.addr);
763 spin_unlock_irqrestore (&kretprobe_lock, flags);
767 struct kretprobe * clone_kretprobe (struct kretprobe *rp)
769 struct kprobe *old_p;
770 struct kretprobe *clone = NULL;
773 clone = kmalloc (sizeof (struct kretprobe), GFP_KERNEL);
776 DBPRINTF ("failed to alloc memory for clone probe %p!", rp->kp.addr);
779 memcpy (clone, rp, sizeof (struct kretprobe));
780 clone->kp.pre_handler = pre_handler_kretprobe;
781 clone->kp.post_handler = NULL;
782 clone->kp.fault_handler = NULL;
783 clone->kp.break_handler = NULL;
784 old_p = get_kprobe(rp->kp.addr, rp->kp.tgid);
787 ret = register_aggr_kprobe (old_p, &clone->kp);
793 atomic_inc (&kprobe_count);
798 EXPORT_SYMBOL_GPL(clone_kretprobe);
800 static void inline set_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri, unsigned long tramp_addr)
802 unsigned long pc = arch_get_task_pc(p);
803 if (pc == tramp_addr)
804 panic("[%d] %s (%d/%d): pc = %08lx --- [%d] %s (%d/%d)\n",
805 task_cpu(p), p->comm, p->tgid, p->pid, pc,
806 task_cpu(current), current->comm, current->tgid, current->pid);
807 ri->ret_addr = (kprobe_opcode_t *)pc;
808 arch_set_task_pc(p, tramp_addr);
811 static void inline rm_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri)
813 arch_set_task_pc(p, (unsigned long)ri->ret_addr);
816 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri)
818 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
819 kprobe_opcode_t *sp = ri->sp;
820 kprobe_opcode_t *found = NULL;
821 int retval = -ENOENT;
824 unsigned long pc = arch_get_task_pc(ri->task);
826 printk("---> [%d] %s (%d/%d): pc = %08lx, ra = %08lx, tramp= %08lx (%08lx)\n",
828 ri->task->comm, ri->task->tgid, ri->task->pid,
829 pc, (unsigned long)ri->ret_addr,
830 (unsigned long)tramp,
831 (unsigned long)(ri->rp ? ri->rp->kp.addr: NULL));
833 /* __switch_to retprobe handling */
834 if (pc == (unsigned long)tramp) {
835 rm_task_trampoline(ri->task, ri);
842 while (sp > ri->sp - RETPROBE_STACK_DEPTH) {
843 if ((unsigned long)*sp == (unsigned long)tramp) {
851 printk("---> [%d] %s (%d/%d): tramp (%08lx) found at %08lx (%08lx /%+d) - %p\n",
853 ri->task->comm, ri->task->tgid, ri->task->pid,
854 (unsigned long)tramp,
855 (unsigned long)found, (unsigned long)ri->sp, found - ri->sp,
856 ri->rp ? ri->rp->kp.addr: NULL);
857 *found = (unsigned long)ri->ret_addr;
860 printk("---> [%d] %s (%d/%d): tramp (%08lx) NOT found at sp = %08lx - %p\n",
862 ri->task->comm, ri->task->tgid, ri->task->pid,
863 (unsigned long)tramp,
864 (unsigned long)ri->sp, ri->rp ? ri->rp->kp.addr: NULL);
870 int patch_suspended_task(struct kretprobe *rp, struct task_struct *task)
872 struct kretprobe_instance *ri;
874 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
876 spin_lock_irqsave(&kretprobe_lock, flags);
878 ri = get_free_rp_inst(rp);
886 set_task_trampoline(task, ri, (unsigned long)tramp);
889 spin_unlock_irqrestore(&kretprobe_lock, flags);
893 static int __init init_kprobes (void)
897 /* FIXME allocate the probe table, currently defined statically */
898 /* initialize all list heads */
899 for (i = 0; i < KPROBE_TABLE_SIZE; i++)
901 INIT_HLIST_HEAD (&kprobe_table[i]);
902 INIT_HLIST_HEAD (&kretprobe_inst_table[i]);
904 atomic_set (&kprobe_count, 0);
906 err = arch_init_kprobes ();
908 DBPRINTF ("init_kprobes: arch_init_kprobes - %d", err);
913 static void __exit exit_kprobes (void)
915 dbi_arch_exit_kprobes ();
918 module_init (init_kprobes);
919 module_exit (exit_kprobes);
921 EXPORT_SYMBOL_GPL (dbi_register_kprobe);
922 EXPORT_SYMBOL_GPL (dbi_unregister_kprobe);
923 EXPORT_SYMBOL_GPL (dbi_register_jprobe);
924 EXPORT_SYMBOL_GPL (dbi_unregister_jprobe);
925 EXPORT_SYMBOL_GPL (dbi_jprobe_return);
926 EXPORT_SYMBOL_GPL (dbi_register_kretprobe);
927 EXPORT_SYMBOL_GPL (dbi_unregister_kretprobe);
929 MODULE_LICENSE ("Dual BSD/GPL");