2 * Copyright 2020 EfficiOS, Inc.
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_COMMON_BYTECODE_H
9 #define LTTNG_COMMON_BYTECODE_H
13 #include "common/macros.h"
14 #include "common/sessiond-comm/sessiond-comm.h"
17 * offsets are absolute from start of bytecode.
21 /* Initially, symbol offset. After link, field offset. */
30 struct get_index_u16
{
34 struct get_index_u64
{
38 struct literal_numeric
{
42 struct literal_double
{
46 struct literal_string
{
51 FILTER_OP_UNKNOWN
= 0,
61 FILTER_OP_BIT_RSHIFT
= 7,
62 FILTER_OP_BIT_LSHIFT
= 8,
63 FILTER_OP_BIT_AND
= 9,
64 FILTER_OP_BIT_OR
= 10,
65 FILTER_OP_BIT_XOR
= 11,
67 /* binary comparators */
75 /* string binary comparator: apply to */
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,
83 /* s64 binary comparator */
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,
91 /* double binary comparator */
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,
99 /* Mixed S64-double binary comparators */
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,
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,
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,
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,
136 /* load immediate from operand */
137 FILTER_OP_LOAD_STRING
= 64,
138 FILTER_OP_LOAD_S64
= 65,
139 FILTER_OP_LOAD_DOUBLE
= 66,
142 FILTER_OP_CAST_TO_S64
= 67,
143 FILTER_OP_CAST_DOUBLE_TO_S64
= 68,
144 FILTER_OP_CAST_NOP
= 69,
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,
152 /* load userspace field ref */
153 FILTER_OP_LOAD_FIELD_REF_USER_STRING
= 74,
154 FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
= 75,
157 * load immediate star globbing pattern (literal string)
160 FILTER_OP_LOAD_STAR_GLOB_STRING
= 76,
162 /* globbing pattern binary operator: apply to */
163 FILTER_OP_EQ_STAR_GLOB_STRING
= 77,
164 FILTER_OP_NE_STAR_GLOB_STRING
= 78,
167 * Instructions for recursive traversal through composed types.
169 FILTER_OP_GET_CONTEXT_ROOT
= 79,
170 FILTER_OP_GET_APP_CONTEXT_ROOT
= 80,
171 FILTER_OP_GET_PAYLOAD_ROOT
= 81,
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,
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,
191 FILTER_OP_UNARY_BIT_NOT
= 98,
193 FILTER_OP_RETURN_S64
= 99,
198 typedef uint8_t filter_opcode_t
;
203 /* data to load. Size known by enum filter_opcode and null-term char. */
214 /* skip_offset is absolute from start of bytecode */
217 uint16_t skip_offset
; /* bytecode insn, if skip second test */
228 struct lttng_filter_bytecode_alloc
{
230 struct lttng_filter_bytecode b
;
233 LTTNG_HIDDEN
int bytecode_init(struct lttng_filter_bytecode_alloc
**fb
);
234 LTTNG_HIDDEN
int32_t bytecode_reserve(struct lttng_filter_bytecode_alloc
**fb
,
235 uint32_t align
, uint32_t len
);
236 LTTNG_HIDDEN
int bytecode_push(struct lttng_filter_bytecode_alloc
**fb
,
237 const void *data
, uint32_t align
, uint32_t len
);
238 LTTNG_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 LTTNG_HIDDEN
struct lttng_filter_bytecode
*lttng_filter_bytecode_copy(
242 const struct lttng_filter_bytecode
*orig_f
);
245 unsigned int bytecode_get_len(struct lttng_filter_bytecode
*bytecode
)
247 return bytecode
->len
;
250 #endif /* LTTNG_COMMON_BYTECODE_H */