Group all syscall enums in one compile unit
[lttng-modules.git] / include / lttng / events.h
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
2df37e95 3 * lttng/events.h
4e3c1b9b 4 *
4e3c1b9b 5 * Holds LTTng per-session event registry.
17baffe2 6 *
886d51a3 7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4e3c1b9b
MD
8 */
9
9f36eaed
MJ
10#ifndef _LTTNG_EVENTS_H
11#define _LTTNG_EVENTS_H
12
5f4c791e 13#include <lttng/kernel-version.h>
4e3c1b9b 14#include <linux/list.h>
d6d808f3 15#include <linux/kprobes.h>
d83004aa 16#include <linux/kref.h>
41f229dc 17#include <linux/uuid.h>
754d534a 18#include <linux/irq_work.h>
149b9a9d 19#include <wrapper/uprobes.h>
2df37e95
MD
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>
4e3c1b9b 25
e97dc605 26#define lttng_is_signed_type(type) (((type) -1) < (type) 1)
9e7e4892 27
a90917c3 28struct lttng_channel;
a40e3229 29struct lttng_kernel_session;
e27e4381 30struct lttng_kernel_ring_buffer_ctx;
4e3c1b9b 31
c0edae1d
MD
32/* Type description */
33
12bb2edb
MD
34enum lttng_kernel_type {
35 lttng_kernel_type_integer,
36 lttng_kernel_type_string,
437d5aa5
MD
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,
12bb2edb 42 NR_LTTNG_KERNEL_TYPES,
c0edae1d
MD
43};
44
28cbcb59
MD
45enum 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,
c0edae1d
MD
50};
51
d83004aa
JD
52enum channel_type {
53 PER_CPU_CHANNEL,
54 METADATA_CHANNEL,
55};
56
a28cc520 57struct lttng_kernel_enum_value {
141ddf28
MD
58 unsigned long long value;
59 unsigned int signedness:1;
60};
61
a28cc520
MD
62struct lttng_kernel_enum_entry {
63 struct lttng_kernel_enum_value start, end; /* start and end are inclusive */
c0edae1d 64 const char *string;
08ad1061
PP
65 struct {
66 unsigned int is_auto:1;
67 } options;
c0edae1d
MD
68};
69
437d5aa5
MD
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 */
74struct lttng_kernel_type_common {
75 enum lttng_kernel_type type;
76};
77
78struct lttng_kernel_type_integer {
79 struct lttng_kernel_type_common parent;
c099397a
MD
80 unsigned int size; /* in bits */
81 unsigned short alignment; /* in bits */
9cccf98a
MD
82 unsigned int signedness:1,
83 reverse_byte_order:1;
e0a7a7c4 84 unsigned int base; /* 2, 8, 10, 16, for pretty print */
437d5aa5
MD
85};
86
87struct lttng_kernel_type_string {
88 struct lttng_kernel_type_common parent;
28cbcb59 89 enum lttng_kernel_string_encoding encoding;
c099397a
MD
90};
91
437d5aa5
MD
92struct 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
98struct 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
106struct lttng_kernel_type_sequence {
107 struct lttng_kernel_type_common parent;
f0039724 108 const char *length_name; /* Length field name. If NULL, use previous field. */
437d5aa5
MD
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
114struct 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
121struct lttng_kernel_type_variant {
122 struct lttng_kernel_type_common parent;
f0039724 123 const char *tag_name; /* Tag field name. If NULL, use previous field. */
437d5aa5
MD
124 const struct lttng_kernel_event_field **choices; /* Array of pointers to fields. */
125 unsigned int nr_choices;
126 unsigned int alignment;
c099397a
MD
127};
128
d96a4a7a 129struct lttng_kernel_enum_desc {
c099397a 130 const char *name;
437d5aa5 131 const struct lttng_kernel_enum_entry **entries;
141ddf28 132 unsigned int nr_entries;
c099397a 133};
c0edae1d
MD
134
135/* Event field description */
136
437d5aa5 137struct lttng_kernel_event_field {
c0edae1d 138 const char *name;
437d5aa5 139 const struct lttng_kernel_type_common *type;
f127e61e 140 unsigned int nowrite:1, /* do not write into trace */
ceabb767
MD
141 user:1, /* fetch from user-space */
142 nofilter:1; /* do not consider for filter */
c0edae1d
MD
143};
144
16e1064f
FD
145#ifndef PARAMS
146#define PARAMS(args...) args
147#endif
148
437d5aa5
MD
149#define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
150 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
151 .parent = { \
152 .type = lttng_kernel_type_integer, \
153 }, \
154 .size = (_size), \
155 .alignment = (_alignment), \
156 .signedness = (_signedness), \
157 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
158 .base = (_base), \
159 }))
160
161#define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
162 lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
163 lttng_alignof(_type) * CHAR_BIT, \
164 lttng_is_signed_type(_type), \
165 _byte_order, \
166 _base)
167
168#define lttng_kernel_static_type_enum(_desc, _container_type) \
169 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
170 .parent = { \
171 .type = lttng_kernel_type_enum, \
172 }, \
173 .desc = (_desc), \
174 .container_type = (_container_type), \
175 }))
176
177#define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
178 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
179 .parent = { \
180 .type = lttng_kernel_type_array, \
181 }, \
182 .length = (_length), \
183 .alignment = (_alignment), \
184 .encoding = lttng_kernel_string_encoding_##_encoding, \
185 .elem_type = (_elem_type), \
186 }))
187
188#define lttng_kernel_static_type_array_text(_length) \
189 lttng_kernel_static_type_array(_length, \
190 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
191 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
192 __BYTE_ORDER, 10), \
193 0, UTF8)
194
195#define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
196 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
197 .parent = { \
198 .type = lttng_kernel_type_sequence, \
199 }, \
200 .length_name = (_length_name), \
201 .alignment = (_alignment), \
202 .encoding = lttng_kernel_string_encoding_##_encoding, \
203 .elem_type = (_elem_type), \
204 }))
205
206#define lttng_kernel_static_type_string(_encoding) \
207 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
208 .parent = { \
209 .type = lttng_kernel_type_string, \
210 }, \
211 .encoding = lttng_kernel_string_encoding_##_encoding, \
212 }))
213
16e1064f
FD
214#define lttng_kernel_static_type_struct_init(_nr_fields, _fields, _alignment) \
215 { \
437d5aa5
MD
216 .parent = { \
217 .type = lttng_kernel_type_struct, \
218 }, \
219 .nr_fields = (_nr_fields), \
220 .fields = _fields, \
221 .alignment = (_alignment), \
16e1064f
FD
222 }
223
224#define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
225 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, \
226 lttng_kernel_static_type_struct_init(_nr_fields, PARAMS(_fields), _alignment) \
227 ))
437d5aa5
MD
228
229#define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
230 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
231 .parent = { \
232 .type = lttng_kernel_type_variant, \
233 }, \
234 .tag_name = (_tag_name), \
235 .choices = _choices, \
236 .nr_choices = (_nr_choices), \
237 .alignment = (_alignment), \
238 }))
239
240#define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \
241 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
242 .name = (_name), \
243 .type = (_type), \
244 .nowrite = (_nowrite), \
245 .user = (_user), \
246 .nofilter = (_nofilter), \
247 })
248
249#define lttng_kernel_static_event_field_array(_fields...) \
250 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
251 _fields \
252 )
253
437d5aa5
MD
254#define lttng_kernel_static_enum_entry_value(_string, _value) \
255 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
256 .start = { \
257 .signedness = lttng_is_signed_type(__typeof__(_value)), \
258 .value = lttng_is_signed_type(__typeof__(_value)) ? \
259 (long long) (_value) : (_value), \
260 }, \
261 .end = { \
262 .signedness = lttng_is_signed_type(__typeof__(_value)), \
263 .value = lttng_is_signed_type(__typeof__(_value)) ? \
264 (long long) (_value) : (_value), \
265 }, \
266 .string = (_string), \
267 }),
268
269#define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
270 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
271 .start = { \
272 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
273 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
274 (long long) (_range_start) : (_range_start), \
275 }, \
276 .end = { \
277 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
278 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
279 (long long) (_range_end) : (_range_end), \
280 }, \
281 .string = (_string), \
282 }),
283
284#define lttng_kernel_static_enum_entry_auto(_string) \
285 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
286 .start = { \
287 .signedness = -1, \
288 .value = -1, \
289 }, \
290 .end = { \
291 .signedness = -1, \
292 .value = -1, \
293 }, \
294 .string = (_string), \
295 .options = { \
296 .is_auto = 1, \
297 } \
298 }),
299
346cb5ee 300struct lttng_kernel_probe_ctx {
e2d5dbc7 301 struct lttng_kernel_event_common *event;
79150a49
JD
302 uint8_t interruptible;
303};
304
437d5aa5
MD
305struct lttng_kernel_event_desc {
306 const char *event_name; /* lttng-modules name */
307 const char *event_kname; /* Linux kernel name (tracepoints) */
308 const struct lttng_kernel_probe_desc *probe_desc;
309 void (*probe_callback)(void);
310 const struct lttng_kernel_event_field **fields; /* event payload */
c0edae1d 311 unsigned int nr_fields;
dc7f600a 312 struct module *owner;
c0edae1d
MD
313};
314
437d5aa5
MD
315struct lttng_kernel_probe_desc {
316 const char *provider_name;
317 const struct lttng_kernel_event_desc **event_desc;
85a9ca7f
MD
318 unsigned int nr_events;
319 struct list_head head; /* chain registered probes */
3c997079
MD
320 struct list_head lazy_init_head;
321 int lazy; /* lazy registration */
85a9ca7f
MD
322};
323
8a445457
MD
324/*
325 * Result of the run_filter() callback.
326 */
327enum lttng_kernel_event_filter_result {
328 LTTNG_KERNEL_EVENT_FILTER_ACCEPT = 0,
329 LTTNG_KERNEL_EVENT_FILTER_REJECT = 1,
330};
331
a67ba386
MD
332struct lttng_kernel_event_common_private;
333
334enum lttng_kernel_event_type {
335 LTTNG_KERNEL_EVENT_TYPE_RECORDER = 0,
336 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER = 1,
337};
338
339struct lttng_kernel_event_common {
340 struct lttng_kernel_event_common_private *priv; /* Private event interface */
341
342 enum lttng_kernel_event_type type;
343 /* Get child with container_of(). */
344
e64957da 345 int enabled;
a67ba386 346 int eval_filter; /* Need to evaluate filters */
8a445457 347 int (*run_filter)(const struct lttng_kernel_event_common *event,
a67ba386 348 const char *stack_data,
346cb5ee 349 struct lttng_kernel_probe_ctx *probe_ctx,
a67ba386 350 void *filter_ctx);
3c997079
MD
351};
352
a67ba386
MD
353struct lttng_kernel_event_recorder_private;
354
355struct lttng_kernel_event_recorder {
356 struct lttng_kernel_event_common parent;
357 struct lttng_kernel_event_recorder_private *priv; /* Private event record interface */
358
359 struct lttng_channel *chan;
c3eddb2e
MD
360};
361
a67ba386
MD
362struct lttng_kernel_notification_ctx {
363 int eval_capture; /* Capture evaluation available. */
364};
dffef45d 365
a67ba386 366struct lttng_kernel_event_notifier_private;
8a8ac9a8 367
a67ba386
MD
368struct lttng_kernel_event_notifier {
369 struct lttng_kernel_event_common parent;
370 struct lttng_kernel_event_notifier_private *priv; /* Private event notifier interface */
dffef45d 371
a67ba386
MD
372 int eval_capture; /* Need to evaluate capture */
373 void (*notification_send)(struct lttng_kernel_event_notifier *event_notifier,
a67ba386 374 const char *stack_data,
346cb5ee 375 struct lttng_kernel_probe_ctx *probe_ctx,
a67ba386 376 struct lttng_kernel_notification_ctx *notif_ctx);
dffef45d
FD
377};
378
da1fe18f
MD
379struct lttng_kernel_channel_buffer_ops {
380 struct lttng_kernel_channel_buffer_ops_private *priv; /* Private channel buffer ops interface. */
381
e27e4381
MD
382 int (*event_reserve)(struct lttng_kernel_ring_buffer_ctx *ctx);
383 void (*event_commit)(struct lttng_kernel_ring_buffer_ctx *ctx);
384 void (*event_write)(struct lttng_kernel_ring_buffer_ctx *ctx, const void *src,
85a9ca7f 385 size_t len);
e27e4381 386 void (*event_write_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
4ea00e4f 387 const void *src, size_t len);
e27e4381 388 void (*event_memset)(struct lttng_kernel_ring_buffer_ctx *ctx,
58aa5d24 389 int c, size_t len);
e27e4381 390 void (*event_strcpy)(struct lttng_kernel_ring_buffer_ctx *ctx, const char *src,
16f78f3a 391 size_t len);
e27e4381 392 void (*event_strcpy_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
16f78f3a 393 const char __user *src, size_t len);
85a9ca7f
MD
394};
395
a90917c3 396struct lttng_channel {
c099397a 397 unsigned int id;
85a9ca7f 398 struct channel *chan; /* Channel buffers */
e64957da 399 int enabled;
437d5aa5 400 struct lttng_kernel_ctx *ctx;
85a9ca7f 401 /* Event ID management */
a40e3229 402 struct lttng_kernel_session *session;
85a9ca7f
MD
403 struct file *file; /* File associated to channel */
404 unsigned int free_event_id; /* Next event ID to allocate */
405 struct list_head list; /* Channel list */
da1fe18f 406 struct lttng_kernel_channel_buffer_ops *ops;
a90917c3 407 struct lttng_transport *transport;
3b82c4e1
MD
408 struct hlist_head *sc_table; /* for syscall tracing */
409 struct hlist_head *compat_sc_table;
410 struct hlist_head *sc_exit_table; /* for syscall exit tracing */
411 struct hlist_head *compat_sc_exit_table;
412 struct hlist_head sc_unknown; /* for unknown syscalls */
413 struct hlist_head sc_compat_unknown;
414 struct hlist_head sc_exit_unknown;
415 struct hlist_head compat_sc_exit_unknown;
80f87dd2 416 struct lttng_syscall_filter *sc_filter;
9115fbdc 417 int header_type; /* 0: unset, 1: compact, 2: large */
d83004aa 418 enum channel_type channel_type;
3b82c4e1
MD
419 int syscall_all_entry;
420 int syscall_all_exit;
80f87dd2
MD
421 unsigned int metadata_dumped:1,
422 sys_enter_registered:1,
423 sys_exit_registered:1,
3c997079 424 tstate:1; /* Transient enable state */
85a9ca7f
MD
425};
426
114667d5
MD
427#define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
428
429struct lttng_dynamic_len_stack {
430 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
431 size_t offset;
432};
433
434DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
e0130fab
MD
435
436/*
a2fa977a 437 * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
e0130fab
MD
438 * in RCU_INITIALIZER(v).
439 */
d1f652f8
MD
440#define LTTNG_ID_HASH_BITS 6
441#define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
e0130fab 442
a2fa977a 443struct lttng_kernel_id_tracker_rcu {
d1f652f8
MD
444 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
445};
446
a2fa977a
MD
447struct lttng_kernel_id_tracker {
448 struct lttng_kernel_id_tracker_private *priv; /* Private API */
449
450 struct lttng_kernel_id_tracker_rcu *p; /* RCU dereferenced. */
e0130fab
MD
451};
452
a40e3229
MD
453struct lttng_kernel_session_private;
454
455struct lttng_kernel_session {
456 struct lttng_kernel_session_private *priv; /* Private session interface */
457
85a9ca7f 458 int active; /* Is trace session active ? */
a40e3229 459
a2fa977a
MD
460 struct lttng_kernel_id_tracker pid_tracker;
461 struct lttng_kernel_id_tracker vpid_tracker;
462 struct lttng_kernel_id_tracker uid_tracker;
463 struct lttng_kernel_id_tracker vuid_tracker;
464 struct lttng_kernel_id_tracker gid_tracker;
465 struct lttng_kernel_id_tracker vgid_tracker;
85a9ca7f
MD
466};
467
c93ed3b0
MD
468int lttng_kernel_probe_register(struct lttng_kernel_probe_desc *desc);
469void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc *desc);
d83004aa 470
a2fa977a 471bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu *p, int id);
271b6681 472
a90917c3 473#endif /* _LTTNG_EVENTS_H */
This page took 0.083827 seconds and 4 git commands to generate.