| 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 | struct field_ref { |
| 38 | /* Initially, symbol offset. After link, field offset. */ |
| 39 | uint16_t offset; |
| 40 | } __attribute__((packed)); |
| 41 | |
| 42 | struct literal_numeric { |
| 43 | int64_t v; |
| 44 | } __attribute__((packed)); |
| 45 | |
| 46 | struct literal_double { |
| 47 | double v; |
| 48 | } __attribute__((packed)); |
| 49 | |
| 50 | struct literal_string { |
| 51 | char string[0]; |
| 52 | } __attribute__((packed)); |
| 53 | |
| 54 | enum filter_op { |
| 55 | FILTER_OP_UNKNOWN = 0, |
| 56 | |
| 57 | FILTER_OP_RETURN, |
| 58 | |
| 59 | /* binary */ |
| 60 | FILTER_OP_MUL, |
| 61 | FILTER_OP_DIV, |
| 62 | FILTER_OP_MOD, |
| 63 | FILTER_OP_PLUS, |
| 64 | FILTER_OP_MINUS, |
| 65 | FILTER_OP_RSHIFT, |
| 66 | FILTER_OP_LSHIFT, |
| 67 | FILTER_OP_BIN_AND, |
| 68 | FILTER_OP_BIN_OR, |
| 69 | FILTER_OP_BIN_XOR, |
| 70 | FILTER_OP_EQ, |
| 71 | FILTER_OP_NE, |
| 72 | FILTER_OP_GT, |
| 73 | FILTER_OP_LT, |
| 74 | FILTER_OP_GE, |
| 75 | FILTER_OP_LE, |
| 76 | |
| 77 | /* unary */ |
| 78 | FILTER_OP_UNARY_PLUS, |
| 79 | FILTER_OP_UNARY_MINUS, |
| 80 | FILTER_OP_UNARY_NOT, |
| 81 | FILTER_OP_UNARY_PLUS_S64, |
| 82 | FILTER_OP_UNARY_MINUS_S64, |
| 83 | FILTER_OP_UNARY_NOT_S64, |
| 84 | FILTER_OP_UNARY_PLUS_DOUBLE, |
| 85 | FILTER_OP_UNARY_MINUS_DOUBLE, |
| 86 | FILTER_OP_UNARY_NOT_DOUBLE, |
| 87 | |
| 88 | /* logical */ |
| 89 | FILTER_OP_AND, |
| 90 | FILTER_OP_OR, |
| 91 | |
| 92 | /* load */ |
| 93 | FILTER_OP_LOAD_FIELD_REF, |
| 94 | FILTER_OP_LOAD_FIELD_REF_STRING, |
| 95 | FILTER_OP_LOAD_FIELD_REF_SEQUENCE, |
| 96 | FILTER_OP_LOAD_FIELD_REF_S64, |
| 97 | FILTER_OP_LOAD_FIELD_REF_DOUBLE, |
| 98 | |
| 99 | FILTER_OP_LOAD_STRING, |
| 100 | FILTER_OP_LOAD_S64, |
| 101 | FILTER_OP_LOAD_DOUBLE, |
| 102 | |
| 103 | NR_FILTER_OPS, |
| 104 | }; |
| 105 | |
| 106 | typedef uint8_t filter_opcode_t; |
| 107 | |
| 108 | struct load_op { |
| 109 | filter_opcode_t op; |
| 110 | uint8_t reg; /* enum filter_register */ |
| 111 | char data[0]; |
| 112 | /* data to load. Size known by enum filter_opcode and null-term char. */ |
| 113 | } __attribute__((packed)); |
| 114 | |
| 115 | struct binary_op { |
| 116 | filter_opcode_t op; |
| 117 | } __attribute__((packed)); |
| 118 | |
| 119 | struct unary_op { |
| 120 | filter_opcode_t op; |
| 121 | uint8_t reg; /* enum filter_register */ |
| 122 | } __attribute__((packed)); |
| 123 | |
| 124 | /* skip_offset is absolute from start of bytecode */ |
| 125 | struct logical_op { |
| 126 | filter_opcode_t op; |
| 127 | uint16_t skip_offset; /* bytecode insn, if skip second test */ |
| 128 | } __attribute__((packed)); |
| 129 | |
| 130 | struct return_op { |
| 131 | filter_opcode_t op; |
| 132 | } __attribute__((packed)); |
| 133 | |
| 134 | #endif /* _FILTER_BYTECODE_H */ |