kprobes.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _ASM_X86_KPROBES_H
  3. #define _ASM_X86_KPROBES_H
  4. /*
  5. * Kernel Probes (KProbes)
  6. *
  7. * Copyright (C) IBM Corporation, 2002, 2004
  8. *
  9. * See arch/x86/kernel/kprobes.c for x86 kprobes history.
  10. */
  11. #include <asm-generic/kprobes.h>
  12. #ifdef CONFIG_KPROBES
  13. #include <linux/types.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/percpu.h>
  16. #include <asm/text-patching.h>
  17. #include <asm/insn.h>
  18. #define __ARCH_WANT_KPROBES_INSN_SLOT
  19. struct pt_regs;
  20. struct kprobe;
  21. typedef u8 kprobe_opcode_t;
  22. #define MAX_STACK_SIZE 64
  23. #define CUR_STACK_SIZE(ADDR) \
  24. (current_top_of_stack() - (unsigned long)(ADDR))
  25. #define MIN_STACK_SIZE(ADDR) \
  26. (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ? \
  27. MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
  28. #define flush_insn_slot(p) do { } while (0)
  29. /* optinsn template addresses */
  30. extern __visible kprobe_opcode_t optprobe_template_entry[];
  31. extern __visible kprobe_opcode_t optprobe_template_clac[];
  32. extern __visible kprobe_opcode_t optprobe_template_val[];
  33. extern __visible kprobe_opcode_t optprobe_template_call[];
  34. extern __visible kprobe_opcode_t optprobe_template_end[];
  35. #define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + DISP32_SIZE)
  36. #define MAX_OPTINSN_SIZE \
  37. (((unsigned long)optprobe_template_end - \
  38. (unsigned long)optprobe_template_entry) + \
  39. MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE)
  40. extern const int kretprobe_blacklist_size;
  41. void arch_remove_kprobe(struct kprobe *p);
  42. /* Architecture specific copy of original instruction*/
  43. struct arch_specific_insn {
  44. /* copy of the original instruction */
  45. kprobe_opcode_t *insn;
  46. /*
  47. * boostable = 0: This instruction type is not boostable.
  48. * boostable = 1: This instruction has been boosted: we have
  49. * added a relative jump after the instruction copy in insn,
  50. * so no single-step and fixup are needed (unless there's
  51. * a post_handler).
  52. */
  53. unsigned boostable:1;
  54. unsigned char size; /* The size of insn */
  55. union {
  56. unsigned char opcode;
  57. struct {
  58. unsigned char type;
  59. } jcc;
  60. struct {
  61. unsigned char type;
  62. unsigned char asize;
  63. } loop;
  64. struct {
  65. unsigned char reg;
  66. } indirect;
  67. };
  68. s32 rel32; /* relative offset must be s32, s16, or s8 */
  69. void (*emulate_op)(struct kprobe *p, struct pt_regs *regs);
  70. /* Number of bytes of text poked */
  71. int tp_len;
  72. };
  73. struct arch_optimized_insn {
  74. /* copy of the original instructions */
  75. kprobe_opcode_t copied_insn[DISP32_SIZE];
  76. /* detour code buffer */
  77. kprobe_opcode_t *insn;
  78. /* the size of instructions copied to detour code buffer */
  79. size_t size;
  80. };
  81. /* Return true (!0) if optinsn is prepared for optimization. */
  82. static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
  83. {
  84. return optinsn->size;
  85. }
  86. struct prev_kprobe {
  87. struct kprobe *kp;
  88. unsigned long status;
  89. unsigned long old_flags;
  90. unsigned long saved_flags;
  91. };
  92. /* per-cpu kprobe control block */
  93. struct kprobe_ctlblk {
  94. unsigned long kprobe_status;
  95. unsigned long kprobe_old_flags;
  96. unsigned long kprobe_saved_flags;
  97. struct prev_kprobe prev_kprobe;
  98. };
  99. extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
  100. extern int kprobe_exceptions_notify(struct notifier_block *self,
  101. unsigned long val, void *data);
  102. extern int kprobe_int3_handler(struct pt_regs *regs);
  103. #else
  104. static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
  105. #endif /* CONFIG_KPROBES */
  106. #endif /* _ASM_X86_KPROBES_H */