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
;
59 LOAD_ROOT_APP_CONTEXT
,
76 OBJECT_TYPE_STRING_SEQUENCE
,
86 struct filter_get_index_data
{
87 uint64_t offset
; /* in bytes */
92 enum object_type type
;
93 bool rev_bo
; /* reverse byte order */
97 /* Validation stack */
100 enum object_type object_type
;
101 const struct lttng_event_field
*field
;
102 bool rev_bo
; /* reverse byte order */
105 struct vstack_entry
{
106 enum entry_type type
;
107 struct vstack_load load
;
111 int top
; /* top of stack */
112 struct vstack_entry e
[FILTER_STACK_LEN
];
116 void vstack_init(struct vstack
*stack
)
122 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
124 if (unlikely(stack
->top
< 0))
126 return &stack
->e
[stack
->top
];
130 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
132 if (unlikely(stack
->top
< 1))
134 return &stack
->e
[stack
->top
- 1];
138 int vstack_push(struct vstack
*stack
)
140 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
141 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
149 int vstack_pop(struct vstack
*stack
)
151 if (unlikely(stack
->top
< 0)) {
152 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
159 /* Execution stack */
160 enum estack_string_literal_type
{
161 ESTACK_STRING_LITERAL_TYPE_NONE
,
162 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
163 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
168 enum object_type object_type
;
171 /* Temporary place-holders for contexts. */
178 * "field" is only needed when nested under a variant, in which
179 * case we cannot specialize the nested operations.
181 const struct lttng_event_field
*field
;
184 struct estack_entry
{
190 const char __user
*user_str
;
192 enum estack_string_literal_type literal_type
;
193 int user
; /* is string from userspace ? */
200 int top
; /* top of stack */
201 struct estack_entry e
[FILTER_STACK_LEN
];
204 #define estack_ax_v ax
205 #define estack_bx_v bx
207 #define estack_ax(stack, top) \
209 BUG_ON((top) <= FILTER_STACK_EMPTY); \
213 #define estack_bx(stack, top) \
215 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
216 &(stack)->e[(top) - 1]; \
219 #define estack_push(stack, top, ax, bx) \
221 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
222 (stack)->e[(top) - 1].u.v = (bx); \
227 #define estack_pop(stack, top, ax, bx) \
229 BUG_ON((top) <= FILTER_STACK_EMPTY); \
231 (bx) = (stack)->e[(top) - 2].u.v; \
235 const char *lttng_filter_print_op(enum filter_op op
);
237 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
238 int lttng_filter_specialize_bytecode(struct lttng_event
*event
,
239 struct bytecode_runtime
*bytecode
);
241 uint64_t lttng_filter_false(void *filter_data
,
242 struct lttng_probe_ctx
*lttng_probe_ctx
,
243 const char *filter_stack_data
);
244 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
245 struct lttng_probe_ctx
*lttng_probe_ctx
,
246 const char *filter_stack_data
);
248 #endif /* _LTTNG_FILTER_H */