common.h 2.7 KB

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