| 1 | #ifndef _LTTNG_FILTER_H |
| 2 | #define _LTTNG_FILTER_H |
| 3 | |
| 4 | /* |
| 5 | * lttng-filter.h |
| 6 | * |
| 7 | * LTTng UST filter header. |
| 8 | * |
| 9 | * Copyright (C) 2010-2012 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 <errno.h> |
| 27 | #include <stdio.h> |
| 28 | #include <helper.h> |
| 29 | #include <lttng/ust-events.h> |
| 30 | #include <stdint.h> |
| 31 | #include <errno.h> |
| 32 | #include <string.h> |
| 33 | #include <inttypes.h> |
| 34 | #include <limits.h> |
| 35 | #include <usterr-signal-safe.h> |
| 36 | #include "filter-bytecode.h" |
| 37 | |
| 38 | #define NR_REG 2 |
| 39 | |
| 40 | #ifndef min_t |
| 41 | #define min_t(type, a, b) \ |
| 42 | ((type) (a) < (type) (b) ? (type) (a) : (type) (b)) |
| 43 | #endif |
| 44 | |
| 45 | #ifndef likely |
| 46 | #define likely(x) __builtin_expect(!!(x), 1) |
| 47 | #endif |
| 48 | |
| 49 | #ifndef unlikely |
| 50 | #define unlikely(x) __builtin_expect(!!(x), 0) |
| 51 | #endif |
| 52 | |
| 53 | #ifdef DEBUG |
| 54 | #define dbg_printf(fmt, args...) printf("[debug bytecode] " fmt, ## args) |
| 55 | #else |
| 56 | #define dbg_printf(fmt, args...) \ |
| 57 | do { \ |
| 58 | /* do nothing but check printf format */ \ |
| 59 | if (0) \ |
| 60 | printf("[debug bytecode] " fmt, ## args); \ |
| 61 | } while (0) |
| 62 | #endif |
| 63 | |
| 64 | /* Linked bytecode */ |
| 65 | struct bytecode_runtime { |
| 66 | uint16_t len; |
| 67 | char data[0]; |
| 68 | }; |
| 69 | |
| 70 | enum reg_type { |
| 71 | REG_S64, |
| 72 | REG_DOUBLE, |
| 73 | REG_STRING, |
| 74 | REG_TYPE_UNKNOWN, |
| 75 | }; |
| 76 | |
| 77 | /* Validation registers */ |
| 78 | struct vreg { |
| 79 | enum reg_type type; |
| 80 | int literal; /* is string literal ? */ |
| 81 | }; |
| 82 | |
| 83 | /* Execution registers */ |
| 84 | struct reg { |
| 85 | enum reg_type type; |
| 86 | int64_t v; |
| 87 | double d; |
| 88 | |
| 89 | const char *str; |
| 90 | size_t seq_len; |
| 91 | int literal; /* is string literal ? */ |
| 92 | }; |
| 93 | |
| 94 | const char *print_op(enum filter_op op); |
| 95 | |
| 96 | int lttng_filter_validate_bytecode(struct bytecode_runtime *bytecode); |
| 97 | int lttng_filter_specialize_bytecode(struct bytecode_runtime *bytecode); |
| 98 | |
| 99 | int lttng_filter_false(void *filter_data, |
| 100 | const char *filter_stack_data); |
| 101 | int lttng_filter_interpret_bytecode(void *filter_data, |
| 102 | const char *filter_stack_data); |
| 103 | |
| 104 | #endif /* _LTTNG_FILTER_H */ |