kprobes.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef _ASM_X86_KPROBES_H
  2. #define _ASM_X86_KPROBES_H
  3. /*
  4. * Kernel Probes (KProbes)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. *
  20. * Copyright (C) IBM Corporation, 2002, 2004
  21. *
  22. * See arch/x86/kernel/kprobes.c for x86 kprobes history.
  23. */
  24. #include <asm-generic/kprobes.h>
  25. #define BREAKPOINT_INSTRUCTION 0xcc
  26. #ifdef CONFIG_KPROBES
  27. #include <linux/types.h>
  28. #include <linux/ptrace.h>
  29. #include <linux/percpu.h>
  30. #include <asm/insn.h>
  31. #define __ARCH_WANT_KPROBES_INSN_SLOT
  32. struct pt_regs;
  33. struct kprobe;
  34. typedef u8 kprobe_opcode_t;
  35. #define RELATIVEJUMP_OPCODE 0xe9
  36. #define RELATIVEJUMP_SIZE 5
  37. #define RELATIVECALL_OPCODE 0xe8
  38. #define RELATIVE_ADDR_SIZE 4
  39. #define MAX_STACK_SIZE 64
  40. #define CUR_STACK_SIZE(ADDR) \
  41. (current_top_of_stack() - (unsigned long)(ADDR))
  42. #define MIN_STACK_SIZE(ADDR) \
  43. (MAX_STACK_SIZE < CUR_STACK_SIZE(ADDR) ? \
  44. MAX_STACK_SIZE : CUR_STACK_SIZE(ADDR))
  45. #define flush_insn_slot(p) do { } while (0)
  46. /* optinsn template addresses */
  47. extern __visible kprobe_opcode_t optprobe_template_entry[];
  48. extern __visible kprobe_opcode_t optprobe_template_val[];
  49. extern __visible kprobe_opcode_t optprobe_template_call[];
  50. extern __visible kprobe_opcode_t optprobe_template_end[];
  51. #define MAX_OPTIMIZED_LENGTH (MAX_INSN_SIZE + RELATIVE_ADDR_SIZE)
  52. #define MAX_OPTINSN_SIZE \
  53. (((unsigned long)optprobe_template_end - \
  54. (unsigned long)optprobe_template_entry) + \
  55. MAX_OPTIMIZED_LENGTH + RELATIVEJUMP_SIZE)
  56. extern const int kretprobe_blacklist_size;
  57. void arch_remove_kprobe(struct kprobe *p);
  58. asmlinkage void kretprobe_trampoline(void);
  59. extern void arch_kprobe_override_function(struct pt_regs *regs);
  60. /* Architecture specific copy of original instruction*/
  61. struct arch_specific_insn {
  62. /* copy of the original instruction */
  63. kprobe_opcode_t *insn;
  64. /*
  65. * boostable = false: This instruction type is not boostable.
  66. * boostable = true: This instruction has been boosted: we have
  67. * added a relative jump after the instruction copy in insn,
  68. * so no single-step and fixup are needed (unless there's
  69. * a post_handler).
  70. */
  71. bool boostable;
  72. bool if_modifier;
  73. };
  74. struct arch_optimized_insn {
  75. /* copy of the original instructions */
  76. kprobe_opcode_t copied_insn[RELATIVE_ADDR_SIZE];
  77. /* detour code buffer */
  78. kprobe_opcode_t *insn;
  79. /* the size of instructions copied to detour code buffer */
  80. size_t size;
  81. };
  82. /* Return true (!0) if optinsn is prepared for optimization. */
  83. static inline int arch_prepared_optinsn(struct arch_optimized_insn *optinsn)
  84. {
  85. return optinsn->size;
  86. }
  87. struct prev_kprobe {
  88. struct kprobe *kp;
  89. unsigned long status;
  90. unsigned long old_flags;
  91. unsigned long saved_flags;
  92. };
  93. /* per-cpu kprobe control block */
  94. struct kprobe_ctlblk {
  95. unsigned long kprobe_status;
  96. unsigned long kprobe_old_flags;
  97. unsigned long kprobe_saved_flags;
  98. struct prev_kprobe prev_kprobe;
  99. };
  100. extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
  101. extern int kprobe_exceptions_notify(struct notifier_block *self,
  102. unsigned long val, void *data);
  103. extern int kprobe_int3_handler(struct pt_regs *regs);
  104. extern int kprobe_debug_handler(struct pt_regs *regs);
  105. #endif /* CONFIG_KPROBES */
  106. #endif /* _ASM_X86_KPROBES_H */