1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __X86_KERNEL_KPROBES_COMMON_H 3 #define __X86_KERNEL_KPROBES_COMMON_H 4 5 /* Kprobes and Optprobes common header */ 6 7 #include <asm/asm.h> 8 #include <asm/frame.h> 9 10 #ifdef CONFIG_X86_64 11 12 #define SAVE_REGS_STRING \ 13 /* Skip cs, ip, orig_ax. */ \ 14 " subq $24, %rsp\n" \ 15 " pushq %rdi\n" \ 16 " pushq %rsi\n" \ 17 " pushq %rdx\n" \ 18 " pushq %rcx\n" \ 19 " pushq %rax\n" \ 20 " pushq %r8\n" \ 21 " pushq %r9\n" \ 22 " pushq %r10\n" \ 23 " pushq %r11\n" \ 24 " pushq %rbx\n" \ 25 " pushq %rbp\n" \ 26 " pushq %r12\n" \ 27 " pushq %r13\n" \ 28 " pushq %r14\n" \ 29 " pushq %r15\n" \ 30 ENCODE_FRAME_POINTER 31 32 #define RESTORE_REGS_STRING \ 33 " popq %r15\n" \ 34 " popq %r14\n" \ 35 " popq %r13\n" \ 36 " popq %r12\n" \ 37 " popq %rbp\n" \ 38 " popq %rbx\n" \ 39 " popq %r11\n" \ 40 " popq %r10\n" \ 41 " popq %r9\n" \ 42 " popq %r8\n" \ 43 " popq %rax\n" \ 44 " popq %rcx\n" \ 45 " popq %rdx\n" \ 46 " popq %rsi\n" \ 47 " popq %rdi\n" \ 48 /* Skip orig_ax, ip, cs */ \ 49 " addq $24, %rsp\n" 50 #else 51 52 #define SAVE_REGS_STRING \ 53 /* Skip cs, ip, orig_ax and gs. */ \ 54 " subl $4*4, %esp\n" \ 55 " pushl %fs\n" \ 56 " pushl %es\n" \ 57 " pushl %ds\n" \ 58 " pushl %eax\n" \ 59 " pushl %ebp\n" \ 60 " pushl %edi\n" \ 61 " pushl %esi\n" \ 62 " pushl %edx\n" \ 63 " pushl %ecx\n" \ 64 " pushl %ebx\n" \ 65 ENCODE_FRAME_POINTER 66 67 #define RESTORE_REGS_STRING \ 68 " popl %ebx\n" \ 69 " popl %ecx\n" \ 70 " popl %edx\n" \ 71 " popl %esi\n" \ 72 " popl %edi\n" \ 73 " popl %ebp\n" \ 74 " popl %eax\n" \ 75 /* Skip ds, es, fs, gs, orig_ax, ip, and cs. */\ 76 " addl $7*4, %esp\n" 77 #endif 78 79 /* Ensure if the instruction can be boostable */ 80 extern int can_boost(struct insn *insn, void *orig_addr); 81 /* Recover instruction if given address is probed */ 82 extern unsigned long recover_probed_instruction(kprobe_opcode_t *buf, 83 unsigned long addr); 84 /* 85 * Copy an instruction and adjust the displacement if the instruction 86 * uses the %rip-relative addressing mode. 87 */ 88 extern int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn); 89 90 /* Generate a relative-jump/call instruction */ 91 extern void synthesize_reljump(void *dest, void *from, void *to); 92 extern void synthesize_relcall(void *dest, void *from, void *to); 93 94 #ifdef CONFIG_OPTPROBES 95 extern int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter); 96 extern unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr); 97 #else /* !CONFIG_OPTPROBES */ 98 static inline int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter) 99 { 100 return 0; 101 } 102 static inline unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr) 103 { 104 return addr; 105 } 106 #endif 107 108 #endif 109