1 #ifndef _LTTNG_FILTER_H
2 #define _LTTNG_FILTER_H
7 * LTTng modules filter header.
9 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <linux/kernel.h>
32 #include <lttng-events.h>
33 #include <filter-bytecode.h>
35 /* Filter stack length, in number of entries */
36 #define FILTER_STACK_LEN 10 /* includes 2 dummy */
37 #define FILTER_STACK_EMPTY 1
39 #define FILTER_MAX_DATA_LEN 65536
42 #define dbg_printk(fmt, args...) \
43 printk(KERN_DEBUG "[debug bytecode in %s:%s@%u] " fmt, \
44 __FILE__, __func__, __LINE__, ## args)
46 #define dbg_printk(fmt, args...) \
48 /* do nothing but check printf format */ \
50 printk(KERN_DEBUG "[debug bytecode in %s:%s@%u] " fmt, \
51 __FILE__, __func__, __LINE__, ## args); \
55 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
56 struct bytecode_runtime
{
57 struct lttng_bytecode_runtime p
;
59 size_t data_alloc_len
;
76 LOAD_ROOT_APP_CONTEXT
,
93 OBJECT_TYPE_STRING_SEQUENCE
,
103 struct filter_get_index_data
{
104 uint64_t offset
; /* in bytes */
109 enum object_type type
;
110 bool rev_bo
; /* reverse byte order */
114 /* Validation stack */
117 enum object_type object_type
;
118 const struct lttng_event_field
*field
;
119 bool rev_bo
; /* reverse byte order */
122 struct vstack_entry
{
123 enum entry_type type
;
124 struct vstack_load load
;
128 int top
; /* top of stack */
129 struct vstack_entry e
[FILTER_STACK_LEN
];
133 void vstack_init(struct vstack
*stack
)
139 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
141 if (unlikely(stack
->top
< 0))
143 return &stack
->e
[stack
->top
];
147 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
149 if (unlikely(stack
->top
< 1))
151 return &stack
->e
[stack
->top
- 1];
155 int vstack_push(struct vstack
*stack
)
157 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
158 printk(KERN_WARNING
"Stack full\n");
166 int vstack_pop(struct vstack
*stack
)
168 if (unlikely(stack
->top
< 0)) {
169 printk(KERN_WARNING
"Stack empty\n");
176 /* Execution stack */
177 enum estack_string_literal_type
{
178 ESTACK_STRING_LITERAL_TYPE_NONE
,
179 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
180 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
185 enum object_type object_type
;
188 /* Temporary place-holders for contexts. */
195 * "field" is only needed when nested under a variant, in which
196 * case we cannot specialize the nested operations.
198 const struct lttng_event_field
*field
;
201 struct estack_entry
{
207 const char __user
*user_str
;
209 enum estack_string_literal_type literal_type
;
210 int user
; /* is string from userspace ? */
217 int top
; /* top of stack */
218 struct estack_entry e
[FILTER_STACK_LEN
];
221 #define estack_ax_v ax
222 #define estack_bx_v bx
224 #define estack_ax(stack, top) \
226 BUG_ON((top) <= FILTER_STACK_EMPTY); \
230 #define estack_bx(stack, top) \
232 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
233 &(stack)->e[(top) - 1]; \
236 #define estack_push(stack, top, ax, bx) \
238 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
239 (stack)->e[(top) - 1].u.v = (bx); \
244 #define estack_pop(stack, top, ax, bx) \
246 BUG_ON((top) <= FILTER_STACK_EMPTY); \
248 (bx) = (stack)->e[(top) - 2].u.v; \
252 const char *lttng_filter_print_op(enum filter_op op
);
254 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
255 int lttng_filter_specialize_bytecode(struct lttng_event
*event
,
256 struct bytecode_runtime
*bytecode
);
258 uint64_t lttng_filter_false(void *filter_data
,
259 struct lttng_probe_ctx
*lttng_probe_ctx
,
260 const char *filter_stack_data
);
261 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
262 struct lttng_probe_ctx
*lttng_probe_ctx
,
263 const char *filter_stack_data
);
265 #endif /* _LTTNG_FILTER_H */