2 * Kernel Probes (KProbes)
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) IBM Corporation, 2002, 2004
23 * Dynamic Binary Instrumentation Module based on KProbes
24 * modules/kprobe/dbi_kprobes.h
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 * Copyright (C) Samsung Electronics, 2006-2010
42 * 2006-2007 Ekaterina Gorelkina <e.gorelkina@samsung.com>: initial implementation for ARM and MIPS
43 * 2008-2009 Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
44 * Probes initial implementation; Support x86/ARM/MIPS for both user and kernel spaces.
45 * 2010 Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
49 #include "dbi_kprobes.h"
50 #include "arch/asm/dbi_kprobes.h"
52 #include "dbi_kdebug.h"
53 #include "dbi_kprobes_deps.h"
54 #include "dbi_insn_slots.h"
57 #include <linux/version.h>
58 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
59 #include <linux/config.h>
62 #include <linux/hash.h>
63 #include <linux/module.h>
65 #include <linux/pagemap.h>
67 struct hlist_head kprobe_insn_pages;
69 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
70 static DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
72 DEFINE_SPINLOCK(kretprobe_lock); /* Protects kretprobe_inst_table */
73 EXPORT_SYMBOL_GPL(kretprobe_lock);
74 static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL;
76 struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
77 static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
79 atomic_t kprobe_count;
80 EXPORT_SYMBOL_GPL(kprobe_count);
82 void kretprobe_assert(struct kretprobe_instance *ri, unsigned long orig_ret_address, unsigned long trampoline_address)
84 if (!orig_ret_address || (orig_ret_address == trampoline_address)) {
85 struct task_struct *task;
87 panic("kretprobe BUG!: ri = NULL\n");
93 panic("kretprobe BUG!: task = NULL\n");
97 panic("kretprobe BUG!: ri->rp = NULL\n");
100 panic("kretprobe BUG!: Processing kretprobe %p @ %p (%d/%d - %s)\n",
101 ri->rp, ri->rp->kp.addr, ri->task->tgid, ri->task->pid, ri->task->comm);
105 /* We have preemption disabled.. so it is safe to use __ versions */
106 static inline void set_kprobe_instance(struct kprobe *kp)
108 __get_cpu_var(kprobe_instance) = kp;
111 static inline void reset_kprobe_instance(void)
113 __get_cpu_var(kprobe_instance) = NULL;
116 /* kprobe_running() will just return the current_kprobe on this CPU */
117 struct kprobe *kprobe_running(void)
119 return __get_cpu_var(current_kprobe);
122 void reset_current_kprobe(void)
124 __get_cpu_var(current_kprobe) = NULL;
127 struct kprobe_ctlblk *get_kprobe_ctlblk(void)
129 return &__get_cpu_var(kprobe_ctlblk);
133 * This routine is called either:
134 * - under the kprobe_mutex - during kprobe_[un]register()
136 * - with preemption disabled - from arch/xxx/kernel/kprobes.c
138 struct kprobe *get_kprobe(void *addr)
140 struct hlist_head *head;
141 struct hlist_node *node;
144 head = &kprobe_table[hash_ptr (addr, KPROBE_HASH_BITS)];
145 hlist_for_each_entry_rcu(p, node, head, hlist) {
146 if (p->addr == addr) {
155 * Aggregate handlers for multiple kprobes support - these handlers
156 * take care of invoking the individual kprobe handlers on p->list
158 static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs)
163 list_for_each_entry_rcu(kp, &p->list, list) {
164 if (kp->pre_handler) {
165 set_kprobe_instance(kp);
166 ret = kp->pre_handler(kp, regs);
170 reset_kprobe_instance();
176 static void aggr_post_handler(struct kprobe *p, struct pt_regs *regs, unsigned long flags)
180 list_for_each_entry_rcu(kp, &p->list, list) {
181 if (kp->post_handler) {
182 set_kprobe_instance(kp);
183 kp->post_handler(kp, regs, flags);
184 reset_kprobe_instance();
189 static int aggr_fault_handler(struct kprobe *p, struct pt_regs *regs, int trapnr)
191 struct kprobe *cur = __get_cpu_var(kprobe_instance);
194 * if we faulted "during" the execution of a user specified
195 * probe handler, invoke just that probe's fault handler
197 if (cur && cur->fault_handler) {
198 if (cur->fault_handler(cur, regs, trapnr))
205 static int aggr_break_handler(struct kprobe *p, struct pt_regs *regs)
207 struct kprobe *cur = __get_cpu_var(kprobe_instance);
209 DBPRINTF ("cur = 0x%p\n", cur);
211 DBPRINTF ("cur = 0x%p cur->break_handler = 0x%p\n", cur, cur->break_handler);
213 if (cur && cur->break_handler) {
214 if (cur->break_handler(cur, regs))
217 reset_kprobe_instance();
222 /* Walks the list and increments nmissed count for multiprobe case */
223 void kprobes_inc_nmissed_count(struct kprobe *p)
226 if (p->pre_handler != aggr_pre_handler) {
229 list_for_each_entry_rcu(kp, &p->list, list) {
235 /* Called with kretprobe_lock held */
236 struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp)
238 struct hlist_node *node;
239 struct kretprobe_instance *ri;
241 hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
245 if (!alloc_nodes_kretprobe(rp)) {
246 hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
253 EXPORT_SYMBOL_GPL(get_free_rp_inst);
255 /* Called with kretprobe_lock held */
256 struct kretprobe_instance *get_free_rp_inst_no_alloc(struct kretprobe *rp)
258 struct hlist_node *node;
259 struct kretprobe_instance *ri;
261 hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
268 /* Called with kretprobe_lock held */
269 struct kretprobe_instance *get_used_rp_inst(struct kretprobe *rp)
271 struct hlist_node *node;
272 struct kretprobe_instance *ri;
274 hlist_for_each_entry(ri, node, &rp->used_instances, uflist) {
280 EXPORT_SYMBOL_GPL(get_used_rp_inst);
282 /* Called with kretprobe_lock held */
283 void add_rp_inst (struct kretprobe_instance *ri)
286 * Remove rp inst off the free list -
287 * Add it back when probed function returns
289 hlist_del(&ri->uflist);
291 /* Add rp inst onto table */
292 INIT_HLIST_NODE(&ri->hlist);
294 hlist_add_head(&ri->hlist, &kretprobe_inst_table[hash_ptr(ri->task, KPROBE_HASH_BITS)]);
296 /* Also add this rp inst to the used list. */
297 INIT_HLIST_NODE(&ri->uflist);
298 hlist_add_head(&ri->uflist, &ri->rp->used_instances);
300 EXPORT_SYMBOL_GPL(add_rp_inst);
302 /* Called with kretprobe_lock held */
303 void recycle_rp_inst(struct kretprobe_instance *ri)
306 hlist_del(&ri->hlist);
307 /* remove rp inst off the used list */
308 hlist_del(&ri->uflist);
309 /* put rp inst back onto the free list */
310 INIT_HLIST_NODE(&ri->uflist);
311 hlist_add_head(&ri->uflist, &ri->rp->free_instances);
314 EXPORT_SYMBOL_GPL(recycle_rp_inst);
316 struct hlist_head *kretprobe_inst_table_head(void *hash_key)
318 return &kretprobe_inst_table[hash_ptr(hash_key, KPROBE_HASH_BITS)];
320 EXPORT_SYMBOL_GPL(kretprobe_inst_table_head);
322 void free_rp_inst(struct kretprobe *rp)
324 struct kretprobe_instance *ri;
325 while ((ri = get_free_rp_inst_no_alloc(rp)) != NULL) {
326 hlist_del(&ri->uflist);
330 EXPORT_SYMBOL_GPL(free_rp_inst);
333 * Keep all fields in the kprobe consistent
335 static inline void copy_kprobe(struct kprobe *old_p, struct kprobe *p)
337 memcpy(&p->opcode, &old_p->opcode, sizeof(kprobe_opcode_t));
338 memcpy(&p->ainsn, &old_p->ainsn, sizeof(struct arch_specific_insn));
339 p->ss_addr = old_p->ss_addr;
341 p->safe_arm = old_p->safe_arm;
342 p->safe_thumb = old_p->safe_thumb;
347 * Add the new probe to old_p->list. Fail if this is the
348 * second jprobe at the address - two jprobes can't coexist
350 static int add_new_kprobe(struct kprobe *old_p, struct kprobe *p)
352 if (p->break_handler) {
353 if (old_p->break_handler) {
357 list_add_tail_rcu(&p->list, &old_p->list);
358 old_p->break_handler = aggr_break_handler;
360 list_add_rcu(&p->list, &old_p->list);
363 if (p->post_handler && !old_p->post_handler) {
364 old_p->post_handler = aggr_post_handler;
371 * hlist_replace_rcu - replace old entry by new one
372 * @old : the element to be replaced
373 * @new : the new element to insert
375 * The @old entry will be replaced with the @new entry atomically.
377 inline void dbi_hlist_replace_rcu(struct hlist_node *old, struct hlist_node *new)
379 struct hlist_node *next = old->next;
382 new->pprev = old->pprev;
385 new->next->pprev = &new->next;
388 old->pprev = LIST_POISON2;
392 * Fill in the required fields of the "manager kprobe". Replace the
393 * earlier kprobe in the hlist with the manager kprobe
395 static inline void add_aggr_kprobe(struct kprobe *ap, struct kprobe *p)
399 ap->pre_handler = aggr_pre_handler;
400 ap->fault_handler = aggr_fault_handler;
402 ap->post_handler = aggr_post_handler;
403 if (p->break_handler)
404 ap->break_handler = aggr_break_handler;
406 INIT_LIST_HEAD(&ap->list);
407 list_add_rcu(&p->list, &ap->list);
409 dbi_hlist_replace_rcu(&p->hlist, &ap->hlist);
413 * This is the second or subsequent kprobe at the address - handle
416 int register_aggr_kprobe(struct kprobe *old_p, struct kprobe *p)
420 DBPRINTF ("start\n");
422 DBPRINTF ("p = %p old_p = %p \n", p, old_p);
423 if (old_p->pre_handler == aggr_pre_handler) {
424 DBPRINTF ("aggr_pre_handler \n");
426 copy_kprobe(old_p, p);
427 ret = add_new_kprobe(old_p, p);
429 DBPRINTF ("kzalloc\n");
431 ap = kzalloc(sizeof(struct kprobe), GFP_KERNEL);
433 ap = kmalloc(sizeof(struct kprobe), GFP_KERNEL);
435 memset(ap, 0, sizeof(struct kprobe));
439 add_aggr_kprobe(ap, old_p);
441 DBPRINTF ("ap = %p p = %p old_p = %p \n", ap, p, old_p);
442 ret = add_new_kprobe(ap, p);
447 EXPORT_SYMBOL_GPL(register_aggr_kprobe);
449 static void remove_kprobe(struct kprobe *p)
451 /* TODO: check boostable for x86 and MIPS */
452 free_insn_slot(&kprobe_insn_pages, NULL, p->ainsn.insn);
455 int dbi_register_kprobe(struct kprobe *p)
457 struct kprobe *old_p;
460 * If we have a symbol_name argument look it up,
461 * and add it to the address. That way the addr
462 * field can either be global or relative to a symbol.
464 if (p->symbol_name) {
467 p->addr = (kprobe_opcode_t *)swap_ksyms(p->symbol_name);
472 DBPRINTF ("p->addr = 0x%p\n", p->addr);
473 p->addr = (kprobe_opcode_t *)(((char *)p->addr) + p->offset);
474 DBPRINTF ("p->addr = 0x%p p = 0x%p\n", p->addr, p);
476 #ifdef KPROBES_PROFILE
477 p->start_tm.tv_sec = p->start_tm.tv_usec = 0;
478 p->hnd_tm_sum.tv_sec = p->hnd_tm_sum.tv_usec = 0;
481 p->mod_refcounted = 0;
484 old_p = get_kprobe(p->addr);
486 ret = register_aggr_kprobe(old_p, p);
488 atomic_inc(&kprobe_count);
492 if ((ret = arch_prepare_kprobe(p, &kprobe_insn_pages)) != 0)
495 DBPRINTF ("before out ret = 0x%x\n", ret);
496 INIT_HLIST_NODE(&p->hlist);
497 hlist_add_head_rcu(&p->hlist, &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]);
501 DBPRINTF ("out ret = 0x%x\n", ret);
505 void dbi_unregister_kprobe(struct kprobe *p, struct task_struct *task)
507 struct kprobe *old_p, *list_p;
510 old_p = get_kprobe(p->addr);
511 DBPRINTF ("dbi_unregister_kprobe p=%p old_p=%p", p, old_p);
512 if (unlikely (!old_p))
516 list_for_each_entry_rcu(list_p, &old_p->list, list)
518 /* kprobe p is a valid probe */
524 DBPRINTF ("dbi_unregister_kprobe valid_p");
525 if ((old_p == p) || ((old_p->pre_handler == aggr_pre_handler) &&
526 (p->list.next == &old_p->list) && (p->list.prev == &old_p->list))) {
527 /* Only probe on the hash list */
528 arch_disarm_kprobe(p);
529 hlist_del_rcu(&old_p->hlist);
532 list_del_rcu(&p->list);
535 DBPRINTF ("dbi_unregister_kprobe cleanup_p=%d", cleanup_p);
539 list_del_rcu(&p->list);
549 if (p->break_handler)
550 old_p->break_handler = NULL;
551 if (p->post_handler) {
552 list_for_each_entry_rcu(list_p, &old_p->list, list) {
553 if (list_p->post_handler) {
560 old_p->post_handler = NULL;
565 int dbi_register_jprobe(struct jprobe *jp)
567 /* Todo: Verify probepoint is a function entry point */
568 jp->kp.pre_handler = setjmp_pre_handler;
569 jp->kp.break_handler = longjmp_break_handler;
571 return dbi_register_kprobe(&jp->kp);
574 void dbi_unregister_jprobe(struct jprobe *jp)
576 dbi_unregister_kprobe(&jp->kp, NULL);
580 * This kprobe pre_handler is registered with every kretprobe. When probe
581 * hits it will set up the return probe.
583 int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs)
585 struct kretprobe *rp = container_of(p, struct kretprobe, kp);
586 unsigned long flags = 0;
587 DBPRINTF ("START\n");
589 /*TODO: consider to only swap the RA after the last pre_handler fired */
590 spin_lock_irqsave(&kretprobe_lock, flags);
592 arch_prepare_kretprobe(rp, regs);
593 spin_unlock_irqrestore(&kretprobe_lock, flags);
597 EXPORT_SYMBOL_GPL(pre_handler_kretprobe);
599 struct kretprobe *sched_rp;
601 #define SCHED_RP_NR 200
602 #define COMMON_RP_NR 10
604 int alloc_nodes_kretprobe(struct kretprobe *rp)
607 struct kretprobe_instance *inst;
610 DBPRINTF("Alloc aditional mem for retprobes");
612 if ((unsigned long)rp->kp.addr == sched_addr) {
613 rp->maxactive += SCHED_RP_NR;//max (100, 2 * NR_CPUS);
614 alloc_nodes = SCHED_RP_NR;
616 #if 1//def CONFIG_PREEMPT
617 rp->maxactive += max (COMMON_RP_NR, 2 * NR_CPUS);
619 rp->maxacpptive += NR_CPUS;
621 alloc_nodes = COMMON_RP_NR;
624 for (i = 0; i < alloc_nodes; i++) {
625 inst = kmalloc(sizeof(struct kretprobe_instance), GFP_ATOMIC);
630 INIT_HLIST_NODE(&inst->uflist);
631 hlist_add_head(&inst->uflist, &rp->free_instances);
634 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)));
638 int dbi_register_kretprobe(struct kretprobe *rp)
641 struct kretprobe_instance *inst;
645 rp->kp.pre_handler = pre_handler_kretprobe;
646 rp->kp.post_handler = NULL;
647 rp->kp.fault_handler = NULL;
648 rp->kp.break_handler = NULL;
652 /* Pre-allocate memory for max kretprobe instances */
653 if ((unsigned long)rp->kp.addr == sched_addr) {
654 rp->maxactive = SCHED_RP_NR;//max (100, 2 * NR_CPUS);
655 rp->kp.pre_handler = NULL; //not needed for __switch_to
656 } else if ((unsigned long)rp->kp.addr == exit_addr) {
657 rp->kp.pre_handler = NULL; //not needed for do_exit
659 } else if (rp->maxactive <= 0) {
660 #if 1//def CONFIG_PREEMPT
661 rp->maxactive = max (COMMON_RP_NR, 2 * NR_CPUS);
663 rp->maxactive = NR_CPUS;
666 INIT_HLIST_HEAD(&rp->used_instances);
667 INIT_HLIST_HEAD(&rp->free_instances);
668 for (i = 0; i < rp->maxactive; i++) {
669 inst = kmalloc(sizeof(struct kretprobe_instance), GFP_KERNEL);
674 INIT_HLIST_NODE(&inst->uflist);
675 hlist_add_head(&inst->uflist, &rp->free_instances);
678 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)));
680 /* Establish function entry probe point */
681 if ((ret = dbi_register_kprobe(&rp->kp)) != 0)
684 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)));
685 if ((unsigned long)rp->kp.addr == sched_addr) {
692 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri);
694 void dbi_unregister_kretprobe(struct kretprobe *rp)
697 struct kretprobe_instance *ri;
699 dbi_unregister_kprobe(&rp->kp, NULL);
702 spin_lock_irqsave(&kretprobe_lock, flags);
704 if ((unsigned long)rp->kp.addr == sched_addr)
707 while ((ri = get_used_rp_inst(rp)) != NULL) {
708 if (dbi_disarm_krp_inst(ri) == 0)
711 panic("%s (%d/%d): cannot disarm krp instance (%08lx)",
712 ri->task->comm, ri->task->tgid, ri->task->pid,
713 (unsigned long)rp->kp.addr);
716 spin_unlock_irqrestore(&kretprobe_lock, flags);
720 struct kretprobe *clone_kretprobe(struct kretprobe *rp)
722 struct kprobe *old_p;
723 struct kretprobe *clone = NULL;
726 clone = kmalloc(sizeof(struct kretprobe), GFP_KERNEL);
728 DBPRINTF ("failed to alloc memory for clone probe %p!", rp->kp.addr);
731 memcpy(clone, rp, sizeof(struct kretprobe));
732 clone->kp.pre_handler = pre_handler_kretprobe;
733 clone->kp.post_handler = NULL;
734 clone->kp.fault_handler = NULL;
735 clone->kp.break_handler = NULL;
736 old_p = get_kprobe(rp->kp.addr);
738 ret = register_aggr_kprobe(old_p, &clone->kp);
743 atomic_inc(&kprobe_count);
748 EXPORT_SYMBOL_GPL(clone_kretprobe);
750 static void inline set_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri, unsigned long tramp_addr)
752 unsigned long pc = arch_get_task_pc(p);
753 if (pc == tramp_addr)
754 panic("[%d] %s (%d/%d): pc = %08lx --- [%d] %s (%d/%d)\n",
755 task_cpu(p), p->comm, p->tgid, p->pid, pc,
756 task_cpu(current), current->comm, current->tgid, current->pid);
757 ri->ret_addr = (kprobe_opcode_t *)pc;
758 arch_set_task_pc(p, tramp_addr);
761 static void inline rm_task_trampoline(struct task_struct *p, struct kretprobe_instance *ri)
763 arch_set_task_pc(p, (unsigned long)ri->ret_addr);
766 static int dbi_disarm_krp_inst(struct kretprobe_instance *ri)
768 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
769 kprobe_opcode_t *sp = ri->sp;
770 kprobe_opcode_t *found = NULL;
771 int retval = -ENOENT;
774 unsigned long pc = arch_get_task_pc(ri->task);
776 printk("---> [%d] %s (%d/%d): pc = %08lx, ra = %08lx, tramp= %08lx (%08lx)\n",
778 ri->task->comm, ri->task->tgid, ri->task->pid,
779 pc, (unsigned long)ri->ret_addr,
780 (unsigned long)tramp,
781 (unsigned long)(ri->rp ? ri->rp->kp.addr: NULL));
783 /* __switch_to retprobe handling */
784 if (pc == (unsigned long)tramp) {
785 rm_task_trampoline(ri->task, ri);
792 while (sp > ri->sp - RETPROBE_STACK_DEPTH) {
793 if ((unsigned long)*sp == (unsigned long)tramp) {
801 printk("---> [%d] %s (%d/%d): tramp (%08lx) found at %08lx (%08lx /%+d) - %p\n",
803 ri->task->comm, ri->task->tgid, ri->task->pid,
804 (unsigned long)tramp,
805 (unsigned long)found, (unsigned long)ri->sp, found - ri->sp,
806 ri->rp ? ri->rp->kp.addr: NULL);
807 *found = (unsigned long)ri->ret_addr;
810 printk("---> [%d] %s (%d/%d): tramp (%08lx) NOT found at sp = %08lx - %p\n",
812 ri->task->comm, ri->task->tgid, ri->task->pid,
813 (unsigned long)tramp,
814 (unsigned long)ri->sp, ri->rp ? ri->rp->kp.addr: NULL);
820 int patch_suspended_task(struct kretprobe *rp, struct task_struct *task)
822 struct kretprobe_instance *ri;
824 kprobe_opcode_t *tramp = (kprobe_opcode_t *)&kretprobe_trampoline;
826 spin_lock_irqsave(&kretprobe_lock, flags);
828 ri = get_free_rp_inst(rp);
835 set_task_trampoline(task, ri, (unsigned long)tramp);
838 spin_unlock_irqrestore(&kretprobe_lock, flags);
842 static int init_module_deps(void)
846 sched_addr = swap_ksyms("__switch_to");
847 fork_addr = swap_ksyms("do_fork");
848 exit_addr = swap_ksyms("do_exit");
850 if (sched_addr == 0 || fork_addr == 0 || exit_addr == 0) {
854 ret = init_module_dependencies();
859 return arch_init_module_deps();
862 static int __init init_kprobes(void)
866 /* FIXME allocate the probe table, currently defined statically */
867 /* initialize all list heads */
868 for (i = 0; i < KPROBE_TABLE_SIZE; ++i) {
869 INIT_HLIST_HEAD(&kprobe_table[i]);
870 INIT_HLIST_HEAD(&kretprobe_inst_table[i]);
872 atomic_set(&kprobe_count, 0);
874 err = init_module_deps();
879 err = arch_init_kprobes();
881 DBPRINTF ("init_kprobes: arch_init_kprobes - %d", err);
886 static void __exit exit_kprobes(void)
891 module_init(init_kprobes);
892 module_exit(exit_kprobes);
894 EXPORT_SYMBOL_GPL(dbi_register_kprobe);
895 EXPORT_SYMBOL_GPL(dbi_unregister_kprobe);
896 EXPORT_SYMBOL_GPL(dbi_register_jprobe);
897 EXPORT_SYMBOL_GPL(dbi_unregister_jprobe);
898 EXPORT_SYMBOL_GPL(dbi_jprobe_return);
899 EXPORT_SYMBOL_GPL(dbi_register_kretprobe);
900 EXPORT_SYMBOL_GPL(dbi_unregister_kretprobe);
902 MODULE_LICENSE("Dual BSD/GPL");