common.h 2.7 KB

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