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