Merge branch 'address-masking'
[linux-2.6-block.git] / include / linux / fprobe.h
CommitLineData
cad9931f
MH
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>
5b0ab789 8#include <linux/rethook.h>
cad9931f 9
73142cab
JO
10struct fprobe;
11
12typedef int (*fprobe_entry_cb)(struct fprobe *fp, unsigned long entry_ip,
13 unsigned long ret_ip, struct pt_regs *regs,
14 void *entry_data);
15
16typedef void (*fprobe_exit_cb)(struct fprobe *fp, unsigned long entry_ip,
17 unsigned long ret_ip, struct pt_regs *regs,
18 void *entry_data);
19
cad9931f
MH
20/**
21 * struct fprobe - ftrace based probe.
22 * @ops: The ftrace_ops.
23 * @nmissed: The counter for missing events.
24 * @flags: The status flag.
5b0ab789 25 * @rethook: The rethook data structure. (internal data)
76d0de57 26 * @entry_data_size: The private data storage size.
59a7a298 27 * @nr_maxactive: The max number of active functions.
cad9931f 28 * @entry_handler: The callback function for function entry.
5b0ab789 29 * @exit_handler: The callback function for function exit.
cad9931f
MH
30 */
31struct fprobe {
32#ifdef CONFIG_FUNCTION_TRACER
33 /*
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.
38 */
39 struct ftrace_ops ops;
40#endif
41 unsigned long nmissed;
42 unsigned int flags;
5b0ab789 43 struct rethook *rethook;
76d0de57 44 size_t entry_data_size;
59a7a298 45 int nr_maxactive;
5b0ab789 46
73142cab
JO
47 fprobe_entry_cb entry_handler;
48 fprobe_exit_cb exit_handler;
cad9931f
MH
49};
50
ab51e15d 51/* This fprobe is soft-disabled. */
cad9931f
MH
52#define FPROBE_FL_DISABLED 1
53
ab51e15d
MH
54/*
55 * This fprobe handler will be shared with kprobes.
56 * This flag must be set before registering.
57 */
58#define FPROBE_FL_KPROBE_SHARED 2
59
cad9931f
MH
60static inline bool fprobe_disabled(struct fprobe *fp)
61{
62 return (fp) ? fp->flags & FPROBE_FL_DISABLED : false;
63}
64
ab51e15d
MH
65static inline bool fprobe_shared_with_kprobes(struct fprobe *fp)
66{
67 return (fp) ? fp->flags & FPROBE_FL_KPROBE_SHARED : false;
68}
69
cad9931f
MH
70#ifdef CONFIG_FPROBE
71int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter);
72int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num);
73int register_fprobe_syms(struct fprobe *fp, const char **syms, int num);
74int unregister_fprobe(struct fprobe *fp);
334e5519 75bool fprobe_is_registered(struct fprobe *fp);
cad9931f
MH
76#else
77static inline int register_fprobe(struct fprobe *fp, const char *filter, const char *notfilter)
78{
79 return -EOPNOTSUPP;
80}
81static inline int register_fprobe_ips(struct fprobe *fp, unsigned long *addrs, int num)
82{
83 return -EOPNOTSUPP;
84}
85static inline int register_fprobe_syms(struct fprobe *fp, const char **syms, int num)
86{
87 return -EOPNOTSUPP;
88}
89static inline int unregister_fprobe(struct fprobe *fp)
90{
91 return -EOPNOTSUPP;
92}
334e5519
MHG
93static inline bool fprobe_is_registered(struct fprobe *fp)
94{
95 return false;
96}
cad9931f
MH
97#endif
98
99/**
100 * disable_fprobe() - Disable fprobe
101 * @fp: The fprobe to be disabled.
102 *
103 * This will soft-disable @fp. Note that this doesn't remove the ftrace
104 * hooks from the function entry.
105 */
106static inline void disable_fprobe(struct fprobe *fp)
107{
108 if (fp)
109 fp->flags |= FPROBE_FL_DISABLED;
110}
111
112/**
113 * enable_fprobe() - Enable fprobe
114 * @fp: The fprobe to be enabled.
115 *
116 * This will soft-enable @fp.
117 */
118static inline void enable_fprobe(struct fprobe *fp)
119{
120 if (fp)
121 fp->flags &= ~FPROBE_FL_DISABLED;
122}
123
124#endif