Commit | Line | Data |
---|---|---|
07dfc1d0 MD |
1 | #ifndef _FILTER_BYTECODE_H |
2 | #define _FILTER_BYTECODE_H | |
3 | ||
4 | /* | |
5 | * filter-bytecode.h | |
6 | * | |
7 | * LTTng filter bytecode | |
8 | * | |
bbf3aef5 | 9 | * Copyright 2012-2016 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
07dfc1d0 | 10 | * |
bbf3aef5 MD |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
07dfc1d0 | 17 | * |
bbf3aef5 MD |
18 | * The above copyright notice and this permission notice shall be included in |
19 | * all copies or substantial portions of the Software. | |
07dfc1d0 | 20 | * |
bbf3aef5 MD |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
07dfc1d0 MD |
28 | */ |
29 | ||
30 | /* | |
31 | * offsets are absolute from start of bytecode. | |
32 | */ | |
33 | ||
34 | struct field_ref { | |
35 | /* Initially, symbol offset. After link, field offset. */ | |
36 | uint16_t offset; | |
37 | } __attribute__((packed)); | |
38 | ||
39 | struct literal_numeric { | |
40 | int64_t v; | |
41 | } __attribute__((packed)); | |
42 | ||
43 | struct literal_double { | |
44 | double v; | |
45 | } __attribute__((packed)); | |
46 | ||
47 | struct literal_string { | |
48 | char string[0]; | |
49 | } __attribute__((packed)); | |
50 | ||
51 | enum filter_op { | |
02aca193 | 52 | FILTER_OP_UNKNOWN = 0, |
07dfc1d0 | 53 | |
02aca193 | 54 | FILTER_OP_RETURN = 1, |
07dfc1d0 MD |
55 | |
56 | /* binary */ | |
02aca193 PP |
57 | FILTER_OP_MUL = 2, |
58 | FILTER_OP_DIV = 3, | |
59 | FILTER_OP_MOD = 4, | |
60 | FILTER_OP_PLUS = 5, | |
61 | FILTER_OP_MINUS = 6, | |
62 | FILTER_OP_RSHIFT = 7, | |
63 | FILTER_OP_LSHIFT = 8, | |
64 | FILTER_OP_BIN_AND = 9, | |
65 | FILTER_OP_BIN_OR = 10, | |
66 | FILTER_OP_BIN_XOR = 11, | |
07dfc1d0 MD |
67 | |
68 | /* binary comparators */ | |
02aca193 PP |
69 | FILTER_OP_EQ = 12, |
70 | FILTER_OP_NE = 13, | |
71 | FILTER_OP_GT = 14, | |
72 | FILTER_OP_LT = 15, | |
73 | FILTER_OP_GE = 16, | |
74 | FILTER_OP_LE = 17, | |
75 | ||
76 | /* string binary comparator: apply to */ | |
77 | FILTER_OP_EQ_STRING = 18, | |
78 | FILTER_OP_NE_STRING = 19, | |
79 | FILTER_OP_GT_STRING = 20, | |
80 | FILTER_OP_LT_STRING = 21, | |
81 | FILTER_OP_GE_STRING = 22, | |
82 | FILTER_OP_LE_STRING = 23, | |
07dfc1d0 MD |
83 | |
84 | /* s64 binary comparator */ | |
02aca193 PP |
85 | FILTER_OP_EQ_S64 = 24, |
86 | FILTER_OP_NE_S64 = 25, | |
87 | FILTER_OP_GT_S64 = 26, | |
88 | FILTER_OP_LT_S64 = 27, | |
89 | FILTER_OP_GE_S64 = 28, | |
90 | FILTER_OP_LE_S64 = 29, | |
07dfc1d0 MD |
91 | |
92 | /* double binary comparator */ | |
02aca193 PP |
93 | FILTER_OP_EQ_DOUBLE = 30, |
94 | FILTER_OP_NE_DOUBLE = 31, | |
95 | FILTER_OP_GT_DOUBLE = 32, | |
96 | FILTER_OP_LT_DOUBLE = 33, | |
97 | FILTER_OP_GE_DOUBLE = 34, | |
98 | FILTER_OP_LE_DOUBLE = 35, | |
07dfc1d0 MD |
99 | |
100 | /* Mixed S64-double binary comparators */ | |
02aca193 PP |
101 | FILTER_OP_EQ_DOUBLE_S64 = 36, |
102 | FILTER_OP_NE_DOUBLE_S64 = 37, | |
103 | FILTER_OP_GT_DOUBLE_S64 = 38, | |
104 | FILTER_OP_LT_DOUBLE_S64 = 39, | |
105 | FILTER_OP_GE_DOUBLE_S64 = 40, | |
106 | FILTER_OP_LE_DOUBLE_S64 = 41, | |
107 | ||
108 | FILTER_OP_EQ_S64_DOUBLE = 42, | |
109 | FILTER_OP_NE_S64_DOUBLE = 43, | |
110 | FILTER_OP_GT_S64_DOUBLE = 44, | |
111 | FILTER_OP_LT_S64_DOUBLE = 45, | |
112 | FILTER_OP_GE_S64_DOUBLE = 46, | |
113 | FILTER_OP_LE_S64_DOUBLE = 47, | |
07dfc1d0 MD |
114 | |
115 | /* unary */ | |
02aca193 PP |
116 | FILTER_OP_UNARY_PLUS = 48, |
117 | FILTER_OP_UNARY_MINUS = 49, | |
118 | FILTER_OP_UNARY_NOT = 50, | |
119 | FILTER_OP_UNARY_PLUS_S64 = 51, | |
120 | FILTER_OP_UNARY_MINUS_S64 = 52, | |
121 | FILTER_OP_UNARY_NOT_S64 = 53, | |
122 | FILTER_OP_UNARY_PLUS_DOUBLE = 54, | |
123 | FILTER_OP_UNARY_MINUS_DOUBLE = 55, | |
124 | FILTER_OP_UNARY_NOT_DOUBLE = 56, | |
07dfc1d0 MD |
125 | |
126 | /* logical */ | |
02aca193 PP |
127 | FILTER_OP_AND = 57, |
128 | FILTER_OP_OR = 58, | |
07dfc1d0 MD |
129 | |
130 | /* load field ref */ | |
02aca193 PP |
131 | FILTER_OP_LOAD_FIELD_REF = 59, |
132 | FILTER_OP_LOAD_FIELD_REF_STRING = 60, | |
133 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE = 61, | |
134 | FILTER_OP_LOAD_FIELD_REF_S64 = 62, | |
135 | FILTER_OP_LOAD_FIELD_REF_DOUBLE = 63, | |
07dfc1d0 MD |
136 | |
137 | /* load immediate from operand */ | |
02aca193 PP |
138 | FILTER_OP_LOAD_STRING = 64, |
139 | FILTER_OP_LOAD_S64 = 65, | |
140 | FILTER_OP_LOAD_DOUBLE = 66, | |
07dfc1d0 MD |
141 | |
142 | /* cast */ | |
02aca193 PP |
143 | FILTER_OP_CAST_TO_S64 = 67, |
144 | FILTER_OP_CAST_DOUBLE_TO_S64 = 68, | |
145 | FILTER_OP_CAST_NOP = 69, | |
07dfc1d0 MD |
146 | |
147 | /* get context ref */ | |
02aca193 PP |
148 | FILTER_OP_GET_CONTEXT_REF = 70, |
149 | FILTER_OP_GET_CONTEXT_REF_STRING = 71, | |
150 | FILTER_OP_GET_CONTEXT_REF_S64 = 72, | |
151 | FILTER_OP_GET_CONTEXT_REF_DOUBLE = 73, | |
07dfc1d0 | 152 | |
f127e61e | 153 | /* load userspace field ref */ |
02aca193 PP |
154 | FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74, |
155 | FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75, | |
156 | ||
157 | /* | |
158 | * load immediate star globbing pattern (literal string) | |
159 | * from immediate | |
160 | */ | |
161 | FILTER_OP_LOAD_STAR_GLOB_STRING = 76, | |
162 | ||
163 | /* globbing pattern binary operator: apply to */ | |
164 | FILTER_OP_EQ_STAR_GLOB_STRING = 77, | |
165 | FILTER_OP_NE_STAR_GLOB_STRING = 78, | |
f127e61e | 166 | |
07dfc1d0 MD |
167 | NR_FILTER_OPS, |
168 | }; | |
169 | ||
170 | typedef uint8_t filter_opcode_t; | |
171 | ||
172 | struct load_op { | |
173 | filter_opcode_t op; | |
174 | char data[0]; | |
175 | /* data to load. Size known by enum filter_opcode and null-term char. */ | |
176 | } __attribute__((packed)); | |
177 | ||
178 | struct binary_op { | |
179 | filter_opcode_t op; | |
180 | } __attribute__((packed)); | |
181 | ||
182 | struct unary_op { | |
183 | filter_opcode_t op; | |
184 | } __attribute__((packed)); | |
185 | ||
186 | /* skip_offset is absolute from start of bytecode */ | |
187 | struct logical_op { | |
188 | filter_opcode_t op; | |
189 | uint16_t skip_offset; /* bytecode insn, if skip second test */ | |
190 | } __attribute__((packed)); | |
191 | ||
192 | struct cast_op { | |
193 | filter_opcode_t op; | |
194 | } __attribute__((packed)); | |
195 | ||
196 | struct return_op { | |
197 | filter_opcode_t op; | |
198 | } __attribute__((packed)); | |
199 | ||
200 | #endif /* _FILTER_BYTECODE_H */ |