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