clang-tidy: add a subset of cppcoreguidelines and other style checks
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.hpp
1 /*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef LTTNG_UST_REGISTRY_H
10 #define LTTNG_UST_REGISTRY_H
11
12 #include "event-class.hpp"
13 #include "field.hpp"
14 #include "lttng-ust-ctl.hpp"
15 #include "session.hpp"
16 #include "stream-class.hpp"
17 #include "trace-class.hpp"
18 #include "ust-clock-class.hpp"
19 #include "ust-registry-channel.hpp"
20 #include "ust-registry-event.hpp"
21
22 #include <common/format.hpp>
23 #include <common/hashtable/hashtable.hpp>
24 #include <common/locked-reference.hpp>
25 #include <common/urcu.hpp>
26 #include <common/uuid.hpp>
27
28 #include <lttng/domain.h>
29
30 #include <ctime>
31 #include <memory>
32 #include <pthread.h>
33 #include <stdint.h>
34 #include <string>
35 #include <type_traits>
36
37 #define CTF_SPEC_MAJOR 1
38 #define CTF_SPEC_MINOR 8
39
40 struct ust_app;
41
42 namespace lttng {
43 namespace sessiond {
44 namespace ust {
45
46 class registry_session;
47
48 namespace details {
49
50 template <class MappingIntegerType>
51 typename trace::typed_enumeration_type<MappingIntegerType>::mappings mappings_from_ust_ctl_entries(
52 const lttng_ust_ctl_enum_entry *in_entries, size_t in_entry_count)
53 {
54 typename trace::typed_enumeration_type<MappingIntegerType>::mappings mappings;
55
56 MappingIntegerType next_range_begin = 0;
57 for (size_t entry_idx = 0; entry_idx < in_entry_count; entry_idx++) {
58 const auto& entry = in_entries[entry_idx];
59 MappingIntegerType range_begin, range_end;
60
61 if (entry.u.extra.options & LTTNG_UST_CTL_UST_ENUM_ENTRY_OPTION_IS_AUTO) {
62 range_begin = range_end = next_range_begin;
63 } else {
64 range_begin = (MappingIntegerType) entry.start.value;
65 range_end = (MappingIntegerType) entry.end.value;
66 }
67
68 next_range_begin = range_end + 1;
69 mappings.emplace_back(entry.string,
70 typename trace::typed_enumeration_type<
71 MappingIntegerType>::mapping::range_t{
72 range_begin, range_end});
73 }
74
75 return mappings;
76 }
77 } /* namespace details */
78
79 class registry_enum {
80 public:
81 using const_rcu_protected_reference = lttng::locked_reference<const registry_enum, lttng::urcu::unique_read_lock>;
82
83 registry_enum(std::string name, enum lttng::sessiond::trace::integer_type::signedness signedness);
84 virtual ~registry_enum() = default;
85 registry_enum(const registry_enum&) = delete;
86 registry_enum(registry_enum&&) = delete;
87 registry_enum& operator=(registry_enum&&) = delete;
88 registry_enum& operator=(const registry_enum&) = delete;
89
90 std::string name;
91 enum lttng::sessiond::trace::integer_type::signedness signedness;
92 /* enum id in session */
93 uint64_t id = -1ULL;
94 /* Enumeration node in session hash table. */
95 struct lttng_ht_node_str node;
96 /* For delayed reclaim. */
97 struct rcu_head rcu_head;
98
99 friend bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept;
100 protected:
101 virtual bool _is_equal(const registry_enum& other) const noexcept = 0;
102 };
103
104 bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept;
105
106 template <class MappingIntegerType>
107 class registry_typed_enum : public registry_enum {
108 public:
109 registry_typed_enum(const char *in_name,
110 const lttng_ust_ctl_enum_entry *entries,
111 size_t entry_count) :
112 registry_enum(in_name,
113 std::is_signed<MappingIntegerType>::value ?
114 lttng::sessiond::trace::integer_type::signedness::SIGNED :
115 lttng::sessiond::trace::integer_type::signedness::UNSIGNED),
116 _mappings{std::make_shared<
117 typename trace::typed_enumeration_type<MappingIntegerType>::mappings>(
118 details::mappings_from_ust_ctl_entries<MappingIntegerType>(
119 entries, entry_count))}
120 {
121 }
122
123 const typename std::shared_ptr<const typename lttng::sessiond::trace::typed_enumeration_type<
124 MappingIntegerType>::mappings>
125 _mappings;
126
127 protected:
128 bool _is_equal(const registry_enum& base_other) const noexcept override
129 {
130 const auto &other = static_cast<decltype(*this)&>(base_other);
131
132 /* Don't compare IDs as some comparisons are performed before an id is assigned. */
133 return this->name == other.name && *this->_mappings == *other._mappings;
134 }
135 };
136
137 using registry_signed_enum = registry_typed_enum<int64_t>;
138 using registry_unsigned_enum = registry_typed_enum<uint64_t>;
139
140 } /* namespace ust */
141 } /* namespace sessiond */
142 } /* namespace lttng */
143
144 #ifdef HAVE_LIBLTTNG_UST_CTL
145
146 /*
147 * Create per-uid registry with default values.
148 *
149 * Return new instance on success, nullptr on error.
150 */
151 lttng::sessiond::ust::registry_session *ust_registry_session_per_uid_create(
152 const lttng::sessiond::trace::abi& abi,
153 uint32_t major,
154 uint32_t minor,
155 const char *root_shm_path,
156 const char *shm_path,
157 uid_t euid,
158 gid_t egid,
159 uint64_t tracing_id,
160 uid_t tracing_uid);
161
162 /*
163 * Create per-pid registry with default values.
164 *
165 * Return new instance on success, nullptr on error.
166 */
167 lttng::sessiond::ust::registry_session *ust_registry_session_per_pid_create(struct ust_app *app,
168 const lttng::sessiond::trace::abi& abi,
169 uint32_t major,
170 uint32_t minor,
171 const char *root_shm_path,
172 const char *shm_path,
173 uid_t euid,
174 gid_t egid,
175 uint64_t tracing_id);
176 void ust_registry_session_destroy(lttng::sessiond::ust::registry_session *session);
177
178 void ust_registry_channel_destroy_event(lttng::sessiond::ust::registry_channel *chan,
179 lttng::sessiond::ust::registry_event *event);
180
181 #else /* HAVE_LIBLTTNG_UST_CTL */
182
183 static inline
184 lttng::sessiond::ust::registry_session *ust_registry_session_per_uid_create(
185 uint32_t bits_per_long __attribute__((unused)),
186 uint32_t uint8_t_alignment __attribute__((unused)),
187 uint32_t uint16_t_alignment __attribute__((unused)),
188 uint32_t uint32_t_alignment __attribute__((unused)),
189 uint32_t uint64_t_alignment __attribute__((unused)),
190 uint32_t long_alignment __attribute__((unused)),
191 int byte_order __attribute__((unused)),
192 uint32_t major __attribute__((unused)),
193 uint32_t minor __attribute__((unused)),
194 const char *root_shm_path __attribute__((unused)),
195 const char *shm_path __attribute__((unused)),
196 uid_t euid __attribute__((unused)),
197 gid_t egid __attribute__((unused)),
198 uint64_t tracing_id __attribute__((unused)),
199 uid_t tracing_uid __attribute__((unused)))
200 {
201 return nullptr;
202 }
203
204 static inline
205 lttng::sessiond::ust::registry_session *ust_registry_session_per_pid_create(
206 struct ust_app *app __attribute__((unused)),
207 uint32_t bits_per_long __attribute__((unused)),
208 uint32_t uint8_t_alignment __attribute__((unused)),
209 uint32_t uint16_t_alignment __attribute__((unused)),
210 uint32_t uint32_t_alignment __attribute__((unused)),
211 uint32_t uint64_t_alignment __attribute__((unused)),
212 uint32_t long_alignment __attribute__((unused)),
213 int byte_order __attribute__((unused)),
214 uint32_t major __attribute__((unused)),
215 uint32_t minor __attribute__((unused)),
216 const char *root_shm_path __attribute__((unused)),
217 const char *shm_path __attribute__((unused)),
218 uid_t euid __attribute__((unused)),
219 gid_t egid __attribute__((unused)),
220 uint64_t tracing_id __attribute__((unused)))
221 {
222 return nullptr;
223 }
224
225 static inline
226 void ust_registry_session_destroy(
227 lttng::sessiond::ust::registry_session *session __attribute__((unused)))
228 {}
229
230 static inline
231 void ust_registry_destroy_event(
232 lttng::sessiond::ust::registry_channel *chan __attribute__((unused)),
233 lttng::sessiond::ust::registry_event *event __attribute__((unused)))
234 {}
235
236 /* The app object can be NULL for registry shared across applications. */
237 static inline
238 int ust_metadata_session_statedump(
239 lttng::sessiond::ust::registry_session *session __attribute__((unused)))
240 {
241 return 0;
242 }
243
244 static inline
245 int ust_metadata_channel_statedump(
246 lttng::sessiond::ust::registry_session *session __attribute__((unused)),
247 lttng::sessiond::ust::registry_channel *chan __attribute__((unused)))
248 {
249 return 0;
250 }
251
252 static inline
253 int ust_metadata_event_statedump(
254 lttng::sessiond::ust::registry_session *session __attribute__((unused)),
255 lttng::sessiond::ust::registry_channel *chan __attribute__((unused)),
256 lttng::sessiond::ust::registry_event *event __attribute__((unused)))
257 {
258 return 0;
259 }
260
261 #endif /* HAVE_LIBLTTNG_UST_CTL */
262
263 #endif /* LTTNG_UST_REGISTRY_H */
This page took 0.035281 seconds and 5 git commands to generate.