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