Fix: sessiond: null pointer dereference on initial evaluation of session
[lttng-tools.git] / src / bin / lttng-sessiond / buffer-registry.hpp
1 /*
2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8 #ifndef LTTNG_BUFFER_REGISTRY_H
9 #define LTTNG_BUFFER_REGISTRY_H
10
11 #include <stdint.h>
12 #include <urcu/list.h>
13
14 #include <lttng/lttng.h>
15 #include <common/hashtable/hashtable.hpp>
16
17 #include "consumer.hpp"
18 #include "lttng-ust-ctl.hpp"
19 #include "ust-registry.hpp"
20 #include "ust-registry-session.hpp"
21
22 struct buffer_reg_stream {
23 struct cds_list_head lnode;
24 union {
25 /* Original object data that MUST be copied over. */
26 struct lttng_ust_abi_object_data *ust;
27 } obj;
28 };
29
30 struct buffer_reg_channel {
31 /* This key is the same as a tracing channel key. */
32 uint32_t key;
33 /* Key of the channel on the consumer side. */
34 uint64_t consumer_key;
35 /* Stream registry object of this channel registry. */
36 struct cds_list_head streams;
37 /* Total number of stream in the list. */
38 uint64_t stream_count;
39 /* Used to ensure mutual exclusion to the stream's list. */
40 pthread_mutex_t stream_list_lock;
41 /* Node for hash table usage. */
42 struct lttng_ht_node_u64 node;
43 /* Size of subbuffers in this channel. */
44 size_t subbuf_size;
45 /* Number of subbuffers per stream. */
46 size_t num_subbuf;
47 union {
48 /* Original object data that MUST be copied over. */
49 struct lttng_ust_abi_object_data *ust;
50 } obj;
51 };
52
53 struct buffer_reg_session {
54 /* Registry per domain. */
55 union {
56 lttng::sessiond::ust::registry_session *ust;
57 } reg;
58
59 /* Contains buffer registry channel indexed by tracing channel key. */
60 struct lttng_ht *channels;
61 };
62
63 /*
64 * Registry object for per UID buffers.
65 */
66 struct buffer_reg_uid {
67 /*
68 * Keys to match this object in a hash table. The following three variables
69 * identify a unique per UID buffer registry.
70 */
71 uint64_t session_id; /* Unique tracing session id. */
72 int bits_per_long; /* ABI */
73 uid_t uid; /* Owner. */
74
75 enum lttng_domain_type domain;
76 struct buffer_reg_session *registry;
77
78 /* Indexed by session id. */
79 struct lttng_ht_node_u64 node;
80 /* Node of a linked list used to teardown object at a destroy session. */
81 struct cds_list_head lnode;
82
83 char root_shm_path[PATH_MAX];
84 char shm_path[PATH_MAX];
85 };
86
87 /*
88 * Registry object for per PID buffers.
89 */
90 struct buffer_reg_pid {
91 uint64_t session_id;
92
93 struct buffer_reg_session *registry;
94
95 /* Indexed by session id. */
96 struct lttng_ht_node_u64 node;
97
98 char root_shm_path[PATH_MAX];
99 char shm_path[PATH_MAX];
100 };
101
102 /* Buffer registry per UID. */
103 void buffer_reg_init_uid_registry(void);
104 int buffer_reg_uid_create(uint64_t session_id, uint32_t bits_per_long, uid_t uid,
105 enum lttng_domain_type domain, struct buffer_reg_uid **regp,
106 const char *root_shm_path, const char *shm_path);
107 void buffer_reg_uid_add(struct buffer_reg_uid *reg);
108 struct buffer_reg_uid *buffer_reg_uid_find(uint64_t session_id,
109 uint32_t bits_per_long, uid_t uid);
110 void buffer_reg_uid_remove(struct buffer_reg_uid *regp);
111 void buffer_reg_uid_destroy(struct buffer_reg_uid *regp,
112 struct consumer_output *consumer);
113
114 /* Buffer registry per PID. */
115 void buffer_reg_init_pid_registry(void);
116 int buffer_reg_pid_create(uint64_t session_id, struct buffer_reg_pid **regp,
117 const char *root_shm_path, const char *shm_path);
118 void buffer_reg_pid_add(struct buffer_reg_pid *reg);
119 struct buffer_reg_pid *buffer_reg_pid_find(uint64_t session_id);
120 void buffer_reg_pid_remove(struct buffer_reg_pid *regp);
121 void buffer_reg_pid_destroy(struct buffer_reg_pid *regp);
122
123 /* Channel */
124 int buffer_reg_channel_create(uint64_t key, struct buffer_reg_channel **regp);
125 void buffer_reg_channel_add(struct buffer_reg_session *session,
126 struct buffer_reg_channel *channel);
127 struct buffer_reg_channel *buffer_reg_channel_find(uint64_t key,
128 struct buffer_reg_uid *reg);
129 void buffer_reg_channel_remove(struct buffer_reg_session *session,
130 struct buffer_reg_channel *regp);
131 void buffer_reg_channel_destroy(struct buffer_reg_channel *regp,
132 enum lttng_domain_type domain);
133
134 /* Stream */
135 int buffer_reg_stream_create(struct buffer_reg_stream **regp);
136 void buffer_reg_stream_add(struct buffer_reg_stream *stream,
137 struct buffer_reg_channel *channel);
138 void buffer_reg_stream_destroy(struct buffer_reg_stream *regp,
139 enum lttng_domain_type domain);
140
141 /* Global registry. */
142 void buffer_reg_destroy_registries(void);
143
144 int buffer_reg_uid_consumer_channel_key(
145 struct cds_list_head *buffer_reg_uid_list,
146 uint64_t chan_key, uint64_t *consumer_chan_key);
147
148 #endif /* LTTNG_BUFFER_REGISTRY_H */
This page took 0.032424 seconds and 4 git commands to generate.