Fix: Reevaluate LTTNG_UST_TRACEPOINT_DEFINE each time tracepoint.h is included
[lttng-ust.git] / include / lttng / ust-tracepoint-event.h
CommitLineData
1c324e59 1/*
e92f3e28 2 * Copyright (c) 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1c324e59 3 *
e92f3e28
MD
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
1c324e59 10 *
e92f3e28
MD
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
d2428e87
MD
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
1c324e59
MD
21 */
22
23#include <stdio.h>
7d381d6e 24#include <stdlib.h>
1c324e59 25#include <urcu/compiler.h>
f488575f 26#include <urcu/rculist.h>
1c324e59 27#include <lttng/ust-events.h>
1c324e59 28#include <lttng/ringbuffer-config.h>
a8909ba5 29#include <lttng/ust-compiler.h>
000b8662 30#include <lttng/tracepoint.h>
39ad74cf 31#include <byteswap.h>
44c72f10 32#include <string.h>
1c324e59 33
24a39530
PP
34#define __LTTNG_UST_NULL_STRING "(null)"
35
000b8662
MD
36#undef tp_list_for_each_entry_rcu
37#define tp_list_for_each_entry_rcu(pos, head, member) \
38 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
39 &pos->member != (head); \
40 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
41
1c324e59
MD
42/*
43 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
44 * same arguments and having the same field layout.
45 *
46 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
47 * its own provider and name. It refers to a class (template).
48 *
49 * TRACEPOINT_EVENT declared both a class and an instance and does a
50 * direct mapping from the instance to the class.
51 */
52
53#undef TRACEPOINT_EVENT
54#define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
5a6a15d8 55 _TRACEPOINT_EVENT_CLASS(_provider, _name, \
1c324e59
MD
56 _TP_PARAMS(_args), \
57 _TP_PARAMS(_fields)) \
5a6a15d8 58 _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
68755429 59 _TP_PARAMS(_args))
1c324e59 60
5a6a15d8
CB
61#undef TRACEPOINT_EVENT_CLASS
62#define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
63 _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields))
64
65#undef TRACEPOINT_EVENT_INSTANCE
66#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
67 _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args))
68
1c324e59
MD
69/* Helpers */
70#define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
71
72#define _tp_max_t(type, x, y) \
73 ({ \
74 type __max1 = (x); \
75 type __max2 = (y); \
76 __max1 > __max2 ? __max1: __max2; \
77 })
78
79/*
80 * Stage 0 of tracepoint event generation.
81 *
82 * Check that each TRACEPOINT_EVENT provider argument match the
83 * TRACEPOINT_PROVIDER by creating dummy callbacks.
84 */
85
86/* Reset all macros within TRACEPOINT_EVENT */
87#include <lttng/ust-tracepoint-event-reset.h>
88
7ce6b21d
PW
89static inline lttng_ust_notrace
90void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
1c324e59
MD
91static inline
92void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
93{
94}
95
5a6a15d8
CB
96#undef _TRACEPOINT_EVENT_CLASS
97#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
1c324e59
MD
98 __tracepoint_provider_mismatch_##_provider();
99
5a6a15d8
CB
100#undef _TRACEPOINT_EVENT_INSTANCE
101#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
1c324e59
MD
102 __tracepoint_provider_mismatch_##_provider();
103
7ce6b21d
PW
104static inline lttng_ust_notrace
105void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
e8bd1da7 106static inline
1c324e59
MD
107void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
108{
109#include TRACEPOINT_INCLUDE
110}
111
f56cd1d5
MD
112/*
113 * Stage 0.1 of tracepoint event generation.
114 *
115 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
116 * tracepoint name length limit.
117 */
118
119/* Reset all macros within TRACEPOINT_EVENT */
120#include <lttng/ust-tracepoint-event-reset.h>
121
5a6a15d8
CB
122#undef _TRACEPOINT_EVENT_INSTANCE
123#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
f56cd1d5
MD
124static const char \
125 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
126 __attribute__((unused)) = \
127 #_provider ":" #_name;
128
129#include TRACEPOINT_INCLUDE
130
c75c0422
MD
131/*
132 * Stage 0.2 of tracepoint event generation.
133 *
134 * Create dummy trace prototypes for each event class, and for each used
135 * template. This will allow checking whether the prototypes from the
136 * class and the instance using the class actually match.
137 */
138
139/* Reset all macros within TRACEPOINT_EVENT */
140#include <lttng/ust-tracepoint-event-reset.h>
141
142#undef TP_ARGS
143#define TP_ARGS(...) __VA_ARGS__
144
5a6a15d8
CB
145#undef _TRACEPOINT_EVENT_INSTANCE
146#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
c75c0422
MD
147void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args));
148
5a6a15d8
CB
149#undef _TRACEPOINT_EVENT_CLASS
150#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
c75c0422
MD
151void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
152
153#include TRACEPOINT_INCLUDE
154
c785c634
MD
155/*
156 * Stage 0.9 of tracepoint event generation
157 *
158 * Unfolding the enums
159 */
160#include <lttng/ust-tracepoint-event-reset.h>
161
162/* Enumeration entry (single value) */
163#undef ctf_enum_value
164#define ctf_enum_value(_string, _value) \
a6f80644
MD
165 { \
166 .start = { \
a6f80644
MD
167 .value = lttng_is_signed_type(__typeof__(_value)) ? \
168 (long long) (_value) : (_value), \
2c3f4c28 169 .signedness = lttng_is_signed_type(__typeof__(_value)), \
a6f80644
MD
170 }, \
171 .end = { \
a6f80644
MD
172 .value = lttng_is_signed_type(__typeof__(_value)) ? \
173 (long long) (_value) : (_value), \
2c3f4c28 174 .signedness = lttng_is_signed_type(__typeof__(_value)), \
a6f80644
MD
175 }, \
176 .string = (_string), \
177 },
c785c634
MD
178
179/* Enumeration entry (range) */
180#undef ctf_enum_range
181#define ctf_enum_range(_string, _range_start, _range_end) \
a6f80644
MD
182 { \
183 .start = { \
a6f80644
MD
184 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
185 (long long) (_range_start) : (_range_start), \
2c3f4c28 186 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
a6f80644
MD
187 }, \
188 .end = { \
a6f80644
MD
189 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
190 (long long) (_range_end) : (_range_end), \
2c3f4c28 191 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
a6f80644
MD
192 }, \
193 .string = (_string), \
194 },
c785c634 195
3e762260
PP
196/* Enumeration entry (automatic value; follows the rules of CTF) */
197#undef ctf_enum_auto
198#define ctf_enum_auto(_string) \
199 { \
200 .start = { \
201 .value = -1ULL, \
202 .signedness = 0, \
203 }, \
204 .end = { \
205 .value = -1ULL, \
206 .signedness = 0, \
207 }, \
208 .string = (_string), \
209 .u = { \
210 .extra = { \
211 .options = LTTNG_ENUM_ENTRY_OPTION_IS_AUTO, \
212 }, \
213 }, \
214 },
215
c785c634
MD
216#undef TP_ENUM_VALUES
217#define TP_ENUM_VALUES(...) \
218 __VA_ARGS__
219
220#undef TRACEPOINT_ENUM
221#define TRACEPOINT_ENUM(_provider, _name, _values) \
222 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
223 _values \
1c80c909 224 ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
c785c634
MD
225 };
226
227#include TRACEPOINT_INCLUDE
228
1c324e59
MD
229/*
230 * Stage 1 of tracepoint event generation.
231 *
232 * Create event field type metadata section.
233 * Each event produce an array of fields.
234 */
235
236/* Reset all macros within TRACEPOINT_EVENT */
237#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
238#include <lttng/ust-tracepoint-event-write.h>
239#include <lttng/ust-tracepoint-event-nowrite.h>
1c324e59 240
4774c8f3 241#undef _ctf_integer_ext
180901e6 242#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
243 { \
244 .name = #_item, \
245 .type = __type_integer(_type, _byte_order, _base, none),\
180901e6 246 .nowrite = _nowrite, \
1c324e59
MD
247 },
248
4774c8f3 249#undef _ctf_float
180901e6 250#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
251 { \
252 .name = #_item, \
253 .type = __type_float(_type), \
180901e6 254 .nowrite = _nowrite, \
1c324e59
MD
255 },
256
4774c8f3 257#undef _ctf_array_encoded
f3ec4cb5
MD
258#define _ctf_array_encoded(_type, _item, _src, _byte_order, \
259 _length, _encoding, _nowrite, \
260 _elem_type_base) \
1c324e59
MD
261 { \
262 .name = #_item, \
263 .type = \
264 { \
265 .atype = atype_array, \
46d52200 266 .u = \
1c324e59 267 { \
46d52200
ZT
268 .array = \
269 { \
f3ec4cb5 270 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
46d52200
ZT
271 .length = _length, \
272 } \
273 } \
1c324e59 274 }, \
180901e6 275 .nowrite = _nowrite, \
1c324e59
MD
276 },
277
4774c8f3 278#undef _ctf_sequence_encoded
48d660d1 279#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \
f968510a
PP
280 _length_type, _src_length, _encoding, _nowrite, \
281 _elem_type_base) \
1c324e59
MD
282 { \
283 .name = #_item, \
284 .type = \
285 { \
286 .atype = atype_sequence, \
46d52200 287 .u = \
1c324e59 288 { \
46d52200
ZT
289 .sequence = \
290 { \
291 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
48d660d1 292 .elem_type = __type_integer(_type, _byte_order, _elem_type_base, _encoding), \
46d52200 293 }, \
1c324e59
MD
294 }, \
295 }, \
180901e6 296 .nowrite = _nowrite, \
1c324e59
MD
297 },
298
4774c8f3 299#undef _ctf_string
180901e6 300#define _ctf_string(_item, _src, _nowrite) \
1c324e59
MD
301 { \
302 .name = #_item, \
303 .type = \
304 { \
305 .atype = atype_string, \
46d52200
ZT
306 .u = \
307 { \
308 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
309 }, \
1c324e59 310 }, \
180901e6 311 .nowrite = _nowrite, \
1c324e59
MD
312 },
313
c785c634
MD
314#undef _ctf_enum
315#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
316 { \
317 .name = #_item, \
318 .type = { \
319 .atype = atype_enum, \
320 .u = { \
321 .basic = { \
322 .enumeration = { \
323 .desc = &__enum_##_provider##_##_name, \
324 .container_type = { \
325 .size = sizeof(_type) * CHAR_BIT, \
326 .alignment = lttng_alignof(_type) * CHAR_BIT, \
327 .signedness = lttng_is_signed_type(_type), \
328 .reverse_byte_order = 0, \
329 .base = 10, \
330 .encoding = lttng_encode_none, \
331 }, \
332 }, \
333 }, \
334 }, \
335 }, \
336 .nowrite = _nowrite, \
337 },
338
1c324e59 339#undef TP_FIELDS
2eda209b 340#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1c324e59 341
5a6a15d8
CB
342#undef _TRACEPOINT_EVENT_CLASS
343#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
1c324e59
MD
344 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
345 _fields \
1c80c909 346 ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
1c324e59
MD
347 };
348
c785c634
MD
349#undef TRACEPOINT_ENUM
350#define TRACEPOINT_ENUM(_provider, _name, _values) \
351 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
352 .name = #_provider "_" #_name, \
353 .entries = __enum_values__##_provider##_##_name, \
1c80c909 354 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
c785c634
MD
355 };
356
1c324e59
MD
357#include TRACEPOINT_INCLUDE
358
359/*
360 * Stage 2 of tracepoint event generation.
361 *
362 * Create probe callback prototypes.
363 */
364
365/* Reset all macros within TRACEPOINT_EVENT */
366#include <lttng/ust-tracepoint-event-reset.h>
367
368#undef TP_ARGS
2eda209b 369#define TP_ARGS(...) __VA_ARGS__
1c324e59 370
5a6a15d8
CB
371#undef _TRACEPOINT_EVENT_CLASS
372#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
1c324e59
MD
373static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
374
375#include TRACEPOINT_INCLUDE
376
377/*
c785c634 378 * Stage 3.0 of tracepoint event generation.
1c324e59 379 *
1c324e59
MD
380 * Create static inline function that calculates event size.
381 */
382
383/* Reset all macros within TRACEPOINT_EVENT */
384#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 385#include <lttng/ust-tracepoint-event-write.h>
1c324e59 386
4774c8f3 387#undef _ctf_integer_ext
180901e6 388#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
389 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
390 __event_len += sizeof(_type);
391
4774c8f3 392#undef _ctf_float
180901e6 393#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
394 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
395 __event_len += sizeof(_type);
396
4774c8f3 397#undef _ctf_array_encoded
f3ec4cb5
MD
398#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
399 _nowrite, _elem_type_base) \
1c324e59
MD
400 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
401 __event_len += sizeof(_type) * (_length);
402
4774c8f3 403#undef _ctf_sequence_encoded
48d660d1 404#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 405 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
406 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
407 __event_len += sizeof(_length_type); \
408 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
409 __dynamic_len[__dynamic_len_idx] = (_src_length); \
410 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
411 __dynamic_len_idx++;
412
4774c8f3 413#undef _ctf_string
180901e6 414#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
415 __event_len += __dynamic_len[__dynamic_len_idx++] = \
416 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
1c324e59 417
c785c634
MD
418#undef _ctf_enum
419#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
420 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
421
1c324e59 422#undef TP_ARGS
2eda209b 423#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
424
425#undef TP_FIELDS
2eda209b 426#define TP_FIELDS(...) __VA_ARGS__
1c324e59 427
5a6a15d8
CB
428#undef _TRACEPOINT_EVENT_CLASS
429#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
430static inline lttng_ust_notrace \
431size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
432static inline \
433size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
1c324e59
MD
434{ \
435 size_t __event_len = 0; \
436 unsigned int __dynamic_len_idx = 0; \
437 \
438 if (0) \
439 (void) __dynamic_len_idx; /* don't warn if unused */ \
440 _fields \
441 return __event_len; \
442}
443
444#include TRACEPOINT_INCLUDE
445
1ddfd641
MD
446/*
447 * Stage 3.1 of tracepoint event generation.
448 *
449 * Create static inline function that layout the filter stack data.
4774c8f3 450 * We make both write and nowrite data available to the filter.
1ddfd641
MD
451 */
452
453/* Reset all macros within TRACEPOINT_EVENT */
454#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
455#include <lttng/ust-tracepoint-event-write.h>
456#include <lttng/ust-tracepoint-event-nowrite.h>
1ddfd641 457
4774c8f3 458#undef _ctf_integer_ext
180901e6 459#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
fa099471 460 if (lttng_is_signed_type(_type)) { \
3ebeea0d
MD
461 int64_t __ctf_tmp_int64; \
462 switch (sizeof(_type)) { \
463 case 1: \
464 { \
465 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
466 __ctf_tmp_int64 = (int64_t) __tmp.v; \
467 break; \
468 } \
469 case 2: \
470 { \
471 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
472 if (_byte_order != BYTE_ORDER) \
473 __tmp.v = bswap_16(__tmp.v); \
3ebeea0d
MD
474 __ctf_tmp_int64 = (int64_t) __tmp.v; \
475 break; \
476 } \
477 case 4: \
478 { \
479 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
480 if (_byte_order != BYTE_ORDER) \
481 __tmp.v = bswap_32(__tmp.v); \
3ebeea0d
MD
482 __ctf_tmp_int64 = (int64_t) __tmp.v; \
483 break; \
484 } \
485 case 8: \
486 { \
487 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
488 if (_byte_order != BYTE_ORDER) \
489 __tmp.v = bswap_64(__tmp.v); \
3ebeea0d
MD
490 __ctf_tmp_int64 = (int64_t) __tmp.v; \
491 break; \
492 } \
493 default: \
494 abort(); \
495 }; \
fa099471
MD
496 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
497 } else { \
3ebeea0d
MD
498 uint64_t __ctf_tmp_uint64; \
499 switch (sizeof(_type)) { \
500 case 1: \
501 { \
502 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
503 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
504 break; \
505 } \
506 case 2: \
507 { \
508 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
509 if (_byte_order != BYTE_ORDER) \
510 __tmp.v = bswap_16(__tmp.v); \
3ebeea0d
MD
511 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
512 break; \
513 } \
514 case 4: \
515 { \
516 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
517 if (_byte_order != BYTE_ORDER) \
518 __tmp.v = bswap_32(__tmp.v); \
3ebeea0d
MD
519 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
520 break; \
521 } \
522 case 8: \
523 { \
524 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
39ad74cf
MD
525 if (_byte_order != BYTE_ORDER) \
526 __tmp.v = bswap_64(__tmp.v); \
3ebeea0d
MD
527 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
528 break; \
529 } \
530 default: \
531 abort(); \
532 }; \
fa099471
MD
533 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
534 } \
1ddfd641
MD
535 __stack_data += sizeof(int64_t);
536
4774c8f3 537#undef _ctf_float
180901e6 538#define _ctf_float(_type, _item, _src, _nowrite) \
fa099471
MD
539 { \
540 double __ctf_tmp_double = (double) (_type) (_src); \
541 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
542 __stack_data += sizeof(double); \
543 }
1ddfd641 544
4774c8f3 545#undef _ctf_array_encoded
f3ec4cb5
MD
546#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
547 _encoding, _nowrite, _elem_type_base) \
fa099471
MD
548 { \
549 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
59034aab 550 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
551 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
552 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
553 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
554 __stack_data += sizeof(void *); \
fa099471 555 }
1ddfd641 556
4774c8f3 557#undef _ctf_sequence_encoded
48d660d1 558#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 559 _src_length, _encoding, _nowrite, _elem_type_base) \
fa099471
MD
560 { \
561 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
59034aab 562 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
563 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
564 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
565 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
566 __stack_data += sizeof(void *); \
fa099471 567 }
1ddfd641 568
4774c8f3 569#undef _ctf_string
180901e6 570#define _ctf_string(_item, _src, _nowrite) \
fa099471 571 { \
24a39530
PP
572 const void *__ctf_tmp_ptr = \
573 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
b1239ad6
MD
574 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
575 __stack_data += sizeof(void *); \
fa099471 576 }
1ddfd641 577
c785c634
MD
578#undef _ctf_enum
579#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
580 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
581
1ddfd641
MD
582#undef TP_ARGS
583#define TP_ARGS(...) __VA_ARGS__
584
585#undef TP_FIELDS
586#define TP_FIELDS(...) __VA_ARGS__
587
5a6a15d8
CB
588#undef _TRACEPOINT_EVENT_CLASS
589#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
1ddfd641
MD
590static inline \
591void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
592 _TP_ARGS_DATA_PROTO(_args)) \
593{ \
594 _fields \
595}
596
597#include TRACEPOINT_INCLUDE
598
1c324e59 599/*
df854e41 600 * Stage 4 of tracepoint event generation.
1c324e59
MD
601 *
602 * Create static inline function that calculates event payload alignment.
603 */
604
605/* Reset all macros within TRACEPOINT_EVENT */
606#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 607#include <lttng/ust-tracepoint-event-write.h>
1c324e59 608
4774c8f3 609#undef _ctf_integer_ext
180901e6 610#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
611 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
612
4774c8f3 613#undef _ctf_float
180901e6 614#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
615 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
616
4774c8f3 617#undef _ctf_array_encoded
f3ec4cb5
MD
618#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
619 _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
620 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
621
4774c8f3 622#undef _ctf_sequence_encoded
48d660d1 623#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 624 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
625 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
626 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
627
4774c8f3 628#undef _ctf_string
180901e6 629#define _ctf_string(_item, _src, _nowrite)
1c324e59 630
c785c634
MD
631#undef _ctf_enum
632#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
633 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
634
1c324e59 635#undef TP_ARGS
2eda209b 636#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
637
638#undef TP_FIELDS
2eda209b 639#define TP_FIELDS(...) __VA_ARGS__
1c324e59 640
5a6a15d8
CB
641#undef _TRACEPOINT_EVENT_CLASS
642#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
643static inline lttng_ust_notrace \
644size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
1c324e59
MD
645static inline \
646size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
647{ \
648 size_t __event_align = 1; \
649 _fields \
650 return __event_align; \
651}
652
653#include TRACEPOINT_INCLUDE
654
655
656/*
df854e41 657 * Stage 5 of tracepoint event generation.
1c324e59
MD
658 *
659 * Create the probe function. This function calls event size calculation
660 * and writes event data into the buffer.
661 */
662
663/* Reset all macros within TRACEPOINT_EVENT */
664#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 665#include <lttng/ust-tracepoint-event-write.h>
1c324e59 666
4774c8f3 667#undef _ctf_integer_ext
180901e6 668#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
669 { \
670 _type __tmp = (_src); \
671 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
672 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
673 }
674
4774c8f3 675#undef _ctf_float
180901e6 676#define _ctf_float(_type, _item, _src, _nowrite) \
1c324e59
MD
677 { \
678 _type __tmp = (_src); \
679 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
680 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
681 }
682
4774c8f3 683#undef _ctf_array_encoded
f3ec4cb5
MD
684#define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \
685 _encoding, _nowrite, _elem_type_base) \
1c324e59
MD
686 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
687 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
688
4774c8f3 689#undef _ctf_sequence_encoded
48d660d1 690#define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 691 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59 692 { \
d71b57b9 693 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
1c324e59
MD
694 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
695 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
696 } \
697 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
698 __chan->ops->event_write(&__ctx, _src, \
699 sizeof(_type) * __get_dynamic_len(dest));
700
a44c74d9
MD
701/*
702 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
703 * tracepoint provider ABI implements event_strcpy. This dynamic check
704 * can be removed when the tracepoint provider ABI moves to 2.
705 */
706#if (LTTNG_UST_PROVIDER_MAJOR > 1)
707#error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
708#endif
709
4774c8f3 710#undef _ctf_string
180901e6 711#define _ctf_string(_item, _src, _nowrite) \
24a39530
PP
712 { \
713 const char *__ctf_tmp_string = \
714 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
715 lib_ring_buffer_align_ctx(&__ctx, \
716 lttng_alignof(*__ctf_tmp_string)); \
717 if (__chan->ops->u.has_strcpy) \
718 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
719 __get_dynamic_len(dest)); \
720 else \
721 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
722 __get_dynamic_len(dest)); \
723 }
724
1c324e59 725
c785c634
MD
726#undef _ctf_enum
727#define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
728 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
729
1c324e59
MD
730/* Beware: this get len actually consumes the len value */
731#undef __get_dynamic_len
d71b57b9 732#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
1c324e59
MD
733
734#undef TP_ARGS
2eda209b 735#define TP_ARGS(...) __VA_ARGS__
1c324e59
MD
736
737#undef TP_FIELDS
2eda209b 738#define TP_FIELDS(...) __VA_ARGS__
1c324e59 739
95c25348
PW
740/*
741 * For state dump, check that "session" argument (mandatory) matches the
742 * session this event belongs to. Ensures that we write state dump data only
743 * into the started session, not into all sessions.
744 */
745#undef _TP_SESSION_CHECK
746#ifdef TP_SESSION_CHECK
747#define _TP_SESSION_CHECK(session, csession) (session == csession)
748#else /* TP_SESSION_CHECK */
749#define _TP_SESSION_CHECK(session, csession) 1
750#endif /* TP_SESSION_CHECK */
751
97904b41
MD
752/*
753 * Use of __builtin_return_address(0) sometimes seems to cause stack
754 * corruption on 32-bit PowerPC. Disable this feature on that
755 * architecture for now by always using the NULL value for the ip
756 * context.
757 */
5dadb547
MD
758#undef _TP_IP_PARAM
759#ifdef TP_IP_PARAM
e1d09f9e 760#define _TP_IP_PARAM(x) (x)
5dadb547 761#else /* TP_IP_PARAM */
97904b41
MD
762
763#if defined(__PPC__) && !defined(__PPC64__)
764#define _TP_IP_PARAM(x) NULL
765#else /* #if defined(__PPC__) && !defined(__PPC64__) */
e1d09f9e 766#define _TP_IP_PARAM(x) __builtin_return_address(0)
97904b41
MD
767#endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
768
5dadb547
MD
769#endif /* TP_IP_PARAM */
770
1ddfd641
MD
771/*
772 * Using twice size for filter stack data to hold size and pointer for
773 * each field (worse case). For integers, max size required is 64-bit.
774 * Same for double-precision floats. Those fit within
775 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 776 * Perform UNION (||) of filter runtime list.
1ddfd641 777 */
5a6a15d8
CB
778#undef _TRACEPOINT_EVENT_CLASS
779#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
a8909ba5
PW
780static lttng_ust_notrace \
781void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
782static \
783void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
1c324e59 784{ \
53569322 785 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
7dd08bec 786 struct lttng_channel *__chan = __event->chan; \
f280cb51 787 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
53569322 788 struct lttng_stack_ctx __lttng_ctx; \
1c324e59
MD
789 size_t __event_len, __event_align; \
790 size_t __dynamic_len_idx = 0; \
d71b57b9 791 union { \
1c80c909
MD
792 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1]; \
793 char __filter_stack_data[2 * sizeof(unsigned long) * (_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1)]; \
d71b57b9 794 } __stackvar; \
1c324e59
MD
795 int __ret; \
796 \
797 if (0) \
798 (void) __dynamic_len_idx; /* don't warn if unused */ \
95c25348
PW
799 if (!_TP_SESSION_CHECK(session, __chan->session)) \
800 return; \
1c324e59
MD
801 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
802 return; \
803 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
804 return; \
805 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
806 return; \
1b436e01
MD
807 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
808 return; \
e58095ef 809 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
f488575f 810 struct lttng_bytecode_runtime *bc_runtime; \
dcdeaff0 811 int __filter_record = __event->has_enablers_without_bytecode; \
f488575f 812 \
1ddfd641 813 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
f488575f 814 _TP_ARGS_DATA_VAR(_args)); \
000b8662 815 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
61ce3223 816 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
8a92ed2a
MD
817 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
818 __filter_record = 1; \
f488575f 819 } \
8a92ed2a 820 if (caa_likely(!__filter_record)) \
61ce3223 821 return; \
1ddfd641
MD
822 } \
823 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
1c324e59
MD
824 _TP_ARGS_DATA_VAR(_args)); \
825 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
53569322
MD
826 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
827 __lttng_ctx.event = __event; \
828 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
829 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
1c324e59 830 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
53569322 831 __event_align, -1, __chan->handle, &__lttng_ctx); \
e1d09f9e 832 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
1c324e59
MD
833 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
834 if (__ret < 0) \
835 return; \
836 _fields \
837 __chan->ops->event_commit(&__ctx); \
838}
839
840#include TRACEPOINT_INCLUDE
841
842#undef __get_dynamic_len
843
68755429
MD
844/*
845 * Stage 5.1 of tracepoint event generation.
846 *
847 * Create probe signature
848 */
849
850/* Reset all macros within TRACEPOINT_EVENT */
851#include <lttng/ust-tracepoint-event-reset.h>
852
853#undef TP_ARGS
2eda209b 854#define TP_ARGS(...) __VA_ARGS__
9eb06182
MD
855
856#define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429 857
5a6a15d8
CB
858#undef _TRACEPOINT_EVENT_CLASS
859#define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
ff82b7c1 860static const char __tp_event_signature___##_provider##___##_name[] = \
9eb06182 861 _TP_EXTRACT_STRING2(_args);
68755429
MD
862
863#include TRACEPOINT_INCLUDE
864
9eb06182
MD
865#undef _TP_EXTRACT_STRING2
866
05ceaafd 867/*
882a56d7 868 * Stage 6 of tracepoint event generation.
1c324e59 869 *
df854e41
MD
870 * Tracepoint loglevel mapping definition generation. We generate a
871 * symbol for each mapping for a provider/event to ensure at most a 1 to
872 * 1 mapping between events and loglevels. If the symbol is repeated,
873 * the compiler will complain.
05ceaafd
MD
874 */
875
876/* Reset all macros within TRACEPOINT_EVENT */
877#include <lttng/ust-tracepoint-event-reset.h>
878
4ea4f80e
MD
879/*
880 * Declare _loglevel___##__provider##___##__name as non-static, with
881 * hidden visibility for c++ handling of weakref. We do a weakref to the
882 * symbol in a later stage, which requires that the symbol is not
883 * mangled.
884 */
885#ifdef __cplusplus
886#define LTTNG_TP_EXTERN_C extern "C"
887#else
888#define LTTNG_TP_EXTERN_C
889#endif
890
05ceaafd 891#undef TRACEPOINT_LOGLEVEL
457a6b58
MD
892#define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
893static const int _loglevel_value___##__provider##___##__name = __loglevel; \
4ea4f80e
MD
894LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \
895 __attribute__((visibility("hidden"))) = \
457a6b58 896 &_loglevel_value___##__provider##___##__name;
df854e41
MD
897
898#include TRACEPOINT_INCLUDE
899
4ea4f80e 900#undef LTTNG_TP_EXTERN_C
4ea4f80e 901
6ddc916d
MD
902/*
903 * Stage 6.1 of tracepoint event generation.
904 *
905 * Tracepoint UML URI info.
906 */
907
908/* Reset all macros within TRACEPOINT_EVENT */
909#include <lttng/ust-tracepoint-event-reset.h>
910
4ea4f80e
MD
911/*
912 * Declare _model_emf_uri___##__provider##___##__name as non-static,
913 * with hidden visibility for c++ handling of weakref. We do a weakref
914 * to the symbol in a later stage, which requires that the symbol is not
915 * mangled.
916 */
917#ifdef __cplusplus
918#define LTTNG_TP_EXTERN_C extern "C"
919#else
920#define LTTNG_TP_EXTERN_C
921#endif
922
6ddc916d
MD
923#undef TRACEPOINT_MODEL_EMF_URI
924#define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
4ea4f80e 925LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \
082802f9 926 __attribute__((visibility("hidden"))) = __uri; \
6ddc916d
MD
927
928#include TRACEPOINT_INCLUDE
929
4ea4f80e 930#undef LTTNG_TP_EXTERN_C
4ea4f80e 931
df854e41 932/*
882a56d7 933 * Stage 7.1 of tracepoint event generation.
df854e41
MD
934 *
935 * Create events description structures. We use a weakref because
936 * loglevels are optional. If not declared, the event will point to the
937 * a loglevel that contains NULL.
938 */
939
940/* Reset all macros within TRACEPOINT_EVENT */
941#include <lttng/ust-tracepoint-event-reset.h>
942
5a6a15d8
CB
943#undef _TRACEPOINT_EVENT_INSTANCE
944#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
945static const int * \
946 __ref_loglevel___##_provider##___##_name \
947 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
948static const char * \
949 __ref_model_emf_uri___##_provider##___##_name \
950 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
ff82b7c1 951static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
df854e41 952 .name = #_provider ":" #_name, \
fbdeb5ec 953 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
46d52200
ZT
954 .ctx = NULL, \
955 .fields = __event_fields___##_provider##___##_template, \
1c80c909 956 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \
882a56d7 957 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 958 .signature = __tp_event_signature___##_provider##___##_template, \
c785c634
MD
959 .u = { \
960 .ext = { \
961 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
962 }, \
963 }, \
df854e41
MD
964};
965
966#include TRACEPOINT_INCLUDE
05ceaafd 967
df854e41 968/*
882a56d7 969 * Stage 7.2 of tracepoint event generation.
df854e41
MD
970 *
971 * Create array of events.
972 */
973
974/* Reset all macros within TRACEPOINT_EVENT */
975#include <lttng/ust-tracepoint-event-reset.h>
976
5a6a15d8
CB
977#undef _TRACEPOINT_EVENT_INSTANCE
978#define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
df854e41
MD
979 &__event_desc___##_provider##_##_name,
980
981static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
05ceaafd 982#include TRACEPOINT_INCLUDE
1c80c909 983 NULL, /* Dummy, C99 forbids 0-len array. */
05ceaafd
MD
984};
985
df854e41 986
05ceaafd 987/*
882a56d7 988 * Stage 8 of tracepoint event generation.
05ceaafd
MD
989 *
990 * Create a toplevel descriptor for the whole probe.
991 */
992
993/* non-const because list head will be modified when registered. */
994static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
df854e41 995 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
05ceaafd 996 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
1c80c909 997 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1,
46d52200
ZT
998 .head = { NULL, NULL },
999 .lazy_init_head = { NULL, NULL },
1000 .lazy = 0,
71d31690
MD
1001 .major = LTTNG_UST_PROVIDER_MAJOR,
1002 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
1003};
1004
f0cc794d
MD
1005static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
1006
05ceaafd 1007/*
882a56d7 1008 * Stage 9 of tracepoint event generation.
05ceaafd 1009 *
1c324e59 1010 * Register/unregister probes at module load/unload.
628e1d81
MD
1011 *
1012 * Generate the constructor as an externally visible symbol for use when
1013 * linking the probe statically.
f0cc794d
MD
1014 *
1015 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
1016 */
1017
1018/* Reset all macros within TRACEPOINT_EVENT */
1019#include <lttng/ust-tracepoint-event-reset.h>
a8fafb67 1020static void lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO)))
a8909ba5
PW
1021_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
1022static void
1c324e59
MD
1023_TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
1024{
1025 int ret;
1026
f0cc794d
MD
1027 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
1028 TRACEPOINT_PROVIDER)++) {
1029 return;
1030 }
e8bd1da7
MD
1031 /*
1032 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
1033 * static inline function that ensures every probe PROVIDER
1034 * argument match the provider within which they appear. It
1035 * calls empty static inline functions, and therefore has no
1036 * runtime effect. However, if it detects an error, a linker
1037 * error will appear.
1038 */
1039 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
7dd08bec 1040 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
7d381d6e 1041 if (ret) {
0fdd0b89 1042 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret);
7d381d6e
MD
1043 abort();
1044 }
1c324e59
MD
1045}
1046
a8fafb67 1047static void lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO)))
a8909ba5
PW
1048_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
1049static void
1c324e59
MD
1050_TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
1051{
f0cc794d
MD
1052 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
1053 TRACEPOINT_PROVIDER)) {
1054 return;
1055 }
7dd08bec 1056 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
1c324e59 1057}
628e1d81 1058
d5ed6edd
MD
1059int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER)
1060__attribute__((visibility("default")));
This page took 0.121388 seconds and 4 git commands to generate.