| 1 | #ifndef _LTTNG_UST_EVENTS_INTERNAL_H |
| 2 | #define _LTTNG_UST_EVENTS_INTERNAL_H |
| 3 | |
| 4 | /* |
| 5 | * ust-events-internal.h |
| 6 | * |
| 7 | * Copyright 2019 (c) - Francis Deslauriers <francis.deslauriers@efficios.com> |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | * of this software and associated documentation files (the "Software"), to deal |
| 11 | * in the Software without restriction, including without limitation the rights |
| 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | * copies of the Software, and to permit persons to whom the Software is |
| 14 | * furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in |
| 17 | * all copies or substantial portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | * SOFTWARE. |
| 26 | */ |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | #include <urcu/list.h> |
| 31 | #include <urcu/hlist.h> |
| 32 | |
| 33 | #include <helper.h> |
| 34 | #include <lttng/ust-events.h> |
| 35 | |
| 36 | struct lttng_event_enabler { |
| 37 | struct lttng_enabler base; |
| 38 | struct cds_list_head node; /* per-session list of enablers */ |
| 39 | struct lttng_channel *chan; |
| 40 | /* |
| 41 | * Unused, but kept around to make it explicit that the tracer can do |
| 42 | * it. |
| 43 | */ |
| 44 | struct lttng_ctx *ctx; |
| 45 | }; |
| 46 | |
| 47 | struct lttng_event_notifier_enabler { |
| 48 | struct lttng_enabler base; |
| 49 | uint64_t error_counter_index; |
| 50 | struct cds_list_head node; /* per-app list of event_notifier enablers */ |
| 51 | struct cds_list_head capture_bytecode_head; |
| 52 | struct lttng_event_notifier_group *group; /* weak ref */ |
| 53 | uint64_t user_token; /* User-provided token */ |
| 54 | uint64_t num_captures; |
| 55 | }; |
| 56 | |
| 57 | enum lttng_ust_bytecode_node_type { |
| 58 | LTTNG_UST_BYTECODE_NODE_TYPE_FILTER, |
| 59 | LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE, |
| 60 | }; |
| 61 | |
| 62 | struct lttng_ust_bytecode_node { |
| 63 | enum lttng_ust_bytecode_node_type type; |
| 64 | struct cds_list_head node; |
| 65 | struct lttng_enabler *enabler; |
| 66 | struct { |
| 67 | uint32_t len; |
| 68 | uint32_t reloc_offset; |
| 69 | uint64_t seqnum; |
| 70 | char data[]; |
| 71 | } bc; |
| 72 | }; |
| 73 | |
| 74 | struct lttng_ust_excluder_node { |
| 75 | struct cds_list_head node; |
| 76 | struct lttng_enabler *enabler; |
| 77 | /* |
| 78 | * struct lttng_ust_event_exclusion had variable sized array, |
| 79 | * must be last field. |
| 80 | */ |
| 81 | struct lttng_ust_event_exclusion excluder; |
| 82 | }; |
| 83 | |
| 84 | static inline |
| 85 | struct lttng_enabler *lttng_event_enabler_as_enabler( |
| 86 | struct lttng_event_enabler *event_enabler) |
| 87 | { |
| 88 | return &event_enabler->base; |
| 89 | } |
| 90 | |
| 91 | static inline |
| 92 | struct lttng_enabler *lttng_event_notifier_enabler_as_enabler( |
| 93 | struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 94 | { |
| 95 | return &event_notifier_enabler->base; |
| 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Allocate and initialize a `struct lttng_event_enabler` object. |
| 100 | * |
| 101 | * On success, returns a `struct lttng_event_enabler`, |
| 102 | * On memory error, returns NULL. |
| 103 | */ |
| 104 | LTTNG_HIDDEN |
| 105 | struct lttng_event_enabler *lttng_event_enabler_create( |
| 106 | enum lttng_enabler_format_type format_type, |
| 107 | struct lttng_ust_event *event_param, |
| 108 | struct lttng_channel *chan); |
| 109 | |
| 110 | /* |
| 111 | * Destroy a `struct lttng_event_enabler` object. |
| 112 | */ |
| 113 | LTTNG_HIDDEN |
| 114 | void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler); |
| 115 | |
| 116 | /* |
| 117 | * Enable a `struct lttng_event_enabler` object and all events related to this |
| 118 | * enabler. |
| 119 | */ |
| 120 | LTTNG_HIDDEN |
| 121 | int lttng_event_enabler_enable(struct lttng_event_enabler *enabler); |
| 122 | |
| 123 | /* |
| 124 | * Disable a `struct lttng_event_enabler` object and all events related to this |
| 125 | * enabler. |
| 126 | */ |
| 127 | LTTNG_HIDDEN |
| 128 | int lttng_event_enabler_disable(struct lttng_event_enabler *enabler); |
| 129 | |
| 130 | /* |
| 131 | * Attach filter bytecode program to `struct lttng_event_enabler` and all |
| 132 | * events related to this enabler. |
| 133 | */ |
| 134 | LTTNG_HIDDEN |
| 135 | int lttng_event_enabler_attach_filter_bytecode( |
| 136 | struct lttng_event_enabler *enabler, |
| 137 | struct lttng_ust_bytecode_node *bytecode); |
| 138 | |
| 139 | /* |
| 140 | * Attach an application context to an event enabler. |
| 141 | * |
| 142 | * Not implemented. |
| 143 | */ |
| 144 | LTTNG_HIDDEN |
| 145 | int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, |
| 146 | struct lttng_ust_context *ctx); |
| 147 | |
| 148 | /* |
| 149 | * Attach exclusion list to `struct lttng_event_enabler` and all |
| 150 | * events related to this enabler. |
| 151 | */ |
| 152 | LTTNG_HIDDEN |
| 153 | int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, |
| 154 | struct lttng_ust_excluder_node *excluder); |
| 155 | |
| 156 | /* |
| 157 | * Synchronize bytecodes for the enabler and the instance (event or |
| 158 | * event_notifier). |
| 159 | * |
| 160 | * This function goes over all bytecode programs of the enabler (event or |
| 161 | * event_notifier enabler) to ensure each is linked to the provided instance. |
| 162 | */ |
| 163 | LTTNG_HIDDEN |
| 164 | void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, |
| 165 | struct lttng_ctx **ctx, |
| 166 | struct cds_list_head *instance_bytecode_runtime_head, |
| 167 | struct cds_list_head *enabler_bytecode_runtime_head); |
| 168 | |
| 169 | /* |
| 170 | * Allocate and initialize a `struct lttng_event_notifier_group` object. |
| 171 | * |
| 172 | * On success, returns a `struct lttng_triggre_group`, |
| 173 | * on memory error, returns NULL. |
| 174 | */ |
| 175 | LTTNG_HIDDEN |
| 176 | struct lttng_event_notifier_group *lttng_event_notifier_group_create(void); |
| 177 | |
| 178 | /* |
| 179 | * Destroy a `struct lttng_event_notifier_group` object. |
| 180 | */ |
| 181 | LTTNG_HIDDEN |
| 182 | void lttng_event_notifier_group_destroy( |
| 183 | struct lttng_event_notifier_group *event_notifier_group); |
| 184 | |
| 185 | /* |
| 186 | * Allocate and initialize a `struct lttng_event_notifier_enabler` object. |
| 187 | * |
| 188 | * On success, returns a `struct lttng_event_notifier_enabler`, |
| 189 | * On memory error, returns NULL. |
| 190 | */ |
| 191 | LTTNG_HIDDEN |
| 192 | struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( |
| 193 | struct lttng_event_notifier_group *event_notifier_group, |
| 194 | enum lttng_enabler_format_type format_type, |
| 195 | struct lttng_ust_event_notifier *event_notifier_param); |
| 196 | |
| 197 | /* |
| 198 | * Destroy a `struct lttng_event_notifier_enabler` object. |
| 199 | */ |
| 200 | LTTNG_HIDDEN |
| 201 | void lttng_event_notifier_enabler_destroy( |
| 202 | struct lttng_event_notifier_enabler *event_notifier_enabler); |
| 203 | |
| 204 | /* |
| 205 | * Enable a `struct lttng_event_notifier_enabler` object and all event |
| 206 | * notifiers related to this enabler. |
| 207 | */ |
| 208 | LTTNG_HIDDEN |
| 209 | int lttng_event_notifier_enabler_enable( |
| 210 | struct lttng_event_notifier_enabler *event_notifier_enabler); |
| 211 | |
| 212 | /* |
| 213 | * Disable a `struct lttng_event_notifier_enabler` object and all event |
| 214 | * notifiers related to this enabler. |
| 215 | */ |
| 216 | LTTNG_HIDDEN |
| 217 | int lttng_event_notifier_enabler_disable( |
| 218 | struct lttng_event_notifier_enabler *event_notifier_enabler); |
| 219 | |
| 220 | /* |
| 221 | * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and |
| 222 | * all event notifiers related to this enabler. |
| 223 | */ |
| 224 | LTTNG_HIDDEN |
| 225 | int lttng_event_notifier_enabler_attach_filter_bytecode( |
| 226 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 227 | struct lttng_ust_bytecode_node *bytecode); |
| 228 | |
| 229 | /* |
| 230 | * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and |
| 231 | * all event_notifiers related to this enabler. |
| 232 | */ |
| 233 | LTTNG_HIDDEN |
| 234 | int lttng_event_notifier_enabler_attach_capture_bytecode( |
| 235 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 236 | struct lttng_ust_bytecode_node *bytecode); |
| 237 | |
| 238 | /* |
| 239 | * Attach exclusion list to `struct lttng_event_notifier_enabler` and all |
| 240 | * event notifiers related to this enabler. |
| 241 | */ |
| 242 | LTTNG_HIDDEN |
| 243 | int lttng_event_notifier_enabler_attach_exclusion( |
| 244 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 245 | struct lttng_ust_excluder_node *excluder); |
| 246 | |
| 247 | LTTNG_HIDDEN |
| 248 | void lttng_free_event_notifier_filter_runtime( |
| 249 | struct lttng_event_notifier *event_notifier); |
| 250 | |
| 251 | /* |
| 252 | * Connect the probe on all enablers matching this event description. |
| 253 | * Called on library load. |
| 254 | */ |
| 255 | LTTNG_HIDDEN |
| 256 | int lttng_fix_pending_event_notifiers(void); |
| 257 | |
| 258 | #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */ |