| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _LTTNG_UST_EVENTS_INTERNAL_H |
| 8 | #define _LTTNG_UST_EVENTS_INTERNAL_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include <urcu/list.h> |
| 13 | #include <urcu/hlist.h> |
| 14 | |
| 15 | #include <ust-helper.h> |
| 16 | #include <lttng/ust-events.h> |
| 17 | |
| 18 | struct lttng_event_enabler { |
| 19 | struct lttng_enabler base; |
| 20 | struct cds_list_head node; /* per-session list of enablers */ |
| 21 | struct lttng_channel *chan; |
| 22 | /* |
| 23 | * Unused, but kept around to make it explicit that the tracer can do |
| 24 | * it. |
| 25 | */ |
| 26 | struct lttng_ctx *ctx; |
| 27 | }; |
| 28 | |
| 29 | struct lttng_event_notifier_enabler { |
| 30 | struct lttng_enabler base; |
| 31 | uint64_t error_counter_index; |
| 32 | struct cds_list_head node; /* per-app list of event_notifier enablers */ |
| 33 | struct cds_list_head capture_bytecode_head; |
| 34 | struct lttng_event_notifier_group *group; /* weak ref */ |
| 35 | uint64_t user_token; /* User-provided token */ |
| 36 | uint64_t num_captures; |
| 37 | }; |
| 38 | |
| 39 | enum lttng_ust_bytecode_node_type { |
| 40 | LTTNG_UST_BYTECODE_NODE_TYPE_FILTER, |
| 41 | LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE, |
| 42 | }; |
| 43 | |
| 44 | struct lttng_ust_bytecode_node { |
| 45 | enum lttng_ust_bytecode_node_type type; |
| 46 | struct cds_list_head node; |
| 47 | struct lttng_enabler *enabler; |
| 48 | struct { |
| 49 | uint32_t len; |
| 50 | uint32_t reloc_offset; |
| 51 | uint64_t seqnum; |
| 52 | char data[]; |
| 53 | } bc; |
| 54 | }; |
| 55 | |
| 56 | struct lttng_ust_excluder_node { |
| 57 | struct cds_list_head node; |
| 58 | struct lttng_enabler *enabler; |
| 59 | /* |
| 60 | * struct lttng_ust_event_exclusion had variable sized array, |
| 61 | * must be last field. |
| 62 | */ |
| 63 | struct lttng_ust_event_exclusion excluder; |
| 64 | }; |
| 65 | |
| 66 | static inline |
| 67 | struct lttng_enabler *lttng_event_enabler_as_enabler( |
| 68 | struct lttng_event_enabler *event_enabler) |
| 69 | { |
| 70 | return &event_enabler->base; |
| 71 | } |
| 72 | |
| 73 | static inline |
| 74 | struct lttng_enabler *lttng_event_notifier_enabler_as_enabler( |
| 75 | struct lttng_event_notifier_enabler *event_notifier_enabler) |
| 76 | { |
| 77 | return &event_notifier_enabler->base; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Allocate and initialize a `struct lttng_event_enabler` object. |
| 82 | * |
| 83 | * On success, returns a `struct lttng_event_enabler`, |
| 84 | * On memory error, returns NULL. |
| 85 | */ |
| 86 | LTTNG_HIDDEN |
| 87 | struct lttng_event_enabler *lttng_event_enabler_create( |
| 88 | enum lttng_enabler_format_type format_type, |
| 89 | struct lttng_ust_event *event_param, |
| 90 | struct lttng_channel *chan); |
| 91 | |
| 92 | /* |
| 93 | * Destroy a `struct lttng_event_enabler` object. |
| 94 | */ |
| 95 | LTTNG_HIDDEN |
| 96 | void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler); |
| 97 | |
| 98 | /* |
| 99 | * Enable a `struct lttng_event_enabler` object and all events related to this |
| 100 | * enabler. |
| 101 | */ |
| 102 | LTTNG_HIDDEN |
| 103 | int lttng_event_enabler_enable(struct lttng_event_enabler *enabler); |
| 104 | |
| 105 | /* |
| 106 | * Disable a `struct lttng_event_enabler` object and all events related to this |
| 107 | * enabler. |
| 108 | */ |
| 109 | LTTNG_HIDDEN |
| 110 | int lttng_event_enabler_disable(struct lttng_event_enabler *enabler); |
| 111 | |
| 112 | /* |
| 113 | * Attach filter bytecode program to `struct lttng_event_enabler` and all |
| 114 | * events related to this enabler. |
| 115 | */ |
| 116 | LTTNG_HIDDEN |
| 117 | int lttng_event_enabler_attach_filter_bytecode( |
| 118 | struct lttng_event_enabler *enabler, |
| 119 | struct lttng_ust_bytecode_node **bytecode); |
| 120 | |
| 121 | /* |
| 122 | * Attach an application context to an event enabler. |
| 123 | * |
| 124 | * Not implemented. |
| 125 | */ |
| 126 | LTTNG_HIDDEN |
| 127 | int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, |
| 128 | struct lttng_ust_context *ctx); |
| 129 | |
| 130 | /* |
| 131 | * Attach exclusion list to `struct lttng_event_enabler` and all |
| 132 | * events related to this enabler. |
| 133 | */ |
| 134 | LTTNG_HIDDEN |
| 135 | int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, |
| 136 | struct lttng_ust_excluder_node **excluder); |
| 137 | |
| 138 | /* |
| 139 | * Synchronize bytecodes for the enabler and the instance (event or |
| 140 | * event_notifier). |
| 141 | * |
| 142 | * This function goes over all bytecode programs of the enabler (event or |
| 143 | * event_notifier enabler) to ensure each is linked to the provided instance. |
| 144 | */ |
| 145 | LTTNG_HIDDEN |
| 146 | void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, |
| 147 | struct lttng_ctx **ctx, |
| 148 | struct cds_list_head *instance_bytecode_runtime_head, |
| 149 | struct cds_list_head *enabler_bytecode_runtime_head); |
| 150 | |
| 151 | /* |
| 152 | * Allocate and initialize a `struct lttng_event_notifier_group` object. |
| 153 | * |
| 154 | * On success, returns a `struct lttng_triggre_group`, |
| 155 | * on memory error, returns NULL. |
| 156 | */ |
| 157 | LTTNG_HIDDEN |
| 158 | struct lttng_event_notifier_group *lttng_event_notifier_group_create(void); |
| 159 | |
| 160 | /* |
| 161 | * Destroy a `struct lttng_event_notifier_group` object. |
| 162 | */ |
| 163 | LTTNG_HIDDEN |
| 164 | void lttng_event_notifier_group_destroy( |
| 165 | struct lttng_event_notifier_group *event_notifier_group); |
| 166 | |
| 167 | /* |
| 168 | * Allocate and initialize a `struct lttng_event_notifier_enabler` object. |
| 169 | * |
| 170 | * On success, returns a `struct lttng_event_notifier_enabler`, |
| 171 | * On memory error, returns NULL. |
| 172 | */ |
| 173 | LTTNG_HIDDEN |
| 174 | struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( |
| 175 | struct lttng_event_notifier_group *event_notifier_group, |
| 176 | enum lttng_enabler_format_type format_type, |
| 177 | struct lttng_ust_event_notifier *event_notifier_param); |
| 178 | |
| 179 | /* |
| 180 | * Destroy a `struct lttng_event_notifier_enabler` object. |
| 181 | */ |
| 182 | LTTNG_HIDDEN |
| 183 | void lttng_event_notifier_enabler_destroy( |
| 184 | struct lttng_event_notifier_enabler *event_notifier_enabler); |
| 185 | |
| 186 | /* |
| 187 | * Enable a `struct lttng_event_notifier_enabler` object and all event |
| 188 | * notifiers related to this enabler. |
| 189 | */ |
| 190 | LTTNG_HIDDEN |
| 191 | int lttng_event_notifier_enabler_enable( |
| 192 | struct lttng_event_notifier_enabler *event_notifier_enabler); |
| 193 | |
| 194 | /* |
| 195 | * Disable a `struct lttng_event_notifier_enabler` object and all event |
| 196 | * notifiers related to this enabler. |
| 197 | */ |
| 198 | LTTNG_HIDDEN |
| 199 | int lttng_event_notifier_enabler_disable( |
| 200 | struct lttng_event_notifier_enabler *event_notifier_enabler); |
| 201 | |
| 202 | /* |
| 203 | * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and |
| 204 | * all event notifiers related to this enabler. |
| 205 | */ |
| 206 | LTTNG_HIDDEN |
| 207 | int lttng_event_notifier_enabler_attach_filter_bytecode( |
| 208 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 209 | struct lttng_ust_bytecode_node **bytecode); |
| 210 | |
| 211 | /* |
| 212 | * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and |
| 213 | * all event_notifiers related to this enabler. |
| 214 | */ |
| 215 | LTTNG_HIDDEN |
| 216 | int lttng_event_notifier_enabler_attach_capture_bytecode( |
| 217 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 218 | struct lttng_ust_bytecode_node **bytecode); |
| 219 | |
| 220 | /* |
| 221 | * Attach exclusion list to `struct lttng_event_notifier_enabler` and all |
| 222 | * event notifiers related to this enabler. |
| 223 | */ |
| 224 | LTTNG_HIDDEN |
| 225 | int lttng_event_notifier_enabler_attach_exclusion( |
| 226 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
| 227 | struct lttng_ust_excluder_node **excluder); |
| 228 | |
| 229 | LTTNG_HIDDEN |
| 230 | void lttng_free_event_notifier_filter_runtime( |
| 231 | struct lttng_event_notifier *event_notifier); |
| 232 | |
| 233 | /* |
| 234 | * Connect the probe on all enablers matching this event description. |
| 235 | * Called on library load. |
| 236 | */ |
| 237 | LTTNG_HIDDEN |
| 238 | int lttng_fix_pending_event_notifiers(void); |
| 239 | |
| 240 | LTTNG_HIDDEN |
| 241 | struct lttng_counter *lttng_ust_counter_create( |
| 242 | const char *counter_transport_name, |
| 243 | size_t number_dimensions, const struct lttng_counter_dimension *dimensions); |
| 244 | |
| 245 | #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */ |