From 086db720b3eb3caa777f958ff39d40bbab99c3d9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Tue, 2 Apr 2013 13:18:41 +0400 Subject: [PATCH] [REFACTOR] redesign get_kprobe_by_insn_slot() -struct kprobe *get_kprobe_by_insn_slot(kprobe_opcode_t *addr, pid_t tgid, struct pt_regs *regs); +struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs); --- kprobe/dbi_kprobes.h | 6 +---- uprobe/arch/asm-arm/swap_uprobes.c | 2 +- uprobe/swap_uprobes.c | 47 +++++++++++++++----------------------- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/kprobe/dbi_kprobes.h b/kprobe/dbi_kprobes.h index df939cd..161c328 100644 --- a/kprobe/dbi_kprobes.h +++ b/kprobe/dbi_kprobes.h @@ -223,11 +223,7 @@ extern void kprobes_inc_nmissed_count (struct kprobe *p); /* Get the kprobe at this addr (if any) - called with preemption disabled */ struct kprobe *get_kprobe(kprobe_opcode_t *addr, pid_t tgid); -#ifdef CONFIG_ARM -struct kprobe *get_kprobe_by_insn_slot(kprobe_opcode_t *addr, pid_t tgid, struct pt_regs *regs); -#else /* CONFIG_ARM */ -struct kprobe *get_kprobe_by_insn_slot (void *addr, int tgid, struct task_struct *ctask); -#endif /* CONFIG_ARM */ +struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs); struct hlist_head *kretprobe_inst_table_head (void *hash_key); diff --git a/uprobe/arch/asm-arm/swap_uprobes.c b/uprobe/arch/asm-arm/swap_uprobes.c index 75446f4..f0097a6 100644 --- a/uprobe/arch/asm-arm/swap_uprobes.c +++ b/uprobe/arch/asm-arm/swap_uprobes.c @@ -693,7 +693,7 @@ static int uprobe_handler(struct pt_regs *regs) p = get_ukprobe(addr, tgid); if (p == NULL) { - p = get_kprobe_by_insn_slot(addr, tgid, regs); + p = get_ukprobe_by_insn_slot(addr, tgid, regs); if (p == NULL) { printk("no_uprobe\n"); return 1; diff --git a/uprobe/swap_uprobes.c b/uprobe/swap_uprobes.c index 38c47cb..5fae81c 100644 --- a/uprobe/swap_uprobes.c +++ b/uprobe/swap_uprobes.c @@ -313,71 +313,62 @@ static void add_uprobe_table(struct kprobe *p) } #ifdef CONFIG_ARM -static struct kprobe *get_kprobe_by_insn_slot_arm(kprobe_opcode_t *addr, pid_t tgid) +static struct kprobe *get_ukprobe_bis_arm(void *addr, pid_t tgid) { struct hlist_head *head; struct hlist_node *node; - struct kprobe *p, *ret = NULL; + struct kprobe *p; /* TODO: test - two processes invokes instrumented function */ head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)]; hlist_for_each_entry_rcu(p, node, head, is_hlist_arm) { - if (p->ainsn.insn == addr && tgid == p->tgid) { - ret = p; - break; + if (p->ainsn.insn == addr && kp2up(p)->task->tgid == tgid) { + return p; } } - return ret; + return NULL; } -static struct kprobe *get_kprobe_by_insn_slot_thumb(kprobe_opcode_t *addr, pid_t tgid) +static struct kprobe *get_ukprobe_bis_thumb(void *addr, pid_t tgid) { struct hlist_head *head; struct hlist_node *node; - struct kprobe *p, *ret = NULL; + struct kprobe *p; /* TODO: test - two processes invokes instrumented function */ head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)]; hlist_for_each_entry_rcu(p, node, head, is_hlist_thumb) { - if (p->ainsn.insn == addr && tgid == p->tgid) { - ret = p; - break; + if (p->ainsn.insn == addr && kp2up(p)->task->tgid == tgid) { + return p; } } - return ret; + return NULL; } -struct kprobe *get_kprobe_by_insn_slot(kprobe_opcode_t *addr, pid_t tgid, struct pt_regs *regs) +struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs) { - struct kprobe *p = NULL; - - if (!thumb_mode(regs)) { - p = get_kprobe_by_insn_slot_arm(addr - UPROBES_TRAMP_RET_BREAK_IDX, tgid); - } else { - p = get_kprobe_by_insn_slot_thumb((kprobe_opcode_t *)((unsigned long)addr - 0x1a), tgid); - } - - return p; + return thumb_mode(regs) ? + get_ukprobe_bis_thumb(addr - 0x1a, tgid) : + get_ukprobe_bis_arm(addr - 4 * UPROBES_TRAMP_RET_BREAK_IDX, tgid); } #else /* CONFIG_ARM */ -struct kprobe *get_kprobe_by_insn_slot(void *addr, int tgid, struct task_struct *ctask) +struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs) { struct hlist_head *head; struct hlist_node *node; - struct kprobe *p, *ret = NULL; + struct kprobe *p; /* TODO: test - two processes invokes instrumented function */ head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)]; hlist_for_each_entry_rcu(p, node, head, is_hlist) { - if (p->ainsn.insn == addr && tgid == p->tgid) { - ret = p; - break; + if (p->ainsn.insn == addr && kp2up(p)->task->tgid == tgid) { + return p; } } - return ret; + return NULL; } #endif /* CONFIG_ARM */ -- 2.7.4