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