From 92943d578946dba39396d1488322af7cc8da422e Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 28 May 2014 14:11:50 +0400 Subject: [PATCH] [REFACTOR] kretprobe_trampoline() for x86 Change-Id: I8035cf2696a0b56d4cb5f30c787e2ac98eccad45 Signed-off-by: Vyacheslav Cherkashin --- kprobe/arch/asm-x86/swap_kprobes.c | 79 ++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/kprobe/arch/asm-x86/swap_kprobes.c b/kprobe/arch/asm-x86/swap_kprobes.c index d302ca9..cd96cf2 100644 --- a/kprobe/arch/asm-x86/swap_kprobes.c +++ b/kprobe/arch/asm-x86/swap_kprobes.c @@ -54,50 +54,55 @@ static void (*swap_show_registers)(struct pt_regs * regs); /** Stack address. */ #define stack_addr(regs) ((unsigned long *)kernel_stack_pointer(regs)) + +#define SWAP_SAVE_REGS_STRING \ + /* Skip cs, ip, orig_ax and gs. */ \ + "subl $16, %esp\n" \ + "pushl %fs\n" \ + "pushl %es\n" \ + "pushl %ds\n" \ + "pushl %eax\n" \ + "pushl %ebp\n" \ + "pushl %edi\n" \ + "pushl %esi\n" \ + "pushl %edx\n" \ + "pushl %ecx\n" \ + "pushl %ebx\n" +#define SWAP_RESTORE_REGS_STRING \ + "popl %ebx\n" \ + "popl %ecx\n" \ + "popl %edx\n" \ + "popl %esi\n" \ + "popl %edi\n" \ + "popl %ebp\n" \ + "popl %eax\n" \ + /* Skip ds, es, fs, gs, orig_ax, and ip. Note: don't pop cs here*/\ + "addl $24, %esp\n" + + /* * Function return probe trampoline: * - init_kprobes() establishes a probepoint here * - When the probed function returns, this probe * causes the handlers to fire */ -static __used void swap_kretprobe_trampoline_holder(void) -{ - asm volatile(".global swap_kretprobe_trampoline\n" - "swap_kretprobe_trampoline:\n" - " pushf\n" - /* skip cs, ip, orig_ax and gs. */ - " subl $16, %esp\n" - " pushl %fs\n" - " pushl %es\n" - " pushl %ds\n" - " pushl %eax\n" - " pushl %ebp\n" - " pushl %edi\n" - " pushl %esi\n" - " pushl %edx\n" - " pushl %ecx\n" - " pushl %ebx\n" - " movl %esp, %eax\n" - " call trampoline_probe_handler_x86\n" - /* move eflags to cs */ - " movl 56(%esp), %edx\n" - " movl %edx, 52(%esp)\n" - /* replace saved flags with true return address. */ - " movl %eax, 56(%esp)\n" - " popl %ebx\n" "" - " popl %ecx\n" - " popl %edx\n" - " popl %esi\n" - " popl %edi\n" - " popl %ebp\n" - " popl %eax\n" - /* skip ds, es, fs, gs, orig_ax, and ip. Note: don't pop cs here*/ - " addl $24, %esp\n" - " popf\n" - " ret\n"); -} - void swap_kretprobe_trampoline(void); +__asm( + ".global swap_kretprobe_trampoline \n" + "swap_kretprobe_trampoline: \n" + "pushf \n" + SWAP_SAVE_REGS_STRING + "movl %esp, %eax \n" + "call trampoline_probe_handler_x86 \n" + /* move eflags to cs */ + "movl 56(%esp), %edx \n" + "movl %edx, 52(%esp) \n" + /* replace saved flags with true return address. */ + "movl %eax, 56(%esp) \n" + SWAP_RESTORE_REGS_STRING + "popf \n" + "ret \n" +); /* insert a jmp code */ static __always_inline void set_jmp_op (void *from, void *to) -- 2.7.4