Remove unused tp_list_for_each_entry_rcu
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <urcu/compiler.h>
11 #include <urcu/rculist.h>
12 #include <lttng/ust-events.h>
13 #include <lttng/ust-ringbuffer-context.h>
14 #include <lttng/ust-arch.h>
15 #include <lttng/ust-compiler.h>
16 #include <lttng/tracepoint.h>
17 #include <lttng/ust-endian.h>
18 #include <lttng/ust-api-compat.h>
19 #include <string.h>
20
21 #define LTTNG_UST__NULL_STRING "(null)"
22
23 /*
24 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
25 * same arguments and having the same field layout.
26 *
27 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
28 * its own provider and name. It refers to a class (template).
29 *
30 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
31 * direct mapping from the instance to the class.
32 */
33
34 #undef LTTNG_UST_TRACEPOINT_EVENT
35 #define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
36 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
37 LTTNG_UST__TP_PARAMS(_args), \
38 LTTNG_UST__TP_PARAMS(_fields)) \
39 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
40 LTTNG_UST__TP_PARAMS(_args))
41
42 #undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
43 #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
44 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
45
46 #undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
47 #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
48 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, LTTNG_UST__TP_PARAMS(_args))
49
50 /* Helpers */
51 #define LTTNG_UST__TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
52
53 #define lttng_ust__tp_max_t(type, x, y) \
54 ({ \
55 type lttng_ust__max1 = (x); \
56 type lttng_ust__max2 = (y); \
57 lttng_ust__max1 > lttng_ust__max2 ? lttng_ust__max1: lttng_ust__max2; \
58 })
59
60 /*
61 * Stage 0 of tracepoint event generation.
62 *
63 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the
64 * LTTNG_UST_TRACEPOINT_PROVIDER by creating dummy callbacks.
65 */
66
67 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
68 #include <lttng/ust-tracepoint-event-reset.h>
69
70 static inline
71 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
72 lttng_ust_notrace;
73 static inline
74 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
75 {
76 }
77
78 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
79 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
80 lttng_ust_tracepoint_provider_mismatch_##_provider();
81
82 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
83 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
84 lttng_ust_tracepoint_provider_mismatch_##_provider();
85
86 static inline
87 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
88 lttng_ust_notrace;
89 static inline
90 void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
91 {
92 #include LTTNG_UST_TRACEPOINT_INCLUDE
93 }
94
95 /*
96 * Stage 0.1 of tracepoint event generation.
97 *
98 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
99 * tracepoint name length limit.
100 */
101
102 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
103 #include <lttng/ust-tracepoint-event-reset.h>
104
105 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
106 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
107 lttng_ust_tracepoint_validate_name_len(_provider, _name);
108
109 #include LTTNG_UST_TRACEPOINT_INCLUDE
110
111 /*
112 * Stage 0.2 of tracepoint event generation.
113 *
114 * Create dummy trace prototypes for each event class, and for each used
115 * template. This will allow checking whether the prototypes from the
116 * class and the instance using the class actually match.
117 */
118
119 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
120 #include <lttng/ust-tracepoint-event-reset.h>
121
122 #undef LTTNG_UST_TP_ARGS
123 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
124
125 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
126 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
127 void lttng_ust__event_template_proto___##_provider##___##_template(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
128
129 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
130 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
131 void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
132
133 #include LTTNG_UST_TRACEPOINT_INCLUDE
134
135 /*
136 * Stage 0.9 of tracepoint event generation
137 *
138 * Unfolding the enums
139 */
140 #include <lttng/ust-tracepoint-event-reset.h>
141
142 /* Enumeration entry (single value) */
143 #undef lttng_ust_field_enum_value
144 #define lttng_ust_field_enum_value(_string, _value) \
145 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
146 .struct_size = sizeof(struct lttng_ust_enum_entry), \
147 .start = { \
148 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
149 (long long) (_value) : (_value), \
150 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
151 }, \
152 .end = { \
153 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
154 (long long) (_value) : (_value), \
155 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
156 }, \
157 .string = (_string), \
158 }),
159
160 /* Enumeration entry (range) */
161 #undef lttng_ust_field_enum_range
162 #define lttng_ust_field_enum_range(_string, _range_start, _range_end) \
163 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
164 .struct_size = sizeof(struct lttng_ust_enum_entry), \
165 .start = { \
166 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
167 (long long) (_range_start) : (_range_start), \
168 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
169 }, \
170 .end = { \
171 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
172 (long long) (_range_end) : (_range_end), \
173 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
174 }, \
175 .string = (_string), \
176 }),
177
178 /* Enumeration entry (automatic value; follows the rules of CTF) */
179 #undef lttng_ust_field_enum_auto
180 #define lttng_ust_field_enum_auto(_string) \
181 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
182 .struct_size = sizeof(struct lttng_ust_enum_entry), \
183 .start = { \
184 .value = -1ULL, \
185 .signedness = 0, \
186 }, \
187 .end = { \
188 .value = -1ULL, \
189 .signedness = 0, \
190 }, \
191 .string = (_string), \
192 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
193 }),
194
195 #undef LTTNG_UST_TP_ENUM_VALUES
196 #define LTTNG_UST_TP_ENUM_VALUES(...) \
197 __VA_ARGS__
198
199 #if LTTNG_UST_COMPAT_API(0)
200 # undef TP_ENUM_VALUES
201 # define TP_ENUM_VALUES LTTNG_UST_TP_ENUM_VALUES
202 #endif /* #if LTTNG_UST_COMPAT_API(0) */
203
204 #undef LTTNG_UST_TRACEPOINT_ENUM
205 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
206 const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \
207 _values \
208 lttng_ust_field_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
209 };
210 #include LTTNG_UST_TRACEPOINT_INCLUDE
211
212 /*
213 * Stage 0.9.1
214 * Verifying array and sequence elements are of an integer type.
215 */
216
217 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
218 #include <lttng/ust-tracepoint-event-reset.h>
219 #include <lttng/ust-tracepoint-event-write.h>
220 #include <lttng/ust-tracepoint-event-nowrite.h>
221
222 #undef lttng_ust__field_array_encoded
223 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
224 _length, _encoding, _nowrite, \
225 _elem_type_base) \
226 lttng_ust_field_array_element_type_is_supported(_type, _item);
227
228 #undef lttng_ust__field_sequence_encoded
229 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
230 _length_type, _src_length, _encoding, _nowrite, \
231 _elem_type_base) \
232 lttng_ust_field_array_element_type_is_supported(_type, _item);
233
234 #undef LTTNG_UST_TP_FIELDS
235 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
236
237 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
238 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
239 _fields
240
241 #include LTTNG_UST_TRACEPOINT_INCLUDE
242
243 /*
244 * Stage 1 of tracepoint event generation.
245 *
246 * Create event field type metadata section.
247 * Each event produce an array of fields.
248 */
249
250 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
251 #include <lttng/ust-tracepoint-event-reset.h>
252 #include <lttng/ust-tracepoint-event-write.h>
253 #include <lttng/ust-tracepoint-event-nowrite.h>
254
255 #undef lttng_ust__field_integer_ext
256 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
257 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
258 .struct_size = sizeof(struct lttng_ust_event_field), \
259 .name = #_item, \
260 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
261 .nowrite = _nowrite, \
262 .nofilter = 0, \
263 }),
264
265 #undef lttng_ust__field_float
266 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
267 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
268 .struct_size = sizeof(struct lttng_ust_event_field), \
269 .name = #_item, \
270 .type = lttng_ust_type_float_define(_type), \
271 .nowrite = _nowrite, \
272 .nofilter = 0, \
273 }),
274
275 #undef lttng_ust__field_array_encoded
276 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
277 _length, _encoding, _nowrite, \
278 _elem_type_base) \
279 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
280 .struct_size = sizeof(struct lttng_ust_event_field), \
281 .name = #_item, \
282 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
283 .parent = { \
284 .type = lttng_ust_type_array, \
285 }, \
286 .struct_size = sizeof(struct lttng_ust_type_array), \
287 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
288 .length = _length, \
289 .alignment = 0, \
290 .encoding = lttng_ust_string_encoding_##_encoding, \
291 }), \
292 .nowrite = _nowrite, \
293 .nofilter = 0, \
294 }),
295
296 #undef lttng_ust__field_sequence_encoded
297 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
298 _length_type, _src_length, _encoding, _nowrite, \
299 _elem_type_base) \
300 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
301 .struct_size = sizeof(struct lttng_ust_event_field), \
302 .name = "_" #_item "_length", \
303 .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \
304 .nowrite = _nowrite, \
305 .nofilter = 1, \
306 }), \
307 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
308 .struct_size = sizeof(struct lttng_ust_event_field), \
309 .name = #_item, \
310 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \
311 .parent = { \
312 .type = lttng_ust_type_sequence, \
313 }, \
314 .struct_size = sizeof(struct lttng_ust_type_sequence), \
315 .length_name = "_" #_item "_length", \
316 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
317 .alignment = 0, \
318 .encoding = lttng_ust_string_encoding_##_encoding, \
319 }), \
320 .nowrite = _nowrite, \
321 .nofilter = 0, \
322 }),
323
324 #undef lttng_ust__field_string
325 #define lttng_ust__field_string(_item, _src, _nowrite) \
326 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
327 .struct_size = sizeof(struct lttng_ust_event_field), \
328 .name = #_item, \
329 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \
330 .parent = { \
331 .type = lttng_ust_type_string, \
332 }, \
333 .struct_size = sizeof(struct lttng_ust_type_string), \
334 .encoding = lttng_ust_string_encoding_UTF8, \
335 }), \
336 .nowrite = _nowrite, \
337 .nofilter = 0, \
338 }),
339
340 #undef lttng_ust__field_unused
341 #define lttng_ust__field_unused(_src)
342
343 #undef lttng_ust__field_enum
344 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
345 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
346 .struct_size = sizeof(struct lttng_ust_event_field), \
347 .name = #_item, \
348 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
349 .parent = { \
350 .type = lttng_ust_type_enum, \
351 }, \
352 .struct_size = sizeof(struct lttng_ust_type_enum), \
353 .desc = &__enum_##_provider##_##_name, \
354 .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \
355 }), \
356 .nowrite = _nowrite, \
357 .nofilter = 0, \
358 }),
359
360 #undef LTTNG_UST_TP_FIELDS
361 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
362
363 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
364 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
365 static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \
366 _fields \
367 lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
368 };
369
370 #undef LTTNG_UST_TRACEPOINT_ENUM
371 #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
372 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
373 .struct_size = sizeof(struct lttng_ust_enum_desc), \
374 .name = #_provider "_" #_name, \
375 .entries = __enum_values__##_provider##_##_name, \
376 .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
377 };
378
379 #include LTTNG_UST_TRACEPOINT_INCLUDE
380
381 /*
382 * Stage 2 of tracepoint event generation.
383 *
384 * Create probe callback prototypes.
385 */
386
387 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
388 #include <lttng/ust-tracepoint-event-reset.h>
389
390 #undef LTTNG_UST_TP_ARGS
391 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
392
393 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
394 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
395 static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
396
397 #include LTTNG_UST_TRACEPOINT_INCLUDE
398
399 /*
400 * Stage 3.0 of tracepoint event generation.
401 *
402 * Create static inline function that calculates event size.
403 */
404
405 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
406 #include <lttng/ust-tracepoint-event-reset.h>
407 #include <lttng/ust-tracepoint-event-write.h>
408
409 #undef lttng_ust__field_integer_ext
410 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
411 if (0) \
412 (void) (_src); /* Unused */ \
413 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
414 __event_len += sizeof(_type);
415
416 #undef lttng_ust__field_float
417 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
418 if (0) \
419 (void) (_src); /* Unused */ \
420 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
421 __event_len += sizeof(_type);
422
423 #undef lttng_ust__field_array_encoded
424 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
425 _nowrite, _elem_type_base) \
426 if (0) \
427 (void) (_src); /* Unused */ \
428 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
429 __event_len += sizeof(_type) * (_length);
430
431 #undef lttng_ust__field_sequence_encoded
432 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
433 _src_length, _encoding, _nowrite, _elem_type_base) \
434 if (0) \
435 (void) (_src); /* Unused */ \
436 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
437 __event_len += sizeof(_length_type); \
438 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
439 __dynamic_len[__dynamic_len_idx] = (_src_length); \
440 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
441 __dynamic_len_idx++;
442
443 #undef lttng_ust__field_string
444 #define lttng_ust__field_string(_item, _src, _nowrite) \
445 __event_len += __dynamic_len[__dynamic_len_idx++] = \
446 strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
447
448 #undef lttng_ust__field_unused
449 #define lttng_ust__field_unused(_src) \
450 if (0) \
451 (void) (_src); /* Unused */
452
453 #undef lttng_ust__field_enum
454 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
455 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
456
457 #undef LTTNG_UST_TP_ARGS
458 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
459
460 #undef LTTNG_UST_TP_FIELDS
461 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
462
463 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
464 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
465 static inline \
466 size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
467 lttng_ust_notrace; \
468 static inline \
469 size_t lttng_ust__event_get_size__##_provider##___##_name( \
470 size_t *__dynamic_len __attribute__((__unused__)), \
471 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
472 { \
473 size_t __event_len = 0; \
474 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
475 \
476 if (0) \
477 (void) __tp_data; /* don't warn if unused */ \
478 \
479 _fields \
480 return __event_len; \
481 }
482
483 #include LTTNG_UST_TRACEPOINT_INCLUDE
484
485 /*
486 * Stage 3.1 of tracepoint event generation.
487 *
488 * Create static inline function that layout the filter stack data.
489 * We make both write and nowrite data available to the filter.
490 */
491
492 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
493 #include <lttng/ust-tracepoint-event-reset.h>
494 #include <lttng/ust-tracepoint-event-write.h>
495 #include <lttng/ust-tracepoint-event-nowrite.h>
496
497 #undef lttng_ust__field_integer_ext
498 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
499 if (lttng_ust_is_signed_type(_type)) { \
500 int64_t __ctf_tmp_int64; \
501 switch (sizeof(_type)) { \
502 case 1: \
503 { \
504 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
505 __ctf_tmp_int64 = (int64_t) __tmp.v; \
506 break; \
507 } \
508 case 2: \
509 { \
510 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
511 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
512 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
513 __ctf_tmp_int64 = (int64_t) __tmp.v; \
514 break; \
515 } \
516 case 4: \
517 { \
518 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
519 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
520 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
521 __ctf_tmp_int64 = (int64_t) __tmp.v; \
522 break; \
523 } \
524 case 8: \
525 { \
526 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
527 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
528 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
529 __ctf_tmp_int64 = (int64_t) __tmp.v; \
530 break; \
531 } \
532 default: \
533 abort(); \
534 }; \
535 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
536 } else { \
537 uint64_t __ctf_tmp_uint64; \
538 switch (sizeof(_type)) { \
539 case 1: \
540 { \
541 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
542 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
543 break; \
544 } \
545 case 2: \
546 { \
547 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
548 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
549 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
550 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
551 break; \
552 } \
553 case 4: \
554 { \
555 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
556 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
557 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
558 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
559 break; \
560 } \
561 case 8: \
562 { \
563 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
564 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
565 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
566 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
567 break; \
568 } \
569 default: \
570 abort(); \
571 }; \
572 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
573 } \
574 __stack_data += sizeof(int64_t);
575
576 #undef lttng_ust__field_float
577 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
578 { \
579 double __ctf_tmp_double = (double) (_type) (_src); \
580 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
581 __stack_data += sizeof(double); \
582 }
583
584 #undef lttng_ust__field_array_encoded
585 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
586 _encoding, _nowrite, _elem_type_base) \
587 { \
588 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
589 const void *__ctf_tmp_ptr = (_src); \
590 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
591 __stack_data += sizeof(unsigned long); \
592 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
593 __stack_data += sizeof(void *); \
594 }
595
596 #undef lttng_ust__field_sequence_encoded
597 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
598 _src_length, _encoding, _nowrite, _elem_type_base) \
599 { \
600 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
601 const void *__ctf_tmp_ptr = (_src); \
602 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
603 __stack_data += sizeof(unsigned long); \
604 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
605 __stack_data += sizeof(void *); \
606 }
607
608 #undef lttng_ust__field_string
609 #define lttng_ust__field_string(_item, _src, _nowrite) \
610 { \
611 const void *__ctf_tmp_ptr = \
612 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
613 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
614 __stack_data += sizeof(void *); \
615 }
616
617 #undef lttng_ust__field_unused
618 #define lttng_ust__field_unused(_src) \
619 if (0) \
620 (void) (_src);
621
622 #undef lttng_ust__field_enum
623 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
624 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
625
626 #undef LTTNG_UST_TP_ARGS
627 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
628
629 #undef LTTNG_UST_TP_FIELDS
630 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
631
632 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
633 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
634 static inline \
635 void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
636 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
637 { \
638 if (0) { \
639 (void) __tp_data; /* don't warn if unused */ \
640 (void) __stack_data; /* don't warn if unused */ \
641 } \
642 \
643 _fields \
644 }
645
646 #include LTTNG_UST_TRACEPOINT_INCLUDE
647
648 /*
649 * Stage 4 of tracepoint event generation.
650 *
651 * Create static inline function that calculates event payload alignment.
652 */
653
654 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
655 #include <lttng/ust-tracepoint-event-reset.h>
656 #include <lttng/ust-tracepoint-event-write.h>
657
658 #undef lttng_ust__field_integer_ext
659 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
660 if (0) \
661 (void) (_src); /* Unused */ \
662 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
663
664 #undef lttng_ust__field_float
665 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
666 if (0) \
667 (void) (_src); /* Unused */ \
668 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
669
670 #undef lttng_ust__field_array_encoded
671 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
672 _encoding, _nowrite, _elem_type_base) \
673 if (0) \
674 (void) (_src); /* Unused */ \
675 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
676
677 #undef lttng_ust__field_sequence_encoded
678 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
679 _src_length, _encoding, _nowrite, _elem_type_base) \
680 if (0) \
681 (void) (_src); /* Unused */ \
682 if (0) \
683 (void) (_src_length); /* Unused */ \
684 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_length_type)); \
685 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
686
687 #undef lttng_ust__field_string
688 #define lttng_ust__field_string(_item, _src, _nowrite) \
689 if (0) \
690 (void) (_src); /* Unused */
691
692 #undef lttng_ust__field_unused
693 #define lttng_ust__field_unused(_src) \
694 if (0) \
695 (void) (_src); /* Unused */
696
697 #undef lttng_ust__field_enum
698 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
699 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
700
701 #undef LTTNG_UST_TP_ARGS
702 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
703
704 #undef LTTNG_UST_TP_FIELDS
705 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
706
707 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
708 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
709 static inline \
710 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
711 lttng_ust_notrace; \
712 static inline \
713 size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
714 { \
715 size_t lttng_ust__event_align = 1; \
716 _fields \
717 return lttng_ust__event_align; \
718 }
719
720 #include LTTNG_UST_TRACEPOINT_INCLUDE
721
722
723 /*
724 * Stage 5 of tracepoint event generation.
725 *
726 * Create the probe function. This function calls event size calculation
727 * and writes event data into the buffer.
728 */
729
730 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
731 #include <lttng/ust-tracepoint-event-reset.h>
732 #include <lttng/ust-tracepoint-event-write.h>
733
734 #undef lttng_ust__field_integer_ext
735 #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
736 { \
737 _type __tmp = (_src); \
738 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
739 }
740
741 #undef lttng_ust__field_float
742 #define lttng_ust__field_float(_type, _item, _src, _nowrite) \
743 { \
744 _type __tmp = (_src); \
745 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
746 }
747
748 #undef lttng_ust__field_array_encoded
749 #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
750 _encoding, _nowrite, _elem_type_base) \
751 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
752 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
753 else \
754 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
755
756 #undef lttng_ust__field_sequence_encoded
757 #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
758 _src_length, _encoding, _nowrite, _elem_type_base) \
759 { \
760 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
761 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
762 } \
763 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
764 __chan->ops->event_write(&__ctx, _src, \
765 sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
766 else \
767 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \
768
769 #undef lttng_ust__field_string
770 #define lttng_ust__field_string(_item, _src, _nowrite) \
771 { \
772 const char *__ctf_tmp_string = \
773 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
774 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
775 lttng_ust__get_dynamic_len(dest)); \
776 }
777
778 #undef lttng_ust__field_unused
779 #define lttng_ust__field_unused(_src)
780
781 #undef lttng_ust__field_enum
782 #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
783 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
784
785 /* Beware: this get len actually consumes the len value */
786 #undef lttng_ust__get_dynamic_len
787 #define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
788
789 #undef LTTNG_UST_TP_ARGS
790 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
791
792 #undef LTTNG_UST_TP_FIELDS
793 #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
794
795 /*
796 * For state dump, check that "session" argument (mandatory) matches the
797 * session this event belongs to. Ensures that we write state dump data only
798 * into the started session, not into all sessions.
799 */
800 #undef LTTNG_UST__TP_SESSION_CHECK
801 #ifdef LTTNG_UST_TP_SESSION_CHECK
802 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession)
803 #else /* TP_SESSION_CHECK */
804 #define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1
805 #endif /* TP_SESSION_CHECK */
806
807 /*
808 * Use of __builtin_return_address(0) sometimes seems to cause stack
809 * corruption on 32-bit PowerPC. Disable this feature on that
810 * architecture for now by always using the NULL value for the ip
811 * context.
812 */
813 #undef LTTNG_UST__TP_IP_PARAM
814
815 #ifdef LTTNG_UST_TP_IP_PARAM
816 #define LTTNG_UST__TP_IP_PARAM(x) (x)
817 #else /* TP_IP_PARAM */
818
819 #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
820 #define LTTNG_UST__TP_IP_PARAM(x) NULL
821 #else
822 #define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0)
823 #endif
824
825 #endif /* TP_IP_PARAM */
826
827 /*
828 * Using twice size for filter stack data to hold size and pointer for
829 * each field (worse case). For integers, max size required is 64-bit.
830 * Same for double-precision floats. Those fit within
831 * 2*sizeof(unsigned long) for all supported architectures.
832 * Perform UNION (||) of filter runtime list.
833 */
834 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
835 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
836 static \
837 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
838 lttng_ust_notrace; \
839 static \
840 void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
841 { \
842 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
843 size_t __dynamic_len_idx = 0; \
844 const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
845 union { \
846 size_t __dynamic_len[__num_fields]; \
847 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
848 } __stackvar; \
849 int __ret; \
850 bool __interpreter_stack_prepared = false; \
851 \
852 if (0) \
853 (void) __dynamic_len_idx; /* don't warn if unused */ \
854 switch (__event->type) { \
855 case LTTNG_UST_EVENT_TYPE_RECORDER: \
856 { \
857 struct lttng_ust_event_recorder *lttng_ust__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
858 struct lttng_ust_channel_buffer *__chan = lttng_ust__event_recorder->chan; \
859 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
860 \
861 if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
862 return; \
863 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
864 return; \
865 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
866 return; \
867 break; \
868 } \
869 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
870 break; \
871 } \
872 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
873 return; \
874 if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
875 return; \
876 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
877 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
878 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
879 __interpreter_stack_prepared = true; \
880 if (caa_likely(__event->run_filter(__event, \
881 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
882 return; \
883 } \
884 switch (__event->type) { \
885 case LTTNG_UST_EVENT_TYPE_RECORDER: \
886 { \
887 size_t __event_len, lttng_ust__event_align; \
888 struct lttng_ust_event_recorder *lttng_ust__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
889 struct lttng_ust_channel_buffer *__chan = lttng_ust__event_recorder->chan; \
890 struct lttng_ust_ring_buffer_ctx __ctx; \
891 \
892 __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
893 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
894 lttng_ust__event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
895 lttng_ust_ring_buffer_ctx_init(&__ctx, lttng_ust__event_recorder, __event_len, lttng_ust__event_align, \
896 LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM)); \
897 __ret = __chan->ops->event_reserve(&__ctx); \
898 if (__ret < 0) \
899 return; \
900 _fields \
901 __chan->ops->event_commit(&__ctx); \
902 break; \
903 } \
904 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
905 { \
906 struct lttng_ust_event_notifier *lttng_ust__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
907 struct lttng_ust_notification_ctx __notif_ctx; \
908 \
909 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
910 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(lttng_ust__event_notifier->eval_capture); \
911 \
912 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
913 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
914 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
915 \
916 lttng_ust__event_notifier->notification_send(lttng_ust__event_notifier, \
917 __stackvar.__interpreter_stack_data, \
918 &__notif_ctx); \
919 break; \
920 } \
921 } \
922 }
923
924 #include LTTNG_UST_TRACEPOINT_INCLUDE
925
926 #undef lttng_ust__get_dynamic_len
927
928 /*
929 * Stage 5.1 of tracepoint event generation.
930 *
931 * Create probe signature
932 */
933
934 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
935 #include <lttng/ust-tracepoint-event-reset.h>
936
937 #undef LTTNG_UST_TP_ARGS
938 #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
939
940 #define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__
941
942 #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
943 #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
944 static const char __tp_event_signature___##_provider##___##_name[] = \
945 LTTNG_UST__TP_EXTRACT_STRING2(_args);
946
947 #include LTTNG_UST_TRACEPOINT_INCLUDE
948
949 #undef LTTNG_UST__TP_EXTRACT_STRING2
950
951 /*
952 * Stage 6 of tracepoint event generation.
953 *
954 * Tracepoint loglevel mapping definition generation. We generate a
955 * symbol for each mapping for a provider/event to ensure at most a 1 to
956 * 1 mapping between events and loglevels. If the symbol is repeated,
957 * the compiler will complain.
958 */
959
960 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
961 #include <lttng/ust-tracepoint-event-reset.h>
962
963 /*
964 * Declare _loglevel___##__provider##___##__name as non-static, with
965 * hidden visibility for c++ handling of weakref. We do a weakref to the
966 * symbol in a later stage, which requires that the symbol is not
967 * mangled.
968 */
969 #ifdef __cplusplus
970 #define LTTNG_UST_TP_EXTERN_C extern "C"
971 #else
972 #define LTTNG_UST_TP_EXTERN_C
973 #endif
974
975 #undef LTTNG_UST_TRACEPOINT_LOGLEVEL
976 #define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
977 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
978 LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
979 __attribute__((visibility("hidden"))) = \
980 &_loglevel_value___##__provider##___##__name;
981
982 #include LTTNG_UST_TRACEPOINT_INCLUDE
983
984 #undef LTTNG_UST_TP_EXTERN_C
985
986 /*
987 * Stage 6.1 of tracepoint event generation.
988 *
989 * Tracepoint UML URI info.
990 */
991
992 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
993 #include <lttng/ust-tracepoint-event-reset.h>
994
995 /*
996 * Declare _model_emf_uri___##__provider##___##__name as non-static,
997 * with hidden visibility for c++ handling of weakref. We do a weakref
998 * to the symbol in a later stage, which requires that the symbol is not
999 * mangled.
1000 */
1001 #ifdef __cplusplus
1002 #define LTTNG_UST_TP_EXTERN_C extern "C"
1003 #else
1004 #define LTTNG_UST_TP_EXTERN_C
1005 #endif
1006
1007 #undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1008 #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
1009 LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
1010 __attribute__((visibility("hidden"))) = __uri; \
1011
1012 #include LTTNG_UST_TRACEPOINT_INCLUDE
1013
1014 #undef LTTNG_UST_TP_EXTERN_C
1015
1016 /*
1017 * Stage 7.0 of tracepoint event generation.
1018 *
1019 * Declare toplevel descriptor for the whole probe.
1020 * Unlike C, C++ does not allow tentative definitions. Therefore, we
1021 * need to explicitly declare the variable with "extern", using hidden
1022 * visibility to keep this symbol from being exported to the global
1023 * symbol table.
1024 */
1025
1026 extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)
1027 __attribute__((visibility("hidden")));
1028
1029 /*
1030 * Stage 7.1 of tracepoint event generation.
1031 *
1032 * Create events description structures. We use a weakref because
1033 * loglevels are optional. If not declared, the event will point to
1034 * a loglevel that contains NULL.
1035 *
1036 * C++ requires that const objects have a user-declared default
1037 * constructor. However, in both C++ and C, weakref cannot be
1038 * initialized because it causes the weakref attribute to be ignored.
1039 * Therefore, the loglevel and model_emf_uri pointers are not const
1040 * to ensure C++ compilers default-initialize them.
1041 */
1042
1043 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1044 #include <lttng/ust-tracepoint-event-reset.h>
1045
1046 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1047 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1048 static const int * \
1049 __ref_loglevel___##_provider##___##_name \
1050 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
1051 static const char * \
1052 __ref_model_emf_uri___##_provider##___##_name \
1053 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
1054 static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \
1055 .struct_size = sizeof(struct lttng_ust_event_desc), \
1056 .event_name = #_name, \
1057 .probe_desc = &lttng_ust__probe_desc___##_provider, \
1058 .probe_callback = (void (*)(void)) &lttng_ust__event_probe__##_provider##___##_template, \
1059 .fields = lttng_ust__event_fields___##_provider##___##_template, \
1060 .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_template) - 1, \
1061 .loglevel = &__ref_loglevel___##_provider##___##_name, \
1062 .signature = __tp_event_signature___##_provider##___##_template, \
1063 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
1064 };
1065
1066 #include LTTNG_UST_TRACEPOINT_INCLUDE
1067
1068 /*
1069 * Stage 7.2 of tracepoint event generation.
1070 *
1071 * Create array of events.
1072 */
1073
1074 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1075 #include <lttng/ust-tracepoint-event-reset.h>
1076
1077 #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1078 #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1079 &lttng_ust__event_desc___##_provider##_##_name,
1080
1081 static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = {
1082 #include LTTNG_UST_TRACEPOINT_INCLUDE
1083 NULL, /* Dummy, C99 forbids 0-len array. */
1084 };
1085
1086
1087 /*
1088 * Stage 8 of tracepoint event generation.
1089 *
1090 * Create a toplevel descriptor for the whole probe.
1091 */
1092
1093 const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) = {
1094 .struct_size = sizeof(struct lttng_ust_probe_desc),
1095 .provider_name = lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER),
1096 .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER),
1097 .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1,
1098 .major = LTTNG_UST_PROVIDER_MAJOR,
1099 .minor = LTTNG_UST_PROVIDER_MINOR,
1100 };
1101
1102 static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, LTTNG_UST_TRACEPOINT_PROVIDER);
1103 static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER);
1104
1105 /*
1106 * Stage 9 of tracepoint event generation.
1107 *
1108 * Register/unregister probes at module load/unload.
1109 *
1110 * Generate the constructor as an externally visible symbol for use when
1111 * linking the probe statically.
1112 *
1113 * Register refcount is protected by libc dynamic loader mutex.
1114 */
1115
1116 /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1117 #include <lttng/ust-tracepoint-event-reset.h>
1118 static void
1119 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1120 lttng_ust_notrace __attribute__((constructor));
1121 static void
1122 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1123 {
1124 struct lttng_ust_registered_probe *reg_probe;
1125
1126 if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___,
1127 LTTNG_UST_TRACEPOINT_PROVIDER)++) {
1128 return;
1129 }
1130 /*
1131 * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a
1132 * static inline function that ensures every probe PROVIDER
1133 * argument match the provider within which they appear. It
1134 * calls empty static inline functions, and therefore has no
1135 * runtime effect. However, if it detects an error, a linker
1136 * error will appear.
1137 */
1138 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)();
1139 assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER));
1140 reg_probe = lttng_ust_probe_register(&LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER));
1141 if (!reg_probe) {
1142 fprintf(stderr, "LTTng-UST: Error while registering tracepoint probe.\n");
1143 abort();
1144 }
1145 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = reg_probe;
1146 }
1147
1148 static void
1149 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1150 lttng_ust_notrace __attribute__((destructor));
1151 static void
1152 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1153 {
1154 if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___,
1155 LTTNG_UST_TRACEPOINT_PROVIDER)) {
1156 return;
1157 }
1158 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER));
1159 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = NULL;
1160 }
1161
1162 int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_, LTTNG_UST_TRACEPOINT_PROVIDER)
1163 __attribute__((visibility("default")));
This page took 0.092783 seconds and 4 git commands to generate.