9a2d4c0a0c04e454be39c96212620f60565237d3
[lttng-ust.git] / liblttng-ust / 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-2016 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
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
27 * SOFTWARE.
28 */
29
30 #include <lttng/ust-abi.h>
31
32 /*
33 * offsets are absolute from start of bytecode.
34 */
35
36 struct field_ref {
37 /* Initially, symbol offset. After link, field offset. */
38 uint16_t offset;
39 } __attribute__((packed));
40
41 struct get_symbol {
42 /* Symbol offset. */
43 uint16_t offset;
44 } LTTNG_PACKED;
45
46 struct get_index_u16 {
47 uint16_t index;
48 } LTTNG_PACKED;
49
50 struct get_index_u64 {
51 uint64_t index;
52 } LTTNG_PACKED;
53
54 struct literal_numeric {
55 int64_t v;
56 } __attribute__((packed));
57
58 struct literal_double {
59 double v;
60 } __attribute__((packed));
61
62 struct literal_string {
63 char string[0];
64 } __attribute__((packed));
65
66 enum filter_op {
67 FILTER_OP_UNKNOWN = 0,
68
69 FILTER_OP_RETURN = 1,
70
71 /* binary */
72 FILTER_OP_MUL = 2,
73 FILTER_OP_DIV = 3,
74 FILTER_OP_MOD = 4,
75 FILTER_OP_PLUS = 5,
76 FILTER_OP_MINUS = 6,
77 FILTER_OP_BIT_RSHIFT = 7,
78 FILTER_OP_BIT_LSHIFT = 8,
79 FILTER_OP_BIT_AND = 9,
80 FILTER_OP_BIT_OR = 10,
81 FILTER_OP_BIT_XOR = 11,
82
83 /* binary comparators */
84 FILTER_OP_EQ = 12,
85 FILTER_OP_NE = 13,
86 FILTER_OP_GT = 14,
87 FILTER_OP_LT = 15,
88 FILTER_OP_GE = 16,
89 FILTER_OP_LE = 17,
90
91 /* string binary comparator: apply to */
92 FILTER_OP_EQ_STRING = 18,
93 FILTER_OP_NE_STRING = 19,
94 FILTER_OP_GT_STRING = 20,
95 FILTER_OP_LT_STRING = 21,
96 FILTER_OP_GE_STRING = 22,
97 FILTER_OP_LE_STRING = 23,
98
99 /* s64 binary comparator */
100 FILTER_OP_EQ_S64 = 24,
101 FILTER_OP_NE_S64 = 25,
102 FILTER_OP_GT_S64 = 26,
103 FILTER_OP_LT_S64 = 27,
104 FILTER_OP_GE_S64 = 28,
105 FILTER_OP_LE_S64 = 29,
106
107 /* double binary comparator */
108 FILTER_OP_EQ_DOUBLE = 30,
109 FILTER_OP_NE_DOUBLE = 31,
110 FILTER_OP_GT_DOUBLE = 32,
111 FILTER_OP_LT_DOUBLE = 33,
112 FILTER_OP_GE_DOUBLE = 34,
113 FILTER_OP_LE_DOUBLE = 35,
114
115 /* Mixed S64-double binary comparators */
116 FILTER_OP_EQ_DOUBLE_S64 = 36,
117 FILTER_OP_NE_DOUBLE_S64 = 37,
118 FILTER_OP_GT_DOUBLE_S64 = 38,
119 FILTER_OP_LT_DOUBLE_S64 = 39,
120 FILTER_OP_GE_DOUBLE_S64 = 40,
121 FILTER_OP_LE_DOUBLE_S64 = 41,
122
123 FILTER_OP_EQ_S64_DOUBLE = 42,
124 FILTER_OP_NE_S64_DOUBLE = 43,
125 FILTER_OP_GT_S64_DOUBLE = 44,
126 FILTER_OP_LT_S64_DOUBLE = 45,
127 FILTER_OP_GE_S64_DOUBLE = 46,
128 FILTER_OP_LE_S64_DOUBLE = 47,
129
130 /* unary */
131 FILTER_OP_UNARY_PLUS = 48,
132 FILTER_OP_UNARY_MINUS = 49,
133 FILTER_OP_UNARY_NOT = 50,
134 FILTER_OP_UNARY_PLUS_S64 = 51,
135 FILTER_OP_UNARY_MINUS_S64 = 52,
136 FILTER_OP_UNARY_NOT_S64 = 53,
137 FILTER_OP_UNARY_PLUS_DOUBLE = 54,
138 FILTER_OP_UNARY_MINUS_DOUBLE = 55,
139 FILTER_OP_UNARY_NOT_DOUBLE = 56,
140
141 /* logical */
142 FILTER_OP_AND = 57,
143 FILTER_OP_OR = 58,
144
145 /* load field ref */
146 FILTER_OP_LOAD_FIELD_REF = 59,
147 FILTER_OP_LOAD_FIELD_REF_STRING = 60,
148 FILTER_OP_LOAD_FIELD_REF_SEQUENCE = 61,
149 FILTER_OP_LOAD_FIELD_REF_S64 = 62,
150 FILTER_OP_LOAD_FIELD_REF_DOUBLE = 63,
151
152 /* load immediate from operand */
153 FILTER_OP_LOAD_STRING = 64,
154 FILTER_OP_LOAD_S64 = 65,
155 FILTER_OP_LOAD_DOUBLE = 66,
156
157 /* cast */
158 FILTER_OP_CAST_TO_S64 = 67,
159 FILTER_OP_CAST_DOUBLE_TO_S64 = 68,
160 FILTER_OP_CAST_NOP = 69,
161
162 /* get context ref */
163 FILTER_OP_GET_CONTEXT_REF = 70,
164 FILTER_OP_GET_CONTEXT_REF_STRING = 71,
165 FILTER_OP_GET_CONTEXT_REF_S64 = 72,
166 FILTER_OP_GET_CONTEXT_REF_DOUBLE = 73,
167
168 /* load userspace field ref */
169 FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74,
170 FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75,
171
172 /*
173 * load immediate star globbing pattern (literal string)
174 * from immediate
175 */
176 FILTER_OP_LOAD_STAR_GLOB_STRING = 76,
177
178 /* globbing pattern binary operator: apply to */
179 FILTER_OP_EQ_STAR_GLOB_STRING = 77,
180 FILTER_OP_NE_STAR_GLOB_STRING = 78,
181
182 /*
183 * Instructions for recursive traversal through composed types.
184 */
185 FILTER_OP_GET_CONTEXT_ROOT = 79,
186 FILTER_OP_GET_APP_CONTEXT_ROOT = 80,
187 FILTER_OP_GET_PAYLOAD_ROOT = 81,
188
189 FILTER_OP_GET_SYMBOL = 82,
190 FILTER_OP_GET_SYMBOL_FIELD = 83,
191 FILTER_OP_GET_INDEX_U16 = 84,
192 FILTER_OP_GET_INDEX_U64 = 85,
193
194 FILTER_OP_LOAD_FIELD = 86,
195 FILTER_OP_LOAD_FIELD_S8 = 87,
196 FILTER_OP_LOAD_FIELD_S16 = 88,
197 FILTER_OP_LOAD_FIELD_S32 = 89,
198 FILTER_OP_LOAD_FIELD_S64 = 90,
199 FILTER_OP_LOAD_FIELD_U8 = 91,
200 FILTER_OP_LOAD_FIELD_U16 = 92,
201 FILTER_OP_LOAD_FIELD_U32 = 93,
202 FILTER_OP_LOAD_FIELD_U64 = 94,
203 FILTER_OP_LOAD_FIELD_STRING = 95,
204 FILTER_OP_LOAD_FIELD_SEQUENCE = 96,
205 FILTER_OP_LOAD_FIELD_DOUBLE = 97,
206
207 FILTER_OP_UNARY_BIT_NOT = 98,
208
209 FILTER_OP_RETURN_S64 = 99,
210
211 NR_FILTER_OPS,
212 };
213
214 typedef uint8_t filter_opcode_t;
215
216 struct load_op {
217 filter_opcode_t op;
218 char data[0];
219 /* data to load. Size known by enum filter_opcode and null-term char. */
220 } __attribute__((packed));
221
222 struct binary_op {
223 filter_opcode_t op;
224 } __attribute__((packed));
225
226 struct unary_op {
227 filter_opcode_t op;
228 } __attribute__((packed));
229
230 /* skip_offset is absolute from start of bytecode */
231 struct logical_op {
232 filter_opcode_t op;
233 uint16_t skip_offset; /* bytecode insn, if skip second test */
234 } __attribute__((packed));
235
236 struct cast_op {
237 filter_opcode_t op;
238 } __attribute__((packed));
239
240 struct return_op {
241 filter_opcode_t op;
242 } __attribute__((packed));
243
244 #endif /* _FILTER_BYTECODE_H */
This page took 0.033507 seconds and 3 git commands to generate.