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