Version 2.7.7
[lttng-modules.git] / lttng-filter.h
CommitLineData
07dfc1d0
MD
1#ifndef _LTTNG_FILTER_H
2#define _LTTNG_FILTER_H
3
4/*
5 * lttng-filter.h
6 *
7 * LTTng modules filter header.
8 *
9 * Copyright (C) 2010-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#include <linux/kernel.h>
27
28#include "lttng-events.h"
29#include "filter-bytecode.h"
30
31/* Filter stack length, in number of entries */
32#define FILTER_STACK_LEN 10 /* includes 2 dummy */
33#define FILTER_STACK_EMPTY 1
34
35#ifdef DEBUG
36#define dbg_printk(fmt, args...) \
37 printk(KERN_DEBUG "[debug bytecode in %s:%s@%u] " fmt, \
38 __FILE__, __func__, __LINE__, ## args)
39#else
40#define dbg_printk(fmt, args...) \
41do { \
42 /* do nothing but check printf format */ \
43 if (0) \
44 printk(KERN_DEBUG "[debug bytecode in %s:%s@%u] " fmt, \
45 __FILE__, __func__, __LINE__, ## args); \
46} while (0)
47#endif
48
49/* Linked bytecode. Child of struct lttng_bytecode_runtime. */
50struct bytecode_runtime {
51 struct lttng_bytecode_runtime p;
52 uint16_t len;
53 char data[0];
54};
55
56enum entry_type {
57 REG_S64,
58 REG_DOUBLE,
59 REG_STRING,
60 REG_TYPE_UNKNOWN,
61};
62
63/* Validation stack */
64struct vstack_entry {
65 enum entry_type type;
66};
67
68struct vstack {
69 int top; /* top of stack */
70 struct vstack_entry e[FILTER_STACK_LEN];
71};
72
73static inline
74void vstack_init(struct vstack *stack)
75{
76 stack->top = -1;
77}
78
79static inline
80struct vstack_entry *vstack_ax(struct vstack *stack)
81{
82 if (unlikely(stack->top < 0))
83 return NULL;
84 return &stack->e[stack->top];
85}
86
87static inline
88struct vstack_entry *vstack_bx(struct vstack *stack)
89{
90 if (unlikely(stack->top < 1))
91 return NULL;
92 return &stack->e[stack->top - 1];
93}
94
95static inline
96int vstack_push(struct vstack *stack)
97{
98 if (stack->top >= FILTER_STACK_LEN - 1) {
99 printk(KERN_WARNING "Stack full\n");
100 return -EINVAL;
101 }
102 ++stack->top;
103 return 0;
104}
105
106static inline
107int vstack_pop(struct vstack *stack)
108{
109 if (unlikely(stack->top < 0)) {
110 printk(KERN_WARNING "Stack empty\n");
111 return -EINVAL;
112 }
113 stack->top--;
114 return 0;
115}
116
117/* Execution stack */
118struct estack_entry {
119 union {
120 int64_t v;
121
122 struct {
123 const char *str;
f127e61e 124 const char __user *user_str;
07dfc1d0
MD
125 size_t seq_len;
126 int literal; /* is string literal ? */
f127e61e 127 int user; /* is string from userspace ? */
07dfc1d0
MD
128 } s;
129 } u;
130};
131
132struct estack {
133 int top; /* top of stack */
134 struct estack_entry e[FILTER_STACK_LEN];
135};
136
137#define estack_ax_v ax
138#define estack_bx_v bx
139
140#define estack_ax(stack, top) \
141 ({ \
9272c0cd 142 BUG_ON((top) <= FILTER_STACK_EMPTY); \
07dfc1d0
MD
143 &(stack)->e[top]; \
144 })
145
146#define estack_bx(stack, top) \
147 ({ \
9272c0cd 148 BUG_ON((top) <= FILTER_STACK_EMPTY + 1); \
07dfc1d0
MD
149 &(stack)->e[(top) - 1]; \
150 })
151
152#define estack_push(stack, top, ax, bx) \
153 do { \
9272c0cd 154 BUG_ON((top) >= FILTER_STACK_LEN - 1); \
07dfc1d0
MD
155 (stack)->e[(top) - 1].u.v = (bx); \
156 (bx) = (ax); \
157 ++(top); \
158 } while (0)
159
160#define estack_pop(stack, top, ax, bx) \
161 do { \
9272c0cd 162 BUG_ON((top) <= FILTER_STACK_EMPTY); \
07dfc1d0
MD
163 (ax) = (bx); \
164 (bx) = (stack)->e[(top) - 2].u.v; \
165 (top)--; \
166 } while (0)
167
168const char *lttng_filter_print_op(enum filter_op op);
169
170int lttng_filter_validate_bytecode(struct bytecode_runtime *bytecode);
171int lttng_filter_specialize_bytecode(struct bytecode_runtime *bytecode);
172
173uint64_t lttng_filter_false(void *filter_data,
174 const char *filter_stack_data);
175uint64_t lttng_filter_interpret_bytecode(void *filter_data,
176 const char *filter_stack_data);
177
178#endif /* _LTTNG_FILTER_H */
This page took 0.029095 seconds and 4 git commands to generate.