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