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