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