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