1 #ifndef _LTTNG_FILTER_H
2 #define _LTTNG_FILTER_H
7 * LTTng UST 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
33 #include <lttng/ust-events.h>
34 #include <lttng/ust-context-provider.h>
41 #include <usterr-signal-safe.h>
42 #include "filter-bytecode.h"
44 /* Filter stack length, in number of entries */
45 #define FILTER_STACK_LEN 10 /* includes 2 dummy */
46 #define FILTER_STACK_EMPTY 1
49 #define min_t(type, a, b) \
50 ((type) (a) < (type) (b) ? (type) (a) : (type) (b))
54 #define likely(x) __builtin_expect(!!(x), 1)
58 #define unlikely(x) __builtin_expect(!!(x), 0)
62 #define dbg_printf(fmt, args...) \
63 printf("[debug bytecode in %s:%s@%u] " fmt, \
64 __FILE__, __func__, __LINE__, ## args)
66 #define dbg_printf(fmt, args...) \
68 /* do nothing but check printf format */ \
70 printf("[debug bytecode in %s:%s@%u] " fmt, \
71 __FILE__, __func__, __LINE__, ## args); \
75 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
76 struct bytecode_runtime
{
77 struct lttng_bytecode_runtime p
;
90 /* Validation stack */
96 int top
; /* top of stack */
97 struct vstack_entry e
[FILTER_STACK_LEN
];
101 void vstack_init(struct vstack
*stack
)
107 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
109 if (unlikely(stack
->top
< 0))
111 return &stack
->e
[stack
->top
];
115 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
117 if (unlikely(stack
->top
< 1))
119 return &stack
->e
[stack
->top
- 1];
123 int vstack_push(struct vstack
*stack
)
125 if (stack
->top
>= FILTER_STACK_LEN
- 1) {
134 int vstack_pop(struct vstack
*stack
)
136 if (unlikely(stack
->top
< 0)) {
137 ERR("Stack empty\n");
144 /* Execution stack */
145 enum estack_string_literal_type
{
146 ESTACK_STRING_LITERAL_TYPE_NONE
,
147 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
148 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
151 struct estack_entry
{
152 enum entry_type type
; /* For dynamic typing. */
160 enum estack_string_literal_type literal_type
;
166 int top
; /* top of stack */
167 struct estack_entry e
[FILTER_STACK_LEN
];
171 * Always use aliased type for ax/bx (top of stack).
172 * When ax/bx are S64, use aliased value.
174 #define estack_ax_v ax
175 #define estack_bx_v bx
176 #define estack_ax_t ax_t
177 #define estack_bx_t bx_t
180 * ax and bx registers can hold either integer, double or string.
182 #define estack_ax(stack, top) \
184 assert((top) > FILTER_STACK_EMPTY); \
188 #define estack_bx(stack, top) \
190 assert((top) > FILTER_STACK_EMPTY + 1); \
191 &(stack)->e[(top) - 1]; \
195 * Currently, only integers (REG_S64) can be pushed into the stack.
197 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
199 assert((top) < FILTER_STACK_LEN - 1); \
200 (stack)->e[(top) - 1].u.v = (bx); \
201 (stack)->e[(top) - 1].type = (bx_t); \
207 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
209 assert((top) > FILTER_STACK_EMPTY); \
212 (bx) = (stack)->e[(top) - 2].u.v; \
213 (bx_t) = (stack)->e[(top) - 2].type; \
217 const char *print_op(enum filter_op op
);
219 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
);
220 int lttng_filter_specialize_bytecode(struct bytecode_runtime
*bytecode
);
222 uint64_t lttng_filter_false(void *filter_data
,
223 const char *filter_stack_data
);
224 uint64_t lttng_filter_interpret_bytecode(void *filter_data
,
225 const char *filter_stack_data
);
227 #endif /* _LTTNG_FILTER_H */