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
;
67 /* Validation stack */
73 int top
; /* top of stack */
74 struct vstack_entry e
[FILTER_STACK_LEN
];
78 void vstack_init(struct vstack
*stack
)
84 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
86 if (unlikely(stack
->top
< 0))
88 return &stack
->e
[stack
->top
];
92 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
94 if (unlikely(stack
->top
< 1))
96 return &stack
->e
[stack
->top
- 1];
100 int vstack_push(struct vstack
*stack
)
102 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
103 printk(KERN_WARNING
"Stack full\n");
111 int vstack_pop(struct vstack
*stack
)
113 if (unlikely(stack
->top
< 0)) {
114 printk(KERN_WARNING
"Stack empty\n");
121 /* Execution stack */
122 struct estack_entry
{
128 const char __user
*user_str
;
130 int literal
; /* is string literal ? */
131 int user
; /* is string from userspace ? */
137 int top
; /* top of stack */
138 struct estack_entry e
[FILTER_STACK_LEN
];
141 #define estack_ax_v ax
142 #define estack_bx_v bx
144 #define estack_ax(stack, top) \
146 BUG_ON((top) <= FILTER_STACK_EMPTY); \
150 #define estack_bx(stack, top) \
152 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
153 &(stack)->e[(top) - 1]; \
156 #define estack_push(stack, top, ax, bx) \
158 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
159 (stack)->e[(top) - 1].u.v = (bx); \
164 #define estack_pop(stack, top, ax, bx) \
166 BUG_ON((top) <= FILTER_STACK_EMPTY); \
168 (bx) = (stack)->e[(top) - 2].u.v; \
172 const char *lttng_filter_print_op(enum filter_op op
);
174 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
175 int lttng_filter_specialize_bytecode(struct bytecode_runtime
*bytecode
);
177 uint64_t lttng_filter_false(void *filter_data
,
178 struct lttng_probe_ctx
*lttng_probe_ctx
,
179 const char *filter_stack_data
);
180 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
181 struct lttng_probe_ctx
*lttng_probe_ctx
,
182 const char *filter_stack_data
);
184 #endif /* _LTTNG_FILTER_H */
This page took 0.036726 seconds and 4 git commands to generate.