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
40 #define dbg_printk(fmt, args...) \
41 printk(KERN_DEBUG "[debug bytecode in %s:%s@%u] " fmt, \
42 __FILE__, __func__, __LINE__, ## args)
44 #define dbg_printk(fmt, args...) \
46 /* do nothing but check printf format */ \
48 printk(KERN_DEBUG "[debug bytecode in %s:%s@%u] " fmt, \
49 __FILE__, __func__, __LINE__, ## args); \
53 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
54 struct bytecode_runtime
{
55 struct lttng_bytecode_runtime p
;
68 /* Validation stack */
74 int top
; /* top of stack */
75 struct vstack_entry e
[FILTER_STACK_LEN
];
79 void vstack_init(struct vstack
*stack
)
85 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
87 if (unlikely(stack
->top
< 0))
89 return &stack
->e
[stack
->top
];
93 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
95 if (unlikely(stack
->top
< 1))
97 return &stack
->e
[stack
->top
- 1];
101 int vstack_push(struct vstack
*stack
)
103 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
104 printk(KERN_WARNING
"Stack full\n");
112 int vstack_pop(struct vstack
*stack
)
114 if (unlikely(stack
->top
< 0)) {
115 printk(KERN_WARNING
"Stack empty\n");
122 /* Execution stack */
123 enum estack_string_literal_type
{
124 ESTACK_STRING_LITERAL_TYPE_NONE
,
125 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
126 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
129 struct estack_entry
{
135 const char __user
*user_str
;
137 enum estack_string_literal_type literal_type
;
138 int user
; /* is string from userspace ? */
144 int top
; /* top of stack */
145 struct estack_entry e
[FILTER_STACK_LEN
];
148 #define estack_ax_v ax
149 #define estack_bx_v bx
151 #define estack_ax(stack, top) \
153 BUG_ON((top) <= FILTER_STACK_EMPTY); \
157 #define estack_bx(stack, top) \
159 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
160 &(stack)->e[(top) - 1]; \
163 #define estack_push(stack, top, ax, bx) \
165 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
166 (stack)->e[(top) - 1].u.v = (bx); \
171 #define estack_pop(stack, top, ax, bx) \
173 BUG_ON((top) <= FILTER_STACK_EMPTY); \
175 (bx) = (stack)->e[(top) - 2].u.v; \
179 const char *lttng_filter_print_op(enum filter_op op
);
181 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
182 int lttng_filter_specialize_bytecode(struct bytecode_runtime
*bytecode
);
184 uint64_t lttng_filter_false(void *filter_data
,
185 struct lttng_probe_ctx
*lttng_probe_ctx
,
186 const char *filter_stack_data
);
187 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
188 struct lttng_probe_ctx
*lttng_probe_ctx
,
189 const char *filter_stack_data
);
191 #endif /* _LTTNG_FILTER_H */