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" | |
21 | ||
22 | #include <common/format.hpp> | |
c9e313bc | 23 | #include <common/hashtable/hashtable.hpp> |
d7bfb9b0 JG |
24 | #include <common/locked-reference.hpp> |
25 | #include <common/urcu.hpp> | |
c9e313bc | 26 | #include <common/uuid.hpp> |
d0b96690 | 27 | |
aeeb48c6 JG |
28 | #include <lttng/domain.h> |
29 | ||
d7bfb9b0 JG |
30 | #include <ctime> |
31 | #include <memory> | |
32 | #include <pthread.h> | |
33 | #include <stdint.h> | |
34 | #include <string> | |
35 | #include <type_traits> | |
7972aab2 | 36 | |
d0b96690 DG |
37 | #define CTF_SPEC_MAJOR 1 |
38 | #define CTF_SPEC_MINOR 8 | |
39 | ||
40 | struct ust_app; | |
d0b96690 | 41 | |
d7bfb9b0 JG |
42 | namespace lttng { |
43 | namespace sessiond { | |
44 | namespace ust { | |
97f630d4 JG |
45 | |
46 | class registry_session; | |
47 | ||
d7bfb9b0 | 48 | namespace details { |
b0f2e8db | 49 | |
d7bfb9b0 JG |
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) | |
d0b96690 | 53 | { |
d7bfb9b0 JG |
54 | typename trace::typed_enumeration_type<MappingIntegerType>::mappings mappings; |
55 | ||
eb5e469d | 56 | MappingIntegerType next_range_begin = 0; |
d7bfb9b0 JG |
57 | for (size_t entry_idx = 0; entry_idx < in_entry_count; entry_idx++) { |
58 | const auto& entry = in_entries[entry_idx]; | |
eb5e469d JG |
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}); | |
d0b96690 DG |
73 | } |
74 | ||
d7bfb9b0 | 75 | return mappings; |
d0b96690 | 76 | } |
d7bfb9b0 | 77 | } /* namespace details */ |
d0b96690 | 78 | |
b0f2e8db JG |
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 | ||
86 | std::string name; | |
87 | enum lttng::sessiond::trace::integer_type::signedness signedness; | |
88 | /* enum id in session */ | |
89 | uint64_t id = -1ULL; | |
90 | /* Enumeration node in session hash table. */ | |
91 | struct lttng_ht_node_str node; | |
92 | /* For delayed reclaim. */ | |
93 | struct rcu_head rcu_head; | |
94 | ||
95 | friend bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept; | |
96 | protected: | |
97 | virtual bool _is_equal(const registry_enum& other) const noexcept = 0; | |
98 | }; | |
99 | ||
100 | bool operator==(const registry_enum& lhs, const registry_enum& rhs) noexcept; | |
101 | ||
d7bfb9b0 JG |
102 | template <class MappingIntegerType> |
103 | class registry_typed_enum : public registry_enum { | |
104 | public: | |
105 | registry_typed_enum(const char *in_name, | |
106 | const lttng_ust_ctl_enum_entry *entries, | |
107 | size_t entry_count) : | |
108 | registry_enum(in_name, | |
109 | std::is_signed<MappingIntegerType>::value ? | |
110 | lttng::sessiond::trace::integer_type::signedness::SIGNED : | |
111 | lttng::sessiond::trace::integer_type::signedness::UNSIGNED), | |
112 | _mappings{std::make_shared< | |
113 | typename trace::typed_enumeration_type<MappingIntegerType>::mappings>( | |
114 | details::mappings_from_ust_ctl_entries<MappingIntegerType>( | |
115 | entries, entry_count))} | |
116 | { | |
d0b96690 DG |
117 | } |
118 | ||
d7bfb9b0 JG |
119 | const typename std::shared_ptr<const typename lttng::sessiond::trace::typed_enumeration_type< |
120 | MappingIntegerType>::mappings> | |
121 | _mappings; | |
d0b96690 | 122 | |
d7bfb9b0 JG |
123 | protected: |
124 | virtual bool _is_equal(const registry_enum& base_other) const noexcept | |
125 | { | |
126 | const auto &other = static_cast<decltype(*this)&>(base_other); | |
d0b96690 | 127 | |
d7bfb9b0 JG |
128 | /* Don't compare IDs as some comparisons are performed before an id is assigned. */ |
129 | return this->name == other.name && *this->_mappings == *other._mappings; | |
130 | } | |
131 | }; | |
7972aab2 | 132 | |
d7bfb9b0 JG |
133 | using registry_signed_enum = registry_typed_enum<int64_t>; |
134 | using registry_unsigned_enum = registry_typed_enum<uint64_t>; | |
135 | ||
136 | } /* namespace ust */ | |
137 | } /* namespace sessiond */ | |
138 | } /* namespace lttng */ | |
139 | ||
140 | #ifdef HAVE_LIBLTTNG_UST_CTL | |
45893984 | 141 | |
aeeb48c6 JG |
142 | /* |
143 | * Create per-uid registry with default values. | |
144 | * | |
145 | * Return new instance on success, nullptr on error. | |
146 | */ | |
b0f2e8db | 147 | lttng::sessiond::ust::registry_session *ust_registry_session_per_uid_create( |
d7bfb9b0 | 148 | const lttng::sessiond::trace::abi& abi, |
af6142cf | 149 | uint32_t major, |
d7ba1388 | 150 | uint32_t minor, |
3d071855 | 151 | const char *root_shm_path, |
d7ba1388 MD |
152 | const char *shm_path, |
153 | uid_t euid, | |
8de88061 JR |
154 | gid_t egid, |
155 | uint64_t tracing_id, | |
c4d702e6 JR |
156 | uid_t tracing_uid, |
157 | const lttng::trace_format_descriptor& trace_format); | |
d0b96690 | 158 | |
aeeb48c6 JG |
159 | /* |
160 | * Create per-pid registry with default values. | |
161 | * | |
162 | * Return new instance on success, nullptr on error. | |
163 | */ | |
b0f2e8db | 164 | lttng::sessiond::ust::registry_session *ust_registry_session_per_pid_create(struct ust_app *app, |
d7bfb9b0 | 165 | const lttng::sessiond::trace::abi& abi, |
aeeb48c6 JG |
166 | uint32_t major, |
167 | uint32_t minor, | |
168 | const char *root_shm_path, | |
169 | const char *shm_path, | |
170 | uid_t euid, | |
171 | gid_t egid, | |
c4d702e6 JR |
172 | uint64_t tracing_id, |
173 | const lttng::trace_format_descriptor& trace_format); | |
b0f2e8db | 174 | void ust_registry_session_destroy(lttng::sessiond::ust::registry_session *session); |
aeeb48c6 | 175 | |
d7bfb9b0 JG |
176 | void ust_registry_channel_destroy_event(lttng::sessiond::ust::registry_channel *chan, |
177 | lttng::sessiond::ust::registry_event *event); | |
178 | ||
7972aab2 DG |
179 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
180 | ||
7972aab2 | 181 | static inline |
b0f2e8db | 182 | lttng::sessiond::ust::registry_session *ust_registry_session_per_uid_create( |
f46376a1 MJ |
183 | uint32_t bits_per_long __attribute__((unused)), |
184 | uint32_t uint8_t_alignment __attribute__((unused)), | |
185 | uint32_t uint16_t_alignment __attribute__((unused)), | |
186 | uint32_t uint32_t_alignment __attribute__((unused)), | |
187 | uint32_t uint64_t_alignment __attribute__((unused)), | |
188 | uint32_t long_alignment __attribute__((unused)), | |
189 | int byte_order __attribute__((unused)), | |
190 | uint32_t major __attribute__((unused)), | |
191 | uint32_t minor __attribute__((unused)), | |
192 | const char *root_shm_path __attribute__((unused)), | |
193 | const char *shm_path __attribute__((unused)), | |
194 | uid_t euid __attribute__((unused)), | |
195 | gid_t egid __attribute__((unused)), | |
196 | uint64_t tracing_id __attribute__((unused)), | |
197 | uid_t tracing_uid __attribute__((unused))) | |
7972aab2 | 198 | { |
aeeb48c6 JG |
199 | return nullptr; |
200 | } | |
201 | ||
202 | static inline | |
b0f2e8db | 203 | lttng::sessiond::ust::registry_session *ust_registry_session_per_pid_create( |
aeeb48c6 JG |
204 | struct ust_app *app __attribute__((unused)), |
205 | uint32_t bits_per_long __attribute__((unused)), | |
206 | uint32_t uint8_t_alignment __attribute__((unused)), | |
207 | uint32_t uint16_t_alignment __attribute__((unused)), | |
208 | uint32_t uint32_t_alignment __attribute__((unused)), | |
209 | uint32_t uint64_t_alignment __attribute__((unused)), | |
210 | uint32_t long_alignment __attribute__((unused)), | |
211 | int byte_order __attribute__((unused)), | |
212 | uint32_t major __attribute__((unused)), | |
213 | uint32_t minor __attribute__((unused)), | |
214 | const char *root_shm_path __attribute__((unused)), | |
215 | const char *shm_path __attribute__((unused)), | |
216 | uid_t euid __attribute__((unused)), | |
217 | gid_t egid __attribute__((unused)), | |
218 | uint64_t tracing_id __attribute__((unused))) | |
219 | { | |
220 | return nullptr; | |
7972aab2 | 221 | } |
f46376a1 | 222 | |
7972aab2 | 223 | static inline |
f46376a1 | 224 | void ust_registry_session_destroy( |
b0f2e8db | 225 | lttng::sessiond::ust::registry_session *session __attribute__((unused))) |
7972aab2 | 226 | {} |
f46376a1 | 227 | |
7972aab2 | 228 | static inline |
f46376a1 | 229 | void ust_registry_destroy_event( |
d7bfb9b0 JG |
230 | lttng::sessiond::ust::registry_channel *chan __attribute__((unused)), |
231 | lttng::sessiond::ust::registry_event *event __attribute__((unused))) | |
7972aab2 DG |
232 | {} |
233 | ||
234 | /* The app object can be NULL for registry shared across applications. */ | |
235 | static inline | |
f46376a1 | 236 | int ust_metadata_session_statedump( |
b0f2e8db | 237 | lttng::sessiond::ust::registry_session *session __attribute__((unused))) |
7972aab2 DG |
238 | { |
239 | return 0; | |
240 | } | |
f46376a1 | 241 | |
7972aab2 | 242 | static inline |
f46376a1 | 243 | int ust_metadata_channel_statedump( |
b0f2e8db | 244 | lttng::sessiond::ust::registry_session *session __attribute__((unused)), |
d7bfb9b0 | 245 | lttng::sessiond::ust::registry_channel *chan __attribute__((unused))) |
7972aab2 DG |
246 | { |
247 | return 0; | |
248 | } | |
f46376a1 | 249 | |
7972aab2 | 250 | static inline |
f46376a1 | 251 | int ust_metadata_event_statedump( |
b0f2e8db | 252 | lttng::sessiond::ust::registry_session *session __attribute__((unused)), |
d7bfb9b0 JG |
253 | lttng::sessiond::ust::registry_channel *chan __attribute__((unused)), |
254 | lttng::sessiond::ust::registry_event *event __attribute__((unused))) | |
7972aab2 DG |
255 | { |
256 | return 0; | |
257 | } | |
f46376a1 | 258 | |
7972aab2 DG |
259 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
260 | ||
d0b96690 | 261 | #endif /* LTTNG_UST_REGISTRY_H */ |