Implement filter bytecode interpreter and linker
[lttng-ust.git] / liblttng-ust / filter-bytecode.h
1 #ifndef _FILTER_BYTECODE_H
2 #define _FILTER_BYTECODE_H
3
4 /*
5 * filter-bytecode.h
6 *
7 * LTTng filter bytecode
8 *
9 * Copyright 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License, version 2.1 only,
13 * as published by the Free Software Foundation.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include <lttng/ust-abi.h>
26
27 /*
28 * offsets are absolute from start of bytecode.
29 */
30
31 enum filter_register {
32 REG_R0 = 0,
33 REG_R1 = 1,
34 REG_ERROR,
35 };
36
37 enum field_ref_type {
38 FIELD_REF_UNKNOWN = 0,
39 FIELD_REF_STRING,
40 FIELD_REF_SEQUENCE,
41 FIELD_REF_S64,
42 };
43
44 struct field_ref {
45 /* Initially, symbol offset. After link, field offset. */
46 uint16_t offset;
47 uint8_t type; /* enum field_ref_type */
48 } __attribute__((packed));
49
50 struct literal_numeric {
51 int64_t v;
52 } __attribute__((packed));
53
54 struct literal_string {
55 char string[0];
56 } __attribute__((packed));
57
58 enum filter_op {
59 FILTER_OP_UNKNOWN = 0,
60
61 FILTER_OP_RETURN,
62
63 /* binary */
64 FILTER_OP_MUL,
65 FILTER_OP_DIV,
66 FILTER_OP_MOD,
67 FILTER_OP_PLUS,
68 FILTER_OP_MINUS,
69 FILTER_OP_RSHIFT,
70 FILTER_OP_LSHIFT,
71 FILTER_OP_BIN_AND,
72 FILTER_OP_BIN_OR,
73 FILTER_OP_BIN_XOR,
74 FILTER_OP_EQ,
75 FILTER_OP_NE,
76 FILTER_OP_GT,
77 FILTER_OP_LT,
78 FILTER_OP_GE,
79 FILTER_OP_LE,
80
81 /* unary */
82 FILTER_OP_UNARY_PLUS,
83 FILTER_OP_UNARY_MINUS,
84 FILTER_OP_UNARY_NOT,
85
86 /* logical */
87 FILTER_OP_AND,
88 FILTER_OP_OR,
89
90 /* load */
91 FILTER_OP_LOAD_FIELD_REF,
92 FILTER_OP_LOAD_STRING,
93 FILTER_OP_LOAD_S64,
94
95 NR_FILTER_OPS,
96 };
97
98 typedef uint8_t filter_opcode_t;
99
100 struct load_op {
101 filter_opcode_t op;
102 uint8_t reg; /* enum filter_register */
103 char data[0];
104 /* data to load. Size known by enum filter_opcode and null-term char. */
105 } __attribute__((packed));
106
107 struct binary_op {
108 filter_opcode_t op;
109 } __attribute__((packed));
110
111 struct unary_op {
112 filter_opcode_t op;
113 uint8_t reg; /* enum filter_register */
114 } __attribute__((packed));
115
116 /* skip_offset is absolute from start of bytecode */
117 struct logical_op {
118 filter_opcode_t op;
119 uint16_t skip_offset; /* bytecode insn, if skip second test */
120 } __attribute__((packed));
121
122 struct return_op {
123 filter_opcode_t op;
124 } __attribute__((packed));
125
126 #endif /* _FILTER_BYTECODE_H */
This page took 0.031864 seconds and 5 git commands to generate.