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