Commit | Line | Data |
---|---|---|
9f36eaed MJ |
1 | /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) |
2 | * | |
451e462f | 3 | * lttng-tracepoint-event-impl.h |
17baffe2 MD |
4 | * |
5 | * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org> | |
f127e61e | 6 | * Copyright (C) 2009-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
17baffe2 | 7 | */ |
f127e61e | 8 | |
d28686c1 | 9 | #include <linux/uaccess.h> |
d0dd2ecb | 10 | #include <linux/debugfs.h> |
f127e61e | 11 | #include <linux/rculist.h> |
43803cf2 | 12 | #include <asm/byteorder.h> |
bf1a9179 | 13 | #include <linux/swab.h> |
8d43abb7 MD |
14 | |
15 | #include <probes/lttng.h> | |
16 | #include <probes/lttng-types.h> | |
17 | #include <probes/lttng-probe-user.h> | |
ea53823c | 18 | #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */ |
8d43abb7 | 19 | #include <wrapper/ringbuffer/frontend_types.h> |
3c8ebbc8 | 20 | #include <wrapper/ringbuffer/backend.h> |
8d43abb7 | 21 | #include <wrapper/rcu.h> |
608416e1 | 22 | #include <wrapper/user_namespace.h> |
8d43abb7 MD |
23 | #include <lttng-events.h> |
24 | #include <lttng-tracer-core.h> | |
ec85ce1d | 25 | #include <lttng-tp-mempool.h> |
40652b65 | 26 | |
1d84e8e7 MD |
27 | #define __LTTNG_NULL_STRING "(null)" |
28 | ||
40652b65 | 29 | /* |
6db3d13b | 30 | * Macro declarations used for all stages. |
40652b65 MD |
31 | */ |
32 | ||
76e4f017 MD |
33 | /* |
34 | * LTTng name mapping macros. LTTng remaps some of the kernel events to | |
35 | * enforce name-spacing. | |
36 | */ | |
3bc29f0a | 37 | #undef LTTNG_TRACEPOINT_EVENT_MAP |
f127e61e | 38 | #define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \ |
3bc29f0a | 39 | LTTNG_TRACEPOINT_EVENT_CLASS(map, \ |
76e4f017 MD |
40 | PARAMS(proto), \ |
41 | PARAMS(args), \ | |
f127e61e | 42 | PARAMS(fields)) \ |
3bc29f0a | 43 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args)) |
76e4f017 | 44 | |
3bc29f0a | 45 | #undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS |
f127e61e | 46 | #define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \ |
3bc29f0a | 47 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \ |
f127e61e | 48 | PARAMS(fields)) \ |
3bc29f0a | 49 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map) |
76e4f017 | 50 | |
f127e61e | 51 | #undef LTTNG_TRACEPOINT_EVENT_CODE_MAP |
265822ae | 52 | #define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code_pre, fields, _code_post) \ |
f127e61e MD |
53 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \ |
54 | PARAMS(proto), \ | |
55 | PARAMS(args), \ | |
56 | PARAMS(_locvar), \ | |
265822ae MD |
57 | PARAMS(_code_pre), \ |
58 | PARAMS(fields), \ | |
59 | PARAMS(_code_post)) \ | |
f127e61e MD |
60 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args)) |
61 | ||
3bc29f0a | 62 | #undef LTTNG_TRACEPOINT_EVENT_CODE |
265822ae | 63 | #define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code_pre, fields, _code_post) \ |
f127e61e | 64 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \ |
7ca580f8 MD |
65 | PARAMS(proto), \ |
66 | PARAMS(args), \ | |
67 | PARAMS(_locvar), \ | |
265822ae MD |
68 | PARAMS(_code_pre), \ |
69 | PARAMS(fields), \ | |
70 | PARAMS(_code_post)) | |
fcf7fa33 | 71 | |
40652b65 | 72 | /* |
3bc29f0a MD |
73 | * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function |
74 | * handlers for events. That is, if all events have the same parameters | |
75 | * and just have distinct trace points. Each tracepoint can be defined | |
76 | * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the | |
77 | * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint. | |
40652b65 | 78 | * |
3bc29f0a MD |
79 | * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and |
80 | * template. | |
40652b65 | 81 | */ |
6db3d13b | 82 | |
3bc29f0a | 83 | #undef LTTNG_TRACEPOINT_EVENT |
f127e61e | 84 | #define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \ |
3bc29f0a MD |
85 | LTTNG_TRACEPOINT_EVENT_MAP(name, name, \ |
86 | PARAMS(proto), \ | |
87 | PARAMS(args), \ | |
f127e61e | 88 | PARAMS(fields)) |
40652b65 | 89 | |
3bc29f0a | 90 | #undef LTTNG_TRACEPOINT_EVENT_NOARGS |
f127e61e MD |
91 | #define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \ |
92 | LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields)) | |
76e4f017 | 93 | |
3bc29f0a MD |
94 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE |
95 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \ | |
96 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args)) | |
76e4f017 | 97 | |
3bc29f0a MD |
98 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS |
99 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \ | |
100 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name) | |
76e4f017 | 101 | |
3bc29f0a | 102 | #undef LTTNG_TRACEPOINT_EVENT_CLASS |
f127e61e | 103 | #define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \ |
3bc29f0a | 104 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \ |
265822ae | 105 | PARAMS(_fields), ) |
7ca580f8 | 106 | |
3bc29f0a | 107 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS |
f127e61e | 108 | #define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
265822ae | 109 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields), ) |
7ca580f8 MD |
110 | |
111 | ||
f62b389e | 112 | /* |
c099397a | 113 | * Stage 1 of the trace events. |
f62b389e MD |
114 | * |
115 | * Create dummy trace calls for each events, verifying that the LTTng module | |
3bc29f0a MD |
116 | * instrumentation headers match the kernel arguments. Will be optimized |
117 | * out by the compiler. | |
f62b389e MD |
118 | */ |
119 | ||
f127e61e | 120 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 | 121 | #include <probes/lttng-events-reset.h> |
f62b389e MD |
122 | |
123 | #undef TP_PROTO | |
f127e61e | 124 | #define TP_PROTO(...) __VA_ARGS__ |
f62b389e MD |
125 | |
126 | #undef TP_ARGS | |
f127e61e | 127 | #define TP_ARGS(...) __VA_ARGS__ |
f62b389e | 128 | |
3bc29f0a MD |
129 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP |
130 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
7eb827f2 | 131 | void trace_##_name(_proto); |
f62b389e | 132 | |
3bc29f0a MD |
133 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS |
134 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
cb1aa0c7 | 135 | void trace_##_name(void); |
f7bdf4db | 136 | |
f62b389e MD |
137 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
138 | ||
d0558de2 MD |
139 | /* |
140 | * Stage 1.1 of the trace events. | |
141 | * | |
142 | * Create dummy trace prototypes for each event class, and for each used | |
143 | * template. This will allow checking whether the prototypes from the | |
144 | * class and the instance using the class actually match. | |
145 | */ | |
146 | ||
ba012e22 | 147 | #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */ |
d0558de2 MD |
148 | |
149 | #undef TP_PROTO | |
150 | #define TP_PROTO(...) __VA_ARGS__ | |
151 | ||
152 | #undef TP_ARGS | |
153 | #define TP_ARGS(...) __VA_ARGS__ | |
154 | ||
155 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP | |
156 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
157 | void __event_template_proto___##_template(_proto); | |
158 | ||
159 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS | |
160 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
161 | void __event_template_proto___##_template(void); | |
162 | ||
163 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE | |
265822ae | 164 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
d0558de2 MD |
165 | void __event_template_proto___##_name(_proto); |
166 | ||
167 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS | |
265822ae | 168 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
d0558de2 MD |
169 | void __event_template_proto___##_name(void); |
170 | ||
171 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
172 | ||
141ddf28 MD |
173 | /* |
174 | * Stage 1.2 of tracepoint event generation | |
175 | * | |
176 | * Unfolding the enums | |
177 | */ | |
178 | #include <probes/lttng-events-reset.h> /* Reset all macros within TRACE_EVENT */ | |
179 | ||
180 | /* Enumeration entry (single value) */ | |
181 | #undef ctf_enum_value | |
182 | #define ctf_enum_value(_string, _value) \ | |
183 | { \ | |
184 | .start = { \ | |
185 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
186 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
187 | (long long) (_value) : (_value), \ | |
188 | }, \ | |
189 | .end = { \ | |
190 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
191 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
192 | (long long) (_value) : (_value), \ | |
193 | }, \ | |
194 | .string = (_string), \ | |
195 | }, | |
196 | ||
197 | /* Enumeration entry (range) */ | |
198 | #undef ctf_enum_range | |
199 | #define ctf_enum_range(_string, _range_start, _range_end) \ | |
200 | { \ | |
201 | .start = { \ | |
202 | .signedness = lttng_is_signed_type(__typeof__(_range_start)), \ | |
203 | .value = lttng_is_signed_type(__typeof__(_range_start)) ? \ | |
204 | (long long) (_range_start) : (_range_start), \ | |
205 | }, \ | |
206 | .end = { \ | |
207 | .signedness = lttng_is_signed_type(__typeof__(_range_end)), \ | |
208 | .value = lttng_is_signed_type(__typeof__(_range_end)) ? \ | |
209 | (long long) (_range_end) : (_range_end), \ | |
210 | }, \ | |
211 | .string = (_string), \ | |
212 | }, | |
213 | ||
08ad1061 PP |
214 | /* Enumeration entry (automatic value; follows the rules of CTF) */ |
215 | #undef ctf_enum_auto | |
216 | #define ctf_enum_auto(_string) \ | |
217 | { \ | |
218 | .start = { \ | |
219 | .signedness = -1, \ | |
220 | .value = -1, \ | |
221 | }, \ | |
222 | .end = { \ | |
223 | .signedness = -1, \ | |
224 | .value = -1, \ | |
225 | }, \ | |
226 | .string = (_string), \ | |
227 | .options = { \ | |
228 | .is_auto = 1, \ | |
229 | } \ | |
230 | }, | |
231 | ||
141ddf28 MD |
232 | #undef TP_ENUM_VALUES |
233 | #define TP_ENUM_VALUES(...) \ | |
234 | __VA_ARGS__ | |
235 | ||
236 | #undef LTTNG_TRACEPOINT_ENUM | |
237 | #define LTTNG_TRACEPOINT_ENUM(_name, _values) \ | |
238 | const struct lttng_enum_entry __enum_values__##_name[] = { \ | |
239 | _values \ | |
240 | }; | |
241 | ||
242 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
243 | ||
6db3d13b | 244 | /* |
c099397a | 245 | * Stage 2 of the trace events. |
6db3d13b MD |
246 | * |
247 | * Create event field type metadata section. | |
248 | * Each event produce an array of fields. | |
249 | */ | |
250 | ||
f127e61e | 251 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
252 | #include <probes/lttng-events-reset.h> |
253 | #include <probes/lttng-events-write.h> | |
254 | #include <probes/lttng-events-nowrite.h> | |
6db3d13b | 255 | |
f127e61e MD |
256 | #undef _ctf_integer_ext |
257 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ | |
c099397a MD |
258 | { \ |
259 | .name = #_item, \ | |
79282ffd | 260 | .type = __type_integer(_type, 0, 0, -1, _byte_order, _user, _base, none),\ |
f127e61e | 261 | .nowrite = _nowrite, \ |
c099397a | 262 | }, |
40652b65 | 263 | |
f127e61e | 264 | #undef _ctf_array_encoded |
3834b99f | 265 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ |
299338c8 | 266 | { \ |
c099397a MD |
267 | .name = #_item, \ |
268 | .type = \ | |
269 | { \ | |
299338c8 | 270 | .atype = atype_array, \ |
f127e61e | 271 | .u = \ |
c099397a | 272 | { \ |
f127e61e MD |
273 | .array = \ |
274 | { \ | |
79282ffd | 275 | .elem_type = __type_integer(_type, 0, 0, 0, _byte_order, _user, _base, _encoding), \ |
f127e61e MD |
276 | .length = _length, \ |
277 | } \ | |
278 | } \ | |
299338c8 | 279 | }, \ |
f127e61e | 280 | .nowrite = _nowrite, \ |
299338c8 | 281 | }, |
40652b65 | 282 | |
43803cf2 MD |
283 | #undef _ctf_array_bitfield |
284 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
285 | { \ | |
286 | .name = #_item, \ | |
287 | .type = \ | |
288 | { \ | |
3834b99f | 289 | .atype = atype_array_bitfield, \ |
43803cf2 MD |
290 | .u = \ |
291 | { \ | |
292 | .array = \ | |
293 | { \ | |
79282ffd | 294 | .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, _user, 10, none), \ |
43803cf2 MD |
295 | .length = (_length) * sizeof(_type) * CHAR_BIT, \ |
296 | .elem_alignment = lttng_alignof(_type), \ | |
297 | } \ | |
298 | } \ | |
299 | }, \ | |
300 | .nowrite = _nowrite, \ | |
43803cf2 MD |
301 | }, |
302 | ||
303 | ||
f127e61e MD |
304 | #undef _ctf_sequence_encoded |
305 | #define _ctf_sequence_encoded(_type, _item, _src, \ | |
306 | _length_type, _src_length, _encoding, \ | |
57ede728 | 307 | _byte_order, _base, _user, _nowrite) \ |
299338c8 | 308 | { \ |
c099397a MD |
309 | .name = #_item, \ |
310 | .type = \ | |
311 | { \ | |
299338c8 | 312 | .atype = atype_sequence, \ |
f127e61e | 313 | .u = \ |
c099397a | 314 | { \ |
f127e61e MD |
315 | .sequence = \ |
316 | { \ | |
79282ffd MD |
317 | .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 0, 10, none), \ |
318 | .elem_type = __type_integer(_type, 0, 0, -1, _byte_order, _user, _base, _encoding), \ | |
43803cf2 MD |
319 | }, \ |
320 | }, \ | |
321 | }, \ | |
322 | .nowrite = _nowrite, \ | |
43803cf2 MD |
323 | }, |
324 | ||
325 | #undef _ctf_sequence_bitfield | |
326 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
327 | _length_type, _src_length, \ | |
328 | _user, _nowrite) \ | |
329 | { \ | |
330 | .name = #_item, \ | |
331 | .type = \ | |
332 | { \ | |
3834b99f | 333 | .atype = atype_sequence_bitfield, \ |
43803cf2 MD |
334 | .u = \ |
335 | { \ | |
336 | .sequence = \ | |
337 | { \ | |
79282ffd MD |
338 | .length_type = __type_integer(_length_type, 0, 0, 0, __BYTE_ORDER, 0, 10, none), \ |
339 | .elem_type = __type_integer(_type, 1, 1, 0, __LITTLE_ENDIAN, _user, 10, none), \ | |
43803cf2 | 340 | .elem_alignment = lttng_alignof(_type), \ |
f127e61e | 341 | }, \ |
c099397a | 342 | }, \ |
299338c8 | 343 | }, \ |
f127e61e | 344 | .nowrite = _nowrite, \ |
299338c8 | 345 | }, |
40652b65 | 346 | |
f127e61e MD |
347 | #undef _ctf_string |
348 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
299338c8 | 349 | { \ |
c099397a MD |
350 | .name = #_item, \ |
351 | .type = \ | |
352 | { \ | |
299338c8 | 353 | .atype = atype_string, \ |
f127e61e MD |
354 | .u = \ |
355 | { \ | |
79282ffd | 356 | .basic = { .string = { .encoding = lttng_encode_UTF8, .user = (_user), } } \ |
f127e61e | 357 | }, \ |
299338c8 | 358 | }, \ |
f127e61e | 359 | .nowrite = _nowrite, \ |
299338c8 | 360 | }, |
1d12cebd | 361 | |
141ddf28 MD |
362 | #undef _ctf_enum |
363 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
364 | { \ | |
365 | .name = #_item, \ | |
366 | .type = { \ | |
367 | .atype = atype_enum, \ | |
368 | .u = { \ | |
369 | .basic = { \ | |
370 | .enumeration = { \ | |
371 | .desc = &__enum_##_name, \ | |
372 | .container_type = { \ | |
373 | .size = sizeof(_type) * CHAR_BIT, \ | |
374 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ | |
375 | .signedness = lttng_is_signed_type(_type), \ | |
376 | .reverse_byte_order = 0, \ | |
79282ffd | 377 | .user = (_user), \ |
141ddf28 MD |
378 | .base = 10, \ |
379 | .encoding = lttng_encode_none, \ | |
380 | }, \ | |
381 | }, \ | |
382 | }, \ | |
383 | }, \ | |
384 | }, \ | |
385 | .nowrite = _nowrite, \ | |
141ddf28 | 386 | }, |
f64dd4be MD |
387 | |
388 | #undef ctf_custom_field | |
389 | #define ctf_custom_field(_type, _item, _code) \ | |
390 | { \ | |
391 | .name = #_item, \ | |
392 | .type = { _type }, \ | |
393 | .nowrite = 0, \ | |
f64dd4be MD |
394 | }, |
395 | ||
396 | #undef ctf_custom_type | |
397 | #define ctf_custom_type(...) __VA_ARGS__ | |
398 | ||
f127e61e MD |
399 | #undef TP_FIELDS |
400 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
1d12cebd | 401 | |
3bc29f0a | 402 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 403 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
0d1d4002 | 404 | static const struct lttng_event_field __event_fields___##_name[] = { \ |
f127e61e | 405 | _fields \ |
299338c8 MD |
406 | }; |
407 | ||
3bc29f0a | 408 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae MD |
409 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
410 | LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, PARAMS(_fields), _code_post) | |
f7bdf4db | 411 | |
141ddf28 MD |
412 | #undef LTTNG_TRACEPOINT_ENUM |
413 | #define LTTNG_TRACEPOINT_ENUM(_name, _values) \ | |
414 | static const struct lttng_enum_desc __enum_##_name = { \ | |
415 | .name = #_name, \ | |
416 | .entries = __enum_values__##_name, \ | |
417 | .nr_entries = ARRAY_SIZE(__enum_values__##_name), \ | |
418 | }; | |
419 | ||
299338c8 MD |
420 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
421 | ||
19c57fbf | 422 | /* |
c099397a | 423 | * Stage 3 of the trace events. |
19c57fbf MD |
424 | * |
425 | * Create probe callback prototypes. | |
426 | */ | |
427 | ||
f127e61e | 428 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 | 429 | #include <probes/lttng-events-reset.h> |
19c57fbf MD |
430 | |
431 | #undef TP_PROTO | |
f127e61e | 432 | #define TP_PROTO(...) __VA_ARGS__ |
19c57fbf | 433 | |
3bc29f0a | 434 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 435 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
19c57fbf MD |
436 | static void __event_probe__##_name(void *__data, _proto); |
437 | ||
3bc29f0a | 438 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 439 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f7bdf4db MD |
440 | static void __event_probe__##_name(void *__data); |
441 | ||
19c57fbf MD |
442 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
443 | ||
f7bdf4db MD |
444 | /* |
445 | * Stage 4 of the trace events. | |
446 | * | |
40652b65 MD |
447 | * Create static inline function that calculates event size. |
448 | */ | |
449 | ||
f127e61e | 450 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
451 | #include <probes/lttng-events-reset.h> |
452 | #include <probes/lttng-events-write.h> | |
6db3d13b | 453 | |
f127e61e MD |
454 | #undef _ctf_integer_ext |
455 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ | |
a90917c3 | 456 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
0d1d4002 | 457 | __event_len += sizeof(_type); |
6db3d13b | 458 | |
f127e61e | 459 | #undef _ctf_array_encoded |
3834b99f | 460 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ |
a90917c3 | 461 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
0d1d4002 | 462 | __event_len += sizeof(_type) * (_length); |
6db3d13b | 463 | |
43803cf2 MD |
464 | #undef _ctf_array_bitfield |
465 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
3834b99f | 466 | _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite) |
43803cf2 | 467 | |
f127e61e MD |
468 | #undef _ctf_sequence_encoded |
469 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 470 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
471 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \ |
472 | __event_len += sizeof(_length_type); \ | |
a90917c3 | 473 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \ |
114667d5 MD |
474 | { \ |
475 | size_t __seqlen = (_src_length); \ | |
476 | \ | |
477 | if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \ | |
478 | goto error; \ | |
479 | barrier(); /* reserve before use. */ \ | |
480 | this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = __seqlen; \ | |
481 | __event_len += sizeof(_type) * __seqlen; \ | |
482 | } | |
6db3d13b | 483 | |
43803cf2 MD |
484 | #undef _ctf_sequence_bitfield |
485 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
486 | _length_type, _src_length, \ | |
487 | _user, _nowrite) \ | |
488 | _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \ | |
489 | none, __LITTLE_ENDIAN, 10, _user, _nowrite) | |
490 | ||
d0255731 | 491 | /* |
f127e61e | 492 | * ctf_user_string includes \0. If returns 0, it faulted, so we set size to |
786b8312 | 493 | * 1 (\0 only). |
d0255731 | 494 | */ |
f127e61e MD |
495 | #undef _ctf_string |
496 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
114667d5 MD |
497 | if (unlikely(++this_cpu_ptr(<tng_dynamic_len_stack)->offset >= LTTNG_DYNAMIC_LEN_STACK_SIZE)) \ |
498 | goto error; \ | |
499 | barrier(); /* reserve before use. */ \ | |
500 | if (_user) { \ | |
501 | __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \ | |
96d0248a | 502 | max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \ |
114667d5 MD |
503 | } else { \ |
504 | __event_len += this_cpu_ptr(<tng_dynamic_len_stack)->stack[this_cpu_ptr(<tng_dynamic_len_stack)->offset - 1] = \ | |
1d84e8e7 | 505 | strlen((_src) ? (_src) : __LTTNG_NULL_STRING) + 1; \ |
114667d5 | 506 | } |
c6e3f225 | 507 | |
141ddf28 MD |
508 | #undef _ctf_enum |
509 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
510 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
511 | ||
f64dd4be MD |
512 | #undef ctf_align |
513 | #define ctf_align(_type) \ | |
514 | __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); | |
515 | ||
516 | #undef ctf_custom_field | |
517 | #define ctf_custom_field(_type, _item, _code) \ | |
518 | { \ | |
519 | _code \ | |
520 | } | |
521 | ||
522 | #undef ctf_custom_code | |
523 | #define ctf_custom_code(...) __VA_ARGS__ | |
524 | ||
0d1d4002 | 525 | #undef TP_PROTO |
f127e61e | 526 | #define TP_PROTO(...) __VA_ARGS__ |
6db3d13b | 527 | |
f127e61e MD |
528 | #undef TP_FIELDS |
529 | #define TP_FIELDS(...) __VA_ARGS__ | |
6db3d13b | 530 | |
7ca580f8 MD |
531 | #undef TP_locvar |
532 | #define TP_locvar(...) __VA_ARGS__ | |
533 | ||
3bc29f0a | 534 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 535 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
114667d5 | 536 | static inline ssize_t __event_get_size__##_name(void *__tp_locvar, _proto) \ |
0d1d4002 MD |
537 | { \ |
538 | size_t __event_len = 0; \ | |
d3de7f14 | 539 | unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \ |
7ca580f8 | 540 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
d3de7f14 | 541 | \ |
f127e61e | 542 | _fields \ |
d3de7f14 | 543 | return __event_len; \ |
114667d5 MD |
544 | \ |
545 | error: \ | |
546 | __attribute__((unused)); \ | |
547 | return -1; \ | |
d3de7f14 MD |
548 | } |
549 | ||
3bc29f0a | 550 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 551 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
114667d5 | 552 | static inline ssize_t __event_get_size__##_name(void *__tp_locvar) \ |
d3de7f14 MD |
553 | { \ |
554 | size_t __event_len = 0; \ | |
555 | unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \ | |
7ca580f8 | 556 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
0d1d4002 | 557 | \ |
f127e61e | 558 | _fields \ |
0d1d4002 | 559 | return __event_len; \ |
114667d5 MD |
560 | \ |
561 | error: \ | |
562 | __attribute__((unused)); \ | |
563 | return -1; \ | |
6db3d13b | 564 | } |
40652b65 MD |
565 | |
566 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
567 | ||
f127e61e | 568 | |
40652b65 | 569 | /* |
f127e61e | 570 | * Stage 4.1 of tracepoint event generation. |
e763dbf5 | 571 | * |
f127e61e MD |
572 | * Create static inline function that layout the filter stack data. |
573 | * We make both write and nowrite data available to the filter. | |
e763dbf5 MD |
574 | */ |
575 | ||
f127e61e | 576 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
577 | #include <probes/lttng-events-reset.h> |
578 | #include <probes/lttng-events-write.h> | |
579 | #include <probes/lttng-events-nowrite.h> | |
f127e61e MD |
580 | |
581 | #undef _ctf_integer_ext_fetched | |
582 | #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
583 | if (lttng_is_signed_type(_type)) { \ | |
584 | int64_t __ctf_tmp_int64; \ | |
585 | switch (sizeof(_type)) { \ | |
586 | case 1: \ | |
587 | { \ | |
588 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ | |
589 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ | |
590 | break; \ | |
591 | } \ | |
592 | case 2: \ | |
593 | { \ | |
594 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
595 | if (_byte_order != __BYTE_ORDER) \ |
596 | __swab16s(&__tmp.v); \ | |
f127e61e MD |
597 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
598 | break; \ | |
599 | } \ | |
600 | case 4: \ | |
601 | { \ | |
602 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
603 | if (_byte_order != __BYTE_ORDER) \ |
604 | __swab32s(&__tmp.v); \ | |
f127e61e MD |
605 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
606 | break; \ | |
607 | } \ | |
608 | case 8: \ | |
609 | { \ | |
610 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
611 | if (_byte_order != __BYTE_ORDER) \ |
612 | __swab64s(&__tmp.v); \ | |
f127e61e MD |
613 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
614 | break; \ | |
615 | } \ | |
616 | default: \ | |
617 | BUG_ON(1); \ | |
618 | }; \ | |
619 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ | |
620 | } else { \ | |
621 | uint64_t __ctf_tmp_uint64; \ | |
622 | switch (sizeof(_type)) { \ | |
623 | case 1: \ | |
624 | { \ | |
625 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ | |
626 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ | |
627 | break; \ | |
628 | } \ | |
629 | case 2: \ | |
630 | { \ | |
631 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
632 | if (_byte_order != __BYTE_ORDER) \ |
633 | __swab16s(&__tmp.v); \ | |
f127e61e MD |
634 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
635 | break; \ | |
636 | } \ | |
637 | case 4: \ | |
638 | { \ | |
639 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
640 | if (_byte_order != __BYTE_ORDER) \ |
641 | __swab32s(&__tmp.v); \ | |
f127e61e MD |
642 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
643 | break; \ | |
644 | } \ | |
645 | case 8: \ | |
646 | { \ | |
647 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ | |
bf1a9179 MD |
648 | if (_byte_order != __BYTE_ORDER) \ |
649 | __swab64s(&__tmp.v); \ | |
f127e61e MD |
650 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
651 | break; \ | |
652 | } \ | |
653 | default: \ | |
654 | BUG_ON(1); \ | |
655 | }; \ | |
656 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ | |
657 | } \ | |
658 | __stack_data += sizeof(int64_t); | |
659 | ||
660 | #undef _ctf_integer_ext_isuser0 | |
661 | #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
662 | _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) | |
663 | ||
664 | #undef _ctf_integer_ext_isuser1 | |
665 | #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \ | |
3c8ebbc8 MD |
666 | { \ |
667 | union { \ | |
668 | char __array[sizeof(_user_src)]; \ | |
669 | __typeof__(_user_src) __v; \ | |
670 | } __tmp_fetch; \ | |
671 | if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \ | |
672 | &(_user_src), sizeof(_user_src))) \ | |
673 | memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \ | |
674 | _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \ | |
f127e61e | 675 | } |
e763dbf5 | 676 | |
f127e61e MD |
677 | #undef _ctf_integer_ext |
678 | #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \ | |
679 | _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite) | |
680 | ||
681 | #undef _ctf_array_encoded | |
3834b99f | 682 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
683 | { \ |
684 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
685 | const void *__ctf_tmp_ptr = (_src); \ | |
686 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ | |
687 | __stack_data += sizeof(unsigned long); \ | |
6b272cda MD |
688 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
689 | __stack_data += sizeof(void *); \ | |
f127e61e MD |
690 | } |
691 | ||
43803cf2 MD |
692 | #undef _ctf_array_bitfield |
693 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
3834b99f | 694 | _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite) |
43803cf2 | 695 | |
f127e61e MD |
696 | #undef _ctf_sequence_encoded |
697 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 698 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
699 | { \ |
700 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
701 | const void *__ctf_tmp_ptr = (_src); \ | |
702 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ | |
703 | __stack_data += sizeof(unsigned long); \ | |
6b272cda MD |
704 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
705 | __stack_data += sizeof(void *); \ | |
f127e61e MD |
706 | } |
707 | ||
43803cf2 MD |
708 | #undef _ctf_sequence_bitfield |
709 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
710 | _length_type, _src_length, \ | |
711 | _user, _nowrite) \ | |
712 | _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \ | |
713 | none, __LITTLE_ENDIAN, 10, _user, _nowrite) | |
714 | ||
f127e61e MD |
715 | #undef _ctf_string |
716 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
717 | { \ | |
1d84e8e7 MD |
718 | const void *__ctf_tmp_ptr = \ |
719 | ((_src) ? (_src) : __LTTNG_NULL_STRING); \ | |
6b272cda MD |
720 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
721 | __stack_data += sizeof(void *); \ | |
f127e61e | 722 | } |
c6e3f225 | 723 | |
141ddf28 MD |
724 | #undef _ctf_enum |
725 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
726 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
727 | ||
e763dbf5 | 728 | #undef TP_PROTO |
f127e61e | 729 | #define TP_PROTO(...) __VA_ARGS__ |
e763dbf5 | 730 | |
f127e61e MD |
731 | #undef TP_FIELDS |
732 | #define TP_FIELDS(...) __VA_ARGS__ | |
e763dbf5 | 733 | |
7ca580f8 MD |
734 | #undef TP_locvar |
735 | #define TP_locvar(...) __VA_ARGS__ | |
736 | ||
f127e61e | 737 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 738 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
739 | static inline \ |
740 | void __event_prepare_filter_stack__##_name(char *__stack_data, \ | |
741 | void *__tp_locvar) \ | |
e763dbf5 | 742 | { \ |
7ca580f8 MD |
743 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
744 | \ | |
f127e61e | 745 | _fields \ |
e763dbf5 MD |
746 | } |
747 | ||
f127e61e | 748 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 749 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
750 | static inline \ |
751 | void __event_prepare_filter_stack__##_name(char *__stack_data, \ | |
752 | void *__tp_locvar, _proto) \ | |
d3de7f14 | 753 | { \ |
7ca580f8 MD |
754 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ |
755 | \ | |
f127e61e | 756 | _fields \ |
d3de7f14 MD |
757 | } |
758 | ||
e763dbf5 MD |
759 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
760 | ||
e763dbf5 | 761 | /* |
f127e61e | 762 | * Stage 5 of the trace events. |
40652b65 | 763 | * |
f127e61e | 764 | * Create static inline function that calculates event payload alignment. |
3c4ffab9 MD |
765 | */ |
766 | ||
f127e61e | 767 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
768 | #include <probes/lttng-events-reset.h> |
769 | #include <probes/lttng-events-write.h> | |
3c4ffab9 | 770 | |
f127e61e MD |
771 | #undef _ctf_integer_ext |
772 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \ | |
773 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
3c4ffab9 | 774 | |
f127e61e | 775 | #undef _ctf_array_encoded |
3834b99f | 776 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e | 777 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); |
3c4ffab9 | 778 | |
43803cf2 MD |
779 | #undef _ctf_array_bitfield |
780 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
3834b99f | 781 | _ctf_array_encoded(_type, _item, _src, _length, none, __LITTLE_ENDIAN, 0, _user, _nowrite) |
43803cf2 | 782 | |
f127e61e MD |
783 | #undef _ctf_sequence_encoded |
784 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 785 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
786 | __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \ |
787 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
64c796d8 | 788 | |
43803cf2 MD |
789 | #undef _ctf_sequence_bitfield |
790 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
791 | _length_type, _src_length, \ | |
792 | _user, _nowrite) \ | |
793 | _ctf_sequence_encoded(_type, _item, _src, _length_type, _src_length, \ | |
794 | none, __LITTLE_ENDIAN, 10, _user, _nowrite) | |
795 | ||
f127e61e MD |
796 | #undef _ctf_string |
797 | #define _ctf_string(_item, _src, _user, _nowrite) | |
64c796d8 | 798 | |
141ddf28 MD |
799 | #undef _ctf_enum |
800 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
801 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
802 | ||
f64dd4be MD |
803 | #undef ctf_align |
804 | #define ctf_align(_type) \ | |
805 | __event_align = max_t(size_t, __event_align, lttng_alignof(_type)); | |
806 | ||
f127e61e MD |
807 | #undef TP_PROTO |
808 | #define TP_PROTO(...) __VA_ARGS__ | |
84da5206 | 809 | |
f127e61e MD |
810 | #undef TP_FIELDS |
811 | #define TP_FIELDS(...) __VA_ARGS__ | |
c6e3f225 | 812 | |
f127e61e MD |
813 | #undef TP_locvar |
814 | #define TP_locvar(...) __VA_ARGS__ | |
3c4ffab9 | 815 | |
f64dd4be MD |
816 | #undef ctf_custom_field |
817 | #define ctf_custom_field(_type, _item, _code) _code | |
818 | ||
819 | #undef ctf_custom_code | |
820 | #define ctf_custom_code(...) \ | |
821 | { \ | |
822 | __VA_ARGS__ \ | |
823 | } | |
824 | ||
f127e61e | 825 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 826 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
827 | static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \ |
828 | { \ | |
829 | size_t __event_align = 1; \ | |
830 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ | |
831 | \ | |
832 | _fields \ | |
833 | return __event_align; \ | |
834 | } | |
3c4ffab9 | 835 | |
3bc29f0a | 836 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 837 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f127e61e MD |
838 | static inline size_t __event_get_align__##_name(void *__tp_locvar) \ |
839 | { \ | |
840 | size_t __event_align = 1; \ | |
841 | struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \ | |
842 | \ | |
843 | _fields \ | |
844 | return __event_align; \ | |
845 | } | |
d3de7f14 | 846 | |
3c4ffab9 MD |
847 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
848 | ||
3c4ffab9 | 849 | /* |
f127e61e | 850 | * Stage 6 of tracepoint event generation. |
e763dbf5 | 851 | * |
f127e61e MD |
852 | * Create the probe function. This function calls event size calculation |
853 | * and writes event data into the buffer. | |
40652b65 MD |
854 | */ |
855 | ||
f127e61e | 856 | /* Reset all macros within TRACEPOINT_EVENT */ |
ba012e22 MD |
857 | #include <probes/lttng-events-reset.h> |
858 | #include <probes/lttng-events-write.h> | |
c6e3f225 | 859 | |
f127e61e MD |
860 | #undef _ctf_integer_ext_fetched |
861 | #define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
e763dbf5 | 862 | { \ |
f127e61e MD |
863 | _type __tmp = _src; \ |
864 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\ | |
aaa4004a | 865 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\ |
f127e61e MD |
866 | } |
867 | ||
868 | #undef _ctf_integer_ext_isuser0 | |
869 | #define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
870 | _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) | |
871 | ||
872 | #undef _ctf_integer_ext_isuser1 | |
873 | #define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \ | |
874 | { \ | |
3c8ebbc8 MD |
875 | union { \ |
876 | char __array[sizeof(_user_src)]; \ | |
877 | __typeof__(_user_src) __v; \ | |
878 | } __tmp_fetch; \ | |
879 | if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \ | |
880 | &(_user_src), sizeof(_user_src))) \ | |
881 | memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \ | |
882 | _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \ | |
f127e61e MD |
883 | } |
884 | ||
885 | #undef _ctf_integer_ext | |
886 | #define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \ | |
887 | _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite) | |
888 | ||
889 | #undef _ctf_array_encoded | |
3834b99f | 890 | #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _byte_order, _base, _user, _nowrite) \ |
f127e61e MD |
891 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
892 | if (_user) { \ | |
893 | __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \ | |
894 | } else { \ | |
895 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \ | |
896 | } | |
897 | ||
43803cf2 MD |
898 | #if (__BYTE_ORDER == __LITTLE_ENDIAN) |
899 | #undef _ctf_array_bitfield | |
900 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
901 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
902 | if (_user) { \ | |
903 | __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \ | |
904 | } else { \ | |
905 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \ | |
906 | } | |
907 | #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
908 | /* | |
909 | * For big endian, we need to byteswap into little endian. | |
910 | */ | |
911 | #undef _ctf_array_bitfield | |
912 | #define _ctf_array_bitfield(_type, _item, _src, _length, _user, _nowrite) \ | |
913 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
914 | { \ | |
915 | size_t _i; \ | |
916 | \ | |
917 | for (_i = 0; _i < (_length); _i++) { \ | |
918 | _type _tmp; \ | |
919 | \ | |
920 | if (_user) { \ | |
921 | if (get_user(_tmp, (_type *) _src + _i)) \ | |
922 | _tmp = 0; \ | |
923 | } else { \ | |
924 | _tmp = ((_type *) _src)[_i]; \ | |
925 | } \ | |
926 | switch (sizeof(_type)) { \ | |
927 | case 1: \ | |
928 | break; \ | |
929 | case 2: \ | |
930 | _tmp = cpu_to_le16(_tmp); \ | |
931 | break; \ | |
932 | case 4: \ | |
933 | _tmp = cpu_to_le32(_tmp); \ | |
934 | break; \ | |
935 | case 8: \ | |
936 | _tmp = cpu_to_le64(_tmp); \ | |
937 | break; \ | |
938 | default: \ | |
939 | BUG_ON(1); \ | |
940 | } \ | |
941 | __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \ | |
942 | } \ | |
943 | } | |
944 | #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
945 | ||
f127e61e MD |
946 | #undef _ctf_sequence_encoded |
947 | #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \ | |
57ede728 | 948 | _src_length, _encoding, _byte_order, _base, _user, _nowrite) \ |
84da5206 | 949 | { \ |
114667d5 | 950 | _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx]; \ |
f127e61e MD |
951 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
952 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
84da5206 | 953 | } \ |
f127e61e MD |
954 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ |
955 | if (_user) { \ | |
956 | __chan->ops->event_write_from_user(&__ctx, _src, \ | |
957 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
958 | } else { \ | |
959 | __chan->ops->event_write(&__ctx, _src, \ | |
960 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
961 | } | |
962 | ||
43803cf2 MD |
963 | #if (__BYTE_ORDER == __LITTLE_ENDIAN) |
964 | #undef _ctf_sequence_bitfield | |
965 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
966 | _length_type, _src_length, \ | |
967 | _user, _nowrite) \ | |
968 | { \ | |
114667d5 | 969 | _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \ |
43803cf2 MD |
970 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
971 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
972 | } \ | |
973 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
974 | if (_user) { \ | |
975 | __chan->ops->event_write_from_user(&__ctx, _src, \ | |
976 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
977 | } else { \ | |
978 | __chan->ops->event_write(&__ctx, _src, \ | |
979 | sizeof(_type) * __get_dynamic_len(dest)); \ | |
980 | } | |
981 | #else /* #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
982 | /* | |
983 | * For big endian, we need to byteswap into little endian. | |
984 | */ | |
985 | #undef _ctf_sequence_bitfield | |
986 | #define _ctf_sequence_bitfield(_type, _item, _src, \ | |
987 | _length_type, _src_length, \ | |
988 | _user, _nowrite) \ | |
989 | { \ | |
114667d5 | 990 | _length_type __tmpl = this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx] * sizeof(_type) * CHAR_BIT; \ |
43803cf2 MD |
991 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\ |
992 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\ | |
993 | } \ | |
994 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \ | |
995 | { \ | |
996 | size_t _i, _length; \ | |
997 | \ | |
998 | _length = __get_dynamic_len(dest); \ | |
999 | for (_i = 0; _i < _length; _i++) { \ | |
1000 | _type _tmp; \ | |
1001 | \ | |
1002 | if (_user) { \ | |
1003 | if (get_user(_tmp, (_type *) _src + _i)) \ | |
1004 | _tmp = 0; \ | |
1005 | } else { \ | |
1006 | _tmp = ((_type *) _src)[_i]; \ | |
1007 | } \ | |
1008 | switch (sizeof(_type)) { \ | |
1009 | case 1: \ | |
1010 | break; \ | |
1011 | case 2: \ | |
1012 | _tmp = cpu_to_le16(_tmp); \ | |
1013 | break; \ | |
1014 | case 4: \ | |
1015 | _tmp = cpu_to_le32(_tmp); \ | |
1016 | break; \ | |
1017 | case 8: \ | |
1018 | _tmp = cpu_to_le64(_tmp); \ | |
1019 | break; \ | |
1020 | default: \ | |
1021 | BUG_ON(1); \ | |
1022 | } \ | |
1023 | __chan->ops->event_write(&__ctx, &_tmp, sizeof(_type)); \ | |
1024 | } \ | |
1025 | } | |
1026 | #endif /* #else #if (__BYTE_ORDER == __LITTLE_ENDIAN) */ | |
1027 | ||
f127e61e MD |
1028 | #undef _ctf_string |
1029 | #define _ctf_string(_item, _src, _user, _nowrite) \ | |
f127e61e | 1030 | if (_user) { \ |
1d84e8e7 | 1031 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \ |
f127e61e MD |
1032 | __chan->ops->event_strcpy_from_user(&__ctx, _src, \ |
1033 | __get_dynamic_len(dest)); \ | |
1034 | } else { \ | |
1d84e8e7 MD |
1035 | const char *__ctf_tmp_string = \ |
1036 | ((_src) ? (_src) : __LTTNG_NULL_STRING); \ | |
1037 | lib_ring_buffer_align_ctx(&__ctx, \ | |
1038 | lttng_alignof(*__ctf_tmp_string)); \ | |
1039 | __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ | |
f127e61e MD |
1040 | __get_dynamic_len(dest)); \ |
1041 | } | |
e763dbf5 | 1042 | |
141ddf28 MD |
1043 | #undef _ctf_enum |
1044 | #define _ctf_enum(_name, _type, _item, _src, _user, _nowrite) \ | |
1045 | _ctf_integer_ext(_type, _item, _src, __BYTE_ORDER, 10, _user, _nowrite) | |
f64dd4be MD |
1046 | |
1047 | #undef ctf_align | |
1048 | #define ctf_align(_type) \ | |
1049 | lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); | |
1050 | ||
1051 | #undef ctf_custom_field | |
1052 | #define ctf_custom_field(_type, _item, _code) _code | |
1053 | ||
1054 | #undef ctf_custom_code | |
1055 | #define ctf_custom_code(...) \ | |
1056 | { \ | |
1057 | __VA_ARGS__ \ | |
1058 | } | |
1059 | ||
e763dbf5 | 1060 | /* Beware: this get len actually consumes the len value */ |
f127e61e | 1061 | #undef __get_dynamic_len |
114667d5 | 1062 | #define __get_dynamic_len(field) this_cpu_ptr(<tng_dynamic_len_stack)->stack[__dynamic_len_idx++] |
e763dbf5 MD |
1063 | |
1064 | #undef TP_PROTO | |
f127e61e | 1065 | #define TP_PROTO(...) __VA_ARGS__ |
e763dbf5 MD |
1066 | |
1067 | #undef TP_ARGS | |
f127e61e | 1068 | #define TP_ARGS(...) __VA_ARGS__ |
e763dbf5 | 1069 | |
f127e61e MD |
1070 | #undef TP_FIELDS |
1071 | #define TP_FIELDS(...) __VA_ARGS__ | |
e763dbf5 | 1072 | |
7ca580f8 MD |
1073 | #undef TP_locvar |
1074 | #define TP_locvar(...) __VA_ARGS__ | |
1075 | ||
265822ae MD |
1076 | #undef TP_code_pre |
1077 | #define TP_code_pre(...) __VA_ARGS__ | |
1078 | ||
1079 | #undef TP_code_post | |
1080 | #define TP_code_post(...) __VA_ARGS__ | |
7ca580f8 | 1081 | |
c337ddc2 MD |
1082 | /* |
1083 | * For state dump, check that "session" argument (mandatory) matches the | |
1084 | * session this event belongs to. Ensures that we write state dump data only | |
1085 | * into the started session, not into all sessions. | |
1086 | */ | |
1087 | #ifdef TP_SESSION_CHECK | |
1088 | #define _TP_SESSION_CHECK(session, csession) (session == csession) | |
1089 | #else /* TP_SESSION_CHECK */ | |
1090 | #define _TP_SESSION_CHECK(session, csession) 1 | |
1091 | #endif /* TP_SESSION_CHECK */ | |
1092 | ||
f9771d39 | 1093 | /* |
f127e61e MD |
1094 | * Using twice size for filter stack data to hold size and pointer for |
1095 | * each field (worse case). For integers, max size required is 64-bit. | |
1096 | * Same for double-precision floats. Those fit within | |
1097 | * 2*sizeof(unsigned long) for all supported architectures. | |
1098 | * Perform UNION (||) of filter runtime list. | |
f9771d39 | 1099 | */ |
3bc29f0a | 1100 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE |
265822ae | 1101 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
e763dbf5 MD |
1102 | static void __event_probe__##_name(void *__data, _proto) \ |
1103 | { \ | |
7ca580f8 | 1104 | struct probe_local_vars { _locvar }; \ |
a90917c3 | 1105 | struct lttng_event *__event = __data; \ |
79150a49 JD |
1106 | struct lttng_probe_ctx __lttng_probe_ctx = { \ |
1107 | .event = __event, \ | |
ccecf3fb | 1108 | .interruptible = !irqs_disabled(), \ |
79150a49 | 1109 | }; \ |
a90917c3 | 1110 | struct lttng_channel *__chan = __event->chan; \ |
e0130fab | 1111 | struct lttng_session *__session = __chan->session; \ |
aaa4004a | 1112 | struct lib_ring_buffer_ctx __ctx; \ |
114667d5 MD |
1113 | ssize_t __event_len; \ |
1114 | size_t __event_align; \ | |
ec0a7fba | 1115 | size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ |
f127e61e | 1116 | union { \ |
114667d5 | 1117 | size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ |
f127e61e MD |
1118 | char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ |
1119 | } __stackvar; \ | |
e763dbf5 | 1120 | int __ret; \ |
7ca580f8 MD |
1121 | struct probe_local_vars __tp_locvar; \ |
1122 | struct probe_local_vars *tp_locvar __attribute__((unused)) = \ | |
1123 | &__tp_locvar; \ | |
d1f652f8 | 1124 | struct lttng_id_tracker_rcu *__lf; \ |
e763dbf5 | 1125 | \ |
e0130fab | 1126 | if (!_TP_SESSION_CHECK(session, __session)) \ |
c337ddc2 | 1127 | return; \ |
57ccbfa6 | 1128 | if (unlikely(!LTTNG_READ_ONCE(__session->active))) \ |
e64957da | 1129 | return; \ |
57ccbfa6 | 1130 | if (unlikely(!LTTNG_READ_ONCE(__chan->enabled))) \ |
e64957da | 1131 | return; \ |
57ccbfa6 | 1132 | if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \ |
52fc2e1f | 1133 | return; \ |
d1f652f8 MD |
1134 | __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ |
1135 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ | |
1136 | return; \ | |
1137 | __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \ | |
1138 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \ | |
1139 | return; \ | |
1140 | __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ | |
1141 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1142 | lttng_current_uid()))) \ |
d1f652f8 MD |
1143 | return; \ |
1144 | __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ | |
1145 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1146 | lttng_current_vuid()))) \ |
d1f652f8 MD |
1147 | return; \ |
1148 | __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ | |
1149 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1150 | lttng_current_gid()))) \ |
d1f652f8 MD |
1151 | return; \ |
1152 | __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ | |
1153 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1154 | lttng_current_vgid()))) \ |
e0130fab | 1155 | return; \ |
114667d5 MD |
1156 | __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ |
1157 | __dynamic_len_idx = __orig_dynamic_len_offset; \ | |
265822ae | 1158 | _code_pre \ |
f127e61e MD |
1159 | if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \ |
1160 | struct lttng_bytecode_runtime *bc_runtime; \ | |
1161 | int __filter_record = __event->has_enablers_without_bytecode; \ | |
1162 | \ | |
1163 | __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ | |
1164 | tp_locvar, _args); \ | |
7a09dcb7 | 1165 | lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ |
79150a49 | 1166 | if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ |
f127e61e MD |
1167 | __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \ |
1168 | __filter_record = 1; \ | |
1169 | } \ | |
1170 | if (likely(!__filter_record)) \ | |
265822ae | 1171 | goto __post; \ |
f127e61e | 1172 | } \ |
114667d5 MD |
1173 | __event_len = __event_get_size__##_name(tp_locvar, _args); \ |
1174 | if (unlikely(__event_len < 0)) { \ | |
1175 | lib_ring_buffer_lost_event_too_big(__chan->chan); \ | |
1176 | goto __post; \ | |
1177 | } \ | |
7ca580f8 | 1178 | __event_align = __event_get_align__##_name(tp_locvar, _args); \ |
79150a49 | 1179 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ |
e763dbf5 | 1180 | __event_align, -1); \ |
aaa4004a | 1181 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ |
e763dbf5 | 1182 | if (__ret < 0) \ |
265822ae | 1183 | goto __post; \ |
f127e61e | 1184 | _fields \ |
aaa4004a | 1185 | __chan->ops->event_commit(&__ctx); \ |
265822ae MD |
1186 | __post: \ |
1187 | _code_post \ | |
114667d5 MD |
1188 | barrier(); /* use before un-reserve. */ \ |
1189 | this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \ | |
265822ae | 1190 | return; \ |
e763dbf5 MD |
1191 | } |
1192 | ||
3bc29f0a | 1193 | #undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS |
265822ae | 1194 | #define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code_pre, _fields, _code_post) \ |
f7bdf4db MD |
1195 | static void __event_probe__##_name(void *__data) \ |
1196 | { \ | |
7ca580f8 | 1197 | struct probe_local_vars { _locvar }; \ |
a90917c3 | 1198 | struct lttng_event *__event = __data; \ |
79150a49 JD |
1199 | struct lttng_probe_ctx __lttng_probe_ctx = { \ |
1200 | .event = __event, \ | |
ccecf3fb | 1201 | .interruptible = !irqs_disabled(), \ |
79150a49 | 1202 | }; \ |
a90917c3 | 1203 | struct lttng_channel *__chan = __event->chan; \ |
e0130fab | 1204 | struct lttng_session *__session = __chan->session; \ |
f7bdf4db | 1205 | struct lib_ring_buffer_ctx __ctx; \ |
114667d5 MD |
1206 | ssize_t __event_len; \ |
1207 | size_t __event_align; \ | |
ec0a7fba | 1208 | size_t __orig_dynamic_len_offset, __dynamic_len_idx __attribute__((unused)); \ |
f127e61e | 1209 | union { \ |
114667d5 | 1210 | size_t __dynamic_len_removed[ARRAY_SIZE(__event_fields___##_name)]; \ |
f127e61e MD |
1211 | char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \ |
1212 | } __stackvar; \ | |
f7bdf4db | 1213 | int __ret; \ |
7ca580f8 MD |
1214 | struct probe_local_vars __tp_locvar; \ |
1215 | struct probe_local_vars *tp_locvar __attribute__((unused)) = \ | |
1216 | &__tp_locvar; \ | |
d1f652f8 | 1217 | struct lttng_id_tracker_rcu *__lf; \ |
f7bdf4db | 1218 | \ |
e0130fab | 1219 | if (!_TP_SESSION_CHECK(session, __session)) \ |
c337ddc2 | 1220 | return; \ |
57ccbfa6 | 1221 | if (unlikely(!LTTNG_READ_ONCE(__session->active))) \ |
f7bdf4db | 1222 | return; \ |
57ccbfa6 | 1223 | if (unlikely(!LTTNG_READ_ONCE(__chan->enabled))) \ |
f7bdf4db | 1224 | return; \ |
57ccbfa6 | 1225 | if (unlikely(!LTTNG_READ_ONCE(__event->enabled))) \ |
f7bdf4db | 1226 | return; \ |
d1f652f8 MD |
1227 | __lf = lttng_rcu_dereference(__session->pid_tracker.p); \ |
1228 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid))) \ | |
1229 | return; \ | |
1230 | __lf = lttng_rcu_dereference(__session->vpid_tracker.p); \ | |
1231 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \ | |
1232 | return; \ | |
1233 | __lf = lttng_rcu_dereference(__session->uid_tracker.p); \ | |
1234 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1235 | lttng_current_uid()))) \ |
d1f652f8 MD |
1236 | return; \ |
1237 | __lf = lttng_rcu_dereference(__session->vuid_tracker.p); \ | |
1238 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1239 | lttng_current_vuid()))) \ |
d1f652f8 MD |
1240 | return; \ |
1241 | __lf = lttng_rcu_dereference(__session->gid_tracker.p); \ | |
1242 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1243 | lttng_current_gid()))) \ |
d1f652f8 MD |
1244 | return; \ |
1245 | __lf = lttng_rcu_dereference(__session->vgid_tracker.p); \ | |
1246 | if (__lf && likely(!lttng_id_tracker_lookup(__lf, \ | |
608416e1 | 1247 | lttng_current_vgid()))) \ |
e0130fab | 1248 | return; \ |
114667d5 MD |
1249 | __orig_dynamic_len_offset = this_cpu_ptr(<tng_dynamic_len_stack)->offset; \ |
1250 | __dynamic_len_idx = __orig_dynamic_len_offset; \ | |
265822ae | 1251 | _code_pre \ |
f127e61e MD |
1252 | if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \ |
1253 | struct lttng_bytecode_runtime *bc_runtime; \ | |
1254 | int __filter_record = __event->has_enablers_without_bytecode; \ | |
1255 | \ | |
1256 | __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \ | |
1257 | tp_locvar); \ | |
7a09dcb7 | 1258 | lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \ |
79150a49 | 1259 | if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \ |
f127e61e MD |
1260 | __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \ |
1261 | __filter_record = 1; \ | |
1262 | } \ | |
1263 | if (likely(!__filter_record)) \ | |
265822ae | 1264 | goto __post; \ |
f127e61e | 1265 | } \ |
114667d5 MD |
1266 | __event_len = __event_get_size__##_name(tp_locvar); \ |
1267 | if (unlikely(__event_len < 0)) { \ | |
1268 | lib_ring_buffer_lost_event_too_big(__chan->chan); \ | |
1269 | goto __post; \ | |
1270 | } \ | |
7ca580f8 | 1271 | __event_align = __event_get_align__##_name(tp_locvar); \ |
79150a49 | 1272 | lib_ring_buffer_ctx_init(&__ctx, __chan->chan, &__lttng_probe_ctx, __event_len, \ |
f7bdf4db MD |
1273 | __event_align, -1); \ |
1274 | __ret = __chan->ops->event_reserve(&__ctx, __event->id); \ | |
1275 | if (__ret < 0) \ | |
265822ae | 1276 | goto __post; \ |
f127e61e | 1277 | _fields \ |
f7bdf4db | 1278 | __chan->ops->event_commit(&__ctx); \ |
265822ae MD |
1279 | __post: \ |
1280 | _code_post \ | |
114667d5 MD |
1281 | barrier(); /* use before un-reserve. */ \ |
1282 | this_cpu_ptr(<tng_dynamic_len_stack)->offset = __orig_dynamic_len_offset; \ | |
265822ae | 1283 | return; \ |
f7bdf4db MD |
1284 | } |
1285 | ||
e763dbf5 MD |
1286 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
1287 | ||
f127e61e MD |
1288 | #undef __get_dynamic_len |
1289 | ||
1290 | /* | |
1291 | * Stage 7 of the trace events. | |
1292 | * | |
1293 | * Create event descriptions. | |
1294 | */ | |
1295 | ||
1296 | /* Named field types must be defined in lttng-types.h */ | |
1297 | ||
ba012e22 | 1298 | #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ |
f127e61e MD |
1299 | |
1300 | #ifndef TP_PROBE_CB | |
1301 | #define TP_PROBE_CB(_template) &__event_probe__##_template | |
1302 | #endif | |
1303 | ||
1304 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS | |
1305 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
1306 | static const struct lttng_event_desc __event_desc___##_map = { \ | |
1307 | .fields = __event_fields___##_template, \ | |
1308 | .name = #_map, \ | |
1309 | .kname = #_name, \ | |
1310 | .probe_callback = (void *) TP_PROBE_CB(_template), \ | |
1311 | .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ | |
1312 | .owner = THIS_MODULE, \ | |
1313 | }; | |
1314 | ||
1315 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP | |
1316 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
1317 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) | |
1318 | ||
1319 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) | |
1320 | ||
1321 | /* | |
1322 | * Stage 8 of the trace events. | |
1323 | * | |
1324 | * Create an array of event description pointers. | |
1325 | */ | |
1326 | ||
ba012e22 | 1327 | #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ |
f127e61e MD |
1328 | |
1329 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS | |
1330 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \ | |
1331 | &__event_desc___##_map, | |
1332 | ||
1333 | #undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP | |
1334 | #define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \ | |
1335 | LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) | |
1336 | ||
1337 | #define TP_ID1(_token, _system) _token##_system | |
1338 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
1339 | ||
ad5e2bb2 | 1340 | static const struct lttng_event_desc *TP_ID(__provider_event_desc___, TRACE_SYSTEM)[] = { |
be43a836 | 1341 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
f127e61e MD |
1342 | }; |
1343 | ||
1344 | #undef TP_ID1 | |
1345 | #undef TP_ID | |
1346 | ||
1347 | /* | |
1348 | * Stage 9 of the trace events. | |
1349 | * | |
1350 | * Create a toplevel descriptor for the whole probe. | |
1351 | */ | |
1352 | ||
1353 | #define TP_ID1(_token, _system) _token##_system | |
1354 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
1355 | ||
1356 | /* non-const because list head will be modified when registered. */ | |
1357 | static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { | |
1358 | .provider = __stringify(TRACE_SYSTEM), | |
ad5e2bb2 MD |
1359 | .event_desc = TP_ID(__provider_event_desc___, TRACE_SYSTEM), |
1360 | .nr_events = ARRAY_SIZE(TP_ID(__provider_event_desc___, TRACE_SYSTEM)), | |
f127e61e MD |
1361 | .head = { NULL, NULL }, |
1362 | .lazy_init_head = { NULL, NULL }, | |
1363 | .lazy = 0, | |
1364 | }; | |
1365 | ||
1366 | #undef TP_ID1 | |
1367 | #undef TP_ID | |
1368 | ||
3afe7aac | 1369 | /* |
c099397a | 1370 | * Stage 10 of the trace events. |
3afe7aac MD |
1371 | * |
1372 | * Register/unregister probes at module load/unload. | |
1373 | */ | |
1374 | ||
ba012e22 | 1375 | #include <probes/lttng-events-reset.h> /* Reset all macros within LTTNG_TRACEPOINT_EVENT */ |
3afe7aac MD |
1376 | |
1377 | #define TP_ID1(_token, _system) _token##_system | |
1378 | #define TP_ID(_token, _system) TP_ID1(_token, _system) | |
1379 | #define module_init_eval1(_token, _system) module_init(_token##_system) | |
1380 | #define module_init_eval(_token, _system) module_init_eval1(_token, _system) | |
1381 | #define module_exit_eval1(_token, _system) module_exit(_token##_system) | |
1382 | #define module_exit_eval(_token, _system) module_exit_eval1(_token, _system) | |
1383 | ||
2655f9ad | 1384 | #ifndef TP_MODULE_NOINIT |
3afe7aac MD |
1385 | static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void) |
1386 | { | |
ea53823c | 1387 | wrapper_vmalloc_sync_mappings(); |
a90917c3 | 1388 | return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
1389 | } |
1390 | ||
3afe7aac MD |
1391 | static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void) |
1392 | { | |
a90917c3 | 1393 | lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM)); |
3afe7aac MD |
1394 | } |
1395 | ||
2655f9ad MD |
1396 | #ifndef TP_MODULE_NOAUTOLOAD |
1397 | module_init_eval(__lttng_events_init__, TRACE_SYSTEM); | |
3afe7aac | 1398 | module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM); |
259b6cb3 | 1399 | #endif |
3afe7aac | 1400 | |
2655f9ad MD |
1401 | #endif |
1402 | ||
3afe7aac MD |
1403 | #undef module_init_eval |
1404 | #undef module_exit_eval | |
1405 | #undef TP_ID1 | |
1406 | #undef TP_ID | |
177b3692 MD |
1407 | |
1408 | #undef TP_PROTO | |
1409 | #undef TP_ARGS |