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