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