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 8
43 #define min_t(type, a, b) \
44 ((type) (a) < (type) (b) ? (type) (a) : (type) (b))
48 #define likely(x) __builtin_expect(!!(x), 1)
52 #define unlikely(x) __builtin_expect(!!(x), 0)
56 #define dbg_printf(fmt, args...) printf("[debug bytecode] " fmt, ## args)
58 #define dbg_printf(fmt, args...) \
60 /* do nothing but check printf format */ \
62 printf("[debug bytecode] " fmt, ## args); \
67 struct bytecode_runtime
{
79 /* Validation stack */
85 int top
; /* top of stack */
86 struct vstack_entry e
[FILTER_STACK_LEN
];
90 void vstack_init(struct vstack
*stack
)
96 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
98 if (unlikely(stack
->top
< 0))
100 return &stack
->e
[stack
->top
];
104 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
106 if (unlikely(stack
->top
< 1))
108 return &stack
->e
[stack
->top
- 1];
112 int vstack_push(struct vstack
*stack
)
114 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
123 int vstack_pop(struct vstack
*stack
)
125 if (unlikely(stack
->top
< 0)) {
126 ERR("Stack empty\n");
133 /* Execution stack */
134 struct estack_entry
{
135 enum entry_type type
;
144 int literal
; /* is string literal ? */
150 int top
; /* top of stack */
151 struct estack_entry e
[FILTER_STACK_LEN
];
155 void estack_init(struct estack
*stack
)
161 struct estack_entry
*estack_ax(struct estack
*stack
)
163 assert(stack
->top
>= 0);
164 return &stack
->e
[stack
->top
];
168 struct estack_entry
*estack_bx(struct estack
*stack
)
170 assert(stack
->top
>= 1);
171 return &stack
->e
[stack
->top
- 1];
175 void estack_push(struct estack
*stack
)
177 assert(stack
->top
< FILTER_STACK_LEN
- 1);
182 void estack_pop(struct estack
*stack
)
184 assert(stack
->top
>= 0);
188 const char *print_op(enum filter_op op
);
190 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
191 int lttng_filter_specialize_bytecode(struct bytecode_runtime
*bytecode
);
193 int lttng_filter_false(void *filter_data
,
194 const char *filter_stack_data
);
195 int lttng_filter_interpret_bytecode(void *filter_data
,
196 const char *filter_stack_data
);
198 #endif /* _LTTNG_FILTER_H */
This page took 0.033395 seconds and 4 git commands to generate.