diff options
author | Vyacheslav Cherkashin <v.cherkashin@samsung.com> | 2014-05-28 14:11:50 +0400 |
---|---|---|
committer | Vyacheslav Cherkashin <v.cherkashin@samsung.com> | 2014-07-31 08:00:26 -0700 |
commit | 92943d578946dba39396d1488322af7cc8da422e (patch) | |
tree | 0666649e773952bee2c53a6a91754b355d2da6e8 | |
parent | 19b057aaa73cc503c448510e746f1edeaa2034ae (diff) | |
download | swap-modules-92943d578946dba39396d1488322af7cc8da422e.tar.gz swap-modules-92943d578946dba39396d1488322af7cc8da422e.tar.bz2 swap-modules-92943d578946dba39396d1488322af7cc8da422e.zip |
[REFACTOR] kretprobe_trampoline() for x86
Change-Id: I8035cf2696a0b56d4cb5f30c787e2ac98eccad45
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
-rw-r--r-- | kprobe/arch/asm-x86/swap_kprobes.c | 79 |
1 files changed, 42 insertions, 37 deletions
diff --git a/kprobe/arch/asm-x86/swap_kprobes.c b/kprobe/arch/asm-x86/swap_kprobes.c index d302ca91..cd96cf2b 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) |