Commit | Line | Data |
---|---|---|
953192ba MD |
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 | ||
d00c599e DG |
25 | #include <common/sessiond-comm/sessiond-comm.h> |
26 | ||
953192ba MD |
27 | #include "filter-ast.h" |
28 | ||
29 | /* | |
30 | * offsets are absolute from start of bytecode. | |
31 | */ | |
32 | ||
953192ba MD |
33 | struct field_ref { |
34 | /* Initially, symbol offset. After link, field offset. */ | |
35 | uint16_t offset; | |
6f30f9b8 | 36 | } LTTNG_PACKED; |
953192ba | 37 | |
bff988fa MD |
38 | struct get_symbol { |
39 | /* Symbol offset. */ | |
661dfdd1 | 40 | uint16_t offset; |
bff988fa MD |
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; | |
661dfdd1 MD |
49 | } LTTNG_PACKED; |
50 | ||
953192ba MD |
51 | struct literal_numeric { |
52 | int64_t v; | |
6f30f9b8 | 53 | } LTTNG_PACKED; |
953192ba | 54 | |
e90d8561 MD |
55 | struct literal_double { |
56 | double v; | |
6f30f9b8 | 57 | } LTTNG_PACKED; |
e90d8561 | 58 | |
953192ba MD |
59 | struct literal_string { |
60 | char string[0]; | |
6f30f9b8 | 61 | } LTTNG_PACKED; |
953192ba MD |
62 | |
63 | enum filter_op { | |
7e6831d1 | 64 | FILTER_OP_UNKNOWN = 0, |
953192ba | 65 | |
7e6831d1 | 66 | FILTER_OP_RETURN = 1, |
953192ba MD |
67 | |
68 | /* binary */ | |
7e6831d1 MD |
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, | |
116d3c01 MD |
74 | FILTER_OP_BIT_RSHIFT = 7, |
75 | FILTER_OP_BIT_LSHIFT = 8, | |
bff988fa MD |
76 | FILTER_OP_BIT_AND = 9, |
77 | FILTER_OP_BIT_OR = 10, | |
78 | FILTER_OP_BIT_XOR = 11, | |
78228322 MD |
79 | |
80 | /* binary comparators */ | |
7e6831d1 MD |
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, | |
953192ba | 87 | |
9f449915 | 88 | /* string binary comparator: apply to */ |
7e6831d1 MD |
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, | |
78228322 MD |
95 | |
96 | /* s64 binary comparator */ | |
7e6831d1 MD |
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, | |
78228322 MD |
103 | |
104 | /* double binary comparator */ | |
7e6831d1 MD |
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, | |
78228322 | 111 | |
78370c0c | 112 | /* Mixed S64-double binary comparators */ |
7e6831d1 MD |
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, | |
78370c0c | 126 | |
953192ba | 127 | /* unary */ |
7e6831d1 MD |
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, | |
953192ba MD |
137 | |
138 | /* logical */ | |
7e6831d1 MD |
139 | FILTER_OP_AND = 57, |
140 | FILTER_OP_OR = 58, | |
953192ba | 141 | |
586dc72f | 142 | /* load field ref */ |
7e6831d1 MD |
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, | |
65775683 | 148 | |
586dc72f | 149 | /* load immediate from operand */ |
7e6831d1 MD |
150 | FILTER_OP_LOAD_STRING = 64, |
151 | FILTER_OP_LOAD_S64 = 65, | |
152 | FILTER_OP_LOAD_DOUBLE = 66, | |
953192ba | 153 | |
8cf9540a | 154 | /* cast */ |
7e6831d1 MD |
155 | FILTER_OP_CAST_TO_S64 = 67, |
156 | FILTER_OP_CAST_DOUBLE_TO_S64 = 68, | |
157 | FILTER_OP_CAST_NOP = 69, | |
8cf9540a | 158 | |
586dc72f MD |
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 | ||
00a62084 MD |
165 | /* load userspace field ref */ |
166 | FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74, | |
167 | FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75, | |
168 | ||
9f449915 PP |
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 | ||
bff988fa MD |
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, | |
661dfdd1 | 203 | |
116d3c01 MD |
204 | FILTER_OP_UNARY_BIT_NOT = 98, |
205 | ||
ba8f6b16 MD |
206 | FILTER_OP_RETURN_S64 = 99, |
207 | ||
953192ba MD |
208 | NR_FILTER_OPS, |
209 | }; | |
210 | ||
211 | typedef uint8_t filter_opcode_t; | |
212 | ||
213 | struct load_op { | |
214 | filter_opcode_t op; | |
953192ba MD |
215 | char data[0]; |
216 | /* data to load. Size known by enum filter_opcode and null-term char. */ | |
6f30f9b8 | 217 | } LTTNG_PACKED; |
953192ba MD |
218 | |
219 | struct binary_op { | |
220 | filter_opcode_t op; | |
6f30f9b8 | 221 | } LTTNG_PACKED; |
953192ba MD |
222 | |
223 | struct unary_op { | |
224 | filter_opcode_t op; | |
6f30f9b8 | 225 | } LTTNG_PACKED; |
953192ba MD |
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 */ | |
6f30f9b8 | 231 | } LTTNG_PACKED; |
953192ba | 232 | |
8cf9540a MD |
233 | struct cast_op { |
234 | filter_opcode_t op; | |
6f30f9b8 | 235 | } LTTNG_PACKED; |
8cf9540a | 236 | |
953192ba MD |
237 | struct return_op { |
238 | filter_opcode_t op; | |
6f30f9b8 | 239 | } LTTNG_PACKED; |
953192ba | 240 | |
53a80697 | 241 | struct lttng_filter_bytecode_alloc { |
5ddb0a08 | 242 | uint32_t alloc_len; |
53a80697 | 243 | struct lttng_filter_bytecode b; |
953192ba MD |
244 | }; |
245 | ||
246 | static inline | |
53a80697 | 247 | unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode) |
953192ba MD |
248 | { |
249 | return bytecode->len; | |
250 | } | |
251 | ||
252 | #endif /* _FILTER_BYTECODE_H */ |