fprobe.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Simple ftrace probe wrapper */
  3. #ifndef _LINUX_FPROBE_H
  4. #define _LINUX_FPROBE_H
  5. #include <linux/compiler.h>
  6. #include <linux/ftrace.h>
  7. #include <linux/rethook.h>
  8. /**
  9. * struct fprobe - ftrace based probe.
  10. * @ops: The ftrace_ops.
  11. * @nmissed: The counter for missing events.
  12. * @flags: The status flag.
  13. * @rethook: The rethook data structure. (internal data)
  14. * @entry_data_size: The private data storage size.
  15. * @nr_maxactive: The max number of active functions.
  16. * @entry_handler: The callback function for function entry.
  17. * @exit_handler: The callback function for function exit.
  18. */
  19. struct fprobe {
  20. #ifdef CONFIG_FUNCTION_TRACER
  21. /*
  22. * If CONFIG_FUNCTION_TRACER is not set, CONFIG_FPROBE is disabled too.
  23. * But user of fprobe may keep embedding the struct fprobe on their own
  24. * code. To avoid build error, this will keep the fprobe data structure
  25. * defined here, but remove ftrace_ops data structure.
  26. */
  27. struct ftrace_ops ops;
  28. #endif
  29. unsigned long nmissed;
  30. unsigned int flags;
  31. struct rethook *rethook;
  32. size_t entry_data_size;
  33. int nr_maxactive;
  34. void (*entry_handler)(struct fprobe *fp, unsigned long entry_ip,
  35. struct pt_regs *regs, void *entry_data);
  36. void (*exit_handler)(struct fprobe *fp, unsigned long entry_ip,
  37. struct pt_regs *regs, void *entry_data);
  38. };
  39. /* This fprobe is soft-disabled. */
  40. #define FPROBE_FL_DISABLED 1
  41. /*
  42. * This fprobe handler will be shared with kprobes.
  43. * This flag must be set before registering.
  44. */
  45. #define FPROBE_FL_KPROBE_SHARED 2
  46. static inline bool fprobe_disabled(struct fprobe *fp)
  47. {
  48. return (fp) ? fp->flags & FPROBE_FL_DISABLED : false;
  49. }
  50. static inline bool fprobe_shared_with_kprobes(struct fprobe *fp)
  51. {
  52. return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false;
  53. }
  54. #ifdef CONFIG_FPROBE
  55. int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter);
  56. int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num);
  57. int register_fprobe_syms(struct fprobe *fp, const char **syms, int num);
  58. int unregister_fprobe(struct fprobe *fp);
  59. #else
  60. static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter)
  61. {
  62. return -EOPNOTSUPP;
  63. }
  64. static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num)
  65. {
  66. return -EOPNOTSUPP;
  67. }
  68. static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num)
  69. {
  70. return -EOPNOTSUPP;
  71. }
  72. static inline int unregister_fprobe(struct fprobe *fp)
  73. {
  74. return -EOPNOTSUPP;
  75. }
  76. #endif
  77. /**
  78. * disable_fprobe() - Disable fprobe
  79. * @fp: The fprobe to be disabled.
  80. *
  81. * This will soft-disable @fp. Note that this doesn't remove the ftrace
  82. * hooks from the function entry.
  83. */
  84. static inline void disable_fprobe(struct fprobe *fp)
  85. {
  86. if (fp)
  87. fp->flags |= FPROBE_FL_DISABLED;
  88. }
  89. /**
  90. * enable_fprobe() - Enable fprobe
  91. * @fp: The fprobe to be enabled.
  92. *
  93. * This will soft-enable @fp.
  94. */
  95. static inline void enable_fprobe(struct fprobe *fp)
  96. {
  97. if (fp)
  98. fp->flags &= ~FPROBE_FL_DISABLED;
  99. }
  100. #endif