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