Fix: consumerd: unbalanced subbuffer 'get' when checking operation availability
[lttng-tools.git] / src / common / bytecode / bytecode.h
1 /*
2 * Copyright 2020 EfficiOS, Inc.
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8 #ifndef LTTNG_COMMON_BYTECODE_H
9 #define LTTNG_COMMON_BYTECODE_H
10
11 #include <stdint.h>
12
13 #include "common/macros.h"
14 #include "common/sessiond-comm/sessiond-comm.h"
15
16 /*
17 * offsets are absolute from start of bytecode.
18 */
19
20 struct field_ref {
21 /* Initially, symbol offset. After link, field offset. */
22 uint16_t offset;
23 } LTTNG_PACKED;
24
25 struct get_symbol {
26 /* Symbol offset. */
27 uint16_t offset;
28 } LTTNG_PACKED;
29
30 struct get_index_u16 {
31 uint16_t index;
32 } LTTNG_PACKED;
33
34 struct get_index_u64 {
35 uint64_t index;
36 } LTTNG_PACKED;
37
38 struct literal_numeric {
39 int64_t v;
40 } LTTNG_PACKED;
41
42 struct literal_double {
43 double v;
44 } LTTNG_PACKED;
45
46 struct literal_string {
47 char string[0];
48 } LTTNG_PACKED;
49
50 enum bytecode_op {
51 BYTECODE_OP_UNKNOWN = 0,
52
53 BYTECODE_OP_RETURN = 1,
54
55 /* binary */
56 BYTECODE_OP_MUL = 2,
57 BYTECODE_OP_DIV = 3,
58 BYTECODE_OP_MOD = 4,
59 BYTECODE_OP_PLUS = 5,
60 BYTECODE_OP_MINUS = 6,
61 BYTECODE_OP_BIT_RSHIFT = 7,
62 BYTECODE_OP_BIT_LSHIFT = 8,
63 BYTECODE_OP_BIT_AND = 9,
64 BYTECODE_OP_BIT_OR = 10,
65 BYTECODE_OP_BIT_XOR = 11,
66
67 /* binary comparators */
68 BYTECODE_OP_EQ = 12,
69 BYTECODE_OP_NE = 13,
70 BYTECODE_OP_GT = 14,
71 BYTECODE_OP_LT = 15,
72 BYTECODE_OP_GE = 16,
73 BYTECODE_OP_LE = 17,
74
75 /* string binary comparator: apply to */
76 BYTECODE_OP_EQ_STRING = 18,
77 BYTECODE_OP_NE_STRING = 19,
78 BYTECODE_OP_GT_STRING = 20,
79 BYTECODE_OP_LT_STRING = 21,
80 BYTECODE_OP_GE_STRING = 22,
81 BYTECODE_OP_LE_STRING = 23,
82
83 /* s64 binary comparator */
84 BYTECODE_OP_EQ_S64 = 24,
85 BYTECODE_OP_NE_S64 = 25,
86 BYTECODE_OP_GT_S64 = 26,
87 BYTECODE_OP_LT_S64 = 27,
88 BYTECODE_OP_GE_S64 = 28,
89 BYTECODE_OP_LE_S64 = 29,
90
91 /* double binary comparator */
92 BYTECODE_OP_EQ_DOUBLE = 30,
93 BYTECODE_OP_NE_DOUBLE = 31,
94 BYTECODE_OP_GT_DOUBLE = 32,
95 BYTECODE_OP_LT_DOUBLE = 33,
96 BYTECODE_OP_GE_DOUBLE = 34,
97 BYTECODE_OP_LE_DOUBLE = 35,
98
99 /* Mixed S64-double binary comparators */
100 BYTECODE_OP_EQ_DOUBLE_S64 = 36,
101 BYTECODE_OP_NE_DOUBLE_S64 = 37,
102 BYTECODE_OP_GT_DOUBLE_S64 = 38,
103 BYTECODE_OP_LT_DOUBLE_S64 = 39,
104 BYTECODE_OP_GE_DOUBLE_S64 = 40,
105 BYTECODE_OP_LE_DOUBLE_S64 = 41,
106
107 BYTECODE_OP_EQ_S64_DOUBLE = 42,
108 BYTECODE_OP_NE_S64_DOUBLE = 43,
109 BYTECODE_OP_GT_S64_DOUBLE = 44,
110 BYTECODE_OP_LT_S64_DOUBLE = 45,
111 BYTECODE_OP_GE_S64_DOUBLE = 46,
112 BYTECODE_OP_LE_S64_DOUBLE = 47,
113
114 /* unary */
115 BYTECODE_OP_UNARY_PLUS = 48,
116 BYTECODE_OP_UNARY_MINUS = 49,
117 BYTECODE_OP_UNARY_NOT = 50,
118 BYTECODE_OP_UNARY_PLUS_S64 = 51,
119 BYTECODE_OP_UNARY_MINUS_S64 = 52,
120 BYTECODE_OP_UNARY_NOT_S64 = 53,
121 BYTECODE_OP_UNARY_PLUS_DOUBLE = 54,
122 BYTECODE_OP_UNARY_MINUS_DOUBLE = 55,
123 BYTECODE_OP_UNARY_NOT_DOUBLE = 56,
124
125 /* logical */
126 BYTECODE_OP_AND = 57,
127 BYTECODE_OP_OR = 58,
128
129 /* load field ref */
130 BYTECODE_OP_LOAD_FIELD_REF = 59,
131 BYTECODE_OP_LOAD_FIELD_REF_STRING = 60,
132 BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE = 61,
133 BYTECODE_OP_LOAD_FIELD_REF_S64 = 62,
134 BYTECODE_OP_LOAD_FIELD_REF_DOUBLE = 63,
135
136 /* load immediate from operand */
137 BYTECODE_OP_LOAD_STRING = 64,
138 BYTECODE_OP_LOAD_S64 = 65,
139 BYTECODE_OP_LOAD_DOUBLE = 66,
140
141 /* cast */
142 BYTECODE_OP_CAST_TO_S64 = 67,
143 BYTECODE_OP_CAST_DOUBLE_TO_S64 = 68,
144 BYTECODE_OP_CAST_NOP = 69,
145
146 /* get context ref */
147 BYTECODE_OP_GET_CONTEXT_REF = 70,
148 BYTECODE_OP_GET_CONTEXT_REF_STRING = 71,
149 BYTECODE_OP_GET_CONTEXT_REF_S64 = 72,
150 BYTECODE_OP_GET_CONTEXT_REF_DOUBLE = 73,
151
152 /* load userspace field ref */
153 BYTECODE_OP_LOAD_FIELD_REF_USER_STRING = 74,
154 BYTECODE_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75,
155
156 /*
157 * load immediate star globbing pattern (literal string)
158 * from immediate
159 */
160 BYTECODE_OP_LOAD_STAR_GLOB_STRING = 76,
161
162 /* globbing pattern binary operator: apply to */
163 BYTECODE_OP_EQ_STAR_GLOB_STRING = 77,
164 BYTECODE_OP_NE_STAR_GLOB_STRING = 78,
165
166 /*
167 * Instructions for recursive traversal through composed types.
168 */
169 BYTECODE_OP_GET_CONTEXT_ROOT = 79,
170 BYTECODE_OP_GET_APP_CONTEXT_ROOT = 80,
171 BYTECODE_OP_GET_PAYLOAD_ROOT = 81,
172
173 BYTECODE_OP_GET_SYMBOL = 82,
174 BYTECODE_OP_GET_SYMBOL_FIELD = 83,
175 BYTECODE_OP_GET_INDEX_U16 = 84,
176 BYTECODE_OP_GET_INDEX_U64 = 85,
177
178 BYTECODE_OP_LOAD_FIELD = 86,
179 BYTECODE_OP_LOAD_FIELD_S8 = 87,
180 BYTECODE_OP_LOAD_FIELD_S16 = 88,
181 BYTECODE_OP_LOAD_FIELD_S32 = 89,
182 BYTECODE_OP_LOAD_FIELD_S64 = 90,
183 BYTECODE_OP_LOAD_FIELD_U8 = 91,
184 BYTECODE_OP_LOAD_FIELD_U16 = 92,
185 BYTECODE_OP_LOAD_FIELD_U32 = 93,
186 BYTECODE_OP_LOAD_FIELD_U64 = 94,
187 BYTECODE_OP_LOAD_FIELD_STRING = 95,
188 BYTECODE_OP_LOAD_FIELD_SEQUENCE = 96,
189 BYTECODE_OP_LOAD_FIELD_DOUBLE = 97,
190
191 BYTECODE_OP_UNARY_BIT_NOT = 98,
192
193 BYTECODE_OP_RETURN_S64 = 99,
194
195 NR_BYTECODE_OPS,
196 };
197
198 typedef uint8_t bytecode_opcode_t;
199
200 struct load_op {
201 bytecode_opcode_t op;
202
203 /*
204 * data to load. Size known by enum bytecode_opcode_t and null-term
205 * char.
206 */
207 char data[0];
208 } LTTNG_PACKED;
209
210 struct binary_op {
211 bytecode_opcode_t op;
212 } LTTNG_PACKED;
213
214 struct unary_op {
215 bytecode_opcode_t op;
216 } LTTNG_PACKED;
217
218 /* skip_offset is absolute from start of bytecode */
219 struct logical_op {
220 bytecode_opcode_t op;
221 uint16_t skip_offset; /* bytecode insn, if skip second test */
222 } LTTNG_PACKED;
223
224 struct cast_op {
225 bytecode_opcode_t op;
226 } LTTNG_PACKED;
227
228 struct return_op {
229 bytecode_opcode_t op;
230 } LTTNG_PACKED;
231
232 struct lttng_bytecode_alloc {
233 uint32_t alloc_len;
234 struct lttng_bytecode b;
235 };
236
237 LTTNG_HIDDEN int bytecode_init(struct lttng_bytecode_alloc **fb);
238 LTTNG_HIDDEN int bytecode_push(struct lttng_bytecode_alloc **fb,
239 const void *data, uint32_t align, uint32_t len);
240 LTTNG_HIDDEN int bytecode_push_logical(struct lttng_bytecode_alloc **fb,
241 struct logical_op *data, uint32_t align, uint32_t len,
242 uint16_t *skip_offset);
243 LTTNG_HIDDEN struct lttng_bytecode *lttng_bytecode_copy(
244 const struct lttng_bytecode *orig_f);
245
246 LTTNG_HIDDEN int bytecode_push_get_payload_root(
247 struct lttng_bytecode_alloc **bytecode);
248 LTTNG_HIDDEN int bytecode_push_get_context_root(
249 struct lttng_bytecode_alloc **bytecode);
250 LTTNG_HIDDEN int bytecode_push_get_app_context_root(
251 struct lttng_bytecode_alloc **bytecode);
252 LTTNG_HIDDEN int bytecode_push_get_index_u64(
253 struct lttng_bytecode_alloc **bytecode, uint64_t index);
254 LTTNG_HIDDEN int bytecode_push_get_symbol(
255 struct lttng_bytecode_alloc **bytecode,
256 struct lttng_bytecode_alloc **bytecode_reloc,
257 const char *symbol);
258
259 static inline
260 unsigned int bytecode_get_len(struct lttng_bytecode *bytecode)
261 {
262 return bytecode->len;
263 }
264
265 #endif /* LTTNG_COMMON_BYTECODE_H */
This page took 0.035024 seconds and 4 git commands to generate.