Filter code relicensing to MIT license
[lttng-modules.git] / 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-2016 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
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:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
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.
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 {
52 FILTER_OP_UNKNOWN = 0,
53
54 FILTER_OP_RETURN,
55
56 /* binary */
57 FILTER_OP_MUL,
58 FILTER_OP_DIV,
59 FILTER_OP_MOD,
60 FILTER_OP_PLUS,
61 FILTER_OP_MINUS,
62 FILTER_OP_RSHIFT,
63 FILTER_OP_LSHIFT,
64 FILTER_OP_BIN_AND,
65 FILTER_OP_BIN_OR,
66 FILTER_OP_BIN_XOR,
67
68 /* binary comparators */
69 FILTER_OP_EQ,
70 FILTER_OP_NE,
71 FILTER_OP_GT,
72 FILTER_OP_LT,
73 FILTER_OP_GE,
74 FILTER_OP_LE,
75
76 /* string binary comparator */
77 FILTER_OP_EQ_STRING,
78 FILTER_OP_NE_STRING,
79 FILTER_OP_GT_STRING,
80 FILTER_OP_LT_STRING,
81 FILTER_OP_GE_STRING,
82 FILTER_OP_LE_STRING,
83
84 /* s64 binary comparator */
85 FILTER_OP_EQ_S64,
86 FILTER_OP_NE_S64,
87 FILTER_OP_GT_S64,
88 FILTER_OP_LT_S64,
89 FILTER_OP_GE_S64,
90 FILTER_OP_LE_S64,
91
92 /* double binary comparator */
93 FILTER_OP_EQ_DOUBLE,
94 FILTER_OP_NE_DOUBLE,
95 FILTER_OP_GT_DOUBLE,
96 FILTER_OP_LT_DOUBLE,
97 FILTER_OP_GE_DOUBLE,
98 FILTER_OP_LE_DOUBLE,
99
100 /* Mixed S64-double binary comparators */
101 FILTER_OP_EQ_DOUBLE_S64,
102 FILTER_OP_NE_DOUBLE_S64,
103 FILTER_OP_GT_DOUBLE_S64,
104 FILTER_OP_LT_DOUBLE_S64,
105 FILTER_OP_GE_DOUBLE_S64,
106 FILTER_OP_LE_DOUBLE_S64,
107
108 FILTER_OP_EQ_S64_DOUBLE,
109 FILTER_OP_NE_S64_DOUBLE,
110 FILTER_OP_GT_S64_DOUBLE,
111 FILTER_OP_LT_S64_DOUBLE,
112 FILTER_OP_GE_S64_DOUBLE,
113 FILTER_OP_LE_S64_DOUBLE,
114
115 /* unary */
116 FILTER_OP_UNARY_PLUS,
117 FILTER_OP_UNARY_MINUS,
118 FILTER_OP_UNARY_NOT,
119 FILTER_OP_UNARY_PLUS_S64,
120 FILTER_OP_UNARY_MINUS_S64,
121 FILTER_OP_UNARY_NOT_S64,
122 FILTER_OP_UNARY_PLUS_DOUBLE,
123 FILTER_OP_UNARY_MINUS_DOUBLE,
124 FILTER_OP_UNARY_NOT_DOUBLE,
125
126 /* logical */
127 FILTER_OP_AND,
128 FILTER_OP_OR,
129
130 /* load field ref */
131 FILTER_OP_LOAD_FIELD_REF,
132 FILTER_OP_LOAD_FIELD_REF_STRING,
133 FILTER_OP_LOAD_FIELD_REF_SEQUENCE,
134 FILTER_OP_LOAD_FIELD_REF_S64,
135 FILTER_OP_LOAD_FIELD_REF_DOUBLE,
136
137 /* load immediate from operand */
138 FILTER_OP_LOAD_STRING,
139 FILTER_OP_LOAD_S64,
140 FILTER_OP_LOAD_DOUBLE,
141
142 /* cast */
143 FILTER_OP_CAST_TO_S64,
144 FILTER_OP_CAST_DOUBLE_TO_S64,
145 FILTER_OP_CAST_NOP,
146
147 /* get context ref */
148 FILTER_OP_GET_CONTEXT_REF,
149 FILTER_OP_GET_CONTEXT_REF_STRING,
150 FILTER_OP_GET_CONTEXT_REF_S64,
151 FILTER_OP_GET_CONTEXT_REF_DOUBLE,
152
153 /* load userspace field ref */
154 FILTER_OP_LOAD_FIELD_REF_USER_STRING,
155 FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE,
156
157 NR_FILTER_OPS,
158 };
159
160 typedef uint8_t filter_opcode_t;
161
162 struct load_op {
163 filter_opcode_t op;
164 char data[0];
165 /* data to load. Size known by enum filter_opcode and null-term char. */
166 } __attribute__((packed));
167
168 struct binary_op {
169 filter_opcode_t op;
170 } __attribute__((packed));
171
172 struct unary_op {
173 filter_opcode_t op;
174 } __attribute__((packed));
175
176 /* skip_offset is absolute from start of bytecode */
177 struct logical_op {
178 filter_opcode_t op;
179 uint16_t skip_offset; /* bytecode insn, if skip second test */
180 } __attribute__((packed));
181
182 struct cast_op {
183 filter_opcode_t op;
184 } __attribute__((packed));
185
186 struct return_op {
187 filter_opcode_t op;
188 } __attribute__((packed));
189
190 #endif /* _FILTER_BYTECODE_H */
This page took 0.033499 seconds and 5 git commands to generate.