c2e8c78398e4f0ea47167b74a39469ca9a1a105c
[lttng-tools.git] / src / lib / lttng-ctl / filter / filter-bytecode.h
1 #ifndef _FILTER_BYTECODE_H
2 #define _FILTER_BYTECODE_H
3
4 /*
5 * filter-bytecode.h
6 *
7 * LTTng filter bytecode
8 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License, version 2.1 only,
13 * as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include <common/sessiond-comm/sessiond-comm.h>
26
27 #include "filter-ast.h"
28
29 /*
30 * offsets are absolute from start of bytecode.
31 */
32
33 struct field_ref {
34 /* Initially, symbol offset. After link, field offset. */
35 uint16_t offset;
36 } LTTNG_PACKED;
37
38 struct get_symbol {
39 /* Symbol offset. */
40 uint16_t offset;
41 } LTTNG_PACKED;
42
43 struct get_index_u16 {
44 uint16_t index;
45 } LTTNG_PACKED;
46
47 struct get_index_u64 {
48 uint64_t index;
49 } LTTNG_PACKED;
50
51 struct literal_numeric {
52 int64_t v;
53 } LTTNG_PACKED;
54
55 struct literal_double {
56 double v;
57 } LTTNG_PACKED;
58
59 struct literal_string {
60 char string[0];
61 } LTTNG_PACKED;
62
63 enum filter_op {
64 FILTER_OP_UNKNOWN = 0,
65
66 FILTER_OP_RETURN = 1,
67
68 /* binary */
69 FILTER_OP_MUL = 2,
70 FILTER_OP_DIV = 3,
71 FILTER_OP_MOD = 4,
72 FILTER_OP_PLUS = 5,
73 FILTER_OP_MINUS = 6,
74 FILTER_OP_BIT_RSHIFT = 7,
75 FILTER_OP_BIT_LSHIFT = 8,
76 FILTER_OP_BIT_AND = 9,
77 FILTER_OP_BIT_OR = 10,
78 FILTER_OP_BIT_XOR = 11,
79
80 /* binary comparators */
81 FILTER_OP_EQ = 12,
82 FILTER_OP_NE = 13,
83 FILTER_OP_GT = 14,
84 FILTER_OP_LT = 15,
85 FILTER_OP_GE = 16,
86 FILTER_OP_LE = 17,
87
88 /* string binary comparator: apply to */
89 FILTER_OP_EQ_STRING = 18,
90 FILTER_OP_NE_STRING = 19,
91 FILTER_OP_GT_STRING = 20,
92 FILTER_OP_LT_STRING = 21,
93 FILTER_OP_GE_STRING = 22,
94 FILTER_OP_LE_STRING = 23,
95
96 /* s64 binary comparator */
97 FILTER_OP_EQ_S64 = 24,
98 FILTER_OP_NE_S64 = 25,
99 FILTER_OP_GT_S64 = 26,
100 FILTER_OP_LT_S64 = 27,
101 FILTER_OP_GE_S64 = 28,
102 FILTER_OP_LE_S64 = 29,
103
104 /* double binary comparator */
105 FILTER_OP_EQ_DOUBLE = 30,
106 FILTER_OP_NE_DOUBLE = 31,
107 FILTER_OP_GT_DOUBLE = 32,
108 FILTER_OP_LT_DOUBLE = 33,
109 FILTER_OP_GE_DOUBLE = 34,
110 FILTER_OP_LE_DOUBLE = 35,
111
112 /* Mixed S64-double binary comparators */
113 FILTER_OP_EQ_DOUBLE_S64 = 36,
114 FILTER_OP_NE_DOUBLE_S64 = 37,
115 FILTER_OP_GT_DOUBLE_S64 = 38,
116 FILTER_OP_LT_DOUBLE_S64 = 39,
117 FILTER_OP_GE_DOUBLE_S64 = 40,
118 FILTER_OP_LE_DOUBLE_S64 = 41,
119
120 FILTER_OP_EQ_S64_DOUBLE = 42,
121 FILTER_OP_NE_S64_DOUBLE = 43,
122 FILTER_OP_GT_S64_DOUBLE = 44,
123 FILTER_OP_LT_S64_DOUBLE = 45,
124 FILTER_OP_GE_S64_DOUBLE = 46,
125 FILTER_OP_LE_S64_DOUBLE = 47,
126
127 /* unary */
128 FILTER_OP_UNARY_PLUS = 48,
129 FILTER_OP_UNARY_MINUS = 49,
130 FILTER_OP_UNARY_NOT = 50,
131 FILTER_OP_UNARY_PLUS_S64 = 51,
132 FILTER_OP_UNARY_MINUS_S64 = 52,
133 FILTER_OP_UNARY_NOT_S64 = 53,
134 FILTER_OP_UNARY_PLUS_DOUBLE = 54,
135 FILTER_OP_UNARY_MINUS_DOUBLE = 55,
136 FILTER_OP_UNARY_NOT_DOUBLE = 56,
137
138 /* logical */
139 FILTER_OP_AND = 57,
140 FILTER_OP_OR = 58,
141
142 /* load field ref */
143 FILTER_OP_LOAD_FIELD_REF = 59,
144 FILTER_OP_LOAD_FIELD_REF_STRING = 60,
145 FILTER_OP_LOAD_FIELD_REF_SEQUENCE = 61,
146 FILTER_OP_LOAD_FIELD_REF_S64 = 62,
147 FILTER_OP_LOAD_FIELD_REF_DOUBLE = 63,
148
149 /* load immediate from operand */
150 FILTER_OP_LOAD_STRING = 64,
151 FILTER_OP_LOAD_S64 = 65,
152 FILTER_OP_LOAD_DOUBLE = 66,
153
154 /* cast */
155 FILTER_OP_CAST_TO_S64 = 67,
156 FILTER_OP_CAST_DOUBLE_TO_S64 = 68,
157 FILTER_OP_CAST_NOP = 69,
158
159 /* get context ref */
160 FILTER_OP_GET_CONTEXT_REF = 70,
161 FILTER_OP_GET_CONTEXT_REF_STRING = 71,
162 FILTER_OP_GET_CONTEXT_REF_S64 = 72,
163 FILTER_OP_GET_CONTEXT_REF_DOUBLE = 73,
164
165 /* load userspace field ref */
166 FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74,
167 FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75,
168
169 /*
170 * load immediate star globbing pattern (literal string)
171 * from immediate
172 */
173 FILTER_OP_LOAD_STAR_GLOB_STRING = 76,
174
175 /* globbing pattern binary operator: apply to */
176 FILTER_OP_EQ_STAR_GLOB_STRING = 77,
177 FILTER_OP_NE_STAR_GLOB_STRING = 78,
178
179 /*
180 * Instructions for recursive traversal through composed types.
181 */
182 FILTER_OP_GET_CONTEXT_ROOT = 79,
183 FILTER_OP_GET_APP_CONTEXT_ROOT = 80,
184 FILTER_OP_GET_PAYLOAD_ROOT = 81,
185
186 FILTER_OP_GET_SYMBOL = 82,
187 FILTER_OP_GET_SYMBOL_FIELD = 83,
188 FILTER_OP_GET_INDEX_U16 = 84,
189 FILTER_OP_GET_INDEX_U64 = 85,
190
191 FILTER_OP_LOAD_FIELD = 86,
192 FILTER_OP_LOAD_FIELD_S8 = 87,
193 FILTER_OP_LOAD_FIELD_S16 = 88,
194 FILTER_OP_LOAD_FIELD_S32 = 89,
195 FILTER_OP_LOAD_FIELD_S64 = 90,
196 FILTER_OP_LOAD_FIELD_U8 = 91,
197 FILTER_OP_LOAD_FIELD_U16 = 92,
198 FILTER_OP_LOAD_FIELD_U32 = 93,
199 FILTER_OP_LOAD_FIELD_U64 = 94,
200 FILTER_OP_LOAD_FIELD_STRING = 95,
201 FILTER_OP_LOAD_FIELD_SEQUENCE = 96,
202 FILTER_OP_LOAD_FIELD_DOUBLE = 97,
203
204 FILTER_OP_UNARY_BIT_NOT = 98,
205
206 FILTER_OP_RETURN_S64 = 99,
207
208 NR_FILTER_OPS,
209 };
210
211 typedef uint8_t filter_opcode_t;
212
213 struct load_op {
214 filter_opcode_t op;
215 char data[0];
216 /* data to load. Size known by enum filter_opcode and null-term char. */
217 } LTTNG_PACKED;
218
219 struct binary_op {
220 filter_opcode_t op;
221 } LTTNG_PACKED;
222
223 struct unary_op {
224 filter_opcode_t op;
225 } LTTNG_PACKED;
226
227 /* skip_offset is absolute from start of bytecode */
228 struct logical_op {
229 filter_opcode_t op;
230 uint16_t skip_offset; /* bytecode insn, if skip second test */
231 } LTTNG_PACKED;
232
233 struct cast_op {
234 filter_opcode_t op;
235 } LTTNG_PACKED;
236
237 struct return_op {
238 filter_opcode_t op;
239 } LTTNG_PACKED;
240
241 struct lttng_filter_bytecode_alloc {
242 uint32_t alloc_len;
243 struct lttng_filter_bytecode b;
244 };
245
246 static inline
247 unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode)
248 {
249 return bytecode->len;
250 }
251
252 #endif /* _FILTER_BYTECODE_H */
This page took 0.033132 seconds and 4 git commands to generate.