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