1 #ifndef _LTTNG_FILTER_H
2 #define _LTTNG_FILTER_H
7 * LTTng UST filter header.
9 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <lttng/ust-events.h>
36 #include <usterr-signal-safe.h>
37 #include "filter-bytecode.h"
39 /* Filter stack length, in number of entries */
40 #define FILTER_STACK_LEN 10 /* includes 2 dummy */
41 #define FILTER_STACK_EMPTY 1
44 #define min_t(type, a, b) \
45 ((type) (a) < (type) (b) ? (type) (a) : (type) (b))
49 #define likely(x) __builtin_expect(!!(x), 1)
53 #define unlikely(x) __builtin_expect(!!(x), 0)
57 #define dbg_printf(fmt, args...) printf("[debug bytecode] " fmt, ## args)
59 #define dbg_printf(fmt, args...) \
61 /* do nothing but check printf format */ \
63 printf("[debug bytecode] " fmt, ## args); \
68 struct bytecode_runtime
{
80 /* Validation stack */
86 int top
; /* top of stack */
87 struct vstack_entry e
[FILTER_STACK_LEN
];
91 void vstack_init(struct vstack
*stack
)
97 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
99 if (unlikely(stack
->top
< 0))
101 return &stack
->e
[stack
->top
];
105 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
107 if (unlikely(stack
->top
< 1))
109 return &stack
->e
[stack
->top
- 1];
113 int vstack_push(struct vstack
*stack
)
115 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
124 int vstack_pop(struct vstack
*stack
)
126 if (unlikely(stack
->top
< 0)) {
127 ERR("Stack empty\n");
134 /* Execution stack */
135 struct estack_entry
{
143 int literal
; /* is string literal ? */
149 int top
; /* top of stack */
150 struct estack_entry e
[FILTER_STACK_LEN
];
153 #define estack_ax_v ax
154 #define estack_bx_v bx
156 #define estack_ax(stack, top) \
158 assert((top) > FILTER_STACK_EMPTY); \
162 #define estack_bx(stack, top) \
164 assert((top) > FILTER_STACK_EMPTY + 1); \
165 &(stack)->e[(top) - 1]; \
168 #define estack_push(stack, top, ax, bx) \
170 assert((top) < FILTER_STACK_LEN - 1); \
171 (stack)->e[(top) - 1].u.v = (bx); \
176 #define estack_pop(stack, top, ax, bx) \
178 assert((top) > FILTER_STACK_EMPTY); \
180 (bx) = (stack)->e[(top) - 2].u.v; \
184 const char *print_op(enum filter_op op
);
186 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
187 int lttng_filter_specialize_bytecode(struct bytecode_runtime
*bytecode
);
189 int lttng_filter_false(void *filter_data
,
190 const char *filter_stack_data
);
191 int lttng_filter_interpret_bytecode(void *filter_data
,
192 const char *filter_stack_data
);
194 #endif /* _LTTNG_FILTER_H */
This page took 0.032941 seconds and 4 git commands to generate.