| 1 | #ifndef _LTTNG_UST_COMM_H |
| 2 | #define _LTTNG_UST_COMM_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 6 | * Julien Desfossez <julien.desfossez@polymtl.ca> |
| 7 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Lesser General Public |
| 11 | * License as published by the Free Software Foundation; only |
| 12 | * version 2.1 of the License. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public |
| 20 | * License along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * This header is meant for liblttng and libust internal use ONLY. |
| 26 | * These declarations should NOT be considered stable API. |
| 27 | */ |
| 28 | |
| 29 | #include <limits.h> |
| 30 | #include <unistd.h> |
| 31 | #include <lttng/ust-abi.h> |
| 32 | #include <lttng/ust-error.h> |
| 33 | #include <lttng/ust-compiler.h> |
| 34 | #include <lttng/ust-ctl.h> |
| 35 | #include <config.h> |
| 36 | |
| 37 | #ifndef LTTNG_PACKED |
| 38 | #error "LTTNG_PACKED should be defined" |
| 39 | #endif |
| 40 | |
| 41 | /* |
| 42 | * Default timeout the application waits for the sessiond to send its |
| 43 | * "register done" command. Can be overridden with the environment |
| 44 | * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not |
| 45 | * found, the application proceeds directly without any delay. |
| 46 | */ |
| 47 | #define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS CONFIG_LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS |
| 48 | |
| 49 | #define LTTNG_DEFAULT_RUNDIR LTTNG_SYSTEM_RUNDIR |
| 50 | #define LTTNG_DEFAULT_HOME_RUNDIR ".lttng" |
| 51 | |
| 52 | /* Queue size of listen(2) */ |
| 53 | #define LTTNG_UST_COMM_MAX_LISTEN 10 |
| 54 | #define LTTNG_UST_COMM_REG_MSG_PADDING 64 |
| 55 | |
| 56 | struct lttng_event_field; |
| 57 | struct lttng_ctx_field; |
| 58 | struct lttng_enum_entry; |
| 59 | struct lttng_integer_type; |
| 60 | struct lttng_session; |
| 61 | |
| 62 | struct ustctl_reg_msg { |
| 63 | uint32_t magic; |
| 64 | uint32_t major; |
| 65 | uint32_t minor; |
| 66 | uint32_t pid; |
| 67 | uint32_t ppid; |
| 68 | uint32_t uid; |
| 69 | uint32_t gid; |
| 70 | uint32_t bits_per_long; |
| 71 | uint32_t uint8_t_alignment; |
| 72 | uint32_t uint16_t_alignment; |
| 73 | uint32_t uint32_t_alignment; |
| 74 | uint32_t uint64_t_alignment; |
| 75 | uint32_t long_alignment; |
| 76 | uint32_t socket_type; /* enum ustctl_socket_type */ |
| 77 | char name[LTTNG_UST_ABI_PROCNAME_LEN]; /* process name */ |
| 78 | char padding[LTTNG_UST_COMM_REG_MSG_PADDING]; |
| 79 | } LTTNG_PACKED; |
| 80 | |
| 81 | /* |
| 82 | * Data structure for the commands sent from sessiond to UST. |
| 83 | */ |
| 84 | #define USTCOMM_MSG_PADDING1 32 |
| 85 | #define USTCOMM_MSG_PADDING2 32 |
| 86 | struct ustcomm_ust_msg { |
| 87 | uint32_t handle; |
| 88 | uint32_t cmd; |
| 89 | char padding[USTCOMM_MSG_PADDING1]; |
| 90 | union { |
| 91 | struct lttng_ust_channel channel; |
| 92 | struct lttng_ust_stream stream; |
| 93 | struct lttng_ust_event event; |
| 94 | struct lttng_ust_context context; |
| 95 | struct lttng_ust_tracer_version version; |
| 96 | struct lttng_ust_tracepoint_iter tracepoint; |
| 97 | struct { |
| 98 | uint32_t data_size; /* following filter data */ |
| 99 | uint32_t reloc_offset; |
| 100 | uint64_t seqnum; |
| 101 | } LTTNG_PACKED filter; |
| 102 | struct { |
| 103 | uint32_t count; /* how many names follow */ |
| 104 | } LTTNG_PACKED exclusion; |
| 105 | char padding[USTCOMM_MSG_PADDING2]; |
| 106 | } u; |
| 107 | } LTTNG_PACKED; |
| 108 | |
| 109 | /* |
| 110 | * Data structure for the response from UST to the session daemon. |
| 111 | * cmd_type is sent back in the reply for validation. |
| 112 | */ |
| 113 | #define USTCOMM_REPLY_PADDING1 32 |
| 114 | #define USTCOMM_REPLY_PADDING2 32 |
| 115 | struct ustcomm_ust_reply { |
| 116 | uint32_t handle; |
| 117 | uint32_t cmd; |
| 118 | int32_t ret_code; /* enum ustcomm_return_code */ |
| 119 | uint32_t ret_val; /* return value */ |
| 120 | char padding[USTCOMM_REPLY_PADDING1]; |
| 121 | union { |
| 122 | struct { |
| 123 | uint64_t memory_map_size; |
| 124 | } LTTNG_PACKED channel; |
| 125 | struct { |
| 126 | uint64_t memory_map_size; |
| 127 | } LTTNG_PACKED stream; |
| 128 | struct lttng_ust_tracer_version version; |
| 129 | struct lttng_ust_tracepoint_iter tracepoint; |
| 130 | char padding[USTCOMM_REPLY_PADDING2]; |
| 131 | } u; |
| 132 | } LTTNG_PACKED; |
| 133 | |
| 134 | struct ustcomm_notify_hdr { |
| 135 | uint32_t notify_cmd; |
| 136 | } LTTNG_PACKED; |
| 137 | |
| 138 | #define USTCOMM_NOTIFY_EVENT_MSG_PADDING 32 |
| 139 | struct ustcomm_notify_event_msg { |
| 140 | uint32_t session_objd; |
| 141 | uint32_t channel_objd; |
| 142 | char event_name[LTTNG_UST_SYM_NAME_LEN]; |
| 143 | int32_t loglevel; |
| 144 | uint32_t signature_len; |
| 145 | uint32_t fields_len; |
| 146 | uint32_t model_emf_uri_len; |
| 147 | char padding[USTCOMM_NOTIFY_EVENT_MSG_PADDING]; |
| 148 | /* followed by signature, fields, and model_emf_uri */ |
| 149 | } LTTNG_PACKED; |
| 150 | |
| 151 | #define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32 |
| 152 | struct ustcomm_notify_event_reply { |
| 153 | int32_t ret_code; /* 0: ok, negative: error code */ |
| 154 | uint32_t event_id; |
| 155 | char padding[USTCOMM_NOTIFY_EVENT_REPLY_PADDING]; |
| 156 | } LTTNG_PACKED; |
| 157 | |
| 158 | #define USTCOMM_NOTIFY_ENUM_MSG_PADDING 32 |
| 159 | struct ustcomm_notify_enum_msg { |
| 160 | uint32_t session_objd; |
| 161 | char enum_name[LTTNG_UST_SYM_NAME_LEN]; |
| 162 | uint32_t entries_len; |
| 163 | char padding[USTCOMM_NOTIFY_ENUM_MSG_PADDING]; |
| 164 | /* followed by enum entries */ |
| 165 | } LTTNG_PACKED; |
| 166 | |
| 167 | #define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32 |
| 168 | struct ustcomm_notify_enum_reply { |
| 169 | int32_t ret_code; /* 0: ok, negative: error code */ |
| 170 | uint64_t enum_id; |
| 171 | char padding[USTCOMM_NOTIFY_EVENT_REPLY_PADDING]; |
| 172 | } LTTNG_PACKED; |
| 173 | |
| 174 | #define USTCOMM_NOTIFY_CHANNEL_MSG_PADDING 32 |
| 175 | struct ustcomm_notify_channel_msg { |
| 176 | uint32_t session_objd; |
| 177 | uint32_t channel_objd; |
| 178 | uint32_t ctx_fields_len; |
| 179 | char padding[USTCOMM_NOTIFY_CHANNEL_MSG_PADDING]; |
| 180 | /* followed by context fields */ |
| 181 | } LTTNG_PACKED; |
| 182 | |
| 183 | #define USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING 32 |
| 184 | struct ustcomm_notify_channel_reply { |
| 185 | int32_t ret_code; /* 0: ok, negative: error code */ |
| 186 | uint32_t chan_id; |
| 187 | uint32_t header_type; /* enum ustctl_channel_header */ |
| 188 | char padding[USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING]; |
| 189 | } LTTNG_PACKED; |
| 190 | |
| 191 | /* |
| 192 | * LTTNG_UST_TRACEPOINT_FIELD_LIST reply is followed by a |
| 193 | * struct lttng_ust_field_iter field. |
| 194 | */ |
| 195 | |
| 196 | extern int ustcomm_create_unix_sock(const char *pathname); |
| 197 | extern int ustcomm_connect_unix_sock(const char *pathname, |
| 198 | long timeout); |
| 199 | extern int ustcomm_accept_unix_sock(int sock); |
| 200 | extern int ustcomm_listen_unix_sock(int sock); |
| 201 | extern int ustcomm_close_unix_sock(int sock); |
| 202 | |
| 203 | extern ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len); |
| 204 | extern ssize_t ustcomm_send_unix_sock(int sock, const void *buf, size_t len); |
| 205 | extern ssize_t ustcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd); |
| 206 | extern ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd); |
| 207 | |
| 208 | extern const char *ustcomm_get_readable_code(int code); |
| 209 | extern int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum); |
| 210 | extern int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, |
| 211 | uint32_t expected_handle, uint32_t expected_cmd); |
| 212 | extern int ustcomm_send_app_cmd(int sock, |
| 213 | struct ustcomm_ust_msg *lum, |
| 214 | struct ustcomm_ust_reply *lur); |
| 215 | int ustcomm_recv_fd(int sock); |
| 216 | |
| 217 | ssize_t ustcomm_recv_channel_from_sessiond(int sock, |
| 218 | void **chan_data, uint64_t len, int *wakeup_fd); |
| 219 | int ustcomm_recv_stream_from_sessiond(int sock, |
| 220 | uint64_t *memory_map_size, |
| 221 | int *shm_fd, int *wakeup_fd); |
| 222 | |
| 223 | /* |
| 224 | * Returns 0 on success, negative error value on error. |
| 225 | * Returns -EPIPE or -ECONNRESET if other end has hung up. |
| 226 | */ |
| 227 | int ustcomm_send_reg_msg(int sock, |
| 228 | enum ustctl_socket_type type, |
| 229 | uint32_t bits_per_long, |
| 230 | uint32_t uint8_t_alignment, |
| 231 | uint32_t uint16_t_alignment, |
| 232 | uint32_t uint32_t_alignment, |
| 233 | uint32_t uint64_t_alignment, |
| 234 | uint32_t long_alignment); |
| 235 | |
| 236 | /* |
| 237 | * Returns 0 on success, negative error value on error. |
| 238 | * Returns -EPIPE or -ECONNRESET if other end has hung up. |
| 239 | */ |
| 240 | int ustcomm_register_event(int sock, |
| 241 | struct lttng_session *session, |
| 242 | int session_objd, /* session descriptor */ |
| 243 | int channel_objd, /* channel descriptor */ |
| 244 | const char *event_name, /* event name (input) */ |
| 245 | int loglevel, |
| 246 | const char *signature, /* event signature (input) */ |
| 247 | size_t nr_fields, /* fields */ |
| 248 | const struct lttng_event_field *fields, |
| 249 | const char *model_emf_uri, |
| 250 | uint32_t *id); /* event id (output) */ |
| 251 | |
| 252 | /* |
| 253 | * Returns 0 on success, negative error value on error. |
| 254 | * Returns -EPIPE or -ECONNRESET if other end has hung up. |
| 255 | */ |
| 256 | int ustcomm_register_enum(int sock, |
| 257 | int session_objd, /* session descriptor */ |
| 258 | const char *enum_name, /* enum name (input) */ |
| 259 | size_t nr_entries, /* entries */ |
| 260 | const struct lttng_enum_entry *entries, |
| 261 | uint64_t *id); /* enum id (output) */ |
| 262 | |
| 263 | /* |
| 264 | * Returns 0 on success, negative error value on error. |
| 265 | * Returns -EPIPE or -ECONNRESET if other end has hung up. |
| 266 | */ |
| 267 | int ustcomm_register_channel(int sock, |
| 268 | struct lttng_session *session, |
| 269 | int session_objd, /* session descriptor */ |
| 270 | int channel_objd, /* channel descriptor */ |
| 271 | size_t nr_ctx_fields, |
| 272 | const struct lttng_ctx_field *ctx_fields, |
| 273 | uint32_t *chan_id, /* channel id (output) */ |
| 274 | int *header_type); /* header type (output) */ |
| 275 | |
| 276 | int ustcomm_setsockopt_rcv_timeout(int sock, unsigned int msec); |
| 277 | int ustcomm_setsockopt_snd_timeout(int sock, unsigned int msec); |
| 278 | |
| 279 | #endif /* _LTTNG_UST_COMM_H */ |