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