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