1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
5 * Holds LTTng per-session event registry.
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #ifndef _LTTNG_EVENTS_H
11 #define _LTTNG_EVENTS_H
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>
26 #define lttng_is_signed_type(type) (((type) -1) < (type) 1)
29 struct lttng_kernel_session
;
30 struct lttng_kernel_ring_buffer_ctx
;
32 /* Type description */
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
,
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
,
57 struct lttng_kernel_enum_value
{
58 unsigned long long value
;
59 unsigned int signedness
:1;
62 struct lttng_kernel_enum_entry
{
63 struct lttng_kernel_enum_value start
, end
; /* start and end are inclusive */
66 unsigned int is_auto
:1;
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.
74 struct lttng_kernel_type_common
{
75 enum lttng_kernel_type type
;
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,
84 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
87 struct lttng_kernel_type_string
{
88 struct lttng_kernel_type_common parent
;
89 enum lttng_kernel_string_encoding encoding
;
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
;
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
;
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
;
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
;
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
;
129 struct lttng_kernel_enum_desc
{
131 const struct lttng_kernel_enum_entry
**entries
;
132 unsigned int nr_entries
;
135 /* Event field description */
137 struct lttng_kernel_event_field
{
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 */
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, { \
148 .type = lttng_kernel_type_integer, \
151 .alignment = (_alignment), \
152 .signedness = (_signedness), \
153 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
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), \
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, { \
167 .type = lttng_kernel_type_enum, \
170 .container_type = (_container_type), \
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, { \
176 .type = lttng_kernel_type_array, \
178 .length = (_length), \
179 .alignment = (_alignment), \
180 .encoding = lttng_kernel_string_encoding_##_encoding, \
181 .elem_type = (_elem_type), \
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), \
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, { \
194 .type = lttng_kernel_type_sequence, \
196 .length_name = (_length_name), \
197 .alignment = (_alignment), \
198 .encoding = lttng_kernel_string_encoding_##_encoding, \
199 .elem_type = (_elem_type), \
202 #define lttng_kernel_static_type_string(_encoding) \
203 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
205 .type = lttng_kernel_type_string, \
207 .encoding = lttng_kernel_string_encoding_##_encoding, \
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, { \
213 .type = lttng_kernel_type_struct, \
215 .nr_fields = (_nr_fields), \
217 .alignment = (_alignment), \
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, { \
223 .type = lttng_kernel_type_variant, \
225 .tag_name = (_tag_name), \
226 .choices = _choices, \
227 .nr_choices = (_nr_choices), \
228 .alignment = (_alignment), \
231 #define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \
232 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
235 .nowrite = (_nowrite), \
237 .nofilter = (_nofilter), \
240 #define lttng_kernel_static_event_field_array(_fields...) \
241 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
245 #define lttng_kernel_static_enum_entry_value(_string, _value) \
246 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
248 .signedness = lttng_is_signed_type(__typeof__(_value)), \
249 .value = lttng_is_signed_type(__typeof__(_value)) ? \
250 (long long) (_value) : (_value), \
253 .signedness = lttng_is_signed_type(__typeof__(_value)), \
254 .value = lttng_is_signed_type(__typeof__(_value)) ? \
255 (long long) (_value) : (_value), \
257 .string = (_string), \
260 #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
261 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
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), \
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), \
272 .string = (_string), \
275 #define lttng_kernel_static_enum_entry_auto(_string) \
276 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
285 .string = (_string), \
291 struct lttng_kernel_probe_ctx
{
292 struct lttng_kernel_event_common
*event
;
293 uint8_t interruptible
;
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
;
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 */
316 * Result of the run_filter() callback.
318 enum lttng_kernel_event_filter_result
{
319 LTTNG_KERNEL_EVENT_FILTER_ACCEPT
= 0,
320 LTTNG_KERNEL_EVENT_FILTER_REJECT
= 1,
323 struct lttng_kernel_event_common_private
;
325 enum lttng_kernel_event_type
{
326 LTTNG_KERNEL_EVENT_TYPE_RECORDER
= 0,
327 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER
= 1,
330 struct lttng_kernel_event_common
{
331 struct lttng_kernel_event_common_private
*priv
; /* Private event interface */
333 enum lttng_kernel_event_type type
;
334 /* Get child with container_of(). */
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
,
344 struct lttng_kernel_event_recorder_private
;
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 */
350 struct lttng_channel
*chan
;
353 struct lttng_kernel_notification_ctx
{
354 int eval_capture
; /* Capture evaluation available. */
357 struct lttng_kernel_event_notifier_private
;
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 */
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
);
370 struct lttng_kernel_channel_buffer_ops
{
371 struct lttng_kernel_channel_buffer_ops_private
*priv
; /* Private channel buffer ops interface. */
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
,
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
,
381 void (*event_strcpy
)(struct lttng_kernel_ring_buffer_ctx
*ctx
, const char *src
,
383 void (*event_strcpy_from_user
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
384 const char __user
*src
, size_t len
);
387 struct lttng_channel
{
389 struct channel
*chan
; /* Channel buffers */
391 struct lttng_kernel_ctx
*ctx
;
392 /* Event ID management */
393 struct lttng_kernel_session
*session
;
394 struct file
*file
; /* File associated to channel */
395 unsigned int free_event_id
; /* Next event ID to allocate */
396 struct list_head list
; /* Channel list */
397 struct lttng_kernel_channel_buffer_ops
*ops
;
398 struct lttng_transport
*transport
;
399 struct hlist_head
*sc_table
; /* for syscall tracing */
400 struct hlist_head
*compat_sc_table
;
401 struct hlist_head
*sc_exit_table
; /* for syscall exit tracing */
402 struct hlist_head
*compat_sc_exit_table
;
403 struct hlist_head sc_unknown
; /* for unknown syscalls */
404 struct hlist_head sc_compat_unknown
;
405 struct hlist_head sc_exit_unknown
;
406 struct hlist_head compat_sc_exit_unknown
;
407 struct lttng_syscall_filter
*sc_filter
;
408 int header_type
; /* 0: unset, 1: compact, 2: large */
409 enum channel_type channel_type
;
410 int syscall_all_entry
;
411 int syscall_all_exit
;
412 unsigned int metadata_dumped
:1,
413 sys_enter_registered
:1,
414 sys_exit_registered
:1,
415 tstate
:1; /* Transient enable state */
418 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
420 struct lttng_dynamic_len_stack
{
421 size_t stack
[LTTNG_DYNAMIC_LEN_STACK_SIZE
];
425 DECLARE_PER_CPU(struct lttng_dynamic_len_stack
, lttng_dynamic_len_stack
);
428 * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
429 * in RCU_INITIALIZER(v).
431 #define LTTNG_ID_HASH_BITS 6
432 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
434 struct lttng_kernel_id_tracker_rcu
{
435 struct hlist_head id_hash
[LTTNG_ID_TABLE_SIZE
];
438 struct lttng_kernel_id_tracker
{
439 struct lttng_kernel_id_tracker_private
*priv
; /* Private API */
441 struct lttng_kernel_id_tracker_rcu
*p
; /* RCU dereferenced. */
444 struct lttng_kernel_session_private
;
446 struct lttng_kernel_session
{
447 struct lttng_kernel_session_private
*priv
; /* Private session interface */
449 int active
; /* Is trace session active ? */
451 struct lttng_kernel_id_tracker pid_tracker
;
452 struct lttng_kernel_id_tracker vpid_tracker
;
453 struct lttng_kernel_id_tracker uid_tracker
;
454 struct lttng_kernel_id_tracker vuid_tracker
;
455 struct lttng_kernel_id_tracker gid_tracker
;
456 struct lttng_kernel_id_tracker vgid_tracker
;
459 int lttng_kernel_probe_register(struct lttng_kernel_probe_desc
*desc
);
460 void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc
*desc
);
462 bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu
*p
, int id
);
464 #endif /* _LTTNG_EVENTS_H */