Fix: ctf_user_integer should not trigger page fault
[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>
f127e61e 5 * Copyright (C) 2009-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
17baffe2 6 *
886d51a3
MD
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; only
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17baffe2 20 */
f127e61e 21
d28686c1 22#include <linux/uaccess.h>
d0dd2ecb 23#include <linux/debugfs.h>
f127e61e 24#include <linux/rculist.h>
c0edae1d
MD
25#include "lttng.h"
26#include "lttng-types.h"
7b8ea3a5 27#include "lttng-probe-user.h"
b13f3ebe 28#include "../wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
f3bc08c5 29#include "../wrapper/ringbuffer/frontend_types.h"
76658350 30#include "../wrapper/ringbuffer/backend.h"
7a09dcb7 31#include "../wrapper/rcu.h"
a90917c3
MD
32#include "../lttng-events.h"
33#include "../lttng-tracer-core.h"
40652b65 34
40652b65 35/*
6db3d13b 36 * Macro declarations used for all stages.
40652b65
MD
37 */
38
76e4f017
MD
39/*
40 * LTTng name mapping macros. LTTng remaps some of the kernel events to
41 * enforce name-spacing.
42 */
3bc29f0a 43#undef LTTNG_TRACEPOINT_EVENT_MAP
f127e61e 44#define LTTNG_TRACEPOINT_EVENT_MAP(name, map, proto, args, fields) \
3bc29f0a 45 LTTNG_TRACEPOINT_EVENT_CLASS(map, \
76e4f017
MD
46 PARAMS(proto), \
47 PARAMS(args), \
f127e61e 48 PARAMS(fields)) \
3bc29f0a 49 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
76e4f017 50
3bc29f0a 51#undef LTTNG_TRACEPOINT_EVENT_MAP_NOARGS
f127e61e 52#define LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, map, fields) \
3bc29f0a 53 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(map, \
f127e61e 54 PARAMS(fields)) \
3bc29f0a 55 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(map, name, map)
76e4f017 56
f127e61e
MD
57#undef LTTNG_TRACEPOINT_EVENT_CODE_MAP
58#define LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, map, proto, args, _locvar, _code, fields) \
59 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(map, \
60 PARAMS(proto), \
61 PARAMS(args), \
62 PARAMS(_locvar), \
63 PARAMS(_code), \
64 PARAMS(fields)) \
65 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(map, name, map, PARAMS(proto), PARAMS(args))
66
3bc29f0a 67#undef LTTNG_TRACEPOINT_EVENT_CODE
f127e61e
MD
68#define LTTNG_TRACEPOINT_EVENT_CODE(name, proto, args, _locvar, _code, fields) \
69 LTTNG_TRACEPOINT_EVENT_CODE_MAP(name, name, \
7ca580f8
MD
70 PARAMS(proto), \
71 PARAMS(args), \
72 PARAMS(_locvar), \
73 PARAMS(_code), \
f127e61e 74 PARAMS(fields))
fcf7fa33 75
40652b65 76/*
3bc29f0a
MD
77 * LTTNG_TRACEPOINT_EVENT_CLASS can be used to add a generic function
78 * handlers for events. That is, if all events have the same parameters
79 * and just have distinct trace points. Each tracepoint can be defined
80 * with LTTNG_TRACEPOINT_EVENT_INSTANCE and that will map the
81 * LTTNG_TRACEPOINT_EVENT_CLASS to the tracepoint.
40652b65 82 *
3bc29f0a
MD
83 * LTTNG_TRACEPOINT_EVENT is a one to one mapping between tracepoint and
84 * template.
40652b65 85 */
6db3d13b 86
3bc29f0a 87#undef LTTNG_TRACEPOINT_EVENT
f127e61e 88#define LTTNG_TRACEPOINT_EVENT(name, proto, args, fields) \
3bc29f0a
MD
89 LTTNG_TRACEPOINT_EVENT_MAP(name, name, \
90 PARAMS(proto), \
91 PARAMS(args), \
f127e61e 92 PARAMS(fields))
40652b65 93
3bc29f0a 94#undef LTTNG_TRACEPOINT_EVENT_NOARGS
f127e61e
MD
95#define LTTNG_TRACEPOINT_EVENT_NOARGS(name, fields) \
96 LTTNG_TRACEPOINT_EVENT_MAP_NOARGS(name, name, PARAMS(fields))
76e4f017 97
3bc29f0a
MD
98#undef LTTNG_TRACEPOINT_EVENT_INSTANCE
99#define LTTNG_TRACEPOINT_EVENT_INSTANCE(template, name, proto, args) \
100 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(template, name, name, PARAMS(proto), PARAMS(args))
76e4f017 101
3bc29f0a
MD
102#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
103#define LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(template, name) \
104 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(template, name, name)
76e4f017 105
3bc29f0a 106#undef LTTNG_TRACEPOINT_EVENT_CLASS
f127e61e 107#define LTTNG_TRACEPOINT_EVENT_CLASS(_name, _proto, _args, _fields) \
3bc29f0a 108 LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, PARAMS(_proto), PARAMS(_args), , , \
f127e61e 109 PARAMS(_fields))
7ca580f8 110
3bc29f0a 111#undef LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
f127e61e
MD
112#define LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
113 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, , , PARAMS(_fields))
7ca580f8
MD
114
115
f62b389e 116/*
c099397a 117 * Stage 1 of the trace events.
f62b389e
MD
118 *
119 * Create dummy trace calls for each events, verifying that the LTTng module
3bc29f0a
MD
120 * instrumentation headers match the kernel arguments. Will be optimized
121 * out by the compiler.
f62b389e
MD
122 */
123
f127e61e
MD
124/* Reset all macros within TRACEPOINT_EVENT */
125#include "lttng-events-reset.h"
f62b389e
MD
126
127#undef TP_PROTO
f127e61e 128#define TP_PROTO(...) __VA_ARGS__
f62b389e
MD
129
130#undef TP_ARGS
f127e61e 131#define TP_ARGS(...) __VA_ARGS__
f62b389e 132
3bc29f0a
MD
133#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
134#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
7eb827f2 135void trace_##_name(_proto);
f62b389e 136
3bc29f0a
MD
137#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
138#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
cb1aa0c7 139void trace_##_name(void);
f7bdf4db 140
f62b389e
MD
141#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
142
d0558de2
MD
143/*
144 * Stage 1.1 of the trace events.
145 *
146 * Create dummy trace prototypes for each event class, and for each used
147 * template. This will allow checking whether the prototypes from the
148 * class and the instance using the class actually match.
149 */
150
151#include "lttng-events-reset.h" /* Reset all macros within TRACE_EVENT */
152
153#undef TP_PROTO
154#define TP_PROTO(...) __VA_ARGS__
155
156#undef TP_ARGS
157#define TP_ARGS(...) __VA_ARGS__
158
159#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
160#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
161void __event_template_proto___##_template(_proto);
162
163#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
164#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
165void __event_template_proto___##_template(void);
166
167#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
168#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
169void __event_template_proto___##_name(_proto);
170
171#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
172#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
173void __event_template_proto___##_name(void);
174
175#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
176
6db3d13b 177/*
c099397a 178 * Stage 2 of the trace events.
6db3d13b
MD
179 *
180 * Create event field type metadata section.
181 * Each event produce an array of fields.
182 */
183
f127e61e
MD
184/* Reset all macros within TRACEPOINT_EVENT */
185#include "lttng-events-reset.h"
186#include "lttng-events-write.h"
187#include "lttng-events-nowrite.h"
6db3d13b 188
f127e61e
MD
189#undef _ctf_integer_ext
190#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
c099397a
MD
191 { \
192 .name = #_item, \
f127e61e
MD
193 .type = __type_integer(_type, _byte_order, _base, none),\
194 .nowrite = _nowrite, \
195 .user = _user, \
c099397a 196 },
40652b65 197
f127e61e
MD
198#undef _ctf_array_encoded
199#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
299338c8 200 { \
c099397a
MD
201 .name = #_item, \
202 .type = \
203 { \
299338c8 204 .atype = atype_array, \
f127e61e 205 .u = \
c099397a 206 { \
f127e61e
MD
207 .array = \
208 { \
209 .elem_type = __type_integer(_type, __BYTE_ORDER, 10, _encoding), \
210 .length = _length, \
211 } \
212 } \
299338c8 213 }, \
f127e61e
MD
214 .nowrite = _nowrite, \
215 .user = _user, \
299338c8 216 },
40652b65 217
f127e61e
MD
218#undef _ctf_sequence_encoded
219#define _ctf_sequence_encoded(_type, _item, _src, \
220 _length_type, _src_length, _encoding, \
57ede728 221 _byte_order, _base, _user, _nowrite) \
299338c8 222 { \
c099397a
MD
223 .name = #_item, \
224 .type = \
225 { \
299338c8 226 .atype = atype_sequence, \
f127e61e 227 .u = \
c099397a 228 { \
f127e61e
MD
229 .sequence = \
230 { \
231 .length_type = __type_integer(_length_type, __BYTE_ORDER, 10, none), \
57ede728 232 .elem_type = __type_integer(_type, _byte_order, _base, _encoding), \
f127e61e 233 }, \
c099397a 234 }, \
299338c8 235 }, \
f127e61e
MD
236 .nowrite = _nowrite, \
237 .user = _user, \
299338c8 238 },
40652b65 239
f127e61e
MD
240#undef _ctf_string
241#define _ctf_string(_item, _src, _user, _nowrite) \
299338c8 242 { \
c099397a
MD
243 .name = #_item, \
244 .type = \
245 { \
299338c8 246 .atype = atype_string, \
f127e61e
MD
247 .u = \
248 { \
249 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
250 }, \
299338c8 251 }, \
f127e61e
MD
252 .nowrite = _nowrite, \
253 .user = _user, \
299338c8 254 },
1d12cebd 255
f127e61e
MD
256#undef TP_FIELDS
257#define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1d12cebd 258
3bc29f0a 259#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
f127e61e 260#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
0d1d4002 261 static const struct lttng_event_field __event_fields___##_name[] = { \
f127e61e 262 _fields \
299338c8
MD
263 };
264
3bc29f0a 265#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
f127e61e
MD
266#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
267 LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, PARAMS(_fields))
f7bdf4db 268
299338c8
MD
269#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
270
19c57fbf 271/*
c099397a 272 * Stage 3 of the trace events.
19c57fbf
MD
273 *
274 * Create probe callback prototypes.
275 */
276
f127e61e
MD
277/* Reset all macros within TRACEPOINT_EVENT */
278#include "lttng-events-reset.h"
19c57fbf
MD
279
280#undef TP_PROTO
f127e61e 281#define TP_PROTO(...) __VA_ARGS__
19c57fbf 282
3bc29f0a 283#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
f127e61e 284#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
19c57fbf
MD
285static void __event_probe__##_name(void *__data, _proto);
286
3bc29f0a 287#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
f127e61e 288#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
f7bdf4db
MD
289static void __event_probe__##_name(void *__data);
290
19c57fbf
MD
291#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
292
f7bdf4db
MD
293/*
294 * Stage 4 of the trace events.
295 *
40652b65
MD
296 * Create static inline function that calculates event size.
297 */
298
f127e61e
MD
299/* Reset all macros within TRACEPOINT_EVENT */
300#include "lttng-events-reset.h"
301#include "lttng-events-write.h"
6db3d13b 302
f127e61e
MD
303#undef _ctf_integer_ext
304#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
a90917c3 305 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 306 __event_len += sizeof(_type);
6db3d13b 307
f127e61e
MD
308#undef _ctf_array_encoded
309#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
a90917c3 310 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
0d1d4002 311 __event_len += sizeof(_type) * (_length);
6db3d13b 312
f127e61e
MD
313#undef _ctf_sequence_encoded
314#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 315 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
f127e61e
MD
316 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
317 __event_len += sizeof(_length_type); \
a90917c3 318 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
f127e61e 319 __dynamic_len[__dynamic_len_idx] = (_src_length); \
41b59694
MD
320 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
321 __dynamic_len_idx++;
6db3d13b 322
d0255731 323/*
f127e61e 324 * ctf_user_string includes \0. If returns 0, it faulted, so we set size to
786b8312 325 * 1 (\0 only).
d0255731 326 */
f127e61e
MD
327#undef _ctf_string
328#define _ctf_string(_item, _src, _user, _nowrite) \
329 if (_user) \
330 __event_len += __dynamic_len[__dynamic_len_idx++] = \
96d0248a 331 max_t(size_t, lttng_strlen_user_inatomic(_src), 1); \
f127e61e
MD
332 else \
333 __event_len += __dynamic_len[__dynamic_len_idx++] = \
96d0248a 334 strlen(_src) + 1;
c6e3f225 335
0d1d4002 336#undef TP_PROTO
f127e61e 337#define TP_PROTO(...) __VA_ARGS__
6db3d13b 338
f127e61e
MD
339#undef TP_FIELDS
340#define TP_FIELDS(...) __VA_ARGS__
6db3d13b 341
7ca580f8
MD
342#undef TP_locvar
343#define TP_locvar(...) __VA_ARGS__
344
3bc29f0a 345#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
f127e61e 346#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
7ca580f8
MD
347static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
348 void *__tp_locvar, _proto) \
0d1d4002
MD
349{ \
350 size_t __event_len = 0; \
d3de7f14 351 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
7ca580f8 352 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
d3de7f14 353 \
f127e61e 354 _fields \
d3de7f14
MD
355 return __event_len; \
356}
357
3bc29f0a 358#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
f127e61e 359#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
7ca580f8
MD
360static inline size_t __event_get_size__##_name(size_t *__dynamic_len, \
361 void *__tp_locvar) \
d3de7f14
MD
362{ \
363 size_t __event_len = 0; \
364 unsigned int __dynamic_len_idx __attribute__((unused)) = 0; \
7ca580f8 365 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
0d1d4002 366 \
f127e61e 367 _fields \
0d1d4002 368 return __event_len; \
6db3d13b 369}
40652b65
MD
370
371#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
372
f127e61e 373
40652b65 374/*
f127e61e 375 * Stage 4.1 of tracepoint event generation.
e763dbf5 376 *
f127e61e
MD
377 * Create static inline function that layout the filter stack data.
378 * We make both write and nowrite data available to the filter.
e763dbf5
MD
379 */
380
f127e61e
MD
381/* Reset all macros within TRACEPOINT_EVENT */
382#include "lttng-events-reset.h"
383#include "lttng-events-write.h"
384#include "lttng-events-nowrite.h"
385
386#undef _ctf_integer_ext_fetched
387#define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
388 if (lttng_is_signed_type(_type)) { \
389 int64_t __ctf_tmp_int64; \
390 switch (sizeof(_type)) { \
391 case 1: \
392 { \
393 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
394 __ctf_tmp_int64 = (int64_t) __tmp.v; \
395 break; \
396 } \
397 case 2: \
398 { \
399 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
400 __ctf_tmp_int64 = (int64_t) __tmp.v; \
401 break; \
402 } \
403 case 4: \
404 { \
405 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
406 __ctf_tmp_int64 = (int64_t) __tmp.v; \
407 break; \
408 } \
409 case 8: \
410 { \
411 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
412 __ctf_tmp_int64 = (int64_t) __tmp.v; \
413 break; \
414 } \
415 default: \
416 BUG_ON(1); \
417 }; \
418 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
419 } else { \
420 uint64_t __ctf_tmp_uint64; \
421 switch (sizeof(_type)) { \
422 case 1: \
423 { \
424 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
425 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
426 break; \
427 } \
428 case 2: \
429 { \
430 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
431 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
432 break; \
433 } \
434 case 4: \
435 { \
436 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
437 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
438 break; \
439 } \
440 case 8: \
441 { \
442 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
443 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
444 break; \
445 } \
446 default: \
447 BUG_ON(1); \
448 }; \
449 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
450 } \
451 __stack_data += sizeof(int64_t);
452
453#undef _ctf_integer_ext_isuser0
454#define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
455 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
456
457#undef _ctf_integer_ext_isuser1
458#define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
76658350
MD
459{ \
460 union { \
461 char __array[sizeof(_user_src)]; \
462 __typeof__(_user_src) __v; \
463 } __tmp_fetch; \
464 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
465 &(_user_src), sizeof(_user_src))) \
466 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
467 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
f127e61e 468}
e763dbf5 469
f127e61e
MD
470#undef _ctf_integer_ext
471#define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
472 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
473
474#undef _ctf_array_encoded
475#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
476 { \
477 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
478 const void *__ctf_tmp_ptr = (_src); \
479 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
480 __stack_data += sizeof(unsigned long); \
6b272cda
MD
481 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
482 __stack_data += sizeof(void *); \
f127e61e
MD
483 }
484
485#undef _ctf_sequence_encoded
486#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 487 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
f127e61e
MD
488 { \
489 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
490 const void *__ctf_tmp_ptr = (_src); \
491 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
492 __stack_data += sizeof(unsigned long); \
6b272cda
MD
493 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
494 __stack_data += sizeof(void *); \
f127e61e
MD
495 }
496
497#undef _ctf_string
498#define _ctf_string(_item, _src, _user, _nowrite) \
499 { \
500 const void *__ctf_tmp_ptr = (_src); \
6b272cda
MD
501 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
502 __stack_data += sizeof(void *); \
f127e61e 503 }
c6e3f225 504
e763dbf5 505#undef TP_PROTO
f127e61e 506#define TP_PROTO(...) __VA_ARGS__
e763dbf5 507
f127e61e
MD
508#undef TP_FIELDS
509#define TP_FIELDS(...) __VA_ARGS__
e763dbf5 510
7ca580f8
MD
511#undef TP_locvar
512#define TP_locvar(...) __VA_ARGS__
513
f127e61e
MD
514#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
515#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
516static inline \
517void __event_prepare_filter_stack__##_name(char *__stack_data, \
518 void *__tp_locvar) \
e763dbf5 519{ \
7ca580f8
MD
520 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
521 \
f127e61e 522 _fields \
e763dbf5
MD
523}
524
f127e61e
MD
525#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
526#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
527static inline \
528void __event_prepare_filter_stack__##_name(char *__stack_data, \
529 void *__tp_locvar, _proto) \
d3de7f14 530{ \
7ca580f8
MD
531 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
532 \
f127e61e 533 _fields \
d3de7f14
MD
534}
535
e763dbf5
MD
536#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
537
e763dbf5 538/*
f127e61e 539 * Stage 5 of the trace events.
40652b65 540 *
f127e61e 541 * Create static inline function that calculates event payload alignment.
3c4ffab9
MD
542 */
543
f127e61e
MD
544/* Reset all macros within TRACEPOINT_EVENT */
545#include "lttng-events-reset.h"
546#include "lttng-events-write.h"
3c4ffab9 547
f127e61e
MD
548#undef _ctf_integer_ext
549#define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _user, _nowrite) \
550 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
3c4ffab9 551
f127e61e
MD
552#undef _ctf_array_encoded
553#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
554 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
3c4ffab9 555
f127e61e
MD
556#undef _ctf_sequence_encoded
557#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 558 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
f127e61e
MD
559 __event_align = max_t(size_t, __event_align, lttng_alignof(_length_type)); \
560 __event_align = max_t(size_t, __event_align, lttng_alignof(_type));
64c796d8 561
f127e61e
MD
562#undef _ctf_string
563#define _ctf_string(_item, _src, _user, _nowrite)
64c796d8 564
f127e61e
MD
565#undef TP_PROTO
566#define TP_PROTO(...) __VA_ARGS__
84da5206 567
f127e61e
MD
568#undef TP_FIELDS
569#define TP_FIELDS(...) __VA_ARGS__
c6e3f225 570
f127e61e
MD
571#undef TP_locvar
572#define TP_locvar(...) __VA_ARGS__
3c4ffab9 573
f127e61e
MD
574#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
575#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
576static inline size_t __event_get_align__##_name(void *__tp_locvar, _proto) \
577{ \
578 size_t __event_align = 1; \
579 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
580 \
581 _fields \
582 return __event_align; \
583}
3c4ffab9 584
3bc29f0a 585#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
f127e61e
MD
586#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
587static inline size_t __event_get_align__##_name(void *__tp_locvar) \
588{ \
589 size_t __event_align = 1; \
590 struct { _locvar } *tp_locvar __attribute__((unused)) = __tp_locvar; \
591 \
592 _fields \
593 return __event_align; \
594}
d3de7f14 595
3c4ffab9
MD
596#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
597
3c4ffab9 598/*
f127e61e 599 * Stage 6 of tracepoint event generation.
e763dbf5 600 *
f127e61e
MD
601 * Create the probe function. This function calls event size calculation
602 * and writes event data into the buffer.
40652b65
MD
603 */
604
f127e61e
MD
605/* Reset all macros within TRACEPOINT_EVENT */
606#include "lttng-events-reset.h"
607#include "lttng-events-write.h"
c6e3f225 608
f127e61e
MD
609#undef _ctf_integer_ext_fetched
610#define _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite) \
e763dbf5 611 { \
f127e61e
MD
612 _type __tmp = _src; \
613 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
aaa4004a 614 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
f127e61e
MD
615 }
616
617#undef _ctf_integer_ext_isuser0
618#define _ctf_integer_ext_isuser0(_type, _item, _src, _byte_order, _base, _nowrite) \
619 _ctf_integer_ext_fetched(_type, _item, _src, _byte_order, _base, _nowrite)
620
621#undef _ctf_integer_ext_isuser1
622#define _ctf_integer_ext_isuser1(_type, _item, _user_src, _byte_order, _base, _nowrite) \
623{ \
76658350
MD
624 union { \
625 char __array[sizeof(_user_src)]; \
626 __typeof__(_user_src) __v; \
627 } __tmp_fetch; \
628 if (lib_ring_buffer_copy_from_user_check_nofault(__tmp_fetch.__array, \
629 &(_user_src), sizeof(_user_src))) \
630 memset(__tmp_fetch.__array, 0, sizeof(__tmp_fetch.__array)); \
631 _ctf_integer_ext_fetched(_type, _item, __tmp_fetch.__v, _byte_order, _base, _nowrite) \
f127e61e
MD
632}
633
634#undef _ctf_integer_ext
635#define _ctf_integer_ext(_type, _item, _user_src, _byte_order, _base, _user, _nowrite) \
636 _ctf_integer_ext_isuser##_user(_type, _item, _user_src, _byte_order, _base, _nowrite)
637
638#undef _ctf_array_encoded
639#define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _user, _nowrite) \
640 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
641 if (_user) { \
642 __chan->ops->event_write_from_user(&__ctx, _src, sizeof(_type) * (_length)); \
643 } else { \
644 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length)); \
645 }
646
647#undef _ctf_sequence_encoded
648#define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
57ede728 649 _src_length, _encoding, _byte_order, _base, _user, _nowrite) \
84da5206 650 { \
f127e61e
MD
651 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
652 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
653 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
84da5206 654 } \
f127e61e
MD
655 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
656 if (_user) { \
657 __chan->ops->event_write_from_user(&__ctx, _src, \
658 sizeof(_type) * __get_dynamic_len(dest)); \
659 } else { \
660 __chan->ops->event_write(&__ctx, _src, \
661 sizeof(_type) * __get_dynamic_len(dest)); \
662 }
663
664#undef _ctf_string
665#define _ctf_string(_item, _src, _user, _nowrite) \
666 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(*(_src))); \
667 if (_user) { \
668 __chan->ops->event_strcpy_from_user(&__ctx, _src, \
669 __get_dynamic_len(dest)); \
670 } else { \
671 __chan->ops->event_strcpy(&__ctx, _src, \
672 __get_dynamic_len(dest)); \
673 }
e763dbf5
MD
674
675/* Beware: this get len actually consumes the len value */
f127e61e
MD
676#undef __get_dynamic_len
677#define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
e763dbf5
MD
678
679#undef TP_PROTO
f127e61e 680#define TP_PROTO(...) __VA_ARGS__
e763dbf5
MD
681
682#undef TP_ARGS
f127e61e 683#define TP_ARGS(...) __VA_ARGS__
e763dbf5 684
f127e61e
MD
685#undef TP_FIELDS
686#define TP_FIELDS(...) __VA_ARGS__
e763dbf5 687
7ca580f8
MD
688#undef TP_locvar
689#define TP_locvar(...) __VA_ARGS__
690
691#undef TP_code
692#define TP_code(...) __VA_ARGS__
693
c337ddc2
MD
694/*
695 * For state dump, check that "session" argument (mandatory) matches the
696 * session this event belongs to. Ensures that we write state dump data only
697 * into the started session, not into all sessions.
698 */
699#ifdef TP_SESSION_CHECK
700#define _TP_SESSION_CHECK(session, csession) (session == csession)
701#else /* TP_SESSION_CHECK */
702#define _TP_SESSION_CHECK(session, csession) 1
703#endif /* TP_SESSION_CHECK */
704
f9771d39 705/*
f127e61e
MD
706 * Using twice size for filter stack data to hold size and pointer for
707 * each field (worse case). For integers, max size required is 64-bit.
708 * Same for double-precision floats. Those fit within
709 * 2*sizeof(unsigned long) for all supported architectures.
710 * Perform UNION (||) of filter runtime list.
f9771d39 711 */
3bc29f0a 712#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE
f127e61e 713#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE(_name, _proto, _args, _locvar, _code, _fields) \
e763dbf5
MD
714static void __event_probe__##_name(void *__data, _proto) \
715{ \
7ca580f8 716 struct probe_local_vars { _locvar }; \
a90917c3
MD
717 struct lttng_event *__event = __data; \
718 struct lttng_channel *__chan = __event->chan; \
e0130fab 719 struct lttng_session *__session = __chan->session; \
aaa4004a 720 struct lib_ring_buffer_ctx __ctx; \
e763dbf5 721 size_t __event_len, __event_align; \
d3de7f14 722 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
f127e61e
MD
723 union { \
724 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
725 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
726 } __stackvar; \
e763dbf5 727 int __ret; \
7ca580f8
MD
728 struct probe_local_vars __tp_locvar; \
729 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
730 &__tp_locvar; \
e0130fab 731 struct lttng_pid_tracker *__lpf; \
e763dbf5 732 \
e0130fab 733 if (!_TP_SESSION_CHECK(session, __session)) \
c337ddc2 734 return; \
e0130fab 735 if (unlikely(!ACCESS_ONCE(__session->active))) \
e64957da
MD
736 return; \
737 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
738 return; \
739 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
52fc2e1f 740 return; \
7a09dcb7 741 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
e0130fab
MD
742 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
743 return; \
7ca580f8 744 _code \
f127e61e
MD
745 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
746 struct lttng_bytecode_runtime *bc_runtime; \
747 int __filter_record = __event->has_enablers_without_bytecode; \
748 \
749 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
750 tp_locvar, _args); \
7a09dcb7 751 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
f127e61e
MD
752 if (unlikely(bc_runtime->filter(bc_runtime, \
753 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
754 __filter_record = 1; \
755 } \
756 if (likely(!__filter_record)) \
757 return; \
758 } \
759 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, \
760 tp_locvar, _args); \
7ca580f8 761 __event_align = __event_get_align__##_name(tp_locvar, _args); \
aaa4004a 762 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
e763dbf5 763 __event_align, -1); \
aaa4004a 764 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
e763dbf5
MD
765 if (__ret < 0) \
766 return; \
f127e61e 767 _fields \
aaa4004a 768 __chan->ops->event_commit(&__ctx); \
e763dbf5
MD
769}
770
3bc29f0a 771#undef LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS
f127e61e 772#define LTTNG_TRACEPOINT_EVENT_CLASS_CODE_NOARGS(_name, _locvar, _code, _fields) \
f7bdf4db
MD
773static void __event_probe__##_name(void *__data) \
774{ \
7ca580f8 775 struct probe_local_vars { _locvar }; \
a90917c3
MD
776 struct lttng_event *__event = __data; \
777 struct lttng_channel *__chan = __event->chan; \
e0130fab 778 struct lttng_session *__session = __chan->session; \
f7bdf4db
MD
779 struct lib_ring_buffer_ctx __ctx; \
780 size_t __event_len, __event_align; \
d3de7f14 781 size_t __dynamic_len_idx __attribute__((unused)) = 0; \
f127e61e
MD
782 union { \
783 size_t __dynamic_len[ARRAY_SIZE(__event_fields___##_name)]; \
784 char __filter_stack_data[2 * sizeof(unsigned long) * ARRAY_SIZE(__event_fields___##_name)]; \
785 } __stackvar; \
f7bdf4db 786 int __ret; \
7ca580f8
MD
787 struct probe_local_vars __tp_locvar; \
788 struct probe_local_vars *tp_locvar __attribute__((unused)) = \
789 &__tp_locvar; \
e0130fab 790 struct lttng_pid_tracker *__lpf; \
f7bdf4db 791 \
e0130fab 792 if (!_TP_SESSION_CHECK(session, __session)) \
c337ddc2 793 return; \
e0130fab 794 if (unlikely(!ACCESS_ONCE(__session->active))) \
f7bdf4db
MD
795 return; \
796 if (unlikely(!ACCESS_ONCE(__chan->enabled))) \
797 return; \
798 if (unlikely(!ACCESS_ONCE(__event->enabled))) \
799 return; \
7a09dcb7 800 __lpf = lttng_rcu_dereference(__session->pid_tracker); \
e0130fab
MD
801 if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->pid))) \
802 return; \
7ca580f8 803 _code \
f127e61e
MD
804 if (unlikely(!list_empty(&__event->bytecode_runtime_head))) { \
805 struct lttng_bytecode_runtime *bc_runtime; \
806 int __filter_record = __event->has_enablers_without_bytecode; \
807 \
808 __event_prepare_filter_stack__##_name(__stackvar.__filter_stack_data, \
809 tp_locvar); \
7a09dcb7 810 lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
f127e61e
MD
811 if (unlikely(bc_runtime->filter(bc_runtime, \
812 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
813 __filter_record = 1; \
814 } \
815 if (likely(!__filter_record)) \
816 return; \
817 } \
818 __event_len = __event_get_size__##_name(__stackvar.__dynamic_len, tp_locvar); \
7ca580f8 819 __event_align = __event_get_align__##_name(tp_locvar); \
f7bdf4db
MD
820 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
821 __event_align, -1); \
822 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
823 if (__ret < 0) \
824 return; \
f127e61e 825 _fields \
f7bdf4db 826 __chan->ops->event_commit(&__ctx); \
f7bdf4db
MD
827}
828
e763dbf5
MD
829#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
830
f127e61e
MD
831#undef __get_dynamic_len
832
833/*
834 * Stage 7 of the trace events.
835 *
836 * Create event descriptions.
837 */
838
839/* Named field types must be defined in lttng-types.h */
840
841#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
842
843#ifndef TP_PROBE_CB
844#define TP_PROBE_CB(_template) &__event_probe__##_template
845#endif
846
847#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
848#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
849static const struct lttng_event_desc __event_desc___##_map = { \
850 .fields = __event_fields___##_template, \
851 .name = #_map, \
852 .kname = #_name, \
853 .probe_callback = (void *) TP_PROBE_CB(_template), \
854 .nr_fields = ARRAY_SIZE(__event_fields___##_template), \
855 .owner = THIS_MODULE, \
856};
857
858#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
859#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
860 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
861
862#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
863
864/*
865 * Stage 8 of the trace events.
866 *
867 * Create an array of event description pointers.
868 */
869
870#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
871
872#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS
873#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map) \
874 &__event_desc___##_map,
875
876#undef LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP
877#define LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(_template, _name, _map, _proto, _args) \
878 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP_NOARGS(_template, _name, _map)
879
880#define TP_ID1(_token, _system) _token##_system
881#define TP_ID(_token, _system) TP_ID1(_token, _system)
882
883static const struct lttng_event_desc *TP_ID(__event_desc___, TRACE_SYSTEM)[] = {
884#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
885};
886
887#undef TP_ID1
888#undef TP_ID
889
890/*
891 * Stage 9 of the trace events.
892 *
893 * Create a toplevel descriptor for the whole probe.
894 */
895
896#define TP_ID1(_token, _system) _token##_system
897#define TP_ID(_token, _system) TP_ID1(_token, _system)
898
899/* non-const because list head will be modified when registered. */
900static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
901 .provider = __stringify(TRACE_SYSTEM),
902 .event_desc = TP_ID(__event_desc___, TRACE_SYSTEM),
903 .nr_events = ARRAY_SIZE(TP_ID(__event_desc___, TRACE_SYSTEM)),
904 .head = { NULL, NULL },
905 .lazy_init_head = { NULL, NULL },
906 .lazy = 0,
907};
908
909#undef TP_ID1
910#undef TP_ID
911
3afe7aac 912/*
c099397a 913 * Stage 10 of the trace events.
3afe7aac
MD
914 *
915 * Register/unregister probes at module load/unload.
916 */
917
f127e61e 918#include "lttng-events-reset.h" /* Reset all macros within LTTNG_TRACEPOINT_EVENT */
3afe7aac
MD
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
This page took 0.081001 seconds and 4 git commands to generate.