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