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, | |
aa449dc5 MD |
118 | FILTER_OP_AND_S64, |
119 | FILTER_OP_OR_S64, | |
120 | FILTER_OP_AND_DOUBLE, | |
121 | FILTER_OP_OR_DOUBLE, | |
953192ba MD |
122 | |
123 | /* load */ | |
124 | FILTER_OP_LOAD_FIELD_REF, | |
65775683 MD |
125 | FILTER_OP_LOAD_FIELD_REF_STRING, |
126 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE, | |
127 | FILTER_OP_LOAD_FIELD_REF_S64, | |
128 | FILTER_OP_LOAD_FIELD_REF_DOUBLE, | |
129 | ||
953192ba MD |
130 | FILTER_OP_LOAD_STRING, |
131 | FILTER_OP_LOAD_S64, | |
e90d8561 | 132 | FILTER_OP_LOAD_DOUBLE, |
953192ba MD |
133 | |
134 | NR_FILTER_OPS, | |
135 | }; | |
136 | ||
137 | typedef uint8_t filter_opcode_t; | |
138 | ||
139 | struct load_op { | |
140 | filter_opcode_t op; | |
141 | uint8_t reg; /* enum filter_register */ | |
142 | char data[0]; | |
143 | /* data to load. Size known by enum filter_opcode and null-term char. */ | |
144 | } __attribute__((packed)); | |
145 | ||
146 | struct binary_op { | |
147 | filter_opcode_t op; | |
148 | } __attribute__((packed)); | |
149 | ||
150 | struct unary_op { | |
151 | filter_opcode_t op; | |
152 | uint8_t reg; /* enum filter_register */ | |
153 | } __attribute__((packed)); | |
154 | ||
155 | /* skip_offset is absolute from start of bytecode */ | |
156 | struct logical_op { | |
157 | filter_opcode_t op; | |
158 | uint16_t skip_offset; /* bytecode insn, if skip second test */ | |
159 | } __attribute__((packed)); | |
160 | ||
161 | struct return_op { | |
162 | filter_opcode_t op; | |
163 | } __attribute__((packed)); | |
164 | ||
53a80697 | 165 | struct lttng_filter_bytecode_alloc { |
953192ba | 166 | uint16_t alloc_len; |
53a80697 | 167 | struct lttng_filter_bytecode b; |
953192ba MD |
168 | }; |
169 | ||
170 | static inline | |
53a80697 | 171 | unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode) |
953192ba MD |
172 | { |
173 | return bytecode->len; | |
174 | } | |
175 | ||
176 | #endif /* _FILTER_BYTECODE_H */ |