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