Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __X86_KERNEL_KPROBES_COMMON_H
0003 #define __X86_KERNEL_KPROBES_COMMON_H
0004 
0005 /* Kprobes and Optprobes common header */
0006 
0007 #include <asm/asm.h>
0008 #include <asm/frame.h>
0009 #include <asm/insn.h>
0010 
0011 #ifdef CONFIG_X86_64
0012 
0013 #define SAVE_REGS_STRING            \
0014     /* Skip cs, ip, orig_ax. */     \
0015     "   subq $24, %rsp\n"       \
0016     "   pushq %rdi\n"           \
0017     "   pushq %rsi\n"           \
0018     "   pushq %rdx\n"           \
0019     "   pushq %rcx\n"           \
0020     "   pushq %rax\n"           \
0021     "   pushq %r8\n"            \
0022     "   pushq %r9\n"            \
0023     "   pushq %r10\n"           \
0024     "   pushq %r11\n"           \
0025     "   pushq %rbx\n"           \
0026     "   pushq %rbp\n"           \
0027     "   pushq %r12\n"           \
0028     "   pushq %r13\n"           \
0029     "   pushq %r14\n"           \
0030     "   pushq %r15\n"           \
0031     ENCODE_FRAME_POINTER
0032 
0033 #define RESTORE_REGS_STRING         \
0034     "   popq %r15\n"            \
0035     "   popq %r14\n"            \
0036     "   popq %r13\n"            \
0037     "   popq %r12\n"            \
0038     "   popq %rbp\n"            \
0039     "   popq %rbx\n"            \
0040     "   popq %r11\n"            \
0041     "   popq %r10\n"            \
0042     "   popq %r9\n"         \
0043     "   popq %r8\n"         \
0044     "   popq %rax\n"            \
0045     "   popq %rcx\n"            \
0046     "   popq %rdx\n"            \
0047     "   popq %rsi\n"            \
0048     "   popq %rdi\n"            \
0049     /* Skip orig_ax, ip, cs */      \
0050     "   addq $24, %rsp\n"
0051 #else
0052 
0053 #define SAVE_REGS_STRING            \
0054     /* Skip cs, ip, orig_ax and gs. */  \
0055     "   subl $4*4, %esp\n"      \
0056     "   pushl %fs\n"            \
0057     "   pushl %es\n"            \
0058     "   pushl %ds\n"            \
0059     "   pushl %eax\n"           \
0060     "   pushl %ebp\n"           \
0061     "   pushl %edi\n"           \
0062     "   pushl %esi\n"           \
0063     "   pushl %edx\n"           \
0064     "   pushl %ecx\n"           \
0065     "   pushl %ebx\n"           \
0066     ENCODE_FRAME_POINTER
0067 
0068 #define RESTORE_REGS_STRING         \
0069     "   popl %ebx\n"            \
0070     "   popl %ecx\n"            \
0071     "   popl %edx\n"            \
0072     "   popl %esi\n"            \
0073     "   popl %edi\n"            \
0074     "   popl %ebp\n"            \
0075     "   popl %eax\n"            \
0076     /* Skip ds, es, fs, gs, orig_ax, ip, and cs. */\
0077     "   addl $7*4, %esp\n"
0078 #endif
0079 
0080 /* Ensure if the instruction can be boostable */
0081 extern int can_boost(struct insn *insn, void *orig_addr);
0082 /* Recover instruction if given address is probed */
0083 extern unsigned long recover_probed_instruction(kprobe_opcode_t *buf,
0084                      unsigned long addr);
0085 /*
0086  * Copy an instruction and adjust the displacement if the instruction
0087  * uses the %rip-relative addressing mode.
0088  */
0089 extern int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn);
0090 
0091 /* Generate a relative-jump/call instruction */
0092 extern void synthesize_reljump(void *dest, void *from, void *to);
0093 extern void synthesize_relcall(void *dest, void *from, void *to);
0094 
0095 #ifdef  CONFIG_OPTPROBES
0096 extern int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter);
0097 extern unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr);
0098 #else   /* !CONFIG_OPTPROBES */
0099 static inline int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
0100 {
0101     return 0;
0102 }
0103 static inline unsigned long __recover_optprobed_insn(kprobe_opcode_t *buf, unsigned long addr)
0104 {
0105     return addr;
0106 }
0107 #endif
0108 
0109 #endif