/arch/x86/include/asm/kprobes.h

https://github.com/srikard/linux · C Header · 114 lines · 70 code · 20 blank · 24 comment · 1 complexity · f498e01819f45cf02fad572cf23760f3 MD5 · raw file

  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. asmlinkage void kretprobe_trampoline(void);
  43. extern void arch_kprobe_override_function(struct pt_regs *regs);
  44. /* Architecture specific copy of original instruction*/
  45. struct arch_specific_insn {
  46. /* copy of the original instruction */
  47. kprobe_opcode_t *insn;
  48. /*
  49. * boostable = false: This instruction type is not boostable.
  50. * boostable = true: This instruction has been boosted: we have
  51. * added a relative jump after the instruction copy in insn,
  52. * so no single-step and fixup are needed (unless there's
  53. * a post_handler).
  54. */
  55. bool boostable;
  56. bool if_modifier;
  57. /* Number of bytes of text poked */
  58. int tp_len;
  59. };
  60. struct arch_optimized_insn {
  61. /* copy of the original instructions */
  62. kprobe_opcode_t copied_insn[DISP32_SIZE];
  63. /* detour code buffer */
  64. kprobe_opcode_t *insn;
  65. /* the size of instructions copied to detour code buffer */
  66. size_t size;
  67. };
  68. /* Return true (!0) if optinsn is prepared for optimization. */
  69. static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
  70. {
  71. return optinsn->size;
  72. }
  73. struct prev_kprobe {
  74. struct kprobe *kp;
  75. unsigned long status;
  76. unsigned long old_flags;
  77. unsigned long saved_flags;
  78. };
  79. /* per-cpu kprobe control block */
  80. struct kprobe_ctlblk {
  81. unsigned long kprobe_status;
  82. unsigned long kprobe_old_flags;
  83. unsigned long kprobe_saved_flags;
  84. struct prev_kprobe prev_kprobe;
  85. };
  86. extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
  87. extern int kprobe_exceptions_notify(struct notifier_block *self,
  88. unsigned long val, void *data);
  89. extern int kprobe_int3_handler(struct pt_regs *regs);
  90. extern int kprobe_debug_handler(struct pt_regs *regs);
  91. #else
  92. static inline int kprobe_debug_handler(struct pt_regs *regs) { return 0; }
  93. #endif /* CONFIG_KPROBES */
  94. #endif /* _ASM_X86_KPROBES_H */