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