2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2011 EfficiOS Inc.
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This header is meant for liblttng and libust internal use ONLY.
10 * These declarations should NOT be considered stable API.
13 #ifndef _UST_COMMON_UST_COMM_H
14 #define _UST_COMMON_UST_COMM_H
19 #include <lttng/ust-abi.h>
20 #include <lttng/ust-error.h>
21 #include <lttng/ust-compiler.h>
22 #include <lttng/ust-ctl.h>
25 * Default timeout the application waits for the sessiond to send its
26 * "register done" command. Can be overridden with the environment
27 * variable "LTTNG_UST_REGISTER_TIMEOUT". Note that if the sessiond is not
28 * found, the application proceeds directly without any delay.
30 #define LTTNG_UST_DEFAULT_CONSTRUCTOR_TIMEOUT_MS 3000
32 #define LTTNG_DEFAULT_RUNDIR LTTNG_SYSTEM_RUNDIR
33 #define LTTNG_DEFAULT_HOME_RUNDIR ".lttng"
35 /* Queue size of listen(2) */
36 #define LTTNG_UST_COMM_MAX_LISTEN 10
37 #define LTTNG_UST_COMM_REG_MSG_PADDING 64
39 struct lttng_ust_event_field
;
40 struct lttng_ust_ctx_field
;
41 struct lttng_ust_enum_entry
;
42 struct lttng_integer_type
;
43 struct lttng_ust_session
;
45 struct lttng_ust_ctl_reg_msg
{
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
;
59 uint32_t socket_type
; /* enum lttng_ust_ctl_socket_type */
60 char name
[LTTNG_UST_ABI_PROCNAME_LEN
]; /* process name */
61 char padding
[LTTNG_UST_COMM_REG_MSG_PADDING
];
62 } __attribute__((packed
));
65 * Data structure for the commands sent from sessiond to UST.
67 #define USTCOMM_MSG_PADDING1 32
68 #define USTCOMM_MSG_PADDING2 32
69 struct ustcomm_ust_msg
{
72 char padding
[USTCOMM_MSG_PADDING1
];
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
;
81 uint32_t data_size
; /* following filter data */
82 uint32_t reloc_offset
;
84 } __attribute__((packed
)) filter
;
86 uint32_t count
; /* how many names follow */
87 } __attribute__((packed
)) exclusion
;
89 uint32_t data_size
; /* following capture data */
90 uint32_t reloc_offset
;
92 } __attribute__((packed
)) capture
;
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
;
97 * For lttng_ust_abi_EVENT_NOTIFIER_CREATE, a struct
98 * lttng_ust_abi_event_notifier implicitly follows struct
102 /* Length of struct lttng_ust_abi_event_notifier */
105 char padding
[USTCOMM_MSG_PADDING2
];
107 } __attribute__((packed
));
110 * Data structure for the response from UST to the session daemon.
111 * cmd_type is sent back in the reply for validation.
113 #define USTCOMM_REPLY_PADDING1 32
114 #define USTCOMM_REPLY_PADDING2 32
115 struct ustcomm_ust_reply
{
118 int32_t ret_code
; /* enum ustcomm_return_code */
119 uint32_t ret_val
; /* return value */
120 char padding
[USTCOMM_REPLY_PADDING1
];
123 uint64_t memory_map_size
;
124 } __attribute__((packed
)) channel
;
126 uint64_t memory_map_size
;
127 } __attribute__((packed
)) stream
;
128 struct lttng_ust_abi_tracer_version version
;
129 struct lttng_ust_abi_tracepoint_iter tracepoint
;
130 char padding
[USTCOMM_REPLY_PADDING2
];
132 } __attribute__((packed
));
134 struct ustcomm_notify_hdr
{
136 } __attribute__((packed
));
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_ABI_SYM_NAME_LEN
];
144 uint32_t signature_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 } __attribute__((packed
));
151 #define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32
152 struct ustcomm_notify_event_reply
{
153 int32_t ret_code
; /* 0: ok, negative: error code */
155 char padding
[USTCOMM_NOTIFY_EVENT_REPLY_PADDING
];
156 } __attribute__((packed
));
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_ABI_SYM_NAME_LEN
];
162 uint32_t entries_len
;
163 char padding
[USTCOMM_NOTIFY_ENUM_MSG_PADDING
];
164 /* followed by enum entries */
165 } __attribute__((packed
));
167 #define USTCOMM_NOTIFY_EVENT_REPLY_PADDING 32
168 struct ustcomm_notify_enum_reply
{
169 int32_t ret_code
; /* 0: ok, negative: error code */
171 char padding
[USTCOMM_NOTIFY_EVENT_REPLY_PADDING
];
172 } __attribute__((packed
));
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 } __attribute__((packed
));
183 #define USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING 32
184 struct ustcomm_notify_channel_reply
{
185 int32_t ret_code
; /* 0: ok, negative: error code */
187 uint32_t header_type
; /* enum lttng_ust_ctl_channel_header */
188 char padding
[USTCOMM_NOTIFY_CHANNEL_REPLY_PADDING
];
189 } __attribute__((packed
));
192 * LTTNG_UST_TRACEPOINT_FIELD_LIST reply is followed by a
193 * struct lttng_ust_field_iter field.
196 int ustcomm_create_unix_sock(const char *pathname
)
197 __attribute__((visibility("hidden")));
199 int ustcomm_connect_unix_sock(const char *pathname
,
201 __attribute__((visibility("hidden")));
203 int ustcomm_accept_unix_sock(int sock
)
204 __attribute__((visibility("hidden")));
206 int ustcomm_listen_unix_sock(int sock
)
207 __attribute__((visibility("hidden")));
209 int ustcomm_shutdown_unix_sock(int sock
)
210 __attribute__((visibility("hidden")));
212 int ustcomm_close_unix_sock(int sock
)
213 __attribute__((visibility("hidden")));
215 ssize_t
ustcomm_recv_unix_sock(int sock
, void *buf
, size_t len
)
216 __attribute__((visibility("hidden")));
218 ssize_t
ustcomm_send_unix_sock(int sock
, const void *buf
, size_t len
)
219 __attribute__((visibility("hidden")));
221 ssize_t
ustcomm_send_fds_unix_sock(int sock
, int *fds
, size_t nb_fd
)
222 __attribute__((visibility("hidden")));
224 ssize_t
ustcomm_recv_fds_unix_sock(int sock
, int *fds
, size_t nb_fd
)
225 __attribute__((visibility("hidden")));
227 const char *ustcomm_get_readable_code(int code
)
228 __attribute__((visibility("hidden")));
230 int ustcomm_send_app_msg(int sock
, struct ustcomm_ust_msg
*lum
)
231 __attribute__((visibility("hidden")));
233 int ustcomm_recv_app_reply(int sock
, struct ustcomm_ust_reply
*lur
,
234 uint32_t expected_handle
, uint32_t expected_cmd
)
235 __attribute__((visibility("hidden")));
237 int ustcomm_send_app_cmd(int sock
,
238 struct ustcomm_ust_msg
*lum
,
239 struct ustcomm_ust_reply
*lur
)
240 __attribute__((visibility("hidden")));
242 int ustcomm_recv_fd(int sock
)
243 __attribute__((visibility("hidden")));
245 ssize_t
ustcomm_recv_channel_from_sessiond(int sock
,
246 void **chan_data
, uint64_t len
, int *wakeup_fd
)
247 __attribute__((visibility("hidden")));
249 int ustcomm_recv_stream_from_sessiond(int sock
,
250 uint64_t *memory_map_size
,
251 int *shm_fd
, int *wakeup_fd
)
252 __attribute__((visibility("hidden")));
254 ssize_t
ustcomm_recv_event_notifier_notif_fd_from_sessiond(int sock
,
255 int *event_notifier_notif_fd
)
256 __attribute__((visibility("hidden")));
258 ssize_t
ustcomm_recv_counter_from_sessiond(int sock
,
259 void **counter_data
, uint64_t len
)
260 __attribute__((visibility("hidden")));
262 int ustcomm_recv_counter_shm_from_sessiond(int sock
,
264 __attribute__((visibility("hidden")));
267 * Returns 0 on success, negative error value on error.
268 * Returns -EPIPE or -ECONNRESET if other end has hung up.
270 int ustcomm_send_reg_msg(int sock
,
271 enum lttng_ust_ctl_socket_type type
,
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
,
277 uint32_t long_alignment
,
278 const char *procname
)
279 __attribute__((visibility("hidden")));
282 * Returns 0 on success, negative error value on error.
283 * Returns -EPIPE or -ECONNRESET if other end has hung up.
285 int ustcomm_register_event(int sock
,
286 struct lttng_ust_session
*session
,
287 int session_objd
, /* session descriptor */
288 int channel_objd
, /* channel descriptor */
289 const char *event_name
, /* event name (input) */
291 const char *signature
, /* event signature (input) */
292 size_t nr_fields
, /* fields */
293 const struct lttng_ust_event_field
* const *fields
,
294 const char *model_emf_uri
,
295 uint32_t *id
) /* event id (output) */
296 __attribute__((visibility("hidden")));
299 * Returns 0 on success, negative error value on error.
300 * Returns -EPIPE or -ECONNRESET if other end has hung up.
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 */
306 const struct lttng_ust_enum_entry
* const *entries
,
307 uint64_t *id
) /* enum id (output) */
308 __attribute__((visibility("hidden")));
311 * Returns 0 on success, negative error value on error.
312 * Returns -EPIPE or -ECONNRESET if other end has hung up.
314 int ustcomm_register_channel(int sock
,
315 struct lttng_ust_session
*session
,
316 int session_objd
, /* session descriptor */
317 int channel_objd
, /* channel descriptor */
318 size_t nr_ctx_fields
,
319 struct lttng_ust_ctx_field
*ctx_fields
,
320 uint32_t *chan_id
, /* channel id (output) */
321 int *header_type
) /* header type (output) */
322 __attribute__((visibility("hidden")));
324 int ustcomm_setsockopt_rcv_timeout(int sock
, unsigned int msec
)
325 __attribute__((visibility("hidden")));
327 int ustcomm_setsockopt_snd_timeout(int sock
, unsigned int msec
)
328 __attribute__((visibility("hidden")));
330 #endif /* _UST_COMMON_UST_COMM_H */