2 * Dynamic Binary Instrumentation Module based on KProbes
3 * modules/kprobe/dbi_uprobes.h
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 * 2008-2009 Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
22 * Probes initial implementation; Support x86/ARM/MIPS for both user and kernel spaces.
23 * 2010 Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
28 #include "swap_uprobes.h"
29 #include "dbi_kdebug.h"
31 #include <asm/swap_uprobes.h>
33 #include <linux/hash.h>
34 #include <linux/mempolicy.h>
35 #include <linux/module.h>
36 #include <dbi_insn_slots.h>
39 UPROBE_HASH_BITS = 10,
40 UPROBE_TABLE_SIZE = (1 << UPROBE_HASH_BITS)
43 struct hlist_head uprobe_insn_slot_table[UPROBE_TABLE_SIZE];
44 struct hlist_head uprobe_table[UPROBE_TABLE_SIZE];
45 struct hlist_head uprobe_insn_pages;
47 DEFINE_SPINLOCK(uretprobe_lock); /* Protects uretprobe_inst_table */
48 static struct hlist_head uretprobe_inst_table[UPROBE_TABLE_SIZE];
50 #define DEBUG_PRINT_HASH_TABLE 0
52 #if DEBUG_PRINT_HASH_TABLE
53 void print_kprobe_hash_table(void)
56 struct hlist_head *head;
57 struct hlist_node *node;
61 for (i = 0; i < KPROBE_TABLE_SIZE; ++i) {
62 head = &kprobe_table[i];
63 hlist_for_each_entry_rcu (p, node, head, is_hlist_arm) {
64 printk("####### find K tgid=%u, addr=%x\n",
70 void print_kretprobe_hash_table(void)
73 struct hlist_head *head;
74 struct hlist_node *node;
78 for (i = 0; i < KPROBE_TABLE_SIZE; ++i) {
79 head = &kretprobe_inst_table[i];
80 hlist_for_each_entry_rcu (p, node, head, is_hlist_arm) {
81 printk("####### find KR tgid=%u, addr=%x\n",
87 void print_uprobe_hash_table(void)
90 struct hlist_head *head;
91 struct hlist_node *node;
95 for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
96 head = &uprobe_insn_slot_table[i];
97 hlist_for_each_entry_rcu (p, node, head, is_hlist_arm) {
98 printk("####### find U tgid=%u, addr=%x\n",
106 * Keep all fields in the uprobe consistent
108 static inline void copy_uprobe(struct kprobe *old_p, struct kprobe *p)
110 memcpy(&p->opcode, &old_p->opcode, sizeof(kprobe_opcode_t));
111 memcpy(&p->ainsn, &old_p->ainsn, sizeof(struct arch_specific_insn));
112 p->ss_addr = old_p->ss_addr;
114 p->safe_arm = old_p->safe_arm;
115 p->safe_thumb = old_p->safe_thumb;
120 * Aggregate handlers for multiple uprobes support - these handlers
121 * take care of invoking the individual uprobe handlers on p->list
123 static int aggr_pre_uhandler(struct kprobe *p, struct pt_regs *regs)
128 list_for_each_entry_rcu(kp, &p->list, list) {
129 if (kp->pre_handler) {
130 ret = kp->pre_handler(kp, regs);
140 static void aggr_post_uhandler(struct kprobe *p, struct pt_regs *regs, unsigned long flags)
144 list_for_each_entry_rcu(kp, &p->list, list) {
145 if (kp->post_handler) {
146 kp->post_handler(kp, regs, flags);
151 static int aggr_fault_uhandler(struct kprobe *p, struct pt_regs *regs, int trapnr)
156 static int aggr_break_uhandler(struct kprobe *p, struct pt_regs *regs)
162 * Add the new probe to old_p->list. Fail if this is the
163 * second ujprobe at the address - two ujprobes can't coexist
165 static int add_new_uprobe(struct kprobe *old_p, struct kprobe *p)
167 if (p->break_handler) {
168 if (old_p->break_handler) {
172 list_add_tail_rcu(&p->list, &old_p->list);
173 old_p->break_handler = aggr_break_uhandler;
175 list_add_rcu (&p->list, &old_p->list);
178 if (p->post_handler && !old_p->post_handler) {
179 old_p->post_handler = aggr_post_uhandler;
186 * Fill in the required fields of the "manager uprobe". Replace the
187 * earlier uprobe in the hlist with the manager uprobe
189 static inline void add_aggr_uprobe(struct kprobe *ap, struct kprobe *p)
194 ap->pre_handler = aggr_pre_uhandler;
195 ap->fault_handler = aggr_fault_uhandler;
197 if (p->post_handler) {
198 ap->post_handler = aggr_post_uhandler;
201 if (p->break_handler) {
202 ap->break_handler = aggr_break_uhandler;
205 INIT_LIST_HEAD(&ap->list);
206 list_add_rcu(&p->list, &ap->list);
208 hlist_replace_rcu(&p->hlist, &ap->hlist);
212 * This is the second or subsequent uprobe at the address - handle
215 static int register_aggr_uprobe(struct kprobe *old_p, struct kprobe *p)
220 if (old_p->pre_handler == aggr_pre_uhandler) {
221 copy_uprobe(old_p, p);
222 ret = add_new_uprobe(old_p, p);
224 struct uprobe *uap = kzalloc(sizeof(*uap), GFP_KERNEL);
229 uap->task = kp2up(p)->task;
231 add_aggr_uprobe(ap, old_p);
233 ret = add_new_uprobe(ap, p);
239 static void arm_uprobe(struct uprobe *p)
241 kprobe_opcode_t insn = BREAKPOINT_INSTRUCTION;
242 int ret = write_proc_vm_atomic(p->task, (unsigned long)p->kp.addr,
243 &insn, sizeof(insn));
245 panic("arm_uprobe: failed to write memory "
246 "tgid=%u addr=%p!\n", p->task->tgid, p->kp.addr);
250 void disarm_uprobe(struct uprobe *p)
252 int ret = write_proc_vm_atomic(p->task, (unsigned long)p->kp.addr,
253 &p->kp.opcode, sizeof(p->kp.opcode));
255 panic("disarm_uprobe: failed to write memory "
256 "tgid=%u, addr=%p!\n", p->task->tgid, p->kp.addr);
259 EXPORT_SYMBOL_GPL(disarm_uprobe);
261 static void init_uprobes_insn_slots(void)
264 for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
265 INIT_HLIST_HEAD(&uprobe_insn_slot_table[i]);
269 static void init_uprobe_table(void)
272 for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
273 INIT_HLIST_HEAD(&uprobe_table[i]);
277 static void init_uretprobe_inst_table(void)
280 for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
281 INIT_HLIST_HEAD (&uretprobe_inst_table[i]);
285 struct kprobe *get_ukprobe(void *addr, pid_t tgid)
287 struct hlist_head *head;
288 struct hlist_node *node;
291 head = &uprobe_table[hash_ptr(addr, UPROBE_HASH_BITS)];
292 hlist_for_each_entry_rcu(p, node, head, hlist) {
293 if (p->addr == addr && kp2up(p)->task->tgid == tgid) {
301 static void add_uprobe_table(struct kprobe *p)
304 INIT_HLIST_NODE(&p->is_hlist_arm);
305 hlist_add_head_rcu(&p->is_hlist_arm, &uprobe_insn_slot_table[hash_ptr(p->ainsn.insn_arm, UPROBE_HASH_BITS)]);
306 INIT_HLIST_NODE(&p->is_hlist_thumb);
307 hlist_add_head_rcu(&p->is_hlist_thumb, &uprobe_insn_slot_table[hash_ptr(p->ainsn.insn_thumb, UPROBE_HASH_BITS)]);
308 #else /* CONFIG_ARM */
309 INIT_HLIST_NODE(&p->is_hlist);
310 hlist_add_head_rcu(&p->is_hlist, &uprobe_insn_slot_table[hash_ptr(p->ainsn.insn, UPROBE_HASH_BITS)]);
311 #endif /* CONFIG_ARM */
315 static struct kprobe *get_ukprobe_bis_arm(void *addr, pid_t tgid)
317 struct hlist_head *head;
318 struct hlist_node *node;
321 /* TODO: test - two processes invokes instrumented function */
322 head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)];
323 hlist_for_each_entry_rcu(p, node, head, is_hlist_arm) {
324 if (p->ainsn.insn == addr && kp2up(p)->task->tgid == tgid) {
332 static struct kprobe *get_ukprobe_bis_thumb(void *addr, pid_t tgid)
334 struct hlist_head *head;
335 struct hlist_node *node;
338 /* TODO: test - two processes invokes instrumented function */
339 head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)];
340 hlist_for_each_entry_rcu(p, node, head, is_hlist_thumb) {
341 if (p->ainsn.insn == addr && kp2up(p)->task->tgid == tgid) {
349 struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs)
351 return thumb_mode(regs) ?
352 get_ukprobe_bis_thumb(addr - 0x1a, tgid) :
353 get_ukprobe_bis_arm(addr - 4 * UPROBES_TRAMP_RET_BREAK_IDX, tgid);
355 #else /* CONFIG_ARM */
356 struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs)
358 struct hlist_head *head;
359 struct hlist_node *node;
362 /* TODO: test - two processes invokes instrumented function */
363 head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)];
364 hlist_for_each_entry_rcu(p, node, head, is_hlist) {
365 if (p->ainsn.insn == addr && kp2up(p)->task->tgid == tgid) {
372 #endif /* CONFIG_ARM */
375 static void remove_uprobe(struct uprobe *up)
377 struct kprobe *p = &up->kp;
378 struct task_struct *task = up->task;
381 free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn_arm);
382 free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn_thumb);
383 #else /* CONFIG_ARM */
384 free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn);
385 #endif /* CONFIG_ARM */
388 static struct hlist_head *uretprobe_inst_table_head(void *hash_key)
390 return &uretprobe_inst_table[hash_ptr (hash_key, UPROBE_HASH_BITS)];
393 /* Called with uretprobe_lock held */
394 static void add_urp_inst(struct uretprobe_instance *ri)
397 * Remove rp inst off the free list -
398 * Add it back when probed function returns
400 hlist_del(&ri->uflist);
402 /* Add rp inst onto table */
403 INIT_HLIST_NODE(&ri->hlist);
404 hlist_add_head(&ri->hlist, uretprobe_inst_table_head(ri->task->mm));
406 /* Also add this rp inst to the used list. */
407 INIT_HLIST_NODE(&ri->uflist);
408 hlist_add_head(&ri->uflist, &ri->rp->used_instances);
411 /* Called with uretprobe_lock held */
412 static void recycle_urp_inst(struct uretprobe_instance *ri)
415 hlist_del(&ri->hlist);
416 /* remove rp inst off the used list */
417 hlist_del(&ri->uflist);
418 /* put rp inst back onto the free list */
419 INIT_HLIST_NODE(&ri->uflist);
420 hlist_add_head(&ri->uflist, &ri->rp->free_instances);
424 /* Called with uretprobe_lock held */
425 static struct uretprobe_instance *get_used_urp_inst(struct uretprobe *rp)
427 struct hlist_node *node;
428 struct uretprobe_instance *ri;
430 hlist_for_each_entry(ri, node, &rp->used_instances, uflist) {
437 /* Called with uretprobe_lock held */
438 struct uretprobe_instance *get_free_urp_inst_no_alloc(struct uretprobe *rp)
440 struct hlist_node *node;
441 struct uretprobe_instance *ri;
443 hlist_for_each_entry (ri, node, &rp->free_instances, uflist) {
450 /* Called with uretprobe_lock held */
451 static void free_urp_inst(struct uretprobe *rp)
453 struct uretprobe_instance *ri;
454 while ((ri = get_free_urp_inst_no_alloc(rp)) != NULL) {
455 hlist_del(&ri->uflist);
460 #define COMMON_URP_NR 10
462 static int alloc_nodes_uretprobe(struct uretprobe *rp)
465 struct uretprobe_instance *inst;
468 #if 1//def CONFIG_PREEMPT
469 rp->maxactive += max(COMMON_URP_NR, 2 * NR_CPUS);
471 rp->maxacpptive += NR_CPUS;
473 alloc_nodes = COMMON_URP_NR;
475 for (i = 0; i < alloc_nodes; ++i) {
476 inst = kmalloc(sizeof(*inst), GFP_ATOMIC);
481 INIT_HLIST_NODE(&inst->uflist);
482 hlist_add_head(&inst->uflist, &rp->free_instances);
488 /* Called with uretprobe_lock held */
489 static struct uretprobe_instance *get_free_urp_inst(struct uretprobe *rp)
491 struct hlist_node *node;
492 struct uretprobe_instance *ri;
494 hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
498 if (!alloc_nodes_uretprobe(rp)) {
499 hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
506 // ===================================================================
508 int dbi_register_uprobe(struct uprobe *up, int atomic)
511 struct kprobe *p, *old_p;
518 DBPRINTF("p->addr = 0x%p p = 0x%p\n", p->addr, p);
520 // thumb address = address-1;
521 #if defined(CONFIG_ARM)
522 // TODO: must be corrected in 'bundle'
523 if ((unsigned long) p->addr & 0x01) {
524 p->addr = (kprobe_opcode_t *)((unsigned long)p->addr & 0xfffffffe);
528 p->mod_refcounted = 0;
530 INIT_LIST_HEAD(&p->list);
531 #ifdef KPROBES_PROFILE
532 p->start_tm.tv_sec = p->start_tm.tv_usec = 0;
533 p->hnd_tm_sum.tv_sec = p->hnd_tm_sum.tv_usec = 0;
537 // get the first item
538 old_p = get_ukprobe(p->addr, kp2up(p)->task->tgid);
541 p->safe_arm = old_p->safe_arm;
542 p->safe_thumb = old_p->safe_thumb;
544 ret = register_aggr_uprobe(old_p, p);
546 // atomic_inc(&kprobe_count);
549 DBPRINTF("goto out\n", ret);
553 ret = arch_prepare_uprobe(up, atomic);
555 DBPRINTF("goto out\n", ret);
559 DBPRINTF ("before out ret = 0x%x\n", ret);
561 // TODO: add uprobe (must be in function)
562 INIT_HLIST_NODE(&p->hlist);
563 hlist_add_head_rcu(&p->hlist, &uprobe_table[hash_ptr(p->addr, UPROBE_HASH_BITS)]);
568 DBPRINTF("out ret = 0x%x\n", ret);
572 void dbi_unregister_uprobe(struct uprobe *up, int atomic)
574 struct kprobe *p, *old_p, *list_p;
578 old_p = get_ukprobe(p->addr, kp2up(p)->task->tgid);
579 if (unlikely(!old_p)) {
584 list_for_each_entry_rcu(list_p, &old_p->list, list) {
586 /* uprobe p is a valid probe */
595 if ((old_p == p) || ((old_p->pre_handler == aggr_pre_uhandler) &&
596 (p->list.next == &old_p->list) && (p->list.prev == &old_p->list))) {
597 /* Only probe on the hash list */
599 hlist_del_rcu(&old_p->hlist);
602 list_del_rcu(&p->list);
608 list_del_rcu(&p->list);
618 if (p->break_handler) {
619 old_p->break_handler = NULL;
622 if (p->post_handler) {
623 list_for_each_entry_rcu (list_p, &old_p->list, list) {
624 if (list_p->post_handler) {
630 if (cleanup_p == 0) {
631 old_p->post_handler = NULL;
637 int dbi_register_ujprobe(struct ujprobe *jp, int atomic)
641 /* Todo: Verify probepoint is a function entry point */
642 jp->up.kp.pre_handler = setjmp_upre_handler;
643 jp->up.kp.break_handler = longjmp_break_uhandler;
645 ret = dbi_register_uprobe(&jp->up, atomic);
650 void dbi_unregister_ujprobe(struct ujprobe *jp, int atomic)
652 dbi_unregister_uprobe(&jp->up, atomic);
654 * Here is an attempt to unregister even those probes that have not been
655 * installed (hence not added to the hlist).
656 * So if we try to delete them from the hlist we will get NULL pointer
657 * dereference error. That is why we check whether this node
658 * really belongs to the hlist.
661 if (!(hlist_unhashed(&jp->up.kp.is_hlist_arm))) {
662 hlist_del_rcu(&jp->up.kp.is_hlist_arm);
664 if (!(hlist_unhashed(&jp->up.kp.is_hlist_thumb))) {
665 hlist_del_rcu(&jp->up.kp.is_hlist_thumb);
667 #else /* CONFIG_ARM */
668 if (!(hlist_unhashed(&jp->up.kp.is_hlist))) {
669 hlist_del_rcu(&jp->up.kp.is_hlist);
671 #endif /* CONFIG_ARM */
674 int trampoline_uprobe_handler(struct kprobe *p, struct pt_regs *regs)
676 struct uretprobe_instance *ri = NULL;
677 struct hlist_head *head;
678 struct hlist_node *node, *tmp;
679 unsigned long flags, tramp_addr, orig_ret_addr = 0;
681 tramp_addr = arch_get_trampoline_addr(p, regs);
682 spin_lock_irqsave(&uretprobe_lock, flags);
684 head = uretprobe_inst_table_head(current->mm);
687 * It is possible to have multiple instances associated with a given
688 * task either because an multiple functions in the call path
689 * have a return probe installed on them, and/or more then one
690 * return probe was registered for a target function.
692 * We can handle this because:
693 * - instances are always inserted at the head of the list
694 * - when multiple return probes are registered for the same
695 * function, the first instance's ret_addr will point to the
696 * real return address, and all the rest will point to
697 * uretprobe_trampoline
699 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
700 if (ri->task != current) {
701 /* another task is sharing our hash bucket */
705 if (ri->rp && ri->rp->handler) {
706 ri->rp->handler(ri, regs, ri->rp->priv_arg);
709 orig_ret_addr = (unsigned long)ri->ret_addr;
710 recycle_urp_inst(ri);
712 if (orig_ret_addr != tramp_addr) {
714 * This is the real return address. Any other
715 * instances associated with this task are for
716 * other calls deeper on the call stack
722 spin_unlock_irqrestore(&uretprobe_lock, flags);
723 arch_set_orig_ret_addr(orig_ret_addr, regs);
728 static int pre_handler_uretprobe(struct kprobe *p, struct pt_regs *regs)
730 struct uprobe *up = container_of(p, struct uprobe, kp);
731 struct uretprobe *rp = container_of(up, struct uretprobe, up);
732 struct uretprobe_instance *ri;
735 /* TODO: consider to only swap the RA after the last pre_handler fired */
736 spin_lock_irqsave(&uretprobe_lock, flags);
738 /* TODO: test - remove retprobe after func entry but before its exit */
739 if ((ri = get_free_urp_inst(rp)) != NULL) {
743 arch_prepare_uretprobe_hl(ri, regs);
750 spin_unlock_irqrestore(&uretprobe_lock, flags);
755 int dbi_register_uretprobe(struct uretprobe *rp, int atomic)
758 struct uretprobe_instance *inst;
760 DBPRINTF ("START\n");
762 rp->up.kp.pre_handler = pre_handler_uretprobe;
763 rp->up.kp.post_handler = NULL;
764 rp->up.kp.fault_handler = NULL;
765 rp->up.kp.break_handler = NULL;
767 /* Pre-allocate memory for max kretprobe instances */
768 if (rp->maxactive <= 0) {
769 #if 1//def CONFIG_PREEMPT
770 rp->maxactive = max(10, 2 * NR_CPUS);
772 rp->maxactive = NR_CPUS;
776 INIT_HLIST_HEAD(&rp->used_instances);
777 INIT_HLIST_HEAD(&rp->free_instances);
779 for (i = 0; i < rp->maxactive; i++) {
780 inst = kmalloc(sizeof(*inst), GFP_KERNEL);
787 INIT_HLIST_NODE(&inst->uflist);
788 hlist_add_head(&inst->uflist, &rp->free_instances);
793 /* Establish function entry probe point */
794 ret = dbi_register_uprobe(&rp->up, atomic);
804 int dbi_disarm_urp_inst(struct uretprobe_instance *ri, struct task_struct *rm_task)
806 struct task_struct *task = rm_task ? rm_task : ri->task;
807 kprobe_opcode_t *tramp;
808 kprobe_opcode_t *sp = (kprobe_opcode_t *)((long)ri->sp & ~1);
809 kprobe_opcode_t *stack = sp - RETPROBE_STACK_DEPTH + 1;
810 kprobe_opcode_t *found = NULL;
811 kprobe_opcode_t *buf[RETPROBE_STACK_DEPTH];
814 /* Understand function mode */
815 if ((long)ri->sp & 1) {
816 tramp = (kprobe_opcode_t *)
817 ((unsigned long)ri->rp->up.kp.ainsn.insn + 0x1b);
819 tramp = (kprobe_opcode_t *)
820 (ri->rp->up.kp.ainsn.insn + UPROBES_TRAMP_RET_BREAK_IDX);
823 retval = read_proc_vm_atomic(task, (unsigned long)stack, buf, sizeof(buf));
824 if (retval != sizeof(buf)) {
825 printk("---> %s (%d/%d): failed to read stack from %08lx",
826 task->comm, task->tgid, task->pid, (unsigned long)stack);
831 /* search the stack from the bottom */
832 for (i = RETPROBE_STACK_DEPTH - 1; i >= 0; i--) {
833 if (buf[i] == tramp) {
840 printk("---> %s (%d/%d): trampoline found at %08lx (%08lx /%+d) - %p\n",
841 task->comm, task->tgid, task->pid,
842 (unsigned long)found, (unsigned long)sp,
843 found - sp, ri->rp->up.kp.addr);
844 retval = write_proc_vm_atomic(task, (unsigned long)found, &ri->ret_addr,
845 sizeof(ri->ret_addr));
846 if (retval != sizeof(ri->ret_addr)) {
847 printk("---> %s (%d/%d): failed to write value to %08lx",
848 task->comm, task->tgid, task->pid, (unsigned long)found);
854 struct pt_regs *uregs = task_pt_regs(ri->task);
855 unsigned long ra = dbi_get_ret_addr(uregs);
856 if (ra == (unsigned long)tramp) {
857 printk("---> %s (%d/%d): trampoline found at lr = %08lx - %p\n",
858 task->comm, task->tgid, task->pid, ra, ri->rp->up.kp.addr);
859 dbi_set_ret_addr(uregs, (unsigned long)tramp);
862 printk("---> %s (%d/%d): trampoline NOT found at sp = %08lx, lr = %08lx - %p\n",
863 task->comm, task->tgid, task->pid,
864 (unsigned long)sp, ra, ri->rp->up.kp.addr);
873 /* Called with uretprobe_lock held */
874 int dbi_disarm_urp_inst_for_task(struct task_struct *parent, struct task_struct *task)
876 struct uretprobe_instance *ri;
877 struct hlist_node *node, *tmp;
878 struct hlist_head *head = uretprobe_inst_table_head(parent->mm);
880 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
881 if (parent == ri->task) {
882 dbi_disarm_urp_inst(ri, task);
888 EXPORT_SYMBOL_GPL(dbi_disarm_urp_inst_for_task);
890 void dbi_unregister_uretprobe(struct uretprobe *rp, int atomic)
893 struct uretprobe_instance *ri;
895 spin_lock_irqsave (&uretprobe_lock, flags);
897 while ((ri = get_used_urp_inst(rp)) != NULL) {
898 if (dbi_disarm_urp_inst(ri, NULL) != 0)
899 /*panic*/printk("%s (%d/%d): cannot disarm urp instance (%08lx)\n",
900 ri->task->comm, ri->task->tgid, ri->task->pid,
901 (unsigned long)rp->up.kp.addr);
902 recycle_urp_inst(ri);
905 if (hlist_empty(&rp->used_instances)) {
906 struct kprobe *p = &rp->up.kp;
908 if (!(hlist_unhashed(&p->is_hlist_arm))) {
909 hlist_del_rcu(&p->is_hlist_arm);
912 if (!(hlist_unhashed(&p->is_hlist_thumb))) {
913 hlist_del_rcu(&p->is_hlist_thumb);
915 #else /* CONFIG_ARM */
916 if (!(hlist_unhashed(&p->is_hlist))) {
917 hlist_del_rcu(&p->is_hlist);
919 #endif /* CONFIG_ARM */
922 while ((ri = get_used_urp_inst(rp)) != NULL) {
924 hlist_del(&ri->uflist);
927 spin_unlock_irqrestore(&uretprobe_lock, flags);
930 dbi_unregister_uprobe(&rp->up, atomic);
933 void dbi_unregister_all_uprobes(struct task_struct *task, int atomic)
935 struct hlist_head *head;
936 struct hlist_node *node, *tnode;
940 for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
941 head = &uprobe_table[i];
942 hlist_for_each_entry_safe(p, node, tnode, head, hlist) {
943 if (kp2up(p)->task->tgid == task->tgid) {
944 struct uprobe *up = container_of(p, struct uprobe, kp);
945 printk("dbi_unregister_all_uprobes: delete uprobe at %p[%lx] for %s/%d\n",
946 p->addr, (unsigned long)p->opcode, task->comm, task->pid);
947 dbi_unregister_uprobe(up, atomic);
953 void dbi_uprobe_return(void)
955 dbi_arch_uprobe_return();
958 static int __init init_uprobes(void)
961 init_uprobes_insn_slots();
962 init_uretprobe_inst_table();
964 return swap_arch_init_uprobes();
967 static void __exit exit_uprobes(void)
969 swap_arch_exit_uprobes();
972 EXPORT_SYMBOL_GPL(dbi_uprobe_return);
973 EXPORT_SYMBOL_GPL(dbi_register_ujprobe);
974 EXPORT_SYMBOL_GPL(dbi_unregister_ujprobe);
975 EXPORT_SYMBOL_GPL(dbi_register_uretprobe);
976 EXPORT_SYMBOL_GPL(dbi_unregister_uretprobe);
977 EXPORT_SYMBOL_GPL(dbi_unregister_all_uprobes);
979 module_init(init_uprobes);
980 module_exit(exit_uprobes);
982 MODULE_LICENSE ("GPL");