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