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; | |
953192ba MD |
36 | } __attribute__((packed)); |
37 | ||
38 | struct literal_numeric { | |
39 | int64_t v; | |
40 | } __attribute__((packed)); | |
41 | ||
e90d8561 MD |
42 | struct literal_double { |
43 | double v; | |
44 | } __attribute__((packed)); | |
45 | ||
953192ba MD |
46 | struct literal_string { |
47 | char string[0]; | |
48 | } __attribute__((packed)); | |
49 | ||
50 | enum filter_op { | |
51 | FILTER_OP_UNKNOWN = 0, | |
52 | ||
53 | FILTER_OP_RETURN, | |
54 | ||
55 | /* binary */ | |
56 | FILTER_OP_MUL, | |
57 | FILTER_OP_DIV, | |
58 | FILTER_OP_MOD, | |
59 | FILTER_OP_PLUS, | |
60 | FILTER_OP_MINUS, | |
61 | FILTER_OP_RSHIFT, | |
62 | FILTER_OP_LSHIFT, | |
63 | FILTER_OP_BIN_AND, | |
64 | FILTER_OP_BIN_OR, | |
65 | FILTER_OP_BIN_XOR, | |
78228322 MD |
66 | |
67 | /* binary comparators */ | |
953192ba MD |
68 | FILTER_OP_EQ, |
69 | FILTER_OP_NE, | |
70 | FILTER_OP_GT, | |
71 | FILTER_OP_LT, | |
72 | FILTER_OP_GE, | |
73 | FILTER_OP_LE, | |
74 | ||
78228322 MD |
75 | /* string binary comparator */ |
76 | FILTER_OP_EQ_STRING, | |
77 | FILTER_OP_NE_STRING, | |
78 | FILTER_OP_GT_STRING, | |
79 | FILTER_OP_LT_STRING, | |
80 | FILTER_OP_GE_STRING, | |
81 | FILTER_OP_LE_STRING, | |
82 | ||
83 | /* s64 binary comparator */ | |
84 | FILTER_OP_EQ_S64, | |
85 | FILTER_OP_NE_S64, | |
86 | FILTER_OP_GT_S64, | |
87 | FILTER_OP_LT_S64, | |
88 | FILTER_OP_GE_S64, | |
89 | FILTER_OP_LE_S64, | |
90 | ||
91 | /* double binary comparator */ | |
92 | FILTER_OP_EQ_DOUBLE, | |
93 | FILTER_OP_NE_DOUBLE, | |
94 | FILTER_OP_GT_DOUBLE, | |
95 | FILTER_OP_LT_DOUBLE, | |
96 | FILTER_OP_GE_DOUBLE, | |
97 | FILTER_OP_LE_DOUBLE, | |
98 | ||
78370c0c MD |
99 | /* Mixed S64-double binary comparators */ |
100 | FILTER_OP_EQ_DOUBLE_S64, | |
101 | FILTER_OP_NE_DOUBLE_S64, | |
102 | FILTER_OP_GT_DOUBLE_S64, | |
103 | FILTER_OP_LT_DOUBLE_S64, | |
104 | FILTER_OP_GE_DOUBLE_S64, | |
105 | FILTER_OP_LE_DOUBLE_S64, | |
106 | ||
107 | FILTER_OP_EQ_S64_DOUBLE, | |
108 | FILTER_OP_NE_S64_DOUBLE, | |
109 | FILTER_OP_GT_S64_DOUBLE, | |
110 | FILTER_OP_LT_S64_DOUBLE, | |
111 | FILTER_OP_GE_S64_DOUBLE, | |
112 | FILTER_OP_LE_S64_DOUBLE, | |
113 | ||
953192ba MD |
114 | /* unary */ |
115 | FILTER_OP_UNARY_PLUS, | |
116 | FILTER_OP_UNARY_MINUS, | |
117 | FILTER_OP_UNARY_NOT, | |
c473659a MD |
118 | FILTER_OP_UNARY_PLUS_S64, |
119 | FILTER_OP_UNARY_MINUS_S64, | |
120 | FILTER_OP_UNARY_NOT_S64, | |
121 | FILTER_OP_UNARY_PLUS_DOUBLE, | |
122 | FILTER_OP_UNARY_MINUS_DOUBLE, | |
123 | FILTER_OP_UNARY_NOT_DOUBLE, | |
953192ba MD |
124 | |
125 | /* logical */ | |
126 | FILTER_OP_AND, | |
127 | FILTER_OP_OR, | |
128 | ||
129 | /* load */ | |
130 | FILTER_OP_LOAD_FIELD_REF, | |
65775683 MD |
131 | FILTER_OP_LOAD_FIELD_REF_STRING, |
132 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE, | |
133 | FILTER_OP_LOAD_FIELD_REF_S64, | |
134 | FILTER_OP_LOAD_FIELD_REF_DOUBLE, | |
135 | ||
953192ba MD |
136 | FILTER_OP_LOAD_STRING, |
137 | FILTER_OP_LOAD_S64, | |
e90d8561 | 138 | FILTER_OP_LOAD_DOUBLE, |
953192ba | 139 | |
8cf9540a MD |
140 | /* cast */ |
141 | FILTER_OP_CAST_TO_S64, | |
142 | FILTER_OP_CAST_DOUBLE_TO_S64, | |
143 | FILTER_OP_CAST_NOP, | |
144 | ||
953192ba MD |
145 | NR_FILTER_OPS, |
146 | }; | |
147 | ||
148 | typedef uint8_t filter_opcode_t; | |
149 | ||
150 | struct load_op { | |
151 | filter_opcode_t op; | |
953192ba MD |
152 | char data[0]; |
153 | /* data to load. Size known by enum filter_opcode and null-term char. */ | |
154 | } __attribute__((packed)); | |
155 | ||
156 | struct binary_op { | |
157 | filter_opcode_t op; | |
158 | } __attribute__((packed)); | |
159 | ||
160 | struct unary_op { | |
161 | filter_opcode_t op; | |
953192ba MD |
162 | } __attribute__((packed)); |
163 | ||
164 | /* skip_offset is absolute from start of bytecode */ | |
165 | struct logical_op { | |
166 | filter_opcode_t op; | |
167 | uint16_t skip_offset; /* bytecode insn, if skip second test */ | |
168 | } __attribute__((packed)); | |
169 | ||
8cf9540a MD |
170 | struct cast_op { |
171 | filter_opcode_t op; | |
8cf9540a MD |
172 | } __attribute__((packed)); |
173 | ||
953192ba MD |
174 | struct return_op { |
175 | filter_opcode_t op; | |
176 | } __attribute__((packed)); | |
177 | ||
53a80697 | 178 | struct lttng_filter_bytecode_alloc { |
5ddb0a08 | 179 | uint32_t alloc_len; |
53a80697 | 180 | struct lttng_filter_bytecode b; |
953192ba MD |
181 | }; |
182 | ||
183 | static inline | |
53a80697 | 184 | unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode) |
953192ba MD |
185 | { |
186 | return bytecode->len; | |
187 | } | |
188 | ||
189 | #endif /* _FILTER_BYTECODE_H */ |