Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Simple ftrace probe wrapper */
0003 #ifndef _LINUX_FPROBE_H
0004 #define _LINUX_FPROBE_H
0005 
0006 #include <linux/compiler.h>
0007 #include <linux/ftrace.h>
0008 #include <linux/rethook.h>
0009 
0010 /**
0011  * struct fprobe - ftrace based probe.
0012  * @ops: The ftrace_ops.
0013  * @nmissed: The counter for missing events.
0014  * @flags: The status flag.
0015  * @rethook: The rethook data structure. (internal data)
0016  * @entry_handler: The callback function for function entry.
0017  * @exit_handler: The callback function for function exit.
0018  */
0019 struct fprobe {
0020 #ifdef CONFIG_FUNCTION_TRACER
0021     /*
0022      * If CONFIG_FUNCTION_TRACER is not set, CONFIG_FPROBE is disabled too.
0023      * But user of fprobe may keep embedding the struct fprobe on their own
0024      * code. To avoid build error, this will keep the fprobe data structure
0025      * defined here, but remove ftrace_ops data structure.
0026      */
0027     struct ftrace_ops   ops;
0028 #endif
0029     unsigned long       nmissed;
0030     unsigned int        flags;
0031     struct rethook      *rethook;
0032 
0033     void (*entry_handler)(struct fprobe *fp, unsigned long entry_ip, struct pt_regs *regs);
0034     void (*exit_handler)(struct fprobe *fp, unsigned long entry_ip, struct pt_regs *regs);
0035 };
0036 
0037 /* This fprobe is soft-disabled. */
0038 #define FPROBE_FL_DISABLED  1
0039 
0040 /*
0041  * This fprobe handler will be shared with kprobes.
0042  * This flag must be set before registering.
0043  */
0044 #define FPROBE_FL_KPROBE_SHARED 2
0045 
0046 static inline bool fprobe_disabled(struct fprobe *fp)
0047 {
0048     return (fp) ? fp->flags & FPROBE_FL_DISABLED : false;
0049 }
0050 
0051 static inline bool fprobe_shared_with_kprobes(struct fprobe *fp)
0052 {
0053     return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false;
0054 }
0055 
0056 #ifdef CONFIG_FPROBE
0057 int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter);
0058 int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num);
0059 int register_fprobe_syms(struct fprobe *fp, const char **syms, int num);
0060 int unregister_fprobe(struct fprobe *fp);
0061 #else
0062 static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter)
0063 {
0064     return -EOPNOTSUPP;
0065 }
0066 static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num)
0067 {
0068     return -EOPNOTSUPP;
0069 }
0070 static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num)
0071 {
0072     return -EOPNOTSUPP;
0073 }
0074 static inline int unregister_fprobe(struct fprobe *fp)
0075 {
0076     return -EOPNOTSUPP;
0077 }
0078 #endif
0079 
0080 /**
0081  * disable_fprobe() - Disable fprobe
0082  * @fp: The fprobe to be disabled.
0083  *
0084  * This will soft-disable @fp. Note that this doesn't remove the ftrace
0085  * hooks from the function entry.
0086  */
0087 static inline void disable_fprobe(struct fprobe *fp)
0088 {
0089     if (fp)
0090         fp->flags |= FPROBE_FL_DISABLED;
0091 }
0092 
0093 /**
0094  * enable_fprobe() - Enable fprobe
0095  * @fp: The fprobe to be enabled.
0096  *
0097  * This will soft-enable @fp.
0098  */
0099 static inline void enable_fprobe(struct fprobe *fp)
0100 {
0101     if (fp)
0102         fp->flags &= ~FPROBE_FL_DISABLED;
0103 }
0104 
0105 #endif