fprobe.h (2835B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* Simple ftrace probe wrapper */ 3#ifndef _LINUX_FPROBE_H 4#define _LINUX_FPROBE_H 5 6#include <linux/compiler.h> 7#include <linux/ftrace.h> 8#include <linux/rethook.h> 9 10/** 11 * struct fprobe - ftrace based probe. 12 * @ops: The ftrace_ops. 13 * @nmissed: The counter for missing events. 14 * @flags: The status flag. 15 * @rethook: The rethook data structure. (internal data) 16 * @entry_handler: The callback function for function entry. 17 * @exit_handler: The callback function for function exit. 18 */ 19struct 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 33 void (*entry_handler)(struct fprobe *fp, unsigned long entry_ip, struct pt_regs *regs); 34 void (*exit_handler)(struct fprobe *fp, unsigned long entry_ip, struct pt_regs *regs); 35}; 36 37/* This fprobe is soft-disabled. */ 38#define FPROBE_FL_DISABLED 1 39 40/* 41 * This fprobe handler will be shared with kprobes. 42 * This flag must be set before registering. 43 */ 44#define FPROBE_FL_KPROBE_SHARED 2 45 46static inline bool fprobe_disabled(struct fprobe *fp) 47{ 48 return (fp) ? fp->flags & FPROBE_FL_DISABLED : false; 49} 50 51static inline bool fprobe_shared_with_kprobes(struct fprobe *fp) 52{ 53 return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false; 54} 55 56#ifdef CONFIG_FPROBE 57int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter); 58int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num); 59int register_fprobe_syms(struct fprobe *fp, const char **syms, int num); 60int unregister_fprobe(struct fprobe *fp); 61#else 62static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter) 63{ 64 return -EOPNOTSUPP; 65} 66static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num) 67{ 68 return -EOPNOTSUPP; 69} 70static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num) 71{ 72 return -EOPNOTSUPP; 73} 74static inline int unregister_fprobe(struct fprobe *fp) 75{ 76 return -EOPNOTSUPP; 77} 78#endif 79 80/** 81 * disable_fprobe() - Disable fprobe 82 * @fp: The fprobe to be disabled. 83 * 84 * This will soft-disable @fp. Note that this doesn't remove the ftrace 85 * hooks from the function entry. 86 */ 87static inline void disable_fprobe(struct fprobe *fp) 88{ 89 if (fp) 90 fp->flags |= FPROBE_FL_DISABLED; 91} 92 93/** 94 * enable_fprobe() - Enable fprobe 95 * @fp: The fprobe to be enabled. 96 * 97 * This will soft-enable @fp. 98 */ 99static inline void enable_fprobe(struct fprobe *fp) 100{ 101 if (fp) 102 fp->flags &= ~FPROBE_FL_DISABLED; 103} 104 105#endif