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