Fix: Integer overflowed argument
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.h
CommitLineData
d0b96690
DG
1/*
2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#ifndef LTTNG_UST_REGISTRY_H
19#define LTTNG_UST_REGISTRY_H
20
21#include <pthread.h>
22#include <stdint.h>
d0b96690
DG
23
24#include <common/hashtable/hashtable.h>
25#include <common/compat/uuid.h>
26
7972aab2
DG
27#include "ust-ctl.h"
28
d0b96690
DG
29#define CTF_SPEC_MAJOR 1
30#define CTF_SPEC_MINOR 8
31
32struct ust_app;
33
34struct ust_registry_session {
35 /*
dc2bbdae
MD
36 * With multiple writers and readers, use this lock to access
37 * the registry. Can nest within the ust app session lock.
38 * Also acts as a registry serialization lock. Used by registry
39 * readers to serialize the registry information sent from the
40 * sessiond to the consumerd.
41 * The consumer socket lock nests within this lock.
d0b96690
DG
42 */
43 pthread_mutex_t lock;
44 /* Next channel ID available for a newly registered channel. */
45 uint32_t next_channel_id;
46 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
47 uint32_t used_channel_id;
10b56aef
MD
48 /* Next enumeration ID available. */
49 uint64_t next_enum_id;
d0b96690
DG
50 /* Universal unique identifier used by the tracer. */
51 unsigned char uuid[UUID_LEN];
52
53 /* session ABI description */
54
55 /* Size of long, in bits */
56 unsigned int bits_per_long;
57 /* Alignment, in bits */
58 unsigned int uint8_t_alignment,
59 uint16_t_alignment,
60 uint32_t_alignment,
61 uint64_t_alignment,
62 long_alignment;
63 /* endianness */
64 int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */
65
66 /* Generated metadata. */
67 char *metadata; /* NOT null-terminated ! Use memcpy. */
68 size_t metadata_len, metadata_alloc_len;
d88aee68
DG
69 /* Length of bytes sent to the consumer. */
70 size_t metadata_len_sent;
93ec662e
JD
71 /* Current version of the metadata. */
72 uint64_t metadata_version;
d7ba1388 73
3d071855 74 char root_shm_path[PATH_MAX];
d7ba1388
MD
75 char shm_path[PATH_MAX];
76 char metadata_path[PATH_MAX];
77 int metadata_fd; /* file-backed metadata FD */
78
45893984 79 /*
dc2bbdae
MD
80 * Hash table containing channels sent by the UST tracer. MUST
81 * be accessed with a RCU read side lock acquired.
45893984
DG
82 */
83 struct lttng_ht *channels;
dc2bbdae
MD
84 /*
85 * Unique key to identify the metadata on the consumer side.
86 */
7972aab2
DG
87 uint64_t metadata_key;
88 /*
89 * Indicates if the metadata is closed on the consumer side. This is to
90 * avoid double close of metadata when an application unregisters AND
91 * deletes its sessions.
92 */
93 unsigned int metadata_closed;
4628484a
MD
94
95 /* User and group owning the session. */
96 uid_t uid;
97 gid_t gid;
10b56aef
MD
98
99 /* Enumerations table. */
100 struct lttng_ht *enums;
7062f070
JD
101
102 /*
103 * Copy of the tracer version when the first app is registered.
104 * It is used if we need to regenerate the metadata.
105 */
106 uint32_t major;
107 uint32_t minor;
d0b96690
DG
108};
109
110struct ust_registry_channel {
45893984 111 uint64_t key;
d0b96690
DG
112 /* Id set when replying to a register channel. */
113 uint32_t chan_id;
114 enum ustctl_channel_header header_type;
115
7972aab2
DG
116 /*
117 * Flag for this channel if the metadata was dumped once during
118 * registration. 0 means no, 1 yes.
119 */
120 unsigned int metadata_dumped;
121 /* Indicates if this channel registry has already been registered. */
122 unsigned int register_done;
123
d0b96690
DG
124 /*
125 * Hash table containing events sent by the UST tracer. MUST be accessed
126 * with a RCU read side lock acquired.
127 */
128 struct lttng_ht *ht;
129 /* Next event ID available for a newly registered event. */
130 uint32_t next_event_id;
131 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
132 uint32_t used_event_id;
133 /*
134 * Context fields of the registry. Context are per channel. Allocated by a
135 * register channel notification from the UST tracer.
136 */
137 size_t nr_ctx_fields;
138 struct ustctl_field *ctx_fields;
45893984 139 struct lttng_ht_node_u64 node;
36b588ed
MD
140 /* For delayed reclaim */
141 struct rcu_head rcu_head;
d0b96690
DG
142};
143
144/*
145 * Event registered from a UST tracer sent to the session daemon. This is
146 * indexed and matched by <event_name/signature>.
147 */
148struct ust_registry_event {
149 int id;
150 /* Both objd are set by the tracer. */
151 int session_objd;
152 int channel_objd;
153 /* Name of the event returned by the tracer. */
154 char name[LTTNG_UST_SYM_NAME_LEN];
155 char *signature;
2106efa0 156 int loglevel_value;
d0b96690
DG
157 size_t nr_fields;
158 struct ustctl_field *fields;
159 char *model_emf_uri;
7972aab2
DG
160 /*
161 * Flag for this channel if the metadata was dumped once during
162 * registration. 0 means no, 1 yes.
163 */
164 unsigned int metadata_dumped;
d0b96690
DG
165 /*
166 * Node in the ust-registry hash table. The event name is used to
167 * initialize the node and the event_name/signature for the match function.
168 */
7972aab2 169 struct lttng_ht_node_u64 node;
d0b96690
DG
170};
171
10b56aef
MD
172struct ust_registry_enum {
173 char name[LTTNG_UST_SYM_NAME_LEN];
174 struct ustctl_enum_entry *entries;
175 size_t nr_entries;
176 uint64_t id; /* enum id in session */
177 /* Enumeration node in session hash table. */
178 struct lttng_ht_node_str node;
179 /* For delayed reclaim. */
180 struct rcu_head rcu_head;
181};
182
d0b96690
DG
183/*
184 * Validate that the id has reached the maximum allowed or not.
185 *
186 * Return 0 if NOT else 1.
187 */
188static inline int ust_registry_is_max_id(uint32_t id)
189{
190 return (id == UINT32_MAX) ? 1 : 0;
191}
192
193/*
194 * Return next available event id and increment the used counter. The
195 * ust_registry_is_max_id function MUST be called before in order to validate
196 * if the maximum number of IDs have been reached. If not, it is safe to call
197 * this function.
198 *
199 * Return a unique channel ID. If max is reached, the used_event_id counter is
200 * returned.
201 */
202static inline uint32_t ust_registry_get_next_event_id(
203 struct ust_registry_channel *r)
204{
205 if (ust_registry_is_max_id(r->used_event_id)) {
206 return r->used_event_id;
207 }
208
209 r->used_event_id++;
210 return r->next_event_id++;
211}
212
213/*
214 * Return next available channel id and increment the used counter. The
215 * ust_registry_is_max_id function MUST be called before in order to validate
216 * if the maximum number of IDs have been reached. If not, it is safe to call
217 * this function.
218 *
219 * Return a unique channel ID. If max is reached, the used_channel_id counter
220 * is returned.
221 */
222static inline uint32_t ust_registry_get_next_chan_id(
223 struct ust_registry_session *r)
224{
225 if (ust_registry_is_max_id(r->used_channel_id)) {
226 return r->used_channel_id;
227 }
228
229 r->used_channel_id++;
230 return r->next_channel_id++;
231}
232
233/*
234 * Return registry event count. This is read atomically.
235 */
236static inline uint32_t ust_registry_get_event_count(
237 struct ust_registry_channel *r)
238{
239 return (uint32_t) uatomic_read(&r->used_event_id);
240}
241
7972aab2
DG
242#ifdef HAVE_LIBLTTNG_UST_CTL
243
d0b96690
DG
244void ust_registry_channel_destroy(struct ust_registry_session *session,
245 struct ust_registry_channel *chan);
45893984
DG
246struct ust_registry_channel *ust_registry_channel_find(
247 struct ust_registry_session *session, uint64_t key);
248int ust_registry_channel_add(struct ust_registry_session *session,
249 uint64_t key);
250void ust_registry_channel_del_free(struct ust_registry_session *session,
251 uint64_t key);
252
253int ust_registry_session_init(struct ust_registry_session **sessionp,
d0b96690
DG
254 struct ust_app *app,
255 uint32_t bits_per_long,
256 uint32_t uint8_t_alignment,
257 uint32_t uint16_t_alignment,
258 uint32_t uint32_t_alignment,
259 uint32_t uint64_t_alignment,
260 uint32_t long_alignment,
af6142cf
MD
261 int byte_order,
262 uint32_t major,
d7ba1388 263 uint32_t minor,
3d071855 264 const char *root_shm_path,
d7ba1388
MD
265 const char *shm_path,
266 uid_t euid,
267 gid_t egid);
d0b96690
DG
268void ust_registry_session_destroy(struct ust_registry_session *session);
269
270int ust_registry_create_event(struct ust_registry_session *session,
45893984 271 uint64_t chan_key, int session_objd, int channel_objd, char *name,
2106efa0
PP
272 char *sig, size_t nr_fields, struct ustctl_field *fields,
273 int loglevel_value, char *model_emf_uri, int buffer_type,
274 uint32_t *event_id_p, struct ust_app *app);
d0b96690
DG
275struct ust_registry_event *ust_registry_find_event(
276 struct ust_registry_channel *chan, char *name, char *sig);
277void ust_registry_destroy_event(struct ust_registry_channel *chan,
278 struct ust_registry_event *event);
279
280/* app can be NULL for registry shared across applications. */
281int ust_metadata_session_statedump(struct ust_registry_session *session,
af6142cf 282 struct ust_app *app, uint32_t major, uint32_t minor);
d0b96690
DG
283int ust_metadata_channel_statedump(struct ust_registry_session *session,
284 struct ust_registry_channel *chan);
285int ust_metadata_event_statedump(struct ust_registry_session *session,
286 struct ust_registry_channel *chan,
287 struct ust_registry_event *event);
10b56aef
MD
288int ust_registry_create_or_find_enum(struct ust_registry_session *session,
289 int session_objd, char *name,
290 struct ustctl_enum_entry *entries, size_t nr_entries,
291 uint64_t *enum_id);
292struct ust_registry_enum *
293 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
294 const char *name, uint64_t id);
d0b96690 295
7972aab2
DG
296#else /* HAVE_LIBLTTNG_UST_CTL */
297
298static inline
299void ust_registry_channel_destroy(struct ust_registry_session *session,
300 struct ust_registry_channel *chan)
301{}
302static inline
303struct ust_registry_channel *ust_registry_channel_find(
304 struct ust_registry_session *session, uint64_t key)
305{
306 return NULL;
307}
308static inline
309int ust_registry_channel_add(struct ust_registry_session *session,
310 uint64_t key)
311{
312 return 0;
313}
314static inline
315void ust_registry_channel_del_free(struct ust_registry_session *session,
316 uint64_t key)
317{}
318static inline
319int ust_registry_session_init(struct ust_registry_session **sessionp,
320 struct ust_app *app,
321 uint32_t bits_per_long,
322 uint32_t uint8_t_alignment,
323 uint32_t uint16_t_alignment,
324 uint32_t uint32_t_alignment,
325 uint32_t uint64_t_alignment,
326 uint32_t long_alignment,
327 int byte_order)
328{
329 return 0;
330}
331static inline
332void ust_registry_session_destroy(struct ust_registry_session *session)
333{}
334static inline
335int ust_registry_create_event(struct ust_registry_session *session,
336 uint64_t chan_key, int session_objd, int channel_objd, char *name,
2106efa0
PP
337 char *sig, size_t nr_fields, struct ustctl_field *fields,
338 int loglevel_value, char *model_emf_uri, int buffer_type,
339 uint32_t *event_id_p)
7972aab2
DG
340{
341 return 0;
342}
343static inline
344struct ust_registry_event *ust_registry_find_event(
345 struct ust_registry_channel *chan, char *name, char *sig)
346{
347 return NULL;
348}
349static inline
350void ust_registry_destroy_event(struct ust_registry_channel *chan,
351 struct ust_registry_event *event)
352{}
353
354/* The app object can be NULL for registry shared across applications. */
355static inline
356int ust_metadata_session_statedump(struct ust_registry_session *session,
9804676e 357 struct ust_app *app, uint32_t major, uint32_t minor)
7972aab2
DG
358{
359 return 0;
360}
361static inline
362int ust_metadata_channel_statedump(struct ust_registry_session *session,
363 struct ust_registry_channel *chan)
364{
365 return 0;
366}
367static inline
368int ust_metadata_event_statedump(struct ust_registry_session *session,
369 struct ust_registry_channel *chan,
370 struct ust_registry_event *event)
371{
372 return 0;
373}
10b56aef
MD
374static inline
375int ust_registry_create_or_find_enum(struct ust_registry_session *session,
376 int session_objd, char *name,
377 struct ustctl_enum_entry *entries, size_t nr_entries,
378 uint64_t *enum_id)
379{
380 return 0;
381}
382static inline
383struct ust_registry_enum *
384 ust_registry_lookup_enum_by_id(struct ust_registry_session *session,
385 const char *name, uint64_t id)
386{
387 return NULL;
388}
7972aab2
DG
389
390#endif /* HAVE_LIBLTTNG_UST_CTL */
391
d0b96690 392#endif /* LTTNG_UST_REGISTRY_H */
This page took 0.051494 seconds and 4 git commands to generate.