Commit | Line | Data |
---|---|---|
17baffe2 | 1 | /* |
451e462f | 2 | * lttng-tracepoint-event-impl.h |
17baffe2 MD |
3 | * |
4 | * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org> | |
f127e61e | 5 | * Copyright (C) 2009-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
17baffe2 | 6 | * |
886d51a3 MD |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; only | |
10 | * version 2.1 of the License. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17baffe2 | 20 | */ |
f127e61e | 21 | |
d28686c1 | 22 | #include <linux/uaccess.h> |
d0dd2ecb | 23 | #include <linux/debugfs.h> |
f127e61e | 24 | #include <linux/rculist.h> |
43803cf2 | 25 | #include <asm/byteorder.h> |
bf1a9179 | 26 | #include <linux/swab.h> |
6599a4eb | 27 | #include <linux/uidgid.h> |
8d43abb7 MD |
28 | |
29 | #include <probes/lttng.h> | |
30 | #include <probes/lttng-types.h> | |
31 | #include <probes/lttng-probe-user.h> | |
32 | #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */ | |
33 | #include <wrapper/ringbuffer/frontend_types.h> | |
3c8ebbc8 | 34 | #include <wrapper/ringbuffer/backend.h> |
8d43abb7 MD |
35 | #include <wrapper/rcu.h> |
36 | #include <lttng-events.h> | |
37 | #include <lttng-tracer-core.h> | |
1e537d1f | 38 | #include <lttng-tp-mempool.h> |
40652b65 | 39 | |
1d84e8e7 MD |
40 | #define __LTTNG_NULL_STRING "(null)" |
41 | ||
40652b65 | 42 | /* |
6db3d13b | 43 | * Macro declarations used for all stages. |
40652b65 MD |
44 | */ |
45 | ||
76e4f017 MD |
46 | /* |
47 | * LTTng name mapping macros. LTTng remaps some of the kernel events to | |
48 | * enforce name-spacing. | |
49 | */ | |
3bc29f0a | 50 | #undef LTTNG_TRACEPOINT_EVENT_MAP |
f127e61e | 51 | #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \ |
3bc29f0a | 52 | LTTNG_TRACEPOINT_EVENT_CLASS(map, \ |
76e4f017 MD |
53 | PARAMS(proto), \ |
54 | PARAMS(args), \ | |
f127e61e | 55 | PARAMS(fields)) \ |
3bc29f0a | 56 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args)) |
76e4f017 | 57 | |
3bc29f0a | 58 | #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS |
f127e61e | 59 | #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \ |
3bc29f0a | 60 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \ |
f127e61e | 61 | PARAMS(fields)) \ |
3bc29f0a | 62 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map) |
76e4f017 | 63 | |
f127e61e | 64 | #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP |
265822ae | 65 | #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \ |
f127e61e MD |
66 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \ |
67 | PARAMS(proto), \ | |
68 | PARAMS(args), \ | |
69 | PARAMS(_locvar), \ | |
265822ae MD |
70 | PARAMS(_code_pre), \ |
71 | PARAMS(fields), \ | |
72 | PARAMS(_code_post)) \ | |
f127e61e MD |
73 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args)) |
74 | ||
3bc29f0a | 75 | #undef LTTNG_TRACEPOINT_EVENT_CODE |
265822ae | 76 | #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \ |
f127e61e | 77 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \ |
7ca580f8 MD |
78 | PARAMS(proto), \ |
79 | PARAMS(args), \ | |
80 | PARAMS(_locvar), \ | |
265822ae MD |
81 | PARAMS(_code_pre), \ |
82 | PARAMS(fields), \ | |
83 | PARAMS(_code_post)) | |
fcf7fa33 | 84 | |
40652b65 | 85 | /* |
3bc29f0a MD |
86 | * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function |
87 | * handlers for events. That is, if all events have the same parameters | |
88 | * and just have distinct trace points. Each tracepoint can be defined | |
89 | * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the | |
90 | * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint. | |
40652b65 | 91 | * |
3bc29f0a MD |
92 | * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and |
93 | * template. | |
40652b65 | 94 | */ |
6db3d13b | 95 | |
3bc29f0a | 96 | #undef LTTNG_TRACEPOINT_EVENT |
f127e61e | 97 | #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \ |
3bc29f0a MD |
98 | LTTNG_TRACEPOINT_EVENT_MAP(name, name, \ |
99 | PARAMS(proto), \ | |
100 | PARAMS(args), \ | |
f127e61e | 101 | PARAMS(fields)) |
40652b65 | 102 | |
3bc29f0a | 103 | #undef LTTNG_TRACEPOINT_EVENT_NOARGS |
f127e61e MD |
104 | #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \ |
105 | LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields)) | |
76e4f017 | 106 | |
3bc29f0a MD |
107 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE |
108 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \ | |
109 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args)) | |
76e4f017 | 110 | |
3bc29f0a MD |
111 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS |
112 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \ | |
113 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name) | |
76e4f017 | 114 | |
3bc29f0a | 115 | #undef LTTNG_TRACEPOINT_EVENT_CLASS |
f127e61e | 116 | #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ |
3bc29f0a | 117 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \ |
265822ae | 118 | PARAMS(_fields), ) |
7ca580f8 | 119 | |
3bc29f0a | 120 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS |
f127e61e | 121 | #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
265822ae | 122 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), ) |
7ca580f8 MD |
123 | |
124 | ||
f62b389e | 125 | /* |
c099397a | 126 | * Stage 1 of the trace events. |
f62b389e MD |
127 | * |
128 | * Create dummy trace calls for each events, verifying that the LTTng module | |
3bc29f0a MD |
129 | * instrumentation headers match the kernel arguments. Will be optimized |
130 | * out by the compiler. | |
f62b389e MD |
131 | */ |
132 | ||
f127e61e | 133 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 | 134 | #include <probes/lttng-events-reset.h> |
f62b389e MD |
135 | |
136 | #undef TP_PROTO | |
f127e61e | 137 | #define TP_PROTO(...) __VA_ARGS__ |
f62b389e MD |
138 | |
139 | #undef TP_ARGS | |
f127e61e | 140 | #define TP_ARGS(...) __VA_ARGS__ |
f62b389e | 141 | |
3bc29f0a MD |
142 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP |
143 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
7eb827f2 | 144 | void trace_##_name(_proto); |
f62b389e | 145 | |
3bc29f0a MD |
146 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS |
147 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
cb1aa0c7 | 148 | void trace_##_name(void); |
f7bdf4db | 149 | |
f62b389e MD |
150 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
151 | ||
d0558de2 MD |
152 | /* |
153 | * Stage 1.1 of the trace events. | |
154 | * | |
155 | * Create dummy trace prototypes for each event class, and for each used | |
156 | * template. This will allow checking whether the prototypes from the | |
157 | * class and the instance using the class actually match. | |
158 | */ | |
159 | ||
ba012e22 | 160 | #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */ |
d0558de2 MD |
161 | |
162 | #undef TP_PROTO | |
163 | #define TP_PROTO(...) __VA_ARGS__ | |
164 | ||
165 | #undef TP_ARGS | |
166 | #define TP_ARGS(...) __VA_ARGS__ | |
167 | ||
168 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP | |
169 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
170 | void __event_template_proto___##_template(_proto); | |
171 | ||
172 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS | |
173 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
174 | void __event_template_proto___##_template(void); | |
175 | ||
176 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE | |
265822ae | 177 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
d0558de2 MD |
178 | void __event_template_proto___##_name(_proto); |
179 | ||
180 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS | |
265822ae | 181 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
d0558de2 MD |
182 | void __event_template_proto___##_name(void); |
183 | ||
184 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
185 | ||
141ddf28 MD |
186 | /* |
187 | * Stage 1.2 of tracepoint event generation | |
188 | * | |
189 | * Unfolding the enums | |
190 | */ | |
191 | #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */ | |
192 | ||
193 | /* Enumeration entry (single value) */ | |
194 | #undef ctf_enum_value | |
195 | #define ctf_enum_value(_string, _value) \ | |
196 | { \ | |
197 | .start = { \ | |
198 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
199 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
200 | (long long) (_value) : (_value), \ | |
201 | }, \ | |
202 | .end = { \ | |
203 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
204 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
205 | (long long) (_value) : (_value), \ | |
206 | }, \ | |
207 | .string = (_string), \ | |
208 | }, | |
209 | ||
210 | /* Enumeration entry (range) */ | |
211 | #undef ctf_enum_range | |
212 | #define ctf_enum_range(_string, _range_start, _range_end) \ | |
213 | { \ | |
214 | .start = { \ | |
215 | .signedness = lttng_is_signed_type(__typeof__(_range_start)), \ | |
216 | .value = lttng_is_signed_type(__typeof__(_range_start)) ? \ | |
217 | (long long) (_range_start) : (_range_start), \ | |
218 | }, \ | |
219 | .end = { \ | |
220 | .signedness = lttng_is_signed_type(__typeof__(_range_end)), \ | |
221 | .value = lttng_is_signed_type(__typeof__(_range_end)) ? \ | |
222 | (long long) (_range_end) : (_range_end), \ | |
223 | }, \ | |
224 | .string = (_string), \ | |
225 | }, | |
226 | ||
08ad1061 PP |
227 | /* Enumeration entry (automatic value; follows the rules of CTF) */ |
228 | #undef ctf_enum_auto | |
229 | #define ctf_enum_auto(_string) \ | |
230 | { \ | |
231 | .start = { \ | |
232 | .signedness = -1, \ | |
233 | .value = -1, \ | |
234 | }, \ | |
235 | .end = { \ | |
236 | .signedness = -1, \ | |
237 | .value = -1, \ | |
238 | }, \ | |
239 | .string = (_string), \ | |
240 | .options = { \ | |
241 | .is_auto = 1, \ | |
242 | } \ | |
243 | }, | |
244 | ||
141ddf28 MD |
245 | #undef TP_ENUM_VALUES |
246 | #define TP_ENUM_VALUES(...) \ | |
247 | __VA_ARGS__ | |
248 | ||
249 | #undef LTTNG_TRACEPOINT_ENUM | |
250 | #define LTTNG_TRACEPOINT_ENUM(_name, _values) \ | |
251 | const struct lttng_enum_entry __enum_values__##_name[] = { \ | |
252 | _values \ | |
253 | }; | |
254 | ||
255 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
256 | ||
6db3d13b | 257 | /* |
c099397a | 258 | * Stage 2 of the trace events. |
6db3d13b MD |
259 | * |
260 | * Create event field type metadata section. | |
261 | * Each event produce an array of fields. | |
262 | */ | |
263 | ||
f127e61e | 264 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
265 | #include <probes/lttng-events-reset.h> |
266 | #include <probes/lttng-events-write.h> | |
267 | #include <probes/lttng-events-nowrite.h> | |
6db3d13b | 268 | |
f127e61e MD |
269 | #undef _ctf_integer_ext |
270 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ | |
c099397a MD |
271 | { \ |
272 | .name = #_item, \ | |
43803cf2 | 273 | .type = __type_integer(_type, 0, 0, -1, _byte_order, _base, none),\ |
f127e61e MD |
274 | .nowrite = _nowrite, \ |
275 | .user = _user, \ | |
c099397a | 276 | }, |
40652b65 | 277 | |
f127e61e MD |
278 | #undef _ctf_array_encoded |
279 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ | |
299338c8 | 280 | { \ |
c099397a MD |
281 | .name = #_item, \ |
282 | .type = \ | |
283 | { \ | |
299338c8 | 284 | .atype = atype_array, \ |
f127e61e | 285 | .u = \ |
c099397a | 286 | { \ |
f127e61e MD |
287 | .array = \ |
288 | { \ | |
43803cf2 | 289 | .elem_type = __type_integer(_type, 0, 0, 0, __BYTE_ORDER, 10, _encoding), \ |
f127e61e MD |
290 | .length = _length, \ |
291 | } \ | |
292 | } \ | |
299338c8 | 293 | }, \ |
f127e61e MD |
294 | .nowrite = _nowrite, \ |
295 | .user = _user, \ | |
299338c8 | 296 | }, |
40652b65 | 297 | |
43803cf2 MD |
298 | #undef _ctf_array_bitfield |
299 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
300 | { \ | |
301 | .name = #_item, \ | |
302 | .type = \ | |
303 | { \ | |
304 | .atype = atype_array, \ | |
305 | .u = \ | |
306 | { \ | |
307 | .array = \ | |
308 | { \ | |
309 | .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \ | |
310 | .length = (_length) * sizeof(_type) * CHAR_BIT, \ | |
311 | .elem_alignment = lttng_alignof(_type), \ | |
312 | } \ | |
313 | } \ | |
314 | }, \ | |
315 | .nowrite = _nowrite, \ | |
316 | .user = _user, \ | |
317 | }, | |
318 | ||
319 | ||
f127e61e MD |
320 | #undef _ctf_sequence_encoded |
321 | #define _ctf_sequence_encoded(_type, _item, _src, \ | |
322 | _length_type, _src_length, _encoding, \ | |
57ede728 | 323 | _byte_order, _base, _user, _nowrite) \ |
299338c8 | 324 | { \ |
c099397a MD |
325 | .name = #_item, \ |
326 | .type = \ | |
327 | { \ | |
299338c8 | 328 | .atype = atype_sequence, \ |
f127e61e | 329 | .u = \ |
c099397a | 330 | { \ |
f127e61e MD |
331 | .sequence = \ |
332 | { \ | |
43803cf2 MD |
333 | .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \ |
334 | .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _base, _encoding), \ | |
335 | }, \ | |
336 | }, \ | |
337 | }, \ | |
338 | .nowrite = _nowrite, \ | |
339 | .user = _user, \ | |
340 | }, | |
341 | ||
342 | #undef _ctf_sequence_bitfield | |
343 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
344 | _length_type, _src_length, \ | |
345 | _user, _nowrite) \ | |
346 | { \ | |
347 | .name = #_item, \ | |
348 | .type = \ | |
349 | { \ | |
350 | .atype = atype_sequence, \ | |
351 | .u = \ | |
352 | { \ | |
353 | .sequence = \ | |
354 | { \ | |
355 | .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 10, none), \ | |
356 | .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, 10, none), \ | |
357 | .elem_alignment = lttng_alignof(_type), \ | |
f127e61e | 358 | }, \ |
c099397a | 359 | }, \ |
299338c8 | 360 | }, \ |
f127e61e MD |
361 | .nowrite = _nowrite, \ |
362 | .user = _user, \ | |
299338c8 | 363 | }, |
40652b65 | 364 | |
f127e61e MD |
365 | #undef _ctf_string |
366 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
299338c8 | 367 | { \ |
c099397a MD |
368 | .name = #_item, \ |
369 | .type = \ | |
370 | { \ | |
299338c8 | 371 | .atype = atype_string, \ |
f127e61e MD |
372 | .u = \ |
373 | { \ | |
374 | .basic = { .string = { .encoding = lttng_encode_UTF8 } } \ | |
375 | }, \ | |
299338c8 | 376 | }, \ |
f127e61e MD |
377 | .nowrite = _nowrite, \ |
378 | .user = _user, \ | |
299338c8 | 379 | }, |
1d12cebd | 380 | |
141ddf28 MD |
381 | #undef _ctf_enum |
382 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
383 | { \ | |
384 | .name = #_item, \ | |
385 | .type = { \ | |
386 | .atype = atype_enum, \ | |
387 | .u = { \ | |
388 | .basic = { \ | |
389 | .enumeration = { \ | |
390 | .desc = &__enum_##_name, \ | |
391 | .container_type = { \ | |
392 | .size = sizeof(_type) * CHAR_BIT, \ | |
393 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ | |
394 | .signedness = lttng_is_signed_type(_type), \ | |
395 | .reverse_byte_order = 0, \ | |
396 | .base = 10, \ | |
397 | .encoding = lttng_encode_none, \ | |
398 | }, \ | |
399 | }, \ | |
400 | }, \ | |
401 | }, \ | |
402 | }, \ | |
403 | .nowrite = _nowrite, \ | |
404 | .user = _user, \ | |
405 | }, | |
f64dd4be MD |
406 | |
407 | #undef ctf_custom_field | |
408 | #define ctf_custom_field(_type, _item, _code) \ | |
409 | { \ | |
410 | .name = #_item, \ | |
411 | .type = { _type }, \ | |
412 | .nowrite = 0, \ | |
413 | .user = 0, \ | |
414 | }, | |
415 | ||
416 | #undef ctf_custom_type | |
417 | #define ctf_custom_type(...) __VA_ARGS__ | |
418 | ||
f127e61e MD |
419 | #undef TP_FIELDS |
420 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
1d12cebd | 421 | |
3bc29f0a | 422 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 423 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
0d1d4002 | 424 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
f127e61e | 425 | _fields \ |
299338c8 MD |
426 | }; |
427 | ||
3bc29f0a | 428 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae MD |
429 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
430 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post) | |
f7bdf4db | 431 | |
141ddf28 MD |
432 | #undef LTTNG_TRACEPOINT_ENUM |
433 | #define LTTNG_TRACEPOINT_ENUM(_name, _values) \ | |
434 | static const struct lttng_enum_desc __enum_##_name = { \ | |
435 | .name = #_name, \ | |
436 | .entries = __enum_values__##_name, \ | |
437 | .nr_entries = ARRAY_SIZE(__enum_values__##_name), \ | |
438 | }; | |
439 | ||
299338c8 MD |
440 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
441 | ||
19c57fbf | 442 | /* |
c099397a | 443 | * Stage 3 of the trace events. |
19c57fbf MD |
444 | * |
445 | * Create probe callback prototypes. | |
446 | */ | |
447 | ||
f127e61e | 448 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 | 449 | #include <probes/lttng-events-reset.h> |
19c57fbf MD |
450 | |
451 | #undef TP_PROTO | |
f127e61e | 452 | #define TP_PROTO(...) __VA_ARGS__ |
19c57fbf | 453 | |
3bc29f0a | 454 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 455 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
19c57fbf MD |
456 | static void __event_probe__##_name(void *__data, _proto); |
457 | ||
3bc29f0a | 458 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 459 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f7bdf4db MD |
460 | static void __event_probe__##_name(void *__data); |
461 | ||
19c57fbf MD |
462 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
463 | ||
f7bdf4db MD |
464 | /* |
465 | * Stage 4 of the trace events. | |
466 | * | |
40652b65 MD |
467 | * Create static inline function that calculates event size. |
468 | */ | |
469 | ||
f127e61e | 470 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
471 | #include <probes/lttng-events-reset.h> |
472 | #include <probes/lttng-events-write.h> | |
6db3d13b | 473 | |
f127e61e MD |
474 | #undef _ctf_integer_ext |
475 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ | |
a90917c3 | 476 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
0d1d4002 | 477 | __event_len += sizeof(_type); |
6db3d13b | 478 | |
f127e61e MD |
479 | #undef _ctf_array_encoded |
480 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ | |
a90917c3 | 481 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
0d1d4002 | 482 | __event_len += sizeof(_type) * (_length); |
6db3d13b | 483 | |
43803cf2 MD |
484 | #undef _ctf_array_bitfield |
485 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
486 | _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite) | |
487 | ||
f127e61e MD |
488 | #undef _ctf_sequence_encoded |
489 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 490 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
491 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \ |
492 | __event_len += sizeof(_length_type); \ | |
a90917c3 | 493 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
114667d5 MD |
494 | { \ |
495 | size_t __seqlen = (_src_length); \ | |
496 | \ | |
497 | if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \ | |
498 | goto error; \ | |
499 | barrier(); /* reserve before use. */ \ | |
500 | this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \ | |
501 | __event_len += sizeof(_type) * __seqlen; \ | |
502 | } | |
6db3d13b | 503 | |
43803cf2 MD |
504 | #undef _ctf_sequence_bitfield |
505 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
506 | _length_type, _src_length, \ | |
507 | _user, _nowrite) \ | |
508 | _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \ | |
509 | none, __LITTLE_ENDIAN, 10, _user, _nowrite) | |
510 | ||
d0255731 | 511 | /* |
f127e61e | 512 | * ctf_user_string includes \0. If returns 0, it faulted, so we set size to |
786b8312 | 513 | * 1 (\0 only). |
d0255731 | 514 | */ |
f127e61e MD |
515 | #undef _ctf_string |
516 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
114667d5 MD |
517 | if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \ |
518 | goto error; \ | |
519 | barrier(); /* reserve before use. */ \ | |
520 | if (_user) { \ | |
521 | __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \ | |
96d0248a | 522 | max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \ |
114667d5 MD |
523 | } else { \ |
524 | __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \ | |
1d84e8e7 | 525 | strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1; \ |
114667d5 | 526 | } |
c6e3f225 | 527 | |
141ddf28 MD |
528 | #undef _ctf_enum |
529 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
530 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
531 | ||
f64dd4be MD |
532 | #undef ctf_align |
533 | #define ctf_align(_type) \ | |
534 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); | |
535 | ||
536 | #undef ctf_custom_field | |
537 | #define ctf_custom_field(_type, _item, _code) \ | |
538 | { \ | |
539 | _code \ | |
540 | } | |
541 | ||
542 | #undef ctf_custom_code | |
543 | #define ctf_custom_code(...) __VA_ARGS__ | |
544 | ||
0d1d4002 | 545 | #undef TP_PROTO |
f127e61e | 546 | #define TP_PROTO(...) __VA_ARGS__ |
6db3d13b | 547 | |
f127e61e MD |
548 | #undef TP_FIELDS |
549 | #define TP_FIELDS(...) __VA_ARGS__ | |
6db3d13b | 550 | |
7ca580f8 MD |
551 | #undef TP_locvar |
552 | #define TP_locvar(...) __VA_ARGS__ | |
553 | ||
3bc29f0a | 554 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 555 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
114667d5 | 556 | static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \ |
0d1d4002 MD |
557 | { \ |
558 | size_t __event_len = 0; \ | |
d3de7f14 | 559 | unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \ |
7ca580f8 | 560 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
d3de7f14 | 561 | \ |
f127e61e | 562 | _fields \ |
d3de7f14 | 563 | return __event_len; \ |
114667d5 MD |
564 | \ |
565 | error: \ | |
566 | __attribute__((unused)); \ | |
567 | return -1; \ | |
d3de7f14 MD |
568 | } |
569 | ||
3bc29f0a | 570 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 571 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
114667d5 | 572 | static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \ |
d3de7f14 MD |
573 | { \ |
574 | size_t __event_len = 0; \ | |
575 | unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \ | |
7ca580f8 | 576 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
0d1d4002 | 577 | \ |
f127e61e | 578 | _fields \ |
0d1d4002 | 579 | return __event_len; \ |
114667d5 MD |
580 | \ |
581 | error: \ | |
582 | __attribute__((unused)); \ | |
583 | return -1; \ | |
6db3d13b | 584 | } |
40652b65 MD |
585 | |
586 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
587 | ||
f127e61e | 588 | |
40652b65 | 589 | /* |
f127e61e | 590 | * Stage 4.1 of tracepoint event generation. |
e763dbf5 | 591 | * |
f127e61e MD |
592 | * Create static inline function that layout the filter stack data. |
593 | * We make both write and nowrite data available to the filter. | |
e763dbf5 MD |
594 | */ |
595 | ||
f127e61e | 596 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
597 | #include <probes/lttng-events-reset.h> |
598 | #include <probes/lttng-events-write.h> | |
599 | #include <probes/lttng-events-nowrite.h> | |
f127e61e MD |
600 | |
601 | #undef _ctf_integer_ext_fetched | |
602 | #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
603 | if (lttng_is_signed_type(_type)) { \ | |
604 | int64_t __ctf_tmp_int64; \ | |
605 | switch (sizeof(_type)) { \ | |
606 | case 1: \ | |
607 | { \ | |
608 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ | |
609 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ | |
610 | break; \ | |
611 | } \ | |
612 | case 2: \ | |
613 | { \ | |
614 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
615 | if (_byte_order != __BYTE_ORDER) \ |
616 | __swab16s(&__tmp.v); \ | |
f127e61e MD |
617 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
618 | break; \ | |
619 | } \ | |
620 | case 4: \ | |
621 | { \ | |
622 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
623 | if (_byte_order != __BYTE_ORDER) \ |
624 | __swab32s(&__tmp.v); \ | |
f127e61e MD |
625 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
626 | break; \ | |
627 | } \ | |
628 | case 8: \ | |
629 | { \ | |
630 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
631 | if (_byte_order != __BYTE_ORDER) \ |
632 | __swab64s(&__tmp.v); \ | |
f127e61e MD |
633 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
634 | break; \ | |
635 | } \ | |
636 | default: \ | |
637 | BUG_ON(1); \ | |
638 | }; \ | |
639 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ | |
640 | } else { \ | |
641 | uint64_t __ctf_tmp_uint64; \ | |
642 | switch (sizeof(_type)) { \ | |
643 | case 1: \ | |
644 | { \ | |
645 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ | |
646 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ | |
647 | break; \ | |
648 | } \ | |
649 | case 2: \ | |
650 | { \ | |
651 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
652 | if (_byte_order != __BYTE_ORDER) \ |
653 | __swab16s(&__tmp.v); \ | |
f127e61e MD |
654 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
655 | break; \ | |
656 | } \ | |
657 | case 4: \ | |
658 | { \ | |
659 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
660 | if (_byte_order != __BYTE_ORDER) \ |
661 | __swab32s(&__tmp.v); \ | |
f127e61e MD |
662 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
663 | break; \ | |
664 | } \ | |
665 | case 8: \ | |
666 | { \ | |
667 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
668 | if (_byte_order != __BYTE_ORDER) \ |
669 | __swab64s(&__tmp.v); \ | |
f127e61e MD |
670 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
671 | break; \ | |
672 | } \ | |
673 | default: \ | |
674 | BUG_ON(1); \ | |
675 | }; \ | |
676 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ | |
677 | } \ | |
678 | __stack_data += sizeof(int64_t); | |
679 | ||
680 | #undef _ctf_integer_ext_isuser0 | |
681 | #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
682 | _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) | |
683 | ||
684 | #undef _ctf_integer_ext_isuser1 | |
685 | #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \ | |
3c8ebbc8 MD |
686 | { \ |
687 | union { \ | |
688 | char __array[sizeof(_user_src)]; \ | |
689 | __typeof__(_user_src) __v; \ | |
690 | } __tmp_fetch; \ | |
691 | if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \ | |
692 | &(_user_src), sizeof(_user_src))) \ | |
693 | memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \ | |
694 | _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \ | |
f127e61e | 695 | } |
e763dbf5 | 696 | |
f127e61e MD |
697 | #undef _ctf_integer_ext |
698 | #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \ | |
699 | _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite) | |
700 | ||
701 | #undef _ctf_array_encoded | |
702 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ | |
703 | { \ | |
704 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
705 | const void *__ctf_tmp_ptr = (_src); \ | |
706 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ | |
707 | __stack_data += sizeof(unsigned long); \ | |
6b272cda MD |
708 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
709 | __stack_data += sizeof(void *); \ | |
f127e61e MD |
710 | } |
711 | ||
43803cf2 MD |
712 | #undef _ctf_array_bitfield |
713 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
714 | _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite) | |
715 | ||
f127e61e MD |
716 | #undef _ctf_sequence_encoded |
717 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 718 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
719 | { \ |
720 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
721 | const void *__ctf_tmp_ptr = (_src); \ | |
722 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ | |
723 | __stack_data += sizeof(unsigned long); \ | |
6b272cda MD |
724 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
725 | __stack_data += sizeof(void *); \ | |
f127e61e MD |
726 | } |
727 | ||
43803cf2 MD |
728 | #undef _ctf_sequence_bitfield |
729 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
730 | _length_type, _src_length, \ | |
731 | _user, _nowrite) \ | |
732 | _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \ | |
733 | none, __LITTLE_ENDIAN, 10, _user, _nowrite) | |
734 | ||
f127e61e MD |
735 | #undef _ctf_string |
736 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
737 | { \ | |
1d84e8e7 MD |
738 | const void *__ctf_tmp_ptr = \ |
739 | ((_src) ? (_src) : __LTTNG_NULL_STRING); \ | |
6b272cda MD |
740 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
741 | __stack_data += sizeof(void *); \ | |
f127e61e | 742 | } |
c6e3f225 | 743 | |
141ddf28 MD |
744 | #undef _ctf_enum |
745 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
746 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
747 | ||
e763dbf5 | 748 | #undef TP_PROTO |
f127e61e | 749 | #define TP_PROTO(...) __VA_ARGS__ |
e763dbf5 | 750 | |
f127e61e MD |
751 | #undef TP_FIELDS |
752 | #define TP_FIELDS(...) __VA_ARGS__ | |
e763dbf5 | 753 | |
7ca580f8 MD |
754 | #undef TP_locvar |
755 | #define TP_locvar(...) __VA_ARGS__ | |
756 | ||
f127e61e | 757 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 758 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
759 | static inline \ |
760 | void __event_prepare_filter_stack__##_name(char *__stack_data, \ | |
761 | void *__tp_locvar) \ | |
e763dbf5 | 762 | { \ |
7ca580f8 MD |
763 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
764 | \ | |
f127e61e | 765 | _fields \ |
e763dbf5 MD |
766 | } |
767 | ||
f127e61e | 768 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 769 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
770 | static inline \ |
771 | void __event_prepare_filter_stack__##_name(char *__stack_data, \ | |
772 | void *__tp_locvar, _proto) \ | |
d3de7f14 | 773 | { \ |
7ca580f8 MD |
774 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
775 | \ | |
f127e61e | 776 | _fields \ |
d3de7f14 MD |
777 | } |
778 | ||
e763dbf5 MD |
779 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
780 | ||
e763dbf5 | 781 | /* |
f127e61e | 782 | * Stage 5 of the trace events. |
40652b65 | 783 | * |
f127e61e | 784 | * Create static inline function that calculates event payload alignment. |
3c4ffab9 MD |
785 | */ |
786 | ||
f127e61e | 787 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
788 | #include <probes/lttng-events-reset.h> |
789 | #include <probes/lttng-events-write.h> | |
3c4ffab9 | 790 | |
f127e61e MD |
791 | #undef _ctf_integer_ext |
792 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ | |
793 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
3c4ffab9 | 794 | |
f127e61e MD |
795 | #undef _ctf_array_encoded |
796 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ | |
797 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
3c4ffab9 | 798 | |
43803cf2 MD |
799 | #undef _ctf_array_bitfield |
800 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
801 | _ctf_array_encoded(_type, _item, _src, _length, none, _user, _nowrite) | |
802 | ||
f127e61e MD |
803 | #undef _ctf_sequence_encoded |
804 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 805 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
806 | __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \ |
807 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
64c796d8 | 808 | |
43803cf2 MD |
809 | #undef _ctf_sequence_bitfield |
810 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
811 | _length_type, _src_length, \ | |
812 | _user, _nowrite) \ | |
813 | _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \ | |
814 | none, __LITTLE_ENDIAN, 10, _user, _nowrite) | |
815 | ||
f127e61e MD |
816 | #undef _ctf_string |
817 | #define _ctf_string(_item, _src, _user, _nowrite) | |
64c796d8 | 818 | |
141ddf28 MD |
819 | #undef _ctf_enum |
820 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
821 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
822 | ||
f64dd4be MD |
823 | #undef ctf_align |
824 | #define ctf_align(_type) \ | |
825 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
826 | ||
f127e61e MD |
827 | #undef TP_PROTO |
828 | #define TP_PROTO(...) __VA_ARGS__ | |
84da5206 | 829 | |
f127e61e MD |
830 | #undef TP_FIELDS |
831 | #define TP_FIELDS(...) __VA_ARGS__ | |
c6e3f225 | 832 | |
f127e61e MD |
833 | #undef TP_locvar |
834 | #define TP_locvar(...) __VA_ARGS__ | |
3c4ffab9 | 835 | |
f64dd4be MD |
836 | #undef ctf_custom_field |
837 | #define ctf_custom_field(_type, _item, _code) _code | |
838 | ||
839 | #undef ctf_custom_code | |
840 | #define ctf_custom_code(...) \ | |
841 | { \ | |
842 | __VA_ARGS__ \ | |
843 | } | |
844 | ||
f127e61e | 845 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 846 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
847 | static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \ |
848 | { \ | |
849 | size_t __event_align = 1; \ | |
850 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ | |
851 | \ | |
852 | _fields \ | |
853 | return __event_align; \ | |
854 | } | |
3c4ffab9 | 855 | |
3bc29f0a | 856 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 857 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
858 | static inline size_t __event_get_align__##_name(void *__tp_locvar) \ |
859 | { \ | |
860 | size_t __event_align = 1; \ | |
861 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ | |
862 | \ | |
863 | _fields \ | |
864 | return __event_align; \ | |
865 | } | |
d3de7f14 | 866 | |
3c4ffab9 MD |
867 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
868 | ||
3c4ffab9 | 869 | /* |
f127e61e | 870 | * Stage 6 of tracepoint event generation. |
e763dbf5 | 871 | * |
f127e61e MD |
872 | * Create the probe function. This function calls event size calculation |
873 | * and writes event data into the buffer. | |
40652b65 MD |
874 | */ |
875 | ||
f127e61e | 876 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
877 | #include <probes/lttng-events-reset.h> |
878 | #include <probes/lttng-events-write.h> | |
c6e3f225 | 879 | |
f127e61e MD |
880 | #undef _ctf_integer_ext_fetched |
881 | #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
e763dbf5 | 882 | { \ |
f127e61e MD |
883 | _type __tmp = _src; \ |
884 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ | |
aaa4004a | 885 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
f127e61e MD |
886 | } |
887 | ||
888 | #undef _ctf_integer_ext_isuser0 | |
889 | #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
890 | _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) | |
891 | ||
892 | #undef _ctf_integer_ext_isuser1 | |
893 | #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \ | |
894 | { \ | |
3c8ebbc8 MD |
895 | union { \ |
896 | char __array[sizeof(_user_src)]; \ | |
897 | __typeof__(_user_src) __v; \ | |
898 | } __tmp_fetch; \ | |
899 | if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \ | |
900 | &(_user_src), sizeof(_user_src))) \ | |
901 | memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \ | |
902 | _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \ | |
f127e61e MD |
903 | } |
904 | ||
905 | #undef _ctf_integer_ext | |
906 | #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \ | |
907 | _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite) | |
908 | ||
909 | #undef _ctf_array_encoded | |
910 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \ | |
911 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
912 | if (_user) { \ | |
913 | __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \ | |
914 | } else { \ | |
915 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \ | |
916 | } | |
917 | ||
43803cf2 MD |
918 | #if (__BYTE_ORDER == __LITTLE_ENDIAN) |
919 | #undef _ctf_array_bitfield | |
920 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
921 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
922 | if (_user) { \ | |
923 | __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \ | |
924 | } else { \ | |
925 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \ | |
926 | } | |
927 | #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
928 | /* | |
929 | * For big endian, we need to byteswap into little endian. | |
930 | */ | |
931 | #undef _ctf_array_bitfield | |
932 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
933 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
934 | { \ | |
935 | size_t _i; \ | |
936 | \ | |
937 | for (_i = 0; _i < (_length); _i++) { \ | |
938 | _type _tmp; \ | |
939 | \ | |
940 | if (_user) { \ | |
941 | if (get_user(_tmp, (_type *) _src + _i)) \ | |
942 | _tmp = 0; \ | |
943 | } else { \ | |
944 | _tmp = ((_type *) _src)[_i]; \ | |
945 | } \ | |
946 | switch (sizeof(_type)) { \ | |
947 | case 1: \ | |
948 | break; \ | |
949 | case 2: \ | |
950 | _tmp = cpu_to_le16(_tmp); \ | |
951 | break; \ | |
952 | case 4: \ | |
953 | _tmp = cpu_to_le32(_tmp); \ | |
954 | break; \ | |
955 | case 8: \ | |
956 | _tmp = cpu_to_le64(_tmp); \ | |
957 | break; \ | |
958 | default: \ | |
959 | BUG_ON(1); \ | |
960 | } \ | |
961 | __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \ | |
962 | } \ | |
963 | } | |
964 | #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
965 | ||
f127e61e MD |
966 | #undef _ctf_sequence_encoded |
967 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 968 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
84da5206 | 969 | { \ |
114667d5 | 970 | _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \ |
f127e61e MD |
971 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
972 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
84da5206 | 973 | } \ |
f127e61e MD |
974 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
975 | if (_user) { \ | |
976 | __chan->ops->event_write_from_user(&__ctx, _src, \ | |
977 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
978 | } else { \ | |
979 | __chan->ops->event_write(&__ctx, _src, \ | |
980 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
981 | } | |
982 | ||
43803cf2 MD |
983 | #if (__BYTE_ORDER == __LITTLE_ENDIAN) |
984 | #undef _ctf_sequence_bitfield | |
985 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
986 | _length_type, _src_length, \ | |
987 | _user, _nowrite) \ | |
988 | { \ | |
114667d5 | 989 | _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \ |
43803cf2 MD |
990 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
991 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
992 | } \ | |
993 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
994 | if (_user) { \ | |
995 | __chan->ops->event_write_from_user(&__ctx, _src, \ | |
996 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
997 | } else { \ | |
998 | __chan->ops->event_write(&__ctx, _src, \ | |
999 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
1000 | } | |
1001 | #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
1002 | /* | |
1003 | * For big endian, we need to byteswap into little endian. | |
1004 | */ | |
1005 | #undef _ctf_sequence_bitfield | |
1006 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
1007 | _length_type, _src_length, \ | |
1008 | _user, _nowrite) \ | |
1009 | { \ | |
114667d5 | 1010 | _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \ |
43803cf2 MD |
1011 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
1012 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
1013 | } \ | |
1014 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
1015 | { \ | |
1016 | size_t _i, _length; \ | |
1017 | \ | |
1018 | _length = __get_dynamic_len(dest); \ | |
1019 | for (_i = 0; _i < _length; _i++) { \ | |
1020 | _type _tmp; \ | |
1021 | \ | |
1022 | if (_user) { \ | |
1023 | if (get_user(_tmp, (_type *) _src + _i)) \ | |
1024 | _tmp = 0; \ | |
1025 | } else { \ | |
1026 | _tmp = ((_type *) _src)[_i]; \ | |
1027 | } \ | |
1028 | switch (sizeof(_type)) { \ | |
1029 | case 1: \ | |
1030 | break; \ | |
1031 | case 2: \ | |
1032 | _tmp = cpu_to_le16(_tmp); \ | |
1033 | break; \ | |
1034 | case 4: \ | |
1035 | _tmp = cpu_to_le32(_tmp); \ | |
1036 | break; \ | |
1037 | case 8: \ | |
1038 | _tmp = cpu_to_le64(_tmp); \ | |
1039 | break; \ | |
1040 | default: \ | |
1041 | BUG_ON(1); \ | |
1042 | } \ | |
1043 | __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \ | |
1044 | } \ | |
1045 | } | |
1046 | #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
1047 | ||
f127e61e MD |
1048 | #undef _ctf_string |
1049 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
f127e61e | 1050 | if (_user) { \ |
1d84e8e7 | 1051 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ |
f127e61e MD |
1052 | __chan->ops->event_strcpy_from_user(&__ctx, _src, \ |
1053 | __get_dynamic_len(dest)); \ | |
1054 | } else { \ | |
1d84e8e7 MD |
1055 | const char *__ctf_tmp_string = \ |
1056 | ((_src) ? (_src) : __LTTNG_NULL_STRING); \ | |
1057 | lib_ring_buffer_align_ctx(&__ctx, \ | |
1058 | lttng_alignof(*__ctf_tmp_string)); \ | |
1059 | __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ | |
f127e61e MD |
1060 | __get_dynamic_len(dest)); \ |
1061 | } | |
e763dbf5 | 1062 | |
141ddf28 MD |
1063 | #undef _ctf_enum |
1064 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
1065 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
f64dd4be MD |
1066 | |
1067 | #undef ctf_align | |
1068 | #define ctf_align(_type) \ | |
1069 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); | |
1070 | ||
1071 | #undef ctf_custom_field | |
1072 | #define ctf_custom_field(_type, _item, _code) _code | |
1073 | ||
1074 | #undef ctf_custom_code | |
1075 | #define ctf_custom_code(...) \ | |
1076 | { \ | |
1077 | __VA_ARGS__ \ | |
1078 | } | |
1079 | ||
e763dbf5 | 1080 | /* Beware: this get len actually consumes the len value */ |
f127e61e | 1081 | #undef __get_dynamic_len |
114667d5 | 1082 | #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++] |
e763dbf5 MD |
1083 | |
1084 | #undef TP_PROTO | |
f127e61e | 1085 | #define TP_PROTO(...) __VA_ARGS__ |
e763dbf5 MD |
1086 | |
1087 | #undef TP_ARGS | |
f127e61e | 1088 | #define TP_ARGS(...) __VA_ARGS__ |
e763dbf5 | 1089 | |
f127e61e MD |
1090 | #undef TP_FIELDS |
1091 | #define TP_FIELDS(...) __VA_ARGS__ | |
e763dbf5 | 1092 | |
7ca580f8 MD |
1093 | #undef TP_locvar |
1094 | #define TP_locvar(...) __VA_ARGS__ | |
1095 | ||
265822ae MD |
1096 | #undef TP_code_pre |
1097 | #define TP_code_pre(...) __VA_ARGS__ | |
1098 | ||
1099 | #undef TP_code_post | |
1100 | #define TP_code_post(...) __VA_ARGS__ | |
7ca580f8 | 1101 | |
c337ddc2 MD |
1102 | /* |
1103 | * For state dump, check that "session" argument (mandatory) matches the | |
1104 | * session this event belongs to. Ensures that we write state dump data only | |
1105 | * into the started session, not into all sessions. | |
1106 | */ | |
1107 | #ifdef TP_SESSION_CHECK | |
1108 | #define _TP_SESSION_CHECK(session, csession) (session == csession) | |
1109 | #else /* TP_SESSION_CHECK */ | |
1110 | #define _TP_SESSION_CHECK(session, csession) 1 | |
1111 | #endif /* TP_SESSION_CHECK */ | |
1112 | ||
f9771d39 | 1113 | /* |
f127e61e MD |
1114 | * Using twice size for filter stack data to hold size and pointer for |
1115 | * each field (worse case). For integers, max size required is 64-bit. | |
1116 | * Same for double-precision floats. Those fit within | |
1117 | * 2*sizeof(unsigned long) for all supported architectures. | |
1118 | * Perform UNION (||) of filter runtime list. | |
f9771d39 | 1119 | */ |
3bc29f0a | 1120 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 1121 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
e763dbf5 MD |
1122 | static void __event_probe__##_name(void *__data, _proto) \ |
1123 | { \ | |
7ca580f8 | 1124 | struct probe_local_vars { _locvar }; \ |
a90917c3 | 1125 | struct lttng_event *__event = __data; \ |
79150a49 JD |
1126 | struct lttng_probe_ctx __lttng_probe_ctx = { \ |
1127 | .event = __event, \ | |
ccecf3fb | 1128 | .interruptible = !irqs_disabled(), \ |
79150a49 | 1129 | }; \ |
a90917c3 | 1130 | struct lttng_channel *__chan = __event->chan; \ |
e0130fab | 1131 | struct lttng_session *__session = __chan->session; \ |
aaa4004a | 1132 | struct lib_ring_buffer_ctx __ctx; \ |
114667d5 MD |
1133 | ssize_t __event_len; \ |
1134 | size_t __event_align; \ | |
ec0a7fba | 1135 | size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ |
f127e61e | 1136 | union { \ |
114667d5 | 1137 | size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ |
f127e61e MD |
1138 | char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ |
1139 | } __stackvar; \ | |
e763dbf5 | 1140 | int __ret; \ |
7ca580f8 MD |
1141 | struct probe_local_vars __tp_locvar; \ |
1142 | struct probe_local_vars *tp_locvar __attribute__((unused)) = \ | |
1143 | &__tp_locvar; \ | |
6599a4eb | 1144 | struct lttng_id_tracker_rcu *__lf; \ |
e763dbf5 | 1145 | \ |
e0130fab | 1146 | if (!_TP_SESSION_CHECK(session, __session)) \ |
c337ddc2 | 1147 | return; \ |
d4fe3450 | 1148 | if (unlikely(!READ_ONCE(__session->active))) \ |
e64957da | 1149 | return; \ |
d4fe3450 | 1150 | if (unlikely(!READ_ONCE(__chan->enabled))) \ |
e64957da | 1151 | return; \ |
d4fe3450 | 1152 | if (unlikely(!READ_ONCE(__event->enabled))) \ |
52fc2e1f | 1153 | return; \ |
6599a4eb MD |
1154 | __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ |
1155 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ | |
1156 | return; \ | |
1157 | __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \ | |
1158 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \ | |
1159 | return; \ | |
1160 | __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ | |
1161 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1162 | from_kuid(&init_user_ns, current_uid())))) \ | |
1163 | return; \ | |
1164 | __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ | |
1165 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1166 | from_kuid(current_user_ns(), current_uid())))) \ | |
1167 | return; \ | |
1168 | __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ | |
1169 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1170 | from_kgid(&init_user_ns, current_gid())))) \ | |
1171 | return; \ | |
1172 | __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ | |
1173 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1174 | from_kgid(current_user_ns(), current_gid())))) \ | |
e0130fab | 1175 | return; \ |
114667d5 MD |
1176 | __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ |
1177 | __dynamic_len_idx = __orig_dynamic_len_offset; \ | |
265822ae | 1178 | _code_pre \ |
f127e61e MD |
1179 | if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \ |
1180 | struct lttng_bytecode_runtime *bc_runtime; \ | |
1181 | int __filter_record = __event->has_enablers_without_bytecode; \ | |
1182 | \ | |
1183 | __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ | |
1184 | tp_locvar, _args); \ | |
7a09dcb7 | 1185 | lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ |
79150a49 | 1186 | if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ |
f127e61e MD |
1187 | __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \ |
1188 | __filter_record = 1; \ | |
1189 | } \ | |
1190 | if (likely(!__filter_record)) \ | |
265822ae | 1191 | goto __post; \ |
f127e61e | 1192 | } \ |
114667d5 MD |
1193 | __event_len = __event_get_size__##_name(tp_locvar, _args); \ |
1194 | if (unlikely(__event_len < 0)) { \ | |
1195 | lib_ring_buffer_lost_event_too_big(__chan->chan); \ | |
1196 | goto __post; \ | |
1197 | } \ | |
7ca580f8 | 1198 | __event_align = __event_get_align__##_name(tp_locvar, _args); \ |
79150a49 | 1199 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ |
e763dbf5 | 1200 | __event_align, -1); \ |
aaa4004a | 1201 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
e763dbf5 | 1202 | if (__ret < 0) \ |
265822ae | 1203 | goto __post; \ |
f127e61e | 1204 | _fields \ |
aaa4004a | 1205 | __chan->ops->event_commit(&__ctx); \ |
265822ae MD |
1206 | __post: \ |
1207 | _code_post \ | |
114667d5 MD |
1208 | barrier(); /* use before un-reserve. */ \ |
1209 | this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \ | |
265822ae | 1210 | return; \ |
e763dbf5 MD |
1211 | } |
1212 | ||
3bc29f0a | 1213 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 1214 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f7bdf4db MD |
1215 | static void __event_probe__##_name(void *__data) \ |
1216 | { \ | |
7ca580f8 | 1217 | struct probe_local_vars { _locvar }; \ |
a90917c3 | 1218 | struct lttng_event *__event = __data; \ |
79150a49 JD |
1219 | struct lttng_probe_ctx __lttng_probe_ctx = { \ |
1220 | .event = __event, \ | |
ccecf3fb | 1221 | .interruptible = !irqs_disabled(), \ |
79150a49 | 1222 | }; \ |
a90917c3 | 1223 | struct lttng_channel *__chan = __event->chan; \ |
e0130fab | 1224 | struct lttng_session *__session = __chan->session; \ |
f7bdf4db | 1225 | struct lib_ring_buffer_ctx __ctx; \ |
114667d5 MD |
1226 | ssize_t __event_len; \ |
1227 | size_t __event_align; \ | |
ec0a7fba | 1228 | size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ |
f127e61e | 1229 | union { \ |
114667d5 | 1230 | size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ |
f127e61e MD |
1231 | char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ |
1232 | } __stackvar; \ | |
f7bdf4db | 1233 | int __ret; \ |
7ca580f8 MD |
1234 | struct probe_local_vars __tp_locvar; \ |
1235 | struct probe_local_vars *tp_locvar __attribute__((unused)) = \ | |
1236 | &__tp_locvar; \ | |
6599a4eb | 1237 | struct lttng_id_tracker_rcu *__lf; \ |
f7bdf4db | 1238 | \ |
e0130fab | 1239 | if (!_TP_SESSION_CHECK(session, __session)) \ |
c337ddc2 | 1240 | return; \ |
d4fe3450 | 1241 | if (unlikely(!READ_ONCE(__session->active))) \ |
f7bdf4db | 1242 | return; \ |
d4fe3450 | 1243 | if (unlikely(!READ_ONCE(__chan->enabled))) \ |
f7bdf4db | 1244 | return; \ |
d4fe3450 | 1245 | if (unlikely(!READ_ONCE(__event->enabled))) \ |
f7bdf4db | 1246 | return; \ |
6599a4eb MD |
1247 | __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ |
1248 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ | |
1249 | return; \ | |
1250 | __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \ | |
1251 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \ | |
1252 | return; \ | |
1253 | __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ | |
1254 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1255 | from_kuid(&init_user_ns, current_uid())))) \ | |
1256 | return; \ | |
1257 | __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ | |
1258 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1259 | from_kuid(current_user_ns(), current_uid())))) \ | |
1260 | return; \ | |
1261 | __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ | |
1262 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1263 | from_kgid(&init_user_ns, current_gid())))) \ | |
1264 | return; \ | |
1265 | __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ | |
1266 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
1267 | from_kgid(current_user_ns(), current_gid())))) \ | |
e0130fab | 1268 | return; \ |
114667d5 MD |
1269 | __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ |
1270 | __dynamic_len_idx = __orig_dynamic_len_offset; \ | |
265822ae | 1271 | _code_pre \ |
f127e61e MD |
1272 | if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \ |
1273 | struct lttng_bytecode_runtime *bc_runtime; \ | |
1274 | int __filter_record = __event->has_enablers_without_bytecode; \ | |
1275 | \ | |
1276 | __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ | |
1277 | tp_locvar); \ | |
7a09dcb7 | 1278 | lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ |
79150a49 | 1279 | if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ |
f127e61e MD |
1280 | __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \ |
1281 | __filter_record = 1; \ | |
1282 | } \ | |
1283 | if (likely(!__filter_record)) \ | |
265822ae | 1284 | goto __post; \ |
f127e61e | 1285 | } \ |
114667d5 MD |
1286 | __event_len = __event_get_size__##_name(tp_locvar); \ |
1287 | if (unlikely(__event_len < 0)) { \ | |
1288 | lib_ring_buffer_lost_event_too_big(__chan->chan); \ | |
1289 | goto __post; \ | |
1290 | } \ | |
7ca580f8 | 1291 | __event_align = __event_get_align__##_name(tp_locvar); \ |
79150a49 | 1292 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ |
f7bdf4db MD |
1293 | __event_align, -1); \ |
1294 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ | |
1295 | if (__ret < 0) \ | |
265822ae | 1296 | goto __post; \ |
f127e61e | 1297 | _fields \ |
f7bdf4db | 1298 | __chan->ops->event_commit(&__ctx); \ |
265822ae MD |
1299 | __post: \ |
1300 | _code_post \ | |
114667d5 MD |
1301 | barrier(); /* use before un-reserve. */ \ |
1302 | this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \ | |
265822ae | 1303 | return; \ |
f7bdf4db MD |
1304 | } |
1305 | ||
e763dbf5 MD |
1306 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
1307 | ||
f127e61e MD |
1308 | #undef __get_dynamic_len |
1309 | ||
1310 | /* | |
1311 | * Stage 7 of the trace events. | |
1312 | * | |
1313 | * Create event descriptions. | |
1314 | */ | |
1315 | ||
1316 | /* Named field types must be defined in lttng-types.h */ | |
1317 | ||
ba012e22 | 1318 | #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ |
f127e61e MD |
1319 | |
1320 | #ifndef TP_PROBE_CB | |
1321 | #define TP_PROBE_CB(_template) &__event_probe__##_template | |
1322 | #endif | |
1323 | ||
1324 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS | |
1325 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
1326 | static const struct lttng_event_desc __event_desc___##_map = { \ | |
1327 | .fields = __event_fields___##_template, \ | |
1328 | .name = #_map, \ | |
1329 | .kname = #_name, \ | |
1330 | .probe_callback = (void *) TP_PROBE_CB(_template), \ | |
1331 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ | |
1332 | .owner = THIS_MODULE, \ | |
1333 | }; | |
1334 | ||
1335 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP | |
1336 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
1337 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) | |
1338 | ||
1339 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
1340 | ||
1341 | /* | |
1342 | * Stage 8 of the trace events. | |
1343 | * | |
1344 | * Create an array of event description pointers. | |
1345 | */ | |
1346 | ||
ba012e22 | 1347 | #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ |
f127e61e MD |
1348 | |
1349 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS | |
1350 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
1351 | &__event_desc___##_map, | |
1352 | ||
1353 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP | |
1354 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
1355 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) | |
1356 | ||
1357 | #define TP_ID1(_token, _system) _token##_system | |
1358 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
1359 | ||
1360 | static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = { | |
1361 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
1362 | }; | |
1363 | ||
1364 | #undef TP_ID1 | |
1365 | #undef TP_ID | |
1366 | ||
1367 | /* | |
1368 | * Stage 9 of the trace events. | |
1369 | * | |
1370 | * Create a toplevel descriptor for the whole probe. | |
1371 | */ | |
1372 | ||
1373 | #define TP_ID1(_token, _system) _token##_system | |
1374 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
1375 | ||
1376 | /* non-const because list head will be modified when registered. */ | |
1377 | static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { | |
1378 | .provider = __stringify(TRACE_SYSTEM), | |
1379 | .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM), | |
1380 | .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)), | |
1381 | .head = { NULL, NULL }, | |
1382 | .lazy_init_head = { NULL, NULL }, | |
1383 | .lazy = 0, | |
1384 | }; | |
1385 | ||
1386 | #undef TP_ID1 | |
1387 | #undef TP_ID | |
1388 | ||
3afe7aac | 1389 | /* |
c099397a | 1390 | * Stage 10 of the trace events. |
3afe7aac MD |
1391 | * |
1392 | * Register/unregister probes at module load/unload. | |
1393 | */ | |
1394 | ||
ba012e22 | 1395 | #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ |
3afe7aac MD |
1396 | |
1397 | #define TP_ID1(_token, _system) _token##_system | |
1398 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
1399 | #define module_init_eval1(_token, _system) module_init(_token##_system) | |
1400 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) | |
1401 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) | |
1402 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) | |
1403 | ||
2655f9ad | 1404 | #ifndef TP_MODULE_NOINIT |
3afe7aac MD |
1405 | static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) |
1406 | { | |
6d2a620c | 1407 | wrapper_vmalloc_sync_all(); |
a90917c3 | 1408 | return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
1409 | } |
1410 | ||
3afe7aac MD |
1411 | static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) |
1412 | { | |
a90917c3 | 1413 | lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
1414 | } |
1415 | ||
2655f9ad MD |
1416 | #ifndef TP_MODULE_NOAUTOLOAD |
1417 | module_init_eval(__lttng_events_init__, TRACE_SYSTEM); | |
3afe7aac | 1418 | module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM); |
259b6cb3 | 1419 | #endif |
3afe7aac | 1420 | |
2655f9ad MD |
1421 | #endif |
1422 | ||
3afe7aac MD |
1423 | #undef module_init_eval |
1424 | #undef module_exit_eval | |
1425 | #undef TP_ID1 | |
1426 | #undef TP_ID | |
177b3692 MD |
1427 | |
1428 | #undef TP_PROTO | |
1429 | #undef TP_ARGS |