Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 3720
b: refs/heads/master
c: 802eae7
h: refs/heads/master
v: v3
  • Loading branch information
Rusty Lynch authored and Linus Torvalds committed Jun 27, 2005
1 parent 0dcff93 commit 1603f1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 76 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9ec4b1f356b3bad928ae8e2aa9caebfa737d52df
refs/heads/master: 802eae7c800fb7f583e6c06afa363585af2bef00
28 changes: 3 additions & 25 deletions trunk/include/linux/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,12 @@ struct jprobe {
};

#ifdef ARCH_SUPPORTS_KRETPROBES
extern int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs);
extern void trampoline_post_handler(struct kprobe *p, struct pt_regs *regs,
unsigned long flags);
extern struct task_struct *arch_get_kprobe_task(void *ptr);
extern void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs);
extern void arch_kprobe_flush_task(struct task_struct *tk);
#else /* ARCH_SUPPORTS_KRETPROBES */
static inline void kretprobe_trampoline(void)
{
}
static inline int trampoline_probe_handler(struct kprobe *p,
struct pt_regs *regs)
{
return 0;
}
static inline void trampoline_post_handler(struct kprobe *p,
struct pt_regs *regs, unsigned long flags)
{
}
static inline void arch_prepare_kretprobe(struct kretprobe *rp,
struct pt_regs *regs)
{
}
static inline void arch_kprobe_flush_task(struct task_struct *tk)
{
}
#define arch_get_kprobe_task(ptr) ((struct task_struct *)NULL)
#endif /* ARCH_SUPPORTS_KRETPROBES */
/*
* Function-return probe -
Expand All @@ -155,8 +134,8 @@ struct kretprobe_instance {
struct hlist_node uflist; /* either on free list or used list */
struct hlist_node hlist;
struct kretprobe *rp;
void *ret_addr;
void *stack_addr;
kprobe_opcode_t *ret_addr;
struct task_struct *task;
};

#ifdef CONFIG_KPROBES
Expand All @@ -176,6 +155,7 @@ extern void arch_copy_kprobe(struct kprobe *p);
extern void arch_arm_kprobe(struct kprobe *p);
extern void arch_disarm_kprobe(struct kprobe *p);
extern void arch_remove_kprobe(struct kprobe *p);
extern int arch_init(void);
extern void show_registers(struct pt_regs *regs);
extern kprobe_opcode_t *get_insn_slot(void);
extern void free_insn_slot(kprobe_opcode_t *slot);
Expand All @@ -196,8 +176,6 @@ int register_kretprobe(struct kretprobe *rp);
void unregister_kretprobe(struct kretprobe *rp);

struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp);
struct kretprobe_instance *get_rp_inst(void *sara);
struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk);
void add_rp_inst(struct kretprobe_instance *ri);
void kprobe_flush_task(struct task_struct *tk);
void recycle_rp_inst(struct kretprobe_instance *ri);
Expand Down
69 changes: 19 additions & 50 deletions trunk/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,6 @@ static int aggr_break_handler(struct kprobe *p, struct pt_regs *regs)
return 0;
}

struct kprobe trampoline_p = {
.addr = (kprobe_opcode_t *) &kretprobe_trampoline,
.pre_handler = trampoline_probe_handler,
.post_handler = trampoline_post_handler
};

struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp)
{
struct hlist_node *node;
Expand All @@ -264,35 +258,18 @@ static struct kretprobe_instance *get_used_rp_inst(struct kretprobe *rp)
return NULL;
}

struct kretprobe_instance *get_rp_inst(void *sara)
{
struct hlist_head *head;
struct hlist_node *node;
struct task_struct *tsk;
struct kretprobe_instance *ri;

tsk = arch_get_kprobe_task(sara);
head = &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)];
hlist_for_each_entry(ri, node, head, hlist) {
if (ri->stack_addr == sara)
return ri;
}
return NULL;
}

void add_rp_inst(struct kretprobe_instance *ri)
{
struct task_struct *tsk;
/*
* Remove rp inst off the free list -
* Add it back when probed function returns
*/
hlist_del(&ri->uflist);
tsk = arch_get_kprobe_task(ri->stack_addr);

/* Add rp inst onto table */
INIT_HLIST_NODE(&ri->hlist);
hlist_add_head(&ri->hlist,
&kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)]);
&kretprobe_inst_table[hash_ptr(ri->task, KPROBE_HASH_BITS)]);

/* Also add this rp inst to the used list. */
INIT_HLIST_NODE(&ri->uflist);
Expand All @@ -319,34 +296,25 @@ struct hlist_head * kretprobe_inst_table_head(struct task_struct *tsk)
return &kretprobe_inst_table[hash_ptr(tsk, KPROBE_HASH_BITS)];
}

struct kretprobe_instance *get_rp_inst_tsk(struct task_struct *tk)
{
struct task_struct *tsk;
struct hlist_head *head;
struct hlist_node *node;
struct kretprobe_instance *ri;

head = &kretprobe_inst_table[hash_ptr(tk, KPROBE_HASH_BITS)];

hlist_for_each_entry(ri, node, head, hlist) {
tsk = arch_get_kprobe_task(ri->stack_addr);
if (tsk == tk)
return ri;
}
return NULL;
}

/*
* This function is called from do_exit or do_execv when task tk's stack is
* about to be recycled. Recycle any function-return probe instances
* associated with this task. These represent probed functions that have
* been called but may never return.
* This function is called from exit_thread or flush_thread when task tk's
* stack is being recycled so that we can recycle any function-return probe
* instances associated with this task. These left over instances represent
* probed functions that have been called but will never return.
*/
void kprobe_flush_task(struct task_struct *tk)
{
struct kretprobe_instance *ri;
struct hlist_head *head;
struct hlist_node *node, *tmp;
unsigned long flags = 0;

spin_lock_irqsave(&kprobe_lock, flags);
arch_kprobe_flush_task(tk);
head = kretprobe_inst_table_head(current);
hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
if (ri->task == tk)
recycle_rp_inst(ri);
}
spin_unlock_irqrestore(&kprobe_lock, flags);
}

Expand Down Expand Up @@ -606,9 +574,10 @@ static int __init init_kprobes(void)
INIT_HLIST_HEAD(&kretprobe_inst_table[i]);
}

err = register_die_notifier(&kprobe_exceptions_nb);
/* Register the trampoline probe for return probe */
register_kprobe(&trampoline_p);
err = arch_init();
if (!err)
err = register_die_notifier(&kprobe_exceptions_nb);

return err;
}

Expand Down

0 comments on commit 1603f1b

Please sign in to comment.