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