Extract input/output arguments from accept and connect syscalls
[lttng-modules.git] / probes / lttng-events.h
CommitLineData
17baffe2
MD
1/*
2 * lttng-events.h
3 *
4 * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
886d51a3 5 * Copyright (C) 2009-2012 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 */
d28686c1 21#include <linux/uaccess.h>
d0dd2ecb 22#include <linux/debugfs.h>
c0edae1d
MD
23#include "lttng.h"
24#include "lttng-types.h"
7b8ea3a5 25#include "lttng-probe-user.h"
b13f3ebe 26#include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
f3bc08c5 27#include "../wrapper/ringbuffer/frontend_types.h"
a90917c3
MD
28#include "../lttng-events.h"
29#include "../lttng-tracer-core.h"
40652b65 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 */
39#undef TRACE_EVENT_MAP
40#define TRACE_EVENT_MAP(name, map, proto, args, tstruct, assign, print) \
41 DECLARE_EVENT_CLASS(map, \
42 PARAMS(proto), \
43 PARAMS(args), \
44 PARAMS(tstruct), \
45 PARAMS(assign), \
46 PARAMS(print)) \
47 DEFINE_EVENT_MAP(map, name, map, PARAMS(proto), PARAMS(args))
48
49#undef TRACE_EVENT_MAP_NOARGS
50#define TRACE_EVENT_MAP_NOARGS(name, map, tstruct, assign, print) \
51 DECLARE_EVENT_CLASS_NOARGS(map, \
52 PARAMS(tstruct), \
53 PARAMS(assign), \
54 PARAMS(print)) \
55 DEFINE_EVENT_MAP_NOARGS(map, name, map)
56
7ca580f8
MD
57#undef LTTNG_TRACE_EVENT
58#define LTTNG_TRACE_EVENT(name, proto, args, _locvar, _code, tstruct, assign, print) \
59 LTTNG_DECLARE_EVENT_CLASS(name, \
60 PARAMS(proto), \
61 PARAMS(args), \
62 PARAMS(_locvar), \
63 PARAMS(_code), \
64 PARAMS(tstruct), \
65 PARAMS(assign), \
66 PARAMS(print)) \
67 DEFINE_EVENT_MAP(name, name, name, PARAMS(proto), PARAMS(args))
68
76e4f017
MD
69#undef DEFINE_EVENT_PRINT_MAP
70#define DEFINE_EVENT_PRINT_MAP(template, name, map, proto, args, print) \
71 DEFINE_EVENT_MAP(template, name, map, PARAMS(proto), PARAMS(args))
72
73/* Callbacks are meaningless to LTTng. */
74#undef TRACE_EVENT_FN_MAP
75#define TRACE_EVENT_FN_MAP(name, map, proto, args, tstruct, \
76 assign, print, reg, unreg) \
77 TRACE_EVENT_MAP(name, map, PARAMS(proto), PARAMS(args), \
78 PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
79
80#undef TRACE_EVENT_CONDITION_MAP
81#define TRACE_EVENT_CONDITION_MAP(name, map, proto, args, cond, tstruct, assign, print) \
82 TRACE_EVENT_MAP(name, map, \
83 PARAMS(proto), \
84 PARAMS(args), \
85 PARAMS(tstruct), \
86 PARAMS(assign), \
87 PARAMS(print))
88
40652b65
MD
89/*
90 * DECLARE_EVENT_CLASS can be used to add a generic function
91 * handlers for events. That is, if all events have the same
92 * parameters and just have distinct trace points.
93 * Each tracepoint can be defined with DEFINE_EVENT and that
94 * will map the DECLARE_EVENT_CLASS to the tracepoint.
95 *
96 * TRACE_EVENT is a one to one mapping between tracepoint and template.
97 */
6db3d13b 98
40652b65 99#undef TRACE_EVENT
76e4f017
MD
100#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
101 TRACE_EVENT_MAP(name, name, \
102 PARAMS(proto), \
103 PARAMS(args), \
104 PARAMS(tstruct), \
105 PARAMS(assign), \
106 PARAMS(print))
40652b65 107
f7bdf4db 108#undef TRACE_EVENT_NOARGS
76e4f017
MD
109#define TRACE_EVENT_NOARGS(name, tstruct, assign, print) \
110 TRACE_EVENT_MAP_NOARGS(name, name, \
111 PARAMS(tstruct), \
112 PARAMS(assign), \
113 PARAMS(print))
f7bdf4db 114
6db3d13b
MD
115#undef DEFINE_EVENT_PRINT
116#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
76e4f017
MD
117 DEFINE_EVENT_PRINT_MAP(template, name, name, \
118 PARAMS(proto), PARAMS(args), PARAMS(print_))
6db3d13b 119
6db3d13b
MD
120#undef TRACE_EVENT_FN
121#define TRACE_EVENT_FN(name, proto, args, tstruct, \
122 assign, print, reg, unreg) \
76e4f017
MD
123 TRACE_EVENT_FN_MAP(name, name, PARAMS(proto), PARAMS(args), \
124 PARAMS(tstruct), PARAMS(assign), PARAMS(print), \
125 PARAMS(reg), PARAMS(unreg)) \
126
127#undef DEFINE_EVENT
128#define DEFINE_EVENT(template, name, proto, args) \
129 DEFINE_EVENT_MAP(template, name, name, PARAMS(proto), PARAMS(args))
130
131#undef DEFINE_EVENT_NOARGS
132#define DEFINE_EVENT_NOARGS(template, name) \
133 DEFINE_EVENT_MAP_NOARGS(template, name, name)
134
135#undef TRACE_EVENT_CONDITION
136#define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
137 TRACE_EVENT_CONDITION_MAP(name, name, \
138 PARAMS(proto), \
139 PARAMS(args), \
140 PARAMS(cond), \
141 PARAMS(tstruct), \
142 PARAMS(assign), \
143 PARAMS(print))
6db3d13b 144
7ca580f8
MD
145#undef DECLARE_EVENT_CLASS
146#define DECLARE_EVENT_CLASS(_name, _proto, _args, _tstruct, _assign, _print) \
147 LTTNG_DECLARE_EVENT_CLASS(_name, PARAMS(_proto), PARAMS(_args), , , \
148 PARAMS(_tstruct), PARAMS(_assign), PARAMS(_print))
149
150#undef DECLARE_EVENT_CLASS_NOARGS
151#define DECLARE_EVENT_CLASS_NOARGS(_name, _tstruct, _assign, _print) \
152 LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, , , PARAMS(_tstruct), \
153 PARAMS(_assign), PARAMS(_print))
154
155
f62b389e 156/*
c099397a 157 * Stage 1 of the trace events.
f62b389e
MD
158 *
159 * Create dummy trace calls for each events, verifying that the LTTng module
160 * TRACE_EVENT headers match the kernel arguments. Will be optimized out by the
161 * compiler.
162 */
163
164#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
165
166#undef TP_PROTO
167#define TP_PROTO(args...) args
168
169#undef TP_ARGS
170#define TP_ARGS(args...) args
171
76e4f017
MD
172#undef DEFINE_EVENT_MAP
173#define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
7eb827f2 174void trace_##_name(_proto);
f62b389e 175
76e4f017
MD
176#undef DEFINE_EVENT_MAP_NOARGS
177#define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
f7bdf4db
MD
178void trace_##_name(void *__data);
179
f62b389e
MD
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
189#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
190
1d12cebd
MD
191/* Named field types must be defined in lttng-types.h */
192
d71e6471
MD
193#undef __field_full
194#define __field_full(_type, _item, _order, _base) \
c099397a
MD
195 { \
196 .name = #_item, \
d71e6471 197 .type = __type_integer(_type, _order, _base, none), \
c099397a 198 },
40652b65 199
d71e6471
MD
200#undef __field
201#define __field(_type, _item) \
202 __field_full(_type, _item, __BYTE_ORDER, 10)
203
40652b65 204#undef __field_ext
d71e6471
MD
205#define __field_ext(_type, _item, _filter_type) \
206 __field(_type, _item)
40652b65 207
6d20e0ae
MD
208#undef __field_hex
209#define __field_hex(_type, _item) \
210 __field_full(_type, _item, __BYTE_ORDER, 16)
211
29021503
MD
212#undef __field_oct
213#define __field_oct(_type, _item) \
214 __field_full(_type, _item, __BYTE_ORDER, 8)
215
c099397a
MD
216#undef __field_network
217#define __field_network(_type, _item) \
d71e6471
MD
218 __field_full(_type, _item, __BIG_ENDIAN, 10)
219
220#undef __field_network_hex
221#define __field_network_hex(_type, _item) \
222 __field_full(_type, _item, __BIG_ENDIAN, 16)
c099397a 223
d71e6471
MD
224#undef __array_enc_ext
225#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
299338c8 226 { \
c099397a
MD
227 .name = #_item, \
228 .type = \
229 { \
299338c8 230 .atype = atype_array, \
c099397a
MD
231 .u.array = \
232 { \
233 .length = _length, \
d71e6471 234 .elem_type = __type_integer(_type, _order, _base, _encoding), \
c099397a 235 }, \
299338c8
MD
236 }, \
237 },
40652b65 238
64c796d8
MD
239#undef __array
240#define __array(_type, _item, _length) \
d71e6471 241 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
64c796d8
MD
242
243#undef __array_text
244#define __array_text(_type, _item, _length) \
d71e6471 245 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
64c796d8 246
d71e6471
MD
247#undef __array_hex
248#define __array_hex(_type, _item, _length) \
249 __array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
250
251#undef __dynamic_array_enc_ext
252#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
299338c8 253 { \
c099397a
MD
254 .name = #_item, \
255 .type = \
256 { \
299338c8 257 .atype = atype_sequence, \
c099397a
MD
258 .u.sequence = \
259 { \
64c796d8 260 .length_type = __type_integer(u32, __BYTE_ORDER, 10, none), \
d71e6471 261 .elem_type = __type_integer(_type, _order, _base, _encoding), \
c099397a 262 }, \
299338c8
MD
263 }, \
264 },
40652b65 265
84da5206
MD
266#undef __dynamic_array_enc_ext_2
267#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding) \
268 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
269
64c796d8
MD
270#undef __dynamic_array
271#define __dynamic_array(_type, _item, _length) \
d71e6471 272 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, none)
64c796d8
MD
273
274#undef __dynamic_array_text
275#define __dynamic_array_text(_type, _item, _length) \
d71e6471
MD
276 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 10, UTF8)
277
278#undef __dynamic_array_hex
279#define __dynamic_array_hex(_type, _item, _length) \
280 __dynamic_array_enc_ext(_type, _item, _length, __BYTE_ORDER, 16, none)
64c796d8 281
7ca580f8
MD
282#undef __dynamic_array_network_hex
283#define __dynamic_array_network_hex(_type, _item, _length) \
284 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 16, none)
285
286#undef __dynamic_array_network
287#define __dynamic_array_network(_type, _item, _length) \
288 __dynamic_array_enc_ext(_type, _item, _length, __BIG_ENDIAN, 10, none)
289
84da5206
MD
290#undef __dynamic_array_text_2
291#define __dynamic_array_text_2(_type, _item, _length1, _length2) \
292 __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, __BYTE_ORDER, 10, UTF8)
293
40652b65 294#undef __string
1d12cebd 295#define __string(_item, _src) \
299338c8 296 { \
c099397a
MD
297 .name = #_item, \
298 .type = \
299 { \
299338c8 300 .atype = atype_string, \
c099397a 301 .u.basic.string.encoding = lttng_encode_UTF8, \
299338c8
MD
302 }, \
303 },
1d12cebd 304
c6e3f225
MD
305#undef __string_from_user
306#define __string_from_user(_item, _src) \
307 __string(_item, _src)
308
40652b65 309#undef TP_STRUCT__entry
1d12cebd
MD
310#define TP_STRUCT__entry(args...) args /* Only one used in this phase */
311
7ca580f8
MD
312#undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
313#define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
0d1d4002
MD
314 static const struct lttng_event_field __event_fields___##_name[] = { \
315 _tstruct \
299338c8
MD
316 };
317
7ca580f8
MD
318#undef LTTNG_DECLARE_EVENT_CLASS
319#define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
320 LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, PARAMS(_tstruct), PARAMS(_assign), \
f7bdf4db
MD
321 PARAMS(_print))
322
299338c8
MD
323#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
324
19c57fbf 325/*
c099397a 326 * Stage 3 of the trace events.
19c57fbf
MD
327 *
328 * Create probe callback prototypes.
329 */
330
331#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
332
333#undef TP_PROTO
334#define TP_PROTO(args...) args
335
7ca580f8
MD
336#undef LTTNG_DECLARE_EVENT_CLASS
337#define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
19c57fbf
MD
338static void __event_probe__##_name(void *__data, _proto);
339
7ca580f8
MD
340#undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
341#define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
f7bdf4db
MD
342static void __event_probe__##_name(void *__data);
343
19c57fbf
MD
344#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
345
299338c8 346/*
f7bdf4db 347 * Stage 3.9 of the trace events.
299338c8 348 *
f7bdf4db 349 * Create event descriptions.
299338c8
MD
350 */
351
299338c8
MD
352/* Named field types must be defined in lttng-types.h */
353
6db3d13b 354#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
299338c8 355
1ec65de1
MD
356#ifndef TP_PROBE_CB
357#define TP_PROBE_CB(_template) &__event_probe__##_template
358#endif
359
76e4f017
MD
360#undef DEFINE_EVENT_MAP_NOARGS
361#define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
362static const struct lttng_event_desc __event_desc___##_map = { \
f7bdf4db 363 .fields = __event_fields___##_template, \
76e4f017 364 .name = #_map, \
a26a7e4f 365 .kname = #_name, \
f7bdf4db
MD
366 .probe_callback = (void *) TP_PROBE_CB(_template), \
367 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
368 .owner = THIS_MODULE, \
369};
370
76e4f017
MD
371#undef DEFINE_EVENT_MAP
372#define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
373 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
f7bdf4db
MD
374
375#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
376
377
378/*
379 * Stage 4 of the trace events.
380 *
381 * Create an array of event description pointers.
382 */
383
384/* Named field types must be defined in lttng-types.h */
385
386#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
387
76e4f017
MD
388#undef DEFINE_EVENT_MAP_NOARGS
389#define DEFINE_EVENT_MAP_NOARGS(_template, _name, _map) \
390 &__event_desc___##_map,
f7bdf4db 391
76e4f017
MD
392#undef DEFINE_EVENT_MAP
393#define DEFINE_EVENT_MAP(_template, _name, _map, _proto, _args) \
394 DEFINE_EVENT_MAP_NOARGS(_template, _name, _map)
40652b65 395
d0dd2ecb
MD
396#define TP_ID1(_token, _system) _token##_system
397#define TP_ID(_token, _system) TP_ID1(_token, _system)
40652b65 398
f7bdf4db 399static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
40652b65 400#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
299338c8
MD
401};
402
d0dd2ecb
MD
403#undef TP_ID1
404#undef TP_ID
405
85a9ca7f
MD
406
407/*
c099397a 408 * Stage 5 of the trace events.
85a9ca7f
MD
409 *
410 * Create a toplevel descriptor for the whole probe.
411 */
412
413#define TP_ID1(_token, _system) _token##_system
414#define TP_ID(_token, _system) TP_ID1(_token, _system)
415
416/* non-const because list head will be modified when registered. */
25631135 417static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
85a9ca7f
MD
418 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
419 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
420};
421
422#undef TP_ID1
423#undef TP_ID
424
d0dd2ecb 425/*
c099397a 426 * Stage 6 of the trace events.
40652b65
MD
427 *
428 * Create static inline function that calculates event size.
429 */
430
6db3d13b 431#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
40652b65 432
6db3d13b
MD
433/* Named field types must be defined in lttng-types.h */
434
d71e6471
MD
435#undef __field_full
436#define __field_full(_type, _item, _order, _base) \
a90917c3 437 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 438 __event_len += sizeof(_type);
6db3d13b 439
d71e6471
MD
440#undef __array_enc_ext
441#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
a90917c3 442 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 443 __event_len += sizeof(_type) * (_length);
6db3d13b 444
d71e6471
MD
445#undef __dynamic_array_enc_ext
446#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
7ca580f8 447 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
85a80742 448 __event_len += sizeof(u32); \
a90917c3 449 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
41b59694
MD
450 __dynamic_len[__dynamic_len_idx] = (_length); \
451 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
452 __dynamic_len_idx++;
6db3d13b 453
84da5206
MD
454#undef __dynamic_array_enc_ext_2
455#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
7ca580f8 456 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(u32)); \
84da5206
MD
457 __event_len += sizeof(u32); \
458 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
459 __dynamic_len[__dynamic_len_idx] = (_length1); \
460 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
461 __dynamic_len_idx++; \
462 __dynamic_len[__dynamic_len_idx] = (_length2); \
463 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
464 __dynamic_len_idx++;
465
6db3d13b 466#undef __string
85a80742 467#define __string(_item, _src) \
0d1d4002
MD
468 __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1;
469
d0255731 470/*
786b8312
MD
471 * strlen_user includes \0. If returns 0, it faulted, so we set size to
472 * 1 (\0 only).
d0255731 473 */
c6e3f225
MD
474#undef __string_from_user
475#define __string_from_user(_item, _src) \
786b8312 476 __event_len += __dynamic_len[__dynamic_len_idx++] = \
7b8ea3a5 477 max_t(size_t, lttng_strlen_user_inatomic(_src), 1);
c6e3f225 478
0d1d4002
MD
479#undef TP_PROTO
480#define TP_PROTO(args...) args
6db3d13b
MD
481
482#undef TP_STRUCT__entry
0d1d4002 483#define TP_STRUCT__entry(args...) args
6db3d13b 484
7ca580f8
MD
485#undef TP_locvar
486#define TP_locvar(...) __VA_ARGS__
487
488#undef LTTNG_DECLARE_EVENT_CLASS
489#define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
490static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
491 void *__tp_locvar, _proto) \
0d1d4002
MD
492{ \
493 size_t __event_len = 0; \
d3de7f14 494 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
7ca580f8 495 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
d3de7f14
MD
496 \
497 _tstruct \
498 return __event_len; \
499}
500
7ca580f8
MD
501#undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
502#define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
503static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
504 void *__tp_locvar) \
d3de7f14
MD
505{ \
506 size_t __event_len = 0; \
507 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
7ca580f8 508 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
0d1d4002 509 \
0d1d4002
MD
510 _tstruct \
511 return __event_len; \
6db3d13b 512}
40652b65
MD
513
514#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
515
516/*
c099397a 517 * Stage 7 of the trace events.
e763dbf5
MD
518 *
519 * Create static inline function that calculates event payload alignment.
520 */
521
522#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
523
524/* Named field types must be defined in lttng-types.h */
525
d71e6471
MD
526#undef __field_full
527#define __field_full(_type, _item, _order, _base) \
a90917c3 528 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
e763dbf5 529
d71e6471
MD
530#undef __array_enc_ext
531#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
a90917c3 532 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
e763dbf5 533
d71e6471
MD
534#undef __dynamic_array_enc_ext
535#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
7ca580f8 536 __event_align = max_t(size_t, __event_align, lttng_alignof(u32)); \
a90917c3 537 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
e763dbf5 538
84da5206
MD
539#undef __dynamic_array_enc_ext_2
540#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
541 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
542
e763dbf5
MD
543#undef __string
544#define __string(_item, _src)
545
c6e3f225
MD
546#undef __string_from_user
547#define __string_from_user(_item, _src)
548
e763dbf5
MD
549#undef TP_PROTO
550#define TP_PROTO(args...) args
551
552#undef TP_STRUCT__entry
553#define TP_STRUCT__entry(args...) args
554
7ca580f8
MD
555#undef TP_locvar
556#define TP_locvar(...) __VA_ARGS__
557
558#undef LTTNG_DECLARE_EVENT_CLASS
559#define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
560static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
e763dbf5
MD
561{ \
562 size_t __event_align = 1; \
7ca580f8
MD
563 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
564 \
e763dbf5
MD
565 _tstruct \
566 return __event_align; \
567}
568
7ca580f8
MD
569#undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
570#define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
571static inline size_t __event_get_align__##_name(void *__tp_locvar) \
d3de7f14
MD
572{ \
573 size_t __event_align = 1; \
7ca580f8
MD
574 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
575 \
d3de7f14
MD
576 _tstruct \
577 return __event_align; \
578}
579
e763dbf5
MD
580#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
581
e763dbf5 582/*
c099397a 583 * Stage 8 of the trace events.
40652b65 584 *
3c4ffab9
MD
585 * Create structure declaration that allows the "assign" macros to access the
586 * field types.
587 */
588
589#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
590
591/* Named field types must be defined in lttng-types.h */
592
d71e6471
MD
593#undef __field_full
594#define __field_full(_type, _item, _order, _base) _type _item;
3c4ffab9 595
d71e6471
MD
596#undef __array_enc_ext
597#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding) \
598 _type _item;
64c796d8 599
d71e6471
MD
600#undef __dynamic_array_enc_ext
601#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
602 _type _item;
64c796d8 603
84da5206
MD
604#undef __dynamic_array_enc_ext_2
605#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
606 __dynamic_array_enc_ext(_type, _item, _length1 + _length2, _order, _base, _encoding)
607
3c4ffab9 608#undef __string
c6e3f225
MD
609#define __string(_item, _src) char _item;
610
611#undef __string_from_user
612#define __string_from_user(_item, _src) \
613 __string(_item, _src)
3c4ffab9
MD
614
615#undef TP_STRUCT__entry
616#define TP_STRUCT__entry(args...) args
617
7ca580f8
MD
618#undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
619#define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
3c4ffab9
MD
620struct __event_typemap__##_name { \
621 _tstruct \
622};
623
7ca580f8
MD
624#undef LTTNG_DECLARE_EVENT_CLASS
625#define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
626 LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print)
d3de7f14 627
3c4ffab9
MD
628#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
629
630
631/*
c099397a 632 * Stage 9 of the trace events.
3c4ffab9 633 *
40652b65
MD
634 * Create the probe function : call even size calculation and write event data
635 * into the buffer.
e763dbf5 636 *
67e5e60c
MD
637 * We use both the field and assignment macros to write the fields in the order
638 * defined in the field declaration. The field declarations control the
639 * execution order, jumping to the appropriate assignment block.
40652b65
MD
640 */
641
e763dbf5
MD
642#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
643
d71e6471
MD
644#undef __field_full
645#define __field_full(_type, _item, _order, _base) \
e763dbf5
MD
646 goto __assign_##_item; \
647__end_field_##_item:
40652b65 648
d71e6471
MD
649#undef __array_enc_ext
650#define __array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
e763dbf5
MD
651 goto __assign_##_item; \
652__end_field_##_item:
40652b65 653
d71e6471
MD
654#undef __dynamic_array_enc_ext
655#define __dynamic_array_enc_ext(_type, _item, _length, _order, _base, _encoding)\
e763dbf5
MD
656 goto __assign_##_item##_1; \
657__end_field_##_item##_1: \
e763dbf5
MD
658 goto __assign_##_item##_2; \
659__end_field_##_item##_2:
40652b65 660
84da5206
MD
661#undef __dynamic_array_enc_ext_2
662#define __dynamic_array_enc_ext_2(_type, _item, _length1, _length2, _order, _base, _encoding)\
663 goto __assign_##_item##_1; \
664__end_field_##_item##_1: \
665 goto __assign_##_item##_2; \
666__end_field_##_item##_2: \
667 goto __assign_##_item##_3; \
668__end_field_##_item##_3:
669
e763dbf5
MD
670#undef __string
671#define __string(_item, _src) \
672 goto __assign_##_item; \
673__end_field_##_item:
674
c6e3f225
MD
675#undef __string_from_user
676#define __string_from_user(_item, _src) \
677 __string(_item, _src)
678
e763dbf5
MD
679/*
680 * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to
681 * strcpy().
682 */
683#undef tp_assign
684#define tp_assign(dest, src) \
685__assign_##dest: \
686 { \
3c4ffab9 687 __typeof__(__typemap.dest) __tmp = (src); \
a90917c3 688 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp)); \
aaa4004a 689 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
e763dbf5
MD
690 } \
691 goto __end_field_##dest;
692
d9a7cf03
FG
693/* fixed length array memcpy */
694#undef tp_memcpy_gen
695#define tp_memcpy_gen(write_ops, dest, src, len) \
e763dbf5 696__assign_##dest: \
d793d5e1
MD
697 if (0) \
698 (void) __typemap.dest; \
a90917c3 699 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
d9a7cf03 700 __chan->ops->write_ops(&__ctx, src, len); \
e763dbf5
MD
701 goto __end_field_##dest;
702
d9a7cf03
FG
703#undef tp_memcpy
704#define tp_memcpy(dest, src, len) \
705 tp_memcpy_gen(event_write, dest, src, len)
706
707#undef tp_memcpy_from_user
708#define tp_memcpy_from_user(dest, src, len) \
709 tp_memcpy_gen(event_write_from_user, dest, src, len)
710
711/* variable length sequence memcpy */
712#undef tp_memcpy_dyn_gen
713#define tp_memcpy_dyn_gen(write_ops, dest, src) \
e763dbf5
MD
714__assign_##dest##_1: \
715 { \
41b59694 716 u32 __tmpl = __dynamic_len[__dynamic_len_idx]; \
a90917c3 717 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
aaa4004a 718 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
e763dbf5
MD
719 } \
720 goto __end_field_##dest##_1; \
721__assign_##dest##_2: \
a90917c3 722 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
d9a7cf03 723 __chan->ops->write_ops(&__ctx, src, \
41b59694 724 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
e763dbf5 725 goto __end_field_##dest##_2;
58aa5d24 726
84da5206
MD
727#undef tp_memcpy_dyn_gen_2
728#define tp_memcpy_dyn_gen_2(write_ops, dest, src1, src2) \
729__assign_##dest##_1: \
730 { \
731 u32 __tmpl = __dynamic_len[__dynamic_len_idx] \
732 + __dynamic_len[__dynamic_len_idx + 1]; \
733 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(u32)); \
734 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(u32)); \
735 } \
736 goto __end_field_##dest##_1; \
737__assign_##dest##_2: \
738 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
739 __chan->ops->write_ops(&__ctx, src1, \
740 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
741 goto __end_field_##dest##_2; \
742__assign_##dest##_3: \
743 __chan->ops->write_ops(&__ctx, src2, \
744 sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\
745 goto __end_field_##dest##_3;
746
d9a7cf03
FG
747#undef tp_memcpy_dyn
748#define tp_memcpy_dyn(dest, src) \
749 tp_memcpy_dyn_gen(event_write, dest, src)
750
84da5206
MD
751#undef tp_memcpy_dyn_2
752#define tp_memcpy_dyn_2(dest, src1, src2) \
753 tp_memcpy_dyn_gen_2(event_write, dest, src1, src2)
754
d9a7cf03
FG
755#undef tp_memcpy_dyn_from_user
756#define tp_memcpy_dyn_from_user(dest, src) \
757 tp_memcpy_dyn_gen(event_write_from_user, dest, src)
58aa5d24 758
d0255731 759/*
786b8312 760 * The string length including the final \0.
d0255731 761 */
4ea00e4f 762#undef tp_copy_string_from_user
58aa5d24 763#define tp_copy_string_from_user(dest, src) \
16f78f3a
MD
764__assign_##dest: \
765 if (0) \
766 (void) __typemap.dest; \
767 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
768 __chan->ops->event_strcpy_from_user(&__ctx, src, \
769 __get_dynamic_array_len(dest)); \
4ea00e4f 770 goto __end_field_##dest;
16f78f3a 771
e763dbf5
MD
772#undef tp_strcpy
773#define tp_strcpy(dest, src) \
16f78f3a
MD
774__assign_##dest: \
775 if (0) \
776 (void) __typemap.dest; \
777 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__typemap.dest)); \
778 __chan->ops->event_strcpy(&__ctx, src, __get_dynamic_array_len(dest)); \
779 goto __end_field_##dest;
40652b65 780
e763dbf5
MD
781/* Named field types must be defined in lttng-types.h */
782
783#undef __get_str
784#define __get_str(field) field
785
786#undef __get_dynamic_array
787#define __get_dynamic_array(field) field
788
789/* Beware: this get len actually consumes the len value */
790#undef __get_dynamic_array_len
791#define __get_dynamic_array_len(field) __dynamic_len[__dynamic_len_idx++]
792
793#undef TP_PROTO
794#define TP_PROTO(args...) args
795
796#undef TP_ARGS
797#define TP_ARGS(args...) args
798
799#undef TP_STRUCT__entry
800#define TP_STRUCT__entry(args...) args
801
802#undef TP_fast_assign
803#define TP_fast_assign(args...) args
804
7ca580f8
MD
805#undef TP_locvar
806#define TP_locvar(...) __VA_ARGS__
807
808#undef TP_code
809#define TP_code(...) __VA_ARGS__
810
c337ddc2
MD
811/*
812 * For state dump, check that "session" argument (mandatory) matches the
813 * session this event belongs to. Ensures that we write state dump data only
814 * into the started session, not into all sessions.
815 */
816#ifdef TP_SESSION_CHECK
817#define _TP_SESSION_CHECK(session, csession) (session == csession)
818#else /* TP_SESSION_CHECK */
819#define _TP_SESSION_CHECK(session, csession) 1
820#endif /* TP_SESSION_CHECK */
821
f9771d39
MD
822/*
823 * __dynamic_len array length is twice the number of fields due to
824 * __dynamic_array_enc_ext_2() and tp_memcpy_dyn_2(), which are the
825 * worse case, needing 2 entries per field.
826 */
7ca580f8
MD
827#undef LTTNG_DECLARE_EVENT_CLASS
828#define LTTNG_DECLARE_EVENT_CLASS(_name, _proto, _args, _locvar, _code, _tstruct, _assign, _print) \
e763dbf5
MD
829static void __event_probe__##_name(void *__data, _proto) \
830{ \
7ca580f8 831 struct probe_local_vars { _locvar }; \
a90917c3
MD
832 struct lttng_event *__event = __data; \
833 struct lttng_channel *__chan = __event->chan; \
aaa4004a 834 struct lib_ring_buffer_ctx __ctx; \
e763dbf5 835 size_t __event_len, __event_align; \
d3de7f14
MD
836 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
837 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
838 struct __event_typemap__##_name __typemap __attribute__((unused)); \
e763dbf5 839 int __ret; \
7ca580f8
MD
840 struct probe_local_vars __tp_locvar; \
841 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
842 &__tp_locvar; \
e763dbf5 843 \
c337ddc2
MD
844 if (!_TP_SESSION_CHECK(session, __chan->session)) \
845 return; \
e64957da
MD
846 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
847 return; \
848 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
849 return; \
850 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
52fc2e1f 851 return; \
7ca580f8
MD
852 _code \
853 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar, \
854 _args); \
855 __event_align = __event_get_align__##_name(tp_locvar, _args); \
aaa4004a 856 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
e763dbf5 857 __event_align, -1); \
aaa4004a 858 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
e763dbf5
MD
859 if (__ret < 0) \
860 return; \
861 /* Control code (field ordering) */ \
862 _tstruct \
aaa4004a 863 __chan->ops->event_commit(&__ctx); \
e763dbf5
MD
864 return; \
865 /* Copy code, steered by control code */ \
866 _assign \
867}
868
7ca580f8
MD
869#undef LTTNG_DECLARE_EVENT_CLASS_NOARGS
870#define LTTNG_DECLARE_EVENT_CLASS_NOARGS(_name, _locvar, _code, _tstruct, _assign, _print) \
f7bdf4db
MD
871static void __event_probe__##_name(void *__data) \
872{ \
7ca580f8 873 struct probe_local_vars { _locvar }; \
a90917c3
MD
874 struct lttng_event *__event = __data; \
875 struct lttng_channel *__chan = __event->chan; \
f7bdf4db
MD
876 struct lib_ring_buffer_ctx __ctx; \
877 size_t __event_len, __event_align; \
d3de7f14
MD
878 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
879 size_t __dynamic_len[2 * ARRAY_SIZE(__event_fields___##_name)] __attribute__((unused)); \
880 struct __event_typemap__##_name __typemap __attribute__((unused)); \
f7bdf4db 881 int __ret; \
7ca580f8
MD
882 struct probe_local_vars __tp_locvar; \
883 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
884 &__tp_locvar; \
f7bdf4db 885 \
c337ddc2
MD
886 if (!_TP_SESSION_CHECK(session, __chan->session)) \
887 return; \
f7bdf4db
MD
888 if (unlikely(!ACCESS_ONCE(__chan->session->active))) \
889 return; \
890 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
891 return; \
892 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
893 return; \
7ca580f8
MD
894 _code \
895 __event_len = __event_get_size__##_name(__dynamic_len, tp_locvar); \
896 __event_align = __event_get_align__##_name(tp_locvar); \
f7bdf4db
MD
897 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
898 __event_align, -1); \
899 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
900 if (__ret < 0) \
901 return; \
902 /* Control code (field ordering) */ \
903 _tstruct \
904 __chan->ops->event_commit(&__ctx); \
905 return; \
906 /* Copy code, steered by control code */ \
907 _assign \
908}
909
e763dbf5
MD
910#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
911
3afe7aac 912/*
c099397a 913 * Stage 10 of the trace events.
3afe7aac
MD
914 *
915 * Register/unregister probes at module load/unload.
916 */
917
918#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
919
920#define TP_ID1(_token, _system) _token##_system
921#define TP_ID(_token, _system) TP_ID1(_token, _system)
922#define module_init_eval1(_token, _system) module_init(_token##_system)
923#define module_init_eval(_token, _system) module_init_eval1(_token, _system)
924#define module_exit_eval1(_token, _system) module_exit(_token##_system)
925#define module_exit_eval(_token, _system) module_exit_eval1(_token, _system)
926
2655f9ad 927#ifndef TP_MODULE_NOINIT
3afe7aac
MD
928static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
929{
6d2a620c 930 wrapper_vmalloc_sync_all();
a90917c3 931 return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
3afe7aac
MD
932}
933
3afe7aac
MD
934static void TP_ID(__lttng_events_exit__, TRACE_SYSTEM)(void)
935{
a90917c3 936 lttng_probe_unregister(&TP_ID(__probe_desc___, TRACE_SYSTEM));
3afe7aac
MD
937}
938
2655f9ad
MD
939#ifndef TP_MODULE_NOAUTOLOAD
940module_init_eval(__lttng_events_init__, TRACE_SYSTEM);
3afe7aac 941module_exit_eval(__lttng_events_exit__, TRACE_SYSTEM);
259b6cb3 942#endif
3afe7aac 943
2655f9ad
MD
944#endif
945
3afe7aac
MD
946#undef module_init_eval
947#undef module_exit_eval
948#undef TP_ID1
949#undef TP_ID
177b3692
MD
950
951#undef TP_PROTO
952#undef TP_ARGS
953#undef TRACE_EVENT_FLAGS
This page took 0.078196 seconds and 4 git commands to generate.