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