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