Fix: bytecode validator: oops during validation of immediate string
[lttng-modules.git] / include / lttng / events.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng/events.h
4 *
5 * Holds LTTng per-session event registry.
6 *
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #ifndef _LTTNG_EVENTS_H
11 #define _LTTNG_EVENTS_H
12
13 #include <lttng/kernel-version.h>
14 #include <linux/list.h>
15 #include <linux/kprobes.h>
16 #include <linux/kref.h>
17 #include <linux/uuid.h>
18 #include <linux/irq_work.h>
19 #include <linux/uprobes.h>
20
21 #include <lttng/cpuhotplug.h>
22 #include <lttng/tracer.h>
23 #include <lttng/abi.h>
24 #include <lttng/abi-old.h>
25 #include <lttng/endian.h>
26
27 #define lttng_is_signed_type(type) (((type) -1) < (type) 1)
28
29 struct lttng_kernel_channel_buffer;
30 struct lttng_kernel_session;
31 struct lttng_kernel_ring_buffer_ctx;
32
33 /* Type description */
34
35 enum lttng_kernel_type {
36 lttng_kernel_type_integer,
37 lttng_kernel_type_string,
38 lttng_kernel_type_enum,
39 lttng_kernel_type_array,
40 lttng_kernel_type_sequence,
41 lttng_kernel_type_struct,
42 lttng_kernel_type_variant,
43 NR_LTTNG_KERNEL_TYPES,
44 };
45
46 enum lttng_kernel_string_encoding {
47 lttng_kernel_string_encoding_none = 0,
48 lttng_kernel_string_encoding_UTF8 = 1,
49 lttng_kernel_string_encoding_ASCII = 2,
50 NR_LTTNG_KERNEL_STRING_ENCODING,
51 };
52
53 struct lttng_kernel_enum_value {
54 unsigned long long value;
55 unsigned int signedness:1;
56 };
57
58 struct lttng_kernel_enum_entry {
59 struct lttng_kernel_enum_value start, end; /* start and end are inclusive */
60 const char *string;
61 struct {
62 unsigned int is_auto:1;
63 } options;
64 };
65
66 /*
67 * struct lttng_kernel_type_common is fixed-size. Its children inherits
68 * from it by embedding struct lttng_kernel_type_common as its first field.
69 */
70 struct lttng_kernel_type_common {
71 enum lttng_kernel_type type;
72 };
73
74 struct lttng_kernel_type_integer {
75 struct lttng_kernel_type_common parent;
76 unsigned int size; /* in bits */
77 unsigned short alignment; /* in bits */
78 unsigned int signedness:1,
79 reverse_byte_order:1,
80 user:1; /* fetch from user-space */
81 unsigned int base; /* 2, 8, 10, 16, for pretty print */
82 };
83
84 struct lttng_kernel_type_string {
85 struct lttng_kernel_type_common parent;
86 enum lttng_kernel_string_encoding encoding;
87 unsigned int user:1; /* fetch from user-space */
88 };
89
90 struct lttng_kernel_type_enum {
91 struct lttng_kernel_type_common parent;
92 const struct lttng_kernel_enum_desc *desc; /* Enumeration mapping */
93 const struct lttng_kernel_type_common *container_type;
94 };
95
96 struct lttng_kernel_type_array {
97 struct lttng_kernel_type_common parent;
98 const struct lttng_kernel_type_common *elem_type;
99 unsigned int length; /* Num. elems. */
100 unsigned int alignment; /* Alignment in bytes before elements. */
101 enum lttng_kernel_string_encoding encoding;
102 };
103
104 struct lttng_kernel_type_sequence {
105 struct lttng_kernel_type_common parent;
106 const char *length_name; /* Length field name. If NULL, use previous field. */
107 const struct lttng_kernel_type_common *elem_type;
108 unsigned int alignment; /* Alignment in bytes before elements. */
109 enum lttng_kernel_string_encoding encoding;
110 };
111
112 struct lttng_kernel_type_struct {
113 struct lttng_kernel_type_common parent;
114 unsigned int nr_fields;
115 const struct lttng_kernel_event_field * const *fields; /* Array of pointers to fields. */
116 unsigned int alignment; /* Alignment in bits */
117 };
118
119 struct lttng_kernel_type_variant {
120 struct lttng_kernel_type_common parent;
121 const char *tag_name; /* Tag field name. If NULL, use previous field. */
122 const struct lttng_kernel_event_field * const *choices; /* Array of pointers to fields. */
123 unsigned int nr_choices;
124 unsigned int alignment; /* Alignment in bytes */
125 };
126
127 struct lttng_kernel_enum_desc {
128 const char *name;
129 const struct lttng_kernel_enum_entry * const *entries;
130 unsigned int nr_entries;
131 const struct lttng_kernel_probe_desc *probe_desc;
132 };
133
134 /* Event field description */
135
136 struct lttng_kernel_event_field {
137 const char *name;
138 const struct lttng_kernel_type_common *type;
139 unsigned int nowrite:1, /* do not write into trace */
140 nofilter:1; /* do not consider for filter */
141 };
142
143 #ifndef PARAMS
144 #define PARAMS(args...) args
145 #endif
146
147 #define _lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _user, _base) \
148 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
149 .parent = { \
150 .type = lttng_kernel_type_integer, \
151 }, \
152 .size = (_size), \
153 .alignment = (_alignment), \
154 .signedness = (_signedness), \
155 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
156 .user = (_user), \
157 .base = (_base), \
158 }))
159
160 #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
161 _lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, 0, _base)
162
163 #define lttng_kernel_static_type_user_integer(_size, _alignment, _signedness, _byte_order, _base) \
164 _lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, 1, _base)
165
166 #define _lttng_kernel_static_type_integer_from_type(_type, _byte_order, _user, _base) \
167 _lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
168 lttng_alignof(_type) * CHAR_BIT, \
169 lttng_is_signed_type(_type), \
170 _byte_order, _user, _base)
171
172 #define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
173 _lttng_kernel_static_type_integer_from_type(_type, _byte_order, 0, _base)
174
175 #define lttng_kernel_static_type_user_integer_from_type(_type, _byte_order, _base) \
176 _lttng_kernel_static_type_integer_from_type(_type, _byte_order, 1, _base)
177
178 #define lttng_kernel_static_type_enum(_desc, _container_type) \
179 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
180 .parent = { \
181 .type = lttng_kernel_type_enum, \
182 }, \
183 .desc = (_desc), \
184 .container_type = (_container_type), \
185 }))
186
187 #define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
188 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
189 .parent = { \
190 .type = lttng_kernel_type_array, \
191 }, \
192 .length = (_length), \
193 .alignment = (_alignment), \
194 .encoding = lttng_kernel_string_encoding_##_encoding, \
195 .elem_type = (_elem_type), \
196 }))
197
198 #define lttng_kernel_static_type_array_text(_length) \
199 lttng_kernel_static_type_array(_length, \
200 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
201 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
202 __BYTE_ORDER, 10), \
203 0, UTF8)
204
205 #define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
206 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
207 .parent = { \
208 .type = lttng_kernel_type_sequence, \
209 }, \
210 .length_name = (_length_name), \
211 .alignment = (_alignment), \
212 .encoding = lttng_kernel_string_encoding_##_encoding, \
213 .elem_type = (_elem_type), \
214 }))
215
216 #define lttng_kernel_static_type_string(_encoding, _user) \
217 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
218 .parent = { \
219 .type = lttng_kernel_type_string, \
220 }, \
221 .encoding = lttng_kernel_string_encoding_##_encoding, \
222 .user = (_user), \
223 }))
224
225 #define lttng_kernel_static_type_struct_init(_nr_fields, _fields, _alignment) \
226 { \
227 .parent = { \
228 .type = lttng_kernel_type_struct, \
229 }, \
230 .nr_fields = (_nr_fields), \
231 .fields = _fields, \
232 .alignment = (_alignment), \
233 }
234
235 #define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
236 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, \
237 lttng_kernel_static_type_struct_init(_nr_fields, PARAMS(_fields), _alignment) \
238 ))
239
240 #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
241 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
242 .parent = { \
243 .type = lttng_kernel_type_variant, \
244 }, \
245 .tag_name = (_tag_name), \
246 .choices = _choices, \
247 .nr_choices = (_nr_choices), \
248 .alignment = (_alignment), \
249 }))
250
251 #define lttng_kernel_static_event_field(_name, _type, _nowrite, _nofilter) \
252 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
253 .name = (_name), \
254 .type = (_type), \
255 .nowrite = (_nowrite), \
256 .nofilter = (_nofilter), \
257 })
258
259 #define lttng_kernel_static_event_field_array(_fields...) \
260 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
261 _fields \
262 )
263
264 #define lttng_kernel_static_enum_entry_value(_string, _value) \
265 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
266 .start = { \
267 .signedness = lttng_is_signed_type(__typeof__(_value)), \
268 .value = lttng_is_signed_type(__typeof__(_value)) ? \
269 (long long) (_value) : (_value), \
270 }, \
271 .end = { \
272 .signedness = lttng_is_signed_type(__typeof__(_value)), \
273 .value = lttng_is_signed_type(__typeof__(_value)) ? \
274 (long long) (_value) : (_value), \
275 }, \
276 .string = (_string), \
277 }),
278
279 #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
280 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
281 .start = { \
282 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
283 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
284 (long long) (_range_start) : (_range_start), \
285 }, \
286 .end = { \
287 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
288 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
289 (long long) (_range_end) : (_range_end), \
290 }, \
291 .string = (_string), \
292 }),
293
294 #define lttng_kernel_static_enum_entry_auto(_string) \
295 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
296 .start = { \
297 .signedness = -1, \
298 .value = -1, \
299 }, \
300 .end = { \
301 .signedness = -1, \
302 .value = -1, \
303 }, \
304 .string = (_string), \
305 .options = { \
306 .is_auto = 1, \
307 } \
308 }),
309
310 struct lttng_kernel_probe_ctx {
311 struct lttng_kernel_event_common *event;
312 uint8_t interruptible;
313 };
314
315 struct lttng_kernel_tracepoint_class {
316 void (*probe_callback)(void);
317 const struct lttng_kernel_event_field * const *fields; /* event payload */
318 unsigned int nr_fields;
319 const struct lttng_kernel_probe_desc *probe_desc;
320 };
321
322 struct lttng_kernel_event_desc {
323 const char *event_name; /* lttng-modules name */
324 const char *event_kname; /* Linux kernel name (tracepoints) */
325 const struct lttng_kernel_probe_desc *probe_desc;
326 const struct lttng_kernel_tracepoint_class *tp_class;
327 struct module *owner;
328 };
329
330 struct lttng_kernel_probe_desc {
331 const char *provider_name;
332 const struct lttng_kernel_event_desc * const *event_desc;
333 unsigned int nr_events;
334 struct list_head head; /* chain registered probes */
335 struct list_head lazy_init_head;
336 int lazy; /* lazy registration */
337 };
338
339 /*
340 * Result of the run_filter() callback.
341 */
342 enum lttng_kernel_event_filter_result {
343 LTTNG_KERNEL_EVENT_FILTER_ACCEPT = 0,
344 LTTNG_KERNEL_EVENT_FILTER_REJECT = 1,
345 };
346
347 struct lttng_kernel_event_common_private;
348
349 enum lttng_kernel_event_type {
350 LTTNG_KERNEL_EVENT_TYPE_RECORDER = 0,
351 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER = 1,
352 };
353
354 struct lttng_kernel_event_common {
355 struct lttng_kernel_event_common_private *priv; /* Private event interface */
356
357 enum lttng_kernel_event_type type;
358 /* Get child with container_of(). */
359
360 int enabled;
361 int eval_filter; /* Need to evaluate filters */
362 int (*run_filter)(const struct lttng_kernel_event_common *event,
363 const char *stack_data,
364 struct lttng_kernel_probe_ctx *probe_ctx,
365 void *filter_ctx);
366 };
367
368 struct lttng_kernel_event_recorder_private;
369
370 struct lttng_kernel_event_recorder {
371 struct lttng_kernel_event_common parent;
372 struct lttng_kernel_event_recorder_private *priv; /* Private event record interface */
373
374 struct lttng_kernel_channel_buffer *chan;
375 };
376
377 struct lttng_kernel_notification_ctx {
378 int eval_capture; /* Capture evaluation available. */
379 };
380
381 struct lttng_kernel_event_notifier_private;
382
383 struct lttng_kernel_event_notifier {
384 struct lttng_kernel_event_common parent;
385 struct lttng_kernel_event_notifier_private *priv; /* Private event notifier interface */
386
387 int eval_capture; /* Need to evaluate capture */
388 void (*notification_send)(struct lttng_kernel_event_notifier *event_notifier,
389 const char *stack_data,
390 struct lttng_kernel_probe_ctx *probe_ctx,
391 struct lttng_kernel_notification_ctx *notif_ctx);
392 };
393
394 struct lttng_kernel_channel_buffer_ops {
395 struct lttng_kernel_channel_buffer_ops_private *priv; /* Private channel buffer ops interface. */
396
397 int (*event_reserve)(struct lttng_kernel_ring_buffer_ctx *ctx);
398 void (*event_commit)(struct lttng_kernel_ring_buffer_ctx *ctx);
399 void (*event_write)(struct lttng_kernel_ring_buffer_ctx *ctx, const void *src,
400 size_t len, size_t alignment);
401 void (*event_write_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
402 const void *src, size_t len, size_t alignment);
403 void (*event_memset)(struct lttng_kernel_ring_buffer_ctx *ctx,
404 int c, size_t len);
405 void (*event_strcpy)(struct lttng_kernel_ring_buffer_ctx *ctx, const char *src,
406 size_t len);
407 void (*event_strcpy_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
408 const char __user *src, size_t len);
409 void (*event_pstrcpy_pad)(struct lttng_kernel_ring_buffer_ctx *ctx,
410 const char *src, size_t len);
411 void (*event_pstrcpy_pad_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
412 const char __user *src, size_t len);
413 void (*lost_event_too_big)(struct lttng_kernel_channel_buffer *lttng_channel);
414 };
415
416 enum lttng_kernel_channel_type {
417 LTTNG_KERNEL_CHANNEL_TYPE_BUFFER = 0,
418 };
419
420 struct lttng_kernel_channel_common_private;
421
422 /* Use container_of() to get child. */
423 struct lttng_kernel_channel_common {
424 struct lttng_kernel_channel_common_private *priv; /* Private channel interface. */
425
426 enum lttng_kernel_channel_type type;
427
428 int enabled;
429 struct lttng_kernel_session *session;
430 };
431
432 struct lttng_kernel_channel_buffer_private;
433
434 struct lttng_kernel_channel_buffer {
435 struct lttng_kernel_channel_common parent;
436 struct lttng_kernel_channel_buffer_private *priv;
437
438 struct lttng_kernel_channel_buffer_ops *ops;
439 };
440
441 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
442
443 struct lttng_dynamic_len_stack {
444 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
445 size_t offset;
446 };
447
448 DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
449
450 /*
451 * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
452 * in RCU_INITIALIZER(v).
453 */
454 #define LTTNG_ID_HASH_BITS 6
455 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
456
457 struct lttng_kernel_id_tracker_rcu {
458 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
459 };
460
461 struct lttng_kernel_id_tracker {
462 struct lttng_kernel_id_tracker_private *priv; /* Private API */
463
464 struct lttng_kernel_id_tracker_rcu *p; /* RCU dereferenced. */
465 };
466
467 struct lttng_kernel_session_private;
468
469 struct lttng_kernel_session {
470 struct lttng_kernel_session_private *priv; /* Private session interface */
471
472 int active; /* Is trace session active ? */
473
474 struct lttng_kernel_id_tracker pid_tracker;
475 struct lttng_kernel_id_tracker vpid_tracker;
476 struct lttng_kernel_id_tracker uid_tracker;
477 struct lttng_kernel_id_tracker vuid_tracker;
478 struct lttng_kernel_id_tracker gid_tracker;
479 struct lttng_kernel_id_tracker vgid_tracker;
480 };
481
482 int lttng_kernel_probe_register(struct lttng_kernel_probe_desc *desc);
483 void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc *desc);
484
485 bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu *p, int id);
486
487 #endif /* _LTTNG_EVENTS_H */
This page took 0.040047 seconds and 4 git commands to generate.