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