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>
30 #include <lttng/ust-context-provider.h>
37 #include <usterr-signal-safe.h>
38 #include "filter-bytecode.h"
40 /* Filter stack length, in number of entries */
41 #define FILTER_STACK_LEN 10 /* includes 2 dummy */
42 #define FILTER_STACK_EMPTY 1
45 #define min_t(type, a, b) \
46 ((type) (a) < (type) (b) ? (type) (a) : (type) (b))
50 #define likely(x) __builtin_expect(!!(x), 1)
54 #define unlikely(x) __builtin_expect(!!(x), 0)
58 #define dbg_printf(fmt, args...) \
59 printf("[debug bytecode in %s:%s@%u] " fmt, \
60 __FILE__, __func__, __LINE__, ## args)
62 #define dbg_printf(fmt, args...) \
64 /* do nothing but check printf format */ \
66 printf("[debug bytecode in %s:%s@%u] " fmt, \
67 __FILE__, __func__, __LINE__, ## args); \
71 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
72 struct bytecode_runtime
{
73 struct lttng_bytecode_runtime p
;
85 /* Validation stack */
91 int top
; /* top of stack */
92 struct vstack_entry e
[FILTER_STACK_LEN
];
96 void vstack_init(struct vstack
*stack
)
102 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
104 if (unlikely(stack
->top
< 0))
106 return &stack
->e
[stack
->top
];
110 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
112 if (unlikely(stack
->top
< 1))
114 return &stack
->e
[stack
->top
- 1];
118 int vstack_push(struct vstack
*stack
)
120 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
129 int vstack_pop(struct vstack
*stack
)
131 if (unlikely(stack
->top
< 0)) {
132 ERR("Stack empty\n");
139 /* Execution stack */
140 struct estack_entry
{
141 enum entry_type type
; /* For dynamic typing. */
149 int literal
; /* is string literal ? */
155 int top
; /* top of stack */
156 struct estack_entry e
[FILTER_STACK_LEN
];
160 * Always use aliased type for ax/bx (top of stack).
161 * When ax/bx are S64, use aliased value.
163 #define estack_ax_v ax
164 #define estack_bx_v bx
165 #define estack_ax_t ax_t
166 #define estack_bx_t bx_t
169 * ax and bx registers can hold either integer, double or string.
171 #define estack_ax(stack, top) \
173 assert((top) > FILTER_STACK_EMPTY); \
177 #define estack_bx(stack, top) \
179 assert((top) > FILTER_STACK_EMPTY + 1); \
180 &(stack)->e[(top) - 1]; \
184 * Currently, only integers (REG_S64) can be pushed into the stack.
186 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
188 assert((top) < FILTER_STACK_LEN - 1); \
189 (stack)->e[(top) - 1].u.v = (bx); \
190 (stack)->e[(top) - 1].type = (bx_t); \
196 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
198 assert((top) > FILTER_STACK_EMPTY); \
201 (bx) = (stack)->e[(top) - 2].u.v; \
202 (bx_t) = (stack)->e[(top) - 2].type; \
206 const char *print_op(enum filter_op op
);
208 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
209 int lttng_filter_specialize_bytecode(struct bytecode_runtime
*bytecode
);
211 uint64_t lttng_filter_false(void *filter_data
,
212 const char *filter_stack_data
);
213 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
214 const char *filter_stack_data
);
216 #endif /* _LTTNG_FILTER_H */
This page took 0.044513 seconds and 4 git commands to generate.