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/events-internal.h>
17 #include <lttng/bytecode.h>
19 /* Interpreter stack length, in number of entries */
20 #define INTERPRETER_STACK_LEN 10 /* includes 2 dummy */
21 #define INTERPRETER_STACK_EMPTY 1
22 #define INTERPRETER_MAX_DATA_LEN 65536
25 #define dbg_printk(fmt, args...) \
26 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
27 __FILE__, __func__, __LINE__, ## args)
29 #define dbg_printk(fmt, args...) \
31 /* do nothing but check printf format */ \
33 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
34 __FILE__, __func__, __LINE__, ## args); \
38 /* Linked bytecode. Child of struct lttng_kernel_bytecode_runtime. */
39 struct bytecode_runtime
{
40 struct lttng_kernel_bytecode_runtime p
;
42 size_t data_alloc_len
;
60 LOAD_ROOT_APP_CONTEXT
,
75 OBJECT_TYPE_SIGNED_ENUM
,
76 OBJECT_TYPE_UNSIGNED_ENUM
,
80 OBJECT_TYPE_STRING_SEQUENCE
,
90 struct bytecode_get_index_data
{
91 uint64_t offset
; /* in bytes */
95 * Field is only populated for LOAD_ROOT_CONTEXT, LOAD_ROOT_APP_CONTEXT
96 * and LOAD_ROOT_PAYLOAD. Left NULL for LOAD_OBJECT, considering that the
97 * interpreter needs to find it from the event fields and types to
100 const struct lttng_kernel_event_field
*field
;
103 enum object_type type
;
104 bool rev_bo
; /* reverse byte order */
108 /* Validation stack */
111 enum object_type object_type
;
112 const struct lttng_kernel_event_field
*field
;
113 bool rev_bo
; /* reverse byte order */
116 struct vstack_entry
{
117 enum entry_type type
;
118 struct vstack_load load
;
122 int top
; /* top of stack */
123 struct vstack_entry e
[INTERPRETER_STACK_LEN
];
127 void vstack_init(struct vstack
*stack
)
133 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
135 if (unlikely(stack
->top
< 0))
137 return &stack
->e
[stack
->top
];
141 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
143 if (unlikely(stack
->top
< 1))
145 return &stack
->e
[stack
->top
- 1];
149 int vstack_push(struct vstack
*stack
)
151 if (stack
->top
>= INTERPRETER_STACK_LEN
- 1) {
152 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
160 int vstack_pop(struct vstack
*stack
)
162 if (unlikely(stack
->top
< 0)) {
163 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
170 /* Execution stack */
171 enum estack_string_literal_type
{
172 ESTACK_STRING_LITERAL_TYPE_NONE
,
173 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
174 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
179 enum object_type object_type
;
183 /* Temporary place-holders for contexts. */
189 const struct lttng_kernel_event_field
*field
;
192 struct estack_entry
{
193 enum entry_type type
;
199 const char __user
*user_str
;
201 enum estack_string_literal_type literal_type
;
202 int user
; /* is string from userspace ? */
209 int top
; /* top of stack */
210 struct estack_entry e
[INTERPRETER_STACK_LEN
];
213 #define estack_ax_v ax
214 #define estack_bx_v bx
216 #define estack_ax_t ax_t
217 #define estack_bx_t bx_t
219 #define estack_ax(stack, top) \
221 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
225 #define estack_bx(stack, top) \
227 BUG_ON((top) <= INTERPRETER_STACK_EMPTY + 1); \
228 &(stack)->e[(top) - 1]; \
231 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
233 BUG_ON((top) >= INTERPRETER_STACK_LEN - 1); \
234 (stack)->e[(top) - 1].u.v = (bx); \
235 (stack)->e[(top) - 1].type = (bx_t); \
241 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
243 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
246 (bx) = (stack)->e[(top) - 2].u.v; \
247 (bx_t) = (stack)->e[(top) - 2].type; \
251 enum lttng_interpreter_type
{
252 LTTNG_INTERPRETER_TYPE_S64
,
253 LTTNG_INTERPRETER_TYPE_U64
,
254 LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
,
255 LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
,
256 LTTNG_INTERPRETER_TYPE_DOUBLE
,
257 LTTNG_INTERPRETER_TYPE_STRING
,
258 LTTNG_INTERPRETER_TYPE_SEQUENCE
,
262 * Represents the output parameter of the lttng interpreter.
263 * Currently capturable field classes are integer, double, string and sequence
266 struct lttng_interpreter_output
{
267 enum lttng_interpreter_type type
;
281 const struct lttng_kernel_type_common
*nested_type
;
286 const char *lttng_bytecode_print_op(enum bytecode_op op
);
288 void lttng_bytecode_sync_state(struct lttng_kernel_bytecode_runtime
*runtime
);
289 int lttng_bytecode_validate(struct bytecode_runtime
*bytecode
);
290 int lttng_bytecode_specialize(const struct lttng_kernel_event_desc
*event_desc
,
291 struct bytecode_runtime
*bytecode
);
293 int lttng_bytecode_interpret_error(struct lttng_kernel_bytecode_runtime
*bytecode_runtime
,
294 const char *stack_data
,
295 struct lttng_kernel_probe_ctx
*probe_ctx
,
298 int lttng_bytecode_interpret(struct lttng_kernel_bytecode_runtime
*kernel_bytecode
,
299 const char *interpreter_stack_data
,
300 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
303 #endif /* _LTTNG_FILTER_H */