Move bytecode structures to internal header
[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 <lttng/events.h>
12
13 struct lttng_kernel_event_common_private {
14 struct lttng_kernel_event_common *pub; /* Public event interface */
15
16 const struct lttng_kernel_event_desc *desc;
17 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
18 struct list_head enablers_ref_head;
19 int registered; /* has reg'd tracepoint probe */
20 uint64_t user_token;
21
22 int has_enablers_without_filter_bytecode;
23 /* list of struct lttng_kernel_bytecode_runtime, sorted by seqnum */
24 struct list_head filter_bytecode_runtime_head;
25 enum lttng_kernel_abi_instrumentation instrumentation;
26 /* Selected by instrumentation */
27 union {
28 struct lttng_kprobe kprobe;
29 struct lttng_uprobe uprobe;
30 struct {
31 struct lttng_krp *lttng_krp;
32 char *symbol_name;
33 } kretprobe;
34 struct {
35 enum lttng_syscall_entryexit entryexit;
36 enum lttng_syscall_abi abi;
37 struct hlist_node node; /* chain registered syscall event_notifier */
38 unsigned int syscall_id;
39 } syscall;
40 } u;
41 };
42
43 struct lttng_kernel_event_recorder_private {
44 struct lttng_kernel_event_common_private parent;
45
46 struct lttng_kernel_event_recorder *pub; /* Public event interface */
47 struct list_head node; /* Event recorder list */
48 struct hlist_node hlist; /* Hash table of event recorders */
49 struct lttng_kernel_ctx *ctx;
50 unsigned int id;
51 unsigned int metadata_dumped:1;
52 };
53
54 struct lttng_kernel_event_notifier_private {
55 struct lttng_kernel_event_common_private parent;
56
57 struct lttng_kernel_event_notifier *pub; /* Public event notifier interface */
58 struct lttng_event_notifier_group *group; /* weak ref */
59 size_t num_captures; /* Needed to allocate the msgpack array. */
60 uint64_t error_counter_index;
61 struct list_head node; /* Event notifier list */
62 struct hlist_node hlist; /* Hash table of event notifiers */
63 struct list_head capture_bytecode_runtime_head;
64
65 };
66
67 enum lttng_kernel_bytecode_interpreter_ret {
68 LTTNG_KERNEL_BYTECODE_INTERPRETER_ERROR = -1,
69 LTTNG_KERNEL_BYTECODE_INTERPRETER_OK = 0,
70 };
71
72 enum lttng_kernel_bytecode_filter_result {
73 LTTNG_KERNEL_BYTECODE_FILTER_ACCEPT = 0,
74 LTTNG_KERNEL_BYTECODE_FILTER_REJECT = 1,
75 };
76
77 struct lttng_kernel_bytecode_filter_ctx {
78 enum lttng_kernel_bytecode_filter_result result;
79 };
80
81 struct lttng_interpreter_output;
82
83 enum lttng_kernel_bytecode_type {
84 LTTNG_KERNEL_BYTECODE_TYPE_FILTER,
85 LTTNG_KERNEL_BYTECODE_TYPE_CAPTURE,
86 };
87
88 struct lttng_kernel_bytecode_node {
89 enum lttng_kernel_bytecode_type type;
90 struct list_head node;
91 struct lttng_enabler *enabler;
92 struct {
93 uint32_t len;
94 uint32_t reloc_offset;
95 uint64_t seqnum;
96 char data[];
97 } bc;
98 };
99
100 struct lttng_kernel_bytecode_runtime {
101 /* Associated bytecode */
102 enum lttng_kernel_bytecode_type type;
103 struct lttng_kernel_bytecode_node *bc;
104 int (*interpreter_func)(struct lttng_kernel_bytecode_runtime *kernel_bytecode,
105 const char *interpreter_stack_data,
106 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
107 void *caller_ctx);
108 int link_failed;
109 struct list_head node; /* list of bytecode runtime in event */
110 struct lttng_kernel_ctx *ctx;
111 };
112
113 /*
114 * Enabler field, within whatever object is enabling an event. Target of
115 * backward reference.
116 */
117 struct lttng_enabler {
118 enum lttng_enabler_format_type format_type;
119
120 /* head list of struct lttng_kernel_bytecode_node */
121 struct list_head filter_bytecode_head;
122
123 struct lttng_kernel_abi_event event_param;
124 unsigned int enabled:1;
125
126 uint64_t user_token; /* User-provided token. */
127 };
128
129 struct lttng_event_enabler {
130 struct lttng_enabler base;
131 struct list_head node; /* per-session list of enablers */
132 struct lttng_channel *chan;
133 };
134
135 struct lttng_event_notifier_enabler {
136 struct lttng_enabler base;
137 uint64_t error_counter_index;
138 struct list_head node; /* List of event_notifier enablers */
139 struct lttng_event_notifier_group *group;
140
141 /* head list of struct lttng_kernel_bytecode_node */
142 struct list_head capture_bytecode_head;
143 uint64_t num_captures;
144 };
145
146 struct lttng_ctx_value {
147 union {
148 int64_t s64;
149 const char *str;
150 double d;
151 } u;
152 };
153
154 /*
155 * We need to keep this perf counter field separately from struct
156 * lttng_kernel_ctx_field because cpu hotplug needs fixed-location addresses.
157 */
158 struct lttng_perf_counter_field {
159 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
160 struct lttng_cpuhp_node cpuhp_prepare;
161 struct lttng_cpuhp_node cpuhp_online;
162 #else
163 struct notifier_block nb;
164 int hp_enable;
165 #endif
166 struct perf_event_attr *attr;
167 struct perf_event **e; /* per-cpu array */
168 char *name;
169 struct lttng_kernel_event_field *event_field;
170 };
171
172 struct lttng_kernel_ctx_field {
173 const struct lttng_kernel_event_field *event_field;
174 size_t (*get_size)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
175 size_t offset);
176 void (*record)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
177 struct lib_ring_buffer_ctx *ctx,
178 struct lttng_channel *chan);
179 void (*get_value)(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
180 struct lttng_ctx_value *value);
181 void (*destroy)(void *priv);
182 void *priv;
183 };
184
185 struct lttng_kernel_ctx {
186 struct lttng_kernel_ctx_field *fields;
187 unsigned int nr_fields;
188 unsigned int allocated_fields;
189 size_t largest_align; /* in bytes */
190 };
191
192 extern struct lttng_kernel_ctx *lttng_static_ctx;
193
194 static inline
195 const struct lttng_kernel_type_integer *lttng_kernel_get_type_integer(const struct lttng_kernel_type_common *type)
196 {
197 if (type->type != lttng_kernel_type_integer)
198 return NULL;
199 return container_of(type, const struct lttng_kernel_type_integer, parent);
200 }
201
202 static inline
203 const struct lttng_kernel_type_string *lttng_kernel_get_type_string(const struct lttng_kernel_type_common *type)
204 {
205 if (type->type != lttng_kernel_type_string)
206 return NULL;
207 return container_of(type, const struct lttng_kernel_type_string, parent);
208 }
209
210 static inline
211 const struct lttng_kernel_type_enum *lttng_kernel_get_type_enum(const struct lttng_kernel_type_common *type)
212 {
213 if (type->type != lttng_kernel_type_enum)
214 return NULL;
215 return container_of(type, const struct lttng_kernel_type_enum, parent);
216 }
217
218 static inline
219 const struct lttng_kernel_type_array *lttng_kernel_get_type_array(const struct lttng_kernel_type_common *type)
220 {
221 if (type->type != lttng_kernel_type_array)
222 return NULL;
223 return container_of(type, const struct lttng_kernel_type_array, parent);
224 }
225
226 static inline
227 const struct lttng_kernel_type_sequence *lttng_kernel_get_type_sequence(const struct lttng_kernel_type_common *type)
228 {
229 if (type->type != lttng_kernel_type_sequence)
230 return NULL;
231 return container_of(type, const struct lttng_kernel_type_sequence, parent);
232 }
233
234 static inline
235 const struct lttng_kernel_type_struct *lttng_kernel_get_type_struct(const struct lttng_kernel_type_common *type)
236 {
237 if (type->type != lttng_kernel_type_struct)
238 return NULL;
239 return container_of(type, const struct lttng_kernel_type_struct, parent);
240 }
241
242 static inline
243 const struct lttng_kernel_type_variant *lttng_kernel_get_type_variant(const struct lttng_kernel_type_common *type)
244 {
245 if (type->type != lttng_kernel_type_variant)
246 return NULL;
247 return container_of(type, const struct lttng_kernel_type_variant, parent);
248 }
249
250 static inline bool lttng_kernel_type_is_bytewise_integer(const struct lttng_kernel_type_common *type)
251 {
252 const struct lttng_kernel_type_integer *type_integer = lttng_kernel_get_type_integer(type);
253
254 if (!type_integer)
255 return false;
256 switch (type_integer->size) {
257 case 8: /* Fall-through. */
258 case 16: /* Fall-through. */
259 case 32: /* Fall-through. */
260 case 64:
261 break;
262 default:
263 return false;
264 }
265 return true;
266 }
267
268 int lttng_kernel_interpret_event_filter(const struct lttng_kernel_event_common *event,
269 const char *interpreter_stack_data,
270 struct lttng_kernel_probe_ctx *probe_ctx,
271 void *event_filter_ctx);
272
273 static inline
274 struct lttng_enabler *lttng_event_enabler_as_enabler(
275 struct lttng_event_enabler *event_enabler)
276 {
277 return &event_enabler->base;
278 }
279
280 static inline
281 struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
282 struct lttng_event_notifier_enabler *event_notifier_enabler)
283 {
284 return &event_notifier_enabler->base;
285 }
286
287 int lttng_context_init(void);
288 void lttng_context_exit(void);
289 int lttng_kernel_context_append(struct lttng_kernel_ctx **ctx_p,
290 const struct lttng_kernel_ctx_field *f);
291 void lttng_kernel_context_remove_last(struct lttng_kernel_ctx **ctx_p);
292 struct lttng_kernel_ctx_field *lttng_kernel_get_context_field_from_index(struct lttng_kernel_ctx *ctx,
293 size_t index);
294 int lttng_kernel_find_context(struct lttng_kernel_ctx *ctx, const char *name);
295 int lttng_kernel_get_context_index(struct lttng_kernel_ctx *ctx, const char *name);
296 void lttng_kernel_destroy_context(struct lttng_kernel_ctx *ctx);
297 int lttng_add_pid_to_ctx(struct lttng_kernel_ctx **ctx);
298 int lttng_add_cpu_id_to_ctx(struct lttng_kernel_ctx **ctx);
299 int lttng_add_procname_to_ctx(struct lttng_kernel_ctx **ctx);
300 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx);
301 int lttng_add_nice_to_ctx(struct lttng_kernel_ctx **ctx);
302 int lttng_add_vpid_to_ctx(struct lttng_kernel_ctx **ctx);
303 int lttng_add_tid_to_ctx(struct lttng_kernel_ctx **ctx);
304 int lttng_add_vtid_to_ctx(struct lttng_kernel_ctx **ctx);
305 int lttng_add_ppid_to_ctx(struct lttng_kernel_ctx **ctx);
306 int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx);
307 int lttng_add_hostname_to_ctx(struct lttng_kernel_ctx **ctx);
308 int lttng_add_interruptible_to_ctx(struct lttng_kernel_ctx **ctx);
309 int lttng_add_need_reschedule_to_ctx(struct lttng_kernel_ctx **ctx);
310 #if defined(CONFIG_PREEMPT_RT_FULL) || defined(CONFIG_PREEMPT)
311 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx);
312 #else
313 static inline
314 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
315 {
316 return -ENOSYS;
317 }
318 #endif
319 #ifdef CONFIG_PREEMPT_RT_FULL
320 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx);
321 #else
322 static inline
323 int lttng_add_migratable_to_ctx(struct lttng_kernel_ctx **ctx)
324 {
325 return -ENOSYS;
326 }
327 #endif
328
329 int lttng_add_callstack_to_ctx(struct lttng_kernel_ctx **ctx, int type);
330
331 #if defined(CONFIG_CGROUPS) && \
332 ((LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0)) || \
333 LTTNG_UBUNTU_KERNEL_RANGE(4,4,0,0, 4,5,0,0))
334 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx);
335 #else
336 static inline
337 int lttng_add_cgroup_ns_to_ctx(struct lttng_kernel_ctx **ctx)
338 {
339 return -ENOSYS;
340 }
341 #endif
342
343 #if defined(CONFIG_IPC_NS) && \
344 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
345 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx);
346 #else
347 static inline
348 int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx)
349 {
350 return -ENOSYS;
351 }
352 #endif
353
354 #if !defined(LTTNG_MNT_NS_MISSING_HEADER) && \
355 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
356 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx);
357 #else
358 static inline
359 int lttng_add_mnt_ns_to_ctx(struct lttng_kernel_ctx **ctx)
360 {
361 return -ENOSYS;
362 }
363 #endif
364
365 #if defined(CONFIG_NET_NS) && \
366 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
367 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx);
368 #else
369 static inline
370 int lttng_add_net_ns_to_ctx(struct lttng_kernel_ctx **ctx)
371 {
372 return -ENOSYS;
373 }
374 #endif
375
376 #if defined(CONFIG_PID_NS) && \
377 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
378 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx);
379 #else
380 static inline
381 int lttng_add_pid_ns_to_ctx(struct lttng_kernel_ctx **ctx)
382 {
383 return -ENOSYS;
384 }
385 #endif
386
387 #if defined(CONFIG_USER_NS) && \
388 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
389 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx);
390 #else
391 static inline
392 int lttng_add_user_ns_to_ctx(struct lttng_kernel_ctx **ctx)
393 {
394 return -ENOSYS;
395 }
396 #endif
397
398 #if defined(CONFIG_UTS_NS) && \
399 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
400 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx);
401 #else
402 static inline
403 int lttng_add_uts_ns_to_ctx(struct lttng_kernel_ctx **ctx)
404 {
405 return -ENOSYS;
406 }
407 #endif
408
409 #if defined(CONFIG_TIME_NS) && \
410 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
411 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx);
412 #else
413 static inline
414 int lttng_add_time_ns_to_ctx(struct lttng_kernel_ctx **ctx)
415 {
416 return -ENOSYS;
417 }
418 #endif
419
420 int lttng_add_uid_to_ctx(struct lttng_kernel_ctx **ctx);
421 int lttng_add_euid_to_ctx(struct lttng_kernel_ctx **ctx);
422 int lttng_add_suid_to_ctx(struct lttng_kernel_ctx **ctx);
423 int lttng_add_gid_to_ctx(struct lttng_kernel_ctx **ctx);
424 int lttng_add_egid_to_ctx(struct lttng_kernel_ctx **ctx);
425 int lttng_add_sgid_to_ctx(struct lttng_kernel_ctx **ctx);
426 int lttng_add_vuid_to_ctx(struct lttng_kernel_ctx **ctx);
427 int lttng_add_veuid_to_ctx(struct lttng_kernel_ctx **ctx);
428 int lttng_add_vsuid_to_ctx(struct lttng_kernel_ctx **ctx);
429 int lttng_add_vgid_to_ctx(struct lttng_kernel_ctx **ctx);
430 int lttng_add_vegid_to_ctx(struct lttng_kernel_ctx **ctx);
431 int lttng_add_vsgid_to_ctx(struct lttng_kernel_ctx **ctx);
432
433 #if defined(CONFIG_PERF_EVENTS)
434 int lttng_add_perf_counter_to_ctx(uint32_t type,
435 uint64_t config,
436 const char *name,
437 struct lttng_kernel_ctx **ctx);
438 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
439 struct lttng_cpuhp_node *node);
440 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
441 struct lttng_cpuhp_node *node);
442 #else
443 static inline
444 int lttng_add_perf_counter_to_ctx(uint32_t type,
445 uint64_t config,
446 const char *name,
447 struct lttng_kernel_ctx **ctx)
448 {
449 return -ENOSYS;
450 }
451 static inline
452 int lttng_cpuhp_perf_counter_online(unsigned int cpu,
453 struct lttng_cpuhp_node *node)
454 {
455 return 0;
456 }
457 static inline
458 int lttng_cpuhp_perf_counter_dead(unsigned int cpu,
459 struct lttng_cpuhp_node *node)
460 {
461 return 0;
462 }
463 #endif
464
465
466
467 #define lttng_kernel_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
468 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_ctx_field, { \
469 .event_field = (_event_field), \
470 .get_size = (_get_size), \
471 .record = (_record), \
472 .get_value = (_get_value), \
473 .destroy = (_destroy), \
474 .priv = (_priv), \
475 })
476
477 #endif /* _LTTNG_EVENTS_INTERNAL_H */
This page took 0.039587 seconds and 5 git commands to generate.