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
,
74 OBJECT_TYPE_SIGNED_ENUM
,
75 OBJECT_TYPE_UNSIGNED_ENUM
,
79 OBJECT_TYPE_STRING_SEQUENCE
,
89 struct bytecode_get_index_data
{
90 uint64_t offset
; /* in bytes */
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
99 const struct lttng_kernel_event_field
*field
;
102 enum object_type type
;
103 bool rev_bo
; /* reverse byte order */
107 /* Validation stack */
110 enum object_type object_type
;
111 const struct lttng_kernel_event_field
*field
;
112 bool rev_bo
; /* reverse byte order */
115 struct vstack_entry
{
116 enum entry_type type
;
117 struct vstack_load load
;
121 int top
; /* top of stack */
122 struct vstack_entry e
[INTERPRETER_STACK_LEN
];
126 void vstack_init(struct vstack
*stack
)
132 struct vstack_entry
*vstack_ax(struct vstack
*stack
)
134 if (unlikely(stack
->top
< 0))
136 return &stack
->e
[stack
->top
];
140 struct vstack_entry
*vstack_bx(struct vstack
*stack
)
142 if (unlikely(stack
->top
< 1))
144 return &stack
->e
[stack
->top
- 1];
148 int vstack_push(struct vstack
*stack
)
150 if (stack
->top
>= INTERPRETER_STACK_LEN
- 1) {
151 printk(KERN_WARNING
"LTTng: filter: Stack full\n");
159 int vstack_pop(struct vstack
*stack
)
161 if (unlikely(stack
->top
< 0)) {
162 printk(KERN_WARNING
"LTTng: filter: Stack empty\n");
169 /* Execution stack */
170 enum estack_string_literal_type
{
171 ESTACK_STRING_LITERAL_TYPE_NONE
,
172 ESTACK_STRING_LITERAL_TYPE_PLAIN
,
173 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB
,
178 enum object_type object_type
;
182 /* Temporary place-holders for contexts. */
188 const struct lttng_kernel_event_field
*field
;
191 struct estack_entry
{
192 enum entry_type type
;
198 const char __user
*user_str
;
200 enum estack_string_literal_type literal_type
;
201 int user
; /* is string from userspace ? */
208 int top
; /* top of stack */
209 struct estack_entry e
[INTERPRETER_STACK_LEN
];
212 #define estack_ax_v ax
213 #define estack_bx_v bx
215 #define estack_ax_t ax_t
216 #define estack_bx_t bx_t
218 #define estack_ax(stack, top) \
220 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
224 #define estack_bx(stack, top) \
226 BUG_ON((top) <= INTERPRETER_STACK_EMPTY + 1); \
227 &(stack)->e[(top) - 1]; \
230 #define estack_push(stack, top, ax, bx, ax_t, bx_t) \
232 BUG_ON((top) >= INTERPRETER_STACK_LEN - 1); \
233 (stack)->e[(top) - 1].u.v = (bx); \
234 (stack)->e[(top) - 1].type = (bx_t); \
240 #define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
242 BUG_ON((top) <= INTERPRETER_STACK_EMPTY); \
245 (bx) = (stack)->e[(top) - 2].u.v; \
246 (bx_t) = (stack)->e[(top) - 2].type; \
250 enum 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
,
261 * Represents the output parameter of the lttng interpreter.
262 * Currently capturable field classes are integer, double, string and sequence
265 struct lttng_interpreter_output
{
266 enum lttng_interpreter_type type
;
280 const struct lttng_kernel_type_common
*nested_type
;
285 const char *lttng_bytecode_print_op(enum bytecode_op op
);
287 void lttng_bytecode_filter_sync_state(struct lttng_bytecode_runtime
*runtime
);
288 void lttng_bytecode_capture_sync_state(struct lttng_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 uint64_t lttng_bytecode_filter_interpret_false(void *filter_data
,
294 struct lttng_probe_ctx
*lttng_probe_ctx
,
295 const char *filter_stack_data
);
296 uint64_t lttng_bytecode_filter_interpret(void *filter_data
,
297 struct lttng_probe_ctx
*lttng_probe_ctx
,
298 const char *filter_stack_data
);
300 uint64_t lttng_bytecode_capture_interpret_false(void *capture_data
,
301 struct lttng_probe_ctx
*lttng_probe_ctx
,
302 const char *capture_stack_data
,
303 struct lttng_interpreter_output
*output
);
304 uint64_t lttng_bytecode_capture_interpret(void *capture_data
,
305 struct lttng_probe_ctx
*lttng_probe_ctx
,
306 const char *capture_stack_data
,
307 struct lttng_interpreter_output
*output
);
309 #endif /* _LTTNG_FILTER_H */