1 /* SPDX-License-Identifier: MIT
5 * LTTng modules filter header.
7 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #ifndef _LTTNG_FILTER_H
11 #define _LTTNG_FILTER_H
13 #include <linux/kernel.h>
15 #include <lttng/events.h>
16 #include <lttng/filter-bytecode.h>
18 /* Filter stack length, in number of entries */
19 #define FILTER_STACK_LEN 10 /* includes 2 dummy */
20 #define FILTER_STACK_EMPTY 1
22 #define FILTER_MAX_DATA_LEN 65536
25 #define dbg_printk(fmt, args...) \
26 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
27 __FILE__, __func__, __LINE__, ## args)
29 #define dbg_printk(fmt, args...) \
31 /* do nothing but check printf format */ \
33 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
34 __FILE__, __func__, __LINE__, ## args); \
38 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
39 struct bytecode_runtime
{
40 struct lttng_bytecode_runtime p
;
42 size_t data_alloc_len
;
60 LOAD_ROOT_APP_CONTEXT
,
77 OBJECT_TYPE_STRING_SEQUENCE
,
87 struct filter_get_index_data
{
88 uint64_t offset
; /* in bytes */
92 * Field is only populated for LOAD_ROOT_CONTEXT, LOAD_ROOT_APP_CONTEXT
93 * and LOAD_ROOT_PAYLOAD. Left NULL for LOAD_OBJECT, considering that the
94 * interpreter needs to find it from the event fields and types to
97 const struct lttng_event_field
*field
;
100 enum object_type type
;
101 bool rev_bo
; /* reverse byte order */
105 /* Validation stack */
108 enum object_type object_type
;
109 const struct lttng_event_field
*field
;
110 bool rev_bo
; /* reverse byte order */
113 struct vstack_entry
{
114 enum entry_type type
;
115 struct vstack_load load
;
119 int top
; /* top of stack */
120 struct vstack_entry e
[FILTER_STACK_LEN
];
124 void vstack_init(struct vstack
*stack
)
130 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
132 if (unlikely(stack
->top
< 0))
134 return &stack
->e
[stack
->top
];
138 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
140 if (unlikely(stack
->top
< 1))
142 return &stack
->e
[stack
->top
- 1];
146 int vstack_push(struct vstack
*stack
)
148 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
149 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
157 int vstack_pop(struct vstack
*stack
)
159 if (unlikely(stack
->top
< 0)) {
160 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
167 /* Execution stack */
168 enum estack_string_literal_type
{
169 ESTACK_STRING_LITERAL_TYPE_NONE
,
170 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
171 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
176 enum object_type object_type
;
180 /* Temporary place-holders for contexts. */
186 const struct lttng_event_field
*field
;
189 struct estack_entry
{
190 enum entry_type type
;
196 const char __user
*user_str
;
198 enum estack_string_literal_type literal_type
;
199 int user
; /* is string from userspace ? */
206 int top
; /* top of stack */
207 struct estack_entry e
[FILTER_STACK_LEN
];
210 #define estack_ax_v ax
211 #define estack_bx_v bx
213 #define estack_ax_t ax_t
214 #define estack_bx_t bx_t
216 #define estack_ax(stack, top) \
218 BUG_ON((top) <= FILTER_STACK_EMPTY); \
222 #define estack_bx(stack, top) \
224 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
225 &(stack)->e[(top) - 1]; \
228 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
230 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
231 (stack)->e[(top) - 1].u.v = (bx); \
232 (stack)->e[(top) - 1].type = (bx_t); \
238 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
240 BUG_ON((top) <= FILTER_STACK_EMPTY); \
243 (bx) = (stack)->e[(top) - 2].u.v; \
244 (bx_t) = (stack)->e[(top) - 2].type; \
248 enum lttng_interpreter_type
{
249 LTTNG_INTERPRETER_TYPE_S64
,
250 LTTNG_INTERPRETER_TYPE_U64
,
251 LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
,
252 LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
,
253 LTTNG_INTERPRETER_TYPE_DOUBLE
,
254 LTTNG_INTERPRETER_TYPE_STRING
,
255 LTTNG_INTERPRETER_TYPE_SEQUENCE
,
259 * Represents the output parameter of the lttng interpreter.
260 * Currently capturable field classes are integer, double, string and sequence
263 struct lttng_interpreter_output
{
264 enum lttng_interpreter_type type
;
278 const struct lttng_type
*nested_type
;
283 const char *lttng_filter_print_op(enum filter_op op
);
285 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
286 int lttng_filter_specialize_bytecode(const struct lttng_event_desc
*event_desc
,
287 struct bytecode_runtime
*bytecode
);
289 uint64_t lttng_filter_interpret_bytecode_false(void *filter_data
,
290 struct lttng_probe_ctx
*lttng_probe_ctx
,
291 const char *filter_stack_data
);
292 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
293 struct lttng_probe_ctx
*lttng_probe_ctx
,
294 const char *filter_stack_data
);
296 #endif /* _LTTNG_FILTER_H */