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 */
93 enum object_type type
;
94 bool rev_bo
; /* reverse byte order */
98 /* Validation stack */
101 enum object_type object_type
;
102 const struct lttng_event_field
*field
;
103 bool rev_bo
; /* reverse byte order */
106 struct vstack_entry
{
107 enum entry_type type
;
108 struct vstack_load load
;
112 int top
; /* top of stack */
113 struct vstack_entry e
[FILTER_STACK_LEN
];
117 void vstack_init(struct vstack
*stack
)
123 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
125 if (unlikely(stack
->top
< 0))
127 return &stack
->e
[stack
->top
];
131 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
133 if (unlikely(stack
->top
< 1))
135 return &stack
->e
[stack
->top
- 1];
139 int vstack_push(struct vstack
*stack
)
141 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
142 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
150 int vstack_pop(struct vstack
*stack
)
152 if (unlikely(stack
->top
< 0)) {
153 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
160 /* Execution stack */
161 enum estack_string_literal_type
{
162 ESTACK_STRING_LITERAL_TYPE_NONE
,
163 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
164 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
169 enum object_type object_type
;
172 /* Temporary place-holders for contexts. */
179 * "field" is only needed when nested under a variant, in which
180 * case we cannot specialize the nested operations.
182 const struct lttng_event_field
*field
;
185 struct estack_entry
{
186 enum entry_type type
;
192 const char __user
*user_str
;
194 enum estack_string_literal_type literal_type
;
195 int user
; /* is string from userspace ? */
202 int top
; /* top of stack */
203 struct estack_entry e
[FILTER_STACK_LEN
];
206 #define estack_ax_v ax
207 #define estack_bx_v bx
209 #define estack_ax_t ax_t
210 #define estack_bx_t bx_t
212 #define estack_ax(stack, top) \
214 BUG_ON((top) <= FILTER_STACK_EMPTY); \
218 #define estack_bx(stack, top) \
220 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
221 &(stack)->e[(top) - 1]; \
224 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
226 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
227 (stack)->e[(top) - 1].u.v = (bx); \
228 (stack)->e[(top) - 1].type = (bx_t); \
234 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
236 BUG_ON((top) <= FILTER_STACK_EMPTY); \
239 (bx) = (stack)->e[(top) - 2].u.v; \
240 (bx_t) = (stack)->e[(top) - 2].type; \
244 const char *lttng_filter_print_op(enum filter_op op
);
246 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
247 int lttng_filter_specialize_bytecode(const struct lttng_event_desc
*event_desc
,
248 struct bytecode_runtime
*bytecode
);
250 uint64_t lttng_filter_false(void *filter_data
,
251 struct lttng_probe_ctx
*lttng_probe_ctx
,
252 const char *filter_stack_data
);
253 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
254 struct lttng_probe_ctx
*lttng_probe_ctx
,
255 const char *filter_stack_data
);
257 #endif /* _LTTNG_FILTER_H */