]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
69d262a9 WN |
2 | /* |
3 | * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> | |
4 | * Copyright (C) 2015, Huawei Inc. | |
5 | */ | |
6 | #ifndef __BPF_LOADER_H | |
7 | #define __BPF_LOADER_H | |
8 | ||
9 | #include <linux/compiler.h> | |
10 | #include <linux/err.h> | |
11 | #include <string.h> | |
d3e0ce39 | 12 | #include <bpf/libbpf.h> |
4edf30e3 | 13 | #include "probe-event.h" |
066dacbf | 14 | #include "evlist.h" |
69d262a9 WN |
15 | #include "debug.h" |
16 | ||
d3e0ce39 WN |
17 | enum bpf_loader_errno { |
18 | __BPF_LOADER_ERRNO__START = __LIBBPF_ERRNO__START - 100, | |
19 | /* Invalid config string */ | |
20 | BPF_LOADER_ERRNO__CONFIG = __BPF_LOADER_ERRNO__START, | |
21 | BPF_LOADER_ERRNO__GROUP, /* Invalid group name */ | |
22 | BPF_LOADER_ERRNO__EVENTNAME, /* Event name is missing */ | |
23 | BPF_LOADER_ERRNO__INTERNAL, /* BPF loader internal error */ | |
24 | BPF_LOADER_ERRNO__COMPILE, /* Error when compiling BPF scriptlet */ | |
0bb93490 | 25 | BPF_LOADER_ERRNO__PROGCONF_TERM,/* Invalid program config term in config string */ |
bfc077b4 HK |
26 | BPF_LOADER_ERRNO__PROLOGUE, /* Failed to generate prologue */ |
27 | BPF_LOADER_ERRNO__PROLOGUE2BIG, /* Prologue too big for program */ | |
28 | BPF_LOADER_ERRNO__PROLOGUEOOB, /* Offset out of bound for prologue */ | |
066dacbf WN |
29 | BPF_LOADER_ERRNO__OBJCONF_OPT, /* Invalid object config option */ |
30 | BPF_LOADER_ERRNO__OBJCONF_CONF, /* Config value not set (lost '=')) */ | |
31 | BPF_LOADER_ERRNO__OBJCONF_MAP_OPT, /* Invalid object map config option */ | |
32 | BPF_LOADER_ERRNO__OBJCONF_MAP_NOTEXIST, /* Target map not exist */ | |
33 | BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE, /* Incorrect value type for map */ | |
34 | BPF_LOADER_ERRNO__OBJCONF_MAP_TYPE, /* Incorrect map type */ | |
35 | BPF_LOADER_ERRNO__OBJCONF_MAP_KEYSIZE, /* Incorrect map key size */ | |
36 | BPF_LOADER_ERRNO__OBJCONF_MAP_VALUESIZE,/* Incorrect map value size */ | |
7630b3e2 WN |
37 | BPF_LOADER_ERRNO__OBJCONF_MAP_NOEVT, /* Event not found for map setting */ |
38 | BPF_LOADER_ERRNO__OBJCONF_MAP_MAPSIZE, /* Invalid map size for event setting */ | |
39 | BPF_LOADER_ERRNO__OBJCONF_MAP_EVTDIM, /* Event dimension too large */ | |
40 | BPF_LOADER_ERRNO__OBJCONF_MAP_EVTINH, /* Doesn't support inherit event */ | |
41 | BPF_LOADER_ERRNO__OBJCONF_MAP_EVTTYPE, /* Wrong event type for map */ | |
2d055bf2 | 42 | BPF_LOADER_ERRNO__OBJCONF_MAP_IDX2BIG, /* Index too large */ |
d3e0ce39 WN |
43 | __BPF_LOADER_ERRNO__END, |
44 | }; | |
45 | ||
78e890ea | 46 | struct perf_evsel; |
69d262a9 | 47 | struct bpf_object; |
066dacbf | 48 | struct parse_events_term; |
aa3abf30 | 49 | #define PERF_BPF_PROBE_GROUP "perf_bpf_probe" |
69d262a9 | 50 | |
cd102d70 | 51 | typedef int (*bpf_prog_iter_callback_t)(const char *group, const char *event, |
4edf30e3 WN |
52 | int fd, void *arg); |
53 | ||
69d262a9 | 54 | #ifdef HAVE_LIBBPF_SUPPORT |
d509db04 | 55 | struct bpf_object *bpf__prepare_load(const char *filename, bool source); |
d3e0ce39 WN |
56 | int bpf__strerror_prepare_load(const char *filename, bool source, |
57 | int err, char *buf, size_t size); | |
69d262a9 | 58 | |
ba1fae43 WN |
59 | struct bpf_object *bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, |
60 | const char *name); | |
61 | ||
69d262a9 | 62 | void bpf__clear(void); |
aa3abf30 WN |
63 | |
64 | int bpf__probe(struct bpf_object *obj); | |
65 | int bpf__unprobe(struct bpf_object *obj); | |
66 | int bpf__strerror_probe(struct bpf_object *obj, int err, | |
67 | char *buf, size_t size); | |
68 | ||
1e5e3ee8 WN |
69 | int bpf__load(struct bpf_object *obj); |
70 | int bpf__strerror_load(struct bpf_object *obj, int err, | |
71 | char *buf, size_t size); | |
cd102d70 WN |
72 | int bpf__foreach_event(struct bpf_object *obj, |
73 | bpf_prog_iter_callback_t func, void *arg); | |
066dacbf WN |
74 | |
75 | int bpf__config_obj(struct bpf_object *obj, struct parse_events_term *term, | |
76 | struct perf_evlist *evlist, int *error_pos); | |
77 | int bpf__strerror_config_obj(struct bpf_object *obj, | |
78 | struct parse_events_term *term, | |
79 | struct perf_evlist *evlist, | |
80 | int *error_pos, int err, char *buf, | |
81 | size_t size); | |
8690a2a7 WN |
82 | int bpf__apply_obj_config(void); |
83 | int bpf__strerror_apply_obj_config(int err, char *buf, size_t size); | |
d7888573 WN |
84 | |
85 | int bpf__setup_stdout(struct perf_evlist *evlist); | |
78e890ea | 86 | struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const char *name); |
aa31be3a | 87 | int bpf__strerror_setup_output_event(struct perf_evlist *evlist, int err, char *buf, size_t size); |
69d262a9 | 88 | #else |
a43783ae ACM |
89 | #include <errno.h> |
90 | ||
69d262a9 | 91 | static inline struct bpf_object * |
d509db04 WN |
92 | bpf__prepare_load(const char *filename __maybe_unused, |
93 | bool source __maybe_unused) | |
69d262a9 WN |
94 | { |
95 | pr_debug("ERROR: eBPF object loading is disabled during compiling.\n"); | |
96 | return ERR_PTR(-ENOTSUP); | |
97 | } | |
98 | ||
ba1fae43 WN |
99 | static inline struct bpf_object * |
100 | bpf__prepare_load_buffer(void *obj_buf __maybe_unused, | |
101 | size_t obj_buf_sz __maybe_unused) | |
102 | { | |
103 | return ERR_PTR(-ENOTSUP); | |
104 | } | |
105 | ||
69d262a9 | 106 | static inline void bpf__clear(void) { } |
aa3abf30 WN |
107 | |
108 | static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;} | |
109 | static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;} | |
1e5e3ee8 | 110 | static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; } |
aa3abf30 | 111 | |
4edf30e3 | 112 | static inline int |
cd102d70 WN |
113 | bpf__foreach_event(struct bpf_object *obj __maybe_unused, |
114 | bpf_prog_iter_callback_t func __maybe_unused, | |
115 | void *arg __maybe_unused) | |
4edf30e3 WN |
116 | { |
117 | return 0; | |
118 | } | |
119 | ||
066dacbf WN |
120 | static inline int |
121 | bpf__config_obj(struct bpf_object *obj __maybe_unused, | |
122 | struct parse_events_term *term __maybe_unused, | |
123 | struct perf_evlist *evlist __maybe_unused, | |
124 | int *error_pos __maybe_unused) | |
125 | { | |
126 | return 0; | |
127 | } | |
128 | ||
8690a2a7 WN |
129 | static inline int |
130 | bpf__apply_obj_config(void) | |
131 | { | |
132 | return 0; | |
133 | } | |
134 | ||
d7888573 WN |
135 | static inline int |
136 | bpf__setup_stdout(struct perf_evlist *evlist __maybe_unused) | |
137 | { | |
138 | return 0; | |
139 | } | |
140 | ||
78e890ea | 141 | static inline struct perf_evsel * |
92bbe8d8 ACM |
142 | bpf__setup_output_event(struct perf_evlist *evlist __maybe_unused, const char *name __maybe_unused) |
143 | { | |
78e890ea | 144 | return NULL; |
92bbe8d8 ACM |
145 | } |
146 | ||
aa3abf30 WN |
147 | static inline int |
148 | __bpf_strerror(char *buf, size_t size) | |
149 | { | |
150 | if (!size) | |
151 | return 0; | |
152 | strncpy(buf, | |
153 | "ERROR: eBPF object loading is disabled during compiling.\n", | |
154 | size); | |
155 | buf[size - 1] = '\0'; | |
156 | return 0; | |
157 | } | |
158 | ||
d3e0ce39 WN |
159 | static inline |
160 | int bpf__strerror_prepare_load(const char *filename __maybe_unused, | |
161 | bool source __maybe_unused, | |
162 | int err __maybe_unused, | |
163 | char *buf, size_t size) | |
164 | { | |
165 | return __bpf_strerror(buf, size); | |
166 | } | |
167 | ||
aa3abf30 WN |
168 | static inline int |
169 | bpf__strerror_probe(struct bpf_object *obj __maybe_unused, | |
170 | int err __maybe_unused, | |
171 | char *buf, size_t size) | |
172 | { | |
173 | return __bpf_strerror(buf, size); | |
174 | } | |
1e5e3ee8 WN |
175 | |
176 | static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused, | |
177 | int err __maybe_unused, | |
178 | char *buf, size_t size) | |
179 | { | |
180 | return __bpf_strerror(buf, size); | |
181 | } | |
066dacbf WN |
182 | |
183 | static inline int | |
184 | bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused, | |
185 | struct parse_events_term *term __maybe_unused, | |
186 | struct perf_evlist *evlist __maybe_unused, | |
187 | int *error_pos __maybe_unused, | |
188 | int err __maybe_unused, | |
189 | char *buf, size_t size) | |
190 | { | |
191 | return __bpf_strerror(buf, size); | |
192 | } | |
8690a2a7 WN |
193 | |
194 | static inline int | |
195 | bpf__strerror_apply_obj_config(int err __maybe_unused, | |
196 | char *buf, size_t size) | |
197 | { | |
198 | return __bpf_strerror(buf, size); | |
199 | } | |
d7888573 WN |
200 | |
201 | static inline int | |
aa31be3a ACM |
202 | bpf__strerror_setup_output_event(struct perf_evlist *evlist __maybe_unused, |
203 | int err __maybe_unused, char *buf, size_t size) | |
d7888573 WN |
204 | { |
205 | return __bpf_strerror(buf, size); | |
206 | } | |
aa31be3a | 207 | |
69d262a9 | 208 | #endif |
aa31be3a ACM |
209 | |
210 | static inline int bpf__strerror_setup_stdout(struct perf_evlist *evlist, int err, char *buf, size_t size) | |
211 | { | |
212 | return bpf__strerror_setup_output_event(evlist, err, buf, size); | |
213 | } | |
69d262a9 | 214 | #endif |