bytecode: add `REG_U64` interpreter register type
[lttng-modules.git] / include / lttng / filter.h
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: MIT
2 *
2df37e95 3 * lttng/filter.h
07dfc1d0
MD
4 *
5 * LTTng modules filter header.
6 *
bbf3aef5 7 * Copyright (C) 2010-2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
07dfc1d0
MD
8 */
9
9f36eaed
MJ
10#ifndef _LTTNG_FILTER_H
11#define _LTTNG_FILTER_H
12
07dfc1d0
MD
13#include <linux/kernel.h>
14
2df37e95
MD
15#include <lttng/events.h>
16#include <lttng/filter-bytecode.h>
07dfc1d0
MD
17
18/* Filter stack length, in number of entries */
19#define FILTER_STACK_LEN 10 /* includes 2 dummy */
20#define FILTER_STACK_EMPTY 1
21
3834b99f
MD
22#define FILTER_MAX_DATA_LEN 65536
23
07dfc1d0
MD
24#ifdef DEBUG
25#define dbg_printk(fmt, args...) \
5a15f70c 26 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
07dfc1d0
MD
27 __FILE__, __func__, __LINE__, ## args)
28#else
29#define dbg_printk(fmt, args...) \
30do { \
31 /* do nothing but check printf format */ \
32 if (0) \
5a15f70c 33 printk(KERN_DEBUG "LTTng: [debug bytecode in %s:%s@%u] " fmt, \
07dfc1d0
MD
34 __FILE__, __func__, __LINE__, ## args); \
35} while (0)
36#endif
37
38/* Linked bytecode. Child of struct lttng_bytecode_runtime. */
39struct bytecode_runtime {
40 struct lttng_bytecode_runtime p;
3834b99f
MD
41 size_t data_len;
42 size_t data_alloc_len;
43 char *data;
07dfc1d0 44 uint16_t len;
3834b99f 45 char code[0];
07dfc1d0
MD
46};
47
48enum entry_type {
49 REG_S64,
1242217a 50 REG_U64,
07dfc1d0
MD
51 REG_DOUBLE,
52 REG_STRING,
02aca193 53 REG_STAR_GLOB_STRING,
07dfc1d0 54 REG_TYPE_UNKNOWN,
3834b99f
MD
55 REG_PTR,
56};
57
58enum load_type {
59 LOAD_ROOT_CONTEXT,
60 LOAD_ROOT_APP_CONTEXT,
61 LOAD_ROOT_PAYLOAD,
62 LOAD_OBJECT,
63};
64
65enum object_type {
66 OBJECT_TYPE_S8,
67 OBJECT_TYPE_S16,
68 OBJECT_TYPE_S32,
69 OBJECT_TYPE_S64,
70 OBJECT_TYPE_U8,
71 OBJECT_TYPE_U16,
72 OBJECT_TYPE_U32,
73 OBJECT_TYPE_U64,
74
75 OBJECT_TYPE_DOUBLE,
76 OBJECT_TYPE_STRING,
77 OBJECT_TYPE_STRING_SEQUENCE,
78
79 OBJECT_TYPE_SEQUENCE,
80 OBJECT_TYPE_ARRAY,
81 OBJECT_TYPE_STRUCT,
82 OBJECT_TYPE_VARIANT,
83
84 OBJECT_TYPE_DYNAMIC,
85};
86
87struct filter_get_index_data {
88 uint64_t offset; /* in bytes */
89 size_t ctx_index;
90 size_t array_len;
91 struct {
92 size_t len;
93 enum object_type type;
94 bool rev_bo; /* reverse byte order */
95 } elem;
07dfc1d0
MD
96};
97
98/* Validation stack */
3834b99f
MD
99struct vstack_load {
100 enum load_type type;
101 enum object_type object_type;
102 const struct lttng_event_field *field;
103 bool rev_bo; /* reverse byte order */
104};
105
07dfc1d0
MD
106struct vstack_entry {
107 enum entry_type type;
3834b99f 108 struct vstack_load load;
07dfc1d0
MD
109};
110
111struct vstack {
112 int top; /* top of stack */
113 struct vstack_entry e[FILTER_STACK_LEN];
114};
115
116static inline
117void vstack_init(struct vstack *stack)
118{
119 stack->top = -1;
120}
121
122static inline
123struct vstack_entry *vstack_ax(struct vstack *stack)
124{
125 if (unlikely(stack->top < 0))
126 return NULL;
127 return &stack->e[stack->top];
128}
129
130static inline
131struct vstack_entry *vstack_bx(struct vstack *stack)
132{
133 if (unlikely(stack->top < 1))
134 return NULL;
135 return &stack->e[stack->top - 1];
136}
137
138static inline
139int vstack_push(struct vstack *stack)
140{
141 if (stack->top >= FILTER_STACK_LEN - 1) {
5a15f70c 142 printk(KERN_WARNING "LTTng: filter: Stack full\n");
07dfc1d0
MD
143 return -EINVAL;
144 }
145 ++stack->top;
146 return 0;
147}
148
149static inline
150int vstack_pop(struct vstack *stack)
151{
152 if (unlikely(stack->top < 0)) {
5a15f70c 153 printk(KERN_WARNING "LTTng: filter: Stack empty\n");
07dfc1d0
MD
154 return -EINVAL;
155 }
156 stack->top--;
157 return 0;
158}
159
160/* Execution stack */
02aca193
PP
161enum estack_string_literal_type {
162 ESTACK_STRING_LITERAL_TYPE_NONE,
163 ESTACK_STRING_LITERAL_TYPE_PLAIN,
164 ESTACK_STRING_LITERAL_TYPE_STAR_GLOB,
165};
166
3834b99f
MD
167struct load_ptr {
168 enum load_type type;
169 enum object_type object_type;
170 const void *ptr;
171 bool rev_bo;
172 /* Temporary place-holders for contexts. */
173 union {
174 int64_t s64;
175 uint64_t u64;
176 double d;
177 } u;
178 /*
179 * "field" is only needed when nested under a variant, in which
180 * case we cannot specialize the nested operations.
181 */
182 const struct lttng_event_field *field;
183};
184
07dfc1d0 185struct estack_entry {
d644d1df 186 enum entry_type type;
07dfc1d0
MD
187 union {
188 int64_t v;
189
190 struct {
191 const char *str;
f127e61e 192 const char __user *user_str;
07dfc1d0 193 size_t seq_len;
02aca193 194 enum estack_string_literal_type literal_type;
f127e61e 195 int user; /* is string from userspace ? */
07dfc1d0 196 } s;
3834b99f 197 struct load_ptr ptr;
07dfc1d0
MD
198 } u;
199};
200
201struct estack {
202 int top; /* top of stack */
203 struct estack_entry e[FILTER_STACK_LEN];
204};
205
206#define estack_ax_v ax
207#define estack_bx_v bx
208
d644d1df
FD
209#define estack_ax_t ax_t
210#define estack_bx_t bx_t
211
07dfc1d0
MD
212#define estack_ax(stack, top) \
213 ({ \
5f12cb8d 214 BUG_ON((top) <= FILTER_STACK_EMPTY); \
07dfc1d0
MD
215 &(stack)->e[top]; \
216 })
217
218#define estack_bx(stack, top) \
219 ({ \
5f12cb8d 220 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
07dfc1d0
MD
221 &(stack)->e[(top) - 1]; \
222 })
223
d644d1df 224#define estack_push(stack, top, ax, bx, ax_t, bx_t) \
07dfc1d0 225 do { \
5f12cb8d 226 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
07dfc1d0 227 (stack)->e[(top) - 1].u.v = (bx); \
d644d1df 228 (stack)->e[(top) - 1].type = (bx_t); \
07dfc1d0 229 (bx) = (ax); \
d644d1df 230 (bx_t) = (ax_t); \
07dfc1d0
MD
231 ++(top); \
232 } while (0)
233
d644d1df 234#define estack_pop(stack, top, ax, bx, ax_t, bx_t) \
07dfc1d0 235 do { \
5f12cb8d 236 BUG_ON((top) <= FILTER_STACK_EMPTY); \
07dfc1d0 237 (ax) = (bx); \
d644d1df 238 (ax_t) = (bx_t); \
07dfc1d0 239 (bx) = (stack)->e[(top) - 2].u.v; \
d644d1df 240 (bx_t) = (stack)->e[(top) - 2].type; \
07dfc1d0
MD
241 (top)--; \
242 } while (0)
243
244const char *lttng_filter_print_op(enum filter_op op);
245
246int lttng_filter_validate_bytecode(struct bytecode_runtime *bytecode);
2dfda770 247int lttng_filter_specialize_bytecode(const struct lttng_event_desc *event_desc,
3834b99f 248 struct bytecode_runtime *bytecode);
07dfc1d0
MD
249
250uint64_t lttng_filter_false(void *filter_data,
79150a49 251 struct lttng_probe_ctx *lttng_probe_ctx,
07dfc1d0
MD
252 const char *filter_stack_data);
253uint64_t lttng_filter_interpret_bytecode(void *filter_data,
79150a49 254 struct lttng_probe_ctx *lttng_probe_ctx,
07dfc1d0
MD
255 const char *filter_stack_data);
256
257#endif /* _LTTNG_FILTER_H */
This page took 0.046421 seconds and 4 git commands to generate.