Warn and return on fd overflow fdt
[lttng-modules.git] / include / lttng / events-internal.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng/events-internal.h
4 *
5 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 */
7
8#ifndef _LTTNG_EVENTS_INTERNAL_H
9#define _LTTNG_EVENTS_INTERNAL_H
10
11#include <wrapper/compiler_attributes.h>
12#include <wrapper/uuid.h>
13
14#include <lttng/events.h>
15
16struct lttng_syscall_filter;
17struct lttng_metadata_cache;
18struct perf_event;
19struct perf_event_attr;
20struct lttng_kernel_ring_buffer_config;
21
22enum lttng_enabler_format_type {
23 LTTNG_ENABLER_FORMAT_STAR_GLOB,
24 LTTNG_ENABLER_FORMAT_NAME,
25};
26
27enum channel_type {
28 PER_CPU_CHANNEL,
29 METADATA_CHANNEL,
30};
31
32/*
33 * Objects in a linked-list of enablers, owned by an event.
34 */
35struct lttng_enabler_ref {
36 struct list_head node; /* enabler ref list */
37 struct lttng_event_enabler_common *ref; /* backward ref */
38};
39
40struct lttng_krp; /* Kretprobe handling */
41
42struct lttng_uprobe_handler {
43 struct lttng_kernel_event_common *event;
44 loff_t offset;
45 struct uprobe_consumer up_consumer;
46 struct list_head node;
47};
48
49struct lttng_kprobe {
50 struct kprobe kp;
51 char *symbol_name;
52};
53
54struct lttng_uprobe {
55 struct inode *inode;
56 struct list_head head;
57};
58
59enum lttng_syscall_entryexit {
60 LTTNG_SYSCALL_ENTRY,
61 LTTNG_SYSCALL_EXIT,
62};
63
64enum lttng_syscall_abi {
65 LTTNG_SYSCALL_ABI_NATIVE,
66 LTTNG_SYSCALL_ABI_COMPAT,
67};
68
69struct lttng_kernel_event_common_private {
70 struct lttng_kernel_event_common *pub; /* Public event interface */
71
72 const struct lttng_kernel_event_desc *desc;
73 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
74 struct list_head enablers_ref_head;
75 int registered; /* has reg'd tracepoint probe */
76 uint64_t user_token;
77
78 int has_enablers_without_filter_bytecode;
79 /* list of struct lttng_kernel_bytecode_runtime, sorted by seqnum */
80 struct list_head filter_bytecode_runtime_head;
81
82 struct hlist_node hlist_node; /* node in events hash table */
83 struct list_head node; /* node in event list */
84
85 enum lttng_kernel_abi_instrumentation instrumentation;
86 /* Selected by instrumentation */
87 union {
88 struct lttng_kprobe kprobe;
89 struct lttng_uprobe uprobe;
90 struct {
91 struct lttng_krp *lttng_krp;
92 char *symbol_name;
93 } kretprobe;
94 struct {
95 enum lttng_syscall_entryexit entryexit;
96 enum lttng_syscall_abi abi;
97 struct hlist_node node; /* chain registered syscall event_notifier */
98 unsigned int syscall_id;
99 } syscall;
100 } u;
101};
102
103struct lttng_kernel_event_recorder_private {
104 struct lttng_kernel_event_common_private parent;
105
106 struct lttng_kernel_event_recorder *pub; /* Public event interface */
107 struct lttng_kernel_ctx *ctx;
108 unsigned int id;
109 unsigned int metadata_dumped:1;
110};
111
112struct lttng_kernel_event_notifier_private {
113 struct lttng_kernel_event_common_private parent;
114
115 struct lttng_kernel_event_notifier *pub; /* Public event notifier interface */
116 struct lttng_event_notifier_group *group; /* weak ref */
117 size_t num_captures; /* Needed to allocate the msgpack array. */
118 uint64_t error_counter_index;
119 struct list_head capture_bytecode_runtime_head;
120};
121
122struct lttng_kernel_syscall_table {
123 unsigned int sys_enter_registered:1,
124 sys_exit_registered:1;
125
126 struct hlist_head *syscall_dispatch; /* for syscall tracing */
127 struct hlist_head *compat_syscall_dispatch;
128 struct hlist_head *syscall_exit_dispatch; /* for syscall exit tracing */
129 struct hlist_head *compat_syscall_exit_dispatch;
130
131 /*
132 * Combining all unknown syscall events works as long as they
133 * are only matched by "all" syscalls enablers, but will require
134 * a design change when we allow matching by syscall number, for
135 * instance by allocating sc_tables accomodating NR_syscalls
136 * entries.
137 */
138 struct hlist_head unknown_syscall_dispatch; /* for unknown syscalls */
139 struct hlist_head compat_unknown_syscall_dispatch;
140 struct hlist_head unknown_syscall_exit_dispatch;
141 struct hlist_head compat_unknown_syscall_exit_dispatch;
142
143 struct lttng_syscall_filter *sc_filter;
144 int syscall_all_entry;
145 int syscall_all_exit;
146};
147
148struct lttng_kernel_channel_common_private {
149 struct lttng_kernel_channel_common *pub;
150
151 struct file *file; /* File associated to channel */
152 unsigned int tstate:1; /* Transient enable state */
153
154 struct lttng_kernel_syscall_table syscall_table;
155};
156
157struct lttng_kernel_channel_buffer_private {
158 struct lttng_kernel_channel_common_private parent;
159
160 struct lttng_kernel_channel_buffer *pub;
161
162 unsigned int id; /* Channel ID */
163 unsigned int free_event_id; /* Next event ID to allocate */
164 int header_type; /* 0: unset, 1: compact, 2: large */
165
166 enum channel_type channel_type;
167 struct lttng_kernel_ctx *ctx;
168 struct lttng_kernel_ring_buffer_channel *rb_chan; /* Ring buffer channel */
169 unsigned int metadata_dumped:1;
170 struct list_head node; /* Channel list in session */
171 struct lttng_transport *transport;
172};
173
174enum lttng_kernel_bytecode_interpreter_ret {
175 LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR = -1,
176 LTTNG_KERNEL_BYTECODE_INTERPRETER_OK = 0,
177};
178
179enum lttng_kernel_bytecode_filter_result {
180 LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT = 0,
181 LTTNG_KERNEL_BYTECODE_FILTER_REJECT = 1,
182};
183
184struct lttng_kernel_bytecode_filter_ctx {
185 enum lttng_kernel_bytecode_filter_result result;
186};
187
188struct lttng_interpreter_output;
189
190enum lttng_kernel_bytecode_type {
191 LTTNG_KERNEL_BYTECODE_TYPE_FILTER,
192 LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE,
193};
194
195enum lttng_kernel_event_enabler_type {
196 LTTNG_EVENT_ENABLER_TYPE_RECORDER,
197 LTTNG_EVENT_ENABLER_TYPE_NOTIFIER,
198};
199
200struct lttng_kernel_bytecode_node {
201 enum lttng_kernel_bytecode_type type;
202 struct list_head node;
203 struct lttng_event_enabler_common *enabler;
204 struct {
205 uint32_t len;
206 uint32_t reloc_offset;
207 uint64_t seqnum;
208 char data[];
209 } bc;
210};
211
212struct lttng_kernel_bytecode_runtime {
213 /* Associated bytecode */
214 enum lttng_kernel_bytecode_type type;
215 struct lttng_kernel_bytecode_node *bc;
216 int (*interpreter_func)(struct lttng_kernel_bytecode_runtime *kernel_bytecode,
217 const char *interpreter_stack_data,
218 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
219 void *caller_ctx);
220 int link_failed;
221 struct list_head node; /* list of bytecode runtime in event */
222 struct lttng_kernel_ctx *ctx;
223};
224
225/*
226 * Enabler field, within whatever object is enabling an event. Target of
227 * backward reference.
228 */
229struct lttng_event_enabler_common {
230 enum lttng_kernel_event_enabler_type enabler_type;
231 enum lttng_enabler_format_type format_type;
232
233 /* head list of struct lttng_kernel_bytecode_node */
234 struct list_head filter_bytecode_head;
235
236 struct lttng_kernel_abi_event event_param;
237 unsigned int enabled:1;
238
239 uint64_t user_token; /* User-provided token. */
240
241 struct list_head node; /* list of enablers */
242 bool published; /* published in list. */
243};
244
245struct lttng_event_recorder_enabler {
246 struct lttng_event_enabler_common parent;
247 struct lttng_kernel_channel_buffer *chan;
248};
249
250struct lttng_event_notifier_enabler {
251 struct lttng_event_enabler_common parent;
252 uint64_t error_counter_index;
253 struct lttng_event_notifier_group *group;
254
255 /* head list of struct lttng_kernel_bytecode_node */
256 struct list_head capture_bytecode_head;
257 uint64_t num_captures;
258};
259
260struct lttng_ctx_value {
261 union {
262 int64_t s64;
263 const char *str;
264 double d;
265 } u;
266};
267
268/*
269 * We need to keep this perf counter field separately from struct
270 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
271 */
272struct lttng_perf_counter_field {
273#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
274 struct lttng_cpuhp_node cpuhp_prepare;
275 struct lttng_cpuhp_node cpuhp_online;
276#else
277 struct notifier_block nb;
278 int hp_enable;
279#endif
280 struct perf_event_attr *attr;
281 struct perf_event **e; /* per-cpu array */
282 char *name;
283 struct lttng_kernel_event_field *event_field;
284};
285
286struct lttng_kernel_ctx_field {
287 const struct lttng_kernel_event_field *event_field;
288 size_t (*get_size)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
289 size_t offset);
290 void (*record)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
291 struct lttng_kernel_ring_buffer_ctx *ctx,
292 struct lttng_kernel_channel_buffer *chan);
293 void (*get_value)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
294 struct lttng_ctx_value *value);
295 void (*destroy)(void *priv);
296 void *priv;
297};
298
299struct lttng_kernel_ctx {
300 struct lttng_kernel_ctx_field *fields;
301 unsigned int nr_fields;
302 unsigned int allocated_fields;
303 size_t largest_align; /* in bytes */
304};
305
306struct lttng_metadata_cache {
307 char *data; /* Metadata cache */
308 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
309 unsigned int metadata_written; /* Number of bytes written in metadata cache */
310 atomic_t producing; /* Metadata being produced (incomplete) */
311 struct kref refcount; /* Metadata cache usage */
312 struct list_head metadata_stream; /* Metadata stream list */
313 guid_t uuid; /* Trace session unique ID (copy) */
314 struct mutex lock; /* Produce/consume lock */
315 uint64_t version; /* Current version of the metadata */
316};
317
318struct lttng_metadata_stream {
319 void *priv; /* Ring buffer private data */
320 struct lttng_metadata_cache *metadata_cache;
321 unsigned int metadata_in; /* Bytes read from the cache */
322 unsigned int metadata_out; /* Bytes consumed from stream */
323 int finalized; /* Has channel been finalized */
324 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
325 struct list_head list; /* Stream list */
326 struct lttng_transport *transport;
327 uint64_t version; /* Current version of the metadata cache */
328 bool coherent; /* Stream in a coherent state */
329};
330
331struct lttng_kernel_channel_buffer_ops_private {
332 struct lttng_kernel_channel_buffer_ops *pub; /* Public channel buffer ops interface */
333
334 struct lttng_kernel_ring_buffer_channel *(*channel_create)(const char *name,
335 void *priv,
336 void *buf_addr,
337 size_t subbuf_size, size_t num_subbuf,
338 unsigned int switch_timer_interval,
339 unsigned int read_timer_interval);
340 void (*channel_destroy)(struct lttng_kernel_ring_buffer_channel *chan);
341 struct lttng_kernel_ring_buffer *(*buffer_read_open)(struct lttng_kernel_ring_buffer_channel *chan);
342 int (*buffer_has_read_closed_stream)(struct lttng_kernel_ring_buffer_channel *chan);
343 void (*buffer_read_close)(struct lttng_kernel_ring_buffer *buf);
344 /*
345 * packet_avail_size returns the available size in the current
346 * packet. Note that the size returned is only a hint, since it
347 * may change due to concurrent writes.
348 */
349 size_t (*packet_avail_size)(struct lttng_kernel_ring_buffer_channel *chan);
350 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct lttng_kernel_ring_buffer_channel *chan, int cpu);
351 wait_queue_head_t *(*get_hp_wait_queue)(struct lttng_kernel_ring_buffer_channel *chan);
352 int (*is_finalized)(struct lttng_kernel_ring_buffer_channel *chan);
353 int (*is_disabled)(struct lttng_kernel_ring_buffer_channel *chan);
354 int (*timestamp_begin) (const struct lttng_kernel_ring_buffer_config *config,
355 struct lttng_kernel_ring_buffer *bufb,
356 uint64_t *timestamp_begin);
357 int (*timestamp_end) (const struct lttng_kernel_ring_buffer_config *config,
358 struct lttng_kernel_ring_buffer *bufb,
359 uint64_t *timestamp_end);
360 int (*events_discarded) (const struct lttng_kernel_ring_buffer_config *config,
361 struct lttng_kernel_ring_buffer *bufb,
362 uint64_t *events_discarded);
363 int (*content_size) (const struct lttng_kernel_ring_buffer_config *config,
364 struct lttng_kernel_ring_buffer *bufb,
365 uint64_t *content_size);
366 int (*packet_size) (const struct lttng_kernel_ring_buffer_config *config,
367 struct lttng_kernel_ring_buffer *bufb,
368 uint64_t *packet_size);
369 int (*stream_id) (const struct lttng_kernel_ring_buffer_config *config,
370 struct lttng_kernel_ring_buffer *bufb,
371 uint64_t *stream_id);
372 int (*current_timestamp) (const struct lttng_kernel_ring_buffer_config *config,
373 struct lttng_kernel_ring_buffer *bufb,
374 uint64_t *ts);
375 int (*sequence_number) (const struct lttng_kernel_ring_buffer_config *config,
376 struct lttng_kernel_ring_buffer *bufb,
377 uint64_t *seq);
378 int (*instance_id) (const struct lttng_kernel_ring_buffer_config *config,
379 struct lttng_kernel_ring_buffer *bufb,
380 uint64_t *id);
381};
382
383struct lttng_counter_ops {
384 struct lib_counter *(*counter_create)(size_t nr_dimensions,
385 const size_t *max_nr_elem, /* for each dimension */
386 int64_t global_sum_step);
387 void (*counter_destroy)(struct lib_counter *counter);
388 int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes,
389 int64_t v);
390 /*
391 * counter_read reads a specific cpu's counter if @cpu >= 0, or
392 * the global aggregation counter if @cpu == -1.
393 */
394 int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
395 int64_t *value, bool *overflow, bool *underflow);
396 /*
397 * counter_aggregate returns the total sum of all per-cpu counters and
398 * the global aggregation counter.
399 */
400 int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes,
401 int64_t *value, bool *overflow, bool *underflow);
402 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
403};
404
405struct lttng_counter {
406 struct file *file; /* File associated to counter. */
407 struct file *owner;
408 struct lttng_counter_transport *transport;
409 struct lib_counter *counter;
410 struct lttng_counter_ops *ops;
411};
412
413#define LTTNG_EVENT_HT_BITS 12
414#define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
415
416struct lttng_event_ht {
417 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
418};
419
420struct lttng_event_notifier_group {
421 struct file *file; /* File associated to event notifier group */
422 struct file *notif_file; /* File used to expose notifications to userspace. */
423 struct list_head node; /* event notifier group list */
424 struct list_head enablers_head; /* List of enablers */
425 struct list_head event_notifiers_head; /* List of event notifier */
426 struct lttng_event_ht events_ht; /* Hash table of event notifiers */
427 struct lttng_kernel_channel_buffer_ops *ops;
428 struct lttng_transport *transport;
429 struct lttng_kernel_ring_buffer_channel *chan; /* Ring buffer channel for event notifier group. */
430 struct lttng_kernel_ring_buffer *buf; /* Ring buffer for event notifier group. */
431 wait_queue_head_t read_wait;
432 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
433
434 struct lttng_kernel_syscall_table syscall_table;
435
436 struct lttng_counter *error_counter;
437 size_t error_counter_len;
438};
439
440struct lttng_transport {
441 char *name;
442 struct module *owner;
443 struct list_head node;
444 struct lttng_kernel_channel_buffer_ops ops;
445};
446
447struct lttng_counter_transport {
448 char *name;
449 struct module *owner;
450 struct list_head node;
451 struct lttng_counter_ops ops;
452};
453
454struct lttng_kernel_session_private {
455 struct lttng_kernel_session *pub; /* Public session interface */
456
457 int been_active; /* Has trace session been active ? */
458 struct file *file; /* File associated to session */
459 struct list_head chan; /* Channel list head */
460 struct list_head events; /* Event list head */
461 struct list_head list; /* Session list */
462 unsigned int free_chan_id; /* Next chan ID to allocate */
463 guid_t uuid; /* Trace session unique ID */
464 struct lttng_metadata_cache *metadata_cache;
465 unsigned int metadata_dumped:1,
466 tstate:1; /* Transient enable state */
467 /* List of event enablers */
468 struct list_head enablers_head;
469 /* Hash table of events */
470 struct lttng_event_ht events_ht;
471 char name[LTTNG_KERNEL_ABI_SESSION_NAME_LEN];
472 char creation_time[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN];
473};
474
475struct lttng_id_hash_node {
476 struct hlist_node hlist;
477 int id;
478};
479
480enum tracker_type {
481 TRACKER_PID,
482 TRACKER_VPID,
483 TRACKER_UID,
484 TRACKER_VUID,
485 TRACKER_GID,
486 TRACKER_VGID,
487
488 TRACKER_UNKNOWN,
489};
490
491struct lttng_kernel_id_tracker_private {
492 struct lttng_kernel_id_tracker *pub; /* Public interface */
493
494 struct lttng_kernel_session *session;
495 enum tracker_type tracker_type;
496};
497
498extern struct lttng_kernel_ctx *lttng_static_ctx;
499
500static inline
501const struct lttng_kernel_type_integer *lttng_kernel_get_type_integer(const struct lttng_kernel_type_common *type)
502{
503 if (type->type != lttng_kernel_type_integer)
504 return NULL;
505 return container_of(type, const struct lttng_kernel_type_integer, parent);
506}
507
508static inline
509const struct lttng_kernel_type_string *lttng_kernel_get_type_string(const struct lttng_kernel_type_common *type)
510{
511 if (type->type != lttng_kernel_type_string)
512 return NULL;
513 return container_of(type, const struct lttng_kernel_type_string, parent);
514}
515
516static inline
517const struct lttng_kernel_type_enum *lttng_kernel_get_type_enum(const struct lttng_kernel_type_common *type)
518{
519 if (type->type != lttng_kernel_type_enum)
520 return NULL;
521 return container_of(type, const struct lttng_kernel_type_enum, parent);
522}
523
524static inline
525const struct lttng_kernel_type_array *lttng_kernel_get_type_array(const struct lttng_kernel_type_common *type)
526{
527 if (type->type != lttng_kernel_type_array)
528 return NULL;
529 return container_of(type, const struct lttng_kernel_type_array, parent);
530}
531
532static inline
533const struct lttng_kernel_type_sequence *lttng_kernel_get_type_sequence(const struct lttng_kernel_type_common *type)
534{
535 if (type->type != lttng_kernel_type_sequence)
536 return NULL;
537 return container_of(type, const struct lttng_kernel_type_sequence, parent);
538}
539
540static inline
541const struct lttng_kernel_type_struct *lttng_kernel_get_type_struct(const struct lttng_kernel_type_common *type)
542{
543 if (type->type != lttng_kernel_type_struct)
544 return NULL;
545 return container_of(type, const struct lttng_kernel_type_struct, parent);
546}
547
548static inline
549const struct lttng_kernel_type_variant *lttng_kernel_get_type_variant(const struct lttng_kernel_type_common *type)
550{
551 if (type->type != lttng_kernel_type_variant)
552 return NULL;
553 return container_of(type, const struct lttng_kernel_type_variant, parent);
554}
555
556static inline bool lttng_kernel_type_is_bytewise_integer(const struct lttng_kernel_type_common *type)
557{
558 const struct lttng_kernel_type_integer *type_integer = lttng_kernel_get_type_integer(type);
559
560 if (!type_integer)
561 return false;
562 switch (type_integer->size) {
563 case 8:
564 lttng_fallthrough;
565 case 16:
566 lttng_fallthrough;
567 case 32:
568 lttng_fallthrough;
569 case 64:
570 break;
571 default:
572 return false;
573 }
574 return true;
575}
576
577int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common *event,
578 const char *interpreter_stack_data,
579 struct lttng_kernel_probe_ctx *probe_ctx,
580 void *event_filter_ctx);
581
582static inline
583struct lttng_event_enabler_common *lttng_event_recorder_enabler_as_enabler(
584 struct lttng_event_recorder_enabler *event_recorder_enabler)
585{
586 return &event_recorder_enabler->parent;
587}
588
589static inline
590struct lttng_event_enabler_common *lttng_event_notifier_enabler_as_enabler(
591 struct lttng_event_notifier_enabler *event_notifier_enabler)
592{
593 return &event_notifier_enabler->parent;
594}
595
596static inline
597struct lttng_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common *event_enabler)
598{
599 switch (event_enabler->enabler_type) {
600 case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
601 {
602 struct lttng_event_recorder_enabler *event_recorder_enabler =
603 container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
604 return &event_recorder_enabler->chan->parent.session->priv->events_ht;
605 }
606 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
607 {
608 struct lttng_event_notifier_enabler *event_notifier_enabler =
609 container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
610 return &event_notifier_enabler->group->events_ht;
611 }
612 default:
613 return NULL;
614 }
615}
616
617static inline
618struct list_head *lttng_get_event_list_head_from_enabler(struct lttng_event_enabler_common *event_enabler)
619{
620 switch (event_enabler->enabler_type) {
621 case LTTNG_EVENT_ENABLER_TYPE_RECORDER:
622 {
623 struct lttng_event_recorder_enabler *event_recorder_enabler =
624 container_of(event_enabler, struct lttng_event_recorder_enabler, parent);
625 return &event_recorder_enabler->chan->parent.session->priv->events;
626 }
627 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
628 {
629 struct lttng_event_notifier_enabler *event_notifier_enabler =
630 container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
631 return &event_notifier_enabler->group->event_notifiers_head;
632 }
633 default:
634 return NULL;
635 }
636}
637
638int lttng_context_init(void);
639void lttng_context_exit(void);
640int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
641 const struct lttng_kernel_ctx_field *f);
642void lttng_kernel_context_remove_last(struct lttng_kernel_ctx **ctx_p);
643struct lttng_kernel_ctx_field *lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx *ctx,
644 size_t index);
645int lttng_kernel_find_context(struct lttng_kernel_ctx *ctx, const char *name);
646int lttng_kernel_get_context_index(struct lttng_kernel_ctx *ctx, const char *name);
647void lttng_kernel_destroy_context(struct lttng_kernel_ctx *ctx);
648int lttng_add_pid_to_ctx(struct lttng_kernel_ctx **ctx);
649int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx **ctx);
650int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx);
651int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx);
652int lttng_add_nice_to_ctx(struct lttng_kernel_ctx **ctx);
653int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx **ctx);
654int lttng_add_tid_to_ctx(struct lttng_kernel_ctx **ctx);
655int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx **ctx);
656int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx **ctx);
657int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx);
658int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx **ctx);
659int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx **ctx);
660int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx **ctx);
661#if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
662int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx);
663#else
664static inline
665int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
666{
667 return -ENOSYS;
668}
669#endif
670#ifdef CONFIG_PREEMPT_RT_FULL
671int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx);
672#else
673static inline
674int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx)
675{
676 return -ENOSYS;
677}
678#endif
679
680int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx **ctx, int type);
681
682#if defined(CONFIG_CGROUPS) && \
683 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
684 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
685int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx);
686#else
687static inline
688int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx)
689{
690 return -ENOSYS;
691}
692#endif
693
694#if defined(CONFIG_IPC_NS) && \
695 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
696int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx);
697#else
698static inline
699int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx)
700{
701 return -ENOSYS;
702}
703#endif
704
705#if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
706 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
707int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx);
708#else
709static inline
710int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx)
711{
712 return -ENOSYS;
713}
714#endif
715
716#if defined(CONFIG_NET_NS) && \
717 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
718int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx);
719#else
720static inline
721int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx)
722{
723 return -ENOSYS;
724}
725#endif
726
727#if defined(CONFIG_PID_NS) && \
728 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
729int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx);
730#else
731static inline
732int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx)
733{
734 return -ENOSYS;
735}
736#endif
737
738#if defined(CONFIG_USER_NS) && \
739 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
740int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx);
741#else
742static inline
743int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx)
744{
745 return -ENOSYS;
746}
747#endif
748
749#if defined(CONFIG_UTS_NS) && \
750 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
751int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx);
752#else
753static inline
754int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx)
755{
756 return -ENOSYS;
757}
758#endif
759
760#if defined(CONFIG_TIME_NS) && \
761 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \
762 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
763int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx);
764#else
765static inline
766int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx)
767{
768 return -ENOSYS;
769}
770#endif
771
772int lttng_add_uid_to_ctx(struct lttng_kernel_ctx **ctx);
773int lttng_add_euid_to_ctx(struct lttng_kernel_ctx **ctx);
774int lttng_add_suid_to_ctx(struct lttng_kernel_ctx **ctx);
775int lttng_add_gid_to_ctx(struct lttng_kernel_ctx **ctx);
776int lttng_add_egid_to_ctx(struct lttng_kernel_ctx **ctx);
777int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx **ctx);
778int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx **ctx);
779int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx **ctx);
780int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx **ctx);
781int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx **ctx);
782int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx **ctx);
783int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx **ctx);
784
785#if defined(CONFIG_PERF_EVENTS)
786int lttng_add_perf_counter_to_ctx(uint32_t type,
787 uint64_t config,
788 const char *name,
789 struct lttng_kernel_ctx **ctx);
790int lttng_cpuhp_perf_counter_online(unsigned int cpu,
791 struct lttng_cpuhp_node *node);
792int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
793 struct lttng_cpuhp_node *node);
794#else
795static inline
796int lttng_add_perf_counter_to_ctx(uint32_t type,
797 uint64_t config,
798 const char *name,
799 struct lttng_kernel_ctx **ctx)
800{
801 return -ENOSYS;
802}
803static inline
804int lttng_cpuhp_perf_counter_online(unsigned int cpu,
805 struct lttng_cpuhp_node *node)
806{
807 return 0;
808}
809static inline
810int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
811 struct lttng_cpuhp_node *node)
812{
813 return 0;
814}
815#endif
816
817struct lttng_event_recorder_enabler *lttng_event_recorder_enabler_create(
818 enum lttng_enabler_format_type format_type,
819 struct lttng_kernel_abi_event *event_param,
820 struct lttng_kernel_channel_buffer *chan);
821void lttng_event_enabler_session_add(struct lttng_kernel_session *session,
822 struct lttng_event_recorder_enabler *event_enabler);
823
824struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
825 enum lttng_enabler_format_type format_type,
826 struct lttng_kernel_abi_event_notifier *event_notifier_param,
827 struct lttng_event_notifier_group *event_notifier_group);
828void lttng_event_notifier_enabler_group_add(struct lttng_event_notifier_group *event_notifier_group,
829 struct lttng_event_notifier_enabler *event_notifier_enabler);
830int lttng_event_notifier_enabler_attach_capture_bytecode(
831 struct lttng_event_notifier_enabler *event_notifier_enabler,
832 struct lttng_kernel_abi_capture_bytecode __user *bytecode);
833
834int lttng_event_enabler_enable(struct lttng_event_enabler_common *event_enabler);
835int lttng_event_enabler_disable(struct lttng_event_enabler_common *event_enabler);
836int lttng_event_enabler_attach_filter_bytecode(struct lttng_event_enabler_common *event_enabler,
837 struct lttng_kernel_abi_filter_bytecode __user *bytecode);
838void lttng_event_enabler_destroy(struct lttng_event_enabler_common *event_enabler);
839
840bool lttng_desc_match_enabler(const struct lttng_kernel_event_desc *desc,
841 struct lttng_event_enabler_common *enabler);
842bool lttng_event_enabler_match_event(struct lttng_event_enabler_common *event_enabler,
843 struct lttng_kernel_event_common *event);
844bool lttng_event_enabler_desc_match_event(struct lttng_event_enabler_common *event_enabler,
845 const struct lttng_kernel_event_desc *desc,
846 struct lttng_kernel_event_common *event);
847bool lttng_event_enabler_event_name_match_event(struct lttng_event_enabler_common *event_enabler,
848 const char *event_name,
849 struct lttng_kernel_event_common *event);
850
851void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_desc,
852 struct lttng_kernel_ctx *ctx,
853 struct list_head *instance_bytecode_runtime_head,
854 struct list_head *enabler_bytecode_runtime_head);
855
856#if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
857int lttng_event_enabler_create_syscall_events_if_missing(struct lttng_event_enabler_common *event_enabler);
858int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event);
859int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event);
860
861int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table);
862int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table);
863
864long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table,
865 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask);
866
867void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common *event_enabler);
868#else
869static inline int lttng_event_enabler_create_syscall_events_if_missing(struct lttng_event_enabler_common *event_enabler)
870{
871 return -ENOSYS;
872}
873
874static inline int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event)
875{
876 return -ENOSYS;
877}
878
879static inline int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event)
880{
881 return -ENOSYS;
882}
883
884static inline int lttng_syscalls_unregister_syscall_table(struct lttng_kernel_syscall_table *syscall_table)
885{
886 return 0;
887}
888
889static inline int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *syscall_table)
890{
891 return 0;
892}
893
894static inline long lttng_syscall_table_get_active_mask(struct lttng_kernel_syscall_table *syscall_table,
895 struct lttng_kernel_abi_syscall_mask __user *usyscall_mask)
896{
897 return -ENOSYS;
898}
899
900static inline int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_notifier_enabler *event_notifier_enabler)
901{
902 return -ENOSYS;
903}
904
905static inline void lttng_syscall_table_set_wildcard_all(struct lttng_event_enabler_common *event_enabler)
906{
907}
908#endif
909
910#ifdef CONFIG_KPROBES
911int lttng_kprobes_register_event(const char *name,
912 const char *symbol_name,
913 uint64_t offset,
914 uint64_t addr,
915 struct lttng_kernel_event_common *event);
916void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event);
917void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event);
918#else
919static inline
920int lttng_kprobes_register_event(const char *name,
921 const char *symbol_name,
922 uint64_t offset,
923 uint64_t addr,
924 struct lttng_kernel_event_common *event)
925{
926 return -ENOSYS;
927}
928
929static inline
930void lttng_kprobes_unregister_event(struct lttng_kernel_event_common *event)
931{
932}
933
934static inline
935void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_common *event)
936{
937}
938#endif
939
940int lttng_event_add_callsite(struct lttng_kernel_event_common *event,
941 struct lttng_kernel_abi_event_callsite __user *callsite);
942
943#ifdef CONFIG_UPROBES
944int lttng_uprobes_register_event(const char *name,
945 int fd, struct lttng_kernel_event_common *event);
946int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
947 struct lttng_kernel_abi_event_callsite __user *callsite);
948void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event);
949void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event);
950#else
951static inline
952int lttng_uprobes_register_event(const char *name,
953 int fd, struct lttng_kernel_event_common *event)
954{
955 return -ENOSYS;
956}
957
958static inline
959int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
960 struct lttng_kernel_abi_event_callsite __user *callsite)
961{
962 return -ENOSYS;
963}
964
965static inline
966void lttng_uprobes_unregister_event(struct lttng_kernel_event_common *event)
967{
968}
969
970static inline
971void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_common *event)
972{
973}
974#endif
975
976#ifdef CONFIG_KRETPROBES
977int lttng_kretprobes_register(const char *name,
978 const char *symbol_name,
979 uint64_t offset,
980 uint64_t addr,
981 struct lttng_kernel_event_common *event_entry,
982 struct lttng_kernel_event_common *event_exit);
983void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event);
984void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event);
985int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
986 int enable);
987#else
988static inline
989int lttng_kretprobes_register(const char *name,
990 const char *symbol_name,
991 uint64_t offset,
992 uint64_t addr,
993 struct lttng_kernel_event_common *event_entry,
994 struct lttng_kernel_event_common *event_exit)
995{
996 return -ENOSYS;
997}
998
999static inline
1000void lttng_kretprobes_unregister(struct lttng_kernel_event_common *event)
1001{
1002}
1003
1004static inline
1005void lttng_kretprobes_destroy_private(struct lttng_kernel_event_common *event)
1006{
1007}
1008
1009static inline
1010int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
1011 int enable)
1012{
1013 return -ENOSYS;
1014}
1015#endif
1016
1017void lttng_lock_sessions(void);
1018void lttng_unlock_sessions(void);
1019
1020struct list_head *lttng_get_probe_list_head(void);
1021
1022int lttng_fix_pending_events(void);
1023int lttng_fix_pending_event_notifiers(void);
1024int lttng_session_active(void);
1025bool lttng_event_notifier_active(void);
1026
1027struct lttng_kernel_session *lttng_session_create(void);
1028int lttng_session_enable(struct lttng_kernel_session *session);
1029int lttng_session_disable(struct lttng_kernel_session *session);
1030void lttng_session_destroy(struct lttng_kernel_session *session);
1031int lttng_session_metadata_regenerate(struct lttng_kernel_session *session);
1032int lttng_session_statedump(struct lttng_kernel_session *session);
1033void metadata_cache_destroy(struct kref *kref);
1034
1035struct lttng_counter *lttng_kernel_counter_create(
1036 const char *counter_transport_name, size_t number_dimensions,
1037 const size_t *dimensions_sizes);
1038int lttng_kernel_counter_read(struct lttng_counter *counter,
1039 const size_t *dimension_indexes, int32_t cpu,
1040 int64_t *val, bool *overflow, bool *underflow);
1041int lttng_kernel_counter_aggregate(struct lttng_counter *counter,
1042 const size_t *dimension_indexes, int64_t *val,
1043 bool *overflow, bool *underflow);
1044int lttng_kernel_counter_clear(struct lttng_counter *counter,
1045 const size_t *dimension_indexes);
1046struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
1047int lttng_event_notifier_group_create_error_counter(
1048 struct file *event_notifier_group_file,
1049 const struct lttng_kernel_abi_counter_conf *error_counter_conf);
1050void lttng_event_notifier_group_destroy(
1051 struct lttng_event_notifier_group *event_notifier_group);
1052
1053struct lttng_kernel_channel_buffer *lttng_channel_buffer_create(struct lttng_kernel_session *session,
1054 const char *transport_name,
1055 void *buf_addr,
1056 size_t subbuf_size, size_t num_subbuf,
1057 unsigned int switch_timer_interval,
1058 unsigned int read_timer_interval,
1059 enum channel_type channel_type);
1060struct lttng_kernel_channel_buffer *lttng_global_channel_create(struct lttng_kernel_session *session,
1061 int overwrite, void *buf_addr,
1062 size_t subbuf_size, size_t num_subbuf,
1063 unsigned int switch_timer_interval,
1064 unsigned int read_timer_interval);
1065
1066void lttng_metadata_channel_destroy(struct lttng_kernel_channel_buffer *chan);
1067struct lttng_kernel_event_common *_lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler,
1068 const struct lttng_kernel_event_desc *event_desc);
1069struct lttng_kernel_event_common *lttng_kernel_event_create(struct lttng_event_enabler_common *event_enabler,
1070 const struct lttng_kernel_event_desc *event_desc);
1071
1072int lttng_channel_enable(struct lttng_kernel_channel_common *channel);
1073int lttng_channel_disable(struct lttng_kernel_channel_common *channel);
1074int lttng_event_enable(struct lttng_kernel_event_common *event);
1075int lttng_event_disable(struct lttng_kernel_event_common *event);
1076
1077void lttng_transport_register(struct lttng_transport *transport);
1078void lttng_transport_unregister(struct lttng_transport *transport);
1079
1080void lttng_counter_transport_register(struct lttng_counter_transport *transport);
1081void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
1082
1083void synchronize_trace(void);
1084int lttng_abi_init(void);
1085int lttng_abi_compat_old_init(void);
1086void lttng_abi_exit(void);
1087void lttng_abi_compat_old_exit(void);
1088
1089const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name);
1090void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc);
1091int lttng_probes_init(void);
1092void lttng_probes_exit(void);
1093
1094int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
1095 struct lttng_kernel_ring_buffer_channel *chan, bool *coherent);
1096
1097int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
1098int lttng_id_tracker_empty_set(struct lttng_kernel_id_tracker *lf);
1099int lttng_id_tracker_init(struct lttng_kernel_id_tracker *lf,
1100 struct lttng_kernel_session *session,
1101 enum tracker_type type);
1102void lttng_id_tracker_fini(struct lttng_kernel_id_tracker *lf);
1103void lttng_id_tracker_destroy(struct lttng_kernel_id_tracker *lf, bool rcu);
1104int lttng_id_tracker_add(struct lttng_kernel_id_tracker *lf, int id);
1105int lttng_id_tracker_del(struct lttng_kernel_id_tracker *lf, int id);
1106
1107int lttng_session_track_id(struct lttng_kernel_session *session,
1108 enum tracker_type tracker_type, int id);
1109int lttng_session_untrack_id(struct lttng_kernel_session *session,
1110 enum tracker_type tracker_type, int id);
1111
1112int lttng_session_list_tracker_ids(struct lttng_kernel_session *session,
1113 enum tracker_type tracker_type);
1114
1115void lttng_clock_ref(void);
1116void lttng_clock_unref(void);
1117
1118void lttng_free_event_filter_runtime(struct lttng_kernel_event_common *event);
1119
1120int lttng_probes_init(void);
1121
1122int lttng_logger_init(void);
1123void lttng_logger_exit(void);
1124
1125extern int lttng_statedump_start(struct lttng_kernel_session *session);
1126
1127int lttng_calibrate(struct lttng_kernel_abi_calibrate *calibrate);
1128
1129extern const struct file_operations lttng_tracepoint_list_fops;
1130extern const struct file_operations lttng_syscall_list_fops;
1131
1132#define lttng_kernel_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
1133 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
1134 .event_field = (_event_field), \
1135 .get_size = (_get_size), \
1136 .record = (_record), \
1137 .get_value = (_get_value), \
1138 .destroy = (_destroy), \
1139 .priv = (_priv), \
1140 })
1141
1142#endif /* _LTTNG_EVENTS_INTERNAL_H */
This page took 0.027221 seconds and 5 git commands to generate.