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 | |
661dfdd1 MD |
38 | struct field_ref_index { |
39 | /* Initially, symbol offset. After link, field offset. */ | |
40 | uint16_t offset; | |
41 | uint64_t index; /* array index */ | |
42 | } LTTNG_PACKED; | |
43 | ||
953192ba MD |
44 | struct literal_numeric { |
45 | int64_t v; | |
6f30f9b8 | 46 | } LTTNG_PACKED; |
953192ba | 47 | |
e90d8561 MD |
48 | struct literal_double { |
49 | double v; | |
6f30f9b8 | 50 | } LTTNG_PACKED; |
e90d8561 | 51 | |
953192ba MD |
52 | struct literal_string { |
53 | char string[0]; | |
6f30f9b8 | 54 | } LTTNG_PACKED; |
953192ba MD |
55 | |
56 | enum filter_op { | |
7e6831d1 | 57 | FILTER_OP_UNKNOWN = 0, |
953192ba | 58 | |
7e6831d1 | 59 | FILTER_OP_RETURN = 1, |
953192ba MD |
60 | |
61 | /* binary */ | |
7e6831d1 MD |
62 | FILTER_OP_MUL = 2, |
63 | FILTER_OP_DIV = 3, | |
64 | FILTER_OP_MOD = 4, | |
65 | FILTER_OP_PLUS = 5, | |
66 | FILTER_OP_MINUS = 6, | |
67 | FILTER_OP_RSHIFT = 7, | |
68 | FILTER_OP_LSHIFT = 8, | |
69 | FILTER_OP_BIN_AND = 9, | |
70 | FILTER_OP_BIN_OR = 10, | |
71 | FILTER_OP_BIN_XOR = 11, | |
78228322 MD |
72 | |
73 | /* binary comparators */ | |
7e6831d1 MD |
74 | FILTER_OP_EQ = 12, |
75 | FILTER_OP_NE = 13, | |
76 | FILTER_OP_GT = 14, | |
77 | FILTER_OP_LT = 15, | |
78 | FILTER_OP_GE = 16, | |
79 | FILTER_OP_LE = 17, | |
953192ba | 80 | |
9f449915 | 81 | /* string binary comparator: apply to */ |
7e6831d1 MD |
82 | FILTER_OP_EQ_STRING = 18, |
83 | FILTER_OP_NE_STRING = 19, | |
84 | FILTER_OP_GT_STRING = 20, | |
85 | FILTER_OP_LT_STRING = 21, | |
86 | FILTER_OP_GE_STRING = 22, | |
87 | FILTER_OP_LE_STRING = 23, | |
78228322 MD |
88 | |
89 | /* s64 binary comparator */ | |
7e6831d1 MD |
90 | FILTER_OP_EQ_S64 = 24, |
91 | FILTER_OP_NE_S64 = 25, | |
92 | FILTER_OP_GT_S64 = 26, | |
93 | FILTER_OP_LT_S64 = 27, | |
94 | FILTER_OP_GE_S64 = 28, | |
95 | FILTER_OP_LE_S64 = 29, | |
78228322 MD |
96 | |
97 | /* double binary comparator */ | |
7e6831d1 MD |
98 | FILTER_OP_EQ_DOUBLE = 30, |
99 | FILTER_OP_NE_DOUBLE = 31, | |
100 | FILTER_OP_GT_DOUBLE = 32, | |
101 | FILTER_OP_LT_DOUBLE = 33, | |
102 | FILTER_OP_GE_DOUBLE = 34, | |
103 | FILTER_OP_LE_DOUBLE = 35, | |
78228322 | 104 | |
78370c0c | 105 | /* Mixed S64-double binary comparators */ |
7e6831d1 MD |
106 | FILTER_OP_EQ_DOUBLE_S64 = 36, |
107 | FILTER_OP_NE_DOUBLE_S64 = 37, | |
108 | FILTER_OP_GT_DOUBLE_S64 = 38, | |
109 | FILTER_OP_LT_DOUBLE_S64 = 39, | |
110 | FILTER_OP_GE_DOUBLE_S64 = 40, | |
111 | FILTER_OP_LE_DOUBLE_S64 = 41, | |
112 | ||
113 | FILTER_OP_EQ_S64_DOUBLE = 42, | |
114 | FILTER_OP_NE_S64_DOUBLE = 43, | |
115 | FILTER_OP_GT_S64_DOUBLE = 44, | |
116 | FILTER_OP_LT_S64_DOUBLE = 45, | |
117 | FILTER_OP_GE_S64_DOUBLE = 46, | |
118 | FILTER_OP_LE_S64_DOUBLE = 47, | |
78370c0c | 119 | |
953192ba | 120 | /* unary */ |
7e6831d1 MD |
121 | FILTER_OP_UNARY_PLUS = 48, |
122 | FILTER_OP_UNARY_MINUS = 49, | |
123 | FILTER_OP_UNARY_NOT = 50, | |
124 | FILTER_OP_UNARY_PLUS_S64 = 51, | |
125 | FILTER_OP_UNARY_MINUS_S64 = 52, | |
126 | FILTER_OP_UNARY_NOT_S64 = 53, | |
127 | FILTER_OP_UNARY_PLUS_DOUBLE = 54, | |
128 | FILTER_OP_UNARY_MINUS_DOUBLE = 55, | |
129 | FILTER_OP_UNARY_NOT_DOUBLE = 56, | |
953192ba MD |
130 | |
131 | /* logical */ | |
7e6831d1 MD |
132 | FILTER_OP_AND = 57, |
133 | FILTER_OP_OR = 58, | |
953192ba | 134 | |
586dc72f | 135 | /* load field ref */ |
7e6831d1 MD |
136 | FILTER_OP_LOAD_FIELD_REF = 59, |
137 | FILTER_OP_LOAD_FIELD_REF_STRING = 60, | |
138 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE = 61, | |
139 | FILTER_OP_LOAD_FIELD_REF_S64 = 62, | |
140 | FILTER_OP_LOAD_FIELD_REF_DOUBLE = 63, | |
65775683 | 141 | |
586dc72f | 142 | /* load immediate from operand */ |
7e6831d1 MD |
143 | FILTER_OP_LOAD_STRING = 64, |
144 | FILTER_OP_LOAD_S64 = 65, | |
145 | FILTER_OP_LOAD_DOUBLE = 66, | |
953192ba | 146 | |
8cf9540a | 147 | /* cast */ |
7e6831d1 MD |
148 | FILTER_OP_CAST_TO_S64 = 67, |
149 | FILTER_OP_CAST_DOUBLE_TO_S64 = 68, | |
150 | FILTER_OP_CAST_NOP = 69, | |
8cf9540a | 151 | |
586dc72f MD |
152 | /* get context ref */ |
153 | FILTER_OP_GET_CONTEXT_REF = 70, | |
154 | FILTER_OP_GET_CONTEXT_REF_STRING = 71, | |
155 | FILTER_OP_GET_CONTEXT_REF_S64 = 72, | |
156 | FILTER_OP_GET_CONTEXT_REF_DOUBLE = 73, | |
157 | ||
00a62084 MD |
158 | /* load userspace field ref */ |
159 | FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74, | |
160 | FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75, | |
161 | ||
9f449915 PP |
162 | /* |
163 | * load immediate star globbing pattern (literal string) | |
164 | * from immediate | |
165 | */ | |
166 | FILTER_OP_LOAD_STAR_GLOB_STRING = 76, | |
167 | ||
168 | /* globbing pattern binary operator: apply to */ | |
169 | FILTER_OP_EQ_STAR_GLOB_STRING = 77, | |
170 | FILTER_OP_NE_STAR_GLOB_STRING = 78, | |
171 | ||
661dfdd1 MD |
172 | /* load field ref with index */ |
173 | FILTER_OP_LOAD_FIELD_REF_INDEX = 79, | |
174 | FILTER_OP_LOAD_FIELD_REF_INDEX_S64 = 80, | |
175 | ||
176 | /* get context ref with index */ | |
177 | FILTER_OP_GET_CONTEXT_REF_INDEX = 81, | |
178 | FILTER_OP_GET_CONTEXT_REF_INDEX_S64 = 82, | |
179 | ||
953192ba MD |
180 | NR_FILTER_OPS, |
181 | }; | |
182 | ||
183 | typedef uint8_t filter_opcode_t; | |
184 | ||
185 | struct load_op { | |
186 | filter_opcode_t op; | |
953192ba MD |
187 | char data[0]; |
188 | /* data to load. Size known by enum filter_opcode and null-term char. */ | |
6f30f9b8 | 189 | } LTTNG_PACKED; |
953192ba MD |
190 | |
191 | struct binary_op { | |
192 | filter_opcode_t op; | |
6f30f9b8 | 193 | } LTTNG_PACKED; |
953192ba MD |
194 | |
195 | struct unary_op { | |
196 | filter_opcode_t op; | |
6f30f9b8 | 197 | } LTTNG_PACKED; |
953192ba MD |
198 | |
199 | /* skip_offset is absolute from start of bytecode */ | |
200 | struct logical_op { | |
201 | filter_opcode_t op; | |
202 | uint16_t skip_offset; /* bytecode insn, if skip second test */ | |
6f30f9b8 | 203 | } LTTNG_PACKED; |
953192ba | 204 | |
8cf9540a MD |
205 | struct cast_op { |
206 | filter_opcode_t op; | |
6f30f9b8 | 207 | } LTTNG_PACKED; |
8cf9540a | 208 | |
953192ba MD |
209 | struct return_op { |
210 | filter_opcode_t op; | |
6f30f9b8 | 211 | } LTTNG_PACKED; |
953192ba | 212 | |
53a80697 | 213 | struct lttng_filter_bytecode_alloc { |
5ddb0a08 | 214 | uint32_t alloc_len; |
53a80697 | 215 | struct lttng_filter_bytecode b; |
953192ba MD |
216 | }; |
217 | ||
218 | static inline | |
53a80697 | 219 | unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode) |
953192ba MD |
220 | { |
221 | return bytecode->len; | |
222 | } | |
223 | ||
224 | #endif /* _FILTER_BYTECODE_H */ |