1 /* SPDX-License-Identifier: MIT
3 * lttng/lttng-bytecode.h
5 * LTTng modules bytecode header.
7 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #ifndef _LTTNG_BYTECODE_H
11 #define _LTTNG_BYTECODE_H
13 #include <linux/kernel.h>
15 #include <lttng/events.h>
16 #include <lttng/bytecode.h>
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
24 #define dbg_printk(fmt, args...) \
25 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
26 __FILE__, __func__, __LINE__, ## args)
28 #define dbg_printk(fmt, args...) \
30 /* do nothing but check printf format */ \
32 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
33 __FILE__, __func__, __LINE__, ## args); \
37 /* Linked bytecode. Child of struct lttng_bytecode_runtime. */
38 struct bytecode_runtime
{
39 struct lttng_bytecode_runtime p
;
41 size_t data_alloc_len
;
59 LOAD_ROOT_APP_CONTEXT
,
76 OBJECT_TYPE_STRING_SEQUENCE
,
86 struct bytecode_get_index_data
{
87 uint64_t offset
; /* in bytes */
91 * Field is only populated for LOAD_ROOT_CONTEXT, LOAD_ROOT_APP_CONTEXT
92 * and LOAD_ROOT_PAYLOAD. Left NULL for LOAD_OBJECT, considering that the
93 * interpreter needs to find it from the event fields and types to
96 const struct lttng_event_field
*field
;
99 enum object_type type
;
100 bool rev_bo
; /* reverse byte order */
104 /* Validation stack */
107 enum object_type object_type
;
108 const struct lttng_event_field
*field
;
109 bool rev_bo
; /* reverse byte order */
112 struct vstack_entry
{
113 enum entry_type type
;
114 struct vstack_load load
;
118 int top
; /* top of stack */
119 struct vstack_entry e
[INTERPRETER_STACK_LEN
];
123 void vstack_init(struct vstack
*stack
)
129 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
131 if (unlikely(stack
->top
< 0))
133 return &stack
->e
[stack
->top
];
137 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
139 if (unlikely(stack
->top
< 1))
141 return &stack
->e
[stack
->top
- 1];
145 int vstack_push(struct vstack
*stack
)
147 if (stack
->top
>= INTERPRETER_STACK_LEN
- 1) {
148 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
156 int vstack_pop(struct vstack
*stack
)
158 if (unlikely(stack
->top
< 0)) {
159 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
166 /* Execution stack */
167 enum estack_string_literal_type
{
168 ESTACK_STRING_LITERAL_TYPE_NONE
,
169 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
170 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
175 enum object_type object_type
;
179 /* Temporary place-holders for contexts. */
185 const struct lttng_event_field
*field
;
188 struct estack_entry
{
189 enum entry_type type
;
195 const char __user
*user_str
;
197 enum estack_string_literal_type literal_type
;
198 int user
; /* is string from userspace ? */
205 int top
; /* top of stack */
206 struct estack_entry e
[INTERPRETER_STACK_LEN
];
209 #define estack_ax_v ax
210 #define estack_bx_v bx
212 #define estack_ax_t ax_t
213 #define estack_bx_t bx_t
215 #define estack_ax(stack, top) \
217 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
221 #define estack_bx(stack, top) \
223 BUG_ON((top) <= INTERPRETER_STACK_EMPTY + 1); \
224 &(stack)->e[(top) - 1]; \
227 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
229 BUG_ON((top) >= INTERPRETER_STACK_LEN - 1); \
230 (stack)->e[(top) - 1].u.v = (bx); \
231 (stack)->e[(top) - 1].type = (bx_t); \
237 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
239 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
242 (bx) = (stack)->e[(top) - 2].u.v; \
243 (bx_t) = (stack)->e[(top) - 2].type; \
247 enum lttng_interpreter_type
{
248 LTTNG_INTERPRETER_TYPE_S64
,
249 LTTNG_INTERPRETER_TYPE_U64
,
250 LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
,
251 LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
,
252 LTTNG_INTERPRETER_TYPE_DOUBLE
,
253 LTTNG_INTERPRETER_TYPE_STRING
,
254 LTTNG_INTERPRETER_TYPE_SEQUENCE
,
258 * Represents the output parameter of the lttng interpreter.
259 * Currently capturable field classes are integer, double, string and sequence
262 struct lttng_interpreter_output
{
263 enum lttng_interpreter_type type
;
277 const struct lttng_type
*nested_type
;
282 const char *lttng_bytecode_print_op(enum bytecode_op op
);
284 void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime
*runtime
);
285 int lttng_bytecode_validate(struct bytecode_runtime
*bytecode
);
286 int lttng_bytecode_specialize(const struct lttng_event_desc
*event_desc
,
287 struct bytecode_runtime
*bytecode
);
289 uint64_t lttng_bytecode_filter_interpret_false(void *filter_data
,
290 struct lttng_probe_ctx
*lttng_probe_ctx
,
291 const char *filter_stack_data
);
292 uint64_t lttng_bytecode_filter_interpret(void *filter_data
,
293 struct lttng_probe_ctx
*lttng_probe_ctx
,
294 const char *filter_stack_data
);
296 #endif /* _LTTNG_FILTER_H */