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