Commit | Line | Data |
---|---|---|
67c5b804 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
15f672f9 | 3 | * |
f350e97f | 4 | * Copyright (C) 2011 EfficiOS Inc. |
c0c0989a | 5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
67c5b804 MD |
6 | */ |
7 | ||
8 | /* | |
9 | * This header is meant for liblttng and libust internal use ONLY. | |
10 | * These declarations should NOT be considered stable API. | |
11 | */ | |
12 | ||
67534785 MJ |
13 | #ifndef _UST_COMMON_UST_COMM_H |
14 | #define _UST_COMMON_UST_COMM_H | |
c0c0989a | 15 | |
fb31eb73 | 16 | #include <stdint.h> |
67c5b804 | 17 | #include <limits.h> |
57773204 | 18 | #include <unistd.h> |
4318ae1b | 19 | #include <lttng/ust-abi.h> |
7bc53e94 | 20 | #include <lttng/ust-error.h> |
b3f60bbf | 21 | #include <lttng/ust-compiler.h> |
c785c634 | 22 | #include <lttng/ust-ctl.h> |
67c5b804 | 23 | |
11ff9c7d | 24 | /* |
cf12a773 MD |
25 | * Default timeout the application waits for the sessiond to send its |
26 | * "register done" command. Can be overridden with the environment | |
69400ac4 | 27 | * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not |
cf12a773 | 28 | * found, the application proceeds directly without any delay. |
11ff9c7d | 29 | */ |
156b0cf7 | 30 | #define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000 |
11ff9c7d | 31 | |
751d4e91 | 32 | #define LTTNG_DEFAULT_RUNDIR LTTNG_SYSTEM_RUNDIR |
32ce8569 | 33 | #define LTTNG_DEFAULT_HOME_RUNDIR ".lttng" |
7fc90dca | 34 | |
67c5b804 | 35 | /* Queue size of listen(2) */ |
32ce8569 MD |
36 | #define LTTNG_UST_COMM_MAX_LISTEN 10 |
37 | #define LTTNG_UST_COMM_REG_MSG_PADDING 64 | |
38 | ||
25cff019 | 39 | struct lttng_ust_event_field; |
daacdbfc | 40 | struct lttng_ust_ctx_field; |
891d6b55 | 41 | struct lttng_ust_enum_entry; |
c785c634 | 42 | struct lttng_integer_type; |
f69fe5fb | 43 | struct lttng_ust_session; |
32ce8569 | 44 | |
249cffb5 | 45 | struct lttng_ust_ctl_reg_msg { |
32ce8569 MD |
46 | uint32_t magic; |
47 | uint32_t major; | |
48 | uint32_t minor; | |
49 | uint32_t pid; | |
50 | uint32_t ppid; | |
51 | uint32_t uid; | |
52 | uint32_t gid; | |
53 | uint32_t bits_per_long; | |
54 | uint32_t uint8_t_alignment; | |
55 | uint32_t uint16_t_alignment; | |
56 | uint32_t uint32_t_alignment; | |
57 | uint32_t uint64_t_alignment; | |
58 | uint32_t long_alignment; | |
249cffb5 | 59 | uint32_t socket_type; /* enum lttng_ust_ctl_socket_type */ |
32ce8569 MD |
60 | char name[LTTNG_UST_ABI_PROCNAME_LEN]; /* process name */ |
61 | char padding[LTTNG_UST_COMM_REG_MSG_PADDING]; | |
9f5ade14 | 62 | } __attribute__((packed)); |
67c5b804 | 63 | |
67c5b804 | 64 | /* |
e7723462 | 65 | * Data structure for the commands sent from sessiond to UST. |
67c5b804 | 66 | */ |
32ce8569 MD |
67 | #define USTCOMM_MSG_PADDING1 32 |
68 | #define USTCOMM_MSG_PADDING2 32 | |
57773204 | 69 | struct ustcomm_ust_msg { |
1ece9766 | 70 | uint32_t handle; |
46050b1a | 71 | uint32_t cmd; |
32ce8569 | 72 | char padding[USTCOMM_MSG_PADDING1]; |
67c5b804 | 73 | union { |
fd17d7ce MD |
74 | struct lttng_ust_abi_channel channel; |
75 | struct lttng_ust_abi_stream stream; | |
76 | struct lttng_ust_abi_event event; | |
77 | struct lttng_ust_abi_context context; | |
78 | struct lttng_ust_abi_tracer_version version; | |
79 | struct lttng_ust_abi_tracepoint_iter tracepoint; | |
2d78951a | 80 | struct { |
2734ca65 CB |
81 | uint32_t data_size; /* following filter data */ |
82 | uint32_t reloc_offset; | |
3f6fd224 | 83 | uint64_t seqnum; |
9f5ade14 | 84 | } __attribute__((packed)) filter; |
75582b3a JI |
85 | struct { |
86 | uint32_t count; /* how many names follow */ | |
9f5ade14 | 87 | } __attribute__((packed)) exclusion; |
d37ecb3f FD |
88 | struct { |
89 | uint32_t data_size; /* following capture data */ | |
90 | uint32_t reloc_offset; | |
91 | uint64_t seqnum; | |
9f5ade14 | 92 | } __attribute__((packed)) capture; |
fd17d7ce MD |
93 | struct lttng_ust_abi_counter counter; |
94 | struct lttng_ust_abi_counter_global counter_global; | |
95 | struct lttng_ust_abi_counter_cpu counter_cpu; | |
8406222c | 96 | /* |
fd17d7ce MD |
97 | * For lttng_ust_abi_EVENT_NOTIFIER_CREATE, a struct |
98 | * lttng_ust_abi_event_notifier implicitly follows struct | |
8406222c MD |
99 | * ustcomm_ust_msg. |
100 | */ | |
101 | struct { | |
fd17d7ce | 102 | /* Length of struct lttng_ust_abi_event_notifier */ |
8406222c MD |
103 | uint32_t len; |
104 | } event_notifier; | |
32ce8569 | 105 | char padding[USTCOMM_MSG_PADDING2]; |
67c5b804 | 106 | } u; |
9f5ade14 | 107 | } __attribute__((packed)); |
67c5b804 | 108 | |
9eb62b9c MD |
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 | */ | |
32ce8569 MD |
113 | #define USTCOMM_REPLY_PADDING1 32 |
114 | #define USTCOMM_REPLY_PADDING2 32 | |
57773204 | 115 | struct ustcomm_ust_reply { |
46050b1a MD |
116 | uint32_t handle; |
117 | uint32_t cmd; | |
7f2348b8 | 118 | int32_t ret_code; /* enum ustcomm_return_code */ |
1ece9766 | 119 | uint32_t ret_val; /* return value */ |
32ce8569 | 120 | char padding[USTCOMM_REPLY_PADDING1]; |
9eb62b9c | 121 | union { |
193183fb MD |
122 | struct { |
123 | uint64_t memory_map_size; | |
9f5ade14 | 124 | } __attribute__((packed)) channel; |
381c0f1e MD |
125 | struct { |
126 | uint64_t memory_map_size; | |
9f5ade14 | 127 | } __attribute__((packed)) stream; |
fd17d7ce MD |
128 | struct lttng_ust_abi_tracer_version version; |
129 | struct lttng_ust_abi_tracepoint_iter tracepoint; | |
32ce8569 | 130 | char padding[USTCOMM_REPLY_PADDING2]; |
9eb62b9c | 131 | } u; |
9f5ade14 | 132 | } __attribute__((packed)); |
9eb62b9c | 133 | |
32ce8569 MD |
134 | struct ustcomm_notify_hdr { |
135 | uint32_t notify_cmd; | |
9f5ade14 | 136 | } __attribute__((packed)); |
32ce8569 MD |
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; | |
fd17d7ce | 142 | char event_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
32ce8569 MD |
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 */ | |
9f5ade14 | 149 | } __attribute__((packed)); |
32ce8569 MD |
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]; | |
9f5ade14 | 156 | } __attribute__((packed)); |
32ce8569 | 157 | |
c785c634 MD |
158 | #define USTCOMM_NOTIFY_ENUM_MSG_PADDING 32 |
159 | struct ustcomm_notify_enum_msg { | |
160 | uint32_t session_objd; | |
fd17d7ce | 161 | char enum_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
c785c634 MD |
162 | uint32_t entries_len; |
163 | char padding[USTCOMM_NOTIFY_ENUM_MSG_PADDING]; | |
164 | /* followed by enum entries */ | |
9f5ade14 | 165 | } __attribute__((packed)); |
c785c634 MD |
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]; | |
9f5ade14 | 172 | } __attribute__((packed)); |
c785c634 | 173 | |
32ce8569 MD |
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 */ | |
9f5ade14 | 181 | } __attribute__((packed)); |
32ce8569 MD |
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; | |
249cffb5 | 187 | uint32_t header_type; /* enum lttng_ust_ctl_channel_header */ |
32ce8569 | 188 | char padding[USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING]; |
9f5ade14 | 189 | } __attribute__((packed)); |
32ce8569 | 190 | |
40003310 MD |
191 | /* |
192 | * LTTNG_UST_TRACEPOINT_FIELD_LIST reply is followed by a | |
193 | * struct lttng_ust_field_iter field. | |
194 | */ | |
195 | ||
1d18d519 MJ |
196 | int ustcomm_create_unix_sock(const char *pathname) |
197 | __attribute__((visibility("hidden"))); | |
ddabe860 | 198 | |
8f1313b1 | 199 | int ustcomm_connect_unix_sock(const char *pathname, |
1d18d519 MJ |
200 | long timeout) |
201 | __attribute__((visibility("hidden"))); | |
ddabe860 | 202 | |
1d18d519 MJ |
203 | int ustcomm_accept_unix_sock(int sock) |
204 | __attribute__((visibility("hidden"))); | |
ddabe860 | 205 | |
1d18d519 MJ |
206 | int ustcomm_listen_unix_sock(int sock) |
207 | __attribute__((visibility("hidden"))); | |
ddabe860 | 208 | |
ea1c5d69 MD |
209 | int ustcomm_shutdown_unix_sock(int sock) |
210 | __attribute__((visibility("hidden"))); | |
211 | ||
1d18d519 MJ |
212 | int ustcomm_close_unix_sock(int sock) |
213 | __attribute__((visibility("hidden"))); | |
74d81a6c | 214 | |
1d18d519 MJ |
215 | ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) |
216 | __attribute__((visibility("hidden"))); | |
ddabe860 | 217 | |
1d18d519 MJ |
218 | ssize_t ustcomm_send_unix_sock(int sock, const void *buf, size_t len) |
219 | __attribute__((visibility("hidden"))); | |
ddabe860 | 220 | |
1d18d519 MJ |
221 | ssize_t ustcomm_send_fds_unix_sock(int sock, int *fds, size_t nb_fd) |
222 | __attribute__((visibility("hidden"))); | |
ddabe860 | 223 | |
1d18d519 MJ |
224 | ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) |
225 | __attribute__((visibility("hidden"))); | |
74d81a6c | 226 | |
1d18d519 MJ |
227 | const char *ustcomm_get_readable_code(int code) |
228 | __attribute__((visibility("hidden"))); | |
ddabe860 | 229 | |
1d18d519 MJ |
230 | int ustcomm_send_app_msg(int sock, struct ustcomm_ust_msg *lum) |
231 | __attribute__((visibility("hidden"))); | |
ddabe860 | 232 | |
8f1313b1 | 233 | int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, |
1d18d519 MJ |
234 | uint32_t expected_handle, uint32_t expected_cmd) |
235 | __attribute__((visibility("hidden"))); | |
ddabe860 | 236 | |
8f1313b1 | 237 | int ustcomm_send_app_cmd(int sock, |
57773204 | 238 | struct ustcomm_ust_msg *lum, |
1d18d519 MJ |
239 | struct ustcomm_ust_reply *lur) |
240 | __attribute__((visibility("hidden"))); | |
ddabe860 | 241 | |
1d18d519 MJ |
242 | int ustcomm_recv_fd(int sock) |
243 | __attribute__((visibility("hidden"))); | |
67c5b804 | 244 | |
74d81a6c | 245 | ssize_t ustcomm_recv_channel_from_sessiond(int sock, |
1d18d519 MJ |
246 | void **chan_data, uint64_t len, int *wakeup_fd) |
247 | __attribute__((visibility("hidden"))); | |
ddabe860 | 248 | |
74d81a6c MD |
249 | int ustcomm_recv_stream_from_sessiond(int sock, |
250 | uint64_t *memory_map_size, | |
1d18d519 MJ |
251 | int *shm_fd, int *wakeup_fd) |
252 | __attribute__((visibility("hidden"))); | |
ddabe860 | 253 | |
d8d2416d | 254 | ssize_t ustcomm_recv_event_notifier_notif_fd_from_sessiond(int sock, |
1d18d519 MJ |
255 | int *event_notifier_notif_fd) |
256 | __attribute__((visibility("hidden"))); | |
74d81a6c | 257 | |
ebabbf58 | 258 | ssize_t ustcomm_recv_counter_from_sessiond(int sock, |
1d18d519 MJ |
259 | void **counter_data, uint64_t len) |
260 | __attribute__((visibility("hidden"))); | |
ddabe860 | 261 | |
ebabbf58 | 262 | int ustcomm_recv_counter_shm_from_sessiond(int sock, |
1d18d519 MJ |
263 | int *shm_fd) |
264 | __attribute__((visibility("hidden"))); | |
ebabbf58 | 265 | |
32ce8569 MD |
266 | /* |
267 | * Returns 0 on success, negative error value on error. | |
268 | * Returns -EPIPE or -ECONNRESET if other end has hung up. | |
269 | */ | |
270 | int ustcomm_send_reg_msg(int sock, | |
249cffb5 | 271 | enum lttng_ust_ctl_socket_type type, |
32ce8569 MD |
272 | uint32_t bits_per_long, |
273 | uint32_t uint8_t_alignment, | |
274 | uint32_t uint16_t_alignment, | |
275 | uint32_t uint32_t_alignment, | |
276 | uint32_t uint64_t_alignment, | |
046bc54c JG |
277 | uint32_t long_alignment, |
278 | const char *procname) | |
1d18d519 | 279 | __attribute__((visibility("hidden"))); |
32ce8569 MD |
280 | |
281 | /* | |
282 | * Returns 0 on success, negative error value on error. | |
283 | * Returns -EPIPE or -ECONNRESET if other end has hung up. | |
284 | */ | |
285 | int ustcomm_register_event(int sock, | |
f69fe5fb | 286 | struct lttng_ust_session *session, |
32ce8569 MD |
287 | int session_objd, /* session descriptor */ |
288 | int channel_objd, /* channel descriptor */ | |
289 | const char *event_name, /* event name (input) */ | |
290 | int loglevel, | |
291 | const char *signature, /* event signature (input) */ | |
292 | size_t nr_fields, /* fields */ | |
3d33ca1d | 293 | const struct lttng_ust_event_field * const *fields, |
32ce8569 | 294 | const char *model_emf_uri, |
1d18d519 MJ |
295 | uint32_t *id) /* event id (output) */ |
296 | __attribute__((visibility("hidden"))); | |
32ce8569 | 297 | |
c785c634 MD |
298 | /* |
299 | * Returns 0 on success, negative error value on error. | |
300 | * Returns -EPIPE or -ECONNRESET if other end has hung up. | |
301 | */ | |
302 | int ustcomm_register_enum(int sock, | |
303 | int session_objd, /* session descriptor */ | |
304 | const char *enum_name, /* enum name (input) */ | |
305 | size_t nr_entries, /* entries */ | |
3d33ca1d | 306 | const struct lttng_ust_enum_entry * const *entries, |
1d18d519 MJ |
307 | uint64_t *id) /* enum id (output) */ |
308 | __attribute__((visibility("hidden"))); | |
c785c634 | 309 | |
32ce8569 MD |
310 | /* |
311 | * Returns 0 on success, negative error value on error. | |
312 | * Returns -EPIPE or -ECONNRESET if other end has hung up. | |
313 | */ | |
314 | int ustcomm_register_channel(int sock, | |
f69fe5fb | 315 | struct lttng_ust_session *session, |
32ce8569 MD |
316 | int session_objd, /* session descriptor */ |
317 | int channel_objd, /* channel descriptor */ | |
318 | size_t nr_ctx_fields, | |
4e48b5d2 | 319 | struct lttng_ust_ctx_field *ctx_fields, |
32ce8569 | 320 | uint32_t *chan_id, /* channel id (output) */ |
1d18d519 MJ |
321 | int *header_type) /* header type (output) */ |
322 | __attribute__((visibility("hidden"))); | |
32ce8569 | 323 | |
1d18d519 MJ |
324 | int ustcomm_setsockopt_rcv_timeout(int sock, unsigned int msec) |
325 | __attribute__((visibility("hidden"))); | |
ddabe860 | 326 | |
1d18d519 MJ |
327 | int ustcomm_setsockopt_snd_timeout(int sock, unsigned int msec) |
328 | __attribute__((visibility("hidden"))); | |
ff517991 | 329 | |
67534785 | 330 | #endif /* _UST_COMMON_UST_COMM_H */ |