common: move bytecode utilities from filter to its own file
[lttng-tools.git] / src / common / bytecode / bytecode.h
CommitLineData
953192ba 1/*
0ae3cfc6 2 * Copyright 2020 EfficiOS, Inc.
953192ba 3 *
ab5be9fa 4 * SPDX-License-Identifier: LGPL-2.1-only
953192ba 5 *
953192ba
MD
6 */
7
0ae3cfc6
SM
8#ifndef LTTNG_COMMON_BYTECODE_H
9#define LTTNG_COMMON_BYTECODE_H
d00c599e 10
0ae3cfc6
SM
11#include <stdint.h>
12
13#include "common/macros.h"
14#include "common/sessiond-comm/sessiond-comm.h"
953192ba
MD
15
16/*
17 * offsets are absolute from start of bytecode.
18 */
19
953192ba
MD
20struct field_ref {
21 /* Initially, symbol offset. After link, field offset. */
22 uint16_t offset;
6f30f9b8 23} LTTNG_PACKED;
953192ba 24
bff988fa
MD
25struct get_symbol {
26 /* Symbol offset. */
661dfdd1 27 uint16_t offset;
bff988fa
MD
28} LTTNG_PACKED;
29
30struct get_index_u16 {
31 uint16_t index;
32} LTTNG_PACKED;
33
34struct get_index_u64 {
35 uint64_t index;
661dfdd1
MD
36} LTTNG_PACKED;
37
953192ba
MD
38struct literal_numeric {
39 int64_t v;
6f30f9b8 40} LTTNG_PACKED;
953192ba 41
e90d8561
MD
42struct literal_double {
43 double v;
6f30f9b8 44} LTTNG_PACKED;
e90d8561 45
953192ba
MD
46struct literal_string {
47 char string[0];
6f30f9b8 48} LTTNG_PACKED;
953192ba
MD
49
50enum filter_op {
7e6831d1 51 FILTER_OP_UNKNOWN = 0,
953192ba 52
7e6831d1 53 FILTER_OP_RETURN = 1,
953192ba
MD
54
55 /* binary */
7e6831d1
MD
56 FILTER_OP_MUL = 2,
57 FILTER_OP_DIV = 3,
58 FILTER_OP_MOD = 4,
59 FILTER_OP_PLUS = 5,
60 FILTER_OP_MINUS = 6,
116d3c01
MD
61 FILTER_OP_BIT_RSHIFT = 7,
62 FILTER_OP_BIT_LSHIFT = 8,
bff988fa
MD
63 FILTER_OP_BIT_AND = 9,
64 FILTER_OP_BIT_OR = 10,
65 FILTER_OP_BIT_XOR = 11,
78228322
MD
66
67 /* binary comparators */
7e6831d1
MD
68 FILTER_OP_EQ = 12,
69 FILTER_OP_NE = 13,
70 FILTER_OP_GT = 14,
71 FILTER_OP_LT = 15,
72 FILTER_OP_GE = 16,
73 FILTER_OP_LE = 17,
953192ba 74
9f449915 75 /* string binary comparator: apply to */
7e6831d1
MD
76 FILTER_OP_EQ_STRING = 18,
77 FILTER_OP_NE_STRING = 19,
78 FILTER_OP_GT_STRING = 20,
79 FILTER_OP_LT_STRING = 21,
80 FILTER_OP_GE_STRING = 22,
81 FILTER_OP_LE_STRING = 23,
78228322
MD
82
83 /* s64 binary comparator */
7e6831d1
MD
84 FILTER_OP_EQ_S64 = 24,
85 FILTER_OP_NE_S64 = 25,
86 FILTER_OP_GT_S64 = 26,
87 FILTER_OP_LT_S64 = 27,
88 FILTER_OP_GE_S64 = 28,
89 FILTER_OP_LE_S64 = 29,
78228322
MD
90
91 /* double binary comparator */
7e6831d1
MD
92 FILTER_OP_EQ_DOUBLE = 30,
93 FILTER_OP_NE_DOUBLE = 31,
94 FILTER_OP_GT_DOUBLE = 32,
95 FILTER_OP_LT_DOUBLE = 33,
96 FILTER_OP_GE_DOUBLE = 34,
97 FILTER_OP_LE_DOUBLE = 35,
78228322 98
78370c0c 99 /* Mixed S64-double binary comparators */
7e6831d1
MD
100 FILTER_OP_EQ_DOUBLE_S64 = 36,
101 FILTER_OP_NE_DOUBLE_S64 = 37,
102 FILTER_OP_GT_DOUBLE_S64 = 38,
103 FILTER_OP_LT_DOUBLE_S64 = 39,
104 FILTER_OP_GE_DOUBLE_S64 = 40,
105 FILTER_OP_LE_DOUBLE_S64 = 41,
106
107 FILTER_OP_EQ_S64_DOUBLE = 42,
108 FILTER_OP_NE_S64_DOUBLE = 43,
109 FILTER_OP_GT_S64_DOUBLE = 44,
110 FILTER_OP_LT_S64_DOUBLE = 45,
111 FILTER_OP_GE_S64_DOUBLE = 46,
112 FILTER_OP_LE_S64_DOUBLE = 47,
78370c0c 113
953192ba 114 /* unary */
7e6831d1
MD
115 FILTER_OP_UNARY_PLUS = 48,
116 FILTER_OP_UNARY_MINUS = 49,
117 FILTER_OP_UNARY_NOT = 50,
118 FILTER_OP_UNARY_PLUS_S64 = 51,
119 FILTER_OP_UNARY_MINUS_S64 = 52,
120 FILTER_OP_UNARY_NOT_S64 = 53,
121 FILTER_OP_UNARY_PLUS_DOUBLE = 54,
122 FILTER_OP_UNARY_MINUS_DOUBLE = 55,
123 FILTER_OP_UNARY_NOT_DOUBLE = 56,
953192ba
MD
124
125 /* logical */
7e6831d1
MD
126 FILTER_OP_AND = 57,
127 FILTER_OP_OR = 58,
953192ba 128
586dc72f 129 /* load field ref */
7e6831d1
MD
130 FILTER_OP_LOAD_FIELD_REF = 59,
131 FILTER_OP_LOAD_FIELD_REF_STRING = 60,
132 FILTER_OP_LOAD_FIELD_REF_SEQUENCE = 61,
133 FILTER_OP_LOAD_FIELD_REF_S64 = 62,
134 FILTER_OP_LOAD_FIELD_REF_DOUBLE = 63,
65775683 135
586dc72f 136 /* load immediate from operand */
7e6831d1
MD
137 FILTER_OP_LOAD_STRING = 64,
138 FILTER_OP_LOAD_S64 = 65,
139 FILTER_OP_LOAD_DOUBLE = 66,
953192ba 140
8cf9540a 141 /* cast */
7e6831d1
MD
142 FILTER_OP_CAST_TO_S64 = 67,
143 FILTER_OP_CAST_DOUBLE_TO_S64 = 68,
144 FILTER_OP_CAST_NOP = 69,
8cf9540a 145
586dc72f
MD
146 /* get context ref */
147 FILTER_OP_GET_CONTEXT_REF = 70,
148 FILTER_OP_GET_CONTEXT_REF_STRING = 71,
149 FILTER_OP_GET_CONTEXT_REF_S64 = 72,
150 FILTER_OP_GET_CONTEXT_REF_DOUBLE = 73,
151
00a62084
MD
152 /* load userspace field ref */
153 FILTER_OP_LOAD_FIELD_REF_USER_STRING = 74,
154 FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE = 75,
155
9f449915
PP
156 /*
157 * load immediate star globbing pattern (literal string)
158 * from immediate
159 */
160 FILTER_OP_LOAD_STAR_GLOB_STRING = 76,
161
162 /* globbing pattern binary operator: apply to */
163 FILTER_OP_EQ_STAR_GLOB_STRING = 77,
164 FILTER_OP_NE_STAR_GLOB_STRING = 78,
165
bff988fa
MD
166 /*
167 * Instructions for recursive traversal through composed types.
168 */
169 FILTER_OP_GET_CONTEXT_ROOT = 79,
170 FILTER_OP_GET_APP_CONTEXT_ROOT = 80,
171 FILTER_OP_GET_PAYLOAD_ROOT = 81,
172
173 FILTER_OP_GET_SYMBOL = 82,
174 FILTER_OP_GET_SYMBOL_FIELD = 83,
175 FILTER_OP_GET_INDEX_U16 = 84,
176 FILTER_OP_GET_INDEX_U64 = 85,
177
178 FILTER_OP_LOAD_FIELD = 86,
179 FILTER_OP_LOAD_FIELD_S8 = 87,
180 FILTER_OP_LOAD_FIELD_S16 = 88,
181 FILTER_OP_LOAD_FIELD_S32 = 89,
182 FILTER_OP_LOAD_FIELD_S64 = 90,
183 FILTER_OP_LOAD_FIELD_U8 = 91,
184 FILTER_OP_LOAD_FIELD_U16 = 92,
185 FILTER_OP_LOAD_FIELD_U32 = 93,
186 FILTER_OP_LOAD_FIELD_U64 = 94,
187 FILTER_OP_LOAD_FIELD_STRING = 95,
188 FILTER_OP_LOAD_FIELD_SEQUENCE = 96,
189 FILTER_OP_LOAD_FIELD_DOUBLE = 97,
661dfdd1 190
116d3c01
MD
191 FILTER_OP_UNARY_BIT_NOT = 98,
192
ba8f6b16
MD
193 FILTER_OP_RETURN_S64 = 99,
194
953192ba
MD
195 NR_FILTER_OPS,
196};
197
198typedef uint8_t filter_opcode_t;
199
200struct load_op {
201 filter_opcode_t op;
953192ba
MD
202 char data[0];
203 /* data to load. Size known by enum filter_opcode and null-term char. */
6f30f9b8 204} LTTNG_PACKED;
953192ba
MD
205
206struct binary_op {
207 filter_opcode_t op;
6f30f9b8 208} LTTNG_PACKED;
953192ba
MD
209
210struct unary_op {
211 filter_opcode_t op;
6f30f9b8 212} LTTNG_PACKED;
953192ba
MD
213
214/* skip_offset is absolute from start of bytecode */
215struct logical_op {
216 filter_opcode_t op;
217 uint16_t skip_offset; /* bytecode insn, if skip second test */
6f30f9b8 218} LTTNG_PACKED;
953192ba 219
8cf9540a
MD
220struct cast_op {
221 filter_opcode_t op;
6f30f9b8 222} LTTNG_PACKED;
8cf9540a 223
953192ba
MD
224struct return_op {
225 filter_opcode_t op;
6f30f9b8 226} LTTNG_PACKED;
953192ba 227
53a80697 228struct lttng_filter_bytecode_alloc {
5ddb0a08 229 uint32_t alloc_len;
53a80697 230 struct lttng_filter_bytecode b;
953192ba
MD
231};
232
0ae3cfc6
SM
233LTTNG_HIDDEN int bytecode_init(struct lttng_filter_bytecode_alloc **fb);
234LTTNG_HIDDEN int32_t bytecode_reserve(struct lttng_filter_bytecode_alloc **fb,
235 uint32_t align, uint32_t len);
236LTTNG_HIDDEN int bytecode_push(struct lttng_filter_bytecode_alloc **fb,
237 const void *data, uint32_t align, uint32_t len);
238LTTNG_HIDDEN int bytecode_push_logical(struct lttng_filter_bytecode_alloc **fb,
239 struct logical_op *data, uint32_t align, uint32_t len,
240 uint16_t *skip_offset);
241
953192ba 242static inline
53a80697 243unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode)
953192ba
MD
244{
245 return bytecode->len;
246}
247
0ae3cfc6 248#endif /* LTTNG_COMMON_BYTECODE_H */
This page took 0.081045 seconds and 5 git commands to generate.