bytecode: Add `OBJECT_TYPE_{UN,}SIGNED_ENUM` type
[lttng-modules.git] / include / lttng / lttng-bytecode.h
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: MIT
2 *
80c2a69a 3 * lttng/lttng-bytecode.h
07dfc1d0 4 *
80c2a69a 5 * LTTng modules bytecode header.
07dfc1d0 6 *
bbf3aef5 7 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
07dfc1d0
MD
8 */
9
80c2a69a
FD
10#ifndef _LTTNG_BYTECODE_H
11#define _LTTNG_BYTECODE_H
9f36eaed 12
07dfc1d0
MD
13#include <linux/kernel.h>
14
2df37e95 15#include <lttng/events.h>
80c2a69a 16#include <lttng/bytecode.h>
07dfc1d0 17
80c2a69a
FD
18/* Interpreter stack length, in number of entries */
19#define INTERPRETER_STACK_LEN 10 /* includes 2 dummy */
20#define INTERPRETER_STACK_EMPTY 1
21#define INTERPRETER_MAX_DATA_LEN 65536
3834b99f 22
07dfc1d0
MD
23#ifdef DEBUG
24#define dbg_printk(fmt, args...) \
5a15f70c 25 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
07dfc1d0
MD
26 __FILE__, __func__, __LINE__, ## args)
27#else
28#define dbg_printk(fmt, args...) \
29do { \
30 /* do nothing but check printf format */ \
31 if (0) \
5a15f70c 32 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
07dfc1d0
MD
33 __FILE__, __func__, __LINE__, ## args); \
34} while (0)
35#endif
36
37/* Linked bytecode. Child of struct lttng_bytecode_runtime. */
38struct bytecode_runtime {
39 struct lttng_bytecode_runtime p;
3834b99f
MD
40 size_t data_len;
41 size_t data_alloc_len;
42 char *data;
07dfc1d0 43 uint16_t len;
3834b99f 44 char code[0];
07dfc1d0
MD
45};
46
47enum entry_type {
48 REG_S64,
1242217a 49 REG_U64,
07dfc1d0
MD
50 REG_DOUBLE,
51 REG_STRING,
02aca193 52 REG_STAR_GLOB_STRING,
07dfc1d0 53 REG_TYPE_UNKNOWN,
3834b99f
MD
54 REG_PTR,
55};
56
57enum load_type {
58 LOAD_ROOT_CONTEXT,
59 LOAD_ROOT_APP_CONTEXT,
60 LOAD_ROOT_PAYLOAD,
61 LOAD_OBJECT,
62};
63
64enum object_type {
65 OBJECT_TYPE_S8,
66 OBJECT_TYPE_S16,
67 OBJECT_TYPE_S32,
68 OBJECT_TYPE_S64,
69 OBJECT_TYPE_U8,
70 OBJECT_TYPE_U16,
71 OBJECT_TYPE_U32,
72 OBJECT_TYPE_U64,
73
29a574c3
FD
74 OBJECT_TYPE_SIGNED_ENUM,
75 OBJECT_TYPE_UNSIGNED_ENUM,
76
3834b99f
MD
77 OBJECT_TYPE_DOUBLE,
78 OBJECT_TYPE_STRING,
79 OBJECT_TYPE_STRING_SEQUENCE,
80
81 OBJECT_TYPE_SEQUENCE,
82 OBJECT_TYPE_ARRAY,
83 OBJECT_TYPE_STRUCT,
84 OBJECT_TYPE_VARIANT,
85
86 OBJECT_TYPE_DYNAMIC,
87};
88
80c2a69a 89struct bytecode_get_index_data {
3834b99f
MD
90 uint64_t offset; /* in bytes */
91 size_t ctx_index;
92 size_t array_len;
03cb0cdd
FD
93 /*
94 * Field is only populated for LOAD_ROOT_CONTEXT, LOAD_ROOT_APP_CONTEXT
95 * and LOAD_ROOT_PAYLOAD. Left NULL for LOAD_OBJECT, considering that the
96 * interpreter needs to find it from the event fields and types to
97 * support variants.
98 */
99 const struct lttng_event_field *field;
3834b99f
MD
100 struct {
101 size_t len;
102 enum object_type type;
103 bool rev_bo; /* reverse byte order */
104 } elem;
07dfc1d0
MD
105};
106
107/* Validation stack */
3834b99f
MD
108struct vstack_load {
109 enum load_type type;
110 enum object_type object_type;
111 const struct lttng_event_field *field;
112 bool rev_bo; /* reverse byte order */
113};
114
07dfc1d0
MD
115struct vstack_entry {
116 enum entry_type type;
3834b99f 117 struct vstack_load load;
07dfc1d0
MD
118};
119
120struct vstack {
121 int top; /* top of stack */
80c2a69a 122 struct vstack_entry e[INTERPRETER_STACK_LEN];
07dfc1d0
MD
123};
124
125static inline
126void vstack_init(struct vstack *stack)
127{
128 stack->top = -1;
129}
130
131static inline
132struct vstack_entry *vstack_ax(struct vstack *stack)
133{
134 if (unlikely(stack->top < 0))
135 return NULL;
136 return &stack->e[stack->top];
137}
138
139static inline
140struct vstack_entry *vstack_bx(struct vstack *stack)
141{
142 if (unlikely(stack->top < 1))
143 return NULL;
144 return &stack->e[stack->top - 1];
145}
146
147static inline
148int vstack_push(struct vstack *stack)
149{
80c2a69a 150 if (stack->top >= INTERPRETER_STACK_LEN - 1) {
5a15f70c 151 printk(KERN_WARNING "LTTng: filter: Stack full\n");
07dfc1d0
MD
152 return -EINVAL;
153 }
154 ++stack->top;
155 return 0;
156}
157
158static inline
159int vstack_pop(struct vstack *stack)
160{
161 if (unlikely(stack->top < 0)) {
5a15f70c 162 printk(KERN_WARNING "LTTng: filter: Stack empty\n");
07dfc1d0
MD
163 return -EINVAL;
164 }
165 stack->top--;
166 return 0;
167}
168
169/* Execution stack */
02aca193
PP
170enum estack_string_literal_type {
171 ESTACK_STRING_LITERAL_TYPE_NONE,
172 ESTACK_STRING_LITERAL_TYPE_PLAIN,
173 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB,
174};
175
3834b99f
MD
176struct load_ptr {
177 enum load_type type;
178 enum object_type object_type;
179 const void *ptr;
03cb0cdd 180 size_t nr_elem;
3834b99f
MD
181 bool rev_bo;
182 /* Temporary place-holders for contexts. */
183 union {
184 int64_t s64;
185 uint64_t u64;
186 double d;
187 } u;
3834b99f
MD
188 const struct lttng_event_field *field;
189};
190
07dfc1d0 191struct estack_entry {
d644d1df 192 enum entry_type type;
07dfc1d0
MD
193 union {
194 int64_t v;
195
196 struct {
197 const char *str;
f127e61e 198 const char __user *user_str;
07dfc1d0 199 size_t seq_len;
02aca193 200 enum estack_string_literal_type literal_type;
f127e61e 201 int user; /* is string from userspace ? */
07dfc1d0 202 } s;
3834b99f 203 struct load_ptr ptr;
07dfc1d0
MD
204 } u;
205};
206
207struct estack {
208 int top; /* top of stack */
80c2a69a 209 struct estack_entry e[INTERPRETER_STACK_LEN];
07dfc1d0
MD
210};
211
212#define estack_ax_v ax
213#define estack_bx_v bx
214
d644d1df
FD
215#define estack_ax_t ax_t
216#define estack_bx_t bx_t
217
07dfc1d0
MD
218#define estack_ax(stack, top) \
219 ({ \
80c2a69a 220 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
07dfc1d0
MD
221 &(stack)->e[top]; \
222 })
223
224#define estack_bx(stack, top) \
225 ({ \
80c2a69a 226 BUG_ON((top) <= INTERPRETER_STACK_EMPTY + 1); \
07dfc1d0
MD
227 &(stack)->e[(top) - 1]; \
228 })
229
d644d1df 230#define estack_push(stack, top, ax, bx, ax_t, bx_t) \
07dfc1d0 231 do { \
80c2a69a 232 BUG_ON((top) >= INTERPRETER_STACK_LEN - 1); \
07dfc1d0 233 (stack)->e[(top) - 1].u.v = (bx); \
d644d1df 234 (stack)->e[(top) - 1].type = (bx_t); \
07dfc1d0 235 (bx) = (ax); \
d644d1df 236 (bx_t) = (ax_t); \
07dfc1d0
MD
237 ++(top); \
238 } while (0)
239
d644d1df 240#define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
07dfc1d0 241 do { \
80c2a69a 242 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
07dfc1d0 243 (ax) = (bx); \
d644d1df 244 (ax_t) = (bx_t); \
07dfc1d0 245 (bx) = (stack)->e[(top) - 2].u.v; \
d644d1df 246 (bx_t) = (stack)->e[(top) - 2].type; \
07dfc1d0
MD
247 (top)--; \
248 } while (0)
249
03cb0cdd
FD
250enum lttng_interpreter_type {
251 LTTNG_INTERPRETER_TYPE_S64,
252 LTTNG_INTERPRETER_TYPE_U64,
253 LTTNG_INTERPRETER_TYPE_SIGNED_ENUM,
254 LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM,
255 LTTNG_INTERPRETER_TYPE_DOUBLE,
256 LTTNG_INTERPRETER_TYPE_STRING,
257 LTTNG_INTERPRETER_TYPE_SEQUENCE,
258};
259
260/*
261 * Represents the output parameter of the lttng interpreter.
262 * Currently capturable field classes are integer, double, string and sequence
263 * of integer.
264 */
265struct lttng_interpreter_output {
266 enum lttng_interpreter_type type;
267 union {
268 int64_t s;
269 uint64_t u;
270
271 struct {
272 const char *str;
273 size_t len;
274 } str;
275 struct {
276 const void *ptr;
277 size_t nr_elem;
278
279 /* Inner type. */
280 const struct lttng_type *nested_type;
281 } sequence;
282 } u;
283};
284
80c2a69a 285const char *lttng_bytecode_print_op(enum bytecode_op op);
07dfc1d0 286
0b365677 287void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime *runtime);
80c2a69a
FD
288int lttng_bytecode_validate(struct bytecode_runtime *bytecode);
289int lttng_bytecode_specialize(const struct lttng_event_desc *event_desc,
3834b99f 290 struct bytecode_runtime *bytecode);
07dfc1d0 291
80c2a69a 292uint64_t lttng_bytecode_filter_interpret_false(void *filter_data,
79150a49 293 struct lttng_probe_ctx *lttng_probe_ctx,
07dfc1d0 294 const char *filter_stack_data);
80c2a69a 295uint64_t lttng_bytecode_filter_interpret(void *filter_data,
79150a49 296 struct lttng_probe_ctx *lttng_probe_ctx,
07dfc1d0
MD
297 const char *filter_stack_data);
298
299#endif /* _LTTNG_FILTER_H */
This page took 0.049875 seconds and 4 git commands to generate.