kprobes.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef _LINUX_KPROBES_H
  2. #define _LINUX_KPROBES_H
  3. /*
  4. * Kernel Probes (KProbes)
  5. * include/linux/kprobes.h
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. *
  21. * Copyright (C) IBM Corporation, 2002, 2004
  22. *
  23. * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
  24. * Probes initial implementation ( includes suggestions from
  25. * Rusty Russell).
  26. * 2004-July Suparna Bhattacharya <suparna@in.ibm.com> added jumper probes
  27. * interface to access function arguments.
  28. */
  29. #include <linux/config.h>
  30. #include <linux/list.h>
  31. #include <linux/notifier.h>
  32. #include <linux/smp.h>
  33. #include <asm/kprobes.h>
  34. struct kprobe;
  35. struct pt_regs;
  36. typedef int (*kprobe_pre_handler_t) (struct kprobe *, struct pt_regs *);
  37. typedef int (*kprobe_break_handler_t) (struct kprobe *, struct pt_regs *);
  38. typedef void (*kprobe_post_handler_t) (struct kprobe *, struct pt_regs *,
  39. unsigned long flags);
  40. typedef int (*kprobe_fault_handler_t) (struct kprobe *, struct pt_regs *,
  41. int trapnr);
  42. struct kprobe {
  43. struct hlist_node hlist;
  44. /* list of kprobes for multi-handler support */
  45. struct list_head list;
  46. /* location of the probe point */
  47. kprobe_opcode_t *addr;
  48. /* Called before addr is executed. */
  49. kprobe_pre_handler_t pre_handler;
  50. /* Called after addr is executed, unless... */
  51. kprobe_post_handler_t post_handler;
  52. /* ... called if executing addr causes a fault (eg. page fault).
  53. * Return 1 if it handled fault, otherwise kernel will see it. */
  54. kprobe_fault_handler_t fault_handler;
  55. /* ... called if breakpoint trap occurs in probe handler.
  56. * Return 1 if it handled break, otherwise kernel will see it. */
  57. kprobe_break_handler_t break_handler;
  58. /* Saved opcode (which has been replaced with breakpoint) */
  59. kprobe_opcode_t opcode;
  60. /* copy of the original instruction */
  61. struct arch_specific_insn ainsn;
  62. };
  63. /*
  64. * Special probe type that uses setjmp-longjmp type tricks to resume
  65. * execution at a specified entry with a matching prototype corresponding
  66. * to the probed function - a trick to enable arguments to become
  67. * accessible seamlessly by probe handling logic.
  68. * Note:
  69. * Because of the way compilers allocate stack space for local variables
  70. * etc upfront, regardless of sub-scopes within a function, this mirroring
  71. * principle currently works only for probes placed on function entry points.
  72. */
  73. struct jprobe {
  74. struct kprobe kp;
  75. kprobe_opcode_t *entry; /* probe handling code to jump to */
  76. };
  77. #ifdef CONFIG_KPROBES
  78. /* Locks kprobe: irq must be disabled */
  79. void lock_kprobes(void);
  80. void unlock_kprobes(void);
  81. /* kprobe running now on this CPU? */
  82. static inline int kprobe_running(void)
  83. {
  84. extern unsigned int kprobe_cpu;
  85. return kprobe_cpu == smp_processor_id();
  86. }
  87. extern int arch_prepare_kprobe(struct kprobe *p);
  88. extern void arch_copy_kprobe(struct kprobe *p);
  89. extern void arch_remove_kprobe(struct kprobe *p);
  90. extern void show_registers(struct pt_regs *regs);
  91. /* Get the kprobe at this addr (if any). Must have called lock_kprobes */
  92. struct kprobe *get_kprobe(void *addr);
  93. int register_kprobe(struct kprobe *p);
  94. void unregister_kprobe(struct kprobe *p);
  95. int setjmp_pre_handler(struct kprobe *, struct pt_regs *);
  96. int longjmp_break_handler(struct kprobe *, struct pt_regs *);
  97. int register_jprobe(struct jprobe *p);
  98. void unregister_jprobe(struct jprobe *p);
  99. void jprobe_return(void);
  100. #else
  101. static inline int kprobe_running(void)
  102. {
  103. return 0;
  104. }
  105. static inline int register_kprobe(struct kprobe *p)
  106. {
  107. return -ENOSYS;
  108. }
  109. static inline void unregister_kprobe(struct kprobe *p)
  110. {
  111. }
  112. static inline int register_jprobe(struct jprobe *p)
  113. {
  114. return -ENOSYS;
  115. }
  116. static inline void unregister_jprobe(struct jprobe *p)
  117. {
  118. }
  119. static inline void jprobe_return(void)
  120. {
  121. }
  122. #endif
  123. #endif /* _LINUX_KPROBES_H */