Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 3724
b: refs/heads/master
c: 97f7943
h: refs/heads/master
v: v3
  • Loading branch information
Rusty Lynch authored and Linus Torvalds committed Jun 27, 2005
1 parent ed41709 commit be46310
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9508dbfe39112813612085c00d55bacd398eddc6
refs/heads/master: 97f7943d70ff0e1e92ea627c44cfacfdae65dbc4
99 changes: 99 additions & 0 deletions trunk/arch/ppc64/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ static inline void restore_previous_kprobe(void)
kprobe_saved_msr = kprobe_saved_msr_prev;
}

void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
{
struct kretprobe_instance *ri;

if ((ri = get_free_rp_inst(rp)) != NULL) {
ri->rp = rp;
ri->task = current;
ri->ret_addr = (kprobe_opcode_t *)regs->link;

/* Replace the return addr with trampoline addr */
regs->link = (unsigned long)kretprobe_trampoline;
add_rp_inst(ri);
} else {
rp->nmissed++;
}
}

static inline int kprobe_handler(struct pt_regs *regs)
{
struct kprobe *p;
Expand Down Expand Up @@ -211,6 +228,78 @@ static inline int kprobe_handler(struct pt_regs *regs)
return ret;
}

/*
* Function return probe trampoline:
* - init_kprobes() establishes a probepoint here
* - When the probed function returns, this probe
* causes the handlers to fire
*/
void kretprobe_trampoline_holder(void)
{
asm volatile(".global kretprobe_trampoline\n"
"kretprobe_trampoline:\n"
"nop\n");
}

/*
* Called when the probe at kretprobe trampoline is hit
*/
int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
{
struct kretprobe_instance *ri = NULL;
struct hlist_head *head;
struct hlist_node *node, *tmp;
unsigned long orig_ret_address = 0;
unsigned long trampoline_address =(unsigned long)&kretprobe_trampoline;

head = kretprobe_inst_table_head(current);

/*
* It is possible to have multiple instances associated with a given
* task either because an multiple functions in the call path
* have a return probe installed on them, and/or more then one return
* return probe was registered for a target function.
*
* We can handle this because:
* - instances are always inserted at the head of the list
* - when multiple return probes are registered for the same
* function, the first instance's ret_addr will point to the
* real return address, and all the rest will point to
* kretprobe_trampoline
*/
hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
if (ri->task != current)
/* another task is sharing our hash bucket */
continue;

if (ri->rp && ri->rp->handler)
ri->rp->handler(ri, regs);

orig_ret_address = (unsigned long)ri->ret_addr;
recycle_rp_inst(ri);

if (orig_ret_address != trampoline_address)
/*
* This is the real return address. Any other
* instances associated with this task are for
* other calls deeper on the call stack
*/
break;
}

BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
regs->nip = orig_ret_address;

unlock_kprobes();

/*
* By returning a non-zero value, we are telling
* kprobe_handler() that we have handled unlocking
* and re-enabling preemption.
*/
return 1;
}

/*
* Called after single-stepping. p->addr is the address of the
* instruction whose first byte has been replaced by the "breakpoint"
Expand Down Expand Up @@ -349,3 +438,13 @@ int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
memcpy(regs, &jprobe_saved_regs, sizeof(struct pt_regs));
return 1;
}

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

int __init arch_init(void)
{
return register_kprobe(&trampoline_p);
}
4 changes: 4 additions & 0 deletions trunk/arch/ppc64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/kallsyms.h>
#include <linux/interrupt.h>
#include <linux/utsname.h>
#include <linux/kprobes.h>

#include <asm/pgtable.h>
#include <asm/uaccess.h>
Expand Down Expand Up @@ -307,6 +308,8 @@ void show_regs(struct pt_regs * regs)

void exit_thread(void)
{
kprobe_flush_task(current);

#ifndef CONFIG_SMP
if (last_task_used_math == current)
last_task_used_math = NULL;
Expand All @@ -321,6 +324,7 @@ void flush_thread(void)
{
struct thread_info *t = current_thread_info();

kprobe_flush_task(current);
if (t->flags & _TIF_ABI_PENDING)
t->flags ^= (_TIF_ABI_PENDING | _TIF_32BIT);

Expand Down
3 changes: 3 additions & 0 deletions trunk/include/asm-ppc64/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ typedef unsigned int kprobe_opcode_t;

#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)((func_descr_t *)pentry)

#define ARCH_SUPPORTS_KRETPROBES
void kretprobe_trampoline(void);

/* Architecture specific copy of original instruction */
struct arch_specific_insn {
/* copy of original instruction */
Expand Down

0 comments on commit be46310

Please sign in to comment.