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