1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Simple ftrace probe wrapper */
3 #ifndef _LINUX_FPROBE_H
4 #define _LINUX_FPROBE_H
6 #include <linux/compiler.h>
7 #include <linux/ftrace.h>
8 #include <linux/rethook.h>
12 typedef int (*fprobe_entry_cb
)(struct fprobe
*fp
, unsigned long entry_ip
,
13 unsigned long ret_ip
, struct pt_regs
*regs
,
16 typedef void (*fprobe_exit_cb
)(struct fprobe
*fp
, unsigned long entry_ip
,
17 unsigned long ret_ip
, struct pt_regs
*regs
,
21 * struct fprobe - ftrace based probe.
22 * @ops: The ftrace_ops.
23 * @nmissed: The counter for missing events.
24 * @flags: The status flag.
25 * @rethook: The rethook data structure. (internal data)
26 * @entry_data_size: The private data storage size.
27 * @nr_maxactive: The max number of active functions.
28 * @entry_handler: The callback function for function entry.
29 * @exit_handler: The callback function for function exit.
32 #ifdef CONFIG_FUNCTION_TRACER
34 * If CONFIG_FUNCTION_TRACER is not set, CONFIG_FPROBE is disabled too.
35 * But user of fprobe may keep embedding the struct fprobe on their own
36 * code. To avoid build error, this will keep the fprobe data structure
37 * defined here, but remove ftrace_ops data structure.
39 struct ftrace_ops ops
;
41 unsigned long nmissed
;
43 struct rethook
*rethook
;
44 size_t entry_data_size
;
47 fprobe_entry_cb entry_handler
;
48 fprobe_exit_cb exit_handler
;
51 /* This fprobe is soft-disabled. */
52 #define FPROBE_FL_DISABLED 1
55 * This fprobe handler will be shared with kprobes.
56 * This flag must be set before registering.
58 #define FPROBE_FL_KPROBE_SHARED 2
60 static inline bool fprobe_disabled(struct fprobe
*fp
)
62 return (fp
) ? fp
->flags
& FPROBE_FL_DISABLED
: false;
65 static inline bool fprobe_shared_with_kprobes(struct fprobe
*fp
)
67 return (fp
) ? fp
->flags
& FPROBE_FL_KPROBE_SHARED
: false;
71 int register_fprobe(struct fprobe
*fp
, const char *filter
, const char *notfilter
);
72 int register_fprobe_ips(struct fprobe
*fp
, unsigned long *addrs
, int num
);
73 int register_fprobe_syms(struct fprobe
*fp
, const char **syms
, int num
);
74 int unregister_fprobe(struct fprobe
*fp
);
75 bool fprobe_is_registered(struct fprobe
*fp
);
77 static inline int register_fprobe(struct fprobe
*fp
, const char *filter
, const char *notfilter
)
81 static inline int register_fprobe_ips(struct fprobe
*fp
, unsigned long *addrs
, int num
)
85 static inline int register_fprobe_syms(struct fprobe
*fp
, const char **syms
, int num
)
89 static inline int unregister_fprobe(struct fprobe
*fp
)
93 static inline bool fprobe_is_registered(struct fprobe
*fp
)
100 * disable_fprobe() - Disable fprobe
101 * @fp: The fprobe to be disabled.
103 * This will soft-disable @fp. Note that this doesn't remove the ftrace
104 * hooks from the function entry.
106 static inline void disable_fprobe(struct fprobe
*fp
)
109 fp
->flags
|= FPROBE_FL_DISABLED
;
113 * enable_fprobe() - Enable fprobe
114 * @fp: The fprobe to be enabled.
116 * This will soft-enable @fp.
118 static inline void enable_fprobe(struct fprobe
*fp
)
121 fp
->flags
&= ~FPROBE_FL_DISABLED
;