| 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 | struct field_ref { |
| 32 | /* Initially, symbol offset. After link, field offset. */ |
| 33 | uint16_t offset; |
| 34 | } __attribute__((packed)); |
| 35 | |
| 36 | struct literal_numeric { |
| 37 | int64_t v; |
| 38 | } __attribute__((packed)); |
| 39 | |
| 40 | struct literal_double { |
| 41 | double v; |
| 42 | } __attribute__((packed)); |
| 43 | |
| 44 | struct literal_string { |
| 45 | char string[0]; |
| 46 | } __attribute__((packed)); |
| 47 | |
| 48 | enum filter_op { |
| 49 | FILTER_OP_UNKNOWN = 0, |
| 50 | |
| 51 | FILTER_OP_RETURN, |
| 52 | |
| 53 | /* binary */ |
| 54 | FILTER_OP_MUL, |
| 55 | FILTER_OP_DIV, |
| 56 | FILTER_OP_MOD, |
| 57 | FILTER_OP_PLUS, |
| 58 | FILTER_OP_MINUS, |
| 59 | FILTER_OP_RSHIFT, |
| 60 | FILTER_OP_LSHIFT, |
| 61 | FILTER_OP_BIN_AND, |
| 62 | FILTER_OP_BIN_OR, |
| 63 | FILTER_OP_BIN_XOR, |
| 64 | |
| 65 | /* binary comparators */ |
| 66 | FILTER_OP_EQ, |
| 67 | FILTER_OP_NE, |
| 68 | FILTER_OP_GT, |
| 69 | FILTER_OP_LT, |
| 70 | FILTER_OP_GE, |
| 71 | FILTER_OP_LE, |
| 72 | |
| 73 | /* string binary comparator */ |
| 74 | FILTER_OP_EQ_STRING, |
| 75 | FILTER_OP_NE_STRING, |
| 76 | FILTER_OP_GT_STRING, |
| 77 | FILTER_OP_LT_STRING, |
| 78 | FILTER_OP_GE_STRING, |
| 79 | FILTER_OP_LE_STRING, |
| 80 | |
| 81 | /* s64 binary comparator */ |
| 82 | FILTER_OP_EQ_S64, |
| 83 | FILTER_OP_NE_S64, |
| 84 | FILTER_OP_GT_S64, |
| 85 | FILTER_OP_LT_S64, |
| 86 | FILTER_OP_GE_S64, |
| 87 | FILTER_OP_LE_S64, |
| 88 | |
| 89 | /* double binary comparator */ |
| 90 | FILTER_OP_EQ_DOUBLE, |
| 91 | FILTER_OP_NE_DOUBLE, |
| 92 | FILTER_OP_GT_DOUBLE, |
| 93 | FILTER_OP_LT_DOUBLE, |
| 94 | FILTER_OP_GE_DOUBLE, |
| 95 | FILTER_OP_LE_DOUBLE, |
| 96 | |
| 97 | /* Mixed S64-double binary comparators */ |
| 98 | FILTER_OP_EQ_DOUBLE_S64, |
| 99 | FILTER_OP_NE_DOUBLE_S64, |
| 100 | FILTER_OP_GT_DOUBLE_S64, |
| 101 | FILTER_OP_LT_DOUBLE_S64, |
| 102 | FILTER_OP_GE_DOUBLE_S64, |
| 103 | FILTER_OP_LE_DOUBLE_S64, |
| 104 | |
| 105 | FILTER_OP_EQ_S64_DOUBLE, |
| 106 | FILTER_OP_NE_S64_DOUBLE, |
| 107 | FILTER_OP_GT_S64_DOUBLE, |
| 108 | FILTER_OP_LT_S64_DOUBLE, |
| 109 | FILTER_OP_GE_S64_DOUBLE, |
| 110 | FILTER_OP_LE_S64_DOUBLE, |
| 111 | |
| 112 | /* unary */ |
| 113 | FILTER_OP_UNARY_PLUS, |
| 114 | FILTER_OP_UNARY_MINUS, |
| 115 | FILTER_OP_UNARY_NOT, |
| 116 | FILTER_OP_UNARY_PLUS_S64, |
| 117 | FILTER_OP_UNARY_MINUS_S64, |
| 118 | FILTER_OP_UNARY_NOT_S64, |
| 119 | FILTER_OP_UNARY_PLUS_DOUBLE, |
| 120 | FILTER_OP_UNARY_MINUS_DOUBLE, |
| 121 | FILTER_OP_UNARY_NOT_DOUBLE, |
| 122 | |
| 123 | /* logical */ |
| 124 | FILTER_OP_AND, |
| 125 | FILTER_OP_OR, |
| 126 | |
| 127 | /* load field ref */ |
| 128 | FILTER_OP_LOAD_FIELD_REF, |
| 129 | FILTER_OP_LOAD_FIELD_REF_STRING, |
| 130 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE, |
| 131 | FILTER_OP_LOAD_FIELD_REF_S64, |
| 132 | FILTER_OP_LOAD_FIELD_REF_DOUBLE, |
| 133 | |
| 134 | /* load immediate from operand */ |
| 135 | FILTER_OP_LOAD_STRING, |
| 136 | FILTER_OP_LOAD_S64, |
| 137 | FILTER_OP_LOAD_DOUBLE, |
| 138 | |
| 139 | /* cast */ |
| 140 | FILTER_OP_CAST_TO_S64, |
| 141 | FILTER_OP_CAST_DOUBLE_TO_S64, |
| 142 | FILTER_OP_CAST_NOP, |
| 143 | |
| 144 | /* get context ref */ |
| 145 | FILTER_OP_GET_CONTEXT_REF, |
| 146 | FILTER_OP_GET_CONTEXT_REF_STRING, |
| 147 | FILTER_OP_GET_CONTEXT_REF_S64, |
| 148 | FILTER_OP_GET_CONTEXT_REF_DOUBLE, |
| 149 | |
| 150 | NR_FILTER_OPS, |
| 151 | }; |
| 152 | |
| 153 | typedef uint8_t filter_opcode_t; |
| 154 | |
| 155 | struct load_op { |
| 156 | filter_opcode_t op; |
| 157 | char data[0]; |
| 158 | /* data to load. Size known by enum filter_opcode and null-term char. */ |
| 159 | } __attribute__((packed)); |
| 160 | |
| 161 | struct binary_op { |
| 162 | filter_opcode_t op; |
| 163 | } __attribute__((packed)); |
| 164 | |
| 165 | struct unary_op { |
| 166 | filter_opcode_t op; |
| 167 | } __attribute__((packed)); |
| 168 | |
| 169 | /* skip_offset is absolute from start of bytecode */ |
| 170 | struct logical_op { |
| 171 | filter_opcode_t op; |
| 172 | uint16_t skip_offset; /* bytecode insn, if skip second test */ |
| 173 | } __attribute__((packed)); |
| 174 | |
| 175 | struct cast_op { |
| 176 | filter_opcode_t op; |
| 177 | } __attribute__((packed)); |
| 178 | |
| 179 | struct return_op { |
| 180 | filter_opcode_t op; |
| 181 | } __attribute__((packed)); |
| 182 | |
| 183 | #endif /* _FILTER_BYTECODE_H */ |