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...) \
58 printf("[debug bytecode in %s:%s@%u] " fmt, \
59 __FILE__, __func__, __LINE__, ## args)
61 #define dbg_printf(fmt, args...) \
63 /* do nothing but check printf format */ \
65 printf("[debug bytecode in %s:%s@%u] " fmt, \
66 __FILE__, __func__, __LINE__, ## args); \
70 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
71 struct bytecode_runtime
{
72 struct lttng_bytecode_runtime p
;
84 /* Validation stack */
90 int top
; /* top of stack */
91 struct vstack_entry e
[FILTER_STACK_LEN
];
95 void vstack_init(struct vstack
*stack
)
101 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
103 if (unlikely(stack
->top
< 0))
105 return &stack
->e
[stack
->top
];
109 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
111 if (unlikely(stack
->top
< 1))
113 return &stack
->e
[stack
->top
- 1];
117 int vstack_push(struct vstack
*stack
)
119 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
128 int vstack_pop(struct vstack
*stack
)
130 if (unlikely(stack
->top
< 0)) {
131 ERR("Stack empty\n");
138 /* Execution stack */
139 struct estack_entry
{
147 int literal
; /* is string literal ? */
153 int top
; /* top of stack */
154 struct estack_entry e
[FILTER_STACK_LEN
];
157 #define estack_ax_v ax
158 #define estack_bx_v bx
160 #define estack_ax(stack, top) \
162 assert((top) > FILTER_STACK_EMPTY); \
166 #define estack_bx(stack, top) \
168 assert((top) > FILTER_STACK_EMPTY + 1); \
169 &(stack)->e[(top) - 1]; \
172 #define estack_push(stack, top, ax, bx) \
174 assert((top) < FILTER_STACK_LEN - 1); \
175 (stack)->e[(top) - 1].u.v = (bx); \
180 #define estack_pop(stack, top, ax, bx) \
182 assert((top) > FILTER_STACK_EMPTY); \
184 (bx) = (stack)->e[(top) - 2].u.v; \
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 uint64_t lttng_filter_false(void *filter_data
,
194 const char *filter_stack_data
);
195 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
196 const char *filter_stack_data
);
198 #endif /* _LTTNG_FILTER_H */
This page took 0.061778 seconds and 4 git commands to generate.