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