Fix: tracepoint event: allow same provider and event name
[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 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_alignof(__tmp)); \
817 }
818
819 #undef _ctf_integer_ext_isuser0
820 #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
821 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
822
823 #undef _ctf_integer_ext_isuser1
824 #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
825 { \
826 union { \
827 char __array[sizeof(_user_src)]; \
828 __typeof__(_user_src) __v; \
829 } __tmp_fetch; \
830 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
831 &(_user_src), sizeof(_user_src))) \
832 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
833 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
834 }
835
836 #undef _ctf_integer_ext
837 #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
838 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
839
840 #undef _ctf_array_encoded
841 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \
842 if (lttng_kernel_string_encoding_##_encoding == lttng_kernel_string_encoding_none) { \
843 if (_user) { \
844 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length), lttng_alignof(_type)); \
845 } else { \
846 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_alignof(_type)); \
847 } \
848 } else { \
849 if (_user) { \
850 __chan->ops->event_pstrcpy_pad_from_user(&__ctx, (const char __user *) (_src), _length); \
851 } else { \
852 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
853 } \
854 }
855
856 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
857 #undef _ctf_array_bitfield
858 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
859 if (_user) { \
860 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length), lttng_alignof(_type)); \
861 } else { \
862 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_alignof(_type)); \
863 }
864 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
865 /*
866 * For big endian, we need to byteswap into little endian.
867 */
868 #undef _ctf_array_bitfield
869 #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \
870 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
871 { \
872 size_t _i; \
873 \
874 for (_i = 0; _i < (_length); _i++) { \
875 _type _tmp; \
876 \
877 if (_user) { \
878 if (get_user(_tmp, (_type *) _src + _i)) \
879 _tmp = 0; \
880 } else { \
881 _tmp = ((_type *) _src)[_i]; \
882 } \
883 switch (sizeof(_type)) { \
884 case 1: \
885 break; \
886 case 2: \
887 _tmp = cpu_to_le16(_tmp); \
888 break; \
889 case 4: \
890 _tmp = cpu_to_le32(_tmp); \
891 break; \
892 case 8: \
893 _tmp = cpu_to_le64(_tmp); \
894 break; \
895 default: \
896 BUG_ON(1); \
897 } \
898 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type), 1); \
899 } \
900 }
901 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
902
903 #undef _ctf_sequence_encoded
904 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
905 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
906 { \
907 _length_type __tmpl = this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx]; \
908 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_alignof(_length_type));\
909 } \
910 if (lttng_kernel_string_encoding_##_encoding == lttng_kernel_string_encoding_none) { \
911 if (_user) { \
912 __chan->ops->event_write_from_user(&__ctx, _src, \
913 sizeof(_type) * __get_dynamic_len(dest), lttng_alignof(_type)); \
914 } else { \
915 __chan->ops->event_write(&__ctx, _src, \
916 sizeof(_type) * __get_dynamic_len(dest), lttng_alignof(_type)); \
917 } \
918 } else { \
919 if (_user) { \
920 __chan->ops->event_pstrcpy_pad_from_user(&__ctx, (const char __user *) (_src), \
921 __get_dynamic_len(dest)); \
922 } else { \
923 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), \
924 __get_dynamic_len(dest)); \
925 } \
926 }
927
928 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
929 #undef _ctf_sequence_bitfield
930 #define _ctf_sequence_bitfield(_type, _item, _src, \
931 _length_type, _src_length, \
932 _user, _nowrite) \
933 { \
934 _length_type __tmpl = this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
935 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_alignof(_length_type)); \
936 } \
937 if (_user) { \
938 __chan->ops->event_write_from_user(&__ctx, _src, \
939 sizeof(_type) * __get_dynamic_len(dest), lttng_alignof(_type)); \
940 } else { \
941 __chan->ops->event_write(&__ctx, _src, \
942 sizeof(_type) * __get_dynamic_len(dest), lttng_alignof(_type)); \
943 }
944 #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
945 /*
946 * For big endian, we need to byteswap into little endian.
947 */
948 #undef _ctf_sequence_bitfield
949 #define _ctf_sequence_bitfield(_type, _item, _src, \
950 _length_type, _src_length, \
951 _user, _nowrite) \
952 { \
953 _length_type __tmpl = this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \
954 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_alignof(_length_type)); \
955 } \
956 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
957 { \
958 size_t _i, _length; \
959 \
960 _length = __get_dynamic_len(dest); \
961 for (_i = 0; _i < _length; _i++) { \
962 _type _tmp; \
963 \
964 if (_user) { \
965 if (get_user(_tmp, (_type *) _src + _i)) \
966 _tmp = 0; \
967 } else { \
968 _tmp = ((_type *) _src)[_i]; \
969 } \
970 switch (sizeof(_type)) { \
971 case 1: \
972 break; \
973 case 2: \
974 _tmp = cpu_to_le16(_tmp); \
975 break; \
976 case 4: \
977 _tmp = cpu_to_le32(_tmp); \
978 break; \
979 case 8: \
980 _tmp = cpu_to_le64(_tmp); \
981 break; \
982 default: \
983 BUG_ON(1); \
984 } \
985 __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type), 1); \
986 } \
987 }
988 #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */
989
990 #undef _ctf_string
991 #define _ctf_string(_item, _src, _user, _nowrite) \
992 if (_user) { \
993 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
994 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
995 __get_dynamic_len(dest)); \
996 } else { \
997 const char *__ctf_tmp_string = \
998 ((_src) ? (_src) : __LTTNG_NULL_STRING); \
999 lib_ring_buffer_align_ctx(&__ctx, \
1000 lttng_alignof(*__ctf_tmp_string)); \
1001 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
1002 __get_dynamic_len(dest)); \
1003 }
1004
1005 #undef _ctf_enum
1006 #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \
1007 _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite)
1008
1009 #undef ctf_align
1010 #define ctf_align(_type) \
1011 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type));
1012
1013 #undef ctf_custom_field
1014 #define ctf_custom_field(_type, _item, _code) _code
1015
1016 #undef ctf_custom_code
1017 #define ctf_custom_code(...) \
1018 { \
1019 __VA_ARGS__ \
1020 }
1021
1022 /* Beware: this get len actually consumes the len value */
1023 #undef __get_dynamic_len
1024 #define __get_dynamic_len(field) this_cpu_ptr(&lttng_dynamic_len_stack)->stack[__dynamic_len_idx++]
1025
1026 #undef TP_PROTO
1027 #define TP_PROTO(...) __VA_ARGS__
1028
1029 #undef TP_ARGS
1030 #define TP_ARGS(...) __VA_ARGS__
1031
1032 #undef TP_FIELDS
1033 #define TP_FIELDS(...) __VA_ARGS__
1034
1035 #undef TP_locvar
1036 #define TP_locvar(...) __VA_ARGS__
1037
1038 #undef TP_code_pre
1039 #define TP_code_pre(...) __VA_ARGS__
1040
1041 #undef TP_code_post
1042 #define TP_code_post(...) __VA_ARGS__
1043
1044 /*
1045 * For state dump, check that "session" argument (mandatory) matches the
1046 * session this event belongs to. Ensures that we write state dump data only
1047 * into the started session, not into all sessions.
1048 */
1049 #ifdef TP_SESSION_CHECK
1050 #define _TP_SESSION_CHECK(session, csession) (session == csession)
1051 #else /* TP_SESSION_CHECK */
1052 #define _TP_SESSION_CHECK(session, csession) 1
1053 #endif /* TP_SESSION_CHECK */
1054
1055 /*
1056 * Using twice size for filter stack data to hold size and pointer for
1057 * each field (worse case). For integers, max size required is 64-bit.
1058 * Same for double-precision floats. Those fit within
1059 * 2*sizeof(unsigned long) for all supported architectures.
1060 * Perform UNION (||) of filter runtime list.
1061 */
1062 #undef _LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1063 #define _LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _data_proto, _locvar_args, _locvar, _code_pre, _fields, _code_post) \
1064 static void __event_probe__##_name(_data_proto) \
1065 { \
1066 struct probe_local_vars { _locvar }; \
1067 struct lttng_kernel_event_common *__event = __data; \
1068 struct lttng_kernel_probe_ctx __lttng_probe_ctx = { \
1069 .event = __event, \
1070 .interruptible = !irqs_disabled(), \
1071 }; \
1072 union { \
1073 size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \
1074 char __interpreter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
1075 } __stackvar; \
1076 size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \
1077 struct probe_local_vars __tp_locvar; \
1078 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
1079 &__tp_locvar; \
1080 bool __interpreter_stack_prepared = false; \
1081 \
1082 switch (__event->type) { \
1083 case LTTNG_KERNEL_EVENT_TYPE_RECORDER: \
1084 { \
1085 struct lttng_kernel_event_recorder *__event_recorder = \
1086 container_of(__event, struct lttng_kernel_event_recorder, parent); \
1087 struct lttng_kernel_channel_buffer *__chan = __event_recorder->chan; \
1088 struct lttng_kernel_session *__session = __chan->parent.session; \
1089 struct lttng_kernel_id_tracker_rcu *__lf; \
1090 \
1091 if (!_TP_SESSION_CHECK(session, __session)) \
1092 return; \
1093 if (unlikely(!LTTNG_READ_ONCE(__session->active))) \
1094 return; \
1095 if (unlikely(!LTTNG_READ_ONCE(__chan->parent.enabled))) \
1096 return; \
1097 __lf = lttng_rcu_dereference(__session->pid_tracker.p); \
1098 if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \
1099 return; \
1100 __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \
1101 if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
1102 return; \
1103 __lf = lttng_rcu_dereference(__session->uid_tracker.p); \
1104 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1105 lttng_current_uid()))) \
1106 return; \
1107 __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \
1108 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1109 lttng_current_vuid()))) \
1110 return; \
1111 __lf = lttng_rcu_dereference(__session->gid_tracker.p); \
1112 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1113 lttng_current_gid()))) \
1114 return; \
1115 __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \
1116 if (__lf && likely(!lttng_id_tracker_lookup(__lf, \
1117 lttng_current_vgid()))) \
1118 return; \
1119 break; \
1120 } \
1121 case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: \
1122 break; \
1123 default: \
1124 WARN_ON_ONCE(1); \
1125 } \
1126 if (unlikely(!READ_ONCE(__event->enabled))) \
1127 return; \
1128 __orig_dynamic_len_offset = this_cpu_ptr(&lttng_dynamic_len_stack)->offset; \
1129 __dynamic_len_idx = __orig_dynamic_len_offset; \
1130 _code_pre \
1131 if (unlikely(READ_ONCE(__event->eval_filter))) { \
1132 __event_prepare_interpreter_stack__##_name(__stackvar.__interpreter_stack_data, \
1133 _locvar_args); \
1134 __interpreter_stack_prepared = true; \
1135 if (likely(__event->run_filter(__event, \
1136 __stackvar.__interpreter_stack_data, &__lttng_probe_ctx, NULL) != LTTNG_KERNEL_EVENT_FILTER_ACCEPT)) \
1137 goto __post; \
1138 } \
1139 switch (__event->type) { \
1140 case LTTNG_KERNEL_EVENT_TYPE_RECORDER: \
1141 { \
1142 struct lttng_kernel_event_recorder *__event_recorder = \
1143 container_of(__event, struct lttng_kernel_event_recorder, parent); \
1144 struct lttng_kernel_channel_buffer *__chan = __event_recorder->chan; \
1145 struct lttng_kernel_ring_buffer_ctx __ctx; \
1146 ssize_t __event_len; \
1147 size_t __event_align; \
1148 int __ret; \
1149 \
1150 __event_len = __event_get_size__##_name(_locvar_args); \
1151 if (unlikely(__event_len < 0)) { \
1152 __chan->ops->lost_event_too_big(__chan); \
1153 goto __post; \
1154 } \
1155 __event_align = __event_get_align__##_name(_locvar_args); \
1156 lib_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, \
1157 __event_align, &__lttng_probe_ctx); \
1158 __ret = __chan->ops->event_reserve(&__ctx); \
1159 if (__ret < 0) \
1160 goto __post; \
1161 _fields \
1162 __chan->ops->event_commit(&__ctx); \
1163 break; \
1164 } \
1165 case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: \
1166 { \
1167 struct lttng_kernel_event_notifier *__event_notifier = \
1168 container_of(__event, struct lttng_kernel_event_notifier, parent); \
1169 struct lttng_kernel_notification_ctx __notif_ctx; \
1170 \
1171 __notif_ctx.eval_capture = LTTNG_READ_ONCE(__event_notifier->eval_capture); \
1172 if (unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
1173 __event_prepare_interpreter_stack__##_name( \
1174 __stackvar.__interpreter_stack_data, \
1175 _locvar_args); \
1176 \
1177 __event_notifier->notification_send(__event_notifier, \
1178 __stackvar.__interpreter_stack_data, \
1179 &__lttng_probe_ctx, \
1180 &__notif_ctx); \
1181 break; \
1182 } \
1183 default: \
1184 WARN_ON_ONCE(1); \
1185 } \
1186 __post: \
1187 _code_post \
1188 barrier(); /* use before un-reserve. */ \
1189 this_cpu_ptr(&lttng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \
1190 return; \
1191 }
1192
1193 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
1194 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \
1195 _LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(void *__data, _proto), PARAMS(tp_locvar, _args), \
1196 PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
1197
1198 #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
1199 #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \
1200 _LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(void *__data), PARAMS(tp_locvar), PARAMS(_locvar), \
1201 PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post))
1202
1203 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1204
1205 #undef __get_dynamic_len
1206
1207 /*
1208 * Stage 7.1 of the trace events.
1209 *
1210 * Create event descriptions.
1211 */
1212
1213 /* Named field types must be defined in lttng-types.h */
1214
1215 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1216
1217 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1218 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1219 static const struct lttng_kernel_event_desc __event_desc___##_map = { \
1220 .event_name = #_map, \
1221 .event_kname = #_name, \
1222 .tp_class = &lttng_kernel__event_class___##_template, \
1223 .probe_desc = &TP_ID(__probe_desc___, TRACE_SYSTEM), \
1224 .owner = THIS_MODULE, \
1225 };
1226
1227 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1228 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1229 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1230
1231 #define TP_ID1(_token, _system) _token##_system
1232 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1233
1234 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1235
1236 #undef TP_ID1
1237 #undef TP_ID
1238
1239 /*
1240 * Stage 8 of the trace events.
1241 *
1242 * Create an array of event description pointers.
1243 */
1244
1245 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1246
1247 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
1248 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
1249 &__event_desc___##_map,
1250
1251 #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
1252 #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
1253 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
1254
1255 #define TP_ID1(_token, _system) _token##_system
1256 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1257
1258 static const struct lttng_kernel_event_desc * const TP_ID(__provider_event_desc___, TRACE_SYSTEM)[] = {
1259 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
1260 };
1261
1262 #undef TP_ID1
1263 #undef TP_ID
1264
1265 /*
1266 * Stage 9 of the trace events.
1267 *
1268 * Create a toplevel descriptor for the whole probe.
1269 */
1270
1271 #define TP_ID1(_token, _system) _token##_system
1272 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1273
1274 /* non-const because list head will be modified when registered. */
1275 static __used struct lttng_kernel_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
1276 .provider_name = __stringify(TRACE_SYSTEM),
1277 .event_desc = TP_ID(__provider_event_desc___, TRACE_SYSTEM),
1278 .nr_events = ARRAY_SIZE(TP_ID(__provider_event_desc___, TRACE_SYSTEM)),
1279 .head = { NULL, NULL },
1280 .lazy_init_head = { NULL, NULL },
1281 .lazy = 0,
1282 };
1283
1284 #undef TP_ID1
1285 #undef TP_ID
1286
1287 /*
1288 * Stage 10 of the trace events.
1289 *
1290 * Register/unregister probes at module load/unload.
1291 */
1292
1293 #include <lttng/events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
1294
1295 #define TP_ID1(_token, _system) _token##_system
1296 #define TP_ID(_token, _system) TP_ID1(_token, _system)
1297 #define module_init_eval1(_token, _system) module_init(_token##_system)
1298 #define module_init_eval(_token, _system) module_init_eval1(_token, _system)
1299 #define module_exit_eval1(_token, _system) module_exit(_token##_system)
1300 #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
1301
1302 #ifndef TP_MODULE_NOINIT
1303 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
1304 {
1305 wrapper_vmalloc_sync_mappings();
1306 return lttng_kernel_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
1307 }
1308
1309 static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
1310 {
1311 lttng_kernel_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
1312 }
1313
1314 #ifndef TP_MODULE_NOAUTOLOAD
1315 module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
1316 module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
1317 #endif
1318
1319 #endif
1320
1321 #undef module_init_eval
1322 #undef module_exit_eval
1323 #undef TP_ID1
1324 #undef TP_ID
1325
1326 #undef TP_PROTO
1327 #undef TP_ARGS
This page took 0.061122 seconds and 4 git commands to generate.