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