Commit | Line | Data |
---|---|---|
953192ba MD |
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 "filter-ast.h" | |
53a80697 | 26 | #include "../../common/sessiond-comm/sessiond-comm.h" |
953192ba MD |
27 | |
28 | /* | |
29 | * offsets are absolute from start of bytecode. | |
30 | */ | |
31 | ||
32 | enum filter_register { | |
33 | REG_R0 = 0, | |
34 | REG_R1 = 1, | |
35 | REG_ERROR, | |
36 | }; | |
37 | ||
953192ba MD |
38 | struct field_ref { |
39 | /* Initially, symbol offset. After link, field offset. */ | |
40 | uint16_t offset; | |
953192ba MD |
41 | } __attribute__((packed)); |
42 | ||
43 | struct literal_numeric { | |
44 | int64_t v; | |
45 | } __attribute__((packed)); | |
46 | ||
e90d8561 MD |
47 | struct literal_double { |
48 | double v; | |
49 | } __attribute__((packed)); | |
50 | ||
953192ba MD |
51 | struct literal_string { |
52 | char string[0]; | |
53 | } __attribute__((packed)); | |
54 | ||
55 | enum filter_op { | |
56 | FILTER_OP_UNKNOWN = 0, | |
57 | ||
58 | FILTER_OP_RETURN, | |
59 | ||
60 | /* binary */ | |
61 | FILTER_OP_MUL, | |
62 | FILTER_OP_DIV, | |
63 | FILTER_OP_MOD, | |
64 | FILTER_OP_PLUS, | |
65 | FILTER_OP_MINUS, | |
66 | FILTER_OP_RSHIFT, | |
67 | FILTER_OP_LSHIFT, | |
68 | FILTER_OP_BIN_AND, | |
69 | FILTER_OP_BIN_OR, | |
70 | FILTER_OP_BIN_XOR, | |
71 | FILTER_OP_EQ, | |
72 | FILTER_OP_NE, | |
73 | FILTER_OP_GT, | |
74 | FILTER_OP_LT, | |
75 | FILTER_OP_GE, | |
76 | FILTER_OP_LE, | |
77 | ||
78 | /* unary */ | |
79 | FILTER_OP_UNARY_PLUS, | |
80 | FILTER_OP_UNARY_MINUS, | |
81 | FILTER_OP_UNARY_NOT, | |
82 | ||
83 | /* logical */ | |
84 | FILTER_OP_AND, | |
85 | FILTER_OP_OR, | |
86 | ||
87 | /* load */ | |
88 | FILTER_OP_LOAD_FIELD_REF, | |
65775683 MD |
89 | FILTER_OP_LOAD_FIELD_REF_STRING, |
90 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE, | |
91 | FILTER_OP_LOAD_FIELD_REF_S64, | |
92 | FILTER_OP_LOAD_FIELD_REF_DOUBLE, | |
93 | ||
953192ba MD |
94 | FILTER_OP_LOAD_STRING, |
95 | FILTER_OP_LOAD_S64, | |
e90d8561 | 96 | FILTER_OP_LOAD_DOUBLE, |
953192ba MD |
97 | |
98 | NR_FILTER_OPS, | |
99 | }; | |
100 | ||
101 | typedef uint8_t filter_opcode_t; | |
102 | ||
103 | struct load_op { | |
104 | filter_opcode_t op; | |
105 | uint8_t reg; /* enum filter_register */ | |
106 | char data[0]; | |
107 | /* data to load. Size known by enum filter_opcode and null-term char. */ | |
108 | } __attribute__((packed)); | |
109 | ||
110 | struct binary_op { | |
111 | filter_opcode_t op; | |
112 | } __attribute__((packed)); | |
113 | ||
114 | struct unary_op { | |
115 | filter_opcode_t op; | |
116 | uint8_t reg; /* enum filter_register */ | |
117 | } __attribute__((packed)); | |
118 | ||
119 | /* skip_offset is absolute from start of bytecode */ | |
120 | struct logical_op { | |
121 | filter_opcode_t op; | |
122 | uint16_t skip_offset; /* bytecode insn, if skip second test */ | |
123 | } __attribute__((packed)); | |
124 | ||
125 | struct return_op { | |
126 | filter_opcode_t op; | |
127 | } __attribute__((packed)); | |
128 | ||
53a80697 | 129 | struct lttng_filter_bytecode_alloc { |
953192ba | 130 | uint16_t alloc_len; |
53a80697 | 131 | struct lttng_filter_bytecode b; |
953192ba MD |
132 | }; |
133 | ||
134 | static inline | |
53a80697 | 135 | unsigned int bytecode_get_len(struct lttng_filter_bytecode *bytecode) |
953192ba MD |
136 | { |
137 | return bytecode->len; | |
138 | } | |
139 | ||
140 | #endif /* _FILTER_BYTECODE_H */ |