From a8e5374c6f509dabd1b859accecd061d9dd84f92 Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Mon, 11 Nov 2013 10:37:03 +0400 Subject: [PATCH] [IMPROVE] add function to get arguments in US Change-Id: Iea141d4ec2aa4b08f682f10ee9b652cbf7864f84 Signed-off-by: Vyacheslav Cherkashin --- uprobe/arch/asm-arm/swap_uprobes.h | 26 ++++++++++++++++++++++++++ uprobe/arch/asm-x86/swap_uprobes.h | 12 ++++++++++++ 2 files changed, 38 insertions(+) diff --git a/uprobe/arch/asm-arm/swap_uprobes.h b/uprobe/arch/asm-arm/swap_uprobes.h index ecdec91..664e1c1 100644 --- a/uprobe/arch/asm-arm/swap_uprobes.h +++ b/uprobe/arch/asm-arm/swap_uprobes.h @@ -28,6 +28,10 @@ #ifndef _ARM_SWAP_UPROBES_H #define _ARM_SWAP_UPROBES_H + +#include + + struct kprobe; struct pt_regs; struct task_struct; @@ -51,6 +55,28 @@ void arch_prepare_uretprobe(struct uretprobe_instance *ri, struct pt_regs *regs) unsigned long arch_get_trampoline_addr(struct kprobe *p, struct pt_regs *regs); void arch_set_orig_ret_addr(unsigned long orig_ret_addr, struct pt_regs *regs); +static inline unsigned long swap_get_uarg(struct pt_regs *regs, unsigned long n) +{ + u32 *ptr, addr = 0; + + switch (n) { + case 0: + return regs->ARM_r0; + case 1: + return regs->ARM_r1; + case 2: + return regs->ARM_r2; + case 3: + return regs->ARM_r3; + } + + ptr = (u32 *)regs->ARM_sp + n - 4; + if (get_user(addr, ptr)) + printk("failed to dereference a pointer, ptr=%p\n", ptr); + + return addr; +} + int swap_arch_init_uprobes(void); void swap_arch_exit_uprobes(void); diff --git a/uprobe/arch/asm-x86/swap_uprobes.h b/uprobe/arch/asm-x86/swap_uprobes.h index 3af126f..51215a4 100644 --- a/uprobe/arch/asm-x86/swap_uprobes.h +++ b/uprobe/arch/asm-x86/swap_uprobes.h @@ -49,6 +49,18 @@ void arch_prepare_uretprobe(struct uretprobe_instance *ri, struct pt_regs *regs) unsigned long arch_get_trampoline_addr(struct kprobe *p, struct pt_regs *regs); void arch_set_orig_ret_addr(unsigned long orig_ret_addr, struct pt_regs *regs); +static inline unsigned long swap_get_uarg(struct pt_regs *regs, unsigned long n) +{ + u32 *ptr, addr = 0; + + /* 1 - return address saved on top of the stack */ + ptr = (u32 *)regs->sp + n + 1; + if (get_user(addr, ptr)) + printk("failed to dereference a pointer, ptr=%p\n", ptr); + + return addr; +} + int swap_arch_init_uprobes(void); void swap_arch_exit_uprobes(void); -- 2.7.4