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 */
105 bool user
; /* from userspace */
109 /* Validation stack */
112 enum object_type object_type
;
113 const struct lttng_kernel_event_field
*field
;
114 bool rev_bo
; /* reverse byte order */
115 bool user
; /* from userspace */
118 struct vstack_entry
{
119 enum entry_type type
;
120 struct vstack_load load
;
124 int top
; /* top of stack */
125 struct vstack_entry e
[INTERPRETER_STACK_LEN
];
129 void vstack_init(struct vstack
*stack
)
135 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
137 if (unlikely(stack
->top
< 0))
139 return &stack
->e
[stack
->top
];
143 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
145 if (unlikely(stack
->top
< 1))
147 return &stack
->e
[stack
->top
- 1];
151 int vstack_push(struct vstack
*stack
)
153 if (stack
->top
>= INTERPRETER_STACK_LEN
- 1) {
154 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
162 int vstack_pop(struct vstack
*stack
)
164 if (unlikely(stack
->top
< 0)) {
165 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
172 /* Execution stack */
173 enum estack_string_literal_type
{
174 ESTACK_STRING_LITERAL_TYPE_NONE
,
175 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
176 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
181 enum object_type object_type
;
185 bool user
; /* from userspace */
186 /* Temporary place-holders for contexts. */
192 const struct lttng_kernel_event_field
*field
;
195 struct estack_entry
{
196 enum entry_type type
;
202 const char __user
*user_str
;
204 enum estack_string_literal_type literal_type
;
205 bool user
; /* is string from userspace ? */
212 int top
; /* top of stack */
213 struct estack_entry e
[INTERPRETER_STACK_LEN
];
216 #define estack_ax_v ax
217 #define estack_bx_v bx
219 #define estack_ax_t ax_t
220 #define estack_bx_t bx_t
222 #define estack_ax(stack, top) \
224 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
228 #define estack_bx(stack, top) \
230 BUG_ON((top) <= INTERPRETER_STACK_EMPTY + 1); \
231 &(stack)->e[(top) - 1]; \
234 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
236 BUG_ON((top) >= INTERPRETER_STACK_LEN - 1); \
237 (stack)->e[(top) - 1].u.v = (bx); \
238 (stack)->e[(top) - 1].type = (bx_t); \
244 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
246 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
249 (bx) = (stack)->e[(top) - 2].u.v; \
250 (bx_t) = (stack)->e[(top) - 2].type; \
254 enum lttng_interpreter_type
{
255 LTTNG_INTERPRETER_TYPE_S64
,
256 LTTNG_INTERPRETER_TYPE_U64
,
257 LTTNG_INTERPRETER_TYPE_SIGNED_ENUM
,
258 LTTNG_INTERPRETER_TYPE_UNSIGNED_ENUM
,
259 LTTNG_INTERPRETER_TYPE_DOUBLE
,
260 LTTNG_INTERPRETER_TYPE_STRING
,
261 LTTNG_INTERPRETER_TYPE_SEQUENCE
,
265 * Represents the output parameter of the lttng interpreter.
266 * Currently capturable field classes are integer, double, string and sequence
269 struct lttng_interpreter_output
{
270 enum lttng_interpreter_type type
;
277 const char __user
*user_str
;
279 bool user
; /* is string from userspace ? */
286 const struct lttng_kernel_type_common
*nested_type
;
291 const char *lttng_bytecode_print_op(enum bytecode_op op
);
293 void lttng_bytecode_sync_state(struct lttng_kernel_bytecode_runtime
*runtime
);
294 int lttng_bytecode_validate(struct bytecode_runtime
*bytecode
);
295 int lttng_bytecode_specialize(const struct lttng_kernel_event_desc
*event_desc
,
296 struct bytecode_runtime
*bytecode
);
298 int lttng_bytecode_interpret_error(struct lttng_kernel_bytecode_runtime
*bytecode_runtime
,
299 const char *stack_data
,
300 struct lttng_kernel_probe_ctx
*probe_ctx
,
303 int lttng_bytecode_interpret(struct lttng_kernel_bytecode_runtime
*kernel_bytecode
,
304 const char *interpreter_stack_data
,
305 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
308 #endif /* _LTTNG_FILTER_H */